avr: added apps and use them in multiple nodes.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
include
|
||||
modules
|
||||
devices
|
||||
apps
|
||||
</subdirs>
|
||||
|
||||
<extradist>
|
||||
|
||||
17
avr/apps/0BUILD
Normal file
17
avr/apps/0BUILD
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml?>
|
||||
|
||||
<gwbuild>
|
||||
|
||||
<subdirs>
|
||||
door
|
||||
motion
|
||||
network
|
||||
</subdirs>
|
||||
|
||||
<extradist>
|
||||
</extradist>
|
||||
|
||||
|
||||
</gwbuild>
|
||||
|
||||
|
||||
115
avr/apps/door/main.asm
Normal file
115
avr/apps/door/main.asm
Normal file
@@ -0,0 +1,115 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; defines
|
||||
|
||||
.equ APP_DOOR_KEEPUPTIME = 50 ; 5s
|
||||
|
||||
.equ APP_DOOR_STATE_OPEN = 255
|
||||
.equ APP_DOOR_STATE_CLOSED = 0
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; data
|
||||
|
||||
.dseg
|
||||
|
||||
appDoorKeepupData: .byte FILTER_KEEPUP_DATA_SIZE
|
||||
appDoorValSchedData: .byte VALSCHED_DATA_SIZE
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
.cseg
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine AppDoor_Init @global
|
||||
;
|
||||
|
||||
AppDoor_Init:
|
||||
ldi yl, LOW(appDoorKeepupData)
|
||||
ldi yh, HIGH(appDoorKeepupData)
|
||||
rcall FilterKeepUp_Init
|
||||
ldi r16, APP_DOOR_KEEPUPTIME
|
||||
std Y+FILTER_KEEPUP_OFFS_RESTARTVALUE, r16
|
||||
|
||||
ldi yl, LOW(appDoorValSchedData)
|
||||
ldi yh, HIGH(appDoorValSchedData)
|
||||
rcall ValueScheduler_Init
|
||||
ldi r16, (1<<VALSCHED_FLAGS_REPEAT1_BIT) ; only repeat report interval for active motion
|
||||
std Y+VALSCHED_OFFS_FLAGS, r16
|
||||
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine AppDoor_Every100ms @global
|
||||
;
|
||||
|
||||
AppDoor_Every100ms:
|
||||
rcall TCRT1K_GetValue ; get value into R16
|
||||
ldi yl, LOW(appDoorKeepupData)
|
||||
ldi yh, HIGH(appDoorKeepupData)
|
||||
brcc AppDoor_Every100ms_l1
|
||||
rcall FilterKeepUp_SetValue ; (R17)
|
||||
|
||||
AppDoor_Every100ms_l1:
|
||||
rcall FilterKeepUp_Every100ms
|
||||
rcall FilterKeepUp_GetValue ; get value into R16
|
||||
|
||||
ldi yl, LOW(appDoorValSchedData)
|
||||
ldi yh, HIGH(appDoorValSchedData)
|
||||
rcall ValueScheduler_SetValue ; (R17)
|
||||
rcall ValueScheduler_Every100ms ; (R16, R17)
|
||||
rcall ValueScheduler_CheckSend ; (R16)
|
||||
brcc AppDoor_Every100ms_end
|
||||
; prepare and send value message
|
||||
rcall appDoorSendValue
|
||||
brcc AppDoor_Every100ms_end ; jmp on error
|
||||
ldi yl, LOW(appDoorValSchedData)
|
||||
ldi yh, HIGH(appDoorValSchedData)
|
||||
rcall ValueScheduler_MarkSent ; (R16)
|
||||
AppDoor_Every100ms_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appDoorSendValue
|
||||
;
|
||||
; @return CFLAGS set if message enqueued, cleared on error
|
||||
; @clobbers R17, R18, R19, R20, R21, R22, Y (R16, R23, R24, R25)
|
||||
|
||||
appDoorSendValue:
|
||||
ldi yl, LOW(appDoorValSchedData)
|
||||
ldi yh, HIGH(appDoorValSchedData)
|
||||
rcall ValueScheduler_GetValue ; get value to r16
|
||||
tst r16
|
||||
ldi r16, APP_DOOR_STATE_CLOSED
|
||||
breq appDoorSendValue_send
|
||||
ldi r16, APP_DOOR_STATE_OPEN
|
||||
appDoorSendValue_send:
|
||||
ldi r17, VALUE_ID_TCRT1K ; VALUE ID
|
||||
ldi r22, AQHOME_VALUETYPE_DOOR ; VALUE TYPE
|
||||
rjmp Main_Send8BitValue
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
108
avr/apps/motion/main.asm
Normal file
108
avr/apps/motion/main.asm
Normal file
@@ -0,0 +1,108 @@
|
||||
; ***************************************************************************
|
||||
; copyright : (C) 2024 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; defines
|
||||
|
||||
.equ APP_MOTION_KEEPUPTIME = 150 ; 15s
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; data
|
||||
|
||||
.dseg
|
||||
|
||||
appMotionKeepupData: .byte FILTER_KEEPUP_DATA_SIZE
|
||||
appMotionValSchedData: .byte VALSCHED_DATA_SIZE
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
.cseg
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine AppMotion_Init @global
|
||||
;
|
||||
|
||||
AppMotion_Init:
|
||||
rcall Motion_Init
|
||||
|
||||
ldi yl, LOW(appMotionKeepupData)
|
||||
ldi yh, HIGH(appMotionKeepupData)
|
||||
rcall FilterKeepUp_Init
|
||||
ldi r16, APP_MOTION_KEEPUPTIME
|
||||
std Y+FILTER_KEEPUP_OFFS_RESTARTVALUE, r16
|
||||
|
||||
ldi yl, LOW(appMotionValSchedData)
|
||||
ldi yh, HIGH(appMotionValSchedData)
|
||||
rcall ValueScheduler_Init
|
||||
ldi r16, (1<<VALSCHED_FLAGS_REPEAT1_BIT) ; only repeat report interval for active motion
|
||||
std Y+VALSCHED_OFFS_FLAGS, r16
|
||||
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine AppMotion_Every100ms @global
|
||||
;
|
||||
|
||||
AppMotion_Every100ms:
|
||||
rcall Motion_GetValue ; get value into R16
|
||||
|
||||
ldi yl, LOW(appMotionKeepupData)
|
||||
ldi yh, HIGH(appMotionKeepupData)
|
||||
rcall FilterKeepUp_SetValue ; (R17)
|
||||
rcall FilterKeepUp_Every100ms
|
||||
rcall FilterKeepUp_GetValue ; get value into R16
|
||||
|
||||
ldi yl, LOW(appMotionValSchedData)
|
||||
ldi yh, HIGH(appMotionValSchedData)
|
||||
rcall ValueScheduler_SetValue ; (R17)
|
||||
rcall ValueScheduler_Every100ms ; (R16, R17)
|
||||
rcall ValueScheduler_CheckSend ; (R16)
|
||||
brcc AppMotion_Every100ms_end
|
||||
; prepare and send value message
|
||||
rcall appMotionSendValue
|
||||
brcc AppMotion_Every100ms_end ; jmp on error
|
||||
ldi yl, LOW(appMotionValSchedData)
|
||||
ldi yh, HIGH(appMotionValSchedData)
|
||||
rcall ValueScheduler_MarkSent ; (R16)
|
||||
AppMotion_Every100ms_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionSendValue
|
||||
;
|
||||
; @return CFLAGS set if message enqueued, cleared on error
|
||||
; @clobbers R17, R18, R19, R20, R21, R22, Y (R16, R23, R24, R25)
|
||||
|
||||
appMotionSendValue:
|
||||
ldi yl, LOW(appMotionValSchedData)
|
||||
ldi yh, HIGH(appMotionValSchedData)
|
||||
rcall ValueScheduler_GetValue ; get value to r16
|
||||
|
||||
ldi r17, VALUE_ID_MOTION ; VALUE ID
|
||||
ldi r22, AQHOME_VALUETYPE_MOTION ; VALUE TYPE
|
||||
rjmp Main_Send8BitValue
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
426
avr/apps/network/main.asm
Normal file
426
avr/apps/network/main.asm
Normal file
@@ -0,0 +1,426 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; defines
|
||||
|
||||
.equ APP_NETWORK_STATE_INITIALWAIT = 0 ; initially wait
|
||||
.equ APP_NETWORK_STATE_NEEDADDRESS = 1 ; wait for range msgs after sending "NEEDADDRESS"
|
||||
.equ APP_NETWORK_STATE_CLAIMADDRESS1 = 2 ; wait for "DENYADDRESS"
|
||||
.equ APP_NETWORK_STATE_CLAIMADDRESS2 = 3 ; wait for "DENYADDRESS"
|
||||
.equ APP_NETWORK_STATE_CLAIMADDRESS3 = 4 ; wait for "DENYADDRESS"
|
||||
.equ APP_NETWORK_STATE_HAVEADDRESS1 = 5 ; just notify (and handle "DENYADDRESS")
|
||||
.equ APP_NETWORK_STATE_HAVEADDRESS2 = 6 ; just notify (and handle "DENYADDRESS")
|
||||
.equ APP_NETWORK_STATE_UP = 7
|
||||
.equ APP_NETWORK_STATE_COUNT = 8
|
||||
|
||||
.equ APP_NETWORK_TIMER_100MS = 50
|
||||
|
||||
|
||||
.equ APP_NETWORK_ADDRESS_RANGE_BEGIN = 1
|
||||
.equ APP_NETWORK_ADDRESS_RANGE_END = 192
|
||||
|
||||
.equ APP_NETWORK_REBOOT_TIME_100MS = 20
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; data
|
||||
|
||||
.dseg
|
||||
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine AppNetwork_Init @global
|
||||
;
|
||||
|
||||
AppNetwork_Init:
|
||||
rcall appNetworkResetState
|
||||
sec
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine AppNetwork_Fini @global
|
||||
;
|
||||
|
||||
AppNetwork_Fini:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine AppNetwork_Every100ms @global
|
||||
;
|
||||
|
||||
AppNetwork_Every100ms:
|
||||
ldd r16, Y+NET_IFACE_OFFS_STATETIMER
|
||||
tst r16
|
||||
brne AppNetwork_Every100ms_decAndJump
|
||||
ret
|
||||
AppNetwork_Every100ms_decAndJump:
|
||||
dec r16
|
||||
std Y+NET_IFACE_OFFS_STATETIMER, r16
|
||||
brne AppNetwork_Every100ms_end
|
||||
ldd r16, Y+NET_IFACE_OFFS_STATUS
|
||||
cpi r16, APP_NETWORK_STATE_COUNT
|
||||
brcs AppNetwork_Every100ms_jump
|
||||
AppNetwork_Every100ms_end:
|
||||
ret
|
||||
AppNetwork_Every100ms_jump:
|
||||
ldi zl, LOW(appNetworkTimerTable)
|
||||
ldi zh, HIGH(appNetworkTimerTable)
|
||||
add zl, r16
|
||||
adc zh, r16
|
||||
sub zh, r16
|
||||
ijmp
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine AppNetwork_HandleMsg @global
|
||||
;
|
||||
; @param X pointer to received message
|
||||
|
||||
AppNetwork_HandleMsg:
|
||||
adiw xh:xl, NETMSG_OFFS_CMD
|
||||
ld r16, X
|
||||
sbiw xh:xl, NETMSG_OFFS_CMD
|
||||
cpi r16, NETMSG_CMD_REBOOT_REQUEST
|
||||
breq AppNetwork_HandleMsg_handleRebootMsg
|
||||
cpi r16, NETMSG_CMD_HAVE_ADDRESS
|
||||
brcs AppNetwork_HandleMsg_clcRet ; lower than "HAVE_ADDR"
|
||||
cpi r16, NETMSG_CMD_ADDRESS_RANGE
|
||||
breq AppNetwork_HandleMsg_handleRangeMsg
|
||||
brcc AppNetwork_HandleMsg_clcRet ; higher or equal to "ADDR_RANGE"
|
||||
rjmp AppNetwork_HandleMsg_handleAddrMsg
|
||||
AppNetwork_HandleMsg_handleRangeMsg:
|
||||
; TODO
|
||||
rjmp AppNetwork_HandleMsg_clcRet
|
||||
|
||||
AppNetwork_HandleMsg_handleAddrMsg:
|
||||
rcall NETMSG_Address_Read ; (R18, R19)
|
||||
mov r16, r18
|
||||
subi r16, NETMSG_CMD_HAVE_ADDRESS
|
||||
ldi zl, LOW(appNetworkMsgTable)
|
||||
ldi zh, HIGH(appNetworkMsgTable)
|
||||
add zl, r16
|
||||
adc zh, r16
|
||||
sub zh, r16
|
||||
ijmp
|
||||
AppNetwork_HandleMsg_handleRebootMsg:
|
||||
push xl
|
||||
push xh
|
||||
rcall appNetworkHandleRebootRequest
|
||||
pop xh
|
||||
pop xl
|
||||
ret
|
||||
AppNetwork_HandleMsg_clcRet:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appNetworkHandleRebootRequest
|
||||
;
|
||||
; @param X pointer to received message
|
||||
|
||||
appNetworkHandleRebootRequest:
|
||||
rcall NETMSG_RebootRequestRead
|
||||
brcc appNetworkHandleRebootRequest_end
|
||||
; reboot
|
||||
cli
|
||||
rjmp BOOTLOADER_ADDR
|
||||
appNetworkHandleRebootRequest_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
appNetworkTimerTable:
|
||||
rjmp appNetworkHandleStateInitialWait
|
||||
rjmp appNetworkHandleStateNeedAddress
|
||||
rjmp appNetworkHandleStateClaimAddress1
|
||||
rjmp appNetworkHandleStateClaimAddress2
|
||||
rjmp appNetworkHandleStateClaimAddress3
|
||||
rjmp appNetworkHandleStateHaveAddress1
|
||||
rjmp appNetworkHandleStateHaveAddress2
|
||||
rjmp appNetworkHandleStateUp
|
||||
|
||||
|
||||
appNetworkHandleStateInitialWait:
|
||||
ldi r18, NETMSG_CMD_NEED_ADDRESS
|
||||
rjmp appNetworkSendMsgNextState
|
||||
|
||||
|
||||
appNetworkHandleStateNeedAddress:
|
||||
ldi r18, NETMSG_CMD_CLAIM_ADDRESS
|
||||
rjmp appNetworkSendMsgNextState
|
||||
|
||||
|
||||
appNetworkHandleStateClaimAddress1:
|
||||
ldi r18, NETMSG_CMD_CLAIM_ADDRESS
|
||||
rjmp appNetworkSendMsgNextState
|
||||
|
||||
|
||||
appNetworkHandleStateClaimAddress2:
|
||||
ldi r18, NETMSG_CMD_CLAIM_ADDRESS
|
||||
rjmp appNetworkSendMsgNextState
|
||||
|
||||
|
||||
appNetworkHandleStateClaimAddress3:
|
||||
ldi r18, NETMSG_CMD_HAVE_ADDRESS
|
||||
rjmp appNetworkSendMsgNextState
|
||||
|
||||
|
||||
appNetworkHandleStateHaveAddress1:
|
||||
ldi r18, NETMSG_CMD_HAVE_ADDRESS
|
||||
rjmp appNetworkSendMsgNextState
|
||||
|
||||
|
||||
appNetworkHandleStateHaveAddress2:
|
||||
ldi r16, APP_NETWORK_STATE_UP
|
||||
std Y+NET_IFACE_OFFS_STATUS, r16
|
||||
ldd r16, Y+NET_IFACE_OFFS_RANGE_BEGIN ; set interface address
|
||||
std Y+NET_IFACE_OFFS_ADDRESS, r16
|
||||
|
||||
in r15, SREG
|
||||
push r15
|
||||
cli
|
||||
ldi xl, LOW(EEPROM_OFFS_COMADDR)
|
||||
ldi xh, HIGH(EEPROM_OFFS_COMADDR)
|
||||
rcall Utils_WriteEepromIncr ; write address to EEPROM
|
||||
pop r15
|
||||
out SREG, r15
|
||||
|
||||
ret
|
||||
|
||||
|
||||
appNetworkHandleStateUp:
|
||||
ldi r16, 200 ; come again after 20s (nothing to do for now, maybe add some cleanup later)
|
||||
std Y+NET_IFACE_OFFS_STATETIMER, r16
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appNetworkSendMsgNextState
|
||||
;
|
||||
; @param R18 msg type to send
|
||||
; @clobbers R16, R19 (R17, R18, R20, R21, X)
|
||||
|
||||
appNetworkSendMsgNextState:
|
||||
ldd r19, Y+NET_IFACE_OFFS_RANGE_BEGIN
|
||||
rcall appNetworkSendAddrMsg ; (R16, R17, R18, R19, R20, R21, X)
|
||||
brcc appNetworkSendMsgNextState_retry
|
||||
ldd r16, Y+NET_IFACE_OFFS_STATUS
|
||||
inc r16
|
||||
std Y+NET_IFACE_OFFS_STATUS, r16
|
||||
ldi r16, APP_NETWORK_TIMER_100MS
|
||||
std Y+NET_IFACE_OFFS_STATETIMER, r16
|
||||
ret
|
||||
appNetworkSendMsgNextState_retry:
|
||||
ldi r16, 1
|
||||
std Y+NET_IFACE_OFFS_STATETIMER, r16
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
appNetworkMsgTable:
|
||||
rjmp appNetworkHandleMsgNeedAddr
|
||||
rjmp appNetworkHandleMsgHaveAddr
|
||||
rjmp appNetworkHandleMsgClaimAddr
|
||||
rjmp appNetworkHandleMsgDenyAddr
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appNetworkHandleMsgNeedAddr
|
||||
;
|
||||
; @param R18 command
|
||||
; @param R19 address to send
|
||||
|
||||
appNetworkHandleMsgNeedAddr:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appNetworkHandleMsgHaveAddr
|
||||
;
|
||||
; @param R18 command
|
||||
; @param R19 address to send
|
||||
|
||||
appNetworkHandleMsgHaveAddr:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appNetworkHandleMsgClaimAddr
|
||||
;
|
||||
; @param R18 command
|
||||
; @param R19 address from CLAIM_ADDRESS message
|
||||
|
||||
appNetworkHandleMsgClaimAddr:
|
||||
ldd r16, Y+NET_IFACE_OFFS_ADDRESS
|
||||
cp r19, r16
|
||||
brne appNetworkHandleMsgClaimAddr_end ; not our address
|
||||
ldd r16, Y+NET_IFACE_OFFS_STATUS
|
||||
cpi r16, APP_NETWORK_STATE_UP ; up?
|
||||
brne appNetworkHandleMsgClaimAddr_end ; nope, ignore
|
||||
; network is up, someone claimed our address, deny it
|
||||
ldi r18, NETMSG_CMD_DENY_ADDRESS ; deny our addr
|
||||
ldd r19, Y+NET_IFACE_OFFS_ADDRESS
|
||||
rjmp appNetworkSendAddrMsg
|
||||
appNetworkHandleMsgClaimAddr_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appNetworkHandleMsgDenyAddr
|
||||
;
|
||||
; @param R18 command
|
||||
; @param R19 address from DENY_ADDR message
|
||||
|
||||
appNetworkHandleMsgDenyAddr:
|
||||
; check state
|
||||
ldd r16, Y+NET_IFACE_OFFS_STATUS
|
||||
cpi r16, APP_NETWORK_STATE_UP
|
||||
breq appNetworkHandleMsgDenyAddr_end ; ignore (our network stack is up)
|
||||
; still setting up address, check whether the last one is denied now
|
||||
ldd r16, Y+NET_IFACE_OFFS_RANGE_BEGIN
|
||||
cp r19, r16 ; our claimed address?
|
||||
brne appNetworkHandleMsgDenyAddr_end ; nope, jump
|
||||
; try next address (if any left)
|
||||
ldd r17, Y+NET_IFACE_OFFS_RANGE_END
|
||||
inc r16
|
||||
cp r16, r17
|
||||
brcs appNetworkHandleMsgDenyAddr_claimNext
|
||||
; out of addresses, start completely new after some waiting time
|
||||
rcall appNetworkResetState
|
||||
ldi r16, 200 ; wait for 20s before trying whole process again
|
||||
std Y+NET_IFACE_OFFS_STATETIMER, r16
|
||||
rjmp appNetworkHandleMsgDenyAddr_end
|
||||
appNetworkHandleMsgDenyAddr_claimNext:
|
||||
; send CLAIM_ADDR for next address (new state: APP_NETWORK_STATE_NEEDADDRESS+1)
|
||||
std Y+NET_IFACE_OFFS_RANGE_BEGIN, r16
|
||||
ldi r16, APP_NETWORK_STATE_NEEDADDRESS
|
||||
std Y+NET_IFACE_OFFS_STATUS, r16
|
||||
ldi r18, NETMSG_CMD_CLAIM_ADDRESS
|
||||
rjmp appNetworkSendMsgNextState
|
||||
appNetworkHandleMsgDenyAddr_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appNetworkSendAddrMsg
|
||||
;
|
||||
; @param Y pointer to device to write msg for
|
||||
; @param R18 command
|
||||
; @param R19 address to send
|
||||
; @clobbers R16 (R17, R18, R19, R20, R21, X)
|
||||
|
||||
appNetworkSendAddrMsg:
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc appNetworkSendAddrMsg_end
|
||||
adiw xh:xl, 1
|
||||
push r16
|
||||
rcall NETMSG_Address_Write ; (R16, R17, R18, R19, R20, R21)
|
||||
pop r16
|
||||
sbiw xh:xl, 1
|
||||
rcall NET_Interface_AddOutgoingMsgNum ; (R17, R18, X)
|
||||
brcs appNetworkSendAddrMsg_end
|
||||
rcall NET_Buffer_ReleaseByNum ; (R16, X)
|
||||
clc
|
||||
appNetworkSendAddrMsg_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appNetworkResetState
|
||||
;
|
||||
; @param Y pointer to device to write msg for
|
||||
; @clobbers R16
|
||||
|
||||
appNetworkResetState:
|
||||
ldi r16, APP_NETWORK_STATE_INITIALWAIT
|
||||
std Y+NET_IFACE_OFFS_STATUS, r16
|
||||
ldi r16, APP_NETWORK_TIMER_100MS
|
||||
std Y+NET_IFACE_OFFS_STATETIMER, r16
|
||||
ldi r16, APP_NETWORK_ADDRESS_RANGE_BEGIN
|
||||
std Y+NET_IFACE_OFFS_RANGE_BEGIN, r16
|
||||
rcall appNetworkGetAddressFromEeprom ; R16=addr (R15, X)
|
||||
tst r16
|
||||
breq appNetworkResetState_setRangeEnd
|
||||
cpi r16, 0xff
|
||||
breq appNetworkResetState_setRangeEnd
|
||||
std Y+NET_IFACE_OFFS_RANGE_BEGIN, r16
|
||||
appNetworkResetState_setRangeEnd:
|
||||
ldi r16, APP_NETWORK_ADDRESS_RANGE_END ; last possible address+1
|
||||
std Y+NET_IFACE_OFFS_RANGE_END, r16
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appNetworkGetAddressFromEeprom
|
||||
;
|
||||
; @return R16 address from EEPROM
|
||||
; @clobbers R15, X
|
||||
|
||||
appNetworkGetAddressFromEeprom:
|
||||
ldi xl, LOW(EEPROM_OFFS_COMADDR)
|
||||
ldi xh, HIGH(EEPROM_OFFS_COMADDR)
|
||||
in r15, SREG
|
||||
push r15
|
||||
cli
|
||||
rcall Utils_ReadEepromIncr ; (R16)
|
||||
pop r15
|
||||
out SREG, r15
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
76
avr/apps/network/stats.asm
Normal file
76
avr/apps/network/stats.asm
Normal file
@@ -0,0 +1,76 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine AppNetwork_SendTxdStats
|
||||
|
||||
; @param Y network interface to work with
|
||||
; @clobbers R16, X (R17, R18, R19, R20, R21, Z)
|
||||
|
||||
AppNetwork_SendTxdStats:
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc AppNetwork_SendTxdStats_end
|
||||
push r16
|
||||
adiw xh:xl, 1
|
||||
rcall NETMSG_SendStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
|
||||
AppNetwork_SendTxdStats_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine AppNetwork_SendRxdStats
|
||||
|
||||
; @param Y network interface to work with
|
||||
; @clobbers R16, X (R17, R18, R19, R20, R21, Z)
|
||||
|
||||
AppNetwork_SendRxdStats:
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc AppNetwork_SendRxdStats_end
|
||||
push r16
|
||||
adiw xh:xl, 1
|
||||
rcall NETMSG_RecvStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
|
||||
AppNetwork_SendRxdStats_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine AppNetwork_SendDevice
|
||||
|
||||
; @param Y network interface to work with
|
||||
; @clobbers R16, X (R17, R18, R19, R20, R21, Z)
|
||||
|
||||
AppNetwork_SendDevice:
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc AppNetwork_SendDevice_end
|
||||
push r16
|
||||
adiw xh:xl, 1
|
||||
rcall NETMSG_Device_Write ; (R16, R17, R18, R19, R20, R21, Z)
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
|
||||
AppNetwork_SendDevice_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user