0
|
1 ;=============================================================================
|
|
2 ;
|
634
|
3 ; File eeprom_rs232.asm * combined next generation V3.09.4n
|
0
|
4 ;
|
|
5 ; Internal EEPROM, RS232
|
|
6 ;
|
|
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
|
|
8 ;=============================================================================
|
|
9 ; HISTORY
|
|
10 ; 2011-08-06 : [mH] moving from OSTC code
|
|
11
|
275
|
12 #include "hwos.inc"
|
0
|
13 #include "wait.inc"
|
582
|
14 #include "shared_definitions.h"
|
|
15 #include "rtc.inc"
|
631
|
16 #include "external_flash.inc"
|
|
17
|
|
18 #DEFINE INSIDE_EEPROM_RS232
|
|
19 #include "eeprom_rs232.inc"
|
|
20
|
582
|
21
|
623
|
22 extern lt2942_charge_done
|
|
23
|
634
|
24
|
|
25 ;=============================================================================
|
|
26 eeprom CODE
|
|
27 ;=============================================================================
|
|
28
|
623
|
29 ;-----------------------------------------------------------------------------
|
631
|
30 ;
|
634
|
31 ; EEPROM Functions - for EEPROM Macros and Memory Map, see eeprom_rs232.inc
|
631
|
32 ;
|
|
33 ;-----------------------------------------------------------------------------
|
623
|
34
|
582
|
35
|
623
|
36 ;-----------------------------------------------------------------------------
|
634
|
37 ; Read from internal EEPROM
|
623
|
38 ;
|
604
|
39 ; Input: EEADRH:EEADR = EEPROM address
|
|
40 ; Output: EEDATA
|
|
41 ; Trashed: NONE
|
623
|
42 ;
|
0
|
43 global read_eeprom
|
582
|
44 read_eeprom:
|
634
|
45 bcf EECON1,EEPGD ; access data EEPROM
|
|
46 bcf EECON1,CFGS ; ...
|
|
47 bsf EECON1,RD ; initiate reading
|
|
48 return ; done
|
|
49
|
0
|
50
|
631
|
51 ;-----------------------------------------------------------------------------
|
634
|
52 ; Write into internal EEPROM
|
623
|
53 ;
|
604
|
54 ; Input: EEADRH:EEADR = EEPROM address
|
|
55 ; EEDATA = byte to write
|
|
56 ; Trashed: WREG
|
623
|
57 ;
|
604
|
58 global write_eeprom
|
|
59 write_eeprom:
|
634
|
60 bcf EECON1,EEPGD ; access data EEPROM
|
|
61 bcf EECON1,CFGS ; ...
|
|
62 bsf EECON1,WREN ; enable writing
|
|
63 bcf INTCON,GIE ; disable interrupts
|
631
|
64 movlw 0x55 ; unlock sequence
|
|
65 movwf EECON2 ; ...
|
|
66 movlw 0xAA ; ...
|
|
67 movwf EECON2 ; ...
|
|
68 bsf EECON1,WR ; start write operation
|
|
69 write_eeprom_loop:
|
|
70 btfsc EECON1,WR ; write completed?
|
634
|
71 bra write_eeprom_loop ; NO - loop waiting
|
|
72 bcf EECON1,WREN ; YES - disable writing
|
|
73 bsf INTCON,GIE ; - re-enable interrupts
|
|
74 return ; - done
|
|
75
|
631
|
76
|
|
77 ;-----------------------------------------------------------------------------
|
634
|
78 ; EEPROM read and write Functions to be used via Macros
|
631
|
79 ;
|
|
80 global eeprom_read_common
|
|
81 eeprom_read_common:
|
|
82 movwf eeprom_loop ; initialize loop counter
|
|
83 eeprom_read_common_loop:
|
|
84 rcall read_eeprom ; execute read
|
|
85 movff EEDATA,POSTINC1 ; copy byte from EEPROM data register to memory
|
|
86 incf EEADR,F ; advance to next EEPROM cell
|
|
87 decfsz eeprom_loop,F ; decrement loop counter, all done?
|
|
88 bra eeprom_read_common_loop ; NO - loop
|
|
89 return ; YES - done
|
604
|
90
|
631
|
91 global eeprom_write_common
|
|
92 eeprom_write_common:
|
|
93 movwf eeprom_loop ; initialize loop counter
|
|
94 eeprom_write_common_loop:
|
|
95 movff POSTINC1,EEDATA ; copy byte from memory to EEPROM data register
|
|
96 rcall write_eeprom ; execute write
|
|
97 incf EEADR,F ; advance to next EEPROM cell
|
|
98 decfsz eeprom_loop,F ; decrement loop counter, all done?
|
|
99 bra eeprom_write_common_loop ; NO - loop
|
|
100 return ; YES - done
|
|
101
|
634
|
102
|
631
|
103 ;-----------------------------------------------------------------------------
|
634
|
104 ; Read OSTC Serial Number
|
631
|
105 ;
|
|
106 global eeprom_serial_number_read
|
|
107 eeprom_serial_number_read:
|
634
|
108 EEPROM_II_READ eeprom_ostc_serial,mpr ; read serial number
|
|
109 return ; done
|
|
110
|
604
|
111
|
631
|
112 ;-----------------------------------------------------------------------------
|
634
|
113 ; Read and Write Dive Number Offset
|
631
|
114 ;
|
|
115 global eeprom_log_offset_read
|
|
116 eeprom_log_offset_read:
|
634
|
117 EEPROM_II_READ eeprom_log_offset,mpr ; read log offset
|
|
118 return ; done
|
631
|
119
|
|
120 global eeprom_log_offset_write
|
|
121 eeprom_log_offset_write:
|
634
|
122 EEPROM_II_WRITE mpr,eeprom_log_offset ; write log-offset
|
|
123 return ; done
|
631
|
124
|
|
125
|
|
126 ;-----------------------------------------------------------------------------
|
634
|
127 ; Read and Write total Number of Dives
|
631
|
128 ;
|
|
129 global eeprom_total_dives_read
|
|
130 eeprom_total_dives_read:
|
634
|
131 EEPROM_II_READ eeprom_num_dives,mpr ; read total dives
|
|
132 return ; done
|
631
|
133
|
|
134 global eeprom_total_dives_write
|
|
135 eeprom_total_dives_write:
|
634
|
136 EEPROM_II_WRITE mpr,eeprom_num_dives ; write total dives
|
|
137 return ; done
|
604
|
138
|
631
|
139
|
|
140 ;-----------------------------------------------------------------------------
|
634
|
141 ; Read and Write the Battery Type and Gauge Reading
|
631
|
142 ;
|
|
143 global eeprom_battery_gauge_read
|
|
144 eeprom_battery_gauge_read:
|
|
145 ; retrieve battery gauge from EEPROM 0x07-0x0C
|
|
146 bsf block_battery_gauge ; suspend ISR from accessing the battery gauge
|
|
147 EEPROM_CC_READ eeprom_battery_type, battery_type ; 1 byte read from EEPROM
|
|
148 EEPROM_RR_READ eeprom_battery_gauge,battery_gauge,.6 ; 6 byte read from EEPROM
|
|
149 bcf block_battery_gauge ; allow ISR to access the battery gauge again
|
634
|
150 return ; done
|
631
|
151
|
|
152 global eeprom_battery_gauge_write
|
|
153 eeprom_battery_gauge_write:
|
|
154 bsf block_battery_gauge ; suspend ISR from accessing the battery gauge
|
|
155 EEPROM_CC_WRITE battery_type, eeprom_battery_type ; 1 byte write to EEPROM
|
|
156 update_battery_gauge:
|
|
157 EEPROM_RR_WRITE battery_gauge,eeprom_battery_gauge,.6 ; 6 byte write to EEPROM
|
|
158 bcf block_battery_gauge ; allow ISR to access the battery gauge again
|
634
|
159 return ; done
|
631
|
160
|
|
161
|
|
162 ;-----------------------------------------------------------------------------
|
634
|
163 ; Memorize the Checksum of the Firmware in the update Storage
|
|
164 ;
|
|
165 global eeprom_memorize_fw_checksum
|
|
166 eeprom_memorize_fw_checksum:
|
|
167 EXT_FLASH_ADDR 0x3E000D ; address firmware ID at 0x3E000D
|
|
168 FLASH_CW_READ_0x40 ; read firmware ID to WREG
|
|
169 movff WREG,buffer+.5 ; append firmware ID to checksum
|
|
170 EEPROM_RR_WRITE buffer,eeprom_fw_chksum_current,.6 ; do a 6 byte write to EEPROM
|
|
171 return ; done
|
|
172
|
|
173
|
|
174 ;-----------------------------------------------------------------------------
|
|
175 ; Read and Write the Deco Status
|
631
|
176 ;
|
|
177 global eeprom_deco_data_read
|
|
178 eeprom_deco_data_read:
|
|
179
|
634
|
180 btfsc RCON,POR ; was there a power outage?
|
631
|
181 bra eeprom_deco_data_read_1 ; NO - RTC is up-to-date
|
|
182
|
|
183 EEPROM_RR_READ eeprom_deco_data_timestamp,rtc_latched_year,.6 ; 6 byte read from EEPROM
|
|
184 call rtc_set_rtc ; recover RTC to last known time & date
|
|
185
|
|
186 eeprom_deco_data_read_1:
|
|
187
|
|
188 ; restore surface interval
|
|
189 EEPROM_II_READ eeprom_deco_data_surfinterval,mpr ; 2 byte read from EEPROM
|
|
190 SMOVII mpr,surface_interval_mins ; ISR-safe copy of surface interval
|
|
191
|
|
192 ; bank 3: restore desaturation status
|
|
193 EEPROM_RR_READ eeprom_deco_data_bank3,0x300,.9 ; 9 byte read from EEPROM
|
|
194
|
|
195 ; bank 5: restore CNS
|
|
196 EEPROM_RR_READ eeprom_deco_data_bank5,0x500,.4 ; 4 byte read from EEPROM
|
|
197
|
|
198 ; bank 7: restore tissue pressures
|
|
199 EEPROM_RR_READ eeprom_deco_data_bank7,0x700,.128 ; 128 byte read from EEPROM
|
|
200
|
|
201 return ; done
|
|
202
|
|
203
|
|
204 global eeprom_deco_data_write
|
|
205 eeprom_deco_data_write:
|
|
206
|
|
207 ; invalidate current data in vault
|
|
208 movlw DECO_DATA_INVALID_TOKEN ; deco data invalid token
|
|
209 EEPROM_CC_WRITE WREG,eeprom_deco_data_validity ; 1 byte write to EEPROM
|
|
210
|
|
211 ; store vault version
|
|
212 movlw eeprom_vault_version ; deco data format version
|
|
213 EEPROM_CC_WRITE WREG,eeprom_deco_data_version ; 1 byte write to EEPROM
|
|
214
|
|
215 ; store date/time
|
|
216 SMOVSS rtc_year,rtc_latched_year ; ISR-safe 6 byte copy of date and time
|
|
217 EEPROM_RR_WRITE rtc_latched_year,eeprom_deco_data_timestamp,.6 ; 6 byte write to EEPROM
|
|
218
|
|
219 ; store surface interval
|
|
220 SMOVII surface_interval_mins,mpr ; ISR-safe copy of surface interval
|
|
221 EEPROM_II_WRITE mpr,eeprom_deco_data_surfinterval ; 2 byte write to EEPROM
|
|
222
|
|
223 ; bank 3: store desaturation status
|
|
224 EEPROM_RR_WRITE 0x300,eeprom_deco_data_bank3,.9 ; 9 byte write to EEPROM
|
|
225
|
|
226 ; bank 5: store CNS
|
|
227 EEPROM_RR_WRITE 0x500,eeprom_deco_data_bank5,.4 ; 4 byte write to EEPROM
|
|
228
|
|
229 ; bank 7: store tissue pressures
|
|
230 EEPROM_RR_WRITE 0x700,eeprom_deco_data_bank7,.128 ; 128 byte write to EEPROM
|
|
231
|
|
232 ; indicate new valid data in vault
|
|
233 movlw DECO_DATA_VALID_TOKEN ; deco data valid token
|
|
234 EEPROM_CC_WRITE WREG,eeprom_deco_data_validity ; 1 byte write to EEPROM
|
|
235
|
|
236 return ; done
|
|
237
|
|
238
|
|
239 ;=============================================================================
|
634
|
240 rs232 CODE
|
623
|
241 ;=============================================================================
|
|
242
|
634
|
243 ;-----------------------------------------------------------------------------
|
|
244 ;
|
|
245 ; RS232 Functions
|
|
246 ;
|
|
247 ;-----------------------------------------------------------------------------
|
0
|
248
|
|
249
|
634
|
250 ;-----------------------------------------------------------------------------
|
|
251 ; Switch-On the IR/S8 Port
|
|
252 ;
|
|
253 global enable_ir_s8_analog
|
|
254 enable_ir_s8_analog:
|
623
|
255 ;initialize serial port2 (TRISG2)
|
634
|
256 btfsc ext_input_s8_ana ; do we have an S8/analog input?
|
|
257 bra enable_s8_analog ; YES - enable S8/analog input
|
|
258 ;bra enable_ir ; NO - enable IR digital input
|
0
|
259
|
634
|
260 enable_ir:
|
|
261 banksel BAUDCON2 ; select bank for IO register access
|
|
262 movlw b'00100000' ; speed generator configuration: BRG16=0, inverted for IR
|
|
263 movwf BAUDCON2 ; ...
|
|
264 movlw b'00100000' ; TX configuration: BRGH=0, SYNC=0
|
|
265 movwf TXSTA2 ; ...
|
|
266 movlw .102 ; speed configuration: SPBRGH:SPBRG = .102 : 2403 BAUD @ 16 MHz
|
|
267 movwf SPBRG2 ; ...
|
|
268 clrf SPBRGH2 ; ...
|
|
269 movlw b'10010000' ; RX configuration
|
|
270 movwf RCSTA2 ; ...
|
|
271 banksel common ; back to bank common
|
|
272 bsf ir_power ; power-up IR
|
|
273 btfss ir_power ; power-up confirmed?
|
|
274 bra $-6 ; NO - loop and wait
|
|
275 bsf PIE3,RC2IE ; enable RC2 INT
|
|
276 return ; done
|
|
277
|
|
278 enable_s8_analog:
|
629
|
279 banksel TXSTA2 ; select bank for IO register access
|
631
|
280 clrf TXSTA2 ; reset UART 2 TX function
|
|
281 clrf RCSTA2 ; reset UART 2 RX function
|
623
|
282 banksel common ; back to bank common
|
631
|
283
|
634
|
284 bsf mcp_power ; power-up instrumentation amp (used by S8 and analog input)
|
631
|
285 btfss mcp_power ; power-up completed?
|
|
286 bra $-4 ; NO - loop
|
113
|
287
|
634
|
288 ; branch according to S8 / analog selection
|
631
|
289 TSTOSS opt_s8_mode ; =0: analog, =1: digital RS232
|
634
|
290 bra enable_analog ; -> analog
|
631
|
291
|
|
292 ; configure S8 digital interface
|
|
293 bcf s8_npower ; power S8 HUD (inverted via P-MOS transistor)
|
623
|
294 WAITMS d'30' ; NO - wait 30 ms
|
631
|
295 banksel BAUDCON2 ; select bank for IO register access
|
634
|
296 movlw b'00000000' ; speed generator configuration: BRG16=0, normal for S8
|
|
297 movwf BAUDCON2 ; ...
|
|
298 movlw b'00100000' ; TX configuration: BRGH=0, SYNC=0
|
|
299 movwf TXSTA2 ; ...
|
|
300 movlw .25 ; speed configuration: SPBRGH:SPBRG = .25 : 9615 BAUD @ 16 MHz
|
|
301 movwf SPBRG2 ; ...
|
|
302 movlw b'10010000' ; RX configuration
|
|
303 movwf RCSTA2 ; ...
|
623
|
304 banksel common ; back to bank common
|
631
|
305 bsf PIE3,RC2IE ; enable RC2 INT
|
582
|
306 return
|
113
|
307
|
634
|
308 enable_analog:
|
631
|
309 ; S8 analog interface
|
|
310 bcf PIE3,RC2IE ; disable RC2 INT
|
634
|
311 bsf s8_npower ; power-down S8 digital interface
|
|
312 return ; done
|
631
|
313
|
|
314
|
634
|
315 ;-----------------------------------------------------------------------------
|
|
316 ; Shut-Down the IR/S8 Port
|
|
317 ;
|
|
318 global disable_ir_s8_analog
|
|
319 disable_ir_s8_analog:
|
631
|
320 banksel TXSTA2 ; select bank for IO register access
|
634
|
321 clrf TXSTA2 ; shut down TX function
|
|
322 clrf RCSTA2 ; shut down RX function
|
|
323 banksel common ; back to bank common
|
|
324 bcf PIE3,RC2IE ; disable RC2 INT
|
|
325 bcf ir_power ; power down IR receiver
|
|
326 bcf mcp_power ; power-down instrumentation amp
|
|
327 bsf s8_npower ; power-down S8 digital interface
|
|
328 return ; done
|
|
329
|
|
330
|
|
331 ;-----------------------------------------------------------------------------
|
|
332 ; Send Byte in WREG via the IR/S8 Port
|
|
333 ;
|
|
334 global ir_s8_tx_single
|
|
335 ir_s8_tx_single:
|
|
336 banksel TXSTA2 ; UART 2 is outside of the access RAM
|
|
337 movwf TXREG2 ; transmit byte
|
|
338 ir_s8_tx_single_loop:
|
|
339 btfss TXSTA2,TRMT ; TX completed?
|
|
340 bra ir_s8_tx_single_loop ; NO - wait...
|
|
341 banksel common ; YES - back to bank common
|
631
|
342 return ; - done
|
|
343
|
634
|
344
|
631
|
345 ;-----------------------------------------------------------------------------
|
634
|
346 ; Switch-On USB/BT Port
|
|
347 ;
|
0
|
348 global enable_rs232
|
|
349 enable_rs232:
|
623
|
350 call request_speed_normal ; request CPU speed change to normal speed
|
|
351 enable_rs232_1:
|
|
352 btfss speed_is_normal ; speed = normal?
|
631
|
353 bra enable_rs232_1 ; NO - loop waiting for ISR to have adjusted the speed
|
640
|
354 bsf TRISC,7
|
631
|
355 bcf PORTE,0 ; YES - switch port to comm
|
|
356 bsf PORTJ,2 ; - /Reset (required for very old OSTC sport)
|
|
357 movlw b'00100100' ; - TX configuration: TX enabled, async, high speed
|
|
358 movwf TXSTA1 ; - ...
|
|
359 movlw b'10010000' ; - RX configuration: port enabled, RX enabled
|
|
360 movwf RCSTA1 ; - ...
|
634
|
361 IFNDEF _comm_debug
|
|
362 movlw HIGH(.65536-rx_timeout*.32) ; - define TMR5H initialization value for RX timeout (rx_timeout defined in hwos.inc)
|
|
363 ELSE
|
|
364 include "math.inc"
|
|
365 movff opt_comm_timeout,xA+0 ; - get timeout setting in multiples of 10 ms (opt_comm_timeout: 10 .. 200 x 10 ms)
|
|
366 clrf xA+1 ; - ...
|
|
367 MOVLI .320,xB ; - multiply with 10 to get timeout in ms and 32 because tmr5 ticks 32x per ms
|
|
368 call mult16x16 ; - xC = xA * xB = timer ticks to go until timeout
|
|
369 MOVII xC,sub_b ; - multiplication result is max. 64000
|
|
370 MOVLI .65535,sub_a ; - timer wraps around after 65535
|
|
371 call subU16 ; - sub_c = sub_a - sub_b = start value for timer
|
|
372
|
|
373 movlw .244 ; safety maximum value for rx_timeout_tmr5h_load (minimum timeout interval)
|
|
374 cpfslt sub_c+1 ; result > safety value?
|
|
375 movwf sub_c+1 ; YES - revert to safety value
|
|
376
|
|
377 movf sub_c+1,W ; - keep only the upper byte as TMR5H initialization value for RX timeout
|
|
378 ENDIF
|
|
379 movwf rx_timeout_tmr5h_load ; - store for later use
|
631
|
380 return ; - done
|
0
|
381
|
582
|
382
|
634
|
383 ;-----------------------------------------------------------------------------
|
|
384 ; Shut-Down USB/BT Port
|
|
385 ;
|
0
|
386 global disable_rs232
|
|
387 disable_rs232:
|
631
|
388 clrf RCSTA1 ; disable RX
|
|
389 clrf TXSTA1 ; disable TX
|
|
390 bcf PORTC,6 ; switch TX pin hard to GND
|
634
|
391 bsf PORTE,0 ; power down BT chip
|
631
|
392 bcf PORTJ,2 ; /Reset (required for very old OSTC sport)
|
640
|
393 bcf TRISC,7
|
|
394 bcf PORTC,7 ; switch RX pin hard to GND
|
582
|
395 return
|
|
396
|
|
397
|
634
|
398 ;-----------------------------------------------------------------------------
|
|
399 ; Wait for last Byte to be sent out of USB/BT Port
|
|
400 ;
|
631
|
401 global rs232_wait_tx ; ++++ do not touch WREG here! ++++
|
|
402 rs232_wait_tx:
|
|
403 btfss TXSTA1,TRMT ; last byte completely shifted out on TX pin?
|
|
404 bra rs232_wait_tx ; NO - wait...
|
|
405 btfss ble_available ; YES - OSTC running with Bluetooth?
|
|
406 return ; NO - done
|
|
407 btfsc NRTS ; YES - Bluetooth module also completed TX?
|
|
408 bra rs232_wait_tx ; NO - wait...
|
|
409 return ; YES - done
|
623
|
410
|
|
411
|
634
|
412 ;-----------------------------------------------------------------------------
|
|
413 ; Receive one Byte via the USB/BT Port
|
|
414 ;
|
|
415 ; ++++ make this code as fast as possible! ++++
|
|
416 ; ++++ do not touch WREG here! ++++
|
|
417 ;
|
|
418 global serial_rx_single
|
|
419 serial_rx_single:
|
631
|
420 bcf rs232_rx_timeout ; clear timeout flag
|
634
|
421 btfsc PIR1,RCIF ; received a data byte? (bit is set on RX completion and reset on reading RCREG1)
|
|
422 return ; YES - done (fast path)
|
|
423 movff rx_timeout_tmr5h_load,TMR5H ; NO - load TMR5 high with timeout value
|
631
|
424 clrf TMR5L ; - load TMR5 low with a zero, writing low starts the timer
|
|
425 bcf PIR5,TMR5IF ; - clear timer overflow flag
|
634
|
426 serial_rx_single_loop:
|
631
|
427 btfsc PIR1,RCIF ; received a data byte?
|
634
|
428 return ; YES - done
|
631
|
429 btfss PIR5,TMR5IF ; NO - timer overflow (timeout)?
|
634
|
430 bra serial_rx_single_loop ; NO - continue waiting
|
|
431 ;bra serial_rx_timeout ; YES - timeout
|
623
|
432
|
582
|
433
|
631
|
434 ;-----------------------------------------------------------------------------
|
634
|
435 ; Helper Function: Timeout in serial_rx_single / serial_tx_steam
|
|
436 ;
|
|
437 serial_rx_timeout:
|
|
438 bsf rs232_rx_timeout ; set timeout flag
|
|
439 bcf RCSTA1,CREN ; clear receiver status: disable RX,
|
|
440 bsf RCSTA1,CREN ; ... enable again RX
|
|
441 return ; done
|
|
442
|
623
|
443
|
634
|
444 ;-----------------------------------------------------------------------------
|
|
445 ; Send and Receive Functions to be used via Macros
|
|
446 ;-----------------------------------------------------------------------------
|
|
447
|
|
448 ;-----------------------------------------------------------------------------
|
|
449 ; Send a Range of 1-256 Bytes from Memory via the USB/BT Port
|
631
|
450 ;
|
634
|
451 global serial_tx_steam
|
|
452 serial_tx_steam:
|
631
|
453 movwf eeprom_loop ; initialize loop counter (eeprom variable used here)
|
|
454 serial_tx_ram_loop:
|
|
455 rcall rs232_wait_tx ; wait for completion of last transmit
|
|
456 movff POSTINC2,TXREG1 ; send a byte from memory to serial
|
|
457 decfsz eeprom_loop,F ; decrement loop counter, became zero?
|
|
458 bra serial_tx_ram_loop ; NO - loop
|
|
459 return ; YES - done
|
582
|
460
|
623
|
461
|
634
|
462 ;-----------------------------------------------------------------------------
|
|
463 ; Receive a Range of 1-256 Byte via the USB/BT Port and write them to Memory
|
|
464 ; ++++ make this code as fast as possible! ++++
|
631
|
465 ;
|
634
|
466 global serial_rx_stream
|
|
467 serial_rx_stream:
|
631
|
468 movwf eeprom_loop ; initialize loop counter (eeprom variable used here)
|
634
|
469 serial_rx_stream_loop:
|
631
|
470 btfss PIR1,RCIF ; received a data byte? (bit is set on RX complete and reset on reading RCREG1)
|
634
|
471 bra serial_rx_stream_tmr ; NO - enter receive loop with timeout
|
|
472 ;bra serial_rx_stream_received ; YES - copy to memory, tick counter, ...
|
|
473
|
|
474 serial_rx_stream_received:
|
|
475 movff RCREG1,POSTINC2 ; copy received byte to memory
|
|
476 decfsz eeprom_loop,F ; decrement loop counter, became zero?
|
|
477 bra serial_rx_stream_loop ; NO - await next byte
|
|
478 bcf rs232_rx_timeout ; YES - clear timeout flag
|
|
479 return ; - all bytes received, done
|
|
480
|
|
481 serial_rx_stream_tmr:
|
|
482 movff rx_timeout_tmr5h_load,TMR5H ; load TMR5 high with timeout value
|
|
483 clrf TMR5L ; load TMR5 low with a zero, writing to low starts the timer
|
631
|
484 bcf PIR5,TMR5IF ; clear timer overflow flag
|
634
|
485 serial_rx_stream_tmr_loop:
|
|
486 btfsc PIR1,RCIF ; received a data byte? (bit is set on RX complete and reset on reading RCREG1)
|
|
487 bra serial_rx_stream_received ; YES - copy to memory, tick counter, ...
|
|
488 btfss PIR5,TMR5IF ; NO - timer overflow (timeout)?
|
|
489 bra serial_rx_stream_tmr_loop ; NO - continue waiting
|
|
490 bra serial_rx_timeout ; YES - timeout
|
623
|
491
|
631
|
492 ;-----------------------------------------------------------------------------
|
634
|
493
|
582
|
494 END
|