From 1e906826053e6bf7bdb379da2177612bd8d8c921 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Tue, 29 Apr 2025 00:35:45 +0200 Subject: [PATCH] avr: use new code in latest nodes. --- avr/devices/0BUILD | 2 + avr/devices/all/0BUILD | 18 ++ avr/devices/all/apps.asm | 59 ++++ avr/devices/all/data.asm | 14 + avr/devices/all/defs.asm | 45 +++ avr/devices/all/includes.asm | 108 +++++++ avr/devices/all/main.asm | 126 ++++++++ avr/devices/all/modules.asm | 210 +++++++++++++ avr/devices/all/sendvalue.asm | 67 ++++ avr/devices/n21/0BUILD | 39 +-- avr/devices/n21/boot/0BUILD | 32 ++ avr/devices/n21/{ => boot}/boot.asm | 4 +- avr/devices/n21/main.asm | 471 ---------------------------- avr/devices/n21/main/0BUILD | 34 ++ avr/devices/n21/main/data.asm | 19 ++ avr/devices/n21/main/main.asm | 323 +++++++++++++++++++ avr/devices/n23/main/0BUILD | 1 + avr/devices/n23/main/data.asm | 3 +- avr/devices/n23/main/main.asm | 294 +++++------------ avr/devices/n23/main/motion.asm | 126 -------- avr/devices/n23/main/network.asm | 401 ----------------------- avr/main_all.asm | 102 +++--- 22 files changed, 1194 insertions(+), 1304 deletions(-) create mode 100644 avr/devices/all/0BUILD create mode 100644 avr/devices/all/apps.asm create mode 100644 avr/devices/all/data.asm create mode 100644 avr/devices/all/defs.asm create mode 100644 avr/devices/all/includes.asm create mode 100644 avr/devices/all/main.asm create mode 100644 avr/devices/all/modules.asm create mode 100644 avr/devices/all/sendvalue.asm create mode 100644 avr/devices/n21/boot/0BUILD rename avr/devices/n21/{ => boot}/boot.asm (98%) delete mode 100644 avr/devices/n21/main.asm create mode 100644 avr/devices/n21/main/0BUILD create mode 100644 avr/devices/n21/main/data.asm create mode 100644 avr/devices/n21/main/main.asm delete mode 100644 avr/devices/n23/main/motion.asm delete mode 100644 avr/devices/n23/main/network.asm diff --git a/avr/devices/0BUILD b/avr/devices/0BUILD index 5202e19..fc494f5 100644 --- a/avr/devices/0BUILD +++ b/avr/devices/0BUILD @@ -22,6 +22,8 @@ + all + n21 n23 diff --git a/avr/devices/all/0BUILD b/avr/devices/all/0BUILD new file mode 100644 index 0000000..106eb17 --- /dev/null +++ b/avr/devices/all/0BUILD @@ -0,0 +1,18 @@ + + + + + + apps.asm + data.asm + defs.asm + includes.asm + main.asm + modules.asm + sendvalue.asm + + + + + + diff --git a/avr/devices/all/apps.asm b/avr/devices/all/apps.asm new file mode 100644 index 0000000..2dedf5f --- /dev/null +++ b/avr/devices/all/apps.asm @@ -0,0 +1,59 @@ +; *************************************************************************** +; copyright : (C) 2025 by Martin Preuss +; email : martin@libchipcard.de +; +; *************************************************************************** +; * This file is part of the project "AqHome". * +; * Please see toplevel file COPYING of that project for license details. * +; *************************************************************************** + + +; *************************************************************************** +; code + + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine initApps +; +; Call init functions of the used apps. Add your routine calls here. + +initApps: + +#ifdef APPS_NETWORK + ldi yl, LOW(netInterfaceData) + ldi yh, HIGH(netInterfaceData) + rcall AppNetwork_Init +#endif + +#ifdef APPS_MOTION + rcall AppMotion_Init +#endif + +#ifdef APPS_DOOR + rcall AppDoor_Init +#endif + + ; done + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine runApps +; +; Call run functions of the used modules. Add your routine calls here. +; + +runApps: + + ; add more modules here + ret + + + + diff --git a/avr/devices/all/data.asm b/avr/devices/all/data.asm new file mode 100644 index 0000000..31ccc2f --- /dev/null +++ b/avr/devices/all/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/all/defs.asm b/avr/devices/all/defs.asm new file mode 100644 index 0000000..b6622bb --- /dev/null +++ b/avr/devices/all/defs.asm @@ -0,0 +1,45 @@ +; *************************************************************************** +; copyright : (C) 2025 by Martin Preuss +; email : martin@libchipcard.de +; +; *************************************************************************** +; * This file is part of the project "AqHome". * +; * Please see toplevel file COPYING of that project for license details. * +; *************************************************************************** + + + +.equ AQHOME_VALUETYPE_UNKNOWN = 0 +.equ AQHOME_VALUETYPE_TEMP = 1 +.equ AQHOME_VALUETYPE_HUMIDITY = 2 +.equ AQHOME_VALUETYPE_DOOR = 3 +.equ AQHOME_VALUETYPE_RGB = 4 +.equ AQHOME_VALUETYPE_RGBW = 5 +.equ AQHOME_VALUETYPE_MOTION = 6 +.equ AQHOME_VALUETYPE_CO2 = 7 +.equ AQHOME_VALUETYPE_TVOC = 8 + + +.equ AQHOME_FW_TYPE_ATT84_BASE = 0 +.equ AQHOME_FW_TYPE_ATT84_TEMP1 = 1 + + +; --------------------------------------------------------------------------- +; EEPROM positions + + +.equ EEPROM_OFFS_UUID = 0 ; 4 bytes (occupy total of 8 bytes for extensibility) +.equ EEPROM_OFFS_COMADDR = 8 ; 1 byte (plus one byte reserved) + +.equ EEPROM_OFFS_SEED = 10 ; 2 bytes + +.equ EEPROM_OFFS_REED_CONF = 12 ; 1 byte (plus one byte reserved) + +.equ EEPROM_OFFS_MAL_CONF_ONTIME = 14 ; 2 bytes +.equ EEPROM_OFFS_MAL_CONF_SRC1_ADDR = 16 ; 1 byte +.equ EEPROM_OFFS_MAL_CONF_SRC1_VALUEID = 17 ; 1 byte +.equ EEPROM_OFFS_MAL_CONF_SRC2_ADDR = 18 ; 1 byte +.equ EEPROM_OFFS_MAL_CONF_SRC2_VALUEID = 19 ; 1 byte + +; next is 20 + diff --git a/avr/devices/all/includes.asm b/avr/devices/all/includes.asm new file mode 100644 index 0000000..e75259e --- /dev/null +++ b/avr/devices/all/includes.asm @@ -0,0 +1,108 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +.include "devices/all/main.asm" +.include "devices/all/apps.asm" +.include "devices/all/modules.asm" +.include "devices/all/sendvalue.asm" +.include "devices/all/data.asm" + +.include "common/utils.asm" +.include "common/utils_initial_wait.asm" +.include "common/utils_wait_fixed.asm" +.include "common/utils_copy_from_flash.asm" +.include "common/utils_copy_sdram.asm" + +.include "modules/basetimer/main.asm" + +#ifdef MODULES_NETWORK +.include "common/crc8.asm" +.include "common/m_fixedbuffers.asm" +.include "common/m_ringbuffer_y.asm" +.include "common/ringbuffer_y.asm" +.include "modules/network/defs.asm" +.include "modules/network/data.asm" +.include "modules/network/iface.asm" +.include "modules/network/main.asm" +.include "modules/network/buffer.asm" +.include "modules/network/msg/defs.asm" +.include "modules/network/msg/common.asm" +.include "modules/network/msg/crc.asm" +.include "modules/network/msg/value-w.asm" +.include "modules/network/msg/addr-r.asm" +.include "modules/network/msg/addr-w.asm" +#endif + +#ifdef MODULES_UART_BITBANG +.include "modules/uart_bitbang2/defs.asm" +.include "modules/uart_bitbang2/iface.asm" +.include "modules/uart_bitbang2/lowlevel.asm" +#endif + +#ifdef MODULES_CLOCK +.include "modules/clock/main.asm" +#endif + +#ifdef MODULES_LED_SIMPLE +.include "modules/led_simple/main.asm" +#endif + +#ifdef MODULES_TWI_MASTER +.include "modules/twimaster/main.asm" +#endif + +#ifdef MODULES_SI7021 +.include "modules/si7021/main2.asm" + #ifdef MODULES_NETWORK + .include "modules/si7021/send.asm" + #endif +#endif + +#ifdef MODULES_STATS +; .include "modules/stats/main.asm" +#endif + +#ifdef MODULES_MOTION +.include "modules/motion/main2.asm" +#endif + +#ifdef MODULES_CCS811 + .include "modules/ccs811/main.asm" +#endif + +#ifdef MODULES_TCRT1000 + .include "modules/tcrt1000/main2.asm" +#endif + + +#ifdef APPS_MOTION +.include "modules/f_keepup/main.asm" +.include "modules/valsched/main.asm" +.include "apps/motion/main.asm" +#endif + + +#ifdef APPS_DOOR +#ifndef APPS_MOTION +.include "modules/f_keepup/main.asm" +.include "modules/valsched/main.asm" +#endif +.include "apps/door/main.asm" +#endif + + +#ifdef APPS_NETWORK +.include "apps/network/main.asm" +.include "modules/network/msg/reboot-d.asm" +.include "modules/network/msg/reboot-r.asm" +#endif + + + diff --git a/avr/devices/all/main.asm b/avr/devices/all/main.asm new file mode 100644 index 0000000..ae7f885 --- /dev/null +++ b/avr/devices/all/main.asm @@ -0,0 +1,126 @@ +; *************************************************************************** +; copyright : (C) 2025 by Martin Preuss +; email : martin@libchipcard.de +; +; *************************************************************************** +; * This file is part of the project "AqHome". * +; * Please see toplevel file COPYING of that project for license details. * +; *************************************************************************** + + +; *************************************************************************** +; code + + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine main @global + +main: + 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 watchdogOff ; turn off watchdog timer (sometimes it stays on after reboot) + + rcall systemSetSpeed + rcall systemInitHardware + rcall Utils_Init + rcall Utils_SetupUid + rcall initModules + rcall initApps + rcall Utils_InitialWait + sei ; Enable interrupts + + rcall onSystemStart + +#ifdef MODULES_LED + ldi xl, LOW(blinkPattern) ; debug: set blink pattern + ldi xh, HIGH(blinkPattern) + ldi zl, LOW(ledA3Flash) + ldi zh, HIGH(ledA3Flash) + ldi yl, LOW(ledA3Sram) + ldi yh, HIGH(ledA3Sram) + rcall Led_SetPattern +#endif + +main_loop: + rcall runModules + rcall runApps + +#ifdef MODULES_NETWORK + rcall handleMessages +#endif + + ; only modify SE, SM1 and SM0 + cli + in r16, MCUCR + ldi r17, (1< - - - - -I $(builddir) - -I $(srcdir) - -I $(topsrcdir)/avr - -I $(topbuilddir)/avr - - - - - main.asm - - - - - - - - - - - -I $(builddir) - -I $(srcdir) - -I $(topsrcdir)/avr - -I $(topbuilddir)/avr - - - - - boot.asm - - - - - - + boot + main diff --git a/avr/devices/n21/boot/0BUILD b/avr/devices/n21/boot/0BUILD new file mode 100644 index 0000000..f972bcd --- /dev/null +++ b/avr/devices/n21/boot/0BUILD @@ -0,0 +1,32 @@ + + + + + + + + -I $(builddir) + -I $(srcdir) + -I $(topsrcdir)/avr + -I $(topbuilddir)/avr + + + + + boot.asm + + + + + + + + + + + + + + + + diff --git a/avr/devices/n21/boot.asm b/avr/devices/n21/boot/boot.asm similarity index 98% rename from avr/devices/n21/boot.asm rename to avr/devices/n21/boot/boot.asm index b2cfa0d..4468a99 100644 --- a/avr/devices/n21/boot.asm +++ b/avr/devices/n21/boot/boot.asm @@ -12,8 +12,8 @@ .include "include/tn84def.inc" ; Define device ATtiny84 .list -.include "./defs.asm" -.include "defs_all.asm" +.include "../defs.asm" +.include "devices/all/defs.asm" diff --git a/avr/devices/n21/main.asm b/avr/devices/n21/main.asm deleted file mode 100644 index 2129197..0000000 --- a/avr/devices/n21/main.asm +++ /dev/null @@ -1,471 +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/tn84def.inc" ; Define device ATtiny84 -.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_SIMPLE -#define MODULES_TWI_MASTER -;#define MODULES_LCD -#define LCD_MINIMAL_FONT -#define MODULES_SI7021 -#define MODULES_STATS -;#define MODULES_OWI_MASTER -;#define MODULES_DS18B20 -#define MODULES_MOTION -#define MODULES_TCRT1000 - -; --------------------------------------------------------------------------- -; defines for values - -.equ VALUE_ID_SI7021_TEMP = 0x01 -.equ VALUE_ID_SI7021_HUM = 0x02 - -.equ VALUE_ID_ADC = 0x03 -;.equ VALUE_ID_REED1 = 0x04 -;.equ VALUE_ID_REED2 = 0x05 -;.equ VALUE_ID_DS18B20_TEMP = 0x06 -.equ VALUE_ID_MOTION = 0x07 -.equ VALUE_ID_TCRT1K = 0x08 - -;.equ VALUE_ID_REED_CONF = 0x81 - - - -; *************************************************************************** -; code segment - -.cseg -.org 000000 - - - -; --------------------------------------------------------------------------- -; Reset and interrupt vectors (will be removed as soon as we can flash data over COM) - -; rjmp main ; Reset vector - rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system - reti ; EXT_INT0 - rjmp uartBitbangIsrPcint0 ; PCI0 - reti ; PCI1 - reti ; WATCHDOG - reti ; ICP1 - reti ; OC1A - reti ; OC1B - reti ; OVF1 - rjmp baseTimerIrqOC0A ; OC0A - reti ; OC0B - reti ; OVF0 - reti ; ACI - reti ; ADCC - reti ; ERDY - reti ; USI_STR - reti ; USI_OVF - - -devInfoBlock: ; 12 bytes -devInfoManufacturer: .db 'A', 'Q', 'U', 'A' -devInfoId: .db DEVICEINFO_ID, 0 -devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; version, revision -firmwareVersion: .db FIRMWARE_VARIANT_TEMP_WINDOW, FIRMWARE_VERSION_MAJOR - .db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL - -firmwareStart: - rjmp main - - -; *************************************************************************** -; includes - -.include "common/utils.asm" -.include "common/utils_wait_fixed.asm" -.include "common/utils_copy_from_flash.asm" -.include "common/utils_copy_sdram.asm" -.include "common/crc8.asm" - -.include "modules/basetimer/main.asm" - -#ifdef MODULES_TIMER - .include "modules/timer/main.asm" -#endif -#ifdef MODULES_LED -.include "modules/led/main.asm" -#endif -#ifdef MODULES_LED_SIMPLE -.include "modules/led_simple/main.asm" -#endif -#ifdef MODULES_COM - .include "modules/com2/defs.asm" - .include "modules/com2/main.asm" - .include "modules/com2/buffer.asm" - .include "modules/uart_bitbang/defs.asm" - .include "modules/uart_bitbang/main.asm" - .include "modules/uart_bitbang/bytelevel.asm" - .include "modules/uart_bitbang/packetlevel.asm" - #ifdef MODULES_COM_WITH_ADDR_PROTO - .include "modules/comproto/defs.asm" - .include "modules/comproto/main.asm" - .include "modules/comproto/addr.asm" - .include "modules/comproto/msg_recvstats.asm" - .include "modules/comproto/msg_sendstats.asm" - .include "modules/comproto/msg_sysstats.asm" - .include "modules/comproto/msg_memstats.asm" - .include "modules/comproto/msg_pong.asm" - .include "modules/comproto/msg_value.asm" - .include "modules/comproto/msg_device.asm" - .include "modules/comproto/msg_reboot.asm" - #endif - #ifdef MODULES_LCD - .include "modules/com2/screen.asm" - .include "modules/comproto/screen.asm" - #endif -#endif -#ifdef MODULES_TWI_MASTER - .include "modules/twimaster/main.asm" -#endif -#ifdef MODULES_OWI_MASTER - .include "modules/owimaster/main.asm" -#endif -#ifdef MODULES_LCD - .include "modules/lcd/main.asm" -#endif -#ifdef MODULES_SI7021 - .include "modules/si7021/main.asm" -#endif -#ifdef MODULES_DS18B20 - .include "modules/ds18b20/main.asm" -#endif -#ifdef MODULES_STATS - .include "modules/stats/main.asm" -#endif -#ifdef MODULES_CNY70 - .include "modules/cny70/main.asm" -#endif -#ifdef MODULES_REED - .include "modules/reed/main.asm" -#endif - -#ifdef MODULES_MOTION - .include "modules/motion/main.asm" -#endif - -#ifdef MODULES_TCRT1000 - .include "modules/tcrt1000/main.asm" -#endif - -; test -;#include "modules/uart_irq/defs.asm" -;#include "modules/uart_irq/iface.asm" -;#include "modules/uart_irq/iface1.asm" - - -; *************************************************************************** -; data in SRAM - -.dseg - -programRamBegin: -#ifdef MODULES_LCD - screenCounter: .byte 1 -#endif - -programRamEnd: - - - -#ifdef MODULES_LCD - sramTimerWriteStats: .byte 2 - sramTimerScreen: .byte 2 -#endif -#ifdef MODULES_SI7021 - sramTimerSI7021Measure: .byte 2 - sramTimerSI7021SendTemp: .byte 2 - sramTimerSI7021SendHumidity: .byte 2 -#endif -#ifdef MODULES_CNY70 - sramTimerCny70SendAdc: .byte 2 -#endif -#ifdef MODULES_LCD - sramPeriodicalLcdMark: .byte 2 -#endif -#ifdef MODULES_DS18B20 - sramDs18b20Timer: .byte 2 - sramSendDs18b20TempTimer: .byte 2 -#endif - - -; *************************************************************************** -; data in FLASH - -.cseg - - - -; --------------------------------------------------------------------------- -; timer list - - -timerList: -; SRAM variable/counter routine flags secs (0=don't start or restart) -#ifdef MODULES_COM_WITH_ADDR_PROTO - .dw cproAddresModeTimer, CPRO_Address_OnTimer, 0, 0 ; (no restart) -#endif -#ifdef MODULES_STATS - .dw statsSendTimer, Stats_Timer, TIMER_FLAGS_IF_ADDR, 9000 ; every 15m -#endif -#ifdef MODULES_LCD -; .dw sramPeriodicalLcdMark, periodicalLcdMark, 0, 20 ; every 2s -; .dw sramTimerWriteStats, writeStats, 0, 100 - .dw sramTimerScreen, printScreen, TIMER_FLAGS_IF_ADDR, 50 ; every 5s -#endif -#ifdef MODULES_SI7021 - .dw sramTimerSI7021Measure, SI7021_OnTimer, 0, 300 ; every 30s - .dw sramTimerSI7021SendTemp, sendSI7021Temp, TIMER_FLAGS_IF_ADDR, 600 ; every 60s - .dw sramTimerSI7021SendHumidity, sendSI7021Humidity, TIMER_FLAGS_IF_ADDR, 600 ; every 60s -#endif -#ifdef MODULES_CNY70 - .dw sramTimerCny70SendAdc, CNY70_OnTimer, TIMER_FLAGS_IF_ADDR, 50 ; every 5s -#endif -#ifdef MODULES_DS18B20 - .dw sramDs18b20Timer, Ds18b20_OnTimer, 0, 300 ; every 30s - .dw sramSendDs18b20TempTimer, sendDs18b20Temp, TIMER_FLAGS_IF_ADDR, 600 ; every 60s -#endif - .dw 0 ; end of list - - - - - -.include "main_all.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/n21/main/data.asm b/avr/devices/n21/main/data.asm new file mode 100644 index 0000000..20b822c --- /dev/null +++ b/avr/devices/n21/main/data.asm @@ -0,0 +1,19 @@ +; *************************************************************************** +; 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: + programRamSensorTimer: .byte 1 ; seconds counter + programRamStatsTimer: .byte 1 ; minutes counter +programRamEnd: + diff --git a/avr/devices/n21/main/main.asm b/avr/devices/n21/main/main.asm new file mode 100644 index 0000000..1e8a1ba --- /dev/null +++ b/avr/devices/n21/main/main.asm @@ -0,0 +1,323 @@ +; *************************************************************************** +; 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/tn84def.inc" ; Define device ATtiny84 +.list + +.include "../defs.asm" +.include "./data.asm" + +.include "devices/all/defs.asm" +.include "common/utils_wait.asm" + + + +; *************************************************************************** +; defines + +; --------------------------------------------------------------------------- +; generic + +.equ NET_BUFFERS_NUM = 6 +.equ NET_BUFFERS_SIZE = 28 + +.equ PROGRAM_SENSOR_INTERVAL_SECS = 60 +.equ PROGRAM_STATS_INTERVAL_MINS = 10 + + + +; --------------------------------------------------------------------------- +; firmware settings including list of modules used + +.equ FIRMWARE_VERSION_MAJOR = 0 +.equ FIRMWARE_VERSION_MINOR = 0 +.equ FIRMWARE_VERSION_PATCHLEVEL = 1 + + +; #define MODULES_TIMER +#define MODULES_CLOCK +#define MODULES_LED_SIMPLE +#define MODULES_NETWORK +#define MODULES_UART_BITBANG +#define MODULES_TWI_MASTER +;#define MODULES_LCD +;#define LCD_MINIMAL_FONT +#define MODULES_SI7021 +;#define MODULES_STATS +;#define MODULES_OWI_MASTER +;#define MODULES_DS18B20 +#define MODULES_MOTION +#define MODULES_TCRT1000 +;#define MODULES_CCS811 + +#define APPS_NETWORK +#define APPS_MOTION +#define APPS_DOOR + + +; --------------------------------------------------------------------------- +; defines for values + +.equ VALUE_ID_SI7021_TEMP = 0x01 +.equ VALUE_ID_SI7021_HUM = 0x02 + +.equ VALUE_ID_ADC = 0x03 +;.equ VALUE_ID_REED1 = 0x04 +;.equ VALUE_ID_REED2 = 0x05 +;.equ VALUE_ID_DS18B20_TEMP = 0x06 +.equ VALUE_ID_MOTION = 0x07 +.equ VALUE_ID_TCRT1K = 0x08 + +;.equ VALUE_ID_REED_CONF = 0x81 + + + +; *************************************************************************** +; code segment + +.cseg +.org 000000 + + + +; --------------------------------------------------------------------------- +; Reset and interrupt vectors (will be removed as soon as we can flash data over COM) + +; rjmp main ; Reset vector + rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system + reti ; EXT_INT0 + rjmp UART_BitBang_PcintIsr ; PCI0 + reti ; PCI1 + reti ; WATCHDOG + reti ; ICP1 + reti ; OC1A + reti ; OC1B + reti ; OVF1 + rjmp baseTimerIrqOC0A ; OC0A + reti ; OC0B + reti ; OVF0 + reti ; ACI + reti ; ADCC + reti ; ERDY + reti ; USI_STR + reti ; USI_OVF + + +devInfoBlock: ; 12 bytes +devInfoManufacturer: .db 'A', 'Q', 'U', 'A' +devInfoId: .db DEVICEINFO_ID, 0 +devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; version, revision +firmwareVersion: .db FIRMWARE_VARIANT_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 systemSetSpeed +; +; Called every 100ms. Add your routine calls here. No arguments, no results. + +systemSetSpeed: +.if clock == 8000000 + ldi r16, (1< + data.asm diff --git a/avr/devices/n23/main/data.asm b/avr/devices/n23/main/data.asm index 95b9d91..20b822c 100644 --- a/avr/devices/n23/main/data.asm +++ b/avr/devices/n23/main/data.asm @@ -13,6 +13,7 @@ programRamBegin: - programRamSensorTimer: .byte 1 + programRamSensorTimer: .byte 1 ; seconds counter + programRamStatsTimer: .byte 1 ; minutes counter programRamEnd: diff --git a/avr/devices/n23/main/main.asm b/avr/devices/n23/main/main.asm index 9c0f645..67a67ae 100644 --- a/avr/devices/n23/main/main.asm +++ b/avr/devices/n23/main/main.asm @@ -33,7 +33,7 @@ .include "../defs.asm" .include "./data.asm" -.include "defs_all.asm" +.include "devices/all/defs.asm" .include "common/utils_wait.asm" @@ -44,10 +44,12 @@ ; --------------------------------------------------------------------------- ; generic -.equ NET_BUFFERS_NUM = 6 -.equ NET_BUFFERS_SIZE = 28 +.equ NET_BUFFERS_NUM = 6 +.equ NET_BUFFERS_SIZE = 28 + +.equ PROGRAM_SENSOR_INTERVAL_SECS = 60 +.equ PROGRAM_STATS_INTERVAL_MINS = 10 -.equ PROGRAM_TIMER_VALUE = 60 ; --------------------------------------------------------------------------- @@ -58,18 +60,25 @@ .equ FIRMWARE_VERSION_PATCHLEVEL = 1 -#define MODULES_TIMER +; #define MODULES_TIMER +#define MODULES_CLOCK #define MODULES_LED_SIMPLE +#define MODULES_NETWORK +#define MODULES_UART_BITBANG #define MODULES_TWI_MASTER ;#define MODULES_LCD -#define LCD_MINIMAL_FONT +;#define LCD_MINIMAL_FONT #define MODULES_SI7021 -#define MODULES_STATS +;#define MODULES_STATS ;#define MODULES_OWI_MASTER ;#define MODULES_DS18B20 #define MODULES_MOTION ;#define MODULES_CCS811 +#define APPS_NETWORK +#define APPS_MOTION + + ; --------------------------------------------------------------------------- ; defines for values @@ -91,6 +100,8 @@ + + ; *************************************************************************** ; code segment @@ -129,49 +140,21 @@ devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; v firmwareVersion: .db FIRMWARE_VARIANT_TEMP_WINDOW, FIRMWARE_VERSION_MAJOR .db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL +; --------------------------------------------------------------------------- +; @routine firmwareStart @global + firmwareStart: - 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 - ldi r16, PROGRAM_TIMER_VALUE - sts programRamSensorTimer, r16 +; --------------------------------------------------------------------------- +; @routine onSystemStart - rcall initModules - - sbi LED_SIMPLE_DDR, LED_SIMPLE_PINNUM ; out - sbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; off - - sei -main_loop: - ; only modify SE, SM1 and SM0 - cli - in r16, MCUCR - ldi r17, (1<