comparison src/eeprom_rs232.inc @ 634:4050675965ea

3.10 stable release
author heinrichsweikamp
date Tue, 28 Apr 2020 17:34:31 +0200
parents 185ba2f91f59
children aeca5717d9eb
comparison
equal deleted inserted replaced
633:690c48db7b5b 634:4050675965ea
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File eeprom_rs232.inc combined next generation V3.08.8 3 ; File eeprom_rs232.inc * combined next generation V3.09.4n
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
12 ; --------------------------------------------------------------------------------------------
13 ; EEPROM read & write Macros
14 ; --------------------------------------------------------------------------------------------
15
16
17 ; read 1 byte from EEPROM to memory
18 ;
19 ; eeprom_address: address:2 containing source address in EEPROM
20 ; memory_address: address:2 containing target address in memory
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 11
156 12
157 ; -------------------------------------------------------------------------------------------- 13 ; --------------------------------------------------------------------------------------------
158 ; EEPROM Defines 14 ; EEPROM Defines
159 ; -------------------------------------------------------------------------------------------- 15 ; --------------------------------------------------------------------------------------------
175 #DEFINE eeprom_log_pointer 0x004 ; | 3 pointer used for accessing log data in external flash 31 #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 32 #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 33 #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 34 #DEFINE eeprom_battery_type 0x00F ; | 1 battery type inside the OSTC
179 #DEFINE eeprom_options_version 0x010 ; 2 options version identifier 35 #DEFINE eeprom_options_version 0x010 ; 2 options version identifier
180 ; 0x012 ; 8 unused 36 #DEFINE eeprom_fw_chksum_current 0x012 ; 6 checksum of the current firmware *)
37 ; 0x018 ; 2 unused
181 #DEFINE eeprom_options_storage 0x01A ; 486 backup storage for the options 38 #DEFINE eeprom_options_storage 0x01A ; 486 backup storage for the options
182 39
183 40
184 ; bank 2: deco data backup 41 ; bank 2: deco data backup
185 ; ------------------------ 42 ; ------------------------
199 ; bank 3: flash backup & factory use 56 ; bank 3: flash backup & factory use
200 ; ---------------------------------- 57 ; ----------------------------------
201 #DEFINE eeprom_prog_page0_backup 0x300 ; 128 backup storage for the first program memory page 58 #DEFINE eeprom_prog_page0_backup 0x300 ; 128 backup storage for the first program memory page
202 ; 0x380 ; 1 unused 59 ; 0x380 ; 1 unused
203 #DEFINE eeprom_button_polarity 0x381 ; 1 button polarity (factory use only, do not change position!) 60 #DEFINE eeprom_button_polarity 0x381 ; 1 button polarity (factory use only, do not change position!)
204 ; 0x382 ; 126 unused 61 #DEFINE eeprom_fw_chksum_recovry 0x382 ; 6 checksum of stored recovery firmware *)
205 62 ; 0x388 ; 121 unused
206 63
207 64
208 ; -------------------------------------------------------------------------------------------- 65 ; *) 4 byte code checksum, 1 byte checksum of the checksum, 1 byte firmware ID
209 ; Serial read & write Macros 66
210 ; -------------------------------------------------------------------------------------------- 67
211 68
212 ; receive 1 byte and write to memory, in case of timeout the flag 'rs232_rx_timeout' will be set 69 ; --------------------------------------------------------------------------------------------
70 ;
71 ; EEPROM read & write Macros
72 ;
73 ; --------------------------------------------------------------------------------------------
74
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
213 ; 237 ;
214 SERIAL_CC_RECEIVE macro mem_address 238 SERIAL_CC_RECEIVE macro mem_address
215 call rs232_get_byte ; (try to) receive one byte 239 extern serial_rx_single
240 call serial_rx_single ; (try to) receive one byte
216 movff RCREG1,mem_address ; copy received byte to memory 241 movff RCREG1,mem_address ; copy received byte to memory
217 endm 242 endm
218 243
219 244
220 ; stream a range of bytes to memory, in case of timeout the flag 'rs232_rx_timeout' will be set 245 ;-----------------------------------------------------------------------------
246 ; Stream a Range of Bytes to Memory
247 ;
248 ; in case of a Timeout the Flag 'rs232_rx_timeout' will be set
221 ; 249 ;
222 ; mem_address: address:2 containing the start address in memory (bank safe) 250 ; mem_address: address:2 containing the start address in memory (bank safe)
223 ; range : number of bytes to receive (1-256) 251 ; range : number of bytes to receive (1-256)
224 ; 252 ;
225 SERIAL_RR_RECEIVE_RAM macro mem_address, range 253 SERIAL_RR_RECEIVE macro mem_address, range
226 lfsr FSR2,mem_address ; set start address in memory 254 lfsr FSR2,mem_address ; set start address in memory
227 movlw low(range) ; set number of bytes to receive 255 movlw low(range) ; set number of bytes to receive
228 extern serial_rx_stream_ram 256 extern serial_rx_stream
229 call serial_rx_stream_ram 257 call serial_rx_stream
230 endm 258 endm
231 259
232 260
233 261 ;-----------------------------------------------------------------------------
234 ; send 1 byte literal 262 ; Send 1 Byte Literal
235 ; 263 ;
236 SERIAL_LC_SEND macro literal 264 SERIAL_LC_SEND macro literal
237 call rs232_wait_tx ; wait for completion of last transmit 265 call rs232_wait_tx ; wait for completion of last transmit
238 movlw literal ; load literal 266 movlw literal ; load literal
239 movwf TXREG1 ; send literal to serial TX 267 movwf TXREG1 ; send literal to serial TX
240 endm 268 endm
241 269
242 270
243 ; send 1 byte from memory 271 ;-----------------------------------------------------------------------------
272 ; Send 1 Byte from Memory
244 ; 273 ;
245 ; mem_address: address:2 containing the source address in memory (bank safe) 274 ; mem_address: address:2 containing the source address in memory (bank safe)
246 ; 275 ;
247 SERIAL_CC_SEND macro mem_address 276 SERIAL_CC_SEND macro mem_address
248 call rs232_wait_tx ; wait for completion of last transmit 277 call rs232_wait_tx ; wait for completion of last transmit
249 movff mem_address,TXREG1 ; send byte from memory to serial TX 278 movff mem_address,TXREG1 ; send byte from memory to serial TX
250 endm 279 endm
251 280
252 281
253 ; send a range of bytes from memory 282 ;-----------------------------------------------------------------------------
283 ; Send a Range of Bytes from Memory
254 ; 284 ;
255 ; mem_address: address:2 containing the start address in memory (bank safe) 285 ; mem_address: address:2 containing the start address in memory (bank safe)
256 ; range : number of bytes to send (1-256) 286 ; range : number of bytes to send (1-256)
257 ; 287 ;
258 SERIAL_RR_SEND_RAM macro mem_address, range 288 SERIAL_RR_SEND macro mem_address, range
259 lfsr FSR2,mem_address ; set start address in memory 289 lfsr FSR2,mem_address ; set start address in memory
260 movlw low(range) ; set number of bytes to send 290 movlw low(range) ; set number of bytes to send
261 extern serial_tx_ram 291 extern serial_tx_steam
262 call serial_tx_ram 292 call serial_tx_steam
263 endm 293 endm
264 294
265 295
266 ; -------------------------------------------------------------------------------------------- 296 ; --------------------------------------------------------------------------------------------
267 ; EXTERN Directives 297 ; EXTERN Directives
295 extern eeprom_deco_data_write 325 extern eeprom_deco_data_write
296 326
297 327
298 ; Serial - IR / S8 328 ; Serial - IR / S8
299 329
300 extern enable_ir_s8 330 extern enable_ir_s8_analog
301 extern disable_ir_s8 331 extern disable_ir_s8_analog
302 extern ir_s8_wait_tx 332 extern ir_s8_tx_single
303 333
304 334
305 ; Serial - RS232 (USB / BT) 335 ; Serial - RS232 (USB / BT)
306 336
307 extern enable_rs232 337 extern enable_rs232
308 extern disable_rs232 338 extern disable_rs232
309 extern rs232_get_byte
310 extern rs232_wait_tx 339 extern rs232_wait_tx
311 340
312 341
313 ENDIF ; INSIDE_EEPROM_RS232 342 ENDIF ; INSIDE_EEPROM_RS232