avr/devices/all: started integrating code from t03.

This commit is contained in:
Martin Preuss
2025-05-08 17:14:33 +02:00
parent cc7ef0cf30
commit 64e2cf5d25
19 changed files with 1544 additions and 100 deletions

View File

@@ -68,4 +68,29 @@ runApps:
; ---------------------------------------------------------------------------
; @routine mainAppsOnPacketReceived
;
; Let all apps handle received message.
mainAppsOnPacketReceived:
#ifdef APPS_NETWORK
; handle messages
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
rcall AppNetwork_HandleMsg
#endif
#ifdef APPS_MA_LIGHT
rcall AppMotionLight_OnPacketReceived
#endif
; add more here
ret
; @end

View File

@@ -63,3 +63,25 @@ systemSetSpeed:
; @end
; ---------------------------------------------------------------------------
; @routine systemSleep
;
systemSleep:
; only modify SE, SM1 and SM0
cli
in r16, MCUCR
ldi r17, (1<<SE) | (1<<SM1) | (1<<SM0)
neg r17
and r16, r17
ori r16, (1<<SE) ; sleep mode "idle", enable
out MCUCR, r16
sei ; make sure interrupts really are enabled
sleep ; sleep, wait for interrupt
ret
; @end

View File

@@ -0,0 +1,79 @@
; ***************************************************************************
; 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. *
; ***************************************************************************
; Hardware routine for AtTiny 84 devices
.cseg
; ---------------------------------------------------------------------------
; @routine systemInitHardware
;
systemInitHardware:
; set all ports as inputs and enable internal pull-up resistors
ldi r16, 0xff
clr r17
out DDRA, r17 ; all input
sts PUEA, r16 ; enable pull-up on all
out DDRB, r17 ; all input
sts PUEB, r16 ; enable pull-up on all
ret
; @end
; ---------------------------------------------------------------------------
; @routine systemSetSpeed
;
systemSetSpeed:
.if clock == 1000000
ldi r17, 0xd8
ldi r16, (1<<CLKPS1) | (1<<CLKPS0) ; SUT=0, CLKPS=0011b
sts CCP, r17
sts CLKPR, r16
.endif
.if clock == 8000000
ldi r17, 0xd8
clr r16 ; SUT=0, CLKPS=0
sts CCP, r17
sts CLKPR, r16
.endif
ret
; @end
; ---------------------------------------------------------------------------
; @routine systemSleep
;
systemSleep:
; only modify SE, SM1 and SM0
cli
in r16, MCUCR
ldi r17, (1<<SE) | (1<<SM1) | (1<<SM0)
neg r17
and r16, r17
ori r16, (1<<SE) ; sleep mode "idle", enable
out MCUCR, r16
sei ; make sure interrupts really are enabled
sleep ; sleep, wait for interrupt
ret
; @end

View File

@@ -63,3 +63,25 @@ systemSetSpeed:
; @end
; ---------------------------------------------------------------------------
; @routine systemSleep
;
systemSleep:
; only modify SE, SM1 and SM0
cli
in r16, MCUCR
ldi r17, (1<<SE) | (1<<SM1) | (1<<SM0)
neg r17
and r16, r17
ori r16, (1<<SE) ; sleep mode "idle", enable
out MCUCR, r16
sei ; make sure interrupts really are enabled
sleep ; sleep, wait for interrupt
ret
; @end

View File

@@ -47,6 +47,24 @@
.include "modules/uart_bitbang2/lowlevel.asm"
#endif
#ifdef MODULES_COMONUART0
.include "modules/uart_hw/defs.asm"
.include "modules/uart_hw/lowlevel.asm"
.include "modules/uart_hw/m_lowlevel_uart.asm"
.include "modules/uart_hw/comonuart0.asm"
#endif
#ifdef MODULES_TTYONUART1
#ifndef MODULES_COMONUART0
.include "modules/uart_hw/defs.asm"
.include "modules/uart_hw/lowlevel.asm"
.include "modules/uart_hw/m_lowlevel_uart.asm"
#endif
.include "modules/uart_hw/ttyonuart1.asm"
#endif
#ifdef MODULES_CLOCK
.include "modules/clock/main.asm"
#endif

