avr: more code sharing.

This commit is contained in:
Martin Preuss
2026-08-07 00:42:45 +02:00
parent 44044e9bba
commit 7bae2072aa
3 changed files with 145 additions and 98 deletions

View File

@@ -82,54 +82,13 @@ AppReportSensors_OnEverySecond_store:
appReportSensorsWalkTable: appReportSensorsWalkTable:
ldi zl, LOW(appReportSensorsTable*2) ldi zl, LOW(appReportSensorsTable*2)
ldi zh, HIGH(appReportSensorsTable*2) ldi zh, HIGH(appReportSensorsTable*2)
lds r22, reportSensorTimer lds r16, reportSensorTimer
appReportSensorsWalkTable_loop: bigcall WalkTable
lpm r16, Z+
adiw zh:zl, 1
lpm r18, Z+
lpm r19, Z+
mov r17, r18 ; routine==0?
or r17, r19
breq appReportSensorsWalkTable_loopEnd ; yes, end of table
tst r16 ; timer==0?
breq appReportSensorsWalkTable_loopCall ; yes, match any value
cp r22, r16
brne appReportSensorsWalkTable_loopNext ; skip
appReportSensorsWalkTable_loopCall:
push r22
push zl
push zh
push yl
push yh
rcall appReportSensorsCallR19R18
pop yh
pop yl
pop zh
pop zl
pop r22
appReportSensorsWalkTable_loopNext:
rjmp appReportSensorsWalkTable_loop
appReportSensorsWalkTable_loopEnd:
ret ret
; @end ; @end
; ---------------------------------------------------------------------------
; @routine appReportSensorsCallR19R18
; Call route at address r19:r18
appReportSensorsCallR19R18:
push r18
push r19
ret
; @end
#ifdef MODULES_SI7021 #ifdef MODULES_SI7021
appReportSensorsSi7021MeasureValue1: appReportSensorsSi7021MeasureValue1:
rjmp SI7021_MeasureTemp rjmp SI7021_MeasureTemp

View File

