STM8S/A Standard Peripherals Drivers: stm8s_can.h Source File

STM8S/A

stm8s_can.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm8s_can.h
00004   * @author  MCD Application Team
00005   * @version V2.3.0
00006   * @date    16-June-2017
00007   * @brief   This file contains all the functions for the CAN peripheral.
00008    ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */
00027 
00028 /* Define to prevent recursive inclusion -------------------------------------*/
00029 #ifndef __STM8S_CAN_H
00030 #define __STM8S_CAN_H
00031 
00032 /* Includes ------------------------------------------------------------------*/
00033 #include "stm8s.h"
00034 
00035 /* Exported constants --------------------------------------------------------*/
00036 #define CAN_STDID_SIZE ((uint16_t)0x07FF)
00037 #define CAN_EXTID_SIZE ((uint32_t)0x1FFFFFFF)
00038 #define CAN_DLC_MAX ((uint8_t)0x08)
00039 
00040 
00041 /** @addtogroup CAN_Exported_Types
00042   * @{
00043   */
00044 
00045 
00046 /**
00047   * @brief  CAN Page Mapping
00048  */
00049 typedef enum
00050 {
00051  CAN_Page_TxMailBox0  = ((uint8_t) 0), /*!< CAN TX mailbox 0 reg page */
00052  CAN_Page_TxMailBox1  = ((uint8_t) 1), /*!< CAN TX mailbox 1 reg page */
00053  CAN_Page_TxMailBox2  = ((uint8_t) 5), /*!< CAN TX mailbox 2 reg page */
00054  CAN_Page_Filter01    = ((uint8_t) 2), /*!< CAN Filters 0 & 1 reg page*/
00055  CAN_Page_Filter23    = ((uint8_t) 3), /*!< CAN Filters 2 & 3 reg page*/
00056  CAN_Page_Filter45    = ((uint8_t) 4), /*!< CAN Filters 4 & 5 reg page*/
00057  CAN_Page_Config      = ((uint8_t) 6), /*!< CAN Configuration control/status reg page*/
00058  CAN_Page_RxFifo      = ((uint8_t) 7) /*!< CAN RX FIFO registers page */
00059 }CAN_Page_TypeDef;
00060 
00061 
00062 
00063 /**
00064   * @brief   CAN sleep constants 
00065  */
00066 typedef enum {
00067   CAN_InitStatus_Failed =0,                        /*!< CAN initialization failed */
00068   CAN_InitStatus_Success =! CAN_InitStatus_Failed  /*!< CAN initialization OK*/
00069 } CAN_InitStatus_TypeDef;
00070 
00071  
00072  /**
00073   * @brief  CAN operating mode */
00074  typedef enum
00075 {
00076   CAN_OperatingMode_Initialization    =((uint8_t)0x00),    /*!< Initialization mode */
00077   CAN_OperatingMode_Normal            =((uint8_t)0x01),    /*!< Normal mode */
00078   CAN_OperatingMode_Sleep             =((uint8_t)0x02)    /*!< sleep mode */
00079 }CAN_OperatingMode_TypeDef;
00080 
00081  /**
00082   * @brief  CAN operating mode status */
00083  typedef enum
00084 {
00085   CAN_ModeStatus_Failed    = ((uint8_t)0x00),          /*!< CAN entering the specific mode failed */
00086   CAN_ModeStatus_Success    =! CAN_ModeStatus_Failed   /*!< CAN entering the specific mode Succeed */
00087 }CAN_ModeStatus_TypeDef;
00088 
00089  /**
00090   * @brief   CAN Time Triggered Communication mode 
00091   */
00092 typedef enum
00093 {
00094  CAN_MasterCtrl_AllDisabled          =((uint8_t)0x00),  /*!<  CAN  ALL Master Control Option are DISABLED */
00095  CAN_MasterCtrl_AllEnabled           =((uint8_t)0xFC),  /*!<  CAN  ALL Master Control Option are DISABLED */
00096  CAN_MasterCtrl_TimeTriggerCOMMode   =((uint8_t)0x80),  /*!<  CAN Time Triggered Communication mode ENABLED */
00097  CAN_MasterCtrl_AutoBusOffManagement =((uint8_t)0x40),  /*!<  CAN Auto Bus Off Management ENABLED */
00098  CAN_MasterCtrl_AutoWakeUpMode       =((uint8_t)0x20),  /*!<  CAN Automatic WakeUp Mode ENABLED , sleep mode is left automatically by hardware  */
00099  CAN_MasterCtrl_NoAutoReTx           =((uint8_t)0x10),  /*!<  CAN Non Automatic Retransmission ENABLED, MSG  will be transmitted only once */
00100  CAN_MasterCtrl_RxFifoLockedMode     =((uint8_t)0x08),  /*!<  CAN Receive FIFO Locked  against overrun ENABLED */
00101  CAN_MasterCtrl_TxFifoPriority       =((uint8_t)0x04)   /*!<  CAN Transmit FIFO Priority  driven by the request order (not by the identifier of the MSG) */
00102  }CAN_MasterCtrl_TypeDef;
00103 
00104 /**
00105   * @brief   CAN  mode options */
00106 typedef enum
00107 {
00108   CAN_Mode_Normal             =((uint8_t)0x00),  /*!< normal mode */
00109   CAN_Mode_LoopBack           =((uint8_t)0x01),  /*!< loopback mode */
00110   CAN_Mode_Silent             =((uint8_t)0x02),  /*!< silent mode */
00111   CAN_Mode_Silent_LoopBack    =((uint8_t)0x03)  /*!< loopback combined with silent mode */
00112 }CAN_Mode_TypeDef;
00113 
00114 /**
00115   * @brief  CAN synchronisation jump width (SJW)*/
00116 typedef enum
00117 {
00118   CAN_SynJumpWidth_1TimeQuantum                 =((uint8_t)0x00),  /*!< 1 time quantum */
00119   CAN_SynJumpWidth_2TimeQuantum                 =((uint8_t)0x40),  /*!< 2 time quantum */
00120   CAN_SynJumpWidth_3TimeQuantum                 =((uint8_t)0x80),  /*!< 3 time quantum */
00121   CAN_SynJumpWidth_4TimeQuantum                 =((uint8_t)0xC0)  /*!< 4 time quantum */
00122 }CAN_SynJumpWidth_TypeDef;
00123 
00124 /**
00125   * @brief   time quantum in bit segment 1 */
00126 typedef enum
00127 {
00128   CAN_BitSeg1_1TimeQuantum                 =((uint8_t)0x00),  /*!< 1 time quantum */
00129   CAN_BitSeg1_2TimeQuantum                 =((uint8_t)0x01),  /*!< 2 time quantum */
00130   CAN_BitSeg1_3TimeQuantum                 =((uint8_t)0x02),  /*!< 3 time quantum */
00131   CAN_BitSeg1_4TimeQuantum                 =((uint8_t)0x03) , /*!< 4 time quantum */
00132   CAN_BitSeg1_5TimeQuantum                 =((uint8_t)0x04) , /*!< 5 time quantum */
00133   CAN_BitSeg1_6TimeQuantum                 =((uint8_t)0x05) , /*!< 6 time quantum */
00134   CAN_BitSeg1_7TimeQuantum                 =((uint8_t)0x06) , /*!< 7 time quantum */
00135   CAN_BitSeg1_8TimeQuantum                 =((uint8_t)0x07),  /*!< 8 time quantum */
00136   CAN_BitSeg1_9TimeQuantum                 =((uint8_t)0x08),  /*!< 9 time quantum */
00137   CAN_BitSeg1_10TimeQuantum                =((uint8_t)0x09),  /*!< 10 time quantum */
00138   CAN_BitSeg1_11TimeQuantum                =((uint8_t)0x0A),  /*!< 11 time quantum */
00139   CAN_BitSeg1_12TimeQuantum                =((uint8_t)0x0B),  /*!< 12 time quantum */
00140   CAN_BitSeg1_13TimeQuantum                =((uint8_t)0x0C),  /*!< 13 time quantum */
00141   CAN_BitSeg1_14TimeQuantum                =((uint8_t)0x0D),  /*!< 14 time quantum */
00142   CAN_BitSeg1_15TimeQuantum                =((uint8_t)0x0E),  /*!< 15 time quantum */
00143   CAN_BitSeg1_16TimeQuantum                =((uint8_t)0x0F)  /*!< 16 time quantum */
00144 }CAN_BitSeg1_TypeDef;
00145 
00146 /**
00147   * @brief   time quantum in bit segment 2 */
00148 typedef enum
00149 {
00150   CAN_BitSeg2_1TimeQuantum                = ((uint8_t)0x00),  /*!< 1 time quantum */
00151   CAN_BitSeg2_2TimeQuantum                = ((uint8_t)0x10),  /*!< 2 time quantum */
00152   CAN_BitSeg2_3TimeQuantum                = ((uint8_t)0x20),  /*!< 3 time quantum */
00153   CAN_BitSeg2_4TimeQuantum                = ((uint8_t)0x30),  /*!< 4 time quantum */
00154   CAN_BitSeg2_5TimeQuantum                = ((uint8_t)0x40),  /*!< 5 time quantum */
00155   CAN_BitSeg2_6TimeQuantum                = ((uint8_t)0x50),  /*!< 6 time quantum */
00156   CAN_BitSeg2_7TimeQuantum                = ((uint8_t)0x60),  /*!< 7 time quantum */
00157   CAN_BitSeg2_8TimeQuantum                = ((uint8_t)0x70)   /*!< 8 time quantum */
00158 }CAN_BitSeg2_TypeDef;
00159 
00160 
00161 /**
00162   * @brief   CAN filter number */
00163 typedef enum
00164 {                                                                  
00165   CAN_FilterNumber_0                = ((uint8_t)0x00),  /*!< Filter number 0 */ 
00166   CAN_FilterNumber_1                = ((uint8_t)0x01),  /*!< Filter number 1 */ 
00167   CAN_FilterNumber_2                = ((uint8_t)0x02),  /*!< Filter number 2 */
00168   CAN_FilterNumber_3                = ((uint8_t)0x03),  /*!< Filter number 3 */
00169   CAN_FilterNumber_4                = ((uint8_t)0x04),  /*!< Filter number 4 */ 
00170   CAN_FilterNumber_5                = ((uint8_t)0x05)   /*!< Filter number 5 */ 
00171 }CAN_FilterNumber_TypeDef;
00172 
00173 /**
00174   * @brief   CAN filter mode */
00175 typedef enum
00176 {
00177   CAN_FilterMode_IdMask                  =  ((uint8_t)0x00),    /*!< id/mask mode */
00178   CAN_FilterMode_IdMask_IdList           =  ((uint8_t)0x10),    /*!< Id/Mask mode First and IdList mode second */
00179   CAN_FilterMode_IdList_IdMask           =  ((uint8_t)0x11),    /*!< IdList mode First and IdMask mode second */
00180   CAN_FilterMode_IdList                  =  ((uint8_t)0x01)     /*!< identifier list mode */
00181 }CAN_FilterMode_TypeDef;
00182 
00183 /**
00184   * @brief   CAN filter scale */
00185 typedef enum
00186 {
00187   CAN_FilterScale_8Bit       =((uint8_t)0x00), /*!< 8-bit filter scale */
00188   CAN_FilterScale_16_8Bit    =((uint8_t)0x02), /*!< 16/8-bit filter scale */
00189   CAN_FilterScale_16Bit      =((uint8_t)0x04), /*!< 16-bit filter scale */
00190   CAN_FilterScale_32Bit      =((uint8_t)0x06)  /*!< 32-bit filter scale */
00191 }CAN_FilterScale_TypeDef;
00192 
00193 
00194 /**
00195   * @brief   CAN Tx mailboxes*/
00196 typedef enum
00197 {
00198  CAN_TransmitMailBox_0       = ((uint8_t) 0x00),  /*!< CAN TX mailbox 0 reg page */
00199  CAN_TransmitMailBox_1       = ((uint8_t) 0x01),  /*!< CAN TX mailbox 1 reg page */
00200  CAN_TransmitMailBox_2       = ((uint8_t) 0x05)   /*!< CAN TX mailbox 2 reg page */
00201 }CAN_TransmitMailBox_TypeDef;
00202 
00203 /**
00204   * @brief   CAN Pending Messages number*/
00205 typedef enum
00206 {
00207   CAN_NbrPendingMessage_0     =  ((uint8_t)0x00),  /*!< No Msg Pending */
00208   CAN_NbrPendingMessage_1     =  ((uint8_t)0x01),  /*!< 1 Msg Pending */
00209   CAN_NbrPendingMessage_2     =  ((uint8_t)0x02),  /*!< 2 Msg Pending */
00210   CAN_NbrPendingMessage_3     =  ((uint8_t)0x03)  /*!< 3 Msg Pending */
00211 }CAN_NbrPendingMessage_TypeDef;
00212 
00213 /**
00214   * @brief   CAN identifier type */
00215 typedef enum
00216 {
00217   CAN_Id_Standard                 =((uint8_t)0x00),  /*!< Standard Id */
00218   CAN_Id_Extended                 =((uint8_t)0x40)  /*!< Extended Id */
00219 }CAN_Id_TypeDef;
00220 
00221 /**
00222   * @brief   CAN remote transmission request */
00223 typedef enum
00224 {
00225   CAN_RTR_Data               = ((uint8_t)0x00),  /*!< Data frame */
00226   CAN_RTR_Remote             = ((uint8_t)0x20)  /*!< Remote frame */
00227 }CAN_RTR_TypeDef;
00228 
00229 /**
00230   * @brief   CAN transmit Status */
00231 typedef enum
00232 {
00233   CAN_TxStatus_Failed                 =((uint8_t)0xF0), /*!< CAN transmission failed */
00234   CAN_TxStatus_Ok                     =((uint8_t)0xF1), /*!< CAN transmission succeeded */
00235   CAN_TxStatus_Pending                =((uint8_t)0xF2), /*!< CAN transmission pending */
00236   CAN_TxStatus_NoMailBox              =((uint8_t)0xF4), /*!< CAN cell did not provide an empty mailbox */
00237   CAN_TxStatus_MailBoxEmpty           =((uint8_t)0xF5), /*!< CAN Tx mailbox is Empty */
00238   CAN_TxStatus_MailBox0Ok             =((uint8_t)0x00), /*!< CAN transmission succeeded by mail box 1*/
00239   CAN_TxStatus_MailBox1Ok             =((uint8_t)0x01), /*!< CAN transmission succeeded by mail box 2*/
00240   CAN_TxStatus_MailBox2Ok             =((uint8_t)0x05) /*!< CAN transmission succeeded by mail box 3*/
00241 }CAN_TxStatus_TypeDef;
00242 
00243 /**
00244   * @brief   CAN sleep Status */
00245 typedef enum
00246 {
00247   CAN_Sleep_Failed             = ((uint8_t)0x00), /*!< CAN did not enter the sleep mode */
00248   CAN_Sleep_Ok                 = ((uint8_t)0x01) /*!< CAN entered the sleep mode */
00249 }CAN_Sleep_TypeDef;
00250 /**
00251   * @brief   CAN wake up status */
00252 typedef enum
00253 {
00254  CAN_WakeUp_Failed          =   ((uint8_t)0x00), /*!< CAN did not leave the sleep mode */
00255  CAN_WakeUp_Ok              =   ((uint8_t)0x01) /*!< CAN leaved the sleep mode */
00256 }CAN_WakeUp_TypeDef;
00257 
00258 /**
00259   * @brief   CAN flags */
00260 typedef enum
00261 {
00262   /* if the flag is 0x3XXX, it means that it can be got (CAN_GetFlagStatus) and Cleared (CAN_ClearFlag) */
00263   /* if the flag is 0x1XXX, it means that it can only be got (CAN_GetFlagStatus)  */
00264   /*Transmit Flags*/
00265   CAN_FLAG_RQCP0            =((uint16_t)0x3401), /*!< Request MailBox0  Flag */
00266   CAN_FLAG_RQCP1            =((uint16_t)0x3402), /*!< Request MailBox1  Flag */
00267   CAN_FLAG_RQCP2            =((uint16_t)0x3404), /*!< Request MailBox2  Flag */
00268   /*Receive Flags*/
00269   CAN_FLAG_FMP              =((uint16_t)0x1203), /*!< FIFO Message Pending Flag */
00270   CAN_FLAG_FF               =((uint16_t)0x3208), /*!< FIFO Full  Flag */
00271   CAN_FLAG_FOV              =((uint16_t)0x3210), /*!< FIFO Overrun  Flag */
00272   /*Wake up Flag*/
00273   CAN_FLAG_WKU              =((uint16_t)0x3108), /*!< wake up   Flag */
00274   /*Error Flags*/
00275   CAN_FLAG_EWG              =((uint16_t)0x1001), /*!< Error Warning Flag */
00276   CAN_FLAG_EPV              =((uint16_t)0x1002), /*!< Error Passive Flag */
00277   CAN_FLAG_BOF              =((uint16_t)0x1004), /*!< Bus-Off Flag */
00278   CAN_FLAG_LEC              =((uint16_t)0x3070) /*!< Last error code Flag */
00279 }CAN_FLAG_TypeDef;
00280 
00281 /**
00282   * @brief   CAN interrupts */
00283 typedef enum
00284 {
00285   /*Transmit Interruption*/
00286   CAN_IT_TME                  =((uint16_t)0x0001), /*!< Transmit mailbox empty interrupt */
00287   /*Receive Interruptions*/
00288   CAN_IT_FMP                  =((uint16_t)0x0002), /*!< FIFO  message pending interrupt   */  
00289   CAN_IT_FF                   =((uint16_t)0x0004), /*!< FIFO  full    interrupt                    */
00290   CAN_IT_FOV                  =((uint16_t)0x0008), /*!< FIFO  overrun  interrupt               */
00291   /*Wake Up Interruption*/
00292   CAN_IT_WKU                  =((uint16_t)0x0080), /*!< Wake-up interrupt                         */
00293   /*Error Interruptions*/
00294   CAN_IT_ERR                  =((uint16_t)0x4000), /*!< Genaral Error interrupt                 */
00295   CAN_IT_EWG                  =((uint16_t)0x0100), /*!< Error warning interrupt                */
00296   CAN_IT_EPV                  =((uint16_t)0x0200), /*!< Error passive  interrupt                */
00297   CAN_IT_BOF                  =((uint16_t)0x0400), /*!< Bus-off   interrupt                        */
00298   CAN_IT_LEC                  =((uint16_t)0x0800)  /*!< Last error code interrupt              */
00299 } CAN_IT_TypeDef;
00300 
00301 /**
00302   * @brief   CAN ST7 Compatibility*/
00303 typedef enum
00304 {
00305   CAN_ST7Compatibility_Enable     =  ((uint8_t)0x00), /*!< CAN is compatible with ST7 beCAN (only 2 mailboxes are available)*/
00306   CAN_ST7Compatibility_Disable    =  ((uint8_t)0x10)  /*!< CAN is not compatible with ST7 beCAN ( 3 mailboxes are available)*/
00307 }CAN_ST7Compatibility_TypeDef;
00308 
00309 /**
00310   * @brief   CAN Error Code description */
00311 typedef enum
00312 {                                                                  
00313   CAN_ErrorCode_NoErr                 = ((uint8_t)0x00),  /*!< No Error  */ 
00314   CAN_ErrorCode_StuffErr              = ((uint8_t)0x10),  /*!< Stuff Error  */ 
00315   CAN_ErrorCode_FormErr               = ((uint8_t)0x20),  /*!< Form Error  */ 
00316   CAN_ErrorCode_ACKErr                = ((uint8_t)0x30),  /*!< Acknowledgment Error  */ 
00317   CAN_ErrorCode_BitRecessiveErr       = ((uint8_t)0x40),  /*!< Bit Recessive Error  */ 
00318   CAN_ErrorCode_BitDominantErr        = ((uint8_t)0x50),  /*!< Bit Dominant Error  */ 
00319   CAN_ErrorCode_CRCErr                = ((uint8_t)0x60),  /*!< CRC Error  */ 
00320   CAN_ErrorCode_SoftwareSetErr        = ((uint8_t)0x70)  /*!< Software Set Error  */ 
00321 }CAN_ErrorCode_TypeDef;
00322 /**
00323   * @}
00324   */
00325 /* Private macros ------------------------------------------------------------*/
00326 /** @addtogroup CAN_Private_Macros
00327   * @{
00328   */
00329 /**
00330   * @brief  Macro used by the assert function in order to check the CAN ST7 Compatibility parameters.
00331   */
00332 #define IS_CAN_ST7_COMPATIBILITY_OK(STATE) (((STATE) == CAN_ST7Compatibility_Enable) || ((STATE) == CAN_ST7Compatibility_Disable))
00333 /**
00334   * @brief  Macro used by the assert function in order to check  CAN operating mode.
00335   */
00336 #define IS_CAN_OPERATINGMODE_OK(MODE) (((MODE) == CAN_OperatingMode_Initialization) ||\
00337                                     ((MODE) == CAN_OperatingMode_Normal)|| \
00338                         ((MODE) == CAN_OperatingMode_Sleep))
00339 /**
00340   * @brief  Macro used by the assert function in order to check CAN Time Triggered Communication mode.
00341   */
00342 #define IS_CAN_MASTERCTRL_OK(MODE) (((MODE) == CAN_MasterCtrl_AllDisabled) || \
00343                                     (((MODE) <= CAN_MasterCtrl_AllEnabled) && ((MODE) >= CAN_MasterCtrl_TxFifoPriority)))
00344 /**
00345   * @brief  Macro used by the assert function in order to check   CAN  mode options .
00346   */
00347 #define IS_CAN_MODE_OK(MODE) (((MODE) == CAN_Mode_Normal) || ((MODE) == CAN_Mode_LoopBack)|| \
00348                            ((MODE) == CAN_Mode_Silent) || ((MODE) == CAN_Mode_Silent_LoopBack))
00349 /**
00350   * @brief  Macro used by the assert function in order to check the CAN synchronisation jump width (SJW).
00351   */
00352 #define IS_CAN_SYNJUMPWIDTH_OK(SJW) (((SJW) == CAN_SynJumpWidth_1TimeQuantum) || ((SJW) == CAN_SynJumpWidth_2TimeQuantum)|| \
00353                          ((SJW) == CAN_SynJumpWidth_3TimeQuantum) || ((SJW) == CAN_SynJumpWidth_4TimeQuantum))
00354 /**
00355   * @brief  Macro used by the assert function in order to check time quantum in bit segment 1 .
00356   */
00357 #define IS_CAN_BITSEG1_OK(BS1) ((BS1) <= CAN_BitSeg1_16TimeQuantum)
00358 /**
00359   * @brief  Macro used by the assert function in order to check time quantum in bit segment 2.
00360   */
00361 #define IS_CAN_BITSEG2_OK(BS2) ((((BS2) >= CAN_BitSeg2_2TimeQuantum) && ((BS2) <= CAN_BitSeg2_8TimeQuantum))|| ((BS2) == CAN_BitSeg2_1TimeQuantum))
00362 /**
00363   * @brief  Macro used by the assert function in order to check CAN clock prescaler.
00364   */
00365 #define IS_CAN_PRESCALER_OK(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 64))
00366 /**
00367   * @brief  Macro used by the assert function in order to check CAN filter number.
00368   */
00369 #define IS_CAN_FILTER_NUMBER_OK(NUMBER) (((NUMBER) == CAN_FilterNumber_0) || \
00370                                        ((NUMBER) == CAN_FilterNumber_1) || \
00371                                        ((NUMBER) == CAN_FilterNumber_2) || \
00372                                        ((NUMBER) == CAN_FilterNumber_3) || \
00373                                        ((NUMBER) == CAN_FilterNumber_4) || \
00374                                        ((NUMBER) == CAN_FilterNumber_5))
00375 /**
00376   * @brief  Macro used by the assert function in order to check  CAN filter mode.
00377   */
00378 #define IS_CAN_FILTER_MODE_OK(MODE) (((MODE) == CAN_FilterMode_IdMask) || \
00379                                      ((MODE) == CAN_FilterMode_IdMask_IdList) || \
00380                                      ((MODE) == CAN_FilterMode_IdList_IdMask) || \
00381                                   ((MODE) == CAN_FilterMode_IdList))
00382 /**
00383   * @brief  Macro used by the assert function in order to check CAN filter scale.
00384   */
00385 #define IS_CAN_FILTER_SCALE_OK(SCALE) (((SCALE) == CAN_FilterScale_8Bit)|| \
00386                                     ((SCALE) == CAN_FilterScale_16_8Bit) ||\
00387                                     ((SCALE) == CAN_FilterScale_16Bit  )||\
00388                                     ((SCALE) == CAN_FilterScale_32Bit))
00389 /**
00390   * @brief  Macro used by the assert function in order to check CAN Tx mailboxes.
00391   */
00392 #define IS_CAN_TRANSMITMAILBOX_OK(TRANSMITMAILBOX) (((TRANSMITMAILBOX) == CAN_TransmitMailBox_0) || \
00393                                                  ((TRANSMITMAILBOX) == CAN_TransmitMailBox_1) || \
00394                                                  ((TRANSMITMAILBOX) == CAN_TransmitMailBox_2))
00395 /**
00396   * @brief  Macro used by the assert function in order to check the Standard ID to be sent.
00397   */
00398 #define IS_CAN_STDID_OK(STDID)   ((STDID) <= ((uint16_t)CAN_STDID_SIZE))
00399 /**
00400   * @brief  Macro used by the assert function in order to check the Extended ID to be sent.
00401   */
00402 #define IS_CAN_EXTID_OK(EXTID)   ((EXTID) <= ((uint32_t)CAN_EXTID_SIZE))
00403 /**
00404   * @brief  Macro used by the assert function in order to check the DLC to be sent.
00405   */
00406 #define IS_CAN_DLC_OK(DLC)       ((DLC) <= CAN_DLC_MAX)
00407 /**
00408   * @brief  Macro used by the assert function in order to check the type of the ID to be sent.
00409   */
00410 #define IS_CAN_IDTYPE_OK(IDTYPE) (((IDTYPE) == CAN_Id_Standard) || ((IDTYPE) == CAN_Id_Extended))
00411 /**
00412   * @brief  Macro used by the assert function in order to check CAN  transmission  Frame Type.
00413   */
00414 #define IS_CAN_RTR_OK(RTR) (((RTR) == CAN_RTR_Data) || ((RTR) == CAN_RTR_Remote))
00415 
00416 /**
00417   * @brief  Macro used by the assert function in order to check  CAN flags which can be got by @ref CAN_GetFlagStatus
00418   */
00419 #define IS_CAN_FLAG_STATUS_OK(FLAG) (((FLAG) == CAN_FLAG_RQCP0) || ((FLAG) == CAN_FLAG_RQCP1) ||\
00420                                   ((FLAG) == CAN_FLAG_RQCP2) || ((FLAG) == CAN_FLAG_FMP) ||\
00421                                   ((FLAG) == CAN_FLAG_FF) || ((FLAG) == CAN_FLAG_FOV) ||\
00422                                   ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_EWG) ||\
00423                                   ((FLAG) == CAN_FLAG_EPV) || ((FLAG) == CAN_FLAG_BOF) ||\
00424                                   ((FLAG) == CAN_FLAG_LEC))
00425 /**
00426   * @brief  Macro used by the assert function in order to check  CAN flags which can be cleared by @ref CAN_ClearFlag
00427   */
00428 #define IS_CAN_FLAG_CLEAR_OK(FLAG) (((FLAG) == CAN_FLAG_RQCP0) || ((FLAG) == CAN_FLAG_RQCP1) ||\
00429                                     ((FLAG) == CAN_FLAG_RQCP2) ||  ((FLAG) == CAN_FLAG_FF)   ||\
00430                                     ((FLAG) == CAN_FLAG_FOV)  ||  ((FLAG) == CAN_FLAG_WKU) ||\
00431                                     ((FLAG) == CAN_FLAG_LEC))
00432 /**
00433   * @brief  Macro used by the assert function in order to check the  CAN Configuration interrupts.
00434   */
00435 #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)
00436 #define IS_CAN_IT_CONFIG_OK(IT) (((IT) != 0x0000) && ((uint16_t)((uint16_t)(IT) & (uint16_t)CAN_IT_CONFIG_MASK) == 0x0000))
00437 /**
00438   * @brief  Macro used by the assert function in order to check the  CAN status interrupts.
00439   */
00440 #define IS_CAN_IT_STATUS_OK(IT) (((IT) == CAN_IT_TME)   || ((IT) == CAN_IT_FMP) ||\
00441                              ((IT) == CAN_IT_FF)    || ((IT) == CAN_IT_FOV) || \
00442                              ((IT) == CAN_IT_WKU)   || ((IT) == CAN_IT_ERR)  || \
00443                              ((IT) == CAN_IT_EWG)   || ((IT) == CAN_IT_EPV)  || \
00444                              ((IT) == CAN_IT_BOF)   || ((IT) == CAN_IT_LEC)  )
00445 /**
00446   * @brief  Macro used by the assert function in order to check the  CAN Pending bit interrupts.
00447   */
00448 #define IS_CAN_IT_PENDING_BIT_OK(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FF)  ||\
00449                                       ((IT) == CAN_IT_FOV)  || ((IT) == CAN_IT_WKU) ||\
00450                                       ((IT) == CAN_IT_ERR)  || ((IT) == CAN_IT_EWG) ||\
00451                                       ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF)||\
00452                                       ((IT) == CAN_IT_LEC))
00453 /**
00454   * @brief  Macro used by the assert function in order to check the Last Error Code.
00455   */
00456 #define IS_CAN_LAST_ERROR_CODE_OK(CODE)  (((CODE) & 0x8F) == 0x00)
00457 /**
00458   * @}
00459   */
00460 
00461 /* Exported function prototypes --------------------------------------------- */
00462 /** @addtogroup CAN_Exported_Functions
00463   * @{
00464   */
00465 void CAN_DeInit(void);
00466 CAN_InitStatus_TypeDef CAN_Init(CAN_MasterCtrl_TypeDef CAN_MasterCtrl,
00467                                 CAN_Mode_TypeDef CAN_Mode,
00468                                 CAN_SynJumpWidth_TypeDef CAN_SynJumpWidth,
00469                                 CAN_BitSeg1_TypeDef CAN_BitSeg1,
00470                                 CAN_BitSeg2_TypeDef CAN_BitSeg2,
00471                                 uint8_t CAN_Prescaler);
00472 
00473 void CAN_FilterInit(CAN_FilterNumber_TypeDef CAN_FilterNumber,
00474                     FunctionalState CAN_FilterActivation,
00475                     CAN_FilterMode_TypeDef CAN_FilterMode,
00476                     CAN_FilterScale_TypeDef CAN_FilterScale,
00477                     uint8_t CAN_FilterID1,  
00478                     uint8_t CAN_FilterID2,
00479                     uint8_t CAN_FilterID3,
00480                      uint8_t CAN_FilterID4,
00481                     uint8_t CAN_FilterIDMask1,
00482                      uint8_t CAN_FilterIDMask2,
00483                     uint8_t CAN_FilterIDMask3,
00484                     uint8_t CAN_FilterIDMask4);
00485 void CAN_ITConfig(CAN_IT_TypeDef CAN_IT, FunctionalState NewState);
00486 void CAN_ST7CompatibilityCmd(CAN_ST7Compatibility_TypeDef CAN_ST7Compatibility);
00487 CAN_TxStatus_TypeDef CAN_Transmit( uint32_t CAN_Id,
00488                                    CAN_Id_TypeDef CAN_IDE,
00489                                    CAN_RTR_TypeDef CAN_RTR,
00490                                    uint8_t CAN_DLC,
00491                                    uint8_t *CAN_Data);
00492 void CAN_TTComModeCmd(FunctionalState NewState);
00493 CAN_TxStatus_TypeDef CAN_TransmitStatus(CAN_TransmitMailBox_TypeDef CAN_TransmitMailbox);
00494 void CAN_CancelTransmit(CAN_TransmitMailBox_TypeDef CAN_TransmitMailbox);
00495 void CAN_FIFORelease(void);
00496 CAN_NbrPendingMessage_TypeDef CAN_MessagePending(void);
00497 void CAN_Receive(void);
00498 uint32_t CAN_GetReceivedId(void);
00499 CAN_Id_TypeDef CAN_GetReceivedIDE(void);
00500 CAN_RTR_TypeDef CAN_GetReceivedRTR(void);
00501 uint8_t CAN_GetReceivedDLC(void);
00502 uint8_t CAN_GetReceivedData(uint8_t CAN_DataIndex);
00503 uint8_t CAN_GetReceivedFMI(void);
00504 uint16_t CAN_GetMessageTimeStamp(void);
00505 CAN_Sleep_TypeDef CAN_Sleep(void);
00506 CAN_WakeUp_TypeDef CAN_WakeUp(void);
00507 CAN_ModeStatus_TypeDef CAN_OperatingModeRequest(CAN_OperatingMode_TypeDef CAN_OperatingMode);
00508 CAN_ErrorCode_TypeDef CAN_GetLastErrorCode(void);
00509 CAN_Page_TypeDef CAN_GetSelectedPage(void);
00510 void CAN_SelectPage(CAN_Page_TypeDef CAN_Page);
00511 FlagStatus CAN_GetFlagStatus(CAN_FLAG_TypeDef CAN_Flag);
00512 void CAN_ClearFlag(CAN_FLAG_TypeDef CAN_Flag);
00513 ITStatus CAN_GetITStatus(CAN_IT_TypeDef CAN_IT);
00514 void CAN_ClearITPendingBit(CAN_IT_TypeDef CAN_IT);
00515 /**
00516   * @}
00517   */
00518 #endif /* __STM8S_CAN_H */
00519 
00520 
00521 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM8 8-bit Microcontrollers platform visit www.st.com