0
|
1 ;=============================================================================
|
|
2 ;
|
634
|
3 ; File eeprom_rs232.inc * combined next generation V3.09.4n
|
0
|
4 ;
|
|
5 ;
|
|
6 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
|
|
7 ;=============================================================================
|
|
8 ; HISTORY
|
|
9 ; 2011-08-03 : [mH] moving from OSTC code
|
|
10
|
582
|
11
|
631
|
12
|
|
13 ; --------------------------------------------------------------------------------------------
|
|
14 ; EEPROM Defines
|
|
15 ; --------------------------------------------------------------------------------------------
|
|
16
|
|
17 #DEFINE DECO_DATA_VALID_TOKEN 0x55 ; deco data valid
|
|
18 #DEFINE DECO_DATA_INVALID_TOKEN 0xAA ; deco data invalid
|
|
19
|
|
20
|
|
21 ; --------------------------------------------------------------------------------------------
|
|
22 ; EEPROM Memory Map
|
|
23 ; --------------------------------------------------------------------------------------------
|
|
24
|
|
25 ; Label EEPROM Address Size Description
|
|
26
|
|
27 ; bank 1+2: settings & options
|
|
28 ; ---------------------------- +--- do not change the position of these data!
|
|
29 #DEFINE eeprom_ostc_serial 0x000 ; | 2 OSTC dive computer unique serial number
|
|
30 #DEFINE eeprom_num_dives 0x002 ; | 2 total number of dives
|
|
31 #DEFINE eeprom_log_pointer 0x004 ; | 3 pointer used for accessing log data in external flash
|
|
32 #DEFINE eeprom_battery_gauge 0x007 ; | 6 backup storage for the battery gauge meter
|
|
33 #DEFINE eeprom_log_offset 0x00D ; | 2 offset between OSTC dive counting and user's counting
|
|
34 #DEFINE eeprom_battery_type 0x00F ; | 1 battery type inside the OSTC
|
|
35 #DEFINE eeprom_options_version 0x010 ; 2 options version identifier
|
634
|
36 #DEFINE eeprom_fw_chksum_current 0x012 ; 6 checksum of the current firmware *)
|
|
37 ; 0x018 ; 2 unused
|
631
|
38 #DEFINE eeprom_options_storage 0x01A ; 486 backup storage for the options
|
|
39
|
|
40
|
|
41 ; bank 2: deco data backup
|
|
42 ; ------------------------
|
|
43 #DEFINE eeprom_deco_data_validity 0x200 ; 1 deco data validity
|
|
44 #DEFINE eeprom_deco_data_version 0x201 ; 1 deco data format version
|
|
45 #DEFINE eeprom_deco_data_timestamp 0x202 ; 6 date/time of deco data
|
|
46 #DEFINE eeprom_deco_data_surfinterval 0x208 ; 2 surface interval
|
|
47 ; 0x20A ; 6 unused
|
|
48 #DEFINE eeprom_deco_data_bank3 0x210 ; 9 desaturation status
|
|
49 ; 0x219 ; 1 unused
|
|
50 #DEFINE eeprom_deco_data_bank5 0x21A ; 4 CNS
|
|
51 ; 0x21E ; 2 unused
|
|
52 #DEFINE eeprom_deco_data_bank7 0x220 ; 128 tissue pressures
|
|
53 ; 0x2A0 ; 96 unused
|
|
54
|
|
55
|
|
56 ; bank 3: flash backup & factory use
|
|
57 ; ----------------------------------
|
|
58 #DEFINE eeprom_prog_page0_backup 0x300 ; 128 backup storage for the first program memory page
|
|
59 ; 0x380 ; 1 unused
|
|
60 #DEFINE eeprom_button_polarity 0x381 ; 1 button polarity (factory use only, do not change position!)
|
634
|
61 #DEFINE eeprom_fw_chksum_recovry 0x382 ; 6 checksum of stored recovery firmware *)
|
|
62 ; 0x388 ; 121 unused
|
|
63
|
|
64
|
|
65 ; *) 4 byte code checksum, 1 byte checksum of the checksum, 1 byte firmware ID
|
631
|
66
|
|
67
|
|
68
|
|
69 ; --------------------------------------------------------------------------------------------
|
634
|
70 ;
|
|
71 ; EEPROM read & write Macros
|
|
72 ;
|
631
|
73 ; --------------------------------------------------------------------------------------------
|
|
74
|
634
|
75
|
|
76 ;-----------------------------------------------------------------------------
|
|
77 ; read 1 byte from EEPROM to memory
|
|
78 ;
|
|
79 ; eeprom_address: address:2 containing source address in EEPROM
|
|
80 ; memory_address: address:2 containing target address in memory
|
|
81 ;
|
|
82 EEPROM_CC_READ macro eeprom_address, memory_address
|
|
83 movlw HIGH(eeprom_address) ; extract bank in EEPROM
|
|
84 movwf EEADRH ; set bank in EEPROM
|
|
85 movlw LOW (eeprom_address) ; extract start address in EEPROM
|
|
86 movwf EEADR ; set start address in EEPROM
|
|
87 call read_eeprom ; read from EEPROM
|
|
88 movff EEDATA,memory_address ; store to memory
|
|
89 endm
|
|
90
|
|
91
|
|
92 ;-----------------------------------------------------------------------------
|
|
93 ; read 2 bytes from EEPROM to memory, both bytes need to be in same EEPROM bank
|
|
94 ;
|
|
95 ; eeprom_address: address:2 containing start address in EEPROM
|
|
96 ; memory_address: address:2 containing start address in memory
|
|
97 ;
|
|
98 EEPROM_II_READ macro eeprom_address, memory_address
|
|
99 movlw HIGH(eeprom_address) ; extract bank in EEPROM
|
|
100 movwf EEADRH ; set bank in EEPROM
|
|
101 movlw LOW (eeprom_address) ; extract start address in EEPROM
|
|
102 movwf EEADR ; set start address in EEPROM
|
|
103 lfsr FSR1,memory_address ; set start address in memory
|
|
104 movlw .2 ; read 2 bytes
|
|
105 call eeprom_read_common ; execute read
|
|
106 endm
|
|
107
|
|
108
|
|
109 ;-----------------------------------------------------------------------------
|
|
110 ; read 3 bytes from EEPROM to memory, all bytes need to be in same EEPROM bank
|
|
111 ;
|
|
112 ; eeprom_address: address:2 containing start address in EEPROM
|
|
113 ; memory_address: address:2 containing start address in memory
|
|
114 ;
|
|
115 EEPROM_TT_READ macro eeprom_address, memory_address
|
|
116 movlw HIGH(eeprom_address) ; extract bank in EEPROM
|
|
117 movwf EEADRH ; set bank in EEPROM
|
|
118 movlw LOW (eeprom_address) ; extract start address in EEPROM
|
|
119 movwf EEADR ; set start address in EEPROM
|
|
120 lfsr FSR1,memory_address ; set start address in memory
|
|
121 movlw .3 ; read 3 bytes
|
|
122 call eeprom_read_common ; execute read
|
|
123 endm
|
|
124
|
|
125
|
|
126 ;-----------------------------------------------------------------------------
|
|
127 ; read a range of bytes from EEPROM to memory, all bytes need to be in same EEPROM bank
|
|
128 ;
|
|
129 ; eeprom_address: address:2 containing start address in EEPROM
|
|
130 ; memory_address: address:2 containing start address in memory (bank safe)
|
|
131 ; range : number of bytes to read (1-256), will wrap-around staying in same EEPROM bank!
|
|
132 ;
|
|
133 EEPROM_RR_READ macro eeprom_address, memory_address, range
|
|
134 movlw HIGH(eeprom_address) ; extract bank in EEPROM
|
|
135 movwf EEADRH ; set bank in EEPROM
|
|
136 movlw LOW (eeprom_address) ; extract start address in EEPROM
|
|
137 movwf EEADR ; set start address in EEPROM
|
|
138 lfsr FSR1,memory_address ; set start address in memory
|
|
139 movlw low(range) ; set size of range to read
|
|
140 call eeprom_read_common ; execute read
|
|
141 endm
|
|
142
|
|
143
|
|
144 ;-----------------------------------------------------------------------------
|
|
145 ; write 1 byte from memory to EEPROM
|
|
146 ;
|
|
147 ; memory_address: address:2 containing source address in memory (bank safe)
|
|
148 ; eeprom_address: address:2 containing destination address in EEPROM
|
|
149 ;
|
|
150 EEPROM_CC_WRITE macro memory_address, eeprom_address
|
|
151 movlw HIGH(eeprom_address) ; extract bank in EEPROM
|
|
152 movwf EEADRH ; set bank in EEPROM
|
|
153 movlw LOW (eeprom_address) ; extract start address in EEPROM
|
|
154 movwf EEADR ; set start address in EEPROM
|
|
155 movff memory_address,EEDATA ; copy byte to EEPROM data register
|
|
156 call write_eeprom ; execute write
|
|
157 endm
|
|
158
|
|
159
|
|
160 ;-----------------------------------------------------------------------------
|
|
161 ; write 2 bytes from memory to EEPROM, both bytes need to go into the same EEPROM bank
|
|
162 ;
|
|
163 ; memory_address: address:2 containing start address in memory (bank safe)
|
|
164 ; eeprom_address: address:2 containing start address in EEPROM
|
|
165 ;
|
|
166 EEPROM_II_WRITE macro memory_address, eeprom_address
|
|
167 movlw HIGH(eeprom_address) ; extract bank in EEPROM
|
|
168 movwf EEADRH ; set bank in EEPROM
|
|
169 movlw LOW (eeprom_address) ; extract start address in EEPROM
|
|
170 movwf EEADR ; set start address in EEPROM
|
|
171 lfsr FSR1,memory_address ; set start address in memory
|
|
172 movlw .2 ; write 2 bytes
|
|
173 call eeprom_write_common ; execute write
|
|
174 endm
|
|
175
|
|
176
|
|
177 ;-----------------------------------------------------------------------------
|
|
178 ; write 3 bytes from memory to EEPROM, all bytes need to go into the same EEPROM bank
|
|
179 ;
|
|
180 ; memory_address: address:2 containing start address in memory (bank safe)
|
|
181 ; eeprom_address: address:2 containing start address in EEPROM
|
|
182 ;
|
|
183 EEPROM_TT_WRITE macro memory_address, eeprom_address
|
|
184 movlw HIGH(eeprom_address) ; extract bank in EEPROM
|
|
185 movwf EEADRH ; set bank in EEPROM
|
|
186 movlw LOW (eeprom_address) ; extract start address in EEPROM
|
|
187 movwf EEADR ; set start address in EEPROM
|
|
188 lfsr FSR1,memory_address ; set start address in memory
|
|
189 movlw .3 ; write 3 bytes
|
|
190 call eeprom_write_common ; execute write
|
|
191 endm
|
|
192
|
|
193
|
|
194 ;-----------------------------------------------------------------------------
|
|
195 ; write a range of bytes from memory to EEPROM, all bytes need to go into the same EEPROM bank
|
|
196 ;
|
|
197 ; memory_address: address:2 containing start address in memory (bank safe)
|
|
198 ; eeprom_address: address:2 containing start address in EEPROM
|
|
199 ; range : number of bytes to write (1-256), will wrap-around staying in same EEPROM bank!
|
|
200 ;
|
|
201 EEPROM_RR_WRITE macro memory_address, eeprom_address, range
|
|
202 movlw HIGH(eeprom_address) ; extract bank in EEPROM
|
|
203 movwf EEADRH ; set bank in EEPROM
|
|
204 movlw LOW (eeprom_address) ; extract start address in EEPROM
|
|
205 movwf EEADR ; set start address in EEPROM
|
|
206 lfsr FSR1,memory_address ; set start address in memory
|
|
207 movlw low(range) ; set size of range to write
|
|
208 call eeprom_write_common ; execute write
|
|
209 endm
|
|
210
|
|
211
|
|
212 ;-----------------------------------------------------------------------------
|
|
213 ; set up EEPROM address register for subsequent read/write operations
|
|
214 ;
|
|
215 ; eeprom_address: address:2 containing the EEPROM address to set up
|
|
216 ;
|
|
217 EEPROM_SET_ADDRESS macro eeprom_address ; Set EEPROM address
|
|
218 movlw HIGH(eeprom_address) ; extract bank in EEPROM ; for subsequent calls to
|
|
219 movwf EEADRH ; set EEPROM bank ; write_eeprom / read_eeprom
|
|
220 movlw LOW (eeprom_address) ; extract start address in EEPROM
|
|
221 movwf EEADR ; set EEPROM cell
|
|
222 endm
|
|
223
|
|
224
|
|
225
|
|
226 ; --------------------------------------------------------------------------------------------
|
|
227 ;
|
|
228 ; Serial Read & Write Macros
|
|
229 ;
|
|
230 ; --------------------------------------------------------------------------------------------
|
|
231
|
|
232
|
|
233 ;-----------------------------------------------------------------------------
|
|
234 ; Receive 1 Byte and write to Memory
|
|
235 ;
|
|
236 ; in case of a Timeout the Flag 'rs232_rx_timeout' will be set
|
631
|
237 ;
|
|
238 SERIAL_CC_RECEIVE macro mem_address
|
634
|
239 extern serial_rx_single
|
|
240 call serial_rx_single ; (try to) receive one byte
|
631
|
241 movff RCREG1,mem_address ; copy received byte to memory
|
0
|
242 endm
|
|
243
|
582
|
244
|
634
|
245 ;-----------------------------------------------------------------------------
|
|
246 ; Stream a Range of Bytes to Memory
|
|
247 ;
|
|
248 ; in case of a Timeout the Flag 'rs232_rx_timeout' will be set
|
631
|
249 ;
|
|
250 ; mem_address: address:2 containing the start address in memory (bank safe)
|
|
251 ; range : number of bytes to receive (1-256)
|
|
252 ;
|
634
|
253 SERIAL_RR_RECEIVE macro mem_address, range
|
631
|
254 lfsr FSR2,mem_address ; set start address in memory
|
|
255 movlw low(range) ; set number of bytes to receive
|
634
|
256 extern serial_rx_stream
|
|
257 call serial_rx_stream
|
631
|
258 endm
|
|
259
|
|
260
|
634
|
261 ;-----------------------------------------------------------------------------
|
|
262 ; Send 1 Byte Literal
|
631
|
263 ;
|
|
264 SERIAL_LC_SEND macro literal
|
|
265 call rs232_wait_tx ; wait for completion of last transmit
|
|
266 movlw literal ; load literal
|
|
267 movwf TXREG1 ; send literal to serial TX
|
|
268 endm
|
|
269
|
|
270
|
634
|
271 ;-----------------------------------------------------------------------------
|
|
272 ; Send 1 Byte from Memory
|
631
|
273 ;
|
|
274 ; mem_address: address:2 containing the source address in memory (bank safe)
|
|
275 ;
|
|
276 SERIAL_CC_SEND macro mem_address
|
|
277 call rs232_wait_tx ; wait for completion of last transmit
|
|
278 movff mem_address,TXREG1 ; send byte from memory to serial TX
|
|
279 endm
|
|
280
|
|
281
|
634
|
282 ;-----------------------------------------------------------------------------
|
|
283 ; Send a Range of Bytes from Memory
|
631
|
284 ;
|
|
285 ; mem_address: address:2 containing the start address in memory (bank safe)
|
|
286 ; range : number of bytes to send (1-256)
|
|
287 ;
|
634
|
288 SERIAL_RR_SEND macro mem_address, range
|
631
|
289 lfsr FSR2,mem_address ; set start address in memory
|
|
290 movlw low(range) ; set number of bytes to send
|
634
|
291 extern serial_tx_steam
|
|
292 call serial_tx_steam
|
631
|
293 endm
|
|
294
|
|
295
|
|
296 ; --------------------------------------------------------------------------------------------
|
|
297 ; EXTERN Directives
|
|
298 ; --------------------------------------------------------------------------------------------
|
|
299
|
|
300 IFNDEF INSIDE_EEPROM_RS232
|
|
301
|
|
302 ; EEPROM - basic read & write
|
|
303
|
|
304 extern eeprom_read_common
|
|
305 extern eeprom_write_common
|
|
306
|
|
307 extern read_eeprom
|
|
308 extern write_eeprom
|
|
309
|
|
310
|
|
311 ; EEPROM high-level access
|
|
312
|
|
313 extern eeprom_serial_number_read
|
|
314
|
|
315 extern eeprom_total_dives_read
|
|
316 extern eeprom_total_dives_write
|
|
317
|
|
318 extern eeprom_log_offset_read
|
|
319 extern eeprom_log_offset_write
|
|
320
|
|
321 extern eeprom_battery_gauge_read
|
|
322 extern eeprom_battery_gauge_write
|
|
323
|
|
324 extern eeprom_deco_data_read
|
|
325 extern eeprom_deco_data_write
|
|
326
|
|
327
|
|
328 ; Serial - IR / S8
|
|
329
|
634
|
330 extern enable_ir_s8_analog
|
|
331 extern disable_ir_s8_analog
|
|
332 extern ir_s8_tx_single
|
631
|
333
|
|
334
|
|
335 ; Serial - RS232 (USB / BT)
|
|
336
|
582
|
337 extern enable_rs232
|
|
338 extern disable_rs232
|
|
339 extern rs232_wait_tx
|
648
|
340 extern ble2_configure
|
623
|
341
|
629
|
342
|
631
|
343 ENDIF ; INSIDE_EEPROM_RS232
|