@@ -71,55 +71,34 @@ AppStats_OnEveryMinute_noIrq:
AppStats_OnEveryMinute_store: AppStats_OnEveryMinute_store:
sts appStatsTimer, r16 sts appStatsTimer, r16
mov r17, r16 rcall appStatsWalkTable
andi r17, 3
brne AppStats_OnEveryMinute_sendStats
; send device announcement
push r16
push yl
push yh
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
rcall AppNetwork_SendDevice
#ifdef APP_STATS_NETDEV2
ldi yl, LOW(netInterfaceData2)
ldi yh, HIGH(netInterfaceData2)
rcall AppNetwork_SendDevice
#endif
pop yh
pop yl
pop r16
AppStats_OnEveryMinute_sendStats:
#if 1
; debug
push r16
push yl
push yh
rcall AppStats_OnEveryMinute_sendMemStats
pop yh
pop yl
pop r16
#else
cpi r16, 2
breq AppStats_OnEveryMinute_sendMemStats
#endif
cpi r16, 3
breq AppStats_OnEveryMinute_sendRecvStats1
cpi r16, 5
breq AppStats_OnEveryMinute_sendSendStats1
#ifdef APP_STATS_NETDEV2
cpi r16, 6
breq AppStats_OnEveryMinute_sendRecvStats2
cpi r16, 7
breq AppStats_OnEveryMinute_sendSendStats2
#endif
; add more here ; add more here
ret ret
; @end
; ---------------------------------------------------------------------------
; @routine appStatsTable
;
; @clobbers r16, r18, r19, r22, Z, (any)
appStatsWalkTable:
ldi zl, LOW(appStatsTable*2)
ldi zh, HIGH(appStatsTable*2)
lds r16, appStatsTimer
bigcall WalkTable
ret
; @end
AppStats_OnEveryMinute_sendDeviceDev1:
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
rjmp AppNetwork_SendDevice
AppStats_OnEveryMinute_sendMemStats: AppStats_OnEveryMinute_sendMemStats:
ldi yl, LOW(netInterfaceData) ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData) ldi yh, HIGH(netInterfaceData)
@@ -135,19 +114,46 @@ AppStats_OnEveryMinute_sendSendStats1:
ldi yh, HIGH(netInterfaceData) ldi yh, HIGH(netInterfaceData)
rjmp AppNetwork_SendTxdStats rjmp AppNetwork_SendTxdStats
#ifdef APP_STATS_NETDEV2
AppStats_OnEveryMinute_sendRecvStats2:
ldi yl, LOW(netInterfaceData2)
ldi yh, HIGH(netInterfaceData2)
rjmp AppNetwork_SendRxdStats
AppStats_OnEveryMinute_sendSendStats2: #ifdef APP_STATS_NETDEV2
ldi yl, LOW(netInterfaceData2) AppStats_OnEveryMinute_sendDeviceDev2:
ldi yh, HIGH(netInterfaceData2) ldi yl, LOW(netInterfaceData2)
rjmp AppNetwork_SendTxdStats ldi yh, HIGH(netInterfaceData2)
rjmp AppNetwork_SendDevice
AppStats_OnEveryMinute_sendRecvStats2:
ldi yl, LOW(netInterfaceData2)
ldi yh, HIGH(netInterfaceData2)
rjmp AppNetwork_SendRxdStats
AppStats_OnEveryMinute_sendSendStats2:
ldi yl, LOW(netInterfaceData2)
ldi yh, HIGH(netInterfaceData2)
rjmp AppNetwork_SendTxdStats
#endif #endif
; @end ; @end
; ---------------------------------------------------------------------------
; table
; time routine (word address)
appStatsTable:
.dw 1, AppStats_OnEveryMinute_sendMemStats
.dw 2, AppStats_OnEveryMinute_sendDeviceDev1
.dw 3, AppStats_OnEveryMinute_sendRecvStats1
.dw 4, AppStats_OnEveryMinute_sendSendStats1
.dw 5, AppStats_OnEveryMinute_sendDeviceDev1
#ifdef APP_STATS_NETDEV2
.dw 6, AppStats_OnEveryMinute_sendDeviceDev2
.dw 7, AppStats_OnEveryMinute_sendRecvStats2
.dw 8, AppStats_OnEveryMinute_sendSendStats2
#endif
; end of table
.dw 0, 0

82
avr/common/walktable.asm Normal file
View File

@@ -0,0 +1,82 @@
; ***************************************************************************
; copyright : (C) 2026 by Martin Preuss
; email : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome". *
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
#ifndef AQH_AVR_COMMON_WALKTABLE_ASM
#define AQH_AVR_COMMON_WALKTABLE_ASM
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine WalkTable
;
; Walks a given table and calls every routine whose table entry
; holds a value equal to the given one.
;
; The loop uses r16-r19 and Z.
;
; @param Z byte pointer to table (for LPM!)
; @param r16 value
; @clobbers (any)
WalkTable:
mov r22, r16
WalkTable_loop:
lpm r16, Z+
adiw zh:zl, 1
lpm r18, Z+
lpm r19, Z+
mov r17, r18 ; routine==0?
or r17, r19
breq WalkTable_loopEnd ; yes, end of table
tst r16 ; timer==0?
breq WalkTable_loopCall ; yes, match any value
cp r22, r16
brne WalkTable_loopNext ; skip
WalkTable_loopCall:
push r22
push zl
push zh
push yl
push yh
rcall walkTableCallR19R18
pop yh
pop yl
pop zh
pop zl
pop r22
WalkTable_loopNext:
rjmp WalkTable_loop
WalkTable_loopEnd:
ret
; @end
; ---------------------------------------------------------------------------
; @routine walkTableCallR19R18
; Call route at address r19:r18
walkTableCallR19R18:
push r18
push r19
ret
; @end
#endif