60 Commits

Author SHA1 Message Date
Martin Preuss
acbe4505b9 ipc2: started working on event-based ipc handling. 2025-01-09 01:42:19 +01:00
Martin Preuss
b2193afa46 added some files to .gitignore. 2025-01-07 22:44:44 +01:00
Martin Preuss
28b130ecd4 aqhome: started rewriting IPC module.
started with basic event interface using unix fd and timers.
2025-01-07 22:43:20 +01:00
Martin Preuss
2ac1182879 etc: fixed a typo. 2025-01-05 00:54:46 +01:00
Martin Preuss
f2d18fceee add device descriptions for n21 and n22. 2025-01-05 00:54:28 +01:00
Martin Preuss
43c23d754c n21: use module TCRT1000 (door sensor). 2025-01-05 00:54:08 +01:00
Martin Preuss
8eee81c682 systemd services: use /var/lib instead of /var/cache for permanent data. 2025-01-05 00:53:04 +01:00
Martin Preuss
34d395bb0b aqhome-mqttlog: read client id from config file if not given as argument. 2025-01-05 00:51:13 +01:00
Martin Preuss
277af02f68 mqtt: added descriptor for old tasmota setup.
Previously I used to rename tasmota plugs to "plugXX". We now use the device
id out of the box.
2025-01-05 00:50:28 +01:00
Martin Preuss
68ef24ea9b si7021: fixed a minor bug. 2025-01-05 00:49:11 +01:00
Martin Preuss
a3d5b33105 mainly built-fixes. 2025-01-01 19:33:32 +01:00
Martin Preuss
a7adf15bf6 avr: call Motion_Run if enabled. 2024-12-17 20:54:07 +01:00
Martin Preuss
a435b995a8 avr: beautifications. 2024-12-17 20:53:18 +01:00
Martin Preuss
9d71ff27a7 avr: cleanup motion module. 2024-12-15 22:54:38 +01:00
Martin Preuss
090e178ed1 tcrt1000: fixed comment. 2024-12-15 22:15:00 +01:00
Martin Preuss
a78e354c28 motion: increased signal stability for motion module. 2024-12-15 22:14:45 +01:00
Martin Preuss
9c87c3e5f3 motion: repeat messages. 2024-12-15 19:56:38 +01:00
Martin Preuss
01133cc35b avr: fixed defs. 2024-12-15 18:21:10 +01:00
Martin Preuss
4dc6031d03 avr: added devices, more work on modules. 2024-12-15 18:20:54 +01:00
Martin Preuss
c3fd458769 avr: renamed some files. 2024-12-15 18:19:09 +01:00
Martin Preuss
433720525d aqhome: handle types for CO2 and TVOC. 2024-12-15 18:17:35 +01:00
Martin Preuss
375ab592ff avr: added ccs811 module (air quality sensor). 2024-12-02 23:57:31 +01:00
Martin Preuss
d2694df67c avr: more work on motion activated light module. 2024-12-02 23:57:06 +01:00
Martin Preuss
2270163837 avr: added module for TCRT1000 (reflex coupler) 2024-12-02 23:55:39 +01:00
Martin Preuss
9282ac3bb2 avr: added defs for motionLight module conf in EEPROM. 2024-11-04 23:29:21 +01:00
Martin Preuss
6f858e3909 avr: use REED_OnPacketReceived and MotionLight_OnPacketReceived. 2024-11-04 23:28:55 +01:00
Martin Preuss
cf26a01bb8 avr: motionLight module now reads/writes its config from/into EEPROM. 2024-11-04 23:28:13 +01:00
Martin Preuss
2e3705946e avr: added SK6812_OnPacketReceived 2024-11-04 23:27:16 +01:00
Martin Preuss
42f76f9d09 avr: added REED_OnPacketReceived 2024-11-04 23:27:00 +01:00
Martin Preuss
bc7a549513 avr: added def and code for CPRO_CMD_DATA 2024-11-03 15:35:32 +01:00
Martin Preuss
f002587aee aqhome: fixed handling of AQH_ValueDataTyp 2024-11-03 15:35:08 +01:00
Martin Preuss
a520b37089 avr: remove code for old LED module. 2024-11-03 15:34:40 +01:00
Martin Preuss
4f628a16c6 avr: added modules to n14 node. 2024-11-03 15:34:21 +01:00
Martin Preuss
630dc2cecb avr: added routine CPRO_ReadValue 2024-11-03 15:33:56 +01:00
Martin Preuss
51a585740d avr: added configurable values for N14 module. 2024-11-03 15:33:37 +01:00
Martin Preuss
dab4980a7a avr: add missing build file. 2024-11-03 15:33:04 +01:00
Martin Preuss
e847130f0c avr: handle ma_light module in main module. 2024-11-03 15:32:46 +01:00
Martin Preuss
4c88c15874 avr: added missing folders. 2024-11-03 15:32:21 +01:00
Martin Preuss
132ec3ce95 avr: added motion_activated_light module. 2024-11-03 15:31:59 +01:00
Martin Preuss
9178a6fca5 avr: indentation changes. 2024-11-03 15:29:16 +01:00
Martin Preuss
eb68e66746 avr: adapted pin defs. 2024-10-31 22:24:42 +01:00
Martin Preuss
b72d474a7f avr: added tests fir uart_irq. 2024-10-31 22:23:58 +01:00
Martin Preuss
2b68bfd3af avr: reduce resend time. 2024-10-31 22:23:28 +01:00
Martin Preuss
e4a0e8557a avr: added routine sk6812SendPattern 2024-10-31 22:23:08 +01:00
Martin Preuss
57bbefdf38 Revert "avr: started working on value manager"
This reverts commit dfad168875.
2024-10-31 18:57:06 +01:00
Martin Preuss
7707cb0a82 avr started working on irq driven uart module.
will be used for routers and usb-serial interface.
2024-10-31 18:50:53 +01:00
Martin Preuss
dfad168875 avr: started working on value manager
will probably not use this since this takes many bytes in flash.
2024-10-31 18:50:08 +01:00
Martin Preuss
7fde61f849 avr: added device n15. 2024-10-28 23:44:58 +01:00
Martin Preuss
8904d33789 avr: implemented motion detector module. 2024-10-28 23:44:34 +01:00
Martin Preuss
d28e20b179 avr: allow for adjustable timing in simple LED module. 2024-10-28 23:44:08 +01:00
Martin Preuss
c5915b5583 avr: more work on bitbang module (works now). 2024-10-28 23:43:19 +01:00
Martin Preuss
2626c4365c avr: add delay when sending messages in boot loader. 2024-10-28 23:42:55 +01:00
Martin Preuss
9c35e7a006 avr: adapted boot firmware to latest changes (mainly switch to uart_bitbang). 2024-10-28 23:42:30 +01:00
Martin Preuss
061438b7c8 avr, aqhome: added modality MOTION. 2024-10-28 23:41:27 +01:00
Martin Preuss
88035efdf9 avr: started working on device n15. 2024-10-25 00:15:45 +02:00
Martin Preuss
3546c93d23 avr: adapted to latest changes in COM2 module (using uartBitbang) 2024-10-25 00:15:24 +02:00
Martin Preuss
e232b4adbf avr: fixed a few errors in new uart_bitbang module. 2024-10-20 23:35:26 +02:00
Martin Preuss
89019f1e60 avr: removed unneeded code. 2024-10-20 23:09:38 +02:00
Martin Preuss
efc91241d9 avr: new uart_bitbang module works now. 2024-10-20 23:09:24 +02:00
Martin Preuss
c90c33ec11 avr: fixed a bug. 2024-10-20 23:08:17 +02:00
162 changed files with 13239 additions and 983 deletions

4
.gitignore vendored
View File

@@ -18,3 +18,7 @@ aqhome-mqtt.pid
aqhome-mqtt.devices
core.*
aqhome.geany
aqhome-nodes.db
aqhome-nodes.db.*

View File

