osd-contiki/platform/stm32f107_basic/gqueue.c
Jeff Ciesielski 222f93f023 stm32f107_basic: Add support for a simple stm32f107 platform
This platform is a basic waveshare stm32f107 devkit which contains a
USART, USB device port, some buttons and some LEDs.  Unfortunately not
enough to bring up networking, but enough to test building and a
simple contiki shell
2013-02-06 15:43:25 -08:00

39 lines
950 B
C

#include <gqueue.h>
void
queue_enqueue(volatile void *q, const void *elt)
{
volatile struct generic_queue *gq = q;
if(gq->len == 0) {
gq->head = gq->memory;
gq->tail = gq->memory;
} else {
if(gq->tail == gq->memory + (gq->max_capacity - 1) * gq->item_size)
/* FIXME: Should something be done about
* queue length? Substact one, maybe?*/
gq->tail = gq->memory;
else
gq->tail = (uint8_t *) gq->tail + gq->item_size;
}
memcpy((void *)gq->tail, elt, gq->item_size);
gq->len++;
}
void
queue_dequeue(volatile void *q, void *elt)
{
volatile struct generic_queue *gq = q;
memcpy(elt, (void *)gq->head, gq->item_size);
if(gq->head == gq->memory + (gq->max_capacity - 1) * gq->item_size)
/* FIXME: Should something be done about
* queue length? Substact one, maybe?*/
gq->head = gq->memory;
else if(gq->len > 1)
gq->head = (uint8_t *) gq->head + gq->item_size;
gq->len--;
}