diff --git a/avr/devices/0BUILD b/avr/devices/0BUILD index c94a727..a00c9ef 100644 --- a/avr/devices/0BUILD +++ b/avr/devices/0BUILD @@ -15,6 +15,7 @@ e03 e04 e05 + e06 n14 n16 n21 diff --git a/avr/devices/e06/.gitignore b/avr/devices/e06/.gitignore new file mode 100644 index 0000000..8e0618c --- /dev/null +++ b/avr/devices/e06/.gitignore @@ -0,0 +1,2 @@ +*.eep.hex +*.obj diff --git a/avr/devices/e06/0BUILD b/avr/devices/e06/0BUILD new file mode 100644 index 0000000..dc4c439 --- /dev/null +++ b/avr/devices/e06/0BUILD @@ -0,0 +1,18 @@ + + + + + + boot + main + + + + defs.asm + README + + + + + + diff --git a/avr/devices/e06/README b/avr/devices/e06/README new file mode 100644 index 0000000..1290883 --- /dev/null +++ b/avr/devices/e06/README @@ -0,0 +1,10 @@ + +E02 +=== + +- Role: COM-PC-Interface extension for S06 +- MCU: AtTiny841 +- Connection: S06-internal +- Predecessor: E01 +- COM: UARTFD0, COM2W + diff --git a/avr/devices/e06/boot/0BUILD b/avr/devices/e06/boot/0BUILD new file mode 100644 index 0000000..9a78a19 --- /dev/null +++ b/avr/devices/e06/boot/0BUILD @@ -0,0 +1,32 @@ + + + + + + + + -I $(builddir) + -I $(srcdir) + -I $(topsrcdir)/avr + -I $(topbuilddir)/avr + + + + + boot.asm + + + + + + + + + + + + + + + + diff --git a/avr/devices/e06/boot/boot.asm b/avr/devices/e06/boot/boot.asm new file mode 100644 index 0000000..2f9fa66 --- /dev/null +++ b/avr/devices/e06/boot/boot.asm @@ -0,0 +1,150 @@ +; *************************************************************************** +; 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 "version.asm" +.include "../defs.asm" +.include "devices/all/defs.asm" + +.include "common/calls.asm" +.include "common/utils_wait.asm" + + + +; *************************************************************************** +; defines + + +;#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_uart0.asm" +.include "modules/flash/io_uart_all.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< + + + + + + + -I $(builddir) + -I $(srcdir) + -I $(topsrcdir)/avr + -I $(topbuilddir)/avr + + + + + main.asm + + + + + + + + + + + + + + + + + diff --git a/avr/devices/e06/main/main.asm b/avr/devices/e06/main/main.asm new file mode 100644 index 0000000..9ba9033 --- /dev/null +++ b/avr/devices/e06/main/main.asm @@ -0,0 +1,308 @@ +; *************************************************************************** +; 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 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 "version.asm" +;.include "defs_all.asm" + +.include "devices/all/defs.asm" + +.include "common/calls.asm" +.include "common/utils_wait.asm" +.include "common/utils_io.asm" + + + +; *************************************************************************** +; defines + +; --------------------------------------------------------------------------- +; generic + +.equ COMONUART0_IFACENUM = 1 +.equ TTYONUART0_IFACENUM = 2 + + +; debug + +;.equ T03_FLAGS_ALLOC = 0x01 +;.equ T03_FLAGS_I1_SKIPPING = 0x02 +;.equ T03_FLAGS_I1_RESTARTED = 0x04 +;.equ T03_FLAGS_ADDIN = 0x08 +;.equ T03_FLAGS_I1_ADDOUT = 0x10 +;.equ T03_FLAGS_I2_ADDOUT = 0x20 + + + +; --------------------------------------------------------------------------- +; firmware settings including list of modules used + + +#define MAIN_WITHOUT_MSG_HANDLING ; we do message handling ourselfes +#define COM_ACCEPT_ALL_DEST ; accept all messages! +#define APP_STATS_NETDEV2 +#define APP_ROUTER_NO_ADDR_MGR + +#define MODULES_CLOCK +#define MODULES_LED1 +#define MODULES_NETWORK +#define MODULES_COM2W +#define MODULES_UARTFD0 + +#define APPS_STATS +#define APPS_FORWARDER + + + +.equ NET_BUFFERS_NUM = 10 +.equ NET_MSGNUMINBUF_SIZE = 8 ; max buffer nums in ringbuffer (global incoming) +.equ NET_IFACE_OUTMSGBUF_SIZE = 8 ; max buffer nums in ringbuffer (per interface outbound) + + + +.equ HEARTBEAT_MAXTIME_IN_MINS = 10 ; 10 minutes + +.equ LEDMCPRESET_ONTIME = 2 +.equ LEDMCPRESET_OFFTIME = 2 +.equ LEDMCPRESET_REPEATS = 50 ; 50*0.4=20s + + +; --------------------------------------------------------------------------- +; defines for values + +; none + + + +; *************************************************************************** +; 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 com2wPcintIsr ; 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 UARTFD0_RxCharIsr ; 23: USART0_RXC USART0 Rx Complete + rjmp UARTFD0_TxUdreIsr ; 24: USART0_DRE USART0 Data Register Empty + rjmp UARTFD0_TxCharIsr ; 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_TEMP_WINDOW, FIRMWARE_VERSION_MAJOR + .db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL + + + +; --------------------------------------------------------------------------- +; @routine firmwareStart @global + +firmwareStart: + rjmp main +; @end + + + +; --------------------------------------------------------------------------- +; @routine onSystemStart + +onSystemStart: + ldi r16, 0xf0 + sts netInterfaceData+NET_IFACE_OFFS_ADDRESS, r16 + sts netInterfaceData2+NET_IFACE_OFFS_ADDRESS, r16 + + ldi r16, HEARTBEAT_MAXTIME_IN_MINS + sts heartbeatTimer, r16 + + rcall resetMcp2221 + + ret +; @end + + + +onEveryMinute: + lds r16, heartbeatTimer + tst r16 + breq onEveryMinute_ret + dec r16 + sts heartbeatTimer, r16 + brne onEveryMinute_ret + +; rcall resetMcp2221 + + ldi r16, HEARTBEAT_MAXTIME_IN_MINS + sts heartbeatTimer, r16 +onEveryMinute_ret: + ret +; @end + + + +onEvery100ms: +onEverySecond: +onEveryHour: +onEveryDay: + ret + + + +; --------------------------------------------------------------------------- +; @routine onEveryLoop +; +; Called on every loop (i.e. after awakening from sleep). + +onEveryLoop: + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine onMessageReceived +; +; Called on every message received + +onMessageReceived: + adiw xh:xl, NETMSG_OFFS_CMD + ld r16, X + sbiw xh:xl, NETMSG_OFFS_CMD + cpi r16, NETMSG_CMD_HEARTBEAT + brne onMessageReceived_ret + ldi r16, HEARTBEAT_MAXTIME_IN_MINS + sts heartbeatTimer, r16 +onMessageReceived_ret: + clc + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine resetMcp2221 +; +; Reset MCP2221 by pulling /RST low for 10us. + +resetMcp2221: + push r15 + inr r15, SREG + cli + sbi MCP2221_RESET_DDR, MCP2221_RESET_PINNUM ; out + cbi MCP2221_RESET_PORT, MCP2221_RESET_PINNUM ; set RST low + Utils_WaitNanoSecs 10000, 0, r22 ; minimum is 2us, use 10us to be safe + sbi MCP2221_RESET_PORT, MCP2221_RESET_PINNUM ; set RST high + outr SREG, r15 + pop r15 + +#ifdef MODULES_LED_SIMPLE + ldi r18, LEDMCPRESET_ONTIME + ldi r19, LEDMCPRESET_OFFTIME + ldi r20, LEDMCPRESET_REPEATS + bigcall LedSimple_SetTiming +#endif + + ret +; @end + + + + + + +; *************************************************************************** +; includes + +.include "devices/all/hw_tn841.asm" +.include "devices/all/includes.asm" +.include "common/debug.asm" + + + + +; --------------------------------------------------------------------------- +; defines for network interface + +.equ netInterfaceData = uartFd0_iface +.equ netInterfaceData2 = com2w_iface + + +deviceCodeEnd: + .if deviceCodeEnd >= BOOTLOADER_ADDR + .warning "Code reaches into boot loader!" + .endif + + + + +; *************************************************************************** +; data segment + +.dseg + +heartbeatTimer: .byte 1 + + + + diff --git a/devices/nodes/0BUILD b/devices/nodes/0BUILD index 44ece78..a725e36 100644 --- a/devices/nodes/0BUILD +++ b/devices/nodes/0BUILD @@ -10,6 +10,7 @@ aqua_e03.xml aqua_e04.xml aqua_e05.xml + aqua_e06.xml aqua_n06.xml aqua_n11.xml aqua_n12.xml diff --git a/devices/nodes/aqua_e06.xml b/devices/nodes/aqua_e06.xml new file mode 100644 index 0000000..65f9fd3 --- /dev/null +++ b/devices/nodes/aqua_e06.xml @@ -0,0 +1,10 @@ + + + AQUA + E + 6 + + + + + diff --git a/flashnode.sh b/flashnode.sh index d4ec831..08c0b15 100755 --- a/flashnode.sh +++ b/flashnode.sh @@ -184,6 +184,14 @@ case $NODE in FILE_ARG="-U flash:w:./0-build/avr/devices/e05/boot/e05_boot.hex" ;; + e06) + DEVICE_ARG="-p t841" + 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/e06/boot/e06_boot.hex" + ;; + *) echo "Unknown node $NODE". exit 1