80 Commits

Author SHA1 Message Date
Martin Preuss
9685e45861 incremented version number. 2025-09-07 11:50:33 +02:00
Martin Preuss
fbda9cf228 n28 has no motion sensor. 2025-09-07 11:50:21 +02:00
Martin Preuss
552cd5b2ae moved device info files to their respective device folders. 2025-09-07 11:50:11 +02:00
Martin Preuss
3926b01b13 remove old stats from device info files. 2025-09-07 11:49:39 +02:00
Martin Preuss
ffaa27ca24 aqhome-data: limit number of open files. 2025-09-07 11:48:55 +02:00
Martin Preuss
9a1c5799aa decreased verbosity. 2025-09-07 11:48:35 +02:00
Martin Preuss
85e66c352d n26, n27: use slow blinking LED_SIMPLE module instead of LED_ACTIVITY. 2025-09-07 01:44:05 +02:00
Martin Preuss
d1b67a4819 devicestate: add valuename for improved filtering. 2025-09-07 01:43:31 +02:00
Martin Preuss
51d55128a9 Decreased verbosity. 2025-09-07 01:43:13 +02:00
Martin Preuss
52a5078706 added flash instructions for n28 and t04. 2025-09-06 00:43:05 +02:00
Martin Preuss
2d15091b0c avr: updated uartfd0 (copied from uartfd1) 2025-09-06 00:42:49 +02:00
Martin Preuss
81598881d1 uartfd1: fixed typos. 2025-09-06 00:42:20 +02:00
Martin Preuss
4a74a9990f minor fixes. 2025-09-06 00:41:58 +02:00
Martin Preuss
6c1e8a45ff com2wn: only trigger led if LED_ACTIVITY is defined. 2025-09-06 00:41:17 +02:00
Martin Preuss
808a7c4258 com2w: check COM_ACCEPT_ALL_DEST 2025-09-06 00:40:42 +02:00
Martin Preuss
80ca6e0ac5 avr: added t04. 2025-09-06 00:40:09 +02:00
Martin Preuss
0989543b1b avr: accept all dest addresses on routers/forwarders. 2025-09-06 00:39:50 +02:00
Martin Preuss
36195f88e0 r05: added missing defs. 2025-09-06 00:39:08 +02:00
Martin Preuss
3b916facf4 avr: added device n28. 2025-09-06 00:38:43 +02:00
Martin Preuss
9d59bf31e6 avr: reduce number of stats messages. 2025-09-06 00:38:26 +02:00
Martin Preuss
a256c6261c decreased verbosity. 2025-09-06 00:38:08 +02:00
Martin Preuss
21830321f7 dataclient: fixed a typo. 2025-09-06 00:37:57 +02:00
Martin Preuss
eb27d223fb aqhome-tool: added command "devicestate". 2025-09-06 00:37:39 +02:00
Martin Preuss
33cae3ab26 incremented version. 2025-09-06 00:36:54 +02:00
Martin Preuss
1612065d8a uartfd1: add comment. 2025-09-01 23:25:39 +02:00
Martin Preuss
eac37b9927 com2w: increase buffer size. 2025-09-01 23:25:20 +02:00
Martin Preuss
b95a4fa872 avr: more work on com2wn module. 2025-09-01 23:25:02 +02:00
Martin Preuss
81669a5442 avr: first try irq driven com2w interface.
probably doesn't work like that but that's for later.
2025-09-01 23:24:15 +02:00
Martin Preuss
3270a71cb0 com2w: simplified module. 2025-09-01 23:23:30 +02:00
Martin Preuss
5ae7f821e4 s03: more work. 2025-09-01 23:22:57 +02:00
Martin Preuss
224aca5c41 n21: don't send ADC values. 2025-09-01 23:22:21 +02:00
Martin Preuss
9600be78a5 more work on m644p. 2025-09-01 23:21:52 +02:00
Martin Preuss
246d00a220 avr: allow for big flash roms. 2025-09-01 23:21:25 +02:00
Martin Preuss
809439fd26 aqhome-nodes: handle new statistics messages. 2025-09-01 23:20:38 +02:00
Martin Preuss
86741a0e50 t03: use forwarder app. 2025-08-25 14:13:08 +02:00
Martin Preuss
41843cbab9 avr: added forwarder app.
simpler than router app, just for forwarding messages between interfaces.
mainly used by t03.
2025-08-25 14:12:58 +02:00
Martin Preuss
64854506e5 fixed recvstats message handling. 2025-08-25 14:11:57 +02:00
Martin Preuss
463385a296 increment version. 2025-08-25 11:26:19 +02:00
Martin Preuss
b97fc98bc1 t03: use led_activity 2025-08-25 11:26:08 +02:00
Martin Preuss
9b86aea7ed use led_activity. 2025-08-25 11:25:53 +02:00
Martin Preuss
5bfb49d9e1 simplified code, remove unused code. 2025-08-25 11:25:30 +02:00
Martin Preuss
32a0ad5eae added comments, removed unused code. 2025-08-25 11:24:53 +02:00
Martin Preuss
65593f95ad use led_activity module. 2025-08-25 11:23:35 +02:00
Martin Preuss
ec3774c7a5 fixed a bug in field order 2025-08-25 11:22:54 +02:00
Martin Preuss
4bd462ea59 use new led modules. 2025-08-25 10:25:53 +02:00
Martin Preuss
77d3a201f5 improved uartfd1. 2025-08-25 10:24:48 +02:00
Martin Preuss
127525e3ec buffer: gather statistics 2025-08-25 10:23:47 +02:00
Martin Preuss
465e750e3c avr: activate new led modules. 2025-08-25 10:22:50 +02:00
Martin Preuss
6e062d3f60 improve stats reporting
now again use three messages to transmit stats (much more efficient than
sending single values, also more acurate).
2025-08-25 10:22:05 +02:00
Martin Preuss
7efaf720cc com2w: work in COM2W_Run, not in COM2W_Every100ms 2025-08-25 10:20:13 +02:00
Martin Preuss
66ac029a69 avr: introduce two more led modules.
- led_signal: blink 8 status bits (short=0, long=1)
- led_activity: blink for a short period after a trigger, e.g. for network
  activity
2025-08-25 10:19:23 +02:00
Martin Preuss
bae188ddee t03: added firmware using new uart_fd module. 2025-08-23 00:10:01 +02:00
Martin Preuss
87788fa93c avr: wait for free CLK line on error when in flash mode 2025-08-23 00:09:39 +02:00
Martin Preuss
5013bb8e29 avr network app: only respond to ping request if dest address matches. 2025-08-23 00:09:01 +02:00
Martin Preuss
08d420a871 avr: added module uart_fd
This module uses hardware UART of MCUs in full duplex mode.
2025-08-23 00:08:25 +02:00
Martin Preuss
3a7951be16 com2w: added some recovery code, improved protocol.
after sending a byte wait for the same time when sending the last bit as
with the other bits (otherwise the last bit might get lost by slower
devices).
2025-08-20 23:27:17 +02:00
Martin Preuss
6a3f6be8a9 avr: improved timing for sending bytes via com2w interface.
Still quite different among devices but that's just prove that the protocol
works without prior synchronisation.
2025-08-20 20:48:55 +02:00
Martin Preuss
6c3926c1e4 avr: added a note regarding timing. 2025-08-19 23:36:58 +02:00
Martin Preuss
8467408fd8 avr: increased waittimes for com2w (too fast for 1MHz nodes). 2025-08-19 23:36:44 +02:00
Martin Preuss
6bb499740d avr: use 16bit for brightness (actually, ADC only presents 10 bit). 2025-08-19 23:03:43 +02:00
Martin Preuss
fc073696f8 avr: tweaked timing for com2w transport layer. 2025-08-19 23:03:15 +02:00
Martin Preuss
102996f69f avr: switched most devices to com2w interface now. 2025-08-18 18:47:13 +02:00
Martin Preuss
f9d721ac02 removed unused device nodes.
- n00
- n06
- n11
- n12
- n15
- n17
- n18
- n19
- n20
- n22
- n23
- r02
- r04
- x03
2025-08-18 18:46:46 +02:00
Martin Preuss
6bf8f03fbb added node S03. 2025-08-18 18:07:34 +02:00
Martin Preuss
fa404a5fcf increase number of runs to 10 (was: 2) 2025-08-18 18:06:56 +02:00
Martin Preuss
3592a745d3 introduce app "hub" 2025-08-18 18:06:35 +02:00
Martin Preuss
7c01aa255f split wait for 50us (value 50000 doesn't work for 20MHz nodes). 2025-08-18 18:05:12 +02:00
Martin Preuss
d9e7d4df81 com2w*: allow for higher frequencies than 8MHz
to be used with node S03, which is run at 20MHz.
2025-08-18 18:04:30 +02:00
Martin Preuss
9b1badb310 avr: introduce reference counter for network buffers. 2025-08-18 18:03:24 +02:00
Martin Preuss
0dc4a3a952 avr: started adding COM2WN module. 2025-08-04 22:28:49 +02:00
Martin Preuss
32bd3bc2f9 added r06 again. 2025-08-04 22:26:26 +02:00
Martin Preuss
3f2ae9dd03 Revert "started working on mqtt support in aqhome-nodes"
This reverts commit 7fbc616ce4.
2025-08-03 00:56:46 +02:00
Martin Preuss
7fbc616ce4 started working on mqtt support in aqhome-nodes 2025-08-03 00:56:22 +02:00
Martin Preuss
8c13f9fdf7 avr: started adding com2wn module (multiple com2w devices in one) 2025-08-03 00:55:52 +02:00
Martin Preuss
6c5dc21f6a avr: started adding r06 device. 2025-08-03 00:55:21 +02:00
Martin Preuss
eb1392f3fd avr: fixed apidoc. 2025-08-03 00:54:45 +02:00
Martin Preuss
2b25fed2cd com2w1: follow changes in com2w0. 2025-07-21 18:25:17 +02:00
Martin Preuss
66b298d977 guard some changes on network data with CLI. 2025-07-20 23:15:46 +02:00
Martin Preuss
1091ec1dee read CLK and DATA early. 2025-07-20 23:15:22 +02:00
Martin Preuss
d0b5f84316 adapt com2w1 from com2w0 (the latter is proven to work now). 2025-07-20 00:15:13 +02:00
219 changed files with 7951 additions and 9843 deletions

2
0BUILD
View File

@@ -2,7 +2,7 @@
<gwbuild>
<project name="aqhome" version="0.0.12" so_current="0" so_age="0" so_revision="12" write_config_h="TRUE">
<project name="aqhome" version="0.0.14" so_current="0" so_age="0" so_revision="14" write_config_h="TRUE">
<setVar name="package">$(project_name)</setVar>
<setVar name="version">
$(project_vmajor).$(project_vminor).$(project_vpatchlevel)

View File

@@ -54,7 +54,7 @@ void AQH_NodeServer_HandleGetNodes(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESS
AQH_Endpoint_GetNextMessageId(ep), AQH_IpcMessage_GetMsgId(msg),
niNext?0:AQH_MSGNODE_GETDEVICES_RSP_FLAGS_LASTMSG, ni);
AQH_Endpoint_AddMsgOut(ep, outMsg);
DBG_ERROR(NULL, "Messages in clients out queue: %d", AQH_Message_List_GetCount(AQH_Endpoint_GetMsgOutList(ep)));
DBG_DEBUG(NULL, "Messages in clients out queue: %d", AQH_Message_List_GetCount(AQH_Endpoint_GetMsgOutList(ep)));
ni=niNext;
}
}

View File

