diff --git a/avr/modules/0BUILD b/avr/modules/0BUILD index afc8cda..ec3eaaf 100644 --- a/avr/modules/0BUILD +++ b/avr/modules/0BUILD @@ -6,6 +6,7 @@ basetimer bmp280 ccs811 + clock cny70 com2 comproto diff --git a/avr/modules/clock/0BUILD b/avr/modules/clock/0BUILD new file mode 100644 index 0000000..febd367 --- /dev/null +++ b/avr/modules/clock/0BUILD @@ -0,0 +1,11 @@ + + + + + + main.asm + + + + + diff --git a/avr/modules/clock/main.asm b/avr/modules/clock/main.asm new file mode 100644 index 0000000..f3bf26f --- /dev/null +++ b/avr/modules/clock/main.asm @@ -0,0 +1,132 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; Counts seconds, minutes and hours +; +; calls onEverySecond, onEveryMinute, onEveryHour and onEveryDay +; + + + +; *************************************************************************** +; defs + + + + + +; *************************************************************************** +; data + +.dseg + +clockModuleData: +clockModuleTickCounter: .byte 1 +clockModuleCounterSecs: .byte 1 +clockModuleCounterMins: .byte 1 +clockModuleCounterHours: .byte 1 +clockModuleData_end: + + + + +; *************************************************************************** +; code + +.cseg + +CLOCK_BEGIN: + + + +; --------------------------------------------------------------------------- +; @routine Clock_Init +; +; @clobbers r16, r17, x + +Clock_Init: + ; reset data in SDRAM + ldi xh, HIGH(clockModuleData) + ldi xl, LOW(clockModuleData) + clr r16 + ldi r17, (clockModuleData_end-clockModuleData) + rcall Utils_FillSram ; (R17, X) + sec + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine Clock_Fini +; + +Clock_Fini: + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine Clock_Every100ms +; + +Clock_Every100ms: + lds r16, clockModuleTickCounter + inc r16 + cpi r16, 10 + brcc Clock_Every100ms_inc1s + sts clockModuleTickCounter, r16 + ret +Clock_Every100ms_inc1s: + clr r16 + sts clockModuleTickCounter, r16 + rcall onEverySecond + lds r16, clockModuleCounterSecs + inc r16 + cpi r16, 60 + brcc Clock_Every100ms_inc1m + sts clockModuleCounterSecs, r16 + ret +Clock_Every100ms_inc1m: + clr r16 + sts clockModuleCounterSecs, r16 + rcall onEveryMinute + lds r16, clockModuleCounterMins + inc r16 + cpi r16, 60 + brcc Clock_Every100ms_inc1h + sts clockModuleCounterMins, r16 + ret +Clock_Every100ms_inc1h: + clr r16 + sts clockModuleCounterMins, r16 + rcall onEveryHour + lds r16, clockModuleCounterHours + inc r16 + cpi r16, 24 + brcc Clock_Every100ms_1d + sts clockModuleCounterHours, r16 + ret +Clock_Every100ms_1d: + clr r16 + sts clockModuleCounterHours, r16 + rcall onEveryDay + ret +; @end + + + + + +CLOCK_END: +.equ MODULE_SIZE_CLOCK = CLOCK_END-CLOCK_BEGIN + +