/*************************************************************************** * Copyright (C) 11/2014 by Olaf Rempel * * razzor@kopf-tisch.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; version 2 of the License, * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include "event.h" /* *********************************************************************** */ #define EVENT_COUNT 16 static struct event_entry events[EVENT_COUNT]; static volatile uint8_t event_in_idx; static volatile uint8_t event_out_idx; /* *********************************************************************** */ void event_queue(uint8_t type, uint8_t num, uint16_t value) { uint8_t idx = event_in_idx; struct event_entry *event = &events[idx++]; if (event->type == EVENT_TYPE_EMPTY) { event->type = type; event->num = num; event->value = value; event_in_idx = idx % EVENT_COUNT; } } /* event_queue */ struct event_entry * event_get(void) { return &events[event_out_idx]; } /* event_get */ void event_clear(void) { uint8_t idx = event_out_idx; events[idx++].type = EVENT_TYPE_EMPTY; event_out_idx = idx % EVENT_COUNT; } /* event_clear */