@@ -41,6 +41,7 @@
#include <aqhome/msg/node/m_value.h>
#include <aqhome/msg/node/m_recvstats.h>
#include <aqhome/msg/node/m_sendstats.h>
#include <aqhome/msg/node/m_memstats.h>
#include <aqhome/data/value.h>
#include <gwenhywfar/args.h>
@@ -122,7 +123,9 @@ static void _forwardTtyMsgToBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH
static void _forwardValueMessageToBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
static void _forwardDataFromSendStatsMsgToBroker(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
static void _forwardDataFromRecvStatsMsgToBroker(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
static void _forwardDataFromMemStatsMsgToBroker(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
static void _forwardTtyMsgToClients(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
static void _publishIntWithIdx(AQH_NODE_SERVER *xo, uint32_t uid, const char *vPath, int idx, int vModality, const char *vUnits, int v);
static void _publishInt(AQH_NODE_SERVER *xo, uint32_t uid, const char *vPath, int vModality, const char *vUnits, int v);
static void _publishDouble(AQH_NODE_SERVER *xo, uint32_t uid, const char *vPath, int vModality, const char *vUnits, double v);
static void _setDeviceName(AQH_VALUE *value, uint32_t uid);
@@ -827,9 +830,11 @@ void _forwardTtyMsgToBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAG
code=AQH_NodeMessage_GetMsgType(msg);
switch(code) {
case AQH_MSG_TYPE_VALUE_REPORT: _forwardValueMessageToBroker(o, xo, msg); break;
case AQH_MSG_TYPE_VALUE_REPORT: _forwardValueMessageToBroker(o, xo, msg); break;
case AQH_MSG_TYPE_COMSENDSTATS: _forwardDataFromSendStatsMsgToBroker(xo, msg); break;
case AQH_MSG_TYPE_COMRECVSTATS: _forwardDataFromRecvStatsMsgToBroker(xo, msg); break;
case AQH_MSG_TYPE_MEMSTATS: _forwardDataFromMemStatsMsgToBroker(xo, msg); break;
default: break;
}
}
@@ -898,24 +903,21 @@ void _forwardDataFromSendStatsMsgToBroker(AQH_NODE_SERVER *xo, const AQH_MESSAGE
packetsOutInt=AQH_SendStatsMessage_GetPacketsOut(msg);
if (packetsOutInt) {
uint32_t uid;
double packetsOut;
double collisions;
double busy;
double collisionsPercentage=0.0;
double busyPercentage=0.0;
int devNum;
uid=AQH_SendStatsMessage_GetUid(msg);
packetsOut=/*(double)*/ packetsOutInt;
collisions=/*(double)*/ AQH_SendStatsMessage_GetCollisions(msg);
busy=/*(double)*/ AQH_SendStatsMessage_GetBusyErrors(msg);
devNum=AQH_SendStatsMessage_GetInterface(msg);
collisionsPercentage=collisions*100.0/packetsOut;
busyPercentage=busy*100.0/packetsOut;
_publishInt( xo, uid, "net/packetsOut", 0, NULL, packetsOutInt);
_publishInt( xo, uid, "net/collisions", 0, NULL, (int) AQH_SendStatsMessage_GetCollisions(msg));
_publishDouble(xo, uid, "net/collisionsPercent", 0, "%", collisionsPercentage);
_publishDouble(xo, uid, "net/busyPercent", 0, "%", busyPercentage);
if (devNum==0) {
_publishInt(xo, uid, "net/packetsOut", 0, NULL, packetsOutInt);
_publishInt(xo, uid, "net/collisions", 0, NULL, (int) AQH_SendStatsMessage_GetCollisions(msg));
_publishInt(xo, uid, "net/busy", 0, NULL, (int) AQH_SendStatsMessage_GetBusyErrors(msg));
}
else {
_publishIntWithIdx(xo, uid, "net/packetsOut", devNum, 0, NULL, packetsOutInt);
_publishIntWithIdx(xo, uid, "net/collisions", devNum, 0, NULL, (int) AQH_SendStatsMessage_GetCollisions(msg));
_publishIntWithIdx(xo, uid, "net/busy", devNum, 0, NULL, (int) AQH_SendStatsMessage_GetBusyErrors(msg));
}
}
}
@@ -928,30 +930,56 @@ void _forwardDataFromRecvStatsMsgToBroker(AQH_NODE_SERVER *xo, const AQH_MESSAGE
packetsInInt=AQH_RecvStatsMessage_GetPacketsIn(msg);
if (packetsInInt) {
uint32_t uid;
double packetsIn;
double crcErrors;
double ioErrors;
double crcErrorsPercentage=0.0;
double ioErrorsPercentage=0.0;
int devNum;
uid=AQH_SendStatsMessage_GetUid(msg);
packetsIn=/*(double)*/ packetsInInt;
crcErrors=/*(double)*/AQH_RecvStatsMessage_GetCrcErrors(msg);
ioErrors=/*(double)*/AQH_RecvStatsMessage_GetIoErrors(msg);
uid=AQH_RecvStatsMessage_GetUid(msg);
devNum=AQH_RecvStatsMessage_GetInterface(msg);
crcErrorsPercentage=crcErrors*100.0/packetsIn;
ioErrorsPercentage=ioErrors*100.0/packetsIn;
_publishInt( xo, uid, "net/packetsIn", 0, NULL, packetsInInt);
_publishInt( xo, uid, "net/crcerrors", 0, NULL, (int) AQH_RecvStatsMessage_GetCrcErrors(msg));
_publishInt( xo, uid, "net/ioerrors", 0, NULL, (int) AQH_RecvStatsMessage_GetIoErrors(msg));
_publishDouble(xo, uid, "net/crcerrorsPercent", 0, "%", crcErrorsPercentage);
_publishDouble(xo, uid, "net/ioerrorsPercent", 0, "%", ioErrorsPercentage);
if (devNum==0) {
_publishInt(xo, uid, "net/packetsIn", 0, NULL, packetsInInt);
_publishInt(xo, uid, "net/crcErrors", 0, NULL, (int) AQH_RecvStatsMessage_GetCrcErrors(msg));
_publishInt(xo, uid, "net/ioErrors", 0, NULL, (int) AQH_RecvStatsMessage_GetIoErrors(msg));
_publishInt(xo, uid, "net/nobufferErrors", 0, NULL, (int) AQH_RecvStatsMessage_GetNoBufferErrors(msg));
_publishInt(xo, uid, "net/msgSizeErrors", 0, NULL, (int) AQH_RecvStatsMessage_GetMsgSizeErrors(msg));
_publishInt(xo, uid, "net/missed", 0, NULL, (int) AQH_RecvStatsMessage_GetMissed(msg));
}
else {
_publishIntWithIdx(xo, uid, "net/packetsIn", devNum, 0, NULL, packetsInInt);
_publishIntWithIdx(xo, uid, "net/crcErrors", devNum, 0, NULL, (int) AQH_RecvStatsMessage_GetCrcErrors(msg));
_publishIntWithIdx(xo, uid, "net/ioErrors", devNum, 0, NULL, (int) AQH_RecvStatsMessage_GetIoErrors(msg));
_publishIntWithIdx(xo, uid, "net/nobufferErrors", devNum, 0, NULL, (int) AQH_RecvStatsMessage_GetNoBufferErrors(msg));
_publishIntWithIdx(xo, uid, "net/msgSizeErrors", devNum, 0, NULL, (int) AQH_RecvStatsMessage_GetMsgSizeErrors(msg));
_publishIntWithIdx(xo, uid, "net/missed", devNum, 0, NULL, (int) AQH_RecvStatsMessage_GetMissed(msg));
}
}
}
void _forwardDataFromMemStatsMsgToBroker(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
{
uint32_t uid;
uid=AQH_MemStatsMessage_GetUid(msg);
_publishInt( xo, uid, "mem/buffersUsed", 0, NULL, AQH_MemStatsMessage_GetBuffersUsed(msg));
_publishInt( xo, uid, "mem/maxBuffersUsed", 0, NULL, AQH_MemStatsMessage_GetMaxBuffersUsed(msg));
}
void _publishIntWithIdx(AQH_NODE_SERVER *xo, uint32_t uid, const char *vPath, int idx, int vModality, const char *vUnits, int v)
{
GWEN_BUFFER *tbuf;
tbuf=GWEN_Buffer_new(0, 256, 0, 1);
GWEN_Buffer_AppendArgs(tbuf, "%s%d", vPath, idx);
_publishInt(xo, uid, GWEN_Buffer_GetStart(tbuf), vModality, vUnits, v);
GWEN_Buffer_free(tbuf);
}
void _publishInt(AQH_NODE_SERVER *xo, uint32_t uid, const char *vPath, int vModality, const char *vUnits, int v)
{
_publishDouble(xo, uid, vPath, vModality, vUnits, /*(double)*/ v);

View File

@@ -43,6 +43,7 @@
setdata.h
moddevice.h
watch.h
devicestate.h
</headers>
<sources>
@@ -58,6 +59,7 @@
setdata.c
moddevice.c
watch.c
devicestate.c
</sources>
<useTargets>

View File

@@ -0,0 +1,265 @@
/****************************************************************************
* 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 "./devicestate.h"
#include "../utils.h"
#include "aqhome/aqhome.h"
#include "aqhome/dataclient/client.h"
#include "aqhome/msg/ipc/m_ipc.h"
#include "aqhome/msg/ipc/m_ipc_result.h"
#include "aqhome/msg/ipc/data/m_ipcd.h"
#include "aqhome/msg/ipc/data/m_ipcd_getdata.h"
#include "aqhome/msg/ipc/data/m_ipcd_multidata.h"
#include "aqhome/dataclient/client.h"
#include <gwenhywfar/args.h>
#include <gwenhywfar/i18n.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/text.h>
#include <gwenhywfar/timestamp.h>
#include <ctype.h>
/* ------------------------------------------------------------------------------------------------
* defs
* ------------------------------------------------------------------------------------------------
*/
#define I18S(msg) msg
#define I18N(msg) GWEN_I18N_Translate(PACKAGE, msg)
#define A_ARG GWEN_ARGS_FLAGS_HAS_ARGUMENT
#define A_END (GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST)
#define A_CHAR GWEN_ArgsType_Char
#define A_INT GWEN_ArgsType_Int
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static int _runCommand(AQH_DATACLIENT *dc);
static void _handleDevice(AQH_DATACLIENT *dc, const AQH_DEVICE *device);
static void _handleValue(AQH_DATACLIENT *dc, const AQH_VALUE *value);
static void _printDataPoints(const uint64_t *dataPoints, uint32_t numValues);
static void _printSingleDataPoint(uint64_t timestamp, double data);
/* ------------------------------------------------------------------------------------------------
* code
* ------------------------------------------------------------------------------------------------
*/
int AQH_Tool_DeviceState(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
{
AQH_EVENT_LOOP *eventLoop;
AQH_DATACLIENT *dc;
int rv;
const GWEN_ARGS args[]= {
/* flags type name min max s long short_descr, long_descr */
{ A_ARG, A_CHAR, "brokerAddress", 0, 1, "t", "tcpaddress", I18S("TCP address to connect to [127.0.0.1]"), NULL},
{ A_ARG, A_INT, "brokerPort", 0, 1, "P", "tcpport", I18S("Specify the TCP port to listen on"), NULL},
{ A_ARG, A_INT, "timeout", 0, 1, "T", NULL, I18S("Specify timeout in seconds for response"), NULL},
{ A_ARG, A_CHAR, "brokerClientId", 0, 1, "c", "clientid", I18S("Specify CLIENTID"), NULL},
{ A_ARG, A_CHAR, "userId", 0, 1, "u", "userid", I18S("Specify user id"), NULL},
{ A_ARG, A_CHAR, "password", 0, 1, "p", "password", I18S("Specify service password"), NULL},
{ A_ARG, A_CHAR, "device", 1, 1, "d", "device", I18S("device name"), NULL},
{ A_ARG, A_CHAR, "valueName", 0, 1, "N", "valuename", I18S("Value name for device(e.g. LIGHT)"), NULL},
{ A_ARG, A_INT, "numOfDatapoints", 0, 1, "n", NULL, I18S("Get up to n datapoints"), NULL},
{ A_END, A_INT, "help", 0, 0, "h", "help", I18S("Show this help screen"), NULL}
};
eventLoop=AQH_EventLoop_new();
dc=AQH_DataClient_new(eventLoop, AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION);
rv=AQH_DataClient_ReadLocalArgs(dc, dbGlobalArgs, args, argc, argv);
if (rv<0) {
DBG_ERROR(NULL, "here (%d)", rv);
AQH_DataClient_free(dc);
AQH_EventLoop_free(eventLoop);
return 2;
}
rv=AQH_DataClient_ConnectWithArgs(dc, 0);
if (rv<0) {
DBG_ERROR(NULL, "Error connecting (%d)", rv);
AQH_DataClient_free(dc);
AQH_EventLoop_free(eventLoop);
return 2;
}
rv=_runCommand(dc);
if (rv<0) {
DBG_ERROR(NULL, "Error running (%d)", rv);
AQH_DataClient_free(dc);
AQH_EventLoop_free(eventLoop);
return 2;
}
AQH_DataClient_free(dc);
AQH_EventLoop_free(eventLoop);
return 0;
}
int _runCommand(AQH_DATACLIENT *dc)
{
GWEN_DB_NODE *dbLocalArgs;
const char *deviceName;
AQH_DEVICE_LIST *deviceList;
AQH_DEVICE *device;
dbLocalArgs=AQH_DataClient_GetDbLocalArgs(dc);
deviceName=GWEN_DB_GetCharValue(dbLocalArgs, "device", 0, "*");
deviceList=AQH_DataClient_GetDevices(dc);
if (deviceList==NULL) {
DBG_ERROR(NULL, "Error getting devices");
return GWEN_ERROR_GENERIC;
}
device=AQH_Device_List_First(deviceList);
while(device) {
const char *s;
s=AQH_Device_GetNameForSystem(device);
if (s && *s && -1!=GWEN_Text_ComparePattern(s, deviceName, 0)) {
_handleDevice(dc, device);
}
device=AQH_Device_List_Next(device);
}
AQH_Device_List_free(deviceList);
return 0;
}
void _handleDevice(AQH_DATACLIENT *dc, const AQH_DEVICE *device)
{
AQH_VALUE_LIST *valueList;
const char *devName;
const char *roomName;
const char *location;
const char *descr;
devName=AQH_Device_GetNameForSystem(device);
roomName=AQH_Device_GetRoomName(device);
location=AQH_Device_GetLocation(device);
descr=AQH_Device_GetDescription(device);
fprintf(stdout, "%s (room: %s, loc: %s, descr: %s)\n",
devName,
roomName?roomName:"--",
location?location:"--",
descr?descr:"--");
valueList=AQH_DataClient_GetValues(dc, devName, 0);
if (valueList) {
const AQH_VALUE *value;
value=AQH_Value_List_First(valueList);
while(value) {
if (AQH_Value_GetValueType(value)==AQH_ValueType_Sensor)
_handleValue(dc, value);
value=AQH_Value_List_Next(value);
}
}
AQH_Value_List_free(valueList);
}
void _handleValue(AQH_DATACLIENT *dc, const AQH_VALUE *value)
{
GWEN_DB_NODE *dbLocalArgs;
const char *wantedValueName;
const char *valueName;
int numDataPoints;
dbLocalArgs=AQH_DataClient_GetDbLocalArgs(dc);
numDataPoints=GWEN_DB_GetIntValue(dbLocalArgs, "numOfDatapoints", 0, 5);
wantedValueName=GWEN_DB_GetCharValue(dbLocalArgs, "valueName", 0, "*");
valueName=AQH_Value_GetName(value);
if (valueName &&
-1==GWEN_Text_ComparePattern(valueName, "stats_*", 0) &&
-1!=GWEN_Text_ComparePattern(valueName, wantedValueName, 0)) {
const char *valueNameForSystem;
uint64_t *dataPoints;
uint64_t recvdNum;
valueNameForSystem=AQH_Value_GetNameForSystem(value);
fprintf(stdout, " %s: ", valueName?valueName:"<empty>");
dataPoints=malloc(numDataPoints*sizeof(uint64_t)*2);
recvdNum=AQH_DataClient_GetLastData(dc, valueNameForSystem, dataPoints, numDataPoints);
if (recvdNum>0)
_printDataPoints(dataPoints, recvdNum);
free(dataPoints);
fprintf(stdout, "\n");
}
}
void _printDataPoints(const uint64_t *dataPoints, uint32_t numValues)
{
uint32_t i;
for(i=0; i<numValues; i++) {
uint64_t timestamp;
union {double f; uint64_t i;} u;
if (i)
fprintf(stdout, " | ");
timestamp=*(dataPoints++);
u.i=*(dataPoints++);
_printSingleDataPoint(timestamp, u.f);
}
}
void _printSingleDataPoint(uint64_t timestamp, double data)
{
GWEN_TIMESTAMP *ts;
ts=GWEN_Timestamp_fromLocalTime((time_t) timestamp);
if (ts)
fprintf(stdout, "%lf (%04d/%02d/%02d-%02d:%02d:%02d)",
data,
GWEN_Timestamp_GetYear(ts),
GWEN_Timestamp_GetMonth(ts),
GWEN_Timestamp_GetDay(ts),
GWEN_Timestamp_GetHour(ts),
GWEN_Timestamp_GetMinute(ts),
GWEN_Timestamp_GetSecond(ts));
else
fprintf(stdout, "%lf", data);
}

View File

@@ -0,0 +1,21 @@
/****************************************************************************
* 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 AQHOME_TOOL_DEVICESTATE_H
#define AQHOME_TOOL_DEVICESTATE_H
#include <gwenhywfar/db.h>
int AQH_Tool_DeviceState(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv);
#endif

View File

@@ -23,6 +23,7 @@
#include "./data/setdata.h"
#include "./data/moddevice.h"
#include "./data/watch.h"
#include "./data/devicestate.h"
#include <aqhome/api.h>
#include <aqhome/aqhome.h>
@@ -101,6 +102,7 @@ int main(int argc, char **argv)
GWEN_FE_DAH("setdata", AQH_Tool_SetData, I18N("Set data for a value on the data server (e.g. a switch or thermostat)")),
GWEN_FE_DAH("moddevice", AQH_Tool_ModDevice, I18N("Modify a device on the data server")),
GWEN_FE_DAH("watch", AQH_Tool_Watch, I18N("Watch and print changes of values on the data server")),
GWEN_FE_DAH("devicestate", AQH_Tool_DeviceState, I18N("Show state of devices")),
GWEN_FE_END(),
};
const GWEN_FUNCS *func;

View File

@@ -23,7 +23,7 @@
#define AQH_STORAGE_DATAPOINTS_STEPS 128
#define AQH_STORAGE_MAXOPENFILES 128
/* ------------------------------------------------------------------------------------------------
@@ -650,6 +650,16 @@ AQH_DATAFILE *_getDataFileByValueId(AQH_STORAGE *sto, uint64_t valueId)
DBG_ERROR(AQH_LOGDOMAIN, "Error opening/creating datafile for valueId \"%lu\"", (unsigned long int) valueId);
return NULL;
}
if (AQH_DataFile_List_GetCount(sto->dataFileList)>=AQH_STORAGE_MAXOPENFILES) {
AQH_DATAFILE *dfLast;
dfLast=AQH_DataFile_List_Last(sto->dataFileList);
if (dfLast) {
AQH_DataFile_Close(dfLast);
AQH_DataFile_List_Del(dfLast);
AQH_DataFile_free(dfLast);
}
}
DBG_DEBUG(AQH_LOGDOMAIN, "Adding datafile for valueId \"%lu\" to list", (unsigned long int) valueId);
AQH_DataFile_List_Add(df, sto->dataFileList);
}
@@ -661,8 +671,17 @@ AQH_DATAFILE *_getDataFileByValueId(AQH_STORAGE *sto, uint64_t valueId)
AQH_DATAFILE *_findDataFileByValueId(const AQH_STORAGE *sto, uint64_t valueId)
{
if (sto && sto->dataFileList)
return AQH_DataFile_List_GetByValueId(sto->dataFileList, valueId);
if (sto && sto->dataFileList) {
AQH_DATAFILE *df;
df=AQH_DataFile_List_GetByValueId(sto->dataFileList, valueId);
if (df) {
/* move to front of list */
AQH_DataFile_List_Del(df);
AQH_DataFile_List_Insert(df, sto->dataFileList);
return df;
}
}
return NULL;
}

View File

@@ -467,7 +467,7 @@ uint64_t _handleDataResponses(AQH_DATACLIENT *dc, uint64_t *dataPtr, uint64_t ma
break;
}
else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) {
DBG_ERROR(NULL, "Server Error: %d", AQH_IpcMessageResult_GetResult(tagList));
DBG_INFO(NULL, "Server Error: %d", AQH_IpcMessageResult_GetResult(tagList));
GWEN_Tag16_List_free(tagList);
AQH_Message_free(msgIn);
return 0;
@@ -538,7 +538,7 @@ int AQH_DataClient_ConnectWithArgs(AQH_DATACLIENT *dc, uint32_t flags)
brokerPort=GWEN_DB_GetIntValue(dc->dbLocalArgs, "brokerPort", 0, -1);
if (brokerPort<0)
brokerPort=GWEN_DB_GetIntValue(dc->dbLocalArgs, "ConfigFile/brokerPort", 0, 45456);
brokerPort=GWEN_DB_GetIntValue(dc->dbLocalArgs, "ConfigFile/brokerPort", 0, 1899);
userId=GWEN_DB_GetCharValue(dc->dbLocalArgs, "userId", 0, NULL);
passwd=GWEN_DB_GetCharValue(dc->dbLocalArgs, "password", 0, NULL);

View File

@@ -79,7 +79,7 @@ AQH_MESSAGE *AQH_IpcEndpoint_WaitForResponseMsg(AQH_OBJECT *ipcEndpoint, uint32_
uint16_t code;
code=AQH_IpcMessage_GetCode(msg);
DBG_ERROR(NULL, "Received unexpected message %d (%x), ignoring", code, code);
DBG_DEBUG(NULL, "Received unexpected message %d (%x), ignoring", code, code);
AQH_Message_free(msg);
}
}

View File

@@ -176,17 +176,17 @@ int _handleSocketReady(AQH_OBJECT *o)
{
AQH_TCPD_OBJECT *xo;
DBG_INFO(NULL, "Socket ready");
DBG_DEBUG(NULL, "Socket ready");
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_TCPD_OBJECT, o);
if (xo) {
int clientSk;
clientSk=_acceptConnection(xo->fdSocket);
if (clientSk<0) {
DBG_ERROR(AQH_LOGDOMAIN, "here (%d)", clientSk);
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", clientSk);
}
else {
DBG_INFO(AQH_LOGDOMAIN, "New connection");
DBG_NOTICE(AQH_LOGDOMAIN, "New connection");
if (0==AQH_Object_EmitSignal(o, AQH_TCPD_OBJECT_SIGNAL_NEWCONN, clientSk, NULL)) {
DBG_ERROR(AQH_LOGDOMAIN, "New connection not handled");
close(clientSk);

View File

@@ -19,8 +19,8 @@
#define AQH_MSG_OFFS_MEMSTATS_SECONDS 0 /* 4 bytes */
#define AQH_MSG_OFFS_MEMSTATS_UID 4 /* 4 bytes */
#define AQH_MSG_OFFS_MEMSTATS_UID 0 /* 4 bytes */
#define AQH_MSG_OFFS_MEMSTATS_SECONDS 4 /* 4 bytes */
#define AQH_MSG_OFFS_MEMSTATS_STACKUSAGE 8 /* 2 bytes */
#define AQH_MSG_OFFS_MEMSTATS_BUFFERSUSED 10 /* 1 byte */
#define AQH_MSG_OFFS_MEMSTATS_MAXBUFFERSUSED 11 /* 1 byte */

View File

@@ -29,8 +29,8 @@
#define AQH_MSG_TYPE_PING 10
#define AQH_MSG_TYPE_PONG 11
#define AQH_MSG_TYPE_COMSENDSTATS 20
#define AQH_MSG_TYPE_COMRECVSTATS 21
#define AQH_MSG_TYPE_COMSENDSTATS 22
#define AQH_MSG_TYPE_COMRECVSTATS 23
#define AQH_MSG_TYPE_TWIBUSMEMBER 30
#define AQH_MSG_TYPE_DEBUG 40
#define AQH_MSG_TYPE_VALUE 50 /* deprecated */

View File

@@ -18,13 +18,21 @@
#include <gwenhywfar/debug.h>
#define AQH_MSG_OFFS_RECVSTATS_UID 0 /* 4 bytes */
#define AQH_MSG_OFFS_RECVSTATS_PACKETSIN 4 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_CRCERRORS 6 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_IOERRORS 8 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_NOBUFFER 10 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_HANDLED 12 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_MISSED 14 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_UID 0 /* 4 bytes */
#define AQH_MSG_OFFS_RECVSTATS_IFACE 4 /* 1 byte */
#define AQH_MSG_OFFS_RECVSTATS_PACKETSIN 5 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_CRCERRORS 7 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_IOERRORS 9 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_NOBUFFER 11 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_MSGSIZEERRORS 13 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_MISSED 15 /* 2 bytes */
uint8_t AQH_RecvStatsMessage_GetInterface(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_IFACE, 0);
}
@@ -63,9 +71,9 @@ uint16_t AQH_RecvStatsMessage_GetNoBufferErrors(const AQH_MESSAGE *msg)
uint16_t AQH_RecvStatsMessage_GetHandled(const AQH_MESSAGE *msg)
uint16_t AQH_RecvStatsMessage_GetMsgSizeErrors(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_HANDLED, 0);
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_MSGSIZEERRORS, 0);
}
@@ -80,17 +88,18 @@ uint16_t AQH_RecvStatsMessage_GetMissed(const AQH_MESSAGE *msg)
void AQH_RecvStatsMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: RECVSTATS %s "
"(uid=0x%08x, in=%d, crc errs=%d, io errs=%d, nobuf errs=%d, handled=%d, missed=%d)\n",
"0x%02x->0x%02x: RECVSTATS %s"
"(uid=0x%08x, dev=%d, in=%d, eCrc=%d, eIo=%d, eNobuf=%d, eMsgSize=%d, eMissed=%d)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
sText,
(unsigned int) AQH_RecvStatsMessage_GetUid(msg),
AQH_RecvStatsMessage_GetInterface(msg),
AQH_RecvStatsMessage_GetPacketsIn(msg),
AQH_RecvStatsMessage_GetCrcErrors(msg),
AQH_RecvStatsMessage_GetIoErrors(msg),
AQH_RecvStatsMessage_GetNoBufferErrors(msg),
AQH_RecvStatsMessage_GetHandled(msg),
AQH_RecvStatsMessage_GetMsgSizeErrors(msg),
AQH_RecvStatsMessage_GetMissed(msg));
}

