avr: added devices, more work on modules.
This commit is contained in:
@@ -9,6 +9,11 @@
|
|||||||
n12
|
n12
|
||||||
n14
|
n14
|
||||||
n15
|
n15
|
||||||
|
n16
|
||||||
|
n17
|
||||||
|
n18
|
||||||
|
r02
|
||||||
|
x03
|
||||||
</subdirs>
|
</subdirs>
|
||||||
|
|
||||||
</gwbuild>
|
</gwbuild>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
.list
|
.list
|
||||||
|
|
||||||
.include "n00_defs.asm"
|
.include "n00_defs.asm"
|
||||||
.include "defs.asm"
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
.list
|
.list
|
||||||
|
|
||||||
.include "n00_defs.asm"
|
.include "n00_defs.asm"
|
||||||
.include "defs.asm"
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ timerList:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
.include "main.asm"
|
.include "main_all.asm"
|
||||||
|
|
||||||
|
|
||||||
systemSetSpeed:
|
systemSetSpeed:
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
.list
|
.list
|
||||||
|
|
||||||
.include "n06_defs.asm"
|
.include "n06_defs.asm"
|
||||||
.include "defs.asm"
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
.list
|
.list
|
||||||
|
|
||||||
.include "n06_defs.asm"
|
.include "n06_defs.asm"
|
||||||
.include "defs.asm"
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ timerList:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
.include "main.asm"
|
.include "main_all.asm"
|
||||||
|
|
||||||
|
|
||||||
systemSetSpeed:
|
systemSetSpeed:
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
.list
|
.list
|
||||||
|
|
||||||
.include "n11_defs.asm"
|
.include "n11_defs.asm"
|
||||||
.include "defs.asm"
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -49,14 +49,11 @@
|
|||||||
.equ COM_BIT_LENGTH = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400
|
.equ COM_BIT_LENGTH = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400
|
||||||
.equ COM_HALFBIT_LENGTH = 26000 ; see https://de.wikipedia.org/wiki/Universal_Asynchronous_Receiver_Transmitter
|
.equ COM_HALFBIT_LENGTH = 26000 ; see https://de.wikipedia.org/wiki/Universal_Asynchronous_Receiver_Transmitter
|
||||||
|
|
||||||
.equ COM_TXD_DDR = DDRA
|
|
||||||
.equ COM_TXD_DATA = PORTA
|
|
||||||
.equ COM_TXD_PIN = PORTA1
|
|
||||||
|
|
||||||
.equ COM_RXD_DDR = DDRA
|
.equ COM_DATA_DDR = DDRA
|
||||||
.equ COM_RXD_INPUT = PINA
|
.equ COM_DATA_INPUT = PINA
|
||||||
.equ COM_RXD_OUTPUT = PORTA
|
.equ COM_DATA_OUTPUT = PORTA
|
||||||
.equ COM_RXD_PIN = PORTA1
|
.equ COM_DATA_PIN = PORTA1
|
||||||
|
|
||||||
.equ COM_ATTN_DDR = DDRA
|
.equ COM_ATTN_DDR = DDRA
|
||||||
.equ COM_ATTN_INPUT = PINA
|
.equ COM_ATTN_INPUT = PINA
|
||||||
@@ -74,7 +71,7 @@
|
|||||||
; TWI master module
|
; TWI master module
|
||||||
|
|
||||||
;.equ TWI_BIT_LENGTH = 10000 ; 100000 and 200000 works for display: 10000, 100000, 200000
|
;.equ TWI_BIT_LENGTH = 10000 ; 100000 and 200000 works for display: 10000, 100000, 200000
|
||||||
.equ TWI_BIT_LENGTH = 1 ; 10, 100, 500, 100000 and 200000 works for display: 10000, 100000, 200000
|
.equ TWI_BIT_LENGTH = 10000 ; 10, 100, 500, 100000 and 200000 works for display: 10000, 100000, 200000
|
||||||
|
|
||||||
.equ TWI_DDR_SCL = DDRA
|
.equ TWI_DDR_SCL = DDRA
|
||||||
.equ TWI_PORT_SCL = PORTA
|
.equ TWI_PORT_SCL = PORTA
|
||||||
@@ -162,3 +159,10 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; CCS 811
|
||||||
|
;
|
||||||
|
|
||||||
|
.equ CCS811_ADDR = 0x5a ; or 0x5b
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
.list
|
.list
|
||||||
|
|
||||||
.include "n11_defs.asm"
|
.include "n11_defs.asm"
|
||||||
.include "defs.asm"
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -64,9 +64,10 @@
|
|||||||
#define MODULES_SI7021
|
#define MODULES_SI7021
|
||||||
#define MODULES_STATS
|
#define MODULES_STATS
|
||||||
;#define MODULES_CNY70
|
;#define MODULES_CNY70
|
||||||
#define MODULES_REED
|
;#define MODULES_REED
|
||||||
;#define MODULES_OWI_MASTER
|
;#define MODULES_OWI_MASTER
|
||||||
;#define MODULES_DS18B20
|
;#define MODULES_DS18B20
|
||||||
|
#define MODULES_CCS811
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
@@ -80,6 +81,11 @@
|
|||||||
.equ VALUE_ID_REED2 = 0x05
|
.equ VALUE_ID_REED2 = 0x05
|
||||||
.equ VALUE_ID_DS18B20_TEMP = 0x06
|
.equ VALUE_ID_DS18B20_TEMP = 0x06
|
||||||
|
|
||||||
|
.equ VALUE_ID_CO2 = 0x07
|
||||||
|
.equ VALUE_ID_TVOC = 0x08
|
||||||
|
|
||||||
|
.equ VALUE_ID_DEBUG = 0x7f
|
||||||
|
|
||||||
.equ VALUE_ID_REED_CONF = 0x81
|
.equ VALUE_ID_REED_CONF = 0x81
|
||||||
|
|
||||||
|
|
||||||
@@ -196,6 +202,10 @@ firmwareStart: rjmp main
|
|||||||
.include "modules/reed/main.asm"
|
.include "modules/reed/main.asm"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_CCS811
|
||||||
|
.include "modules/ccs811/main.asm"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
; ***************************************************************************
|
||||||
@@ -233,6 +243,10 @@ sramTimerEnqueueValues: .byte 2
|
|||||||
sramSendDs18b20TempTimer: .byte 2
|
sramSendDs18b20TempTimer: .byte 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_CCS811
|
||||||
|
sramCcs811Timer: .byte 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
; ***************************************************************************
|
||||||
; data in FLASH
|
; data in FLASH
|
||||||
@@ -269,6 +283,9 @@ timerList:
|
|||||||
#ifdef MODULES_DS18B20
|
#ifdef MODULES_DS18B20
|
||||||
.dw sramDs18b20Timer, Ds18b20_OnTimer, 0, 300 ; every 30s
|
.dw sramDs18b20Timer, Ds18b20_OnTimer, 0, 300 ; every 30s
|
||||||
.dw sramSendDs18b20TempTimer, sendDs18b20Temp, TIMER_FLAGS_IF_ADDR, 600 ; every 60s
|
.dw sramSendDs18b20TempTimer, sendDs18b20Temp, TIMER_FLAGS_IF_ADDR, 600 ; every 60s
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_CCS811
|
||||||
|
.dw sramCcs811Timer, CCS811_OnTimer, 0, 10 ; every 1s
|
||||||
#endif
|
#endif
|
||||||
.dw 0 ; end of list
|
.dw 0 ; end of list
|
||||||
|
|
||||||
@@ -276,7 +293,7 @@ timerList:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
.include "main.asm"
|
.include "main_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -313,6 +330,28 @@ onSystemStart:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MODULES_CCS811
|
||||||
|
handleCcsTimer:
|
||||||
|
rjmp sendCcs811Data
|
||||||
|
|
||||||
|
|
||||||
|
sendCcs811Data:
|
||||||
|
ldi r16, 0xff ; destination address
|
||||||
|
ldi r17, VALUE_ID_DEBUG ; value id
|
||||||
|
ldi r22, 0
|
||||||
|
; lds r18, ccs811ResponseData ; value
|
||||||
|
lds r18, ccs811Flags ; value
|
||||||
|
lds r19, ccs811ResponseData ; denominator
|
||||||
|
ldi r20, 1
|
||||||
|
clr r21
|
||||||
|
|
||||||
|
ldi xl, LOW(com2SendBuffer)
|
||||||
|
ldi xh, HIGH(com2SendBuffer)
|
||||||
|
rcall CPRO_WriteReportValue
|
||||||
|
rjmp COM2_SendPacket
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef MODULES_LCD
|
#ifdef MODULES_LCD
|
||||||
|
|
||||||
printScreen:
|
printScreen:
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
.list
|
.list
|
||||||
|
|
||||||
.include "n12_defs.asm"
|
.include "n12_defs.asm"
|
||||||
.include "defs.asm"
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,8 @@
|
|||||||
.list
|
.list
|
||||||
|
|
||||||
.include "n12_defs.asm"
|
.include "n12_defs.asm"
|
||||||
.include "defs.asm"
|
.include "defs_all.asm"
|
||||||
|
|
||||||
.include "common/utils_wait.asm" ; wait macro
|
.include "common/utils_wait.asm" ; wait macro
|
||||||
|
|
||||||
|
|
||||||
@@ -259,7 +260,7 @@ timerList:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
.include "main.asm"
|
.include "main_all.asm"
|
||||||
|
|
||||||
|
|
||||||
systemSetSpeed:
|
systemSetSpeed:
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
.list
|
.list
|
||||||
|
|
||||||
.include "n14_defs.asm"
|
.include "n14_defs.asm"
|
||||||
.include "defs.asm"
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
.list
|
.list
|
||||||
|
|
||||||
.include "n14_defs.asm"
|
.include "n14_defs.asm"
|
||||||
.include "defs.asm"
|
.include "defs_all.asm"
|
||||||
.include "common/utils_wait.asm" ; wait macro
|
.include "common/utils_wait.asm" ; wait macro
|
||||||
|
|
||||||
|
|
||||||
@@ -198,7 +198,7 @@ timerList:
|
|||||||
.dw cproAddresModeTimer, CPRO_Address_OnTimer, 0, 0 ; (no restart)
|
.dw cproAddresModeTimer, CPRO_Address_OnTimer, 0, 0 ; (no restart)
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODULES_STATS
|
#ifdef MODULES_STATS
|
||||||
.dw statsSendTimer, Stats_Timer, TIMER_FLAGS_IF_ADDR, 3000 ; every 5m
|
.dw statsSendTimer, Stats_Timer, TIMER_FLAGS_IF_ADDR, 9000 ; every 15m
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODULES_DS18B20
|
#ifdef MODULES_DS18B20
|
||||||
.dw sramDs18b20Timer, Ds18b20_OnTimer, 0, 300 ; every 30s
|
.dw sramDs18b20Timer, Ds18b20_OnTimer, 0, 300 ; every 30s
|
||||||
@@ -210,7 +210,7 @@ timerList:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
.include "main.asm"
|
.include "main_all.asm"
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
.list
|
.list
|
||||||
|
|
||||||
.include "n15_defs.asm"
|
.include "n15_defs.asm"
|
||||||
.include "defs.asm"
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
.list
|
.list
|
||||||
|
|
||||||
.include "n15_defs.asm"
|
.include "n15_defs.asm"
|
||||||
.include "defs.asm"
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
#define MODULES_TWI_MASTER
|
#define MODULES_TWI_MASTER
|
||||||
;#define MODULES_LCD
|
;#define MODULES_LCD
|
||||||
#define LCD_MINIMAL_FONT
|
#define LCD_MINIMAL_FONT
|
||||||
;#define MODULES_SI7021
|
#define MODULES_SI7021
|
||||||
#define MODULES_STATS
|
#define MODULES_STATS
|
||||||
;#define MODULES_CNY70
|
;#define MODULES_CNY70
|
||||||
;#define MODULES_REED
|
;#define MODULES_REED
|
||||||
@@ -259,7 +259,7 @@ timerList:
|
|||||||
.dw cproAddresModeTimer, CPRO_Address_OnTimer, 0, 0 ; (no restart)
|
.dw cproAddresModeTimer, CPRO_Address_OnTimer, 0, 0 ; (no restart)
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODULES_STATS
|
#ifdef MODULES_STATS
|
||||||
.dw statsSendTimer, Stats_Timer, TIMER_FLAGS_IF_ADDR, 3000 ; every 5m
|
.dw statsSendTimer, Stats_Timer, TIMER_FLAGS_IF_ADDR, 9000 ; every 15m
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODULES_LCD
|
#ifdef MODULES_LCD
|
||||||
; .dw sramPeriodicalLcdMark, periodicalLcdMark, 0, 20 ; every 2s
|
; .dw sramPeriodicalLcdMark, periodicalLcdMark, 0, 20 ; every 2s
|
||||||
@@ -284,7 +284,7 @@ timerList:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
.include "main.asm"
|
.include "main_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
avr/devices/n16/.gitignore
vendored
Normal file
2
avr/devices/n16/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.eep.hex
|
||||||
|
*.obj
|
||||||
52
avr/devices/n16/0BUILD
Normal file
52
avr/devices/n16/0BUILD
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml?>
|
||||||
|
|
||||||
|
<gwbuild>
|
||||||
|
|
||||||
|
<target type="AvrHexFile" name="n16_main" >
|
||||||
|
|
||||||
|
<includes type="avrasm" >
|
||||||
|
-I $(builddir)
|
||||||
|
-I $(srcdir)
|
||||||
|
-I $(topsrcdir)/avr
|
||||||
|
-I $(topbuilddir)/avr
|
||||||
|
</includes>
|
||||||
|
|
||||||
|
|
||||||
|
<sources type="avrasm" >
|
||||||
|
n16_main.asm
|
||||||
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<target type="AvrHexFile" name="n16_boot" >
|
||||||
|
|
||||||
|
<includes type="avrasm" >
|
||||||
|
-I $(builddir)
|
||||||
|
-I $(srcdir)
|
||||||
|
-I $(topsrcdir)/avr
|
||||||
|
-I $(topbuilddir)/avr
|
||||||
|
</includes>
|
||||||
|
|
||||||
|
|
||||||
|
<sources type="avrasm" >
|
||||||
|
n16_boot.asm
|
||||||
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
<subdirs>
|
||||||
|
</subdirs>
|
||||||
|
|
||||||
|
<extradist>
|
||||||
|
n16_defs.asm
|
||||||
|
</extradist>
|
||||||
|
|
||||||
|
|
||||||
|
</gwbuild>
|
||||||
|
|
||||||
|
|
||||||
162
avr/devices/n16/n16_boot.asm
Normal file
162
avr/devices/n16/n16_boot.asm
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; Source file for base system node on AtTiny 84
|
||||||
|
;
|
||||||
|
; This is for the maintenance system (i.e. the flash loader).
|
||||||
|
;
|
||||||
|
; All definitions and changes should go into this file.
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
.equ clock=1000000 ; Define the clock frequency
|
||||||
|
|
||||||
|
.nolist
|
||||||
|
.include "include/tn84def.inc" ; Define device ATtiny84
|
||||||
|
.list
|
||||||
|
|
||||||
|
.include "n16_defs.asm"
|
||||||
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; generic
|
||||||
|
|
||||||
|
.include "common/utils_wait.asm"
|
||||||
|
.include "modules/com2/defs.asm"
|
||||||
|
.include "modules/comproto/defs.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; firmware settings
|
||||||
|
|
||||||
|
.equ FIRMWARE_VERSION_MAJOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_MINOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LED
|
||||||
|
|
||||||
|
.equ LED_DDR = DDRA
|
||||||
|
.equ LED_PORT = PORTA
|
||||||
|
.equ LED_PIN = PINA
|
||||||
|
.equ LED_PINNUM = PORTA3
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code segment
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
.org 0x0000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Reset and interrupt vectors
|
||||||
|
; rjmp start ; Reset vector
|
||||||
|
rjmp main ; Reset vector
|
||||||
|
reti ; EXT_INT0
|
||||||
|
reti ; PCI0
|
||||||
|
reti ; PCI1
|
||||||
|
reti ; WATCHDOG
|
||||||
|
reti ; ICP1
|
||||||
|
reti ; OC1A
|
||||||
|
reti ; OC1B
|
||||||
|
reti ; OVF1
|
||||||
|
reti ; OC0A
|
||||||
|
reti ; OC0B
|
||||||
|
reti ; OVF0
|
||||||
|
reti ; ACI
|
||||||
|
reti ; ADCC
|
||||||
|
reti ; ERDY
|
||||||
|
reti ; USI_STR
|
||||||
|
reti ; USI_OVF
|
||||||
|
|
||||||
|
|
||||||
|
devInfoBlock: ; 12 bytes
|
||||||
|
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
|
||||||
|
devInfoId: .db 'N', 0
|
||||||
|
devInfoVersion: .db 16, 0 ; version, revision
|
||||||
|
firmwareVersion: .db FIRMWARE_VARIANT_BOOT, FIRMWARE_VERSION_MAJOR
|
||||||
|
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
|
||||||
|
|
||||||
|
firmwareStart: rjmp main ; will be overwritten when flashing
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; main code
|
||||||
|
|
||||||
|
|
||||||
|
.org BOOTLOADER_ADDR
|
||||||
|
|
||||||
|
|
||||||
|
main:
|
||||||
|
rjmp bootLoader ; this routine is in modules/flash/proto.asm
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; includes
|
||||||
|
|
||||||
|
.include "modules/uart_bitbang/bytelevel.asm"
|
||||||
|
.include "modules/uart_bitbang/packetlevel.asm"
|
||||||
|
.include "modules/com2/crc.asm"
|
||||||
|
.include "common/crc8.asm"
|
||||||
|
.include "common/utils_wait_fixed.asm"
|
||||||
|
.include "common/utils_copy_from_flash.asm"
|
||||||
|
.include "common/utils_copy_sdram.asm"
|
||||||
|
.include "modules/flash/bootloader.asm"
|
||||||
|
.include "modules/flash/flash.asm"
|
||||||
|
.include "modules/flash/recv.asm"
|
||||||
|
.include "modules/flash/send.asm"
|
||||||
|
.include "modules/flash/wait.asm"
|
||||||
|
.include "modules/flash/hdl_flash_start.asm"
|
||||||
|
.include "modules/flash/hdl_flash_data.asm"
|
||||||
|
.include "modules/flash/hdl_flash_end.asm"
|
||||||
|
.include "modules/flash/flash_rsp.asm"
|
||||||
|
.include "modules/flash/flash_ready.asm"
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
debugStop:
|
||||||
|
cli
|
||||||
|
sbi LED_SIMPLE_DDR, LED_SIMPLE_PINNUM ; out
|
||||||
|
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
|
||||||
|
|
||||||
|
cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN port as input
|
||||||
|
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable internal pullup for ATTN
|
||||||
|
|
||||||
|
ldi r18, 0
|
||||||
|
test_loop1:
|
||||||
|
ldi r16, 100
|
||||||
|
test_loop2:
|
||||||
|
ldi r17, 100
|
||||||
|
test_loop3:
|
||||||
|
Utils_WaitNanoSecs 10000, 0, r22
|
||||||
|
dec r17
|
||||||
|
brne test_loop3
|
||||||
|
dec r16
|
||||||
|
brne test_loop2
|
||||||
|
sbi LED_SIMPLE_PORTIN, LED_SIMPLE_PINNUM ; toggle
|
||||||
|
inc r18
|
||||||
|
mov r19, r18
|
||||||
|
andi r19, 1
|
||||||
|
brne test1
|
||||||
|
sbi COM_ATTN_DDR, COM_ATTN_PIN
|
||||||
|
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN
|
||||||
|
rjmp test_loop1
|
||||||
|
test1:
|
||||||
|
cbi COM_ATTN_DDR, COM_ATTN_PIN
|
||||||
|
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN
|
||||||
|
|
||||||
|
rjmp test_loop1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
187
avr/devices/n16/n16_defs.asm
Normal file
187
avr/devices/n16/n16_defs.asm
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2023 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
;
|
||||||
|
; AtTiny84
|
||||||
|
; --------
|
||||||
|
; VCC 1 14 GND
|
||||||
|
; PB0 2 13 PA0 TCRT1000_Enable
|
||||||
|
; PIR PB1 3 12 PA1 COM-DATA
|
||||||
|
; /RESET PB3 4 11 PA2 TCRT1000_Input
|
||||||
|
; PB2 5 10 PA3 LED
|
||||||
|
; COM_ATTN PA7 6 9 PA4 TWI-SCL
|
||||||
|
; TWI-SDA PA6 7 8 PA5
|
||||||
|
; --------
|
||||||
|
;
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.equ BOOTLOADER_ADDR = 0xd00
|
||||||
|
|
||||||
|
.equ FIRMWARE_VARIANT_BOOT = 0
|
||||||
|
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LED module
|
||||||
|
|
||||||
|
.equ LED_SIMPLE_ONTIME = 2
|
||||||
|
.equ LED_SIMPLE_OFFTIME = 30
|
||||||
|
.equ LED_SIMPLE_DDR = DDRA
|
||||||
|
.equ LED_SIMPLE_PORT = PORTA
|
||||||
|
.equ LED_SIMPLE_PORTIN = PINA
|
||||||
|
.equ LED_SIMPLE_PINNUM = PORTA3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; COM module
|
||||||
|
|
||||||
|
.equ COM_BIT_LENGTH = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400
|
||||||
|
.equ COM_HALFBIT_LENGTH = 26000 ; see https://de.wikipedia.org/wiki/Universal_Asynchronous_Receiver_Transmitter
|
||||||
|
|
||||||
|
.equ COM_DATA_DDR = DDRA
|
||||||
|
.equ COM_DATA_INPUT = PINA
|
||||||
|
.equ COM_DATA_OUTPUT = PORTA
|
||||||
|
.equ COM_DATA_PIN = PORTA1
|
||||||
|
|
||||||
|
.equ COM_ATTN_DDR = DDRA
|
||||||
|
.equ COM_ATTN_INPUT = PINA
|
||||||
|
.equ COM_ATTN_OUTPUT = PORTA
|
||||||
|
.equ COM_ATTN_PIN = PORTA7
|
||||||
|
|
||||||
|
.equ COM_IRQ_ADDR_ATTN = PCMSK0
|
||||||
|
.equ COM_IRQ_BIT_ATTN = PCINT7 ; bit 7 in PCMSK0
|
||||||
|
.equ COM_IRQ_GIFR_ATTN = PCIF0
|
||||||
|
.equ COM_IRQ_GIMSK_ATTN = PCIE0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; TWI master module
|
||||||
|
|
||||||
|
;.equ TWI_BIT_LENGTH = 10000 ; 100000 and 200000 works for display: 10000, 100000, 200000
|
||||||
|
.equ TWI_BIT_LENGTH = 1 ; 10, 100, 500, 100000 and 200000 works for display: 10000, 100000, 200000
|
||||||
|
|
||||||
|
.equ TWI_DDR_SCL = DDRA
|
||||||
|
.equ TWI_PORT_SCL = PORTA
|
||||||
|
.equ TWI_PIN_SCL = PINA
|
||||||
|
.equ TWI_PINNUM_SCL = PORTA4
|
||||||
|
|
||||||
|
.equ TWI_DDR_SDA = DDRA
|
||||||
|
.equ TWI_PORT_SDA = PORTA
|
||||||
|
.equ TWI_PIN_SDA = PINA
|
||||||
|
.equ TWI_PINNUM_SDA = PORTA6
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LCD module
|
||||||
|
|
||||||
|
.equ LCD_TWI_ADDRESS = 0x3c
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; BMP 280
|
||||||
|
|
||||||
|
.equ BMP280_ADDR = 0x76
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; SI 7021
|
||||||
|
|
||||||
|
.equ SI7021_ADDR = 0x40
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; ADC/CNY70
|
||||||
|
|
||||||
|
|
||||||
|
.equ CNY70_LED_PORT = PORTA
|
||||||
|
.equ CNY70_LED_DDR = DDRA
|
||||||
|
.equ CNY70_LED_PIN = PORTA0
|
||||||
|
|
||||||
|
.equ CNY70_ADC_PORT = PORTA ; adc2
|
||||||
|
.equ CNY70_ADC_DDR = DDRA
|
||||||
|
.equ CNY70_ADC_PIN = PORTA2
|
||||||
|
.equ CNY70_ADC_MUX = MUX2
|
||||||
|
.equ CNY70_ADC_ADCSRB = ADC2D
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; ADC/TCRT1K
|
||||||
|
|
||||||
|
|
||||||
|
.equ TCRT1K_LED_PORT = PORTA
|
||||||
|
.equ TCRT1K_LED_DDR = DDRA
|
||||||
|
.equ TCRT1K_LED_PIN = PORTA0
|
||||||
|
|
||||||
|
.equ TCRT1K_ADC_PORT = PORTA ; adc2
|
||||||
|
.equ TCRT1K_ADC_DDR = DDRA
|
||||||
|
.equ TCRT1K_ADC_PIN = PORTA2
|
||||||
|
.equ TCRT1K_ADC_MUX = MUX2
|
||||||
|
.equ TCRT1K_ADC_ADCSRB = ADC2D
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Reed
|
||||||
|
;
|
||||||
|
|
||||||
|
.equ REEDOUT1_DDR = DDRA
|
||||||
|
.equ REEDOUT1_PORT = PORTA
|
||||||
|
.equ REEDOUT1_PIN = PINA
|
||||||
|
.equ REEDOUT1_PINNUM = PORTA0
|
||||||
|
|
||||||
|
.equ REEDOUT2_DDR = DDRB
|
||||||
|
.equ REEDOUT2_PORT = PORTB
|
||||||
|
.equ REEDOUT2_PIN = PINB
|
||||||
|
.equ REEDOUT2_PINNUM = PORTB0
|
||||||
|
|
||||||
|
.equ REED1_DDR = DDRA
|
||||||
|
.equ REED1_PORT = PORTA
|
||||||
|
.equ REED1_PIN = PINA
|
||||||
|
.equ REED1_PINNUM = PORTA2
|
||||||
|
|
||||||
|
.equ REED2_DDR = DDRA
|
||||||
|
.equ REED2_PORT = PORTA
|
||||||
|
.equ REED2_PIN = PINA
|
||||||
|
.equ REED2_PINNUM = PORTA5
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; 1-Wire Master
|
||||||
|
;
|
||||||
|
|
||||||
|
.equ OWI_DDR = DDRB
|
||||||
|
.equ OWI_PORTOUT = PORTB
|
||||||
|
.equ OWI_PORTIN = PINB
|
||||||
|
.equ OWI_PINNUM = PORTB2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Motion Sensor
|
||||||
|
;
|
||||||
|
|
||||||
|
.equ MOTION_DDR = DDRB
|
||||||
|
.equ MOTION_INPUT = PINB
|
||||||
|
.equ MOTION_OUTPUT = PORTB
|
||||||
|
.equ MOTION_PIN = PORTB1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
476
avr/devices/n16/n16_main.asm
Normal file
476
avr/devices/n16/n16_main.asm
Normal file
@@ -0,0 +1,476 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2024 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; Source file for temperature sensor node on AtTiny 84
|
||||||
|
;
|
||||||
|
; This is for the full system (i.e. not the boot loader).
|
||||||
|
;
|
||||||
|
; All definitions and changes should go into this file.
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
.equ clock=1000000 ; Define the clock frequency
|
||||||
|
;.equ clock=8000000 ; Define the clock frequency
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.nolist
|
||||||
|
.include "include/tn84def.inc" ; Define device ATtiny84
|
||||||
|
.list
|
||||||
|
|
||||||
|
.include "n16_defs.asm"
|
||||||
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; generic
|
||||||
|
|
||||||
|
|
||||||
|
.include "common/utils_wait.asm"
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; firmware settings including list of modules used
|
||||||
|
|
||||||
|
.equ FIRMWARE_VERSION_MAJOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_MINOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
|
||||||
|
|
||||||
|
|
||||||
|
#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 MODULES_SI7021
|
||||||
|
#define MODULES_STATS
|
||||||
|
; #define MODULES_CNY70
|
||||||
|
;#define MODULES_REED
|
||||||
|
;#define MODULES_OWI_MASTER
|
||||||
|
;#define MODULES_DS18B20
|
||||||
|
#define MODULES_MOTION
|
||||||
|
#define MODULES_TCRT1000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; defines for values
|
||||||
|
|
||||||
|
.equ VALUE_ID_SI7021_TEMP = 0x01
|
||||||
|
.equ VALUE_ID_SI7021_HUM = 0x02
|
||||||
|
|
||||||
|
.equ VALUE_ID_ADC = 0x03
|
||||||
|
.equ VALUE_ID_REED1 = 0x04
|
||||||
|
.equ VALUE_ID_REED2 = 0x05
|
||||||
|
.equ VALUE_ID_DS18B20_TEMP = 0x06
|
||||||
|
.equ VALUE_ID_MOTION = 0x07
|
||||||
|
.equ VALUE_ID_TCRT1K = 0x08
|
||||||
|
|
||||||
|
.equ VALUE_ID_REED_CONF = 0x81
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code segment
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
.org 000000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Reset and interrupt vectors (will be removed as soon as we can flash data over COM)
|
||||||
|
|
||||||
|
; rjmp main ; Reset vector
|
||||||
|
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
|
||||||
|
reti ; EXT_INT0
|
||||||
|
rjmp uartBitbangIsrPcint0 ; PCI0
|
||||||
|
reti ; PCI1
|
||||||
|
reti ; WATCHDOG
|
||||||
|
reti ; ICP1
|
||||||
|
reti ; OC1A
|
||||||
|
reti ; OC1B
|
||||||
|
reti ; OVF1
|
||||||
|
rjmp baseTimerIrqOC0A ; OC0A
|
||||||
|
reti ; OC0B
|
||||||
|
reti ; OVF0
|
||||||
|
reti ; ACI
|
||||||
|
reti ; ADCC
|
||||||
|
reti ; ERDY
|
||||||
|
reti ; USI_STR
|
||||||
|
reti ; USI_OVF
|
||||||
|
|
||||||
|
|
||||||
|
devInfoBlock: ; 12 bytes
|
||||||
|
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
|
||||||
|
devInfoId: .db 'N', 0
|
||||||
|
devInfoVersion: .db 16, 0 ; version, revision
|
||||||
|
firmwareVersion: .db FIRMWARE_VARIANT_TEMP_WINDOW, FIRMWARE_VERSION_MAJOR
|
||||||
|
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
|
||||||
|
|
||||||
|
firmwareStart: rjmp main
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; includes
|
||||||
|
|
||||||
|
.include "common/utils.asm"
|
||||||
|
.include "common/utils_wait_fixed.asm"
|
||||||
|
.include "common/utils_copy_from_flash.asm"
|
||||||
|
.include "common/utils_copy_sdram.asm"
|
||||||
|
.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
|
||||||
|
|
||||||
|
#ifdef MODULES_TCRT1000
|
||||||
|
.include "modules/tcrt1000/main.asm"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
; test
|
||||||
|
;#include "modules/uart_irq/defs.asm"
|
||||||
|
;#include "modules/uart_irq/iface.asm"
|
||||||
|
;#include "modules/uart_irq/iface1.asm"
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; data in SRAM
|
||||||
|
|
||||||
|
.dseg
|
||||||
|
|
||||||
|
programRamBegin:
|
||||||
|
#ifdef MODULES_LCD
|
||||||
|
screenCounter: .byte 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; timer list
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.include "main_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
systemSetSpeed:
|
||||||
|
.if clock == 8000000
|
||||||
|
ldi r16, (1<<CLKPCE)
|
||||||
|
ldi r17, 0
|
||||||
|
out CLKPR, r16
|
||||||
|
out CLKPR, r17
|
||||||
|
.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:
|
||||||
|
#ifdef MODULES_LED_SIMPLE
|
||||||
|
rcall LedSimple_Every100ms
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_REED
|
||||||
|
rcall REED_Every100ms
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_MOTION
|
||||||
|
rcall Motion_Every100ms
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_TCRT1000
|
||||||
|
rcall TCRT1K_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
|
||||||
|
|
||||||
|
|
||||||
2
avr/devices/n17/.gitignore
vendored
Normal file
2
avr/devices/n17/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.eep.hex
|
||||||
|
*.obj
|
||||||
52
avr/devices/n17/0BUILD
Normal file
52
avr/devices/n17/0BUILD
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml?>
|
||||||
|
|
||||||
|
<gwbuild>
|
||||||
|
|
||||||
|
<target type="AvrHexFile" name="n17_main" >
|
||||||
|
|
||||||
|
<includes type="avrasm" >
|
||||||
|
-I $(builddir)
|
||||||
|
-I $(srcdir)
|
||||||
|
-I $(topsrcdir)/avr
|
||||||
|
-I $(topbuilddir)/avr
|
||||||
|
</includes>
|
||||||
|
|
||||||
|
|
||||||
|
<sources type="avrasm" >
|
||||||
|
n17_main.asm
|
||||||
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<target type="AvrHexFile" name="n17_boot" >
|
||||||
|
|
||||||
|
<includes type="avrasm" >
|
||||||
|
-I $(builddir)
|
||||||
|
-I $(srcdir)
|
||||||
|
-I $(topsrcdir)/avr
|
||||||
|
-I $(topbuilddir)/avr
|
||||||
|
</includes>
|
||||||
|
|
||||||
|
|
||||||
|
<sources type="avrasm" >
|
||||||
|
n17_boot.asm
|
||||||
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
<subdirs>
|
||||||
|
</subdirs>
|
||||||
|
|
||||||
|
<extradist>
|
||||||
|
n17_defs.asm
|
||||||
|
</extradist>
|
||||||
|
|
||||||
|
|
||||||
|
</gwbuild>
|
||||||
|
|
||||||
|
|
||||||
162
avr/devices/n17/n17_boot.asm
Normal file
162
avr/devices/n17/n17_boot.asm
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; Source file for base system node on AtTiny 84
|
||||||
|
;
|
||||||
|
; This is for the maintenance system (i.e. the flash loader).
|
||||||
|
;
|
||||||
|
; All definitions and changes should go into this file.
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
.equ clock=1000000 ; Define the clock frequency
|
||||||
|
|
||||||
|
.nolist
|
||||||
|
.include "include/tn84def.inc" ; Define device ATtiny84
|
||||||
|
.list
|
||||||
|
|
||||||
|
.include "n17_defs.asm"
|
||||||
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; generic
|
||||||
|
|
||||||
|
.include "common/utils_wait.asm"
|
||||||
|
.include "modules/com2/defs.asm"
|
||||||
|
.include "modules/comproto/defs.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; firmware settings
|
||||||
|
|
||||||
|
.equ FIRMWARE_VERSION_MAJOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_MINOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LED
|
||||||
|
|
||||||
|
.equ LED_DDR = DDRA
|
||||||
|
.equ LED_PORT = PORTA
|
||||||
|
.equ LED_PIN = PINA
|
||||||
|
.equ LED_PINNUM = PORTA3
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code segment
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
.org 0x0000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Reset and interrupt vectors
|
||||||
|
; rjmp start ; Reset vector
|
||||||
|
rjmp main ; Reset vector
|
||||||
|
reti ; EXT_INT0
|
||||||
|
reti ; PCI0
|
||||||
|
reti ; PCI1
|
||||||
|
reti ; WATCHDOG
|
||||||
|
reti ; ICP1
|
||||||
|
reti ; OC1A
|
||||||
|
reti ; OC1B
|
||||||
|
reti ; OVF1
|
||||||
|
reti ; OC0A
|
||||||
|
reti ; OC0B
|
||||||
|
reti ; OVF0
|
||||||
|
reti ; ACI
|
||||||
|
reti ; ADCC
|
||||||
|
reti ; ERDY
|
||||||
|
reti ; USI_STR
|
||||||
|
reti ; USI_OVF
|
||||||
|
|
||||||
|
|
||||||
|
devInfoBlock: ; 12 bytes
|
||||||
|
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
|
||||||
|
devInfoId: .db 'N', 0
|
||||||
|
devInfoVersion: .db 17, 0 ; version, revision
|
||||||
|
firmwareVersion: .db FIRMWARE_VARIANT_BOOT, FIRMWARE_VERSION_MAJOR
|
||||||
|
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
|
||||||
|
|
||||||
|
firmwareStart: rjmp main ; will be overwritten when flashing
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; main code
|
||||||
|
|
||||||
|
|
||||||
|
.org BOOTLOADER_ADDR
|
||||||
|
|
||||||
|
|
||||||
|
main:
|
||||||
|
rjmp bootLoader ; this routine is in modules/flash/proto.asm
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; includes
|
||||||
|
|
||||||
|
.include "modules/uart_bitbang/bytelevel.asm"
|
||||||
|
.include "modules/uart_bitbang/packetlevel.asm"
|
||||||
|
.include "modules/com2/crc.asm"
|
||||||
|
.include "common/crc8.asm"
|
||||||
|
.include "common/utils_wait_fixed.asm"
|
||||||
|
.include "common/utils_copy_from_flash.asm"
|
||||||
|
.include "common/utils_copy_sdram.asm"
|
||||||
|
.include "modules/flash/bootloader.asm"
|
||||||
|
.include "modules/flash/flash.asm"
|
||||||
|
.include "modules/flash/recv.asm"
|
||||||
|
.include "modules/flash/send.asm"
|
||||||
|
.include "modules/flash/wait.asm"
|
||||||
|
.include "modules/flash/hdl_flash_start.asm"
|
||||||
|
.include "modules/flash/hdl_flash_data.asm"
|
||||||
|
.include "modules/flash/hdl_flash_end.asm"
|
||||||
|
.include "modules/flash/flash_rsp.asm"
|
||||||
|
.include "modules/flash/flash_ready.asm"
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
debugStop:
|
||||||
|
cli
|
||||||
|
sbi LED_SIMPLE_DDR, LED_SIMPLE_PINNUM ; out
|
||||||
|
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
|
||||||
|
|
||||||
|
cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN port as input
|
||||||
|
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable internal pullup for ATTN
|
||||||
|
|
||||||
|
ldi r18, 0
|
||||||
|
test_loop1:
|
||||||
|
ldi r16, 100
|
||||||
|
test_loop2:
|
||||||
|
ldi r17, 100
|
||||||
|
test_loop3:
|
||||||
|
Utils_WaitNanoSecs 10000, 0, r22
|
||||||
|
dec r17
|
||||||
|
brne test_loop3
|
||||||
|
dec r16
|
||||||
|
brne test_loop2
|
||||||
|
sbi LED_SIMPLE_PORTIN, LED_SIMPLE_PINNUM ; toggle
|
||||||
|
inc r18
|
||||||
|
mov r19, r18
|
||||||
|
andi r19, 1
|
||||||
|
brne test1
|
||||||
|
sbi COM_ATTN_DDR, COM_ATTN_PIN
|
||||||
|
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN
|
||||||
|
rjmp test_loop1
|
||||||
|
test1:
|
||||||
|
cbi COM_ATTN_DDR, COM_ATTN_PIN
|
||||||
|
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN
|
||||||
|
|
||||||
|
rjmp test_loop1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
123
avr/devices/n17/n17_defs.asm
Normal file
123
avr/devices/n17/n17_defs.asm
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2023 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
;
|
||||||
|
; AtTiny84
|
||||||
|
; --------
|
||||||
|
; VCC 1 14 GND
|
||||||
|
; PB0 2 13 PA0 AUX-A0
|
||||||
|
; PIR PB1 3 12 PA1 COM-DATA
|
||||||
|
; /RESET PB3 4 11 PA2
|
||||||
|
; AUX-B2 PB2 5 10 PA3 LED
|
||||||
|
; COM_ATTN PA7 6 9 PA4 TWI-SCL
|
||||||
|
; TWI-SDA PA6 7 8 PA5
|
||||||
|
; --------
|
||||||
|
;
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.equ BOOTLOADER_ADDR = 0xd00
|
||||||
|
|
||||||
|
.equ FIRMWARE_VARIANT_BOOT = 0
|
||||||
|
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LED module
|
||||||
|
|
||||||
|
.equ LED_SIMPLE_ONTIME = 1 ; shorter
|
||||||
|
.equ LED_SIMPLE_OFFTIME = 50 ; longer
|
||||||
|
.equ LED_SIMPLE_DDR = DDRA
|
||||||
|
.equ LED_SIMPLE_PORT = PORTA
|
||||||
|
.equ LED_SIMPLE_PORTIN = PINA
|
||||||
|
.equ LED_SIMPLE_PINNUM = PORTA3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; COM module
|
||||||
|
|
||||||
|
.equ COM_BIT_LENGTH = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400
|
||||||
|
.equ COM_HALFBIT_LENGTH = 26000 ; see https://de.wikipedia.org/wiki/Universal_Asynchronous_Receiver_Transmitter
|
||||||
|
|
||||||
|
.equ COM_DATA_DDR = DDRA
|
||||||
|
.equ COM_DATA_INPUT = PINA
|
||||||
|
.equ COM_DATA_OUTPUT = PORTA
|
||||||
|
.equ COM_DATA_PIN = PORTA1
|
||||||
|
|
||||||
|
.equ COM_ATTN_DDR = DDRA
|
||||||
|
.equ COM_ATTN_INPUT = PINA
|
||||||
|
.equ COM_ATTN_OUTPUT = PORTA
|
||||||
|
.equ COM_ATTN_PIN = PORTA7
|
||||||
|
|
||||||
|
.equ COM_IRQ_ADDR_ATTN = PCMSK0
|
||||||
|
.equ COM_IRQ_BIT_ATTN = PCINT7 ; bit 7 in PCMSK0
|
||||||
|
.equ COM_IRQ_GIFR_ATTN = PCIF0
|
||||||
|
.equ COM_IRQ_GIMSK_ATTN = PCIE0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; TWI master module
|
||||||
|
|
||||||
|
;.equ TWI_BIT_LENGTH = 10000 ; 100000 and 200000 works for display: 10000, 100000, 200000
|
||||||
|
.equ TWI_BIT_LENGTH = 1 ; 10, 100, 500, 100000 and 200000 works for display: 10000, 100000, 200000
|
||||||
|
|
||||||
|
.equ TWI_DDR_SCL = DDRA
|
||||||
|
.equ TWI_PORT_SCL = PORTA
|
||||||
|
.equ TWI_PIN_SCL = PINA
|
||||||
|
.equ TWI_PINNUM_SCL = PORTA4
|
||||||
|
|
||||||
|
.equ TWI_DDR_SDA = DDRA
|
||||||
|
.equ TWI_PORT_SDA = PORTA
|
||||||
|
.equ TWI_PIN_SDA = PINA
|
||||||
|
.equ TWI_PINNUM_SDA = PORTA6
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LCD module
|
||||||
|
|
||||||
|
.equ LCD_TWI_ADDRESS = 0x3c
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; SI 7021
|
||||||
|
|
||||||
|
.equ SI7021_ADDR = 0x40
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; 1-Wire Master
|
||||||
|
;
|
||||||
|
|
||||||
|
.equ OWI_DDR = DDRB
|
||||||
|
.equ OWI_PORTOUT = PORTB
|
||||||
|
.equ OWI_PORTIN = PINB
|
||||||
|
.equ OWI_PINNUM = PORTB2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Motion Sensor
|
||||||
|
;
|
||||||
|
|
||||||
|
.equ MOTION_DDR = DDRB
|
||||||
|
.equ MOTION_INPUT = PINB
|
||||||
|
.equ MOTION_OUTPUT = PORTB
|
||||||
|
.equ MOTION_PIN = PORTB1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
459
avr/devices/n17/n17_main.asm
Normal file
459
avr/devices/n17/n17_main.asm
Normal file
@@ -0,0 +1,459 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2024 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; Source file for temperature sensor node on AtTiny 84
|
||||||
|
;
|
||||||
|
; This is for the full system (i.e. not the boot loader).
|
||||||
|
;
|
||||||
|
; All definitions and changes should go into this file.
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
.equ clock=1000000 ; Define the clock frequency
|
||||||
|
;.equ clock=8000000 ; Define the clock frequency
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.nolist
|
||||||
|
.include "include/tn84def.inc" ; Define device ATtiny84
|
||||||
|
.list
|
||||||
|
|
||||||
|
.include "n17_defs.asm"
|
||||||
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; generic
|
||||||
|
|
||||||
|
|
||||||
|
.include "common/utils_wait.asm"
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; firmware settings including list of modules used
|
||||||
|
|
||||||
|
.equ FIRMWARE_VERSION_MAJOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_MINOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
|
||||||
|
|
||||||
|
|
||||||
|
#define MODULES_TIMER
|
||||||
|
#define MODULES_COM
|
||||||
|
#define MODULES_COM_WITH_ADDR_PROTO
|
||||||
|
#define MODULES_LED_SIMPLE
|
||||||
|
#define MODULES_TWI_MASTER
|
||||||
|
;#define MODULES_LCD
|
||||||
|
#define LCD_MINIMAL_FONT
|
||||||
|
#define MODULES_SI7021
|
||||||
|
#define MODULES_STATS
|
||||||
|
;#define MODULES_OWI_MASTER
|
||||||
|
;#define MODULES_DS18B20
|
||||||
|
#define MODULES_MOTION
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; defines for values
|
||||||
|
|
||||||
|
.equ VALUE_ID_SI7021_TEMP = 0x01
|
||||||
|
.equ VALUE_ID_SI7021_HUM = 0x02
|
||||||
|
|
||||||
|
.equ VALUE_ID_ADC = 0x03
|
||||||
|
;.equ VALUE_ID_REED1 = 0x04
|
||||||
|
;.equ VALUE_ID_REED2 = 0x05
|
||||||
|
;.equ VALUE_ID_DS18B20_TEMP = 0x06
|
||||||
|
.equ VALUE_ID_MOTION = 0x07
|
||||||
|
|
||||||
|
;.equ VALUE_ID_REED_CONF = 0x81
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code segment
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
.org 000000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Reset and interrupt vectors (will be removed as soon as we can flash data over COM)
|
||||||
|
|
||||||
|
; rjmp main ; Reset vector
|
||||||
|
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
|
||||||
|
reti ; EXT_INT0
|
||||||
|
rjmp uartBitbangIsrPcint0 ; PCI0
|
||||||
|
reti ; PCI1
|
||||||
|
reti ; WATCHDOG
|
||||||
|
reti ; ICP1
|
||||||
|
reti ; OC1A
|
||||||
|
reti ; OC1B
|
||||||
|
reti ; OVF1
|
||||||
|
rjmp baseTimerIrqOC0A ; OC0A
|
||||||
|
reti ; OC0B
|
||||||
|
reti ; OVF0
|
||||||
|
reti ; ACI
|
||||||
|
reti ; ADCC
|
||||||
|
reti ; ERDY
|
||||||
|
reti ; USI_STR
|
||||||
|
reti ; USI_OVF
|
||||||
|
|
||||||
|
|
||||||
|
devInfoBlock: ; 12 bytes
|
||||||
|
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
|
||||||
|
devInfoId: .db 'N', 0
|
||||||
|
devInfoVersion: .db 17, 0 ; version, revision
|
||||||
|
firmwareVersion: .db FIRMWARE_VARIANT_TEMP_WINDOW, FIRMWARE_VERSION_MAJOR
|
||||||
|
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
|
||||||
|
|
||||||
|
firmwareStart: rjmp main
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; includes
|
||||||
|
|
||||||
|
.include "common/utils.asm"
|
||||||
|
.include "common/utils_wait_fixed.asm"
|
||||||
|
.include "common/utils_copy_from_flash.asm"
|
||||||
|
.include "common/utils_copy_sdram.asm"
|
||||||
|
.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"
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; data in SRAM
|
||||||
|
|
||||||
|
.dseg
|
||||||
|
|
||||||
|
programRamBegin:
|
||||||
|
#ifdef MODULES_LCD
|
||||||
|
screenCounter: .byte 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; timer list
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.include "main_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
systemSetSpeed:
|
||||||
|
.if clock == 8000000
|
||||||
|
ldi r16, (1<<CLKPCE)
|
||||||
|
ldi r17, 0
|
||||||
|
out CLKPR, r16
|
||||||
|
out CLKPR, r17
|
||||||
|
.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:
|
||||||
|
#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
|
||||||
|
|
||||||
|
|
||||||
2
avr/devices/n18/.gitignore
vendored
Normal file
2
avr/devices/n18/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.eep.hex
|
||||||
|
*.obj
|
||||||
52
avr/devices/n18/0BUILD
Normal file
52
avr/devices/n18/0BUILD
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml?>
|
||||||
|
|
||||||
|
<gwbuild>
|
||||||
|
|
||||||
|
<target type="AvrHexFile" name="firmware" >
|
||||||
|
|
||||||
|
<includes type="avrasm" >
|
||||||
|
-I $(builddir)
|
||||||
|
-I $(srcdir)
|
||||||
|
-I $(topsrcdir)/avr
|
||||||
|
-I $(topbuilddir)/avr
|
||||||
|
</includes>
|
||||||
|
|
||||||
|
|
||||||
|
<sources type="avrasm" >
|
||||||
|
main.asm
|
||||||
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<target type="AvrHexFile" name="boot" >
|
||||||
|
|
||||||
|
<includes type="avrasm" >
|
||||||
|
-I $(builddir)
|
||||||
|
-I $(srcdir)
|
||||||
|
-I $(topsrcdir)/avr
|
||||||
|
-I $(topbuilddir)/avr
|
||||||
|
</includes>
|
||||||
|
|
||||||
|
|
||||||
|
<sources type="avrasm" >
|
||||||
|
boot.asm
|
||||||
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
<subdirs>
|
||||||
|
</subdirs>
|
||||||
|
|
||||||
|
<extradist>
|
||||||
|
defs.asm
|
||||||
|
</extradist>
|
||||||
|
|
||||||
|
|
||||||
|
</gwbuild>
|
||||||
|
|
||||||
|
|
||||||
124
avr/devices/n18/boot.asm
Normal file
124
avr/devices/n18/boot.asm
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; Source file for base system node on AtTiny 85
|
||||||
|
;
|
||||||
|
; This is for the maintenance system (i.e. the flash loader).
|
||||||
|
;
|
||||||
|
; All definitions and changes should go into this file.
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
.equ clock=1000000 ; Define the clock frequency
|
||||||
|
|
||||||
|
.nolist
|
||||||
|
.include "include/tn85def.inc" ; Define device ATtiny85
|
||||||
|
.list
|
||||||
|
|
||||||
|
.include "./defs.asm"
|
||||||
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; generic
|
||||||
|
|
||||||
|
.include "common/utils_wait.asm"
|
||||||
|
.include "modules/com2/defs.asm"
|
||||||
|
.include "modules/comproto/defs.asm"
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; firmware settings
|
||||||
|
|
||||||
|
.equ FIRMWARE_VERSION_MAJOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_MINOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LED
|
||||||
|
|
||||||
|
.equ LED_DDR = DDRB
|
||||||
|
.equ LED_PORT = PORTB
|
||||||
|
.equ LED_PIN = PINB
|
||||||
|
.equ LED_PINNUM = PORTB3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code segment
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
.org 0x0000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Reset and interrupt vectors
|
||||||
|
rjmp main ; Reset vector
|
||||||
|
reti ; EXT_INT0
|
||||||
|
reti ; PCI0
|
||||||
|
reti ; OC1A
|
||||||
|
reti ; OVF1
|
||||||
|
reti ; OVF0
|
||||||
|
reti ; ERDY
|
||||||
|
reti ; ACI
|
||||||
|
reti ; ADCC
|
||||||
|
reti ; OC1B
|
||||||
|
reti ; OC0A
|
||||||
|
reti ; OC0B
|
||||||
|
reti ; WATCHDOG
|
||||||
|
reti ; USI_STR
|
||||||
|
reti ; USI_OVF
|
||||||
|
|
||||||
|
devInfoBlock: ; 12 bytes
|
||||||
|
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
|
||||||
|
devInfoId: .db 'N', 0
|
||||||
|
devInfoVersion: .db 18, 0 ; version, revision
|
||||||
|
firmwareVersion: .db FIRMWARE_VARIANT_BOOT, FIRMWARE_VERSION_MAJOR
|
||||||
|
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
|
||||||
|
|
||||||
|
firmwareStart: rjmp main ; will be overwritten when flashing
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; main code
|
||||||
|
|
||||||
|
|
||||||
|
.org BOOTLOADER_ADDR
|
||||||
|
|
||||||
|
|
||||||
|
main:
|
||||||
|
rjmp bootLoader ; this routine is in modules/flash/proto.asm
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; includes
|
||||||
|
|
||||||
|
.include "modules/uart_bitbang/bytelevel.asm"
|
||||||
|
.include "modules/uart_bitbang/packetlevel.asm"
|
||||||
|
.include "modules/com2/crc.asm"
|
||||||
|
.include "common/crc8.asm"
|
||||||
|
.include "common/utils_wait_fixed.asm"
|
||||||
|
.include "common/utils_copy_from_flash.asm"
|
||||||
|
.include "common/utils_copy_sdram.asm"
|
||||||
|
.include "modules/flash/bootloader.asm"
|
||||||
|
.include "modules/flash/flash.asm"
|
||||||
|
.include "modules/flash/recv.asm"
|
||||||
|
.include "modules/flash/send.asm"
|
||||||
|
.include "modules/flash/wait.asm"
|
||||||
|
.include "modules/flash/hdl_flash_start.asm"
|
||||||
|
.include "modules/flash/hdl_flash_data.asm"
|
||||||
|
.include "modules/flash/hdl_flash_end.asm"
|
||||||
|
.include "modules/flash/flash_rsp.asm"
|
||||||
|
.include "modules/flash/flash_ready.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
98
avr/devices/n18/defs.asm
Normal file
98
avr/devices/n18/defs.asm
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2024 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
;
|
||||||
|
; AtTiny85
|
||||||
|
; --------
|
||||||
|
; /RESET PB5 1 8 VCC
|
||||||
|
; LED PB3 2 7 PB2 TWI-SDA
|
||||||
|
; COM-DATA PB4 3 6 PB1 TWI-SCL
|
||||||
|
; GND 4 5 PB0 COM-ATTN [PCINT0]
|
||||||
|
; --------
|
||||||
|
;
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.equ BOOTLOADER_ADDR = 0xd00
|
||||||
|
|
||||||
|
|
||||||
|
.equ FIRMWARE_VARIANT_BOOT = 0
|
||||||
|
.equ FIRMWARE_VARIANT_MAIN = 1
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LED module
|
||||||
|
|
||||||
|
.equ LED_SIMPLE_ONTIME = 2
|
||||||
|
.equ LED_SIMPLE_OFFTIME = 50
|
||||||
|
.equ LED_SIMPLE_DDR = DDRB
|
||||||
|
.equ LED_SIMPLE_PORT = PORTB
|
||||||
|
.equ LED_SIMPLE_PINNUM = PORTB3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; COM module
|
||||||
|
|
||||||
|
.equ COM_BIT_LENGTH = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400
|
||||||
|
.equ COM_HALFBIT_LENGTH = 26000 ; see https://de.wikipedia.org/wiki/Universal_Asynchronous_Receiver_Transmitter
|
||||||
|
|
||||||
|
.equ COM_DATA_DDR = DDRB
|
||||||
|
.equ COM_DATA_INPUT = PINB
|
||||||
|
.equ COM_DATA_OUTPUT = PORTB
|
||||||
|
.equ COM_DATA_PIN = PORTB4
|
||||||
|
|
||||||
|
.equ COM_ATTN_DDR = DDRB
|
||||||
|
.equ COM_ATTN_INPUT = PINB
|
||||||
|
.equ COM_ATTN_OUTPUT = PORTB
|
||||||
|
.equ COM_ATTN_PIN = PORTB0
|
||||||
|
|
||||||
|
.equ COM_IRQ_ADDR_ATTN = PCMSK
|
||||||
|
.equ COM_IRQ_BIT_ATTN = PCINT0 ; bit 0 in PCMSK0 (PCINT0)
|
||||||
|
.equ COM_IRQ_GIFR_ATTN = PCIF
|
||||||
|
.equ COM_IRQ_GIMSK_ATTN = PCIE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; TWI master module
|
||||||
|
|
||||||
|
;.equ TWI_BIT_LENGTH = 10000 ; 100000 and 200000 works for display: 10000, 100000, 200000
|
||||||
|
.equ TWI_BIT_LENGTH = 1 ; 10, 100, 500, 100000 and 200000 works for display: 10000, 100000, 200000
|
||||||
|
|
||||||
|
.equ TWI_DDR_SCL = DDRB
|
||||||
|
.equ TWI_PORT_SCL = PORTB
|
||||||
|
.equ TWI_PIN_SCL = PINB
|
||||||
|
.equ TWI_PINNUM_SCL = PORTB1
|
||||||
|
|
||||||
|
.equ TWI_DDR_SDA = DDRB
|
||||||
|
.equ TWI_PORT_SDA = PORTB
|
||||||
|
.equ TWI_PIN_SDA = PINB
|
||||||
|
.equ TWI_PINNUM_SDA = PORTB2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; SI 7021
|
||||||
|
|
||||||
|
.equ SI7021_ADDR = 0x40
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; CCS 811
|
||||||
|
;
|
||||||
|
|
||||||
|
.equ CCS811_ADDR = 0x5a ; or 0x5b
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
379
avr/devices/n18/main.asm
Normal file
379
avr/devices/n18/main.asm
Normal file
@@ -0,0 +1,379 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2024 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; Source file for LED controller node on AtTiny 85
|
||||||
|
;
|
||||||
|
; This is for the full system (i.e. not the boot loader).
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
.equ clock=1000000 ; Define the clock frequency
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.nolist
|
||||||
|
.include "include/tn85def.inc" ; Define device ATtiny85
|
||||||
|
.list
|
||||||
|
|
||||||
|
.include "./defs.asm"
|
||||||
|
.include "defs_all.asm"
|
||||||
|
.include "common/utils_wait.asm" ; wait macro
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; firmware settings including list of modules used
|
||||||
|
|
||||||
|
.equ FIRMWARE_VERSION_MAJOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_MINOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
|
||||||
|
|
||||||
|
|
||||||
|
#define MODULES_TIMER
|
||||||
|
#define MODULES_COM
|
||||||
|
#define MODULES_COM_WITH_ADDR_PROTO
|
||||||
|
#define MODULES_LED_SIMPLE
|
||||||
|
#define MODULES_TWI_MASTER
|
||||||
|
#define MODULES_SI7021
|
||||||
|
#define MODULES_STATS
|
||||||
|
; #define MODULES_OWI_MASTER
|
||||||
|
; #define MODULES_DS18B20
|
||||||
|
; #define MODULES_SK6812
|
||||||
|
; #define MODULES_MOTION_LIGHT
|
||||||
|
|
||||||
|
; #define COM_ACCEPT_ALL_DEST
|
||||||
|
#define MODULES_CCS811
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; defines for modules
|
||||||
|
|
||||||
|
.equ VALUE_ID_SI7021_TEMP = 0x01
|
||||||
|
.equ VALUE_ID_SI7021_HUM = 0x02
|
||||||
|
|
||||||
|
.equ VALUE_ID_CO2 = 0x07
|
||||||
|
.equ VALUE_ID_TVOC = 0x08
|
||||||
|
|
||||||
|
.equ VALUE_ID_DEBUG = 0x7f
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code segment
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
.org 000000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Reset and interrupt vectors
|
||||||
|
|
||||||
|
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
|
||||||
|
reti ; EXT_INT0
|
||||||
|
rjmp uartBitbangIsrPcint0 ; PCI0
|
||||||
|
reti ; OC1A
|
||||||
|
reti ; OVF1
|
||||||
|
reti ; OVF0
|
||||||
|
reti ; ERDY
|
||||||
|
reti ; ACI
|
||||||
|
reti ; ADCC
|
||||||
|
reti ; OC1B
|
||||||
|
rjmp baseTimerIrqOC0A ; OC0A
|
||||||
|
reti ; OC0B
|
||||||
|
reti ; WATCHDOG
|
||||||
|
reti ; USI_STR
|
||||||
|
reti ; USI_OVF
|
||||||
|
|
||||||
|
|
||||||
|
devInfoBlock: ; 12 bytes
|
||||||
|
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
|
||||||
|
devInfoId: .db 'N', 0
|
||||||
|
devInfoVersion: .db 18, 0 ; version, revision
|
||||||
|
firmwareVersion: .db FIRMWARE_VARIANT_MAIN, FIRMWARE_VERSION_MAJOR
|
||||||
|
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
|
||||||
|
|
||||||
|
firmwareStart: rjmp main
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; includes
|
||||||
|
|
||||||
|
.include "common/utils.asm"
|
||||||
|
.include "common/utils_wait_fixed.asm"
|
||||||
|
.include "common/utils_copy_from_flash.asm"
|
||||||
|
.include "common/utils_copy_sdram.asm"
|
||||||
|
.include "common/crc8.asm"
|
||||||
|
|
||||||
|
.include "modules/basetimer/main.asm"
|
||||||
|
|
||||||
|
#ifdef MODULES_TIMER
|
||||||
|
.include "modules/timer/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"
|
||||||
|
#ifdef MODULES_STATS
|
||||||
|
.include "modules/comproto/msg_recvstats.asm"
|
||||||
|
.include "modules/comproto/msg_sendstats.asm"
|
||||||
|
.include "modules/comproto/msg_sysstats.asm"
|
||||||
|
.include "modules/comproto/msg_memstats.asm"
|
||||||
|
#endif
|
||||||
|
.include "modules/comproto/msg_pong.asm"
|
||||||
|
.include "modules/comproto/msg_value.asm"
|
||||||
|
.include "modules/comproto/msg_device.asm"
|
||||||
|
.include "modules/comproto/msg_reboot.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"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_STATS
|
||||||
|
.include "modules/stats/main.asm"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_TWI_MASTER
|
||||||
|
.include "modules/twimaster/main.asm"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_OWI_MASTER
|
||||||
|
.include "modules/owimaster/main.asm"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_SI7021
|
||||||
|
.include "modules/si7021/main.asm"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_DS18B20
|
||||||
|
.include "modules/ds18b20/main.asm"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_SK6812
|
||||||
|
.include "modules/sk6812/main.asm"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_MOTION_LIGHT
|
||||||
|
.include "modules/ma_light/main.asm"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_CCS811
|
||||||
|
.include "modules/ccs811/main.asm"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; data in SRAM
|
||||||
|
|
||||||
|
.dseg
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MODULES_SI7021
|
||||||
|
sramTimerSI7021Measure: .byte 2
|
||||||
|
sramTimerSI7021SendTemp: .byte 2
|
||||||
|
sramTimerSI7021SendHumidity: .byte 2
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_DS18B20
|
||||||
|
sramDs18b20Timer: .byte 2
|
||||||
|
sramSendDs18b20TempTimer: .byte 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_CCS811
|
||||||
|
sramCcs811Timer: .byte 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; data in FLASH
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; timer list
|
||||||
|
|
||||||
|
|
||||||
|
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_DS18B20
|
||||||
|
.dw sramDs18b20Timer, Ds18b20_OnTimer, 0, 300 ; every 30s
|
||||||
|
.dw sramSendDs18b20TempTimer, sendDs18b20Temp, TIMER_FLAGS_IF_ADDR, 600 ; every 60s
|
||||||
|
#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_CCS811
|
||||||
|
.dw sramCcs811Timer, CCS811_OnTimer, 0, 10 ; every 1s
|
||||||
|
#endif
|
||||||
|
.dw 0 ; end of list
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.include "main_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Called early on system startup. No arguments, no results.
|
||||||
|
|
||||||
|
systemSetSpeed:
|
||||||
|
.if clock == 1000000
|
||||||
|
ldi r16, (1<<CLKPCE)
|
||||||
|
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
|
||||||
|
out CLKPR, r16
|
||||||
|
out CLKPR, r17
|
||||||
|
.endif
|
||||||
|
|
||||||
|
.if clock == 8000000
|
||||||
|
ldi r16, (1<<CLKPCE)
|
||||||
|
ldi r17, 0
|
||||||
|
out CLKPR, r16
|
||||||
|
out CLKPR, r17
|
||||||
|
.endif
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Called just before rebooting to bootloader. No arguments, no results.
|
||||||
|
|
||||||
|
systemSetBootSpeed:
|
||||||
|
ldi r16, (1<<CLKPCE)
|
||||||
|
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
|
||||||
|
out CLKPR, r16
|
||||||
|
out CLKPR, r17
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Called on first time run, i.e. on system start. No arguments, no results.
|
||||||
|
|
||||||
|
onSystemStart:
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
#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:
|
||||||
|
#ifdef MODULES_LED_SIMPLE
|
||||||
|
rcall LedSimple_Every100ms
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_REED
|
||||||
|
rcall REED_Every100ms
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_MOTION_LIGHT
|
||||||
|
rcall MotionLight_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:
|
||||||
|
; get msg code
|
||||||
|
adiw xh:xl, COM2_MSG_OFFS_CMD
|
||||||
|
ld r16, x
|
||||||
|
sbiw xh:xl, COM2_MSG_OFFS_CMD
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
2
avr/devices/r02/.gitignore
vendored
Normal file
2
avr/devices/r02/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.eep.hex
|
||||||
|
*.obj
|
||||||
52
avr/devices/r02/0BUILD
Normal file
52
avr/devices/r02/0BUILD
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml?>
|
||||||
|
|
||||||
|
<gwbuild>
|
||||||
|
|
||||||
|
<target type="AvrHexFile" name="r02_main" >
|
||||||
|
|
||||||
|
<includes type="avrasm" >
|
||||||
|
-I $(builddir)
|
||||||
|
-I $(srcdir)
|
||||||
|
-I $(topsrcdir)/avr
|
||||||
|
-I $(topbuilddir)/avr
|
||||||
|
</includes>
|
||||||
|
|
||||||
|
|
||||||
|
<sources type="avrasm" >
|
||||||
|
r02_main.asm
|
||||||
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<target type="AvrHexFile" name="r02_boot" >
|
||||||
|
|
||||||
|
<includes type="avrasm" >
|
||||||
|
-I $(builddir)
|
||||||
|
-I $(srcdir)
|
||||||
|
-I $(topsrcdir)/avr
|
||||||
|
-I $(topbuilddir)/avr
|
||||||
|
</includes>
|
||||||
|
|
||||||
|
|
||||||
|
<sources type="avrasm" >
|
||||||
|
r02_boot.asm
|
||||||
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
<subdirs>
|
||||||
|
</subdirs>
|
||||||
|
|
||||||
|
<extradist>
|
||||||
|
r02_defs.asm
|
||||||
|
</extradist>
|
||||||
|
|
||||||
|
|
||||||
|
</gwbuild>
|
||||||
|
|
||||||
|
|
||||||
163
avr/devices/r02/r02_boot.asm
Normal file
163
avr/devices/r02/r02_boot.asm
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; Source file for base system node on AtTiny 84
|
||||||
|
;
|
||||||
|
; This is for the maintenance system (i.e. the flash loader).
|
||||||
|
;
|
||||||
|
; All definitions and changes should go into this file.
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
.equ clock=1000000 ; Define the clock frequency
|
||||||
|
|
||||||
|
.nolist
|
||||||
|
.include "include/tn841def.inc" ; Define device ATtiny841
|
||||||
|
.list
|
||||||
|
|
||||||
|
.include "r02_defs.asm"
|
||||||
|
.include "defs.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; generic
|
||||||
|
|
||||||
|
.include "common/utils_wait.asm"
|
||||||
|
.include "modules/com2/defs.asm"
|
||||||
|
.include "modules/comproto/defs.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; firmware settings
|
||||||
|
|
||||||
|
.equ FIRMWARE_VERSION_MAJOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_MINOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LED
|
||||||
|
|
||||||
|
.equ LED_DDR = DDRB
|
||||||
|
.equ LED_PORT = PORTB
|
||||||
|
.equ LED_PIN = PINB
|
||||||
|
.equ LED_PINNUM = PORTB2
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code segment
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
.org 0x0000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Reset and interrupt vectors
|
||||||
|
; rjmp start ; Reset vector
|
||||||
|
rjmp main ; Reset vector
|
||||||
|
reti ; EXT_INT0
|
||||||
|
reti ; PCI0
|
||||||
|
reti ; PCI1
|
||||||
|
reti ; WATCHDOG
|
||||||
|
reti ; ICP1
|
||||||
|
reti ; OC1A
|
||||||
|
reti ; OC1B
|
||||||
|
reti ; OVF1
|
||||||
|
reti ; OC0A
|
||||||
|
reti ; OC0B
|
||||||
|
reti ; OVF0
|
||||||
|
reti ; ACI
|
||||||
|
reti ; ADCC
|
||||||
|
reti ; ERDY
|
||||||
|
reti ; USI_STR
|
||||||
|
reti ; USI_OVF
|
||||||
|
|
||||||
|
|
||||||
|
devInfoBlock: ; 12 bytes
|
||||||
|
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
|
||||||
|
devInfoId: .db 'R', 0
|
||||||
|
devInfoVersion: .db 2, 0 ; version, revision
|
||||||
|
firmwareVersion: .db FIRMWARE_VARIANT_BOOT, FIRMWARE_VERSION_MAJOR
|
||||||
|
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
|
||||||
|
|
||||||
|
firmwareStart: rjmp main ; will be overwritten when flashing
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; main code
|
||||||
|
|
||||||
|
|
||||||
|
.org BOOTLOADER_ADDR
|
||||||
|
|
||||||
|
|
||||||
|
main:
|
||||||
|
; rjmp debugStop
|
||||||
|
rjmp bootLoader ; this routine is in modules/flash/proto.asm
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; includes
|
||||||
|
|
||||||
|
.include "modules/uart_bitbang/bytelevel.asm"
|
||||||
|
.include "modules/uart_bitbang/packetlevel.asm"
|
||||||
|
.include "modules/com2/crc.asm"
|
||||||
|
.include "common/crc8.asm"
|
||||||
|
.include "common/utils_wait_fixed.asm"
|
||||||
|
.include "common/utils_copy_from_flash.asm"
|
||||||
|
.include "common/utils_copy_sdram.asm"
|
||||||
|
.include "modules/flash/bootloader.asm"
|
||||||
|
.include "modules/flash/flash.asm"
|
||||||
|
.include "modules/flash/recv.asm"
|
||||||
|
.include "modules/flash/send.asm"
|
||||||
|
.include "modules/flash/wait.asm"
|
||||||
|
.include "modules/flash/hdl_flash_start.asm"
|
||||||
|
.include "modules/flash/hdl_flash_data.asm"
|
||||||
|
.include "modules/flash/hdl_flash_end.asm"
|
||||||
|
.include "modules/flash/flash_rsp.asm"
|
||||||
|
.include "modules/flash/flash_ready.asm"
|
||||||
|
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
debugStop:
|
||||||
|
cli
|
||||||
|
sbi LED_SIMPLE_DDR, LED_SIMPLE_PINNUM ; out
|
||||||
|
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
|
||||||
|
|
||||||
|
cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN port as input
|
||||||
|
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable internal pullup for ATTN
|
||||||
|
|
||||||
|
ldi r18, 0
|
||||||
|
test_loop1:
|
||||||
|
ldi r16, 100
|
||||||
|
test_loop2:
|
||||||
|
ldi r17, 100
|
||||||
|
test_loop3:
|
||||||
|
Utils_WaitNanoSecs 10000, 0, r22
|
||||||
|
dec r17
|
||||||
|
brne test_loop3
|
||||||
|
dec r16
|
||||||
|
brne test_loop2
|
||||||
|
sbi LED_SIMPLE_PORTIN, LED_SIMPLE_PINNUM ; toggle
|
||||||
|
inc r18
|
||||||
|
mov r19, r18
|
||||||
|
andi r19, 1
|
||||||
|
brne test1
|
||||||
|
sbi COM_ATTN_DDR, COM_ATTN_PIN
|
||||||
|
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN
|
||||||
|
rjmp test_loop1
|
||||||
|
test1:
|
||||||
|
cbi COM_ATTN_DDR, COM_ATTN_PIN
|
||||||
|
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN
|
||||||
|
|
||||||
|
rjmp test_loop1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
87
avr/devices/r02/r02_defs.asm
Normal file
87
avr/devices/r02/r02_defs.asm
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2024 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
;
|
||||||
|
; AtTiny 841
|
||||||
|
; -------
|
||||||
|
; VCC 1 14 GND
|
||||||
|
; PB0 2 13 PA0 ATTN0
|
||||||
|
; PB1 3 12 PA1 TXD0 (UART0)
|
||||||
|
; /RESET PB3 4 11 PA2 RXD0 (UART0)
|
||||||
|
; LED PB2 5 10 PA3 ATTN1
|
||||||
|
; 1-wire PA7 6 9 PA4 RXD1 (UART1) [SCK, PRG]
|
||||||
|
; [MOSI,PRG] SDA (I2C) PA6 7 8 PA5 TXD1 (UART1) [MISO, PRG]
|
||||||
|
; -------
|
||||||
|
;
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.equ BOOTLOADER_ADDR = 0xd00
|
||||||
|
|
||||||
|
.equ FIRMWARE_VARIANT_BOOT = 0
|
||||||
|
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LED module
|
||||||
|
|
||||||
|
.equ LED_SIMPLE_ONTIME = 2
|
||||||
|
.equ LED_SIMPLE_OFFTIME = 30
|
||||||
|
.equ LED_SIMPLE_DDR = DDRB
|
||||||
|
.equ LED_SIMPLE_PORT = PORTB
|
||||||
|
.equ LED_SIMPLE_PORTIN = PINB
|
||||||
|
.equ LED_SIMPLE_PINNUM = PORTB2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; COM module
|
||||||
|
|
||||||
|
.equ COM_BIT_LENGTH = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400
|
||||||
|
.equ COM_HALFBIT_LENGTH = 26000 ; see https://de.wikipedia.org/wiki/Universal_Asynchronous_Receiver_Transmitter
|
||||||
|
|
||||||
|
.equ COM_DATA_DDR = DDRA
|
||||||
|
.equ COM_DATA_INPUT = PINA
|
||||||
|
.equ COM_DATA_OUTPUT = PORTA
|
||||||
|
.equ COM_DATA_PIN = PORTA2
|
||||||
|
|
||||||
|
.equ COM_ATTN_DDR = DDRA
|
||||||
|
.equ COM_ATTN_INPUT = PINA
|
||||||
|
.equ COM_ATTN_OUTPUT = PORTA
|
||||||
|
.equ COM_ATTN_PIN = PORTA0
|
||||||
|
|
||||||
|
.equ COM_IRQ_ADDR_ATTN = PCMSK0
|
||||||
|
.equ COM_IRQ_BIT_ATTN = PCINT0 ; bit 7 in PCMSK0
|
||||||
|
.equ COM_IRQ_GIFR_ATTN = PCIF0
|
||||||
|
.equ COM_IRQ_GIMSK_ATTN = PCIE0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LCD module
|
||||||
|
|
||||||
|
.equ LCD_TWI_ADDRESS = 0x3c
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; 1-Wire Master
|
||||||
|
;
|
||||||
|
|
||||||
|
.equ OWI_DDR = DDRA
|
||||||
|
.equ OWI_PORTOUT = PORTA
|
||||||
|
.equ OWI_PORTIN = PINA
|
||||||
|
.equ OWI_PINNUM = PORTA7
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
448
avr/devices/r02/r02_main.asm
Normal file
448
avr/devices/r02/r02_main.asm
Normal file
@@ -0,0 +1,448 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2024 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; Source file for temperature sensor node on AtTiny 84
|
||||||
|
;
|
||||||
|
; This is for the full system (i.e. not the boot loader).
|
||||||
|
;
|
||||||
|
; All definitions and changes should go into this file.
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
.equ clock=1000000 ; Define the clock frequency
|
||||||
|
;.equ clock=8000000 ; Define the clock frequency
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.nolist
|
||||||
|
.include "include/tn841def.inc" ; Define device ATtiny84
|
||||||
|
.list
|
||||||
|
|
||||||
|
.include "r02_defs.asm"
|
||||||
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; generic
|
||||||
|
|
||||||
|
|
||||||
|
.include "common/utils_wait.asm"
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; firmware settings including list of modules used
|
||||||
|
|
||||||
|
.equ FIRMWARE_VERSION_MAJOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_MINOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
|
||||||
|
|
||||||
|
|
||||||
|
#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 MODULES_SI7021
|
||||||
|
#define MODULES_STATS
|
||||||
|
;#define MODULES_CNY70
|
||||||
|
;#define MODULES_REED
|
||||||
|
#define MODULES_OWI_MASTER
|
||||||
|
;#define MODULES_DS18B20
|
||||||
|
;#define MODULES_MOTION
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code segment
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
.org 000000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Reset and interrupt vectors (will be removed as soon as we can flash data over COM)
|
||||||
|
|
||||||
|
; rjmp main ; Reset vector
|
||||||
|
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
|
||||||
|
reti ; EXT_INT0
|
||||||
|
rjmp uartBitbangIsrPcint0 ; PCI0
|
||||||
|
reti ; PCI1
|
||||||
|
reti ; WATCHDOG
|
||||||
|
reti ; ICP1
|
||||||
|
reti ; OC1A
|
||||||
|
reti ; OC1B
|
||||||
|
reti ; OVF1
|
||||||
|
rjmp baseTimerIrqOC0A ; OC0A
|
||||||
|
reti ; OC0B
|
||||||
|
reti ; OVF0
|
||||||
|
reti ; ACI
|
||||||
|
reti ; ADCC
|
||||||
|
reti ; ERDY
|
||||||
|
reti ; USI_STR
|
||||||
|
reti ; USI_OVF
|
||||||
|
|
||||||
|
|
||||||
|
devInfoBlock: ; 12 bytes
|
||||||
|
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
|
||||||
|
devInfoId: .db 'R', 0
|
||||||
|
devInfoVersion: .db 2, 0 ; version, revision
|
||||||
|
firmwareVersion: .db FIRMWARE_VARIANT_TEMP_WINDOW, FIRMWARE_VERSION_MAJOR
|
||||||
|
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
|
||||||
|
|
||||||
|
firmwareStart: rjmp main
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; includes
|
||||||
|
|
||||||
|
.include "common/utils.asm"
|
||||||
|
.include "common/utils_wait_fixed.asm"
|
||||||
|
.include "common/utils_copy_from_flash.asm"
|
||||||
|
.include "common/utils_copy_sdram.asm"
|
||||||
|
.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"
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; data in SRAM
|
||||||
|
|
||||||
|
.dseg
|
||||||
|
|
||||||
|
programRamBegin:
|
||||||
|
#ifdef MODULES_LCD
|
||||||
|
screenCounter: .byte 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; timer list
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.include "main_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
systemSetSpeed:
|
||||||
|
.if clock == 8000000
|
||||||
|
ldi r16, (1<<CLKPCE)
|
||||||
|
ldi r17, 0
|
||||||
|
out CLKPR, r16
|
||||||
|
out CLKPR, r17
|
||||||
|
.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:
|
||||||
|
#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
|
||||||
|
|
||||||
|
|
||||||
11
avr/devices/x03/0BUILD
Normal file
11
avr/devices/x03/0BUILD
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml?>
|
||||||
|
|
||||||
|
<gwbuild>
|
||||||
|
|
||||||
|
<subdirs>
|
||||||
|
uart
|
||||||
|
ccs811
|
||||||
|
</subdirs>
|
||||||
|
|
||||||
|
</gwbuild>
|
||||||
|
|
||||||
52
avr/devices/x03/ccs811/0BUILD
Normal file
52
avr/devices/x03/ccs811/0BUILD
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml?>
|
||||||
|
|
||||||
|
<gwbuild>
|
||||||
|
|
||||||
|
<target type="AvrHexFile" name="firmware" >
|
||||||
|
|
||||||
|
<includes type="avrasm" >
|
||||||
|
-I $(builddir)
|
||||||
|
-I $(srcdir)
|
||||||
|
-I $(topsrcdir)/avr
|
||||||
|
-I $(topbuilddir)/avr
|
||||||
|
</includes>
|
||||||
|
|
||||||
|
|
||||||
|
<sources type="avrasm" >
|
||||||
|
main.asm
|
||||||
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<target type="AvrHexFile" name="boot" >
|
||||||
|
|
||||||
|
<includes type="avrasm" >
|
||||||
|
-I $(builddir)
|
||||||
|
-I $(srcdir)
|
||||||
|
-I $(topsrcdir)/avr
|
||||||
|
-I $(topbuilddir)/avr
|
||||||
|
</includes>
|
||||||
|
|
||||||
|
|
||||||
|
<sources type="avrasm" >
|
||||||
|
boot.asm
|
||||||
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
<subdirs>
|
||||||
|
</subdirs>
|
||||||
|
|
||||||
|
<extradist>
|
||||||
|
defs.asm
|
||||||
|
</extradist>
|
||||||
|
|
||||||
|
|
||||||
|
</gwbuild>
|
||||||
|
|
||||||
|
|
||||||
124
avr/devices/x03/ccs811/boot.asm
Normal file
124
avr/devices/x03/ccs811/boot.asm
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; Source file for base system node on AtTiny 85
|
||||||
|
;
|
||||||
|
; This is for the maintenance system (i.e. the flash loader).
|
||||||
|
;
|
||||||
|
; All definitions and changes should go into this file.
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
.equ clock=1000000 ; Define the clock frequency
|
||||||
|
|
||||||
|
.nolist
|
||||||
|
.include "include/tn84def.inc" ; Define device ATtiny84
|
||||||
|
.list
|
||||||
|
|
||||||
|
.include "./defs.asm"
|
||||||
|
.include "defs_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; generic
|
||||||
|
|
||||||
|
.include "common/utils_wait.asm"
|
||||||
|
.include "modules/com2/defs.asm"
|
||||||
|
.include "modules/comproto/defs.asm"
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; firmware settings
|
||||||
|
|
||||||
|
.equ FIRMWARE_VERSION_MAJOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_MINOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LED
|
||||||
|
|
||||||
|
.equ LED_DDR = DDRA
|
||||||
|
.equ LED_PORT = PORTA
|
||||||
|
.equ LED_PIN = PINA
|
||||||
|
.equ LED_PINNUM = PORTA3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code segment
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
.org 0x0000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Reset and interrupt vectors
|
||||||
|
rjmp main ; Reset vector
|
||||||
|
reti ; EXT_INT0
|
||||||
|
reti ; PCI0
|
||||||
|
reti ; OC1A
|
||||||
|
reti ; OVF1
|
||||||
|
reti ; OVF0
|
||||||
|
reti ; ERDY
|
||||||
|
reti ; ACI
|
||||||
|
reti ; ADCC
|
||||||
|
reti ; OC1B
|
||||||
|
reti ; OC0A
|
||||||
|
reti ; OC0B
|
||||||
|
reti ; WATCHDOG
|
||||||
|
reti ; USI_STR
|
||||||
|
reti ; USI_OVF
|
||||||
|
|
||||||
|
devInfoBlock: ; 12 bytes
|
||||||
|
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
|
||||||
|
devInfoId: .db 'N', 0
|
||||||
|
devInfoVersion: .db 14, 0 ; version, revision
|
||||||
|
firmwareVersion: .db FIRMWARE_VARIANT_BOOT, FIRMWARE_VERSION_MAJOR
|
||||||
|
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
|
||||||
|
|
||||||
|
firmwareStart: rjmp main ; will be overwritten when flashing
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; main code
|
||||||
|
|
||||||
|
|
||||||
|
.org BOOTLOADER_ADDR
|
||||||
|
|
||||||
|
|
||||||
|
main:
|
||||||
|
rjmp bootLoader ; this routine is in modules/flash/proto.asm
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; includes
|
||||||
|
|
||||||
|
.include "modules/uart_bitbang/bytelevel.asm"
|
||||||
|
.include "modules/uart_bitbang/packetlevel.asm"
|
||||||
|
.include "modules/com2/crc.asm"
|
||||||
|
.include "common/crc8.asm"
|
||||||
|
.include "common/utils_wait_fixed.asm"
|
||||||
|
.include "common/utils_copy_from_flash.asm"
|
||||||
|
.include "common/utils_copy_sdram.asm"
|
||||||
|
.include "modules/flash/bootloader.asm"
|
||||||
|
.include "modules/flash/flash.asm"
|
||||||
|
.include "modules/flash/recv.asm"
|
||||||
|
.include "modules/flash/send.asm"
|
||||||
|
.include "modules/flash/wait.asm"
|
||||||
|
.include "modules/flash/hdl_flash_start.asm"
|
||||||
|
.include "modules/flash/hdl_flash_data.asm"
|
||||||
|
.include "modules/flash/hdl_flash_end.asm"
|
||||||
|
.include "modules/flash/flash_rsp.asm"
|
||||||
|
.include "modules/flash/flash_ready.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
134
avr/devices/x03/ccs811/defs.asm
Normal file
134
avr/devices/x03/ccs811/defs.asm
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2023 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
;
|
||||||
|
; AtTiny84
|
||||||
|
; --------
|
||||||
|
; VCC 1 14 GND
|
||||||
|
; PB0 2 13 PA0 AUX-A0
|
||||||
|
; PIR PB1 3 12 PA1 COM-DATA
|
||||||
|
; /RESET PB3 4 11 PA2
|
||||||
|
; AUX-B2 PB2 5 10 PA3 LED
|
||||||
|
; COM_ATTN PA7 6 9 PA4 TWI-SCL
|
||||||
|
; TWI-SDA PA6 7 8 PA5
|
||||||
|
; --------
|
||||||
|
;
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.equ BOOTLOADER_ADDR = 0xd00
|
||||||
|
|
||||||
|
.equ FIRMWARE_VARIANT_BOOT = 0
|
||||||
|
.equ FIRMWARE_VARIANT_MAIN = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LED module
|
||||||
|
|
||||||
|
.equ LED_SIMPLE_ONTIME = 1 ; shorter
|
||||||
|
.equ LED_SIMPLE_OFFTIME = 50 ; longer
|
||||||
|
.equ LED_SIMPLE_DDR = DDRA
|
||||||
|
.equ LED_SIMPLE_PORT = PORTA
|
||||||
|
.equ LED_SIMPLE_PORTIN = PINA
|
||||||
|
.equ LED_SIMPLE_PINNUM = PORTA3
|
||||||
|
|
||||||
|
|
||||||
|
.equ LED_DEBUG_DDR = DDRA
|
||||||
|
.equ LED_DEBUG_PORT = PORTA
|
||||||
|
.equ LED_DEBUG_PORTIN = PINA
|
||||||
|
.equ LED_DEBUG_PINNUM = PORTA5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; COM module
|
||||||
|
|
||||||
|
.equ COM_BIT_LENGTH = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400
|
||||||
|
.equ COM_HALFBIT_LENGTH = 26000 ; see https://de.wikipedia.org/wiki/Universal_Asynchronous_Receiver_Transmitter
|
||||||
|
|
||||||
|
.equ COM_DATA_DDR = DDRA
|
||||||
|
.equ COM_DATA_INPUT = PINA
|
||||||
|
.equ COM_DATA_OUTPUT = PORTA
|
||||||
|
.equ COM_DATA_PIN = PORTA1
|
||||||
|
|
||||||
|
.equ COM_ATTN_DDR = DDRA
|
||||||
|
.equ COM_ATTN_INPUT = PINA
|
||||||
|
.equ COM_ATTN_OUTPUT = PORTA
|
||||||
|
.equ COM_ATTN_PIN = PORTA7
|
||||||
|
|
||||||
|
.equ COM_IRQ_ADDR_ATTN = PCMSK0
|
||||||
|
.equ COM_IRQ_BIT_ATTN = PCINT7 ; bit 7 in PCMSK0
|
||||||
|
.equ COM_IRQ_GIFR_ATTN = PCIF0
|
||||||
|
.equ COM_IRQ_GIMSK_ATTN = PCIE0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; TWI master module
|
||||||
|
|
||||||
|
;.equ TWI_BIT_LENGTH = 10000 ; 100000 and 200000 works for display: 10000, 100000, 200000
|
||||||
|
.equ TWI_BIT_LENGTH = 1 ; 10, 100, 500, 100000 and 200000 works for display: 10000, 100000, 200000
|
||||||
|
|
||||||
|
.equ TWI_DDR_SCL = DDRA
|
||||||
|
.equ TWI_PORT_SCL = PORTA
|
||||||
|
.equ TWI_PIN_SCL = PINA
|
||||||
|
.equ TWI_PINNUM_SCL = PORTA4
|
||||||
|
|
||||||
|
.equ TWI_DDR_SDA = DDRA
|
||||||
|
.equ TWI_PORT_SDA = PORTA
|
||||||
|
.equ TWI_PIN_SDA = PINA
|
||||||
|
.equ TWI_PINNUM_SDA = PORTA6
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LCD module
|
||||||
|
|
||||||
|
.equ LCD_TWI_ADDRESS = 0x3c
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; SI 7021
|
||||||
|
|
||||||
|
.equ SI7021_ADDR = 0x40
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; 1-Wire Master
|
||||||
|
;
|
||||||
|
|
||||||
|
.equ OWI_DDR = DDRB
|
||||||
|
.equ OWI_PORTOUT = PORTB
|
||||||
|
.equ OWI_PORTIN = PINB
|
||||||
|
.equ OWI_PINNUM = PORTB2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Motion Sensor
|
||||||
|
;
|
||||||
|
|
||||||
|
.equ MOTION_DDR = DDRB
|
||||||
|
.equ MOTION_INPUT = PINB
|
||||||
|
.equ MOTION_OUTPUT = PORTB
|
||||||
|
.equ MOTION_PIN = PORTB1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.equ CCS811_ADDR = 0x5a ; or 0x5b
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
339
avr/devices/x03/ccs811/main.asm
Normal file
339
avr/devices/x03/ccs811/main.asm
Normal file
@@ -0,0 +1,339 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2024 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; Source file for LED controller node on AtTiny 85
|
||||||
|
;
|
||||||
|
; This is for the full system (i.e. not the boot loader).
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
.equ clock=1000000 ; Define the clock frequency
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.nolist
|
||||||
|
.include "include/tn84def.inc" ; Define device ATtiny84
|
||||||
|
.list
|
||||||
|
|
||||||
|
.include "./defs.asm"
|
||||||
|
.include "defs_all.asm"
|
||||||
|
.include "common/utils_wait.asm" ; wait macro
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; firmware settings including list of modules used
|
||||||
|
|
||||||
|
.equ FIRMWARE_VERSION_MAJOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_MINOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
|
||||||
|
|
||||||
|
|
||||||
|
#define MODULES_TIMER
|
||||||
|
#define MODULES_COM
|
||||||
|
#define MODULES_COM_WITH_ADDR_PROTO
|
||||||
|
#define MODULES_LED_SIMPLE
|
||||||
|
#define MODULES_TWI_MASTER
|
||||||
|
;#define MODULES_SI7021
|
||||||
|
#define MODULES_STATS
|
||||||
|
; #define MODULES_OWI_MASTER
|
||||||
|
; #define MODULES_DS18B20
|
||||||
|
; #define MODULES_SK6812
|
||||||
|
; #define MODULES_MOTION_LIGHT
|
||||||
|
|
||||||
|
; #define COM_ACCEPT_ALL_DEST
|
||||||
|
#define MODULES_CCS811
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; defines for modules
|
||||||
|
|
||||||
|
;.equ VALUE_ID_SI7021_TEMP = 0x01
|
||||||
|
;.equ VALUE_ID_SI7021_HUM = 0x02
|
||||||
|
|
||||||
|
;.equ VALUE_ID_ADC = 0x03
|
||||||
|
;.equ VALUE_ID_REED1 = 0x04
|
||||||
|
;.equ VALUE_ID_REED2 = 0x05
|
||||||
|
;.equ VALUE_ID_DS18B20_TEMP = 0x06
|
||||||
|
|
||||||
|
;.equ VALUE_ID_LED_NUMLEDS = 0x82
|
||||||
|
;.equ VALUE_ID_LED_RGBW_VALUE = 0x83
|
||||||
|
;.equ VALUE_ID_MAL_RGBW_VALUE = 0x84
|
||||||
|
;.equ VALUE_ID_MAL_ONTIME = 0x85
|
||||||
|
;.equ VALUE_ID_MAL_SOURCE1 = 0x86
|
||||||
|
;.equ VALUE_ID_MAL_SOURCE2 = 0x87
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code segment
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
.org 000000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Reset and interrupt vectors
|
||||||
|
|
||||||
|
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
|
||||||
|
reti ; EXT_INT0
|
||||||
|
rjmp uartBitbangIsrPcint0 ; PCI0
|
||||||
|
reti ; OC1A
|
||||||
|
reti ; OVF1
|
||||||
|
reti ; OVF0
|
||||||
|
reti ; ERDY
|
||||||
|
reti ; ACI
|
||||||
|
reti ; ADCC
|
||||||
|
reti ; OC1B
|
||||||
|
rjmp baseTimerIrqOC0A ; OC0A
|
||||||
|
reti ; OC0B
|
||||||
|
reti ; WATCHDOG
|
||||||
|
reti ; USI_STR
|
||||||
|
reti ; USI_OVF
|
||||||
|
|
||||||
|
|
||||||
|
devInfoBlock: ; 12 bytes
|
||||||
|
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
|
||||||
|
devInfoId: .db 'N', 0
|
||||||
|
devInfoVersion: .db 18, 0 ; version, revision
|
||||||
|
firmwareVersion: .db FIRMWARE_VARIANT_MAIN, FIRMWARE_VERSION_MAJOR
|
||||||
|
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
|
||||||
|
|
||||||
|
firmwareStart: rjmp main
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; includes
|
||||||
|
|
||||||
|
.include "common/utils.asm"
|
||||||
|
.include "common/utils_wait_fixed.asm"
|
||||||
|
.include "common/utils_copy_from_flash.asm"
|
||||||
|
.include "common/utils_copy_sdram.asm"
|
||||||
|
.include "common/crc8.asm"
|
||||||
|
|
||||||
|
.include "modules/basetimer/main.asm"
|
||||||
|
|
||||||
|
#ifdef MODULES_TIMER
|
||||||
|
.include "modules/timer/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"
|
||||||
|
#ifdef MODULES_STATS
|
||||||
|
.include "modules/comproto/msg_recvstats.asm"
|
||||||
|
.include "modules/comproto/msg_sendstats.asm"
|
||||||
|
.include "modules/comproto/msg_sysstats.asm"
|
||||||
|
.include "modules/comproto/msg_memstats.asm"
|
||||||
|
#endif
|
||||||
|
.include "modules/comproto/msg_pong.asm"
|
||||||
|
.include "modules/comproto/msg_value.asm"
|
||||||
|
.include "modules/comproto/msg_device.asm"
|
||||||
|
.include "modules/comproto/msg_reboot.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"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_STATS
|
||||||
|
.include "modules/stats/main.asm"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_TWI_MASTER
|
||||||
|
.include "modules/twimaster/main.asm"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_OWI_MASTER
|
||||||
|
.include "modules/owimaster/main.asm"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_SI7021
|
||||||
|
.include "modules/si7021/main.asm"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_DS18B20
|
||||||
|
.include "modules/ds18b20/main.asm"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_SK6812
|
||||||
|
.include "modules/sk6812/main.asm"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_MOTION_LIGHT
|
||||||
|
.include "modules/ma_light/main.asm"
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_CCS811
|
||||||
|
.include "modules/ccs811/main.asm"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; data in SRAM
|
||||||
|
|
||||||
|
.dseg
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MODULES_DS18B20
|
||||||
|
sramDs18b20Timer: .byte 2
|
||||||
|
sramSendDs18b20TempTimer: .byte 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; data in FLASH
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; timer list
|
||||||
|
|
||||||
|
|
||||||
|
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_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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.include "main_all.asm"
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Called early on system startup. No arguments, no results.
|
||||||
|
|
||||||
|
systemSetSpeed:
|
||||||
|
.if clock == 8000000
|
||||||
|
ldi r16, (1<<CLKPCE)
|
||||||
|
ldi r17, 0
|
||||||
|
out CLKPR, r16
|
||||||
|
out CLKPR, r17
|
||||||
|
.endif
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Called just before rebooting to bootloader. No arguments, no results.
|
||||||
|
|
||||||
|
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:
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
#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:
|
||||||
|
#ifdef MODULES_LED_SIMPLE
|
||||||
|
rcall LedSimple_Every100ms
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_REED
|
||||||
|
rcall REED_Every100ms
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_MOTION_LIGHT
|
||||||
|
rcall MotionLight_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:
|
||||||
|
; get msg code
|
||||||
|
adiw xh:xl, COM2_MSG_OFFS_CMD
|
||||||
|
ld r16, x
|
||||||
|
sbiw xh:xl, COM2_MSG_OFFS_CMD
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
2
avr/devices/x03/uart/.gitignore
vendored
Normal file
2
avr/devices/x03/uart/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.eep.hex
|
||||||
|
*.obj
|
||||||
52
avr/devices/x03/uart/0BUILD
Normal file
52
avr/devices/x03/uart/0BUILD
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml?>
|
||||||
|
|
||||||
|
<gwbuild>
|
||||||
|
|
||||||
|
<target type="AvrHexFile" name="firmware" >
|
||||||
|
|
||||||
|
<includes type="avrasm" >
|
||||||
|
-I $(builddir)
|
||||||
|
-I $(srcdir)
|
||||||
|
-I $(topsrcdir)/avr
|
||||||
|
-I $(topbuilddir)/avr
|
||||||
|
</includes>
|
||||||
|
|
||||||
|
|
||||||
|
<sources type="avrasm" >
|
||||||
|
main.asm
|
||||||
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<target type="AvrHexFile" name="boot" >
|
||||||
|
|
||||||
|
<includes type="avrasm" >
|
||||||
|
-I $(builddir)
|
||||||
|
-I $(srcdir)
|
||||||
|
-I $(topsrcdir)/avr
|
||||||
|
-I $(topbuilddir)/avr
|
||||||
|
</includes>
|
||||||
|
|
||||||
|
|
||||||
|
<sources type="avrasm" >
|
||||||
|
boot.asm
|
||||||
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
<subdirs>
|
||||||
|
</subdirs>
|
||||||
|
|
||||||
|
<extradist>
|
||||||
|
defs.asm
|
||||||
|
</extradist>
|
||||||
|
|
||||||
|
|
||||||
|
</gwbuild>
|
||||||
|
|
||||||
|
|
||||||
162
avr/devices/x03/uart/boot.asm
Normal file
162
avr/devices/x03/uart/boot.asm
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; Source file for base system node on AtTiny 84
|
||||||
|
;
|
||||||
|
; This is for the maintenance system (i.e. the flash loader).
|
||||||
|
;
|
||||||
|
; All definitions and changes should go into this file.
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
.equ clock=1000000 ; Define the clock frequency
|
||||||
|
|
||||||
|
.nolist
|
||||||
|
.include "include/tn84def.inc" ; Define device ATtiny84
|
||||||
|
.list
|
||||||
|
|
||||||
|
.include "defs_all.asm"
|
||||||
|
.include "./defs.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; generic
|
||||||
|
|
||||||
|
.include "common/utils_wait.asm"
|
||||||
|
.include "modules/com2/defs.asm"
|
||||||
|
.include "modules/comproto/defs.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; firmware settings
|
||||||
|
|
||||||
|
.equ FIRMWARE_VERSION_MAJOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_MINOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LED
|
||||||
|
|
||||||
|
.equ LED_DDR = DDRA
|
||||||
|
.equ LED_PORT = PORTA
|
||||||
|
.equ LED_PIN = PINA
|
||||||
|
.equ LED_PINNUM = PORTA3
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code segment
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
.org 0x0000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Reset and interrupt vectors
|
||||||
|
; rjmp start ; Reset vector
|
||||||
|
rjmp main ; Reset vector
|
||||||
|
reti ; EXT_INT0
|
||||||
|
reti ; PCI0
|
||||||
|
reti ; PCI1
|
||||||
|
reti ; WATCHDOG
|
||||||
|
reti ; ICP1
|
||||||
|
reti ; OC1A
|
||||||
|
reti ; OC1B
|
||||||
|
reti ; OVF1
|
||||||
|
reti ; OC0A
|
||||||
|
reti ; OC0B
|
||||||
|
reti ; OVF0
|
||||||
|
reti ; ACI
|
||||||
|
reti ; ADCC
|
||||||
|
reti ; ERDY
|
||||||
|
reti ; USI_STR
|
||||||
|
reti ; USI_OVF
|
||||||
|
|
||||||
|
|
||||||
|
devInfoBlock: ; 12 bytes
|
||||||
|
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
|
||||||
|
devInfoId: .db 'X', 0
|
||||||
|
devInfoVersion: .db 3, 0 ; version, revision
|
||||||
|
firmwareVersion: .db FIRMWARE_VARIANT_BOOT, FIRMWARE_VERSION_MAJOR
|
||||||
|
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
|
||||||
|
|
||||||
|
firmwareStart: rjmp main ; will be overwritten when flashing
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; main code
|
||||||
|
|
||||||
|
|
||||||
|
.org BOOTLOADER_ADDR
|
||||||
|
|
||||||
|
|
||||||
|
main:
|
||||||
|
rjmp bootLoader ; this routine is in modules/flash/proto.asm
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; includes
|
||||||
|
|
||||||
|
.include "modules/uart_bitbang/bytelevel.asm"
|
||||||
|
.include "modules/uart_bitbang/packetlevel.asm"
|
||||||
|
.include "modules/com2/crc.asm"
|
||||||
|
.include "common/crc8.asm"
|
||||||
|
.include "common/utils_wait_fixed.asm"
|
||||||
|
.include "common/utils_copy_from_flash.asm"
|
||||||
|
.include "common/utils_copy_sdram.asm"
|
||||||
|
.include "modules/flash/bootloader.asm"
|
||||||
|
.include "modules/flash/flash.asm"
|
||||||
|
.include "modules/flash/recv.asm"
|
||||||
|
.include "modules/flash/send.asm"
|
||||||
|
.include "modules/flash/wait.asm"
|
||||||
|
.include "modules/flash/hdl_flash_start.asm"
|
||||||
|
.include "modules/flash/hdl_flash_data.asm"
|
||||||
|
.include "modules/flash/hdl_flash_end.asm"
|
||||||
|
.include "modules/flash/flash_rsp.asm"
|
||||||
|
.include "modules/flash/flash_ready.asm"
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
debugStop:
|
||||||
|
cli
|
||||||
|
sbi LED_SIMPLE_DDR, LED_SIMPLE_PINNUM ; out
|
||||||
|
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
|
||||||
|
|
||||||
|
cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN port as input
|
||||||
|
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable internal pullup for ATTN
|
||||||
|
|
||||||
|
ldi r18, 0
|
||||||
|
test_loop1:
|
||||||
|
ldi r16, 100
|
||||||
|
test_loop2:
|
||||||
|
ldi r17, 100
|
||||||
|
test_loop3:
|
||||||
|
Utils_WaitNanoSecs 10000, 0, r22
|
||||||
|
dec r17
|
||||||
|
brne test_loop3
|
||||||
|
dec r16
|
||||||
|
brne test_loop2
|
||||||
|
sbi LED_SIMPLE_PORTIN, LED_SIMPLE_PINNUM ; toggle
|
||||||
|
inc r18
|
||||||
|
mov r19, r18
|
||||||
|
andi r19, 1
|
||||||
|
brne test1
|
||||||
|
sbi COM_ATTN_DDR, COM_ATTN_PIN
|
||||||
|
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN
|
||||||
|
rjmp test_loop1
|
||||||
|
test1:
|
||||||
|
cbi COM_ATTN_DDR, COM_ATTN_PIN
|
||||||
|
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN
|
||||||
|
|
||||||
|
rjmp test_loop1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
72
avr/devices/x03/uart/defs.asm
Normal file
72
avr/devices/x03/uart/defs.asm
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2023 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
;
|
||||||
|
; AtTiny84
|
||||||
|
; --------
|
||||||
|
; VCC 1 14 GND
|
||||||
|
; PB0 2 13 PA0 COM_ATTN1
|
||||||
|
; PB1 3 12 PA1 COM-DATA1
|
||||||
|
; /RESET PB3 4 11 PA2
|
||||||
|
; COM_ATTN2 PB2 5 10 PA3 LED
|
||||||
|
; COM_DATA2 PA7 6 9 PA4
|
||||||
|
; PA6 7 8 PA5
|
||||||
|
; --------
|
||||||
|
;
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.equ BOOTLOADER_ADDR = 0xd00
|
||||||
|
|
||||||
|
.equ FIRMWARE_VARIANT_BOOT = 0
|
||||||
|
.equ FIRMWARE_VARIANT_ROUTER = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; LED module
|
||||||
|
|
||||||
|
.equ LED_SIMPLE_DDR = DDRA
|
||||||
|
.equ LED_SIMPLE_PORT = PORTA
|
||||||
|
.equ LED_SIMPLE_PORTIN = PINA
|
||||||
|
.equ LED_SIMPLE_PINNUM = PORTA3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; COM module
|
||||||
|
|
||||||
|
.equ COM_BIT_LENGTH = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400
|
||||||
|
.equ COM_HALFBIT_LENGTH = 26000 ; see https://de.wikipedia.org/wiki/Universal_Asynchronous_Receiver_Transmitter
|
||||||
|
|
||||||
|
.equ COM_DATA_DDR = DDRA
|
||||||
|
.equ COM_DATA_INPUT = PINA
|
||||||
|
.equ COM_DATA_OUTPUT = PORTA
|
||||||
|
.equ COM_DATA_PIN = PORTA1
|
||||||
|
|
||||||
|
.equ COM_ATTN_DDR = DDRA
|
||||||
|
.equ COM_ATTN_INPUT = PINA
|
||||||
|
.equ COM_ATTN_OUTPUT = PORTA
|
||||||
|
.equ COM_ATTN_PIN = PORTA0
|
||||||
|
|
||||||
|
.equ COM_DATA2_DDR = DDRA
|
||||||
|
.equ COM_DATA2_INPUT = PINA
|
||||||
|
.equ COM_DATA2_OUTPUT = PORTA
|
||||||
|
.equ COM_DATA2_PIN = PORTA7
|
||||||
|
|
||||||
|
.equ COM_ATTN2_DDR = DDRB
|
||||||
|
.equ COM_ATTN2_INPUT = PINB
|
||||||
|
.equ COM_ATTN2_OUTPUT = PORTB
|
||||||
|
.equ COM_ATTN2_PIN = PORTB2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
221
avr/devices/x03/uart/main.asm
Normal file
221
avr/devices/x03/uart/main.asm
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2024 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; Source file for temperature sensor node on AtTiny 84
|
||||||
|
;
|
||||||
|
; This is for the full system (i.e. not the boot loader).
|
||||||
|
;
|
||||||
|
; All definitions and changes should go into this file.
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
; .equ clock=1000000 ; Define the clock frequency
|
||||||
|
.equ clock=8000000 ; Define the clock frequency
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.nolist
|
||||||
|
.include "include/tn84def.inc" ; Define device ATtiny84
|
||||||
|
.list
|
||||||
|
|
||||||
|
.include "defs_all.asm"
|
||||||
|
.include "./defs.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; generic
|
||||||
|
|
||||||
|
|
||||||
|
.include "common/utils_wait.asm"
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; firmware settings including list of modules used
|
||||||
|
|
||||||
|
.equ FIRMWARE_VERSION_MAJOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_MINOR = 0
|
||||||
|
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code segment
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
.org 000000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Reset and interrupt vectors (will be removed as soon as we can flash data over COM)
|
||||||
|
|
||||||
|
; rjmp main ; Reset vector
|
||||||
|
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
|
||||||
|
reti ; EXT_INT0
|
||||||
|
reti ; PCI0
|
||||||
|
reti ; PCI1
|
||||||
|
reti ; WATCHDOG
|
||||||
|
reti ; ICP1
|
||||||
|
reti ; OC1A
|
||||||
|
reti ; OC1B
|
||||||
|
reti ; OVF1
|
||||||
|
rjmp uartIrqIsrOC0A ; OC0A
|
||||||
|
reti ; OC0B
|
||||||
|
reti ; OVF0
|
||||||
|
reti ; ACI
|
||||||
|
reti ; ADCC
|
||||||
|
reti ; ERDY
|
||||||
|
reti ; USI_STR
|
||||||
|
reti ; USI_OVF
|
||||||
|
|
||||||
|
|
||||||
|
devInfoBlock: ; 12 bytes
|
||||||
|
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
|
||||||
|
devInfoId: .db 'X', 0
|
||||||
|
devInfoVersion: .db 3, 0 ; version, revision
|
||||||
|
firmwareVersion: .db FIRMWARE_VARIANT_ROUTER, FIRMWARE_VERSION_MAJOR
|
||||||
|
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
|
||||||
|
|
||||||
|
firmwareStart: rjmp main
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; includes
|
||||||
|
|
||||||
|
.include "common/utils.asm"
|
||||||
|
.include "common/utils_wait_fixed.asm"
|
||||||
|
;.include "common/utils_copy_from_flash.asm"
|
||||||
|
;.include "common/utils_copy_sdram.asm"
|
||||||
|
.include "common/crc8.asm"
|
||||||
|
|
||||||
|
#include "modules/uart_irq/defs.asm"
|
||||||
|
#include "modules/uart_irq/iface.asm"
|
||||||
|
#include "modules/uart_irq/iface1.asm"
|
||||||
|
#include "modules/uart_irq/iface2.asm"
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; data in SRAM
|
||||||
|
|
||||||
|
.dseg
|
||||||
|
|
||||||
|
programRamBegin:
|
||||||
|
ledTimer: .byte 1
|
||||||
|
programRamEnd:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; data in FLASH
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
|
||||||
|
|
||||||
|
main:
|
||||||
|
ldi xh, HIGH(programRamBegin)
|
||||||
|
ldi xl, LOW(programRamBegin)
|
||||||
|
clr r16
|
||||||
|
ldi r17, (programRamEnd-programRamBegin)
|
||||||
|
rcall Utils_FillSram
|
||||||
|
rcall init
|
||||||
|
sbi LED_SIMPLE_DDR, LED_SIMPLE_PINNUM ; out
|
||||||
|
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
|
||||||
|
clr r16
|
||||||
|
sts ledTimer, r16
|
||||||
|
sei
|
||||||
|
main_loop:
|
||||||
|
; rcall writeTestByteToIface2
|
||||||
|
; rcall copyFromIface1To2
|
||||||
|
; brcc main_sleep
|
||||||
|
; rjmp main_loop
|
||||||
|
|
||||||
|
main_sleep:
|
||||||
|
; 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
|
||||||
|
lds r16, ledTimer
|
||||||
|
dec r16
|
||||||
|
sts ledTimer, r16
|
||||||
|
brne main_loop
|
||||||
|
sbi LED_SIMPLE_PORTIN, LED_SIMPLE_PINNUM ; toggle
|
||||||
|
rcall writeTestByteToIface2
|
||||||
|
rjmp main_loop
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
init:
|
||||||
|
rcall systemSetSpeed
|
||||||
|
rcall Utils_Init
|
||||||
|
rcall UART_Irq_InitIface1
|
||||||
|
rcall UART_Irq_InitIface2
|
||||||
|
rcall uart_irq_timer_init
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
copyFromIface1To2:
|
||||||
|
ldi yl, LOW(uartIrqDataIface1)
|
||||||
|
ldi yh, HIGH(uartIrqDataIface1)
|
||||||
|
rcall uart_irq_rdbuf_readbyte
|
||||||
|
brcs copyFromIface1To2_gotOne
|
||||||
|
ret
|
||||||
|
copyFromIface1To2_gotOne:
|
||||||
|
ldi yl, LOW(uartIrqDataIface2)
|
||||||
|
ldi yh, HIGH(uartIrqDataIface2)
|
||||||
|
rcall uart_irq_wrbuf_writebyte
|
||||||
|
sec
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
writeTestByteToIface2:
|
||||||
|
ldi yl, LOW(uartIrqDataIface2)
|
||||||
|
ldi yh, HIGH(uartIrqDataIface2)
|
||||||
|
ldi r16, 0x55
|
||||||
|
rjmp uart_irq_wrbuf_writebyte
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
systemSetSpeed:
|
||||||
|
;.if clock == 8000000
|
||||||
|
ldi r16, (1<<CLKPCE)
|
||||||
|
ldi r17, 0
|
||||||
|
out CLKPR, r16
|
||||||
|
out CLKPR, r17
|
||||||
|
;.endif
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
systemSetBootSpeed:
|
||||||
|
.if clock == 8000000
|
||||||
|
ldi r16, (1<<CLKPCE)
|
||||||
|
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
|
||||||
|
out CLKPR, r16
|
||||||
|
out CLKPR, r17
|
||||||
|
.endif
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -5,25 +5,26 @@
|
|||||||
<subdirs>
|
<subdirs>
|
||||||
basetimer
|
basetimer
|
||||||
bmp280
|
bmp280
|
||||||
|
ccs811
|
||||||
cny70
|
cny70
|
||||||
com2
|
com2
|
||||||
comproto
|
comproto
|
||||||
|
ds18b20
|
||||||
flash
|
flash
|
||||||
lcd
|
lcd
|
||||||
led
|
led
|
||||||
led_simple
|
led_simple
|
||||||
reed
|
|
||||||
si7021
|
|
||||||
stats
|
|
||||||
timer
|
|
||||||
twimaster
|
|
||||||
owimaster
|
|
||||||
ds18b20
|
|
||||||
sk6812
|
|
||||||
ma_light
|
ma_light
|
||||||
motion
|
motion
|
||||||
uart_bitbang
|
owimaster
|
||||||
|
reed
|
||||||
|
si7021
|
||||||
|
sk6812
|
||||||
|
stats
|
||||||
tcrt1000
|
tcrt1000
|
||||||
|
timer
|
||||||
|
twimaster
|
||||||
|
uart_bitbang
|
||||||
</subdirs>
|
</subdirs>
|
||||||
|
|
||||||
</gwbuild>
|
</gwbuild>
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ CCS811_OnTimer_measure:
|
|||||||
lds r16, ccs811ResponseData+4
|
lds r16, ccs811ResponseData+4
|
||||||
andi r16, (1<<CCS811_STATUS_DATAREADY_BIT)
|
andi r16, (1<<CCS811_STATUS_DATAREADY_BIT)
|
||||||
; breq CCS811_OnTimer_ret
|
; breq CCS811_OnTimer_ret
|
||||||
breq CCS811_OnTimer_storetimerret
|
breq CCS811_OnTimer_storetimerret ; jmp if data not ready
|
||||||
lds r16, ccs811Flags
|
lds r16, ccs811Flags
|
||||||
ori r16, CCS811_FLAGS_VALIDDATA
|
ori r16, CCS811_FLAGS_VALIDDATA
|
||||||
sts ccs811Flags, r16
|
sts ccs811Flags, r16
|
||||||
@@ -421,7 +421,6 @@ ccs811SendDebug:
|
|||||||
|
|
||||||
|
|
||||||
ccs811SendCo2:
|
ccs811SendCo2:
|
||||||
ldi r16, 0xff ; destination address
|
|
||||||
ldi r17, VALUE_ID_CO2 ; value id
|
ldi r17, VALUE_ID_CO2 ; value id
|
||||||
ldi r22, AQHOME_VALUETYPE_CO2
|
ldi r22, AQHOME_VALUETYPE_CO2
|
||||||
lds r18, ccs811ResponseData+1 ; value
|
lds r18, ccs811ResponseData+1 ; value
|
||||||
@@ -431,7 +430,6 @@ ccs811SendCo2:
|
|||||||
|
|
||||||
|
|
||||||
ccs811SendTvoc:
|
ccs811SendTvoc:
|
||||||
ldi r16, 0xff ; destination address
|
|
||||||
ldi r17, VALUE_ID_TVOC ; value id
|
ldi r17, VALUE_ID_TVOC ; value id
|
||||||
ldi r22, AQHOME_VALUETYPE_TVOC
|
ldi r22, AQHOME_VALUETYPE_TVOC
|
||||||
lds r18, ccs811ResponseData+3 ; value
|
lds r18, ccs811ResponseData+3 ; value
|
||||||
@@ -441,6 +439,14 @@ ccs811SendTvoc:
|
|||||||
|
|
||||||
|
|
||||||
ccs811SendAny:
|
ccs811SendAny:
|
||||||
|
mov r16, r18 ; check for FF FF
|
||||||
|
and r16, r19
|
||||||
|
inc r16
|
||||||
|
brne ccs811SendAny_send ; send only if data is not FFFF
|
||||||
|
clc
|
||||||
|
ret
|
||||||
|
ccs811SendAny_send:
|
||||||
|
ldi r16, 0xff ; destination address
|
||||||
ldi r20, 1
|
ldi r20, 1
|
||||||
clr r21
|
clr r21
|
||||||
ldi xl, LOW(com2SendBuffer)
|
ldi xl, LOW(com2SendBuffer)
|
||||||
@@ -464,70 +470,6 @@ ccs811WaitMs_loop2:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; ccs811ReadFirmwareRevision
|
|
||||||
;
|
|
||||||
; Expects interrupts being disabled!
|
|
||||||
; Currently doesn't work (my CCS811 doesn't accept the command).
|
|
||||||
;
|
|
||||||
; IN:
|
|
||||||
; - nothing
|
|
||||||
; OUT:
|
|
||||||
; - CFLAG: set if okay, clear on error
|
|
||||||
; - R16: firmware revision (0xff: version 1.0, 0x20: version 2.0)
|
|
||||||
; USED:
|
|
||||||
|
|
||||||
ccs811ReadFirmwareRevision:
|
|
||||||
rcall twiStart
|
|
||||||
ldi r16, (CCS811_ADDR*2) ; write access
|
|
||||||
rcall twiSendByteExpectAck
|
|
||||||
brcc ccs811ReadFirmwareRevision_error1
|
|
||||||
ldi r16, 0x84
|
|
||||||
rcall twiSendByteExpectAck
|
|
||||||
brcc ccs811ReadFirmwareRevision_error2
|
|
||||||
ldi r16, 0xb8
|
|
||||||
rcall twiSendByteExpectAck
|
|
||||||
brcc ccs811ReadFirmwareRevision_error3
|
|
||||||
rcall twiRestart
|
|
||||||
ldi r16, (CCS811_ADDR*2)+1 ; read access
|
|
||||||
rcall twiSendByteExpectAck
|
|
||||||
brcc ccs811ReadFirmwareRevision_error4
|
|
||||||
rcall twiReceiveByte ; don't send ACK
|
|
||||||
brcc ccs811ReadFirmwareRevision_error5
|
|
||||||
rcall twiStop
|
|
||||||
sec
|
|
||||||
ret
|
|
||||||
|
|
||||||
ccs811ReadFirmwareRevision_error1:
|
|
||||||
ldi r16, 1
|
|
||||||
rcall ccs811SetError
|
|
||||||
rjmp ccs811ReadFirmwareRevision_error
|
|
||||||
ccs811ReadFirmwareRevision_error2:
|
|
||||||
ldi r16, 2
|
|
||||||
rcall ccs811SetError
|
|
||||||
rjmp ccs811ReadFirmwareRevision_error
|
|
||||||
ccs811ReadFirmwareRevision_error3:
|
|
||||||
ldi r16, 3
|
|
||||||
rcall ccs811SetError
|
|
||||||
rjmp ccs811ReadFirmwareRevision_error
|
|
||||||
ccs811ReadFirmwareRevision_error4:
|
|
||||||
ldi r16, 4
|
|
||||||
rcall ccs811SetError
|
|
||||||
rjmp ccs811ReadFirmwareRevision_error
|
|
||||||
ccs811ReadFirmwareRevision_error5:
|
|
||||||
ldi r16, 5
|
|
||||||
rcall ccs811SetError
|
|
||||||
rjmp ccs811ReadFirmwareRevision_error
|
|
||||||
|
|
||||||
ccs811ReadFirmwareRevision_error:
|
|
||||||
rcall twiStop
|
|
||||||
clc
|
|
||||||
ret
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -54,12 +54,12 @@ CNY70_Init:
|
|||||||
rcall Utils_FillSram
|
rcall Utils_FillSram
|
||||||
|
|
||||||
; setup pins
|
; setup pins
|
||||||
sbi CNY70_DDR_LED, CNY70_PINNUM_LED ; set DATA port as output
|
sbi CNY70_LED_DDR, CNY70_LED_PIN ; set DATA port as output
|
||||||
sbi CNY70_PORT_LED, CNY70_PINNUM_LED ; LED off
|
sbi CNY70_LED_PORT, CNY70_LED_PIN ; LED off
|
||||||
cbi CNY70_PORT_ADC, CNY70_PINNUM_ADC ; disable internal pullup for ADC
|
cbi CNY70_ADC_PORT, CNY70_ADC_PIN ; disable internal pullup for ADC
|
||||||
cbi CNY70_DDR_ADC, CNY70_PINNUM_ADC ; set ADC port as input
|
cbi CNY70_ADC_DDR, CNY70_ADC_PIN ; set ADC port as input
|
||||||
|
|
||||||
ldi r16, CNY70_MUX_ADC ; select input pin, use Vcc as reference voltage
|
ldi r16, CNY70_ADC_MUX ; select input pin, use Vcc as reference voltage
|
||||||
out ADMUX, r16
|
out ADMUX, r16
|
||||||
ldi r16, (1 << ADLAR)
|
ldi r16, (1 << ADLAR)
|
||||||
out ADCSRB, r16
|
out ADCSRB, r16
|
||||||
@@ -107,14 +107,14 @@ CNY70_OnTimer:
|
|||||||
sts cny70Flags, r16
|
sts cny70Flags, r16
|
||||||
in r16, ADCH ; read value from ADC
|
in r16, ADCH ; read value from ADC
|
||||||
sts cny70LastData, r16
|
sts cny70LastData, r16
|
||||||
sbi CNY70_PORT_LED, CNY70_PINNUM_LED ; LED off
|
sbi CNY70_LED_PORT, CNY70_LED_PIN ; LED off
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
ret
|
ret
|
||||||
|
|
||||||
CNY70_OnTimer_startConversion:
|
CNY70_OnTimer_startConversion:
|
||||||
cbi CNY70_PORT_LED, CNY70_PINNUM_LED ; LED on
|
cbi CNY70_LED_PORT, CNY70_LED_PIN ; LED on
|
||||||
lds r16, cny70Flags
|
lds r16, cny70Flags
|
||||||
ori r16, CNY70_FLAGS_ADC_STARTED
|
ori r16, CNY70_FLAGS_ADC_STARTED
|
||||||
sts cny70Flags, r16
|
sts cny70Flags, r16
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ This is the inter-node communication protocol.
|
|||||||
Hardware
|
Hardware
|
||||||
========
|
========
|
||||||
|
|
||||||
AqHome uses asynchronous serial communication, nodes are connected via a 4 lines:
|
AqHome uses asynchronous serial communication, nodes are connected via 4 lines:
|
||||||
- 5V
|
- 5V [red]
|
||||||
- GND
|
- GND [black]
|
||||||
- DATA (0V/3.3V)
|
- DATA (0V/3.3V) [green]
|
||||||
- ATTN (0V/3.3V)
|
- ATTN (0V/3.3V) [blue]
|
||||||
|
|
||||||
DATA and ATTN are only pulled low by nodes on the bus, never pulled high, this allows for multi-master
|
DATA and ATTN are only pulled low by nodes on the bus, never pulled high, this allows for multi-master
|
||||||
mode. Every node sends data at will.
|
mode. Every node sends data at will (after checking for free line).
|
||||||
|
|
||||||
|
|
||||||
5V, GND
|
5V, GND
|
||||||
|
|||||||
@@ -61,12 +61,10 @@ COM2_BEGIN:
|
|||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
; Com2_Init
|
; @routine Com2_Init @global
|
||||||
;
|
;
|
||||||
; IN:
|
; @return CFLAG set if okay, clear on error
|
||||||
; OUT:
|
; @clobbers R16, R17, X, Y
|
||||||
; - CFLAG: set if okay, clear on error
|
|
||||||
; USED: R16, R17, X, Y
|
|
||||||
|
|
||||||
Com2_Init:
|
Com2_Init:
|
||||||
; preset SRAM data area
|
; preset SRAM data area
|
||||||
@@ -81,6 +79,7 @@ Com2_Init:
|
|||||||
sts com2Address, r16
|
sts com2Address, r16
|
||||||
|
|
||||||
rjmp COMIO_Init
|
rjmp COMIO_Init
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -151,15 +150,16 @@ com2HandleNextPacketInQueue_retNc:
|
|||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine COM2_WriteMsgWithCmdAndSrcAddr @global
|
||||||
|
;
|
||||||
; Write a simple packet into the given buffer with payload being only CMD and source address.
|
; Write a simple packet into the given buffer with payload being only CMD and source address.
|
||||||
;
|
;
|
||||||
; IN:
|
; IN:
|
||||||
; - R16: destination address
|
; @param R16 destination address
|
||||||
; - R18: command (e.g. CPRO_CMD_PING or CPRO_CMD_PONG)
|
; @param R18 command (e.g. CPRO_CMD_PING or CPRO_CMD_PONG)
|
||||||
; - X : pointer to buffer to write to
|
; @param X pointer to buffer to write to
|
||||||
; OUT:
|
; @return CFLAG set if okay, clear otherwise
|
||||||
; - CFLAG: set if okay, clear otherwise
|
; @clobbers R16, R17, X, Y (R3, R4, R15, R16, R17, R18, R19, R20, R21)
|
||||||
; REGS: R16, R17, X, Y (R3, R4, R15, R16, R17, R18, R19, R20, R21)
|
|
||||||
|
|
||||||
COM2_WriteMsgWithCmdAndSrcAddr:
|
COM2_WriteMsgWithCmdAndSrcAddr:
|
||||||
ldi r17, COM2_PAYLOAD_FLAGS_SECONDS
|
ldi r17, COM2_PAYLOAD_FLAGS_SECONDS
|
||||||
@@ -174,13 +174,15 @@ COM2_WriteMsgWithCmdAndSrcAddr:
|
|||||||
COM2_WriteMsgWithCmdAndSrcAddr_error:
|
COM2_WriteMsgWithCmdAndSrcAddr_error:
|
||||||
clc
|
clc
|
||||||
ret
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine COM2_BeginMsgWithVariablePayload @global
|
||||||
|
;
|
||||||
; begin packet with variable payload.
|
; begin packet with variable payload.
|
||||||
;
|
;
|
||||||
; IN:
|
|
||||||
; @param R16 destination address
|
; @param R16 destination address
|
||||||
; @param R17 flags
|
; @param R17 flags
|
||||||
; @param R18 command (e.g. CPRO_CMD_PING)
|
; @param R18 command (e.g. CPRO_CMD_PING)
|
||||||
@@ -212,6 +214,7 @@ COM2_BeginMsgWithVariablePayload_l1:
|
|||||||
rcall COM2_AddUidToBuffer
|
rcall COM2_AddUidToBuffer
|
||||||
COM2_BeginMsgWithVariablePayload_l2:
|
COM2_BeginMsgWithVariablePayload_l2:
|
||||||
ret
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -246,7 +249,7 @@ COM2_AddUidToBuffer:
|
|||||||
;
|
;
|
||||||
; @return X points to behind written seconds
|
; @return X points to behind written seconds
|
||||||
; @param X pointer to packet buffer
|
; @param X pointer to packet buffer
|
||||||
; @clobbers: r16
|
; @clobbers r16
|
||||||
|
|
||||||
COM2_AddSecsToBuffer:
|
COM2_AddSecsToBuffer:
|
||||||
lds r16, timerModuleCounterSecs ; add current seconds counter
|
lds r16, timerModuleCounterSecs ; add current seconds counter
|
||||||
@@ -292,11 +295,9 @@ COM2_AddNextMsgIdToBuffer:
|
|||||||
;
|
;
|
||||||
; Calculate payload size from given flags
|
; Calculate payload size from given flags
|
||||||
;
|
;
|
||||||
; IN:
|
; @param R16 flags
|
||||||
; - R16: flags
|
; @return R16 payload size
|
||||||
; OUT:
|
; @clobbers R4, R16, R17
|
||||||
; - R16: payload size
|
|
||||||
; MODIFIED REGS: R4, R16, R17
|
|
||||||
|
|
||||||
com2CalcPayloadSize:
|
com2CalcPayloadSize:
|
||||||
clr r4
|
clr r4
|
||||||
@@ -312,6 +313,7 @@ com2CalcPayloadSize_l2:
|
|||||||
lsr r16 ; shift out reserved1, after this R16 contains COM2_PAYLOAD_FLAGS_NUM0-4
|
lsr r16 ; shift out reserved1, after this R16 contains COM2_PAYLOAD_FLAGS_NUM0-4
|
||||||
add r16, r4 ; add previous bytes to R16
|
add r16, r4 ; add previous bytes to R16
|
||||||
ret
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -321,6 +323,7 @@ com2CalcPayloadSize_l2:
|
|||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
; @routine COM2_SendPacket
|
; @routine COM2_SendPacket
|
||||||
|
;
|
||||||
; send packet from sendBuffer, if line free.
|
; send packet from sendBuffer, if line free.
|
||||||
;
|
;
|
||||||
; @return CFLAG set if okay (packet sent), cleared on error
|
; @return CFLAG set if okay (packet sent), cleared on error
|
||||||
@@ -330,6 +333,7 @@ COM2_SendPacket:
|
|||||||
ldi xl, LOW(com2SendBuffer)
|
ldi xl, LOW(com2SendBuffer)
|
||||||
ldi xh, HIGH(com2SendBuffer)
|
ldi xh, HIGH(com2SendBuffer)
|
||||||
rjmp COMIO_SendPacket
|
rjmp COMIO_SendPacket
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
; ***************************************************************************
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
.equ MOTION_TIMER_REPORT = 20 ; report motion at most every 2s
|
.equ MOTION_TIMER_REPORT = 50 ; report motion at most every 5s
|
||||||
|
|
||||||
|
|
||||||
.dseg
|
.dseg
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ l_end:
|
|||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
; @macro UART_BB_M_WAIT_FOR_PIN_HIGH IN_REG_DATA, IN_PINNUM
|
; @macro UART_BB_M_WAIT_FOR_PIN_HIGH IN_REG_DATA, IN_PINNUM
|
||||||
; 0 1
|
; 0 1
|
||||||
; Wait for a pin to become high
|
; Wait for a pin to become high (up to 1ms)
|
||||||
; @param %0 DATA register for input pin (e.g. PINB)
|
; @param %0 DATA register for input pin (e.g. PINB)
|
||||||
; @param %1 pin number for input (e.g. PORTB1)
|
; @param %1 pin number for input (e.g. PORTB1)
|
||||||
; @return CFLAG set if okay, clear otherwise
|
; @return CFLAG set if okay, clear otherwise
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ uartBitbang_SendPacket:
|
|||||||
brcc uartBitbang_SendPacket_lineBusyError
|
brcc uartBitbang_SendPacket_lineBusyError
|
||||||
|
|
||||||
rcall uartBitbang_WaitForOneBitLength ; wait for one bit duration (R22)
|
rcall uartBitbang_WaitForOneBitLength ; wait for one bit duration (R22)
|
||||||
; rcall uartBitbang_WaitForOneBitLength ; wait for one bit duration (R22)
|
rcall uartBitbang_WaitForOneBitLength ; wait for one bit duration (R22)
|
||||||
|
|
||||||
adiw xh:xl, COM2_MSG_OFFS_MSGLEN
|
adiw xh:xl, COM2_MSG_OFFS_MSGLEN
|
||||||
ld r17, X
|
ld r17, X
|
||||||
|
|||||||
@@ -46,10 +46,20 @@
|
|||||||
.equ UART_IRQ_IFACE_PINFN_WRITEDATA = 2
|
.equ UART_IRQ_IFACE_PINFN_WRITEDATA = 2
|
||||||
.equ UART_IRQ_IFACE_PINFN_WRITEATTN = 3
|
.equ UART_IRQ_IFACE_PINFN_WRITEATTN = 3
|
||||||
|
|
||||||
.equ UART_IRQ_TIME_BITTIME1 = 8
|
.equ UART_IRQ_TIME_BITTIME1 = 4
|
||||||
.equ UART_IRQ_TIME_BITTIME1_5 = 12
|
.equ UART_IRQ_TIME_BITTIME1_5 = 6
|
||||||
.equ UART_IRQ_TIME_BITTIME2 = 16
|
.equ UART_IRQ_TIME_BITTIME2 = 8
|
||||||
.equ UART_IRQ_TIME_BITTIME10 = 80
|
.equ UART_IRQ_TIME_BITTIME10 = 40
|
||||||
|
|
||||||
|
;.equ UART_IRQ_TIME_BITTIME1 = 2
|
||||||
|
;.equ UART_IRQ_TIME_BITTIME1_5 = 3
|
||||||
|
;.equ UART_IRQ_TIME_BITTIME2 = 4
|
||||||
|
;.equ UART_IRQ_TIME_BITTIME10 = 20
|
||||||
|
|
||||||
|
;.equ UART_IRQ_TIME_BITTIME1 = 8
|
||||||
|
;.equ UART_IRQ_TIME_BITTIME1_5 = 12
|
||||||
|
;.equ UART_IRQ_TIME_BITTIME2 = 16
|
||||||
|
;.equ UART_IRQ_TIME_BITTIME10 = 80
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -52,19 +52,23 @@ _readAttnBit:
|
|||||||
_writeDataBit:
|
_writeDataBit:
|
||||||
tst r16
|
tst r16
|
||||||
brne _writeDataBit1
|
brne _writeDataBit1
|
||||||
cbi @0, @3 ; set data line to output (makes it LOW)
|
sbi @0, @3 ; set data line to output
|
||||||
|
cbi @2, @3 ; set line LOW
|
||||||
ret
|
ret
|
||||||
_writeDataBit1:
|
_writeDataBit1:
|
||||||
sbi @0, @3 ; set data line to output (external pullup R makes it HIGH)
|
cbi @0, @3 ; set data line to input (external pullup R makes it HIGH)
|
||||||
|
cbi @2, @3 ; disable internal pullup
|
||||||
ret
|
ret
|
||||||
|
|
||||||
_writeAttnBit:
|
_writeAttnBit:
|
||||||
tst r16
|
tst r16
|
||||||
brne _writeAttnBit1
|
brne _writeAttnBit1
|
||||||
cbi @4, @7 ; set ATTN line to output (makes it LOW)
|
sbi @4, @7 ; set ATTN line to output (makes it LOW)
|
||||||
|
cbi @2, @7 ; set line LOW
|
||||||
ret
|
ret
|
||||||
_writeAttnBit1:
|
_writeAttnBit1:
|
||||||
sbi @4, @7 ; set ATTN line to output (external pullup R makes it HIGH)
|
cbi @4, @7 ; set ATTN line to output (external pullup R makes it HIGH)
|
||||||
|
cbi @2, @7 ; disable internal pullup
|
||||||
ret
|
ret
|
||||||
.endmacro
|
.endmacro
|
||||||
; @end
|
; @end
|
||||||
@@ -166,12 +170,31 @@ uartIrqBase: .byte 4
|
|||||||
UART_IRQ_BEGIN:
|
UART_IRQ_BEGIN:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine UART_Irq_InitIface @global
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @clobbers any
|
||||||
|
|
||||||
|
UART_Irq_InitIface:
|
||||||
|
; preset SRAM data area
|
||||||
|
mov xh, yh
|
||||||
|
mov xl, yl
|
||||||
|
clr r16
|
||||||
|
ldi r17, UART_IRQ_IFACE_SIZE
|
||||||
|
rcall Utils_FillSram
|
||||||
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
; @routine UART_Irq_HandleTick @global
|
; @routine UART_Irq_HandleTick @global
|
||||||
;
|
;
|
||||||
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
; @param Z pointer to IFACE jump table for the given interface
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
; @clobbers any
|
; @clobbers r16, r17, X
|
||||||
|
|
||||||
UART_Irq_HandleTick:
|
UART_Irq_HandleTick:
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER
|
||||||
@@ -181,24 +204,32 @@ UART_Irq_HandleTick:
|
|||||||
std Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER, r16
|
std Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER, r16
|
||||||
UART_Irq_HandleTick_handle:
|
UART_Irq_HandleTick_handle:
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATE
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATE
|
||||||
rjmp uart_irq_JumpToStateFunction
|
rjmp uart_irq_JumpToStateFunction ; (r16, r17, r18, r19, X)
|
||||||
; @end
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; r16: function
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uart_irq_JumpToStateFunction
|
||||||
|
;
|
||||||
|
; @param r16 function
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
|
; @clobbers r16, X (r17)
|
||||||
|
|
||||||
uart_irq_JumpToStateFunction:
|
uart_irq_JumpToStateFunction:
|
||||||
cpi r16, UART_IRQ_STATE_COUNT ; invalid function num?
|
cpi r16, UART_IRQ_STATE_COUNT ; invalid function num?
|
||||||
brcc uart_irq_JumpToStateFunction_end
|
brcc uart_irq_JumpToStateFunction_end
|
||||||
ldi r18, LOW(uart_irq_state_jumptable)
|
ldi xl, LOW(uart_irq_state_jumptable)
|
||||||
ldi r19, HIGH(uart_irq_state_jumptable)
|
ldi xh, HIGH(uart_irq_state_jumptable)
|
||||||
add r18, r16
|
add xl, r16
|
||||||
clr r16
|
clr r16
|
||||||
adc r19, r16
|
adc xh, r16
|
||||||
push r18
|
push xl
|
||||||
push r19
|
push xh
|
||||||
uart_irq_JumpToStateFunction_end:
|
uart_irq_JumpToStateFunction_end:
|
||||||
ret ; indirect jump to address we just pushed to the stack
|
ret ; indirect jump to address we just pushed to the stack
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -213,48 +244,88 @@ uart_irq_state_jumptable:
|
|||||||
rjmp uart_irq_handle_sendingdatabit
|
rjmp uart_irq_handle_sendingdatabit
|
||||||
rjmp uart_irq_handle_sendingstopbit
|
rjmp uart_irq_handle_sendingstopbit
|
||||||
|
|
||||||
; z=iface jumptable
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uart_irq_ReadDataBit
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
|
; @clobbers r16
|
||||||
|
|
||||||
uart_irq_ReadDataBit:
|
uart_irq_ReadDataBit:
|
||||||
adiw zh:zl, UART_IRQ_IFACE_PINFN_READDATA
|
adiw zh:zl, UART_IRQ_IFACE_PINFN_READDATA
|
||||||
push zl
|
push zl
|
||||||
push zh
|
push zh
|
||||||
sbiw zh:zl, UART_IRQ_IFACE_PINFN_READDATA
|
sbiw zh:zl, UART_IRQ_IFACE_PINFN_READDATA
|
||||||
ret ; indirect jump to address we just pushed to the stack
|
ret ; indirect jump to address we just pushed to the stack
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uart_irq_ReadAttnBit
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
|
; @clobbers r16
|
||||||
|
|
||||||
uart_irq_ReadAttnBit:
|
uart_irq_ReadAttnBit:
|
||||||
adiw zh:zl, UART_IRQ_IFACE_PINFN_READATTN
|
adiw zh:zl, UART_IRQ_IFACE_PINFN_READATTN
|
||||||
push zl
|
push zl
|
||||||
push zh
|
push zh
|
||||||
sbiw zh:zl, UART_IRQ_IFACE_PINFN_READATTN
|
sbiw zh:zl, UART_IRQ_IFACE_PINFN_READATTN
|
||||||
ret ; indirect jump to address we just pushed to the stack
|
ret ; indirect jump to address we just pushed to the stack
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uart_irq_WriteDataBit
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
|
; @clobbers none
|
||||||
|
|
||||||
uart_irq_WriteDataBit:
|
uart_irq_WriteDataBit:
|
||||||
adiw zh:zl, UART_IRQ_IFACE_PINFN_WRITEDATA
|
adiw zh:zl, UART_IRQ_IFACE_PINFN_WRITEDATA
|
||||||
push zl
|
push zl
|
||||||
push zh
|
push zh
|
||||||
sbiw zh:zl, UART_IRQ_IFACE_PINFN_WRITEDATA
|
sbiw zh:zl, UART_IRQ_IFACE_PINFN_WRITEDATA
|
||||||
ret ; indirect jump to address we just pushed to the stack
|
ret ; indirect jump to address we just pushed to the stack
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uart_irq_WriteAttnBit
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
|
; @clobbers none
|
||||||
|
|
||||||
uart_irq_WriteAttnBit:
|
uart_irq_WriteAttnBit:
|
||||||
adiw zh:zl, UART_IRQ_IFACE_PINFN_WRITEATTN
|
adiw zh:zl, UART_IRQ_IFACE_PINFN_WRITEATTN
|
||||||
push zl
|
push zl
|
||||||
push zh
|
push zh
|
||||||
sbiw zh:zl, UART_IRQ_IFACE_PINFN_WRITEATTN
|
sbiw zh:zl, UART_IRQ_IFACE_PINFN_WRITEATTN
|
||||||
ret ; indirect jump to address we just pushed to the stack
|
ret ; indirect jump to address we just pushed to the stack
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
; y=iface sram data
|
; @routine uart_irq_handle_idle
|
||||||
; z=iface jumptable
|
;
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
|
; @clobbers R16
|
||||||
|
|
||||||
uart_irq_handle_idle:
|
uart_irq_handle_idle:
|
||||||
rcall uart_irq_ReadAttnBit
|
rjmp uart_irq_handle_idle_checksend ; DEBUG!!
|
||||||
|
|
||||||
|
rcall uart_irq_ReadAttnBit ; (R16)
|
||||||
tst r16
|
tst r16
|
||||||
brne uart_irq_handle_idle_checksend ; jump if ATTN line high
|
brne uart_irq_handle_idle_checksend ; jump if ATTN line high
|
||||||
; ATTN low, start receiving
|
; ATTN low, start receiving
|
||||||
ldi r16, UART_IRQ_STATE_WAITFORSTARTBIT
|
ldi r16, UART_IRQ_STATE_WAITFORSTARTBIT
|
||||||
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
||||||
@@ -265,25 +336,33 @@ uart_irq_handle_idle_checksend:
|
|||||||
; check whether there is something to send
|
; check whether there is something to send
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_WRITEBUF_USED
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_WRITEBUF_USED
|
||||||
tst r16
|
tst r16
|
||||||
breq uart_irq_handle_idle_end ; nothing to send
|
breq uart_irq_handle_idle_end ; nothing to send
|
||||||
; start sending
|
; start sending
|
||||||
clr r16
|
clr r16
|
||||||
rcall uart_irq_WriteAttnBit
|
rcall uart_irq_WriteAttnBit ; (none)
|
||||||
ldi r16, UART_IRQ_STATE_SENDINGATTN
|
ldi r16, UART_IRQ_STATE_SENDINGATTN
|
||||||
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
||||||
ldi r16, UART_IRQ_TIME_BITTIME2
|
ldi r16, UART_IRQ_TIME_BITTIME2
|
||||||
std Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER, r16
|
std Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER, r16
|
||||||
uart_irq_handle_idle_end:
|
uart_irq_handle_idle_end:
|
||||||
ret
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uart_irq_handle_waitforstartbit
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
|
; @clobbers R16
|
||||||
|
|
||||||
uart_irq_handle_waitforstartbit:
|
uart_irq_handle_waitforstartbit:
|
||||||
rcall uart_irq_ReadAttnBit
|
rcall uart_irq_ReadAttnBit ; (R16)
|
||||||
tst r16
|
tst r16
|
||||||
brne uart_irq_handle_waitforstartbit_toidle
|
brne uart_irq_handle_waitforstartbit_toidle
|
||||||
; ATTN still low
|
; ATTN still low
|
||||||
rcall uart_irq_ReadDataBit
|
rcall uart_irq_ReadDataBit ; (R16)
|
||||||
tst r16
|
tst r16
|
||||||
breq uart_irq_handle_waitforstartbit_datalow
|
breq uart_irq_handle_waitforstartbit_datalow
|
||||||
; DATA still high
|
; DATA still high
|
||||||
@@ -308,20 +387,28 @@ uart_irq_handle_waitforstartbit_toidle:
|
|||||||
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
||||||
uart_irq_handle_waitforstartbit_end:
|
uart_irq_handle_waitforstartbit_end:
|
||||||
ret
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uart_irq_handle_waitfordatabit
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
|
; @clobbers R16
|
||||||
|
|
||||||
uart_irq_handle_waitfordatabit:
|
uart_irq_handle_waitfordatabit:
|
||||||
rcall uart_irq_ReadAttnBit
|
rcall uart_irq_ReadAttnBit ; (R16)
|
||||||
tst r16
|
tst r16
|
||||||
brne uart_irq_handle_waitfordatabit_toidle
|
brne uart_irq_handle_waitfordatabit_toidle
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER
|
||||||
tst r16
|
tst r16
|
||||||
brne uart_irq_handle_waitfordatabit_end
|
brne uart_irq_handle_waitfordatabit_end
|
||||||
; counter=0: read data
|
; counter=0: read data
|
||||||
rcall uart_irq_ReadDataBit
|
rcall uart_irq_ReadDataBit ; (R16)
|
||||||
ror r16 ; rotate bit into carry flag
|
ror r16 ; rotate bit into carry flag
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATEDATA ; doesn't change carry flag
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATEDATA ; doesn't change carry flag
|
||||||
ror r16 ; rotate carry flag into data byte
|
ror r16 ; rotate carry flag into data byte
|
||||||
std Y+UART_IRQ_IFACE_OFFS_STATEDATA, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATEDATA, r16
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATECOUNTER
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATECOUNTER
|
||||||
@@ -341,11 +428,19 @@ uart_irq_handle_waitfordatabit_toidle:
|
|||||||
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
||||||
uart_irq_handle_waitfordatabit_end:
|
uart_irq_handle_waitfordatabit_end:
|
||||||
ret
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uart_irq_handle_waitforstopbit
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
|
; @clobbers R16 (R17, X)
|
||||||
|
|
||||||
uart_irq_handle_waitforstopbit:
|
uart_irq_handle_waitforstopbit:
|
||||||
rcall uart_irq_ReadAttnBit
|
rcall uart_irq_ReadAttnBit ; (R16)
|
||||||
tst r16
|
tst r16
|
||||||
brne uart_irq_handle_waitforstopbit_toidle
|
brne uart_irq_handle_waitforstopbit_toidle
|
||||||
rcall uart_irq_ReadDataBit
|
rcall uart_irq_ReadDataBit
|
||||||
@@ -358,7 +453,7 @@ uart_irq_handle_waitforstopbit:
|
|||||||
rjmp uart_irq_handle_waitforstopbit_end
|
rjmp uart_irq_handle_waitforstopbit_end
|
||||||
uart_irq_handle_waitforstopbit_datahigh:
|
uart_irq_handle_waitforstopbit_datahigh:
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATEDATA ; store received byte
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATEDATA ; store received byte
|
||||||
rcall uart_irq_rdbuf_writebyte
|
rcall uart_irq_rdbuf_writebyte ; (R17, X)
|
||||||
brcc uart_irq_handle_waitforstopbit_abortmsg ; readbuffer full, abort
|
brcc uart_irq_handle_waitforstopbit_abortmsg ; readbuffer full, abort
|
||||||
ldi r16, UART_IRQ_STATE_WAITFORSTARTBIT ; wait for next byte
|
ldi r16, UART_IRQ_STATE_WAITFORSTARTBIT ; wait for next byte
|
||||||
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
||||||
@@ -374,11 +469,19 @@ uart_irq_handle_waitforstopbit_toidle:
|
|||||||
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
||||||
uart_irq_handle_waitforstopbit_end:
|
uart_irq_handle_waitforstopbit_end:
|
||||||
ret
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uart_irq_handle_waitforattnhigh
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
|
; @clobbers R16
|
||||||
|
|
||||||
uart_irq_handle_waitforattnhigh:
|
uart_irq_handle_waitforattnhigh:
|
||||||
rcall uart_irq_ReadAttnBit
|
rcall uart_irq_ReadAttnBit ; (R16)
|
||||||
tst r16
|
tst r16
|
||||||
breq uart_irq_handle_waitforattnhigh_end ; still low
|
breq uart_irq_handle_waitforattnhigh_end ; still low
|
||||||
uart_irq_handle_waitforattnhigh_toidle:
|
uart_irq_handle_waitforattnhigh_toidle:
|
||||||
@@ -386,36 +489,52 @@ uart_irq_handle_waitforattnhigh_toidle:
|
|||||||
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
||||||
uart_irq_handle_waitforattnhigh_end:
|
uart_irq_handle_waitforattnhigh_end:
|
||||||
ret
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uart_irq_handle_sendingattn
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
|
; @clobbers R16
|
||||||
|
|
||||||
uart_irq_handle_sendingattn:
|
uart_irq_handle_sendingattn:
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER
|
||||||
tst r16
|
tst r16
|
||||||
brne uart_irq_handle_sendingattn_end
|
brne uart_irq_handle_sendingattn_end
|
||||||
; send start bit
|
; send start bit
|
||||||
clr r16
|
clr r16
|
||||||
rcall uart_irq_WriteDataBit
|
rcall uart_irq_WriteDataBit ; (none)
|
||||||
ldi r16, UART_IRQ_STATE_SENDINGSTARTBIT
|
ldi r16, UART_IRQ_STATE_SENDINGSTARTBIT
|
||||||
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
||||||
ldi r16, UART_IRQ_TIME_BITTIME1
|
ldi r16, UART_IRQ_TIME_BITTIME1
|
||||||
std Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER, r16
|
std Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER, r16
|
||||||
uart_irq_handle_sendingattn_end:
|
uart_irq_handle_sendingattn_end:
|
||||||
ret
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uart_irq_handle_sendingstartbit
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
|
; @clobbers R16 (R17, X)
|
||||||
|
|
||||||
uart_irq_handle_sendingstartbit:
|
uart_irq_handle_sendingstartbit:
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER
|
||||||
tst r16
|
tst r16
|
||||||
brne uart_irq_handle_sendingstartbit_end
|
brne uart_irq_handle_sendingstartbit_end
|
||||||
; store current data byte from ringbuffer
|
; get current data byte from ringbuffer
|
||||||
rcall uart_irq_wrbuf_readbyte
|
rcall uart_irq_wrbuf_readbyte ; (R17, X)
|
||||||
std Y+UART_IRQ_IFACE_OFFS_STATEDATA, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATEDATA, r16
|
||||||
; send data bit
|
; send data bit
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATEDATA
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATEDATA
|
||||||
andi r16, 1
|
andi r16, 1
|
||||||
rcall uart_irq_WriteDataBit
|
rcall uart_irq_WriteDataBit ; (none)
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATEDATA
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATEDATA
|
||||||
ror r16
|
ror r16
|
||||||
std Y+UART_IRQ_IFACE_OFFS_STATEDATA, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATEDATA, r16
|
||||||
@@ -427,9 +546,17 @@ uart_irq_handle_sendingstartbit:
|
|||||||
std Y+UART_IRQ_IFACE_OFFS_STATECOUNTER, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATECOUNTER, r16
|
||||||
uart_irq_handle_sendingstartbit_end:
|
uart_irq_handle_sendingstartbit_end:
|
||||||
ret
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uart_irq_handle_sendingdatabit
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
|
; @clobbers R16
|
||||||
|
|
||||||
uart_irq_handle_sendingdatabit:
|
uart_irq_handle_sendingdatabit:
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER
|
||||||
tst r16
|
tst r16
|
||||||
@@ -442,26 +569,34 @@ uart_irq_handle_sendingdatabit:
|
|||||||
; send next data bit
|
; send next data bit
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATEDATA
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATEDATA
|
||||||
andi r16, 1
|
andi r16, 1
|
||||||
rcall uart_irq_WriteDataBit
|
rcall uart_irq_WriteDataBit ; (none)
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATEDATA
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_STATEDATA
|
||||||
ror r16
|
ror r16
|
||||||
std Y+UART_IRQ_IFACE_OFFS_STATEDATA, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATEDATA, r16
|
||||||
ldi r16, UART_IRQ_TIME_BITTIME1 ; send next bit
|
ldi r16, UART_IRQ_TIME_BITTIME1 ; send next bit
|
||||||
std Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER, r16
|
std Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER, r16
|
||||||
rjmp uart_irq_handle_sendingstartbit_end
|
rjmp uart_irq_handle_sendingstartbit_end
|
||||||
uart_irq_handle_sendingdatabit_tosendstopbit:
|
uart_irq_handle_sendingdatabit_tosendstopbit:
|
||||||
; send stop bit
|
; send stop bit
|
||||||
ldi r16, 1
|
ldi r16, 1
|
||||||
rcall uart_irq_WriteDataBit
|
rcall uart_irq_WriteDataBit ; (none)
|
||||||
ldi r16, UART_IRQ_STATE_SENDINGSTOPBIT
|
ldi r16, UART_IRQ_STATE_SENDINGSTOPBIT
|
||||||
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
||||||
ldi r16, UART_IRQ_TIME_BITTIME1
|
ldi r16, UART_IRQ_TIME_BITTIME1
|
||||||
std Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER, r16
|
std Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER, r16
|
||||||
uart_irq_handle_sendingdatabit_end:
|
uart_irq_handle_sendingdatabit_end:
|
||||||
ret
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uart_irq_handle_sendingstopbit
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SRAM (see @ref UART_IRQ_IFACE_OFFS_STATE)
|
||||||
|
; @param Z pointer to IFACE jump table for the given interface
|
||||||
|
; @clobbers R16
|
||||||
|
|
||||||
uart_irq_handle_sendingstopbit:
|
uart_irq_handle_sendingstopbit:
|
||||||
ldd r16, Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER
|
ldd r16, Y+UART_IRQ_IFACE_OFFS_TICKCOUNTER
|
||||||
tst r16
|
tst r16
|
||||||
@@ -478,7 +613,7 @@ uart_irq_handle_sendingstopbit:
|
|||||||
rjmp uart_irq_handle_sendingstopbit_end
|
rjmp uart_irq_handle_sendingstopbit_end
|
||||||
uart_irq_handle_sendingstopbit_toidle:
|
uart_irq_handle_sendingstopbit_toidle:
|
||||||
ldi r16, 1
|
ldi r16, 1
|
||||||
rcall uart_irq_WriteAttnBit
|
rcall uart_irq_WriteAttnBit ; (none)
|
||||||
ldi r16, UART_IRQ_STATE_IDLE
|
ldi r16, UART_IRQ_STATE_IDLE
|
||||||
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
std Y+UART_IRQ_IFACE_OFFS_STATE, r16
|
||||||
uart_irq_handle_sendingstopbit_end:
|
uart_irq_handle_sendingstopbit_end:
|
||||||
@@ -569,6 +704,84 @@ uart_irq_wrbuf_readbyte:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uart_irq_timer_init
|
||||||
|
;
|
||||||
|
; setup timer0 for irq every 52/4 ns
|
||||||
|
|
||||||
|
uart_irq_timer_init: ; setup timer for IRQ every 52/4 ns
|
||||||
|
ldi r16, (1<<WGM01) | (0<<WGM00) ; CTC mode
|
||||||
|
out TCCR0A, r16
|
||||||
|
|
||||||
|
;
|
||||||
|
; Settings for clock 8Mhz
|
||||||
|
; use timer0 with prescaler 1, OCR0A=104-1 (irq every 13us)
|
||||||
|
;
|
||||||
|
ldi r16, (0<<CS02) | (0<<CS01) | (1<<CS00) ; Prescaler 1
|
||||||
|
out TCCR0B, r16
|
||||||
|
|
||||||
|
; ldi r16, 52-1 ; set timer for 8 times baudrate (fixed to 19200 for now)
|
||||||
|
ldi r16, 104-1 ; set timer for 4 times baudrate (fixed to 19200 for now)
|
||||||
|
; ldi r16, 208-1 ; set timer for 2 times baudrate (fixed to 19200 for now)
|
||||||
|
out OCR0A, r16
|
||||||
|
|
||||||
|
ldi r16, (1<<OCF0A) ; clear pending interrupts
|
||||||
|
.ifdef TIFR0
|
||||||
|
out TIFR0, r16
|
||||||
|
.else
|
||||||
|
out TIFR, r16
|
||||||
|
.endif
|
||||||
|
|
||||||
|
ldi r16, (1<<OCIE0A) ; Timer/Counter0 Output Compare Match A Interrupt Enable
|
||||||
|
.ifdef TIMSK0
|
||||||
|
out TIMSK0, r16
|
||||||
|
.else
|
||||||
|
out TIMSK, r16
|
||||||
|
.endif
|
||||||
|
sec
|
||||||
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine uartIrqIsrOC0A @isr
|
||||||
|
;
|
||||||
|
; OC0A interrupt handler
|
||||||
|
;
|
||||||
|
|
||||||
|
uartIrqIsrOC0A:
|
||||||
|
push r15
|
||||||
|
in r15, SREG
|
||||||
|
push r16
|
||||||
|
push r17
|
||||||
|
push xh
|
||||||
|
push xl
|
||||||
|
push yh
|
||||||
|
push yl
|
||||||
|
push zh
|
||||||
|
push zl
|
||||||
|
push r15
|
||||||
|
rcall UART_Irq_Iface1_HandleTick
|
||||||
|
rcall UART_Irq_Iface2_HandleTick
|
||||||
|
pop r15
|
||||||
|
pop zl
|
||||||
|
pop zh
|
||||||
|
pop yl
|
||||||
|
pop yh
|
||||||
|
pop xl
|
||||||
|
pop xh
|
||||||
|
pop r17
|
||||||
|
pop r16
|
||||||
|
out SREG, r15
|
||||||
|
pop r15
|
||||||
|
reti
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UART_IRQ_END:
|
UART_IRQ_END:
|
||||||
.equ MODULE_SIZE_UART_IRQ = UART_IRQ_END-UART_IRQ_BEGIN
|
.equ MODULE_SIZE_UART_IRQ = UART_IRQ_END-UART_IRQ_BEGIN
|
||||||
|
|||||||
@@ -18,6 +18,21 @@ uartIrqDataIface1: .byte UART_IRQ_IFACE_SIZE
|
|||||||
.cseg
|
.cseg
|
||||||
|
|
||||||
|
|
||||||
|
UART_Irq_InitIface1:
|
||||||
|
ldi yl, LOW(uartIrqDataIface1)
|
||||||
|
ldi yh, HIGH(uartIrqDataIface1)
|
||||||
|
rcall UART_Irq_InitIface
|
||||||
|
; setup pins and interrupts
|
||||||
|
cbi COM_DATA_DDR, COM_DATA_PIN ; set DATA port as input
|
||||||
|
cbi COM_DATA_OUTPUT, COM_DATA_PIN ; disable internal pullup for TXD
|
||||||
|
|
||||||
|
cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN port as input
|
||||||
|
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable internal pullup for ATTN
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UART_Irq_Iface1_HandleTick:
|
UART_Irq_Iface1_HandleTick:
|
||||||
m_uart_irq_handle_tick \
|
m_uart_irq_handle_tick \
|
||||||
COM_DATA_DDR, COM_DATA_INPUT, COM_DATA_OUTPUT, COM_DATA_PIN, \
|
COM_DATA_DDR, COM_DATA_INPUT, COM_DATA_OUTPUT, COM_DATA_PIN, \
|
||||||
@@ -25,3 +40,4 @@ UART_Irq_Iface1_HandleTick:
|
|||||||
uartIrqDataIface1
|
uartIrqDataIface1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
39
avr/modules/uart_irq/iface2.asm
Normal file
39
avr/modules/uart_irq/iface2.asm
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2024 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
|
||||||
|
|
||||||
|
uartIrqDataIface2: .byte UART_IRQ_IFACE_SIZE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
|
||||||
|
|
||||||
|
UART_Irq_InitIface2:
|
||||||
|
ldi yl, LOW(uartIrqDataIface2)
|
||||||
|
ldi yh, HIGH(uartIrqDataIface2)
|
||||||
|
rcall UART_Irq_InitIface
|
||||||
|
; setup pins and interrupts
|
||||||
|
cbi COM_DATA2_DDR, COM_DATA2_PIN ; set DATA port as input
|
||||||
|
cbi COM_DATA2_OUTPUT, COM_DATA2_PIN ; disable internal pullup for TXD
|
||||||
|
|
||||||
|
cbi COM_ATTN2_DDR, COM_ATTN2_PIN ; set ATTN port as input
|
||||||
|
cbi COM_ATTN2_OUTPUT, COM_ATTN2_PIN ; disable internal pullup for ATTN
|
||||||
|
|
||||||
|
|
||||||
|
UART_Irq_Iface2_HandleTick:
|
||||||
|
m_uart_irq_handle_tick \
|
||||||
|
COM_DATA2_DDR, COM_DATA2_INPUT, COM_DATA2_OUTPUT, COM_DATA2_PIN, \
|
||||||
|
COM_ATTN2_DDR, COM_ATTN2_INPUT, COM_ATTN2_OUTPUT, COM_ATTN2_PIN, \
|
||||||
|
uartIrqDataIface2
|
||||||
|
|
||||||
|
|
||||||
@@ -7,6 +7,9 @@
|
|||||||
aqua_n12.xml
|
aqua_n12.xml
|
||||||
aqua_n14.xml
|
aqua_n14.xml
|
||||||
aqua_n15.xml
|
aqua_n15.xml
|
||||||
|
aqua_n16.xml
|
||||||
|
aqua_n17.xml
|
||||||
|
aqua_n18.xml
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
</gwbuild>
|
</gwbuild>
|
||||||
|
|||||||
@@ -9,7 +9,9 @@
|
|||||||
<value name="SI7021_HUM" id="0x02" type="sensor" dataType="rational" modality="humidity" units="%" denom="1" />
|
<value name="SI7021_HUM" id="0x02" type="sensor" dataType="rational" modality="humidity" units="%" denom="1" />
|
||||||
<value name="REED1" id="0x04" type="sensor" dataType="rational" modality="door" />
|
<value name="REED1" id="0x04" type="sensor" dataType="rational" modality="door" />
|
||||||
<value name="REED2" id="0x05" type="sensor" dataType="rational" modality="door" />
|
<value name="REED2" id="0x05" type="sensor" dataType="rational" modality="door" />
|
||||||
<value name="DS18B20_TEMP" id="0x06" type="sensor" dataType="rational" modality="temperature" units="C" denom="16" />
|
<value name="DS18B20_TEMP" id="0x06" type="sensor" dataType="rational" modality="temperature" units="C" denom="16" />
|
||||||
|
<value name="CCS811_CO2" id="0x07" type="sensor" dataType="rational" modality="co2" units="ppm" denom="1" />
|
||||||
|
<value name="CCS811_TVOC" id="0x08" type="sensor" dataType="rational" modality="tvoc" units="ppb" denom="1" />
|
||||||
|
|
||||||
<value name="REEDCONF" id="0x81" type="actor" dataType="int" />
|
<value name="REEDCONF" id="0x81" type="actor" dataType="int" />
|
||||||
</values>
|
</values>
|
||||||
|
|||||||
15
devices/nodes/aqua_n16.xml
Normal file
15
devices/nodes/aqua_n16.xml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
<device name="aqua_n16" driver="nodes">
|
||||||
|
<manufacturer>AQUA</manufacturer>
|
||||||
|
<devicetype>N</devicetype>
|
||||||
|
<deviceversion>16</deviceversion>
|
||||||
|
|
||||||
|
<values>
|
||||||
|
<value name="SI7021_TEMP" id="0x01" type="sensor" dataType="rational" modality="temperature" units="C" denom="100" />
|
||||||
|
<value name="SI7021_HUM" id="0x02" type="sensor" dataType="rational" modality="humidity" units="%" denom="1" />
|
||||||
|
<value name="MOTION" id="0x07" type="sensor" dataType="rational" modality="motion" denom="1" />
|
||||||
|
<value name="DOOR" id="0x08" type="sensor" dataType="rational" modality="door" denom="1" />
|
||||||
|
|
||||||
|
</values>
|
||||||
|
|
||||||
|
</device>
|
||||||
13
devices/nodes/aqua_n17.xml
Normal file
13
devices/nodes/aqua_n17.xml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
<device name="aqua_n17" driver="nodes">
|
||||||
|
<manufacturer>AQUA</manufacturer>
|
||||||
|
<devicetype>N</devicetype>
|
||||||
|
<deviceversion>17</deviceversion>
|
||||||
|
|
||||||
|
<values>
|
||||||
|
<value name="SI7021_TEMP" id="0x01" type="sensor" dataType="rational" modality="temperature" units="C" denom="100" />
|
||||||
|
<value name="SI7021_HUM" id="0x02" type="sensor" dataType="rational" modality="humidity" units="%" denom="1" />
|
||||||
|
<value name="MOTION" id="0x07" type="sensor" dataType="rational" modality="motion" denom="1" />
|
||||||
|
</values>
|
||||||
|
|
||||||
|
</device>
|
||||||
14
devices/nodes/aqua_n18.xml
Normal file
14
devices/nodes/aqua_n18.xml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
<device name="aqua_n18" driver="nodes">
|
||||||
|
<manufacturer>AQUA</manufacturer>
|
||||||
|
<devicetype>N</devicetype>
|
||||||
|
<deviceversion>18</deviceversion>
|
||||||
|
|
||||||
|
<values>
|
||||||
|
<value name="SI7021_TEMP" id="0x01" type="sensor" dataType="rational" modality="temperature" units="C" denom="100" />
|
||||||
|
<value name="SI7021_HUM" id="0x02" type="sensor" dataType="rational" modality="humidity" units="%" denom="1" />
|
||||||
|
<value name="CCS811_CO2" id="0x07" type="sensor" dataType="rational" modality="co2" units="ppm" denom="1" />
|
||||||
|
<value name="CCS811_TVOC" id="0x08" type="sensor" dataType="rational" modality="tvoc" units="ppb" denom="1" />
|
||||||
|
</values>
|
||||||
|
|
||||||
|
</device>
|
||||||
Reference in New Issue
Block a user