diff --git a/avr/devices/t03/main.asm b/avr/devices/t03/main.asm
index 4069ce4..4497448 100644
--- a/avr/devices/t03/main.asm
+++ b/avr/devices/t03/main.asm
@@ -72,8 +72,8 @@
;#define MODULES_MOTION
-.equ UART_HW_FIXEDBUFFERS_NUM = 32
-.equ UART_HW_FIXEDBUFFERS_SIZE = 6
+.equ NET_BUFFERS_NUM = 6
+.equ NET_BUFFERS_SIZE = 32
.equ UART_HW_MSGNUMINBUF_SIZE = 6
.equ UART_HW_MSGNUMOUTBUF_SIZE = 6
@@ -233,7 +233,7 @@ initHardware:
initModules:
rcall BaseTimer_Init
rcall LedSimple_Init
- rcall UART_HW_Init
+ rcall NET_Init
rcall TtyOnUart1_Init
ldi r16, LOW(SEND_DEVICE_EVERY)
@@ -265,13 +265,16 @@ initModules:
.include "modules/com2/defs.asm"
.include "modules/com2/crc.asm"
.include "modules/comproto/defs.asm"
+.include "modules/network/defs.asm"
+.include "modules/network/buffer.asm"
+.include "modules/network/data.asm"
+.include "modules/network/main.asm"
+.include "modules/network/iface.asm"
+
.include "modules/uart_hw/defs.asm"
-.include "modules/uart_hw/buffers.asm"
.include "modules/uart_hw/lowlevel.asm"
.include "modules/uart_hw/m_lowlevel_uart.asm"
.include "modules/uart_hw/lowlevel_uart1.asm"
-;.include "modules/uart_hw/msglevel_recv.asm"
-;.include "modules/uart_hw/msglevel_send.asm"
.include "modules/uart_hw/ttyonuart1.asm"
@@ -288,7 +291,7 @@ maybeSendDeviceMsg:
sbiw r25:r24, 1
brne maybeSendDeviceMsg_storeCounter
; send device msg
- rcall UART_HW_FixedBuffers_Alloc
+ rcall NET_Buffer_Alloc ; (R16, R17, X)
brcc maybeSendDeviceMsg_resetCounter
push r16
adiw xh:xl, 1
@@ -299,7 +302,7 @@ maybeSendDeviceMsg:
rcall TtyOnUart1_SendBuffer
pop r16
brcs maybeSendDeviceMsg_resetCounter
- rcall UART_HW_FixedBuffers_ReleaseByNum ; (R16, X)
+ rcall NET_Buffer_ReleaseByNum ; (R16, X)
rjmp maybeSendDeviceMsg_end
; reset counter
maybeSendDeviceMsg_resetCounter:
diff --git a/avr/modules/0BUILD b/avr/modules/0BUILD
index a119ebe..95758dc 100644
--- a/avr/modules/0BUILD
+++ b/avr/modules/0BUILD
@@ -24,6 +24,7 @@
tcrt1000
timer
twimaster
+ network
uart_bitbang
uart_irq
bootloader
diff --git a/avr/modules/network/0BUILD b/avr/modules/network/0BUILD
new file mode 100644
index 0000000..e59ecc5
--- /dev/null
+++ b/avr/modules/network/0BUILD
@@ -0,0 +1,12 @@
+
+
+
+
+
+ buffer.asm
+ defs.asm
+
+
+
+
+
diff --git a/avr/modules/network/buffer.asm b/avr/modules/network/buffer.asm
new file mode 100644
index 0000000..c5e6692
--- /dev/null
+++ b/avr/modules/network/buffer.asm
@@ -0,0 +1,125 @@
+; ***************************************************************************
+; 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. *
+; ***************************************************************************
+
+
+; ===========================================================================
+; defs
+
+.equ NET_BUFFER_INUSE_BIT = 7
+.equ NET_BUFFER_IFACENUM1_BIT = 1
+.equ NET_BUFFER_IFACENUM0_BIT = 0
+
+
+
+
+; ===========================================================================
+; code segment
+
+.cseg
+
+; ---------------------------------------------------------------------------
+; @routine NET_Buffer_Init @global
+;
+; @clobbers R16, R17, X
+
+NET_Buffer_Init:
+ ldi xl, LOW(netBuffers)
+ ldi xh, HIGH(netBuffers)
+ m_fixedbuf_init NET_BUFFERS_SIZE, NET_BUFFERS_NUM
+ ret
+; @end
+
+
+
+; ---------------------------------------------------------------------------
+; @routine NET_Buffer_Alloc @global
+;
+; @return CFLAG set if buffer available, cleared otherwise
+; @return r16 buffer num
+; @return X pointer to start of buffer
+; @clobbers R16, R17, X
+
+NET_Buffer_Alloc:
+ ldi xl, LOW(netBuffers)
+ ldi xh, HIGH(netBuffers)
+ m_fixedbuf_reserve NET_BUFFERS_SIZE, NET_BUFFERS_NUM
+ brcc NET_Buffer_Alloc_end
+ ldi r17, (1<
- buffers.asm
defs.asm
init_uart1.asm
lowlevel.asm
diff --git a/avr/modules/uart_hw/buffers.asm b/avr/modules/uart_hw/buffers.asm
deleted file mode 100644
index 0e38a12..0000000
--- a/avr/modules/uart_hw/buffers.asm
+++ /dev/null
@@ -1,204 +0,0 @@
-; ***************************************************************************
-; 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. *
-; ***************************************************************************
-
-
-.dseg
-
-uartHwDataBegin:
- ; fixed buffers for incoming and outgoing messages
- uartHw_buffers: .byte UART_HW_FIXEDBUFFERS_NUM*UART_HW_FIXEDBUFFERS_SIZE
- uartHw_ringBufferMsgNumIn: .byte UART_HW_MSGNUMINBUF_SIZE
- uartHw_ringBufferMsgNumOut: .byte UART_HW_MSGNUMOUTBUF_SIZE
-uartHwDataEnd:
-
-
-
-.cseg
-
-
-
-; ---------------------------------------------------------------------------
-; @routine UART_HW_FixedBuffers_Init @global
-;
-; @clobbers R16, R17, X
-
-UART_HW_FixedBuffers_Init:
- ldi xl, LOW(uartHw_buffers)
- ldi xh, HIGH(uartHw_buffers)
- m_fixedbuf_init UART_HW_FIXEDBUFFERS_SIZE, UART_HW_FIXEDBUFFERS_NUM
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine UART_HW_FixedBuffers_Alloc @global
-;
-; @return CFLAG set if buffer available, cleared otherwise
-; @return r16 buffer num
-; @return X pointer to start of buffer
-; @clobbers R16, R17, X
-
-UART_HW_FixedBuffers_Alloc:
- ldi xl, LOW(uartHw_buffers)
- ldi xh, HIGH(uartHw_buffers)
- m_fixedbuf_reserve UART_HW_FIXEDBUFFERS_SIZE, UART_HW_FIXEDBUFFERS_NUM
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine UART_HW_FixedBuffers_ReleaseByAddr @global
-;
-; @param X pointer to start of buffers
-; @clobbers R16
-
-UART_HW_FixedBuffers_ReleaseByAddr:
- m_fixedbuf_release
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine UART_HW_FixedBuffers_ReleaseByNum @global
-;
-; @param r16 buffer number
-; @clobbers X (R16)
-
-UART_HW_FixedBuffers_ReleaseByNum:
- rcall UART_HW_FixedBuffers_Locate ; (R16)
- brcc UART_HW_FixedBuffers_ReleaseByNum_end
- rcall UART_HW_FixedBuffers_ReleaseByAddr ; (R16)
-UART_HW_FixedBuffers_ReleaseByNum_end:
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine UART_HW_FixedBuffers_Locate
-;
-; Get position of a given buffer.
-;
-; CAVE: need to change this routine if UART_HW_FIXEDBUFFERS_SIZE is changed!
-;
-; @return CFLAG set if okay, cleared on error
-; @return X points to start of buffer with the given num
-; @param r16 buffer num (0-max)
-; @clobbers r16
-
-UART_HW_FixedBuffers_Locate:
- cpi r16, UART_HW_FIXEDBUFFERS_NUM
- brcc UART_HW_FixedBuffers_Locate_end ; out of range
- mov xh, r16 ; * 256
- clr xl
- lsr xh ; *128
- ror xl
- lsr xh ; *64
- ror xl
- lsr xh ; *32
- ror xl
- ldi r16, LOW(uartHw_buffers)
- add xl, r16
- ldi r16, HIGH(uartHw_buffers)
- adc xh, r16
- sec
-UART_HW_FixedBuffers_Locate_end:
- ret
-; @end
-
-
-
-
-
-; ---------------------------------------------------------------------------
-; @routine UART_HW_AddIncomingMsg @global
-;
-; @return CFLAG on success, cleared on error
-; @param R16 buffer number of the next incoming message
-; @clobbers R17, R18, X
-
-UART_HW_AddIncomingMsgNum:
- push yl
- push yh
- ldi yl, LOW(uartHw_ringBufferMsgNumIn)
- ldi yh, HIGH(uartHw_ringBufferMsgNumIn)
- rcall RingBufferY_WriteByte ; R17, R18, X
- pop yh
- pop yl
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine UART_HW_GetNextIncomingMsgNum @global
-;
-; @return CFLAG on success, cleared on error
-; @return R16 buffer number of the next incoming message
-; @param Y pointer to start of interface data
-; @clobbers R17, R18, X
-
-UART_HW_GetNextIncomingMsgNum:
- push yl
- push yh
- ldi yl, LOW(uartHw_ringBufferMsgNumIn)
- ldi yh, HIGH(uartHw_ringBufferMsgNumIn)
- rcall RingBufferY_ReadByte ; R17, R18, X
- pop yh
- pop yl
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine UART_HW_AddOutgoingMsg @global
-;
-; @return CFLAG on success, cleared on error
-; @param R16 buffer number of the next incoming message
-; @clobbers R17, R18, X
-
-UART_HW_AddOutgoingMsgNum:
- push yl
- push yh
- ldi yl, LOW(uartHw_ringBufferMsgNumOut)
- ldi yh, HIGH(uartHw_ringBufferMsgNumOut)
- rcall RingBufferY_WriteByte ; R17, R18, X
- pop yh
- pop yl
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine UART_HW_GetNextOutgoingMsgNum @global
-;
-; @return CFLAG on success, cleared on error
-; @return R16 buffer number of the next incoming message
-; @param Y pointer to start of interface data
-; @clobbers R17, R18, X
-
-UART_HW_GetNextOutgoingMsgNum:
- push yl
- push yh
- ldi yl, LOW(uartHw_ringBufferMsgNumOut)
- ldi yh, HIGH(uartHw_ringBufferMsgNumOut)
- rcall RingBufferY_ReadByte ; R17, R18, X
- pop yh
- pop yl
- ret
-; @end
-
-
-
-
diff --git a/avr/modules/uart_hw/defs.asm b/avr/modules/uart_hw/defs.asm
index c7154b9..7acf9ec 100644
--- a/avr/modules/uart_hw/defs.asm
+++ b/avr/modules/uart_hw/defs.asm
@@ -8,58 +8,46 @@
; ***************************************************************************
-.equ UART_HW_IFACE_READBUF_SIZE = 8
-.equ UART_HW_IFACE_WRITEBUF_SIZE = 8
-.equ UART_HW_IFACE_OUTMSGBUF_SIZE = 4
-
-.equ UART_HW_BUFFER_INUSE_BIT = 7
-.equ UART_HW_BUFFER_IFACENUM1_BIT = 1
-.equ UART_HW_BUFFER_IFACENUM0_BIT = 0
+.equ UART_HW_BUFFER_INUSE_BIT = 7
+.equ UART_HW_BUFFER_IFACENUM1_BIT = 1
+.equ UART_HW_BUFFER_IFACENUM0_BIT = 0
-.equ UART_HW_READMODE_OFF = 0
-.equ UART_HW_READMODE_IDLE = 1
-.equ UART_HW_READMODE_READING = 2
-.equ UART_HW_READMODE_SKIPPING = 3
+.equ UART_HW_READMODE_OFF = 0
+.equ UART_HW_READMODE_IDLE = 1
+.equ UART_HW_READMODE_READING = 2
+.equ UART_HW_READMODE_SKIPPING = 3
-.equ UART_HW_WRITEMODE_OFF = 0
-.equ UART_HW_WRITEMODE_IDLE = 1
-.equ UART_HW_WRITEMODE_WRITING = 2
-.equ UART_HW_WRITEMODE_WAITBUFFEREMPTY = 3
-.equ UART_HW_WRITEMODE_WRITEBUFFEREMPTY = 4
+.equ UART_HW_WRITEMODE_OFF = 0
+.equ UART_HW_WRITEMODE_IDLE = 1
+.equ UART_HW_WRITEMODE_WRITING = 2
+.equ UART_HW_WRITEMODE_WAITBUFFEREMPTY = 3
+.equ UART_HW_WRITEMODE_WRITEBUFFEREMPTY = 4
-.equ UART_HW_STATUS_UNDERRUN_BIT = 0
-.equ UART_HW_STATUS_OVERRUN_BIT = 1
-.equ UART_HW_STATUS_HWERR_BIT = 2
-.equ UART_HW_STATUS_SOFTERR_BIT = 3
-.equ UART_HW_STATUS_ATTN_BIT = 7
+.equ UART_HW_STATUS_UNDERRUN_BIT = 0
+.equ UART_HW_STATUS_OVERRUN_BIT = 1
+.equ UART_HW_STATUS_HWERR_BIT = 2
+.equ UART_HW_STATUS_SOFTERR_BIT = 3
+.equ UART_HW_STATUS_ATTN_BIT = 7
-.equ UART_HW_IFACE_OFFS_IFACENUM = 0 ; interface number (put into received messages)
-.equ UART_HW_IFACE_OFFS_STATUS = 1
-.equ UART_HW_IFACE_OFFS_READTIMER = 2
-.equ UART_HW_IFACE_OFFS_WRITETIMER = 3
-.equ UART_HW_IFACE_OFFS_ERR_OVRLOW = 4
-.equ UART_HW_IFACE_OFFS_ERR_OVRHIGH = 5
-.equ UART_HW_IFACE_OFFS_ERR_CONTENTLOW = 6
-.equ UART_HW_IFACE_OFFS_ERR_CONTENTHIGH = 7
+.equ UART_HW_IFACE_OFFS_READ = NET_IFACE_SIZE
+.equ UART_HW_IFACE_OFFS_READMODE = UART_HW_IFACE_OFFS_READ
+.equ UART_HW_IFACE_OFFS_READBUFNUM = UART_HW_IFACE_OFFS_READ+1
+.equ UART_HW_IFACE_OFFS_READBUFPOS_LOW = UART_HW_IFACE_OFFS_READ+2
+.equ UART_HW_IFACE_OFFS_READBUFPOS_HIGH = UART_HW_IFACE_OFFS_READ+3
+.equ UART_HW_IFACE_OFFS_READBUFUSED = UART_HW_IFACE_OFFS_READ+4
+.equ UART_HW_IFACE_OFFS_READBUFLEFT = UART_HW_IFACE_OFFS_READ+5
-.equ UART_HW_IFACE_OFFS_READMODE = 8
-.equ UART_HW_IFACE_OFFS_READBUFNUM = 9
-.equ UART_HW_IFACE_OFFS_READBUFPOSLOW = 10
-.equ UART_HW_IFACE_OFFS_READBUFPOSHIGH = 11
-.equ UART_HW_IFACE_OFFS_READBUFUSED = 12
-.equ UART_HW_IFACE_OFFS_READBUFLEFT = 13
+.equ UART_HW_IFACE_OFFS_WRITE = UART_HW_IFACE_OFFS_READBUFLEFT+1
+.equ UART_HW_IFACE_OFFS_WRITEMODE = UART_HW_IFACE_OFFS_WRITE
+.equ UART_HW_IFACE_OFFS_WRITEBUFNUM = UART_HW_IFACE_OFFS_WRITE+1
+.equ UART_HW_IFACE_OFFS_WRITEBUFPOS_LOW = UART_HW_IFACE_OFFS_WRITE+2
+.equ UART_HW_IFACE_OFFS_WRITEBUFPOS_HIGH = UART_HW_IFACE_OFFS_WRITE+3
+.equ UART_HW_IFACE_OFFS_WRITEBUFUSED = UART_HW_IFACE_OFFS_WRITE+4
+.equ UART_HW_IFACE_OFFS_WRITEBUFLEFT = UART_HW_IFACE_OFFS_WRITE+5
-.equ UART_HW_IFACE_OFFS_WRITEMODE = 14
-.equ UART_HW_IFACE_OFFS_WRITEBUFNUM = 15
-.equ UART_HW_IFACE_OFFS_WRITEBUFPOSLOW = 16
-.equ UART_HW_IFACE_OFFS_WRITEBUFPOSHIGH = 17
-.equ UART_HW_IFACE_OFFS_WRITEBUFUSED = 18
-.equ UART_HW_IFACE_OFFS_WRITEBUFLEFT = 19
-.equ UART_HW_IFACE_OFFS_WRITEMSGRINGBUF = 20
-
-.equ UART_HW_IFACE_SIZE = UART_HW_IFACE_OFFS_WRITEMSGRINGBUF+RINGBUFFERY_SIZE+UART_HW_IFACE_OUTMSGBUF_SIZE
+.equ UART_HW_IFACE_SIZE = UART_HW_IFACE_OFFS_WRITEBUFLEFT+1
diff --git a/avr/modules/uart_hw/lowlevel.asm b/avr/modules/uart_hw/lowlevel.asm
index adacd50..9d2dc14 100644
--- a/avr/modules/uart_hw/lowlevel.asm
+++ b/avr/modules/uart_hw/lowlevel.asm
@@ -13,67 +13,20 @@
; ---------------------------------------------------------------------------
-; @routine UART_HW_Init @global
+; @routine UART_HW_Interface_Init @global
;
-; Initializes buffers.
-;
-; @clobbers R16, R17, X, Y
-
-UART_HW_Init:
- ldi xh, HIGH(uartHwDataBegin)
- ldi xl, LOW(uartHwDataBegin)
- clr r16
- ldi r17, (uartHwDataEnd-uartHwDataBegin)
- rcall Utils_FillSram
-
- rcall UART_HW_FixedBuffers_Init
-
- ldi r16, UART_HW_MSGNUMINBUF_SIZE
- ldi yl, LOW(uartHw_ringBufferMsgNumIn)
- ldi yh, HIGH(uartHw_ringBufferMsgNumIn)
- rcall RingBufferY_Init
-
- ldi r16, UART_HW_MSGNUMOUTBUF_SIZE
- ldi yl, LOW(uartHw_ringBufferMsgNumOut)
- ldi yh, HIGH(uartHw_ringBufferMsgNumOut)
- rcall RingBufferY_Init
- sec
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine UART_HW_InterfaceInit @global
-;
-; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_STATE)
-; @clobbers R16, R17, X
-
-UART_HW_InterfaceInit:
- mov xl, yl
- mov xh, yh
- ldi r17, UART_HW_IFACE_SIZE
- clr r16
- rcall Utils_FillSram ; (R17, X)
+; @param Y pointer to interface data in SRAM
+; @clobbers R16 (R17, X)
+UART_HW_Interface_Init:
+ rcall NET_Interface_Init ; (R16, R17, X)
ldi r16, 0xff
std Y+UART_HW_IFACE_OFFS_READBUFNUM, r16
std Y+UART_HW_IFACE_OFFS_WRITEBUFNUM, r16
-
- ldi r16, UART_HW_READMODE_OFF
+ ldi r16, UART_HW_READMODE_IDLE
std Y+UART_HW_IFACE_OFFS_READMODE, r16
-
ldi r16, UART_HW_WRITEMODE_IDLE
std Y+UART_HW_IFACE_OFFS_WRITEMODE, r16
-
- push yl
- push yh
- adiw yh:yl, UART_HW_IFACE_OFFS_WRITEMSGRINGBUF
- ldi r16, UART_HW_IFACE_OUTMSGBUF_SIZE
- rcall RingBufferY_Init
- pop yh
- pop yl
-
ret
; @end
@@ -84,14 +37,14 @@ UART_HW_InterfaceInit:
;
; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_STATE)
; @param r16 read buffer number
-; @param X read buffer pos
+; @param X pointer to read buffer
; @clobbers R17
UART_HW_Interface_SetReadBuffer:
std Y+UART_HW_IFACE_OFFS_READBUFNUM, r16
adiw xh:xl, 1
- std Y+UART_HW_IFACE_OFFS_READBUFPOSLOW, xl
- std Y+UART_HW_IFACE_OFFS_READBUFPOSHIGH, xh
+ std Y+UART_HW_IFACE_OFFS_READBUFPOS_LOW, xl
+ std Y+UART_HW_IFACE_OFFS_READBUFPOS_HIGH, xh
sbiw xh:xl, 1
clr r17
std Y+UART_HW_IFACE_OFFS_READBUFUSED, r17
@@ -106,14 +59,14 @@ UART_HW_Interface_SetReadBuffer:
;
; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_STATE)
; @param r16 write buffer number
-; @param X write buffer pos
+; @param X pointer to write buffer
; @clobbers r17
UART_HW_Interface_SetWriteBuffer:
std Y+UART_HW_IFACE_OFFS_WRITEBUFNUM, r16
adiw xh:xl, 1
- std Y+UART_HW_IFACE_OFFS_WRITEBUFPOSLOW, xl ; begin of msg (dest addr byte)
- std Y+UART_HW_IFACE_OFFS_WRITEBUFPOSHIGH, xh
+ std Y+UART_HW_IFACE_OFFS_WRITEBUFPOS_LOW, xl ; begin of msg (dest addr byte)
+ std Y+UART_HW_IFACE_OFFS_WRITEBUFPOS_HIGH, xh
adiw xh:xl, 1
ld r17, X ; payload length byte
sbiw xh:xl, 2 ; back to start of buffer
@@ -127,146 +80,3 @@ UART_HW_Interface_SetWriteBuffer:
-; ---------------------------------------------------------------------------
-; @routine UART_HW_InterfaceAddOutgoingMsgNum @global
-;
-; @return CFLAG on success, cleared on error
-; @param r16 byte to write
-; @param Y pointer to start of interface data
-; @clobbers R17, R18, X
-
-UART_HW_InterfaceAddOutgoingMsgNum:
- push yl
- push yh
- adiw yh:yl, UART_HW_IFACE_OFFS_WRITEMSGRINGBUF
- rcall uartHwRingBufferWriteGuarded ; R17, R18, X
- pop yh
- pop yl
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine UART_HW_InterfaceGetNextOutgoingMsgNum @global
-;
-; @return CFLAG on success, cleared on error
-; @return R16 byte read
-; @param Y pointer to start of interface data
-; @clobbers R17, R18, X
-
-UART_HW_InterfaceGetNextOutgoingMsgNum:
- push yl
- push yh
- adiw yh:yl, UART_HW_IFACE_OFFS_WRITEMSGRINGBUF
- rcall uartHwRingBufferReadGuarded ; R17, R18, X
- pop yh
- pop yl
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine UART_HW_InterfacePeekNextOutgoingMsgNum @global
-;
-; @return CFLAG on success, cleared on error
-; @return R16 byte read
-; @param Y pointer to start of interface data
-; @clobbers R17, R18, X
-
-UART_HW_InterfacePeekNextOutgoingMsgNum:
- push yl
- push yh
- adiw yh:yl, UART_HW_IFACE_OFFS_WRITEMSGRINGBUF
- rcall uartHwRingBufferPeekGuarded ; R17, R18, X
- pop yh
- pop yl
- ret
-; @end
-
-
-
-
-
-
-; ---------------------------------------------------------------------------
-; @routine uartHwRingBufferReadGuarded
-;
-; @return CFLAG on success, cleared on error
-; @param r16 byte to write
-; @param Y pointer to start of interface data
-; @clobbers R17, R18, X
-
-uartHwRingBufferReadGuarded:
- push r15
- in r15, SREG
- cli
- rcall RingBufferY_ReadByte ; R17, R18, X
- brcc uartHwRingBufferReadGuarded_error
- out SREG, r15
- pop r15
- sec
- ret
-uartHwRingBufferReadGuarded_error:
- out SREG, r15
- pop r15
- clc
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine uartHwRingBufferPeekGuarded
-;
-; @return CFLAG on success, cleared on error
-; @param r16 byte to write
-; @param Y pointer to start of interface data
-; @clobbers R17, R18, X
-
-uartHwRingBufferPeekGuarded:
- push r15
- in r15, SREG
- cli
- rcall RingBufferY_PeekByte ; R17, R18, X
- brcc uartHwRingBufferPeekGuarded_error
- out SREG, r15
- pop r15
- sec
- ret
-uartHwRingBufferPeekGuarded_error:
- out SREG, r15
- pop r15
- clc
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine uartHwRingBufferWriteGuarded
-;
-; @return CFLAG on success, cleared on error
-; @param r16 byte to write
-; @param Y pointer to start of interface data
-; @clobbers R17, R18, X
-
-uartHwRingBufferWriteGuarded:
- push r15
- in r15, SREG
- cli
- rcall RingBufferY_WriteByte ; R17, R18, X
- brcc uartHwRingBufferWriteGuarded_error
- out SREG, r15
- pop r15
- sec
- ret
-uartHwRingBufferWriteGuarded_error:
- out SREG, r15
- pop r15
- clc
- ret
-; @end
-
-
diff --git a/avr/modules/uart_hw/m_lowlevel_uart.asm b/avr/modules/uart_hw/m_lowlevel_uart.asm
index a0d2f09..a1c3cc1 100644
--- a/avr/modules/uart_hw/m_lowlevel_uart.asm
+++ b/avr/modules/uart_hw/m_lowlevel_uart.asm
@@ -13,11 +13,11 @@
; @macro M_UART_HW_Uart_Init
;
; @param %0 UART number ("0" for UART0)
-; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_STATE)
+; @param Y pointer to interface data in SRAM
; @clobbers R16, R17, X
.macro M_UART_HW_Uart_Init
- rcall UART_HW_InterfaceInit
+ rcall NET_Interface_Init
; set baudrate
.if clock == 8000000
@@ -75,7 +75,7 @@
; @macro M_UART_HW_Uart_StartTx
;
; @param %0 UART number ("0" for UART0)
-; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_STATE)
+; @param Y pointer to interface data in SRAM
; @clobbers R16
.macro M_UART_HW_Uart_StartTx
@@ -94,7 +94,7 @@
; @macro M_UART_HW_Uart_StopTx
;
; @param %0 UART number ("0" for UART0)
-; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_STATE)
+; @param Y pointer to interface data in SRAM
; @clobbers R16
.macro M_UART_HW_Uart_StopTx
@@ -112,7 +112,7 @@
; Flush receiption buffer.
;
; @param %0 UART number ("0" for UART0)
-; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_MODE)
+; @param Y pointer to interface data in SRAM
; @clobbers R16
.macro M_UART_HW_Uart_Flush
@@ -122,7 +122,7 @@ l_loop_%:
rjmp l_end_%
lds r16, UDR@0
clr r16
- std Y+UART_HW_IFACE_OFFS_READTIMER, r16
+ std Y+NET_IFACE_OFFS_READTIMER, r16
rjmp l_loop_%
l_end_%:
.endmacro
@@ -134,7 +134,7 @@ l_end_%:
; @macro M_UART_HW_Uart_RxCharIsr
;
; @param %0 UART number ("0" for UART0)
-; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_MODE)
+; @param Y pointer to interface data in SRAM
; @clobbers R16 (R17, R18, X)
.macro M_UART_HW_Uart_RxCharIsr
@@ -142,7 +142,7 @@ l_end_%:
lds r16, UCSR@0A ; check for errors
andi r16, (1< HWERR
rjmp l_setStatusAndEnd_%
l_recv_%:
@@ -153,13 +153,13 @@ l_recv_%:
rcall UART_HW_InterfaceWriteToReadBuffer ; (R17, R18, X)
brcc l_overrun_%
clr r16
- std Y+UART_HW_IFACE_OFFS_READTIMER, r16 ; reset read timer
+ std Y+NET_IFACE_OFFS_READTIMER, r16 ; reset read timer
rjmp l_end_%
l_overrun_%:
- ldd r16, Y+UART_HW_IFACE_OFFS_STATUS ; set overrun error
+ ldd r16, Y+NET_IFACE_OFFS_STATUS ; set overrun error
ori r16, (1< OVERRUN
l_setStatusAndEnd_%:
- std Y+UART_HW_IFACE_OFFS_STATUS, r16
+ std Y+NET_IFACE_OFFS_STATUS, r16
l_end_%:
#endif
.endmacro
@@ -173,7 +173,7 @@ l_end_%:
; Handler for UDREn interrupt called when TX data register is empty.
;
; @param %0 UART number ("0" for UART0)
-; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_MODE)
+; @param Y pointer to interface data in SRAM
; @clobbers R16, R17, X
.macro M_UART_HW_Uart_TxUdreIsr
@@ -197,18 +197,18 @@ l_end_%:
breq l_disable_irq_% ; nothing left to write
; get read ptr, read byte, inc read ptr, store ptr and bytesLeft
- ldd xl, Y+UART_HW_IFACE_OFFS_WRITEBUFPOSLOW
- ldd xh, Y+UART_HW_IFACE_OFFS_WRITEBUFPOSHIGH
+ ldd xl, Y+UART_HW_IFACE_OFFS_WRITEBUFPOS_LOW
+ ldd xh, Y+UART_HW_IFACE_OFFS_WRITEBUFPOS_HIGH
ld r16, X+ ; r16=byte to write
- std Y+UART_HW_IFACE_OFFS_WRITEBUFPOSLOW, xl
- std Y+UART_HW_IFACE_OFFS_WRITEBUFPOSHIGH, xh
+ std Y+UART_HW_IFACE_OFFS_WRITEBUFPOS_LOW, xl
+ std Y+UART_HW_IFACE_OFFS_WRITEBUFPOS_HIGH, xh
dec r17
std Y+UART_HW_IFACE_OFFS_WRITEBUFLEFT, r17
; send byte, reset write timer
sts UDR@0, r16
clr r16
- std Y+UART_HW_IFACE_OFFS_WRITETIMER, r16 ; reset write timer
+ std Y+NET_IFACE_OFFS_WRITETIMER, r16 ; reset write timer
; still bytes left to write?
tst r17
@@ -234,7 +234,7 @@ l_end_%:
; the data register is empty.
;
; @param %0 UART number ("0" for UART0)
-; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_MODE)
+; @param Y pointer to interface data in SRAM
; @clobbers R16
.macro M_UART_HW_Uart_TxCharIsr
diff --git a/avr/modules/uart_hw/msglevel_recv.asm b/avr/modules/uart_hw/msglevel_recv.asm
deleted file mode 100644
index a35c0bb..0000000
--- a/avr/modules/uart_hw/msglevel_recv.asm
+++ /dev/null
@@ -1,241 +0,0 @@
-; ***************************************************************************
-; 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. *
-; ***************************************************************************
-
-
-.cseg
-
-; ---------------------------------------------------------------------------
-; @routine UART_HW_Interface_RunRead
-;
-; This routine reads bytes from the ringbuffer of the given
-; interface and parses them into messages.
-; If a valid message is received it will be added to the system's
-; incoming message ringbuffer.
-;
-; @param Y pointer to start of interface data
-; @clobbers R16, R20 (R17, R18, R18, R19, R20, R21, X)
-
-UART_HW_Interface_RunRead:
- ldd r16, Y+UART_HW_IFACE_OFFS_READMSG_BUFNUM
- cpi r16, 0xff
- brne UART_HW_Interface_RunRead_HaveBuffer
- rcall uartHwAllocateReadBuffer ; (r16, R17, X)
- brcc UART_HW_Interface_RunRead_ovrError
- rcall uartHwReadSetBuffer ; (r16)
-UART_HW_Interface_RunRead_HaveBuffer:
- ldd r16, Y+UART_HW_IFACE_OFFS_READMSG_LEFT
- tst r16
- brne UART_HW_Interface_RunRead_HaveHeader
- ldd r16, Y+UART_HW_IFACE_OFFS_READMSG_USED
- ldi r20, 2
- sub r20, r16
- rcall uartHwReadUptoNumBytes ; (r16, r17, r20, r21, X)
- tst r20
- brne UART_HW_Interface_RunRead_end
- ldd xl, Y+UART_HW_IFACE_OFFS_READMSG_PTR
- ldd xh, Y+UART_HW_IFACE_OFFS_READMSG_PTR+1
- sbiw xh:xl, 1
- ld r16, X ; msg len
- cpi r16, UART_HW_FIXEDBUFFERS_SIZE-4 ; minus buffer status byte, dest addr, msglen, crc
- brcc UART_HW_Interface_RunRead_dataError ; invalid msg
- inc r16
- std Y+UART_HW_IFACE_OFFS_READMSG_LEFT, r16
-UART_HW_Interface_RunRead_HaveHeader:
- ldd r20, Y+UART_HW_IFACE_OFFS_READMSG_LEFT
- tst r20
- breq UART_HW_Interface_RunRead_HaveMsg
- rcall uartHwReadUptoNumBytes ; (r16, r17, r20, r21, X)
- tst r20
- brne UART_HW_Interface_RunRead_end ; not all bytes received, done for now
-UART_HW_Interface_RunRead_HaveMsg:
- ldd xl, Y+UART_HW_IFACE_OFFS_READMSG_PTR
- ldd xh, Y+UART_HW_IFACE_OFFS_READMSG_PTR+1
- ldd r16, Y+UART_HW_IFACE_OFFS_READMSG_USED
- sub xl, r16 ; X-=r16
- sbc xh, r16
- add xh, r16
- rcall com2CheckMessageInBuffer ; (R16, R17, R18, R19, R20, X)
- brcc UART_HW_Interface_RunRead_dataError
- ldd r16, Y+UART_HW_IFACE_OFFS_READMSG_BUFNUM
- rcall UART_HW_AddIncomingMsgNum ; (R17, R18, X)
- brcc UART_HW_Interface_RunRead_ovrError
- ldi r16, 0xff
- std Y+UART_HW_IFACE_OFFS_READMSG_BUFNUM, r16
- rjmp UART_HW_Interface_RunRead_end
-UART_HW_Interface_RunRead_ovrError:
- rcall uartHwIncOvrCounter ; (R16)
- rcall uartHwReadResetBuffer ; (R16, X)
- rjmp UART_HW_Interface_RunRead_end
-UART_HW_Interface_RunRead_dataError:
- rcall uartHwIncContentCounter ; (R16)
- rcall uartHwResetBufferStartSkipping ; (R16, X)
-UART_HW_Interface_RunRead_end:
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine uartHwReadSetBuffer
-;
-; @param Y pointer to start of interface data
-; @param X pointer to start of buffer
-; @param r16 buffer number
-; @clobbers r16
-
-uartHwReadSetBuffer:
- std Y+UART_HW_IFACE_OFFS_READMSG_BUFNUM, r16 ; set buffer data
- adiw xh:xl, 1
- std Y+UART_HW_IFACE_OFFS_READMSG_PTR, xl
- std Y+UART_HW_IFACE_OFFS_READMSG_PTR+1, xh
- sbiw xh:xl, 1
- clr r16
- std Y+UART_HW_IFACE_OFFS_READMSG_USED, r16
- std Y+UART_HW_IFACE_OFFS_READMSG_LEFT, r16
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine uartHwReadResetBuffer
-;
-; @param Y pointer to start of interface data
-; @clobbers r16, X
-
-uartHwReadResetBuffer:
- ; reset READ buffer settings
- ldd r16, Y+UART_HW_IFACE_OFFS_READMSG_BUFNUM
- cpi r16, 0xff
- brne uartHwReadResetBuffer_haveBuffer
- ret
-uartHwReadResetBuffer_haveBuffer:
- rcall UART_HW_FixedBuffers_Locate ; (X)
- ldd r16, Y+UART_HW_IFACE_OFFS_READMSG_BUFNUM
- rjmp uartHwReadSetBuffer ; (r16)
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine uartHwResetBufferStartSkipping
-;
-; @param Y pointer to start of interface data
-; @clobbers r16 (X)
-
-uartHwResetBufferStartSkipping:
- ; reset READ buffer settings, enter skip mode
- rcall uartHwReadResetBuffer ; (R16, X)
- ldd r16, Y+UART_HW_IFACE_OFFS_MODE
- ori r16, UART_HW_MODE_SKIPPING
- std Y+UART_HW_IFACE_OFFS_MODE, r16
- ret
-; @end
-
-
-
-; ---------------------------------------------------------------------------
-; @routine uartHwAllocateReadBuffer
-;
-; @return CFLAG set if buffer set, cleared otherwise
-; @param Y pointer to start of interface data
-; @clobbers r16, R17 (X)
-
-uartHwAllocateReadBuffer:
- rcall UART_HW_FixedBuffers_Alloc ; (R16, R17, X)
- brcc uartHwAllocateReadBuffer_end
- std Y+UART_HW_IFACE_OFFS_READMSG_BUFNUM, r16
- ldd r17, Y+UART_HW_IFACE_OFFS_IFACENUM
- ori r17, (1<