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:
@@ -164,7 +164,7 @@ appNetworkHandleRebootRequest:
|
||||
brcc appNetworkHandleRebootRequest_end
|
||||
; reboot
|
||||
cli
|
||||
rjmp BOOTLOADER_ADDR
|
||||
bigjmp BOOTLOADER_ADDR
|
||||
appNetworkHandleRebootRequest_end:
|
||||
ret
|
||||
; @end
|
||||
@@ -249,7 +249,7 @@ appNetworkHandleStateHaveAddress2:
|
||||
cli
|
||||
ldi xl, LOW(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
|
||||
pop r15
|
||||
appNetworkHandleStateHaveAddress2_end:
|
||||
@@ -451,7 +451,7 @@ appNetworkGetAddressFromEeprom:
|
||||
cli
|
||||
ldi xl, LOW(EEPROM_OFFS_COMADDR)
|
||||
ldi xh, HIGH(EEPROM_OFFS_COMADDR)
|
||||
rcall Utils_ReadEepromIncr ; (R16)
|
||||
bigcall Utils_ReadEepromIncr ; (R16)
|
||||
out SREG, r15
|
||||
pop r15
|
||||
ret
|
||||
|
||||
@@ -162,7 +162,7 @@ appStatsSend16BitValue:
|
||||
ldi r20, 1
|
||||
clr r21
|
||||
ldi r22, AQHOME_VALUETYPE_STATS
|
||||
rjmp Main_SendValueReport
|
||||
bigjmp Main_SendValueReport
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
30
avr/common/calls.asm
Normal file
30
avr/common/calls.asm
Normal 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
|
||||
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ waitFor10ms:
|
||||
ldi r22, 100
|
||||
waitFor10ms_loop:
|
||||
push r22
|
||||
rcall Utils_WaitFor100MicroSecs
|
||||
bigcall Utils_WaitFor100MicroSecs
|
||||
pop r22
|
||||
dec r22
|
||||
brne waitFor10ms_loop
|
||||
|
||||
@@ -26,27 +26,27 @@ initApps:
|
||||
#ifdef APPS_NETWORK
|
||||
ldi yl, LOW(netInterfaceData)
|
||||
ldi yh, HIGH(netInterfaceData)
|
||||
rcall AppNetwork_Init
|
||||
bigcall AppNetwork_Init
|
||||
#endif
|
||||
|
||||
#ifdef APPS_MOTION
|
||||
rcall AppMotion_Init
|
||||
bigcall AppMotion_Init
|
||||
#endif
|
||||
|
||||
#ifdef APPS_DOOR
|
||||
rcall AppDoor_Init
|
||||
bigcall AppDoor_Init
|
||||
#endif
|
||||
|
||||
#ifdef APPS_REPORTSENSORS
|
||||
rcall AppReportSensors_Init
|
||||
bigcall AppReportSensors_Init
|
||||
#endif
|
||||
|
||||
#ifdef APPS_STATS
|
||||
rcall AppStats_Init
|
||||
bigcall AppStats_Init
|
||||
#endif
|
||||
|
||||
#ifdef APPS_MA_LIGHT
|
||||
rcall AppMotionLight_Init
|
||||
bigcall AppMotionLight_Init
|
||||
#endif
|
||||
|
||||
; done
|
||||
@@ -78,11 +78,11 @@ mainAppsOnPacketReceived:
|
||||
; handle messages
|
||||
ldi yl, LOW(netInterfaceData)
|
||||
ldi yh, HIGH(netInterfaceData)
|
||||
rcall AppNetwork_HandleMsg
|
||||
bigcall AppNetwork_HandleMsg
|
||||
#endif
|
||||
|
||||
#ifdef APPS_MA_LIGHT
|
||||
rcall AppMotionLight_OnPacketReceived
|
||||
bigcall AppMotionLight_OnPacketReceived
|
||||
#endif
|
||||
|
||||
; add more here
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
@@ -31,16 +32,16 @@ main:
|
||||
|
||||
; rcall watchdogOff ; turn off watchdog timer (sometimes it stays on after reboot)
|
||||
|
||||
rcall systemSetSpeed
|
||||
rcall systemInitHardware
|
||||
rcall Utils_Init
|
||||
rcall Utils_SetupUid
|
||||
rcall initModules
|
||||
rcall initApps
|
||||
rcall Utils_InitialWait
|
||||
bigcall systemSetSpeed
|
||||
bigcall systemInitHardware
|
||||
bigcall Utils_Init
|
||||
bigcall Utils_SetupUid
|
||||
bigcall initModules
|
||||
bigcall initApps
|
||||
bigcall Utils_InitialWait
|
||||
sei ; Enable interrupts
|
||||
|
||||
rcall onSystemStart
|
||||
bigcall onSystemStart
|
||||
|
||||
#ifdef MODULES_LED
|
||||
ldi xl, LOW(blinkPattern) ; debug: set blink pattern
|
||||
@@ -53,11 +54,11 @@ main:
|
||||
#endif
|
||||
|
||||
main_loop:
|
||||
rcall systemSleep ; system-dependant
|
||||
rcall runModules
|
||||
rcall runApps
|
||||
bigcall systemSleep ; system-dependant
|
||||
bigcall runModules
|
||||
bigcall runApps
|
||||
|
||||
rcall onEveryLoop ; call into main app
|
||||
bigcall onEveryLoop ; call into main app
|
||||
|
||||
#ifdef MODULES_NETWORK
|
||||
#ifndef MAIN_WITHOUT_MSG_HANDLING
|
||||
@@ -69,7 +70,7 @@ main_loop:
|
||||
|
||||
main_loop_reboot:
|
||||
cli
|
||||
rjmp BOOTLOADER_ADDR
|
||||
bigjmp BOOTLOADER_ADDR
|
||||
; @end
|
||||
|
||||
|
||||
@@ -80,53 +81,53 @@ main_loop_reboot:
|
||||
; Called every 100ms. No arguments, no results.
|
||||
|
||||
onSystemTimerTick:
|
||||
rcall onEvery100ms
|
||||
bigcall onEvery100ms
|
||||
|
||||
#ifdef MODULES_CLOCK
|
||||
rcall Clock_Every100ms ; generates calls to onEverySecond/Minute/Hour/Day
|
||||
bigcall Clock_Every100ms ; generates calls to onEverySecond/Minute/Hour/Day
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_LED_SIMPLE
|
||||
rcall LedSimple_Every100ms
|
||||
bigcall LedSimple_Every100ms
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_UART_BITBANG
|
||||
rcall UART_BitBang_Every100ms
|
||||
bigcall UART_BitBang_Every100ms
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_UART_HW
|
||||
rcall NET_Uart_Every100ms
|
||||
bigcall NET_Uart_Every100ms
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TTYONUART1
|
||||
rcall TtyOnUart1_Periodically
|
||||
bigcall TtyOnUart1_Periodically
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_COMONUART0
|
||||
rcall ComOnUart0_Periodically
|
||||
bigcall ComOnUart0_Periodically
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TCRT1000
|
||||
rcall TCRT1K_Every100ms
|
||||
bigcall TCRT1K_Every100ms
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef APPS_NETWORK
|
||||
ldi yl, LOW(netInterfaceData)
|
||||
ldi yh, HIGH(netInterfaceData)
|
||||
rcall AppNetwork_Every100ms
|
||||
bigcall AppNetwork_Every100ms
|
||||
#endif
|
||||
|
||||
#ifdef APPS_MOTION
|
||||
rcall AppMotion_Every100ms
|
||||
bigcall AppMotion_Every100ms
|
||||
#endif
|
||||
|
||||
#ifdef APPS_DOOR
|
||||
rcall AppDoor_Every100ms
|
||||
bigcall AppDoor_Every100ms
|
||||
#endif
|
||||
|
||||
#ifdef APPS_MA_LIGHT
|
||||
rcall AppMotionLight_Every100ms
|
||||
bigcall AppMotionLight_Every100ms
|
||||
#endif
|
||||
|
||||
ret
|
||||
@@ -138,32 +139,32 @@ onSystemTimerTick:
|
||||
|
||||
sysOnEverySecond:
|
||||
#ifdef MODULES_DS18B20
|
||||
rcall Ds18b20_OnEverySecond
|
||||
bigcall Ds18b20_OnEverySecond
|
||||
#endif
|
||||
|
||||
#ifdef APPS_REPORTSENSORS
|
||||
rcall AppReportSensors_OnEverySecond
|
||||
bigcall AppReportSensors_OnEverySecond
|
||||
#endif
|
||||
rjmp onEverySecond
|
||||
bigjmp onEverySecond
|
||||
; @end
|
||||
|
||||
|
||||
sysOnEveryMinute:
|
||||
#ifdef APPS_STATS
|
||||
rcall AppStats_OnEveryMinute
|
||||
bigcall AppStats_OnEveryMinute
|
||||
#endif
|
||||
|
||||
rjmp onEveryMinute
|
||||
bigjmp onEveryMinute
|
||||
; @end
|
||||
|
||||
|
||||
sysOnEveryHour:
|
||||
rjmp onEveryHour
|
||||
bigjmp onEveryHour
|
||||
; @end
|
||||
|
||||
|
||||
sysOnEveryDay:
|
||||
rjmp onEveryDay
|
||||
bigjmp onEveryDay
|
||||
; @end
|
||||
|
||||
#endif
|
||||
@@ -175,17 +176,17 @@ sysOnEveryDay:
|
||||
; @routine mainHandleMessages
|
||||
|
||||
mainHandleMessages:
|
||||
rcall NET_GetNextIncomingMsgNum ; R16=msg num
|
||||
bigcall NET_GetNextIncomingMsgNum ; R16=msg num
|
||||
brcc mainHandleMessages_end
|
||||
rcall NET_Buffer_Locate ; X=buffer addr (R17)
|
||||
bigcall NET_Buffer_Locate ; X=buffer addr (R17)
|
||||
adiw xh:xl, 1
|
||||
|
||||
push r16
|
||||
rcall onMessageReceived
|
||||
rcall mainModulesOnPacketReceived
|
||||
rcall mainAppsOnPacketReceived
|
||||
bigcall onMessageReceived
|
||||
bigcall mainModulesOnPacketReceived
|
||||
bigcall mainAppsOnPacketReceived
|
||||
pop r16
|
||||
rcall NET_Buffer_ReleaseByNum
|
||||
bigcall NET_Buffer_ReleaseByNum
|
||||
sec
|
||||
mainHandleMessages_end:
|
||||
ret
|
||||
|
||||
@@ -22,22 +22,22 @@
|
||||
; Call init functions of the used modules. Add your routine calls here.
|
||||
|
||||
initModules:
|
||||
rcall BaseTimer_Init ; unconditionally call this
|
||||
bigcall BaseTimer_Init ; unconditionally call this
|
||||
|
||||
#ifdef MODULES_HEAP
|
||||
rcall Heap_Init
|
||||
bigcall Heap_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_CLOCK
|
||||
rcall Clock_Init
|
||||
bigcall Clock_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TIMER
|
||||
rcall Timer_Init
|
||||
bigcall Timer_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_XRAM
|
||||
rcall XRAM_Init
|
||||
bigcall XRAM_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_LED
|
||||
@@ -45,107 +45,107 @@ initModules:
|
||||
ldi zh, HIGH(ledA3Flash)
|
||||
ldi yl, LOW(ledA3Sram)
|
||||
ldi yh, HIGH(ledA3Sram)
|
||||
rcall Led_Init
|
||||
bigcall Led_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_LED_SIMPLE
|
||||
rcall LedSimple_Init
|
||||
bigcall LedSimple_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_COM
|
||||
rcall Com2_Init ; init COM module
|
||||
rcall CPRO_Init ; init COM protocol module
|
||||
bigcall Com2_Init ; init COM module
|
||||
bigcall CPRO_Init ; init COM protocol module
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_NETWORK
|
||||
rcall NET_Init
|
||||
bigcall NET_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_UART_BITBANG
|
||||
rcall UART_BitBang_Init
|
||||
bigcall UART_BitBang_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_UART_HW
|
||||
rcall NET_Uart_Init
|
||||
bigcall NET_Uart_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TTYONUART1
|
||||
rcall TtyOnUart1_Init
|
||||
bigcall TtyOnUart1_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_COMONUART0
|
||||
rcall ComOnUart0_Init
|
||||
bigcall ComOnUart0_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_MOTION
|
||||
rcall Motion_Init
|
||||
bigcall Motion_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TWI_MASTER
|
||||
rcall TWI_Master_Init
|
||||
bigcall TWI_Master_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_OWI_MASTER
|
||||
rcall OwiMaster_Init
|
||||
bigcall OwiMaster_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_SPI_HW
|
||||
rcall SPIHW_Init
|
||||
bigcall SPIHW_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_LCD
|
||||
rcall LCD_Init
|
||||
bigcall LCD_Init
|
||||
#endif
|
||||
#ifdef MODULES_BMP280
|
||||
rcall BMP280_Init
|
||||
bigcall BMP280_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_SI7021
|
||||
rcall SI7021_Init
|
||||
bigcall SI7021_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_SGP30
|
||||
rcall SGP30_Init
|
||||
bigcall SGP30_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_SGP40
|
||||
rcall SGP40_Init
|
||||
bigcall SGP40_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_DS18B20
|
||||
rcall Ds18b20_Init
|
||||
bigcall Ds18b20_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_STATS
|
||||
rcall Stats_Init
|
||||
bigcall Stats_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_CNY70
|
||||
rcall CNY70_Init
|
||||
bigcall CNY70_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_REED
|
||||
rcall REED_Init
|
||||
bigcall REED_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_SK6812
|
||||
rcall SK6812_Init
|
||||
bigcall SK6812_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_MOTION_LIGHT
|
||||
rcall MotionLight_Init
|
||||
bigcall MotionLight_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TCRT1000
|
||||
rcall TCRT1K_Init
|
||||
bigcall TCRT1K_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_CCS811
|
||||
rcall CCS811_Init
|
||||
bigcall CCS811_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_ILI9341
|
||||
rcall ILI9341_Init
|
||||
bigcall ILI9341_Init
|
||||
#endif
|
||||
|
||||
|
||||
@@ -167,14 +167,14 @@ initModules:
|
||||
; USED: depending on called routines
|
||||
|
||||
runModules:
|
||||
rcall BaseTimer_Run
|
||||
bigcall BaseTimer_Run
|
||||
|
||||
#ifdef MODULES_COM
|
||||
; COM module (call until carry flag cleared but at most 10 times to not starve other modules)
|
||||
ldi r16, 10
|
||||
runModules_Com:
|
||||
push r16
|
||||
rcall Com2_Run
|
||||
bigcall Com2_Run
|
||||
pop r16
|
||||
brcc runModules_ComEnd
|
||||
dec r16
|
||||
@@ -183,23 +183,23 @@ runModules_ComEnd:
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TTYONUART1
|
||||
rcall TtyOnUart1_Run
|
||||
bigcall TtyOnUart1_Run
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_COMONUART0
|
||||
rcall ComOnUart0_Run
|
||||
bigcall ComOnUart0_Run
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_STATS
|
||||
rcall Stats_Run
|
||||
bigcall Stats_Run
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_REED
|
||||
rcall REED_Run
|
||||
bigcall REED_Run
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_CNY70
|
||||
rcall CNY70_Run
|
||||
bigcall CNY70_Run
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_MOTION_LIGHT
|
||||
@@ -220,12 +220,12 @@ runModules_ComEnd:
|
||||
mainModulesOnPacketReceived:
|
||||
|
||||
#ifdef MODULES_SK6812
|
||||
rcall SK6812_OnPacketReceived
|
||||
bigcall SK6812_OnPacketReceived
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_LED_SIMPLE
|
||||
#ifdef MODULES_NETWORK
|
||||
rcall LedSimple_OnPacketReceived
|
||||
bigcall LedSimple_OnPacketReceived
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -70,7 +70,8 @@ bootLoader_startFirmware:
|
||||
ldi r20, 4 ; on time
|
||||
ldi r21, 1 ; off time
|
||||
rcall bootLoaderBlinkLed
|
||||
rjmp firmwareStart
|
||||
bigjmp firmwareStart
|
||||
|
||||
bootLoader_waitAndRestartBootLoader:
|
||||
ldi r19, 3 ; loop count
|
||||
ldi r20, 1 ; on time
|
||||
|
||||
@@ -29,7 +29,7 @@ NETMSG_Device_Write:
|
||||
ldi zh, HIGH(devInfoBlock*2) ; 6-17: devInfoBlock
|
||||
ldi zl, LOW(devInfoBlock*2)
|
||||
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)
|
||||
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)
|
||||
|
||||
@@ -28,7 +28,7 @@ NETMSG_RecvStats_Write:
|
||||
rcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21)
|
||||
adiw yh:yl, NET_IFACE_OFFS_PACKETSIN_LOW
|
||||
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 xh:xl, 20 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload)
|
||||
|
||||
@@ -28,7 +28,7 @@ NETMSG_SendStats_Write:
|
||||
rcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21)
|
||||
adiw yh:yl, NET_IFACE_OFFS_PACKETSOUT_LOW
|
||||
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 xh:xl, 14 ; go back to beginning of message (1 byte dst addr, 1 byte length, 12 bytes payload)
|
||||
|
||||
Reference in New Issue
Block a user