N23 basically works now.

This commit is contained in:
Martin Preuss
2025-04-26 11:04:01 +02:00
parent feabc76e36
commit 8925ce23e9
4 changed files with 258 additions and 102 deletions

View File

@@ -31,7 +31,10 @@
.list
.include "../defs.asm"
.include "./data.asm"
.include "defs_all.asm"
.include "common/utils_wait.asm"
@@ -41,6 +44,10 @@
; ---------------------------------------------------------------------------
; generic
.equ NET_BUFFERS_NUM = 6
.equ NET_BUFFERS_SIZE = 28
.equ PROGRAM_TIMER_VALUE = 60
; ---------------------------------------------------------------------------
@@ -98,7 +105,7 @@
; rjmp main ; Reset vector
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp uartBitbangIsrPcint0 ; PCI0
rjmp UART_BitBang_PcintIsr ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
@@ -139,6 +146,9 @@ firmwareStart:
rcall Utils_Init
rcall Utils_SetupUid
ldi r16, PROGRAM_TIMER_VALUE
sts programRamSensorTimer, r16
rcall initModules
sbi LED_SIMPLE_DDR, LED_SIMPLE_PINNUM ; out
@@ -157,11 +167,10 @@ main_loop:
sei ; make sure interrupts really are enabled
sleep ; sleep, wait for interrupt
rcall BaseTimer_Run
rcall BaseTimer_Run ; let basetimer run
rcall handleMessages ; handle incoming messages
; rcall ComOnUart0_Run
; TODO: read recved messages
rjmp main_loop
@@ -172,19 +181,20 @@ main_loop:
; Called every 100ms. Add your routine calls here. No arguments, no results.
systemSetSpeed:
.if clock == 1000000
ldi r17, 0xd8
ldi r16, (1<<CLKPS1) | (1<<CLKPS0) ; SUT=0, CLKPS=0011b
sts CCP, r17
sts CLKPR, r16
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
.if clock == 8000000
ldi r17, 0xd8
clr r16 ; SUT=0, CLKPS=0
sts CCP, r17
sts CLKPR, r16
.if clock == 1000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret
@@ -199,17 +209,17 @@ initHardware:
clr r17
.ifdef PORTA
out DDRA, r17 ; all input
sts PUEA, r16 ; enable pull-up on all
out PORTA, r16 ; enable pull-up on all
.endif
.ifdef PORTB
out DDRB, r17 ; all input
sts PUEB, r16 ; enable pull-up on all
out PORTB, r16 ; enable pull-up on all
.endif
.ifdef PORTC
out DDRC, r17 ; all input
sts PUEC, r16 ; enable pull-up on all
out PORTC, r16 ; enable pull-up on all
.endif
ret
; @end
@@ -227,6 +237,8 @@ initModules:
rcall LedSimple_Init
rcall NET_Init
rcall UART_BitBang_Init
rcall Motion_Init
rcall SI7021_Init
; init apps
ldi yl, LOW(uart_bitbang_iface)
@@ -254,13 +266,43 @@ onSystemTimerTick:
rcall AppNetwork_Every100ms
rcall AppMotion_Every100ms
ret
; @end
; ---------------------------------------------------------------------------
; @routine onEverySecond
onEverySecond:
lds r16, programRamSensorTimer
dec r16
brne onEverySecond_store
ldi r16, PROGRAM_TIMER_VALUE
onEverySecond_store:
sts programRamSensorTimer, r16
cpi r16, 59
breq onEverySecond_measureValue1
cpi r16, 29
breq onEverySecond_measureValue2
cpi r16, 19
breq onEverySecond_sendValue1
cpi r16, 9
breq onEverySecond_sendValue2
ret
onEverySecond_measureValue1:
rjmp SI7021_MeasureTemp
onEverySecond_measureValue2:
rjmp SI7021_MeasureHumidity
onEverySecond_sendValue1:
rjmp sendTemperature
onEverySecond_sendValue2:
rjmp sendHumidity
; @end
onEveryMinute:
onEveryHour:
onEveryDay:
@@ -268,9 +310,88 @@ onEveryDay:
; ---------------------------------------------------------------------------
; @routine handleMessages
handleMessages:
rcall NET_GetNextIncomingMsgNum ; R16=msg num
brcc handleMessages_end
rcall NET_Buffer_Locate ; X=buffer addr (R17)
push r16
; handle messages
ldi yl, LOW(uart_bitbang_iface)
ldi yh, HIGH(uart_bitbang_iface)
rcall AppNetwork_HandleMsg
; add more here
pop r16
rcall NET_Buffer_ReleaseByNum
sec
handleMessages_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine sendTemperature
sendTemperature:
ldi r16, SI7021_VALUE_TEMP
rcall SI7021_GetValue
brcc sendTemperature_end
ldi r17, VALUE_ID_SI7021_TEMP ; VALUE ID
ldi r22, AQHOME_VALUETYPE_TEMP ; VALUE TYPE
rcall sendValue
sendTemperature_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine sendHumidity
sendHumidity:
ldi r16, SI7021_VALUE_HUMIDITY
rcall SI7021_GetValue
brcc sendHumidity_end
ldi r17, VALUE_ID_SI7021_HUM ; VALUE ID
ldi r22, AQHOME_VALUETYPE_HUMIDITY ; VALUE TYPE
rcall sendValue
sendHumidity_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine 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
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
@@ -283,23 +404,45 @@ onEveryDay:
.include "common/utils_copy_sdram.asm"
.include "common/crc8.asm"
.include "modules/uart_bitbang2/main.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"
.include "modules/uart_bitbang2/defs.asm"
.include "modules/uart_bitbang2/iface.asm"
.include "modules/uart_bitbang2/lowlevel.asm"
.include "modules/basetimer/main.asm"
.include "modules/clock/main.asm"
.include "modules/led_simple/main.asm"
.include "modules/twimaster/main.asm"
.include "modules/si7021/main.asm"
.include "modules/si7021/main2.asm"
#ifdef MODULES_STATS
.include "modules/stats/main.asm"
; .include "modules/stats/main.asm"
#endif
.include "modules/motion/main.asm"
.include "modules/motion/main2.asm"
#ifdef MODULES_CCS811
.include "modules/ccs811/main.asm"
#endif
.include "modules/f_keepup/main.asm"
.include "modules/valsched/main.asm"
.include "./motion.asm"
.include "./network.asm"
; ---------------------------------------------------------------------------
@@ -309,56 +452,3 @@ onEveryDay:
; ***************************************************************************
; data in SRAM
.dseg
programRamBegin:
;
programRamEnd:
.cseg
#ifdef MODULES_SI7021
sendSI7021Humidity:
rcall SI7021_SendHumidity
brcs sendSI7021Humidity_okay
; set timer to 1s to retry later
ldi xl, LOW(sramTimerSI7021SendHumidity)
ldi xh, HIGH(sramTimerSI7021SendHumidity)
rjmp Timer_SetValueTo1s
sendSI7021Humidity_okay:
ret
sendSI7021Temp:
rcall SI7021_SendTemp
brcs sendSI7021Temp_okay
; set timer to 1s to retry later
ldi xl, LOW(sramTimerSI7021SendTemp)
ldi xh, HIGH(sramTimerSI7021SendTemp)
rjmp Timer_SetValueTo1s
sendSI7021Temp_okay:
ret
#endif
#ifdef MODULES_DS18B20
sendDs18b20Temp:
rcall Ds18b20_SendTemp
brcs sendDs18b20Temp_okay
; set timer to 1s to retry later
ldi xl, LOW(sramSendDs18b20TempTimer)
ldi xh, HIGH(sramSendDs18b20TempTimer)
rjmp Timer_SetValueTo1s
sendDs18b20Temp_okay:
ret
#endif