can_dev.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #ifndef _CAN_DEV_H_
  2. #define _CAN_DEV_H_
  3. /*
  4. * Copyright (C) 2004 by Ole Reinhardt<ole.reinhardt@kernelconcepts.de>
  5. * Kernel concepts (http://www.kernelconcepts.de) All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the name of the copyright holders nor the names of
  17. * contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  21. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  24. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  27. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  28. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  30. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. *
  33. * For additional information see http://www.ethernut.de/
  34. *
  35. */
  36. /*!
  37. * \file dev/can_dev.h
  38. * \brief Headers for can driver interface
  39. */
  40. /*
  41. * $Log: can_dev.h,v $
  42. * Revision 1.5 2005/10/07 21:44:22 hwmaier
  43. * CAN_SetSpeed function added. Baudrates moved here.
  44. *
  45. * Revision 1.4 2004/08/25 15:48:21 olereinhardt
  46. * Added function to set an acceptance filter
  47. *
  48. * Revision 1.3 2004/08/02 09:59:53 olereinhardt
  49. * changed typing of CAN_TryRxFrame
  50. *
  51. * Revision 1.2 2004/06/23 10:15:35 olereinhardt
  52. * Added function for buffer monitoring (avail / free)
  53. *
  54. * Revision 1.1 2004/06/07 15:13:48 olereinhardt
  55. * Initial checkin
  56. *
  57. */
  58. #include <sys/types.h>
  59. #include <sys/device.h>
  60. /*!
  61. * \addtogroup xgCanDev
  62. */
  63. /*@{*/
  64. #define CAN_IF_2A 0x01
  65. #define CAN_IF_2B 0x02
  66. /*
  67. * CAN Baud rate constants
  68. */
  69. #define CAN_SPEED_10K 0 ///< 10 kbit/s, max. cable length 5000 m
  70. #define CAN_SPEED_20K 1 ///< 20 kbit/s, max. cable length 2500 m
  71. #define CAN_SPEED_50K 2 ///< 50 kbit/s, max. cable length 1000 m
  72. #define CAN_SPEED_100K 3 ///< 100 kbit/s, max. cable length 600 m
  73. #define CAN_SPEED_125K 4 ///< 125 kbit/s, max. cable length 500 m
  74. #define CAN_SPEED_250K 5 ///< 250 kbit/s, max. cable length 250 m
  75. #define CAN_SPEED_500K 6 ///< 500 kbit/s, max. cable length 100 m
  76. #define CAN_SPEED_800K 7 ///< 800 kbit/s, max. cable length 50 m
  77. #define CAN_SPEED_1M 8 ///< 1 Mbit/s, max. cable length 25 m
  78. #define CAN_SPEED_CUSTOM 255
  79. /*!
  80. * \struct _CANFRAME can_dev.h
  81. * \brief CAN frame structure
  82. */
  83. struct _CANFRAME { // todo: Implement flags
  84. u_long id; // Identifier
  85. u_char len; // Length of frame, max = 8
  86. u_char byte[8];
  87. u_char ext; // Boolean, extendet frame
  88. u_char rtr; // Boolean, remote transmition bit
  89. };
  90. /*!
  91. * \brief CAN frame type
  92. */
  93. typedef struct _CANFRAME CANFRAME;
  94. /*!
  95. * \struct _CANINFO can_dev.h
  96. * \brief CAN controller information structure.
  97. */
  98. struct _CANINFO {
  99. HANDLE volatile can_rx_rdy; /*!< Receiver event queue. */
  100. HANDLE volatile can_tx_rdy; /*!< Transmitter event queue. */
  101. u_long can_rx_frames; /*!< Number of packets received. */
  102. u_long can_tx_frames; /*!< Number of packets sent. */
  103. u_long can_interrupts; /*!< Number of interrupts. */
  104. u_long can_overruns; /*!< Number of packet overruns. */
  105. u_long can_errors; /*!< Number of frame errors. */
  106. };
  107. /*!
  108. * \brief CAN controller information type.
  109. */
  110. typedef struct _CANINFO CANINFO;
  111. /*!
  112. * \struct ifcan can_dev.h can/can_dev.h
  113. * \brief CAN interface structure.
  114. *
  115. * Contains information about the CAN interface.
  116. */
  117. struct ifcan {
  118. u_char can_type; /*!< \brief Interface type. Either CAN_IF_2A or CAN_IF_2B. */
  119. u_long can_baudrate; /*!< \brief Baudrate of device */
  120. u_char can_acc_mask[4]; /*!< \brief Acceptance mask */
  121. u_char can_acc_code[4]; /*!< \brief Acceptance code */
  122. u_char (*can_rxavail) (NUTDEVICE *); /*!< \brief Receive buffer data available? */
  123. u_char (*can_txfree) (NUTDEVICE *); /*!< \brief Transmit buffer free? */
  124. void (*can_recv) (NUTDEVICE *, CANFRAME *); /*!< \brief Receive routine. */
  125. void (*can_send) (NUTDEVICE *, CANFRAME *); /*!< \brief Send routine. */
  126. void (*can_set_ac) (NUTDEVICE *, u_char*); /*!< \brief Set accaptance code */
  127. void (*can_set_am) (NUTDEVICE *, u_char*); /*!< \brief Set accaptance mask */
  128. u_char (*can_set_baud) (NUTDEVICE *, u_long); /*!< \brief Set speed */
  129. };
  130. /*!
  131. * \brief Canbus interface type.
  132. */
  133. typedef struct ifcan IFCAN;
  134. u_char CAN_SetSpeed(NUTDEVICE *dev, u_long baudrate);
  135. void CAN_SetFilter(NUTDEVICE *dev, u_char *ac, u_char *am);
  136. void CAN_TxFrame(NUTDEVICE *dev, CANFRAME *frame);
  137. u_char CAN_TryTxFrame(NUTDEVICE *dev, CANFRAME *frame);
  138. u_char CAN_TxFree(NUTDEVICE *dev);
  139. void CAN_RxFrame(NUTDEVICE *dev, CANFRAME *frame);
  140. u_char CAN_TryRxFrame(NUTDEVICE *dev, CANFRAME *frame);
  141. u_char CAN_RxAvail(NUTDEVICE *dev);
  142. /*@}*/
  143. #endif