⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lpc17xx_can.h.svn-base

📁 uCOSII_lwip_lpc1768
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
 */
typedef enum {
	CANCTRL_GLOBAL_STS = 0, /**< CAN Global Status */
	CANCTRL_INT_CAP, 		/**< CAN Interrupt and Capture */
	CANCTRL_ERR_WRN, 		/**< CAN Error Warning Limit */
	CANCTRL_STS				/**< CAN Control Status */
} CAN_CTRL_STS_Type;

/**
 * @brief Central CAN status type definition
 */
typedef enum {
	CANCR_TX_STS = 0, 	/**< Central CAN Tx Status */
	CANCR_RX_STS, 		/**< Central CAN Rx Status */
	CANCR_MS			/**< Central CAN Miscellaneous Status */
} CAN_CR_STS_Type;

/**
 * @brief FullCAN Interrupt Capture type definition
 */
typedef enum{
	FULLCAN_IC0,	/**< FullCAN Interrupt and Capture 0 */
	FULLCAN_IC1	/**< FullCAN Interrupt and Capture 1 */
}FullCAN_IC_Type;

/**
 * @brief CAN interrupt enable type definition
 */
typedef enum {
	CANINT_RIE = 0, 	/**< CAN Receiver Interrupt Enable */
	CANINT_TIE1, 		/**< CAN Transmit Interrupt Enable */
	CANINT_EIE, 		/**< CAN Error Warning Interrupt Enable */
	CANINT_DOIE, 		/**< CAN Data Overrun Interrupt Enable */
	CANINT_WUIE, 		/**< CAN Wake-Up Interrupt Enable */
	CANINT_EPIE, 		/**< CAN Error Passive Interrupt Enable */
	CANINT_ALIE, 		/**< CAN Arbitration Lost Interrupt Enable */
	CANINT_BEIE, 		/**< CAN Bus Error Inter rupt Enable */
	CANINT_IDIE, 		/**< CAN ID Ready Interrupt Enable */
	CANINT_TIE2, 		/**< CAN Transmit Interrupt Enable for Buffer2 */
	CANINT_TIE3, 		/**< CAN Transmit Interrupt Enable for Buffer3 */
	CANINT_FCE			/**< FullCAN Interrupt Enable */
} CAN_INT_EN_Type;

/**
 * @brief Acceptance Filter Mode type definition
 */
typedef enum {
	CAN_Normal = 0, 	/**< Normal Mode */
	CAN_AccOff, 		/**< Acceptance Filter Off Mode */
	CAN_AccBP, 			/**< Acceptance Fileter Bypass Mode */
	CAN_eFCAN			/**< FullCAN Mode Enhancement */
} CAN_AFMODE_Type;

/**
 * @brief CAN Mode Type definition
 */
typedef enum {
	CAN_OPERATING_MODE = 0, 	/**< Operating Mode */
	CAN_RESET_MODE, 			/**< Reset Mode */
	CAN_LISTENONLY_MODE, 		/**< Listen Only Mode */
	CAN_SELFTEST_MODE, 			/**< Seft Test Mode */
	CAN_TXPRIORITY_MODE, 		/**< Transmit Priority Mode */
	CAN_SLEEP_MODE, 			/**< Sleep Mode */
	CAN_RXPOLARITY_MODE, 		/**< Receive Polarity Mode */
	CAN_TEST_MODE				/**< Test Mode */
} CAN_MODE_Type;

/**
 * @brief Error values that functions can return
 */
typedef enum {
	CAN_OK = 1, 				/**< No error */
	CAN_OBJECTS_FULL_ERROR, 	/**< No more rx or tx objects available */
	CAN_FULL_OBJ_NOT_RCV, 		/**< Full CAN object not received */
	CAN_NO_RECEIVE_DATA, 		/**< No have receive data available */
	CAN_AF_ENTRY_ERROR, 		/**< Entry load in AFLUT is unvalid */
	CAN_CONFLICT_ID_ERROR, 		/**< Conflict ID occur */
	CAN_ENTRY_NOT_EXIT_ERROR	/**< Entry remove outo AFLUT is not exit */
} CAN_ERROR;

/**
 * @brief Pin Configuration structure
 */
