27 #ifndef LPC17XX_CAN_H_
28 #define LPC17XX_CAN_H_
43 #define MSG_ENABLE ((uint8_t)(0))
44 #define MSG_DISABLE ((uint8_t)(1))
45 #define CAN1_CTRL ((uint8_t)(0))
46 #define CAN2_CTRL ((uint8_t)(1))
47 #define PARAM_FULLCAN_IC(n) ((n==FULLCAN_IC0)||(n==FULLCAN_IC1))
49 #define MAX_HW_FULLCAN_OBJ 64
50 #define MAX_SW_FULLCAN_OBJ 32
66 #define CAN_MOD_RM ((uint32_t)(1))
68 #define CAN_MOD_LOM ((uint32_t)(1<<1))
70 #define CAN_MOD_STM ((uint32_t)(1<<2))
72 #define CAN_MOD_TPM ((uint32_t)(1<<3))
74 #define CAN_MOD_SM ((uint32_t)(1<<4))
76 #define CAN_MOD_RPM ((uint32_t)(1<<5))
78 #define CAN_MOD_TM ((uint32_t)(1<<7))
84 #define CAN_CMR_TR ((uint32_t)(1))
86 #define CAN_CMR_AT ((uint32_t)(1<<1))
88 #define CAN_CMR_RRB ((uint32_t)(1<<2))
90 #define CAN_CMR_CDO ((uint32_t)(1<<3))
92 #define CAN_CMR_SRR ((uint32_t)(1<<4))
94 #define CAN_CMR_STB1 ((uint32_t)(1<<5))
96 #define CAN_CMR_STB2 ((uint32_t)(1<<6))
98 #define CAN_CMR_STB3 ((uint32_t)(1<<7))
104 #define CAN_GSR_RBS ((uint32_t)(1))
106 #define CAN_GSR_DOS ((uint32_t)(1<<1))
108 #define CAN_GSR_TBS ((uint32_t)(1<<2))
110 #define CAN_GSR_TCS ((uint32_t)(1<<3))
112 #define CAN_GSR_RS ((uint32_t)(1<<4))
114 #define CAN_GSR_TS ((uint32_t)(1<<5))
116 #define CAN_GSR_ES ((uint32_t)(1<<6))
118 #define CAN_GSR_BS ((uint32_t)(1<<7))
120 #define CAN_GSR_RXERR(n) ((uint32_t)((n&0xFF)<<16))
122 #define CAN_GSR_TXERR(n) ((uint32_t)(n&0xFF)<<24))
128 #define CAN_ICR_RI ((uint32_t)(1))
130 #define CAN_ICR_TI1 ((uint32_t)(1<<1))
132 #define CAN_ICR_EI ((uint32_t)(1<<2))
134 #define CAN_ICR_DOI ((uint32_t)(1<<3))
136 #define CAN_ICR_WUI ((uint32_t)(1<<4))
138 #define CAN_ICR_EPI ((uint32_t)(1<<5))
140 #define CAN_ICR_ALI ((uint32_t)(1<<6))
142 #define CAN_ICR_BEI ((uint32_t)(1<<7))
144 #define CAN_ICR_IDI ((uint32_t)(1<<8))
146 #define CAN_ICR_TI2 ((uint32_t)(1<<9))
148 #define CAN_ICR_TI3 ((uint32_t)(1<<10))
150 #define CAN_ICR_ERRBIT(n) ((uint32_t)((n&0x1F)<<16))
152 #define CAN_ICR_ERRDIR ((uint32_t)(1<<21))
154 #define CAN_ICR_ERRC(n) ((uint32_t)((n&0x3)<<22))
156 #define CAN_ICR_ALCBIT(n) ((uint32_t)((n&0xFF)<<24))
162 #define CAN_IER_RIE ((uint32_t)(1))
164 #define CAN_IER_TIE1 ((uint32_t)(1<<1))
166 #define CAN_IER_EIE ((uint32_t)(1<<2))
168 #define CAN_IER_DOIE ((uint32_t)(1<<3))
170 #define CAN_IER_WUIE ((uint32_t)(1<<4))
172 #define CAN_IER_EPIE ((uint32_t)(1<<5))
174 #define CAN_IER_ALIE ((uint32_t)(1<<6))
176 #define CAN_IER_BEIE ((uint32_t)(1<<7))
178 #define CAN_IER_IDIE ((uint32_t)(1<<8))
180 #define CAN_IER_TIE2 ((uint32_t)(1<<9))
182 #define CAN_IER_TIE3 ((uint32_t)(1<<10))
188 #define CAN_BTR_BRP(n) ((uint32_t)(n&0x3FF))
190 #define CAN_BTR_SJM(n) ((uint32_t)((n&0x3)<<14))
192 #define CAN_BTR_TESG1(n) ((uint32_t)(n&0xF)<<16))
194 #define CAN_BTR_TESG2(n) ((uint32_t)(n&0xF)<<20))
196 #define CAN_BTR_SAM(n) ((uint32_t)(1<<23))
202 #define CAN_EWL_EWL(n) ((uint32_t)(n&0xFF))
208 #define CAN_SR_RBS ((uint32_t)(1))
210 #define CAN_SR_DOS ((uint32_t)(1<<1))
212 #define CAN_SR_TBS1 ((uint32_t)(1<<2))
214 #define CAN_SR_TCS1 ((uint32_t)(1<<3))
216 #define CAN_SR_RS ((uint32_t)(1<<4))
218 #define CAN_SR_TS1 ((uint32_t)(1<<5))
220 #define CAN_SR_ES ((uint32_t)(1<<6))
222 #define CAN_SR_BS ((uint32_t)(1<<7))
224 #define CAN_SR_TBS2 ((uint32_t)(1<<10))
226 #define CAN_SR_TCS2 ((uint32_t)(1<<11))
228 #define CAN_SR_TS2 ((uint32_t)(1<<13))
230 #define CAN_SR_TBS3 ((uint32_t)(1<<18))
232 #define CAN_SR_TCS3 ((uint32_t)(1<<19))
234 #define CAN_SR_TS3 ((uint32_t)(1<<21))
240 #define CAN_RFS_ID_INDEX(n) ((uint32_t)(n&0x3FF))
242 #define CAN_RFS_BP ((uint32_t)(1<<10))
244 #define CAN_RFS_DLC(n) ((uint32_t)((n&0xF)<<16)
246 #define CAN_RFS_RTR ((uint32_t)(1<<30))
248 #define CAN_RFS_FF ((uint32_t)(1<<31))
254 #define CAN_RID_ID_11(n) ((uint32_t)(n&0x7FF))
256 #define CAN_RID_ID_29(n) ((uint32_t)(n&0x1FFFFFFF))
262 #define CAN_RDA_DATA1(n) ((uint32_t)(n&0xFF))
264 #define CAN_RDA_DATA2(n) ((uint32_t)((n&0xFF)<<8))
266 #define CAN_RDA_DATA3(n) ((uint32_t)((n&0xFF)<<16))
268 #define CAN_RDA_DATA4(n) ((uint32_t)((n&0xFF)<<24))
274 #define CAN_RDB_DATA5(n) ((uint32_t)(n&0xFF))
276 #define CAN_RDB_DATA6(n) ((uint32_t)((n&0xFF)<<8))
278 #define CAN_RDB_DATA7(n) ((uint32_t)((n&0xFF)<<16))
280 #define CAN_RDB_DATA8(n) ((uint32_t)((n&0xFF)<<24))
286 #define CAN_TFI_PRIO(n) ((uint32_t)(n&0xFF))
288 #define CAN_TFI_DLC(n) ((uint32_t)((n&0xF)<<16))
290 #define CAN_TFI_RTR ((uint32_t)(1<<30))
292 #define CAN_TFI_FF ((uint32_t)(1<<31))
298 #define CAN_TID_ID11(n) ((uint32_t)(n&0x7FF))
300 #define CAN_TID_ID29(n) ((uint32_t)(n&0x1FFFFFFF))
306 #define CAN_TDA_DATA1(n) ((uint32_t)(n&0xFF))
308 #define CAN_TDA_DATA2(n) ((uint32_t)((n&0xFF)<<8))
310 #define CAN_TDA_DATA3(n) ((uint32_t)((n&0xFF)<<16))
312 #define CAN_TDA_DATA4(n) ((uint32_t)((n&0xFF)<<24))
318 #define CAN_TDA_DATA5(n) ((uint32_t)(n&0xFF))
320 #define CAN_TDA_DATA6(n) ((uint32_t)((n&0xFF)<<8))
322 #define CAN_TDA_DATA7(n) ((uint32_t)((n&0xFF)<<16))
324 #define CAN_TDA_DATA8(n) ((uint32_t)((n&0xFF)<<24))
330 #define CAN1SLEEPCLR ((uint32_t)(1<<1))
332 #define CAN2SLEEPCLR ((uint32_t)(1<<2))
338 #define CAN_WAKEFLAGES_CAN1WAKE ((uint32_t)(1<<1))
340 #define CAN_WAKEFLAGES_CAN2WAKE ((uint32_t)(1<<2))
346 #define CAN_TSR_TS1 ((uint32_t)(1))
348 #define CAN_TSR_TS2 ((uint32_t)(1<<1))
350 #define CAN_TSR_TBS1 ((uint32_t)(1<<8))
352 #define CAN_TSR_TBS2 ((uint32_t)(1<<9))
354 #define CAN_TSR_TCS1 ((uint32_t)(1<<16))
356 #define CAN_TSR_TCS2 ((uint32_t)(1<<17))
362 #define CAN_RSR_RS1 ((uint32_t)(1))
364 #define CAN_RSR_RS2 ((uint32_t)(1<<1))
366 #define CAN_RSR_RB1 ((uint32_t)(1<<8))
368 #define CAN_RSR_RB2 ((uint32_t)(1<<9))
370 #define CAN_RSR_DOS1 ((uint32_t)(1<<16))
372 #define CAN_RSR_DOS2 ((uint32_t)(1<<17))
378 #define CAN_MSR_E1 ((uint32_t)(1))
380 #define CAN_MSR_E2 ((uint32_t)(1<<1))
382 #define CAN_MSR_BS1 ((uint32_t)(1<<8))
384 #define CAN_MSR_BS2 ((uint32_t)(1<<9))
390 #define CAN_AFMR_AccOff ((uint32_t)(1))
392 #define CAN_AFMR_AccBP ((uint32_t)(1<<1))
394 #define CAN_AFMR_eFCAN ((uint32_t)(1<<2))
400 #define CAN_STT_sa(n) ((uint32_t)((n&1FF)<<2))
406 #define CAN_SFF_GRP_sa(n) ((uint32_t)((n&3FF)<<2))
412 #define CAN_EFF_sa(n) ((uint32_t)((n&1FF)<<2))
418 #define CAN_Eff_GRP_sa(n) ((uint32_t)((n&3FF)<<2))
424 #define CAN_EndofTable(n) ((uint32_t)((n&3FF)<<2))
430 #define CAN_LUTerrAd(n) ((uint32_t)((n&1FF)<<2))
436 #define CAN_LUTerr ((uint32_t)(1))
442 #define CAN_FCANIE ((uint32_t)(1))
448 #define CAN_FCANIC0_IntPnd(n) ((uint32_t)(1<<n))
454 #define CAN_FCANIC1_IntPnd(n) ((uint32_t)(1<<(n-32)))
459 #define PARAM_CANx(x) ((((uint32_t*)x)==((uint32_t *)LPC_CAN1)) \
460 ||(((uint32_t*)x)==((uint32_t *)LPC_CAN2)))
463 #define PARAM_CANAFx(x) (((uint32_t*)x)== ((uint32_t*)LPC_CANAF))
466 #define PARAM_CANAFRAMx(x) (((uint32_t*)x)== (uint32_t*)LPC_CANAF_RAM)
469 #define PARAM_CANCRx(x) (((uint32_t*)x)==((uint32_t*)LPC_CANCR))
472 #define PARAM_I2S_DATA(data) ((data>=0)&&(data <= 0xFFFFFFFF))
475 #define PRAM_I2S_FREQ(freq) ((freq>=16000)&&(freq <= 96000))
478 #define PARAM_ID_11(n) ((n>>11)==0)
479 #define PARAM_ID_29(n) ((n>>29)==0)
482 #define PARAM_DLC(n) ((n>>4)==0)
484 #define PARAM_ID_FORMAT(n) ((n==STD_ID_FORMAT)||(n==EXT_ID_FORMAT))
487 #define PARAM_GRP_ID(x, y) ((x<=y))
490 #define PARAM_FRAME_TYPE(n) ((n==DATA_FRAME)||(n==REMOTE_FRAME))
493 #define PARAM_CTRL_STS_TYPE(n) ((n==CANCTRL_GLOBAL_STS)||(n==CANCTRL_INT_CAP) \
494 ||(n==CANCTRL_ERR_WRN)||(n==CANCTRL_STS))
497 #define PARAM_CR_STS_TYPE(n) ((n==CANCR_TX_STS)||(n==CANCR_RX_STS) \
500 #define PARAM_AFMODE_TYPE(n) ((n==CAN_Normal)||(n==CAN_AccOff) \
501 ||(n==CAN_AccBP)||(n==CAN_eFCAN))
504 #define PARAM_MODE_TYPE(n) ((n==CAN_OPERATING_MODE)||(n==CAN_RESET_MODE) \
505 ||(n==CAN_LISTENONLY_MODE)||(n==CAN_SELFTEST_MODE) \
506 ||(n==CAN_TXPRIORITY_MODE)||(n==CAN_SLEEP_MODE) \
507 ||(n==CAN_RXPOLARITY_MODE)||(n==CAN_TEST_MODE))
510 #define PARAM_CTRL(n) ((n==CAN1_CTRL)|(n==CAN2_CTRL))
513 #define PARAM_MSG_DISABLE(n) ((n==MSG_ENABLE)|(n==MSG_DISABLE))
516 #define PARAM_INT_EN_TYPE(n) ((n==CANINT_RIE)||(n==CANINT_TIE1) \
517 ||(n==CANINT_EIE)||(n==CANINT_DOIE) \
518 ||(n==CANINT_WUIE)||(n==CANINT_EPIE) \
519 ||(n==CANINT_ALIE)||(n==CANINT_BEIE) \
520 ||(n==CANINT_IDIE)||(n==CANINT_TIE2) \
521 ||(n==CANINT_TIE3)||(n==CANINT_FCE))
524 #define PARAM_AFLUT_ENTRY_TYPE(n) ((n==FULLCAN_ENTRY)||(n==EXPLICIT_STANDARD_ENTRY)\
525 ||(n==GROUP_STANDARD_ENTRY)||(n==EXPLICIT_EXTEND_ENTRY) \
526 ||(n==GROUP_EXTEND_ENTRY))
529 #define PARAM_POSITION(n) ((n>=0)&&(n<512))