329 lines
7.1 KiB
NASM
329 lines
7.1 KiB
NASM
; ***************************************************************************
|
|
; 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.asm"
|
|
.include "./data.asm"
|
|
|
|
.include "devices/all/defs.asm"
|
|
.include "common/utils_wait.asm"
|
|
|
|
|
|
|
|
; ***************************************************************************
|
|
; defines
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; generic
|
|
|
|
.equ NET_BUFFERS_NUM = 6
|
|
.equ NET_BUFFERS_SIZE = 28
|
|
|
|
.equ PROGRAM_SENSOR_INTERVAL_SECS = 60
|
|
.equ PROGRAM_STATS_INTERVAL_MINS = 10
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; 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_CLOCK
|
|
#define MODULES_LED_SIMPLE
|
|
#define MODULES_NETWORK
|
|
#define MODULES_UART_BITBANG
|
|
#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
|
|
;#define MODULES_CCS811
|
|
|
|
#define APPS_NETWORK
|
|
#define APPS_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_CO2 = 0x08
|
|
.equ VALUE_ID_TVOC = 0x09
|
|
|
|
;.equ VALUE_ID_REED_CONF = 0x81
|
|
|
|
.equ VALUE_ID_DEBUG = 0x7f
|
|
|
|
|
|
|
|
|
|
|
|
; ***************************************************************************
|
|
; 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 UART_BitBang_PcintIsr ; 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 DEVICEINFO_ID, 0
|
|
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; version, revision
|
|
firmwareVersion: .db FIRMWARE_VARIANT_TEMP_WINDOW, FIRMWARE_VERSION_MAJOR
|
|
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine firmwareStart @global
|
|
|
|
firmwareStart:
|
|
rjmp main
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine onSystemStart
|
|
|
|
onSystemStart:
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine systemSetSpeed
|
|
;
|
|
; Called every 100ms. Add your routine calls here. No arguments, no results.
|
|
|
|
systemSetSpeed:
|
|
.if clock == 8000000
|
|
ldi r16, (1<<CLKPCE)
|
|
ldi r17, 0
|
|
out CLKPR, r16
|
|
out CLKPR, r17
|
|
.endif
|
|
|
|
.if clock == 1000000
|
|
ldi r16, (1<<CLKPCE)
|
|
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
|
|
out CLKPR, r16
|
|
out CLKPR, r17
|
|
.endif
|
|
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine systemInitHardware
|
|
;
|
|
|
|
systemInitHardware:
|
|
; set all ports as inputs and enable internal pull-up resistors
|
|
ldi r16, 0xff
|
|
clr r17
|
|
.ifdef PORTA
|
|
out DDRA, r17 ; all input
|
|
out PORTA, r16 ; enable pull-up on all
|
|
.endif
|
|
|
|
.ifdef PORTB
|
|
out DDRB, r17 ; all input
|
|
out PORTB, r16 ; enable pull-up on all
|
|
.endif
|
|
|
|
.ifdef PORTC
|
|
out DDRC, r17 ; all input
|
|
out PORTC, r16 ; enable pull-up on all
|
|
.endif
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine onMessageReceived
|
|
;
|
|
; Called on every message received
|
|
|
|
onMessageReceived:
|
|
clc
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine onEvery100ms
|
|
;
|
|
; Called every 100ms. Add your routine calls here. No arguments, no results.
|
|
|
|
onEvery100ms:
|
|
; nothing to do here (all done in devices/all/main.asm)
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine onEverySecond
|
|
|
|
onEverySecond:
|
|
lds r16, programRamSensorTimer
|
|
inc r16
|
|
cpi r16, PROGRAM_SENSOR_INTERVAL_SECS
|
|
brcs onEverySecond_store
|
|
clr r16
|
|
onEverySecond_store:
|
|
sts programRamSensorTimer, r16
|
|
cpi r16, 1
|
|
breq onEverySecond_measureValue1
|
|
cpi r16, 19
|
|
breq onEverySecond_measureValue2
|
|
cpi r16, 39
|
|
breq onEverySecond_sendValue1
|
|
cpi r16, 49
|
|
breq onEverySecond_sendValue2
|
|
ret
|
|
onEverySecond_measureValue1:
|
|
rjmp SI7021_MeasureTemp
|
|
onEverySecond_measureValue2:
|
|
rjmp SI7021_MeasureHumidity
|
|
onEverySecond_sendValue1:
|
|
rjmp SI7021_SendTemperature
|
|
onEverySecond_sendValue2:
|
|
rjmp SI7021_SendHumidity
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine onEveryMinute
|
|
|
|
onEveryMinute:
|
|
rcall checkSendStats
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
onEveryHour:
|
|
onEveryDay:
|
|
ret
|
|
|
|
|
|
|
|
checkSendStats:
|
|
lds r16, programRamStatsTimer
|
|
inc r16
|
|
cpi r16, PROGRAM_STATS_INTERVAL_MINS
|
|
brcs checkSendStats_store
|
|
clr r16
|
|
checkSendStats_store:
|
|
sts programRamStatsTimer, r16
|
|
ldi yl, LOW(netInterfaceData)
|
|
ldi yh, HIGH(netInterfaceData)
|
|
cpi r16, 1
|
|
breq checkSendStats_sendDevice
|
|
cpi r16, 2
|
|
breq checkSendStats_sendTxdStats
|
|
cpi r16, 3
|
|
breq checkSendStats_sendRxdStats
|
|
ret
|
|
checkSendStats_sendTxdStats:
|
|
rjmp AppNetwork_SendTxdStats
|
|
checkSendStats_sendRxdStats:
|
|
rjmp AppNetwork_SendRxdStats
|
|
checkSendStats_sendDevice:
|
|
rjmp AppNetwork_SendDevice
|
|
|
|
|
|
|
|
; ***************************************************************************
|
|
; includes
|
|
|
|
.include "devices/all/includes.asm"
|
|
.include "apps/network/stats.asm"
|
|
.include "modules/network/msg/sendstats-w.asm"
|
|
.include "modules/network/msg/recvstats-w.asm"
|
|
.include "modules/network/msg/device-w.asm"
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; defines for network interface
|
|
|
|
.equ netInterfaceData = uart_bitbang_iface
|
|
|
|
|
|
|