avr: use new code in latest nodes.
This commit is contained in:
18
avr/devices/all/0BUILD
Normal file
18
avr/devices/all/0BUILD
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml?>
|
||||
|
||||
<gwbuild>
|
||||
|
||||
<extradist>
|
||||
apps.asm
|
||||
data.asm
|
||||
defs.asm
|
||||
includes.asm
|
||||
main.asm
|
||||
modules.asm
|
||||
sendvalue.asm
|
||||
|
||||
</extradist>
|
||||
|
||||
</gwbuild>
|
||||
|
||||
|
||||
59
avr/devices/all/apps.asm
Normal file
59
avr/devices/all/apps.asm
Normal file
@@ -0,0 +1,59 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine initApps
|
||||
;
|
||||
; Call init functions of the used apps. Add your routine calls here.
|
||||
|
||||
initApps:
|
||||
|
||||
#ifdef APPS_NETWORK
|
||||
ldi yl, LOW(netInterfaceData)
|
||||
ldi yh, HIGH(netInterfaceData)
|
||||
rcall AppNetwork_Init
|
||||
#endif
|
||||
|
||||
#ifdef APPS_MOTION
|
||||
rcall AppMotion_Init
|
||||
#endif
|
||||
|
||||
#ifdef APPS_DOOR
|
||||
rcall AppDoor_Init
|
||||
#endif
|
||||
|
||||
; done
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine runApps
|
||||
;
|
||||
; Call run functions of the used modules. Add your routine calls here.
|
||||
;
|
||||
|
||||
runApps:
|
||||
|
||||
; add more modules here
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
14
avr/devices/all/data.asm
Normal file
14
avr/devices/all/data.asm
Normal file
@@ -0,0 +1,14 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
|
||||
.dseg
|
||||
|
||||
|
||||
45
avr/devices/all/defs.asm
Normal file
45
avr/devices/all/defs.asm
Normal file
@@ -0,0 +1,45 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
|
||||
.equ AQHOME_VALUETYPE_UNKNOWN = 0
|
||||
.equ AQHOME_VALUETYPE_TEMP = 1
|
||||
.equ AQHOME_VALUETYPE_HUMIDITY = 2
|
||||
.equ AQHOME_VALUETYPE_DOOR = 3
|
||||
.equ AQHOME_VALUETYPE_RGB = 4
|
||||
.equ AQHOME_VALUETYPE_RGBW = 5
|
||||
.equ AQHOME_VALUETYPE_MOTION = 6
|
||||
.equ AQHOME_VALUETYPE_CO2 = 7
|
||||
.equ AQHOME_VALUETYPE_TVOC = 8
|
||||
|
||||
|
||||
.equ AQHOME_FW_TYPE_ATT84_BASE = 0
|
||||
.equ AQHOME_FW_TYPE_ATT84_TEMP1 = 1
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; EEPROM positions
|
||||
|
||||
|
||||
.equ EEPROM_OFFS_UUID = 0 ; 4 bytes (occupy total of 8 bytes for extensibility)
|
||||
.equ EEPROM_OFFS_COMADDR = 8 ; 1 byte (plus one byte reserved)
|
||||
|
||||
.equ EEPROM_OFFS_SEED = 10 ; 2 bytes
|
||||
|
||||
.equ EEPROM_OFFS_REED_CONF = 12 ; 1 byte (plus one byte reserved)
|
||||
|
||||
.equ EEPROM_OFFS_MAL_CONF_ONTIME = 14 ; 2 bytes
|
||||
.equ EEPROM_OFFS_MAL_CONF_SRC1_ADDR = 16 ; 1 byte
|
||||
.equ EEPROM_OFFS_MAL_CONF_SRC1_VALUEID = 17 ; 1 byte
|
||||
.equ EEPROM_OFFS_MAL_CONF_SRC2_ADDR = 18 ; 1 byte
|
||||
.equ EEPROM_OFFS_MAL_CONF_SRC2_VALUEID = 19 ; 1 byte
|
||||
|
||||
; next is 20
|
||||
|
||||
108
avr/devices/all/includes.asm
Normal file
108
avr/devices/all/includes.asm
Normal file
@@ -0,0 +1,108 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
.include "devices/all/main.asm"
|
||||
.include "devices/all/apps.asm"
|
||||
.include "devices/all/modules.asm"
|
||||
.include "devices/all/sendvalue.asm"
|
||||
.include "devices/all/data.asm"
|
||||
|
||||
.include "common/utils.asm"
|
||||
.include "common/utils_initial_wait.asm"
|
||||
.include "common/utils_wait_fixed.asm"
|
||||
.include "common/utils_copy_from_flash.asm"
|
||||
.include "common/utils_copy_sdram.asm"
|
||||
|
||||
.include "modules/basetimer/main.asm"
|
||||
|
||||
#ifdef MODULES_NETWORK
|
||||
.include "common/crc8.asm"
|
||||
.include "common/m_fixedbuffers.asm"
|
||||
.include "common/m_ringbuffer_y.asm"
|
||||
.include "common/ringbuffer_y.asm"
|
||||
.include "modules/network/defs.asm"
|
||||
.include "modules/network/data.asm"
|
||||
.include "modules/network/iface.asm"
|
||||
.include "modules/network/main.asm"
|
||||
.include "modules/network/buffer.asm"
|
||||
.include "modules/network/msg/defs.asm"
|
||||
.include "modules/network/msg/common.asm"
|
||||
.include "modules/network/msg/crc.asm"
|
||||
.include "modules/network/msg/value-w.asm"
|
||||
.include "modules/network/msg/addr-r.asm"
|
||||
.include "modules/network/msg/addr-w.asm"
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_UART_BITBANG
|
||||
.include "modules/uart_bitbang2/defs.asm"
|
||||
.include "modules/uart_bitbang2/iface.asm"
|
||||
.include "modules/uart_bitbang2/lowlevel.asm"
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_CLOCK
|
||||
.include "modules/clock/main.asm"
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_LED_SIMPLE
|
||||
.include "modules/led_simple/main.asm"
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TWI_MASTER
|
||||
.include "modules/twimaster/main.asm"
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_SI7021
|
||||
.include "modules/si7021/main2.asm"
|
||||
#ifdef MODULES_NETWORK
|
||||
.include "modules/si7021/send.asm"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_STATS
|
||||
; .include "modules/stats/main.asm"
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_MOTION
|
||||
.include "modules/motion/main2.asm"
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_CCS811
|
||||
.include "modules/ccs811/main.asm"
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TCRT1000
|
||||
.include "modules/tcrt1000/main2.asm"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef APPS_MOTION
|
||||
.include "modules/f_keepup/main.asm"
|
||||
.include "modules/valsched/main.asm"
|
||||
.include "apps/motion/main.asm"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef APPS_DOOR
|
||||
#ifndef APPS_MOTION
|
||||
.include "modules/f_keepup/main.asm"
|
||||
.include "modules/valsched/main.asm"
|
||||
#endif
|
||||
.include "apps/door/main.asm"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef APPS_NETWORK
|
||||
.include "apps/network/main.asm"
|
||||
.include "modules/network/msg/reboot-d.asm"
|
||||
.include "modules/network/msg/reboot-r.asm"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
126
avr/devices/all/main.asm
Normal file
126
avr/devices/all/main.asm
Normal file
@@ -0,0 +1,126 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine main @global
|
||||
|
||||
main:
|
||||
cli
|
||||
; setup stack
|
||||
.ifdef SPH ; if SPH is defined
|
||||
ldi r16, High(RAMEND)
|
||||
out SPH, r16 ; init MSB stack pointer
|
||||
.endif
|
||||
ldi r16, Low(RAMEND)
|
||||
out SPL, r16 ; init LSB stack pointer
|
||||
|
||||
; 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
|
||||
sei ; Enable interrupts
|
||||
|
||||
rcall onSystemStart
|
||||
|
||||
#ifdef MODULES_LED
|
||||
ldi xl, LOW(blinkPattern) ; debug: set blink pattern
|
||||
ldi xh, HIGH(blinkPattern)
|
||||
ldi zl, LOW(ledA3Flash)
|
||||
ldi zh, HIGH(ledA3Flash)
|
||||
ldi yl, LOW(ledA3Sram)
|
||||
ldi yh, HIGH(ledA3Sram)
|
||||
rcall Led_SetPattern
|
||||
#endif
|
||||
|
||||
main_loop:
|
||||
rcall runModules
|
||||
rcall runApps
|
||||
|
||||
#ifdef MODULES_NETWORK
|
||||
rcall handleMessages
|
||||
#endif
|
||||
|
||||
; 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
|
||||
rjmp main_loop
|
||||
|
||||
main_loop_reboot:
|
||||
cli
|
||||
rjmp BOOTLOADER_ADDR
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine onSystemTimerTick
|
||||
;
|
||||
; Called every 100ms. No arguments, no results.
|
||||
|
||||
onSystemTimerTick:
|
||||
rcall onEvery100ms
|
||||
|
||||
#ifdef MODULES_CLOCK
|
||||
rcall Clock_Every100ms ; generates calls to onEverySecond/Minute/Hour/Day
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_LED_SIMPLE
|
||||
rcall LedSimple_Every100ms
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_UART_BITBANG
|
||||
rcall UART_BitBang_Every100ms
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TCRT1000
|
||||
rcall TCRT1K_Every100ms
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef APPS_NETWORK
|
||||
ldi yl, LOW(netInterfaceData)
|
||||
ldi yh, HIGH(netInterfaceData)
|
||||
rcall AppNetwork_Every100ms
|
||||
#endif
|
||||
|
||||
#ifdef APPS_MOTION
|
||||
rcall AppMotion_Every100ms
|
||||
#endif
|
||||
|
||||
#ifdef APPS_DOOR
|
||||
rcall AppDoor_Every100ms
|
||||
#endif
|
||||
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
210
avr/devices/all/modules.asm
Normal file
210
avr/devices/all/modules.asm
Normal file
@@ -0,0 +1,210 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine initModules
|
||||
;
|
||||
; Call init functions of the used modules. Add your routine calls here.
|
||||
|
||||
initModules:
|
||||
rcall BaseTimer_Init ; unconditionally call this
|
||||
|
||||
#ifdef MODULES_CLOCK
|
||||
rcall Clock_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TIMER
|
||||
rcall Timer_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_LED
|
||||
ldi zl, LOW(ledA3Flash)
|
||||
ldi zh, HIGH(ledA3Flash)
|
||||
ldi yl, LOW(ledA3Sram)
|
||||
ldi yh, HIGH(ledA3Sram)
|
||||
rcall Led_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_LED_SIMPLE
|
||||
rcall LedSimple_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_COM
|
||||
rcall Com2_Init ; init COM module
|
||||
rcall CPRO_Init ; init COM protocol module
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_NETWORK
|
||||
rcall NET_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_UART_BITBANG
|
||||
rcall UART_BitBang_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_MOTION
|
||||
rcall Motion_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TWI_MASTER
|
||||
rcall TWI_Master_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_OWI_MASTER
|
||||
rcall OwiMaster_Init
|
||||
#endif
|
||||
#ifdef MODULES_LCD
|
||||
rcall LCD_Init
|
||||
#endif
|
||||
#ifdef MODULES_BMP280
|
||||
rcall BMP280_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_SI7021
|
||||
rcall SI7021_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_DS18B20
|
||||
rcall Ds18b20_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_STATS
|
||||
rcall Stats_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_CNY70
|
||||
rcall CNY70_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_REED
|
||||
rcall REED_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_SK6812
|
||||
rcall SK6812_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_MOTION_LIGHT
|
||||
rcall MotionLight_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TCRT1000
|
||||
rcall TCRT1K_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_CCS811
|
||||
rcall CCS811_Init
|
||||
#endif
|
||||
|
||||
; done
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; runModules
|
||||
;
|
||||
; Call run functions of the used modules. Add your routine calls here.
|
||||
;
|
||||
; IN:
|
||||
; - nothing
|
||||
; OUT:
|
||||
; - nothing
|
||||
; USED: depending on called routines
|
||||
|
||||
runModules:
|
||||
rcall 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
|
||||
pop r16
|
||||
brcc runModules_ComEnd
|
||||
dec r16
|
||||
brne runModules_Com
|
||||
runModules_ComEnd:
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_STATS
|
||||
rcall Stats_Run
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_REED
|
||||
rcall REED_Run
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_CNY70
|
||||
rcall CNY70_Run
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_DS18B20
|
||||
rcall Ds18b20_Run
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_MOTION_LIGHT
|
||||
; rcall MotionLight_Run
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef MODULES_TCRT1000
|
||||
; rcall TCRT1K_Run
|
||||
#endif
|
||||
|
||||
; add more modules here
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
#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
|
||||
|
||||
#ifdef APPS_NETWORK
|
||||
; handle messages
|
||||
ldi yl, LOW(netInterfaceData)
|
||||
ldi yh, HIGH(netInterfaceData)
|
||||
rcall AppNetwork_HandleMsg
|
||||
#endif
|
||||
|
||||
; add more here
|
||||
pop r16
|
||||
rcall NET_Buffer_ReleaseByNum
|
||||
sec
|
||||
handleMessages_end:
|
||||
ret
|
||||
; @end
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
67
avr/devices/all/sendvalue.asm
Normal file
67
avr/devices/all/sendvalue.asm
Normal file
@@ -0,0 +1,67 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Main_SendValue
|
||||
;
|
||||
; @param R17 value id
|
||||
; @param R19:R18 value
|
||||
; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100)
|
||||
; @param R22 value type
|
||||
|
||||
Main_SendValue:
|
||||
push r17
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
pop r17
|
||||
brcc sendValue_end ; jmp on error
|
||||
push r16 ; buffer num
|
||||
ldi r16, 0xff ; DEST addr
|
||||
adiw xh:xl, 1
|
||||
ldi yl, LOW(netInterfaceData)
|
||||
ldi yh, HIGH(netInterfaceData)
|
||||
rcall NETMSG_ValueWriteReport ; (R16, R17, R18, R19, R20, R21, R23, R24, R25)
|
||||
sbiw xh:xl, 1
|
||||
pop r16 ; buffer num
|
||||
rcall NET_Interface_AddOutgoingMsgNum ; (R17, R18, X)
|
||||
brcs sendValue_end ; jump if okay
|
||||
rcall NET_Buffer_ReleaseByNum ; otherwise release buffer
|
||||
clc
|
||||
sendValue_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Main_Send8BitValue
|
||||
;
|
||||
; Send 8 bit value with denominator 1.
|
||||
;
|
||||
; @param R16 value
|
||||
; @param R17 value id
|
||||
; @param R22 value type
|
||||
|
||||
Main_Send8BitValue:
|
||||
mov r18, r16 ; R19:R18 = value
|
||||
clr r19
|
||||
ldi r20, 1 ; R21:R20 = denom
|
||||
clr r21
|
||||
rjmp Main_SendValue
|
||||
; @end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user