summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/config.h22
-rw-r--r--include/data.pb.h154
-rw-r--r--include/dataflow.h47
-rw-r--r--include/devices.h43
-rw-r--r--include/handshake.pb.h133
-rw-r--r--include/main.h73
-rw-r--r--include/stream.h10
-rw-r--r--include/stream_i2c.h5
-rw-r--r--include/stream_stdio.h5
9 files changed, 492 insertions, 0 deletions
diff --git a/include/config.h b/include/config.h
new file mode 100644
index 0000000..e4a6590
--- /dev/null
+++ b/include/config.h
@@ -0,0 +1,22 @@
+
+/* Enable debug mode */
+/* #define DEBUG_ENABLE 1 */
+
+/* Enable testing mode */
+/* #define TESTING_ENABLE 1 */
+
+/* Buffer size for routing */
+#define ROUTING_BUFSIZE 128
+
+/**
+ * \def MASTER_I2C_BUS_INTERVAL
+ * \brief General interval value used by master in milliseconds
+ *
+ * Master uses this value to introduce delays on the I2C bus in order to reduce I2C timeout values.
+ * The optimum interval is usually dependent on I2C bus configuration on the hardware. Testing and debug UART
+ * operations will also affect this value.
+ * If unforeseen I2C timeout issues are encountered on master side, this value should be increased to suit the
+ * hardware.
+ *
+*/
+#define MASTER_I2C_BUS_INTERVAL 5
diff --git a/include/data.pb.h b/include/data.pb.h
new file mode 100644
index 0000000..ce1395d
--- /dev/null
+++ b/include/data.pb.h
@@ -0,0 +1,154 @@
+/* Automatically generated nanopb header */
+/* Generated by nanopb-0.4.2-dev */
+
+#ifndef PB_PROTO_DATA_PB_H_INCLUDED
+#define PB_PROTO_DATA_PB_H_INCLUDED
+#include <pb.h>
+
+#if PB_PROTO_HEADER_VERSION != 40
+#error Regenerate this file with the current version of nanopb generator.
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Struct definitions */
+typedef struct _s2m_data {
+ pb_callback_t datapoints;
+} s2m_data;
+
+typedef struct __datapoint {
+ uint32_t entity_id;
+ double data;
+ bool has_channel_id;
+ uint32_t channel_id;
+ bool has_unit_id;
+ uint32_t unit_id;
+ bool has_timestamp;
+ int32_t timestamp;
+} _datapoint;
+
+typedef struct _command {
+ uint32_t source_module_id;
+ uint32_t dest_module_id;
+ pb_callback_t cmd_bytes;
+ pb_callback_t cmd_str;
+} command;
+
+typedef struct _m2s_CTS {
+ uint32_t timeout;
+} m2s_CTS;
+
+typedef struct _m2s_SOR {
+ uint32_t SOR_code;
+ bool has_rx_length;
+ uint32_t rx_length;
+} m2s_SOR;
+
+typedef struct _s2m_DOC {
+ uint32_t DOC_code;
+ uint32_t tx_length;
+} s2m_DOC;
+
+
+/* Initializer values for message structs */
+#define m2s_SOR_init_default {1u, false, 0}
+#define s2m_DOC_init_default {1u, 0u}
+#define m2s_CTS_init_default {0}
+#define command_init_default {0, 0, {{NULL}, NULL}, {{NULL}, NULL}}
+#define _datapoint_init_default {0u, 0, false, 1u, false, 1u, false, 1}
+#define s2m_data_init_default {{{NULL}, NULL}}
+#define m2s_SOR_init_zero {0, false, 0}
+#define s2m_DOC_init_zero {0, 0}
+#define m2s_CTS_init_zero {0}
+#define command_init_zero {0, 0, {{NULL}, NULL}, {{NULL}, NULL}}
+#define _datapoint_init_zero {0, 0, false, 0, false, 0, false, 0}
+#define s2m_data_init_zero {{{NULL}, NULL}}
+
+/* Field tags (for use in manual encoding/decoding) */
+#define s2m_data_datapoints_tag 1
+#define _datapoint_entity_id_tag 1
+#define _datapoint_data_tag 2
+#define _datapoint_channel_id_tag 3
+#define _datapoint_unit_id_tag 4
+#define _datapoint_timestamp_tag 5
+#define command_source_module_id_tag 1
+#define command_dest_module_id_tag 2
+#define command_cmd_bytes_tag 3
+#define command_cmd_str_tag 4
+#define m2s_CTS_timeout_tag 1
+#define m2s_SOR_SOR_code_tag 1
+#define m2s_SOR_rx_length_tag 2
+#define s2m_DOC_DOC_code_tag 1
+#define s2m_DOC_tx_length_tag 2
+
+/* Struct field encoding specification for nanopb */
+#define m2s_SOR_FIELDLIST(X, a) \
+X(a, STATIC, REQUIRED, UINT32, SOR_code, 1) \
+X(a, STATIC, OPTIONAL, UINT32, rx_length, 2)
+#define m2s_SOR_CALLBACK NULL
+#define m2s_SOR_DEFAULT (const pb_byte_t*)"\x08\x01\x00"
+
+#define s2m_DOC_FIELDLIST(X, a) \
+X(a, STATIC, REQUIRED, UINT32, DOC_code, 1) \
+X(a, STATIC, REQUIRED, UINT32, tx_length, 2)
+#define s2m_DOC_CALLBACK NULL
+#define s2m_DOC_DEFAULT (const pb_byte_t*)"\x08\x01\x10\x00\x00"
+
+#define m2s_CTS_FIELDLIST(X, a) \
+X(a, STATIC, REQUIRED, UINT32, timeout, 1)
+#define m2s_CTS_CALLBACK NULL
+#define m2s_CTS_DEFAULT NULL
+
+#define command_FIELDLIST(X, a) \
+X(a, STATIC, REQUIRED, UINT32, source_module_id, 1) \
+X(a, STATIC, REQUIRED, UINT32, dest_module_id, 2) \
+X(a, CALLBACK, OPTIONAL, BYTES, cmd_bytes, 3) \
+X(a, CALLBACK, OPTIONAL, STRING, cmd_str, 4)
+#define command_CALLBACK pb_default_field_callback
+#define command_DEFAULT NULL
+
+#define _datapoint_FIELDLIST(X, a) \
+X(a, STATIC, REQUIRED, UINT32, entity_id, 1) \
+X(a, STATIC, REQUIRED, DOUBLE, data, 2) \
+X(a, STATIC, OPTIONAL, UINT32, channel_id, 3) \
+X(a, STATIC, OPTIONAL, UINT32, unit_id, 4) \
+X(a, STATIC, OPTIONAL, INT32, timestamp, 5)
+#define _datapoint_CALLBACK NULL
+#define _datapoint_DEFAULT (const pb_byte_t*)"\x08\x00\x11\x00\x00\x00\x00\x00\x00\x00\x00\x18\x01\x20\x01\x28\x01\x00"
+
+#define s2m_data_FIELDLIST(X, a) \
+X(a, CALLBACK, REPEATED, MESSAGE, datapoints, 1)
+#define s2m_data_CALLBACK pb_default_field_callback
+#define s2m_data_DEFAULT NULL
+#define s2m_data_datapoints_MSGTYPE _datapoint
+
+extern const pb_msgdesc_t m2s_SOR_msg;
+extern const pb_msgdesc_t s2m_DOC_msg;
+extern const pb_msgdesc_t m2s_CTS_msg;
+extern const pb_msgdesc_t command_msg;
+extern const pb_msgdesc_t _datapoint_msg;
+extern const pb_msgdesc_t s2m_data_msg;
+
+/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
+#define m2s_SOR_fields &m2s_SOR_msg
+#define s2m_DOC_fields &s2m_DOC_msg
+#define m2s_CTS_fields &m2s_CTS_msg
+#define command_fields &command_msg
+#define _datapoint_fields &_datapoint_msg
+#define s2m_data_fields &s2m_data_msg
+
+/* Maximum encoded size of messages (where known) */
+#define m2s_SOR_size 12
+#define s2m_DOC_size 12
+#define m2s_CTS_size 6
+/* command_size depends on runtime parameters */
+#define _datapoint_size 38
+/* s2m_data_size depends on runtime parameters */
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif
diff --git a/include/dataflow.h b/include/dataflow.h
new file mode 100644
index 0000000..2aed40a
--- /dev/null
+++ b/include/dataflow.h
@@ -0,0 +1,47 @@
+
+/*
+ *
+ * Dataflow Status Enumeration
+ *
+ * This typedef governs the dataflow state machine. Enums should be self explanatory
+ *
+ * TODO Handle other DF pathways for slave RX datapoint and slave RX command
+ *
+ * |------------+-----+----------------------------------------+---------------------+-------------------------|
+ * | Status | Int | Status Invariant | Action | Next Status |
+ * |------------+-----+----------------------------------------+---------------------+-------------------------|
+ * | DF_IDLE | 0 | Ready to send m2s_SOR | Send m2s_SOR | DF_RX_DOC or ??? |
+ * | DF_RX_DOC | 1 | Sent m2s_SOR; ready to receive s2m_DOC | Receive s2m_DOC | DF_CTS |
+ * | DF_CTS | 2 | Received m2s_SOR; ready to send DF_CTS | Send m2s_CTS | DF_RX_DATA or DF_RX_CMD |
+ * | DF_RX_DATA | 3 | Sent m2s_CTS; receive s2m_data | Receive s2m_data | DF_SUCCESS |
+ * | DF_RX_CMD | 4 | sent m2s_CTS receive s2m_command | Receive s2m_command | DF_SUCCESS |
+ * |------------+-----+----------------------------------------+---------------------+-------------------------|
+ *
+ *
+*/
+
+typedef enum dataflow_status {
+ DF_IDLE = 0,
+ DF_RX_DOC = 1,
+ DF_CTS = 2,
+ DF_RX_DATA = 3,
+ DF_RX_CMD = 4,
+ DF_SUCCESS = 5,
+ DF_FAIL = 6,
+ DF_TX_DATA = 7,
+ DF_TX_CMD = 8
+} dataflow_status_t;
+
+typedef enum SOR_codes {
+ SLAVE_TX = 1,
+ SLAVE_RX_DATAPOINT = 2,
+ SLAVE_RX_COMMAND = 3
+} SOR_codes_t;
+
+typedef enum DOC_codes {
+ CMD_UNICAST = 0x1,
+ CMD_MULTICAST = 0x2,
+ CMD_BROADCAST = 0x3,
+ RESERVED = 0x4,
+ DATA = 0x5
+} DOC_codes_t;
diff --git a/include/devices.h b/include/devices.h
new file mode 100644
index 0000000..b2cb825
--- /dev/null
+++ b/include/devices.h
@@ -0,0 +1,43 @@
+
+#include "handshake.pb.h"
+
+#define _MDR s2m_MDR_response
+
+typedef struct _device_info {
+ uint8_t device_id;
+ uint8_t i2c_addr;
+ _MDR MDR;
+
+ uint32_t subscription_requests[4]; /* Subscriptions to this device */
+ uint32_t subscriptions[4]; /* Subscriptions by this device */
+} device_info_t;
+
+/* TODO These IDs could be represented as a single 8-bit integer */
+typedef struct _subscription_info {
+ uint8_t module_ids[128];
+ uint8_t entity_ids[128];
+ uint8_t module_class[3];
+ uint8_t i2c_address[128];
+ uint8_t mod_idx, entity_idx, class_idx, i2c_idx;
+} subscription_info_t;
+
+typedef enum hs_status {
+ IDLE = 0, // send mdr request. success: mdr_ack. fail: hs_fail
+ HS_MDR_ACK = 1, // get mdr ack. success: mdr_cts. fail: hs_fail
+ HS_MDR_CTS = 2, // send mdr cts. success: mdr_mdr. fail: hs_fail
+ HS_MDR_MDR = 3, // get mdr. success: registered. fail: hs_fail
+ HS_REGISTERED = 4, // send registered. success: exit. fail: hs_fail
+ HS_FAILED = 5
+} hs_status_t;
+
+typedef enum state {
+ NO_HS = 0, /* Initial state: handshake not attempted yet */
+ OFFLINE = 1, /* Device not found on bus */
+ CONNECTED = 2, /* Device found on bus but handshake not completed */
+ REGISTERED = 3, /* Completed handshake; ready for action */
+ FAILED = 4, /* Handshake failed */
+ NO_DATA = 5 /* ??? */
+} state_t;
+
+/* Handshake message size definitions */
+#define MDR_req_buf_len 2
diff --git a/include/handshake.pb.h b/include/handshake.pb.h
new file mode 100644
index 0000000..67f10e6
--- /dev/null
+++ b/include/handshake.pb.h
@@ -0,0 +1,133 @@
+/* Automatically generated nanopb header */
+/* Generated by nanopb-0.4.2-dev */
+
+#ifndef PB_HANDSHAKE_PB_H_INCLUDED
+#define PB_HANDSHAKE_PB_H_INCLUDED
+#include <pb.h>
+
+#if PB_PROTO_HEADER_VERSION != 40
+#error Regenerate this file with the current version of nanopb generator.
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Struct definitions */
+typedef struct __subscriptions {
+ bool has_module_id;
+ uint32_t module_id;
+ bool has_entity_id;
+ uint32_t entity_id;
+ bool has_module_class;
+ uint32_t module_class;
+ bool has_i2c_address;
+ uint32_t i2c_address;
+} _subscriptions;
+
+typedef struct _m2s_MDR_request {
+ uint32_t record_type;
+} m2s_MDR_request;
+
+typedef struct _m2s_MDR_res_CTS {
+ uint32_t timeout;
+} m2s_MDR_res_CTS;
+
+typedef struct _s2m_MDR_req_ACK {
+ uint32_t MDR_res_length;
+} s2m_MDR_req_ACK;
+
+typedef struct _s2m_MDR_response {
+ float MDR_version;
+ uint32_t module_id;
+ uint32_t module_class;
+ uint32_t entity_id;
+ pb_callback_t subscriptions;
+} s2m_MDR_response;
+
+
+/* Initializer values for message structs */
+#define m2s_MDR_request_init_default {0}
+#define s2m_MDR_req_ACK_init_default {0}
+#define m2s_MDR_res_CTS_init_default {0}
+#define _subscriptions_init_default {false, 0u, false, 0u, false, 0u, false, 0u}
+#define s2m_MDR_response_init_default {0, 0, 0, 0, {{NULL}, NULL}}
+#define m2s_MDR_request_init_zero {0}
+#define s2m_MDR_req_ACK_init_zero {0}
+#define m2s_MDR_res_CTS_init_zero {0}
+#define _subscriptions_init_zero {false, 0, false, 0, false, 0, false, 0}
+#define s2m_MDR_response_init_zero {0, 0, 0, 0, {{NULL}, NULL}}
+
+/* Field tags (for use in manual encoding/decoding) */
+#define _subscriptions_module_id_tag 1
+#define _subscriptions_entity_id_tag 2
+#define _subscriptions_module_class_tag 3
+#define _subscriptions_i2c_address_tag 4
+#define m2s_MDR_request_record_type_tag 1
+#define m2s_MDR_res_CTS_timeout_tag 1
+#define s2m_MDR_req_ACK_MDR_res_length_tag 1
+#define s2m_MDR_response_MDR_version_tag 1
+#define s2m_MDR_response_module_id_tag 2
+#define s2m_MDR_response_module_class_tag 3
+#define s2m_MDR_response_entity_id_tag 4
+#define s2m_MDR_response_subscriptions_tag 5
+
+/* Struct field encoding specification for nanopb */
+#define m2s_MDR_request_FIELDLIST(X, a) \
+X(a, STATIC, REQUIRED, UINT32, record_type, 1)
+#define m2s_MDR_request_CALLBACK NULL
+#define m2s_MDR_request_DEFAULT NULL
+
+#define s2m_MDR_req_ACK_FIELDLIST(X, a) \
+X(a, STATIC, REQUIRED, UINT32, MDR_res_length, 1)
+#define s2m_MDR_req_ACK_CALLBACK NULL
+#define s2m_MDR_req_ACK_DEFAULT NULL
+
+#define m2s_MDR_res_CTS_FIELDLIST(X, a) \
+X(a, STATIC, REQUIRED, UINT32, timeout, 1)
+#define m2s_MDR_res_CTS_CALLBACK NULL
+#define m2s_MDR_res_CTS_DEFAULT NULL
+
+#define _subscriptions_FIELDLIST(X, a) \
+X(a, STATIC, OPTIONAL, UINT32, module_id, 1) \
+X(a, STATIC, OPTIONAL, UINT32, entity_id, 2) \
+X(a, STATIC, OPTIONAL, UINT32, module_class, 3) \
+X(a, STATIC, OPTIONAL, UINT32, i2c_address, 4)
+#define _subscriptions_CALLBACK NULL
+#define _subscriptions_DEFAULT (const pb_byte_t*)"\x08\x00\x10\x00\x18\x00\x20\x00\x00"
+
+#define s2m_MDR_response_FIELDLIST(X, a) \
+X(a, STATIC, REQUIRED, FLOAT, MDR_version, 1) \
+X(a, STATIC, REQUIRED, UINT32, module_id, 2) \
+X(a, STATIC, REQUIRED, UINT32, module_class, 3) \
+X(a, STATIC, REQUIRED, UINT32, entity_id, 4) \
+X(a, CALLBACK, REPEATED, MESSAGE, subscriptions, 5)
+#define s2m_MDR_response_CALLBACK pb_default_field_callback
+#define s2m_MDR_response_DEFAULT NULL
+#define s2m_MDR_response_subscriptions_MSGTYPE _subscriptions
+
+extern const pb_msgdesc_t m2s_MDR_request_msg;
+extern const pb_msgdesc_t s2m_MDR_req_ACK_msg;
+extern const pb_msgdesc_t m2s_MDR_res_CTS_msg;
+extern const pb_msgdesc_t _subscriptions_msg;
+extern const pb_msgdesc_t s2m_MDR_response_msg;
+
+/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
+#define m2s_MDR_request_fields &m2s_MDR_request_msg
+#define s2m_MDR_req_ACK_fields &s2m_MDR_req_ACK_msg
+#define m2s_MDR_res_CTS_fields &m2s_MDR_res_CTS_msg
+#define _subscriptions_fields &_subscriptions_msg
+#define s2m_MDR_response_fields &s2m_MDR_response_msg
+
+/* Maximum encoded size of messages (where known) */
+#define m2s_MDR_request_size 6
+#define s2m_MDR_req_ACK_size 6
+#define m2s_MDR_res_CTS_size 6
+#define _subscriptions_size 24
+/* s2m_MDR_response_size depends on runtime parameters */
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif
diff --git a/include/main.h b/include/main.h
new file mode 100644
index 0000000..6579484
--- /dev/null
+++ b/include/main.h
@@ -0,0 +1,73 @@
+/* USER CODE BEGIN Header */
+/**
+ ******************************************************************************
+ * @file : main.h
+ * @brief : Header for main.c file.
+ * This file contains the common defines of the application.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
+ * All rights reserved.</center></h2>
+ *
+ * This software component is licensed by ST under BSD 3-Clause license,
+ * the "License"; You may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ * opensource.org/licenses/BSD-3-Clause
+ *
+ ******************************************************************************
+ */
+/* USER CODE END Header */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __MAIN_H
+#define __MAIN_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "port.h"
+
+/* Private includes ----------------------------------------------------------*/
+/* USER CODE BEGIN Includes */
+
+/* USER CODE END Includes */
+
+/* Exported types ------------------------------------------------------------*/
+/* USER CODE BEGIN ET */
+
+/* USER CODE END ET */
+
+/* Exported constants --------------------------------------------------------*/
+/* USER CODE BEGIN EC */
+
+/* USER CODE END EC */
+
+/* Exported macro ------------------------------------------------------------*/
+/* USER CODE BEGIN EM */
+
+/* USER CODE END EM */
+
+/* Exported functions prototypes ---------------------------------------------*/
+void Error_Handler(void);
+
+/* USER CODE BEGIN EFP */
+
+/* USER CODE END EFP */
+
+/* Private defines -----------------------------------------------------------*/
+#define led_Pin GPIO_PIN_13
+#define led_GPIO_Port GPIOC
+/* USER CODE BEGIN Private defines */
+
+/* USER CODE END Private defines */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MAIN_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/include/stream.h b/include/stream.h
new file mode 100644
index 0000000..6bdc29e
--- /dev/null
+++ b/include/stream.h
@@ -0,0 +1,10 @@
+#include <stdint.h>
+#include <stddef.h>
+
+typedef struct p_stream_s p_stream_t;
+
+struct p_stream_s {
+ int (*read)(uint8_t *buf, size_t len, void **vptr, void *sptr);
+ int (*write)(uint8_t *buf, size_t len, void **vptr, void *sptr);
+ void **props;
+};
diff --git a/include/stream_i2c.h b/include/stream_i2c.h
new file mode 100644
index 0000000..ccbccde
--- /dev/null
+++ b/include/stream_i2c.h
@@ -0,0 +1,5 @@
+#include <stdint.h>
+#include <stddef.h>
+
+int i2c_read(uint8_t* buf, size_t count, void **vptr, void *sptr);
+int i2c_write(uint8_t* buf, size_t count, void **vptr, void *sptr);
diff --git a/include/stream_stdio.h b/include/stream_stdio.h
new file mode 100644
index 0000000..c72183b
--- /dev/null
+++ b/include/stream_stdio.h
@@ -0,0 +1,5 @@
+#include <stdint.h>
+#include <stddef.h>
+
+int stdio_read(uint8_t* buf, size_t count, void **vptr, void *sptr);
+int stdio_write(uint8_t* buf, size_t count, void **vptr, void *sptr);