3 Commits

Author SHA1 Message Date
Martin Preuss
deddf42379 First try to unify ATTN handling. 2025-05-29 14:32:48 +02:00
Martin Preuss
e584245965 c01: added defs when using uart_bitbang2. 2025-05-29 14:32:29 +02:00
Martin Preuss
46720d791c avr: some ideas for autosync. 2025-05-29 12:47:41 +02:00
72 changed files with 1512 additions and 2476 deletions

View File

@@ -58,7 +58,6 @@ static AQH_MESSAGE *_createRequestMessage(AQH_OBJECT *o, uint32_t msgId);
static int _handleResponseMessage(AQH_OBJECT *o, const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, int first);
static void _printNode(const AQH_NODE_INFO *ni, int printAll);
static void _printUintAsTextOrHex(uint32_t u, int bits);
static void _printDeviceIdAsTextOrHex(uint32_t u, int version);
@@ -164,7 +163,9 @@ void _printNode(const AQH_NODE_INFO *ni, int printAll)
_printUintAsTextOrHex(u, 32);
fprintf(stdout, ":");
u=AQH_NodeInfo_GetDeviceType(ni);
_printDeviceIdAsTextOrHex(u, AQH_NodeInfo_GetDeviceVersion(ni));
_printUintAsTextOrHex(u, 16);
u=AQH_NodeInfo_GetDeviceVersion(ni);
fprintf(stdout, " v%d.%d", (u>>8) & 0xff, u & 0xff);
u=AQH_NodeInfo_GetFirmwareVersion(ni);
fprintf(stdout, ", firmware=%d.%d.%d (%d), ",
(u>>16) & 0xff, (u>>8) & 0xff, u & 0xff, (u>>24) & 0xff);
@@ -188,36 +189,6 @@ void _printNode(const AQH_NODE_INFO *ni, int printAll)
void _printDeviceIdAsTextOrHex(uint32_t u, int version)
{
int i;
uint8_t d;
int hasNonPrintable=0;
int hasPrintable=0;
for (i=0; i<16; i+=8) {
d=((u>>i) & 0xff);
if (d==0) { /* undecided */
}
else if (isalnum(d))
hasPrintable=1;
else
hasNonPrintable=1;
}
if (hasNonPrintable || !hasPrintable)
fprintf(stdout, "%02x v%d.%d", u, (version>>8) & 0xff, version & 0xff);
else {
for (i=0; i<16; i+=8) {
d=((u>>i) & 0xff);
fprintf(stdout, "%c", d?d:' ');
}
fprintf(stdout, "%2d (%d)", (version>>8) & 0xff, version & 0xff);
}
}
void _printUintAsTextOrHex(uint32_t u, int bits)
{
int i;

View File

@@ -111,8 +111,6 @@ AppNetwork_HandleMsg:
sbiw xh:xl, NETMSG_OFFS_CMD
cpi r16, NETMSG_CMD_REBOOT_REQUEST
breq AppNetwork_HandleMsg_handleRebootMsg
cpi r16, NETMSG_CMD_PING
breq AppNetwork_HandleMsg_handlePingMsg
cpi r16, NETMSG_CMD_NEED_ADDRESS
brcs AppNetwork_HandleMsg_clcRet ; lower than "HAVE_NEED"
cpi r16, NETMSG_CMD_ADDRESS_RANGE
@@ -140,13 +138,6 @@ AppNetwork_HandleMsg_handleRebootMsg:
pop xh
pop xl
ret
AppNetwork_HandleMsg_handlePingMsg:
push xl
push xh
rcall appNetworkHandlePingRequest
pop xh
pop xl
ret
AppNetwork_HandleMsg_clcRet:
clc
ret
@@ -164,33 +155,13 @@ appNetworkHandleRebootRequest:
brcc appNetworkHandleRebootRequest_end
; reboot
cli
bigjmp BOOTLOADER_ADDR
rjmp BOOTLOADER_ADDR
appNetworkHandleRebootRequest_end:
ret
; @end
appNetworkHandlePingRequest:
adiw xh:xl, NETMSG_OFFS_SRCADDR
ld r17, X
push r17
rcall NET_Buffer_Alloc ; (R16, R17, X)
pop r17
brcc appNetworkHandlePingRequest_end ; jmp on error
push r16 ; buffer num
mov r16, r17 ; DEST addr
adiw xh:xl, 1
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
rcall NETMSG_Pong_Write ; (R16, R17, R18, R19, R20, X)
sbiw xh:xl, 1
pop r16 ; buffer num
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
appNetworkHandlePingRequest_end:
ret
appNetworkTimerTable:
rjmp appNetworkHandleStateInitialWait
@@ -249,7 +220,7 @@ appNetworkHandleStateHaveAddress2:
cli
ldi xl, LOW(EEPROM_OFFS_COMADDR)
ldi xh, HIGH(EEPROM_OFFS_COMADDR)
bigcall Utils_WriteEepromIncr ; write address to EEPROM
rcall Utils_WriteEepromIncr ; write address to EEPROM
out SREG, r15
pop r15
appNetworkHandleStateHaveAddress2_end:
@@ -262,6 +233,7 @@ appNetworkHandleStateUp:
ret
; ---------------------------------------------------------------------------
; @routine appNetworkSendMsgNextState
;
@@ -451,7 +423,7 @@ appNetworkGetAddressFromEeprom:
cli
ldi xl, LOW(EEPROM_OFFS_COMADDR)
ldi xh, HIGH(EEPROM_OFFS_COMADDR)
bigcall Utils_ReadEepromIncr ; (R16)
rcall Utils_ReadEepromIncr ; (R16)
out SREG, r15
pop r15
ret

View File

@@ -53,19 +53,6 @@ AppStats_Fini:
;
AppStats_OnEveryMinute:
push r15
in r15, SREG
cli
rcall AppStats_OnEveryMinute_noIrq
out SREG, r15
pop r15
ret
AppStats_OnEveryMinute_noIrq:
; ldi yl, LOW(netInterfaceData)
; ldi yh, HIGH(netInterfaceData)
; rcall AppNetwork_SendRxdStats ; debug
lds r16, appStatsTimer
inc r16
cpi r16, APP_STATS_INTERVAL_MINS
@@ -162,7 +149,7 @@ appStatsSend16BitValue:
ldi r20, 1
clr r21
ldi r22, AQHOME_VALUETYPE_STATS
bigjmp Main_SendValueReport
rjmp Main_SendValueReport
; @end

View File

@@ -1,30 +0,0 @@
; ***************************************************************************
; 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

@@ -38,8 +38,6 @@ DEBUG2:
; @clobbers (R16, R18, R22, R24, R25)
blinkLed:
sbi LED_SIMPLE_DDR, LED_SIMPLE_PINNUM ; out
blinkLed_loop:
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
mov r22, r20
rcall waitForMultiple100ms ; (R252
@@ -47,7 +45,7 @@ blinkLed_loop:
mov r22, r21
rcall waitForMultiple100ms ; (R22)
dec r19
brne blinkLed_loop
brne blinkLed
ret
@@ -76,7 +74,7 @@ waitFor10ms:
ldi r22, 100
waitFor10ms_loop:
push r22
bigcall Utils_WaitFor100MicroSecs
rcall Utils_WaitFor100MicroSecs
pop r22
dec r22
brne waitFor10ms_loop

View File

@@ -7,7 +7,6 @@
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
.error "Dont include this, use devices/all/defs.asm instead"
.equ AQHOME_VALUETYPE_UNKNOWN = 0

View File

@@ -25,14 +25,11 @@
<subdirs>
all
c01
c02
n16
n20
n21
n22
n23
n24
n25
t03
</subdirs>

View File

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

278
avr/devices/all/attn.asm Normal file
View File

@@ -0,0 +1,278 @@
; ***************************************************************************
; 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. *
; ***************************************************************************
; not used for now
; ***************************************************************************
; macros
.macro mAttnInitInt0
; select falling edge of ATTN
inr r16, MCUCR
cbr r16, (1<<ISC01) | (1<<ISC00)
sbr r16, (1<<ISC01) | (0<<ISC00)
outr MCUCR, r16
.endmacro
.macro mAttnInitPCI
in r16, GIMSK ; enable pin change irq PCIE0 or PCIE1
ori r16, (1<<COM_IRQ_GIMSK_ATTN)
out GIMSK, R16
ldi r16, (1<<COM_IRQ_GIFR_ATTN) ; clear pending irq by writing 1 to ATTN bit
out GIFR, r16
.endmacro
.macro mAttnEnableIrqInt0
inr r16, COM_IRQ_ADDR_ATTN
sbr r16, (1<<ATTN_IRQ_BIT)
outr COM_IRQ_ADDR_ATTN, r16
.endmacro
.macro mAttnEnableIrqPCI
sbi COM_IRQ_ADDR_ATTN, ATTN_IRQ_BIT ; enable pin change irq for ATTN line
.endmacro
.macro mAttnDisableIrqInt0
inr r16, COM_IRQ_ADDR_ATTN ; disable irq for ATTN line
cbr r16, (1<<ATTN_IRQ_BIT)
outr COM_IRQ_ADDR_ATTN, r16
.endmacro
.macro mAttnDisableIrqPCI
cbi COM_IRQ_ADDR_ATTN, ATTN_IRQ_BIT ; disable pin change irq for ATTN line
.endmacro
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine ATTN_Init @global
;
; @clobbers R16
ATTN_Init:
.ifdef INT0
.if ATTN_IRQ_BIT == INT0
mAttnInitInt0
.else
mAttnInitPCI
.endif
.else
mAttnInitPCI
.endif
rcall ATTN_SetHighEnableIrq
sec
ret
; @end
; ---------------------------------------------------------------------------
; @routine ATTN_SetLowDisableIrq @global
;
; @clobbers R16
ATTN_SetLowDisableIrq:
.ifdef INT0
.if ATTN_IRQ_BIT == INT0
mAttnDisableIrqInt0
.else
mAttnDisableIrqPCI
.endif
.else
mAttnDisableIrqPCI
.endif
sbi ATTN_DDR, ATTN_PIN ; set ATTN as output
cbi ATTN_OUTPUT, ATTN_PIN ; set ATTN low
ret
; @end
; ---------------------------------------------------------------------------
; @routine ATTN_SetHighEnableIrq @global
;
; @clobbers R16
ATTN_SetHighEnableIrq:
cbi ATTN_DDR, ATTN_PIN ; set ATTN as input
.ifdef ATTN_PUE
cbi ATTN_PUE, ATTN_PIN ; disable pullup on ATTN
.else
cbi ATTN_OUTPUT, ATTN_PIN ; disable pullup on ATTN
.endif
.ifdef INT0
.if ATTN_IRQ_BIT == INT0
mAttnEnableIrqInt0
.else
mAttnEnableIrqPCI
.endif
.else
mAttnEnableIrqPCI
.endif
ret
; @end
; ---------------------------------------------------------------------------
; @routine ATTN_IsHigh @global
;
; @return CFLAG set if ATTN is high
; @clobbers none
ATTN_IsHigh:
clc
sbic ATTN_INPUT, ATTN_PIN ; ATTN low?
sec ; yes, set CF
ret
; @end
; ---------------------------------------------------------------------------
; @routine ATTN_WaitForStateSeconds
;
; Wait for ATTN state max given seconds
;
; @return CFLAG set if okay (data available), cleared on error
; @param R16 expected state (0xff for high, 0 for low)
; @param r20 maximum number of seconds to wait
; @clobbers: r20, r22
ATTN_WaitForStateSeconds:
ATTN_WaitForStateSeconds_loop:
push r20
rcall ATTN_WaitForState1s ; (r20, r22)
pop r20
brcs ATTN_WaitForStateSeconds_gotit
sbi LED_PIN, LED_PINNUM ; toggle (doen't work on AtMega8515)
dec r20
brne ATTN_WaitForStateSeconds_loop
clc
ATTN_WaitForStateSeconds_gotit:
ret
; @end
; ---------------------------------------------------------------------------
; @routine ATTN_WaitForState1s
;
; Wait for ATTN state for max 1s
;
; @param R16 expected state (0xff for high, 0 for low)
; @return CFLAG set if okay (ATTN state reached), cleared on error
; @clobbers: r20, r22
ATTN_WaitForState1s:
ldi r20, 100
ATTN_WaitForState1s_loop:
push r20
rcall ATTN_WaitForState10ms ; (R20, R22)
pop r20
brcs ATTN_WaitForState1s_gotit
dec r20
brne ATTN_WaitForState1s_loop
clc
ATTN_WaitForState1s_gotit:
ret
; @end
; ---------------------------------------------------------------------------
; @routine ATTN_WaitForState10ms
;
; Wait for ATTN state for max 10 milliseconds.
;
; @param R16 expected state (0xff for high, 0 for low)
; @return CFLAG set if okay (ATTN state reached), cleared on error
; @clobbers: r20, r22
ATTN_WaitForState10ms:
.if clock == 8000000
ldi r20, 80
.endif
.if clock == 1000000
ldi r20, 10
.endif
ATTN_WaitForState10ms_loop:
push r20
rcall ATTN_WaitForState1000Cycles ; (r20, r22)
pop r20
brcs ATTN_WaitForState10ms_gotit
dec r20
brne ATTN_WaitForState10ms_loop
clc
ATTN_WaitForState10ms_gotit:
ret
; @end
; ---------------------------------------------------------------------------
; @routine ATTN_WaitForStateState1000Cycles
;
; Wait for ATTN state for max 1000 clock cycles
; (about 1ms at 1MHz, 0.125ms at 8MHz)
;
; @param R16 expected state (0xff for high, 0 for low)
; @return CFLAG set if okay (packet received), cleared on error
; @clobbers: r20, r22
ATTN_WaitForState1000Cycles:
ldi r20, 90 ; 1
ATTN_WaitForState1000Cycles_loop:
push r17 ; +2
in r17, COM_ATTN_INPUT ; +1
eor r17, r16 ; +1
andi r17, (1<<COM_ATTN_PIN) ; +1
pop r17 ; +2
breq ATTN_WaitForState1000Cycles_stateReached ; +1
dec r20 ; +1
brne ATTN_WaitForState1000Cycles_loop ; +2
clc
ret
ATTN_WaitForState1000Cycles_stateReached:
sec
ret
; @end

View File

@@ -7,6 +7,7 @@
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
; ---------------------------------------------------------------------------
; Value types

View File

@@ -1,136 +0,0 @@
; ***************************************************************************
; 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 AtMega 644P 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
out PORTA, r16 ; enable pull-up on all
out DDRB, r17 ; all input
out PORTB, r16 ; enable pull-up on all
out DDRC, r17 ; all input
out PORTC, r16 ; enable pull-up on all
out DDRD, r17 ; all input
out PORTD, r16 ; enable pull-up on all
ret
; @end
; ---------------------------------------------------------------------------
; @routine systemSetSpeed
;
systemSetSpeed:
ret
; @end
; ---------------------------------------------------------------------------
; @routine systemSleep
;
systemSleep:
; only modify SE, SM2, SM1 and SM0
cli
inr r16, SMCR
cbr r16, (1<<SE) | (0<<SM2) | (0<<SM1) | (0<<SM0)
outr SMCR, r16
sei ; make sure interrupts really are enabled
inr r16, SMCR ; enable sleep mode
sbr r16, (1<<SE)
outr SMCR, r16
sleep ; sleep, wait for interrupt
inr r16, SMCR ; disable sleep mode
cbr r16, (1<<SE)
outr SMCR, r16
ret
; @end
; ---------------------------------------------------------------------------
; @routine systemSetupTimer0
;
systemSetupTimer0: ; setup timer for IRQ every 100ms
ldi r16, (1<<WGM01) | (0<<WGM00) ; Prescaler 1024, CTC mode
outr TCCR0A, r16
ldi r16, (1<<CS02) | (0<<CS01) | (1<<CS00) | (0<<WGM02) ; Prescaler 1024, CTC mode
outr TCCR0B, r16
;
; Settings for clock 1Mhz (default)
; use timer0 with OCR0A=98-1 (irq every 97.65625 millisecs), baseTimerModuleReloadValue 1
;
.if clock == 1000000
; CMP-A interrupt about every 100ms
ldi r16, 98-1 ; (1,000,000/1024)/10 = 97.65625
outr OCR0A, r16
ldi r16, 1
sts baseTimerModuleReloadValue, r16
sts baseTimerModuleTickCounter, r16
.endif
;
; Settings for clock 8Mhz
; use timer0 with OCR0=78 (irq every 9.984 millisecs), baseTimerModuleReloadValue 10
;
.if clock == 8000000
; CMP interrupt about every 10ms
ldi r16, 78-1
outr OCR0A, r16
ldi r16, 10
sts baseTimerModuleReloadValue, r16
sts baseTimerModuleTickCounter, r16
.endif
ldi r16, (1<<OCF0A) ; clear pending interrupts
outr TIFR0, r16
inr r16, TIMSK0
sbr r16, (1<<OCIE0A) ; Timer/Counter0 Output Compare Match A Interrupt Enable
outr TIMSK0, r16
.endif
sec
ret
; @end

View File

@@ -72,14 +72,13 @@ systemSleep:
; only modify SE, SM1 and SM0
cli
in r16, MCUCR
cbr r16, (1<<SE) | (1<<SM1) | (1<<SM0)
out MCUCR, r16
sbr r16, (1<<SE) | (0<<SM1) | (0<<SM0) ; sleep mode "idle", enable
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
cbr r16, (1<<SE) | (1<<SM1) | (1<<SM0)
out MCUCR, r16
ret
; @end
@@ -91,7 +90,7 @@ systemSleep:
;
systemSetupTimer0: ; setup timer for IRQ every 100ms
ldi r16, (0<<WGM02) | (1<<CS02) | (0<<CS01) | (1<<CS00) ; Prescaler 1024
ldi r16, (1<<CS02) | (0<<CS01) | (1<<CS00) ; Prescaler 1024
out TCCR0B, r16
ldi r16, (1<<WGM01) | (0<<WGM00) ; CTC mode
@@ -126,12 +125,19 @@ systemSetupTimer0: ; setup timer for IRQ every 100ms
ldi r16, (1<<OCF0A) ; clear pending interrupts
.ifdef TIFR0
out TIFR0, r16
.else
out TIFR, r16
.endif
ldi r16, (1<<OCIE0A) ; Timer/Counter0 Output Compare Match A Interrupt Enable
.ifdef TIMSK0
out TIMSK0, r16
sec
.else
out TIMSK, r16
.endif
sec
ret
; @end

View File

@@ -54,8 +54,7 @@
#ifdef MODULES_UART_BITBANG
.include "modules/uart_bitbang2/defs.asm"
.include "modules/uart_bitbang2/iface.asm"
.include "modules/uart_bitbang2/bytelevel.asm"
.include "modules/uart_bitbang2/msglevel.asm"
.include "modules/uart_bitbang2/lowlevel.asm"
#endif
#ifdef MODULES_UART_HW
@@ -197,7 +196,6 @@
.include "apps/network/main.asm"
.include "modules/network/msg/reboot-d.asm"
.include "modules/network/msg/reboot-r.asm"
.include "modules/network/msg/pong-w.asm"
#endif

View File

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

View File

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

View File

@@ -13,9 +13,8 @@
.list
.include "../defs.asm"
.include "devices/all/defs.asm"
.include "defs_all.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
.include "common/utils_io.asm"

View File

@@ -67,11 +67,12 @@
.equ COM_BIT_LENGTH = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400
.equ COM_HALFBIT_LENGTH = 26000 ; see https://de.wikipedia.org/wiki/Universal_Asynchronous_Receiver_Transmitter
.equ COM_DATA_DDR = DDRD
.equ COM_DATA_DDR = DDRD ; use RX pin
.equ COM_DATA_INPUT = PIND
.equ COM_DATA_OUTPUT = PORTD
.equ COM_DATA_PIN = PORTD0
.equ COM_ATTN_DDR = DDRD
.equ COM_ATTN_INPUT = PIND
.equ COM_ATTN_OUTPUT = PORTD

View File

@@ -16,7 +16,6 @@
.include "include/m8515def.inc" ; Define device ATmega8515
.list
.include "version.asm"
.include "../defs.asm"
.include "./data.asm"
@@ -49,6 +48,11 @@
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
; #define MODULES_TIMER
#define MODULES_CLOCK
#define MODULES_XRAM
@@ -56,8 +60,9 @@
#define MODULES_LED_SIMPLE
#define MODULES_NETWORK
;#define MODULES_COMONUART0
;#define MODULES_UART_HW
#define MODULES_UART_BITBANG
#define MODULES_UART_HW
;#define MODULES_UART_BITBANG
#define MODULES_SPI_HW
#define MODULES_ILI9341
;#define MODULES_FONT_8X8
@@ -118,8 +123,7 @@
; ---------------------------------------------------------------------------
; Reset and interrupt vectors
rjmp BOOTLOADER_ADDR ; 1: Reset vector RESET
; rjmp NetUart_AttnChangeIsr ; 2: INT0 External Interrupt Request 0
rjmp UART_BitBang_PcintIsr ; 2: INT0 External Interrupt Request 0
rjmp NetUart_AttnChangeIsr ; 2: INT0 External Interrupt Request 0
reti ; 3: INT1 External Interrupt Request 1
reti ; 4: TIMER1_CAPT Timer/Counter1 Capture Event
reti ; 5: TIMER1_COMPA Timer/Counter1 Compare Match A
@@ -218,8 +222,7 @@ onEveryLoop:
; ---------------------------------------------------------------------------
; defines for network interface
;.equ netInterfaceData = netUartIface
.equ netInterfaceData = uart_bitbang_iface
.equ netInterfaceData = netUartIface
;.equ netInterfaceData = uart_bitbang_iface

View File

@@ -1,2 +0,0 @@
*.eep.hex
*.obj

View File

@@ -1,22 +0,0 @@
<?xml?>
<gwbuild>
<subdirs>
boot
main
</subdirs>
<data dist="true" install="$(datadir)/aqhome/devices/nodes">
aqua_c02.xml
</data>
<extradist>
defs.asm
README
</extradist>
</gwbuild>

View File

@@ -1,10 +0,0 @@
C01
===
- Role: Controller with Display
- MCU: AtMega 644P
- Connection: RJ45
- Periphery:
- Display with SPI

View File

@@ -1,24 +0,0 @@
<device name="aqua_c02" driver="nodes">
<manufacturer>AQUA</manufacturer>
<devicetype>C</devicetype>
<deviceversion>2</deviceversion>
<values>
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
<value name="stats_packets_in" id="0xe0" type="sensor" dataType="uint16" denom="1" />
<value name="stats_packets_out" id="0xe1" type="sensor" dataType="uint16" denom="1" />
<value name="stats_content_errors" id="0xe2" type="sensor" dataType="uint16" denom="1" />
<value name="stats_io_errors" id="0xe3" type="sensor" dataType="uint16" denom="1" />
<value name="stats_nobuf_errors" id="0xe4" type="sensor" dataType="uint16" denom="1" />
<value name="stats_collision_errors" id="0xe5" type="sensor" dataType="uint16" denom="1" />
<value name="stats_busy_errors" id="0xe6" type="sensor" dataType="uint16" denom="1" />
<value name="stats_heap_used" id="0xe7" type="sensor" dataType="uint16" denom="1" />
<value name="stats_heap_free" id="0xe8" type="sensor" dataType="uint16" denom="1" />
<value name="stats_noram_errors" id="0xe9" type="sensor" dataType="uint16" denom="1" />
</values>
</device>

View File

@@ -1,32 +0,0 @@
<?xml?>
<gwbuild>
<target type="AvrHexFile" name="c02_boot" >
<includes type="avrasm" >
-I $(builddir)
-I $(srcdir)
-I $(topsrcdir)/avr
-I $(topbuilddir)/avr
</includes>
<sources type="avrasm" >
boot.asm
</sources>
</target>
<subdirs>
</subdirs>
<extradist>
</extradist>
</gwbuild>

View File

@@ -1,160 +0,0 @@
; ***************************************************************************
; Source file for base system node on AtMega 644P
;
; This is for the maintenance system (i.e. the flash loader).
;
; All definitions and changes should go into this file.
; ***************************************************************************
.equ clock=8000000 ; Define the clock frequency
.nolist
.include "include/m644Pdef.inc" ; Define device ATmega8515
.list
.include "../defs.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
.include "common/utils_io.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
.equ NET_BUFFERS_NUM = 6
.equ NET_BUFFERS_SIZE = 32
; ---------------------------------------------------------------------------
; firmware settings
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
; ---------------------------------------------------------------------------
; LED
.equ LED_DDR = DDRD
.equ LED_PORT = PORTD
.equ LED_PIN = PIND
.equ LED_PINNUM = PORTD4
; ***************************************************************************
; code segment
.cseg
.org 0x0000
; ---------------------------------------------------------------------------
; Reset and interrupt vectors
jmp main ; 1: Reset vector RESET
jmp irqNotSet ; 2: INT0 External Interrupt Request 0
jmp irqNotSet ; 3: INT1 External Interrupt Request 1
jmp irqNotSet ; 4: INT2 External Interrupt Request 2
jmp irqNotSet ; 5: PCINT0 Pin Change Interrupt Request 0
jmp irqNotSet ; 6: PCINT1 Pin Change Interrupt Request 1
jmp irqNotSet ; 7: PCINT2 Pin Change Interrupt Request 2
jmp irqNotSet ; 8: PCINT3 Pin Change Interrupt Request 3
jmp irqNotSet ; 9: WDT Watchdog Time-out Interrupt
jmp irqNotSet ; 10: TIMER2_COMPA Timer/Counter2 Compare Match A
jmp irqNotSet ; 11: TIMER2_COMPB Timer/Counter2 Compare Match B
jmp irqNotSet ; 12: TIMER2_OVF Timer/Counter2 Overflow
jmp irqNotSet ; 13: TIMER1_CAPT Timer/Counter1 Capture Event
jmp irqNotSet ; 14: TIMER1_COMPA Timer/Counter1 Compare Match A
jmp irqNotSet ; 15: TIMER1_COMPB Timer/Counter1 Compare Match B
jmp irqNotSet ; 16: TIMER1_OVF Timer/Counter1 Overflow
jmp irqNotSet ; 17: TIMER0_COMPA Timer/Counter0 Compare Match A
jmp irqNotSet ; 18: TIMER0_COMPB Timer/Counter0 Compare Match B
jmp irqNotSet ; 19: TIMER0_OVF Timer/Counter0 Overflow
jmp irqNotSet ; 20: SPI_STC Serial Transfer Complete
jmp irqNotSet ; 21: USART0_RXC USART0 Rx Complete
jmp irqNotSet ; 22: USART0_UDRE USART0 Data Register Empty
jmp irqNotSet ; 23: USART0_TXC USART0 Tx Complete
jmp irqNotSet ; 24: ANA_COMP Analog Comparator
jmp irqNotSet ; 25: ADC ADC Conversion Complete
jmp irqNotSet ; 26: EE_RDY EEPROM Ready
jmp irqNotSet ; 27: TWI 2-Wire Interface
jmp irqNotSet ; 28: SPM_RDY Store Program Memory Ready
; ---------------------------------------------------------------------------
; Device Info Block
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; version, revision
firmwareVersion: .db FIRMWARE_VARIANT_BOOT, FIRMWARE_VERSION_MAJOR
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
firmwareStart:
jmp main ; will be overwritten when flashing
irqNotSet:
reti
; ***************************************************************************
; main code
.org BOOTLOADER_ADDR
main:
; ldi r16, 0xb0 ; orig: a0
; out OSCCAL, r16
jmp bootLoader ; this routine is in modules/bootloader/main.asm
; ***************************************************************************
; includes
.include "common/wait_10us.asm"
.include "common/utils_copy_from_flash.asm"
.include "common/utils_copy_sdram.asm"
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/flash1pmega.asm"
.include "modules/flash/flashxp.asm"
.include "modules/flash/flashprocess.asm"
.include "modules/flash/wait.asm"
.include "modules/bootloader/main.asm"
.include "modules/network/msg/defs.asm"
.include "modules/network/msg/crc.asm"
;.include "common/debug.asm"
systemSetSpeed:
; speed not changeable at runtime on this device
ret

View File

@@ -1,175 +0,0 @@
; ***************************************************************************
; 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. *
; ***************************************************************************
; ***************************************************************************
;
; AtMega644
; --------
; DSPLED PB0 1 40 PA0 DEV0
; DC PB1 2 39 PA1 DEV1
; INT2 PB2 3 38 PA2 DEV2
; DSPRES PB3 4 37 PA3 PA3
; SS PB4 5 36 PA4 PA4
; MOSI PB5 6 35 PA5
; MISO PB6 7 34 PA6
; SCK PB7 8 33 PA7
; /RESET 9 32 AREF
; VCC 10 31 GND
; GND 11 30 AVCC
; XTAL2 12 29 PC7
; XTAL1 13 28 PC6
; RXD PD0 14 27 PC5
; TXD PD1 15 26 PC4
; ATTN PD2 16 25 PC3
; INT1 PD3 17 24 PC2
; LED PD4 18 23 PC1
; PD5 19 22 PC0
; PD6 20 21 PD7
; --------
;
; ***************************************************************************
.equ BOOTLOADER_ADDR = 0x7c00
.equ FIRMWARE_VARIANT_BOOT = 0
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1
.equ DEVICEINFO_ID = 'C'
.equ DEVICEINFO_VERSION = 2
.equ DEVICEINFO_REVISION = 0
; ---------------------------------------------------------------------------
; LED module
.equ LED_SIMPLE_ONTIME = 1 ; shorter
.equ LED_SIMPLE_OFFTIME = 50 ; longer
.equ LED_SIMPLE_DDR = DDRD
.equ LED_SIMPLE_PORT = PORTD
.equ LED_SIMPLE_PORTIN = PIND
.equ LED_SIMPLE_PINNUM = PORTD4
; ---------------------------------------------------------------------------
; COM module
.equ COM_BIT_LENGTH = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400
.equ COM_HALFBIT_LENGTH = 26000 ; see https://de.wikipedia.org/wiki/Universal_Asynchronous_Receiver_Transmitter
.equ COM_DATA_DDR = DDRD
.equ COM_DATA_INPUT = PIND
.equ COM_DATA_OUTPUT = PORTD
.equ COM_DATA_PIN = PORTD0
.equ COM_ATTN_DDR = DDRD
.equ COM_ATTN_INPUT = PIND
.equ COM_ATTN_OUTPUT = PORTD
.equ COM_ATTN_PIN = PORTD2
.equ COM_IRQ_ADDR_ATTN = EIMSK
.equ COM_IRQ_BIT_ATTN = INT0
.equ COM_IRQ_GIFR_ATTN = INTF0
;.equ COM_IRQ_GIMSK_ATTN = PCIE0
; ---------------------------------------------------------------------------
; SPI hardware module
.equ SPIHW_SS_DDR = DDRB
.equ SPIHW_SS_INPUT = PINB
.equ SPIHW_SS_OUTPUT = PORTB
.equ SPIHW_SS_PIN = PORTB4
.equ SPIHW_MOSI_DDR = DDRB
.equ SPIHW_MOSI_INPUT = PINB
.equ SPIHW_MOSI_OUTPUT = PORTB
.equ SPIHW_MOSI_PIN = PORTB5
.equ SPIHW_MISO_DDR = DDRB
.equ SPIHW_MISO_INPUT = PINB
.equ SPIHW_MISO_OUTPUT = PORTB
.equ SPIHW_MISO_PIN = PORTB6
.equ SPIHW_SCK_DDR = DDRB
.equ SPIHW_SCK_INPUT = PINB
.equ SPIHW_SCK_OUTPUT = PORTB
.equ SPIHW_SCK_PIN = PORTB7
.equ SPIHW_SS0_DDR = DDRA
.equ SPIHW_SS0_OUTPUT = PORTA
.equ SPIHW_SS0_INPUT = PORTA
.equ SPIHW_SS0_PIN = PORTA0
.equ SPIHW_SS1_DDR = DDRA
.equ SPIHW_SS1_OUTPUT = PORTA
.equ SPIHW_SS1_INPUT = PORTA
.equ SPIHW_SS1_PIN = PORTA1
.equ SPIHW_SS2_DDR = DDRA
.equ SPIHW_SS2_OUTPUT = PORTA
.equ SPIHW_SS2_INPUT = PORTA
.equ SPIHW_SS2_PIN = PORTA2
; ---------------------------------------------------------------------------
; ILI9341 module
.equ ILI9341_DEVICENUM = 0
.equ ILI9341_DSP_WIDTH = 320
.equ ILI9341_DSP_HEIGHT = 240
.equ ILI9341_RESET_DDR = DDRB
.equ ILI9341_RESET_OUTPUT = PORTB
.equ ILI9341_RESET_INPUT = PORTB
.equ ILI9341_RESET_PIN = PORTB3
.equ ILI9341_DC_DDR = DDRB
.equ ILI9341_DC_OUTPUT = PORTB
.equ ILI9341_DC_INPUT = PORTB
.equ ILI9341_DC_PIN = PORTB1
.equ ILI9341_LED_DDR = DDRB
.equ ILI9341_LED_OUTPUT = PORTB
.equ ILI9341_LED_INPUT = PORTB
.equ ILI9341_LED_PIN = PORTB0
; ---------------------------------------------------------------------------
; ComOnUart module
;.equ USART0_DATAREG = UDR
;.equ UCSR0A = UCSRA
;.equ UCSR0B = UCSRB
;.equ UCSR0C = UCSRC
;.equ UBRR0L = UBRRL
;.equ UBRR0H = UBRRH
;.equ UCSZ00 = UCSZ0
;.equ UCSZ01 = UCSZ1
;.equ UDRE0 = UDRE
;.equ RXC0 = RXC
;.equ TXC0 = TXC
;.equ FE0 = FE
;.equ DOR0 = DOR
;.equ UPE0 = UPE
;.equ RXEN0 = RXEN
;.equ TXEN0 = TXEN
;.equ USBS0 = USBS
;.equ RXCIE0 = RXCIE
;.equ UDRIE0 = UDRIE

View File

@@ -1,34 +0,0 @@
<?xml?>
<gwbuild>
<target type="AvrHexFile" name="c02_firmware" >
<includes type="avrasm" >
-I $(builddir)
-I $(srcdir)
-I $(topsrcdir)/avr
-I $(topbuilddir)/avr
</includes>
<sources type="avrasm" >
main.asm
</sources>
</target>
<subdirs>
</subdirs>
<extradist>
data.asm
</extradist>
</gwbuild>

View File

@@ -1,14 +0,0 @@
; ***************************************************************************
; 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

View File

@@ -1,240 +0,0 @@
; ***************************************************************************
; 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 clock=1000000 ; Define the clock frequency
.equ clock=8000000 ; Define the clock frequency
.nolist
.include "include/m644Pdef.inc" ; Define device ATmega644P
.list
.include "version.asm"
.include "../defs.asm"
.include "./data.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
.include "common/utils_io.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
.equ NET_BUFFERS_NUM = 8
.equ NET_BUFFERS_SIZE = 32
; ---------------------------------------------------------------------------
; heap
.equ HEAP_START = SRAM_START+0x200
.equ HEAP_SIZE = SRAM_SIZE-HEAP_START
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
; #define MODULES_TIMER
#define MODULES_CLOCK
;#define MODULES_XRAM
#define MODULES_HEAP
#define MODULES_LED_SIMPLE
#define MODULES_NETWORK
;#define MODULES_COMONUART0
;#define MODULES_UART_HW
#define MODULES_UART_BITBANG
#define MODULES_SPI_HW
#define MODULES_ILI9341
;#define MODULES_FONT_8X8
#define MODULES_FONT_6X8
;#define MODULES_UART_BITBANG
;#define MODULES_TWI_MASTER
;#define MODULES_LCD
;#define LCD_MINIMAL_FONT
;#define MODULES_SI7021
;#define MODULES_SGP30
;#define MODULES_SGP40
;#define MODULES_STATS
;#define MODULES_OWI_MASTER
;#define MODULES_DS18B20
;#define MODULES_MOTION
;#define MODULES_CCS811
#define APPS_NETWORK
;#define APPS_MOTION
;#define APPS_REPORTSENSORS
#define APPS_STATS
; ---------------------------------------------------------------------------
; defines for values
.equ VALUE_ID_SI7021_TEMP = 0x01
.equ VALUE_ID_SI7021_HUM = 0x02
.equ VALUE_ID_ADC = 0x03
;.equ VALUE_ID_DS18B20_TEMP = 0x06
.equ VALUE_ID_MOTION = 0x07
.equ VALUE_ID_SGP40_TVOC = 0x08
.equ VALUE_ID_SGP30_TVOC = 0x09
.equ VALUE_ID_SGP30_CO2 = 0x0a
;.equ VALUE_ID_REED_CONF = 0x81
.equ VALUE_ID_DEBUG = 0x7f
.equ VALUE_ID_LEDSIMPLE_TIMING = 0x88
; ***************************************************************************
; code segment
.cseg
.org 000000
; ---------------------------------------------------------------------------
; Reset and interrupt vectors
jmp BOOTLOADER_ADDR ; 1: Reset vector RESET
jmp UART_BitBang_PcintIsr ; 2: INT0 External Interrupt Request 0
jmp irqNotSet ; 3: INT1 External Interrupt Request 1
jmp irqNotSet ; 4: INT2 External Interrupt Request 2
jmp irqNotSet ; 5: PCINT0 Pin Change Interrupt Request 0
jmp irqNotSet ; 6: PCINT1 Pin Change Interrupt Request 1
jmp irqNotSet ; 7: PCINT2 Pin Change Interrupt Request 2
jmp irqNotSet ; 8: PCINT3 Pin Change Interrupt Request 3
jmp irqNotSet ; 9: WDT Watchdog Time-out Interrupt
jmp irqNotSet ; 10: TIMER2_COMPA Timer/Counter2 Compare Match A
jmp irqNotSet ; 11: TIMER2_COMPB Timer/Counter2 Compare Match B
jmp irqNotSet ; 12: TIMER2_OVF Timer/Counter2 Overflow
jmp irqNotSet ; 13: TIMER1_CAPT Timer/Counter1 Capture Event
jmp irqNotSet ; 14: TIMER1_COMPA Timer/Counter1 Compare Match A
jmp irqNotSet ; 15: TIMER1_COMPB Timer/Counter1 Compare Match B
jmp irqNotSet ; 16: TIMER1_OVF Timer/Counter1 Overflow
jmp baseTimerIrqOC0A ; 17: TIMER0_COMPA Timer/Counter0 Compare Match A
jmp irqNotSet ; 18: TIMER0_COMPB Timer/Counter0 Compare Match B
jmp irqNotSet ; 19: TIMER0_OVF Timer/Counter0 Overflow
jmp irqNotSet ; 20: SPI_STC Serial Transfer Complete
jmp irqNotSet ; 21: USART0_RXC USART0 Rx Complete
jmp irqNotSet ; 22: USART0_UDRE USART0 Data Register Empty
jmp irqNotSet ; 23: USART0_TXC USART0 Tx Complete
jmp irqNotSet ; 24: ANA_COMP Analog Comparator
jmp irqNotSet ; 25: ADC ADC Conversion Complete
jmp irqNotSet ; 26: EE_RDY EEPROM Ready
jmp irqNotSet ; 27: TWI 2-Wire Interface
jmp irqNotSet ; 28: SPM_RDY Store Program Memory Ready
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; version, revision
firmwareVersion: .db FIRMWARE_VARIANT_TEMP_WINDOW, FIRMWARE_VERSION_MAJOR
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
; ---------------------------------------------------------------------------
; @routine firmwareStart @global
firmwareStart:
rjmp main
; @end
irqNotSet:
reti
; ---------------------------------------------------------------------------
; @routine onSystemStart
onSystemStart:
ret
; @end
; ---------------------------------------------------------------------------
; @routine onMessageReceived
;
; Called on every message received
onMessageReceived:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine onEvery100ms
;
; Called every 100ms. Add your routine calls here. No arguments, no results.
onEvery100ms:
onEverySecond:
onEveryMinute:
onEveryHour:
onEveryDay:
ret
; @end
; ---------------------------------------------------------------------------
; @routine onEveryLoop
;
; Called on every loop (i.e. after awakening from sleep).
;
onEveryLoop:
ret
; @end
; ***************************************************************************
; includes
.include "devices/all/hw_m644p.asm"
.include "devices/all/includes.asm"
.include "common/debug.asm"
; ---------------------------------------------------------------------------
; defines for network interface
;.equ netInterfaceData = netUartIface
.equ netInterfaceData = uart_bitbang_iface

View File

@@ -12,20 +12,32 @@
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "version.asm"
.include "../defs.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
;.include "modules/com2/defs.asm"
;.include "modules/comproto/defs.asm"
.include "defs_all.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
.include "common/utils_wait.asm"
.include "modules/com2/defs.asm"
.include "modules/comproto/defs.asm"
; ---------------------------------------------------------------------------
; firmware settings
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
; ---------------------------------------------------------------------------
; LED

View File

@@ -30,12 +30,9 @@
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "version.asm"
.include "../defs.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
@@ -54,6 +51,11 @@
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
#define MODULES_CLOCK
#define MODULES_LED_SIMPLE
#define MODULES_NETWORK

View File

@@ -12,18 +12,32 @@
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "version.asm"
.include "./defs.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
.include "defs_all.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
.include "common/utils_wait.asm"
.include "modules/com2/defs.asm"
.include "modules/comproto/defs.asm"
; ---------------------------------------------------------------------------
; firmware settings
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
; ---------------------------------------------------------------------------
; LED
@@ -99,7 +113,6 @@ main:
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashxp.asm"
.include "modules/flash/flashprocess.asm"
.include "modules/flash/wait.asm"
.include "modules/bootloader/main.asm"
@@ -108,6 +121,7 @@ main:
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)

View File

@@ -30,12 +30,8 @@
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "version.asm"
.include "./defs.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
.include "defs_all.asm"
@@ -45,37 +41,31 @@
; ---------------------------------------------------------------------------
; generic
.equ NET_BUFFERS_NUM = 4
.equ NET_BUFFERS_SIZE = 32
.include "common/utils_wait.asm"
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
; #define MODULES_TIMER
#define MODULES_CLOCK
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
#define MODULES_TIMER
#define MODULES_COM
#define MODULES_COM_WITH_ADDR_PROTO
#define MODULES_LED_SIMPLE
#define MODULES_NETWORK
#define MODULES_UART_BITBANG
#define MODULES_TWI_MASTER
;#define MODULES_LCD
;#define LCD_MINIMAL_FONT
#define LCD_MINIMAL_FONT
#define MODULES_SI7021
;#define MODULES_STATS
#define MODULES_STATS
;#define MODULES_OWI_MASTER
;#define MODULES_DS18B20
;#define MODULES_MOTION
;#define MODULES_TCRT1000
;#define MODULES_CCS811
#define APPS_NETWORK
;#define APPS_MOTION
;#define APPS_DOOR
#define APPS_REPORTSENSORS
#define APPS_STATS
#define MODULES_MOTION
#define MODULES_CCS811
; ---------------------------------------------------------------------------
; defines for values
@@ -96,8 +86,6 @@
.equ VALUE_ID_DEBUG = 0x7f
.equ VALUE_ID_LEDSIMPLE_TIMING = 0x88
; ***************************************************************************
@@ -114,7 +102,7 @@
; rjmp main ; Reset vector
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp UART_BitBang_PcintIsr ; PCI0
rjmp uartBitbangIsrPcint0 ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
@@ -138,85 +126,351 @@ devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; v
firmwareVersion: .db FIRMWARE_VARIANT_TEMP_WINDOW, FIRMWARE_VERSION_MAJOR
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
; ---------------------------------------------------------------------------
; @routine firmwareStart @global
firmwareStart:
rjmp main
; @end
; ---------------------------------------------------------------------------
; @routine onSystemStart
onSystemStart:
ret
; @end
; ---------------------------------------------------------------------------
; @routine onMessageReceived
;
; Called on every message received
onMessageReceived:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine onEvery100ms
;
; Called every 100ms. Add your routine calls here. No arguments, no results.
onEvery100ms:
onEverySecond:
onEveryMinute:
onEveryHour:
onEveryDay:
ret
; @end
; ---------------------------------------------------------------------------
; @routine onEveryLoop
;
; Called on every loop (i.e. after awakening from sleep).
;
onEveryLoop:
ret
; @end
firmwareStart: rjmp main
; ***************************************************************************
; includes
.include "devices/all/hw_tn84.asm"
.include "devices/all/includes.asm"
.include "common/utils.asm"
.include "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"
.include "common/utils_copy_sdram.asm"
.include "common/crc8.asm"
;.include "common/debug.asm"
.include "modules/basetimer/main.asm"
#ifdef MODULES_TIMER
.include "modules/timer/main.asm"
#endif
#ifdef MODULES_LED
.include "modules/led/main.asm"
#endif
#ifdef MODULES_LED_SIMPLE
.include "modules/led_simple/main.asm"
#endif
#ifdef MODULES_COM
.include "modules/com2/defs.asm"
.include "modules/com2/main.asm"
.include "modules/com2/buffer.asm"
.include "modules/uart_bitbang/defs.asm"
.include "modules/uart_bitbang/main.asm"
.include "modules/uart_bitbang/bytelevel.asm"
.include "modules/uart_bitbang/packetlevel.asm"
#ifdef MODULES_COM_WITH_ADDR_PROTO
.include "modules/comproto/defs.asm"
.include "modules/comproto/main.asm"
.include "modules/comproto/addr.asm"
.include "modules/comproto/msg_recvstats.asm"
.include "modules/comproto/msg_sendstats.asm"
.include "modules/comproto/msg_sysstats.asm"
.include "modules/comproto/msg_memstats.asm"
.include "modules/comproto/msg_pong.asm"
.include "modules/comproto/msg_value.asm"
.include "modules/comproto/msg_device.asm"
.include "modules/comproto/msg_reboot.asm"
#endif
#ifdef MODULES_LCD
.include "modules/com2/screen.asm"
.include "modules/comproto/screen.asm"
#endif
#endif
#ifdef MODULES_TWI_MASTER
.include "modules/twimaster/main.asm"
#endif
#ifdef MODULES_OWI_MASTER
.include "modules/owimaster/main.asm"
#endif
#ifdef MODULES_LCD
.include "modules/lcd/main.asm"
#endif
#ifdef MODULES_SI7021
.include "modules/si7021/main.asm"
#endif
#ifdef MODULES_DS18B20
.include "modules/ds18b20/main.asm"
#endif
#ifdef MODULES_STATS
.include "modules/stats/main.asm"
#endif
#ifdef MODULES_CNY70
.include "modules/cny70/main.asm"
#endif
#ifdef MODULES_REED
.include "modules/reed/main.asm"
#endif
#ifdef MODULES_MOTION
.include "modules/motion/main.asm"
#endif
#ifdef MODULES_CCS811
.include "modules/ccs811/main.asm"
#endif
; test
;#include "modules/uart_irq/defs.asm"
;#include "modules/uart_irq/iface.asm"
;#include "modules/uart_irq/iface1.asm"
; ***************************************************************************
; data in SRAM
.dseg
programRamBegin:
#ifdef MODULES_LCD
screenCounter: .byte 1
#endif
programRamEnd:
#ifdef MODULES_LCD
sramTimerWriteStats: .byte 2
sramTimerScreen: .byte 2
#endif
#ifdef MODULES_SI7021
sramTimerSI7021Measure: .byte 2
sramTimerSI7021SendTemp: .byte 2
sramTimerSI7021SendHumidity: .byte 2
#endif
#ifdef MODULES_CNY70
sramTimerCny70SendAdc: .byte 2
#endif
#ifdef MODULES_LCD
sramPeriodicalLcdMark: .byte 2
#endif
#ifdef MODULES_DS18B20
sramDs18b20Timer: .byte 2
sramSendDs18b20TempTimer: .byte 2
#endif
#ifdef MODULES_CCS811
sramCcs811Timer: .byte 2
#endif
; ***************************************************************************
; data in FLASH
.cseg
; ---------------------------------------------------------------------------
; defines for network interface
; timer list
.equ netInterfaceData = uart_bitbang_iface
timerList:
; SRAM variable/counter routine flags secs (0=don't start or restart)
#ifdef MODULES_COM_WITH_ADDR_PROTO
.dw cproAddresModeTimer, CPRO_Address_OnTimer, 0, 0 ; (no restart)
#endif
#ifdef MODULES_STATS
.dw statsSendTimer, Stats_Timer, TIMER_FLAGS_IF_ADDR, 9000 ; every 15m
#endif
#ifdef MODULES_LCD
; .dw sramPeriodicalLcdMark, periodicalLcdMark, 0, 20 ; every 2s
; .dw sramTimerWriteStats, writeStats, 0, 100
.dw sramTimerScreen, printScreen, TIMER_FLAGS_IF_ADDR, 50 ; every 5s
#endif
#ifdef MODULES_SI7021
.dw sramTimerSI7021Measure, SI7021_OnTimer, 0, 300 ; every 30s
.dw sramTimerSI7021SendTemp, sendSI7021Temp, TIMER_FLAGS_IF_ADDR, 600 ; every 60s
.dw sramTimerSI7021SendHumidity, sendSI7021Humidity, TIMER_FLAGS_IF_ADDR, 600 ; every 60s
#endif
#ifdef MODULES_CNY70
.dw sramTimerCny70SendAdc, CNY70_OnTimer, TIMER_FLAGS_IF_ADDR, 50 ; every 5s
#endif
#ifdef MODULES_DS18B20
.dw sramDs18b20Timer, Ds18b20_OnTimer, 0, 300 ; every 30s
.dw sramSendDs18b20TempTimer, sendDs18b20Temp, TIMER_FLAGS_IF_ADDR, 600 ; every 60s
#endif
#ifdef MODULES_CCS811
.dw sramCcs811Timer, CCS811_OnTimer, 0, 10 ; every 1s
#endif
.dw 0 ; end of list
.include "main_all.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
ret
systemSetBootSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret
; ---------------------------------------------------------------------------
; Called on first time run, i.e. on system start. No arguments, no results.
onSystemStart:
ldi xh, HIGH(programRamBegin)
ldi xl, LOW(programRamBegin)
clr r16
ldi r17, (programRamEnd-programRamBegin)
rcall Utils_FillSram
ret
#ifdef MODULES_LCD
printScreen:
lds r16, screenCounter
tst r16
brne printScreen_l1
rcall CPRO_Screen
rjmp printScreen_counter
printScreen_l1:
cpi r16, 1
brne printScreen_l2
rcall COM2_Screen_RecvStats
rjmp printScreen_counter
printScreen_l2:
; cpi r16, 2
; brne printScreen_l3
; rcall COM2_Screen_SendStats
; rjmp printScreen_counter
printScreen_l3:
; add more screens here
printScreen_counter:
lds r16, screenCounter
inc r16
cpi r16, 2 ; number of screens
brcs printScreen_store
clr r16
printScreen_store:
sts screenCounter, r16
printScreen_end:
ret
;periodicalLcdMark:
; rcall printTimerMark
; ret
;writeStats:
; rcall printSendStats
; ret
#endif
#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
; ---------------------------------------------------------------------------
; Called every 100ms. Add your routine calls here. No arguments, no results.
onEvery100ms:
#ifdef MODULES_LED_SIMPLE
rcall LedSimple_Every100ms
#endif
#ifdef MODULES_REED
rcall REED_Every100ms
#endif
#ifdef MODULES_MOTION
rcall Motion_Every100ms
#endif
ret
; ---------------------------------------------------------------------------
; @routine onPacketReceived:
;
; Called after a packet was received via COM module. Add your routine calls here.
;
; The packet will be released in any case after return from this call.
;
; @return CFLAG set if message handled, cleared otherwise
; @param X pointer to received buffer
; @clobbers all
onPacketReceived:
#ifdef MODULES_MOTION_LIGHT
rcall MotionLight_OnPacketReceived
brcs onPacketReceived_end
#endif
#ifdef MODULES_SK6812
rcall SK6812_OnPacketReceived
brcs onPacketReceived_end
#endif
#ifdef MODULES_REED
rcall REED_OnPacketReceived
brcs onPacketReceived_end
#endif
#ifdef MODULES_COM
rcall CPRO_OnPacketReceived
brcs onPacketReceived_end
#endif
clc
onPacketReceived_end:
ret
; @end

View File

@@ -12,18 +12,31 @@
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "version.asm"
.include "../defs.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
.include "common/utils_wait.asm"
.include "modules/com2/defs.asm"
.include "modules/comproto/defs.asm"
; ---------------------------------------------------------------------------
; firmware settings
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
; ---------------------------------------------------------------------------
; LED

View File

@@ -30,12 +30,10 @@
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "version.asm"
.include "../defs.asm"
.include "./data.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
@@ -55,6 +53,11 @@
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
; #define MODULES_TIMER
#define MODULES_CLOCK
#define MODULES_LED_SIMPLE

View File

@@ -14,20 +14,29 @@
.include "include/tn85def.inc" ; Define device ATtiny85
.list
.include "version.asm"
.include "../defs.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
.include "modules/com2/defs.asm"
.include "modules/comproto/defs.asm"
.include "defs_all.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
.include "common/utils_wait.asm"
.include "modules/com2/defs.asm"
.include "modules/comproto/defs.asm"
; ---------------------------------------------------------------------------
; firmware settings
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
; ---------------------------------------------------------------------------
; LED

View File

@@ -22,13 +22,10 @@
.include "include/tn85def.inc" ; Define device ATtiny85
.list
.include "version.asm"
.include "../defs.asm"
;.include "./data.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
@@ -47,6 +44,11 @@
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
#define MODULES_CLOCK
#define MODULES_LED_SIMPLE
#define MODULES_NETWORK

View File

@@ -12,12 +12,8 @@
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "version.asm"
.include "../defs.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
.include "defs_all.asm"
#define COM_ACCEPT_ALL_DEST
@@ -27,6 +23,22 @@
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
.include "common/utils_wait.asm"
; ---------------------------------------------------------------------------
; firmware settings
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
; ---------------------------------------------------------------------------
; LED

View File

@@ -30,12 +30,10 @@
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "version.asm"
.include "../defs.asm"
.include "./data.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
@@ -57,6 +55,11 @@
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
; #define MODULES_TIMER
#define MODULES_CLOCK
#define MODULES_LED_SIMPLE

View File

@@ -1,13 +1,3 @@
; ***************************************************************************
; 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. *
; ***************************************************************************
; ***************************************************************************
; Source file for base system node on AtTiny 84
;
@@ -22,11 +12,8 @@
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "version.asm"
.include "../defs.asm"
.include "common/calls.asm"
.include "devices/all/defs.asm"
.include "defs_all.asm"
#define COM_ACCEPT_ALL_DEST
@@ -48,6 +35,10 @@
; ---------------------------------------------------------------------------
; firmware settings
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
; ---------------------------------------------------------------------------

View File

@@ -13,7 +13,7 @@
; AtTiny84
; --------
; VCC 1 14 GND
; AUX-PB0 PB0 2 13 PA0 AUX-PA0
; AUX-PB2 PB0 2 13 PA0 AUX-PA0
; PIR PB1 3 12 PA1 COM-DATA
; /RESET PB3 4 11 PA2 AUX-PA2
; PB2 5 10 PA3 LED

View File

@@ -33,9 +33,7 @@
.include "../defs.asm"
.include "./data.asm"
.include "version.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
@@ -57,6 +55,11 @@
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
; #define MODULES_TIMER
#define MODULES_CLOCK
#define MODULES_LED_SIMPLE

View File

@@ -1,2 +0,0 @@
*.eep.hex
*.obj

View File

@@ -1,21 +0,0 @@
<?xml?>
<gwbuild>
<subdirs>
boot
main
</subdirs>
<data dist="true" install="$(datadir)/aqhome/devices/nodes">
aqua_n25.xml
</data>
<extradist>
defs.asm
README
</extradist>
</gwbuild>

View File

@@ -1,18 +0,0 @@
N25
===
- Role: LED strip controller
- MCU: AtTiny84
- Connection: RJ45
- Predecessor: N22, N16
- UART: uart_bitbang2
- Periphery:
- LED strip connection (SK6812)
- OWI interface
- DS18B20 temperature sensor
- Apps:
- NETWORK: Basic network functionality (address setup etc.)
- REPORTSENSORS: report sensor data from temperature sensor etc.
- STATS : periodically send stats data
- MA_LIGHT : motion activated light

View File

@@ -1,33 +0,0 @@
<device name="aqua_n25" driver="nodes">
<manufacturer>AQUA</manufacturer>
<devicetype>N</devicetype>
<deviceversion>25</deviceversion>
<values>
<value name="DS18B20_TEMP" id="0x06" type="sensor" dataType="rational" modality="temperature" units="C" denom="16" />
<value name="NUMLEDS" id="0x82" type="actor" dataType="int" />
<value name="RGBWVALUE" id="0x83" type="actor" dataType="dword" />
<value name="MALRGBWVALUE" id="0x84" type="actor" dataType="dword" />
<value name="MALONTIME" id="0x85" type="actor" dataType="uint16" />
<value name="MALSOURCE1" id="0x86" type="actor" dataType="uint16" />
<value name="MALSOURCE2" id="0x87" type="actor" dataType="uint16" />
<value name="stats_packets_in" id="0xe0" type="sensor" dataType="uint16" denom="1" />
<value name="stats_packets_out" id="0xe1" type="sensor" dataType="uint16" denom="1" />
<value name="stats_content_errors" id="0xe2" type="sensor" dataType="uint16" denom="1" />
<value name="stats_io_errors" id="0xe3" type="sensor" dataType="uint16" denom="1" />
<value name="stats_nobuf_errors" id="0xe4" type="sensor" dataType="uint16" denom="1" />
<value name="stats_collision_errors" id="0xe5" type="sensor" dataType="uint16" denom="1" />
<value name="stats_busy_errors" id="0xe6" type="sensor" dataType="uint16" denom="1" />
<value name="stats_heap_used" id="0xe7" type="sensor" dataType="uint16" denom="1" />
<value name="stats_heap_free" id="0xe8" type="sensor" dataType="uint16" denom="1" />
<value name="stats_noram_errors" id="0xe9" type="sensor" dataType="uint16" denom="1" />
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
</values>
</device>

View File

@@ -1,32 +0,0 @@
<?xml?>
<gwbuild>
<target type="AvrHexFile" name="n25_boot" >
<includes type="avrasm" >
-I $(builddir)
-I $(srcdir)
-I $(topsrcdir)/avr
-I $(topbuilddir)/avr
</includes>
<sources type="avrasm" >
boot.asm
</sources>
</target>
<subdirs>
</subdirs>
<extradist>
</extradist>
</gwbuild>

View File

@@ -1,130 +0,0 @@
; ***************************************************************************
; Source file for base system node on AtTiny 84
;
; This is for the maintenance system (i.e. the flash loader).
;
; All definitions and changes should go into this file.
;
;
; ***************************************************************************
.equ clock=1000000 ; Define the clock frequency
.nolist
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "version.asm"
.include "../defs.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; LED
.equ LED_DDR = DDRA
.equ LED_PORT = PORTA
.equ LED_PIN = PINA
.equ LED_PINNUM = PORTA3
; ***************************************************************************
; code segment
.cseg
.org 0x0000
; ---------------------------------------------------------------------------
; Reset and interrupt vectors
rjmp main ; 1: Reset vector
reti ; 2: EXT_INT0
reti ; 3: PCI0
reti ; 4: PCI1
reti ; 5: WDT
reti ; 6: TIM1_CAPT
reti ; 7: TIM1_COMPA
reti ; 8: TIM1_COMPB
reti ; 9: TIM1_OVF
reti ; 10: TIM0_COMPA
reti ; 11: TIM0_COMPB
reti ; 12: TIM0_OVF
reti ; 13: ANA_COMP
reti ; 14: ADC
reti ; 15: EE_RDY
reti ; 16: USI_STR
reti ; 17: USI_OVF
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; version, revision
firmwareVersion: .db FIRMWARE_VARIANT_BOOT, FIRMWARE_VERSION_MAJOR
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
firmwareStart:
rjmp main ; will be overwritten when flashing
; ***************************************************************************
; main code
.org BOOTLOADER_ADDR
main:
rjmp bootLoader ; this routine is in modules/bootloader/main.asm
; ***************************************************************************
; includes
.include "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"
.include "common/utils_copy_sdram.asm"
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/flashxp.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashprocess.asm"
.include "modules/flash/wait.asm"
.include "modules/bootloader/main.asm"
.include "modules/network/msg/defs.asm"
.include "modules/network/msg/crc.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
.if clock == 1000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret

View File

@@ -1,90 +0,0 @@
; ***************************************************************************
; 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. *
; ***************************************************************************
; ***************************************************************************
;
; AtTiny84
; --------
; VCC 1 14 GND
; OWI PB0 2 13 PA0
; PB1 3 12 PA1 COM-DATA
; PB3 4 11 PA2
; PB2 5 10 PA3 LED
; COM_ATTN PA7 6 9 PA4 LED_CLK
; LED_DATA PA6 7 8 PA5
; --------
;
; ***************************************************************************
.equ BOOTLOADER_ADDR = 0xd00
.equ FIRMWARE_VARIANT_BOOT = 0
.equ FIRMWARE_VARIANT_LEDSTRIPS = 1
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 25
.equ DEVICEINFO_REVISION = 0
; ---------------------------------------------------------------------------
; LED module
.equ LED_SIMPLE_ONTIME = 1
.equ LED_SIMPLE_OFFTIME = 50
.equ LED_SIMPLE_DDR = DDRA
.equ LED_SIMPLE_PORT = PORTA
.equ LED_SIMPLE_PORTIN = PINA
.equ LED_SIMPLE_PINNUM = PORTA3
; ---------------------------------------------------------------------------
; COM module
.equ COM_BIT_LENGTH = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400
.equ COM_HALFBIT_LENGTH = 26000 ; see https://de.wikipedia.org/wiki/Universal_Asynchronous_Receiver_Transmitter
.equ COM_DATA_DDR = DDRA
.equ COM_DATA_INPUT = PINA
.equ COM_DATA_OUTPUT = PORTA
.equ COM_DATA_PIN = PORTA1
.equ COM_ATTN_DDR = DDRA
.equ COM_ATTN_INPUT = PINA
.equ COM_ATTN_OUTPUT = PORTA
.equ COM_ATTN_PIN = PORTA7
.equ COM_IRQ_ADDR_ATTN = PCMSK0
.equ COM_IRQ_BIT_ATTN = PCINT7 ; bit 7 in PCMSK0 (PCINT7)
.equ COM_IRQ_GIFR_ATTN = PCIF0
.equ COM_IRQ_GIMSK_ATTN = PCIE0
; ---------------------------------------------------------------------------
; 1-Wire Master
;
.equ OWI_DDR = DDRB
.equ OWI_PORTOUT = PORTB
.equ OWI_PORTIN = PINB
.equ OWI_PINNUM = PORTB0
; ---------------------------------------------------------------------------
; SK6812
.equ SK6812_DDR = DDRA
.equ SK6812_PORT = PORTA
.equ SK6812_PINNUM = PORTA6

View File

@@ -1,33 +0,0 @@
<?xml?>
<gwbuild>
<target type="AvrHexFile" name="n25_firmware" >
<includes type="avrasm" >
-I $(builddir)
-I $(srcdir)
-I $(topsrcdir)/avr
-I $(topbuilddir)/avr
</includes>
<sources type="avrasm" >
main.asm
</sources>
</target>
<subdirs>
</subdirs>
<extradist>
</extradist>
</gwbuild>

View File

@@ -1,217 +0,0 @@
; ***************************************************************************
; 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. *
; ***************************************************************************
; ***************************************************************************
; Source file for LED controller node on AtTiny 84
;
; This is for the full system (i.e. not the boot loader).
; ***************************************************************************
.equ clock=8000000 ; Define the clock frequency
.nolist
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "version.asm"
.include "../defs.asm"
;.include "./data.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
.equ NET_BUFFERS_NUM = 6
.equ NET_BUFFERS_SIZE = 32
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
#define MODULES_CLOCK
#define MODULES_LED_SIMPLE
#define MODULES_NETWORK
#define MODULES_UART_BITBANG
#define MODULES_OWI_MASTER
#define MODULES_DS18B20
#define MODULES_SK6812
;#define MODULES_MOTION_LIGHT
#define APPS_NETWORK
#define APPS_REPORTSENSORS
#define APPS_STATS
#define APPS_MA_LIGHT
; ---------------------------------------------------------------------------
; defines for modules
;.equ VALUE_ID_SI7021_TEMP = 0x01
;.equ VALUE_ID_SI7021_HUM = 0x02
;.equ VALUE_ID_ADC = 0x03
;.equ VALUE_ID_REED1 = 0x04
;.equ VALUE_ID_REED2 = 0x05
.equ VALUE_ID_DS18B20_TEMP = 0x06
;.equ VALUE_ID_REED_CONF = 0x81
.equ VALUE_ID_LED_NUMLEDS = 0x82
.equ VALUE_ID_LED_RGBW_VALUE = 0x83
.equ VALUE_ID_MAL_RGBW_VALUE = 0x84
.equ VALUE_ID_MAL_ONTIME = 0x85
.equ VALUE_ID_MAL_SOURCE1 = 0x86
.equ VALUE_ID_MAL_SOURCE2 = 0x87
.equ VALUE_ID_LEDSIMPLE_TIMING = 0x88
; ***************************************************************************
; code segment
.cseg
.org 000000
; ---------------------------------------------------------------------------
; Reset and interrupt vectors
rjmp BOOTLOADER_ADDR ; 1: Reset vector ; use this for flashed system
reti ; 2: EXT_INT0
#ifdef MODULES_UART_BITBANG
rjmp UART_BitBang_PcintIsr ; 3: PCI0
#else
reti ; 3: PCI0
#endif
reti ; 4: PCI1
reti ; 5: WDT
reti ; 6: TIM1_CAPT
reti ; 7: TIM1_COMPA
reti ; 8: TIM1_COMPB
reti ; 9: TIM1_OVF
rjmp baseTimerIrqOC0A ; 10: TIM0_COMPA
reti ; 11: TIM0_COMPB
reti ; 12: TIM0_OVF
reti ; 13: ANA_COMP
reti ; 14: ADC
reti ; 15: EE_RDY
reti ; 16: USI_STR
reti ; 17: USI_OVF
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; version, revision
firmwareVersion: .db FIRMWARE_VARIANT_LEDSTRIPS, FIRMWARE_VERSION_MAJOR
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
; ---------------------------------------------------------------------------
; @routine firmwareStart @global
firmwareStart:
rjmp main
; @end
; ---------------------------------------------------------------------------
; @routine onSystemStart
onSystemStart:
ret
; @end
; ---------------------------------------------------------------------------
; @routine onMessageReceived
;
; Called on every message received
onMessageReceived:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine onEvery100ms
;
; Called every 100ms. Add your routine calls here. No arguments, no results.
onEvery100ms:
onEveryMinute:
onEveryHour:
onEveryDay:
ret
; @end
onEverySecond:
ret
#if 0
; debug
ldi r19, 0x00 ; G
ldi r18, 0xff ; R
ldi r20, 0x55 ; B
ldi r21, 0xaa ; W
rcall SK6812_SetAllColor ; r23 (r16, r17)
#endif
ret
; ---------------------------------------------------------------------------
; @routine onEveryLoop
;
; Called on every loop (i.e. after awakening from sleep).
;
onEveryLoop:
ret
; @end
; ***************************************************************************
; includes
.include "devices/all/hw_tn84.asm"
.include "devices/all/includes.asm"
;.include "common/debug.asm"
; ---------------------------------------------------------------------------
; defines for network interface
#ifdef MODULES_UART_BITBANG
.equ netInterfaceData = uart_bitbang_iface
#endif

View File

@@ -13,18 +13,28 @@
.include "include/tn841def.inc" ; Define device ATtiny841
.list
.include "version.asm"
.include "../defs.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
.include "defs_all.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
.include "common/utils_wait.asm"
; ---------------------------------------------------------------------------
; firmware settings
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
;#define COM_ACCEPT_ALL_DEST 1

View File

@@ -30,12 +30,8 @@
.list
.include "../defs.asm"
.include "version.asm"
;.include "defs_all.asm"
.include "defs_all.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
.include "common/utils_io.asm"
@@ -51,6 +47,10 @@
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
#define MAIN_WITHOUT_MSG_HANDLING ; we do message handling ourselfes

View File

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

View File

@@ -42,14 +42,13 @@ flash1pMegaWritePage:
ldi xl, LOW(flashPageBuffer)
ldi xh, HIGH(flashPageBuffer)
ldi r24, LOW(PAGESIZE)
ldi r25, HIGH(PAGESIZE)
flash1pMegaWritePages_loop:
ld r0, X+ ; read source data from buffer (low)
ld r1, X+ ; read source data from buffer (high)
ldi r20, (1<<SPMEN) ; enable next SPM, write R1:R0 into temp page buffer
rcall flashDoSpm ; (R16)
adiw zh:zl, 2
sbiw r25:r24, 1
dec r24
brne flash1pMegaWritePages_loop
subi zl, LOW(PAGESIZE*2) ; point back to begin of page

View File

@@ -7,8 +7,6 @@
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
; Code for large pagesizes (128 and larger)
; ***************************************************************************
; code
@@ -94,7 +92,7 @@ flashWriteData:
flashWriteData_beginPage:
rcall flashBeginPage ; (r16, r24, r25, X)
flashWriteData_calcPosAndLength:
rcall flashCalcPosAndLength ; r18=bytes_to_write, x=pos_in_buffer (r19, r24, r25)
rcall flashCalcPosAndLength ; r18=bytes_to_write, x=pos_in_buffer (r24, r25)
; X=abs pos in buffer, r18=bytes to read, r17=bytes initially requested
; prepare data for return
sub r17, r18 ; r17 holds remainder
@@ -119,30 +117,24 @@ flashWriteData_copyLoop:
; @param R17 number of bytes to write
; @return X absolute write position inside buffer
; @return R18 bytes to write
; @clobbers r19, r24, r25
; @clobbers r24, r25
flashCalcPosAndLength:
; calc offset into buffer
mov r24, zl
mov r25, zh
andi r24, LOW(FLASH_PAGESIZE-1)
andi r25, HIGH(FLASH_PAGESIZE-1) ; R25:r24=pos inside page
ldi r18, LOW(FLASH_PAGESIZE)
ldi r19, HIGH(FLASH_PAGESIZE)
sub r18, r24
sbc r19, r25 ; R19:R18=FLASH_PAGESIZE-relPos
tst r19 ; high byte zero?
breq flashCalcPosAndLength_8bit ; yes, already 8-bit
ldi r18, 255 ; clip size to 8 bit
flashCalcPosAndLength_8bit:
cp r17, r18 ; r18>r17?
brcc flashCalcPosAndLength_sizeOk ; nope: jump
mov r18, r17 ; clip r18 to size requested
flashCalcPosAndLength_sizeOk: ; r18=bytes to write
ldi xl, LOW(flashPageBuffer) ; set X to pos within page buffer
andi r24, (FLASH_PAGESIZE-1) ; r24=rel pos inside buffer
ldi r25, FLASH_PAGESIZE
sub r25, r24 ; r25=bytes left inside page
mov r18, r17
cp r25, r17 ; bytes to read > bytes left in page?
brcc flashCalcPosAndLength_l1 ; no: jump
mov r18, r25 ; yes: cut r18 to number of bytes left in page
flashCalcPosAndLength_l1:
ldi xl, LOW(flashPageBuffer) ; set X to pos within page buffer
ldi xh, HIGH(flashPageBuffer)
add xl, r24
adc xh, r25
adc xh, r24
sub xh, r24
ret
; @end
@@ -253,17 +245,17 @@ flashEndPage_write:
; @routine flashReadPageIntoSram
;
; @param Z Address to read from (byte address as for LPM!)
; @clobbers r16, r24, r25, X, Z
; @clobbers r16, r24, X, Z
flashReadPageIntoSram:
ldi xl, LOW(flashPageBuffer)
ldi xh, HIGH(flashPageBuffer)
ldi r24, LOW(FLASH_PAGESIZE)
ldi r25, HIGH(FLASH_PAGESIZE)
flashReadPageIntoSram_loop:
lpm r16, Z+
st X+, r16
sbiw r25:r24, 1
; adiw ZH:ZL, 1
dec r24
brne flashReadPageIntoSram_loop
ret
; @end

View File

@@ -189,7 +189,7 @@ ioRawReceivePacketIntoBuffer:
breq ioRawReceivePacketIntoBuffer_acceptAddr
cpi r16, 0xff
breq ioRawReceivePacketIntoBuffer_acceptAddr
clr r16 ; not for me
ldi r16, COM2_ERROR_NOTFORME
rjmp ioRawReceivePacketIntoBuffer_error ; clc/ret
#endif
ioRawReceivePacketIntoBuffer_acceptAddr:

View File

@@ -0,0 +1,170 @@
; ***************************************************************************
; 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 UARTSOFT_WAITFORSYNCSTART = 200
; ***************************************************************************
; code
.cseg
uartSoftWaitAndReadSyncByte:
; wait for begin of startbit
ldi r24, LOW(UARTSOFT_WAITFORSYNCSTART)
ldi r25, HIGH(UARTSOFT_WAITFORSYNCSTART)
uartSoftWaitAndReadSyncByte_loop0:
sbis COM_DATA_INPUT, COM_DATA_PIN
rjmp uartSoftWaitAndReadSyncByte_gotStartBit
sbiw r25:r24, 1
brne uartSoftWaitAndReadSyncByte_loop0
uartSoftWaitAndReadSyncByte_error: ; timeout
clc
ret
uartSoftWaitAndReadSyncByte_gotStartBit:
clr r25
clr r24
; count cycles while DATA low (count length of startBit)
uartSoftWaitAndReadSyncByte_loopLow: ; 5 cycles per loop +3 cycles to leave loop
sbic COM_DATA_INPUT, COM_DATA_PIN ; +2 (skip)/+1 (no skip)
rjmp uartSoftWaitAndReadSyncByte_startDataBit1 ; +0 (skip) / +2 (no skip)
adiw r25:r24, 1 ; +1
brne uartSoftWaitAndReadSyncByte_loopLow ; +2
rjmp uartSoftWaitAndReadSyncByte_error
uartSoftWaitAndReadSyncByte_startDataBit1:
clr r25
clr r24
ldi r17, 4
uartSoftWaitAndReadSyncByte_loopData:
; count cycles while DATA high (count length of dataBit)
uartSoftWaitAndReadSyncByte_loopDataHigh: ; 5 cycles per loop +3 cycles to leave loop
sbis COM_DATA_INPUT, COM_DATA_PIN ; +2 (skip)/+1 (no skip)
rjmp uartSoftWaitAndReadSyncByte_startLowDataBit ; +0 (skip) / +2 (no skip)
adiw r25:r24, 1 ; +1
brne uartSoftWaitAndReadSyncByte_loopDataHigh ; +2
; too long LOW
rjmp uartSoftWaitAndReadSyncByte_error
uartSoftWaitAndReadSyncByte_startLowDataBit:
; count cycles while DATA low (count length of dataBit)
uartSoftWaitAndReadSyncByte_loopDataLow: ; 5 cycles per loop +3 cycles to leave loop
sbic COM_DATA_INPUT, COM_DATA_PIN ; +2 (skip)/+1 (no skip)
rjmp uartSoftWaitAndReadSyncByte_startHighDataBit ; +0 (skip) / +2 (no skip)
adiw r25:r24, 1 ; +1
brne uartSoftWaitAndReadSyncByte_loop4 ; +2
; too long LOW
rjmp uartSoftWaitAndReadSyncByte_error
uartSoftWaitAndReadSyncByte_startHighDataBit:
dec r17
brne uartSoftWaitAndReadSyncByte_loopData
; calc average (8 values)
lsr r25 ; /2
ror r24
lsr r25 ; /4
ror r24
lsr r25 ; /8
ror r24
sec
ret
; @end
uartSoftReceiveByte:
; wait for begin of startbit
ldi r24, LOW(UARTSOFT_WAITFORSYNCSTART)
ldi r25, HIGH(UARTSOFT_WAITFORSYNCSTART)
uartSoftReceiveByte_waitForBeginOfStartBit:
sbis COM_DATA_INPUT, COM_DATA_PIN
rjmp uartSoftReceiveByte_gotBeginOfStartBit
sbiw r25:r24, 1
brne uartSoftReceiveByte_waitForBeginOfStartBit
uartSoftReceiveByte_error: ; timeout
clc
ret
uartSoftReceiveByte_gotBeginOfStartBit:
clr r25
clr r24
; count cycles while DATA low (count length of startBit)
uartSoftReceiveByte_waitForEndOfStartBit: ; 5 cycles per loop
sbic COM_DATA_INPUT, COM_DATA_PIN ; +2 (skip)/+1 (no skip)
rjmp uartSoftReceiveByte_gotEndOfStartBit ; +0 (skip) / +2 (no skip)
adiw r25:r24, 1 ; +1
brne uartSoftWaitAndReadSyncByte_loopLow ; +2
rjmp uartSoftReceiveByte_error
uartSoftReceiveByte_gotEndOfStartBit:
; r25:r24=counter equivalent for length of startbit
clr r16
ldi r17, 8
uartSoftReceiveByte_bitLoop:
; TODO: receive 8bits, wait for start of endbit
ret
uartSoftCountDataLow: ; 5 cycles per loop +5 cycles outside (+3 cycles RCALL)
sbic COM_DATA_INPUT, COM_DATA_PIN ; +2 (skip)/+1 (no skip)
rjmp uartSoftCountDataLow_ok ; +0 (skip) / +2 (no skip)
adiw r25:r24, 1 ; +1
brne uartSoftCountDataLow ; +2
clc
ret
uartSoftCountDataLow_ok:
sec
ret
; @end
uartSoftCountDataHigh: ; 5 cycles per loop +5 cycles outside (+3 cycles RCALL)
sbis COM_DATA_INPUT, COM_DATA_PIN ; +2 (skip)/+1 (no skip)
rjmp uartSoftCountDataHigh_ok ; +0 (skip) / +2 (no skip)
adiw r25:r24, 1 ; +1
brne uartSoftCountDataHigh ; +2
clc
ret
uartSoftCountDataHigh_ok:
sec ; +1
ret ; +4
; @end
uartSoftWaitBitTime: ; 5 cycles per loop +5 cycles outside (+3 cycles RCALL)
uartSoftWaitBitTime_loop:
nop ; +1
nop ; +1
sbiw r25:r24, 1 ; +1
brne uartSoftWaitBitTime_loop ; +2
nop ; +1
ret ; +4
; @end

View File

@@ -40,8 +40,8 @@
.equ NET_IFACE_OFFS_ERR_IO_HIGH = 15
.equ NET_IFACE_OFFS_ERR_NOBUF_LOW = 16
.equ NET_IFACE_OFFS_ERR_NOBUF_HIGH = 17
.equ NET_IFACE_OFFS_ERR_MSGSIZE_LOW = 18
.equ NET_IFACE_OFFS_ERR_MSGSIZE_HIGH = 19
.equ NET_IFACE_OFFS_HANDLED_LOW = 18
.equ NET_IFACE_OFFS_HANDLED_HIGH = 19
.equ NET_IFACE_OFFS_ERR_MISSED_LOW = 20
.equ NET_IFACE_OFFS_ERR_MISSED_HIGH = 21

View File

@@ -12,7 +12,6 @@
debug-w.asm
device-w.asm
memstats-w.asm
pong-w.asm
reboot-d.asm
reboot-r.asm
recvstats-w.asm

View File

@@ -29,7 +29,7 @@ NETMSG_Device_Write:
ldi zh, HIGH(devInfoBlock*2) ; 6-17: devInfoBlock
ldi zl, LOW(devInfoBlock*2)
ldi r18, 12
bigcall Utils_CopyFromFlash ; (R17, R18, X, Z)
rcall 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)

View File

@@ -1,37 +0,0 @@
; ***************************************************************************
; 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. *
; ***************************************************************************
; ---------------------------------------------------------------------------
; @routine NETMSG_Pong_Write @global
;
; @param R16 dest addr
; @param Y pointer to device to write msg for and to
; @param X pointer to buffer to write to
; @clobbers R16 (R17, R18, R19, R20, R21, Z)
NETMSG_Pong_Write:
st X+, r16 ; dest address
ldi r16, 6 ; msg code+src address+4 payload bytes
st X+, r16 ; msg len
ldi r16, NETMSG_CMD_PONG
st X+, r16 ; msg code
ldd r16, Y+NET_IFACE_OFFS_ADDRESS
st X+, r16 ; src address
rcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21)
sbiw xh:xl, 8 ; go back to beginning of message (1 byte dst addr, 1 byte length, 6 bytes payload)
rcall NETMSG_CalcAndAddChecksumByte ; (R16, R17, R18, R19, R20, X)
sbiw xh:xl, 9 ; go back to beginning of message (1 byte dst addr, 1 byte length, 6 bytes payload, 1 byte crc)
ret
; @end

View File

@@ -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
bigcall Utils_Copy_SDRAM ; (R17, R18, X, Y)
rcall 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)

