ih_canit.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. * \file arch/avr/dev/ih_canit.c
  35. * \brief CAN serial transfer interrupt.
  36. *
  37. * \verbatim
  38. * $Id: ih_canit.c 4706 2012-10-06 17:42:01Z haraldkipp $
  39. * \endverbatim
  40. */
  41. #include <dev/irqreg.h>
  42. /*!
  43. * \addtogroup xgIrqReg
  44. */
  45. /*@{*/
  46. #if defined(CANIT_vect) || defined(iv_CAN_TRANSFER)
  47. static int AvrCanTxIrqCtl(int cmd, void *param);
  48. IRQ_HANDLER sig_CAN_TRANSFER = {
  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. AvrCanTxIrqCtl /* Interrupt control, ir_ctl. */
  55. };
  56. /*!
  57. * \brief CAN serial transfer interrupt control.
  58. *
  59. * \param cmd Control command.
  60. * \param param Pointer to optional parameter.
  61. *
  62. * \return 0 on success, -1 otherwise.
  63. */
  64. static int AvrCanTxIrqCtl(int cmd, void *param)
  65. {
  66. int rc = 0;
  67. unsigned int *ival = (unsigned int *) param;
  68. int_fast8_t enabled = bit_is_set(CANGIE, ENIT);
  69. /* Disable interrupt. */
  70. cbi(CANGIE, ENIT);
  71. switch (cmd) {
  72. case NUT_IRQCTL_INIT:
  73. case NUT_IRQCTL_DISABLE:
  74. enabled = 0;
  75. break;
  76. case NUT_IRQCTL_ENABLE:
  77. enabled = 1;
  78. break;
  79. case NUT_IRQCTL_GETPRIO:
  80. *ival = 0;
  81. break;
  82. #ifdef NUT_PERFMON
  83. case NUT_IRQCTL_GETCOUNT:
  84. *ival = (unsigned int) sig_CAN_TRANSFER.ir_count;
  85. sig_CAN_TRANSFER.ir_count = 0;
  86. break;
  87. #endif
  88. default:
  89. rc = -1;
  90. break;
  91. }
  92. /* Enable interrupt. */
  93. if (enabled) {
  94. sbi(CANGIE, ENIT);
  95. }
  96. return rc;
  97. }
  98. /*! \fn CANIT_vect(void)
  99. * \brief CAN serial transfer interrupt entry.
  100. */
  101. #ifdef __IMAGECRAFT__
  102. #pragma interrupt_handler CANIT_vect:iv_CAN_TRANSFER
  103. #endif
  104. NUTSIGNAL(CANIT_vect, sig_CAN_TRANSFER)
  105. #endif
  106. /*@}*/