@@ -268,6 +268,9 @@ int _setupMqtt(AQHOME_MQTT *aqh, GWEN_DB_NODE *dbArgs)
mqttPort=GWEN_DB_GetIntValue(dbArgs, "ConfigFile/mqttPort", 0, 1883);
mqttClientId=GWEN_DB_GetCharValue(dbArgs, "mqttClientId", 0, "aqhome-mqttlog");
if (!(mqttClientId && *mqttClientId))
mqttClientId=GWEN_DB_GetCharValue(dbArgs, "ConfigFile/mqttClientId", 0, "aqhome-mqttlog");
mqttKeepAlive=GWEN_DB_GetIntValue(dbArgs, "mqttKeepAlive", 0, 600);
if (mqttAddress && *mqttAddress && mqttPort) {

View File

@@ -65,11 +65,13 @@
<subdirs>
msg
ipc
ipc2
nodes
mqtt
hexfile
data
events
events2
client
</subdirs>
@@ -77,11 +79,13 @@
<useTargets>
aqhmsg
aqhipc
aqhipc2
aqhnodes
aqhmqtt
aqhhexfile
aqhdata
aqhevents
aqhevents2
aqhclient
</useTargets>

View File

@@ -219,11 +219,11 @@ int AQH_ValueDataType_fromString(const char *s)
return AQH_ValueDataType_Uint32;
else if (strcasecmp(s, "rational")==0)
return AQH_ValueDataType_Rational;
else if (strcasecmp(s, "AQH_ValueDataType_Uint8")==0)
else if (strcasecmp(s, "uint8")==0)
return AQH_ValueDataType_Uint8;
else if (strcasecmp(s, "AQH_ValueDataType_Uint16")==0)
else if (strcasecmp(s, "uint16")==0)
return AQH_ValueDataType_Uint16;
else if (strcasecmp(s, "AQH_ValueDataType_Uint32")==0)
else if (strcasecmp(s, "uint32")==0)
return AQH_ValueDataType_Uint32;
}
return AQH_ValueDataType_Unknown;
@@ -259,6 +259,8 @@ int AQH_ValueModality_fromString(const char *s)
return AQH_ValueModality_RGB;
else if (strcasecmp(s, "rgbw")==0)
return AQH_ValueModality_RGBW;
else if (strcasecmp(s, "motion")==0)
return AQH_ValueModality_Motion;
}
return AQH_ValueModality_Unknown;
}
@@ -273,6 +275,7 @@ const char *AQH_ValueModality_toString(int i)
case AQH_ValueModality_Door: return "door";
case AQH_ValueModality_RGB: return "rgb";
case AQH_ValueModality_RGBW: return "rgbw";
case AQH_ValueModality_Motion: return "motion";
case AQH_ValueModality_Unknown:
default: return "unknown";
}
@@ -451,10 +454,10 @@ GWEN_BUFFER *_findFileinPath(const char *pathName, const char *sFilename)
int AQH_ReadDataFromString(int dataType, const char *s, uint16_t *pDataVal, uint16_t *pDataDenom)
{
if (s && *s) {
//DBG_ERROR(NULL, "Reading \"%s\" as datatype %d (%s)", s?s:"<NULL>", dataType, AQH_ValueDataType_toString(dataType));
switch(dataType) {
case AQH_ValueDataType_Int:
case AQH_ValueDataType_Uint8: return _readUint8DataFromString(s, pDataVal, pDataDenom);
case AQH_ValueDataType_Int:
case AQH_ValueDataType_Uint16: return _readUint16DataFromString(s, pDataVal, pDataDenom);
case AQH_ValueDataType_Uint32: return _readUint32DataFromString(s, pDataVal, pDataDenom);
case AQH_ValueDataType_Rational: break;
@@ -469,7 +472,7 @@ int AQH_ReadDataFromString(int dataType, const char *s, uint16_t *pDataVal, uint
int _readUint8DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataDenom)
{
unsigned int v=0;
int v=0;
if (1==sscanf(s, "%i", &v)) {
*pDataVal=v & 0xff;
@@ -483,7 +486,7 @@ int _readUint8DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataD
int _readUint16DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataDenom)
{
unsigned int v=0;
int v=0;
if (1==sscanf(s, "%i", &v)) {
*pDataVal=v & 0xffff;
@@ -497,7 +500,7 @@ int _readUint16DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pData
int _readUint32DataFromString(const char *s, uint16_t *pDataVal, uint16_t *pDataDenom)
{
unsigned long int v=0;
long int v=0;
if (1==sscanf(s, "%li", &v)) {
*pDataVal=(v>>16) & 0xffff;

View File

@@ -41,7 +41,8 @@ enum {
AQH_ValueModality_Humidity,
AQH_ValueModality_Door,
AQH_ValueModality_RGB,
AQH_ValueModality_RGBW
AQH_ValueModality_RGBW,
AQH_ValueModality_Motion
};

View File

@@ -50,6 +50,7 @@
<headers dist="true" >
df_direct.h
df_direct_p.h
</headers>

88
aqhome/events2/0BUILD Normal file
View File

@@ -0,0 +1,88 @@
<?xml?>
<gwbuild>
<target type="ConvenienceLibrary" name="aqhevents2" >
<includes type="c" >
$(gwenhywfar_cflags)
$(aqdatabase_cflags)
-I$(topsrcdir)
-I$(topbuilddir)
</includes>
<includes type="tm2" >
--include=$(builddir)
--include=$(srcdir)
--include=$(aqdatabase_AQDATABASE_TYPEMAKERDIR)/c
</includes>
<define name="BUILDING_AQHOME" />
<setVar name="local/cflags">$(visibility_cflags)</setVar>
<setVar name="tm2flags" >
--api=AQHOME_API
</setVar>
<setVar name="local/typefiles" >
</setVar>
<setVar name="local/built_sources" >
</setVar>
<setVar name="local/built_headers_pub">
</setVar>
<setVar name="local/built_headers_priv" >
</setVar>
<headers dist="false" install="$(pkgincludedir)/data" >
$(local/built_headers_pub)
</headers>
<headers dist="true" install="$(pkgincludedir)/data" >
eventloop.h
object.h
fdobject.h
</headers>
<headers dist="true" >
eventloop_p.h
object_p.h
fdobject_p.h
</headers>
<sources>
$(local/typefiles)
eventloop.c
eventloop_select.c
object.c
fdobject.c
</sources>
<extradist>
</extradist>
<useTargets>
</useTargets>
<subdirs>
</subdirs>
</target>
</gwbuild>

View File

@@ -0,0 +1,79 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "./eventloop_p.h"
#include <gwenhywfar/debug.h>
AQH_EVENT_LOOP *AQH_EventLoop_new()
{
AQH_EVENT_LOOP *eventLoop;
GWEN_NEW_OBJECT(AQH_EVENT_LOOP, eventLoop);
eventLoop->fdObjectList=AQH_Object_List2_new();
eventLoop->timerObjectList=AQH_Object_List2_new();
return eventLoop;
}
void AQH_EventLoop_free(AQH_EVENT_LOOP *eventLoop)
{
if (eventLoop) {
AQH_Object_List2_free(eventLoop->timerObjectList);
AQH_Object_List2_free(eventLoop->fdObjectList);
}
}
void AQH_EventLoop_AddFdObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o)
{
if (eventLoop && o && NULL==AQH_Object_List2_Contains(eventLoop->fdObjectList, o)) {
AQH_Object_List2_PushBack(eventLoop->fdObjectList, o);
}
}
void AQH_EventLoop_DelFdObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o)
{
if (eventLoop && o)
AQH_Object_List2_Remove(eventLoop->fdObjectList, o);
}
void AQH_EventLoop_AddTimerObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o)
{
if (eventLoop && o && NULL==AQH_Object_List2_Contains(eventLoop->timerObjectList, o)) {
AQH_Object_List2_PushBack(eventLoop->timerObjectList, o);
}
}
void AQH_EventLoop_DelTimerObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o)
{
if (eventLoop && o)
AQH_Object_List2_Remove(eventLoop->timerObjectList, o);
}

View File

@@ -0,0 +1,32 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQH_EVENTLOOP_H
#define AQH_EVENTLOOP_H
typedef struct AQH_EVENT_LOOP AQH_EVENT_LOOP;
#include <aqhome/events2/object.h>
AQHOME_API AQH_EVENT_LOOP *AQH_EventLoop_new();
AQHOME_API void AQH_EventLoop_free(AQH_EVENT_LOOP *eventLoop);
AQHOME_API void AQH_EventLoop_Run(AQH_EVENT_LOOP *eventLoop);
AQHOME_API void AQH_EventLoop_AddFdObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o);
AQHOME_API void AQH_EventLoop_DelFdObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o);
AQHOME_API void AQH_EventLoop_AddTimerObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o);
AQHOME_API void AQH_EventLoop_DelTimerObject(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *o);
#endif

View File

@@ -0,0 +1,25 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQH_EVENTLOOP_P_H
#define AQH_EVENTLOOP_P_H
#include "./eventloop.h"
struct AQH_EVENT_LOOP
{
AQH_OBJECT_LIST2 *fdObjectList;
AQH_OBJECT_LIST2 *timerObjectList;
};
#endif

View File

@@ -0,0 +1,173 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "./eventloop_p.h"
#include "./fdobject.h"
#include <gwenhywfar/debug.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/select.h>
#include <errno.h>
#include <string.h>
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static int _sampleFdsIntoSet(AQH_OBJECT_LIST2 *ol, fd_set *fds, int mode);
static void _markReadyFdObjects(AQH_OBJECT_LIST2 *ol, fd_set *fds, int mode);
static void _signalReadyFdObjects(AQH_OBJECT_LIST2 *ol);
/* ------------------------------------------------------------------------------------------------
* code
* ------------------------------------------------------------------------------------------------
*/
void AQH_EventLoop_Run(AQH_EVENT_LOOP *eventLoop)
{
fd_set fdRead;
fd_set fdWrite;
int highestFd=-1;
int rv;
FD_ZERO(&fdRead);
FD_ZERO(&fdWrite);
highestFd=_sampleFdsIntoSet(eventLoop->fdObjectList, &fdRead, AQH_FDOBJECT_FDMODE_READ);
rv=_sampleFdsIntoSet(eventLoop->fdObjectList, &fdWrite, AQH_FDOBJECT_FDMODE_WRITE);
highestFd=(rv>highestFd)?rv:highestFd;
if (highestFd>-1) {
struct timeval tv;
tv.tv_sec=0;
tv.tv_usec=200000;
rv=select(highestFd+1, &fdRead, &fdWrite, NULL, &tv);
if (rv>0) {
/* some fds became active */
_markReadyFdObjects(eventLoop->fdObjectList, &fdRead, AQH_FDOBJECT_FDMODE_READ);
_markReadyFdObjects(eventLoop->fdObjectList, &fdWrite, AQH_FDOBJECT_FDMODE_WRITE);
_signalReadyFdObjects(eventLoop->fdObjectList);
}
else if (rv<0) {
if (errno!=EINTR) {
/* error */
DBG_ERROR(AQH_LOGDOMAIN, "Error on SELECT: %d (%s)", errno, strerror(errno));
}
}
else {
/* no fd became active (TODO: maybe signal deep idle objects?) */
}
}
}
int _sampleFdsIntoSet(AQH_OBJECT_LIST2 *ol, fd_set *fds, int mode)
{
AQH_OBJECT_LIST2_ITERATOR *it;
int highestFd=-1;
it=AQH_Object_List2_First(ol);
if (it) {
AQH_OBJECT *o;
o=AQH_Object_List2Iterator_Data(it);
while(o) {
int m;
m=AQH_FdObject_GetFdMode(o);
if (m==mode) {
int fd;
fd=AQH_FdObject_GetFd(o);
if (fd>-1) {
highestFd=(fd>highestFd)?fd:highestFd;
FD_SET(fd, fds);
}
}
o=AQH_Object_List2Iterator_Next(it);
}
AQH_Object_List2Iterator_free(it);
}
return highestFd;
}
void _markReadyFdObjects(AQH_OBJECT_LIST2 *ol, fd_set *fds, int mode)
{
AQH_OBJECT_LIST2_ITERATOR *it;
it=AQH_Object_List2_First(ol);
if (it) {
AQH_OBJECT *o;
o=AQH_Object_List2Iterator_Data(it);
while(o) {
int m;
m=AQH_FdObject_GetFdMode(o);
if (m==mode) {
int fd;
fd=AQH_FdObject_GetFd(o);
if (FD_ISSET(fd, fds))
AQH_Object_AddFlags(o, AQH_OBJECT_FLAGS_FIRE);
}
o=AQH_Object_List2Iterator_Next(it);
}
AQH_Object_List2Iterator_free(it);
}
}
void _signalReadyFdObjects(AQH_OBJECT_LIST2 *ol)
{
AQH_OBJECT_LIST2_ITERATOR *it;
it=AQH_Object_List2_First(ol);
if (it) {
AQH_OBJECT *o;
o=AQH_Object_List2Iterator_Data(it);
while(o) {
if (AQH_Object_GetFlags(o) & AQH_OBJECT_FLAGS_FIRE) {
AQH_Object_SubFlags(o, AQH_OBJECT_FLAGS_FIRE);
AQH_Object_EmitSignal(o, AQH_FDOBJECT_SIGNAL_ISREADY, 0, NULL);
}
o=AQH_Object_List2Iterator_Next(it);
}
AQH_Object_List2Iterator_free(it);
}
}

192
aqhome/events2/fdobject.c Normal file
View File

@@ -0,0 +1,192 @@
/****************************************************************************
* This file is part of the project Gwenhywfar.
* Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "./fdobject_p.h"
#include <gwenhywfar/inherit.h>
#include <gwenhywfar/debug.h>
#include <sys/socket.h>
#include <errno.h>
#include <string.h>
GWEN_INHERIT(AQH_OBJECT, AQH_FDOBJECT)
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
static void _cbEnable(AQH_OBJECT *o);
static void _cbDisable(AQH_OBJECT *o);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
AQH_OBJECT *AQH_FdObject_new(AQH_EVENT_LOOP *eventLoop, int fd, int mode)
{
AQH_OBJECT *o;
AQH_FDOBJECT *xo;
o=AQH_Object_new(eventLoop);
GWEN_NEW_OBJECT(AQH_FDOBJECT, xo);
GWEN_INHERIT_SETDATA(AQH_OBJECT, AQH_FDOBJECT, o, xo, _freeData);
xo->fd=fd;
xo->fdMode=mode;
AQH_Object_SetEnableFn(o, _cbEnable);
AQH_Object_SetDisableFn(o, _cbDisable);
return o;
}
void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
{
AQH_FDOBJECT *xo;
xo=(AQH_FDOBJECT*)p;
GWEN_FREE_OBJECT(xo);
}
int AQH_FdObject_GetFdMode(const AQH_OBJECT *o)
{
if (o) {
AQH_FDOBJECT *xo;
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
if (xo)
return xo->fdMode;
}
return 0;
}
void AQH_FdObject_SetFdMode(AQH_OBJECT *o, int i)
{
if (o) {
AQH_FDOBJECT *xo;
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
if (xo)
xo->fdMode=i;
}
}
int AQH_FdObject_GetFd(const AQH_OBJECT *o)
{
if (o) {
AQH_FDOBJECT *xo;
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
if (xo)
return xo->fd;
}
return -1;
}
int AQH_FdObject_Read(AQH_OBJECT *o, uint8_t *ptrBuffer, uint32_t lenBuffer)
{
if (o && ptrBuffer && lenBuffer) {
AQH_FDOBJECT *xo;
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_FDOBJECT, o);
if (xo) {
if (xo->fd!=-1) {
ssize_t rv;
rv=recv(xo->fd, ptrBuffer, lenBuffer, MSG_DONTWAIT);
if (rv==0) {
DBG_INFO(AQH_LOGDOMAIN, "EOF met");
return 0;
}
else if (rv>0) {
/* data received */
return (int) rv;
}
else {
if (rv==EINTR || errno==EWOULDBLOCK || errno==EAGAIN) {
/* temporarily no data, try again */
return GWEN_ERROR_TRY_AGAIN;
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "Error on read: %s (%d)", strerror(errno), errno);
xo->fd=-1;
return GWEN_ERROR_IO;
}
}
}
else {
DBG_ERROR(AQH_LOGDOMAIN, "Previous error, not reading.");
return GWEN_ERROR_IO;
}
}
}
return GWEN_ERROR_INVALID;
}
void _cbEnable(AQH_OBJECT *o)
{
if (o && !(AQH_Object_GetFlags(o) & AQH_OBJECT_FLAGS_ENABLED)) {
AQH_EVENT_LOOP *eventLoop;
eventLoop=AQH_Object_GetEventLoop(o);
if (eventLoop) {
AQH_EventLoop_AddFdObject(eventLoop, o);
AQH_Object_AddFlags(o, AQH_OBJECT_FLAGS_ENABLED);
}
}
}
void _cbDisable(AQH_OBJECT *o)
{
if (o && (AQH_Object_GetFlags(o) & AQH_OBJECT_FLAGS_ENABLED)) {
AQH_EVENT_LOOP *eventLoop;
eventLoop=AQH_Object_GetEventLoop(o);
if (eventLoop) {
AQH_EventLoop_DelFdObject(eventLoop, o);
AQH_Object_SubFlags(o, AQH_OBJECT_FLAGS_ENABLED);
}
}
}

