cleanup build system.
This commit is contained in:
2
0BUILD
2
0BUILD
@@ -2,7 +2,7 @@
|
||||
|
||||
<gwbuild>
|
||||
|
||||
<project name="aqhome" version="0.0.9" so_current="0" so_age="0" so_revision="9" write_config_h="TRUE">
|
||||
<project name="aqhome" version="0.0.10" so_current="0" so_age="0" so_revision="10" write_config_h="TRUE">
|
||||
<setVar name="package">$(project_name)</setVar>
|
||||
<setVar name="version">
|
||||
$(project_vmajor).$(project_vminor).$(project_vpatchlevel)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
defs.asm
|
||||
hw_tn84.asm
|
||||
hw_tn85.asm
|
||||
hw_tn841.asm
|
||||
includes.asm
|
||||
main.asm
|
||||
modules.asm
|
||||
|
||||
@@ -1,161 +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
|
||||
.equ clock=8000000 ; Define the clock frequency
|
||||
|
||||
.nolist
|
||||
.include "include/tn841def.inc" ; Define device ATtiny841
|
||||
.list
|
||||
|
||||
.include "./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
|
||||
|
||||
|
||||
;#define COM_ACCEPT_ALL_DEST 1
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; LED
|
||||
|
||||
.equ LED_DDR = DDRB
|
||||
.equ LED_PORT = PORTB
|
||||
.equ LED_PIN = PINB
|
||||
.equ LED_PINNUM = PORTB2
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code segment
|
||||
|
||||
.cseg
|
||||
.org 0x0000
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Reset and interrupt vectors
|
||||
|
||||
rjmp main ; 1: RESET Reset vector use this for flashed system
|
||||
reti ; 2: INT0 External Interrupt Request 0
|
||||
reti ; 3: PCINT0 Pin Change Interrupt 0
|
||||
reti ; 4: PCINT1 Pin Change Interrupt 1
|
||||
reti ; 5: WDT Watchdog Time-out
|
||||
reti ; 6: TIM1_CAPT Timer/Counter1 Capture Event
|
||||
reti ; 7: TIM1_COMPA (OC1A) Timer/Counter1 Compare Match A
|
||||
reti ; 8: TIM1_COMPB (OC1B) Timer/Counter1 Compare Match B
|
||||
reti ; 9: TIM1_OVF (OVF1) Timer/Counter1 Overflow
|
||||
reti ; 10: TIM0_COMPA (OC0A) Timer/Counter0 Compare Match A
|
||||
reti ; 11: TIM0_COMPB (OC0B) Timer/Counter0 Compare Match B
|
||||
reti ; 12: TIM0_OVF (OVF0) Timer/Counter0 Overflow
|
||||
reti ; 13: ANA_COMP0 Analog Comparator 0
|
||||
reti ; 14: ADC_READY ADC Conversion Complete
|
||||
reti ; 15: EE_RDY (ERDY) EEPROM Ready
|
||||
reti ; 16: ANA_COMP1 Analog Comparator 1
|
||||
reti ; 17: TIM2_CAPT Timer/Counter2 Capture Event
|
||||
reti ; 18: TIM2_COMPA (OC2A) Timer/Counter2 Compare Match A
|
||||
reti ; 19: TIM2_COMPB (OC2B) Timer/Counter2 Compare Match B
|
||||
reti ; 20: TIM2_OVF (OVF2) Timer/Counter2 Overflow
|
||||
reti ; 21: SPI SPI Serial Transfer Complete
|
||||
reti ; 22: USART0_RXS USART0 Rx Start
|
||||
reti ; 23: USART0_RXC USART0 Rx Complete
|
||||
reti ; 24: USART0_DRE USART0 Data Register Empty
|
||||
reti ; 25: USART0_TXC USART0 Tx Complete
|
||||
reti ; 26: USART1_RXS USART1 Rx Start
|
||||
reti ; 27: USART1_RXC USART1 Rx Complete
|
||||
reti ; 28: USART1_DRE USART1 Data Register Empty
|
||||
reti ; 29: USART1_TXC USART1 Tx Complete
|
||||
reti ; 30: TWI Two-Wire-Interface
|
||||
reti ; 31: RESERVED reserved
|
||||
|
||||
|
||||
|
||||
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_uart1.asm"
|
||||
.include "modules/flash/flashxp.asm"
|
||||
.include "modules/flash/flash4p.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 == 1000000
|
||||
ldi r17, 0xd8
|
||||
ldi r16, (1<<CLKPS1) | (1<<CLKPS0) ; SUT=0, CLKPS=0011b
|
||||
sts CCP, r17
|
||||
sts CLKPR, r16
|
||||
.endif
|
||||
|
||||
.if clock == 8000000
|
||||
ldi r17, 0xd8
|
||||
clr r16 ; SUT=0, CLKPS=0
|
||||
sts CCP, r17
|
||||
sts CLKPR, r16
|
||||
.endif
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -1,398 +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
|
||||
.equ clock=8000000 ; Define the clock frequency
|
||||
|
||||
.nolist
|
||||
.include "include/tn841def.inc" ; Define device ATtiny841
|
||||
.list
|
||||
|
||||
.include "./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
|
||||
|
||||
|
||||
;#define COM_ACCEPT_ALL_DEST 1
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; LED
|
||||
|
||||
.equ LED_DDR = DDRB
|
||||
.equ LED_PORT = PORTB
|
||||
.equ LED_PIN = PINB
|
||||
.equ LED_PINNUM = PORTB2
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code segment
|
||||
|
||||
.cseg
|
||||
.org 0x0000
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Reset and interrupt vectors
|
||||
|
||||
rjmp main ; 1: RESET Reset vector use this for flashed system
|
||||
reti ; 2: INT0 External Interrupt Request 0
|
||||
reti ; 3: PCINT0 Pin Change Interrupt 0
|
||||
reti ; 4: PCINT1 Pin Change Interrupt 1
|
||||
reti ; 5: WDT Watchdog Time-out
|
||||
reti ; 6: TIM1_CAPT Timer/Counter1 Capture Event
|
||||
reti ; 7: TIM1_COMPA (OC1A) Timer/Counter1 Compare Match A
|
||||
reti ; 8: TIM1_COMPB (OC1B) Timer/Counter1 Compare Match B
|
||||
reti ; 9: TIM1_OVF (OVF1) Timer/Counter1 Overflow
|
||||
reti ; 10: TIM0_COMPA (OC0A) Timer/Counter0 Compare Match A
|
||||
reti ; 11: TIM0_COMPB (OC0B) Timer/Counter0 Compare Match B
|
||||
reti ; 12: TIM0_OVF (OVF0) Timer/Counter0 Overflow
|
||||
reti ; 13: ANA_COMP0 Analog Comparator 0
|
||||
reti ; 14: ADC_READY ADC Conversion Complete
|
||||
reti ; 15: EE_RDY (ERDY) EEPROM Ready
|
||||
reti ; 16: ANA_COMP1 Analog Comparator 1
|
||||
reti ; 17: TIM2_CAPT Timer/Counter2 Capture Event
|
||||
reti ; 18: TIM2_COMPA (OC2A) Timer/Counter2 Compare Match A
|
||||
reti ; 19: TIM2_COMPB (OC2B) Timer/Counter2 Compare Match B
|
||||
reti ; 20: TIM2_OVF (OVF2) Timer/Counter2 Overflow
|
||||
reti ; 21: SPI SPI Serial Transfer Complete
|
||||
reti ; 22: USART0_RXS USART0 Rx Start
|
||||
reti ; 23: USART0_RXC USART0 Rx Complete
|
||||
reti ; 24: USART0_DRE USART0 Data Register Empty
|
||||
reti ; 25: USART0_TXC USART0 Tx Complete
|
||||
reti ; 26: USART1_RXS USART1 Rx Start
|
||||
reti ; 27: USART1_RXC USART1 Rx Complete
|
||||
reti ; 28: USART1_DRE USART1 Data Register Empty
|
||||
reti ; 29: USART1_TXC USART1 Tx Complete
|
||||
reti ; 30: TWI Two-Wire-Interface
|
||||
reti ; 31: RESERVED reserved
|
||||
|
||||
|
||||
|
||||
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 debugFlash
|
||||
; rjmp debugEchoUart1
|
||||
; rjmp bootLoader ; this routine is in modules/bootloader/main.asm
|
||||
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; includes
|
||||
|
||||
;.include "modules/uart_hw/raw_uart1.asm"
|
||||
.include "modules/com2/crc.asm"
|
||||
.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_uart1.asm"
|
||||
.include "modules/flash/flash4p.asm"
|
||||
;.include "modules/flash/flashprocess.asm"
|
||||
.include "modules/flash/wait.asm"
|
||||
;.include "modules/bootloader/main.asm"
|
||||
|
||||
|
||||
|
||||
systemSetSpeed:
|
||||
.if clock == 1000000
|
||||
ldi r17, 0xd8
|
||||
ldi r16, (1<<CLKPS1) | (1<<CLKPS0) ; SUT=0, CLKPS=0011b
|
||||
sts CCP, r17
|
||||
sts CLKPR, r16
|
||||
.endif
|
||||
|
||||
.if clock == 8000000
|
||||
ldi r17, 0xd8
|
||||
clr r16 ; SUT=0, CLKPS=0
|
||||
sts CCP, r17
|
||||
sts CLKPR, r16
|
||||
.endif
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.dseg
|
||||
|
||||
debugFlashBuffer: .byte 32
|
||||
flashUid: .byte 4
|
||||
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
|
||||
debugFlash:
|
||||
cli
|
||||
; setup stack
|
||||
.ifdef SPH ; if SPH is defined
|
||||
ldi r16, High(RAMEND)
|
||||
out SPH, r16 ; init MSB stack pointer
|
||||
.endif
|
||||
ldi r16, Low(RAMEND)
|
||||
out SPL, r16 ; init LSB stack pointer
|
||||
|
||||
rcall systemSetSpeed
|
||||
|
||||
sbi LED_DDR, LED_PINNUM ; out
|
||||
cbi LED_PORT, LED_PINNUM ; on
|
||||
|
||||
; set baudrate
|
||||
.if clock == 8000000
|
||||
ldi r16, 25 ; (19.2Kb/s at 8MHz)
|
||||
ldi r17, 0
|
||||
.endif
|
||||
|
||||
.if clock == 1000000
|
||||
ldi r16, 3 ; (19.2Kb/s at 1MHz)
|
||||
ldi r17, 0
|
||||
.endif
|
||||
|
||||
sts UBRR1H, r17
|
||||
sts UBRR1L, r16
|
||||
|
||||
; set character format (asynchronous USART, 8-bit, one stop bit, no parity)
|
||||
ldi r16, (3<<UCSZ10)
|
||||
sts UCSR1C, r16
|
||||
|
||||
; enable transceiver
|
||||
lds r16, UCSR1B
|
||||
; cbr r16, (1<<UDRIE1) ; disable DRE interrupt
|
||||
ori r16, (1<<RXEN1) | (1<<TXEN1) ; enable transmit and receive
|
||||
sts UCSR1B, r16
|
||||
|
||||
|
||||
ldi xl, LOW(debugFlashBuffer)
|
||||
ldi xh, HIGH(debugFlashBuffer)
|
||||
ldi r17, 32
|
||||
clr r16
|
||||
debugFlash_loop1:
|
||||
st X+, r16
|
||||
inc r16
|
||||
dec r17
|
||||
brne debugFlash_loop1
|
||||
|
||||
rcall Flash_Init
|
||||
ldi yl, LOW(debugFlashBuffer)
|
||||
ldi yh, HIGH(debugFlashBuffer)
|
||||
ldi zl, LOW(0x500)
|
||||
ldi zh, HIGH(0x500)
|
||||
ldi r17, 32
|
||||
rcall Flash_WriteData
|
||||
|
||||
rcall Flash_Fini
|
||||
|
||||
debugFlash_loop2:
|
||||
sbi LED_PIN, LED_PINNUM ; toggle
|
||||
ldi zl, LOW(0x500)
|
||||
ldi zh, HIGH(0x500)
|
||||
ldi r18, 64
|
||||
rcall debugDumpFlash
|
||||
|
||||
ldi r16, 50
|
||||
rcall flashWaitForMulti100ms ; print every 5 secs
|
||||
rjmp debugFlash_loop2
|
||||
ret
|
||||
|
||||
|
||||
|
||||
debugWriteString:
|
||||
lpm r16, Z+
|
||||
tst r16
|
||||
breq debugWriteString_done
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
rjmp debugWriteString
|
||||
debugWriteString_done:
|
||||
ret
|
||||
|
||||
|
||||
debugString: .db "FLASH", 13, 10, 0
|
||||
|
||||
|
||||
#if 0
|
||||
debugPrintLoop:
|
||||
sbi LED_PORT, LED_PINNUM ; off
|
||||
; enable transceiver
|
||||
lds r17, UCSR1B
|
||||
; cbr r17, (1<<UDRIE1) ; disable DRE interrupt
|
||||
ori r17, (1<<RXEN1) | (1<<TXEN1) ; enable transmit and receive
|
||||
sts UCSR1B, r17
|
||||
|
||||
debugPrintLoop1:
|
||||
push r16
|
||||
rcall debugPrintHexByte
|
||||
ldi r16, 13
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
ldi r16, 10
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
ldi r16, 10
|
||||
rcall flashWaitForMulti100ms
|
||||
pop r16
|
||||
rjmp debugPrintLoop1
|
||||
#endif
|
||||
|
||||
|
||||
; @param Z start of FLASH to dump
|
||||
; @param r18: number of bytes to dump
|
||||
|
||||
debugDumpFlash:
|
||||
push zh
|
||||
push zl
|
||||
ldi zl, LOW(debugString*2)
|
||||
ldi zh, HIGH(debugString*2)
|
||||
rcall debugWriteString
|
||||
pop zl
|
||||
pop zh
|
||||
debugDumpFlash_loop1:
|
||||
mov r16, zh
|
||||
rcall debugPrintHexByte
|
||||
mov r16, zl
|
||||
rcall debugPrintHexByte
|
||||
ldi r16, ':'
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
ldi r16, ' '
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
ldi r19, 16
|
||||
debugDumpFlash_loop2:
|
||||
lpm r16, Z+
|
||||
rcall debugPrintHexByte
|
||||
ldi r16, ' '
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
dec r18
|
||||
breq debugDumpFlash_done
|
||||
dec r19
|
||||
brne debugDumpFlash_loop2
|
||||
ldi r16, 13
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
ldi r16, 10
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
rjmp debugDumpFlash_loop1
|
||||
debugDumpFlash_done:
|
||||
ldi r16, 13
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
ldi r16, 10
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine debugPrintHexByte
|
||||
;
|
||||
; Convert a give byte into HEX and write it to USART1.
|
||||
;
|
||||
; @return CFLAG set if okay, cleared on error
|
||||
; @param R16 byte to convert to print
|
||||
; @clobbers r16, r20 (r17)
|
||||
|
||||
debugPrintHexByte:
|
||||
mov r20, r16
|
||||
swap r16
|
||||
rcall debugNibbleToAscii ; write high nibble (r17)
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
brcc debugPrintHexByte_error
|
||||
mov r16, r20
|
||||
rcall debugNibbleToAscii ; write low nibble (r17)
|
||||
rcall debugPrintOneChar ; (r17)
|
||||
brcc debugPrintHexByte_error
|
||||
sec
|
||||
ret
|
||||
debugPrintHexByte_error:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine debugNibbleToAscii
|
||||
;
|
||||
; Convert a nibble to an ASCII char.
|
||||
; @return R16 ASCII representation of that nibble (e.g. '0' for 0)
|
||||
; @param R16 byte (in bits 0-3)
|
||||
; @clobbers r17
|
||||
|
||||
debugNibbleToAscii:
|
||||
andi r16, 0xf
|
||||
cpi r16, 10
|
||||
brcs debugNibbleToAscii_l1
|
||||
ldi r17, 7
|
||||
add r16, r17
|
||||
debugNibbleToAscii_l1:
|
||||
ldi r17, '0'
|
||||
add r16, r17
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine debugPrintOneChar
|
||||
;
|
||||
; Write one byte to UART1.
|
||||
; @param R16 byte to send
|
||||
; @clobbers r17
|
||||
|
||||
debugPrintOneChar:
|
||||
lds r17, UCSR1A
|
||||
sbrs r17, UDRE1
|
||||
rjmp debugPrintOneChar
|
||||
sbr r17, (1<<TXC1)
|
||||
sts UCSR1A, r17
|
||||
sts UDR1, r16
|
||||
sec
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,749 +0,0 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; Source file for temperature sensor node on AtTiny 84
|
||||
;
|
||||
; This is for the full system (i.e. not the boot loader).
|
||||
;
|
||||
; All definitions and changes should go into this file.
|
||||
;
|
||||
;
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
;.equ clock=1000000 ; Define the clock frequency
|
||||
.equ clock=8000000 ; Define the clock frequency
|
||||
|
||||
;.equ SEND_DEVICE_EVERY = 3000
|
||||
.equ SEND_DEVICE_EVERY = 3000 ; every 5mins
|
||||
.equ SEND_STATS_EVERY = 3100 ; about every 5mins
|
||||
;.equ SEND_STATS_EVERY = 300 ; every 30s
|
||||
;.equ SEND_DEBUG_EVERY = 110
|
||||
|
||||
;#define WITH_SEND_DEBUG
|
||||
|
||||
|
||||
.nolist
|
||||
.include "include/tn841def.inc" ; Define device ATtiny841
|
||||
.list
|
||||
|
||||
.include "./defs.asm"
|
||||
.include "defs_all.asm"
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; defines
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; generic
|
||||
|
||||
|
||||
.include "common/utils_wait.asm"
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; 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_COM
|
||||
;#define MODULES_COM_WITH_ADDR_PROTO
|
||||
;#define MODULES_LED
|
||||
#define MODULES_LED_SIMPLE
|
||||
;#define MODULES_TWI_MASTER
|
||||
;#define MODULES_LCD
|
||||
;#define LCD_MINIMAL_FONT
|
||||
;#define MODULES_SI7021
|
||||
;#define MODULES_STATS
|
||||
;#define MODULES_CNY70
|
||||
;#define MODULES_REED
|
||||
;#define MODULES_OWI_MASTER
|
||||
;#define MODULES_DS18B20
|
||||
;#define MODULES_MOTION
|
||||
|
||||
|
||||
.equ NET_BUFFERS_NUM = 8
|
||||
.equ NET_BUFFERS_SIZE = 32
|
||||
|
||||
.equ UART_HW_MSGNUMINBUF_SIZE = 8
|
||||
.equ UART_HW_MSGNUMOUTBUF_SIZE = 8
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code segment
|
||||
|
||||
.cseg
|
||||
.org 000000
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Reset and interrupt vectors
|
||||
|
||||
rjmp BOOTLOADER_ADDR ; 1: RESET Reset vector use this for flashed system
|
||||
reti ; 2: INT0 External Interrupt Request 0
|
||||
rjmp ComOnUart0_AttnChangeIsr ; 3: PCINT0 Pin Change Interrupt 0
|
||||
reti ; 4: PCINT1 Pin Change Interrupt 1
|
||||
reti ; 5: WDT Watchdog Time-out
|
||||
reti ; 6: TIM1_CAPT Timer/Counter1 Capture Event
|
||||
reti ; 7: TIM1_COMPA (OC1A) Timer/Counter1 Compare Match A
|
||||
reti ; 8: TIM1_COMPB (OC1B) Timer/Counter1 Compare Match B
|
||||
reti ; 9: TIM1_OVF (OVF1) Timer/Counter1 Overflow
|
||||
rjmp baseTimerIrqOC0A ; 10: TIM0_COMPA (OC0A) Timer/Counter0 Compare Match A
|
||||
reti ; 11: TIM0_COMPB (OC0B) Timer/Counter0 Compare Match B
|
||||
reti ; 12: TIM0_OVF (OVF0) Timer/Counter0 Overflow
|
||||
reti ; 13: ANA_COMP0 Analog Comparator 0
|
||||
reti ; 14: ADC_READY ADC Conversion Complete
|
||||
reti ; 15: EE_RDY (ERDY) EEPROM Ready
|
||||
reti ; 16: ANA_COMP1 Analog Comparator 1
|
||||
reti ; 17: TIM2_CAPT Timer/Counter2 Capture Event
|
||||
reti ; 18: TIM2_COMPA (OC2A) Timer/Counter2 Compare Match A
|
||||
reti ; 19: TIM2_COMPB (OC2B) Timer/Counter2 Compare Match B
|
||||
reti ; 20: TIM2_OVF (OVF2) Timer/Counter2 Overflow
|
||||
reti ; 21: SPI SPI Serial Transfer Complete
|
||||
reti ; 22: USART0_RXS USART0 Rx Start
|
||||
rjmp ComOnUart0_RxCharIsr ; 23: USART0_RXC USART0 Rx Complete
|
||||
rjmp ComOnUart0_TxUdreIsr ; 24: USART0_DRE USART0 Data Register Empty
|
||||
rjmp ComOnUart0_TxCharIsr ; 25: USART0_TXC USART0 Tx Complete
|
||||
reti ; 26: USART1_RXS USART1 Rx Start
|
||||
rjmp TtyOnUart1_RxCharIsr ; 27: USART1_RXC USART1 Rx Complete
|
||||
rjmp TtyOnUart1_TxUdreIsr ; 28: USART1_DRE USART1 Data Register Empty
|
||||
rjmp TtyOnUart1_TxCharIsr ; 29: USART1_TXC USART1 Tx Complete
|
||||
reti ; 30: TWI Two-Wire-Interface
|
||||
reti ; 31: RESERVED reserved
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
firmwareStart:
|
||||
cli
|
||||
; setup stack
|
||||
.ifdef SPH ; if SPH is defined
|
||||
ldi r16, High(RAMEND)
|
||||
out SPH, r16 ; init MSB stack pointer
|
||||
.endif
|
||||
ldi r16, Low(RAMEND)
|
||||
out SPL, r16 ; init LSB stack pointer
|
||||
|
||||
rcall systemSetSpeed
|
||||
rcall initHardware
|
||||
; rcall watchdogOff ; turn off watchdog timer (sometimes it stays on after reboot)
|
||||
|
||||
rcall Utils_Init
|
||||
rcall Utils_SetupUid
|
||||
|
||||
rcall initModules
|
||||
|
||||
sbi LED_SIMPLE_DDR, LED_SIMPLE_PINNUM ; out
|
||||
sbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; off
|
||||
|
||||
sei
|
||||
main_loop:
|
||||
rcall BaseTimer_Run
|
||||
rcall TtyOnUart1_Run
|
||||
rcall ComOnUart0_Run
|
||||
|
||||
; check incoming msg
|
||||
rcall checkRecvdMsg
|
||||
; rcall freeRecvdMsg
|
||||
|
||||
; only modify SE, SM1 and SM0
|
||||
cli
|
||||
in r16, MCUCR
|
||||
ldi r17, (1<<SE) | (1<<SM1) | (1<<SM0)
|
||||
neg r17
|
||||
and r16, r17
|
||||
ori r16, (1<<SE) ; sleep mode "idle", enable
|
||||
out MCUCR, r16
|
||||
sei ; make sure interrupts really are enabled
|
||||
sleep ; sleep, wait for interrupt
|
||||
|
||||
rjmp main_loop
|
||||
|
||||
|
||||
|
||||
|
||||
systemSetSpeed:
|
||||
.if clock == 1000000
|
||||
ldi r17, 0xd8
|
||||
ldi r16, (1<<CLKPS1) | (1<<CLKPS0) ; SUT=0, CLKPS=0011b
|
||||
sts CCP, r17
|
||||
sts CLKPR, r16
|
||||
.endif
|
||||
|
||||
.if clock == 8000000
|
||||
ldi r17, 0xd8
|
||||
clr r16 ; SUT=0, CLKPS=0
|
||||
sts CCP, r17
|
||||
sts CLKPR, r16
|
||||
.endif
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Called every 100ms. Add your routine calls here. No arguments, no results.
|
||||
|
||||
onSystemTimerTick:
|
||||
#ifdef MODULES_LED_SIMPLE
|
||||
rcall LedSimple_Every100ms
|
||||
#endif
|
||||
rcall TtyOnUart1_Periodically
|
||||
rcall ComOnUart0_Periodically
|
||||
#ifdef WITH_SEND_DEBUG
|
||||
rcall sendDebug
|
||||
#endif
|
||||
; rcall maybeSendDeviceMsg
|
||||
rcall maybeSendTStatsMsg
|
||||
rcall maybeSendRStatsMsg
|
||||
rcall maybeSendMStatsMsg
|
||||
ret
|
||||
|
||||
|
||||
|
||||
initHardware:
|
||||
; set all ports as inputs and enable internal pull-up resistors
|
||||
ldi r16, 0xff
|
||||
clr r17
|
||||
.ifdef PORTA
|
||||
out DDRA, r17 ; all input
|
||||
sts PUEA, r16 ; enable pull-up on all
|
||||
.endif
|
||||
|
||||
.ifdef PORTB
|
||||
out DDRB, r17 ; all input
|
||||
sts PUEB, r16 ; enable pull-up on all
|
||||
.endif
|
||||
|
||||
.ifdef PORTC
|
||||
out DDRC, r17 ; all input
|
||||
sts PUEC, r16 ; enable pull-up on all
|
||||
.endif
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
initModules:
|
||||
rcall BaseTimer_Init
|
||||
rcall LedSimple_Init
|
||||
rcall NET_Init
|
||||
rcall TtyOnUart1_Init
|
||||
ldi r16, 0xfe
|
||||
sts ttyOnUart1_iface+NET_IFACE_OFFS_ADDRESS, r16
|
||||
rcall ComOnUart0_Init
|
||||
|
||||
ldi r16, LOW(SEND_DEVICE_EVERY)
|
||||
sts deviceCounter, r16
|
||||
ldi r16, HIGH(SEND_DEVICE_EVERY)
|
||||
sts deviceCounter+1, r16
|
||||
|
||||
ldi r16, LOW(SEND_STATS_EVERY)
|
||||
sts sendTStatsCounter, r16
|
||||
ldi r16, HIGH(SEND_STATS_EVERY)
|
||||
sts sendTStatsCounter+1, r16
|
||||
|
||||
ldi r16, LOW(SEND_STATS_EVERY+10)
|
||||
sts sendRStatsCounter, r16
|
||||
ldi r16, HIGH(SEND_STATS_EVERY+10)
|
||||
sts sendRStatsCounter+1, r16
|
||||
|
||||
ldi r16, LOW(SEND_STATS_EVERY+20)
|
||||
sts sendMStatsCounter, r16
|
||||
ldi r16, HIGH(SEND_STATS_EVERY+20)
|
||||
sts sendMStatsCounter+1, r16
|
||||
|
||||
#ifdef WITH_SEND_DEBUG
|
||||
ldi r16, LOW(SEND_DEBUG_EVERY)
|
||||
sts debugMsgCounter, r16
|
||||
ldi r16, HIGH(SEND_DEBUG_EVERY)
|
||||
sts debugMsgCounter+1, r16
|
||||
#endif
|
||||
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; includes
|
||||
|
||||
.include "common/utils.asm"
|
||||
.include "common/utils_wait.asm"
|
||||
.include "common/utils_wait_fixed.asm"
|
||||
.include "common/utils_copy_from_flash.asm"
|
||||
.include "common/utils_copy_sdram.asm"
|
||||
.include "common/m_ringbuffer_y.asm"
|
||||
.include "common/ringbuffer_y.asm"
|
||||
.include "common/m_fixedbuffers.asm"
|
||||
.include "modules/basetimer/main.asm"
|
||||
.include "modules/led_simple/main.asm"
|
||||
.include "modules/network/defs.asm"
|
||||
.include "modules/network/buffer.asm"
|
||||
.include "modules/network/data.asm"
|
||||
.include "modules/network/main.asm"
|
||||
.include "modules/network/iface.asm"
|
||||
.include "modules/network/msg/defs.asm"
|
||||
.include "modules/network/msg/common.asm"
|
||||
.include "modules/network/msg/crc.asm"
|
||||
.include "modules/network/msg/device-w.asm"
|
||||
.include "modules/network/msg/sendstats-w.asm"
|
||||
.include "modules/network/msg/recvstats-w.asm"
|
||||
.include "modules/network/msg/memstats-w.asm"
|
||||
.include "modules/network/msg/debug-w.asm"
|
||||
|
||||
.include "modules/uart_hw/defs.asm"
|
||||
.include "modules/uart_hw/lowlevel.asm"
|
||||
.include "modules/uart_hw/m_lowlevel_uart.asm"
|
||||
.include "modules/uart_hw/ttyonuart1.asm"
|
||||
.include "modules/uart_hw/comonuart0.asm"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
maybeSendDeviceMsg:
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
|
||||
lds r24, deviceCounter
|
||||
lds r25, deviceCounter+1
|
||||
sbiw r25:r24, 1
|
||||
brne maybeSendDeviceMsg_storeCounter
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc maybeSendDeviceMsg_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)
|
||||
brcc maybeSendDeviceMsg_end
|
||||
; reset counter
|
||||
maybeSendDeviceMsg_resetCounter:
|
||||
ldi r24, LOW(SEND_DEVICE_EVERY)
|
||||
ldi r25, HIGH(SEND_DEVICE_EVERY)
|
||||
maybeSendDeviceMsg_storeCounter:
|
||||
sts deviceCounter, r24
|
||||
sts deviceCounter+1, r25
|
||||
maybeSendDeviceMsg_end:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
maybeSendTStatsMsg:
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
|
||||
lds r24, sendTStatsCounter
|
||||
lds r25, sendTStatsCounter+1
|
||||
sbiw r25:r24, 1
|
||||
brne maybeSendTStatsMsg_storeCounter
|
||||
|
||||
rcall sendTStatsForUart0ToUart1
|
||||
|
||||
; reset counter
|
||||
maybeSendTStatsMsg_resetCounter:
|
||||
ldi r24, LOW(SEND_STATS_EVERY)
|
||||
ldi r25, HIGH(SEND_STATS_EVERY)
|
||||
maybeSendTStatsMsg_storeCounter:
|
||||
sts sendTStatsCounter, r24
|
||||
sts sendTStatsCounter+1, r25
|
||||
maybeSendTStatsMsg_end:
|
||||
ret
|
||||
|
||||
|
||||
sendTStatsForUart0ToUart1:
|
||||
push yl
|
||||
push yh
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc sendTStatsForUart0ToUart1_end
|
||||
push r16
|
||||
ldi yl, LOW(comOnUart0_iface)
|
||||
ldi yh, HIGH(comOnUart0_iface)
|
||||
adiw xh:xl, 1
|
||||
rcall NETMSG_SendStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
|
||||
sendTStatsForUart0ToUart1_end:
|
||||
pop yh
|
||||
pop yl
|
||||
ret
|
||||
|
||||
|
||||
|
||||
maybeSendRStatsMsg:
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
|
||||
lds r24, sendRStatsCounter
|
||||
lds r25, sendRStatsCounter+1
|
||||
sbiw r25:r24, 1
|
||||
brne maybeSendRStatsMsg_storeCounter
|
||||
|
||||
rcall sendRStatsForUart0ToUart1
|
||||
; rcall sendRStatsForUart1ToUart1
|
||||
|
||||
; reset counter
|
||||
maybeSendRStatsMsg_resetCounter:
|
||||
ldi r24, LOW(SEND_STATS_EVERY)
|
||||
ldi r25, HIGH(SEND_STATS_EVERY)
|
||||
maybeSendRStatsMsg_storeCounter:
|
||||
sts sendRStatsCounter, r24
|
||||
sts sendRStatsCounter+1, r25
|
||||
maybeSendRStatsMsg_end:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
sendRStatsForUart0ToUart1:
|
||||
push yl
|
||||
push yh
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc sendRStatsForUart0ToUart1_end
|
||||
push r16
|
||||
ldi yl, LOW(comOnUart0_iface)
|
||||
ldi yh, HIGH(comOnUart0_iface)
|
||||
adiw xh:xl, 1
|
||||
rcall NETMSG_RecvStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
|
||||
sendRStatsForUart0ToUart1_end:
|
||||
pop yh
|
||||
pop yl
|
||||
ret
|
||||
|
||||
|
||||
|
||||
sendRStatsForUart1ToUart1:
|
||||
push yl
|
||||
push yh
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc sendRStatsForUart1ToUart1_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)
|
||||
sendRStatsForUart1ToUart1_end:
|
||||
pop yh
|
||||
pop yl
|
||||
ret
|
||||
|
||||
|
||||
|
||||
maybeSendMStatsMsg:
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
|
||||
lds r24, sendMStatsCounter
|
||||
lds r25, sendMStatsCounter+1
|
||||
sbiw r25:r24, 1
|
||||
brne maybeSendMStatsMsg_storeCounter
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
; brcc maybeSendTStatsMsg_resetCounter
|
||||
brcc maybeSendMStatsMsg_end
|
||||
push r16
|
||||
adiw xh:xl, 1
|
||||
rcall NETMSG_MemStats_Write ; (R16, R17, R18, R19, R20, R21)
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
|
||||
brcc maybeSendMStatsMsg_end
|
||||
; reset counter
|
||||
maybeSendMStatsMsg_resetCounter:
|
||||
ldi r24, LOW(SEND_STATS_EVERY)
|
||||
ldi r25, HIGH(SEND_STATS_EVERY)
|
||||
maybeSendMStatsMsg_storeCounter:
|
||||
sts sendMStatsCounter, r24
|
||||
sts sendMStatsCounter+1, r25
|
||||
maybeSendMStatsMsg_end:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
checkRecvdMsg:
|
||||
rcall NET_PeekNextIncomingMsgNum ; check read queue (bufNum->r16)
|
||||
brcc checkRecvdMsg_end ; no msg, jmp
|
||||
rcall NET_Buffer_Locate ; (R17)
|
||||
ld r17, X
|
||||
andi r17, (NET_IFACE_BUFFER_IFACENUM1_BIT | NET_IFACE_BUFFER_IFACENUM0_BIT)
|
||||
rcall reverseInterfaceNum ; (R17)
|
||||
; ldi r17, TTYONUART1_IFACENUM ; DEBUG: send everything to uart1 to test that code first
|
||||
rcall addMsgToInterface
|
||||
brcc checkRecvdMsg_end ; could not add, jmp
|
||||
rcall NET_GetNextIncomingMsgNum ; take off the queue
|
||||
rjmp checkRecvdMsg
|
||||
checkRecvdMsg_end:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
freeRecvdMsg:
|
||||
rcall NET_GetNextIncomingMsgNum ; take off the queue
|
||||
brcc freeRecvdMsg_end
|
||||
rcall NET_Buffer_ReleaseByNum ; delete
|
||||
freeRecvdMsg_end:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; @return r17 reversed interface number
|
||||
; @param r17 buffer num
|
||||
; @clobbers r17
|
||||
|
||||
reverseInterfaceNum:
|
||||
cpi r17, COMONUART0_IFACENUM
|
||||
brne reverseInterfaceNum_notUart0
|
||||
ldi r17, TTYONUART1_IFACENUM
|
||||
ret
|
||||
reverseInterfaceNum_notUart0:
|
||||
ldi r17, COMONUART0_IFACENUM
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; @param r16 buffer num
|
||||
; @param r17 interface num
|
||||
|
||||
addMsgToInterface:
|
||||
cpi r17, COMONUART0_IFACENUM
|
||||
brne addMsgToInterface_notUart0
|
||||
ldi yl, LOW(comOnUart0_iface)
|
||||
ldi yh, HIGH(comOnUart0_iface)
|
||||
rjmp NET_Interface_AddOutgoingMsgNum ; try to add msg to interface
|
||||
addMsgToInterface_notUart0:
|
||||
cpi r17, TTYONUART1_IFACENUM
|
||||
brne addMsgToInterface_end
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
rjmp NET_Interface_AddOutgoingMsgNum ; try to add msg to interface
|
||||
addMsgToInterface_end:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
#ifdef WITH_SEND_DEBUG
|
||||
sendDebug:
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
|
||||
lds r24, debugMsgCounter
|
||||
lds r25, debugMsgCounter+1
|
||||
sbiw r25:r24, 1
|
||||
brne sendDebug_storeCounter
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc sendDebug_end
|
||||
push r16
|
||||
adiw xh:xl, 1
|
||||
rcall writeDebugMsg
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
|
||||
brcc sendDebug_end
|
||||
; reset counter
|
||||
sendDebug_resetCounter:
|
||||
ldi r24, LOW(SEND_DEBUG_EVERY)
|
||||
ldi r25, HIGH(SEND_DEBUG_EVERY)
|
||||
sendDebug_storeCounter:
|
||||
sts debugMsgCounter, r24
|
||||
sts debugMsgCounter+1, r25
|
||||
sendDebug_end:
|
||||
ret
|
||||
|
||||
|
||||
writeDebugMsg:
|
||||
push yl
|
||||
push yh
|
||||
ldi yl, LOW(netBuffers)
|
||||
ldi yh, HIGH(netBuffers)
|
||||
|
||||
rcall writeBufferInfoToRegs
|
||||
mov r0, r17
|
||||
mov r1, r18
|
||||
adiw yh:yl, NET_BUFFERS_SIZE
|
||||
|
||||
rcall writeBufferInfoToRegs
|
||||
mov r2, r17
|
||||
mov r3, r18
|
||||
adiw yh:yl, NET_BUFFERS_SIZE
|
||||
|
||||
rcall writeBufferInfoToRegs
|
||||
mov r4, r17
|
||||
mov r5, r18
|
||||
adiw yh:yl, NET_BUFFERS_SIZE
|
||||
|
||||
rcall writeBufferInfoToRegs
|
||||
mov r6, r17
|
||||
mov r7, r18
|
||||
adiw yh:yl, NET_BUFFERS_SIZE
|
||||
|
||||
rcall writeBufferInfoToRegs
|
||||
mov r8, r17
|
||||
mov r9, r18
|
||||
adiw yh:yl, NET_BUFFERS_SIZE
|
||||
|
||||
rcall writeBufferInfoToRegs
|
||||
mov r10, r17
|
||||
mov r11, r18
|
||||
adiw yh:yl, NET_BUFFERS_SIZE
|
||||
|
||||
clr r12
|
||||
clr r13
|
||||
|
||||
push xl
|
||||
push xh
|
||||
rcall NET_Buffer_CountUsed
|
||||
pop xh
|
||||
pop xl
|
||||
mov r14, r16
|
||||
pop yh
|
||||
pop yl
|
||||
|
||||
rcall NETMSG_Debug_Write ; (R16, R17, R18, R19, R20, R21, Z)
|
||||
ret
|
||||
|
||||
|
||||
|
||||
writeBufferInfoToRegs:
|
||||
ldi r17, 0xff
|
||||
ldi r18, 0xff
|
||||
ld r16, Y
|
||||
andi r16, 0x80
|
||||
breq writeBufferInfoToRegs_end
|
||||
ldd r17, Y+(1+2) ; cmd code
|
||||
ldd r18, Y+(1+3) ; source addr
|
||||
writeBufferInfoToRegs_end:
|
||||
ret
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
DEBUG1:
|
||||
ldi r19, 10
|
||||
ldi r20, 2
|
||||
ldi r21, 8
|
||||
rcall blinkLed
|
||||
rjmp DEBUG1
|
||||
|
||||
|
||||
DEBUG2:
|
||||
ldi r19, 50
|
||||
ldi r20, 1
|
||||
ldi r21, 1
|
||||
rcall blinkLed
|
||||
rjmp DEBUG2
|
||||
|
||||
|
||||
|
||||
; @param r19 loop count
|
||||
; @param r20 on time
|
||||
; @param r21 off time
|
||||
; @clobbers (R16, R18, R22, R24, R25)
|
||||
|
||||
blinkLed:
|
||||
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
|
||||
mov r22, r20
|
||||
rcall waitForMultiple100ms ; (R252
|
||||
sbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; off
|
||||
mov r22, r21
|
||||
rcall waitForMultiple100ms ; (R22)
|
||||
dec r19
|
||||
brne blinkLed
|
||||
ret
|
||||
|
||||
|
||||
; @param r22 number of 100ms periods to wait
|
||||
waitForMultiple100ms:
|
||||
waitForMultiple100ms_loop:
|
||||
push r22
|
||||
rcall waitFor100ms
|
||||
pop r22
|
||||
dec r22
|
||||
brne waitForMultiple100ms_loop
|
||||
ret
|
||||
|
||||
|
||||
waitFor100ms:
|
||||
ldi r22, 10
|
||||
waitFor100ms_loop:
|
||||
push r22
|
||||
rcall waitFor10ms
|
||||
pop r22
|
||||
dec r22
|
||||
brne waitFor100ms_loop
|
||||
ret
|
||||
|
||||
waitFor10ms:
|
||||
ldi r22, 100
|
||||
waitFor10ms_loop:
|
||||
push r22
|
||||
rcall Utils_WaitFor100MicroSecs
|
||||
pop r22
|
||||
dec r22
|
||||
brne waitFor10ms_loop
|
||||
ret
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; data in SRAM
|
||||
|
||||
.dseg
|
||||
|
||||
programRamBegin:
|
||||
flashUid: .byte 4
|
||||
deviceCounter: .byte 2
|
||||
sendTStatsCounter: .byte 2
|
||||
sendRStatsCounter: .byte 2
|
||||
sendMStatsCounter: .byte 2
|
||||
#ifdef WITH_SEND_DEBUG
|
||||
debugMsgCounter: .byte 2
|
||||
#endif
|
||||
programRamEnd:
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
|
||||
<sources type="avrasm" >
|
||||
main2.asm
|
||||
main.asm
|
||||
</sources>
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
</subdirs>
|
||||
|
||||
<extradist>
|
||||
data.asm
|
||||
</extradist>
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +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
|
||||
|
||||
|
||||
programRamBegin:
|
||||
flashUid: .byte 4
|
||||
programRamEnd:
|
||||
|
||||
@@ -24,14 +24,6 @@
|
||||
;.equ clock=1000000 ; Define the clock frequency
|
||||
.equ clock=8000000 ; Define the clock frequency
|
||||
|
||||
;.equ SEND_DEVICE_EVERY = 3000
|
||||
.equ SEND_DEVICE_EVERY = 3000 ; every 5mins
|
||||
.equ SEND_STATS_EVERY = 3100 ; about every 5mins
|
||||
;.equ SEND_STATS_EVERY = 300 ; every 30s
|
||||
;.equ SEND_DEBUG_EVERY = 110
|
||||
|
||||
;#define WITH_SEND_DEBUG
|
||||
|
||||
|
||||
.nolist
|
||||
.include "include/tn841def.inc" ; Define device ATtiny841
|
||||
@@ -60,7 +52,9 @@
|
||||
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
|
||||
|
||||
|
||||
;#define MODULES_TIMER
|
||||
#define MAIN_WITHOUT_MSG_HANDLING ; we do message handling ourselfes
|
||||
|
||||
#define MODULES_CLOCK
|
||||
;#define MODULES_COM
|
||||
;#define MODULES_COM_WITH_ADDR_PROTO
|
||||
;#define MODULES_LED
|
||||
@@ -75,6 +69,11 @@
|
||||
;#define MODULES_OWI_MASTER
|
||||
;#define MODULES_DS18B20
|
||||
;#define MODULES_MOTION
|
||||
#define MODULES_NETWORK
|
||||
#define MODULES_TTYONUART1
|
||||
#define MODULES_COMONUART0
|
||||
#define APPS_STATS
|
||||
|
||||
|
||||
|
||||
.equ NET_BUFFERS_NUM = 8
|
||||
@@ -138,375 +137,80 @@ firmwareVersion: .db FIRMWARE_VARIANT_TEMP_WINDOW, FIRMWARE_VERSION_MAJOR
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine firmwareStart @global
|
||||
|
||||
firmwareStart:
|
||||
cli
|
||||
; setup stack
|
||||
.ifdef SPH ; if SPH is defined
|
||||
ldi r16, High(RAMEND)
|
||||
out SPH, r16 ; init MSB stack pointer
|
||||
.endif
|
||||
ldi r16, Low(RAMEND)
|
||||
out SPL, r16 ; init LSB stack pointer
|
||||
rjmp main
|
||||
; @end
|
||||
|
||||
rcall systemSetSpeed
|
||||
rcall initHardware
|
||||
; rcall watchdogOff ; turn off watchdog timer (sometimes it stays on after reboot)
|
||||
|
||||
rcall Utils_Init
|
||||
rcall Utils_SetupUid
|
||||
|
||||
rcall initModules
|
||||
|
||||
sbi LED_SIMPLE_DDR, LED_SIMPLE_PINNUM ; out
|
||||
sbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; off
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine onSystemStart
|
||||
|
||||
sei
|
||||
main_loop:
|
||||
rcall BaseTimer_Run
|
||||
rcall TtyOnUart1_Run
|
||||
rcall ComOnUart0_Run
|
||||
|
||||
; check incoming msg
|
||||
rcall checkRecvdMsg
|
||||
; rcall freeRecvdMsg
|
||||
|
||||
; only modify SE, SM1 and SM0
|
||||
cli
|
||||
in r16, MCUCR
|
||||
ldi r17, (1<<SE) | (1<<SM1) | (1<<SM0)
|
||||
neg r17
|
||||
and r16, r17
|
||||
ori r16, (1<<SE) ; sleep mode "idle", enable
|
||||
out MCUCR, r16
|
||||
sei ; make sure interrupts really are enabled
|
||||
sleep ; sleep, wait for interrupt
|
||||
|
||||
rjmp main_loop
|
||||
onSystemStart:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
systemSetSpeed:
|
||||
.if clock == 1000000
|
||||
ldi r17, 0xd8
|
||||
ldi r16, (1<<CLKPS1) | (1<<CLKPS0) ; SUT=0, CLKPS=0011b
|
||||
sts CCP, r17
|
||||
sts CLKPR, r16
|
||||
.endif
|
||||
|
||||
.if clock == 8000000
|
||||
ldi r17, 0xd8
|
||||
clr r16 ; SUT=0, CLKPS=0
|
||||
sts CCP, r17
|
||||
sts CLKPR, r16
|
||||
.endif
|
||||
|
||||
|
||||
onEvery100ms:
|
||||
onEverySecond:
|
||||
onEveryMinute:
|
||||
onEveryHour:
|
||||
onEveryDay:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Called every 100ms. Add your routine calls here. No arguments, no results.
|
||||
; @routine onEveryLoop
|
||||
;
|
||||
; Called on every loop (i.e. after awakening from sleep).
|
||||
|
||||
onSystemTimerTick:
|
||||
#ifdef MODULES_LED_SIMPLE
|
||||
rcall LedSimple_Every100ms
|
||||
#endif
|
||||
rcall TtyOnUart1_Periodically
|
||||
rcall ComOnUart0_Periodically
|
||||
#ifdef WITH_SEND_DEBUG
|
||||
rcall sendDebug
|
||||
#endif
|
||||
; rcall maybeSendDeviceMsg
|
||||
rcall maybeSendTStatsMsg
|
||||
rcall maybeSendRStatsMsg
|
||||
rcall maybeSendMStatsMsg
|
||||
ret
|
||||
|
||||
|
||||
|
||||
initHardware:
|
||||
; set all ports as inputs and enable internal pull-up resistors
|
||||
ldi r16, 0xff
|
||||
clr r17
|
||||
.ifdef PORTA
|
||||
out DDRA, r17 ; all input
|
||||
sts PUEA, r16 ; enable pull-up on all
|
||||
.endif
|
||||
|
||||
.ifdef PORTB
|
||||
out DDRB, r17 ; all input
|
||||
sts PUEB, r16 ; enable pull-up on all
|
||||
.endif
|
||||
|
||||
.ifdef PORTC
|
||||
out DDRC, r17 ; all input
|
||||
sts PUEC, r16 ; enable pull-up on all
|
||||
.endif
|
||||
onEveryLoop:
|
||||
rcall checkRecvdMsg
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
initModules:
|
||||
rcall BaseTimer_Init
|
||||
rcall LedSimple_Init
|
||||
rcall NET_Init
|
||||
rcall TtyOnUart1_Init
|
||||
ldi r16, 0xfe
|
||||
sts ttyOnUart1_iface+NET_IFACE_OFFS_ADDRESS, r16
|
||||
rcall ComOnUart0_Init
|
||||
|
||||
ldi r16, LOW(SEND_DEVICE_EVERY)
|
||||
sts deviceCounter, r16
|
||||
ldi r16, HIGH(SEND_DEVICE_EVERY)
|
||||
sts deviceCounter+1, r16
|
||||
|
||||
ldi r16, LOW(SEND_STATS_EVERY)
|
||||
sts sendTStatsCounter, r16
|
||||
ldi r16, HIGH(SEND_STATS_EVERY)
|
||||
sts sendTStatsCounter+1, r16
|
||||
|
||||
ldi r16, LOW(SEND_STATS_EVERY+10)
|
||||
sts sendRStatsCounter, r16
|
||||
ldi r16, HIGH(SEND_STATS_EVERY+10)
|
||||
sts sendRStatsCounter+1, r16
|
||||
|
||||
ldi r16, LOW(SEND_STATS_EVERY+20)
|
||||
sts sendMStatsCounter, r16
|
||||
ldi r16, HIGH(SEND_STATS_EVERY+20)
|
||||
sts sendMStatsCounter+1, r16
|
||||
|
||||
#ifdef WITH_SEND_DEBUG
|
||||
ldi r16, LOW(SEND_DEBUG_EVERY)
|
||||
sts debugMsgCounter, r16
|
||||
ldi r16, HIGH(SEND_DEBUG_EVERY)
|
||||
sts debugMsgCounter+1, r16
|
||||
#endif
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine onMessageReceived
|
||||
;
|
||||
; Called on every message received
|
||||
|
||||
onMessageReceived:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; includes
|
||||
|
||||
.include "common/utils.asm"
|
||||
.include "common/utils_wait.asm"
|
||||
.include "common/utils_wait_fixed.asm"
|
||||
.include "common/utils_copy_from_flash.asm"
|
||||
.include "common/utils_copy_sdram.asm"
|
||||
.include "common/m_ringbuffer_y.asm"
|
||||
.include "common/ringbuffer_y.asm"
|
||||
.include "common/m_fixedbuffers.asm"
|
||||
.include "modules/basetimer/main.asm"
|
||||
.include "modules/led_simple/main.asm"
|
||||
.include "modules/network/defs.asm"
|
||||
.include "modules/network/buffer.asm"
|
||||
.include "modules/network/data.asm"
|
||||
.include "modules/network/main.asm"
|
||||
.include "modules/network/iface.asm"
|
||||
.include "modules/network/msg/defs.asm"
|
||||
.include "modules/network/msg/common.asm"
|
||||
.include "modules/network/msg/crc.asm"
|
||||
.include "modules/network/msg/device-w.asm"
|
||||
.include "modules/network/msg/sendstats-w.asm"
|
||||
.include "modules/network/msg/recvstats-w.asm"
|
||||
.include "modules/network/msg/memstats-w.asm"
|
||||
.include "modules/network/msg/debug-w.asm"
|
||||
|
||||
.include "modules/uart_hw/defs.asm"
|
||||
.include "modules/uart_hw/lowlevel.asm"
|
||||
.include "modules/uart_hw/m_lowlevel_uart.asm"
|
||||
.include "modules/uart_hw/ttyonuart1.asm"
|
||||
.include "modules/uart_hw/comonuart0.asm"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
maybeSendDeviceMsg:
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
|
||||
lds r24, deviceCounter
|
||||
lds r25, deviceCounter+1
|
||||
sbiw r25:r24, 1
|
||||
brne maybeSendDeviceMsg_storeCounter
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc maybeSendDeviceMsg_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)
|
||||
brcc maybeSendDeviceMsg_end
|
||||
; reset counter
|
||||
maybeSendDeviceMsg_resetCounter:
|
||||
ldi r24, LOW(SEND_DEVICE_EVERY)
|
||||
ldi r25, HIGH(SEND_DEVICE_EVERY)
|
||||
maybeSendDeviceMsg_storeCounter:
|
||||
sts deviceCounter, r24
|
||||
sts deviceCounter+1, r25
|
||||
maybeSendDeviceMsg_end:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
maybeSendTStatsMsg:
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
|
||||
lds r24, sendTStatsCounter
|
||||
lds r25, sendTStatsCounter+1
|
||||
sbiw r25:r24, 1
|
||||
brne maybeSendTStatsMsg_storeCounter
|
||||
|
||||
rcall sendTStatsForUart0ToUart1
|
||||
|
||||
; reset counter
|
||||
maybeSendTStatsMsg_resetCounter:
|
||||
ldi r24, LOW(SEND_STATS_EVERY)
|
||||
ldi r25, HIGH(SEND_STATS_EVERY)
|
||||
maybeSendTStatsMsg_storeCounter:
|
||||
sts sendTStatsCounter, r24
|
||||
sts sendTStatsCounter+1, r25
|
||||
maybeSendTStatsMsg_end:
|
||||
ret
|
||||
|
||||
|
||||
sendTStatsForUart0ToUart1:
|
||||
push yl
|
||||
push yh
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc sendTStatsForUart0ToUart1_end
|
||||
push r16
|
||||
ldi yl, LOW(comOnUart0_iface)
|
||||
ldi yh, HIGH(comOnUart0_iface)
|
||||
adiw xh:xl, 1
|
||||
rcall NETMSG_SendStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
|
||||
sendTStatsForUart0ToUart1_end:
|
||||
pop yh
|
||||
pop yl
|
||||
ret
|
||||
|
||||
|
||||
|
||||
maybeSendRStatsMsg:
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
|
||||
lds r24, sendRStatsCounter
|
||||
lds r25, sendRStatsCounter+1
|
||||
sbiw r25:r24, 1
|
||||
brne maybeSendRStatsMsg_storeCounter
|
||||
|
||||
rcall sendRStatsForUart0ToUart1
|
||||
; rcall sendRStatsForUart1ToUart1
|
||||
|
||||
; reset counter
|
||||
maybeSendRStatsMsg_resetCounter:
|
||||
ldi r24, LOW(SEND_STATS_EVERY)
|
||||
ldi r25, HIGH(SEND_STATS_EVERY)
|
||||
maybeSendRStatsMsg_storeCounter:
|
||||
sts sendRStatsCounter, r24
|
||||
sts sendRStatsCounter+1, r25
|
||||
maybeSendRStatsMsg_end:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
sendRStatsForUart0ToUart1:
|
||||
push yl
|
||||
push yh
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc sendRStatsForUart0ToUart1_end
|
||||
push r16
|
||||
ldi yl, LOW(comOnUart0_iface)
|
||||
ldi yh, HIGH(comOnUart0_iface)
|
||||
adiw xh:xl, 1
|
||||
rcall NETMSG_RecvStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
|
||||
sendRStatsForUart0ToUart1_end:
|
||||
pop yh
|
||||
pop yl
|
||||
ret
|
||||
|
||||
|
||||
|
||||
sendRStatsForUart1ToUart1:
|
||||
push yl
|
||||
push yh
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc sendRStatsForUart1ToUart1_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)
|
||||
sendRStatsForUart1ToUart1_end:
|
||||
pop yh
|
||||
pop yl
|
||||
ret
|
||||
|
||||
|
||||
|
||||
maybeSendMStatsMsg:
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
|
||||
lds r24, sendMStatsCounter
|
||||
lds r25, sendMStatsCounter+1
|
||||
sbiw r25:r24, 1
|
||||
brne maybeSendMStatsMsg_storeCounter
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
; brcc maybeSendTStatsMsg_resetCounter
|
||||
brcc maybeSendMStatsMsg_end
|
||||
push r16
|
||||
adiw xh:xl, 1
|
||||
rcall NETMSG_MemStats_Write ; (R16, R17, R18, R19, R20, R21)
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
|
||||
brcc maybeSendMStatsMsg_end
|
||||
; reset counter
|
||||
maybeSendMStatsMsg_resetCounter:
|
||||
ldi r24, LOW(SEND_STATS_EVERY)
|
||||
ldi r25, HIGH(SEND_STATS_EVERY)
|
||||
maybeSendMStatsMsg_storeCounter:
|
||||
sts sendMStatsCounter, r24
|
||||
sts sendMStatsCounter+1, r25
|
||||
maybeSendMStatsMsg_end:
|
||||
ret
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine checkRecvdMsg
|
||||
;
|
||||
; Read messages from either interface and forward to the other one.
|
||||
|
||||
checkRecvdMsg:
|
||||
rcall NET_PeekNextIncomingMsgNum ; check read queue (bufNum->r16)
|
||||
brcc checkRecvdMsg_end ; no msg, jmp
|
||||
rcall NET_Buffer_Locate ; (R17)
|
||||
; let system handle incoming messages
|
||||
push xl
|
||||
push xh
|
||||
rcall onMessageReceived
|
||||
rcall mainModulesOnPacketReceived
|
||||
rcall mainAppsOnPacketReceived
|
||||
pop xh
|
||||
pop xl
|
||||
|
||||
; forward to other interface
|
||||
ld r17, X
|
||||
andi r17, (NET_IFACE_BUFFER_IFACENUM1_BIT | NET_IFACE_BUFFER_IFACENUM0_BIT)
|
||||
rcall reverseInterfaceNum ; (R17)
|
||||
@@ -517,20 +221,15 @@ checkRecvdMsg:
|
||||
rjmp checkRecvdMsg
|
||||
checkRecvdMsg_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
freeRecvdMsg:
|
||||
rcall NET_GetNextIncomingMsgNum ; take off the queue
|
||||
brcc freeRecvdMsg_end
|
||||
rcall NET_Buffer_ReleaseByNum ; delete
|
||||
freeRecvdMsg_end:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; @return r17 reversed interface number
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine reverseInterfaceNum
|
||||
;
|
||||
; @param r17 buffer num
|
||||
; @return r17 reversed interface number
|
||||
; @clobbers r17
|
||||
|
||||
reverseInterfaceNum:
|
||||
@@ -545,6 +244,8 @@ reverseInterfaceNum_notUart0:
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine addMsgToInterface
|
||||
; @param r16 buffer num
|
||||
; @param r17 interface num
|
||||
|
||||
@@ -566,184 +267,23 @@ addMsgToInterface_end:
|
||||
; @end
|
||||
|
||||
|
||||
#ifdef WITH_SEND_DEBUG
|
||||
sendDebug:
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
|
||||
lds r24, debugMsgCounter
|
||||
lds r25, debugMsgCounter+1
|
||||
sbiw r25:r24, 1
|
||||
brne sendDebug_storeCounter
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc sendDebug_end
|
||||
push r16
|
||||
adiw xh:xl, 1
|
||||
rcall writeDebugMsg
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
|
||||
brcc sendDebug_end
|
||||
; reset counter
|
||||
sendDebug_resetCounter:
|
||||
ldi r24, LOW(SEND_DEBUG_EVERY)
|
||||
ldi r25, HIGH(SEND_DEBUG_EVERY)
|
||||
sendDebug_storeCounter:
|
||||
sts debugMsgCounter, r24
|
||||
sts debugMsgCounter+1, r25
|
||||
sendDebug_end:
|
||||
ret
|
||||
|
||||
|
||||
writeDebugMsg:
|
||||
push yl
|
||||
push yh
|
||||
ldi yl, LOW(netBuffers)
|
||||
ldi yh, HIGH(netBuffers)
|
||||
|
||||
rcall writeBufferInfoToRegs
|
||||
mov r0, r17
|
||||
mov r1, r18
|
||||
adiw yh:yl, NET_BUFFERS_SIZE
|
||||
|
||||
rcall writeBufferInfoToRegs
|
||||
mov r2, r17
|
||||
mov r3, r18
|
||||
adiw yh:yl, NET_BUFFERS_SIZE
|
||||
|
||||
rcall writeBufferInfoToRegs
|
||||
mov r4, r17
|
||||
mov r5, r18
|
||||
adiw yh:yl, NET_BUFFERS_SIZE
|
||||
|
||||
rcall writeBufferInfoToRegs
|
||||
mov r6, r17
|
||||
mov r7, r18
|
||||
adiw yh:yl, NET_BUFFERS_SIZE
|
||||
|
||||
rcall writeBufferInfoToRegs
|
||||
mov r8, r17
|
||||
mov r9, r18
|
||||
adiw yh:yl, NET_BUFFERS_SIZE
|
||||
|
||||
rcall writeBufferInfoToRegs
|
||||
mov r10, r17
|
||||
mov r11, r18
|
||||
adiw yh:yl, NET_BUFFERS_SIZE
|
||||
|
||||
clr r12
|
||||
clr r13
|
||||
|
||||
push xl
|
||||
push xh
|
||||
rcall NET_Buffer_CountUsed
|
||||
pop xh
|
||||
pop xl
|
||||
mov r14, r16
|
||||
pop yh
|
||||
pop yl
|
||||
|
||||
rcall NETMSG_Debug_Write ; (R16, R17, R18, R19, R20, R21, Z)
|
||||
ret
|
||||
|
||||
|
||||
|
||||
writeBufferInfoToRegs:
|
||||
ldi r17, 0xff
|
||||
ldi r18, 0xff
|
||||
ld r16, Y
|
||||
andi r16, 0x80
|
||||
breq writeBufferInfoToRegs_end
|
||||
ldd r17, Y+(1+2) ; cmd code
|
||||
ldd r18, Y+(1+3) ; source addr
|
||||
writeBufferInfoToRegs_end:
|
||||
ret
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
DEBUG1:
|
||||
ldi r19, 10
|
||||
ldi r20, 2
|
||||
ldi r21, 8
|
||||
rcall blinkLed
|
||||
rjmp DEBUG1
|
||||
|
||||
|
||||
DEBUG2:
|
||||
ldi r19, 50
|
||||
ldi r20, 1
|
||||
ldi r21, 1
|
||||
rcall blinkLed
|
||||
rjmp DEBUG2
|
||||
|
||||
|
||||
|
||||
; @param r19 loop count
|
||||
; @param r20 on time
|
||||
; @param r21 off time
|
||||
; @clobbers (R16, R18, R22, R24, R25)
|
||||
|
||||
blinkLed:
|
||||
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
|
||||
mov r22, r20
|
||||
rcall waitForMultiple100ms ; (R252
|
||||
sbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; off
|
||||
mov r22, r21
|
||||
rcall waitForMultiple100ms ; (R22)
|
||||
dec r19
|
||||
brne blinkLed
|
||||
ret
|
||||
|
||||
|
||||
; @param r22 number of 100ms periods to wait
|
||||
waitForMultiple100ms:
|
||||
waitForMultiple100ms_loop:
|
||||
push r22
|
||||
rcall waitFor100ms
|
||||
pop r22
|
||||
dec r22
|
||||
brne waitForMultiple100ms_loop
|
||||
ret
|
||||
|
||||
|
||||
waitFor100ms:
|
||||
ldi r22, 10
|
||||
waitFor100ms_loop:
|
||||
push r22
|
||||
rcall waitFor10ms
|
||||
pop r22
|
||||
dec r22
|
||||
brne waitFor100ms_loop
|
||||
ret
|
||||
|
||||
waitFor10ms:
|
||||
ldi r22, 100
|
||||
waitFor10ms_loop:
|
||||
push r22
|
||||
rcall Utils_WaitFor100MicroSecs
|
||||
pop r22
|
||||
dec r22
|
||||
brne waitFor10ms_loop
|
||||
ret
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; data in SRAM
|
||||
; includes
|
||||
|
||||
.dseg
|
||||
|
||||
programRamBegin:
|
||||
flashUid: .byte 4
|
||||
deviceCounter: .byte 2
|
||||
sendTStatsCounter: .byte 2
|
||||
sendRStatsCounter: .byte 2
|
||||
sendMStatsCounter: .byte 2
|
||||
#ifdef WITH_SEND_DEBUG
|
||||
debugMsgCounter: .byte 2
|
||||
#endif
|
||||
programRamEnd:
|
||||
.include "devices/all/hw_tn841.asm"
|
||||
.include "devices/all/includes.asm"
|
||||
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; defines for network interface
|
||||
|
||||
.equ netInterfaceData = ttyOnUart1_iface
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,289 +0,0 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; Source file for temperature sensor node on AtTiny 84
|
||||
;
|
||||
; This is for the full system (i.e. not the boot loader).
|
||||
;
|
||||
; All definitions and changes should go into this file.
|
||||
;
|
||||
;
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
;.equ clock=1000000 ; Define the clock frequency
|
||||
.equ clock=8000000 ; Define the clock frequency
|
||||
|
||||
|
||||
.nolist
|
||||
.include "include/tn841def.inc" ; Define device ATtiny841
|
||||
.list
|
||||
|
||||
.include "../defs.asm"
|
||||
.include "defs_all.asm"
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; defines
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; generic
|
||||
|
||||
|
||||
.include "common/utils_wait.asm"
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; 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
|
||||
|
||||
#define MODULES_CLOCK
|
||||
;#define MODULES_COM
|
||||
;#define MODULES_COM_WITH_ADDR_PROTO
|
||||
;#define MODULES_LED
|
||||
#define MODULES_LED_SIMPLE
|
||||
;#define MODULES_TWI_MASTER
|
||||
;#define MODULES_LCD
|
||||
;#define LCD_MINIMAL_FONT
|
||||
;#define MODULES_SI7021
|
||||
;#define MODULES_STATS
|
||||
;#define MODULES_CNY70
|
||||
;#define MODULES_REED
|
||||
;#define MODULES_OWI_MASTER
|
||||
;#define MODULES_DS18B20
|
||||
;#define MODULES_MOTION
|
||||
#define MODULES_NETWORK
|
||||
#define MODULES_TTYONUART1
|
||||
#define MODULES_COMONUART0
|
||||
#define APPS_STATS
|
||||
|
||||
|
||||
|
||||
.equ NET_BUFFERS_NUM = 8
|
||||
.equ NET_BUFFERS_SIZE = 32
|
||||
|
||||
.equ UART_HW_MSGNUMINBUF_SIZE = 8
|
||||
.equ UART_HW_MSGNUMOUTBUF_SIZE = 8
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code segment
|
||||
|
||||
.cseg
|
||||
.org 000000
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Reset and interrupt vectors
|
||||
|
||||
rjmp BOOTLOADER_ADDR ; 1: RESET Reset vector use this for flashed system
|
||||
reti ; 2: INT0 External Interrupt Request 0
|
||||
rjmp ComOnUart0_AttnChangeIsr ; 3: PCINT0 Pin Change Interrupt 0
|
||||
reti ; 4: PCINT1 Pin Change Interrupt 1
|
||||
reti ; 5: WDT Watchdog Time-out
|
||||
reti ; 6: TIM1_CAPT Timer/Counter1 Capture Event
|
||||
reti ; 7: TIM1_COMPA (OC1A) Timer/Counter1 Compare Match A
|
||||
reti ; 8: TIM1_COMPB (OC1B) Timer/Counter1 Compare Match B
|
||||
reti ; 9: TIM1_OVF (OVF1) Timer/Counter1 Overflow
|
||||
rjmp baseTimerIrqOC0A ; 10: TIM0_COMPA (OC0A) Timer/Counter0 Compare Match A
|
||||
reti ; 11: TIM0_COMPB (OC0B) Timer/Counter0 Compare Match B
|
||||
reti ; 12: TIM0_OVF (OVF0) Timer/Counter0 Overflow
|
||||
reti ; 13: ANA_COMP0 Analog Comparator 0
|
||||
reti ; 14: ADC_READY ADC Conversion Complete
|
||||
reti ; 15: EE_RDY (ERDY) EEPROM Ready
|
||||
reti ; 16: ANA_COMP1 Analog Comparator 1
|
||||
reti ; 17: TIM2_CAPT Timer/Counter2 Capture Event
|
||||
reti ; 18: TIM2_COMPA (OC2A) Timer/Counter2 Compare Match A
|
||||
reti ; 19: TIM2_COMPB (OC2B) Timer/Counter2 Compare Match B
|
||||
reti ; 20: TIM2_OVF (OVF2) Timer/Counter2 Overflow
|
||||
reti ; 21: SPI SPI Serial Transfer Complete
|
||||
reti ; 22: USART0_RXS USART0 Rx Start
|
||||
rjmp ComOnUart0_RxCharIsr ; 23: USART0_RXC USART0 Rx Complete
|
||||
rjmp ComOnUart0_TxUdreIsr ; 24: USART0_DRE USART0 Data Register Empty
|
||||
rjmp ComOnUart0_TxCharIsr ; 25: USART0_TXC USART0 Tx Complete
|
||||
reti ; 26: USART1_RXS USART1 Rx Start
|
||||
rjmp TtyOnUart1_RxCharIsr ; 27: USART1_RXC USART1 Rx Complete
|
||||
rjmp TtyOnUart1_TxUdreIsr ; 28: USART1_DRE USART1 Data Register Empty
|
||||
rjmp TtyOnUart1_TxCharIsr ; 29: USART1_TXC USART1 Tx Complete
|
||||
reti ; 30: TWI Two-Wire-Interface
|
||||
reti ; 31: RESERVED reserved
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine onSystemStart
|
||||
|
||||
onSystemStart:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
onEvery100ms:
|
||||
onEverySecond:
|
||||
onEveryMinute:
|
||||
onEveryHour:
|
||||
onEveryDay:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine onEveryLoop
|
||||
;
|
||||
; Called on every loop (i.e. after awakening from sleep).
|
||||
|
||||
onEveryLoop:
|
||||
rcall checkRecvdMsg
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine onMessageReceived
|
||||
;
|
||||
; Called on every message received
|
||||
|
||||
onMessageReceived:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine checkRecvdMsg
|
||||
;
|
||||
; Read messages from either interface and forward to the other one.
|
||||
|
||||
checkRecvdMsg:
|
||||
rcall NET_PeekNextIncomingMsgNum ; check read queue (bufNum->r16)
|
||||
brcc checkRecvdMsg_end ; no msg, jmp
|
||||
rcall NET_Buffer_Locate ; (R17)
|
||||
; let system handle incoming messages
|
||||
push xl
|
||||
push xh
|
||||
rcall onMessageReceived
|
||||
rcall mainModulesOnPacketReceived
|
||||
rcall mainAppsOnPacketReceived
|
||||
pop xh
|
||||
pop xl
|
||||
|
||||
; forward to other interface
|
||||
ld r17, X
|
||||
andi r17, (NET_IFACE_BUFFER_IFACENUM1_BIT | NET_IFACE_BUFFER_IFACENUM0_BIT)
|
||||
rcall reverseInterfaceNum ; (R17)
|
||||
; ldi r17, TTYONUART1_IFACENUM ; DEBUG: send everything to uart1 to test that code first
|
||||
rcall addMsgToInterface
|
||||
brcc checkRecvdMsg_end ; could not add, jmp
|
||||
rcall NET_GetNextIncomingMsgNum ; take off the queue
|
||||
rjmp checkRecvdMsg
|
||||
checkRecvdMsg_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine reverseInterfaceNum
|
||||
;
|
||||
; @param r17 buffer num
|
||||
; @return r17 reversed interface number
|
||||
; @clobbers r17
|
||||
|
||||
reverseInterfaceNum:
|
||||
cpi r17, COMONUART0_IFACENUM
|
||||
brne reverseInterfaceNum_notUart0
|
||||
ldi r17, TTYONUART1_IFACENUM
|
||||
ret
|
||||
reverseInterfaceNum_notUart0:
|
||||
ldi r17, COMONUART0_IFACENUM
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine addMsgToInterface
|
||||
; @param r16 buffer num
|
||||
; @param r17 interface num
|
||||
|
||||
addMsgToInterface:
|
||||
cpi r17, COMONUART0_IFACENUM
|
||||
brne addMsgToInterface_notUart0
|
||||
ldi yl, LOW(comOnUart0_iface)
|
||||
ldi yh, HIGH(comOnUart0_iface)
|
||||
rjmp NET_Interface_AddOutgoingMsgNum ; try to add msg to interface
|
||||
addMsgToInterface_notUart0:
|
||||
cpi r17, TTYONUART1_IFACENUM
|
||||
brne addMsgToInterface_end
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
rjmp NET_Interface_AddOutgoingMsgNum ; try to add msg to interface
|
||||
addMsgToInterface_end:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; includes
|
||||
|
||||
.include "devices/all/hw_tn841.asm"
|
||||
.include "devices/all/includes.asm"
|
||||
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; defines for network interface
|
||||
|
||||
.equ netInterfaceData = ttyOnUart1_iface
|
||||
|
||||
|
||||
|
||||
@@ -27,9 +27,12 @@
|
||||
twimaster
|
||||
network
|
||||
uart_bitbang
|
||||
uart_bitbang2
|
||||
uart_irq
|
||||
uart_hw
|
||||
bootloader
|
||||
f_keepup
|
||||
valsched
|
||||
</subdirs>
|
||||
|
||||
</gwbuild>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
<extradist>
|
||||
main.asm
|
||||
main2.asm
|
||||
</extradist>
|
||||
|
||||
</gwbuild>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
<extradist>
|
||||
main.asm
|
||||
recv.asm
|
||||
</extradist>
|
||||
|
||||
</gwbuild>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
<extradist>
|
||||
main.asm
|
||||
main2.asm
|
||||
</extradist>
|
||||
|
||||
</gwbuild>
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
<gwbuild>
|
||||
|
||||
<extradist>
|
||||
bytelevel.asm
|
||||
defs.asm
|
||||
iface.asm
|
||||
lowlevel.asm
|
||||
main.asm
|
||||
packetlevel.asm
|
||||
</extradist>
|
||||
|
||||
</gwbuild>
|
||||
|
||||
Reference in New Issue
Block a user