View File

@@ -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
bigcall Utils_Copy_SDRAM ; (R17, R18, X, Y)
rcall 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)

View File

@@ -3,11 +3,10 @@
<gwbuild>
<extradist>
bytelevel.asm
defs.asm
iface.asm
lowlevel.asm
main.asm
msglevel.asm
</extradist>
</gwbuild>

View File

@@ -1,229 +0,0 @@
; ***************************************************************************
; 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. *
; ***************************************************************************
; ***************************************************************************
; macros
; ---------------------------------------------------------------------------
; @macro UART_BB_M_WAIT_FOR_PIN_LOW IN_REG_DATA, IN_PINNUM
; 0 1
; Wait for a pin to become low
; @param %0 DATA register for input pin (e.g. PINB)
; @param %1 pin number for input (e.g. PORTB1)
; @return CFLAG set if okay, clear otherwise
; @clobbers R17, R22
.macro UART_BB_M_WAIT_FOR_PIN_LOW
ldi r17, 200
l_loop:
sbis @0, @1
rjmp l_reached
Utils_WaitNanoSecs 5000, 0, r22 ; wait for 5us
dec r17
brne l_loop
clc
rjmp l_end
l_reached:
sec
l_end:
.endmacro
; @end
; ---------------------------------------------------------------------------
; @macro UART_BB_M_WAIT_FOR_PIN_HIGH IN_REG_DATA, IN_PINNUM
; 0 1
; Wait for a pin to become high (up to 1ms)
; @param %0 DATA register for input pin (e.g. PINB)
; @param %1 pin number for input (e.g. PORTB1)
; @return CFLAG set if okay, clear otherwise
; @clobbers R17, R22
.macro UART_BB_M_WAIT_FOR_PIN_HIGH
ldi r17, 200
l_loop:
sbic @0, @1
rjmp l_reached
Utils_WaitNanoSecs 5000, 0, r22 ; wait for 5us
dec r17
brne l_loop
clc
rjmp l_end
l_reached:
sec
l_end:
.endmacro
; @end
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine uartBitbang_SendByte
;
; Send a byte.
; We only set the data pin to low at the beginning for the startbit. After that
; we only change the pin direction (e.g. input vs output):
; - for 0 bit: set DDR to output, forcing the data line low
; - for 1 bit: set DDR to input, letting the external pullup R pull the data line to HIGH
; since the output pin is still set to 0 the internal pullup is disabled
; Expects interrupts to be disabled.
;
; @param R16 byte to send
; @return CFLAG set if okay, clear otherwise
; @clobbers R16, R21, R22
uartBitbang_SendByte:
cbi COM_DATA_DDR, COM_DATA_PIN ; set DATA port as input
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; disable internal pullup for DATA
ldi r21, 8 ; +1 bits left
; send startbit
sbi COM_DATA_DDR, COM_DATA_PIN ; +2 set DATA as output
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; +2 set DATA low
Utils_WaitNanoSecs COM_BIT_LENGTH, 1, r22 ; wait for one bit duration
; send data bits
uartBitbang_SendByte_loop: ; 11 for low bit
lsr r16 ; 1+ bit to send -> CARRY
brcs uartBitbang_SendByte_setHigh ; HI: +2, LO: +1
uartBitbang_SendByte_setLow:
sbi COM_DATA_DDR, COM_DATA_PIN ; +2 set DATA as output
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; +2 set DATA low
rjmp uartBitbang_SendByte_wait ; +2
uartBitbang_SendByte_setHigh:
cbi COM_DATA_DDR, COM_DATA_PIN ; +2 set DATA as input, pullup R makes it ONE
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; +2 disable internal pullup for DATA
nop ; +1
nop ; +1
uartBitbang_SendByte_wait:
Utils_WaitNanoSecs COM_BIT_LENGTH, 12, r22
uartBitbang_SendByte_loopEnd:
dec r21 ; +1
brne uartBitbang_SendByte_loop ; +2, sum per loop: 11 cycles
; send stopbit
cbi COM_DATA_DDR, COM_DATA_PIN ; +2 set DATA as input, pullup R makes it ONE
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; +2 disable internal pullup for DATA
Utils_WaitNanoSecs COM_BIT_LENGTH, 1, r22 ; wait for one bit length
sec
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbangReceiveByte
;
; Read a byte.
; Expects interrupts to be disabled.
;
; @return CFLAG set if okay, clear otherwise
; @return R16 byte received
; @clobbers R16, R17, R20, R21, R22
uartBitbang_ReceiveByte:
cbi COM_DATA_DDR, COM_DATA_PIN ; set DATA port as input
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; disable internal pullup for RXD
ldi r21, 8 ; bits left
clr r20 ; byte currently receiving
; wait for startbit
ldi r16, 10
uartBitbang_ReceiveByte_loopStartBit1:
ldi r17, 100 ; wait for 100us
uartBitbang_ReceiveByte_loopStartBit2:
sbis COM_DATA_INPUT, COM_DATA_PIN
rjmp uartBitbang_ReceiveByte_gotStartBit
Utils_WaitNanoSecs 1000, 0, r22 ; wait for 1us
dec r17
brne uartBitbang_ReceiveByte_loopStartBit2
dec r16
brne uartBitbang_ReceiveByte_loopStartBit1
rjmp uartBitbang_ReceiveByte_error
uartBitbang_ReceiveByte_gotStartBit:
Utils_WaitNanoSecs COM_HALFBIT_LENGTH, 0, r22 ; goto middle of startbit to maximize sync stability (4)
uartBitbang_ReceiveByte_loop:
Utils_WaitNanoSecs COM_BIT_LENGTH, 8, r22 ; 8 cycles used in the complete loop between waits
sec ; +1
sbic COM_DATA_INPUT, COM_DATA_PIN ; LOW: +2, HIGH: +1
rjmp uartBitbang_ReceiveByte_shiftIn ; HIGH: +2, rjmp, use set CFLAG
clc ; LOW: +1
uartBitbang_ReceiveByte_shiftIn:
ror r20 ; +1
dec r21 ; +1
brne uartBitbang_ReceiveByte_loop ; +2, sum per loop: 8 cycles
rcall uartBitbang_WaitForDataHigh ; wait for start of stopbit
brcc uartBitbang_ReceiveByte_error
mov r16, r20
sec
ret
uartBitbang_ReceiveByte_error:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_WaitForDataLow
;
; Wait up to 1ms for data pin to become low
; @return CFLAG set if okay, clear otherwise
; @clobbers R17, R22
uartBitbang_WaitForDataLow:
cbi COM_DATA_DDR, COM_DATA_PIN ; set DATA port as input
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; disable internal pullup for TXD
UART_BB_M_WAIT_FOR_PIN_LOW COM_DATA_INPUT, COM_DATA_PIN
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_WaitForDataHigh
;
; Wait up to 1ms for data pin to become high
; @return CFLAG set if okay, clear otherwise
; @clobbers R17, R22
uartBitbang_WaitForDataHigh:
cbi COM_DATA_DDR, COM_DATA_PIN ; set DATA port as input
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; disable internal pullup for TXD
UART_BB_M_WAIT_FOR_PIN_HIGH COM_DATA_INPUT, COM_DATA_PIN
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_WaitForOneBitLength
;
; wait for one bit length (minus cycles for call and ret).
;
; @clobbers r22
uartBitbang_WaitForOneBitLength:
Utils_WaitNanoSecs COM_BIT_LENGTH, 7, r22 ; wait for one bit duration (minus RCALL/RET)
ret
; @end

