comparison src/rx_ops.asm @ 628:cd58f7fc86db

3.05 stable work
author heinrichsweikamp
date Thu, 19 Sep 2019 12:01:29 +0200
parents c40025d8e750
children 185ba2f91f59
comparison
equal deleted inserted replaced
627:bf5fee575701 628:cd58f7fc86db
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File rx_ops.asm combined next generation V3.03.1 3 ; File rx_ops.asm combined next generation V3.03.7
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 ;=============================================================================
17 17
18 IFDEF _rx_functions 18 IFDEF _rx_functions
19 19
20 20
21 extern get_first_gas_to_WREG 21 extern get_first_gas_to_WREG
22 extern I2C_probe_OSTC_rx
23
24 IFDEF _rx_update
22 extern I2C_update_OSTC_rx 25 extern I2C_update_OSTC_rx
23 extern I2C_probe_OSTC_rx
24 extern rx_firmware_storage 26 extern rx_firmware_storage
27 ENDIF
25 28
26 IFDEF _ccr_pscr 29 IFDEF _ccr_pscr
27 extern get_first_dil_to_WREG 30 extern get_first_dil_to_WREG
28 ENDIF 31 ENDIF
29 32
269 ; Memory Map: 272 ; Memory Map:
270 ; ------------------------------------------------------------------------------------ 273 ; ------------------------------------------------------------------------------------
271 ; 274 ;
272 ; pres_accu_1st res 4 ; accumulator for pressure drop in 1/(160 * 2^16) bar 275 ; pres_accu_1st res 4 ; accumulator for pressure drop in 1/(160 * 2^16) bar
273 ; pres_accu_2nd res 4 ; accumulator for pressure drop in 1/(160 * 2^16) bar 276 ; pres_accu_2nd res 4 ; accumulator for pressure drop in 1/(160 * 2^16) bar
274 ; time_accu_1st res 1 ; accumulator for reading periods in seconds 277 ; time_accu_1st res 2 ; accumulator for reading periods in seconds
275 ; gas__last_1st res 1 ; last gas assignment 278 ; gas__last_1st res 1 ; last gas assignment
276 ; time_accu_2nd res 1 ; accumulator for reading periods in seconds 279 ; time_accu_2nd res 2 ; accumulator for reading periods in seconds
277 ; gas__last_2nd res 1 ; last gas assignment 280 ; gas__last_2nd res 1 ; last gas assignment
278 ; pres_last_1st res 2 ; last pressure reading pressure in 1/160 bar 281 ; pres_last_1st res 2 ; last pressure reading pressure in 1/160 bar
279 ; pres_last_2nd res 2 ; last pressure reading pressure in 1/160 bar 282 ; pres_last_2nd res 2 ; last pressure reading pressure in 1/160 bar
280 ; time_last_1st res 2 ; last pressure reading time in seconds 283 ; time_last_1st res 2 ; last pressure reading time in seconds
281 ; time_last_2nd res 2 ; last pressure reading time in seconds 284 ; time_last_2nd res 2 ; last pressure reading time in seconds
285 ; int_I_pressure_drop [1] res 2 ; calculated average pressure drop in 1/5120 bar/sec 288 ; int_I_pressure_drop [1] res 2 ; calculated average pressure drop in 1/5120 bar/sec
286 ; int_I_pressure_drop [2] res 2 ; calculated average pressure drop in 1/5120 bar/sec 289 ; int_I_pressure_drop [2] res 2 ; calculated average pressure drop in 1/5120 bar/sec
287 290
288 ; relative positioning of 16 bit ASM variables 291 ; relative positioning of 16 bit ASM variables
289 #DEFINE offset_FSR1_time_accu .0 ; offset 0 == base address of 1st/2nd 292 #DEFINE offset_FSR1_time_accu .0 ; offset 0 == base address of 1st/2nd
290 #DEFINE offset_FSR1_gas__last .1 ; offset 1 to base address of 1st/2nd 293 #DEFINE offset_FSR1_gas__last .2 ; offset 1 to base address of 1st/2nd
291 #DEFINE offset_FSR1_pres_last .4 ; offset 4 ... 294 #DEFINE offset_FSR1_pres_last .6 ; offset 6 ...
292 #DEFINE offset_FSR1_time_last .8 ; offset 8 ... 295 #DEFINE offset_FSR1_time_last .10 ; offset 10 ...
293 296
294 ; relative positioning of shared integer variables 297 ; relative positioning of shared integer variables
295 #DEFINE offset_FSR2_press_curr .0 ; offset 0 == base address of 1st/2nd 298 #DEFINE offset_FSR2_press_curr .0 ; offset 0 == base address of 1st/2nd
296 #DEFINE offset_FSR2_press_drop .4 ; offset 4 to base address of 1st/2nd 299 #DEFINE offset_FSR2_press_drop .4 ; offset 4 to base address of 1st/2nd
297 300
298 301
299 calc_pres_drop_1st: 302 calc_pres_drop_1st:
300 ; set up base addresses 303 ; set up base addresses
301 lfsr FSR0,pres_accu_1st-1 ; load base address - 1 of pressure accumulator 304 lfsr FSR0,pres_accu_1st ; load base address of pressure accumulator
302 lfsr FSR1,time_accu_1st ; load base address of other ASM variables 305 lfsr FSR1,time_accu_1st ; load base address of other ASM variables
303 lfsr FSR2,int_IO_pressure_value+0; load base address of the shared variables 306 lfsr FSR2,int_IO_pressure_value+0; load base address of the shared variables
304 307
305 ; get the currently assigned gas into lo 308 ; get the currently assigned gas into lo
306 movff char_I_pressure_gas+0,lo 309 movff char_I_pressure_gas+0,lo
307 310
308 ; get the age of the current reading into hi 311 ; get the age of the current reading into hi
322 325
323 ; get the age of the current reading into hi 326 ; get the age of the current reading into hi
324 movff char_I_pressure_age+1,hi 327 movff char_I_pressure_age+1,hi
325 328
326 calc_pres_drop_common: 329 calc_pres_drop_common:
327 ; load the pressure accumulator into xC - FSR0 has been initialized to base address -1 330 ; load the pressure accumulator into xC - after copying, FSR0 stays on highest byte
328 movff PREINC0,xC+0 ; copy pressure accumulator to xC, lowest byte 331 movff POSTINC0,xC+0 ; copy pressure accumulator to xC, lowest byte
329 movff PREINC0,xC+1 ; copy pressure accumulator to xC, second byte 332 movff POSTINC0,xC+1 ; copy pressure accumulator to xC, second byte
330 movff PREINC0,xC+2 ; copy pressure accumulator to xC, third byte 333 movff POSTINC0,xC+2 ; copy pressure accumulator to xC, third byte
331 movff PREINC0,xC+3 ; copy pressure accumulator to xC, highest byte 334 movff INDF0, xC+3 ; copy pressure accumulator to xC, highest byte
332 335
333 ; check if the assigned gas has changed 336 ; check if the assigned gas has changed
334 movlw offset_FSR1_gas__last ; load index of last assigned gas 337 movlw offset_FSR1_gas__last ; load index of last assigned gas
335 movf PLUSW1,W ; copy last gas to WREG 338 movf PLUSW1,W ; copy last gas to WREG
336 cpfseq lo ; is current gas = last gas ? 339 cpfseq lo ; is current gas = last gas ?
340 tstfsz lo ; is there no gas (0=off) assigned to the reading? 343 tstfsz lo ; is there no gas (0=off) assigned to the reading?
341 bra calc_pres_drop_common_1 ; NO - continue 344 bra calc_pres_drop_common_1 ; NO - continue
342 bra calc_pres_drop_reset ; YES - reset everything 345 bra calc_pres_drop_reset ; YES - reset everything
343 346
344 calc_pres_drop_common_1: 347 calc_pres_drop_common_1:
345 ; load the time accumulator into xB 348 ; load the time accumulator into xB - after copying, FSR1 will have been restored to initial address
346 movff INDF1,xB+0 ; load time accumulator, low byte (had been stored) 349 movff POSTINC1,xB+0 ; load time accumulator, low byte
347 clrf xB+1 ; clear time accumulator, high byte (will be reset to 0 each round) 350 movff POSTDEC1,xB+1 ; load time accumulator, high byte
348 351
349 ; get the current pressure value into divA - after copying, FSR2 will have been restored to initial address 352 ; get the current pressure value into divA - after copying, FSR2 will have been restored to initial address
350 movff POSTINC2,divA+0 ; copy current pressure value to divA, low byte 353 movff POSTINC2,divA+0 ; copy current pressure value to divA, low byte
351 movff POSTDEC2,divA+1 ; copy current pressure value to divA, high byte 354 movff POSTDEC2,divA+1 ; copy current pressure value to divA, high byte
352 355
410 ; add the current time to the time accumulator: time_accu (xB) += time_curr (mpr) 413 ; add the current time to the time accumulator: time_accu (xB) += time_curr (mpr)
411 movf lo,W ; copy time_curr (mpr) to WREG, low byte 414 movf lo,W ; copy time_curr (mpr) to WREG, low byte
412 addwf xB+0,F ; add to time_accu (xB), low byte 415 addwf xB+0,F ; add to time_accu (xB), low byte
413 movf hi,W ; copy time_curr (mpr) to WREG, high byte 416 movf hi,W ; copy time_curr (mpr) to WREG, high byte
414 addwfc xB+1,F ; add to time_accu (xB), high_byte 417 addwfc xB+1,F ; add to time_accu (xB), high_byte
418 btfsc STATUS,C ; did the accumulator over-run ?
419 bra calc_pres_drop_restart ; YES - reset both accumulators and set average pressure drop to not available
415 420
416 ; subtract the last pressure time from time accumulator: time_accu (xB) -= time_last (sub_b) 421 ; subtract the last pressure time from time accumulator: time_accu (xB) -= time_last (sub_b)
417 movf sub_b+0,W ; copy time_last (sub_b) to WREG, low byte 422 movf sub_b+0,W ; copy time_last (sub_b) to WREG, low byte
418 subwf xB+0,F ; subtract from time_accu (xB), low byte 423 subwf xB+0,F ; subtract from time_accu (xB), low byte
419 movf sub_b+1,W ; copy time_last (sub_b) to WREG, high byte 424 movf sub_b+1,W ; copy time_last (sub_b) to WREG, high byte
420 subwfb xB+1,F ; subtract from time_accu (xB), high byte 425 subwfb xB+1,F ; subtract from time_accu (xB), high byte
421 btfss STATUS,C ; did the accumulator under-run (result negative) because of a wrap-around of the current time? 426 btfss STATUS,C ; did the accumulator under-run (result negative) because of a wrap-around of the current time?
422 bra calc_pres_drop_restart ; YES - reset both accumulators and set average pressure drop to not available 427 bra calc_pres_drop_restart ; YES - reset both accumulators and set average pressure drop to not available
423 428
424 ; check if the time accumulator (xB) is or has become too large
425 ; this will happen if the last valid pressure reading is older than (256 - time_accu target) seconds
426 tstfsz xB+1 ; is the time accumulator < 256 [seconds], i.e. high byte = 0 ?
427 bra calc_pres_drop_restart ; NO - reset both accumulators and set average pressure drop to not available
428
429 calc_pres_drop_common_2: 429 calc_pres_drop_common_2:
430 ; check if the time accumulator is or has become zero to avoid a div/0 430 ; check if the time accumulator is or has become zero to avoid a div/0
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 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
432 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
433 iorwf xB+1,W ; inclusive-or time accumulator high byte into WREG, is result = zero ?
433 bz calc_pres_drop_restart ; YES - reset both accumulators and set average pressure drop to not available 434 bz calc_pres_drop_restart ; YES - reset both accumulators and set average pressure drop to not available
434 435
435 ; duplicate pressure and time accumulators to other variables because xC and xB will get destroyed in div32x16 operation 436 ; duplicate pressure and time accumulators to other variables because xC and xB will get destroyed in div32x16 operation
436 movff xC+0,mpr+0 ; duplicate pres_accu to mpr, lowest byte 437 movff xC+0,mpr+0 ; duplicate pres_accu to mpr, lowest byte
437 movff xC+1,mpr+1 ; duplicate pres_accu to mpr, second byte 438 movff xC+1,mpr+1 ; duplicate pres_accu to mpr, second byte
442 443
443 ; calculate average pressure drop: pres_drop (xC) = pres_accu (xC) / time_accu (xB) 444 ; calculate average pressure drop: pres_drop (xC) = pres_accu (xC) / time_accu (xB)
444 call div32x16 ; xC = xC / xB, xC is average pressure drop in 1/(160 * 2^16) bar/sec 445 call div32x16 ; xC = xC / xB, xC is average pressure drop in 1/(160 * 2^16) bar/sec
445 446
446 ; is the time accumulator above target level? (only the low byte needs to be evaluated)? 447 ; is the time accumulator above target level? (only the low byte needs to be evaluated)?
447 incf ul,W ; load the target threshold, +1 (incf) transforms cpfslt from < to <= operation 448 tstfsz divA+1 ; is the time accumulator > 255 seconds?
448 cpfslt divA+0 ; is the time accumulator > target threshold ? 449 bra calc_pres_drop_common_2a ; YES - do an accumulator reduction
449 rcall calc_pres_drop_reduce_accus ; YES - do an accumulator reduction 450 incf ul,W ; NO - load the target threshold, +1 (incf) transforms cpfslt from < to <= operation
451 cpfslt divA+0 ; - is the time accumulator > target threshold ?
452 calc_pres_drop_common_2a:
453 rcall calc_pres_drop_reduce_accus ; YES - do an accumulator reduction
450 454
451 ; do an additional half-rate (every 2nd second) accumulator reduction 455 ; do an additional half-rate (every 2nd second) accumulator reduction
452 btfsc timebase_1sec ; are we on an even second? 456 btfsc timebase_1sec ; are we on an even second?
453 rcall calc_pres_drop_reduce_accus ; YES - do an additional accumulator reduction 457 rcall calc_pres_drop_reduce_accus ; YES - do an additional accumulator reduction
454 458
455 ; store pressure accumulator (mpr:4) - FSR0 was left pointing to address of highest byte 459 ; store pressure accumulator (mpr:4) - FSR0 was left pointing to address of highest byte
456 movff mpr+3,POSTDEC0 ; store pressure accumulator, highest byte 460 movff mpr+3,POSTDEC0 ; store pressure accumulator, highest byte
457 movff mpr+2,POSTDEC0 ; store pressure accumulator, third byte 461 movff mpr+2,POSTDEC0 ; store pressure accumulator, third byte
458 movff mpr+1,POSTDEC0 ; store pressure accumulator, second byte 462 movff mpr+1,POSTDEC0 ; store pressure accumulator, second byte
459 movff mpr+0,POSTDEC0 ; store pressure accumulator, lowest byte 463 movff mpr+0,INDF0 ; store pressure accumulator, lowest byte
460 464
461 ; store the time accumulator 465 ; store the time accumulator - after copying, FSR1 will have been restored to initial address
462 movff divA+0,INDF1 ; store time accumulator (only the low byte will be stored) 466 movff divA+0,POSTINC1 ; store time accumulator, low byte
467 movff divA+1,POSTDEC1 ; store time accumulator, high byte
463 468
464 ; check if the average pressure drop for transfer to p2deco needs to be limited 469 ; check if the average pressure drop for transfer to p2deco needs to be limited
465 tstfsz xC+3 ; check if the highest byte is all zero 470 tstfsz xC+3 ; check if the highest byte is all zero
466 bra calc_pres_drop_limit ; NO - limit output 471 bra calc_pres_drop_limit ; NO - limit output
467 btfsc xC+2,7 ; check if the highest bit of the third byte is zero 472 btfsc xC+2,7 ; check if the highest bit of the third byte is zero
483 ; set the average pressure drop as not available if the last pressure reading is outdated or not available 488 ; set the average pressure drop as not available if the last pressure reading is outdated or not available
484 btfsc aux_flag ; is the last pressure reading outdated or not available? 489 btfsc aux_flag ; is the last pressure reading outdated or not available?
485 bsf divA+1,int_not_avail_flag ; YES - set pressure drop to not available, too 490 bsf divA+1,int_not_avail_flag ; YES - set pressure drop to not available, too
486 491
487 ; set the average pressure drop as outdated if time_accu (divA) < (target threshold / 2) 492 ; set the average pressure drop as outdated if time_accu (divA) < (target threshold / 2)
488 rrncf ul,W ; load time accumulator target value / 2 into WREG 493 movlw offset_FSR1_time_accu+1 ; address high byte of time accumulator
489 decf WREG,W ; subtract 1 to transform cpfsgt from > to >= operation 494 tstfsz PLUSW1 ; time accumulator > 255 ?
495 bra calc_pres_drop_common_3a ; YES - can not be outdated then
496 rrncf ul,W ; NO - load time accumulator target value / 2 into WREG
497 decf WREG,W ; subtract 1 to transform cpfsgt from > into >= operation
490 cpfsgt INDF1 ; time accumulator < (target threshold / 2) ? 498 cpfsgt INDF1 ; time accumulator < (target threshold / 2) ?
491 bsf divA+1,int_outdated_flag ; YES - set outdated flag 499 bsf divA+1,int_outdated_flag ; YES - set outdated flag
492 500
501 calc_pres_drop_common_3a:
493 ; write average pressure drop to p2deco interface 502 ; write average pressure drop to p2deco interface
494 movlw offset_FSR2_press_drop+0 ; load index of average pressure drop, low byte 503 movlw offset_FSR2_press_drop+0 ; load index of average pressure drop, low byte
495 movff divA+0,PLUSW2 ; store average pressure drop, low byte 504 movff divA+0,PLUSW2 ; store average pressure drop, low byte
496 movlw offset_FSR2_press_drop+1 ; load index of average pressure drop, high byte 505 movlw offset_FSR2_press_drop+1 ; load index of average pressure drop, high byte
497 movff divA+1,PLUSW2 ; store average pressure drop, high byte 506 movff divA+1,PLUSW2 ; store average pressure drop, high byte
543 clrf POSTDEC0 ; clear pressure accumulator, highest byte 552 clrf POSTDEC0 ; clear pressure accumulator, highest byte
544 clrf POSTDEC0 ; clear pressure accumulator, third byte 553 clrf POSTDEC0 ; clear pressure accumulator, third byte
545 clrf POSTDEC0 ; clear pressure accumulator, second byte 554 clrf POSTDEC0 ; clear pressure accumulator, second byte
546 clrf POSTDEC0 ; clear pressure accumulator, lowest byte 555 clrf POSTDEC0 ; clear pressure accumulator, lowest byte
547 556
548 ; clear time accumulator 557 ; clear time accumulator - after clearing, FSR1 will have been restored to initial address
549 clrf INDF1 ; clear time accumulator 558 clrf POSTINC1 ; clear time accumulator, low byte
559 clrf POSTDEC1 ; clear time accumulator, high byte
550 560
551 ; clear pressure drop and set it to not available 561 ; clear pressure drop and set it to not available
552 movlw offset_FSR2_press_drop+0 ; load index of average pressure drop, low byte 562 movlw offset_FSR2_press_drop+0 ; load index of average pressure drop, low byte
553 clrf PLUSW2 ; clear average pressure drop, low byte 563 clrf PLUSW2 ; clear average pressure drop, low byte
554 movlw offset_FSR2_press_drop+1 ; load index of average pressure drop, high byte 564 movlw offset_FSR2_press_drop+1 ; load index of average pressure drop, high byte
603 613
604 614
605 ;----------------------------------------------------------------------------- 615 ;-----------------------------------------------------------------------------
606 ; Update TR module 616 ; Update TR module
607 ; 617 ;
618
619 IFDEF _rx_update
620
608 global update_tr_module 621 global update_tr_module
609 update_tr_module: 622 update_tr_module:
610 movlw LOW rx_firmware_storage ; setup program memory read for embedded TR firmware 623 movlw LOW rx_firmware_storage ; setup program memory read for embedded TR firmware
611 movwf TBLPTRL 624 movwf TBLPTRL
612 movlw HIGH rx_firmware_storage 625 movlw HIGH rx_firmware_storage
655 return ; YES 668 return ; YES
656 call wait_1s ; NO - wait (up to) 1 second 669 call wait_1s ; NO - wait (up to) 1 second
657 call I2C_probe_OSTC_rx ; - give it a 2nd try 670 call I2C_probe_OSTC_rx ; - give it a 2nd try
658 return ; - finally done (whatever result on 2nd tray) 671 return ; - finally done (whatever result on 2nd tray)
659 672
673 ENDIF ; _rx_update
660 674
661 ;============================================================================= 675 ;=============================================================================
662 676
663 ENDIF ; _rx_functions 677 ENDIF ; _rx_functions
664 678