38
aqhome/events2/fdobject.h Normal file
View File

@@ -0,0 +1,38 @@
/****************************************************************************
* This file is part of the project Gwenhywfar.
* Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQH_FDOBJECT_H
#define AQH_FDOBJECT_H
#include <aqhome/events2/object.h>
enum {
AQH_FDOBJECT_FDMODE_READ=1,
AQH_FDOBJECT_FDMODE_WRITE
};
enum {
AQH_FDOBJECT_SIGNAL_ISREADY=AQH_OBJECT_SIGNAL_LAST
};
AQHOME_API AQH_OBJECT *AQH_FdObject_new(AQH_EVENT_LOOP *eventLoop, int fd, int mode);
AQHOME_API int AQH_FdObject_GetFdMode(const AQH_OBJECT *o);
AQHOME_API void AQH_FdObject_SetFdMode(AQH_OBJECT *o, int i);
AQHOME_API int AQH_FdObject_GetFd(const AQH_OBJECT *o);
AQHOME_API int AQH_FdObject_Read(AQH_OBJECT *o, uint8_t *ptrBuffer, uint32_t lenBuffer);
#endif

View File

@@ -0,0 +1,23 @@
/****************************************************************************
* This file is part of the project Gwenhywfar.
* Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQH_FDOBJECT_P_H
#define AQH_FDOBJECT_P_H
#include "./fdobject.h"
typedef struct AQH_FDOBJECT AQH_FDOBJECT;
struct AQH_FDOBJECT {
int fdMode;
int fd;
};
#endif

276
aqhome/events2/object.c Normal file
View File

@@ -0,0 +1,276 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "./object_p.h"
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
AQH_LINK *AQH_Link_new();
void AQH_Link_free(AQH_LINK *ln);
AQH_LINK *_findLink(AQH_OBJECT *o, uint32_t signalId, uint32_t slotId, AQH_OBJECT *targetObject);
/* ------------------------------------------------------------------------------------------------
* list, inherit
* ------------------------------------------------------------------------------------------------
*/
GWEN_LIST_FUNCTIONS(AQH_LINK, AQH_Link)
GWEN_INHERIT_FUNCTIONS(AQH_OBJECT)
GWEN_LIST_FUNCTIONS(AQH_OBJECT, AQH_Object)
GWEN_LIST2_FUNCTIONS(AQH_OBJECT, AQH_Object)
/* ------------------------------------------------------------------------------------------------
* code
* ------------------------------------------------------------------------------------------------
*/
AQH_OBJECT *AQH_Object_new(AQH_EVENT_LOOP *eventLoop)
{
AQH_OBJECT *o;
GWEN_NEW_OBJECT(AQH_OBJECT, o);
GWEN_INHERIT_INIT(AQH_OBJECT, o);
GWEN_LIST_INIT(AQH_OBJECT, o);
o->eventLoop=eventLoop;
o->linkList=AQH_Link_List_new();
return 0;
}
void AQH_Object_free(AQH_OBJECT *o)
{
if (o) {
GWEN_INHERIT_FINI(AQH_OBJECT, o);
GWEN_LIST_FINI(AQH_OBJECT, o);
AQH_Link_List_free(o->linkList);
GWEN_FREE_OBJECT(o);
}
}
uint32_t AQH_Object_GetFlags(const AQH_OBJECT *o)
{
return o?o->flags:0;
}
void AQH_Object_SetFlags(AQH_OBJECT *o, uint32_t i)
{
if (o)
o->flags=i;
}
void AQH_Object_AddFlags(AQH_OBJECT *o, uint32_t i)
{
if (o)
o->flags|=i;
}
void AQH_Object_SubFlags(AQH_OBJECT *o, uint32_t i)
{
if (o)
o->flags&=~i;
}
AQH_EVENT_LOOP *AQH_Object_GetEventLoop(const AQH_OBJECT *o)
{
return o?o->eventLoop:NULL;
}
AQH_LINK *_findLink(AQH_OBJECT *o, uint32_t signalId, uint32_t slotId, AQH_OBJECT *targetObject)
{
if (o) {
AQH_LINK *ln;
ln=AQH_Link_List_First(o->linkList);
while(ln) {
if (ln->signalIdForSender==signalId &&
ln->signalIdForTarget==slotId &&
ln->targetObject==targetObject)
return ln;
ln=AQH_Link_List_Next(ln);
}
}
return NULL;
}
void AQH_Object_AddLink(AQH_OBJECT *o, uint32_t signalId, uint32_t slotId, AQH_OBJECT *targetObject)
{
AQH_LINK *ln;
ln=_findLink(o, signalId, slotId, targetObject);
if (ln==NULL) {
ln=AQH_Link_new();
ln->signalIdForSender=signalId;
ln->signalIdForTarget=slotId;
ln->targetObject=targetObject;
AQH_Link_List_Add(ln, o->linkList);
}
}
void AQH_Object_DelLink(AQH_OBJECT *o, uint32_t signalId, uint32_t slotId, AQH_OBJECT *targetObject)
{
AQH_LINK *ln;
ln=_findLink(o, signalId, slotId, targetObject);
if (ln) {
AQH_Link_List_Del(ln);
AQH_Link_free(ln);
}
}
int AQH_Object_EmitSignal(AQH_OBJECT *o, uint32_t signalId, int param1, void *param2)
{
int signalWasHandled=0;
if (o) {
AQH_LINK *ln;
ln=AQH_Link_List_First(o->linkList);
while(ln) {
if (ln->signalIdForSender==signalId && ln->targetObject) {
if (AQH_Object_HandleSignal(ln->targetObject, ln->signalIdForTarget, o, param1, param2))
signalWasHandled=1;
}
ln=AQH_Link_List_Next(ln);
}
}
return signalWasHandled;
}
int AQH_Object_HandleSignal(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2)
{
if (o && o->signalHandlerFn)
return o->signalHandlerFn(o, slotId, senderObject, param1, param2);
return 0;
}
void AQH_Object_Enable(AQH_OBJECT *o)
{
if (o && o->enableFn)
o->enableFn(o);
}
void AQH_Object_Disable(AQH_OBJECT *o)
{
if (o && o->disableFn)
o->disableFn(o);
}
AQH_OBJECT_SIGNALHANDLER_FN AQH_Object_SetSignalHandlerFn(AQH_OBJECT *o, AQH_OBJECT_SIGNALHANDLER_FN f)
{
if (o) {
AQH_OBJECT_SIGNALHANDLER_FN oldFn;
oldFn=o->signalHandlerFn;
o->signalHandlerFn=f;
return oldFn;
}
return NULL;
}
AQH_OBJECT_ENABLE_FN AQH_Object_SetEnableFn(AQH_OBJECT *o, AQH_OBJECT_ENABLE_FN f)
{
if (o) {
AQH_OBJECT_ENABLE_FN oldFn;
oldFn=o->enableFn;
o->enableFn=f;
return oldFn;
}
return NULL;
}
AQH_OBJECT_DISABLE_FN AQH_Object_SetDisableFn(AQH_OBJECT *o, AQH_OBJECT_DISABLE_FN f)
{
if (o) {
AQH_OBJECT_DISABLE_FN oldFn;
oldFn=o->disableFn;
o->disableFn=f;
return oldFn;
}
return NULL;
}
AQH_LINK *AQH_Link_new()
{
AQH_LINK *ln;
GWEN_NEW_OBJECT(AQH_LINK, ln);
GWEN_LIST_INIT(AQH_LINK, ln);
return ln;
}
void AQH_Link_free(AQH_LINK *ln)
{
if (ln) {
GWEN_LIST_FINI(AQH_LINK, ln);
GWEN_FREE_OBJECT(ln);
}
}

122
aqhome/events2/object.h Normal file
View File

