ih_at91wdi.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. /*
  34. * $Log$
  35. * Revision 1.4 2008/08/11 06:59:12 haraldkipp
  36. * BSD types replaced by stdint types (feature request #1282721).
  37. *
  38. * Revision 1.3 2006/07/05 07:56:34 haraldkipp
  39. * Interrupt handler will be included only, if the related interrupt
  40. * ID is defined in the platform specific header file.
  41. *
  42. * Revision 1.2 2006/06/28 17:10:35 haraldkipp
  43. * Include more general header file for ARM.
  44. *
  45. * Revision 1.1 2005/10/24 08:56:09 haraldkipp
  46. * First check in.
  47. *
  48. */
  49. #include <arch/arm.h>
  50. #include <dev/irqreg.h>
  51. #if defined(WDI_ID)
  52. #ifndef NUT_IRQPRI_WDI
  53. #define NUT_IRQPRI_WDI 4
  54. #endif
  55. static int WatchdogIrqCtl(int cmd, void *param);
  56. IRQ_HANDLER sig_WDI = {
  57. #ifdef NUT_PERFMON
  58. 0, /* Interrupt counter, ir_count. */
  59. #endif
  60. NULL, /* Passed argument, ir_arg. */
  61. NULL, /* Handler subroutine, ir_handler. */
  62. WatchdogIrqCtl /* Interrupt control, ir_ctl. */
  63. };
  64. /*!
  65. * \brief Watchdog interrupt entry.
  66. */
  67. void WatchdogIrqEntry(void) NUT_NAKED_FUNC;
  68. void WatchdogIrqEntry(void)
  69. {
  70. IRQ_ENTRY();
  71. #ifdef NUT_PERFMON
  72. sig_WDI.ir_count++;
  73. #endif
  74. if (sig_WDI.ir_handler) {
  75. (sig_WDI.ir_handler) (sig_WDI.ir_arg);
  76. }
  77. IRQ_EXIT();
  78. }
  79. /*!
  80. * \brief Watchdog interrupt control.
  81. *
  82. * \param cmd Control command.
  83. * - NUT_IRQCTL_INIT Initialize and disable interrupt.
  84. * - NUT_IRQCTL_STATUS Query interrupt status.
  85. * - NUT_IRQCTL_ENABLE Enable interrupt.
  86. * - NUT_IRQCTL_DISABLE Disable interrupt.
  87. * - NUT_IRQCTL_GETPRIO Query interrupt priority.
  88. * - NUT_IRQCTL_SETPRIO Set interrupt priority.
  89. * - NUT_IRQCTL_GETCOUNT Query and clear interrupt counter.
  90. * \param param Pointer to optional parameter.
  91. *
  92. * \return 0 on success, -1 otherwise.
  93. */
  94. static int WatchdogIrqCtl(int cmd, void *param)
  95. {
  96. int rc = 0;
  97. unsigned int *ival = (unsigned int *)param;
  98. int_fast8_t enabled = inr(AIC_IMR) & _BV(WDI_ID);
  99. /* Disable interrupt. */
  100. if (enabled) {
  101. outr(AIC_IDCR, _BV(WDI_ID));
  102. }
  103. switch(cmd) {
  104. case NUT_IRQCTL_INIT:
  105. /* Set the vector. */
  106. outr(AIC_SVR(WDI_ID), (unsigned int)WatchdogIrqEntry);
  107. /* Initialize to edge triggered with defined priority. */
  108. outr(AIC_SMR(WDI_ID), AIC_SRCTYPE_INT_EDGE_TRIGGERED | NUT_IRQPRI_WDI);
  109. /* Clear interrupt */
  110. outr(AIC_ICCR, _BV(WDI_ID));
  111. break;
  112. case NUT_IRQCTL_STATUS:
  113. if (enabled) {
  114. *ival |= 1;
  115. }
  116. else {
  117. *ival &= ~1;
  118. }
  119. break;
  120. case NUT_IRQCTL_ENABLE:
  121. enabled = 1;
  122. break;
  123. case NUT_IRQCTL_DISABLE:
  124. enabled = 0;
  125. break;
  126. case NUT_IRQCTL_GETPRIO:
  127. *ival = inr(AIC_SMR(WDI_ID)) & AIC_PRIOR;
  128. break;
  129. case NUT_IRQCTL_SETPRIO:
  130. outr(AIC_SMR(WDI_ID), (inr(AIC_SMR(WDI_ID)) & ~AIC_PRIOR) | *ival);
  131. break;
  132. #ifdef NUT_PERFMON
  133. case NUT_IRQCTL_GETCOUNT:
  134. *ival = (unsigned int)sig_WDI.ir_count;
  135. sig_WDI.ir_count = 0;
  136. break;
  137. #endif
  138. default:
  139. rc = -1;
  140. break;
  141. }
  142. /* Enable interrupt. */
  143. if (enabled) {
  144. outr(AIC_IECR, _BV(WDI_ID));
  145. }
  146. return rc;
  147. }
  148. #endif /* WDI_ID */