typedef struct {
	uint8_t RD; 			/**< Serial Inputs, from CAN transceivers, should be:
							 ** For CAN1:
							 - CAN_RD1_P0_0: RD pin is on P0.0
							 - CAN_RD1_P0_21 : RD pin is on P0.21
							 ** For CAN2:
							 - CAN_RD2_P0_4: RD pin is on P0.4
							 - CAN_RD2_P2_7: RD pin is on P2.7
							 */
	uint8_t TD;				/**< Serial Outputs, To CAN transceivers, should be:
							 ** For CAN1:
							 - CAN_TD1_P0_1: TD pin is on P0.1
							 - CAN_TD1_P0_22: TD pin is on P0.22
							 ** For CAN2:
							 - CAN_TD2_P0_5: TD pin is on P0.5
							 - CAN_TD2_P2_8: TD pin is on P2.8
							 */
} CAN_PinCFG_Type;

/**
 * @brief CAN message object structure
 */
typedef struct {
	uint32_t id; 			/**< 29 bit identifier, it depend on "format" value
								 - if format = STD_ID_FORMAT, id should be 11 bit identifier
								 - if format = EXT_ID_FORMAT, id should be 29 bit identifier
							 */
	uint8_t dataA[4]; 		/**< Data field A */
	uint8_t dataB[4]; 		/**< Data field B */
	uint8_t len; 			/**< Length of data field in bytes, should be:
								 - 0000b-0111b: 0-7 bytes
								 - 1xxxb: 8 bytes
							*/
	uint8_t format; 		/**< Identifier Format, should be:
								 - STD_ID_FORMAT: Standard ID - 11 bit format
								 - EXT_ID_FORMAT: Extended ID - 29 bit format
							*/
	uint8_t type; 			/**< Remote Frame transmission, should be:
								 - DATA_FRAME: the number of data bytes called out by the DLC
								 field are send from the CANxTDA and CANxTDB registers
								 - REMOTE_FRAME: Remote Frame is sent
							*/
} CAN_MSG_Type;

/**
 * @brief FullCAN Entry structure
 */
typedef struct {
	uint8_t controller;		/**< CAN Controller, should be:
								 - CAN1_CTRL: CAN1 Controller
								 - CAN2_CTRL: CAN2 Controller
							*/
	uint8_t disable;		/**< Disable bit, should be:
								 - MSG_ENABLE: disable bit = 0
								 - MSG_DISABLE: disable bit = 1
							*/
	uint16_t id_11;			/**< Standard ID, should be 11-bit value */
} FullCAN_Entry;

/**
 * @brief Standard ID Frame Format Entry structure
 */
typedef struct {
	uint8_t controller; 	/**< CAN Controller, should be:
								 - CAN1_CTRL: CAN1 Controller
								 - CAN2_CTRL: CAN2 Controller
							*/
	uint8_t disable; 		/**< Disable bit, should be:
								 - MSG_ENABLE: disable bit = 0
								 - MSG_DISABLE: disable bit = 1
							*/
	uint16_t id_11; 		/**< Standard ID, should be 11-bit value */
} SFF_Entry;

/**
 * @brief Group of Standard ID Frame Format Entry structure
 */
typedef struct {
	uint8_t controller1; 	/**< First CAN Controller, should be:
								 - CAN1_CTRL: CAN1 Controller
								 - CAN2_CTRL: CAN2 Controller
							*/
	uint8_t disable1; 		/**< First Disable bit, should be:
								 - MSG_ENABLE: disable bit = 0)
								 - MSG_DISABLE: disable bit = 1
							*/
	uint16_t lowerID; 		/**< ID lower bound, should be 11-bit value */
	uint8_t controller2; 	/**< Second CAN Controller, should be:
								 - CAN1_CTRL: CAN1 Controller
								 - CAN2_CTRL: CAN2 Controller
							*/
	uint8_t disable2; 		/**< Second Disable bit, should be:
								 - MSG_ENABLE: disable bit = 0
								 - MSG_DISABLE: disable bit = 1
							*/
	uint16_t upperID; 		/**< ID upper bound, should be 11-bit value and
								 equal or greater than lowerID
							*/
} SFF_GPR_Entry;

/**
 * @brief Extended ID Frame Format Entry structure
 */
typedef struct {
	uint8_t controller; 	/**< CAN Controller, should be:
								 - CAN1_CTRL: CAN1 Controller
								 - CAN2_CTRL: CAN2 Controller
							*/
	uint32_t ID_29; 		/**< Extend ID, shoud be 29-bit value */
} EFF_Entry;


/**
 * @brief Group of Extended ID Frame Format Entry structure
 */
