ICARUS OS (Intelligent Cooperative Architecture for Real-time Unified Systems) 0.1.0
Preemptive Real-Time Operating System for ARM Cortex-M7
Loading...
Searching...
No Matches
cdc_rx.c
Go to the documentation of this file.
1
26#include "icarus/cdc_rx.h"
27#include "icarus/config.h"
28#include <stddef.h>
29
30/* ---- Backing storage in DTCM_PRIV --------------------------------------- */
31
32DTCM_DATA_PRIV static volatile uint8_t rx_buf[CDC_RX_BUF_SIZE];
33DTCM_DATA_PRIV static volatile uint32_t rx_head;
34DTCM_DATA_PRIV static volatile uint32_t rx_tail;
35
36/* ---- Privileged implementations (run in priv mode, ITCM hot path) ------ */
37
39 rx_head = 0;
40 rx_tail = 0;
41}
42
43ITCM_FUNC void __cdc_rx_push(const uint8_t *data, uint32_t len) {
44 if ((data == NULL) || (len == 0u)) {
45 return;
46 }
47 for (uint32_t i = 0u; i < len; i++) {
48 uint32_t next = (rx_head + 1u) % (uint32_t)CDC_RX_BUF_SIZE;
49 if (next == rx_tail) {
50 break;
51 }
52 rx_buf[rx_head] = data[i];
53 rx_head = next;
54 }
55}
56
57ITCM_FUNC bool __cdc_rx_read_byte(uint8_t *out) {
58 if ((out == NULL) || (rx_head == rx_tail)) {
59 return false;
60 }
61 *out = rx_buf[rx_tail];
62 rx_tail = (rx_tail + 1u) % (uint32_t)CDC_RX_BUF_SIZE;
63 return true;
64}
65
67 uint32_t h = rx_head;
68 uint32_t t = rx_tail;
69 if (h >= t) {
70 return h - t;
71 }
72 return ((uint32_t)CDC_RX_BUF_SIZE - t) + h;
73}
static volatile uint8_t rx_buf[512]
Definition cdc_rx.c:32
static volatile uint32_t rx_head
Definition cdc_rx.c:33
bool __cdc_rx_read_byte(uint8_t *out)
Definition cdc_rx.c:57
static volatile uint32_t rx_tail
Definition cdc_rx.c:34
uint32_t __cdc_rx_available(void)
Definition cdc_rx.c:66
void __cdc_rx_init(void)
Definition cdc_rx.c:38
void __cdc_rx_push(const uint8_t *data, uint32_t len)
Definition cdc_rx.c:43
USB CDC receive ring buffer.
#define CDC_RX_BUF_SIZE
Definition cdc_rx.h:29
ICARUS OS Configuration Header.
#define DTCM_DATA_PRIV
Definition config.h:156
#define ITCM_FUNC
Definition config.h:155