avr: more work on t03 and hw uart modules.

Too complicated, will start new...
This commit is contained in:
Martin Preuss
2025-02-10 23:36:52 +01:00
parent 358ceaaa7d
commit 0790ac0dea
6 changed files with 165 additions and 347 deletions

View File

@@ -24,6 +24,8 @@
;.equ clock=1000000 ; Define the clock frequency
.equ clock=8000000 ; Define the clock frequency
; .equ SEND_DEVICE_EVERY = 3000
.equ SEND_DEVICE_EVERY = 100 ; every 10s
.nolist
@@ -86,7 +88,7 @@
; ---------------------------------------------------------------------------
; Reset and interrupt vectors (will be removed as soon as we can flash data over COM)
; Reset and interrupt vectors
rjmp BOOTLOADER_ADDR ; 1: RESET Reset vector use this for flashed system
reti ; 2: INT0 External Interrupt Request 0
@@ -114,9 +116,9 @@
reti ; 24: USART0_DRE USART0 Data Register Empty
reti ; 25: USART0_TXC USART0 Tx Complete
reti ; 26: USART1_RXS USART1 Rx Start
reti ; 27: USART1_RXC USART1 Rx Complete
reti ; 28: USART1_DRE USART1 Data Register Empty
reti ; 29: USART1_TXC USART1 Tx Complete
rjmp TtyOnUart1_RxCharIsr ; 27: USART1_RXC USART1 Rx Complete
rjmp TtyOnUart1_TxUdreIsr ; 28: USART1_DRE USART1 Data Register Empty
rjmp TtyOnUart1_TxCharIsr ; 29: USART1_TXC USART1 Tx Complete
reti ; 30: TWI Two-Wire-Interface
reti ; 31: RESERVED reserved
@@ -145,8 +147,10 @@ firmwareStart:
rcall initHardware
; rcall watchdogOff ; turn off watchdog timer (sometimes it stays on after reboot)
rcall initModules
rcall Utils_Init
rcall Utils_SetupUid
rcall initModules
sbi LED_SIMPLE_DDR, LED_SIMPLE_PINNUM ; out
sbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; off
@@ -197,7 +201,7 @@ onSystemTimerTick:
#ifdef MODULES_LED_SIMPLE
rcall LedSimple_Every100ms
#endif
rcall maybeSendDeviceMsg
rcall TtyOnUart1_Periodically
ret
@@ -227,11 +231,15 @@ initHardware:
initModules:
rcall Utils_Init
rcall BaseTimer_Init
rcall LedSimple_Init
rcall UART_HW_Init
rcall TtyOnUart1_Init
ldi r16, LOW(SEND_DEVICE_EVERY)
sts deviceCounter, r16
ldi r16, HIGH(SEND_DEVICE_EVERY)
sts deviceCounter+1, r16
ret
; @end
@@ -256,6 +264,7 @@ initModules:
.include "modules/led_simple/main.asm"
.include "modules/com2/defs.asm"
.include "modules/com2/crc.asm"
.include "modules/comproto/defs.asm"
.include "modules/uart_hw/defs.asm"
.include "modules/uart_hw/buffers.asm"
.include "modules/uart_hw/lowlevel.asm"
@@ -267,6 +276,136 @@ initModules:
maybeSendDeviceMsg:
ldi yl, LOW(ttyOnUart1_iface)
ldi yh, HIGH(ttyOnUart1_iface)
lds r24, deviceCounter
lds r25, deviceCounter+1
sbiw r25:r24, 1
brne maybeSendDeviceMsg_storeCounter
; send device msg
rcall UART_HW_FixedBuffers_Alloc
brcc maybeSendDeviceMsg_resetCounter
push r16
adiw xh:xl, 1
rcall writeDeviceMsg
pop r16
rcall UART_HW_InterfaceAddOutgoingMsgNum
; reset counter
maybeSendDeviceMsg_resetCounter:
ldi r24, LOW(SEND_DEVICE_EVERY)
ldi r25, HIGH(SEND_DEVICE_EVERY)
maybeSendDeviceMsg_storeCounter:
sts deviceCounter, r24
sts deviceCounter+1, r25
ret
writeDeviceMsg:
ldi r16, 0xff
st X+, r16 ; dest address
ldi r16, 18 ; msg code+src address+12 payload bytes
st X+, r16 ; msg len
ldi r16, CPRO_CMD_DEVICE
st X+, r16 ; msg code
clr r16
st X+, r16 ; src address
rcall addUidToBuffer ; (r16, r18, r19, r20, r21)
ldi zh, HIGH(devInfoBlock*2) ; 6-17: devInfoBlock
ldi zl, LOW(devInfoBlock*2)
ldi r18, 12
rcall Utils_CopyFromFlash ; (R17, R18, X, Y)
sbiw xh:xl, 20 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload)
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, R20, X)
sbiw xh:xl, 21 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload, 1 byte crc)
ret
addUidToBuffer:
push xh
push xl
rcall Utils_ReadUid ; (R16, X)
pop xl
pop xh
st X+, r18
st X+, r19
st X+, r20
st X+, r21
ret
DEBUG1:
ldi r19, 10
ldi r20, 2
ldi r21, 8
rcall blinkLed
rjmp DEBUG1
DEBUG2:
ldi r19, 50
ldi r20, 1
ldi r21, 1
rcall blinkLed
rjmp DEBUG2
; @param r19 loop count
; @param r20 on time
; @param r21 off time
; @clobbers (R16, R18, R22, R24, R25)
blinkLed:
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
mov r22, r20
rcall waitForMultiple100ms ; (R252
sbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; off
mov r22, r21
rcall waitForMultiple100ms ; (R22)
dec r19
brne blinkLed
ret
; @param r22 number of 100ms periods to wait
waitForMultiple100ms:
waitForMultiple100ms_loop:
push r22
rcall waitFor100ms
pop r22
dec r22
brne waitForMultiple100ms_loop
ret
waitFor100ms:
ldi r22, 10
waitFor100ms_loop:
push r22
rcall waitFor10ms
pop r22
dec r22
brne waitFor100ms_loop
ret
waitFor10ms:
ldi r22, 100
waitFor10ms_loop:
push r22
rcall Utils_WaitFor100MicroSecs
pop r22
dec r22
brne waitFor10ms_loop
ret
; ***************************************************************************
; data in SRAM
@@ -275,18 +414,8 @@ initModules:
programRamBegin:
; nothing for now
flashUid: .byte 4
deviceCounter: .byte 2
programRamEnd:
; macro test: can we use parameters for names? -> yes, we can ;-)
.macro m_testMacro
testname@0:
rjmp testname@0
.endm
macroTest:
m_testMacro 1