|
Last change
on this file since 70 was 69, checked in by f.jahn, 4 weeks ago |
|
Started implementing Modbus on USB CDC channel.
|
|
File size:
623 bytes
|
| Line | |
|---|
| 1 | #ifndef RING_BUFFER_H
|
|---|
| 2 | #define RING_BUFFER_H
|
|---|
| 3 |
|
|---|
| 4 | #include <stdint.h>
|
|---|
| 5 | #include <stdbool.h>
|
|---|
| 6 |
|
|---|
| 7 | #define RB_SIZE (1U << 13U) // must be power of 2 for efficiency
|
|---|
| 8 |
|
|---|
| 9 | typedef struct
|
|---|
| 10 | {
|
|---|
| 11 | uint8_t buffer[RB_SIZE];
|
|---|
| 12 | volatile uint16_t head;
|
|---|
| 13 | volatile uint16_t tail;
|
|---|
| 14 | } ring_buffer_t;
|
|---|
| 15 |
|
|---|
| 16 | void rb_init(ring_buffer_t* rb);
|
|---|
| 17 | bool rb_push(ring_buffer_t* rb, uint8_t data);
|
|---|
| 18 | bool rb_pop(ring_buffer_t* rb, uint8_t* data);
|
|---|
| 19 | uint16_t rb_available(const ring_buffer_t* rb);
|
|---|
| 20 | bool rb_peek(const ring_buffer_t* const rb, uint8_t* const data);
|
|---|
| 21 | bool rb_peek_at(const ring_buffer_t* const rb, uint16_t index, uint8_t* data);
|
|---|
| 22 |
|
|---|
| 23 | #endif
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.