introduce macros bigjmp and bigcall for intermodule calls/jmps

translates to rjmp/rcall on MCUs with up to 8K flash and to jmp/call
on others.
This commit is contained in:
Martin Preuss
2025-06-01 19:18:25 +02:00
parent 188e7da379
commit bb14dd4c22
11 changed files with 128 additions and 96 deletions

View File

@@ -164,7 +164,7 @@ appNetworkHandleRebootRequest:
brcc appNetworkHandleRebootRequest_end brcc appNetworkHandleRebootRequest_end
; reboot ; reboot
cli cli
rjmp BOOTLOADER_ADDR bigjmp BOOTLOADER_ADDR
appNetworkHandleRebootRequest_end: appNetworkHandleRebootRequest_end:
ret ret
; @end ; @end
@@ -249,7 +249,7 @@ appNetworkHandleStateHaveAddress2:
cli cli
ldi xl, LOW(EEPROM_OFFS_COMADDR) ldi xl, LOW(EEPROM_OFFS_COMADDR)
ldi xh, HIGH(EEPROM_OFFS_COMADDR) ldi xh, HIGH(EEPROM_OFFS_COMADDR)
rcall Utils_WriteEepromIncr ; write address to EEPROM bigcall Utils_WriteEepromIncr ; write address to EEPROM
out SREG, r15 out SREG, r15
pop r15 pop r15
appNetworkHandleStateHaveAddress2_end: appNetworkHandleStateHaveAddress2_end:
@@ -451,7 +451,7 @@ appNetworkGetAddressFromEeprom:
cli cli
ldi xl, LOW(EEPROM_OFFS_COMADDR) ldi xl, LOW(EEPROM_OFFS_COMADDR)
ldi xh, HIGH(EEPROM_OFFS_COMADDR) ldi xh, HIGH(EEPROM_OFFS_COMADDR)
rcall Utils_ReadEepromIncr ; (R16) bigcall Utils_ReadEepromIncr ; (R16)
out SREG, r15 out SREG, r15
pop r15 pop r15
ret ret

View File

@@ -162,7 +162,7 @@ appStatsSend16BitValue:
ldi r20, 1 ldi r20, 1
clr r21 clr r21
ldi r22, AQHOME_VALUETYPE_STATS ldi r22, AQHOME_VALUETYPE_STATS
rjmp Main_SendValueReport bigjmp Main_SendValueReport
; @end ; @end

30
avr/common/calls.asm Normal file
View File

@@ -0,0 +1,30 @@
; ***************************************************************************
; copyright : (C) 2025 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. *
; ***************************************************************************
.macro bigcall
.if FLASHEND >= 0x1000
call @0
.else
rcall @0
.endif
.endmacro
.macro bigjmp
.if FLASHEND >= 0x1000
jmp @0
.else
rjmp @0
.endif
.endmacro

View File

@@ -74,7 +74,7 @@ waitFor10ms:
ldi r22, 100 ldi r22, 100
waitFor10ms_loop: waitFor10ms_loop:
push r22 push r22
rcall Utils_WaitFor100MicroSecs bigcall Utils_WaitFor100MicroSecs
pop r22 pop r22
dec r22 dec r22
brne waitFor10ms_loop brne waitFor10ms_loop

View File

@@ -26,27 +26,27 @@ initApps:
#ifdef APPS_NETWORK #ifdef APPS_NETWORK
ldi yl, LOW(netInterfaceData) ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData) ldi yh, HIGH(netInterfaceData)
rcall AppNetwork_Init bigcall AppNetwork_Init
#endif #endif
#ifdef APPS_MOTION #ifdef APPS_MOTION
rcall AppMotion_Init bigcall AppMotion_Init
#endif #endif
#ifdef APPS_DOOR #ifdef APPS_DOOR
rcall AppDoor_Init bigcall AppDoor_Init
#endif #endif
#ifdef APPS_REPORTSENSORS #ifdef APPS_REPORTSENSORS
rcall AppReportSensors_Init bigcall AppReportSensors_Init
#endif #endif
#ifdef APPS_STATS #ifdef APPS_STATS
rcall AppStats_Init bigcall AppStats_Init
#endif #endif
#ifdef APPS_MA_LIGHT #ifdef APPS_MA_LIGHT
rcall AppMotionLight_Init bigcall AppMotionLight_Init
#endif #endif
; done ; done
@@ -78,11 +78,11 @@ mainAppsOnPacketReceived:
; handle messages ; handle messages
ldi yl, LOW(netInterfaceData) ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData) ldi yh, HIGH(netInterfaceData)
rcall AppNetwork_HandleMsg bigcall AppNetwork_HandleMsg
#endif #endif
#ifdef APPS_MA_LIGHT #ifdef APPS_MA_LIGHT
rcall AppMotionLight_OnPacketReceived bigcall AppMotionLight_OnPacketReceived
#endif #endif
; add more here ; add more here