@@ -0,0 +1,122 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQH_OBJECT_H
#define AQH_OBJECT_H
#include "aqhome/api.h"
#include <gwenhywfar/inherit.h>
#include <gwenhywfar/list.h>
#include <gwenhywfar/list2.h>
#include <stdint.h>
#define AQH_OBJECT_FLAGS_ENABLED 0x80000000L
#define AQH_OBJECT_FLAGS_FIRE 0x40000000L
enum {
AQH_OBJECT_SIGNAL_LAST=10 /* reserve signal ids 0-9 */
};
/* ------------------------------------------------------------------------------------------------
* @name Type Definition
*/
/*@{*/
typedef struct AQH_OBJECT AQH_OBJECT;
GWEN_INHERIT_FUNCTION_LIB_DEFS(AQH_OBJECT, AQHOME_API)
GWEN_LIST_FUNCTION_LIB_DEFS(AQH_OBJECT, AQH_Object, AQHOME_API)
GWEN_LIST2_FUNCTION_LIB_DEFS(AQH_OBJECT, AQH_Object, AQHOME_API)
/*@}*/
#include <aqhome/events2/eventloop.h>
/* ------------------------------------------------------------------------------------------------
* @name Virtual Function Declarations
*/
/*@{*/
typedef int (*AQH_OBJECT_SIGNALHANDLER_FN)(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2);
typedef void (*AQH_OBJECT_ENABLE_FN)(AQH_OBJECT *o);
typedef void (*AQH_OBJECT_DISABLE_FN)(AQH_OBJECT *o);
/*@}*/
/* ------------------------------------------------------------------------------------------------
* @name Construction, Destruction
*/
/*@{*/
AQHOME_API AQH_OBJECT *AQH_Object_new(AQH_EVENT_LOOP *eventLoop);
AQHOME_API void AQH_Object_free(AQH_OBJECT *o);
/*@}*/
/* ------------------------------------------------------------------------------------------------
* @name Manipulate Flags
*/
/*@{*/
AQHOME_API uint32_t AQH_Object_GetFlags(const AQH_OBJECT *o);
AQHOME_API void AQH_Object_SetFlags(AQH_OBJECT *o, uint32_t i);
AQHOME_API void AQH_Object_AddFlags(AQH_OBJECT *o, uint32_t i);
AQHOME_API void AQH_Object_SubFlags(AQH_OBJECT *o, uint32_t i);
/*@}*/
/* ------------------------------------------------------------------------------------------------
* @name Getters, Setters
*/
/*@{*/
AQHOME_API AQH_EVENT_LOOP *AQH_Object_GetEventLoop(const AQH_OBJECT *o);
/*@}*/
/* ------------------------------------------------------------------------------------------------
* @name Link Handling
*/
/*@{*/
AQHOME_API void AQH_Object_AddLink(AQH_OBJECT *o, uint32_t signalId, uint32_t slotId, AQH_OBJECT *targetObject);
AQHOME_API void AQH_Object_DelLink(AQH_OBJECT *o, uint32_t signalId, uint32_t slotId, AQH_OBJECT *targetObject);
/*@}*/
/* ------------------------------------------------------------------------------------------------
* @name Virtual Function Declarations
*/
/*@{*/
AQHOME_API int AQH_Object_EmitSignal(AQH_OBJECT *o, uint32_t signalId, int param1, void *param2);
AQHOME_API int AQH_Object_HandleSignal(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2);
AQHOME_API void AQH_Object_Enable(AQH_OBJECT *o);
AQHOME_API void AQH_Object_Disable(AQH_OBJECT *o);
/*@}*/
/* ------------------------------------------------------------------------------------------------
* @name Setter for Virtual Functions
*/
/*@{*/
AQHOME_API AQH_OBJECT_SIGNALHANDLER_FN AQH_Object_SetSignalHandlerFn(AQH_OBJECT *o, AQH_OBJECT_SIGNALHANDLER_FN f);
AQHOME_API AQH_OBJECT_ENABLE_FN AQH_Object_SetEnableFn(AQH_OBJECT *o, AQH_OBJECT_ENABLE_FN f);
AQHOME_API AQH_OBJECT_DISABLE_FN AQH_Object_SetDisableFn(AQH_OBJECT *o, AQH_OBJECT_DISABLE_FN f);
/*@}*/
#endif

46
aqhome/events2/object_p.h Normal file
View File

@@ -0,0 +1,46 @@
/****************************************************************************
* This file is part of the project Gwenhywfar.
* Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQH_OBJECT_P_H
#define AQH_OBJECT_P_H
#include "./object.h"
typedef struct AQH_LINK AQH_LINK;
GWEN_LIST_FUNCTION_DEFS(AQH_LINK, AQH_Link)
struct AQH_LINK {
GWEN_LIST_ELEMENT(AQH_LINK)
uint32_t signalIdForSender;
uint32_t signalIdForTarget;
AQH_OBJECT *targetObject;
};
struct AQH_OBJECT {
GWEN_INHERIT_ELEMENT(AQH_OBJECT)
GWEN_LIST_ELEMENT(AQH_OBJECT)
uint32_t flags;
AQH_EVENT_LOOP *eventLoop;
AQH_LINK_LIST *linkList;
AQH_OBJECT_SIGNALHANDLER_FN signalHandlerFn;
AQH_OBJECT_ENABLE_FN enableFn;
AQH_OBJECT_DISABLE_FN disableFn;
};
#endif

82
aqhome/ipc2/0BUILD Normal file
View File

@@ -0,0 +1,82 @@
<?xml?>
<gwbuild>
<target type="ConvenienceLibrary" name="aqhipc2" >
<includes type="c" >
$(gwenhywfar_cflags)
-I$(topsrcdir)
-I$(topbuilddir)
</includes>
<includes type="tm2" >
--include=$(builddir)
--include=$(srcdir)
</includes>
<define name="BUILDING_AQHOME" />
<setVar name="local/cflags">$(visibility_cflags)</setVar>
<setVar name="tm2flags" >
--api=AQHOME_API
</setVar>
<setVar name="local/typefiles" >
</setVar>
<setVar name="local/built_sources" >
</setVar>
<setVar name="local/built_headers_pub">
</setVar>
<setVar name="local/built_headers_priv" >
</setVar>
<headers dist="false" install="$(pkgincludedir)/ipc" >
$(local/built_headers_pub)
</headers>
<headers dist="true" install="$(pkgincludedir)/ipc" >
msgreader.h
tcpd_object.h
</headers>
<headers dist="true" >
msgreader_p.h
tcpd_object_p.h
</headers>
<sources>
$(local/typefiles)
msgreader.c
tcpd_object.c
</sources>
<extradist>
</extradist>
<useTargets>
</useTargets>
<subdirs>
</subdirs>
</target>
</gwbuild>

314
aqhome/ipc2/msgreader.c Normal file
View File

@@ -0,0 +1,314 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "./msgreader_p.h"
#include <aqhome/events2/fdobject.h>
#include <gwenhywfar/inherit.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endianfns.h>
#include <sys/socket.h>
#define AQH_MSG_READER_MINMSGSIZE 12
#define AQH_MSG_READER_MAXMSGSIZE 10240
enum {
AQH_MSGREADER_SLOT_SOCKETREADY=1
};
GWEN_INHERIT(AQH_OBJECT, AQH_MSG_READER)
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
static int _handleSignal(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2);
static int _handleSocketReady(AQH_OBJECT *o);
static int _fillRingbuffer(AQH_OBJECT *o);
static int _readMsgFromRingbuffer(AQH_OBJECT *o, AQH_MSG_READER *xo);
static int _readHeaderFromRingbuffer(AQH_MSG_READER *xo);
static int _readRemainderFromRingbuffer(AQH_MSG_READER *xo);
/* ------------------------------------------------------------------------------------------------
* implementation
* ------------------------------------------------------------------------------------------------
*/
AQH_OBJECT *AQH_MsgReader_new(AQH_EVENT_LOOP *eventLoop, int fd)
{
AQH_OBJECT *o;
AQH_MSG_READER *xo;
o=AQH_Object_new(eventLoop);
GWEN_NEW_OBJECT(AQH_MSG_READER, xo);
GWEN_INHERIT_SETDATA(AQH_OBJECT, AQH_MSG_READER, o, xo, _freeData);
xo->fdSocket=fd;
xo->ringBuffer=GWEN_RingBuffer_new(AQH_MSG_READER_RINGBUFFER_SIZE);
AQH_Object_SetSignalHandlerFn(o, _handleSignal);
/* create object for readable socket, connect to THIS, enable */
xo->fdObject=AQH_FdObject_new(AQH_Object_GetEventLoop(o), fd, AQH_FDOBJECT_FDMODE_READ);
AQH_Object_AddLink(xo->fdObject, AQH_FDOBJECT_SIGNAL_ISREADY, AQH_MSGREADER_SLOT_SOCKETREADY, o);
AQH_Object_Enable(xo->fdObject);
return o;
}
void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
{
AQH_MSG_READER *xo;
xo=(AQH_MSG_READER*) p;
if (xo->fdObject) {
AQH_Object_Disable(xo->fdObject);
AQH_Object_free(xo->fdObject);
}
GWEN_FREE_OBJECT(xo);
}
int _handleSignal(AQH_OBJECT *o,
uint32_t slotId,
GWEN_UNUSED AQH_OBJECT *senderObject,
GWEN_UNUSED int param1,
GWEN_UNUSED void *param2)
{
switch(slotId) {
case AQH_MSGREADER_SLOT_SOCKETREADY: return _handleSocketReady(o);
default:
break;
}
return 0; /* not handled */
}
int _handleSocketReady(AQH_OBJECT *o)
{
AQH_MSG_READER *xo;
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
if (xo) {
int rv;
/* read available data into ringbuffer */
rv=_fillRingbuffer(o);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
AQH_Object_EmitSignal(o, AQH_MSG_READER_SIGNAL_ERROR, rv, NULL);
xo->fdSocket=-1;
return 1;
}
/* read messages from ring buffer until buffer empty */
do {
rv=_readMsgFromRingbuffer(o, xo);
} while (rv==1);
if (rv<0) {
AQH_Object_EmitSignal(o, AQH_MSG_READER_SIGNAL_ERROR, rv, NULL);
xo->fdSocket=-1;
}
return 1;
}
return 0;
}
int _fillRingbuffer(AQH_OBJECT *o)
{
AQH_MSG_READER *xo;
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_MSG_READER, o);
if (xo && xo->fdSocket!=-1) {
uint32_t len;
/* read data into ringbuffer */
len=GWEN_RingBuffer_GetMaxUnsegmentedWrite(xo->ringBuffer);
if (len>0) {
int rv;
rv=AQH_FdObject_Read(xo->fdObject, (uint8_t*) GWEN_RingBuffer_GetWritePointer(xo->ringBuffer), len);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
xo->fdSocket=-1;
return rv;
}
else if (rv==0) {
DBG_INFO(AQH_LOGDOMAIN, "EOF met");
xo->fdSocket=-1;
return 0;
}
else {
/* bytes received */
GWEN_RingBuffer_SkipBytesWrite(xo->ringBuffer, rv);
return rv;
}
}
else {
DBG_INFO(AQH_LOGDOMAIN, "Ringbuffer full");
return GWEN_ERROR_BUFFER_OVERFLOW;
}
}
else {
DBG_INFO(AQH_LOGDOMAIN, "fd inactive (previous error or EOF?)");
return GWEN_ERROR_INVALID;
}
}
int _readMsgFromRingbuffer(AQH_OBJECT *o, AQH_MSG_READER *xo)
{
int rv;
if (xo->bytesReceived<AQH_MSG_READER_HEADERBUFFER_SIZE) {
rv=_readHeaderFromRingbuffer(xo);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
}
if (xo->bytesReceived>=AQH_MSG_READER_HEADERBUFFER_SIZE) {
/* reading remainder of msg directly into allocated buffer */
rv=_readRemainderFromRingbuffer(xo);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
else if (rv==1) {
int msgLen;
uint8_t *msgPtr;
msgLen=xo->bytesReceived;
msgPtr=xo->currentMsgBuf;
xo->bytesReceived=0;
xo->bytesLeft=0;
xo->currentMsgBuf=NULL;
rv=AQH_Object_EmitSignal(o, AQH_MSG_READER_SIGNAL_MSGRECVD, msgLen, (void*) msgPtr);
if (rv==0) {
DBG_INFO(AQH_LOGDOMAIN, "Received message ignored");
free(msgPtr);
}
return 1;
}
}
return 0;
}
int _readHeaderFromRingbuffer(AQH_MSG_READER *xo)
{
uint32_t remaining;
int rv;
uint32_t xferSize;
uint32_t bytesInBuffer;
bytesInBuffer=GWEN_RingBuffer_GetUsedBytes(xo->ringBuffer);
/* still reading header */
remaining=AQH_MSG_READER_HEADERBUFFER_SIZE-xo->bytesReceived;
if (bytesInBuffer<remaining)
remaining=bytesInBuffer;
xferSize=remaining;
rv=GWEN_RingBuffer_ReadBytes(xo->ringBuffer, (char*) (xo->headerBuffer+xo->bytesReceived), &xferSize);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
if (xferSize<remaining) {
DBG_ERROR(AQH_LOGDOMAIN, "Read fewer bytes than available?");
return GWEN_ERROR_GENERIC;
}
xo->bytesReceived+=xferSize;
if (xo->bytesReceived==AQH_MSG_READER_HEADERBUFFER_SIZE) {
uint32_t msgLen;
/* full size received, parse msg size, allocate buffer */
msgLen=GWEN_ENDIAN_LE32TOH(*((const uint32_t*)(xo->headerBuffer)));
if (msgLen<AQH_MSG_READER_MINMSGSIZE || msgLen>AQH_MSG_READER_MAXMSGSIZE) {
DBG_ERROR(AQH_LOGDOMAIN, "Bad message size(%lu)", (unsigned long int) msgLen);
return GWEN_ERROR_GENERIC;
}
xo->currentMsgBuf=(uint8_t*) malloc(msgLen+4);
memmove(xo->currentMsgBuf, xo->headerBuffer, xo->bytesReceived);
xo->bytesLeft=(msgLen+4)-xo->bytesReceived;
}
return 0;
}
int _readRemainderFromRingbuffer(AQH_MSG_READER *xo)
{
uint32_t bytesInBuffer;
uint32_t bytesToRead;
int rv;
bytesInBuffer=GWEN_RingBuffer_GetUsedBytes(xo->ringBuffer);
/* still reading header */
bytesToRead=xo->bytesLeft;
if (bytesInBuffer<bytesToRead)
bytesToRead=bytesInBuffer;
if (bytesToRead) {
uint32_t xferSize;
xferSize=bytesToRead;
rv=GWEN_RingBuffer_ReadBytes(xo->ringBuffer, (char*) (xo->currentMsgBuf+xo->bytesReceived), &xferSize);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
if (xferSize<bytesToRead) {
DBG_ERROR(AQH_LOGDOMAIN, "Read fewer bytes than available?");
return GWEN_ERROR_GENERIC;
}
xo->bytesReceived+=xferSize;
xo->bytesLeft-=xferSize;
if (xo->bytesLeft==0) {
/* msg finished */
DBG_INFO(AQH_LOGDOMAIN, "Message complete");
return 1;
}
}
return 0;
}

