summaryrefslogtreecommitdiff
path: root/fw/esp32/components/eos/msgq.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/esp32/components/eos/msgq.c')
-rw-r--r--fw/esp32/components/eos/msgq.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/fw/esp32/components/eos/msgq.c b/fw/esp32/components/eos/msgq.c
index 57fb669..50dbd3e 100644
--- a/fw/esp32/components/eos/msgq.c
+++ b/fw/esp32/components/eos/msgq.c
@@ -5,6 +5,24 @@
#define IDX_MASK(IDX, SIZE) ((IDX) & ((SIZE) - 1))
+void eos_msg_init(EOSMessage *msg, unsigned char *buffer, uint16_t size) {
+ msg->buffer = buffer;
+ msg->size = size;
+ msg->flags = 0;
+}
+
+void eos_msg_set_flags(EOSMessage *msg, uint8_t flags) {
+ msg->flags |= flags;
+}
+
+void eos_msg_clear_flags(EOSMessage *msg, uint8_t flags) {
+ msg->flags &= ~flags;
+}
+
+uint8_t eos_msg_flags(EOSMessage *msg) {
+ return msg->flags;
+}
+
void eos_msgq_init(EOSMsgQ *msgq, EOSMsgItem *array, uint8_t size) {
msgq->idx_r = 0;
msgq->idx_w = 0;
@@ -16,26 +34,37 @@ uint8_t eos_msgq_len(EOSMsgQ *msgq) {
return (uint8_t)(msgq->idx_w - msgq->idx_r);
}
-int eos_msgq_push(EOSMsgQ *msgq, unsigned char type, unsigned char *buffer, uint16_t len) {
+int eos_msgq_push(EOSMsgQ *msgq, unsigned char type, EOSMessage *msg, uint16_t len) {
+ uint8_t idx;
+
if ((uint8_t)(msgq->idx_w - msgq->idx_r) == msgq->size) return EOS_ERR_FULL;
- uint8_t idx = IDX_MASK(msgq->idx_w, msgq->size);
+ idx = IDX_MASK(msgq->idx_w, msgq->size);
msgq->array[idx].type = type;
- msgq->array[idx].buffer = buffer;
- msgq->array[idx].len = len;
+ if (msg) {
+ msgq->array[idx].buffer = msg->buffer;
+ msgq->array[idx].size = msg->size;
+ msgq->array[idx].len = len;
+ } else {
+ msgq->array[idx].buffer = NULL;
+ msgq->array[idx].size = 0;
+ msgq->array[idx].len = 0;
+ }
msgq->idx_w++;
+
return EOS_OK;
}
-void eos_msgq_pop(EOSMsgQ *msgq, unsigned char *type, unsigned char **buffer, uint16_t *len) {
+void eos_msgq_pop(EOSMsgQ *msgq, unsigned char *type, EOSMessage *msg, uint16_t *len) {
if (msgq->idx_r == msgq->idx_w) {
*type = 0;
- *buffer = NULL;
+ eos_msg_init(msg, NULL, 0);
*len = 0;
} else {
uint8_t idx = IDX_MASK(msgq->idx_r, msgq->size);
+
*type = msgq->array[idx].type;
- *buffer = msgq->array[idx].buffer;
+ eos_msg_init(msg, msgq->array[idx].buffer, msgq->array[idx].size);
*len = msgq->array[idx].len;
msgq->idx_r++;
}