comparison src/rx_ops.asm @ 623:c40025d8e750

3.03 beta released
author heinrichsweikamp
date Mon, 03 Jun 2019 14:01:48 +0200
parents ca4556fb60b9
children cd58f7fc86db
comparison
equal deleted inserted replaced
622:02d1386429a6 623:c40025d8e750
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File rx_ops.asm V2.99c 3 ; File rx_ops.asm combined next generation V3.03.1
4 ; 4 ;
5 ; RX (Tank Pressure Transmitter) Routines. 5 ; RX (Tank Pressure Transmitter) Routines.
6 ; 6 ;
7 ; Copyright (c) 2018, heinrichs weikamp, all right reserved. 7 ; Copyright (c) 2018, heinrichs weikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
9 9
10 #include "hwos.inc" ; mandatory header 10 #include "hwos.inc" ; mandatory header
11 #include "shared_definitions.h" ; mailbox to p2_deco.c 11 #include "shared_definitions.h" ; mailbox to p2_deco.c
12 #include "i2c.inc" 12 #include "i2c.inc"
13 #include "math.inc" 13 #include "math.inc"
14 #include "isr.inc" 14 #include "wait.inc"
15
16 ;=============================================================================
17
18 IFDEF _rx_functions
19
15 20
16 extern get_first_gas_to_WREG 21 extern get_first_gas_to_WREG
22 extern I2C_update_OSTC_rx
23 extern I2C_probe_OSTC_rx
24 extern rx_firmware_storage
25
26 IFDEF _ccr_pscr
17 extern get_first_dil_to_WREG 27 extern get_first_dil_to_WREG
28 ENDIF
18 29
19 30
20 ; SAC calculation averaging settings 31 ; SAC calculation averaging settings
21 #DEFINE time_accu_target_OC .60 ; [s] target time accumulator filling level in OC modes 32 #DEFINE time_accu_target_OC .60 ; [s] target time accumulator filling level in OC modes
22 #DEFINE time_accu_target_CCR .180; [s] target time accumulator filling level in CCR mode 33 #DEFINE time_accu_target_CCR .180; [s] target time accumulator filling level in CCR mode
23 34
24 35
25 rx_ops CODE 36 rx_ops CODE
26 37
27 IFDEF _rx_functions
28
29 ;============================================================================= 38 ;=============================================================================
39
40
41 ;-----------------------------------------------------------------------------
30 ; Get configured pressure readings 42 ; Get configured pressure readings
31 ; 43 ;
32 ; input : opt_TR_1st_pres - selector for first pressure reading, in normal mode 44 ; input : opt_TR_1st_pres - selector for first pressure reading, in normal mode
33 ; opt_TR_Bail_pres - selector for first pressure reading, in bailout mode 45 ; opt_TR_Bail_pres - selector for first pressure reading, in bailout mode
34 ; opt_TR_2nd_pres - selector for second pressure reading, all modes 46 ; opt_TR_2nd_pres - selector for second pressure reading, all modes
42 global get_pressure_readings 54 global get_pressure_readings
43 get_pressure_readings: 55 get_pressure_readings:
44 call I2C_get_tankdata ; get raw pressure data 56 call I2C_get_tankdata ; get raw pressure data
45 get_pressure_readings_1: 57 get_pressure_readings_1:
46 movff opt_TR_1st_pres,ul ; 1st pressure to read 58 movff opt_TR_1st_pres,ul ; 1st pressure to read
47 btfsc FLAG_bailout_mode ; in bailout mode? 59 btfsc bailout_mode ; in bailout mode?
48 movff opt_TR_Bail_pres,ul ; YES - replace with assigned bailout selection 60 movff opt_TR_Bail_pres,ul ; YES - replace with assigned bailout selection
49 tstfsz ul ; disabled? 61 tstfsz ul ; disabled?
50 bra get_pressure_readings_1a ; NO - get received pressure data 62 bra get_pressure_readings_1a ; NO - get received pressure data
51 rcall get_pressure_readings_H1 ; YES - set pressure data to not available 63 rcall get_pressure_readings_H1 ; YES - set pressure data to not available
52 bra get_pressure_readings_1c ; - continue with copying to result vars 64 bra get_pressure_readings_1c ; - continue with copying to result vars
53 get_pressure_readings_1a: 65 get_pressure_readings_1a:
66 IFDEF _ccr_pscr
54 movlw .11 ; first code for "special" pressures 67 movlw .11 ; first code for "special" pressures
55 cpfslt ul ; opt_TR_1st_pres < 11 ? 68 cpfslt ul ; opt_TR_1st_pres < 11 ?
56 rcall get_pressure_readings_H2 ; NO - pre-process measurement selection 69 rcall get_pressure_readings_H2 ; NO - pre-process measurement selection
70 ENDIF
57 rcall get_pressure_readings_H3 ; get transmitter ID 71 rcall get_pressure_readings_H3 ; get transmitter ID
58 rcall get_pres_by_transmitter_id ; get data from transmitter with ID in hi:lo into hi:lo (pressure) and up (status) 72 rcall get_pres_by_transmitter_id ; get data from transmitter with ID in hi:lo into hi:lo (pressure) and up (status)
59 get_pressure_readings_1c: 73 get_pressure_readings_1c:
60 movff lo,int_IO_pressure_value+0 ; copy pressure, low byte 74 movff lo,int_IO_pressure_value+0 ; copy pressure, low byte
61 movff hi,int_IO_pressure_value+1 ; copy pressure, high byte 75 movff hi,int_IO_pressure_value+1 ; copy pressure, high byte
67 tstfsz ul ; disabled? 81 tstfsz ul ; disabled?
68 bra get_pressure_readings_2a ; NO - get received pressure data 82 bra get_pressure_readings_2a ; NO - get received pressure data
69 rcall get_pressure_readings_H1 ; YES - set pressure data to not available 83 rcall get_pressure_readings_H1 ; YES - set pressure data to not available
70 bra get_pressure_readings_2c ; - continue with copying to result vars 84 bra get_pressure_readings_2c ; - continue with copying to result vars
71 get_pressure_readings_2a: 85 get_pressure_readings_2a:
86 IFDEF _ccr_pscr
72 movlw .11 ; first code for "special" pressures 87 movlw .11 ; first code for "special" pressures
73 cpfslt ul ; opt_TR_2nd_pres < 11 ? 88 cpfslt ul ; opt_TR_2nd_pres < 11 ?
74 rcall get_pressure_readings_H2 ; NO - pre-process measurement selection 89 rcall get_pressure_readings_H2 ; NO - pre-process measurement selection
90 ENDIF
75 btfss ul,7 ; gas selector >= 127 (special treatment)? 91 btfss ul,7 ; gas selector >= 127 (special treatment)?
76 bra get_pressure_readings_2b ; NO - proceed reading a pressure 92 bra get_pressure_readings_2b ; NO - proceed reading a pressure
77 rcall get_pressure_readings_H1 ; YES - set pressure data to not available 93 rcall get_pressure_readings_H1 ; YES - set pressure data to not available
78 bra get_pressure_readings_2c ; - continue wit copying to output data 94 bra get_pressure_readings_2c ; - continue wit copying to output data
79 get_pressure_readings_2b: 95 get_pressure_readings_2b:
93 clrf up ; set age to 0 109 clrf up ; set age to 0
94 clrf ex ; set status to 0 110 clrf ex ; set status to 0
95 bsf hi,int_not_avail_flag ; set flag for data not available 111 bsf hi,int_not_avail_flag ; set flag for data not available
96 return 112 return
97 113
114
115 IFDEF _ccr_pscr
98 get_pressure_readings_H2: 116 get_pressure_readings_H2:
99 movlw .11 117 movlw .11
100 subwf ul,F 118 subwf ul,F
101 bnz get_pressure_readings_H2a 119 bnz get_pressure_readings_H2a
102 call get_first_gas_to_WREG ; ul = 11 -> ul = (get_first_gas_to_WREG) 120 call get_first_gas_to_WREG ; ul = 11 -> ul = (get_first_gas_to_WREG)
124 return 142 return
125 get_pressure_readings_H2d: 143 get_pressure_readings_H2d:
126 movlw .1 144 movlw .1
127 movwf ul ; ul >= 15 -> should not happen, default to ul = 1 145 movwf ul ; ul >= 15 -> should not happen, default to ul = 1
128 return 146 return
147 ENDIF ; _ccr_pscr
148
129 149
130 get_pressure_readings_H3: 150 get_pressure_readings_H3:
131 lfsr FSR1,opt_transmitter_id_1 ; load base address of transmitter ID array 151 lfsr FSR1,opt_transmitter_id_1 ; load base address of transmitter ID array
132 decf ul,W ; (1-10) -> (0-9) 152 decf ul,W ; (1-10) -> (0-9)
133 mullw .2 ; IDs are 2 byte in size 153 mullw .2 ; IDs are 2 byte in size
136 incf WREG,W ; increment index 156 incf WREG,W ; increment index
137 movff PLUSW1,hi ; get transmitter ID (high byte) 157 movff PLUSW1,hi ; get transmitter ID (high byte)
138 return 158 return
139 159
140 160
141 ;============================================================================= 161 ;-----------------------------------------------------------------------------
142 ; Get data from transmitter with ID in (hi:lo) 162 ; Get data from transmitter with ID in (hi:lo)
143 ; 163 ;
144 ; input: hi:lo = transmitter ID 164 ; input: hi:lo = transmitter ID
145 ; 165 ;
146 ; output: hi:lo = pressure in 0.1 bar if return code = 0, else 0 + int_not_avail_flag 166 ; output: hi:lo = pressure in 0.1 bar if return code = 0, else 0 + int_not_avail_flag
224 clrf up ; clear up (age of data) 244 clrf up ; clear up (age of data)
225 bsf hi,int_not_avail_flag ; set flag for data not available 245 bsf hi,int_not_avail_flag ; set flag for data not available
226 return ; done 246 return ; done
227 247
228 248
229 ;============================================================================= 249 ;-----------------------------------------------------------------------------
230 ; Get transmitter ID in given slot 250 ; Get transmitter ID in given slot
231 ; 251 ;
232 ; input : WREG = slot (0-7) 252 ; input : WREG = slot (0-7)
233 ; output : hi:lo = transmitter ID 253 ; output : hi:lo = transmitter ID
234 ; 254 ;
241 incf WREG,W ; increment index 261 incf WREG,W ; increment index
242 movff PLUSW1,lo ; read transmitter ID low byte 262 movff PLUSW1,lo ; read transmitter ID low byte
243 return 263 return
244 264
245 265
246 ;============================================================================= 266 ;-----------------------------------------------------------------------------
247 ; Compute average pressure drop from 1st / 2nd reading 267 ; Compute average pressure drop from 1st / 2nd reading
248 ; 268 ;
249 ; Memory Map: 269 ; Memory Map:
250 ; ------------------------------------------------------------------------------------ 270 ; ------------------------------------------------------------------------------------
251 ; 271 ;
369 movf divA+1,W ; copy pres_curr (divA) to WREG, high byte 389 movf divA+1,W ; copy pres_curr (divA) to WREG, high byte
370 subwfb xC+3,F ; subtract from pres_accu (xC), highest byte 390 subwfb xC+3,F ; subtract from pres_accu (xC), highest byte
371 btfss STATUS,C ; did the accumulator under-run (result negative)? 391 btfss STATUS,C ; did the accumulator under-run (result negative)?
372 bsf neg_flag ; YES - memorize this 392 bsf neg_flag ; YES - memorize this
373 393
374 ; get the current time into lo 394 ; get the current time into the multi-purpose register
375 SAFE_2BYTE_COPY total_divetime_seconds,lo ; get current total dive time into lo:2 395 SMOVII total_divetime_secs,mpr ; ISR-safe 2 byte copy of current total dive time into hi:lo
376 396
377 ; get the last pressure time and store the current time as the new last pressure time 397 ; get the last pressure time and store the current time as the new last pressure time
378 movlw offset_FSR1_time_last+0 ; load index of last pressure time, low byte 398 movlw offset_FSR1_time_last+0 ; load index of last pressure time, low byte
379 movff PLUSW1,sub_b+0 ; copy last pressure time to sub_b, low byte 399 movff PLUSW1,sub_b+0 ; copy last pressure time to sub_b, low byte
380 movff lo+0,PLUSW1 ; store current time as new last pressure time, low byte 400 movff lo,PLUSW1 ; store current time as new last pressure time, low byte
381 movlw offset_FSR1_time_last+1 ; load index of last pressure time, high byte 401 movlw offset_FSR1_time_last+1 ; load index of last pressure time, high byte
382 movff PLUSW1,sub_b+1 ; copy last pressure time to sub_b, high byte 402 movff PLUSW1,sub_b+1 ; copy last pressure time to sub_b, high byte
383 movff lo+1,PLUSW1 ; store current time as new last pressure time, high byte 403 movff hi,PLUSW1 ; store current time as new last pressure time, high byte
384 404
385 ; did the pressure accumulator under-run before because the current pressure is higher than the accumulator value was? 405 ; did the pressure accumulator under-run before because the current pressure is higher than the accumulator value was?
386 ; we can not check & abort earlier because the current time needs to be stored along with the current pressure 406 ; we can not check & abort earlier because the current time needs to be stored along with the current pressure
387 btfsc neg_flag ; did the pressure accumulator under-run? 407 btfsc neg_flag ; did the pressure accumulator under-run?
388 bra calc_pres_drop_restart ; YES - reset both accumulators and set average pressure drop to not available 408 bra calc_pres_drop_restart ; YES - reset both accumulators and set average pressure drop to not available
389 409
390 ; add the current time to the time accumulator: time_accu (xB) += time_curr (lo) 410 ; add the current time to the time accumulator: time_accu (xB) += time_curr (mpr)
391 movf lo+0,W ; copy time_curr (lo) to WREG, low byte 411 movf lo,W ; copy time_curr (mpr) to WREG, low byte
392 addwf xB+0,F ; add to time_accu (xB), low byte 412 addwf xB+0,F ; add to time_accu (xB), low byte
393 movf lo+1,W ; copy time_curr (lo) to WREG, high byte 413 movf hi,W ; copy time_curr (mpr) to WREG, high byte
394 addwfc xB+1,F ; add to time_accu (xB), high_byte 414 addwfc xB+1,F ; add to time_accu (xB), high_byte
395 415
396 ; subtract the last pressure time from time accumulator: time_accu (xB) -= time_last (sub_b) 416 ; subtract the last pressure time from time accumulator: time_accu (xB) -= time_last (sub_b)
397 movf sub_b+0,W ; copy time_last (sub_b) to WREG, low byte 417 movf sub_b+0,W ; copy time_last (sub_b) to WREG, low byte
398 subwf xB+0,F ; subtract from time_accu (xB), low byte 418 subwf xB+0,F ; subtract from time_accu (xB), low byte
399 movf sub_b+1,W ; copy time_last (sub_b) to WREG, high byte 419 movf sub_b+1,W ; copy time_last (sub_b) to WREG, high byte
411 ; as long as no valid pressure value is available, the time accumulator will stay at 0 and the pressure drop calculation kept in reset 431 ; as long as no valid pressure value is available, the time accumulator will stay at 0 and the pressure drop calculation kept in reset
412 movf xB+0,W ; copy time accumulator low byte to WREG, does it set the zero flag? 432 movf xB+0,W ; copy time accumulator low byte to WREG, does it set the zero flag?
413 bz calc_pres_drop_restart ; YES - reset both accumulators and set average pressure drop to not available 433 bz calc_pres_drop_restart ; YES - reset both accumulators and set average pressure drop to not available
414 434
415 ; duplicate pressure and time accumulators to other variables because xC and xB will get destroyed in div32x16 operation 435 ; duplicate pressure and time accumulators to other variables because xC and xB will get destroyed in div32x16 operation
416 movff xC+0,lo+0 ; duplicate pres_accu to lo, lowest byte 436 movff xC+0,mpr+0 ; duplicate pres_accu to mpr, lowest byte
417 movff xC+1,lo+1 ; duplicate pres_accu to lo, second byte 437 movff xC+1,mpr+1 ; duplicate pres_accu to mpr, second byte
418 movff xC+2,lo+2 ; duplicate pres_accu to lo, third byte 438 movff xC+2,mpr+3 ; duplicate pres_accu to mpr, third byte
419 movff xC+3,lo+3 ; duplicate pres_accu to lo, highest byte 439 movff xC+3,mpr+4 ; duplicate pres_accu to mpr, highest byte
420 movff xB+0,divA+0 ; duplicate time_accu to divA, low byte 440 movff xB+0,divA+0 ; duplicate time_accu to divA, low byte
421 movff xB+1,divA+1 ; duplicate time_accu to divA, high byte 441 movff xB+1,divA+1 ; duplicate time_accu to divA, high byte
422 442
423 ; calculate average pressure drop: pres_drop (xC) = pres_accu (xC) / time_accu (xB) 443 ; calculate average pressure drop: pres_drop (xC) = pres_accu (xC) / time_accu (xB)
424 call div32x16 ; xC = xC / xB, xC is average pressure drop in 1/(160 * 2^16) bar/sec 444 call div32x16 ; xC = xC / xB, xC is average pressure drop in 1/(160 * 2^16) bar/sec
427 incf ul,W ; load the target threshold, +1 (incf) transforms cpfslt from < to <= operation 447 incf ul,W ; load the target threshold, +1 (incf) transforms cpfslt from < to <= operation
428 cpfslt divA+0 ; is the time accumulator > target threshold ? 448 cpfslt divA+0 ; is the time accumulator > target threshold ?
429 rcall calc_pres_drop_reduce_accus ; YES - do an accumulator reduction 449 rcall calc_pres_drop_reduce_accus ; YES - do an accumulator reduction
430 450
431 ; do an additional half-rate (every 2nd second) accumulator reduction 451 ; do an additional half-rate (every 2nd second) accumulator reduction
432 btfsc total_divetime_seconds+0,0 ; are we on an even second? 452 btfsc timebase_1sec ; are we on an even second?
433 rcall calc_pres_drop_reduce_accus ; YES - do an additional accumulator reduction 453 rcall calc_pres_drop_reduce_accus ; YES - do an additional accumulator reduction
434 454
435 ; store pressure accumulator (lo:4) - FSR0 was left pointing to address of highest byte 455 ; store pressure accumulator (mpr:4) - FSR0 was left pointing to address of highest byte
436 movff lo+3,POSTDEC0 ; store pressure accumulator, highest byte 456 movff mpr+3,POSTDEC0 ; store pressure accumulator, highest byte
437 movff lo+2,POSTDEC0 ; store pressure accumulator, third byte 457 movff mpr+2,POSTDEC0 ; store pressure accumulator, third byte
438 movff lo+1,POSTDEC0 ; store pressure accumulator, second byte 458 movff mpr+1,POSTDEC0 ; store pressure accumulator, second byte
439 movff lo+0,POSTDEC0 ; store pressure accumulator, lowest byte 459 movff mpr+0,POSTDEC0 ; store pressure accumulator, lowest byte
440 460
441 ; store the time accumulator 461 ; store the time accumulator
442 movff divA+0,INDF1 ; store time accumulator (only the low byte will be stored) 462 movff divA+0,INDF1 ; store time accumulator (only the low byte will be stored)
443 463
444 ; check if the average pressure drop for transfer to p2deco needs to be limited 464 ; check if the average pressure drop for transfer to p2deco needs to be limited
454 call div16 ; divA = divA / 2^WREG 474 call div16 ; divA = divA / 2^WREG
455 bra calc_pres_drop_common_3 475 bra calc_pres_drop_common_3
456 476
457 calc_pres_drop_limit: 477 calc_pres_drop_limit:
458 ; limit output to 0x0FFF 478 ; limit output to 0x0FFF
459 movlw LOW 0x0FFF ; set output to 0x0FFF 479 MOVLI 0x0FFF,divA ; set output to 0x0FFF
460 movwf divA+0 ; ...
461 movlw HIGH 0x0FFF ; ...
462 movwf divA+1 ; ...
463 bsf divA+1,int_warning_flag ; set warning flag indicating out-of-range 480 bsf divA+1,int_warning_flag ; set warning flag indicating out-of-range
464 481
465 calc_pres_drop_common_3: 482 calc_pres_drop_common_3:
466 ; set the average pressure drop as not available if the last pressure reading is outdated or not available 483 ; set the average pressure drop as not available if the last pressure reading is outdated or not available
467 btfsc aux_flag ; is the last pressure reading outdated or not available? 484 btfsc aux_flag ; is the last pressure reading outdated or not available?
485 502
486 calc_pres_drop_reduce_accus: 503 calc_pres_drop_reduce_accus:
487 ; subtract 1 second from the time accumulator: time_accu (divA) -= 1 (only the low byte needs to be processed) 504 ; subtract 1 second from the time accumulator: time_accu (divA) -= 1 (only the low byte needs to be processed)
488 decf divA+0,F ; decrement low byte of time_accu 505 decf divA+0,F ; decrement low byte of time_accu
489 506
490 ; subtract average pressure drop per second from pressure accumulator: press_accu (lo) -= press_drop (xC) 507 ; subtract average pressure drop per second from pressure accumulator: press_accu (mpr) -= press_drop (xC)
491 movf xC+0,W ; copy press_drop(xC) to WREG, lowest byte 508 movf xC+0,W ; copy press_drop(xC) to WREG, lowest byte
492 subwf lo+0,F ; subtract from pres_accu, lowest byte 509 subwf mpr+0,F ; subtract from pres_accu, lowest byte
493 movf xC+1,W ; copy press_drop(xC) to WREG, second byte 510 movf xC+1,W ; copy press_drop(xC) to WREG, second byte
494 subwfb lo+1,F ; subtract from pres_accu, second byte 511 subwfb mpr+1,F ; subtract from pres_accu, second byte
495 movf xC+2,W ; copy press_drop(xC) to WREG, third byte 512 movf xC+2,W ; copy press_drop(xC) to WREG, third byte
496 subwfb lo+2,F ; subtract from pres_accu, third byte 513 subwfb mpr+2,F ; subtract from pres_accu, third byte
497 movf xC+3,W ; copy press_drop(xC) to WREG, highest byte 514 movf xC+3,W ; copy press_drop(xC) to WREG, highest byte
498 subwfb lo+3,F ; subtract from pres_accu, highest byte 515 subwfb mpr+3,F ; subtract from pres_accu, highest byte
499 btfsc STATUS,C ; did the buffer under-run (result negative)? 516 btfsc STATUS,C ; did the buffer under-run (result negative)?
500 return ; NO - done 517 return ; NO - done
501 clrf lo+0 ; YES - clear pressure accumulator, lowest byte 518 clrf mpr+0 ; YES - clear pressure accumulator, lowest byte
502 clrf lo+1 ; - clear pressure accumulator, second byte 519 clrf mpr+1 ; - clear pressure accumulator, second byte
503 clrf lo+2 ; - clear pressure accumulator, third byte 520 clrf mpr+2 ; - clear pressure accumulator, third byte
504 clrf lo+3 ; - clear pressure accumulator, highest byte 521 clrf mpr+3 ; - clear pressure accumulator, highest byte
505 return ; - done 522 return ; - done
506 523
507 calc_pres_drop_reset: 524 calc_pres_drop_reset:
508 ; store the current gas as the last gas 525 ; store the current gas as the last gas
509 movlw offset_FSR1_gas__last ; load index of last gas 526 movlw offset_FSR1_gas__last ; load index of last gas
539 bsf PLUSW2,int_not_avail_flag ; set flag for data not available 556 bsf PLUSW2,int_not_avail_flag ; set flag for data not available
540 557
541 return ; done 558 return ; done
542 559
543 560
544 ;============================================================================= 561 ;-----------------------------------------------------------------------------
545 ; set up SAC calculation dependent on TR mode 562 ; set up SAC calculation dependent on TR mode
546 ; 563 ;
547 global configure_sac_calculation 564 global configure_sac_calculation
548 configure_sac_calculation: 565 configure_sac_calculation:
549 movlw time_accu_target_OC ; load time accumulator target value for OC as default 566 movlw time_accu_target_OC ; load time accumulator target value for OC as default
567 rcall calc_pres_drop_2nd ; calculate pressure drop on 2nd reading 584 rcall calc_pres_drop_2nd ; calculate pressure drop on 2nd reading
568 movlw .3 ; select SAC mode 3: SAC on higher of both readings 585 movlw .3 ; select SAC mode 3: SAC on higher of both readings
569 bra configure_sac_calculation_5 ; goto exit 586 bra configure_sac_calculation_5 ; goto exit
570 587
571 configure_sac_calculation_3: ; TR mode 3: CCR Dil+O2 588 configure_sac_calculation_3: ; TR mode 3: CCR Dil+O2
572 btfsc FLAG_bailout_mode ; in bailout? 589 btfsc bailout_mode ; in bailout?
573 bra configure_sac_calculation_1 ; YES - handle alike TR mode 1 590 bra configure_sac_calculation_1 ; YES - handle alike TR mode 1
574 movlw time_accu_target_CCR ; load time accumulator target value for CCR mode 591 movlw time_accu_target_CCR ; load time accumulator target value for CCR mode
575 movwf ul ; store it in ul 592 movwf ul ; store it in ul
576 rcall calc_pres_drop_2nd ; calculate pressure drop on 2nd reading 593 rcall calc_pres_drop_2nd ; calculate pressure drop on 2nd reading
577 movlw .4 ; select SAC mode 4: SAC on 2nd reading, O2 usage 594 movlw .4 ; select SAC mode 4: SAC on 2nd reading, O2 usage
582 599
583 configure_sac_calculation_5: 600 configure_sac_calculation_5:
584 movff WREG,char_I_SAC_mode ; write SAC mode selection 601 movff WREG,char_I_SAC_mode ; write SAC mode selection
585 return 602 return
586 603
604
605 ;-----------------------------------------------------------------------------
606 ; Update TR module
607 ;
608 global update_tr_module
609 update_tr_module:
610 movlw LOW rx_firmware_storage ; setup program memory read for embedded TR firmware
611 movwf TBLPTRL
612 movlw HIGH rx_firmware_storage
613 movwf TBLPTRH
614 movlw UPPER rx_firmware_storage
615 movwf TBLPTRU
616
617 bsf active_reset_ostc_rx ; apply a reset to the RX co-processor
618 WAITMS .200 ; wait 200 ms
619 bcf active_reset_ostc_rx ; release reset
620 WAITMS .100 ; wait 100 ms, the RX co-processor will be in bootloader stage by then
621
622 bcf INTCON,GIE ; halt all interrupts
623
624 movlw .64 ; load loop counter
625 movwf lo ; ...
626
627 update_tr_module_loop: ; (loop 64 times)
628 call I2C_update_OSTC_rx ; send a batch of 64 bytes to the RX co-processor
629 tstfsz WREG ; WREG = 0, i.e. data sent successfully?
630 bra update_tr_module_fail ; NO - transfer error, abort
631 decfsz lo,F ; YES - decrement loop counter, became zero?
632 bra update_tr_module_loop ; NO - loop
633 bra update_tr_module_done ; YES - transfer complete & successful
634
635 update_tr_module_fail:
636 bsf INTCON,GIE ; re-enable interrupts
637 bcf ostc_rx_present ; flag TR module as unserviceable
638 return ; done
639
640 update_tr_module_done:
641 bsf INTCON,GIE ; re-enable interrupts
642
643 call wait_1s ; wait (up to) 1 second
644 call wait_1s ; wait (another full) 1 second
645
646 bsf active_reset_ostc_rx ; apply a reset to the RX co-processor
647 WAITMS .200 ; wait 200 ms
648 bcf active_reset_ostc_rx ; release reset
649 call wait_1s ; wait (up to) 1 second
650 call wait_1s ; wait (another full) 1 second
651 call wait_1s ; wait (another full) 1 second
652
653 call I2C_probe_OSTC_rx ; check if RX co-processor is alive, will set ostc_rx_present if so (1st try)
654 btfsc ostc_rx_present ; RX co-processor up & running?
655 return ; YES
656 call wait_1s ; NO - wait (up to) 1 second
657 call I2C_probe_OSTC_rx ; - give it a 2nd try
658 return ; - finally done (whatever result on 2nd tray)
659
660
587 ;============================================================================= 661 ;=============================================================================
588 662
589 ENDIF 663 ENDIF ; _rx_functions
590 664
591 END 665 END