ih_udphs_sam3u.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright (C) 2005 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. #include <arch/cm3.h>
  34. #include <dev/irqreg.h>
  35. #ifndef NUT_IRQPRI_UDPHS
  36. #define NUT_IRQPRI_UDPHS 0
  37. #endif
  38. static int UsbHighSpeedIrqCtl(int cmd, void *param);
  39. IRQ_HANDLER sig_UDPHS = {
  40. #ifdef NUT_PERFMON
  41. 0, /* Interrupt counter, ir_count. */
  42. #endif
  43. NULL, /* Passed argument, ir_arg. */
  44. NULL, /* Handler subroutine, ir_handler. */
  45. UsbHighSpeedIrqCtl /* Interrupt control, ir_ctl. */
  46. };
  47. /*!
  48. * \brief Timer/Counter 0 interrupt entry.
  49. */
  50. static void UsbHighSpeedIrqEntry(void); //__attribute__ ((naked));
  51. void UsbHighSpeedIrqEntry(void)
  52. {
  53. // IRQ_ENTRY();
  54. #ifdef NUT_PERFMON
  55. sig_UDPHS.ir_count++;
  56. #endif
  57. if (sig_UDPHS.ir_handler) {
  58. (sig_UDPHS.ir_handler) (sig_UDPHS.ir_arg);
  59. }
  60. // IRQ_EXIT();
  61. }
  62. /*!
  63. * \brief Timer/Counter 0 interrupt control.
  64. *
  65. * \param cmd Control command.
  66. * - NUT_IRQCTL_INIT Initialize and disable interrupt.
  67. * - NUT_IRQCTL_STATUS Query interrupt status.
  68. * - NUT_IRQCTL_ENABLE Enable interrupt.
  69. * - NUT_IRQCTL_DISABLE Disable interrupt.
  70. * - NUT_IRQCTL_GETMODE Query interrupt mode.
  71. * - NUT_IRQCTL_SETMODE Set interrupt mode (NUT_IRQMODE_LEVEL or NUT_IRQMODE_EDGE).
  72. * - NUT_IRQCTL_GETPRIO Query interrupt priority.
  73. * - NUT_IRQCTL_SETPRIO Set interrupt priority.
  74. * - NUT_IRQCTL_GETCOUNT Query and clear interrupt counter.
  75. * \param param Pointer to optional parameter.
  76. *
  77. * \return 0 on success, -1 otherwise.
  78. */
  79. static int UsbHighSpeedIrqCtl(int cmd, void *param)
  80. {
  81. int rc = 0;
  82. unsigned int *ival = (unsigned int *)param;
  83. int_fast8_t enabled = inr(AT91C_NVIC_ABR) & _BV(AT91C_ID_UDPHS);
  84. /* Disable interrupt. */
  85. if (enabled) {
  86. NVIC_DisableIRQ(INT_UDPHS);
  87. }
  88. switch(cmd) {
  89. case NUT_IRQCTL_INIT:
  90. /* Set the vector. */
  91. Cortex_RegisterInt(INT_UDPHS,(void*)UsbHighSpeedIrqEntry);
  92. /* Initialize with defined priority. */
  93. NVIC_SetPriority(INT_UDPHS,NUT_IRQPRI_UDPHS);
  94. /* set as edge triggered */ //É ËÁË? ÏÎÏ ÄÅÌÁÅÔÓÑ ÐÏÐÉÎÏ×Ï
  95. //outr(AT91C_PIOA_ESR,_BV(AT91C_ID_PIOA);
  96. /* Clear interrupt */
  97. outr(AT91C_NVIC_ICPR,_BV(AT91C_ID_UDPHS));
  98. break;
  99. case NUT_IRQCTL_STATUS:
  100. if (enabled) {
  101. *ival |= 1;
  102. }
  103. else {
  104. *ival &= ~1;
  105. }
  106. break;
  107. case NUT_IRQCTL_ENABLE:
  108. enabled = 1;
  109. break;
  110. case NUT_IRQCTL_DISABLE:
  111. enabled = 0;
  112. break;
  113. /* case NUT_IRQCTL_GETMODE:
  114. {
  115. unsigned int val = inr(AIC_SMR(TC0_ID)) & AIC_SRCTYPE;
  116. if (val == AIC_SRCTYPE_INT_LEVEL_SENSITIVE || val == AIC_SRCTYPE_EXT_HIGH_LEVEL) {
  117. *ival = NUT_IRQMODE_LEVEL;
  118. } else {
  119. *ival = NUT_IRQMODE_EDGE;
  120. }
  121. }
  122. break;
  123. case NUT_IRQCTL_SETMODE:
  124. if (*ival == NUT_IRQMODE_LEVEL) {
  125. outr(AIC_SMR(TC0_ID), (inr(AIC_SMR(TC0_ID)) & ~AIC_SRCTYPE) | AIC_SRCTYPE_INT_LEVEL_SENSITIVE);
  126. } else if (*ival == NUT_IRQMODE_EDGE) {
  127. outr(AIC_SMR(TC0_ID), (inr(AIC_SMR(TC0_ID)) & ~AIC_SRCTYPE) | AIC_SRCTYPE_INT_EDGE_TRIGGERED);
  128. } else {
  129. rc = -1;
  130. }
  131. break;*/
  132. case NUT_IRQCTL_GETPRIO:
  133. *ival = NVIC_GetPriority(INT_UDPHS);
  134. break;
  135. case NUT_IRQCTL_SETPRIO:
  136. NVIC_SetPriority(INT_UDPHS, *ival);
  137. break;
  138. #ifdef NUT_PERFMON
  139. case NUT_IRQCTL_GETCOUNT:
  140. *ival = (unsigned int)sig_UDPHS.ir_count;
  141. sig_UDPHS.ir_count = 0;
  142. break;
  143. #endif
  144. default:
  145. rc = -1;
  146. break;
  147. }
  148. /* Enable interrupt. */
  149. if (enabled) {
  150. NVIC_EnableIRQ(INT_UDPHS);
  151. }
  152. return rc;
  153. }