ih_sam3udbgu.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright (C) 2007 by egnite Software GmbH. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the copyright holders nor the names of
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  21. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  24. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  25. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  27. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. * For additional information see http://www.ethernut.de/
  31. *
  32. */
  33. /*
  34. * $Log$
  35. * Revision 1.2 2008/08/11 06:59:11 haraldkipp
  36. * BSD types replaced by stdint types (feature request #1282721).
  37. *
  38. * Revision 1.1 2007/02/15 16:11:14 haraldkipp
  39. * Support for system controller interrupts added.
  40. *
  41. */
  42. #include <arch/cm3.h>
  43. #include <dev/irqreg.h>
  44. #ifndef NUT_IRQPRI_UART
  45. #define NUT_IRQPRI_UART 0
  46. #endif
  47. static int UartIrqCtl(int cmd, void *param);
  48. IRQ_HANDLER sig_UART = {
  49. #ifdef NUT_PERFMON
  50. 0, /* Interrupt counter, ir_count. */
  51. #endif
  52. NULL, /* Passed argument, ir_arg. */
  53. NULL, /* Handler subroutine, ir_handler. */
  54. UartIrqCtl /* Interrupt control, ir_ctl. */
  55. };
  56. /*!
  57. * \brief System interrupt entry.
  58. */
  59. static void UartIrqEntry(void);// __attribute__ ((naked));
  60. void UartIrqEntry(void)
  61. {
  62. #ifdef NUT_PERFMON
  63. sig_UART.ir_count++;
  64. #endif
  65. if (sig_UART.ir_handler) {
  66. /* Call debug unit interrupt handler. */
  67. (sig_UART.ir_handler) (sig_UART.ir_arg);
  68. }
  69. }
  70. /*!
  71. * \brief Timer/Counter 0 interrupt control.
  72. *
  73. * \param cmd Control command.
  74. * - NUT_IRQCTL_INIT Initialize and disable interrupt.
  75. * - NUT_IRQCTL_STATUS Query interrupt status.
  76. * - NUT_IRQCTL_ENABLE Enable interrupt.
  77. * - NUT_IRQCTL_DISABLE Disable interrupt.
  78. * - NUT_IRQCTL_GETPRIO Query interrupt priority.
  79. * - NUT_IRQCTL_SETPRIO Set interrupt priority.
  80. * - NUT_IRQCTL_GETCOUNT Query and clear interrupt counter.
  81. * \param param Pointer to optional parameter.
  82. *
  83. * \return 0 on success, -1 otherwise.
  84. */
  85. static int UartIrqCtl(int cmd, void *param)
  86. {
  87. int rc = 0;
  88. unsigned int *ival = (unsigned int *)param;
  89. int_fast8_t enabled = inr(AT91C_NVIC_ABR) & _BV(AT91C_ID_DBGU);
  90. /* Disable interrupt. */
  91. if (enabled) {
  92. NVIC_DisableIRQ(INT_UART);
  93. }
  94. switch(cmd) {
  95. case NUT_IRQCTL_INIT:
  96. Cortex_RegisterInt(INT_UART,(void*)UartIrqEntry);
  97. NVIC_SetPriority(INT_UART,NUT_IRQPRI_UART);
  98. outr(AT91C_NVIC_ICPR,_BV(AT91C_ID_DBGU));
  99. break;
  100. case NUT_IRQCTL_STATUS:
  101. if (enabled) {
  102. *ival |= 1;
  103. }
  104. else {
  105. *ival &= ~1;
  106. }
  107. break;
  108. case NUT_IRQCTL_ENABLE:
  109. enabled = 1;
  110. break;
  111. case NUT_IRQCTL_DISABLE:
  112. enabled = 0;
  113. break;
  114. case NUT_IRQCTL_GETPRIO:
  115. *ival = NVIC_GetPriority(INT_UART);
  116. break;
  117. case NUT_IRQCTL_SETPRIO:
  118. NVIC_SetPriority(INT_UART, *ival);
  119. break;
  120. #ifdef NUT_PERFMON
  121. case NUT_IRQCTL_GETCOUNT:
  122. *ival = (unsigned int)sig_UART.ir_count;
  123. sig_UART.ir_count = 0;
  124. break;
  125. #endif
  126. default:
  127. rc = -1;
  128. break;
  129. }
  130. /* Enable interrupt. */
  131. if (enabled) {
  132. NVIC_EnableIRQ(INT_UART);
  133. }
  134. return rc;
  135. }