avr: started working on base system vs. main system.

base system will be a base system which can be used to flash and start
the main system.
This commit is contained in:
Martin Preuss
2023-02-20 23:47:30 +01:00
parent a12d6ae133
commit 8119cba750
8 changed files with 446 additions and 363 deletions

View File

@@ -1,7 +1,7 @@
; ***************************************************************************
; Source file for temperature sensor node on AtTiny 84
; Source file for base system node on AtTiny 84
;
; This is for the full system (i.e. not the boot loader).
; This is for the maintenance system (i.e. the flash loader).
;
; All definitions and changes should go into this file.
;
@@ -11,10 +11,10 @@
; VCC 1 14 GND
; PB0 2 13 PA0
; PB1 3 12 PA1 COM-DATA
; /RESET PB3 4 11 PA2 OWI
; /RESET PB3 4 11 PA2
; KEY1 PB2 5 10 PA3 LED
; COM_ATTN PA7 6 9 PA4 TWI-SCL
; TWI-SDA PA6 7 8 PA5
; COM_ATTN PA7 6 9 PA4
; PA6 7 8 PA5
; --------
;
; ***************************************************************************
@@ -42,17 +42,24 @@
; ---------------------------------------------------------------------------
; list of modules to use
#define BASE_SYSTEM
#define WITH_FLASH
#define MODULES_TIMER
#define MODULES_COM
#define MODULES_LED
#define MODULES_TWI_MASTER
#define MODULES_LCD
#define MODULES_SI7021
;#define MODULES_LED
; #define MODULES_TWI_MASTER
; #define MODULES_LCD
; #define MODULES_SI7021
.equ VALUE_ID_TEMP1 = 0x01
.equ VALUE_ID_HUM1 = 0x02
; ---------------------------------------------------------------------------
; EEPROM positions
.equ EEPROM_OFFS_UUID = 0 ; 4 bytes (occupy total of 8 bytes for extensibility)
.equ EEPROM_OFFS_COMADDR = 8 ; 1 byte
; ---------------------------------------------------------------------------
@@ -80,8 +87,6 @@
; ---------------------------------------------------------------------------
; TWI master module
.equ LCD_TWI_ADDRESS = 0x3c
.equ TWI_DDR_SCL = DDRA
.equ TWI_PORT_SCL = PORTA
.equ TWI_PIN_SCL = PINA
@@ -94,6 +99,29 @@
; ---------------------------------------------------------------------------
; LCD module
.equ LCD_TWI_ADDRESS = 0x3c
; ---------------------------------------------------------------------------
; BMP 280
.equ BMP280_ADDR = 0x76
; ---------------------------------------------------------------------------
; SI 7021
.equ SI7021_ADDR = 0x40
; ***************************************************************************
; code segment
@@ -104,58 +132,47 @@
; ---------------------------------------------------------------------------
; Reset and interrupt vectors
rjmp PC+0x20 ; Reset vector
rjmp PC+0x20 ; EXT_INT0
rjmp PC+0x20 ; PCI0
rjmp PC+0x20 ; PCI1
rjmp PC+0x20 ; WATCHDOG
rjmp PC+0x20 ; ICP1
rjmp PC+0x20 ; OC1A
rjmp PC+0x20 ; OC1B
rjmp PC+0x20 ; OVF1
rjmp PC+0x20 ; OC0A
rjmp PC+0x20 ; OC0B
rjmp PC+0x20 ; OVF0
rjmp PC+0x20 ; ACI
rjmp PC+0x20 ; ADCC
rjmp PC+0x20 ; ERDY
rjmp PC+0x20 ; USI_STR
rjmp PC+0x20 ; USI_OVF
rjmp main ; Reset vector
reti ; EXT_INT0
rjmp comIsrPcint0 ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
reti ; OC1A
reti ; OC1B
reti ; OVF1
rjmp timerIrqOC0A ; OC0A
reti ; OC0B
reti ; OVF0
reti ; ACI
reti ; ADCC
reti ; ERDY
reti ; USI_STR
reti ; USI_OVF
.org 0x40
; ---------------------------------------------------------------------------
; Node Id (not overwritten when updating system)
nodeUid: .db 0, 0, 0, 0, 0, 0, 0, 0
.org 0x50 ; begin of maintenance system
; ---------------------------------------------------------------------------
; Reset and interrupt vectors of maintenance system
; maintenance system starts here.
maintIrqHandlerTable:
.dw main ; reset address
.dw 0 ; EXT_INT0
.dw comIsrPcint0 ; PCI0
.dw 0 ; PCI1
.dw 0 ; WATCHDOG
.dw 0 ; ICP1
.dw 0 ; OC1A
.dw 0 ; OC1B
.dw 0 ; OVF1
.dw timerIrqOC0A ; OC0A
.dw 0 ; OC0B
.dw 0 ; OVF0
.dw 0 ; ACI
.dw 0 ; ADCC
.dw 0 ; ERDY
.dw 0 ; USI_STR
.dw 0 ; USI_OVF
.org 0x20
rjmp main ; Reset vector
reti ; EXT_INT0
rjmp comIsrPcint0 ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
reti ; OC1A
reti ; OC1B
reti ; OVF1
rjmp timerIrqOC0A ; OC0A
reti ; OC0B
reti ; OVF0
reti ; ACI
reti ; ADCC
reti ; ERDY
reti ; USI_STR
reti ; USI_OVF
; ***************************************************************************
@@ -163,13 +180,9 @@ maintIrqHandlerTable:
.include "utils.asm"
.include "timer.asm"
.include "led.asm"
.include "com.asm"
.include "comproto.asm"
;.include "twimaster.asm"
;.include "lcd.asm"
;.include "bmp280.asm"
;.include "si7021.asm"
.include "flash.asm"
@@ -178,19 +191,12 @@ maintIrqHandlerTable:
.dseg
ledA3Sram: .byte LED_SRAM_SIZE
; ***************************************************************************
; data in FLASH
.cseg
ledA3Flash: .db DDRA+0x20, PORTA+0x20, PINA+0x20, (1<<PORTA3)
blinkPattern: .db 5, 5, 5, 5, 5, 10, 0xff, 0xff ; 3 short blinks, 1s pause, restart
blinkPattern2: .db 10, 20, 0xff, 0xff ; 1 long blink, 2s pause, restart
@@ -199,58 +205,36 @@ blinkPattern2: .db 10, 20, 0xff, 0xff ; 1 long blink, 2s pause, restart
; ---------------------------------------------------------------------------
; onEvery100ms
;
; Called every 100ms. Add your routine calls here.
;
; IN:
; - nothing
; OUT:
; - nothing
; USED: depending on called routines
; Called on first time run, i.e. on system start. No arguments, no results.
onSystemStart:
rcall Utils_SetupUid
ldi r16, COM_MAINTENANCE_ADDR ; use fixed address in base system, smaller code
sts comAddress, r16
; rcall CPRO_StartReclaimAddrProcedure
ret
; ---------------------------------------------------------------------------
; Called every 100ms. Add your routine calls here. No arguments, no results.
onEvery100ms:
#ifdef MODULES_LED
; ticker for LED module
ldi zl, LOW(ledA3Flash)
ldi zh, HIGH(ledA3Flash)
ldi yl, LOW(ledA3Sram)
ldi yh, HIGH(ledA3Sram)
rcall Led_Tick
#endif
; add more calls here
ret
; ---------------------------------------------------------------------------
; onEverySecond
;
; Called every second. Add your routine calls here.
;
; IN:
; - nothing
; OUT:
; - nothing
; USED: depending on called routines
; Called every second. Add your routine calls here. No arguments, no results.
onEverySecond:
rcall CPRO_OnEverySecond
ret
; ---------------------------------------------------------------------------
; onEvery10s
;
; Called every 10 seconds. Add your routine calls here.
;
; IN:
; - nothing
; OUT:
; - nothing
; USED: depending on called routines
; Called every 10 seconds. Add your routine calls here. No arguments, no results.
onEvery10s:
ret
@@ -258,15 +242,7 @@ onEvery10s:
; ---------------------------------------------------------------------------
; onEvery30s
;
; Called every 10 seconds. Add your routine calls here.
;
; IN:
; - nothing
; OUT:
; - nothing
; USED: depending on called routines
; Called every 30 seconds. Add your routine calls here. No arguments, no results.
onEvery30s:
ret
@@ -274,24 +250,49 @@ onEvery30s:
; ---------------------------------------------------------------------------
; onEveryMinute
;
; Called every minute. Add your routine calls here.
;
; IN:
; - nothing
; OUT:
; - nothing
; USED: depending on called routines
; Called every minute. Add your routine calls here. No arguments, no results.
onEveryMinute:
in r15, SREG ; debug
cli
push r15
ldi r16, 219
rcall CPRO_EnqueueComSendStats
pop r15
out SREG, r15
ret
; ---------------------------------------------------------------------------
; Called every 15 minutes. Add your routine calls here. No arguments, no results.
onEvery15m:
ret
; ---------------------------------------------------------------------------
; Called every 30 minutes. Add your routine calls here. No arguments, no results.
onEvery30m:
ret
; ---------------------------------------------------------------------------
; Called every hour. Add your routine calls here. No arguments, no results.
onEvery1h:
ret
; ---------------------------------------------------------------------------
; Called every 12 hours. Add your routine calls here. No arguments, no results.
onEvery12h:
ret
; ---------------------------------------------------------------------------
; Called every day. Add your routine calls here. No arguments, no results.
onEvery1d:
ret
@@ -309,7 +310,7 @@ onEveryMinute:
; USED: depending on called routines
onPacketReceived:
clc ; not handled
rcall CPRO_OnPacketReceived
ret