diff --git a/avr/devices/n06/.gitignore b/avr/devices/n06/.gitignore new file mode 100644 index 0000000..8e0618c --- /dev/null +++ b/avr/devices/n06/.gitignore @@ -0,0 +1,2 @@ +*.eep.hex +*.obj diff --git a/avr/devices/n06/0BUILD b/avr/devices/n06/0BUILD new file mode 100644 index 0000000..ae878c4 --- /dev/null +++ b/avr/devices/n06/0BUILD @@ -0,0 +1,52 @@ + + + + + + + + -I $(builddir) + -I $(srcdir) + -I $(topsrcdir)/avr + -I $(topbuilddir)/avr + + + + + n06_main.asm + + + + + + + + + + + -I $(builddir) + -I $(srcdir) + -I $(topsrcdir)/avr + -I $(topbuilddir)/avr + + + + + n06_boot.asm + + + + + + + + + + + n06_defs.asm + + + + + + diff --git a/avr/devices/n06/n06_boot.asm b/avr/devices/n06/n06_boot.asm new file mode 100644 index 0000000..c29a7b0 --- /dev/null +++ b/avr/devices/n06/n06_boot.asm @@ -0,0 +1,127 @@ +; *************************************************************************** +; 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/tn84def.inc" ; Define device ATtiny84 +.list + +.include "n06_defs.asm" +.include "defs.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 + + + +; --------------------------------------------------------------------------- +; 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 start ; Reset vector + rjmp main ; Reset vector + reti ; EXT_INT0 + reti ; PCI0 + reti ; PCI1 + reti ; WATCHDOG + reti ; ICP1 + reti ; OC1A + reti ; OC1B + reti ; OVF1 + reti ; 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 'N', 0 +devInfoVersion: .db 6, 4 ; 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/flash/proto.asm + + + + +; *************************************************************************** +; includes + +.include "modules/com2/lowlevel.asm" +.include "modules/com2/crc.asm" +.include "modules/com2/packets.asm" +.include "common/crc8.asm" +.include "common/utils_wait_fixed.asm" +.include "common/utils_copy_from_flash.asm" +.include "common/utils_copy_sdram.asm" +.include "modules/flash/bootloader.asm" +.include "modules/flash/flash.asm" +.include "modules/flash/recv.asm" +.include "modules/flash/send.asm" +.include "modules/flash/wait.asm" +.include "modules/flash/hdl_flash_start.asm" +.include "modules/flash/hdl_flash_data.asm" +.include "modules/flash/hdl_flash_end.asm" +.include "modules/flash/flash_rsp.asm" +.include "modules/flash/flash_ready.asm" + + + + diff --git a/avr/devices/n06/n06_defs.asm b/avr/devices/n06/n06_defs.asm new file mode 100644 index 0000000..153ebf5 --- /dev/null +++ b/avr/devices/n06/n06_defs.asm @@ -0,0 +1,123 @@ +; *************************************************************************** +; copyright : (C) 2023 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. * +; *************************************************************************** + + +; *************************************************************************** +; +; AtTiny84 +; -------- +; VCC 1 14 GND +; PB0 2 13 PA0 +; CNY70-K PB1 3 12 PA1 COM-DATA +; /RESET PB3 4 11 PA2 +; AUX PB2 5 10 PA3 LED +; COM_ATTN PA7 6 9 PA4 TWI-SCL +; TWI-SDA PA6 7 8 PA5 CNY70-C +; -------- +; +; *************************************************************************** + + + +.equ BOOTLOADER_ADDR = 0xd00 + +.equ FIRMWARE_VARIANT_BOOT = 0 +.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1 + + + + +; --------------------------------------------------------------------------- +; LED module + +.equ LED_SIMPLE_ONTIME = 2 +.equ LED_SIMPLE_OFFTIME = 30 +.equ LED_SIMPLE_DDR = DDRA +.equ LED_SIMPLE_PORT = PORTA +.equ LED_SIMPLE_PINNUM = PORTA3 + + + +; --------------------------------------------------------------------------- +; COM module + +.equ COM_BIT_LENGTH = 52000 ; 104000=9600, 52000=19200, 26000=38400 + +.equ COM_DDR_DATA = DDRA +.equ COM_PORT_DATA = PORTA +.equ COM_PIN_DATA = PINA +.equ COM_PINNUM_DATA = PORTA1 + +.equ COM_DDR_ATTN = DDRA +.equ COM_PORT_ATTN = PORTA +.equ COM_PIN_ATTN = PINA +.equ COM_PINNUM_ATTN = PORTA7 + +.equ COM_IRQ_ADDR_ATTN = PCMSK0 +.equ COM_IRQ_BIT_ATTN = 7 ; bit 7 in PCMSK0 +.equ COM_IRQ_GIFR_ATTN = PCIF0 +.equ COM_IRQ_GIMSK_ATTN = PCIE0 + + + +; --------------------------------------------------------------------------- +; TWI master module + +;.equ TWI_BIT_LENGTH = 10000 ; 100000 and 200000 works for display: 10000, 100000, 200000 +.equ TWI_BIT_LENGTH = 1 ; 10, 100, 500, 100000 and 200000 works for display: 10000, 100000, 200000 + +.equ TWI_DDR_SCL = DDRA +.equ TWI_PORT_SCL = PORTA +.equ TWI_PIN_SCL = PINA +.equ TWI_PINNUM_SCL = PORTA4 + +.equ TWI_DDR_SDA = DDRA +.equ TWI_PORT_SDA = PORTA +.equ TWI_PIN_SDA = PINA +.equ TWI_PINNUM_SDA = PORTA6 + + + +; --------------------------------------------------------------------------- +; LCD module + +.equ LCD_TWI_ADDRESS = 0x3c + + + +; --------------------------------------------------------------------------- +; BMP 280 + +.equ BMP280_ADDR = 0x76 + + + +; --------------------------------------------------------------------------- +; SI 7021 + +.equ SI7021_ADDR = 0x40 + + + +; --------------------------------------------------------------------------- +; ADC/CNY70 + + +.equ CNY70_PORT_LED = PORTB +.equ CNY70_DDR_LED = DDRB +.equ CNY70_PINNUM_LED = PORTB1 + +.equ CNY70_PORT_ADC = PORTA ; adc5 +.equ CNY70_DDR_ADC = DDRA +.equ CNY70_PINNUM_ADC = PORTA5 +.equ CNY70_MUX_ADC = MUX5 + + + + diff --git a/avr/devices/n06/n06_main.asm b/avr/devices/n06/n06_main.asm new file mode 100644 index 0000000..0a2fa81 --- /dev/null +++ b/avr/devices/n06/n06_main.asm @@ -0,0 +1,336 @@ +; *************************************************************************** +; 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 + + + +.nolist +.include "include/tn84def.inc" ; Define device ATtiny84 +.list + +.include "n06_defs.asm" +.include "defs.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 + + + +; --------------------------------------------------------------------------- +; defines for values + +.equ VALUE_ID_TEMP1 = 0x01 +.equ VALUE_ID_HUM1 = 0x02 + +.equ VALUE_ID_ADC = 0x03 +.equ VALUE_ID_REED1 = 0x04 +.equ VALUE_ID_REED2 = 0x05 + + + +; *************************************************************************** +; 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 com2IsrPcint0 ; PCI0 + reti ; PCI1 + reti ; WATCHDOG + reti ; ICP1 + reti ; OC1A + reti ; OC1B + reti ; OVF1 + rjmp timerIrqOC0A ; 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 'N', 0 +devInfoVersion: .db 6, 4 ; version, revision +firmwareVersion: .db FIRMWARE_VARIANT_BOOT, 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" + +#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" + #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 +#endif +#ifdef MODULES_TWI_MASTER + .include "modules/twimaster/main.asm" +#endif +#ifdef MODULES_LCD + .include "modules/lcd/main.asm" +#endif +#ifdef MODULES_SI7021 + .include "modules/si7021/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 + + + +; *************************************************************************** +; data in SRAM + +.dseg + + +#ifdef MODULES_LCD + sramTimerWriteStats: .byte 2 +#endif +sramTimerEnqueueValues: .byte 2 +#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 + + +; *************************************************************************** +; data in FLASH + +.cseg + +ledA3Flash: .db DDRA+0x20, PORTA+0x20, PINA+0x20, (1<