View File

@@ -20,41 +20,13 @@
; ***************************************************************************
; macros
.macro mUartBitbangSetupInt0
inr r16, MCUCR
cbr r16, (1<<ISC01) | (1<<ISC00)
sbr r16, (1<<ISC01) | (0<<ISC00) ; falling edge of ATTN
outr MCUCR, r16
; sbr r16, (0<<ISC01) | (0<<ISC00) ; low level triggers
inr r16, COM_IRQ_ADDR_ATTN ; enable irq for ATTN line
sbr r16, (1<<COM_IRQ_BIT_ATTN)
outr COM_IRQ_ADDR_ATTN, r16
.endmacro
.macro mUartBitbangSetupPci
sbi COM_IRQ_ADDR_ATTN, COM_IRQ_BIT_ATTN ; enable pin change irq for ATTN line
in r16, GIMSK ; enable pin change irq PCIE0 or PCIE1
ori r16, (1<<COM_IRQ_GIMSK_ATTN)
out GIMSK, R16
ldi r16, (1<<COM_IRQ_GIFR_ATTN) ; clear pending irq by writing 1 to ATTN bit
out GIFR, r16
.endmacro
; ***************************************************************************
; data
.dseg
uart_bitbang_iface: .byte NET_IFACE_SIZE
uart_bitbang_iface: .byte NET_IFACE_SIZE
@@ -78,30 +50,12 @@ UART_BitBang_Init:
rcall NET_Interface_Init ; (R16, R17, X)
; init hw
cbi COM_DATA_DDR, COM_DATA_PIN ; set TXD port as input
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; disable internal pullup for DATA
cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN port as input
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable internal pullup for ATTN
; enable IRQ
.ifdef INT0
.if COM_IRQ_BIT_ATTN == INT0
mUartBitbangSetupInt0
.else
mUartBitbangSetupPci
.endif
.else
mUartBitbangSetupPci
.endif
#if 0
sbi COM_IRQ_ADDR_ATTN, COM_IRQ_BIT_ATTN ; enable pin change irq for ATTN line
in r16, GIMSK ; enable pin change irq PCIE0 or PCIE1
ori r16, (1<<COM_IRQ_GIMSK_ATTN)
out GIMSK, R16
ldi r16, (1<<COM_IRQ_GIFR_ATTN) ; clear pending irq by writing 1 to ATTN bit
out GIFR, r16
#endif
sec
ret
@@ -119,7 +73,6 @@ UART_BitBang_Fini:
cbi COM_DATA_DDR, COM_DATA_PIN ; set TXD port as input
cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN port as input
#if 0
cbi COM_IRQ_ADDR_ATTN, COM_IRQ_BIT_ATTN ; disable pin change irq for ATTN line
in r16, GIMSK ; enable pin change irq PCIE0 or PCIE1
andi r16, ~(1<<COM_IRQ_GIMSK_ATTN)
@@ -127,8 +80,6 @@ UART_BitBang_Fini:
ldi r16, (1<<COM_IRQ_GIFR_ATTN) ; clear pending irq by writing 1 to ATTN bit
out GIFR, r16
#endif
ret
; @end
@@ -173,12 +124,16 @@ uartBitBang_sendNextPkg:
rcall NET_Buffer_Locate ; get pointer to buffer (R17)
brcc uartBitBang_sendNextPkg_end
adiw xh:xl, 1 ; skip buffer header
rcall uartBitbang_SendMsg ; (R16, R17, R21, R22, R24, R25, X)
brcc uartBitBang_sendNextPkg_end
rcall uartBitbang_SendPacket ; (R16, R17, R21, R22, X)
brcc uartBitBang_sendNextPkg_error
rcall NET_Interface_GetNextOutgoingMsgNum ; remove from stack (R17, R18, X)
rcall NET_Buffer_ReleaseByNum ; release buffer (R16, X)
ldi r16, NET_IFACE_OFFS_PACKETSOUT_LOW
rcall NET_Interface_IncCounter16 ; (R24, R25)
sec
rjmp uartBitBang_sendNextPkg_end
uartBitBang_sendNextPkg_error:
rcall NET_Interface_IncCounter16 ; (R24, R25)
uartBitBang_sendNextPkg_end:
ret
; @end
@@ -190,38 +145,73 @@ uartBitBang_sendNextPkg_end:
;
; Receive packet.
;
; @param Y pointer to start of interface data
; @clobbers R16, R17, R18, R19, R20, R21, R22, R24, R25, X
; @return CFLAG set if okay (packet received), cleared on error
; @clobbers R16, R17, X (R18, R19, R20, R21, R22, R24, R25)
uartBitbang_receiveNextPkg:
rcall NET_Buffer_Alloc ; R16=buffer num (R16, R17, X)
rcall NET_Buffer_Alloc ; (R16, R17, X)
brcs uartBitbang_receiveNextPkg_gotBuffer
ldi r16, NET_IFACE_OFFS_ERR_NOBUF_LOW
rcall NET_Interface_IncCounter16 ; (R24, R25)
clc
rjmp uartBitbang_receiveNextPkg_end
uartBitbang_receiveNextPkg_gotBuffer:
push r16 ; buffer number
adiw xh:xl, 1
ldd r18, Y+NET_IFACE_OFFS_ADDRESS
ldi r19, NET_BUFFERS_SIZE-1
rcall uartBitbang_ReceiveAndCheckMsg ; (R16, R17, R19, R20, R21, R22, R24, R25)
pop r16
brcc uartBitbang_receiveNextPkg_relBuffer
rcall NET_AddIncomingMsgNum ; (R17, R18, X)
brcs uartBitbang_receiveNextPkg_end
push r16
ldi r16, NET_IFACE_OFFS_ERR_MISSED_LOW
rcall NET_Interface_IncCounter16 ; (R24, R25)
pop r16
; fall-through to release buffer
uartBitbang_receiveNextPkg_relBuffer:
rcall uartBitbang_receiveAndCheckPkg ; (r16, r17, r18, r19, r20, r21, r22, X)
pop r17 ; pop buffer number to R17
brcs uartBitbang_receiveNextPkg_gotPkg
tst r16 ; error code=0: pkg not for me
breq uartBitbang_receiveNextPkg_RelBuffer
uartBitbang_receiveNextPkg_incCntRelBuffer:
rcall NET_Interface_IncCounter16 ; (R24, R25)
uartBitbang_receiveNextPkg_RelBuffer:
mov r16, r17
rcall NET_Buffer_ReleaseByNum ; (R16, X)
clc
rjmp uartBitbang_receiveNextPkg_end
uartBitbang_receiveNextPkg_gotPkg:
mov r16, r17
rcall NET_AddIncomingMsgNum ; (R17, R18, X)
ldi r16, NET_IFACE_OFFS_ERR_NOBUF_LOW
brcc uartBitbang_receiveNextPkg_incCntRelBuffer
ldi r16, NET_IFACE_OFFS_PACKETSIN_LOW
rcall NET_Interface_IncCounter16 ; (R24, R25)
sec
uartBitbang_receiveNextPkg_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_receiveAndCheckPkg
;
; Receive a packet into buffer pointed to by X and CRC check it.
; Expects interrupts to be disabled.
;
; @param X buffer to receive to
; @param Y pointer to start of interface data
; @return CFLAG set if okay (packet received), cleared on error
; @return R16 error var offset if CFLAG is cleared
; @clobbers: r16 (r17, r18, r19, r20, r21, r22, X)
uartBitbang_receiveAndCheckPkg:
ldd r16, Y+NET_IFACE_OFFS_ADDRESS
ldi r17, (NET_BUFFERS_SIZE-2)
push xl
push xh
rcall uartBitbang_ReceivePacketIntoBuffer ; (r16, r17, r18, r19, r20, r21, r22, X)
pop xh
pop xl
brcc uartBitbang_receiveAndCheckPkg_end
rcall NETMSG_CheckMessageInBuffer ; (R16, R17, R18, R19, R20, X)
ldi r16, NET_IFACE_OFFS_ERR_CONTENT_LOW
uartBitbang_receiveAndCheckPkg_end:
ret
; @end

