From bdd710fc5cb9728832005f457a56aeb5499887d4 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 19 Jul 2025 09:42:02 +0200 Subject: [PATCH] avr: started working on new SPI-like COM protocol. use a clock and a data line to introduce synchronisation into the protocol to be able to work with the wide range of mcu speeds (no need for exact timing, no need for exact calibration). --- avr/devices/all/includes.asm | 15 + avr/devices/all/main.asm | 13 + avr/devices/all/modules.asm | 27 ++ avr/modules/com2w/com2w.asm | 664 +++++++++++++++++++++++++++++++++++ avr/modules/com2w/com2w1.asm | 638 +++++++++++++++++++++++++++++++++ avr/modules/com2w/common.asm | 244 +++++++++++++ avr/modules/com2w/defs.asm | 74 ++++ 7 files changed, 1675 insertions(+) create mode 100644 avr/modules/com2w/com2w.asm create mode 100644 avr/modules/com2w/com2w1.asm create mode 100644 avr/modules/com2w/common.asm create mode 100644 avr/modules/com2w/defs.asm diff --git a/avr/devices/all/includes.asm b/avr/devices/all/includes.asm index 220c03e..41039f9 100644 --- a/avr/devices/all/includes.asm +++ b/avr/devices/all/includes.asm @@ -96,6 +96,21 @@ #endif + +#ifdef MODULES_COM2W +.include "modules/com2w/defs.asm" +.include "modules/com2w/com2w.asm" +#endif + + + +#ifdef MODULES_COM2W1 +.include "modules/com2w/defs.asm" +.include "modules/com2w/common.asm" +.include "modules/com2w/com2w1.asm" +#endif + + #ifdef MODULES_CLOCK .include "modules/clock/main.asm" #endif diff --git a/avr/devices/all/main.asm b/avr/devices/all/main.asm index 3d29c32..8c520a0 100644 --- a/avr/devices/all/main.asm +++ b/avr/devices/all/main.asm @@ -135,6 +135,19 @@ onSystemTimerTick: bigcall ComOnUart1_Periodically #endif +#ifdef MODULES_COM2W + bigcall COM2W_Every100ms +#endif + + +#ifdef MODULES_COM2W0 + bigcall COM2W0_Periodically +#endif + +#ifdef MODULES_COM2W1 + bigcall COM2W1_Periodically +#endif + #ifdef MODULES_TCRT1000 bigcall TCRT1K_Every100ms #endif diff --git a/avr/devices/all/modules.asm b/avr/devices/all/modules.asm index 14f405d..b5a3e19 100644 --- a/avr/devices/all/modules.asm +++ b/avr/devices/all/modules.asm @@ -81,6 +81,18 @@ initModules: bigcall ComOnUart1_Init #endif +#ifdef MODULES_COM2W + bigcall COM2W_Init +#endif + +#ifdef MODULES_COM2W0 + bigcall COM2W0_Init +#endif + +#ifdef MODULES_COM2W1 + bigcall COM2W1_Init +#endif + #ifdef MODULES_MOTION bigcall Motion_Init #endif @@ -223,6 +235,21 @@ runComModules_loop: pop r16 sbci r16, 0 #endif + +#ifdef MODULES_COM2W0 + push r16 + bigcall COM2W0_Run + pop r16 + sbci r16, 0 +#endif + +#ifdef MODULES_COM2W1 + push r16 + bigcall COM2W1_Run + pop r16 + sbci r16, 0 +#endif + pop r17 ; check for repeat request tst r16 diff --git a/avr/modules/com2w/com2w.asm b/avr/modules/com2w/com2w.asm new file mode 100644 index 0000000..00c38b4 --- /dev/null +++ b/avr/modules/com2w/com2w.asm @@ -0,0 +1,664 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + +#ifndef AVR_MODULES_COM2W_COM2W_H +#define AVR_MODULES_COM2W_COM2W_H + + +.dseg + +com2w_iface: .byte COM2W_IFACE_SIZE + + + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine COM2W_Init +; +; @clobbers + +COM2W_Init: + ldi yl, LOW(com2w_iface) + ldi yh, HIGH(com2w_iface) + rcall NET_Interface_Init ; (R16, R17, X) + + ; setup CLK line (as input, disable internal pull-up resistor) + cbi COM_CLK_DDR, COM_CLK_PIN ; set CLK as input +.ifdef COM_CLK_PUE + inr r16, COM_CLK_PUE + cbr r16, (1<