View File

@@ -8,6 +8,7 @@
; *************************************************************************** ; ***************************************************************************
; *************************************************************************** ; ***************************************************************************
; code ; code
@@ -31,16 +32,16 @@ main:
; rcall watchdogOff ; turn off watchdog timer (sometimes it stays on after reboot) ; rcall watchdogOff ; turn off watchdog timer (sometimes it stays on after reboot)
rcall systemSetSpeed bigcall systemSetSpeed
rcall systemInitHardware bigcall systemInitHardware
rcall Utils_Init bigcall Utils_Init
rcall Utils_SetupUid bigcall Utils_SetupUid
rcall initModules bigcall initModules
rcall initApps bigcall initApps
rcall Utils_InitialWait bigcall Utils_InitialWait
sei ; Enable interrupts sei ; Enable interrupts
rcall onSystemStart bigcall onSystemStart
#ifdef MODULES_LED #ifdef MODULES_LED
ldi xl, LOW(blinkPattern) ; debug: set blink pattern ldi xl, LOW(blinkPattern) ; debug: set blink pattern
@@ -53,11 +54,11 @@ main:
#endif #endif
main_loop: main_loop:
rcall systemSleep ; system-dependant bigcall systemSleep ; system-dependant
rcall runModules bigcall runModules
rcall runApps bigcall runApps
rcall onEveryLoop ; call into main app bigcall onEveryLoop ; call into main app
#ifdef MODULES_NETWORK #ifdef MODULES_NETWORK
#ifndef MAIN_WITHOUT_MSG_HANDLING #ifndef MAIN_WITHOUT_MSG_HANDLING
@@ -69,7 +70,7 @@ main_loop:
main_loop_reboot: main_loop_reboot:
cli cli
rjmp BOOTLOADER_ADDR bigjmp BOOTLOADER_ADDR
; @end ; @end
@@ -80,53 +81,53 @@ main_loop_reboot:
; Called every 100ms. No arguments, no results. ; Called every 100ms. No arguments, no results.
onSystemTimerTick: onSystemTimerTick:
rcall onEvery100ms bigcall onEvery100ms
#ifdef MODULES_CLOCK #ifdef MODULES_CLOCK
rcall Clock_Every100ms ; generates calls to onEverySecond/Minute/Hour/Day bigcall Clock_Every100ms ; generates calls to onEverySecond/Minute/Hour/Day
#endif #endif
#ifdef MODULES_LED_SIMPLE #ifdef MODULES_LED_SIMPLE
rcall LedSimple_Every100ms bigcall LedSimple_Every100ms
#endif #endif
#ifdef MODULES_UART_BITBANG #ifdef MODULES_UART_BITBANG
rcall UART_BitBang_Every100ms bigcall UART_BitBang_Every100ms
#endif #endif
#ifdef MODULES_UART_HW #ifdef MODULES_UART_HW
rcall NET_Uart_Every100ms bigcall NET_Uart_Every100ms
#endif #endif
#ifdef MODULES_TTYONUART1 #ifdef MODULES_TTYONUART1
rcall TtyOnUart1_Periodically bigcall TtyOnUart1_Periodically
#endif #endif
#ifdef MODULES_COMONUART0 #ifdef MODULES_COMONUART0
rcall ComOnUart0_Periodically bigcall ComOnUart0_Periodically
#endif #endif
#ifdef MODULES_TCRT1000 #ifdef MODULES_TCRT1000
rcall TCRT1K_Every100ms bigcall TCRT1K_Every100ms
#endif #endif
#ifdef APPS_NETWORK #ifdef APPS_NETWORK
ldi yl, LOW(netInterfaceData) ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData) ldi yh, HIGH(netInterfaceData)
rcall AppNetwork_Every100ms bigcall AppNetwork_Every100ms
#endif #endif
#ifdef APPS_MOTION #ifdef APPS_MOTION
rcall AppMotion_Every100ms bigcall AppMotion_Every100ms
#endif #endif
#ifdef APPS_DOOR #ifdef APPS_DOOR
rcall AppDoor_Every100ms bigcall AppDoor_Every100ms
#endif #endif
#ifdef APPS_MA_LIGHT #ifdef APPS_MA_LIGHT
rcall AppMotionLight_Every100ms bigcall AppMotionLight_Every100ms
#endif #endif
ret ret
@@ -138,32 +139,32 @@ onSystemTimerTick:
sysOnEverySecond: sysOnEverySecond:
#ifdef MODULES_DS18B20 #ifdef MODULES_DS18B20
rcall Ds18b20_OnEverySecond bigcall Ds18b20_OnEverySecond
#endif #endif
#ifdef APPS_REPORTSENSORS #ifdef APPS_REPORTSENSORS
rcall AppReportSensors_OnEverySecond bigcall AppReportSensors_OnEverySecond
#endif #endif
rjmp onEverySecond bigjmp onEverySecond
; @end ; @end
sysOnEveryMinute: sysOnEveryMinute:
#ifdef APPS_STATS #ifdef APPS_STATS
rcall AppStats_OnEveryMinute bigcall AppStats_OnEveryMinute
#endif #endif
rjmp onEveryMinute bigjmp onEveryMinute
; @end ; @end
sysOnEveryHour: sysOnEveryHour:
rjmp onEveryHour bigjmp onEveryHour
; @end ; @end
sysOnEveryDay: sysOnEveryDay:
rjmp onEveryDay bigjmp onEveryDay
; @end ; @end
#endif #endif
@@ -175,17 +176,17 @@ sysOnEveryDay:
; @routine mainHandleMessages ; @routine mainHandleMessages
mainHandleMessages: mainHandleMessages:
rcall NET_GetNextIncomingMsgNum ; R16=msg num bigcall NET_GetNextIncomingMsgNum ; R16=msg num
brcc mainHandleMessages_end brcc mainHandleMessages_end
rcall NET_Buffer_Locate ; X=buffer addr (R17) bigcall NET_Buffer_Locate ; X=buffer addr (R17)
adiw xh:xl, 1 adiw xh:xl, 1
push r16 push r16
rcall onMessageReceived bigcall onMessageReceived
rcall mainModulesOnPacketReceived bigcall mainModulesOnPacketReceived
rcall mainAppsOnPacketReceived bigcall mainAppsOnPacketReceived
pop r16 pop r16
rcall NET_Buffer_ReleaseByNum bigcall NET_Buffer_ReleaseByNum
sec sec
mainHandleMessages_end: mainHandleMessages_end:
ret ret