View File

@@ -0,0 +1,368 @@
; ***************************************************************************
; 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
; ---------------------------------------------------------------------------
; @macro UART_BB_M_WAIT_FOR_PIN_LOW IN_REG_DATA, IN_PINNUM
; 0 1
; Wait for a pin to become low
; @param %0 DATA register for input pin (e.g. PINB)
; @param %1 pin number for input (e.g. PORTB1)
; @return CFLAG set if okay, clear otherwise
; @clobbers R17, R22
.macro UART_BB_M_WAIT_FOR_PIN_LOW
ldi r17, 200
l_loop:
sbis @0, @1
rjmp l_reached
Utils_WaitNanoSecs 5000, 0, r22 ; wait for 5us
dec r17
brne l_loop
clc
rjmp l_end
l_reached:
sec
l_end:
.endmacro
; @end
; ---------------------------------------------------------------------------
; @macro UART_BB_M_WAIT_FOR_PIN_HIGH IN_REG_DATA, IN_PINNUM
; 0 1
; Wait for a pin to become high (up to 1ms)
; @param %0 DATA register for input pin (e.g. PINB)
; @param %1 pin number for input (e.g. PORTB1)
; @return CFLAG set if okay, clear otherwise
; @clobbers R17, R22
.macro UART_BB_M_WAIT_FOR_PIN_HIGH
ldi r17, 200
l_loop:
sbic @0, @1
rjmp l_reached
Utils_WaitNanoSecs 5000, 0, r22 ; wait for 5us
dec r17
brne l_loop
clc
rjmp l_end
l_reached:
sec
l_end:
.endmacro
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_SendByte
;
; Send a byte.
; We only set the data pin to low at the beginning for the startbit. After that
; we only change the pin direction (e.g. input vs output):
; - for 0 bit: set DDR to output, forcing the data line low
; - for 1 bit: set DDR to input, letting the external pullup R pull the data line to HIGH
; since the output pin is still set to 0 the internal pullup is disabled
; Expects interrupts to be disabled.
;
; @param R16 byte to send
; @return CFLAG set if okay, clear otherwise
; @clobbers R16, R21, R22
uartBitbang_SendByte:
cbi COM_DATA_DDR, COM_DATA_PIN ; set DATA port as input
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; disable internal pullup for DATA
ldi r21, 8 ; +1 bits left
; send startbit
sbi COM_DATA_DDR, COM_DATA_PIN ; +2 set DATA as output
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; +2 set DATA low
Utils_WaitNanoSecs COM_BIT_LENGTH, 1, r22 ; wait for one bit duration
; send data bits
uartBitbang_SendByte_loop: ; 9 for low bit
lsr r16 ; 1+ bit to send -> CARRY
brcs uartBitbang_SendByte_setHigh ; HI: +2, LO: +1
uartBitbang_SendByte_setLow:
sbi COM_DATA_DDR, COM_DATA_PIN ; +2 set DATA as output
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; +2 set DATA low
Utils_WaitNanoSecs COM_BIT_LENGTH, 11, r22
rjmp uartBitbang_SendByte_loopEnd ; +2
uartBitbang_SendByte_setHigh:
cbi COM_DATA_DDR, COM_DATA_PIN ; +2 set DATA as input, pullup R makes it ONE
nop ; +1 (to make pin change available)
Utils_WaitNanoSecs COM_HALFBIT_LENGTH, 0, r22 ; wait for half a bit length for line to safely settle
sbis COM_DATA_INPUT, COM_DATA_PIN ; +1 if no skip, +2 if skipped
rjmp uartBitbang_SendByte_error ; +2 if error (collision: we wanted line to be high but it is low)
Utils_WaitNanoSecs COM_HALFBIT_LENGTH, 11, r22
uartBitbang_SendByte_loopEnd:
dec r21 ; +1
brne uartBitbang_SendByte_loop ; +2, sum per loop: 10 cycles
; send stopbit
cbi COM_DATA_DDR, COM_DATA_PIN ; +2 set DATA as input, pullup R makes it ONE
Utils_WaitNanoSecs COM_BIT_LENGTH, 0, r22 ; wait for one bit length
sec
ret
uartBitbang_SendByte_error:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbangReceiveByte
;
; Read a byte.
; Expects interrupts to be disabled.
;
; @return CFLAG set if okay, clear otherwise
; @return R16 byte received
; @clobbers R16, R20, R21, R22 (R17)
uartBitbang_ReceiveByte:
cbi COM_DATA_DDR, COM_DATA_PIN ; set DATA port as input
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; disable internal pullup for RXD
ldi r21, 8 ; bits left
clr r20 ; byte currently receiving
; wait for startbit
rcall uartBitbang_WaitForDataLow ; (R17, R22)
brcc uartBitbang_ReceiveByte_error
Utils_WaitNanoSecs COM_HALFBIT_LENGTH, 10, r22 ; goto middle of startbit to maximize sync stability
uartBitbang_ReceiveByte_loop:
Utils_WaitNanoSecs COM_BIT_LENGTH, 8, r22 ; 8 cycles used in the complete loop between waits
sec ; +1
sbic COM_DATA_INPUT, COM_DATA_PIN ; LOW: +2, HIGH: +1
rjmp uartBitbang_ReceiveByte_shiftIn ; HIGH: +2, rjmp, use set CFLAG
clc ; LOW: +1
uartBitbang_ReceiveByte_shiftIn:
ror r20 ; +1
dec r21 ; +1
brne uartBitbang_ReceiveByte_loop ; +2, sum per loop: 8 cycles
rcall uartBitbang_WaitForDataHigh ; wait for start of stopbit
brcc uartBitbang_ReceiveByte_error
mov r16, r20
sec
ret
uartBitbang_ReceiveByte_error:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_WaitForDataLow
;
; Wait up to 1ms for data pin to become low
; @return CFLAG set if okay, clear otherwise
; @clobbers R17, R22
uartBitbang_WaitForDataLow:
cbi COM_DATA_DDR, COM_DATA_PIN ; set DATA port as input
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; disable internal pullup for TXD
UART_BB_M_WAIT_FOR_PIN_LOW COM_DATA_INPUT, COM_DATA_PIN
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_WaitForDataHigh
;
; Wait up to 1ms for data pin to become high
; @return CFLAG set if okay, clear otherwise
; @clobbers R17, R22
uartBitbang_WaitForDataHigh:
cbi COM_DATA_DDR, COM_DATA_PIN ; set DATA port as input
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; disable internal pullup for TXD
UART_BB_M_WAIT_FOR_PIN_HIGH COM_DATA_INPUT, COM_DATA_PIN
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_WaitForAttnHigh
;
; Wait up to 1ms for data pin to become high
; @return CFLAG set if okay, clear otherwise
; @clobbers R17, R22
uartBitbang_WaitForAttnHigh:
cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN port as input
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable internal pullup for ATTN
UART_BB_M_WAIT_FOR_PIN_HIGH COM_ATTN_INPUT, COM_ATTN_PIN
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_ReceivePacketIntoBuffer
;
; Receive a packet into buffer pointed to by X.
; Expects interrupts to be disabled.
;
; @param R16 COM address to listen to
; @param R17 maximum value for accepted msg data (i.e. buffersize minus 3)
; @param X buffer to receive to
; @return CFLAG set if okay (packet received), cleared on error
; @return R16 error code if CFLAG is cleared (COM2_ERROR_NOTFORME, COM2_ERROR_IOERROR, COM2_ERROR_DATAERROR)
; @clobbers: r16, r17, r18, X (r19, r20, r21, r22)
uartBitbang_ReceivePacketIntoBuffer:
mov r18, r17
push r16
; read destination address
rcall uartBitbang_ReceiveByte ; read byte (R16, R17, R20, R21, R22)
pop r17 ; pop from R16 to R17
brcc uartBitbang_ReceivePacketIntoBuffer_ioError
#ifndef COM_ACCEPT_ALL_DEST ; accept every destination address
; compare destination address (accept "FF" and own address)
cp r16, r17
breq uartBitbang_ReceivePacketIntoBuffer_acceptAddr
cpi r16, 0xff
breq uartBitbang_ReceivePacketIntoBuffer_acceptAddr
clr r16
rjmp uartBitbang_ReceivePacketIntoBuffer_error ; clc/ret
#endif
uartBitbang_ReceivePacketIntoBuffer_acceptAddr:
st X+, r16 ; store dest address, lock buffer
; read msg length
rcall uartBitbang_ReceiveByte ; read packet length (R16, R17, R20, R21, R22)
brcc uartBitbang_ReceivePacketIntoBuffer_ioError
st X+, r16
cp r16, r18 ; (COM2_BUFFER_SIZE-3)
brcc uartBitbang_ReceivePacketIntoBuffer_contentError ; packet too long
inc r16 ; account for checksum byte
mov r17, r16
uartBitbang_ReceivePacketIntoBuffer_loop:
push r17
rcall uartBitbang_ReceiveByte ; read byte (R16, R17, R20, R21, R22)
pop r17
brcc uartBitbang_ReceivePacketIntoBuffer_ioError
st X+, r16
dec r17
brne uartBitbang_ReceivePacketIntoBuffer_loop
sec
ret
uartBitbang_ReceivePacketIntoBuffer_ioError:
ldi r16, NET_IFACE_OFFS_ERR_IO_LOW
rjmp uartBitbang_ReceivePacketIntoBuffer_error
uartBitbang_ReceivePacketIntoBuffer_contentError:
ldi r16, NET_IFACE_OFFS_ERR_CONTENT_LOW
uartBitbang_ReceivePacketIntoBuffer_error:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_SendPacket
;
; Send packet over wire, handle ATTN line.
;
; @param X ptr to buffer to send
; @return CFLAGS set if okay, cleared otherwise (index of error variable in R16)
; @return R16 index of error variable (if CFLAGS cleared)
; @clobbers R16, R22 (R17, R21, X)
uartBitbang_SendPacket:
rcall uartBitbang_AcquireBus
brcc uartBitbang_SendPacket_lineBusyError
rcall uartBitbang_WaitForOneBitLength ; wait for one bit duration (R22)
rcall uartBitbang_WaitForOneBitLength ; wait for one bit duration (R22)
rcall uartBitbang_WaitForOneBitLength ; wait for one bit duration (R22)
adiw xh:xl, NETMSG_OFFS_MSGLEN
ld r17, X
sbiw xh:xl, NETMSG_OFFS_MSGLEN
inc r17 ; account for dest addr
inc r17 ; account for msglen byte
inc r17 ; account for crc byte
uartBitbang_SendPacket_loop:
ld r16, X+
rcall uartBitbang_SendByte ; send byte (R16, R21, R22)
brcc uartBitbang_SendPacket_releaseBusRet
dec r17
brne uartBitbang_SendPacket_loop
sec
uartBitbang_SendPacket_releaseBusRet:
cbi COM_ATTN_DDR, COM_ATTN_PIN ; release ATTN line (by setting direction to IN)
brcc uartBitbang_SendPacket_ioError
; packet successfully sent
ret
uartBitbang_SendPacket_ioError:
ldi r16, NET_IFACE_OFFS_ERR_COLLISIONS_LOW
ret
uartBitbang_SendPacket_lineBusyError:
ldi r16, NET_IFACE_OFFS_ERR_BUSY_LOW
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_AcquireBus
;
; Reserve bus if free (otherwise return error)
; Expects interrupts to be disabled.
;
; @return CFLAG set if okay (bus acquired), cleared on error
; @clobbers: none
uartBitbang_AcquireBus:
; check for ATTN line: busy?
cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN as input
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable pullup on ATTN
nop ; needed to sample current input
sbis COM_ATTN_INPUT, COM_ATTN_PIN ; ATTN low?
rjmp uartBitbang_AcquireBus_busy ; jump if it is
sbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN as output
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; set ATTN low
sec
ret
uartBitbang_AcquireBus_busy:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_WaitForOneBitLength
;
; wait for one bit length (minus cycles for call and ret).
;
; @clobbers r22
uartBitbang_WaitForOneBitLength:
Utils_WaitNanoSecs COM_BIT_LENGTH, 7, r22 ; wait for one bit duration (minus RCALL/RET)
ret
; @end

