aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-09-25 15:47:14 +0200
committerlonkaars <loek@pipeframe.xyz>2022-09-25 15:47:14 +0200
commit3608f1cc19f4bc102c1f0c5a3ab242e2e318a0b9 (patch)
tree3a829b7ff1b7d1d25cf8b9fb029459a78a4e7dd8
parent9d9f9dc034765aa4b1c5bd2d0aa4cd24e4110055 (diff)
implement backlog interface
-rw-r--r--stm32f091/backlog.c1
-rw-r--r--stm32f091/backlog.h54
-rw-r--r--stm32f091/makefile2
3 files changed, 56 insertions, 1 deletions
diff --git a/stm32f091/backlog.c b/stm32f091/backlog.c
new file mode 100644
index 0000000..1c847f0
--- /dev/null
+++ b/stm32f091/backlog.c
@@ -0,0 +1 @@
+#include "backlog.h"
diff --git a/stm32f091/backlog.h b/stm32f091/backlog.h
new file mode 100644
index 0000000..7051ecf
--- /dev/null
+++ b/stm32f091/backlog.h
@@ -0,0 +1,54 @@
+#pragma once
+
+#include <stdint.h>
+
+/**
+ * @brief allocate backlog buffer and set global backlog pointer
+ * @param record_amt amount of records to keep before overwriting oldest record
+ */
+void ws_backlog_alloc(uint16_t record_amt);
+
+// enable struct packing
+#pragma pack(push, 1)
+
+/** @brief backlog record */
+typedef struct {
+ uint16_t id; /**< unique record identifier, numbered sequentially */
+ uint8_t sens_temperature; /**< temperature reading */
+ uint8_t sens_humidity; /**< humidity reading */
+ uint8_t sens_atm_pressure; /**< atmospheric pressure reading */
+} ws_s_backlog_record;
+
+typedef struct {
+ uint16_t buffer_size; /**< buffer size (buffer_size + 1 = amount of records) */
+ uint16_t buffer_start; /** first record index */
+ uint16_t buffer_end; /** last record index */
+ ws_s_backlog_record* records; /** pointer to record array */
+} ws_s_backlog_database;
+
+// disable struct packing
+#pragma pack(pop)
+
+/** @brief global record backlog database pointer */
+extern ws_s_backlog_database* WS_G_BACKLOG_DATABASE;
+
+/**
+ * @brief add record to database
+ *
+ * automatically sets record.id, pushes buffer_end forwards and overwrites the
+ * last record if the buffer is full
+ */
+void ws_backlog_add_record(ws_s_backlog_record* record);
+
+/**
+ * there's intentionally no function to retrieve multiple records as an array,
+ * as this would either require
+ * (a) copying the selection which is not possible with the current memory
+ * constraints, or
+ * (b) giving a direct pointer, but this would cause undefined behavior at the
+ * ring buffer seam
+ */
+
+/** @brief get pointer to record with index `record_index` from the database */
+ws_s_backlog_record* ws_backlog_get_record(uint16_t record_index);
+
diff --git a/stm32f091/makefile b/stm32f091/makefile
index 5f5371d..08c582a 100644
--- a/stm32f091/makefile
+++ b/stm32f091/makefile
@@ -18,7 +18,7 @@ SHARED_FLAGS += -ffunction-sections
SHARED_FLAGS += -fdata-sections
SHARED_FLAGS += -mlittle-endian
SHARED_FLAGS += -mthumb
-SHARED_FLAGS += -masm-syntax-unified
+# SHARED_FLAGS += -masm-syntax-unified
SHARED_FLAGS += -specs=nosys.specs
# SHARED_FLAGS += -fno-threadsafe-statics
# SHARED_FLAGS += -fno-rtti