73 lines
2.5 KiB
C
73 lines
2.5 KiB
C
/***************************************************************************
|
|
* Copyright (C) 02/2021 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 m_events[EVENT_COUNT];
|
|
static volatile uint8_t m_event_in_idx;
|
|
static volatile uint8_t m_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 = m_event_in_idx;
|
|
p_event = &m_events[idx];
|
|
if (p_event->type == EVENT_TYPE_EMPTY)
|
|
{
|
|
p_event->type = type;
|
|
p_event->num = num;
|
|
p_event->value = value;
|
|
m_event_in_idx = (idx +1) % EVENT_COUNT;
|
|
}
|
|
|
|
SREG = sreg_save;
|
|
} /* event_queue */
|
|
|
|
|
|
event_entry_t * event_get(void)
|
|
{
|
|
return &m_events[m_event_out_idx];
|
|
} /* event_get */
|
|
|
|
|
|
void event_clear(event_entry_t * p_event)
|
|
{
|
|
uint8_t idx = m_event_out_idx;
|
|
|
|
if ((p_event == &m_events[idx]) &&
|
|
(p_event->type != EVENT_TYPE_EMPTY)
|
|
)
|
|
{
|
|
p_event->type = EVENT_TYPE_EMPTY;
|
|
m_event_out_idx = (idx +1) % EVENT_COUNT;
|
|
}
|
|
} /* event_clear */
|