View File

@@ -1,240 +0,0 @@
; ***************************************************************************
; 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
; ---------------------------------------------------------------------------
; @routine uartBitbang_ReceiveAndCheckMsg
;
; Receive a packet into buffer pointed to by X.
; Expects interrupts to be disabled.
;
; @param R18 COM address to listen to
; @param R19 max buffer size
; @param X buffer to receive to
; @return CFLAG set if msg received, cleared on error
; @clobbers R16, R19 (R17, R20, R21, R22, R24, R25)
uartBitbang_ReceiveAndCheckMsg:
push xl
push xh
rcall uartBitbang_RawReceiveMsg ; (R16, R17, R19, R20, R21, R22, R24, R25, X)
pop xh
pop xl
brcs uartBitbang_ReceiveAndCheckMsg_recvd
; fall-through, return with CF cleared (from uartBitbang_RawReceiveMsg)
ret
uartBitbang_ReceiveAndCheckMsg_recvd:
push xl
push xh
rcall NETMSG_CheckMessageInBuffer ; (R16, R17, R18, R19, R20, X)
pop xh
pop xl
brcs uartBitbang_ReceiveAndCheckMsg_msgOk
ldi r16, NET_IFACE_OFFS_ERR_CONTENT_LOW
rcall NET_Interface_IncCounter16 ; (R24, R25)
clc
ret
uartBitbang_ReceiveAndCheckMsg_msgOk:
ldi r16, NET_IFACE_OFFS_PACKETSIN_LOW
rcall NET_Interface_IncCounter16 ; (R24, R25)
sec
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_RawReceiveMsg
;
; Receive a packet into buffer pointed to by X.
; Expects interrupts to be disabled.
;
; @param R18 COM address to listen to
; @param R19 max buffer size
; @param X buffer to receive to
; @return CFLAG set if msg received, cleared on error (see R16)
; @return R16 if CFLAG cleared: 0=message not for this node, otherwise error
; @clobbers R16, R19 (R17, R20, R21, R22, R24, R25, X)
uartBitbang_RawReceiveMsg:
cpi r19, 3
brcs uartBitbang_RawReceiveMsg_eBadSize
; read destination address
rcall uartBitbang_ReceiveByte ; read byte (R16, R17, R20, R21, R22)
brcc uartBitbang_RawReceiveMsg_eIo
cp r16, r18
breq uartBitbang_RawReceiveMsg_forMe
cpi r16, 0xff
breq uartBitbang_RawReceiveMsg_forMe
clr r16 ; not for me
rjmp uartBitbang_RawReceiveMsg_clcRet
uartBitbang_RawReceiveMsg_forMe:
subi r19, 1
brcs uartBitbang_RawReceiveMsg_eBadSize
st X+, r16
; read size of msg payload (e.g. number of msg bytes following minus CRC byte)
rcall uartBitbang_ReceiveByte ; read byte (R16, R17, R20, R21, R22)
brcc uartBitbang_RawReceiveMsg_eIo
subi r19, 1
brcs uartBitbang_RawReceiveMsg_eBadSize
st X+, r16 ; store msg payload size
inc r16 ; account for crc byte
sub r19, r16 ; check msg size against remaining buffer size
brcs uartBitbang_RawReceiveMsg_eBadSize
mov r19, r16
uartBitbang_RawReceiveMsg_loop:
rcall uartBitbang_ReceiveByte ; read byte (R16, R17, R20, R21, R22)
brcc uartBitbang_RawReceiveMsg_eIo
st X+, r16 ; store msg
dec r19
brne uartBitbang_RawReceiveMsg_loop
sec
rjmp uartBitbang_RawReceiveMsg_end
uartBitbang_RawReceiveMsg_eBadSize:
ldi r16, NET_IFACE_OFFS_ERR_MSGSIZE_LOW
rjmp uartBitbang_RawReceiveMsg_incCounterRet
uartBitbang_RawReceiveMsg_eIo:
ldi r16, NET_IFACE_OFFS_ERR_IO_LOW
uartBitbang_RawReceiveMsg_incCounterRet:
rcall NET_Interface_IncCounter16 ; (R24, R25)
uartBitbang_RawReceiveMsg_clcRet:
clc
uartBitbang_RawReceiveMsg_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_SendMsg
;
; Send packet over wire, handle ATTN line.
;
; @param X ptr to buffer to send
; @return CFLAGS set if okay, cleared otherwise (index of error variable in R16)
; @return R16 index of error variable (if CFLAGS cleared)
; @clobbers R16 (R17, R21, R22, R24, R25, X)
uartBitbang_SendMsg:
rcall uartBitbang_AcquireBus
brcc uartBitbang_SendMsg_lineBusyError
rcall uartBitbang_WaitForOneBitLength ; wait for one bit duration (R22)
rcall uartBitbang_WaitForOneBitLength ; wait for one bit duration (R22)
rcall uartBitbang_RawSendMsg ; (R16, R17, R21, R22, R24, R25, X)
cbi COM_ATTN_DDR, COM_ATTN_PIN ; release ATTN line (by setting direction to IN)
ret
uartBitbang_SendMsg_lineBusyError:
ldi r16, NET_IFACE_OFFS_ERR_BUSY_LOW
rcall NET_Interface_IncCounter16 ; (R24, R25)
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_RawSendMsg
;
; Send packet over wire.
;
; @param X ptr to buffer to send
; @return CFLAGS set if okay, cleared otherwise (index of error variable in R16)
; @return R16 index of error variable (if CFLAGS cleared)
; @clobbers R16, R17 (R21, R22, R24, R25, X)
uartBitbang_RawSendMsg:
adiw xh:xl, NETMSG_OFFS_MSGLEN
ld r17, X
sbiw xh:xl, NETMSG_OFFS_MSGLEN
inc r17 ; account for dest addr
inc r17 ; account for msglen byte
inc r17 ; account for crc byte
uartBitbang_RawSendMsg_loop:
rcall uartBitbang_WaitForOneBitLength ; wait for one bit duration (R22)
ld r16, X+
rcall uartBitbang_SendByte ; send byte (R16, R21, R22)
brcc uartBitbang_RawSendMsg_ioError
dec r17
brne uartBitbang_RawSendMsg_loop
ldi r16, NET_IFACE_OFFS_PACKETSOUT_LOW
rcall NET_Interface_IncCounter16 ; (R24, R25)
sec
ret
uartBitbang_RawSendMsg_ioError:
ldi r16, NET_IFACE_OFFS_ERR_COLLISIONS_LOW
rcall NET_Interface_IncCounter16 ; (R24, R25)
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_WaitForAttnHigh
;
; Wait up to 1ms for data pin to become high
; @return CFLAG set if okay, clear otherwise
; @clobbers R17, R22
uartBitbang_WaitForAttnHigh:
cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN port as input
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable internal pullup for ATTN
UART_BB_M_WAIT_FOR_PIN_HIGH COM_ATTN_INPUT, COM_ATTN_PIN
ret
; @end
; ---------------------------------------------------------------------------
; @routine uartBitbang_AcquireBus
;
; Reserve bus if free (otherwise return error)
; Expects interrupts to be disabled.
;
; @return CFLAG set if okay (bus acquired), cleared on error
; @clobbers: none
uartBitbang_AcquireBus:
; check for ATTN line: busy?
cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN as input
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable pullup on ATTN
nop ; needed to sample current input
sbis COM_ATTN_INPUT, COM_ATTN_PIN ; ATTN low?
rjmp uartBitbang_AcquireBus_busy ; jump if it is
sbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN as output
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; set ATTN low
sec
ret
uartBitbang_AcquireBus_busy:
clc
ret
; @end

