stm8s_can.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /**
  2. ******************************************************************************
  3. * @file stm8s_can.h
  4. * @author MCD Application Team
  5. * @version V2.2.0
  6. * @date 30-September-2014
  7. * @brief This file contains all the functions for the CAN peripheral.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  12. *
  13. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14. * You may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at:
  16. *
  17. * http://www.st.com/software_license_agreement_liberty_v2
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *
  25. ******************************************************************************
  26. */
  27. /* Define to prevent recursive inclusion -------------------------------------*/
  28. #ifndef __STM8S_CAN_H
  29. #define __STM8S_CAN_H
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "stm8s.h"
  32. /* Exported constants --------------------------------------------------------*/
  33. #define CAN_STDID_SIZE ((uint16_t)0x07FF)
  34. #define CAN_EXTID_SIZE ((uint32_t)0x1FFFFFFF)
  35. #define CAN_DLC_MAX ((uint8_t)0x08)
  36. /** @addtogroup CAN_Exported_Types
  37. * @{
  38. */
  39. /**
  40. * @brief CAN Page Mapping
  41. */
  42. typedef enum
  43. {
  44. CAN_Page_TxMailBox0 = ((uint8_t) 0), /*!< CAN TX mailbox 0 reg page */
  45. CAN_Page_TxMailBox1 = ((uint8_t) 1), /*!< CAN TX mailbox 1 reg page */
  46. CAN_Page_TxMailBox2 = ((uint8_t) 5), /*!< CAN TX mailbox 2 reg page */
  47. CAN_Page_Filter01 = ((uint8_t) 2), /*!< CAN Filters 0 & 1 reg page*/
  48. CAN_Page_Filter23 = ((uint8_t) 3), /*!< CAN Filters 2 & 3 reg page*/
  49. CAN_Page_Filter45 = ((uint8_t) 4), /*!< CAN Filters 4 & 5 reg page*/
  50. CAN_Page_Config = ((uint8_t) 6), /*!< CAN Configuration control/status reg page*/
  51. CAN_Page_RxFifo = ((uint8_t) 7) /*!< CAN RX FIFO registers page */
  52. }CAN_Page_TypeDef;
  53. /**
  54. * @brief CAN sleep constants
  55. */
  56. typedef enum {
  57. CAN_InitStatus_Failed =0, /*!< CAN initialization failed */
  58. CAN_InitStatus_Success =! CAN_InitStatus_Failed /*!< CAN initialization OK*/
  59. } CAN_InitStatus_TypeDef;
  60. /**
  61. * @brief CAN operating mode */
  62. typedef enum
  63. {
  64. CAN_OperatingMode_Initialization =((uint8_t)0x00), /*!< Initialization mode */
  65. CAN_OperatingMode_Normal =((uint8_t)0x01), /*!< Normal mode */
  66. CAN_OperatingMode_Sleep =((uint8_t)0x02) /*!< sleep mode */
  67. }CAN_OperatingMode_TypeDef;
  68. /**
  69. * @brief CAN operating mode status */
  70. typedef enum
  71. {
  72. CAN_ModeStatus_Failed = ((uint8_t)0x00), /*!< CAN entering the specific mode failed */
  73. CAN_ModeStatus_Success =! CAN_ModeStatus_Failed /*!< CAN entering the specific mode Succeed */
  74. }CAN_ModeStatus_TypeDef;
  75. /**
  76. * @brief CAN Time Triggered Communication mode
  77. */
  78. typedef enum
  79. {
  80. CAN_MasterCtrl_AllDisabled =((uint8_t)0x00), /*!< CAN ALL Master Control Option are DISABLED */
  81. CAN_MasterCtrl_AllEnabled =((uint8_t)0xFC), /*!< CAN ALL Master Control Option are DISABLED */
  82. CAN_MasterCtrl_TimeTriggerCOMMode =((uint8_t)0x80), /*!< CAN Time Triggered Communication mode ENABLED */
  83. CAN_MasterCtrl_AutoBusOffManagement =((uint8_t)0x40), /*!< CAN Auto Bus Off Management ENABLED */
  84. CAN_MasterCtrl_AutoWakeUpMode =((uint8_t)0x20), /*!< CAN Automatic WakeUp Mode ENABLED , sleep mode is left automatically by hardware */
  85. CAN_MasterCtrl_NoAutoReTx =((uint8_t)0x10), /*!< CAN Non Automatic Retransmission ENABLED, MSG will be transmitted only once */
  86. CAN_MasterCtrl_RxFifoLockedMode =((uint8_t)0x08), /*!< CAN Receive FIFO Locked against overrun ENABLED */
  87. CAN_MasterCtrl_TxFifoPriority =((uint8_t)0x04) /*!< CAN Transmit FIFO Priority driven by the request order (not by the identifier of the MSG) */
  88. }CAN_MasterCtrl_TypeDef;
  89. /**
  90. * @brief CAN mode options */
  91. typedef enum
  92. {
  93. CAN_Mode_Normal =((uint8_t)0x00), /*!< normal mode */
  94. CAN_Mode_LoopBack =((uint8_t)0x01), /*!< loopback mode */
  95. CAN_Mode_Silent =((uint8_t)0x02), /*!< silent mode */
  96. CAN_Mode_Silent_LoopBack =((uint8_t)0x03) /*!< loopback combined with silent mode */
  97. }CAN_Mode_TypeDef;
  98. /**
  99. * @brief CAN synchronisation jump width (SJW)*/
  100. typedef enum
  101. {
  102. CAN_SynJumpWidth_1TimeQuantum =((uint8_t)0x00), /*!< 1 time quantum */
  103. CAN_SynJumpWidth_2TimeQuantum =((uint8_t)0x40), /*!< 2 time quantum */
  104. CAN_SynJumpWidth_3TimeQuantum =((uint8_t)0x80), /*!< 3 time quantum */
  105. CAN_SynJumpWidth_4TimeQuantum =((uint8_t)0xC0) /*!< 4 time quantum */
  106. }CAN_SynJumpWidth_TypeDef;
  107. /**
  108. * @brief time quantum in bit segment 1 */
  109. typedef enum
  110. {
  111. CAN_BitSeg1_1TimeQuantum =((uint8_t)0x00), /*!< 1 time quantum */
  112. CAN_BitSeg1_2TimeQuantum =((uint8_t)0x01), /*!< 2 time quantum */
  113. CAN_BitSeg1_3TimeQuantum =((uint8_t)0x02), /*!< 3 time quantum */
  114. CAN_BitSeg1_4TimeQuantum =((uint8_t)0x03) , /*!< 4 time quantum */
  115. CAN_BitSeg1_5TimeQuantum =((uint8_t)0x04) , /*!< 5 time quantum */
  116. CAN_BitSeg1_6TimeQuantum =((uint8_t)0x05) , /*!< 6 time quantum */
  117. CAN_BitSeg1_7TimeQuantum =((uint8_t)0x06) , /*!< 7 time quantum */
  118. CAN_BitSeg1_8TimeQuantum =((uint8_t)0x07), /*!< 8 time quantum */
  119. CAN_BitSeg1_9TimeQuantum =((uint8_t)0x08), /*!< 9 time quantum */
  120. CAN_BitSeg1_10TimeQuantum =((uint8_t)0x09), /*!< 10 time quantum */
  121. CAN_BitSeg1_11TimeQuantum =((uint8_t)0x0A), /*!< 11 time quantum */
  122. CAN_BitSeg1_12TimeQuantum =((uint8_t)0x0B), /*!< 12 time quantum */
  123. CAN_BitSeg1_13TimeQuantum =((uint8_t)0x0C), /*!< 13 time quantum */
  124. CAN_BitSeg1_14TimeQuantum =((uint8_t)0x0D), /*!< 14 time quantum */
  125. CAN_BitSeg1_15TimeQuantum =((uint8_t)0x0E), /*!< 15 time quantum */
  126. CAN_BitSeg1_16TimeQuantum =((uint8_t)0x0F) /*!< 16 time quantum */
  127. }CAN_BitSeg1_TypeDef;
  128. /**
  129. * @brief time quantum in bit segment 2 */
  130. typedef enum
  131. {
  132. CAN_BitSeg2_1TimeQuantum = ((uint8_t)0x00), /*!< 1 time quantum */
  133. CAN_BitSeg2_2TimeQuantum = ((uint8_t)0x10), /*!< 2 time quantum */
  134. CAN_BitSeg2_3TimeQuantum = ((uint8_t)0x20), /*!< 3 time quantum */
  135. CAN_BitSeg2_4TimeQuantum = ((uint8_t)0x30), /*!< 4 time quantum */
  136. CAN_BitSeg2_5TimeQuantum = ((uint8_t)0x40), /*!< 5 time quantum */
  137. CAN_BitSeg2_6TimeQuantum = ((uint8_t)0x50), /*!< 6 time quantum */
  138. CAN_BitSeg2_7TimeQuantum = ((uint8_t)0x60), /*!< 7 time quantum */
  139. CAN_BitSeg2_8TimeQuantum = ((uint8_t)0x70) /*!< 8 time quantum */
  140. }CAN_BitSeg2_TypeDef;
  141. /**
  142. * @brief CAN filter number */
  143. typedef enum
  144. {
  145. CAN_FilterNumber_0 = ((uint8_t)0x00), /*!< Filter number 0 */
  146. CAN_FilterNumber_1 = ((uint8_t)0x01), /*!< Filter number 1 */
  147. CAN_FilterNumber_2 = ((uint8_t)0x02), /*!< Filter number 2 */
  148. CAN_FilterNumber_3 = ((uint8_t)0x03), /*!< Filter number 3 */
  149. CAN_FilterNumber_4 = ((uint8_t)0x04), /*!< Filter number 4 */
  150. CAN_FilterNumber_5 = ((uint8_t)0x05) /*!< Filter number 5 */
  151. }CAN_FilterNumber_TypeDef;
  152. /**
  153. * @brief CAN filter mode */
  154. typedef enum
  155. {
  156. CAN_FilterMode_IdMask = ((uint8_t)0x00), /*!< id/mask mode */
  157. CAN_FilterMode_IdMask_IdList = ((uint8_t)0x10), /*!< Id/Mask mode First and IdList mode second */
  158. CAN_FilterMode_IdList_IdMask = ((uint8_t)0x11), /*!< IdList mode First and IdMask mode second */
  159. CAN_FilterMode_IdList = ((uint8_t)0x01) /*!< identifier list mode */
  160. }CAN_FilterMode_TypeDef;
  161. /**
  162. * @brief CAN filter scale */
  163. typedef enum
  164. {
  165. CAN_FilterScale_8Bit =((uint8_t)0x00), /*!< 8-bit filter scale */
  166. CAN_FilterScale_16_8Bit =((uint8_t)0x02), /*!< 16/8-bit filter scale */
  167. CAN_FilterScale_16Bit =((uint8_t)0x04), /*!< 16-bit filter scale */
  168. CAN_FilterScale_32Bit =((uint8_t)0x06) /*!< 32-bit filter scale */
  169. }CAN_FilterScale_TypeDef;
  170. /**
  171. * @brief CAN Tx mailboxes*/
  172. typedef enum
  173. {
  174. CAN_TransmitMailBox_0 = ((uint8_t) 0x00), /*!< CAN TX mailbox 0 reg page */
  175. CAN_TransmitMailBox_1 = ((uint8_t) 0x01), /*!< CAN TX mailbox 1 reg page */
  176. CAN_TransmitMailBox_2 = ((uint8_t) 0x05) /*!< CAN TX mailbox 2 reg page */
  177. }CAN_TransmitMailBox_TypeDef;
  178. /**
  179. * @brief CAN Pending Messages number*/
  180. typedef enum
  181. {
  182. CAN_NbrPendingMessage_0 = ((uint8_t)0x00), /*!< No Msg Pending */
  183. CAN_NbrPendingMessage_1 = ((uint8_t)0x01), /*!< 1 Msg Pending */
  184. CAN_NbrPendingMessage_2 = ((uint8_t)0x02), /*!< 2 Msg Pending */
  185. CAN_NbrPendingMessage_3 = ((uint8_t)0x03) /*!< 3 Msg Pending */
  186. }CAN_NbrPendingMessage_TypeDef;
  187. /**
  188. * @brief CAN identifier type */
  189. typedef enum
  190. {
  191. CAN_Id_Standard =((uint8_t)0x00), /*!< Standard Id */
  192. CAN_Id_Extended =((uint8_t)0x40) /*!< Extended Id */
  193. }CAN_Id_TypeDef;
  194. /**
  195. * @brief CAN remote transmission request */
  196. typedef enum
  197. {
  198. CAN_RTR_Data = ((uint8_t)0x00), /*!< Data frame */
  199. CAN_RTR_Remote = ((uint8_t)0x20) /*!< Remote frame */
  200. }CAN_RTR_TypeDef;
  201. /**
  202. * @brief CAN transmit Status */
  203. typedef enum
  204. {
  205. CAN_TxStatus_Failed =((uint8_t)0xF0), /*!< CAN transmission failed */
  206. CAN_TxStatus_Ok =((uint8_t)0xF1), /*!< CAN transmission succeeded */
  207. CAN_TxStatus_Pending =((uint8_t)0xF2), /*!< CAN transmission pending */
  208. CAN_TxStatus_NoMailBox =((uint8_t)0xF4), /*!< CAN cell did not provide an empty mailbox */
  209. CAN_TxStatus_MailBoxEmpty =((uint8_t)0xF5), /*!< CAN Tx mailbox is Empty */
  210. CAN_TxStatus_MailBox0Ok =((uint8_t)0x00), /*!< CAN transmission succeeded by mail box 1*/
  211. CAN_TxStatus_MailBox1Ok =((uint8_t)0x01), /*!< CAN transmission succeeded by mail box 2*/
  212. CAN_TxStatus_MailBox2Ok =((uint8_t)0x05) /*!< CAN transmission succeeded by mail box 3*/
  213. }CAN_TxStatus_TypeDef;
  214. /**
  215. * @brief CAN sleep Status */
  216. typedef enum
  217. {
  218. CAN_Sleep_Failed = ((uint8_t)0x00), /*!< CAN did not enter the sleep mode */
  219. CAN_Sleep_Ok = ((uint8_t)0x01) /*!< CAN entered the sleep mode */
  220. }CAN_Sleep_TypeDef;
  221. /**
  222. * @brief CAN wake up status */
  223. typedef enum
  224. {
  225. CAN_WakeUp_Failed = ((uint8_t)0x00), /*!< CAN did not leave the sleep mode */
  226. CAN_WakeUp_Ok = ((uint8_t)0x01) /*!< CAN leaved the sleep mode */
  227. }CAN_WakeUp_TypeDef;
  228. /**
  229. * @brief CAN flags */
  230. typedef enum
  231. {
  232. /* if the flag is 0x3XXX, it means that it can be got (CAN_GetFlagStatus) and Cleared (CAN_ClearFlag) */
  233. /* if the flag is 0x1XXX, it means that it can only be got (CAN_GetFlagStatus) */
  234. /*Transmit Flags*/
  235. CAN_FLAG_RQCP0 =((uint16_t)0x3401), /*!< Request MailBox0 Flag */
  236. CAN_FLAG_RQCP1 =((uint16_t)0x3402), /*!< Request MailBox1 Flag */
  237. CAN_FLAG_RQCP2 =((uint16_t)0x3404), /*!< Request MailBox2 Flag */
  238. /*Receive Flags*/
  239. CAN_FLAG_FMP =((uint16_t)0x1203), /*!< FIFO Message Pending Flag */
  240. CAN_FLAG_FF =((uint16_t)0x3208), /*!< FIFO Full Flag */
  241. CAN_FLAG_FOV =((uint16_t)0x3210), /*!< FIFO Overrun Flag */
  242. /*Wake up Flag*/
  243. CAN_FLAG_WKU =((uint16_t)0x3108), /*!< wake up Flag */
  244. /*Error Flags*/
  245. CAN_FLAG_EWG =((uint16_t)0x1001), /*!< Error Warning Flag */
  246. CAN_FLAG_EPV =((uint16_t)0x1002), /*!< Error Passive Flag */
  247. CAN_FLAG_BOF =((uint16_t)0x1004), /*!< Bus-Off Flag */
  248. CAN_FLAG_LEC =((uint16_t)0x3070) /*!< Last error code Flag */
  249. }CAN_FLAG_TypeDef;
  250. /**
  251. * @brief CAN interrupts */
  252. typedef enum
  253. {
  254. /*Transmit Interruption*/
  255. CAN_IT_TME =((uint16_t)0x0001), /*!< Transmit mailbox empty interrupt */
  256. /*Receive Interruptions*/
  257. CAN_IT_FMP =((uint16_t)0x0002), /*!< FIFO message pending interrupt */
  258. CAN_IT_FF =((uint16_t)0x0004), /*!< FIFO full interrupt */
  259. CAN_IT_FOV =((uint16_t)0x0008), /*!< FIFO overrun interrupt */
  260. /*Wake Up Interruption*/
  261. CAN_IT_WKU =((uint16_t)0x0080), /*!< Wake-up interrupt */
  262. /*Error Interruptions*/
  263. CAN_IT_ERR =((uint16_t)0x4000), /*!< Genaral Error interrupt */
  264. CAN_IT_EWG =((uint16_t)0x0100), /*!< Error warning interrupt */
  265. CAN_IT_EPV =((uint16_t)0x0200), /*!< Error passive interrupt */
  266. CAN_IT_BOF =((uint16_t)0x0400), /*!< Bus-off interrupt */
  267. CAN_IT_LEC =((uint16_t)0x0800) /*!< Last error code interrupt */
  268. } CAN_IT_TypeDef;
  269. /**
  270. * @brief CAN ST7 Compatibility*/
  271. typedef enum
  272. {
  273. CAN_ST7Compatibility_Enable = ((uint8_t)0x00), /*!< CAN is compatible with ST7 beCAN (only 2 mailboxes are available)*/
  274. CAN_ST7Compatibility_Disable = ((uint8_t)0x10) /*!< CAN is not compatible with ST7 beCAN ( 3 mailboxes are available)*/
  275. }CAN_ST7Compatibility_TypeDef;
  276. /**
  277. * @brief CAN Error Code description */
  278. typedef enum
  279. {
  280. CAN_ErrorCode_NoErr = ((uint8_t)0x00), /*!< No Error */
  281. CAN_ErrorCode_StuffErr = ((uint8_t)0x10), /*!< Stuff Error */
  282. CAN_ErrorCode_FormErr = ((uint8_t)0x20), /*!< Form Error */
  283. CAN_ErrorCode_ACKErr = ((uint8_t)0x30), /*!< Acknowledgment Error */
  284. CAN_ErrorCode_BitRecessiveErr = ((uint8_t)0x40), /*!< Bit Recessive Error */
  285. CAN_ErrorCode_BitDominantErr = ((uint8_t)0x50), /*!< Bit Dominant Error */
  286. CAN_ErrorCode_CRCErr = ((uint8_t)0x60), /*!< CRC Error */
  287. CAN_ErrorCode_SoftwareSetErr = ((uint8_t)0x70) /*!< Software Set Error */
  288. }CAN_ErrorCode_TypeDef;
  289. /**
  290. * @}
  291. */
  292. /* Private macros ------------------------------------------------------------*/
  293. /** @addtogroup CAN_Private_Macros
  294. * @{
  295. */
  296. /**
  297. * @brief Macro used by the assert function in order to check the CAN ST7 Compatibility parameters.
  298. */
  299. #define IS_CAN_ST7_COMPATIBILITY_OK(STATE) (((STATE) == CAN_ST7Compatibility_Enable) || ((STATE) == CAN_ST7Compatibility_Disable))
  300. /**
  301. * @brief Macro used by the assert function in order to check CAN operating mode.
  302. */
  303. #define IS_CAN_OPERATINGMODE_OK(MODE) (((MODE) == CAN_OperatingMode_Initialization) ||\
  304. ((MODE) == CAN_OperatingMode_Normal)|| \
  305. ((MODE) == CAN_OperatingMode_Sleep))
  306. /**
  307. * @brief Macro used by the assert function in order to check CAN Time Triggered Communication mode.
  308. */
  309. #define IS_CAN_MASTERCTRL_OK(MODE) (((MODE) == CAN_MasterCtrl_AllDisabled) || \
  310. (((MODE) <= CAN_MasterCtrl_AllEnabled) && ((MODE) >= CAN_MasterCtrl_TxFifoPriority)))
  311. /**
  312. * @brief Macro used by the assert function in order to check CAN mode options .
  313. */
  314. #define IS_CAN_MODE_OK(MODE) (((MODE) == CAN_Mode_Normal) || ((MODE) == CAN_Mode_LoopBack)|| \
  315. ((MODE) == CAN_Mode_Silent) || ((MODE) == CAN_Mode_Silent_LoopBack))
  316. /**
  317. * @brief Macro used by the assert function in order to check the CAN synchronisation jump width (SJW).
  318. */
  319. #define IS_CAN_SYNJUMPWIDTH_OK(SJW) (((SJW) == CAN_SynJumpWidth_1TimeQuantum) || ((SJW) == CAN_SynJumpWidth_2TimeQuantum)|| \
  320. ((SJW) == CAN_SynJumpWidth_3TimeQuantum) || ((SJW) == CAN_SynJumpWidth_4TimeQuantum))
  321. /**
  322. * @brief Macro used by the assert function in order to check time quantum in bit segment 1 .
  323. */
  324. #define IS_CAN_BITSEG1_OK(BS1) ((BS1) <= CAN_BitSeg1_16TimeQuantum)
  325. /**
  326. * @brief Macro used by the assert function in order to check time quantum in bit segment 2.
  327. */
  328. #define IS_CAN_BITSEG2_OK(BS2) ((((BS2) >= CAN_BitSeg2_2TimeQuantum) && ((BS2) <= CAN_BitSeg2_8TimeQuantum))|| ((BS2) == CAN_BitSeg2_1TimeQuantum))
  329. /**
  330. * @brief Macro used by the assert function in order to check CAN clock prescaler.
  331. */
  332. #define IS_CAN_PRESCALER_OK(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 64))
  333. /**
  334. * @brief Macro used by the assert function in order to check CAN filter number.
  335. */
  336. #define IS_CAN_FILTER_NUMBER_OK(NUMBER) (((NUMBER) == CAN_FilterNumber_0) || \
  337. ((NUMBER) == CAN_FilterNumber_1) || \
  338. ((NUMBER) == CAN_FilterNumber_2) || \
  339. ((NUMBER) == CAN_FilterNumber_3) || \
  340. ((NUMBER) == CAN_FilterNumber_4) || \
  341. ((NUMBER) == CAN_FilterNumber_5))
  342. /**
  343. * @brief Macro used by the assert function in order to check CAN filter mode.
  344. */
  345. #define IS_CAN_FILTER_MODE_OK(MODE) (((MODE) == CAN_FilterMode_IdMask) || \
  346. ((MODE) == CAN_FilterMode_IdMask_IdList) || \
  347. ((MODE) == CAN_FilterMode_IdList_IdMask) || \
  348. ((MODE) == CAN_FilterMode_IdList))
  349. /**
  350. * @brief Macro used by the assert function in order to check CAN filter scale.
  351. */
  352. #define IS_CAN_FILTER_SCALE_OK(SCALE) (((SCALE) == CAN_FilterScale_8Bit)|| \
  353. ((SCALE) == CAN_FilterScale_16_8Bit) ||\
  354. ((SCALE) == CAN_FilterScale_16Bit )||\
  355. ((SCALE) == CAN_FilterScale_32Bit))
  356. /**
  357. * @brief Macro used by the assert function in order to check CAN Tx mailboxes.
  358. */
  359. #define IS_CAN_TRANSMITMAILBOX_OK(TRANSMITMAILBOX) (((TRANSMITMAILBOX) == CAN_TransmitMailBox_0) || \
  360. ((TRANSMITMAILBOX) == CAN_TransmitMailBox_1) || \
  361. ((TRANSMITMAILBOX) == CAN_TransmitMailBox_2))
  362. /**
  363. * @brief Macro used by the assert function in order to check the Standard ID to be sent.
  364. */
  365. #define IS_CAN_STDID_OK(STDID) ((STDID) <= ((uint16_t)CAN_STDID_SIZE))
  366. /**
  367. * @brief Macro used by the assert function in order to check the Extended ID to be sent.
  368. */
  369. #define IS_CAN_EXTID_OK(EXTID) ((EXTID) <= ((uint32_t)CAN_EXTID_SIZE))
  370. /**
  371. * @brief Macro used by the assert function in order to check the DLC to be sent.
  372. */
  373. #define IS_CAN_DLC_OK(DLC) ((DLC) <= CAN_DLC_MAX)
  374. /**
  375. * @brief Macro used by the assert function in order to check the type of the ID to be sent.
  376. */
  377. #define IS_CAN_IDTYPE_OK(IDTYPE) (((IDTYPE) == CAN_Id_Standard) || ((IDTYPE) == CAN_Id_Extended))
  378. /**
  379. * @brief Macro used by the assert function in order to check CAN transmission Frame Type.
  380. */
  381. #define IS_CAN_RTR_OK(RTR) (((RTR) == CAN_RTR_Data) || ((RTR) == CAN_RTR_Remote))
  382. /**
  383. * @brief Macro used by the assert function in order to check CAN flags which can be got by @ref CAN_GetFlagStatus
  384. */
  385. #define IS_CAN_FLAG_STATUS_OK(FLAG) (((FLAG) == CAN_FLAG_RQCP0) || ((FLAG) == CAN_FLAG_RQCP1) ||\
  386. ((FLAG) == CAN_FLAG_RQCP2) || ((FLAG) == CAN_FLAG_FMP) ||\
  387. ((FLAG) == CAN_FLAG_FF) || ((FLAG) == CAN_FLAG_FOV) ||\
  388. ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_EWG) ||\
  389. ((FLAG) == CAN_FLAG_EPV) || ((FLAG) == CAN_FLAG_BOF) ||\
  390. ((FLAG) == CAN_FLAG_LEC))
  391. /**
  392. * @brief Macro used by the assert function in order to check CAN flags which can be cleared by @ref CAN_ClearFlag
  393. */
  394. #define IS_CAN_FLAG_CLEAR_OK(FLAG) (((FLAG) == CAN_FLAG_RQCP0) || ((FLAG) == CAN_FLAG_RQCP1) ||\
  395. ((FLAG) == CAN_FLAG_RQCP2) || ((FLAG) == CAN_FLAG_FF) ||\
  396. ((FLAG) == CAN_FLAG_FOV) || ((FLAG) == CAN_FLAG_WKU) ||\
  397. ((FLAG) == CAN_FLAG_LEC))
  398. /**
  399. * @brief Macro used by the assert function in order to check the CAN Configuration interrupts.
  400. */
  401. #define CAN_IT_CONFIG_MASK ~(uint16_t)(CAN_IT_TME|CAN_IT_FMP|CAN_IT_FF|CAN_IT_FOV|CAN_IT_WKU|CAN_IT_EWG|CAN_IT_EPV|CAN_IT_BOF|CAN_IT_LEC|CAN_IT_ERR)
  402. #define IS_CAN_IT_CONFIG_OK(IT) (((IT) != 0x0000) && ((uint16_t)((uint16_t)(IT) & (uint16_t)CAN_IT_CONFIG_MASK) == 0x0000))
  403. /**
  404. * @brief Macro used by the assert function in order to check the CAN status interrupts.
  405. */
  406. #define IS_CAN_IT_STATUS_OK(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FMP) ||\
  407. ((IT) == CAN_IT_FF) || ((IT) == CAN_IT_FOV) || \
  408. ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_ERR) || \
  409. ((IT) == CAN_IT_EWG) || ((IT) == CAN_IT_EPV) || \
  410. ((IT) == CAN_IT_BOF) || ((IT) == CAN_IT_LEC) )
  411. /**
  412. * @brief Macro used by the assert function in order to check the CAN Pending bit interrupts.
  413. */
  414. #define IS_CAN_IT_PENDING_BIT_OK(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FF) ||\
  415. ((IT) == CAN_IT_FOV) || ((IT) == CAN_IT_WKU) ||\
  416. ((IT) == CAN_IT_ERR) || ((IT) == CAN_IT_EWG) ||\
  417. ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF)||\
  418. ((IT) == CAN_IT_LEC))
  419. /**
  420. * @brief Macro used by the assert function in order to check the Last Error Code.
  421. */
  422. #define IS_CAN_LAST_ERROR_CODE_OK(CODE) (((CODE) & 0x8F) == 0x00)
  423. /**
  424. * @}
  425. */
  426. /* Exported function prototypes --------------------------------------------- */
  427. /** @addtogroup CAN_Exported_Functions
  428. * @{
  429. */
  430. void CAN_DeInit(void);
  431. CAN_InitStatus_TypeDef CAN_Init(CAN_MasterCtrl_TypeDef CAN_MasterCtrl,
  432. CAN_Mode_TypeDef CAN_Mode,
  433. CAN_SynJumpWidth_TypeDef CAN_SynJumpWidth,
  434. CAN_BitSeg1_TypeDef CAN_BitSeg1,
  435. CAN_BitSeg2_TypeDef CAN_BitSeg2,
  436. uint8_t CAN_Prescaler);
  437. void CAN_FilterInit(CAN_FilterNumber_TypeDef CAN_FilterNumber,
  438. FunctionalState CAN_FilterActivation,
  439. CAN_FilterMode_TypeDef CAN_FilterMode,
  440. CAN_FilterScale_TypeDef CAN_FilterScale,
  441. uint8_t CAN_FilterID1,
  442. uint8_t CAN_FilterID2,
  443. uint8_t CAN_FilterID3,
  444. uint8_t CAN_FilterID4,
  445. uint8_t CAN_FilterIDMask1,
  446. uint8_t CAN_FilterIDMask2,
  447. uint8_t CAN_FilterIDMask3,
  448. uint8_t CAN_FilterIDMask4);
  449. void CAN_ITConfig(CAN_IT_TypeDef CAN_IT, FunctionalState NewState);
  450. void CAN_ST7CompatibilityCmd(CAN_ST7Compatibility_TypeDef CAN_ST7Compatibility);
  451. CAN_TxStatus_TypeDef CAN_Transmit( uint32_t CAN_Id,
  452. CAN_Id_TypeDef CAN_IDE,
  453. CAN_RTR_TypeDef CAN_RTR,
  454. uint8_t CAN_DLC,
  455. uint8_t *CAN_Data);
  456. void CAN_TTComModeCmd(FunctionalState NewState);
  457. CAN_TxStatus_TypeDef CAN_TransmitStatus(CAN_TransmitMailBox_TypeDef CAN_TransmitMailbox);
  458. void CAN_CancelTransmit(CAN_TransmitMailBox_TypeDef CAN_TransmitMailbox);
  459. void CAN_FIFORelease(void);
  460. CAN_NbrPendingMessage_TypeDef CAN_MessagePending(void);
  461. void CAN_Receive(void);
  462. uint32_t CAN_GetReceivedId(void);
  463. CAN_Id_TypeDef CAN_GetReceivedIDE(void);
  464. CAN_RTR_TypeDef CAN_GetReceivedRTR(void);
  465. uint8_t CAN_GetReceivedDLC(void);
  466. uint8_t CAN_GetReceivedData(uint8_t CAN_DataIndex);
  467. uint8_t CAN_GetReceivedFMI(void);
  468. uint16_t CAN_GetMessageTimeStamp(void);
  469. CAN_Sleep_TypeDef CAN_Sleep(void);
  470. CAN_WakeUp_TypeDef CAN_WakeUp(void);
  471. CAN_ModeStatus_TypeDef CAN_OperatingModeRequest(CAN_OperatingMode_TypeDef CAN_OperatingMode);
  472. CAN_ErrorCode_TypeDef CAN_GetLastErrorCode(void);
  473. CAN_Page_TypeDef CAN_GetSelectedPage(void);
  474. void CAN_SelectPage(CAN_Page_TypeDef CAN_Page);
  475. FlagStatus CAN_GetFlagStatus(CAN_FLAG_TypeDef CAN_Flag);
  476. void CAN_ClearFlag(CAN_FLAG_TypeDef CAN_Flag);
  477. ITStatus CAN_GetITStatus(CAN_IT_TypeDef CAN_IT);
  478. void CAN_ClearITPendingBit(CAN_IT_TypeDef CAN_IT);
  479. /**
  480. * @}
  481. */
  482. #endif /* __STM8S_CAN_H */
  483. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/