From 9d4e24222c372421276ddbda147fdb8db6c51af0 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Tue, 14 Apr 2026 23:50:29 +0200 Subject: [PATCH] avr: added device "minimal" (minimal example for a device using AqOS4Avr). --- avr/devices/0BUILD | 1 + avr/devices/minimal/.gitignore | 2 + avr/devices/minimal/0BUILD | 18 +++ avr/devices/minimal/README | 11 ++ avr/devices/minimal/boot/0BUILD | 32 +++++ avr/devices/minimal/boot/boot.asm | 157 ++++++++++++++++++++++++ avr/devices/minimal/defs.asm | 73 ++++++++++++ avr/devices/minimal/main/0BUILD | 33 +++++ avr/devices/minimal/main/main.asm | 192 ++++++++++++++++++++++++++++++ 9 files changed, 519 insertions(+) create mode 100644 avr/devices/minimal/.gitignore create mode 100644 avr/devices/minimal/0BUILD create mode 100644 avr/devices/minimal/README create mode 100644 avr/devices/minimal/boot/0BUILD create mode 100644 avr/devices/minimal/boot/boot.asm create mode 100644 avr/devices/minimal/defs.asm create mode 100644 avr/devices/minimal/main/0BUILD create mode 100644 avr/devices/minimal/main/main.asm diff --git a/avr/devices/0BUILD b/avr/devices/0BUILD index 78ccc18..23e950c 100644 --- a/avr/devices/0BUILD +++ b/avr/devices/0BUILD @@ -27,6 +27,7 @@ s03 t03 t04 + minimal diff --git a/avr/devices/minimal/.gitignore b/avr/devices/minimal/.gitignore new file mode 100644 index 0000000..8e0618c --- /dev/null +++ b/avr/devices/minimal/.gitignore @@ -0,0 +1,2 @@ +*.eep.hex +*.obj diff --git a/avr/devices/minimal/0BUILD b/avr/devices/minimal/0BUILD new file mode 100644 index 0000000..dc4c439 --- /dev/null +++ b/avr/devices/minimal/0BUILD @@ -0,0 +1,18 @@ + + + + + + boot + main + + + + defs.asm + README + + + + + + diff --git a/avr/devices/minimal/README b/avr/devices/minimal/README new file mode 100644 index 0000000..a293e73 --- /dev/null +++ b/avr/devices/minimal/README @@ -0,0 +1,11 @@ + +Minimal +======= + +- Role: Example for minimal system +- MCU: AtTiny84 +- Frequency: 1MHz +- Connection: RJ45 +- COM: COM2W +- Predecessor: none +- Periphery: none diff --git a/avr/devices/minimal/boot/0BUILD b/avr/devices/minimal/boot/0BUILD new file mode 100644 index 0000000..48dc0f0 --- /dev/null +++ b/avr/devices/minimal/boot/0BUILD @@ -0,0 +1,32 @@ + + + + + + + + -I $(builddir) + -I $(srcdir) + -I $(topsrcdir)/avr + -I $(topbuilddir)/avr + + + + + boot.asm + + + + + + + + + + + + + + + + diff --git a/avr/devices/minimal/boot/boot.asm b/avr/devices/minimal/boot/boot.asm new file mode 100644 index 0000000..7f35036 --- /dev/null +++ b/avr/devices/minimal/boot/boot.asm @@ -0,0 +1,157 @@ +; *************************************************************************** +; 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/tn84def.inc" ; Define device ATtiny84 +.list + +.include "version.asm" +.include "../defs.asm" + +.include "common/calls.asm" +.include "common/utils_io.asm" +.include "devices/all/defs.asm" + + +#define COM_ACCEPT_ALL_DEST + + + +; *************************************************************************** +; defines + +; --------------------------------------------------------------------------- +; generic + +.include "common/utils_wait.asm" +.include "modules/com2/defs.asm" +.include "modules/comproto/defs.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 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 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 + + + + + + + + + + + + + + + + + diff --git a/avr/devices/minimal/main/main.asm b/avr/devices/minimal/main/main.asm new file mode 100644 index 0000000..da7e674 --- /dev/null +++ b/avr/devices/minimal/main/main.asm @@ -0,0 +1,192 @@ +; *************************************************************************** +; 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 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 "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_CLOCK +#define MODULES_LED_SIMPLE +#define MODULES_NETWORK +#define MODULES_COM2W + +#define APPS_NETWORK +#define APPS_STATS + + + +; *************************************************************************** +; code segment + +.cseg +.org 000000 + + + +; --------------------------------------------------------------------------- +; Reset and interrupt vectors + + rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system + reti ; EXT_INT0 +#ifdef MODULES_COM2W. + rjmp com2wPcintIsr ; PCI0 +#else + reti ; PCI0 +#endif + 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_DEFAULT, 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_tn84.asm" +.include "devices/all/includes.asm" + + + +; --------------------------------------------------------------------------- +; defines for network interface + + +#ifdef MODULES_COM2W +.equ netInterfaceData = com2w_iface +#endif + + + +deviceCodeEnd: + .if deviceCodeEnd >= BOOTLOADER_ADDR + .warning "Code reaches into boot loader!" + .endif +