32
aqhome/ipc2/msgreader.h Normal file
View File

@@ -0,0 +1,32 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQH_MSGREADER_H
#define AQH_MSGREADER_H
#include <aqhome/events2/object.h>
enum {
/** param1=msgSize, param2=msgPointer */
AQH_MSG_READER_SIGNAL_MSGRECVD=AQH_OBJECT_SIGNAL_LAST,
/** param1: error code */
AQH_MSG_READER_SIGNAL_ERROR,
AQH_MSG_READER_SIGNAL_CLOSED
};
AQH_OBJECT *AQH_MsgReader_new(AQH_EVENT_LOOP *eventLoop, int fd);
#endif

38
aqhome/ipc2/msgreader_p.h Normal file
View File

@@ -0,0 +1,38 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQH_MSGREADER_P_H
#define AQH_MSGREADER_P_H
#include "./msgreader.h"
#include <gwenhywfar/ringbuffer.h>
#define AQH_MSG_READER_RINGBUFFER_SIZE 1024
#define AQH_MSG_READER_HEADERBUFFER_SIZE 4
typedef struct AQH_MSG_READER AQH_MSG_READER;
struct AQH_MSG_READER {
int fdSocket;
AQH_OBJECT *fdObject;
GWEN_RINGBUFFER *ringBuffer;
int bytesReceived;
int bytesLeft;
uint8_t headerBuffer[AQH_MSG_READER_HEADERBUFFER_SIZE];
uint8_t *currentMsgBuf;
};
#endif

379
aqhome/ipc2/tcpd_object.c Normal file
View File

@@ -0,0 +1,379 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "./tcpd_object_p.h"
#include <aqhome/events2/fdobject.h>
#include <gwenhywfar/inherit.h>
#include <gwenhywfar/debug.h>
#include <unistd.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include <string.h>
#define MAX_BACKLOG 10
enum {
AQH_TCPD_OBJECT_SLOT_SOCKETREADY=1
};
GWEN_INHERIT(AQH_OBJECT, AQH_TCPD_OBJECT)
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
static int _handleSignal(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2);
static int _handleSocketReady(AQH_OBJECT *o);
static int _createListeningSocket(const char *addr, int port);
static int _socketSetReuseAddress(int sk, int fl);
static int _socketSetBlocking(int sk, int fl);
static int _translateHError(int herr);
static int _setHostAddr(struct in_addr *inetAddr, const char *sAddr);
static int _setHostName(struct in_addr *inetAddr, const char *sAddr);
static int _acceptConnection(int serverSocket);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
AQH_OBJECT *AQH_TcpdObject_new(AQH_EVENT_LOOP *eventLoop)
{
AQH_OBJECT *o;
AQH_TCPD_OBJECT *xo;
o=AQH_Object_new(eventLoop);
GWEN_NEW_OBJECT(AQH_TCPD_OBJECT, xo);
GWEN_INHERIT_SETDATA(AQH_OBJECT, AQH_TCPD_OBJECT, o, xo, _freeData);
xo->fdSocket=-1;
AQH_Object_SetSignalHandlerFn(o, _handleSignal);
return o;
}
void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
{
AQH_TCPD_OBJECT *xo;
xo=(AQH_TCPD_OBJECT*) p;
if (xo->fdObject)
AQH_Object_free(xo->fdObject);
if (xo->fdSocket)
close(xo->fdSocket);
GWEN_FREE_OBJECT(xo);
}
int AQH_TcpdObject_StartListening(AQH_OBJECT *o, const char *addr, int port)
{
if (o) {
AQH_TCPD_OBJECT *xo;
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_TCPD_OBJECT, o);
if (xo) {
if (xo->fdSocket<0) {
int rv;
rv=_createListeningSocket(addr, port);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
xo->fdSocket=rv;
/* create object for readable socket, connect to THIS, enable */
xo->fdObject=AQH_FdObject_new(AQH_Object_GetEventLoop(o), rv, AQH_FDOBJECT_FDMODE_READ);
AQH_Object_AddLink(xo->fdObject, AQH_FDOBJECT_SIGNAL_ISREADY, AQH_TCPD_OBJECT_SLOT_SOCKETREADY, o);
AQH_Object_Enable(xo->fdObject);
}
}
}
return GWEN_ERROR_GENERIC;
}
void AQH_TcpdObject_StopListening(AQH_OBJECT *o)
{
if (o) {
AQH_TCPD_OBJECT *xo;
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_TCPD_OBJECT, o);
if (xo) {
if (xo->fdObject) {
AQH_Object_Disable(xo->fdObject);
AQH_Object_free(xo->fdObject);
xo->fdObject=NULL;
}
if (xo->fdSocket<0) {
close(xo->fdSocket);
xo->fdSocket=-1;
}
}
}
}
int _handleSignal(AQH_OBJECT *o,
uint32_t slotId,
GWEN_UNUSED AQH_OBJECT *senderObject,
GWEN_UNUSED int param1,
GWEN_UNUSED void *param2)
{
switch(slotId) {
case AQH_TCPD_OBJECT_SLOT_SOCKETREADY: return _handleSocketReady(o);
default:
break;
}
return 0; /* not handled */
}
int _handleSocketReady(AQH_OBJECT *o)
{
AQH_TCPD_OBJECT *xo;
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_TCPD_OBJECT, o);
if (xo) {
int clientSk;
clientSk=_acceptConnection(xo->fdSocket);
if (clientSk<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", clientSk);
}
else {
if (0==AQH_Object_EmitSignal(o, AQH_TCPD_OBJECT_SIGNAL_NEWCONN, clientSk, NULL)) {
DBG_INFO(AQH_LOGDOMAIN, "New connection not handled");
close(clientSk);
}
}
return 1; /* handled */
}
return 0; /* not handled */
}
int _createListeningSocket(const char *addr, int port)
{
int sk;
struct sockaddr_in inetAddr;
int rv;
memset(&inetAddr, 0, sizeof(inetAddr));
inetAddr.sin_family=AF_INET;
rv=_setHostAddr(&inetAddr.sin_addr, addr); /* try tuple */
if (rv<0) {
rv=_setHostName(&inetAddr.sin_addr, addr); /* lookup name */
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
}
inetAddr.sin_port=htons(port);
sk=socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sk<0) {
DBG_INFO(AQH_LOGDOMAIN, "socket(): %s", strerror(errno));
return GWEN_ERROR_IO;
}
rv=_socketSetReuseAddress(sk, 1);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
close(sk);
return rv;
}
rv=_socketSetBlocking(sk, 0);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
close(sk);
return rv;
}
rv=bind(sk, (struct sockaddr*) &inetAddr, sizeof(inetAddr));
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
close(sk);
return rv;
}
rv=listen(sk, MAX_BACKLOG);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
close(sk);
return rv;
}
return sk;
}
int _setHostAddr(struct in_addr *inetAddr, const char *sAddr)
{
inetAddr->s_addr=0;
if (!inet_aton(sAddr, inetAddr)) {
DBG_ERROR(AQH_LOGDOMAIN, "Invalid address \"%s\"", sAddr);
return GWEN_ERROR_INVALID;
}
return 0;
}
int _setHostName(struct in_addr *inetAddr, const char *sAddr)
{
struct hostent *he;
he=gethostbyname(sAddr);
if (!he) {
DBG_ERROR(AQH_LOGDOMAIN, "gethostbyname(\"%s\"): %s", sAddr, hstrerror(h_errno));
return _translateHError(h_errno);
}
/* name resolved, store address */
memcpy(inetAddr, he->h_addr_list[0], sizeof(struct in_addr));
return 0;
}
int _socketSetBlocking(int sk, int fl)
{
int prevFlags;
int newFlags;
/* get current socket flags */
prevFlags=fcntl(sk, F_GETFL);
if (prevFlags==-1) {
DBG_INFO(AQH_LOGDOMAIN, "fcntl(): %s", strerror(errno));
return GWEN_ERROR_IO;
}
/* set nonblocking/blocking */
if (fl)
newFlags=prevFlags&(~O_NONBLOCK);
else
newFlags=prevFlags|O_NONBLOCK;
if (-1==fcntl(sk, F_SETFL, newFlags)) {
DBG_INFO(AQH_LOGDOMAIN, "fcntl(): %s", strerror(errno));
return GWEN_ERROR_IO;
}
prevFlags=fcntl(sk, F_GETFL);
if (prevFlags!=newFlags) {
DBG_ERROR(AQH_LOGDOMAIN, "fcntl() did not set flags correctly (%08x!=%08x)", prevFlags, newFlags);
return GWEN_ERROR_IO;
}
return 0;
}
int _socketSetReuseAddress(int sk, int fl)
{
if (setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &fl, sizeof(fl))) {
DBG_INFO(AQH_LOGDOMAIN, "setsockopt(): %s", strerror(errno));
return GWEN_ERROR_IO;
}
return 0;
}
int _translateHError(int herr)
{
int rv;
switch (herr) {
case HOST_NOT_FOUND:
rv=GWEN_ERROR_HOST_NOT_FOUND;
break;
#ifdef NO_ADDRESS
case NO_ADDRESS:
rv=GWEN_ERROR_NO_ADDRESS;
break;
#endif
case NO_RECOVERY:
rv=GWEN_ERROR_NO_RECOVERY;
break;
case TRY_AGAIN:
rv=GWEN_ERROR_TRY_AGAIN;
break;
default:
rv=GWEN_ERROR_UNKNOWN_DNS_ERROR;
break;
} /* switch */
return rv;
}
int _acceptConnection(int serverSocket)
{
int clientSk;
struct sockaddr_in inetAddr;
unsigned int socklen;
int rv;
socklen=sizeof(inetAddr);
clientSk=accept(serverSocket, (struct sockaddr*) &inetAddr, &socklen);
if (clientSk<0) {
DBG_INFO(AQH_LOGDOMAIN, "accept(): %s", strerror(errno));
return GWEN_ERROR_IO;
}
DBG_INFO(AQH_LOGDOMAIN, "Accepted incoming connection");
rv=_socketSetBlocking(clientSk, 0);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
close(clientSk);
return rv;
}
return clientSk;
}

29
aqhome/ipc2/tcpd_object.h Normal file
View File

