avr: bootloader partially works now but stops after 3 messages...
This commit is contained in:
@@ -21,8 +21,8 @@
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
.equ clock=1000000 ; Define the clock frequency
|
||||
;.equ clock=8000000 ; Define the clock frequency
|
||||
;.equ clock=1000000 ; Define the clock frequency
|
||||
.equ clock=8000000 ; Define the clock frequency
|
||||
|
||||
|
||||
|
||||
@@ -53,19 +53,19 @@
|
||||
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
|
||||
|
||||
|
||||
#define MODULES_TIMER
|
||||
#define MODULES_COM
|
||||
#define MODULES_COM_WITH_ADDR_PROTO
|
||||
;#define MODULES_TIMER
|
||||
;#define MODULES_COM
|
||||
;#define MODULES_COM_WITH_ADDR_PROTO
|
||||
;#define MODULES_LED
|
||||
#define MODULES_LED_SIMPLE
|
||||
;#define MODULES_TWI_MASTER
|
||||
;#define MODULES_LCD
|
||||
#define LCD_MINIMAL_FONT
|
||||
;#define LCD_MINIMAL_FONT
|
||||
;#define MODULES_SI7021
|
||||
#define MODULES_STATS
|
||||
;#define MODULES_STATS
|
||||
;#define MODULES_CNY70
|
||||
;#define MODULES_REED
|
||||
#define MODULES_OWI_MASTER
|
||||
;#define MODULES_OWI_MASTER
|
||||
;#define MODULES_DS18B20
|
||||
;#define MODULES_MOTION
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
|
||||
rjmp BOOTLOADER_ADDR ; 1: RESET Reset vector use this for flashed system
|
||||
reti ; 2: INT0 External Interrupt Request 0
|
||||
rjmp uartBitbangIsrPcint0 ; 3: PCINT0 Pin Change Interrupt 0
|
||||
reti ; 3: PCINT0 Pin Change Interrupt 0
|
||||
reti ; 4: PCINT1 Pin Change Interrupt 1
|
||||
reti ; 5: WDT Watchdog Time-out
|
||||
reti ; 6: TIM1_CAPT Timer/Counter1 Capture Event
|
||||
@@ -135,75 +135,8 @@ firmwareStart: rjmp main
|
||||
.include "common/crc8.asm"
|
||||
|
||||
.include "modules/basetimer/main.asm"
|
||||
|
||||
#ifdef MODULES_TIMER
|
||||
.include "modules/timer/main.asm"
|
||||
#endif
|
||||
#ifdef MODULES_LED
|
||||
.include "modules/led/main.asm"
|
||||
#endif
|
||||
#ifdef MODULES_LED_SIMPLE
|
||||
.include "modules/led_simple/main.asm"
|
||||
#endif
|
||||
#ifdef MODULES_COM
|
||||
.include "modules/com2/defs.asm"
|
||||
.include "modules/com2/main.asm"
|
||||
.include "modules/com2/buffer.asm"
|
||||
.include "modules/uart_bitbang/defs.asm"
|
||||
.include "modules/uart_bitbang/main.asm"
|
||||
.include "modules/uart_bitbang/bytelevel.asm"
|
||||
.include "modules/uart_bitbang/packetlevel.asm"
|
||||
#ifdef MODULES_COM_WITH_ADDR_PROTO
|
||||
.include "modules/comproto/defs.asm"
|
||||
.include "modules/comproto/main.asm"
|
||||
.include "modules/comproto/addr.asm"
|
||||
.include "modules/comproto/msg_recvstats.asm"
|
||||
.include "modules/comproto/msg_sendstats.asm"
|
||||
.include "modules/comproto/msg_sysstats.asm"
|
||||
.include "modules/comproto/msg_memstats.asm"
|
||||
.include "modules/comproto/msg_pong.asm"
|
||||
.include "modules/comproto/msg_value.asm"
|
||||
.include "modules/comproto/msg_device.asm"
|
||||
.include "modules/comproto/msg_reboot.asm"
|
||||
#endif
|
||||
#ifdef MODULES_LCD
|
||||
.include "modules/com2/screen.asm"
|
||||
.include "modules/comproto/screen.asm"
|
||||
#endif
|
||||
#endif
|
||||
#ifdef MODULES_TWI_MASTER
|
||||
.include "modules/twimaster/main.asm"
|
||||
#endif
|
||||
#ifdef MODULES_OWI_MASTER
|
||||
.include "modules/owimaster/main.asm"
|
||||
#endif
|
||||
#ifdef MODULES_LCD
|
||||
.include "modules/lcd/main.asm"
|
||||
#endif
|
||||
#ifdef MODULES_SI7021
|
||||
.include "modules/si7021/main.asm"
|
||||
#endif
|
||||
#ifdef MODULES_DS18B20
|
||||
.include "modules/ds18b20/main.asm"
|
||||
#endif
|
||||
#ifdef MODULES_STATS
|
||||
.include "modules/stats/main.asm"
|
||||
#endif
|
||||
#ifdef MODULES_CNY70
|
||||
.include "modules/cny70/main.asm"
|
||||
#endif
|
||||
#ifdef MODULES_REED
|
||||
.include "modules/reed/main.asm"
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_MOTION
|
||||
.include "modules/motion/main.asm"
|
||||
#endif
|
||||
|
||||
; test
|
||||
;#include "modules/uart_irq/defs.asm"
|
||||
;#include "modules/uart_irq/iface.asm"
|
||||
;#include "modules/uart_irq/iface1.asm"
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
@@ -212,250 +145,95 @@ firmwareStart: rjmp main
|
||||
.dseg
|
||||
|
||||
programRamBegin:
|
||||
#ifdef MODULES_LCD
|
||||
screenCounter: .byte 1
|
||||
#endif
|
||||
|
||||
; nothing for now
|
||||
programRamEnd:
|
||||
|
||||
|
||||
|
||||
#ifdef MODULES_LCD
|
||||
sramTimerWriteStats: .byte 2
|
||||
sramTimerScreen: .byte 2
|
||||
#endif
|
||||
#ifdef MODULES_SI7021
|
||||
sramTimerSI7021Measure: .byte 2
|
||||
sramTimerSI7021SendTemp: .byte 2
|
||||
sramTimerSI7021SendHumidity: .byte 2
|
||||
#endif
|
||||
#ifdef MODULES_CNY70
|
||||
sramTimerCny70SendAdc: .byte 2
|
||||
#endif
|
||||
#ifdef MODULES_LCD
|
||||
sramPeriodicalLcdMark: .byte 2
|
||||
#endif
|
||||
#ifdef MODULES_DS18B20
|
||||
sramDs18b20Timer: .byte 2
|
||||
sramSendDs18b20TempTimer: .byte 2
|
||||
#endif
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; data in FLASH
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
main:
|
||||
cli
|
||||
; setup stack
|
||||
.ifdef SPH ; if SPH is defined
|
||||
ldi r16, High(RAMEND)
|
||||
out SPH, r16 ; init MSB stack pointer
|
||||
.endif
|
||||
ldi r16, Low(RAMEND)
|
||||
out SPL, r16 ; init LSB stack pointer
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; timer list
|
||||
; start by setting all ports as inputs and enable internal pull-up resistors
|
||||
ldi r16, 0xff
|
||||
clr r17
|
||||
.ifdef PORTA
|
||||
out DDRA, r17 ; all input
|
||||
out PORTA, r16 ; enable pull-up on all
|
||||
.endif
|
||||
|
||||
.ifdef PORTB
|
||||
out DDRB, r17 ; all input
|
||||
out PORTB, r16 ; enable pull-up on all
|
||||
.endif
|
||||
|
||||
timerList:
|
||||
; SRAM variable/counter routine flags secs (0=don't start or restart)
|
||||
#ifdef MODULES_COM_WITH_ADDR_PROTO
|
||||
.dw cproAddresModeTimer, CPRO_Address_OnTimer, 0, 0 ; (no restart)
|
||||
#endif
|
||||
#ifdef MODULES_STATS
|
||||
.dw statsSendTimer, Stats_Timer, TIMER_FLAGS_IF_ADDR, 9000 ; every 15m
|
||||
#endif
|
||||
#ifdef MODULES_LCD
|
||||
; .dw sramPeriodicalLcdMark, periodicalLcdMark, 0, 20 ; every 2s
|
||||
; .dw sramTimerWriteStats, writeStats, 0, 100
|
||||
.dw sramTimerScreen, printScreen, TIMER_FLAGS_IF_ADDR, 50 ; every 5s
|
||||
#endif
|
||||
#ifdef MODULES_SI7021
|
||||
.dw sramTimerSI7021Measure, SI7021_OnTimer, 0, 300 ; every 30s
|
||||
.dw sramTimerSI7021SendTemp, sendSI7021Temp, TIMER_FLAGS_IF_ADDR, 600 ; every 60s
|
||||
.dw sramTimerSI7021SendHumidity, sendSI7021Humidity, TIMER_FLAGS_IF_ADDR, 600 ; every 60s
|
||||
#endif
|
||||
#ifdef MODULES_CNY70
|
||||
.dw sramTimerCny70SendAdc, CNY70_OnTimer, TIMER_FLAGS_IF_ADDR, 50 ; every 5s
|
||||
#endif
|
||||
#ifdef MODULES_DS18B20
|
||||
.dw sramDs18b20Timer, Ds18b20_OnTimer, 0, 300 ; every 30s
|
||||
.dw sramSendDs18b20TempTimer, sendDs18b20Temp, TIMER_FLAGS_IF_ADDR, 600 ; every 60s
|
||||
#endif
|
||||
.dw 0 ; end of list
|
||||
.ifdef PORTC
|
||||
out DDRC, r17 ; all input
|
||||
out PORTC, r16 ; enable pull-up on all
|
||||
.endif
|
||||
|
||||
rcall systemSetSpeed
|
||||
; rcall watchdogOff ; turn off watchdog timer (sometimes it stays on after reboot)
|
||||
|
||||
rcall Utils_SetupUid
|
||||
|
||||
rcall LedSimple_Init
|
||||
|
||||
sei
|
||||
main_loop:
|
||||
; do something
|
||||
|
||||
; only modify SE, SM1 and SM0
|
||||
cli
|
||||
in r16, MCUCR
|
||||
ldi r17, (1<<SE) | (1<<SM1) | (1<<SM0)
|
||||
neg r17
|
||||
and r16, r17
|
||||
ori r16, (1<<SE) ; sleep mode "idle", enable
|
||||
out MCUCR, r16
|
||||
sei ; make sure interrupts really are enabled
|
||||
sleep ; sleep, wait for interrupt
|
||||
rjmp main_loop
|
||||
|
||||
.include "main_all.asm"
|
||||
|
||||
|
||||
|
||||
systemSetSpeed:
|
||||
.if clock == 1000000
|
||||
ldi r17, 0xd8
|
||||
ldi r16, (1<<CLKPS1) | (1<<CLKPS0) ; SUT=0, CLKPS=0011b
|
||||
sts CCP, r17
|
||||
sts CLKPR, r16
|
||||
.endif
|
||||
|
||||
.if clock == 8000000
|
||||
ldi r16, (1<<CLKPCE)
|
||||
ldi r17, 0
|
||||
out CLKPR, r16
|
||||
out CLKPR, r17
|
||||
ldi r17, 0xd8
|
||||
clr r16 ; SUT=0, CLKPS=0
|
||||
sts CCP, r17
|
||||
sts CLKPR, r16
|
||||
.endif
|
||||
ret
|
||||
|
||||
|
||||
systemSetBootSpeed:
|
||||
.if clock == 8000000
|
||||
ldi r16, (1<<CLKPCE)
|
||||
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
|
||||
out CLKPR, r16
|
||||
out CLKPR, r17
|
||||
.endif
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Called on first time run, i.e. on system start. No arguments, no results.
|
||||
|
||||
onSystemStart:
|
||||
ldi xh, HIGH(programRamBegin)
|
||||
ldi xl, LOW(programRamBegin)
|
||||
clr r16
|
||||
ldi r17, (programRamEnd-programRamBegin)
|
||||
rcall Utils_FillSram
|
||||
ret
|
||||
|
||||
|
||||
#ifdef MODULES_LCD
|
||||
|
||||
printScreen:
|
||||
lds r16, screenCounter
|
||||
tst r16
|
||||
brne printScreen_l1
|
||||
rcall CPRO_Screen
|
||||
rjmp printScreen_counter
|
||||
printScreen_l1:
|
||||
cpi r16, 1
|
||||
brne printScreen_l2
|
||||
rcall COM2_Screen_RecvStats
|
||||
rjmp printScreen_counter
|
||||
printScreen_l2:
|
||||
; cpi r16, 2
|
||||
; brne printScreen_l3
|
||||
; rcall COM2_Screen_SendStats
|
||||
; rjmp printScreen_counter
|
||||
printScreen_l3:
|
||||
; add more screens here
|
||||
|
||||
printScreen_counter:
|
||||
lds r16, screenCounter
|
||||
inc r16
|
||||
cpi r16, 2 ; number of screens
|
||||
brcs printScreen_store
|
||||
clr r16
|
||||
printScreen_store:
|
||||
sts screenCounter, r16
|
||||
printScreen_end:
|
||||
ret
|
||||
|
||||
|
||||
;periodicalLcdMark:
|
||||
; rcall printTimerMark
|
||||
; ret
|
||||
|
||||
|
||||
;writeStats:
|
||||
; rcall printSendStats
|
||||
; ret
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef MODULES_SI7021
|
||||
|
||||
sendSI7021Humidity:
|
||||
rcall SI7021_SendHumidity
|
||||
brcs sendSI7021Humidity_okay
|
||||
; set timer to 1s to retry later
|
||||
ldi xl, LOW(sramTimerSI7021SendHumidity)
|
||||
ldi xh, HIGH(sramTimerSI7021SendHumidity)
|
||||
rjmp Timer_SetValueTo1s
|
||||
sendSI7021Humidity_okay:
|
||||
ret
|
||||
|
||||
|
||||
sendSI7021Temp:
|
||||
rcall SI7021_SendTemp
|
||||
brcs sendSI7021Temp_okay
|
||||
; set timer to 1s to retry later
|
||||
ldi xl, LOW(sramTimerSI7021SendTemp)
|
||||
ldi xh, HIGH(sramTimerSI7021SendTemp)
|
||||
rjmp Timer_SetValueTo1s
|
||||
sendSI7021Temp_okay:
|
||||
ret
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef MODULES_DS18B20
|
||||
sendDs18b20Temp:
|
||||
rcall Ds18b20_SendTemp
|
||||
brcs sendDs18b20Temp_okay
|
||||
; set timer to 1s to retry later
|
||||
ldi xl, LOW(sramSendDs18b20TempTimer)
|
||||
ldi xh, HIGH(sramSendDs18b20TempTimer)
|
||||
rjmp Timer_SetValueTo1s
|
||||
sendDs18b20Temp_okay:
|
||||
ret
|
||||
#endif
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Called every 100ms. Add your routine calls here. No arguments, no results.
|
||||
|
||||
onEvery100ms:
|
||||
onSystemTimerTick:
|
||||
#ifdef MODULES_LED_SIMPLE
|
||||
rcall LedSimple_Every100ms
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_REED
|
||||
rcall REED_Every100ms
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_MOTION
|
||||
rcall Motion_Every100ms
|
||||
#endif
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine onPacketReceived:
|
||||
;
|
||||
; Called after a packet was received via COM module. Add your routine calls here.
|
||||
;
|
||||
; The packet will be released in any case after return from this call.
|
||||
;
|
||||
; @return CFLAG set if message handled, cleared otherwise
|
||||
; @param X pointer to received buffer
|
||||
; @clobbers all
|
||||
|
||||
onPacketReceived:
|
||||
#ifdef MODULES_MOTION_LIGHT
|
||||
rcall MotionLight_OnPacketReceived
|
||||
brcs onPacketReceived_end
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_SK6812
|
||||
rcall SK6812_OnPacketReceived
|
||||
brcs onPacketReceived_end
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_REED
|
||||
rcall REED_OnPacketReceived
|
||||
brcs onPacketReceived_end
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_COM
|
||||
rcall CPRO_OnPacketReceived
|
||||
brcs onPacketReceived_end
|
||||
#endif
|
||||
|
||||
clc
|
||||
onPacketReceived_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user