View File

@@ -305,8 +305,7 @@ l_overrun_%:
ldi r16, NET_IFACE_OFFS_ERR_MISSED_LOW
l_incCounterAndEnterSkipping_%:
ldi r17, UART_HW_READMODE_SKIPPING
std Y+UART_HW_IFACE_OFFS_READMODE, r17 ; set read mode
rjmp l_end_%
ldi r16, NET_IFACE_OFFS_HANDLED_LOW
l_incCounterAndEnterMode_%:
rcall NET_Interface_IncCounter16 ; (R24, R25)
std Y+UART_HW_IFACE_OFFS_READMODE, r17 ; set read mode

View File

@@ -1,15 +0,0 @@
; ***************************************************************************
; 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 FIRMWARE_VERSION_MAJOR = 1
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 2

View File

@@ -10,18 +10,6 @@
<value name="MOTION" id="0x07" type="sensor" dataType="rational" modality="motion" denom="1" />
<value name="DOOR" id="0x08" type="sensor" dataType="rational" modality="door" denom="1" />
<value name="stats_packets_in" id="0xe0" type="sensor" dataType="uint16" denom="1" />
<value name="stats_packets_out" id="0xe1" type="sensor" dataType="uint16" denom="1" />
<value name="stats_content_errors" id="0xe2" type="sensor" dataType="uint16" denom="1" />
<value name="stats_io_errors" id="0xe3" type="sensor" dataType="uint16" denom="1" />
<value name="stats_nobuf_errors" id="0xe4" type="sensor" dataType="uint16" denom="1" />
<value name="stats_collision_errors" id="0xe5" type="sensor" dataType="uint16" denom="1" />
<value name="stats_busy_errors" id="0xe6" type="sensor" dataType="uint16" denom="1" />
<value name="stats_heap_used" id="0xe7" type="sensor" dataType="uint16" denom="1" />
<value name="stats_heap_free" id="0xe8" type="sensor" dataType="uint16" denom="1" />
<value name="stats_noram_errors" id="0xe9" type="sensor" dataType="uint16" denom="1" />
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
</values>

