67 lines
2.4 KiB
C
67 lines
2.4 KiB
C
/***************************************************************************
|
|
* Copyright (C) 01/2019 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 <avr/interrupt.h>
|
|
#include <avr/io.h>
|
|
|
|
#include "event.h"
|
|
|
|
/* *********************************************************************** */
|
|
|
|
static event_entry_t 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)
|
|
{
|
|
event_entry_t * p_event;
|
|
uint8_t sreg_save;
|
|
uint8_t idx;
|
|
|
|
sreg_save = SREG;
|
|
cli();
|
|
|
|
idx = event_in_idx;
|
|
p_event = &events[idx++];
|
|
if (p_event->type == EVENT_TYPE_EMPTY)
|
|
{
|
|
p_event->type = type;
|
|
p_event->num = num;
|
|
p_event->value = value;
|
|
event_in_idx = idx % EVENT_COUNT;
|
|
}
|
|
|
|
SREG = sreg_save;
|
|
} /* event_queue */
|
|
|
|
|
|
event_entry_t * 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 */
|