Correct types for FIFO16 on 32-bit platforms

This commit is contained in:
Mark Qvist 2022-01-09 23:45:40 +01:00
parent 3e0536b272
commit b2d318b576
2 changed files with 27 additions and 27 deletions

View File

@ -6,17 +6,17 @@ FIFOBuffer serialFIFO;
uint8_t serialBuffer[CONFIG_UART_BUFFER_SIZE+1]; uint8_t serialBuffer[CONFIG_UART_BUFFER_SIZE+1];
FIFOBuffer16 packet_starts; FIFOBuffer16 packet_starts;
size_t packet_starts_buf[CONFIG_QUEUE_MAX_LENGTH+1]; uint16_t packet_starts_buf[CONFIG_QUEUE_MAX_LENGTH+1];
FIFOBuffer16 packet_lengths; FIFOBuffer16 packet_lengths;
size_t packet_lengths_buf[CONFIG_QUEUE_MAX_LENGTH+1]; uint16_t packet_lengths_buf[CONFIG_QUEUE_MAX_LENGTH+1];
uint8_t packet_queue[CONFIG_QUEUE_SIZE]; uint8_t packet_queue[CONFIG_QUEUE_SIZE];
volatile uint8_t queue_height = 0; volatile uint8_t queue_height = 0;
volatile size_t queued_bytes = 0; volatile uint16_t queued_bytes = 0;
volatile size_t queue_cursor = 0; volatile uint16_t queue_cursor = 0;
volatile size_t current_packet_start = 0; volatile uint16_t current_packet_start = 0;
volatile bool serial_buffering = false; volatile bool serial_buffering = false;
char sbuf[128]; char sbuf[128];
@ -250,7 +250,7 @@ void flushQueue(void) {
if (!queue_flushing) { if (!queue_flushing) {
queue_flushing = true; queue_flushing = true;
size_t processed = 0; uint16_t processed = 0;
#if MCU_VARIANT == MCU_ESP32 #if MCU_VARIANT == MCU_ESP32
while (!fifo16_isempty(&packet_starts)) { while (!fifo16_isempty(&packet_starts)) {
@ -258,12 +258,12 @@ void flushQueue(void) {
while (!fifo16_isempty_locked(&packet_starts)) { while (!fifo16_isempty_locked(&packet_starts)) {
#endif #endif
size_t start = fifo16_pop(&packet_starts); uint16_t start = fifo16_pop(&packet_starts);
size_t length = fifo16_pop(&packet_lengths); uint16_t length = fifo16_pop(&packet_lengths);
if (length >= MIN_L && length <= MTU) { if (length >= MIN_L && length <= MTU) {
for (size_t i = 0; i < length; i++) { for (uint16_t i = 0; i < length; i++) {
size_t pos = (start+i)%CONFIG_QUEUE_SIZE; uint16_t pos = (start+i)%CONFIG_QUEUE_SIZE;
tbuf[i] = packet_queue[pos]; tbuf[i] = packet_queue[pos];
} }
@ -278,11 +278,11 @@ void flushQueue(void) {
queue_flushing = false; queue_flushing = false;
} }
void transmit(size_t size) { void transmit(uint16_t size) {
if (radio_online) { if (radio_online) {
if (!promisc) { if (!promisc) {
led_tx_on(); led_tx_on();
size_t written = 0; uint16_t written = 0;
uint8_t header = random(256) & 0xF0; uint8_t header = random(256) & 0xF0;
if (size > SINGLE_MTU - HEADER_L) { if (size > SINGLE_MTU - HEADER_L) {
@ -292,7 +292,7 @@ void transmit(size_t size) {
LoRa.beginPacket(); LoRa.beginPacket();
LoRa.write(header); written++; LoRa.write(header); written++;
for (size_t i; i < size; i++) { for (uint16_t i; i < size; i++) {
LoRa.write(tbuf[i]); LoRa.write(tbuf[i]);
written++; written++;
@ -314,7 +314,7 @@ void transmit(size_t size) {
// plain raw LoRa packets with a maximum // plain raw LoRa packets with a maximum
// payload of 255 bytes // payload of 255 bytes
led_tx_on(); led_tx_on();
size_t written = 0; uint16_t written = 0;
// Cap packets at 255 bytes // Cap packets at 255 bytes
if (size > SINGLE_MTU) { if (size > SINGLE_MTU) {
@ -329,7 +329,7 @@ void transmit(size_t size) {
LoRa.beginPacket(size); LoRa.beginPacket(size);
} }
for (size_t i; i < size; i++) { for (uint16_t i; i < size; i++) {
LoRa.write(tbuf[i]); LoRa.write(tbuf[i]);
written++; written++;
@ -350,9 +350,9 @@ void serialCallback(uint8_t sbyte) {
IN_FRAME = false; IN_FRAME = false;
if (!fifo16_isfull(&packet_starts) && queued_bytes < CONFIG_QUEUE_SIZE) { if (!fifo16_isfull(&packet_starts) && queued_bytes < CONFIG_QUEUE_SIZE) {
size_t s = current_packet_start; uint16_t s = current_packet_start;
size_t e = queue_cursor-1; if (e == -1) e = CONFIG_QUEUE_SIZE-1; uint16_t e = queue_cursor-1; if (e == -1) e = CONFIG_QUEUE_SIZE-1;
size_t l; uint16_t l;
if (s != e) { if (s != e) {
l = (s < e) ? e - s + 1 : CONFIG_QUEUE_SIZE - s + e + 1; l = (s < e) ? e - s + 1 : CONFIG_QUEUE_SIZE - s + e + 1;

View File

@ -713,10 +713,10 @@ inline size_t fifo_len(FIFOBuffer *f) {
typedef struct FIFOBuffer16 typedef struct FIFOBuffer16
{ {
size_t *begin; uint16_t *begin;
size_t *end; uint16_t *end;
size_t * volatile head; uint16_t * volatile head;
size_t * volatile tail; uint16_t * volatile tail;
} FIFOBuffer16; } FIFOBuffer16;
inline bool fifo16_isempty(const FIFOBuffer16 *f) { inline bool fifo16_isempty(const FIFOBuffer16 *f) {
@ -727,7 +727,7 @@ inline bool fifo16_isfull(const FIFOBuffer16 *f) {
return ((f->head == f->begin) && (f->tail == f->end)) || (f->tail == f->head - 1); return ((f->head == f->begin) && (f->tail == f->end)) || (f->tail == f->head - 1);
} }
inline void fifo16_push(FIFOBuffer16 *f, size_t c) { inline void fifo16_push(FIFOBuffer16 *f, uint16_t c) {
*(f->tail) = c; *(f->tail) = c;
if (f->tail == f->end) { if (f->tail == f->end) {
@ -737,7 +737,7 @@ inline void fifo16_push(FIFOBuffer16 *f, size_t c) {
} }
} }
inline size_t fifo16_pop(FIFOBuffer16 *f) { inline uint16_t fifo16_pop(FIFOBuffer16 *f) {
if(f->head == f->end) { if(f->head == f->end) {
f->head = f->begin; f->head = f->begin;
return *(f->end); return *(f->end);
@ -771,7 +771,7 @@ static inline bool fifo16_isfull_locked(const FIFOBuffer16 *f) {
} }
static inline void fifo16_push_locked(FIFOBuffer16 *f, size_t c) { static inline void fifo16_push_locked(FIFOBuffer16 *f, uint16_t c) {
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
fifo16_push(f, c); fifo16_push(f, c);
} }
@ -786,11 +786,11 @@ static inline size_t fifo16_pop_locked(FIFOBuffer16 *f) {
} }
*/ */
inline void fifo16_init(FIFOBuffer16 *f, size_t *buffer, size_t size) { inline void fifo16_init(FIFOBuffer16 *f, uint16_t *buffer, uint16_t size) {
f->head = f->tail = f->begin = buffer; f->head = f->tail = f->begin = buffer;
f->end = buffer + size; f->end = buffer + size;
} }
inline size_t fifo16_len(FIFOBuffer16 *f) { inline uint16_t fifo16_len(FIFOBuffer16 *f) {
return (f->end - f->begin); return (f->end - f->begin);
} }