@@ -0,0 +1,29 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQH_TCPD_OBJECT_H
#define AQH_TCPD_OBJECT_H
#include <aqhome/events2/object.h>
enum {
/** new client connected (param1 is fd for the new clients non-blocking socket) */
AQH_TCPD_OBJECT_SIGNAL_NEWCONN=AQH_OBJECT_SIGNAL_LAST
};
AQHOME_API AQH_OBJECT *AQH_TcpdObject_new(AQH_EVENT_LOOP *eventLoop);
AQHOME_API int AQH_TcpdObject_StartListening(AQH_OBJECT *o, const char *addr, int port);
AQHOME_API void AQH_TcpdObject_StopListening(AQH_OBJECT *o);
#endif

View File

@@ -0,0 +1,27 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQH_TCPD_OBJECT_P_H
#define AQH_TCPD_OBJECT_P_H
#include "./tcpd_object.h"
typedef struct AQH_TCPD_OBJECT AQH_TCPD_OBJECT;
struct AQH_TCPD_OBJECT {
int fdSocket;
AQH_OBJECT *fdObject;
};
#endif

View File

@@ -59,6 +59,7 @@
msg_sysstats.h
msg_value.h
msg_value2.h
msg_value3.h
msg_device.h
msg_flashready.h
msg_flashstart.h

View File

@@ -122,6 +122,9 @@ const char *AQH_Value3Msg_GetValueTypeName(const GWEN_MSG *msg)
case AQH_MSG_VALUE3_TYPE_TEMP: return "temperature";
case AQH_MSG_VALUE3_TYPE_HUMIDITY: return "humidity";
case AQH_MSG_VALUE3_TYPE_DOOR: return "door_window";
case AQH_MSG_VALUE3_TYPE_MOTION: return "motion";
case AQH_MSG_VALUE3_TYPE_CO2: return "CO2";
case AQH_MSG_VALUE3_TYPE_TVOC: return "TVOC";
default: break;
}
return "unknown";
@@ -151,6 +154,8 @@ const char *AQH_Value3Msg_GetValueTypeUnits(const GWEN_MSG *msg)
case AQH_MSG_VALUE3_TYPE_TEMP: return "Celsius";
case AQH_MSG_VALUE3_TYPE_HUMIDITY: return "%";
case AQH_MSG_VALUE3_TYPE_DOOR: return NULL;
case AQH_MSG_VALUE3_TYPE_CO2: return "ppm";
case AQH_MSG_VALUE3_TYPE_TVOC: return "ppb";
default: break;
}
return NULL;
@@ -194,7 +199,8 @@ void AQH_Value3Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const ch
}
if (AQH_Value3Msg_GetValueType(msg)==AQH_MSG_VALUE3_TYPE_DOOR)
GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: VALUE3(%s) %s (uid=0x%08x, msgId=%u, value_id=0x%02x type=%s value=%s)\n",
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: VALUE3(%s) %s (uid=0x%08x, msgId=%u, value_id=0x%02x type=%s value=%s [%04x/%04x])\n",
AQH_NodeMsg_GetSourceAddress(msg),
AQH_NodeMsg_GetDestAddress(msg),
sCmd,
@@ -203,7 +209,9 @@ void AQH_Value3Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const ch
(unsigned int)AQH_Value3Msg_GetMsgId(msg),
AQH_Value3Msg_GetValueId(msg),
AQH_Value3Msg_GetValueTypeName(msg),
AQH_Value3Msg_GetValueAsWindowStateString(msg));
AQH_Value3Msg_GetValueAsWindowStateString(msg),
AQH_Value3Msg_GetValueNom(msg),
AQH_Value3Msg_GetValueDenom(msg));
else
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: VALUE3(%s) %s (uid=0x%08x, msgId=%u, value_id=0x%02x type=%s value=%f [%04x/%04x])\n",

View File

