can.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**************************************************************************//**
  2. * @file can.h
  3. * @version V1.00
  4. * $Revision: 8 $
  5. * $Date: 14/09/26 3:38p $
  6. * @brief NUC472/NUC442 CAN driver header file
  7. *
  8. * @note
  9. * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved.
  10. *****************************************************************************/
  11. #ifndef __CAN_H__
  12. #define __CAN_H__
  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif
  17. /** @addtogroup NUC472_442_Device_Driver NUC472/NUC442 Device Driver
  18. @{
  19. */
  20. /** @addtogroup NUC472_442_CAN_Driver CAN Driver
  21. @{
  22. */
  23. /** @addtogroup NUC472_442_CAN_EXPORTED_TYPEDEF CAN Exported Type Defines
  24. @{
  25. */
  26. /**
  27. * @details Message ID types.
  28. */
  29. typedef enum {
  30. CAN_STD_ID = 0, /*!< Standard Identifier */
  31. CAN_EXT_ID = 1 /*!< Extended Identifier */
  32. } E_CAN_ID_TYPE;
  33. /**
  34. * @details Message Frame types.
  35. */
  36. typedef enum {
  37. REMOTE_FRAME = 0, /*!< Remote Frame */
  38. DATA_FRAME = 1 /*!< Data Frame */
  39. } E_CAN_FRAME_TYPE;
  40. /**
  41. * @details CAN message structure.
  42. */
  43. typedef struct {
  44. uint32_t IdType; /*!< Identifier Type */
  45. uint32_t FrameType; /*!< Frame Type */
  46. uint32_t Id; /*!< Message Identifier */
  47. uint8_t DLC; /*!< Data Length Code */
  48. uint8_t Data[8]; /*!< Data byte 0 ~ 7 */
  49. } STR_CANMSG_T;
  50. /**
  51. * @details CAN mask message structure.
  52. */
  53. typedef struct {
  54. uint8_t u8Xtd; /*!< Extended Identifier */
  55. uint8_t u8Dir; /*!< Message Direction */
  56. uint32_t u32Id; /*!< Message Identifier */
  57. uint8_t u8IdType; /*!< Identifier Type */
  58. } STR_CANMASK_T;
  59. /**
  60. * @details CAN operation mode: normal/basic mode.
  61. */
  62. typedef enum {
  63. CAN_NORMAL_MODE = 1, /*!< Normal Mode */
  64. CAN_BASIC_MODE = 2 /*!< Basic Mode */
  65. } CAN_MODE_SELECT;
  66. #define ALL_MSG 32 /*!< All Message ram number */
  67. #define MSG(id) id /*!< Message ram number */
  68. /*@}*/ /* end of group NUC472_442_CAN_EXPORTED_TYPEDEF */
  69. /** @addtogroup NUC472_442_CAN_EXPORTED_FUNCTIONS CAN Exported Functions
  70. @{
  71. */
  72. /**
  73. * @brief Get interrupt status
  74. *
  75. * @param[in] can The base address of can module
  76. *
  77. * @return CAN module status register value
  78. * \hideinitializer
  79. */
  80. #define CAN_GET_INT_STATUS(can) (can->STATUS)
  81. /**
  82. * @brief Get specified interrupt pending status
  83. *
  84. * @param[in] can The base address of can module
  85. *
  86. * @return The source of the interrupt.
  87. * \hideinitializer
  88. */
  89. #define CAN_GET_INT_PENDING_STATUS(can) (can->IIDR)
  90. /**
  91. * @brief Disable Wakeup function
  92. *
  93. * @param[in] can The base address of can module
  94. *
  95. * @return None
  96. * \hideinitializer
  97. */
  98. #define CAN_DISABLE_WAKEUP(can) (can->WU_IE = 0)
  99. /**
  100. * @brief Enable Wakeup function
  101. *
  102. * @param[in] can The base address of can module
  103. *
  104. * @return None
  105. * \hideinitializer
  106. */
  107. #define CAN_ENABLE_WAKEUP(can) (can->WU_IE = CAN_WUEN_WAKUP_EN_Msk)
  108. /**
  109. * @brief Get specified Message Object new data into bit value
  110. *
  111. * @param[in] can The base address of can module
  112. * @param[in] u32MsgNum Specified Message Object number. (0 ~ 31)
  113. *
  114. * @return Specified Message Object new data into bit value.
  115. * \hideinitializer
  116. */
  117. #define CAN_GET_NEW_DATA_IN_BIT(can, u32MsgNum) (u32MsgNum < 16 ? can->NDAT1 & (1 << u32MsgNum) : can->NDAT2 & (1 << (u32MsgNum-16)))
  118. /*---------------------------------------------------------------------------------------------------------*/
  119. /* Define CAN functions prototype */
  120. /*---------------------------------------------------------------------------------------------------------*/
  121. uint32_t CAN_SetBaudRate(CAN_T *tCAN, uint32_t u32BaudRate);
  122. uint32_t CAN_Open(CAN_T *tCAN, uint32_t u32BaudRate, uint32_t u32Mode);
  123. int32_t CAN_Transmit(CAN_T *tCAN, uint32_t u32MsgNum , STR_CANMSG_T* pCanMsg);
  124. int32_t CAN_Receive(CAN_T *tCAN, uint32_t u32MsgNum , STR_CANMSG_T* pCanMsg);
  125. void CAN_CLR_INT_PENDING_BIT(CAN_T *tCAN, uint8_t u32MsgNum);
  126. void CAN_EnableInt(CAN_T *tCAN, uint32_t u32Mask);
  127. void CAN_DisableInt(CAN_T *tCAN, uint32_t u32Mask);
  128. int32_t CAN_SetMultiRxMsg(CAN_T *tCAN, uint32_t u32MsgNum , uint32_t u32MsgCount, uint32_t u32IDType, uint32_t u32ID);
  129. int32_t CAN_SetRxMsg(CAN_T *tCAN, uint32_t u32MsgNum , uint32_t u32IDType, uint32_t u32ID);
  130. int32_t CAN_SetTxMsg(CAN_T *tCAN, uint32_t u32MsgNum , STR_CANMSG_T* pCanMsg);
  131. int32_t CAN_TriggerTxMsg(CAN_T *tCAN, uint32_t u32MsgNum);
  132. /*@}*/ /* end of group NUC472_442_CAN_EXPORTED_FUNCTIONS */
  133. /*@}*/ /* end of group NUC472_442_CAN_Driver */
  134. /*@}*/ /* end of group NUC472_442_Device_Driver */
  135. #ifdef __cplusplus
  136. }
  137. #endif
  138. #endif //__CAN_H__
  139. /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/