View File

@@ -16,33 +16,12 @@ case $NODE in
LFUSE_ARG="-U lfuse:w:0xE4:m"
FILE_ARG="-U flash:w:./0-build/avr/devices/c01/boot/c01_boot.hex"
;;
c02)
DEVICE_ARG="-p m644p"
HFUSE_ARG="-U hfuse:w:0xD5:m"
LFUSE_ARG="-U lfuse:w:0xE2:m"
EFUSE_ARG="-U efuse:w:0xFF:m"
FILE_ARG="-U flash:w:./0-build/avr/devices/c02/boot/c02_boot.hex"
;;
n16)
DEVICE_ARG="-p t84"
HFUSE_ARG="-U hfuse:w:0xD7:m"
LFUSE_ARG=""
EFUSE_ARG="-U efuse:w:0xFE:m"
FILE_ARG="-U flash:w:./0-build/avr/devices/n16/boot/n16_boot.hex"
;;
n20)
DEVICE_ARG="-p t84"
HFUSE_ARG="-U hfuse:w:0xD7:m"
LFUSE_ARG=""
EFUSE_ARG="-U efuse:w:0xFE:m"
FILE_ARG="-U flash:w:./0-build/avr/devices/n20/n20_boot.hex"
;;
n21)
DEVICE_ARG="-p t84"
HFUSE_ARG="-U hfuse:w:0xD7:m"
LFUSE_ARG=""
EFUSE_ARG="-U efuse:w:0xFE:m"
FILE_ARG="-U flash:w:./0-build/avr/devices/n21/boot/n21_boot.hex"
FILE="-U flash:w:./0-build/avr/devices/n21/boot/n21_boot.hex"
;;
n22)
DEVICE_ARG="-p t85"
@@ -63,14 +42,7 @@ case $NODE in
HFUSE_ARG="-U hfuse:w:0xD7:m"
LFUSE_ARG=""
EFUSE_ARG="-U efuse:w:0xFE:m"
FILE_ARG="-U flash:w:./0-build/avr/devices/n24/boot/n24_boot.hex"
;;
n25)
DEVICE_ARG="-p t84"
HFUSE_ARG="-U hfuse:w:0xD7:m"
LFUSE_ARG=""
EFUSE_ARG="-U efuse:w:0xFE:m"
FILE_ARG="-U flash:w:./0-build/avr/devices/n25/boot/n25_boot.hex"
FILE_ARG="-U flash:w:./0-build/avr/devices/n23/boot/n23_boot.hex"
;;
t03)
DEVICE_ARG="-p t841"