From b784f6bb45dc2fc764664e37b3f1d5d1d7b42e74 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Mon, 29 Jun 2026 17:48:02 +0200 Subject: [PATCH] avr: added device n32 (FAN controller). --- avr/devices/0BUILD | 1 + avr/devices/n32/.gitignore | 4 + avr/devices/n32/0BUILD | 19 +++ avr/devices/n32/README | 14 ++ avr/devices/n32/boot/0BUILD | 32 +++++ avr/devices/n32/boot/boot.asm | 156 +++++++++++++++++++++ avr/devices/n32/defs.asm | 97 +++++++++++++ avr/devices/n32/enclosure.scad | 244 +++++++++++++++++++++++++++++++++ avr/devices/n32/main/0BUILD | 34 +++++ avr/devices/n32/main/data.asm | 14 ++ avr/devices/n32/main/main.asm | 221 +++++++++++++++++++++++++++++ devices/nodes/0BUILD | 1 + devices/nodes/aqua_n32.xml | 14 ++ flashnode.sh | 8 ++ 14 files changed, 859 insertions(+) create mode 100644 avr/devices/n32/.gitignore create mode 100644 avr/devices/n32/0BUILD create mode 100644 avr/devices/n32/README create mode 100644 avr/devices/n32/boot/0BUILD create mode 100644 avr/devices/n32/boot/boot.asm create mode 100644 avr/devices/n32/defs.asm create mode 100644 avr/devices/n32/enclosure.scad create mode 100644 avr/devices/n32/main/0BUILD create mode 100644 avr/devices/n32/main/data.asm create mode 100644 avr/devices/n32/main/main.asm create mode 100644 devices/nodes/aqua_n32.xml diff --git a/avr/devices/0BUILD b/avr/devices/0BUILD index 4c1a4d3..c94a727 100644 --- a/avr/devices/0BUILD +++ b/avr/devices/0BUILD @@ -26,6 +26,7 @@ n29 n30 n31 + n32 r06 s03 t03 diff --git a/avr/devices/n32/.gitignore b/avr/devices/n32/.gitignore new file mode 100644 index 0000000..abf3d5c --- /dev/null +++ b/avr/devices/n32/.gitignore @@ -0,0 +1,4 @@ +*.eep.hex +*.obj +n32-enclosure.stl +n32-enclosure-2.stl diff --git a/avr/devices/n32/0BUILD b/avr/devices/n32/0BUILD new file mode 100644 index 0000000..3f7db52 --- /dev/null +++ b/avr/devices/n32/0BUILD @@ -0,0 +1,19 @@ + + + + + + boot + main + + + + defs.asm + README + enclosure.scad + + + + + + diff --git a/avr/devices/n32/README b/avr/devices/n32/README new file mode 100644 index 0000000..0226956 --- /dev/null +++ b/avr/devices/n32/README @@ -0,0 +1,14 @@ + +N32 +=== + +- Role: Fan Controller +- MCU: AtTiny861 +- Frequency: 1MHz +- Connection: RJ45 +- COM: COM2W +- Periphery: +- Apps: + - NETWORK : Basic network functionality (address setup etc.) + - REPORTSENSORS: report sensor data from temperature sensor etc. + - STATS : periodically send stats data diff --git a/avr/devices/n32/boot/0BUILD b/avr/devices/n32/boot/0BUILD new file mode 100644 index 0000000..cb22aa0 --- /dev/null +++ b/avr/devices/n32/boot/0BUILD @@ -0,0 +1,32 @@ + + + + + + + + -I $(builddir) + -I $(srcdir) + -I $(topsrcdir)/avr + -I $(topbuilddir)/avr + + + + + boot.asm + + + + + + + + + + + + + + + + diff --git a/avr/devices/n32/boot/boot.asm b/avr/devices/n32/boot/boot.asm new file mode 100644 index 0000000..1caf3e7 --- /dev/null +++ b/avr/devices/n32/boot/boot.asm @@ -0,0 +1,156 @@ +; *************************************************************************** +; copyright : (C) 2026 by Martin Preuss +; email : martin@libchipcard.de +; +; *************************************************************************** +; * This file is part of the project "AqHome". * +; * Please see toplevel file COPYING of that project for license details. * +; *************************************************************************** + + +; *************************************************************************** +; Source file for base system node on AtTiny 84 +; +; This is for the maintenance system (i.e. the flash loader). +; +; All definitions and changes should go into this file. +; *************************************************************************** + +.equ clock=1000000 ; Define the clock frequency + +.nolist +.include "include/tn861Adef.inc" ; Define device ATtiny861A +.list + +.include "common/calls.asm" +.include "common/utils_io.asm" +.include "devices/all/io_1.asm" + +.include "version.asm" +.include "../defs.asm" + +.include "devices/all/defs.asm" + + +#define COM_ACCEPT_ALL_DEST + + + +; *************************************************************************** +; defines + +; --------------------------------------------------------------------------- +; generic + +.include "common/utils_wait.asm" + + + +; --------------------------------------------------------------------------- +; firmware settings + + + +; --------------------------------------------------------------------------- +; LED + +.equ LED_DDR = DDRA +.equ LED_PORT = PORTA +.equ LED_PIN = PINA +.equ LED_PINNUM = PORTA3 + + +; *************************************************************************** +; code segment + +.cseg +.org 0x0000 + + + +; --------------------------------------------------------------------------- +; Reset and interrupt vectors + rjmp main ; 0x00: Reset vector Reset Vector + reti ; 0x01: INT0 External Interrupt 0 + reti ; 0x02: PCI Pin Change Interrupt + reti ; 0x03: OC1A Timer/Counter1 Compare Match 1A + reti ; 0x04: OC1B Timer/Counter1 Compare Match 1B + reti ; 0x05: OVF1 Timer/Counter1 Overflow + reti ; 0x06: OVF0 Timer/Counter0 Overflow + reti ; 0x07: USI_START USI Start + reti ; 0x08: USI_OVF USI Overflow + reti ; 0x09: ERDY EEPROM Ready + reti ; 0x0a: ACI Analog Comparator + reti ; 0x0b: ADCC ADC Conversion Complete + reti ; 0x0c: WDT Watchdog Time-Out + reti ; 0x0d: INT1 External Interrupt 1 + reti ; 0x0e: OC0A Timer/Counter0 Compare Match A + reti ; 0x0f: OC0B Timer/Counter0 Compare Match B + reti ; 0x10: ICP0 Interrupt Capture Event for Timer/Counter0 + reti ; 0x11: OC1D Timer/Counter1 Compare Match D + reti ; 0x12: FAULT_PROT Timer/Counter1 Fault Protection + +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_com2w.asm" +.include "modules/flash/flash1p.asm" +.include "modules/flash/flashxp.asm" +.include "modules/flash/flashprocess.asm" +.include "modules/flash/wait.asm" +.include "modules/bootloader/main.asm" +.include "modules/network/msg/defs.asm" +.include "modules/network/msg/crc.asm" + +;.include "common/debug.asm" + + + +systemSetSpeed: +.if clock == 8000000 + ldi r16, (1< + + + + + + + -I $(builddir) + -I $(srcdir) + -I $(topsrcdir)/avr + -I $(topbuilddir)/avr + + + + + main.asm + + + + + + + + + + + + data.asm + + + + + + diff --git a/avr/devices/n32/main/data.asm b/avr/devices/n32/main/data.asm new file mode 100644 index 0000000..31ccc2f --- /dev/null +++ b/avr/devices/n32/main/data.asm @@ -0,0 +1,14 @@ +; *************************************************************************** +; 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 + + diff --git a/avr/devices/n32/main/main.asm b/avr/devices/n32/main/main.asm new file mode 100644 index 0000000..732be3a --- /dev/null +++ b/avr/devices/n32/main/main.asm @@ -0,0 +1,221 @@ +; *************************************************************************** +; copyright : (C) 2026 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 fan controller node on AtTiny 861 +; +; 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/tn861Adef.inc" ; Define device ATtiny861A +.list + +.include "../defs.asm" +.include "./data.asm" + +.include "version.asm" +.include "devices/all/defs.asm" +.include "common/calls.asm" +.include "common/utils_io.asm" +.include "common/utils_wait.asm" + + + +; *************************************************************************** +; defines + +; --------------------------------------------------------------------------- +; generic + +.equ NET_BUFFERS_NUM = 6 +.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) + + + + +; --------------------------------------------------------------------------- +; firmware settings including list of modules used + +; #define MODULES_TIMER +#define MODULES_CLOCK +#define MODULES_LED1 +;#define MODULES_LED2 +;#define MODULES_LED3 +#define MODULES_NETWORK +#define MODULES_COM2W +;#define MODULES_TWI_MASTER +;#define MODULES_LCD +;#define LCD_MINIMAL_FONT +;#define MODULES_SI7021 +;#define MODULES_SGP30 +;#define MODULES_SGP40 +;#define MODULES_STATS +;#define MODULES_OWI_MASTER +;#define MODULES_DS18B20 +;#define MODULES_MOTION +;#define MODULES_CCS811 +;#define MODULES_BRIGHTNESS +#define MODULES_MULTIFAN + + +#define APPS_NETWORK +;#define APPS_MOTION +#define APPS_REPORTSENSORS +#define APPS_STATS +;#define APPS_CO2WATCH + + +; defines for modules + +; #define LED1_NETWORK_ACTIVITY + + + +; --------------------------------------------------------------------------- +; defines for values + +;.equ VALUE_ID_SGP40_TVOC = 0x08 + + + + + + +; *************************************************************************** +; code segment + +.cseg +.org 000000 + + + +; --------------------------------------------------------------------------- +; Reset and interrupt vectors + rjmp BOOTLOADER_ADDR ; 0x00: Reset vector Reset Vector + reti ; 0x01: INT0 External Interrupt 0 + rjmp com2wPcintIsr ; 0x02: PCI Pin Change Interrupt + reti ; 0x03: OC1A Timer/Counter1 Compare Match 1A + reti ; 0x04: OC1B Timer/Counter1 Compare Match 1B + reti ; 0x05: OVF1 Timer/Counter1 Overflow + reti ; 0x06: OVF0 Timer/Counter0 Overflow + reti ; 0x07: USI_START USI Start + reti ; 0x08: USI_OVF USI Overflow + reti ; 0x09: ERDY EEPROM Ready + reti ; 0x0a: ACI Analog Comparator + reti ; 0x0b: ADCC ADC Conversion Complete + reti ; 0x0c: WDT Watchdog Time-Out + reti ; 0x0d: INT1 External Interrupt 1 + rjmp baseTimerIrqOC0A ; 0x0e: OC0A Timer/Counter0 Compare Match A + reti ; 0x0f: OC0B Timer/Counter0 Compare Match B + reti ; 0x10: ICP0 Interrupt Capture Event for Timer/Counter0 + reti ; 0x11: OC1D Timer/Counter1 Compare Match D + reti ; 0x12: FAULT_PROT Timer/Counter1 Fault Protection + +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 + + + +; --------------------------------------------------------------------------- +; @routine onMessageReceived +; +; Called on every message received + +onMessageReceived: + clc + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine onEvery100ms +; +; Called every 100ms. Add your routine calls here. No arguments, no results. + +onEvery100ms: +onEverySecond: +onEveryMinute: +onEveryHour: +onEveryDay: + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine onEveryLoop +; +; Called on every loop (i.e. after awakening from sleep). +; +onEveryLoop: + ret +; @end + + + + + +; *************************************************************************** +; includes + +.include "devices/all/hw_tn861.asm" +.include "devices/all/includes.asm" + + + +; --------------------------------------------------------------------------- +; defines for network interface + +.equ netInterfaceData = com2w_iface + + + +deviceCodeEnd: + .if deviceCodeEnd >= BOOTLOADER_ADDR + .warning "Code reaches into boot loader!" + .endif + diff --git a/devices/nodes/0BUILD b/devices/nodes/0BUILD index 1c60179..44ece78 100644 --- a/devices/nodes/0BUILD +++ b/devices/nodes/0BUILD @@ -30,6 +30,7 @@ aqua_n29.xml aqua_n30.xml aqua_n31.xml + aqua_n32.xml aqua_r05.xml aqua_r06.xml aqua_s03.xml diff --git a/devices/nodes/aqua_n32.xml b/devices/nodes/aqua_n32.xml new file mode 100644 index 0000000..18b7a6f --- /dev/null +++ b/devices/nodes/aqua_n32.xml @@ -0,0 +1,14 @@ + + + AQUA + N + 32 + + + + + + diff --git a/flashnode.sh b/flashnode.sh index e0f747f..d4ec831 100755 --- a/flashnode.sh +++ b/flashnode.sh @@ -107,6 +107,14 @@ case $NODE in EFUSE_ARG="-U efuse:w:0xFE:m" FILE_ARG="-U flash:w:./0-build/avr/devices/n31/boot/n31_boot.hex" ;; + n32) + DEVICE_ARG="-p t861" + HFUSE_ARG="-U hfuse:w:0xD7:m" + LFUSE_ARG="-U lfuse:w:0x62:m" + EFUSE_ARG="-U efuse:w:0xFE:m" + FILE_ARG="-U flash:w:./0-build/avr/devices/n32/boot/n32_boot.hex" + ;; + r05) DEVICE_ARG="-p t841" HFUSE_ARG="-U hfuse:w:0xD7:m"