From cdcb4e2b3e712871068dc18da4db953fed6dde4b Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Fri, 13 Sep 2024 21:39:24 +0200 Subject: [PATCH] avr: rewrote timer code (split into timer and basetimer). Only basetimer depends on hardware and clock speed. Works onj AtTiny 84 at 1 MHz and 8 MHz. --- avr/modules/0BUILD | 1 + avr/modules/basetimer/0BUILD | 12 ++ avr/modules/basetimer/main.asm | 188 +++++++++++++++++++++++ avr/modules/comproto/msg_sysstats.asm | 5 +- avr/modules/timer/main.asm | 206 +++++++++----------------- 5 files changed, 276 insertions(+), 136 deletions(-) create mode 100644 avr/modules/basetimer/0BUILD create mode 100644 avr/modules/basetimer/main.asm diff --git a/avr/modules/0BUILD b/avr/modules/0BUILD index 077e1e4..4ee28d5 100644 --- a/avr/modules/0BUILD +++ b/avr/modules/0BUILD @@ -3,6 +3,7 @@ + basetimer bmp280 cny70 com2 diff --git a/avr/modules/basetimer/0BUILD b/avr/modules/basetimer/0BUILD new file mode 100644 index 0000000..8038787 --- /dev/null +++ b/avr/modules/basetimer/0BUILD @@ -0,0 +1,12 @@ + + + + + + main.asm + + + + + + diff --git a/avr/modules/basetimer/main.asm b/avr/modules/basetimer/main.asm new file mode 100644 index 0000000..5607ff2 --- /dev/null +++ b/avr/modules/basetimer/main.asm @@ -0,0 +1,188 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + +; +; The base timer makes sure that "onSystemTimerTick" is called about every +; 100ms. +; The setup depends on hardware and clock. +; + + + +; *************************************************************************** +; data + +.dseg + +baseTimerModuleData: +baseTimerModuleReloadValue: .byte 1 +baseTimerModuleTickCounter: .byte 1 +baseTimerTicksSinceLastRun: .byte 2 +baseTimerModuleData_end: + + + + +; *************************************************************************** +; code + +.cseg + +BASETIMER_BEGIN: + + + +; --------------------------------------------------------------------------- +; @rotuine BaseTimer_Init @global +; +; @clobbers r16, r17, x + +BaseTimer_Init: ; setup timer for IRQ every 100ms + ; reset data in SDRAM + ldi xh, HIGH(baseTimerModuleData) + ldi xl, LOW(baseTimerModuleData) + ldi r16, 0 + ldi r17, (baseTimerModuleData_end-baseTimerModuleData) + rcall Utils_FillSram + + ldi r16, (1< IRQ_OC0A - - ; CMP-A interrupt about every 100ms - ldi r16, (1<