View File

@@ -17,12 +17,13 @@
AQHOME_API uint8_t AQH_RecvStatsMessage_GetInterface(const AQH_MESSAGE *msg);
AQHOME_API uint32_t AQH_RecvStatsMessage_GetUid(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_RecvStatsMessage_GetPacketsIn(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_RecvStatsMessage_GetCrcErrors(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_RecvStatsMessage_GetIoErrors(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_RecvStatsMessage_GetNoBufferErrors(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_RecvStatsMessage_GetHandled(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_RecvStatsMessage_GetMsgSizeErrors(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_RecvStatsMessage_GetMissed(const AQH_MESSAGE *msg);
AQHOME_API void AQH_RecvStatsMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);

View File

@@ -1,6 +1,6 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
* 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.
@@ -19,9 +19,17 @@
#define AQH_MSG_OFFS_SENDSTATS_UID 0 /* 4 bytes */
#define AQH_MSG_OFFS_SENDSTATS_PACKETSOUT 4 /* 2 bytes */
#define AQH_MSG_OFFS_SENDSTATS_COLLISIONS 6 /* 2 bytes */
#define AQH_MSG_OFFS_SENDSTATS_BUSY 8 /* 2 bytes */
#define AQH_MSG_OFFS_SENDSTATS_IFACE 4 /* 1 byte */
#define AQH_MSG_OFFS_SENDSTATS_PACKETSOUT 5 /* 2 bytes */
#define AQH_MSG_OFFS_SENDSTATS_COLLISIONS 7 /* 2 bytes */
#define AQH_MSG_OFFS_SENDSTATS_BUSY 9 /* 2 bytes */
uint8_t AQH_SendStatsMessage_GetInterface(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_IFACE, 0);
}
@@ -57,11 +65,12 @@ void AQH_SendStatsMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf
{
if (msg)
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: SENDSTATS %s (uid=0x%08x, out=%d, collisions=%d, busy line=%d)\n",
"0x%02x->0x%02x: SENDSTATS %s (uid=0x%08x, dev=%d, out=%d, collisions=%d, busy line=%d)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
sText,
(unsigned int) AQH_SendStatsMessage_GetUid(msg),
AQH_SendStatsMessage_GetInterface(msg),
AQH_SendStatsMessage_GetPacketsOut(msg),
AQH_SendStatsMessage_GetCollisions(msg),
AQH_SendStatsMessage_GetBusyErrors(msg));

View File

@@ -17,6 +17,7 @@
AQHOME_API uint8_t AQH_SendStatsMessage_GetInterface(const AQH_MESSAGE *msg);
AQHOME_API uint32_t AQH_SendStatsMessage_GetUid(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_SendStatsMessage_GetPacketsOut(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_SendStatsMessage_GetCollisions(const AQH_MESSAGE *msg);

View File

@@ -10,6 +10,8 @@
reportsensors
stats
router
hub
forwarder
</subdirs>
<extradist>

View File

@@ -3,15 +3,13 @@
<gwbuild>
<subdirs>
boot
main
</subdirs>
<extradist>
defs.asm
README
main.asm
</extradist>
</gwbuild>

359
avr/apps/forwarder/main.asm Normal file
View File

@@ -0,0 +1,359 @@
; ***************************************************************************
; copyright : (C) 2025 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. *
; ***************************************************************************
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; network interfaces
.equ NETDEV0_IFACENUM = 1
.equ NETDEV1_IFACENUM = 2
; ***************************************************************************
; data
.dseg
; nothing so far
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine AppForwarder_Init @global
AppForwarder_Init:
; set interface number for NETDEV0
ldi r16, NETDEV0_IFACENUM
sts netInterfaceData+NET_IFACE_OFFS_IFACENUM, r16
; set interface number for NETDEV1
ldi r16, NETDEV1_IFACENUM
sts netInterfaceData2+NET_IFACE_OFFS_IFACENUM, r16
sec
ret
; @end
; ---------------------------------------------------------------------------
; @routine AppForwarder_EveryDay @global
;
; @clobbers R16, R17, X
AppForwarder_EveryDay:
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
bigcall NET_Interface_ResetStats ; (R16, R17, X)
ldi yl, LOW(netInterfaceData2)
ldi yh, HIGH(netInterfaceData2)
bigcall NET_Interface_ResetStats ; (R16, R17, X)
ret
; @end
; ---------------------------------------------------------------------------
; @routine AppForwarder_Run @global
;
; Read messages from either interface and forward to the other one.
AppForwarder_Run:
rjmp appForwarderCheckRecvdMsg
; @end
; ---------------------------------------------------------------------------
; @routine appForwarderCheckRecvdMsg
;
; Read messages from either interface and forward to the other one.
; @return CFLAG set if something done, cleared otherwise
; @clobbers any
appForwarderCheckRecvdMsg:
rcall NET_PeekNextIncomingMsgNum ; check read queue (bufNum->r16)
brcc appForwarderCheckRecvdMsg_ret ; no msg, jmp
rcall NET_Buffer_Locate ; (R17)
push r16
ld r16, X ; read buffer header
andi r16, 0x0f ; keep interface number (in low nibble)
rcall appForwarderGetDeviceByIfaceNum ; Y=src interface (R17)
pop r16
brcc appForwarderCheckRecvdMsg_ret ; interface not found
adiw xh:xl, 1 ; point to message begin
push r16
rcall appForwarderHandleMsgAnyDev ; check for message we should handle (ping etc)
pop r16
; let system handle incoming messages
push r16
rcall appForwarderLetSysHandleMsg
pop r16
; forward to other interface
ldd r17, Y+NET_IFACE_OFFS_IFACENUM
rcall appForwarderSendToOtherDev
brcc appForwarderCheckRecvdMsg_ret ; could not add, jmp
rcall NET_GetNextIncomingMsgNum ; take off the queue
sec
appForwarderCheckRecvdMsg_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appForwarderHandleMsgAnyDev @global
;
; @param Y pointer to source interface for the message
; @param X pointer to received message
; @return CFLAG set if msg handled, cleared otherwise
; @clobbers any, !X
appForwarderHandleMsgAnyDev:
push xl
push xh
rcall appForwarderHandleMsgAnyDev_savedX
pop xh
pop xl
rjmp appForwarderHandleMsgAnyDev_end
appForwarderHandleMsgAnyDev_savedX:
adiw xh:xl, NETMSG_OFFS_CMD ; maybe move ping/reboot handling to all/main.asm?
ld r16, X
sbiw xh:xl, NETMSG_OFFS_CMD
cpi r16, NETMSG_CMD_REBOOT_REQUEST
breq appForwarderHandleMsgAnyDev_handleRebootMsg
cpi r16, NETMSG_CMD_PING
breq appForwarderHandleMsgAnyDev_handlePingMsg
cpi r16, NETMSG_CMD_CLAIM_ADDRESS
breq appForwarderHandleMsgAnyDev_handleClaimAddr
rjmp appForwarderHandleMsgAnyDev_clcRet
appForwarderHandleMsgAnyDev_handleRebootMsg:
rcall appForwarderHandleRebootRequest
ret
appForwarderHandleMsgAnyDev_handlePingMsg:
rcall appForwarderHandlePingRequest
clc
ret
appForwarderHandleMsgAnyDev_handleClaimAddr:
rcall appForwarderHandleClaimAddrRequest
clc
ret
appForwarderHandleMsgAnyDev_clcRet:
clc
appForwarderHandleMsgAnyDev_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appForwarderHandleClaimAddrRequest
;
; @param X pointer to received message
; @param Y pointer to source interface for the message
; @clobbers
appForwarderHandleClaimAddrRequest:
rcall NETMSG_Address_Read ; R18=cmd, R19=addr(R18, R19)
lds r16, netInterfaceData+NET_IFACE_OFFS_ADDRESS
cp r19, r16
brne appForwarderHandleClaimAddrRequest_ret
ldi r18, NETMSG_CMD_DENY_ADDRESS ; deny addr
rcall appForwarderSendAddrMsg ; (R16, R17, R18, R19, R20, R21, X, Y)
appForwarderHandleClaimAddrRequest_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appForwarderSendAddrMsg
;
; @param R18 command
; @param R19 address to send
; @param Y pointer to interface to send to
; @clobbers R16 (R17, R18, R19, R20, R21, X, Y)
appForwarderSendAddrMsg:
bigcall NET_Buffer_Alloc ; (R16, R17, X)
brcc appForwarderSendAddrMsg_end
push r16
adiw xh:xl, 1
bigcall NETMSG_Address_Write ; (R16, R17, R18, R19, R20, R21)
sbiw xh:xl, 1
pop r16
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
appForwarderSendAddrMsg_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appForwarderHandleRebootRequest
;
; Doesn't return if reboot msg is valid.
;
; @param X pointer to received message
appForwarderHandleRebootRequest:
rcall NETMSG_RebootRequestRead
brcc appForwarderHandleRebootRequest_end
; reboot
cli
bigjmp BOOTLOADER_ADDR
appForwarderHandleRebootRequest_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appForwarderHandlePingRequest
;
; @param X pointer to received message
; @param Y pointer to source interface for the message
appForwarderHandlePingRequest:
ld r17, X
lds r16, (netInterfaceData+NET_IFACE_OFFS_ADDRESS)
cp r16, r17
breq appForwarderHandlePingRequest_forMe
cpi r17, 0xff
breq appForwarderHandlePingRequest_forMe
clc
rjmp appForwarderHandlePingRequest_end
appForwarderHandlePingRequest_forMe:
adiw xh:xl, NETMSG_OFFS_SRCADDR
ld r17, X
sbiw xh:xl, NETMSG_OFFS_SRCADDR
push r17
bigcall NET_Buffer_Alloc ; (R16, R17, X)
pop r17
brcc appForwarderHandlePingRequest_end ; jmp on error
push r16 ; buffer num
mov r16, r17 ; DEST addr
adiw xh:xl, 1
bigcall NETMSG_Pong_Write ; (R16, R17, R18, R19, R20, X)
sbiw xh:xl, 1
pop r16 ; buffer num
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
appForwarderHandlePingRequest_end:
ret
; ---------------------------------------------------------------------------
; @routine appForwarderLetSysHandleMsg
;
; @param X pointer to msg to handle (point behind the buffer header!)
; @param Y pointer to source interface for the message
; @clobbers any, !X
appForwarderLetSysHandleMsg:
ld r16, X
cpi r16, 0xff
breq appForwarderLetSysHandleMsg_forMe
lds r17, netInterfaceData+NET_IFACE_OFFS_ADDRESS
cp r16, r17
brne appForwarderLetSysHandleMsg_end
appForwarderLetSysHandleMsg_forMe:
push xl
push xh
rcall onMessageReceived
pop xh
pop xl
push xl
push xh
rcall mainModulesOnPacketReceived
pop xh
pop xl
push xl
push xh
rcall mainAppsOnPacketReceived
pop xh
pop xl
appForwarderLetSysHandleMsg_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appForwarderSendToOtherDev
; @param r16 buffer num
; @param r17 src interface num
appForwarderSendToOtherDev:
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
ldd r18, Y+NET_IFACE_OFFS_IFACENUM
andi r18, 0x0f
cp r18, r17
breq appForwarderSendToAllDevsBut_check2
bigcall NET_Interface_AddOutgoingMsgNum ; (R17, R18, X)
rjmp appForwarderSendToOtherDev_ret
appForwarderSendToAllDevsBut_check2:
ldi yl, LOW(netInterfaceData2)
ldi yh, HIGH(netInterfaceData2)
ldd r18, Y+NET_IFACE_OFFS_IFACENUM
andi r18, 0x0f
cp r18, r17
breq appForwarderSendToOtherDev_ret
bigcall NET_Interface_AddOutgoingMsgNum ; (R17, R18, X)
appForwarderSendToOtherDev_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appForwarderGetDeviceByIfaceNum
;
; @param r16 interface number
; @return CFLAG set if interface found (cleared otherwise)
; @return Y pointer to interface with given number
; @clobbers r17
appForwarderGetDeviceByIfaceNum:
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
ldd r17, Y+NET_IFACE_OFFS_IFACENUM
cp r16, r17
breq appForwarderGetDeviceByIfaceNum_secRet
ldi yl, LOW(netInterfaceData2)
ldi yh, HIGH(netInterfaceData2)
ldd r17, Y+NET_IFACE_OFFS_IFACENUM
cp r16, r17
breq appForwarderGetDeviceByIfaceNum_secRet
clc
rjmp appForwarderGetDeviceByIfaceNum_ret
appForwarderGetDeviceByIfaceNum_secRet:
sec
appForwarderGetDeviceByIfaceNum_ret:
ret
; @end

View File

@@ -3,15 +3,13 @@
<gwbuild>
<subdirs>
boot
main
</subdirs>
<extradist>
defs.asm
README
main.asm
</extradist>
</gwbuild>

715
avr/apps/hub/main.asm Normal file
View File

@@ -0,0 +1,715 @@
; ***************************************************************************
; copyright : (C) 2025 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. *
; ***************************************************************************
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; network interfaces
; ***************************************************************************
; data
.dseg
appHubDataBegin:
appHubRangeBegin: .byte 1
appHubRangeEnd: .byte 1
appHubDataEnd:
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine AppHub_Init @global
AppHub_Init:
ldi xh, HIGH(appHubDataBegin)
ldi xl, LOW(appHubDataBegin)
clr r16
ldi r17, (appHubDataEnd-appHubDataBegin)
rcall Utils_FillSram
; set device address and interface number in all interfaces
ldi r16, 0xf0 ; hub address
ldi r17, 1 ; first interface number
rcall appHubAllSetAddrIfaceNumAndRange ; (R17, R19, R20, Y)
; TODO: read ranges from EEPROM
; TODO: send range msg to all interfaces
ret
; @end
; ---------------------------------------------------------------------------
; @routine AppHub_Run @global
;
; Read messages from any interface, handle them and probably forward to the other
; interfaces.
; @return CFLAG set if something done, cleared otherwise
; @clobbers all
AppHub_Run:
rjmp appHubCheckRecvdMsg
; @end
; ---------------------------------------------------------------------------
; @routine appHubGetDeviceByIfaceNum
;
; @param r16 interface number
; @clobbers r17, r19, r20, Y
appHubGetDeviceByIfaceNum:
ldi r19, COM_PORTS
ldi yl, LOW(com2w0_iface) ; first interface
ldi yh, HIGH(com2w0_iface)
appHubGetDeviceByIfaceNum_loop:
ldd r17, Y+NET_IFACE_OFFS_IFACENUM
cp r16, r17
sec ; mark "found"
breq appHubGetDeviceByIfaceNum_ret
ldi r20, COM2W_IFACE_SIZE
add yl, r20
adc yh, r20
sub yh, r20
dec r19
brne appHubGetDeviceByIfaceNum_loop
clc ; mark "not found"
appHubGetDeviceByIfaceNum_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubAllSetAddrIfaceNumAndRange
;
; @clobbers R17, R18, R19, R20, Y
appHubAllSetAddrIfaceNumAndRange:
ldi r19, COM_PORTS
ldi yl, LOW(com2w0_iface) ; first interface
ldi yh, HIGH(com2w0_iface)
ldi r18, 0x10
appHubAllSetAddrIfaceNumAndRange_loop:
; set address
std Y+NET_IFACE_OFFS_ADDRESS, r16
; set interface number
std Y+NET_IFACE_OFFS_IFACENUM, r17
inc r17
; set default range (step of 16)
std Y+NET_IFACE_OFFS_RANGE_BEGIN, r18
subi r18, -15
std Y+NET_IFACE_OFFS_RANGE_END, r18
inc r18
; next interface
ldi r20, COM2W_IFACE_SIZE
add yl, r20
adc yh, r20
sub yh, r20
dec r19
brne appHubAllSetAddrIfaceNumAndRange_loop
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubSendRangeMsg
;
; @param R18 msg code
; @param Y pointer to interface data
; @return CFLAG set if message enqueued, cleared on error
; @clobbers (R16, R17, R18, R19, R20, R21, R24, R25, X)
appHubSendRangeMsg:
bigcall NET_Buffer_Alloc ; (R16, R17, X)
brcc appHubSendRangeMsg_end
push r16
ldd r20, Y+NET_IFACE_OFFS_RANGE_BEGIN
ldd r21, Y+NET_IFACE_OFFS_RANGE_END
adiw xh:xl, 1
bigcall NETMSG_Range_Write ; (R16, R17, R18, R19, R20, R21)
sbiw xh:xl, 1
pop r16
rcall appHubSendMsg ; (R16, R17, R18, R24, R25, X)
appHubSendRangeMsg_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubSendDenyAddrR19
;
; @param R19 address to send
; @clobbers R16, R17, R18, R19, R20, R21, X, Y
appHubSendDenyAddrR19:
ldi r18, NETMSG_CMD_DENY_ADDRESS ; deny addr
rjmp appHubSendAddrMsg ; (R16, R17, R18, R19, R20, R21, X, Y)
; @end
; ---------------------------------------------------------------------------
; @routine appHubSendAddrMsg
;
; @param R18 command
; @param R19 address to send
; @clobbers R16 (R17, R18, R19, R20, R21, X, Y)
appHubSendAddrMsg:
bigcall NET_Buffer_Alloc ; (R16, R17, X)
brcc appHubSendAddrMsg_end
push r16
adiw xh:xl, 1
bigcall NETMSG_Address_Write ; (R16, R17, R18, R19, R20, R21)
sbiw xh:xl, 1
pop r16
rcall appHubSendMsg ; (R16, R17, R18, R24, R25, X)
appHubSendAddrMsg_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubSendValueResponse
;
; @param R17 value id
; @param R19:R18 value
; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100)
; @param R23 command
; @param R25:R24 ref msg id
; @return CFLAG on success, cleared on error
; @clobbers r22 (r16, r17, r18, r19, r20, r21, r23, r24, r25, X)
appHubSendValueResponse:
push r17
rcall NET_Buffer_Alloc ; (R16, R17, X)
pop r17
brcc appHubSendValueResponse_end ; jmp on error
push r16 ; buffer num
ldi r16, 0xff ; DEST addr
clr r22 ; value type
adiw xh:xl, 1
rcall NETMSG_ValueWriteResponse ; (R16, R17, R18, R19, R20, R21, R23, R24, R25)
sbiw xh:xl, 1
pop r16 ; buffer num
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
appHubSendValueResponse_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubSendMsg
;
; @param R16 num of allocated buffer
; @param Y pointer to interface data
; @param X msg to send (points to start of allocated buffer, e.g. buffer header)
; @return CFLAG set if message enqueued, cleared on error
; @clobbers R16 (R17, R18, R24, R25, X)
appHubSendMsg:
bigcall NET_Interface_AddOutgoingMsgNum ; (R17, R18, X)
brcs appHubSendMsg_end
bigcall NET_Buffer_ReleaseByNum ; (R16, X)
ldi r16, NET_IFACE_OFFS_ERR_NOBUF_LOW
rcall NET_Interface_IncCounter16 ; (R24, R25)
clc
appHubSendMsg_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubAllResetStats
;
; @clobbers r19, r20, Y (r16, r17, X)
appHubAllResetStats:
ldi r19, COM_PORTS
ldi yl, LOW(com2w0_iface) ; first interface
ldi yh, HIGH(com2w0_iface)
appHubAllResetStats_loop:
bigcall NET_Interface_ResetStats ; (R16, R17, X)
ldi r20, COM2W_IFACE_SIZE
add yl, r20
adc yh, r20
sub yh, r20
dec r19
brne appHubAllResetStats_loop
ret
; @end
; ---------------------------------------------------------------------------
; @routine AppHub_EveryDay @global
;
; @clobbers R16, R17, X
AppHub_EveryDay:
rcall appHubAllResetStats
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubSendMsgToAllOthers
;
; @param R16 buffer number
; @param X buffer pointer
; @clobbers r17, r19, r20, r24, r25 (r16, r18, X)
appHubSendMsgToAllOthers:
ld r24, X
andi r24, 0x0f ; get sender interface num
ldi r19, COM_PORTS ; number of ports
ldi yl, LOW(com2w0_iface) ; first interface
ldi yh, HIGH(com2w0_iface)
appHubSendMsgToAllOthers_loop:
ldd r25, Y+NET_IFACE_OFFS_IFACENUM
cp r24, r25 ; same interface?
breq appHubSendMsgToAllOthers_next
; current iface is not source, send and inc ref counter
bigcall NET_Interface_AddOutgoingMsgNum ; (R17, R18, X)
brcs appHubSendMsgToAllOthers_added
; inc error counter
push r24
mov r17, r16 ; save r16
ldi r16, NET_IFACE_OFFS_ERR_NOBUF_LOW
bigcall NET_Interface_IncCounter16 ; (R24, R25)
mov r16, r17 ; restore r16
pop r24
rjmp appHubSendMsgToAllOthers_next
appHubSendMsgToAllOthers_added:
mov r17, r16 ; save r16
bigcall NET_Buffer_IncRef ; (r16)
mov r16, r17 ; restore r16
appHubSendMsgToAllOthers_next:
ldi r20, COM2W_IFACE_SIZE
add yl, r20
adc yh, r20
sub yh, r20
dec r19
brne appHubSendMsgToAllOthers_loop
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubHandleMsgLocally
;
; @param X pointer to received buffer (points to header byte)
; @param Y pointer to IFACE data from which msg was received
; @clobbers all, !X
appHubHandleMsgLocally:
push xl
push xh
rcall appHubHandleMsgLocally_savedX
pop xh
pop xl
rjmp appHubHandleMsgLocally_ret
appHubHandleMsgLocally_savedX:
; get message type
adiw xh:xl, NETMSG_OFFS_CMD+1 ; account for header byte
ld r16, X
sbiw xh:xl, NETMSG_OFFS_CMD+1
cpi r16, NETMSG_CMD_PING
breq appHubHandleMsgLocally_handlePingMsg
cpi r16, NETMSG_CMD_REBOOT_REQUEST
breq appHubHandleMsgLocally_handleRebootMsg
cpi r16, NETMSG_CMD_VALUE_SET
breq appHubHandleMsgLocally_handleSetValue
rjmp appHubHandleMsgLocally_ret
appHubHandleMsgLocally_handlePingMsg:
rjmp appHubHandlePingMsg
appHubHandleMsgLocally_handleRebootMsg:
rjmp appHubHandleRebootMsg
appHubHandleMsgLocally_handleSetValue:
rjmp appHubHandleSetValueMsg
appHubHandleMsgLocally_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubHandlePingMsg
;
; @param X pointer to received message
; @clobbers any, !X, !Y
appHubHandlePingMsg:
adiw xh:xl, NETMSG_OFFS_DESTADDR+1
ld r17, X
sbiw xh:xl, NETMSG_OFFS_DESTADDR+1
ldd r16, Y+NET_IFACE_OFFS_ADDRESS
cp r16, r17
breq appHubHandlePingMsg_forMe
cpi r17, 0xff
breq appHubHandlePingMsg_forMe
clc
rjmp appHubHandlePingMsg_end
appHubHandlePingMsg_forMe:
adiw xh:xl, NETMSG_OFFS_SRCADDR+1
ld r17, X
sbiw xh:xl, NETMSG_OFFS_SRCADDR+1
push r17
bigcall NET_Buffer_Alloc ; (R16, R17, X)
pop r17
brcc appHubHandlePingMsg_end ; jmp on error
push r16 ; buffer num
mov r16, r17 ; DEST addr
adiw xh:xl, 1
bigcall NETMSG_Pong_Write ; (R16, R17, R18, R19, R20, X)
sbiw xh:xl, 1
pop r16 ; buffer num
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
appHubHandlePingMsg_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubHandleRebootMsg
;
; Doesn't return if reboot msg is valid.
;
; @param X pointer to received message
appHubHandleRebootMsg:
rcall NETMSG_RebootRequestRead
brcc appHubHandleRebootMsg_end
; reboot
cli
bigjmp BOOTLOADER_ADDR
appHubHandleRebootMsg_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubHandleSetValueMsg
;
; @param X pointer to received message
; @param Y pointer to IFACE data from which msg was received
; @clobbers all, !Y
appHubHandleSetValueMsg:
adiw xh:xl, NETMSG_OFFS_DESTADDR+1
ld r17, X
sbiw xh:xl, NETMSG_OFFS_DESTADDR+1
ldd r16, Y+NET_IFACE_OFFS_ADDRESS
cp r16, r17
breq appHubHandleSetValueMsg_forMe
cpi r17, 0xff
breq appHubHandleSetValueMsg_forMe
rjmp appHubHandleSetValueMsg_ret
appHubHandleSetValueMsg_forMe:
rcall NETMSG_ValueRead ; (none)
cpi r17, VALUE_ID_HUB_SETRANGE1
brcs appHubHandleSetValueMsg_ret
cpi r17, VALUE_ID_HUB_SETRANGE8+1
brcc appHubHandleSetValueMsg_ret
appHubHandleSetValueMsg_setRange:
push yl
push yh
subi r17, (VALUE_ID_HUB_SETRANGE1-1)
push r18
push r19
; send ACK back the same interface the request came from
push r17 ; interface number
ldi r23, NETMSG_CMD_VALUE_SET_ACK
rcall appHubSendValueResponse ; r22 (r16, r17, r18, r19, r20, r21, r23, r24, r25, X)
pop r16 ; pop interface number to r16 (from r17)
rcall appHubGetDeviceByIfaceNum ; Y=interface to modify (r17, r19, r20)
pop r19
pop r18
; modify interface
std Y+NET_IFACE_OFFS_RANGE_BEGIN, r18
std Y+NET_IFACE_OFFS_RANGE_END, r19
; TODO: store new config
; let subnodes of modified interface re-eunumerate
ldi r18, NETMSG_CMD_REENUM
rcall appHubSendRangeMsg ; (R16, R17, R18, R19, R20, R21, X)
pop yh
pop yl
appHubHandleSetValueMsg_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubHandleRoutingMsg
;
; @param X pointer to received buffer (points to header byte)
; @param Y pointer to IFACE data from which msg was received
; @clobbers all, !X
appHubHandleRoutingMsg:
push xl
push xh
rcall appHubHandleRoutingMsg_savedX
pop xh
pop xl
rjmp appHubHandleRoutingMsg_ret
appHubHandleRoutingMsg_savedX:
; get message type
adiw xh:xl, NETMSG_OFFS_CMD+1 ; account for header byte
ld r16, X
sbiw xh:xl, NETMSG_OFFS_CMD+1
cpi r16, NETMSG_CMD_NEED_ADDRESS
breq appHubHandleRoutingMsg_handleNeedAddress
cpi r16, NETMSG_CMD_CLAIM_ADDRESS
breq appHubHandleRoutingMsg_handleClaimAddress
clc
rjmp appHubHandleRoutingMsg_ret
appHubHandleRoutingMsg_handleNeedAddress:
rcall appHubHandleNeedAddressMsg
rjmp appHubHandleRoutingMsg_secRet
appHubHandleRoutingMsg_handleClaimAddress:
rcall appHubHandleClaimAddressMsg
appHubHandleRoutingMsg_secRet:
sec
appHubHandleRoutingMsg_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubHandleNeedAddressMsg
;
; @param X pointer to received message
; @param Y pointer to IFACE data from which msg was received
; @clobbers all, !Y
appHubHandleNeedAddressMsg:
ldi r18, NETMSG_CMD_ADDRESS_RANGE
rcall appHubSendRangeMsg ; (R16, R17, R18, R19, R20, R21, X)
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubHandleClaimAddressMsg
;
; @param X pointer to received message
; @param Y pointer to IFACE data from which msg was received
; @clobbers all, !Y
appHubHandleClaimAddressMsg:
rcall NETMSG_Address_Read ; R18=cmd, R19=addr(R18, R19)
rcall appHubIsR19InRange
brcs appHubHandleClaimAddressMsg_end
; is not in subnet range, deny
rcall appHubSendDenyAddrR19 ; (R16, R17, R18, R19, R20, R21, X)
appHubHandleClaimAddressMsg_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubIsR19InRange
;
; @param R19 address to check against range
; @param Y pointer to IFACE data
; @clobbers R16
appHubIsR19InRange:
ldd r16, Y+NET_IFACE_OFFS_RANGE_BEGIN
cp r19, r16
brcs appHubIsR19InRangeClcRet
ldd r16, Y+NET_IFACE_OFFS_RANGE_END
cp r16, r19
brcs appHubIsR19InRangeClcRet
sec
rjmp appHubIsR19InRange_end
appHubIsR19InRangeClcRet:
clc
appHubIsR19InRange_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubCheckRecvdMsg
;
; Read messages from any interface and forward to the other ones.
;
; @return CFLAG set if something done, cleared otherwise
appHubCheckRecvdMsg:
rcall NET_PeekNextIncomingMsgNum ; check read queue (R16=bufNum)
brcc appHubCheckRecvdMsg_end ; no msg, jmp
rcall NET_Buffer_Locate ; (R17)
rcall appHubHandleRecvdMsg ; (all, !X)
rcall NET_GetNextIncomingMsgNum ; take off the queue
rcall NET_Buffer_ReleaseByNum ; (R16, X)
sec ; we had a message, so something was done
appHubCheckRecvdMsg_end:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubHandleRecvdMsg
;
; @param R16 buffer number
; @param X pointer to received message
; @clobbers all, !X
appHubHandleRecvdMsg:
mov r18, r16
ld r16, X
andi r16, 0x0f
rcall appHubGetDeviceByIfaceNum ; Y=source iface (r17, r19, r20)
brcc appHubHandleRecvdMsg_ret
; filter out routing msgs
push yl
push yh
push r18
rcall appHubHandleRoutingMsg ; (all, !X)
pop r18
pop yh
pop yl
brcs appHubHandleRecvdMsg_ret
; check for PING, SETVALUE etc
push r18
push yl
push yh
rcall appHubHandleMsgLocally ; (all, !X)
pop yh
pop yl
; let other apps and modules handle message
push xl
push xh
bigcall mainHandleMessages
pop xh
pop xl
pop r18
; forward message to all other interfaces
mov r16, r18 ; buffer number
push xl
push xh
rcall appHubSendMsgToAllOthers ; (r17, r19, r20, r24, r25 (r16, r18, X)
pop xh
pop xl
appHubHandleRecvdMsg_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine appHubWriteConfToEeprom
;
; @clobbers R16, X (R17)
appHubWriteConfToEeprom:
; write range begin
ldi xl, LOW(EEPROM_OFFS_ROUTER_RANGE_BEGIN)
ldi xh, HIGH(EEPROM_OFFS_ROUTER_RANGE_BEGIN)
lds r16, appHubRangeBegin
rcall Eeprom_WriteByteIfChanged ; (R17)
brcc appHubWriteConfToEeprom_end
; write range end
ldi xl, LOW(EEPROM_OFFS_ROUTER_RANGE_END)
ldi xh, HIGH(EEPROM_OFFS_ROUTER_RANGE_END)
lds r16, appHubRangeEnd
rcall Eeprom_WriteByteIfChanged ; (R17)
appHubWriteConfToEeprom_end:
ret
; @end
#if 0
; ---------------------------------------------------------------------------
; @routine appHubReadConfFromEeprom
;
; @clobbers R16, X (R17)
appHubReadConfFromEeprom:
; read range begin
ldi xl, LOW(EEPROM_OFFS_ROUTER_RANGE_BEGIN)
ldi xh, HIGH(EEPROM_OFFS_ROUTER_RANGE_BEGIN)
rcall Eeprom_ReadByte
brcc appHubReadConfFromEeprom_end
cpi r16, 0xff
breq appHubReadConfFromEeprom_okay ; not set, jmp
cpi r16, 2 ; range should at least start at 2 to assign 1 to router
brcs appHubReadConfFromEeprom_okay
sts appHubRangeBegin, r16
dec r16
sts netInterfaceData+NET_IFACE_OFFS_ADDRESS, r16 ; use addr rangeBegin-1 for router itself
sts netInterfaceData2+NET_IFACE_OFFS_ADDRESS, r16 ; use same address for both interfaces to save on addresses
; read range end
ldi xl, LOW(EEPROM_OFFS_ROUTER_RANGE_END)
ldi xh, HIGH(EEPROM_OFFS_ROUTER_RANGE_END)
rcall Eeprom_ReadByte
brcc appHubReadConfFromEeprom_end
cpi r16, 0xff
breq appHubReadConfFromEeprom_okay
sts appHubRangeEnd, r16
appHubReadConfFromEeprom_okay:
sec
appHubReadConfFromEeprom_end:
ret
; @end
#endif

View File

@@ -189,6 +189,15 @@ appNetworkHandleRebootRequest_end:
appNetworkHandlePingRequest:
ld r17, X
lds r16, (netInterfaceData+NET_IFACE_OFFS_ADDRESS)
cp r16, r17
breq appNetworkHandlePingRequest_forMe
cpi r17, 0xff
breq appNetworkHandlePingRequest_forMe
clc
rjmp appNetworkHandlePingRequest_end
appNetworkHandlePingRequest_forMe:
adiw xh:xl, NETMSG_OFFS_SRCADDR
ld r17, X
push r17

View File

@@ -25,7 +25,13 @@ AppNetwork_SendTxdStats:
bigcall NETMSG_SendStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
sbiw xh:xl, 1
pop r16
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
push yl
push yh
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
pop yh
pop yl
AppNetwork_SendTxdStats_end:
ret
; @end
@@ -35,7 +41,7 @@ AppNetwork_SendTxdStats_end:
; ---------------------------------------------------------------------------
; @routine AppNetwork_SendRxdStats
; @param Y network interface to work with
; @param Y network interface whose stats to send
; @clobbers R16, X (R17, R18, R19, R20, R21, Z)
AppNetwork_SendRxdStats:
@@ -46,7 +52,13 @@ AppNetwork_SendRxdStats:
bigcall NETMSG_RecvStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
sbiw xh:xl, 1
pop r16
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
push yl
push yh
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
pop yh
pop yl
AppNetwork_SendRxdStats_end:
ret
; @end
@@ -54,9 +66,8 @@ AppNetwork_SendRxdStats_end:
; ---------------------------------------------------------------------------
; @routine AppNetwork_SendRxdStats
; @routine AppNetwork_SendMemStats
; @param Y network interface to work with
; @clobbers R16, X (R17, R18, R19, R20, R21, Z)
AppNetwork_SendMemStats:
@@ -67,7 +78,13 @@ AppNetwork_SendMemStats:
bigcall NETMSG_MemStats_Write ; (R16, R17, R18, R19, R20, R21)
sbiw xh:xl, 1
pop r16
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
push yl
push yh
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
pop yh
pop yl
AppNetwork_SendMemStats_end:
ret
; @end

View File

@@ -11,7 +11,7 @@
; ***************************************************************************
; defines
.equ APP_STATS_INTERVAL_MINS = 31
.equ APP_STATS_INTERVAL_MINS = 30
@@ -62,10 +62,6 @@ AppStats_OnEveryMinute:
ret
AppStats_OnEveryMinute_noIrq:
; ldi yl, LOW(netInterfaceData)
; ldi yh, HIGH(netInterfaceData)
; rcall AppNetwork_SendRxdStats ; debug
lds r16, appStatsTimer
inc r16
cpi r16, APP_STATS_INTERVAL_MINS
@@ -73,72 +69,11 @@ AppStats_OnEveryMinute_noIrq:
clr r16
AppStats_OnEveryMinute_store:
sts appStatsTimer, r16
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
ldi r17, AQHOME_VALUEID_STATS_PACKETS_IN
ldi xl, LOW(netInterfaceData)
ldi xh, HIGH(netInterfaceData)
cpi r16, 1
breq AppStats_OnEveryMinute_sendDevice
cpi r16, 3
breq AppStats_OnEveryMinute_sendPacketsIn
cpi r16, 5
breq AppStats_OnEveryMinute_sendPacketsOut
cpi r16, 6
breq AppStats_OnEveryMinute_sendDevice
cpi r16, 7
breq AppStats_OnEveryMinute_sendContentErrs
cpi r16, 9
breq AppStats_OnEveryMinute_sendIoErrs
cpi r16, 10
breq AppStats_OnEveryMinute_sendDevice
cpi r16, 11
breq AppStats_OnEveryMinute_sendNoBufErrs
cpi r16, 13
breq AppStats_OnEveryMinute_sendCollisionErrs
cpi r16, 14
breq AppStats_OnEveryMinute_sendDevice
cpi r16, 15
breq AppStats_OnEveryMinute_sendBusyErrs
#ifdef APP_STATS_NETDEV2
ldi r17, AQHOME_VALUEID_STATS_PACKETS_IN2
ldi xl, LOW(netInterfaceData2)
ldi xh, HIGH(netInterfaceData2)
cpi r16, 16
breq AppStats_OnEveryMinute_sendPacketsIn
cpi r16, 17
breq AppStats_OnEveryMinute_sendPacketsOut
cpi r16, 18
breq AppStats_OnEveryMinute_sendDevice
cpi r16, 19
breq AppStats_OnEveryMinute_sendContentErrs
cpi r16, 20
breq AppStats_OnEveryMinute_sendIoErrs
cpi r16, 21
breq AppStats_OnEveryMinute_sendDevice
cpi r16, 22
breq AppStats_OnEveryMinute_sendNoBufErrs
cpi r16, 23
breq AppStats_OnEveryMinute_sendDevice
cpi r16, 24
breq AppStats_OnEveryMinute_sendCollisionErrs
cpi r16, 25
breq AppStats_OnEveryMinute_sendBusyErrs
#endif
#ifdef MODULES_HEAP
cpi r16, 26
breq AppStats_OnEveryMinute_sendHeapUsed
cpi r16, 27
breq AppStats_OnEveryMinute_sendHeapfree
#endif
cpi r16, 28
breq AppStats_OnEveryMinute_sendDevice
ret
AppStats_OnEveryMinute_sendDevice:
mov r17, r16
andi r17, 3
brne AppStats_OnEveryMinute_sendStats
; send device announcement
push yl
push yh
ldi yl, LOW(netInterfaceData)
@@ -151,81 +86,51 @@ AppStats_OnEveryMinute_sendDevice:
#endif
pop yh
pop yl
ret
AppStats_OnEveryMinute_sendPacketsIn:
ldi r16, 0
rjmp appStatsSendDeviceStat
AppStats_OnEveryMinute_sendPacketsOut:
ldi r16, 1
rjmp appStatsSendDeviceStat
AppStats_OnEveryMinute_sendContentErrs:
ldi r16, 2
rjmp appStatsSendDeviceStat
AppStats_OnEveryMinute_sendIoErrs:
ldi r16, 3
rjmp appStatsSendDeviceStat
AppStats_OnEveryMinute_sendNoBufErrs:
ldi r16, 4
rjmp appStatsSendDeviceStat
AppStats_OnEveryMinute_sendCollisionErrs:
ldi r16, 5
rjmp appStatsSendDeviceStat
AppStats_OnEveryMinute_sendBusyErrs:
ldi r16, 6
rjmp appStatsSendDeviceStat
AppStats_OnEveryMinute_sendStats:
cpi r16, 2
breq AppStats_OnEveryMinute_sendMemStats
#ifdef MODULES_HEAP
AppStats_OnEveryMinute_sendHeapUsed:
ldi r17, AQHOME_VALUEID_STATS_HEAP_USED
lds r18, heapUsed
lds r19, heapUsed+1
rjmp appStatsSend16BitValue
AppStats_OnEveryMinute_sendHeapfree:
ldi r17, AQHOME_VALUEID_STATS_HEAP_FREE
lds r18, heapFree
lds r19, heapFree+1
rjmp appStatsSend16BitValue
cpi r16, 3
breq AppStats_OnEveryMinute_sendRecvStats1
cpi r16, 5
breq AppStats_OnEveryMinute_sendSendStats1
#ifdef APP_STATS_NETDEV2
cpi r16, 6
breq AppStats_OnEveryMinute_sendRecvStats2
cpi r16, 7
breq AppStats_OnEveryMinute_sendSendStats2
#endif
; add more here
ret
AppStats_OnEveryMinute_sendMemStats:
rjmp AppNetwork_SendMemStats
AppStats_OnEveryMinute_sendRecvStats1:
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
rjmp AppNetwork_SendRxdStats
AppStats_OnEveryMinute_sendSendStats1:
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
rjmp AppNetwork_SendTxdStats
#ifdef APP_STATS_NETDEV2
AppStats_OnEveryMinute_sendRecvStats2:
ldi yl, LOW(netInterfaceData2)
ldi yh, HIGH(netInterfaceData2)
rjmp AppNetwork_SendRxdStats
AppStats_OnEveryMinute_sendSendStats2:
ldi yl, LOW(netInterfaceData2)
ldi yh, HIGH(netInterfaceData2)
rjmp AppNetwork_SendTxdStats
#endif
; @end
; ---------------------------------------------------------------------------
; @routine AppStats_OnEveryMinute @global
;
; @param r16 index into device table (e.g. 0 for NET_IFACE_OFFS_PACKETSIN_LOW)
; @param r17 offset to first value id (e.g. AQHOME_VALUEID_STATS_PACKETS_IN for device 0,
; AQHOME_VALUEID_STATS_PACKETS_IN2 for device 1)
; @param Y pointer to device to send data to
; @param X pointer to device to inspect
appStatsSendDeviceStat:
add r17, r16
lsl r16
adiw xh:xl, NET_IFACE_OFFS_PACKETSIN_LOW
add xl, r16
adc xh, r16
sub xh, r16
ld r18, X+
ld r19, X
rjmp appStatsSend16BitValue
; @end
; ---------------------------------------------------------------------------
; @routine AppStats_OnEveryMinute @global
;
; @param R17 value id
; @param R19:R18 value
appStatsSend16BitValue:
ldi r20, 1
clr r21
ldi r22, AQHOME_VALUETYPE_STATS
bigjmp Main_SendValueReport
; @end

View File

@@ -52,7 +52,7 @@ l_loop:
brcs l_loop
rjmp l_end ; use cleared CFLAG
l_foundfree:
ldi r16, 0x80 ; mark as used
ldi r16, 0x10 ; mark as used
st X, r16
mov r16, r17
sec ; set CFLAG, return bufnum in r16, pointre in X

View File

@@ -120,7 +120,7 @@ RingBufferY_Reset:
;
; @return CFLAG on success, cleared on error
; @return r16 byte read
; @param Y pointer to start of interface data
; @param Y base address of ringbuffer struct
; @clobbers R17, R18, X
RingBufferY_ReadByteGuarded:

View File

@@ -18,7 +18,8 @@
; @clobbers r22
Utils_WaitFor50MicroSecs:
Utils_WaitNanoSecs 50000, 7, r22 ; wait for 50us (minus RCALL and RET)
Utils_WaitNanoSecs 25000, 0, r22 ; wait for 25us
Utils_WaitNanoSecs 25000, 7, r22 ; wait for 25us (minus RCALL and RET)
ret
; @end

View File

@@ -28,18 +28,17 @@
c02
n14
n16
n19
n20
n21
n22
n23
n24
n25
n26
n27
r04
n28
r05
r06
s03
t03
t04
</subdirs>
</gwbuild>

View File

@@ -33,6 +33,14 @@ initApps:
bigcall AppRouter_Init
#endif
#ifdef APPS_HUB
bigcall AppHub_Init
#endif
#ifdef APPS_FORWARDER
bigcall AppForwarder_Init
#endif
#ifdef APPS_MOTION
bigcall AppMotion_Init
#endif
@@ -74,6 +82,20 @@ runApps:
sbci r16, 0 ; decrease r16 only if CFLAG set
#endif
#ifdef APPS_HUB
push r16
bigcall AppHub_Run
pop r16
sbci r16, 0 ; decrease r16 only if CFLAG set
#endif
#ifdef APPS_FORWARDER
push r16
bigcall AppForwarder_Run
pop r16
sbci r16, 0 ; decrease r16 only if CFLAG set
#endif
; add more modules here
tst r16

View File

@@ -103,13 +103,11 @@ systemSetupTimer0: ; setup timer for IRQ every 100ms
ldi r16, 1
sts baseTimerModuleReloadValue, r16
sts baseTimerModuleTickCounter, r16
.endif
;
; Settings for clock 8Mhz
; use timer0 with OCR0=78 (irq every 9.984 millisecs), baseTimerModuleReloadValue 10
;
.if clock == 8000000
.elif clock == 8000000
; CMP interrupt about every 10ms
ldi r16, 78-1
outr OCR0A, r16
@@ -117,6 +115,24 @@ systemSetupTimer0: ; setup timer for IRQ every 100ms
ldi r16, 10
sts baseTimerModuleReloadValue, r16
sts baseTimerModuleTickCounter, r16
.elif clock == 10000000
; CMP-A interrupt about every 10ms
ldi r16, 98-1 ; (10,000,000/1024)/10 = 97.65625
outr OCR0A, r16
ldi r16, 10
sts baseTimerModuleReloadValue, r16
sts baseTimerModuleTickCounter, r16
.elif clock == 20000000
; CMP-A interrupt about every 5ms
ldi r16, 98-1
outr OCR0A, r16
ldi r16, 20
sts baseTimerModuleReloadValue, r16
sts baseTimerModuleTickCounter, r16
.else
.error "Unhandled clock frequency"
.endif
ldi r16, (1<<OCF0A) ; clear pending interrupts

View File

@@ -119,6 +119,37 @@
#endif
#ifdef MODULES_COM2WN
.include "modules/com2w/defs.asm"
.include "modules/com2w/com2wn_init.asm"
.include "modules/com2w/com2wn_io.asm"
.include "modules/com2w/com2wn_irq.asm"
.include "modules/com2w/com2wn_recv.asm"
.include "modules/com2w/com2wn_run.asm"
.include "modules/com2w/com2wn_send.asm"
.include "modules/com2w/com2wn_wait.asm"
.include "modules/com2w/com2wn_data.asm"
#endif
#ifdef MODULES_UARTFD0
.include "modules/uart_fd/defs.asm"
.include "modules/uart_fd/macros.asm"
.include "modules/uart_fd/uartfd0.asm"
#endif
#ifdef MODULES_UARTFD1
.include "modules/uart_fd/defs.asm"
.include "modules/uart_fd/macros.asm"
.include "modules/uart_fd/uartfd1.asm"
#endif
#ifdef MODULES_CLOCK
.include "modules/clock/main.asm"
#endif
@@ -130,6 +161,16 @@
#endif
#endif
#ifdef MODULES_LED_SIGNAL
.include "modules/led_signal/main.asm"
#endif
#ifdef MODULES_LED_ACTIVITY
.include "modules/led_activity/main.asm"
#endif
#ifdef MODULES_TWI_MASTER
.include "modules/twimaster/main.asm"
#endif
@@ -282,6 +323,27 @@
#endif
#ifdef APPS_HUB
.include "apps/hub/main.asm"
.include "modules/network/msg/reboot-d.asm"
.include "modules/network/msg/reboot-r.asm"
.include "modules/network/msg/pong-w.asm"
.include "modules/network/msg/range-d.asm"
.include "modules/network/msg/range-r.asm"
.include "modules/network/msg/range-w.asm"
.include "common/eeprom-r.asm"
.include "common/eeprom-w.asm"
#endif
#ifdef APPS_FORWARDER
.include "apps/forwarder/main.asm"
.include "modules/network/msg/reboot-r.asm"
.include "modules/network/msg/reboot-d.asm"
.include "modules/network/msg/pong-w.asm"
#endif
#ifdef APPS_REPORTSENSORS
.include "apps/reportsensors/data.asm"
.include "apps/reportsensors/main.asm"

View File

@@ -79,7 +79,7 @@ main_runLoop:
tst r16
breq main_endRunLoop
inc r17
cpi r17, 2
cpi r17, 10
brcc main_endRunLoop
brne main_runLoop
main_endRunLoop:
@@ -115,6 +115,16 @@ onSystemTimerTick:
bigcall LedSimple_Every100ms
#endif
#ifdef MODULES_LED_SIGNAL
bigcall LedSignal_Every100ms
#endif
#ifdef MODULES_LED_ACTIVITY
bigcall LedActivity_Every100ms
#endif
#ifdef MODULES_UART_BITBANG
bigcall UART_BitBang_Every100ms
#endif
@@ -127,6 +137,14 @@ onSystemTimerTick:
bigcall TtyOnUart1_Periodically
#endif
#ifdef MODULES_UARTFD0
bigcall UARTFD0_Every100ms
#endif
#ifdef MODULES_UARTFD1
bigcall UARTFD1_Every100ms
#endif
#ifdef MODULES_COMONUART0
bigcall ComOnUart0_Periodically
#endif
@@ -148,6 +166,11 @@ onSystemTimerTick:
bigcall COM2W1_Periodically
#endif
#ifdef MODULES_COM2WN
bigcall COM2WN_Periodically
#endif
#ifdef MODULES_TCRT1000
bigcall TCRT1K_Every100ms
#endif
@@ -227,6 +250,10 @@ sysOnEveryDay:
bigcall AppRouter_EveryDay
#endif
#ifdef APPS_FORWARDER
bigcall AppForwarder_EveryDay
#endif
bigjmp onEveryDay
; @end

View File

@@ -51,7 +51,19 @@ initModules:
#ifdef MODULES_LED_SIMPLE
bigcall LedSimple_Init
#endif
#ifdef MODULES_LED_SIGNAL
bigcall LedSignal_Init
#endif
#ifdef MODULES_LED_ACTIVITY
bigcall LedActivity_Init
#endif
#ifdef MODULES_COM
bigcall Com2_Init ; init COM module
bigcall CPRO_Init ; init COM protocol module
@@ -73,6 +85,14 @@ initModules:
bigcall TtyOnUart1_Init
#endif
#ifdef MODULES_UARTFD0
bigcall UARTFD0_Init
#endif
#ifdef MODULES_UARTFD1
bigcall UARTFD1_Init
#endif
#ifdef MODULES_COMONUART0
bigcall ComOnUart0_Init
#endif
@@ -93,6 +113,11 @@ initModules:
bigcall COM2W1_Init
#endif
#ifdef MODULES_COM2WN
bigcall COM2WN_Init
#endif
#ifdef MODULES_MOTION
bigcall Motion_Init
#endif
@@ -180,11 +205,8 @@ initModules:
;
; Call run functions of the used modules. Add your routine calls here.
;
; IN:
; - nothing
; OUT:
; - nothing
; USED: depending on called routines
; @return CFLAG set: at least one RUN routine returned CFLAG set
; @clobbers all
runModules:
clr r16
@@ -192,6 +214,7 @@ runModules:
push r16
bigcall BaseTimer_Run
pop r16
sbci r16, 0
#ifdef MODULES_TTYONUART1
push r16
@@ -199,10 +222,64 @@ runModules:
pop r16
#endif
#ifdef MODULES_UARTFD0
push r16
rcall runComModules
bigcall UARTFD0_Run
pop r16
sbci r16, 0
#endif
#ifdef MODULES_UARTFD1
push r16
bigcall UARTFD1_Run
pop r16
sbci r16, 0
#endif
#ifdef MODULES_COMONUART0
push r16
bigcall ComOnUart0_Run
pop r16
sbci r16, 0
#endif
#ifdef MODULES_COMONUART1
push r16
bigcall ComOnUart1_Run
pop r16
sbci r16, 0
#endif
#ifdef MODULES_COM2W
push r16
bigcall COM2W_Run
pop r16
sbci r16, 0
#endif
#ifdef MODULES_COM2W0
push r16
bigcall COM2W0_Run
pop r16
sbci r16, 0
#endif
#ifdef MODULES_COM2W1
push r16
bigcall COM2W1_Run
pop r16
sbci r16, 0
#endif
#ifdef MODULES_COM2WN
push r16
bigcall COM2WN_Run
pop r16
sbci r16, 0
#endif
; add more modules here
@@ -213,60 +290,7 @@ runModules:
sec
runModules_end:
ret
; run until every module idle
runComModules:
clr r17
runComModules_loop:
push r17
clr r16
#ifdef MODULES_COMONUART0
push r16
bigcall ComOnUart0_Run
pop r16
sbci r16, 0
#endif
#ifdef MODULES_COMONUART1
push r16
bigcall ComOnUart1_Run
pop r16
sbci r16, 0
#endif
#ifdef MODULES_COM2W0
push r16
bigcall COM2W0_Run
pop r16
sbci r16, 0
#endif
#ifdef MODULES_COM2W1
push r16
bigcall COM2W1_Run
pop r16
sbci r16, 0
#endif
pop r17
; check for repeat request
tst r16
clc
breq runComModules_loopEnd
inc r17
cpi r17, 2
brne runComModules_loop
runComModules_loopEnd:
tst r17
clc
breq runComModules_end
sec
runComModules_end:
ret
; @end
mainModulesOnPacketReceived:

View File

@@ -7,18 +7,6 @@
<values>
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
<value name="stats_packets_in" id="0xe0" type="sensor" dataType="uint16" denom="1" />
<value name="stats_packets_out" id="0xe1" type="sensor" dataType="uint16" denom="1" />
<value name="stats_content_errors" id="0xe2" type="sensor" dataType="uint16" denom="1" />
<value name="stats_io_errors" id="0xe3" type="sensor" dataType="uint16" denom="1" />
<value name="stats_nobuf_errors" id="0xe4" type="sensor" dataType="uint16" denom="1" />
<value name="stats_collision_errors" id="0xe5" type="sensor" dataType="uint16" denom="1" />
<value name="stats_busy_errors" id="0xe6" type="sensor" dataType="uint16" denom="1" />
<value name="stats_heap_used" id="0xe7" type="sensor" dataType="uint16" denom="1" />
<value name="stats_heap_free" id="0xe8" type="sensor" dataType="uint16" denom="1" />
<value name="stats_noram_errors" id="0xe9" type="sensor" dataType="uint16" denom="1" />
</values>
</device>

View File

@@ -7,18 +7,6 @@
<values>
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
<value name="stats_packets_in" id="0xe0" type="sensor" dataType="uint16" denom="1" />
<value name="stats_packets_out" id="0xe1" type="sensor" dataType="uint16" denom="1" />
<value name="stats_content_errors" id="0xe2" type="sensor" dataType="uint16" denom="1" />
<value name="stats_io_errors" id="0xe3" type="sensor" dataType="uint16" denom="1" />
<value name="stats_nobuf_errors" id="0xe4" type="sensor" dataType="uint16" denom="1" />
<value name="stats_collision_errors" id="0xe5" type="sensor" dataType="uint16" denom="1" />
<value name="stats_busy_errors" id="0xe6" type="sensor" dataType="uint16" denom="1" />
<value name="stats_heap_used" id="0xe7" type="sensor" dataType="uint16" denom="1" />
<value name="stats_heap_free" id="0xe8" type="sensor" dataType="uint16" denom="1" />
<value name="stats_noram_errors" id="0xe9" type="sensor" dataType="uint16" denom="1" />
</values>
</device>

View File

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

View File

@@ -1,143 +0,0 @@
; ***************************************************************************
; 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 "./n00_defs.asm"
.include "defs_all.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
.include "common/utils_wait.asm"
.include "modules/com2/defs.asm"
.include "modules/comproto/defs.asm"
; ---------------------------------------------------------------------------
; firmware settings
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
; ---------------------------------------------------------------------------
; LED
.equ LED_DDR = DDRA
.equ LED_PORT = PORTA
.equ LED_PIN = PINA
.equ LED_PINNUM = PORTA3
; ***************************************************************************
; code segment
.cseg
.org 0x0000
; ---------------------------------------------------------------------------
; Reset and interrupt vectors
; rjmp start ; Reset vector
rjmp main ; Reset vector
reti ; EXT_INT0
reti ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
reti ; OC1A
reti ; OC1B
reti ; OVF1
reti ; OC0A
reti ; OC0B
reti ; OVF0
reti ; ACI
reti ; ADCC
reti ; ERDY
reti ; USI_STR
reti ; USI_OVF
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db 'N', 0
devInfoVersion: .db 0, 1 ; 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 "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"
.include "common/utils_copy_sdram.asm"
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashprocess.asm"
.include "modules/flash/wait.asm"
.include "modules/bootloader/main.asm"
.include "modules/network/msg/defs.asm"
.include "modules/network/msg/crc.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
.if clock == 1000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret

View File

@@ -1,135 +0,0 @@
; ***************************************************************************
; 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
; CNY70-K PB1 3 12 PA1 COM-DATA
; /RESET PB3 4 11 PA2
; AUX PB2 5 10 PA3 LED
; COM_ATTN PA7 6 9 PA4 TWI-SCL
; TWI-SDA PA6 7 8 PA5 CNY70-C
; --------
;
; ***************************************************************************
.equ BOOTLOADER_ADDR = 0xd00
.equ FIRMWARE_VARIANT_BOOT = 0
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1
; ---------------------------------------------------------------------------
; LED module
.equ LED_SIMPLE_ONTIME = 2
.equ LED_SIMPLE_OFFTIME = 30
.equ LED_SIMPLE_DDR = DDRA
.equ LED_SIMPLE_PORT = PORTA
.equ LED_SIMPLE_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 = 7 ; 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
; ---------------------------------------------------------------------------
; 1-Wire Master
;
.equ OWI_DDR = DDRB
.equ OWI_PORTOUT = PORTB
.equ OWI_PORTIN = PINB
.equ OWI_PINNUM = PORTB2

View File

@@ -1,363 +0,0 @@
; ***************************************************************************
; 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
.nolist
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "./n00_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
; ---------------------------------------------------------------------------
; 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
; ***************************************************************************
; code segment
.cseg
.org 000000
; ---------------------------------------------------------------------------
; Reset and interrupt vectors (will be removed as soon as we can flash data over COM)
; rjmp main ; Reset vector
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp uartBitbangIsrPcint0 ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
reti ; OC1A
reti ; OC1B
reti ; OVF1
rjmp baseTimerIrqOC0A ; OC0A
reti ; OC0B
reti ; OVF0
reti ; ACI
reti ; ADCC
reti ; ERDY
reti ; USI_STR
reti ; USI_OVF
devInfoBlock: ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId: .db 'N', 0
devInfoVersion: .db 0, 1 ; 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
#endif
#ifdef MODULES_TWI_MASTER
.include "modules/twimaster/main.asm"
#endif
#ifdef MODULES_LCD
.include "modules/lcd/main.asm"
#endif
#ifdef MODULES_SI7021
.include "modules/si7021/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
; ***************************************************************************
; data in SRAM
.dseg
#ifdef MODULES_LCD
sramTimerWriteStats: .byte 2
#endif
sramTimerEnqueueValues: .byte 2
#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
; ***************************************************************************
; data in FLASH
.cseg
ledA3Flash: .db DDRA+0x20, PORTA+0x20, PINA+0x20, (1<<PORTA3)
blinkPattern: .db 2, 50, 0xff, 0xff ; 1 short blink, 5s pause, restart
;blinkPattern2: .db 2, 2, 0xff, 0xff ; 1 short blink, short pause, restart
; ---------------------------------------------------------------------------
; 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, 3000 ; every 5m
#endif
#ifdef MODULES_LCD
; .dw sramPeriodicalLcdMark, periodicalLcdMark, 0, 20 ; every 2s
.dw sramTimerWriteStats, writeStats, 0, 100
#endif
#ifdef MODULES_SI7021
.dw sramTimerSI7021Measure, SI7021_PeriodicMeasurement, 0, 300 ; every 30s
.dw sramTimerSI7021SendTemp, sendTemp, TIMER_FLAGS_IF_ADDR, 600 ; every 60s
.dw sramTimerSI7021SendHumidity, sendHumidity, TIMER_FLAGS_IF_ADDR, 600 ; every 60s
#endif
#ifdef MODULES_CNY70
.dw sramTimerCny70SendAdc, CNY70_OnTimer, TIMER_FLAGS_IF_ADDR, 50 ; every 5s
#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:
ret
#ifdef MODULES_LCD
periodicalLcdMark:
rcall printTimerMark
ret
writeStats:
rcall printSendStats
ret
#endif
#ifdef MODULES_SI7021
sendHumidity:
rcall SI7021_SendHumidity
brcs sendHumidity_okay
; set timer to 1s to retry later
ldi xl, LOW(sramTimerSI7021SendHumidity)
ldi xh, HIGH(sramTimerSI7021SendHumidity)
rjmp Timer_SetValueTo1s
sendHumidity_okay:
ret
sendTemp:
rcall SI7021_SendTemp
brcs sendTemp_okay
; set timer to 1s to retry later
ldi xl, LOW(sramTimerSI7021SendTemp)
ldi xh, HIGH(sramTimerSI7021SendTemp)
rjmp Timer_SetValueTo1s
sendTemp_okay:
ret
#endif
; ---------------------------------------------------------------------------
; Called every 100ms. Add your routine calls here. No arguments, no results.
onEvery100ms:
#ifdef MODULES_LED
; ticker for LED module
ldi zl, LOW(ledA3Flash)
ldi zh, HIGH(ledA3Flash)
ldi yl, LOW(ledA3Sram)
ldi yh, HIGH(ledA3Sram)
rcall Led_Tick
#endif
#ifdef MODULES_LED_SIMPLE
rcall LedSimple_Every100ms
#endif
#ifdef MODULES_REED
rcall REED_Every100ms
#endif
ret
; ---------------------------------------------------------------------------
; 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.
; IN:
; - X : pointer to received buffer
; OUT:
; - CFLAG: set if handled, cleared otherwise
; USED: depending on called routines
onPacketReceived:
rcall CPRO_OnPacketReceived
ret

View File

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

View File

@@ -1,142 +0,0 @@
; ***************************************************************************
; 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 "./n06_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 "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"
.include "common/utils_copy_sdram.asm"
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashprocess.asm"
.include "modules/flash/wait.asm"
.include "modules/bootloader/main.asm"
.include "modules/network/msg/defs.asm"
.include "modules/network/msg/crc.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
.if clock == 1000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret

View File

@@ -1,139 +0,0 @@
; ***************************************************************************
; 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
; CNY70-K PB1 3 12 PA1 COM-DATA
; /RESET PB3 4 11 PA2
; AUX PB2 5 10 PA3 LED
; COM_ATTN PA7 6 9 PA4 TWI-SCL
; TWI-SDA PA6 7 8 PA5 CNY70-C
; --------
;
; ***************************************************************************
.equ BOOTLOADER_ADDR = 0xd00
.equ FIRMWARE_VARIANT_BOOT = 0
.equ FIRMWARE_VARIANT_TEMP_WINDOW = 1
.equ DEVICEINFO_ID = 'N'
.equ DEVICEINFO_VERSION = 6
.equ DEVICEINFO_REVISION = 4
; ---------------------------------------------------------------------------
; 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_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_OUTPUT = PORTA
.equ COM_DATA_INPUT = PINA
.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
; ---------------------------------------------------------------------------
; 1-Wire Master
;
.equ OWI_DDR = DDRB
.equ OWI_PORTOUT = PORTB
.equ OWI_PORTIN = PINB
.equ OWI_PINNUM = PORTB2

View File

@@ -1,363 +0,0 @@
; ***************************************************************************
; 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
.nolist
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "n06_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
; ---------------------------------------------------------------------------
; 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
; ***************************************************************************
; 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
#endif
#ifdef MODULES_TWI_MASTER
.include "modules/twimaster/main.asm"
#endif
#ifdef MODULES_LCD
.include "modules/lcd/main.asm"
#endif
#ifdef MODULES_SI7021
.include "modules/si7021/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
; ***************************************************************************
; data in SRAM
.dseg
#ifdef MODULES_LCD
sramTimerWriteStats: .byte 2
#endif
sramTimerEnqueueValues: .byte 2
#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
; ***************************************************************************
; data in FLASH
.cseg
ledA3Flash: .db DDRA+0x20, PORTA+0x20, PINA+0x20, (1<<PORTA3)
blinkPattern: .db 2, 50, 0xff, 0xff ; 1 short blink, 5s pause, restart
;blinkPattern2: .db 2, 2, 0xff, 0xff ; 1 short blink, short pause, restart
; ---------------------------------------------------------------------------
; 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, 3000 ; every 5m
#endif
#ifdef MODULES_LCD
; .dw sramPeriodicalLcdMark, periodicalLcdMark, 0, 20 ; every 2s
.dw sramTimerWriteStats, writeStats, 0, 100
#endif
#ifdef MODULES_SI7021
.dw sramTimerSI7021Measure, SI7021_OnTimer, 0, 300 ; every 30s
.dw sramTimerSI7021SendTemp, sendTemp, TIMER_FLAGS_IF_ADDR, 600 ; every 60s
.dw sramTimerSI7021SendHumidity, sendHumidity, TIMER_FLAGS_IF_ADDR, 600 ; every 60s
#endif
#ifdef MODULES_CNY70
.dw sramTimerCny70SendAdc, CNY70_OnTimer, TIMER_FLAGS_IF_ADDR, 50 ; every 5s
#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:
ret
#ifdef MODULES_LCD
periodicalLcdMark:
rcall printTimerMark
ret
writeStats:
rcall printSendStats
ret
#endif
#ifdef MODULES_SI7021
sendHumidity:
rcall SI7021_SendHumidity
brcs sendHumidity_okay
; set timer to 1s to retry later
ldi xl, LOW(sramTimerSI7021SendHumidity)
ldi xh, HIGH(sramTimerSI7021SendHumidity)
rjmp Timer_SetValueTo1s
sendHumidity_okay:
ret
sendTemp:
rcall SI7021_SendTemp
brcs sendTemp_okay
; set timer to 1s to retry later
ldi xl, LOW(sramTimerSI7021SendTemp)
ldi xh, HIGH(sramTimerSI7021SendTemp)
rjmp Timer_SetValueTo1s
sendTemp_okay:
ret
#endif
; ---------------------------------------------------------------------------
; Called every 100ms. Add your routine calls here. No arguments, no results.
onEvery100ms:
#ifdef MODULES_LED
; ticker for LED module
ldi zl, LOW(ledA3Flash)
ldi zh, HIGH(ledA3Flash)
ldi yl, LOW(ledA3Sram)
ldi yh, HIGH(ledA3Sram)
rcall Led_Tick
#endif
#ifdef MODULES_LED_SIMPLE
rcall LedSimple_Every100ms
#endif
#ifdef MODULES_REED
rcall REED_Every100ms
#endif
ret
; ---------------------------------------------------------------------------
; 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.
; IN:
; - X : pointer to received buffer
; OUT:
; - CFLAG: set if handled, cleared otherwise
; USED: depending on called routines
onPacketReceived:
rcall CPRO_OnPacketReceived
ret

View File

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

View File

@@ -1,142 +0,0 @@
; ***************************************************************************
; 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 "n11_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 "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"
.include "common/utils_copy_sdram.asm"
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashprocess.asm"
.include "modules/flash/wait.asm"
.include "modules/bootloader/main.asm"
.include "modules/network/msg/defs.asm"
.include "modules/network/msg/crc.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
.if clock == 1000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret

View File

@@ -1,172 +0,0 @@
; ***************************************************************************
; 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
; REED_OUT2 PB0 2 13 PA0 REED_OUT1
; 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 = 11
.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_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 = 10000 ; 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
; ---------------------------------------------------------------------------
; CCS 811
;
.equ CCS811_ADDR = 0x5a ; or 0x5b

View File

@@ -1,522 +0,0 @@
; ***************************************************************************
; 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 "n11_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_CCS811
; ---------------------------------------------------------------------------
; 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_CO2 = 0x07
.equ VALUE_ID_TVOC = 0x08
.equ VALUE_ID_DEBUG = 0x7f
.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_CCS811
.include "modules/ccs811/main.asm"
#endif
; ***************************************************************************
; data in SRAM
.dseg
programRamBegin:
#ifdef MODULES_LCD
screenCounter: .byte 1
#endif
programRamEnd:
#ifdef MODULES_LCD
sramTimerWriteStats: .byte 2
sramTimerScreen: .byte 2
#endif
sramTimerEnqueueValues: .byte 2
#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
#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, 3000 ; every 5m
#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
#ifdef MODULES_CCS811
.dw sramCcs811Timer, CCS811_OnTimer, 0, 10 ; every 1s
#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_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:
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
; ticker for LED module
ldi zl, LOW(ledA3Flash)
ldi zh, HIGH(ledA3Flash)
ldi yl, LOW(ledA3Sram)
ldi yh, HIGH(ledA3Sram)
rcall Led_Tick
#endif
#ifdef MODULES_LED_SIMPLE
rcall LedSimple_Every100ms
#endif
#ifdef MODULES_REED
rcall REED_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
cpi r16, CPRO_CMD_VALUE_SET
brne onPacketReceived_l1
; msg code is CPRO_CMD_VALUE_SET
rjmp onSetValueReceived
onPacketReceived_l1:
rjmp CPRO_OnPacketReceived
; @end
onSetValueReceived:
adiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUEID
ld r16, X
sbiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUEID
cpi r16, VALUE_ID_REED_CONF
brne onSetValueReceived_l1
#ifdef MODULES_REED
rjmp onSetReedConf
#else
ret
#endif
onSetValueReceived_l1:
clc
ret
#ifdef MODULES_REED
onSetReedConf:
; get new value
adiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUE
ld r16, X
sbiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUE
; set config
rcall REED_SetConfig
; send ACK
ldi r16, CPRO_CMD_VALUE_SET_ACK
rcall CPRO_SendSetValueResponse
sec
ret
#endif

View File

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

View File

@@ -1,144 +0,0 @@
; ***************************************************************************
; 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 "n12_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 = PORTA7
; ***************************************************************************
; 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 "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"
.include "common/utils_copy_sdram.asm"
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashprocess.asm"
.include "modules/flash/wait.asm"
.include "modules/bootloader/main.asm"
.include "modules/network/msg/defs.asm"
.include "modules/network/msg/crc.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
.if clock == 1000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret

View File

@@ -1,175 +0,0 @@
; ***************************************************************************
; 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. *
; ***************************************************************************
; ***************************************************************************
;
; AtTiny84
; --------
; VCC 1 14 GND
; [PCINT8] REED_IN1 PB0 2 13 PA0 COM-DATA
; [PCINT9] REED_IN2 PB1 3 12 PA1 COM_ATTN [PCINT1]
; /RESET PB3 4 11 PA2 TWI-SDA
; [KEY1] PB2 5 10 PA3 TWI-SCL
; LED PA7 6 9 PA4 [USCK/SCL]
; [DI/SDA/OC1A] PA6 7 8 PA5 REED_OUT [DO/OC1B]
; --------
;
; ***************************************************************************
.equ BOOTLOADER_ADDR = 0xd00
.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
.equ LED_SIMPLE_ONTIME = 3
.equ LED_SIMPLE_OFFTIME = 30
.equ LED_SIMPLE_DDR = DDRA
.equ LED_SIMPLE_PORT = PORTA
.equ LED_SIMPLE_PINNUM = PORTA7
; ---------------------------------------------------------------------------
; 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_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_IRQ_ADDR_ATTN = PCMSK0
.equ COM_IRQ_BIT_ATTN = 1 ; bit 1 in PCMSK0
.equ COM_IRQ_GIFR_ATTN = PCIF0
.equ COM_IRQ_GIMSK_ATTN = PCIE0
; ---------------------------------------------------------------------------
; TWI master module
.equ TWI_BIT_LENGTH = 1 ; 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 = PORTA3
.equ TWI_DDR_SDA = DDRA
.equ TWI_PORT_SDA = PORTA
.equ TWI_PIN_SDA = PINA
.equ TWI_PINNUM_SDA = PORTA2
; ---------------------------------------------------------------------------
; 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 = DDRB
.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 = PORTA5
.equ REED1_DDR = DDRB
.equ REED1_PORT = PORTB
.equ REED1_PIN = PINB
.equ REED1_PINNUM = PORTB0
.equ REED2_DDR = DDRB
.equ REED2_PORT = PORTB
.equ REED2_PIN = PINB
.equ REED2_PINNUM = PORTB1
; ---------------------------------------------------------------------------
; 1-Wire Master
;
.equ OWI_DDR = DDRB
.equ OWI_PORTOUT = PORTB
.equ OWI_PORTIN = PINB
.equ OWI_PINNUM = PORTB2
; ---------------------------------------------------------------------------
; SK6812
.equ SK6812_DDR = DDRA
.equ SK6812_PORT = PORTA
.equ SK6812_PINNUM = PORTA5
; ---------------------------------------------------------------------------
; debug
.equ DEBUG_LED_DDR = DDRA
.equ DEBUG_LED_PORT_OUT = PORTA
.equ DEBUG_LED_PORT_IN = PINA
.equ DEBUG_LED_PINNUM = PORTA5

View File

@@ -1,480 +0,0 @@
; ***************************************************************************
; 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. *
; ***************************************************************************
; ***************************************************************************
; Source file for temperature sensor node on AtTiny 84
;
; This is for the full system (i.e. not the boot loader).
; ***************************************************************************
.equ clock=8000000 ; Define the clock frequency
.nolist
.include "include/tn84def.inc" ; Define device ATtiny84
.list
.include "n12_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
#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_SK6812
; ---------------------------------------------------------------------------
; 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_REED_CONF = 0x81
.equ VALUE_ID_LED_NUMLEDS = 0x82
.equ VALUE_ID_LED_RGBW_VALUE = 0x83
; ***************************************************************************
; code segment
.cseg
.org 000000
; ---------------------------------------------------------------------------
; Reset and interrupt vectors
; 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
#endif
#ifdef MODULES_TWI_MASTER
.include "modules/twimaster/main.asm"
#endif
#ifdef MODULES_LCD
.include "modules/lcd/main.asm"
#endif
#ifdef MODULES_SI7021
.include "modules/si7021/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_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
; ***************************************************************************
; data in SRAM
.dseg
#ifdef MODULES_LCD
sramTimerWriteStats: .byte 2
#endif
sramTimerEnqueueValues: .byte 2
#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
#ifdef MODULES_LED
ledA3Flash: .db DDRA+0x20, PORTA+0x20, PINA+0x20, (1<<PORTA3)
blinkPattern: .db 2, 50, 0xff, 0xff ; 1 short blink, 5s pause, restart
;blinkPattern2: .db 2, 2, 0xff, 0xff ; 1 short blink, short pause, restart
#endif
; ---------------------------------------------------------------------------
; 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, 3000 ; every 5m
#endif
#ifdef MODULES_LCD
.dw sramPeriodicalLcdMark, periodicalLcdMark, 0, 10 ; every sec
.dw sramTimerWriteStats, writeStats, 0, 100
#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 == 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
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_LCD
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
; ticker for LED module
ldi zl, LOW(ledA3Flash)
ldi zh, HIGH(ledA3Flash)
ldi yl, LOW(ledA3Sram)
ldi yh, HIGH(ledA3Sram)
rcall Led_Tick
#endif
#ifdef MODULES_LED_SIMPLE
rcall LedSimple_Every100ms
#endif
#ifdef MODULES_REED
rcall REED_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
cpi r16, CPRO_CMD_VALUE_SET
brne onPacketReceived_l1
; msg code is CPRO_CMD_VALUE_SET
rjmp onSetValueReceived
onPacketReceived_l1:
rjmp CPRO_OnPacketReceived
; @end
onSetValueReceived:
adiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUEID
ld r16, X
sbiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUEID
cpi r16, VALUE_ID_REED_CONF
brne onSetValueReceived_l1
#ifdef MODULES_REED
rjmp onSetReedConf
#else
ret
#endif
onSetValueReceived_l1:
cpi r16, VALUE_ID_LED_RGBW_VALUE
brne onSetValueReceived_l2
#ifdef MODULES_SK6812
rjmp onSetRgbwValue
#endif
onSetValueReceived_l2:
cpi r16, VALUE_ID_LED_NUMLEDS
brne onSetValueReceived_l3
#ifdef MODULES_SK6812
rjmp onSetNumLeds
#endif
onSetValueReceived_l3:
ldi r16, CPRO_CMD_VALUE_SET_NACK
rcall CPRO_SendSetValueResponse
clc
ret
#ifdef MODULES_REED
onSetReedConf:
; get new value
adiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUE
ld r16, X
sbiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUE
; set config
rcall REED_SetConfig
; send ACK
ldi r16, CPRO_CMD_VALUE_SET_ACK
rcall CPRO_SendSetValueResponse
sec
ret
#endif
#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

View File

@@ -15,14 +15,6 @@
<value name="MALSOURCE1" id="0x86" type="actor" dataType="uint16" />
<value name="MALSOURCE2" id="0x87" type="actor" dataType="uint16" />
<value name="stats_packets_in" id="0xe0" type="sensor" dataType="uint16" denom="1" />
<value name="stats_packets_out" id="0xe1" type="sensor" dataType="uint16" denom="1" />
<value name="stats_content_errors" id="0xe2" type="sensor" dataType="uint16" denom="1" />
<value name="stats_io_errors" id="0xe3" type="sensor" dataType="uint16" denom="1" />
<value name="stats_nobuf_errors" id="0xe4" type="sensor" dataType="uint16" denom="1" />
<value name="stats_collision_errors" id="0xe5" type="sensor" dataType="uint16" denom="1" />
<value name="stats_busy_errors" id="0xe6" type="sensor" dataType="uint16" denom="1" />
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
</values>

View File

@@ -19,6 +19,7 @@
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_io.asm"
.include "common/utils_wait.asm"
.include "modules/com2/defs.asm"
.include "modules/comproto/defs.asm"
@@ -98,8 +99,7 @@ main:
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/io_com2w.asm"
.include "modules/flash/flashxp.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashprocess.asm"

View File

@@ -55,15 +55,15 @@
.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_CLK_DDR = DDRB
.equ COM_CLK_INPUT = PINB
.equ COM_CLK_OUTPUT = PORTB
.equ COM_CLK_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
.equ COM_IRQ_ADDR_CLK = PCMSK
.equ COM_IRQ_BIT_CLK = PCINT2 ; bit 2 in PCMSK0 (PCINT2)
.equ COM_IRQ_GIFR_CLK = PCIF
.equ COM_IRQ_GIMSK_CLK = PCIE

View File

@@ -40,7 +40,9 @@
; ---------------------------------------------------------------------------
; generic
.equ NET_BUFFERS_NUM = 6
.equ NET_BUFFERS_NUM = 6
.equ NET_MSGNUMINBUF_SIZE = 8 ; max buffer nums in ringbuffer (global incoming)
.equ NET_IFACE_OUTMSGBUF_SIZE = 8 ; max buffer nums in ringbuffer (per interface outbound)
@@ -50,7 +52,7 @@
#define MODULES_CLOCK
#define MODULES_LED_SIMPLE
#define MODULES_NETWORK
#define MODULES_UART_BITBANG
#define MODULES_COM2W
#define MODULES_OWI_MASTER
#define MODULES_DS18B20
#define MODULES_SK6812
@@ -98,7 +100,7 @@
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp UART_BitBang_PcintIsr ; PCI0
rjmp com2wPcintIsr ; PCI0
reti ; OC1A
reti ; OVF1
reti ; OVF0
@@ -199,7 +201,7 @@ onEveryLoop:
; ---------------------------------------------------------------------------
; defines for network interface
.equ netInterfaceData = uart_bitbang_iface
.equ netInterfaceData = com2w_iface

View File

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

View File

@@ -1,52 +0,0 @@
<?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

@@ -1,178 +0,0 @@
; ***************************************************************************
; 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 "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"
.include "common/utils_copy_sdram.asm"
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashprocess.asm"
.include "modules/flash/wait.asm"
.include "modules/bootloader/main.asm"
.include "modules/network/msg/defs.asm"
.include "modules/network/msg/crc.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
.if clock == 1000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret
#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

@@ -1,176 +0,0 @@
; ***************************************************************************
; 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

@@ -1,462 +0,0 @@
; ***************************************************************************
; 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

View File

@@ -7,6 +7,10 @@
main
</subdirs>
<data dist="true" install="$(datadir)/aqhome/devices/nodes">
aqua_n16.xml
</data>
<extradist>
defs.asm
README

View File

@@ -0,0 +1,17 @@
<device name="aqua_n16" driver="nodes">
<manufacturer>AQUA</manufacturer>
<devicetype>N</devicetype>
<deviceversion>16</deviceversion>
<values>
<value name="SI7021_TEMP" id="0x01" type="sensor" dataType="rational" modality="temperature" units="C" denom="100" />
<value name="SI7021_HUM" id="0x02" type="sensor" dataType="rational" modality="humidity" units="%" denom="1" />
<value name="MOTION" id="0x07" type="sensor" dataType="rational" modality="motion" denom="1" />
<value name="DOOR" id="0x08" type="sensor" dataType="rational" modality="door" denom="1" />
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
</values>
</device>

View File

@@ -17,6 +17,7 @@
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_io.asm"
.include "common/utils_wait.asm"
;.include "modules/com2/defs.asm"
;.include "modules/comproto/defs.asm"
@@ -99,8 +100,7 @@ main:
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/io_com2w.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashxp.asm"
.include "modules/flash/flashprocess.asm"

View File

@@ -17,7 +17,7 @@
; 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
; COM_CLK PA7 6 9 PA4 TWI-SCL
; TWI-SDA PA6 7 8 PA5
; --------
;
@@ -59,15 +59,15 @@
.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_CLK_DDR = DDRA
.equ COM_CLK_INPUT = PINA
.equ COM_CLK_OUTPUT = PORTA
.equ COM_CLK_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
.equ COM_IRQ_ADDR_CLK = PCMSK0
.equ COM_IRQ_BIT_CLK = PCINT7 ; bit 7 in PCMSK0
.equ COM_IRQ_GIFR_CLK = PCIF0
.equ COM_IRQ_GIMSK_CLK = PCIE0

View File

@@ -47,7 +47,9 @@
; ---------------------------------------------------------------------------
; generic
.equ NET_BUFFERS_NUM = 6
.equ NET_BUFFERS_NUM = 6
.equ NET_MSGNUMINBUF_SIZE = 8 ; max buffer nums in ringbuffer (global incoming)
.equ NET_IFACE_OUTMSGBUF_SIZE = 8 ; max buffer nums in ringbuffer (per interface outbound)
@@ -57,7 +59,7 @@
#define MODULES_CLOCK
#define MODULES_LED_SIMPLE
#define MODULES_NETWORK
#define MODULES_UART_BITBANG
#define MODULES_COM2W
#define MODULES_TWI_MASTER
;#define MODULES_LCD
;#define LCD_MINIMAL_FONT
@@ -107,7 +109,7 @@
; rjmp main ; Reset vector
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp UART_BitBang_PcintIsr ; PCI0
rjmp com2wPcintIsr ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
@@ -202,7 +204,7 @@ onEveryLoop:
; ---------------------------------------------------------------------------
; defines for network interface
.equ netInterfaceData = uart_bitbang_iface
.equ netInterfaceData = com2w_iface

View File

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

View File

@@ -1,52 +0,0 @@
<?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

@@ -1,178 +0,0 @@
; ***************************************************************************
; 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 "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"
.include "common/utils_copy_sdram.asm"
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashprocess.asm"
.include "modules/flash/wait.asm"
.include "modules/bootloader/main.asm"
.include "modules/network/msg/defs.asm"
.include "modules/network/msg/crc.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
.if clock == 1000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret
#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

@@ -1,127 +0,0 @@
; ***************************************************************************
; 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

@@ -1,459 +0,0 @@
; ***************************************************************************
; 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

View File

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

View File

@@ -1,52 +0,0 @@
<?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

@@ -1,140 +0,0 @@
; ***************************************************************************
; 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 "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"
.include "common/utils_copy_sdram.asm"
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashprocess.asm"
.include "modules/flash/wait.asm"
.include "modules/bootloader/main.asm"
.include "modules/network/msg/defs.asm"
.include "modules/network/msg/crc.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
.if clock == 1000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret

View File

@@ -1,103 +0,0 @@
; ***************************************************************************
; 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

View File

@@ -1,379 +0,0 @@
; ***************************************************************************
; 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

View File

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

View File

@@ -1,138 +0,0 @@
; ***************************************************************************
; 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 "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
; ---------------------------------------------------------------------------
; 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 "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"
.include "common/utils_copy_sdram.asm"
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashprocess.asm"
.include "modules/flash/wait.asm"
.include "modules/bootloader/main.asm"
.include "modules/network/msg/defs.asm"
.include "modules/network/msg/crc.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
.if clock == 1000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret

View File

@@ -1,104 +0,0 @@
; ***************************************************************************
; 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_PORTIN = PINB
.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

View File

@@ -1,176 +0,0 @@
; ***************************************************************************
; copyright : (C) 2025 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 "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_io.asm"
.include "common/utils_wait.asm" ; wait macro
; ***************************************************************************
; defines
.equ NET_BUFFERS_NUM = 6
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
.equ FIRMWARE_VERSION_MAJOR = 0
.equ FIRMWARE_VERSION_MINOR = 0
.equ FIRMWARE_VERSION_PATCHLEVEL = 1
#define MODULES_CLOCK
#define MODULES_LED_SIMPLE
#define MODULES_NETWORK
#define MODULES_UART_BITBANG
#define MODULES_TWI_MASTER
#define MODULES_SI7021
#define MODULES_CCS811
#define APPS_NETWORK
#define APPS_REPORTSENSORS
#define APPS_STATS
; ---------------------------------------------------------------------------
; 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
.equ VALUE_ID_LEDSIMPLE_TIMING = 0x88
; ***************************************************************************
; code segment
.cseg
.org 000000
; ---------------------------------------------------------------------------
; Reset and interrupt vectors
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp UART_BitBang_PcintIsr ; 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
; ---------------------------------------------------------------------------
; @routine onSystemStart
onSystemStart:
ret
; @end
; ---------------------------------------------------------------------------
; @routine onMessageReceived
;
; Called on every message received
onMessageReceived:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine onEvery100ms
;
; Called every 100ms. Add your routine calls here. No arguments, no results.
onEvery100ms:
onEverySecond:
onEveryMinute:
onEveryHour:
onEveryDay:
ret
; @end
; ---------------------------------------------------------------------------
; @routine onEveryLoop
;
; Called on every loop (i.e. after awakening from sleep).
;
onEveryLoop:
ret
; @end
; ***************************************************************************
; includes
.include "devices/all/hw_tn85.asm"
.include "devices/all/includes.asm"
; ---------------------------------------------------------------------------
; defines for network interface
.equ netInterfaceData = uart_bitbang_iface

View File

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

View File

@@ -1,13 +0,0 @@
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

View File

@@ -11,14 +11,6 @@
<value name="MOTION" id="0x07" type="sensor" dataType="rational" modality="motion" denom="1" />
<value name="DOOR" id="0x08" type="sensor" dataType="rational" modality="door" denom="1" />
<value name="stats_packets_in" id="0xe0" type="sensor" dataType="uint16" denom="1" />
<value name="stats_packets_out" id="0xe1" type="sensor" dataType="uint16" denom="1" />
<value name="stats_content_errors" id="0xe2" type="sensor" dataType="uint16" denom="1" />
<value name="stats_io_errors" id="0xe3" type="sensor" dataType="uint16" denom="1" />
<value name="stats_nobuf_errors" id="0xe4" type="sensor" dataType="uint16" denom="1" />
<value name="stats_collision_errors" id="0xe5" type="sensor" dataType="uint16" denom="1" />
<value name="stats_busy_errors" id="0xe6" type="sensor" dataType="uint16" denom="1" />
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
</values>

View File

@@ -17,6 +17,7 @@
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_io.asm"
.include "common/utils_wait.asm"
@@ -98,8 +99,7 @@ main:
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/io_com2w.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashxp.asm"
.include "modules/flash/flashprocess.asm"

View File

@@ -17,7 +17,7 @@
; 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
; COM_CLK PA7 6 9 PA4 TWI-SCL
; TWI-SDA PA6 7 8 PA5
; --------
;
@@ -48,6 +48,16 @@
; ---------------------------------------------------------------------------
; LED activity module
.equ LED_ACTIVITY_DDR = DDRA
.equ LED_ACTIVITY_PORT = PORTA
.equ LED_ACTIVITY_PORTIN = PINA
.equ LED_ACTIVITY_PINNUM = PORTA3
; ---------------------------------------------------------------------------
; COM module
@@ -59,15 +69,15 @@
.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_CLK_DDR = DDRA
.equ COM_CLK_INPUT = PINA
.equ COM_CLK_OUTPUT = PORTA
.equ COM_CLK_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
.equ COM_IRQ_ADDR_CLK = PCMSK0
.equ COM_IRQ_BIT_CLK = PCINT7 ; bit 7 in PCMSK0
.equ COM_IRQ_GIFR_CLK = PCIF0
.equ COM_IRQ_GIMSK_CLK = PCIE0

View File

@@ -47,7 +47,9 @@
; ---------------------------------------------------------------------------
; generic
.equ NET_BUFFERS_NUM = 6
.equ NET_BUFFERS_NUM = 10
.equ NET_MSGNUMINBUF_SIZE = 8 ; max buffer nums in ringbuffer (global incoming)
.equ NET_IFACE_OUTMSGBUF_SIZE = 8 ; max buffer nums in ringbuffer (per interface outbound)
@@ -57,9 +59,10 @@
; #define MODULES_TIMER
#define MODULES_CLOCK
#define MODULES_LED_SIMPLE
;#define MODULES_LED_SIMPLE
#define MODULES_LED_ACTIVITY
#define MODULES_NETWORK
#define MODULES_UART_BITBANG
#define MODULES_COM2W
#define MODULES_TWI_MASTER
;#define MODULES_LCD
;#define LCD_MINIMAL_FONT
@@ -112,7 +115,7 @@
; rjmp main ; Reset vector
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp UART_BitBang_PcintIsr ; PCI0
rjmp com2wPcintIsr ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
@@ -181,10 +184,11 @@ onEveryDay:
onEveryMinute:
lds r16, tcrt1kLastValue
ldi r17, VALUE_ID_ADC
ldi r22, AQHOME_VALUETYPE_UNKNOWN ; VALUE TYPE
rjmp Main_Send8BitValueReport
; lds r16, tcrt1kLastValue
; ldi r17, VALUE_ID_ADC
; ldi r22, AQHOME_VALUETYPE_UNKNOWN ; VALUE TYPE
; rcall Main_Send8BitValueReport
ret
@@ -212,6 +216,6 @@ onEveryLoop:
; ---------------------------------------------------------------------------
; defines for network interface
.equ netInterfaceData = uart_bitbang_iface
.equ netInterfaceData = com2w_iface

View File

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

View File

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

View File

@@ -1,129 +0,0 @@
; ***************************************************************************
; 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 "version.asm"
.include "../defs.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_wait.asm"
.include "modules/com2/defs.asm"
.include "modules/comproto/defs.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; 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/bootloader/main.asm
; ***************************************************************************
; includes
.include "common/utils_wait_fixed.asm"
.include "common/utils_copy_from_flash.asm"
.include "common/utils_copy_sdram.asm"
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/flashxp.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashprocess.asm"
.include "modules/flash/wait.asm"
.include "modules/bootloader/main.asm"
.include "modules/network/msg/defs.asm"
.include "modules/network/msg/crc.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
.if clock == 1000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret

View File

@@ -1,88 +0,0 @@
; ***************************************************************************
; 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_PORTIN = PINB
.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

View File

@@ -1,206 +0,0 @@
; ***************************************************************************
; 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 "version.asm"
.include "../defs.asm"
;.include "./data.asm"
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_io.asm"
.include "common/utils_wait.asm"
; ***************************************************************************
; defines
; ---------------------------------------------------------------------------
; generic
.equ NET_BUFFERS_NUM = 6
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
#define MODULES_CLOCK
#define MODULES_LED_SIMPLE
#define MODULES_NETWORK
#define MODULES_UART_BITBANG
#define MODULES_OWI_MASTER
#define MODULES_DS18B20
#define MODULES_SK6812
;#define MODULES_MOTION_LIGHT
#define APPS_NETWORK
#define APPS_REPORTSENSORS
#define APPS_STATS
#define APPS_MA_LIGHT
; ---------------------------------------------------------------------------
; 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
.equ VALUE_ID_LEDSIMPLE_TIMING = 0x88
; ***************************************************************************
; code segment
.cseg
.org 000000
; ---------------------------------------------------------------------------
; Reset and interrupt vectors
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp UART_BitBang_PcintIsr ; 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
; ---------------------------------------------------------------------------
; @routine firmwareStart @global
firmwareStart:
rjmp main
; @end
; ---------------------------------------------------------------------------
; @routine onSystemStart
onSystemStart:
ret
; @end
; ---------------------------------------------------------------------------
; @routine onMessageReceived
;
; Called on every message received
onMessageReceived:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine onEvery100ms
;
; Called every 100ms. Add your routine calls here. No arguments, no results.
onEvery100ms:
onEveryMinute:
onEveryHour:
onEveryDay:
ret
; @end
onEverySecond:
ret
; debug
ldi r19, 0x00 ; G
ldi r18, 0xff ; R
ldi r20, 0x55 ; B
ldi r21, 0xaa ; W
rcall SK6812_SetAllColor ; r23 (r16, r17)
ret
; ---------------------------------------------------------------------------
; @routine onEveryLoop
;
; Called on every loop (i.e. after awakening from sleep).
;
onEveryLoop:
ret
; @end
; ***************************************************************************
; includes
.include "devices/all/hw_tn85.asm"
.include "devices/all/includes.asm"
.include "common/debug.asm"
; ---------------------------------------------------------------------------
; defines for network interface
.equ netInterfaceData = uart_bitbang_iface

View File

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

View File

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

View File

@@ -1,28 +0,0 @@
<device name="aqua_n23" driver="nodes">
<manufacturer>AQUA</manufacturer>
<devicetype>N</devicetype>
<deviceversion>23</deviceversion>
<values>
<value name="SI7021_TEMP" id="0x01" type="sensor" dataType="rational" modality="temperature" units="C" denom="100" />
<value name="SI7021_HUM" id="0x02" type="sensor" dataType="rational" modality="humidity" units="%" denom="1" />
<value name="MOTION" id="0x07" type="sensor" dataType="rational" modality="motion" denom="1" />
<value name="SGP40_VALUE" id="0x08" type="sensor" dataType="rational" modality="tvoc" denom="1" />
<value name="SGP30_TVOC" id="0x09" type="sensor" dataType="rational" modality="tvoc" denom="1" />
<value name="SGP30_CO2" id="0x0a" type="sensor" dataType="rational" modality="co2" denom="1" />
<value name="stats_packets_in" id="0xe0" type="sensor" dataType="uint16" denom="1" />
<value name="stats_packets_out" id="0xe1" type="sensor" dataType="uint16" denom="1" />
<value name="stats_content_errors" id="0xe2" type="sensor" dataType="uint16" denom="1" />
<value name="stats_io_errors" id="0xe3" type="sensor" dataType="uint16" denom="1" />
<value name="stats_nobuf_errors" id="0xe4" type="sensor" dataType="uint16" denom="1" />
<value name="stats_collision_errors" id="0xe5" type="sensor" dataType="uint16" denom="1" />
<value name="stats_busy_errors" id="0xe6" type="sensor" dataType="uint16" denom="1" />
<value name="stats_msgsize_errors" id="0xe7" type="sensor" dataType="uint16" denom="1" />
<value name="stats_missed_errors" id="0xe8" type="sensor" dataType="uint16" denom="1" />
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
</values>
</device>

View File

@@ -13,16 +13,6 @@
<value name="SGP30_CO2" id="0x0a" type="sensor" dataType="rational" modality="co2" denom="1" />
<value name="LIGHT" id="0x0b" type="sensor" dataType="rational" modality="light" denom="1" />
<value name="stats_packets_in" id="0xe0" type="sensor" dataType="uint16" denom="1" />
<value name="stats_packets_out" id="0xe1" type="sensor" dataType="uint16" denom="1" />
<value name="stats_content_errors" id="0xe2" type="sensor" dataType="uint16" denom="1" />
<value name="stats_io_errors" id="0xe3" type="sensor" dataType="uint16" denom="1" />
<value name="stats_nobuf_errors" id="0xe4" type="sensor" dataType="uint16" denom="1" />
<value name="stats_collision_errors" id="0xe5" type="sensor" dataType="uint16" denom="1" />
<value name="stats_busy_errors" id="0xe6" type="sensor" dataType="uint16" denom="1" />
<value name="stats_msgsize_errors" id="0xe7" type="sensor" dataType="uint16" denom="1" />
<value name="stats_missed_errors" id="0xe8" type="sensor" dataType="uint16" denom="1" />
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
</values>

View File

@@ -26,6 +26,7 @@
.include "../defs.asm"
.include "common/calls.asm"
.include "common/utils_io.asm"
.include "devices/all/defs.asm"
@@ -122,8 +123,7 @@ main:
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/io_com2w.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashxp.asm"
.include "modules/flash/flashprocess.asm"

View File

@@ -17,7 +17,7 @@
; PIR PB1 3 12 PA1 COM-DATA
; /RESET PB3 4 11 PA2 AUX-PA2
; PB2 5 10 PA3 LED
; COM_ATTN PA7 6 9 PA4 TWI-SCL
; COM_CLK PA7 6 9 PA4 TWI-SCL
; TWI-SDA PA6 7 8 PA5
; --------
;
@@ -59,15 +59,15 @@
.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_CLK_DDR = DDRA
.equ COM_CLK_INPUT = PINA
.equ COM_CLK_OUTPUT = PORTA
.equ COM_CLK_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
.equ COM_IRQ_ADDR_CLK = PCMSK0
.equ COM_IRQ_BIT_CLK = PCINT7 ; bit 7 in PCMSK0
.equ COM_IRQ_GIFR_CLK = PCIF0
.equ COM_IRQ_GIMSK_CLK = PCIE0

View File

@@ -47,7 +47,9 @@
; ---------------------------------------------------------------------------
; generic
.equ NET_BUFFERS_NUM = 6
.equ NET_BUFFERS_NUM = 6
.equ NET_MSGNUMINBUF_SIZE = 8 ; max buffer nums in ringbuffer (global incoming)
.equ NET_IFACE_OUTMSGBUF_SIZE = 8 ; max buffer nums in ringbuffer (per interface outbound)
.equ PROGRAM_SENSOR_INTERVAL_SECS = 60
.equ PROGRAM_STATS_INTERVAL_MINS = 10
@@ -61,7 +63,7 @@
#define MODULES_CLOCK
#define MODULES_LED_SIMPLE
#define MODULES_NETWORK
#define MODULES_UART_BITBANG
#define MODULES_COM2W
#define MODULES_TWI_MASTER
;#define MODULES_LCD
;#define LCD_MINIMAL_FONT
@@ -123,7 +125,7 @@
; rjmp main ; Reset vector
rjmp BOOTLOADER_ADDR ; Reset vector ; use this for flashed system
reti ; EXT_INT0
rjmp UART_BitBang_PcintIsr ; PCI0
rjmp com2wPcintIsr ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
@@ -218,7 +220,7 @@ onEveryLoop:
; ---------------------------------------------------------------------------
; defines for network interface
.equ netInterfaceData = uart_bitbang_iface
.equ netInterfaceData = com2w_iface

View File

@@ -15,16 +15,6 @@
<value name="MALSOURCE1" id="0x86" type="actor" dataType="uint16" />
<value name="MALSOURCE2" id="0x87" type="actor" dataType="uint16" />
<value name="stats_packets_in" id="0xe0" type="sensor" dataType="uint16" denom="1" />
<value name="stats_packets_out" id="0xe1" type="sensor" dataType="uint16" denom="1" />
<value name="stats_content_errors" id="0xe2" type="sensor" dataType="uint16" denom="1" />
<value name="stats_io_errors" id="0xe3" type="sensor" dataType="uint16" denom="1" />
<value name="stats_nobuf_errors" id="0xe4" type="sensor" dataType="uint16" denom="1" />
<value name="stats_collision_errors" id="0xe5" type="sensor" dataType="uint16" denom="1" />
<value name="stats_busy_errors" id="0xe6" type="sensor" dataType="uint16" denom="1" />
<value name="stats_msgsize_errors" id="0xe7" type="sensor" dataType="uint16" denom="1" />
<value name="stats_missed_errors" id="0xe8" type="sensor" dataType="uint16" denom="1" />
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
</values>

View File

@@ -19,6 +19,7 @@
.include "devices/all/defs.asm"
.include "common/calls.asm"
.include "common/utils_io.asm"
.include "common/utils_wait.asm"
@@ -99,8 +100,7 @@ main:
.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
.include "modules/flash/io_attn.asm"
.include "modules/flash/io_bitbang.asm"
.include "modules/flash/io_com2w.asm"
.include "modules/flash/flashxp.asm"
.include "modules/flash/flash1p.asm"
.include "modules/flash/flashprocess.asm"

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