Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #ifndef _MCAN_
00045 #define _MCAN_
00046
00047
00048
00049
00050
00051 #include "chip.h"
00052
00053 #include <stdint.h>
00054
00055
00056
00057
00058
00059 #ifdef __cplusplus
00060 extern "C" {
00061 #endif
00062
00063 typedef enum {
00064 CAN_STD_ID = 0,
00065 CAN_EXT_ID = 1
00066 } MCan_IdType;
00067
00068 typedef enum {
00069 CAN_DLC_0 = 0,
00070 CAN_DLC_1 = 1,
00071 CAN_DLC_2 = 2,
00072 CAN_DLC_3 = 3,
00073 CAN_DLC_4 = 4,
00074 CAN_DLC_5 = 5,
00075 CAN_DLC_6 = 6,
00076 CAN_DLC_7 = 7,
00077 CAN_DLC_8 = 8,
00078 CAN_DLC_12 = 9,
00079 CAN_DLC_16 = 10,
00080 CAN_DLC_20 = 11,
00081 CAN_DLC_24 = 12,
00082 CAN_DLC_32 = 13,
00083 CAN_DLC_48 = 14,
00084 CAN_DLC_64 = 15
00085 } MCan_DlcType;
00086
00087 typedef enum {
00088 CAN_FIFO_0 = 0,
00089 CAN_FIFO_1 = 1
00090 } MCan_FifoType;
00091
00092 typedef enum {
00093 CAN_INTR_LINE_0 = 0,
00094 CAN_INTR_LINE_1 = 1
00095 } MCan_IntrLineType;
00096
00097 typedef struct MailboxInfoTag {
00098 uint32_t id;
00099 uint32_t length;
00100 uint32_t timestamp;
00101 } MailboxInfoType;
00102
00103
00104 typedef struct MailBox8Tag {
00105 MailboxInfoType info;
00106 uint8_t data[8];
00107 } Mailbox8Type;
00108
00109 typedef struct MailBox12Tag {
00110 MailboxInfoType info;
00111 uint8_t data[12];
00112 } Mailbox12Type;
00113
00114 typedef struct MailBox16Tag {
00115 MailboxInfoType info;
00116 uint8_t data[16];
00117 } Mailbox16Type;
00118
00119 typedef struct MailBox20Tag {
00120 MailboxInfoType info;
00121 uint8_t data[20];
00122 } Mailbox20Type;
00123
00124 typedef struct MailBox24Tag {
00125 MailboxInfoType info;
00126 uint8_t data[24];
00127 } Mailbox24Type;
00128
00129 typedef struct MailBox32Tag {
00130 MailboxInfoType info;
00131 uint8_t data[32];
00132 } Mailbox32ype;
00133
00134 typedef struct MailBox48Tag {
00135 MailboxInfoType info;
00136 uint8_t data[48];
00137 } Mailbox48Type;
00138
00139 typedef struct MailBox64Tag {
00140 MailboxInfoType info;
00141 uint8_t data[64];
00142 } Mailbox64Type;
00143
00144
00145
00146 typedef struct MCan_MsgRamPntrsTag {
00147 uint32_t *pStdFilts;
00148 uint32_t *pExtFilts;
00149 uint32_t *pRxFifo0;
00150 uint32_t *pRxFifo1;
00151 uint32_t *pRxDedBuf;
00152 uint32_t *pTxEvtFifo;
00153 uint32_t *pTxDedBuf;
00154 uint32_t *pTxFifoQ;
00155 } MCan_MsgRamPntrs;
00156
00157 typedef struct MCan_ConfigTag {
00158 Mcan *pMCan;
00159 uint32_t bitTiming;
00160 uint32_t fastBitTiming;
00161 uint32_t nmbrStdFilts;
00162 uint32_t nmbrExtFilts;
00163 uint32_t nmbrFifo0Elmts;
00164 uint32_t nmbrFifo1Elmts;
00165 uint32_t nmbrRxDedBufElmts;
00166 uint32_t nmbrTxEvtFifoElmts;
00167 uint32_t nmbrTxDedBufElmts;
00168 uint32_t nmbrTxFifoQElmts;
00169 uint32_t rxFifo0ElmtSize;
00170 uint32_t rxFifo1ElmtSize;
00171 uint32_t rxBufElmtSize;
00172
00173 uint32_t txBufElmtSize;
00174
00175 MCan_MsgRamPntrs msgRam;
00176 } MCan_ConfigType;
00177
00178 extern const MCan_ConfigType mcan0Config;
00179 extern const MCan_ConfigType mcan1Config;
00180
00181 __STATIC_INLINE uint32_t MCAN_IsTxComplete(
00182 const MCan_ConfigType *mcanConfig)
00183 {
00184 Mcan *mcan = mcanConfig->pMCan;
00185 return (mcan->MCAN_IR & MCAN_IR_TC);
00186 }
00187
00188 __STATIC_INLINE void MCAN_ClearTxComplete(
00189 const MCan_ConfigType *mcanConfig)
00190 {
00191 Mcan *mcan = mcanConfig->pMCan;
00192 mcan->MCAN_IR = MCAN_IR_TC;
00193 }
00194
00195 __STATIC_INLINE uint32_t MCAN_IsMessageStoredToRxDedBuffer(
00196 const MCan_ConfigType *mcanConfig)
00197 {
00198 Mcan *mcan = mcanConfig->pMCan;
00199
00200 return (mcan->MCAN_IR & MCAN_IR_DRX);
00201 }
00202
00203 __STATIC_INLINE void MCAN_ClearMessageStoredToRxBuffer(
00204 const MCan_ConfigType *mcanConfig)
00205 {
00206 Mcan *mcan = mcanConfig->pMCan;
00207 mcan->MCAN_IR = MCAN_IR_DRX;
00208 }
00209
00210 __STATIC_INLINE uint32_t MCAN_IsMessageStoredToRxFifo0(
00211 const MCan_ConfigType *mcanConfig)
00212 {
00213 Mcan *mcan = mcanConfig->pMCan;
00214 return (mcan->MCAN_IR & MCAN_IR_RF0N);
00215 }
00216
00217 __STATIC_INLINE void MCAN_ClearMessageStoredToRxFifo0(
00218 const MCan_ConfigType *mcanConfig)
00219 {
00220 Mcan *mcan = mcanConfig->pMCan;
00221 mcan->MCAN_IR = MCAN_IR_RF0N;
00222 }
00223
00224 __STATIC_INLINE uint32_t MCAN_IsMessageStoredToRxFifo1(
00225 const MCan_ConfigType *mcanConfig)
00226 {
00227 Mcan *mcan = mcanConfig->pMCan;
00228 return (mcan->MCAN_IR & MCAN_IR_RF1N);
00229 }
00230
00231 __STATIC_INLINE void MCAN_ClearMessageStoredToRxFifo1(
00232 const MCan_ConfigType *mcanConfig)
00233 {
00234 Mcan *mcan = mcanConfig->pMCan;
00235 mcan->MCAN_IR = MCAN_IR_RF1N;
00236 }
00237
00238 void MCAN_Init(
00239 const MCan_ConfigType *mcanConfig);
00240
00241 void MCAN_InitFdEnable(
00242 const MCan_ConfigType *mcanConfig);
00243
00244 void MCAN_InitFdBitRateSwitchEnable(
00245 const MCan_ConfigType *mcanConfig);
00246
00247 void MCAN_InitTxQueue(
00248 const MCan_ConfigType *mcanConfig);
00249
00250 void MCAN_InitLoopback(
00251 const MCan_ConfigType *mcanConfig);
00252
00253 void MCAN_Enable(
00254 const MCan_ConfigType *mcanConfig);
00255
00256 void MCAN_RequestIso11898_1(
00257 const MCan_ConfigType *mcanConfig);
00258
00259 void MCAN_RequestFd(
00260 const MCan_ConfigType *mcanConfig);
00261
00262 void MCAN_RequestFdBitRateSwitch(
00263 const MCan_ConfigType *mcanConfig);
00264
00265 void MCAN_LoopbackOn(
00266 const MCan_ConfigType *mcanConfig);
00267
00268 void MCAN_LoopbackOff(
00269 const MCan_ConfigType *mcanConfig);
00270
00271 void MCAN_IEnableMessageStoredToRxDedBuffer(
00272 const MCan_ConfigType *mcanConfig,
00273 MCan_IntrLineType line);
00274
00275 uint8_t *MCAN_ConfigTxDedBuffer(
00276 const MCan_ConfigType *mcanConfig,
00277 uint8_t buffer,
00278 uint32_t id,
00279 MCan_IdType idType,
00280 MCan_DlcType dlc);
00281
00282 void MCAN_SendTxDedBuffer(
00283 const MCan_ConfigType *mcanConfig,
00284 uint8_t buffer);
00285
00286 uint32_t MCAN_AddToTxFifoQ(
00287 const MCan_ConfigType *mcanConfig,
00288 uint32_t id, MCan_IdType idType,
00289 MCan_DlcType dlc, uint8_t *data);
00290
00291 uint8_t MCAN_IsBufferTxd(
00292 const MCan_ConfigType *mcanConfig,
00293 uint8_t buffer);
00294
00295 void MCAN_ConfigRxBufferFilter(
00296 const MCan_ConfigType *mcanConfig,
00297 uint32_t buffer,
00298 uint32_t filter,
00299 uint32_t id,
00300 MCan_IdType idType);
00301
00302 void MCAN_ConfigRxClassicFilter(
00303 const MCan_ConfigType *mcanConfig,
00304 MCan_FifoType fifo,
00305 uint8_t filter,
00306 uint32_t id,
00307 MCan_IdType idType,
00308 uint32_t mask);
00309
00310 uint8_t MCAN_IsNewDataInRxDedBuffer(
00311 const MCan_ConfigType *mcanConfig,
00312 uint8_t buffer);
00313
00314 void MCAN_GetRxDedBuffer(
00315 const MCan_ConfigType *mcanConfig,
00316 uint8_t buffer,
00317 Mailbox64Type *pRxMailbox);
00318
00319 uint32_t MCAN_GetRxFifoBuffer(
00320 const MCan_ConfigType *mcanConfig,
00321 MCan_FifoType fifo,
00322 Mailbox64Type *pRxMailbox);
00323
00324 #ifdef __cplusplus
00325 }
00326 #endif
00327
00328 #endif
00329