View File

@@ -22,22 +22,22 @@
; Call init functions of the used modules. Add your routine calls here. ; Call init functions of the used modules. Add your routine calls here.
initModules: initModules:
rcall BaseTimer_Init ; unconditionally call this bigcall BaseTimer_Init ; unconditionally call this
#ifdef MODULES_HEAP #ifdef MODULES_HEAP
rcall Heap_Init bigcall Heap_Init
#endif #endif
#ifdef MODULES_CLOCK #ifdef MODULES_CLOCK
rcall Clock_Init bigcall Clock_Init
#endif #endif
#ifdef MODULES_TIMER #ifdef MODULES_TIMER
rcall Timer_Init bigcall Timer_Init
#endif #endif
#ifdef MODULES_XRAM #ifdef MODULES_XRAM
rcall XRAM_Init bigcall XRAM_Init
#endif #endif
#ifdef MODULES_LED #ifdef MODULES_LED
@@ -45,107 +45,107 @@ initModules:
ldi zh, HIGH(ledA3Flash) ldi zh, HIGH(ledA3Flash)
ldi yl, LOW(ledA3Sram) ldi yl, LOW(ledA3Sram)
ldi yh, HIGH(ledA3Sram) ldi yh, HIGH(ledA3Sram)
rcall Led_Init bigcall Led_Init
#endif #endif
#ifdef MODULES_LED_SIMPLE #ifdef MODULES_LED_SIMPLE
rcall LedSimple_Init bigcall LedSimple_Init
#endif #endif
#ifdef MODULES_COM #ifdef MODULES_COM
rcall Com2_Init ; init COM module bigcall Com2_Init ; init COM module
rcall CPRO_Init ; init COM protocol module bigcall CPRO_Init ; init COM protocol module
#endif #endif
#ifdef MODULES_NETWORK #ifdef MODULES_NETWORK
rcall NET_Init bigcall NET_Init
#endif #endif
#ifdef MODULES_UART_BITBANG #ifdef MODULES_UART_BITBANG
rcall UART_BitBang_Init bigcall UART_BitBang_Init
#endif #endif
#ifdef MODULES_UART_HW #ifdef MODULES_UART_HW
rcall NET_Uart_Init bigcall NET_Uart_Init
#endif #endif
#ifdef MODULES_TTYONUART1 #ifdef MODULES_TTYONUART1
rcall TtyOnUart1_Init bigcall TtyOnUart1_Init
#endif #endif
#ifdef MODULES_COMONUART0 #ifdef MODULES_COMONUART0
rcall ComOnUart0_Init bigcall ComOnUart0_Init
#endif #endif
#ifdef MODULES_MOTION #ifdef MODULES_MOTION
rcall Motion_Init bigcall Motion_Init
#endif #endif
#ifdef MODULES_TWI_MASTER #ifdef MODULES_TWI_MASTER
rcall TWI_Master_Init bigcall TWI_Master_Init
#endif #endif
#ifdef MODULES_OWI_MASTER #ifdef MODULES_OWI_MASTER
rcall OwiMaster_Init bigcall OwiMaster_Init
#endif #endif
#ifdef MODULES_SPI_HW #ifdef MODULES_SPI_HW
rcall SPIHW_Init bigcall SPIHW_Init
#endif #endif
#ifdef MODULES_LCD #ifdef MODULES_LCD
rcall LCD_Init bigcall LCD_Init
#endif #endif
#ifdef MODULES_BMP280 #ifdef MODULES_BMP280
rcall BMP280_Init bigcall BMP280_Init
#endif #endif
#ifdef MODULES_SI7021 #ifdef MODULES_SI7021
rcall SI7021_Init bigcall SI7021_Init
#endif #endif
#ifdef MODULES_SGP30 #ifdef MODULES_SGP30
rcall SGP30_Init bigcall SGP30_Init
#endif #endif
#ifdef MODULES_SGP40 #ifdef MODULES_SGP40
rcall SGP40_Init bigcall SGP40_Init
#endif #endif
#ifdef MODULES_DS18B20 #ifdef MODULES_DS18B20
rcall Ds18b20_Init bigcall Ds18b20_Init
#endif #endif
#ifdef MODULES_STATS #ifdef MODULES_STATS
rcall Stats_Init bigcall Stats_Init
#endif #endif
#ifdef MODULES_CNY70 #ifdef MODULES_CNY70
rcall CNY70_Init bigcall CNY70_Init
#endif #endif
#ifdef MODULES_REED #ifdef MODULES_REED
rcall REED_Init bigcall REED_Init
#endif #endif
#ifdef MODULES_SK6812 #ifdef MODULES_SK6812
rcall SK6812_Init bigcall SK6812_Init
#endif #endif
#ifdef MODULES_MOTION_LIGHT #ifdef MODULES_MOTION_LIGHT
rcall MotionLight_Init bigcall MotionLight_Init
#endif #endif
#ifdef MODULES_TCRT1000 #ifdef MODULES_TCRT1000
rcall TCRT1K_Init bigcall TCRT1K_Init
#endif #endif
#ifdef MODULES_CCS811 #ifdef MODULES_CCS811
rcall CCS811_Init bigcall CCS811_Init
#endif #endif
#ifdef MODULES_ILI9341 #ifdef MODULES_ILI9341
rcall ILI9341_Init bigcall ILI9341_Init
#endif #endif
@@ -167,14 +167,14 @@ initModules:
; USED: depending on called routines ; USED: depending on called routines
runModules: runModules:
rcall BaseTimer_Run bigcall BaseTimer_Run
#ifdef MODULES_COM #ifdef MODULES_COM
; COM module (call until carry flag cleared but at most 10 times to not starve other modules) ; COM module (call until carry flag cleared but at most 10 times to not starve other modules)
ldi r16, 10 ldi r16, 10
runModules_Com: runModules_Com:
push r16 push r16
rcall Com2_Run bigcall Com2_Run
pop r16 pop r16
brcc runModules_ComEnd brcc runModules_ComEnd
dec r16 dec r16
@@ -183,23 +183,23 @@ runModules_ComEnd:
#endif #endif
#ifdef MODULES_TTYONUART1 #ifdef MODULES_TTYONUART1
rcall TtyOnUart1_Run bigcall TtyOnUart1_Run
#endif #endif
#ifdef MODULES_COMONUART0 #ifdef MODULES_COMONUART0
rcall ComOnUart0_Run bigcall ComOnUart0_Run
#endif #endif
#ifdef MODULES_STATS #ifdef MODULES_STATS
rcall Stats_Run bigcall Stats_Run
#endif #endif
#ifdef MODULES_REED #ifdef MODULES_REED
rcall REED_Run bigcall REED_Run
#endif #endif
#ifdef MODULES_CNY70 #ifdef MODULES_CNY70
rcall CNY70_Run bigcall CNY70_Run
#endif #endif
#ifdef MODULES_MOTION_LIGHT #ifdef MODULES_MOTION_LIGHT
@@ -220,12 +220,12 @@ runModules_ComEnd:
mainModulesOnPacketReceived: mainModulesOnPacketReceived:
#ifdef MODULES_SK6812 #ifdef MODULES_SK6812
rcall SK6812_OnPacketReceived bigcall SK6812_OnPacketReceived
#endif #endif
#ifdef MODULES_LED_SIMPLE #ifdef MODULES_LED_SIMPLE
#ifdef MODULES_NETWORK #ifdef MODULES_NETWORK
rcall LedSimple_OnPacketReceived bigcall LedSimple_OnPacketReceived
#endif #endif
#endif #endif

View File

@@ -70,7 +70,8 @@ bootLoader_startFirmware:
ldi r20, 4 ; on time ldi r20, 4 ; on time
ldi r21, 1 ; off time ldi r21, 1 ; off time
rcall bootLoaderBlinkLed rcall bootLoaderBlinkLed
rjmp firmwareStart bigjmp firmwareStart
bootLoader_waitAndRestartBootLoader: bootLoader_waitAndRestartBootLoader:
ldi r19, 3 ; loop count ldi r19, 3 ; loop count
ldi r20, 1 ; on time ldi r20, 1 ; on time

View File

@@ -29,7 +29,7 @@ NETMSG_Device_Write:
ldi zh, HIGH(devInfoBlock*2) ; 6-17: devInfoBlock ldi zh, HIGH(devInfoBlock*2) ; 6-17: devInfoBlock
ldi zl, LOW(devInfoBlock*2) ldi zl, LOW(devInfoBlock*2)
ldi r18, 12 ldi r18, 12
rcall Utils_CopyFromFlash ; (R17, R18, X, Z) bigcall Utils_CopyFromFlash ; (R17, R18, X, Z)
sbiw xh:xl, 20 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload) sbiw xh:xl, 20 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload)
rcall NETMSG_CalcAndAddChecksumByte ; (R16, R17, R18, R19, R20, X) rcall NETMSG_CalcAndAddChecksumByte ; (R16, R17, R18, R19, R20, X)
sbiw xh:xl, 21 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload, 1 byte crc) sbiw xh:xl, 21 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload, 1 byte crc)