typedef struct {
	uint8_t controller1; 	/**< First CAN Controller, should be:
								 - CAN1_CTRL: CAN1 Controller
								 - CAN2_CTRL: CAN2 Controller
							*/
	uint8_t controller2; 	/**< Second Disable bit, should be:
								 - MSG_ENABLE: disable bit = 0(default)
								 - MSG_DISABLE: disable bit = 1
							*/
	uint32_t lowerEID; 		/**< Extended ID lower bound, should be 29-bit value */
	uint32_t upperEID; 		/**< Extended ID upper bound, should be 29-bit value */
} EFF_GPR_Entry;


/**
 * @brief Acceptance Filter Section Table structure
 */
typedef struct {
	FullCAN_Entry* FullCAN_Sec; 	/**< The pointer point to FullCAN_Entry */
	uint8_t FC_NumEntry;			/**< FullCAN Entry Number */
	SFF_Entry* SFF_Sec; 			/**< The pointer point to SFF_Entry */
	uint8_t SFF_NumEntry;			/**< Standard ID Entry Number */
	SFF_GPR_Entry* SFF_GPR_Sec; 	/**< The pointer point to SFF_GPR_Entry */
	uint8_t SFF_GPR_NumEntry;		/**< Group Standard ID Entry Number */
	EFF_Entry* EFF_Sec; 			/**< The pointer point to EFF_Entry */
	uint8_t EFF_NumEntry;			/**< Extended ID Entry Number */
	EFF_GPR_Entry* EFF_GPR_Sec; 	/**< The pointer point to EFF_GPR_Entry */
	uint8_t EFF_GPR_NumEntry;		/**< Group Extended ID Entry Number */
} AF_SectionDef;

/**
 * @}
 */


/* Public Functions ----------------------------------------------------------- */
/** @defgroup CAN_Public_Functions CAN Public Functions
 * @{
 */

/* Init/DeInit CAN peripheral -----------*/
void CAN_Init(LPC_CAN_TypeDef *CANx, uint32_t baudrate);
void CAN_DeInit(LPC_CAN_TypeDef *CANx);

/* CAN messages functions ---------------*/
Status CAN_SendMsg(LPC_CAN_TypeDef *CANx, CAN_MSG_Type *CAN_Msg);
Status CAN_ReceiveMsg(LPC_CAN_TypeDef *CANx, CAN_MSG_Type *CAN_Msg);
CAN_ERROR FCAN_ReadObj(LPC_CANAF_TypeDef* CANAFx, CAN_MSG_Type *CAN_Msg);

/* CAN configure functions ---------------*/
void CAN_ModeConfig(LPC_CAN_TypeDef* CANx, CAN_MODE_Type mode,
		FunctionalState NewState);
void CAN_SetAFMode(LPC_CANAF_TypeDef* CANAFx, CAN_AFMODE_Type AFmode);
void CAN_SetCommand(LPC_CAN_TypeDef* CANx, uint32_t CMRType);

/* AFLUT functions ---------------------- */
CAN_ERROR CAN_SetupAFLUT(LPC_CANAF_TypeDef* CANAFx, AF_SectionDef* AFSection);
CAN_ERROR CAN_LoadFullCANEntry(LPC_CAN_TypeDef* CANx, uint16_t ID);
CAN_ERROR CAN_LoadExplicitEntry(LPC_CAN_TypeDef* CANx, uint32_t ID,
		CAN_ID_FORMAT_Type format);
CAN_ERROR CAN_LoadGroupEntry(LPC_CAN_TypeDef* CANx, uint32_t lowerID,
		uint32_t upperID, CAN_ID_FORMAT_Type format);
CAN_ERROR CAN_RemoveEntry(AFLUT_ENTRY_Type EntryType, uint16_t position);

/* CAN interrupt functions -----------------*/
void CAN_IRQCmd(LPC_CAN_TypeDef* CANx, CAN_INT_EN_Type arg, FunctionalState NewState);
uint32_t CAN_IntGetStatus(LPC_CAN_TypeDef* CANx);

/* CAN get status functions ----------------*/
IntStatus CAN_FullCANIntGetStatus (LPC_CANAF_TypeDef* CANAFx);
uint32_t CAN_FullCANPendGetStatus (LPC_CANAF_TypeDef* CANAFx, FullCAN_IC_Type type);
uint32_t CAN_GetCTRLStatus(LPC_CAN_TypeDef* CANx, CAN_CTRL_STS_Type arg);
uint32_t CAN_GetCRStatus(LPC_CANCR_TypeDef* CANCRx, CAN_CR_STS_Type arg);

/**
 * @}
 */


#ifdef __cplusplus
}
#endif

#endif /* LPC17XX_CAN_H_ */

/**
 * @}
 */

/* --------------------------------- End Of File ------------------------------ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -