STM32 firmware for a remotely-controlled stepper motor demo with a mobile interface.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
f105-motor-demo_stm32/project/bus/event_queue.c

66 lines
922 B

#include "event_queue.h"
#include "com/debug.h"
/** Task queue */
static CircBuf *tq;
/** Event queue */
static CircBuf *eq;
void queues_init(size_t tq_size, size_t eq_size)
{
tq = cbuf_create(tq_size, sizeof(QueuedTask));
eq = cbuf_create(eq_size, sizeof(Event));
}
bool tq_post(void (*handler)(void*), void *arg)
{
QueuedTask task;
task.handler = handler;
task.arg = arg;
bool suc = cbuf_append(tq, &task);
if (!suc) error("TQ overflow");
return suc;
}
bool eq_post(const Event *event)
{
bool suc = cbuf_append(eq, event);
if (!suc) {
error("EQ overflow, evt %d", event->type);
}
return suc;
}
bool tq_poll_one(void)
{
QueuedTask task;
// serve all tasks
bool suc = cbuf_pop(tq, &task);
if (suc) {
task.handler(task.arg);
}
return suc;
}
void tq_poll(void)
{
// serve all tasks
while (tq_poll_one());
}
bool eq_take(Event *dest)
{
bool suc = cbuf_pop(eq, dest);
return suc;
}