View File

@@ -28,7 +28,7 @@ NETMSG_RecvStats_Write:
rcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21) rcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21)
adiw yh:yl, NET_IFACE_OFFS_PACKETSIN_LOW adiw yh:yl, NET_IFACE_OFFS_PACKETSIN_LOW
ldi r18, 12 ldi r18, 12
rcall Utils_Copy_SDRAM ; (R17, R18, X, Y) bigcall Utils_Copy_SDRAM ; (R17, R18, X, Y)
sbiw yh:yl, NET_IFACE_OFFS_PACKETSIN_LOW+12 sbiw yh:yl, NET_IFACE_OFFS_PACKETSIN_LOW+12
sbiw xh:xl, 20 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload) sbiw xh:xl, 20 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload)

View File

@@ -28,7 +28,7 @@ NETMSG_SendStats_Write:
rcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21) rcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21)
adiw yh:yl, NET_IFACE_OFFS_PACKETSOUT_LOW adiw yh:yl, NET_IFACE_OFFS_PACKETSOUT_LOW
ldi r18, 6 ldi r18, 6
rcall Utils_Copy_SDRAM ; (R17, R18, X, Y) bigcall Utils_Copy_SDRAM ; (R17, R18, X, Y)
sbiw yh:yl, NET_IFACE_OFFS_PACKETSOUT_LOW+6 sbiw yh:yl, NET_IFACE_OFFS_PACKETSOUT_LOW+6
sbiw xh:xl, 14 ; go back to beginning of message (1 byte dst addr, 1 byte length, 12 bytes payload) sbiw xh:xl, 14 ; go back to beginning of message (1 byte dst addr, 1 byte length, 12 bytes payload)