mirror of
https://github.com/halleysfifthinc/AVCLAN-Mockingboard.git
synced 2026-08-07 01:13:18 +00:00
Fix incorrect definition/initialization of caches
This commit is contained in:
+8
-7
@@ -4,24 +4,25 @@
|
|||||||
#include "avclandrv.h"
|
#include "avclandrv.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
void constructQueue(Queue_t *q, void *buf, uint8_t size, uint8_t len,
|
void constructQueue(Queue_t *q, void **slots, void *items, uint8_t itemSize,
|
||||||
uint8_t constructFull) {
|
uint8_t len, uint8_t constructFull) {
|
||||||
q->read = 0;
|
q->read = 0;
|
||||||
q->size = len;
|
q->size = len;
|
||||||
|
q->buf = slots;
|
||||||
if (!!constructFull) {
|
if (!!constructFull) {
|
||||||
q->write = len;
|
q->write = len;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < len; ++i) {
|
for (uint8_t i = 0; i < len; ++i) {
|
||||||
q->buf[i] = buf;
|
q->buf[i] = items;
|
||||||
buf = (char *)buf + size;
|
items = (char *)items + itemSize;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
q->write = 0;
|
q->write = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void constructEmptyQueue(Queue_t *q, uint8_t size, uint8_t len) {
|
void constructEmptyQueue(Queue_t *q, void **slots, uint8_t len) {
|
||||||
constructQueue(q, NULL, size, len, 0);
|
constructQueue(q, slots, NULL, 0, len, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t isEmpty(const Queue_t *q) { return (q->write == q->read); }
|
uint8_t isEmpty(const Queue_t *q) { return (q->write == q->read); }
|
||||||
@@ -43,7 +44,7 @@ uint8_t pushQueue(Queue_t *q, void *x) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *peekQueue(const Queue_t *q) {
|
void *peekQueue(const Queue_t *q) {
|
||||||
if (isEmpty(q))
|
if (isEmpty(q))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|||||||
+7
-6
@@ -5,14 +5,15 @@
|
|||||||
typedef struct Queue_struct {
|
typedef struct Queue_struct {
|
||||||
uint8_t write;
|
uint8_t write;
|
||||||
uint8_t read;
|
uint8_t read;
|
||||||
uint8_t size;
|
uint8_t size; // MUST be a power of 2 (qMask depends on it)
|
||||||
void *buf[];
|
void **buf; // size entries, owned by caller
|
||||||
} Queue_t;
|
} Queue_t;
|
||||||
|
|
||||||
void constructQueue(Queue_t *q, void *buf, uint8_t size, uint8_t len,
|
void constructQueue(Queue_t *q, void **slots, void *items, uint8_t itemSize,
|
||||||
uint8_t constructFull);
|
uint8_t len, uint8_t constructFull);
|
||||||
void constructEmptyQueue(Queue_t *q, uint8_t size, uint8_t len);
|
void constructEmptyQueue(Queue_t *q, void **slots, uint8_t len);
|
||||||
uint8_t isEmpty(const Queue_t *q);
|
uint8_t isEmpty(const Queue_t *q);
|
||||||
|
inline void incrementRead(Queue_t *q) { q->read++; };
|
||||||
uint8_t pushQueue(Queue_t *q, void *x);
|
uint8_t pushQueue(Queue_t *q, void *x);
|
||||||
const void *peekQueue(const Queue_t *q);
|
void *peekQueue(const Queue_t *q);
|
||||||
void *popQueue(Queue_t *q);
|
void *popQueue(Queue_t *q);
|
||||||
|
|||||||
+13
-4
@@ -37,11 +37,18 @@
|
|||||||
const char *const offon[] = {"OFF", "ON"};
|
const char *const offon[] = {"OFF", "ON"};
|
||||||
|
|
||||||
#define CACHE_SIZE 16
|
#define CACHE_SIZE 16
|
||||||
|
_Static_assert((CACHE_SIZE & (CACHE_SIZE - 1)) == 0,
|
||||||
|
"CACHE_SIZE must be a power of two (qMask depends on it)");
|
||||||
|
|
||||||
AVCLAN_frame_t frames[CACHE_SIZE];
|
AVCLAN_frame_t frames[CACHE_SIZE];
|
||||||
RFrame_t responses[CACHE_SIZE];
|
RFrame_t responses[CACHE_SIZE];
|
||||||
uint8_t framesdata[CACHE_SIZE][MAXMSGLEN];
|
uint8_t framesdata[CACHE_SIZE][MAXMSGLEN];
|
||||||
|
|
||||||
|
void *cacheSlots[CACHE_SIZE];
|
||||||
|
void *rcacheSlots[CACHE_SIZE];
|
||||||
|
void *incomingSlots[CACHE_SIZE];
|
||||||
|
void *outgoingSlots[CACHE_SIZE];
|
||||||
|
|
||||||
Queue_t cache, rcache, incoming, outgoing;
|
Queue_t cache, rcache, incoming, outgoing;
|
||||||
|
|
||||||
volatile uint8_t enqueueStatus = 0;
|
volatile uint8_t enqueueStatus = 0;
|
||||||
@@ -107,11 +114,13 @@ int main() {
|
|||||||
frames[i].data = framesdata[i];
|
frames[i].data = framesdata[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
constructQueue(&cache, frames, sizeof(AVCLAN_frame_t), CACHE_SIZE, 1);
|
constructQueue(&cache, cacheSlots, frames, sizeof(AVCLAN_frame_t), CACHE_SIZE,
|
||||||
constructEmptyQueue(&incoming, sizeof(AVCLAN_frame_t), CACHE_SIZE);
|
1);
|
||||||
|
constructEmptyQueue(&incoming, incomingSlots, CACHE_SIZE);
|
||||||
|
|
||||||
constructQueue(&rcache, responses, sizeof(RFrame_t), CACHE_SIZE, 1);
|
constructQueue(&rcache, rcacheSlots, responses, sizeof(RFrame_t), CACHE_SIZE,
|
||||||
constructEmptyQueue(&outgoing, sizeof(RFrame_t), CACHE_SIZE);
|
1);
|
||||||
|
constructEmptyQueue(&outgoing, outgoingSlots, CACHE_SIZE);
|
||||||
|
|
||||||
Setup();
|
Setup();
|
||||||
print_help();
|
print_help();
|
||||||
|
|||||||
Reference in New Issue
Block a user