@@ -21,6 +21,9 @@
#define AQH_MSG_VALUE3_TYPE_TEMP 1
#define AQH_MSG_VALUE3_TYPE_HUMIDITY 2
#define AQH_MSG_VALUE3_TYPE_DOOR 3
#define AQH_MSG_VALUE3_TYPE_MOTION 6
#define AQH_MSG_VALUE3_TYPE_CO2 7
#define AQH_MSG_VALUE3_TYPE_TVOC 8
AQHOME_API GWEN_MSG *AQH_Value3Msg_new(uint8_t srcAddr, uint8_t destAddr,

View File

@@ -10,8 +10,8 @@
</subdirs>
<extradist>
defs.asm
main.asm
defs_all.asm
main_all.asm
</extradist>

View File

@@ -7,8 +7,11 @@
ringbuffer.asm
shared.asm
utils.asm
utils_copy_from_flash.asm
utils_copy_sdram.asm
utils_wait.asm
utils_wait_fixed.asm
utils_wait_pin.asm
watchdog.asm
</extradist>

View File

@@ -13,6 +13,11 @@
.equ AQHOME_VALUETYPE_TEMP = 1
.equ AQHOME_VALUETYPE_HUMIDITY = 2
.equ AQHOME_VALUETYPE_DOOR = 3
.equ AQHOME_VALUETYPE_RGB = 4
.equ AQHOME_VALUETYPE_RGBW = 5
.equ AQHOME_VALUETYPE_MOTION = 6
.equ AQHOME_VALUETYPE_CO2 = 7
.equ AQHOME_VALUETYPE_TVOC = 8
.equ AQHOME_FW_TYPE_ATT84_BASE = 0
@@ -23,10 +28,18 @@
; EEPROM positions
.equ EEPROM_OFFS_UUID = 0 ; 4 bytes (occupy total of 8 bytes for extensibility)
.equ EEPROM_OFFS_COMADDR = 8 ; 1 byte (plus one byte reserved)
.equ EEPROM_OFFS_SEED = 10 ; 2 bytes
.equ EEPROM_OFFS_UUID = 0 ; 4 bytes (occupy total of 8 bytes for extensibility)
.equ EEPROM_OFFS_COMADDR = 8 ; 1 byte (plus one byte reserved)
.equ EEPROM_OFFS_REED_CONF = 12 ; 1 byte (plus one byte reserved)
; next is 14
.equ EEPROM_OFFS_SEED = 10 ; 2 bytes
.equ EEPROM_OFFS_REED_CONF = 12 ; 1 byte (plus one byte reserved)
.equ EEPROM_OFFS_MAL_CONF_ONTIME = 14 ; 2 bytes
.equ EEPROM_OFFS_MAL_CONF_SRC1_ADDR = 16 ; 1 byte
.equ EEPROM_OFFS_MAL_CONF_SRC1_VALUEID = 17 ; 1 byte
.equ EEPROM_OFFS_MAL_CONF_SRC2_ADDR = 18 ; 1 byte
.equ EEPROM_OFFS_MAL_CONF_SRC2_VALUEID = 19 ; 1 byte
; next is 20

View File

@@ -3,11 +3,20 @@
<gwbuild>
<subdirs>
n00
n06
n11
n12
n14
n15
n16
n17
n18
n19
n20
n21
n22
r02
x03
</subdirs>
</gwbuild>

View File

@@ -2,7 +2,7 @@
<gwbuild>
<target type="AvrHexFile" name="n00_main" >
<target type="AvrHexFile" name="n00_firmware" >
<includes type="avrasm" >
-I $(builddir)

View File

@@ -12,8 +12,8 @@
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "n00_defs.asm"
.include "defs.asm"
.include "./n00_defs.asm"
.include "defs_all.asm"
@@ -104,9 +104,9 @@ main:
; ***************************************************************************
; includes
.include "modules/com2/lowlevel.asm"
.include "modules/uart_bitbang/bytelevel.asm"
.include "modules/uart_bitbang/packetlevel.asm"
.include "modules/com2/crc.asm"
.include "modules/com2/packets.asm"
.include "common/crc8.asm"
.include "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"

View File

@@ -50,15 +50,15 @@
.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_DDR_DATA = DDRA
.equ COM_PORT_DATA = PORTA
.equ COM_PIN_DATA = PINA
.equ COM_PINNUM_DATA = PORTA1
.equ COM_DATA_DDR = DDRA
.equ COM_DATA_INPUT = PINA
.equ COM_DATA_OUTPUT = PORTA
.equ COM_DATA_PIN = PORTA1
.equ COM_DDR_ATTN = DDRA
.equ COM_PORT_ATTN = PORTA
.equ COM_PIN_ATTN = PINA
.equ COM_PINNUM_ATTN = PORTA7
.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 = 7 ; bit 7 in PCMSK0

View File

@@ -29,8 +29,8 @@
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "n00_defs.asm"
.include "defs.asm"
.include "./n00_defs.asm"
.include "defs_all.asm"
@@ -93,7 +93,7 @@
; rjmp main ; Reset vector
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp com2IsrPcint0 ; PCI0
rjmp uartBitbangIsrPcint0 ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
@@ -143,6 +143,11 @@ firmwareStart: rjmp main
#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"
@@ -243,7 +248,7 @@ timerList:
.include "main.asm"
.include "main_all.asm"
systemSetSpeed:

View File

@@ -12,8 +12,8 @@
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "n06_defs.asm"
.include "defs.asm"
.include "./n06_defs.asm"
.include "defs_all.asm"
@@ -79,8 +79,8 @@
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db 'N', 0
devInfoVersion: .db 6, 4 ; version, revision
devInfoId: .db DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; version, revision
firmwareVersion: .db FIRMWARE_VARIANT_BOOT, FIRMWARE_VERSION_MAJOR
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
@@ -104,9 +104,9 @@ main:
; ***************************************************************************
; includes
.include "modules/com2/lowlevel.asm"
.include "modules/uart_bitbang/bytelevel.asm"
.include "modules/uart_bitbang/packetlevel.asm"
.include "modules/com2/crc.asm"
.include "modules/com2/packets.asm"
.include "common/crc8.asm"
.include "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"

View File

@@ -30,6 +30,10 @@
.equ FIRMWARE_VARIANT_BOOT = 0
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 6
.equ DEVICEINFO_REVISION = 4
@@ -50,15 +54,15 @@
.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_DDR_DATA = DDRA
.equ COM_PORT_DATA = PORTA
.equ COM_PIN_DATA = PINA
.equ COM_PINNUM_DATA = PORTA1
.equ COM_DATA_DDR = DDRA
.equ COM_DATA_OUTPUT = PORTA
.equ COM_DATA_INPUT = PINA
.equ COM_DATA_PIN = PORTA1
.equ COM_DDR_ATTN = DDRA
.equ COM_PORT_ATTN = PORTA
.equ COM_PIN_ATTN = PINA
.equ COM_PINNUM_ATTN = PORTA7
.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

View File

@@ -30,7 +30,7 @@
.list
.include "n06_defs.asm"
.include "defs.asm"
.include "defs_all.asm"
@@ -93,7 +93,7 @@
; rjmp main ; Reset vector
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp com2IsrPcint0 ; PCI0
rjmp uartBitbangIsrPcint0 ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
@@ -112,8 +112,8 @@
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db 'N', 0
devInfoVersion: .db 6, 4 ; version, revision
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
@@ -143,6 +143,11 @@ firmwareStart: rjmp main
#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"
@@ -243,7 +248,7 @@ timerList:
.include "main.asm"
.include "main_all.asm"
systemSetSpeed:

View File

@@ -13,7 +13,7 @@
.list
.include "n11_defs.asm"
.include "defs.asm"
.include "defs_all.asm"
@@ -79,8 +79,8 @@
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db 'N', 0
devInfoVersion: .db 11, 0 ; version, revision
devInfoId: .db DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; version, revision
firmwareVersion: .db FIRMWARE_VARIANT_BOOT, FIRMWARE_VERSION_MAJOR
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
@@ -104,9 +104,9 @@ main:
; ***************************************************************************
; includes
.include "modules/com2/lowlevel.asm"
.include "modules/uart_bitbang/bytelevel.asm"
.include "modules/uart_bitbang/packetlevel.asm"
.include "modules/com2/crc.asm"
.include "modules/com2/packets.asm"
.include "common/crc8.asm"
.include "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"

View File

@@ -30,6 +30,10 @@
.equ FIRMWARE_VARIANT_BOOT = 0
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 11
.equ DEVICEINFO_REVISION = 0
; ---------------------------------------------------------------------------
@@ -48,15 +52,17 @@
.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_DDR_DATA = DDRA
.equ COM_PORT_DATA = PORTA
.equ COM_PIN_DATA = PINA
.equ COM_PINNUM_DATA = PORTA1
.equ COM_DDR_ATTN = DDRA
.equ COM_PORT_ATTN = PORTA
.equ COM_PIN_ATTN = PINA
.equ COM_PINNUM_ATTN = PORTA7
.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
@@ -69,7 +75,7 @@
; 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_BIT_LENGTH = 10000 ; 10, 100, 500, 100000 and 200000 works for display: 10000, 100000, 200000
.equ TWI_DDR_SCL = DDRA
.equ TWI_PORT_SCL = PORTA
@@ -157,3 +163,10 @@
; ---------------------------------------------------------------------------
; CCS 811
;
.equ CCS811_ADDR = 0x5a ; or 0x5b

View File

@@ -31,7 +31,7 @@
.list
.include "n11_defs.asm"
.include "defs.asm"
.include "defs_all.asm"
@@ -64,9 +64,10 @@
#define MODULES_SI7021
#define MODULES_STATS
;#define MODULES_CNY70
#define MODULES_REED
;#define MODULES_REED
;#define MODULES_OWI_MASTER
;#define MODULES_DS18B20
#define MODULES_CCS811
; ---------------------------------------------------------------------------
@@ -80,6 +81,11 @@
.equ VALUE_ID_REED2 = 0x05
.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
@@ -98,7 +104,7 @@
; rjmp main ; Reset vector
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp com2IsrPcint0 ; PCI0
rjmp uartBitbangIsrPcint0 ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
@@ -117,8 +123,8 @@
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db 'N', 0
devInfoVersion: .db 11, 0 ; version, revision
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
@@ -148,6 +154,11 @@ firmwareStart: rjmp main
#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"
@@ -191,6 +202,10 @@ firmwareStart: rjmp main
.include "modules/reed/main.asm"
#endif
#ifdef MODULES_CCS811
.include "modules/ccs811/main.asm"
#endif
; ***************************************************************************
@@ -228,6 +243,10 @@ sramTimerEnqueueValues: .byte 2
sramSendDs18b20TempTimer: .byte 2
#endif
#ifdef MODULES_CCS811
sramCcs811Timer: .byte 2
#endif
; ***************************************************************************
; data in FLASH
@@ -264,6 +283,9 @@ timerList:
#ifdef MODULES_DS18B20
.dw sramDs18b20Timer, Ds18b20_OnTimer, 0, 300 ; every 30s
.dw sramSendDs18b20TempTimer, sendDs18b20Temp, 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
@@ -271,7 +293,7 @@ timerList:
.include "main.asm"
.include "main_all.asm"
@@ -308,6 +330,28 @@ onSystemStart:
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
printScreen:

View File

@@ -15,7 +15,7 @@
.list
.include "n12_defs.asm"
.include "defs.asm"
.include "defs_all.asm"
@@ -80,8 +80,8 @@
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db 'N', 0
devInfoVersion: .db 12, 0 ; version, revision
devInfoId: .db DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; version, revision
firmwareVersion: .db FIRMWARE_VARIANT_BOOT, FIRMWARE_VERSION_MAJOR
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
@@ -105,9 +105,9 @@ main:
; ***************************************************************************
; includes
.include "modules/com2/lowlevel.asm"
.include "modules/uart_bitbang/bytelevel.asm"
.include "modules/uart_bitbang/packetlevel.asm"
.include "modules/com2/crc.asm"
.include "modules/com2/packets.asm"
.include "common/crc8.asm"
.include "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"

View File

@@ -30,6 +30,10 @@
.equ FIRMWARE_VARIANT_BOOT = 0
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 12
.equ DEVICEINFO_REVISION = 0
; ---------------------------------------------------------------------------
; LED module
@@ -48,15 +52,16 @@
.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_DDR_DATA = DDRA
.equ COM_PORT_DATA = PORTA
.equ COM_PIN_DATA = PINA
.equ COM_PINNUM_DATA = PORTA0
.equ COM_DATA_DDR = DDRA
.equ COM_DATA_OUTPUT = PORTA
.equ COM_DATA_INPUT = PINA
.equ COM_DATA_PIN = PORTA0
.equ COM_ATTN_DDR = DDRA
.equ COM_ATTN_INPUT = PINA
.equ COM_ATTN_OUTPUT = PORTA
.equ COM_ATTN_PIN = PORTA1
.equ COM_DDR_ATTN = DDRA
.equ COM_PORT_ATTN = PORTA
.equ COM_PIN_ATTN = PINA
.equ COM_PINNUM_ATTN = PORTA1
.equ COM_IRQ_ADDR_ATTN = PCMSK0
.equ COM_IRQ_BIT_ATTN = 1 ; bit 1 in PCMSK0

View File

@@ -23,7 +23,8 @@
.list
.include "n12_defs.asm"
.include "defs.asm"
.include "defs_all.asm"
.include "common/utils_wait.asm" ; wait macro
@@ -87,7 +88,7 @@
; rjmp main ; Reset vector
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp com2IsrPcint0 ; PCI0
rjmp uartBitbangIsrPcint0 ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
@@ -106,8 +107,8 @@
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db 'N', 0
devInfoVersion: .db 12, 0 ; version, revision
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
@@ -137,6 +138,11 @@ firmwareStart: rjmp main
#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"
@@ -254,7 +260,7 @@ timerList:
.include "main.asm"
.include "main_all.asm"
systemSetSpeed:

View File

@@ -15,7 +15,7 @@
.list
.include "n14_defs.asm"
.include "defs.asm"
.include "defs_all.asm"
@@ -76,8 +76,8 @@
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db 'N', 0
devInfoVersion: .db 14, 0 ; version, revision
devInfoId: .db DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; version, revision
firmwareVersion: .db FIRMWARE_VARIANT_BOOT, FIRMWARE_VERSION_MAJOR
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
@@ -101,9 +101,9 @@ main:
; ***************************************************************************
; includes
.include "modules/com2/lowlevel.asm"
.include "modules/uart_bitbang/bytelevel.asm"
.include "modules/uart_bitbang/packetlevel.asm"
.include "modules/com2/crc.asm"
.include "modules/com2/packets.asm"
.include "common/crc8.asm"
.include "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"

View File

@@ -27,6 +27,10 @@
.equ FIRMWARE_VARIANT_BOOT = 0
.equ FIRMWARE_VARIANT_LEDSTRIPS = 1
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 14
.equ DEVICEINFO_REVISION = 0
; ---------------------------------------------------------------------------
; LED module
@@ -45,15 +49,15 @@
.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_DDR_DATA = DDRB
.equ COM_PORT_DATA = PORTB
.equ COM_PIN_DATA = PINB
.equ COM_PINNUM_DATA = PORTB1
.equ COM_DATA_DDR = DDRB
.equ COM_DATA_INPUT = PINB
.equ COM_DATA_OUTPUT = PORTB
.equ COM_DATA_PIN = PORTB1
.equ COM_DDR_ATTN = DDRB
.equ COM_PORT_ATTN = PORTB
.equ COM_PIN_ATTN = PINB
.equ COM_PINNUM_ATTN = PORTB2
.equ COM_ATTN_DDR = DDRB
.equ COM_ATTN_INPUT = PINB
.equ COM_ATTN_OUTPUT = PORTB
.equ COM_ATTN_PIN = PORTB2
.equ COM_IRQ_ADDR_ATTN = PCMSK
.equ COM_IRQ_BIT_ATTN = PCINT2 ; bit 2 in PCMSK0 (PCINT2)
@@ -61,19 +65,6 @@
.equ COM_IRQ_GIMSK_ATTN = PCIE
.equ COM_TXD_DDR = DDRB
.equ COM_TXD_DATA = PORTB
.equ COM_TXD_PIN = PORTB1
.equ COM_RXD_DDR = DDRB
.equ COM_RXD_DATA = PORTB
.equ COM_RXD_PIN = PORTB1
.equ COM_ATTN_DDR = DDRB
.equ COM_ATTN_INPUT = PINB
.equ COM_ATTN_OUTPUT = PORTB
.equ COM_ATTN_PIN = PORTB2
; ---------------------------------------------------------------------------
; 1-Wire Master

View File

@@ -23,7 +23,7 @@
.list
.include "n14_defs.asm"
.include "defs.asm"
.include "defs_all.asm"
.include "common/utils_wait.asm" ; wait macro
@@ -47,6 +47,7 @@
#define MODULES_OWI_MASTER
#define MODULES_DS18B20
#define MODULES_SK6812
#define MODULES_MOTION_LIGHT
; #define COM_ACCEPT_ALL_DEST
@@ -66,7 +67,10 @@
;.equ VALUE_ID_REED_CONF = 0x81
.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
; ***************************************************************************
@@ -82,7 +86,7 @@
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp com2IsrPcint0 ; PCI0
rjmp uartBitbangIsrPcint0 ; PCI0
reti ; OC1A
reti ; OVF1
reti ; OVF0
@@ -99,8 +103,8 @@
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db 'N', 0
devInfoVersion: .db 14, 0 ; version, revision
devInfoId: .db DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; version, revision
firmwareVersion: .db FIRMWARE_VARIANT_LEDSTRIPS, FIRMWARE_VERSION_MAJOR
.db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL
@@ -127,6 +131,17 @@ firmwareStart: rjmp main
#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"
@@ -135,14 +150,6 @@ firmwareStart: rjmp main
.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
#endif
#ifdef MODULES_STATS
@@ -157,6 +164,9 @@ firmwareStart: rjmp main
#ifdef MODULES_SK6812
.include "modules/sk6812/main.asm"
#endif
#ifdef MODULES_MOTION_LIGHT
.include "modules/ma_light/main.asm"
#endif
; ***************************************************************************
@@ -188,7 +198,7 @@ timerList:
.dw cproAddresModeTimer, CPRO_Address_OnTimer, 0, 0 ; (no restart)
#endif
#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
#ifdef MODULES_DS18B20
.dw sramDs18b20Timer, Ds18b20_OnTimer, 0, 300 ; every 30s
@@ -200,7 +210,7 @@ timerList:
.include "main.asm"
.include "main_all.asm"
; ---------------------------------------------------------------------------
@@ -269,6 +279,10 @@ onEvery100ms:
rcall REED_Every100ms
#endif
#ifdef MODULES_MOTION_LIGHT
rcall MotionLight_Every100ms
#endif
ret
@@ -290,66 +304,30 @@ onPacketReceived:
ld r16, x
sbiw xh:xl, COM2_MSG_OFFS_CMD
cpi r16, CPRO_CMD_VALUE_SET
brne onPacketReceived_l1
; msg code is CPRO_CMD_VALUE_SET
rjmp onSetValueReceived
#ifdef MODULES_MOTION_LIGHT
rcall MotionLight_OnPacketReceived
brcs onPacketReceived_end
#endif
onPacketReceived_l1:
rjmp CPRO_OnPacketReceived
#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
onSetValueReceived:
adiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUEID
ld r16, X
sbiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUEID
#ifdef MODULES_SK6812
cpi r16, VALUE_ID_LED_RGBW_VALUE
brne onSetValueReceived_l1
rjmp onSetRgbwValue
onSetValueReceived_l1:
cpi r16, VALUE_ID_LED_NUMLEDS
brne onSetValueReceived_l2
rjmp onSetNumLeds
#endif
onSetValueReceived_l2:
ldi r16, CPRO_CMD_VALUE_SET_NACK
rcall CPRO_SendSetValueResponse
clc
ret
#ifdef MODULES_SK6812
onSetRgbwValue:
; get new value
adiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUE
ld r18, X+ ; R
ld r19, X+ ; G
ld r20, X+ ; B
ld r21, X+ ; W
sbiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUE+4
rcall SK6812_SetAllColor
; send ACK
ldi r16, CPRO_CMD_VALUE_SET_ACK
rcall CPRO_SendSetValueResponse
sec
ret
onSetNumLeds:
; get new value
adiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUE
ld r16, X ; number of leds
sbiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUE
sts sk6812NumLeds, r16
; send ACK
ldi r16, CPRO_CMD_VALUE_SET_ACK
rcall CPRO_SendSetValueResponse
sec
ret
#endif

2
avr/devices/n15/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.eep.hex
*.obj

52
avr/devices/n15/0BUILD Normal file
View File

@@ -0,0 +1,52 @@
<?xml?>
<gwbuild>
<target type="AvrHexFile" name="n15_main" >
<includes type="avrasm" >
-I $(builddir)
-I $(srcdir)
-I $(topsrcdir)/avr
-I $(topbuilddir)/avr
</includes>
<sources type="avrasm" >
n15_main.asm
</sources>
</target>
<target type="AvrHexFile" name="n15_boot" >
<includes type="avrasm" >
-I $(builddir)
-I $(srcdir)
-I $(topsrcdir)/avr
-I $(topbuilddir)/avr
</includes>
<sources type="avrasm" >
n15_boot.asm
</sources>
</target>
<subdirs>
</subdirs>
<extradist>
n15_defs.asm
</extradist>
</gwbuild>

View 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 "n15_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 DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; 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

View File

@@ -0,0 +1,176 @@
; ***************************************************************************
; 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 REED_OUT
; PIR PB1 3 12 PA1 COM-DATA
; /RESET PB3 4 11 PA2 REED_IN1
; [KEY1] PB2 5 10 PA3 LED
; COM_ATTN PA7 6 9 PA4 TWI-SCL
; TWI-SDA PA6 7 8 PA5 REED_IN2
; --------
;
; ***************************************************************************
.equ BOOTLOADER_ADDR = 0xd00
.equ FIRMWARE_VARIANT_BOOT = 0
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 15
.equ DEVICEINFO_REVISION = 0
; ---------------------------------------------------------------------------
; 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_PORT_LED = PORTB
.equ CNY70_DDR_LED = DDRB
.equ CNY70_PINNUM_LED = PORTB1
.equ CNY70_PORT_ADC = PORTA ; adc5
.equ CNY70_DDR_ADC = DDRA
.equ CNY70_PINNUM_ADC = PORTA5
.equ CNY70_MUX_ADC = MUX5
.equ CNY70_ADCSRB_ADC = ADC5D
; ---------------------------------------------------------------------------
; 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

View File

@@ -0,0 +1,462 @@
; ***************************************************************************
; 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 "n15_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
; ---------------------------------------------------------------------------
; 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 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
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/n16/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.eep.hex
*.obj

52
avr/devices/n16/0BUILD Normal file
View 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>

View 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 DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; 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

View File

@@ -0,0 +1,191 @@
; ***************************************************************************
; 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
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 16
.equ DEVICEINFO_REVISION = 0
; ---------------------------------------------------------------------------
; 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

View 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 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
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
View File

@@ -0,0 +1,2 @@
*.eep.hex
*.obj

52
avr/devices/n17/0BUILD Normal file
View 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>

View 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 DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; 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

View File

@@ -0,0 +1,127 @@
; ***************************************************************************
; 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
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 17
.equ DEVICEINFO_REVISION = 0
; ---------------------------------------------------------------------------
; 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

View 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 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
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
View File

@@ -0,0 +1,2 @@
*.eep.hex
*.obj

52
avr/devices/n18/0BUILD Normal file
View 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
View 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 DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; 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"

103
avr/devices/n18/defs.asm Normal file
View File

@@ -0,0 +1,103 @@
; ***************************************************************************
; 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
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 18
.equ DEVICEINFO_REVISION = 0
; ---------------------------------------------------------------------------
; 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
View 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 DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; 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/n19/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.eep.hex
*.obj

52
avr/devices/n19/0BUILD Normal file
View 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/n19/boot.asm Normal file
View 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 DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; 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"

103
avr/devices/n19/defs.asm Normal file
View File

@@ -0,0 +1,103 @@
; ***************************************************************************
; 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
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 19
.equ DEVICEINFO_REVISION = 0
; ---------------------------------------------------------------------------
; 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/n19/main.asm Normal file
View 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 DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; 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/n20/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.eep.hex
*.obj

53
avr/devices/n20/0BUILD Normal file
View File

@@ -0,0 +1,53 @@
<?xml?>
<gwbuild>
<target type="AvrHexFile" name="n20_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="n20_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
README
</extradist>
</gwbuild>

13
avr/devices/n20/README Normal file
View File

@@ -0,0 +1,13 @@
N20
===
- Role: Air quality and climate sensors
- MCU: AtTiny84
- Connection: RJ45
- Periphery:
- PIR sensor (AMN31112)
- TWI interface
- SI7021 temperature and humidity sensor
- CCS811 air quality sensor

162
avr/devices/n20/boot.asm Normal file
View 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.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 DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; 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

127
avr/devices/n20/defs.asm Normal file
View File

@@ -0,0 +1,127 @@
; ***************************************************************************
; 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
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 20
.equ DEVICEINFO_REVISION = 0
; ---------------------------------------------------------------------------
; 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

462
avr/devices/n20/main.asm Normal file
View File

@@ -0,0 +1,462 @@
; ***************************************************************************
; 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 "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_CO2 = 0x08
.equ VALUE_ID_TVOC = 0x09
;.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 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
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/n21/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.eep.hex
*.obj

53
avr/devices/n21/0BUILD Normal file
View File

@@ -0,0 +1,53 @@
<?xml?>
<gwbuild>
<target type="AvrHexFile" name="n21_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="n21_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
README
</extradist>
</gwbuild>

13
avr/devices/n21/README Normal file
View File

@@ -0,0 +1,13 @@
N21
===
- Role: Door sensor with temp and motion detection
- MCU: AtTiny84
- Connection: RJ45
- Periphery:
- PIR sensor (AMN31112)
- door sensor (TCRT1000)
- TWI interface
- SI7021 temperature and humidity sensor

162
avr/devices/n21/boot.asm Normal file
View 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.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 DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; 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

143
avr/devices/n21/defs.asm Normal file
View File

@@ -0,0 +1,143 @@
; ***************************************************************************
; 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
; 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
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 21
.equ DEVICEINFO_REVISION = 0
; ---------------------------------------------------------------------------
; 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
; ---------------------------------------------------------------------------
; 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

470
avr/devices/n21/main.asm Normal file
View File

@@ -0,0 +1,470 @@
; ***************************************************************************
; 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 "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
#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 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
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/n22/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.eep.hex
*.obj

53
avr/devices/n22/0BUILD Normal file
View File

@@ -0,0 +1,53 @@
<?xml?>
<gwbuild>
<target type="AvrHexFile" name="n22_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="n22_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
README
</extradist>
</gwbuild>

13
avr/devices/n22/README Normal file
View File

@@ -0,0 +1,13 @@
N22
===
- Role: LED strip controller
- MCU: AtTiny85
- Connection: RJ45
- Periphery:
- LED strip connection (SK6812)
- OWI interface
- DS18B20 temperature sensor
- Modules:
- MA_LIGHT: motion activated light

124
avr/devices/n22/boot.asm Normal file
View 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 = PORTB4
; ***************************************************************************
; 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 DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; 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"

87
avr/devices/n22/defs.asm Normal file
View 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. *
; ***************************************************************************
; ***************************************************************************
;
; AtTiny85
; --------
; /RESET PB5 1 8 VCC
; OWI PB3 2 7 PB2 COM-ATTN
; LED PB4 3 6 PB1 COM-DATA
; GND 4 5 PB0 LEDSTRIP
; --------
;
; ***************************************************************************
.equ BOOTLOADER_ADDR = 0xd00
.equ FIRMWARE_VARIANT_BOOT = 0
.equ FIRMWARE_VARIANT_LEDSTRIPS = 1
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 22
.equ DEVICEINFO_REVISION = 0
; ---------------------------------------------------------------------------
; LED module
.equ LED_SIMPLE_ONTIME = 1
.equ LED_SIMPLE_OFFTIME = 50
.equ LED_SIMPLE_DDR = DDRB
.equ LED_SIMPLE_PORT = PORTB
.equ LED_SIMPLE_PINNUM = PORTB4
; ---------------------------------------------------------------------------
; 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 = PORTB1
.equ COM_ATTN_DDR = DDRB
.equ COM_ATTN_INPUT = PINB
.equ COM_ATTN_OUTPUT = PORTB
.equ COM_ATTN_PIN = PORTB2
.equ COM_IRQ_ADDR_ATTN = PCMSK
.equ COM_IRQ_BIT_ATTN = PCINT2 ; bit 2 in PCMSK0 (PCINT2)
.equ COM_IRQ_GIFR_ATTN = PCIF
.equ COM_IRQ_GIMSK_ATTN = PCIE
; ---------------------------------------------------------------------------
; 1-Wire Master
;
.equ OWI_DDR = DDRB
.equ OWI_PORTOUT = PORTB
.equ OWI_PORTIN = PINB
.equ OWI_PINNUM = PORTB3
; ---------------------------------------------------------------------------
; SK6812
.equ SK6812_DDR = DDRB
.equ SK6812_PORT = PORTB
.equ SK6812_PINNUM = PORTB0

333
avr/devices/n22/main.asm Normal file
View File

@@ -0,0 +1,333 @@
; ***************************************************************************
; 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=8000000 ; 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_STATS
#define MODULES_OWI_MASTER
#define MODULES_DS18B20
#define MODULES_SK6812
#define MODULES_MOTION_LIGHT
; #define COM_ACCEPT_ALL_DEST
; ---------------------------------------------------------------------------
; 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_REED_CONF = 0x81
.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 DEVICEINFO_ID, 0
devInfoVersion: .db DEVICEINFO_VERSION, DEVICEINFO_REVISION ; version, revision
firmwareVersion: .db FIRMWARE_VARIANT_LEDSTRIPS, 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_OWI_MASTER
.include "modules/owimaster/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
; ***************************************************************************
; 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 == 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

2
avr/devices/r02/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.eep.hex
*.obj

52
avr/devices/r02/0BUILD Normal file
View File

@@ -0,0 +1,52 @@
<?xml?>
<gwbuild>
<target type="AvrHexFile" name="r02_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="r02_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>

163
avr/devices/r02/boot.asm Normal file
View 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 "./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 = 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/defs.asm Normal file
View 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/main.asm Normal file
View 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 ATtiny841
.list
.include "./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
View File

@@ -0,0 +1,11 @@
<?xml?>
<gwbuild>
<subdirs>
uart
ccs811
</subdirs>
</gwbuild>

View 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>

View 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"

View 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

View File

@@ -0,0 +1,344 @@
; ***************************************************************************
; 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_CO2 = 0x07
.equ VALUE_ID_TVOC = 0x08
.equ VALUE_ID_DEBUG = 0x7f
;.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

Some files were not shown because too many files have changed in this diff Show More