View File

@@ -53,22 +53,16 @@ main:
#endif
main_loop:
; only modify SE, SM1 and SM0
cli
in r16, MCUCR
ldi r17, (1<<SE) | (1<<SM1) | (1<<SM0)
neg r17
and r16, r17
ori r16, (1<<SE) ; sleep mode "idle", enable
out MCUCR, r16
sei ; make sure interrupts really are enabled
sleep ; sleep, wait for interrupt
rcall systemSleep ; system-dependant
rcall runModules
rcall runApps
rcall onEveryLoop ; call into main app
#ifdef MODULES_NETWORK
rcall handleMessages
#ifndef MAIN_WITHOUT_MSG_HANDLING
rcall mainHandleMessages
#endif
#endif
rjmp main_loop
@@ -100,6 +94,14 @@ onSystemTimerTick:
rcall UART_BitBang_Every100ms
#endif
#ifdef MODULES_TTYONUART1
rcall TtyOnUart1_Periodically
#endif
#ifdef MODULES_COMONUART0
rcall ComOnUart0_Periodically
#endif
#ifdef MODULES_TCRT1000
rcall TCRT1K_Every100ms
#endif
@@ -163,6 +165,27 @@ sysOnEveryDay:
#ifdef MODULES_NETWORK
; ---------------------------------------------------------------------------
; @routine mainHandleMessages
mainHandleMessages:
rcall NET_GetNextIncomingMsgNum ; R16=msg num
brcc mainHandleMessages_end
rcall NET_Buffer_Locate ; X=buffer addr (R17)
adiw xh:xl, 1
push r16
rcall onMessageReceived
rcall mainModulesOnPacketReceived
rcall mainAppsOnPacketReceived
pop r16
rcall NET_Buffer_ReleaseByNum
sec
mainHandleMessages_end:
ret
; @end
#endif

View File

@@ -57,6 +57,14 @@ initModules:
rcall UART_BitBang_Init
#endif
#ifdef MODULES_TTYONUART1
rcall TtyOnUart1_Init
#endif
#ifdef MODULES_COMONUART0
rcall ComOnUart0_Init
#endif
#ifdef MODULES_MOTION
rcall Motion_Init
#endif
@@ -111,6 +119,7 @@ initModules:
rcall CCS811_Init
#endif
; done
ret
; @end
@@ -142,7 +151,14 @@ runModules_Com:
dec r16
brne runModules_Com
runModules_ComEnd:
#endif
#ifdef MODULES_TTYONUART1
rcall TtyOnUart1_Run
#endif
#ifdef MODULES_COMONUART0
rcall ComOnUart0_Run
#endif
#ifdef MODULES_STATS
@@ -172,44 +188,16 @@ runModules_ComEnd:
#ifdef MODULES_NETWORK
; ---------------------------------------------------------------------------
; @routine handleMessages
handleMessages:
rcall NET_GetNextIncomingMsgNum ; R16=msg num
brcc handleMessages_end
rcall NET_Buffer_Locate ; X=buffer addr (R17)
adiw xh:xl, 1
push r16
rcall onMessageReceived
mainModulesOnPacketReceived:
#ifdef MODULES_SK6812
rcall SK6812_OnPacketReceived
#endif
#ifdef APPS_NETWORK
; handle messages
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
rcall AppNetwork_HandleMsg
#endif
; add more here
#ifdef APPS_MA_LIGHT
rcall AppMotionLight_OnPacketReceived
#endif
; add more here
pop r16
rcall NET_Buffer_ReleaseByNum
sec
handleMessages_end:
ret
; @end
#endif