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