remcon.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*! \file
  2. * remcon.c contains all interface- and low-level routines that
  3. * perform handling of the infrared bitstream
  4. * [COPYRIGHT] Copyright (C) STREAMIT BV
  5. * \version 1.0
  6. * \date 26 september 2003
  7. */
  8. #define LOG_MODULE LOG_REMCON_MODULE
  9. #include <stdlib.h>
  10. #include <fs/typedefs.h>
  11. #include <sys/heap.h>
  12. #include <sys/event.h>
  13. #include <sys/atom.h>
  14. #include <sys/types.h>
  15. #include <dev/irqreg.h>
  16. #include "system.h"
  17. #include "portio.h"
  18. #include "remcon.h"
  19. #include "display.h"
  20. #include "keyboard.h"
  21. #include "led.h"
  22. /*-------------------------------------------------------------------------*/
  23. /* local variable definitions */
  24. /*-------------------------------------------------------------------------*/
  25. static HANDLE hRCEvent;
  26. /*-------------------------------------------------------------------------*/
  27. /* local routines (prototyping) */
  28. /*-------------------------------------------------------------------------*/
  29. static void RcInterrupt(void*);
  30. static void RcClearEvent(HANDLE*);
  31. /*!
  32. * \addtogroup RemoteControl
  33. */
  34. /*@{*/
  35. /*-------------------------------------------------------------------------*/
  36. /* start of code */
  37. /*-------------------------------------------------------------------------*/
  38. /* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
  39. /*!
  40. * \brief ISR Remote Control Interrupt (ISR called by Nut/OS)
  41. *
  42. * NEC-code consists of 5 parts:
  43. *
  44. * - leader (9 msec high, 4,5 msec low)
  45. * - address (8 bits)
  46. * - inverted address (8 bits)
  47. * - data (8 bits)
  48. * - inverted data (8 bits)
  49. *
  50. * The first sequence contains these 5 parts, next
  51. * sequences only contain the leader + 1 '0' bit as long
  52. * as the user holds down the button
  53. * repetition time is 108 msec in that case
  54. *
  55. * Resolution of the 16-bit timer we use here is 4,3 usec
  56. *
  57. * 13,5 msecs are 3109 ticks
  58. * '0' is 1,25 msecs (260 ticks)
  59. * '1' is 2,25 msecs (517 ticks)
  60. *
  61. * \param *p not used (might be used to pass parms from the ISR)
  62. */
  63. /* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
  64. static void RcInterrupt(void *p)
  65. {
  66. // Hier ISR implementeren voor bijv. NEC protocol
  67. }
  68. /* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
  69. /*!
  70. * \brief Clear the eventbuffer of this module
  71. *
  72. * This routine is called during module initialization.
  73. *
  74. * \param *pEvent pointer to the event queue
  75. */
  76. /* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
  77. static void RcClearEvent(HANDLE *pEvent)
  78. {
  79. NutEnterCritical();
  80. *pEvent = 0;
  81. NutExitCritical();
  82. }
  83. /* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
  84. /*!
  85. * \brief Initialise the Remote Control module
  86. *
  87. * - register the ISR in NutOS
  88. * - initialise the HW-timer that is used for this module (Timer1)
  89. * - initialise the external interrupt that inputs the infrared data
  90. * - flush the remote control buffer
  91. * - flush the eventqueue for this module
  92. */
  93. /* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
  94. void RcInit()
  95. {
  96. int nError = 0;
  97. EICRB &= ~RC_INT_SENS_MASK; // clear b0, b1 of EICRB
  98. // Install Remote Control interrupt
  99. nError = NutRegisterIrqHandler(&sig_INTERRUPT4, RcInterrupt, NULL);
  100. if (nError == FALSE)
  101. {
  102. /*
  103. * ToDo: control External Interrupt following NutOS calls
  104. #if (NUTOS_VERSION >= 421)
  105. NutIrqSetMode(&sig_INTERRUPT4, NUT_IRQMODE_FALLINGEDGE);
  106. #else
  107. EICRB |= RC_INT_FALLING_EDGE;
  108. #endif
  109. EIMSK |= 1<<IRQ_INT4; // enable interrupt
  110. */
  111. EICRB |= RC_INT_FALLING_EDGE;
  112. EIMSK |= 1<<IRQ_INT4; // enable interrupt
  113. }
  114. // Initialise 16-bit Timer (Timer1)
  115. TCCR1B |= (1<<CS11) | (1<<CS10); // clockdivider = 64
  116. TIFR |= 1<<ICF1;
  117. //TIMSK = 1<<TICIE1;
  118. RcClearEvent(&hRCEvent);
  119. }
  120. /* ---------- end of module ------------------------------------------------ */
  121. /*@}*/