diff --git a/avr/modules/com2w/com2wn_data.asm b/avr/modules/com2w/com2wn_data.asm new file mode 100644 index 0000000..6b92875 --- /dev/null +++ b/avr/modules/com2w/com2wn_data.asm @@ -0,0 +1,59 @@ +; *************************************************************************** +; 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_COM2WN_DATA_H +#define AVR_MODULES_COM2W_COM2WN_DATA_H + + +.dseg + + +com2wnIoRingBuffer: .byte RINGBUFFERY_SIZE+COM2WN_IO_RINGBUFFER_SIZE +com2wnIoCurrentClockStates: .byte 1 +com2wnIoLastClockStates: .byte 1 +com2wnIoFlags: .byte 1 + + +.if COM_PORTS >0 +com2w0_iface: .byte COM2W_IFACE_SIZE +.endif + +.if COM_PORTS >1 +com2w1_iface: .byte COM2W_IFACE_SIZE +.endif + +.if COM_PORTS >2 +com2w2_iface: .byte COM2W_IFACE_SIZE +.endif + +.if COM_PORTS >3 +com2w3_iface: .byte COM2W_IFACE_SIZE +.endif + +.if COM_PORTS >4 +com2w4_iface: .byte COM2W_IFACE_SIZE +.endif + +.if COM_PORTS >5 +com2w5_iface: .byte COM2W_IFACE_SIZE +.endif + +.if COM_PORTS >6 +com2w6_iface: .byte COM2W_IFACE_SIZE +.endif + +.if COM_PORTS >7 +com2w7_iface: .byte COM2W_IFACE_SIZE +.endif + + + + +#endif ; AVR_MODULES_COM2W_COM2WN_DATA_H + diff --git a/avr/modules/com2w/com2wn_init.asm b/avr/modules/com2w/com2wn_init.asm new file mode 100644 index 0000000..897253d --- /dev/null +++ b/avr/modules/com2w/com2wn_init.asm @@ -0,0 +1,112 @@ +; *************************************************************************** +; 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_COM2WN_INIT_H +#define AVR_MODULES_COM2W_COM2WN_INIT_H + + +; WORK IN PROGRESS + + +; --------------------------------------------------------------------------- +; @macro mCOM2WN_INIT +; +; @param @0 interface number (beginning with 0) + +.macro mCOM2WN_INIT + ldi yl, LOW(com2w@0_iface) + ldi yh, HIGH(com2w@0_iface) + rcall com2wnInit + ldi r16, COM_MASK_CLK@0 + std Y+COM2W_IFACE_OFFS_PINMASK_CLK, r16 + ldi r16, COM_MASK_DATA@0 + std Y+COM2W_IFACE_OFFS_PINMASK_DATA, r16 + ldi r16, COM_MASK_IRQ@0 + std Y+COM2W_IFACE_OFFS_PINMASK_IRQ, r16 +.endmacro +; @end + + + + + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine COM2WN_Init +; + +COM2WN_Init: + ldi r16, 0xff ; start with all clock lines hi + sts com2wnIoCurrentClockStates, r16 + sts com2wnIoLastClockStates, r16 + + clr r16 + sts com2wnIoFlags, r16 + + ldi yl, LOW(com2wnIoRingBuffer) + ldi yh, HIGH(com2wnIoRingBuffer) + ldi r16, COM2WN_IO_RINGBUFFER_SIZE + rcall RingBufferY_Init ; (R17) + +.if COM_PORTS >0 + mCOM2WN_INIT 0 +.endif +.if COM_PORTS >1 + mCOM2WN_INIT 1 +.endif + +.if COM_PORTS >2 + mCOM2WN_INIT 2 +.endif +.if COM_PORTS >3 + mCOM2WN_INIT 3 +.endif + +.if COM_PORTS >4 + mCOM2WN_INIT 4 +.endif +.if COM_PORTS >5 + mCOM2WN_INIT 5 +.endif + +.if COM_PORTS >6 + mCOM2WN_INIT 6 +.endif +.if COM_PORTS >7 + mCOM2WN_INIT 7 +.endif + + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine com2wInit +; + +com2wnInit: + rcall NET_Interface_Init ; (R16, R17, X) + ldi r16, COM2W_MODE_IDLE + rcall com2wSetMode ; (R17) + + rcall com2wSetupLines + rcall com2wSetupIrq + + ret +; @end + + + +#endif ; AVR_MODULES_COM2W_COM2WN_INIT_H + + diff --git a/avr/modules/com2w/com2wn_io.asm b/avr/modules/com2w/com2wn_io.asm new file mode 100644 index 0000000..9cf78a5 --- /dev/null +++ b/avr/modules/com2w/com2wn_io.asm @@ -0,0 +1,165 @@ +; *************************************************************************** +; 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_COM2WN_IO_H +#define AVR_MODULES_COM2W_COM2WN_IO_H + + +; WORK IN PROGRESS + + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine com2wSetupLines + +com2wSetupLines: + ; setup CLK line (as input, disable internal pull-up resistor) + rcall com2wClkSetHigh + +.ifdef COM_CLK_PUE + ldd r16, Y+COM2W_IFACE_OFFS_PINMASK_CLK + com r16 + inr r17, COM_CLK_PUE + and r17, r16 + outr COM_CLK_PUE, r17 +.endif + + ; setup DATA line (as input, disable internal pull-up resistor) + rcall com2wDataSetHigh +.ifdef COM_DATA_PUE + ldd r16, Y+COM2W_IFACE_OFFS_PINMASK_DATA + com r16 + inr r17, COM_DATA_PUE + and r17, r16 + outr COM_DATA_PUE, r17 +.endif + + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine com2wClkSetHigh +; +; @clobbers none + +com2wClkSetHigh: + push r16 + push r17 + ldd r16, Y+COM2W_IFACE_OFFS_PINMASK_CLK + ; clear bit in io reg (AND with complement) + com r16 + inr r17, COM_CLK_DDR + and r17, r16 + outr COM_CLK_DDR, r17 ; make pin input +.ifndef COM_CLK_PUE + inr r17, COM_CLK_OUTPUT + and r17, r16 ; disable pullup + outr COM_CLK_OUTPUT, r17 +.endif + pop r17 + pop r16 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine com2wClkSetLow +; +; @param Y pointer to interface data in SRAM +; @clobbers none + +com2wClkSetLow: + push r16 + push r17 + ldd r16, Y+COM2W_IFACE_OFFS_PINMASK_CLK + ; set bit in io reg + inr r17, COM_CLK_DDR + or r17, r16 + outr COM_CLK_DDR, r17 ; make pin output + + com r16 + inr r17, COM_CLK_OUTPUT + and r17, r16 + outr COM_CLK_OUTPUT, r17 ; set pin low + + pop r17 + pop r16 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine com2wDataSetHigh +; +; @param Y pointer to interface data in SRAM +; @clobbers none + +com2wDataSetHigh: + push r16 + push r17 + ldd r16, Y+COM2W_IFACE_OFFS_PINMASK_DATA + ; clear bit in io reg (AND with complement) + com r16 + inr r17, COM_DATA_DDR + and r17, r16 + outr COM_DATA_DDR, r17 ; make pin input +.ifndef COM_DATA_PUE + inr r17, COM_DATA_OUTPUT + and r17, r16 ; disable pullup + outr COM_DATA_OUTPUT, r17 +.endif + pop r17 + pop r16 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine com2wDataSetLow +; +; @param Y pointer to interface data in SRAM +; @clobbers none + +com2wDataSetLow: + push r16 + push r17 + ldd r16, Y+COM2W_IFACE_OFFS_PINMASK_DATA + ; set bit in io reg + inr r17, COM_DATA_DDR + or r17, r16 + outr COM_DATA_DDR, r17 ; make pin output + + com r16 + inr r17, COM_DATA_OUTPUT + and r17, r16 + outr COM_DATA_OUTPUT, r17 ; set pin low + + pop r17 + pop r16 + ret +; @end + + + + + + + + + +#endif ; AVR_MODULES_COM2W_COM2WN_IO_H + diff --git a/avr/modules/com2w/com2wn_irq.asm b/avr/modules/com2w/com2wn_irq.asm new file mode 100644 index 0000000..b2e5f9e --- /dev/null +++ b/avr/modules/com2w/com2wn_irq.asm @@ -0,0 +1,165 @@ +; *************************************************************************** +; 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_COM2WN_IRQ_H +#define AVR_MODULES_COM2W_COM2WN_IRQ_H + + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine com2wnSetupIrq +; + +com2wnSetupIrq: + ; setup pin-change interrupt for CLK + rcall com2wnEnableClkIrq + + ; enable and clear PCIE0/1 (@TODO put later into general setup) + inr r16, GIMSK ; enable pin change irq PCIE0 or PCIE1 + sbr r16, (1<