Files
aqhomecontrol/avr/devices/n32/main/main.asm
2026-06-29 22:17:29 +02:00

275 lines
7.2 KiB
NASM

; ***************************************************************************
; copyright : (C) 2026 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 fan controller node on AtTiny 861
;
; 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/tn861Adef.inc" ; Define device ATtiny861A
.list
.include "../defs.asm"
.include "./data.asm"
.include "version.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_io.asm"
.include "common/utils_wait.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
.equ NET_BUFFERS_NUM = 6
.equ NET_MSGNUMINBUF_SIZE = 8 ; max buffer nums in ringbuffer (global incoming)
.equ NET_IFACE_OUTMSGBUF_SIZE = 8 ; max buffer nums in ringbuffer (per interface outbound)
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
; #define MODULES_TIMER
#define MODULES_CLOCK
#define MODULES_LED1
;#define MODULES_LED2
;#define MODULES_LED3
#define MODULES_NETWORK
#define MODULES_COM2W
;#define MODULES_TWI_MASTER
;#define MODULES_LCD
;#define LCD_MINIMAL_FONT
;#define MODULES_SI7021
;#define MODULES_SGP30
;#define MODULES_SGP40
;#define MODULES_STATS
;#define MODULES_OWI_MASTER
;#define MODULES_DS18B20
;#define MODULES_MOTION
;#define MODULES_CCS811
;#define MODULES_BRIGHTNESS
#define MODULES_MULTIFAN
#define APPS_NETWORK
;#define APPS_MOTION
#define APPS_REPORTSENSORS
#define APPS_STATS
; defines for modules
; #define LED1_NETWORK_ACTIVITY
; ---------------------------------------------------------------------------
; defines for values
.equ VALUE_ID_FAN1_DUTY = 0x88 ; 0-99
.equ VALUE_ID_FAN1_SPEED = 0x08 ; RPM
.equ VALUE_ID_FAN2_DUTY = 0x89 ; 0-99
.equ VALUE_ID_FAN2_SPEED = 0x09 ; RPM
.equ VALUE_ID_FAN3_DUTY = 0x8a ; 0-99
.equ VALUE_ID_FAN3_SPEED = 0x0a ; RPM
; ***************************************************************************
; code segment
.cseg
.org 000000
; ---------------------------------------------------------------------------
; Reset and interrupt vectors
rjmp BOOTLOADER_ADDR ; 0x00: Reset vector Reset Vector
reti ; 0x01: INT0 External Interrupt 0
rjmp com2wPcintIsr ; 0x02: PCI Pin Change Interrupt
; rjmp pinChangeIsr ; 0x02: PCI Pin Change Interrupt
reti ; 0x03: OC1A Timer/Counter1 Compare Match 1A
reti ; 0x04: OC1B Timer/Counter1 Compare Match 1B
reti ; 0x05: OVF1 Timer/Counter1 Overflow
reti ; 0x06: OVF0 Timer/Counter0 Overflow
reti ; 0x07: USI_START USI Start
reti ; 0x08: USI_OVF USI Overflow
reti ; 0x09: ERDY EEPROM Ready
reti ; 0x0a: ACI Analog Comparator
reti ; 0x0b: ADCC ADC Conversion Complete
reti ; 0x0c: WDT Watchdog Time-Out
reti ; 0x0d: INT1 External Interrupt 1
rjmp baseTimerIrqOC0A ; 0x0e: OC0A Timer/Counter0 Compare Match A
reti ; 0x0f: OC0B Timer/Counter0 Compare Match B
reti ; 0x10: ICP0 Interrupt Capture Event for Timer/Counter0
reti ; 0x11: OC1D Timer/Counter1 Compare Match D
reti ; 0x12: FAULT_PROT Timer/Counter1 Fault Protection
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 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:
onEverySecond:
onEveryMinute:
onEveryHour:
onEveryDay:
ret
; @end
; ---------------------------------------------------------------------------
; @routine onEveryLoop
;
; Called on every loop (i.e. after awakening from sleep).
;
onEveryLoop:
ret
; @end
; ---------------------------------------------------------------------------
; @routine pinChangeIsr @global @isr
;
; ISR for PCINT0/1
;
; @clobbers: none
pinChangeIsr:
push r15
in r15, SREG
push r18
push r19
inr r18, PINA
inr r19, PINB
push r16
push r17
push r20
push r21
push r22
push r24
push r25
push xl
push xh
push yl
push yh
push r18
mov r16, r19 ; PINB
bigcall MultiFan_CheckPort ; r17, r18, r24, r25, Y
pop r16 ; pop PINA to r16
bigcall COM2W_CheckPort ; (r16, r17, r18, r19, r20, r21, r22, r24, r25, X, Y)
pop yh
pop yl
pop xh
pop xl
pop r25
pop r24
pop r22
pop r21
pop r17
pop r16
pop r19
pop r18
out SREG, r15
pop r15
reti
; @end
; ***************************************************************************
; includes
.include "devices/all/hw_tn861.asm"
.include "devices/all/includes.asm"
.include "common/divide.asm"
; ---------------------------------------------------------------------------
; defines for network interface
.equ netInterfaceData = com2w_iface
deviceCodeEnd:
.if deviceCodeEnd >= BOOTLOADER_ADDR
.warning "Code reaches into boot loader!"
.endif