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