can_dev.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (C) 2004 by Ole Reinhardt <ole.reinhardt@kernelconcepts.de>,
  3. * Kernelconcepts http://www.kernelconcepts.de
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the copyright holders nor the names of
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  21. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  22. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  23. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  24. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  25. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  26. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  28. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * For additional information see http://www.ethernut.de/
  32. *
  33. */
  34. /*!
  35. * \file dev/can_dev.c
  36. * \brief Driver for CAN-Bus devices
  37. *
  38. *
  39. */
  40. /*
  41. * $Log$
  42. * Revision 1.7 2008/08/11 06:59:41 haraldkipp
  43. * BSD types replaced by stdint types (feature request #1282721).
  44. *
  45. * Revision 1.6 2007/09/08 03:01:11 hwmaier
  46. * Changes to support RX time-out, CAN_SetRxTimeout() added.
  47. *
  48. * Revision 1.5 2005/10/07 21:38:44 hwmaier
  49. * CAN_SetSpeed function added.
  50. *
  51. * Revision 1.4 2004/08/25 15:45:18 olereinhardt
  52. * Added function to set acceptance filter
  53. *
  54. * Revision 1.3 2004/08/02 09:56:13 olereinhardt
  55. * changed typing of CAN_TryRxFrame
  56. *
  57. * Revision 1.2 2004/06/23 10:17:04 olereinhardt
  58. * Added buffer monitoring functions (free / avail)
  59. *
  60. * Revision 1.1 2004/06/07 15:15:28 olereinhardt
  61. * Initial checkin
  62. *
  63. */
  64. /*!
  65. * \addtogroup xgCanDev
  66. */
  67. /*@{*/
  68. /* Not ported. */
  69. #ifdef __GNUC__
  70. #include <stdio.h>
  71. #include <sys/timer.h>
  72. #include <sys/device.h>
  73. #include <dev/can_dev.h>
  74. uint8_t CAN_SetSpeed(NUTDEVICE *dev, uint32_t baudrate)
  75. {
  76. return (((IFCAN *)(dev->dev_icb))->can_set_baud)(dev, baudrate);
  77. }
  78. void CAN_SetFilter(NUTDEVICE *dev, uint8_t *ac, uint8_t *am)
  79. {
  80. (((IFCAN *)(dev->dev_icb))->can_set_ac)(dev, ac);
  81. (((IFCAN *)(dev->dev_icb))->can_set_am)(dev, am);
  82. }
  83. void CAN_TxFrame(NUTDEVICE *dev, CANFRAME *frame)
  84. {
  85. (((IFCAN *)(dev->dev_icb))->can_send)(dev, frame);
  86. }
  87. uint8_t CAN_TryTxFrame(NUTDEVICE *dev, CANFRAME *frame)
  88. {
  89. if (((IFCAN *)(dev->dev_icb))->can_txfree(dev)) {
  90. (((IFCAN *)(dev->dev_icb))->can_send)(dev, frame);
  91. return 0;
  92. }
  93. return 1;
  94. }
  95. uint8_t CAN_TxFree(NUTDEVICE *dev)
  96. {
  97. return ((IFCAN *)(dev->dev_icb))->can_txfree(dev);
  98. }
  99. uint8_t CAN_RxFrame(NUTDEVICE *dev, CANFRAME *frame)
  100. {
  101. return (((IFCAN *)(dev->dev_icb))->can_recv)(dev, frame);
  102. }
  103. uint8_t CAN_TryRxFrame(NUTDEVICE *dev, CANFRAME *frame)
  104. {
  105. if (((IFCAN *)(dev->dev_icb))->can_rxavail(dev)) {
  106. (((IFCAN *)(dev->dev_icb))->can_recv)(dev, frame);
  107. return 0;
  108. }
  109. return 1;
  110. }
  111. uint8_t CAN_RxAvail(NUTDEVICE *dev)
  112. {
  113. return ((IFCAN *)(dev->dev_icb))->can_rxavail(dev);
  114. }
  115. /*!
  116. * Sets the CAN receive timeout
  117. *
  118. * \param dev Pointer to the device structure
  119. * \param timeout Timeout in milliseconds, NUT_WAIT_INFINITE = no time-out
  120. * \warning Timeout values are given in milliseconds and are limited to
  121. * the granularity of the system timer. To disable timeout,
  122. * set the parameter to NUT_WAIT_INFINITE.
  123. */
  124. void CAN_SetRxTimeout(NUTDEVICE *dev, uint32_t timeout)
  125. {
  126. ((IFCAN *)(dev->dev_icb))->can_rtimeout = timeout;
  127. }
  128. #else
  129. void keep_icc_happy(void)
  130. {
  131. }
  132. #endif
  133. /*@}*/