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.
 
 
 

68 lines
2.4 KiB

  1. /***************************************************************************
  2. * Copyright (C) 11/2014 by Olaf Rempel *
  3. * razzor@kopf-tisch.de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; version 2 of the License, *
  8. * *
  9. * This program is distributed in the hope that it will be useful, *
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  12. * GNU General Public License for more details. *
  13. * *
  14. * You should have received a copy of the GNU General Public License *
  15. * along with this program; if not, write to the *
  16. * Free Software Foundation, Inc., *
  17. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  18. ***************************************************************************/
  19. #include <avr/interrupt.h>
  20. #include <avr/io.h>
  21. #include "event.h"
  22. #include "target.h"
  23. /* *********************************************************************** */
  24. static struct event_entry events[EVENT_COUNT];
  25. static volatile uint8_t event_in_idx;
  26. static volatile uint8_t event_out_idx;
  27. /* *********************************************************************** */
  28. void event_queue(uint8_t type, uint8_t num, uint16_t value)
  29. {
  30. struct event_entry *event;
  31. uint8_t sreg_save;
  32. uint8_t idx;
  33. sreg_save = SREG;
  34. cli();
  35. idx = event_in_idx;
  36. event = &events[idx++];
  37. if (event->type == EVENT_TYPE_EMPTY)
  38. {
  39. event->type = type;
  40. event->num = num;
  41. event->value = value;
  42. event_in_idx = idx % EVENT_COUNT;
  43. }
  44. SREG = sreg_save;
  45. } /* event_queue */
  46. struct event_entry * event_get(void)
  47. {
  48. return &events[event_out_idx];
  49. } /* event_get */
  50. void event_clear(void)
  51. {
  52. uint8_t idx = event_out_idx;
  53. events[idx++].type = EVENT_TYPE_EMPTY;
  54. event_out_idx = idx % EVENT_COUNT;
  55. } /* event_clear */