📄 can.h
字号:
/*******************************************************************************
* Function Name : CAN_SetUnusedMsgObj
* Description : Configure the message object as unused
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : None
*******************************************************************************/
void CAN_SetUnusedMsgObj(u32 msgobj);
/*******************************************************************************
* Function Name : CAN_SetTxMsgObj
* Description : Configure the message object as TX
* Input 1 : message object number, from 0 to 31
* Input 2 : CAN_STD_ID or CAN_EXT_ID
* Output : None
* Return : None
*******************************************************************************/
void CAN_SetTxMsgObj(u32 msgobj, u32 idType);
/*******************************************************************************
* Function Name : CAN_SetRxMsgObj
* Description : Configure the message object as RX
* Input 1 : message object number, from 0 to 31
* Input 2 : CAN_STD_ID or CAN_EXT_ID
* Input 3 : low part of the identifier range used for acceptance filtering
* Input 4 : high part of the identifier range used for acceptance filtering
* Input 5 : TRUE for a single receive object or a FIFO receive object that
* is the last one of the FIFO
* FALSE for a FIFO receive object that is not the last one
* Output : None
* Return : None
*******************************************************************************/
void CAN_SetRxMsgObj(u32 msgobj, u32 idType, u32 idLow, u32 idHigh, bool singleOrFifoLast);
/*******************************************************************************
* Function Name : CAN_InvalidateAllMsgObj
* Description : Configure all the message objects as unused
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void CAN_InvalidateAllMsgObj(void);
/*******************************************************************************
* Function Name : CAN_Init
* Description : Initialize the CAN cell and set the bitrate
* Input 1 : any binary value formed from the CAN_CTL_xxx defines
* Input 2 : one of the CAN_BITRATE_xxx defines
* Output : None
* Return : None
*******************************************************************************/
void CAN_Init(u8 mask, u32 bitrate);
/*******************************************************************************
* Function Name : CAN_ReleaseMessage
* Description : Release the message object
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : None
*******************************************************************************/
void CAN_ReleaseMessage(u32 msgobj);
/*******************************************************************************
* Function Name : CAN_ReleaseTxMessage
* Description : Release the transmit message object
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : None
* Note : assume that message interface 0 is free
*******************************************************************************/
inline void CAN_ReleaseTxMessage(u32 msgobj)
{
CAN->sMsgObj[0].CMR = CAN_CMR_CLRINTPND | CAN_CMR_TXRQST;
CAN->sMsgObj[0].CRR = 1 + msgobj;
}
/*******************************************************************************
* Function Name : CAN_ReleaseRxMessage
* Description : Release the receive message object
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : None
* Note : assume that message interface 1 is free
*******************************************************************************/
inline void CAN_ReleaseRxMessage(u32 msgobj)
{
CAN->sMsgObj[1].CMR = CAN_CMR_CLRINTPND | CAN_CMR_TXRQST;
CAN->sMsgObj[1].CRR = 1 + msgobj;
}
/*******************************************************************************
* Function Name : CAN_SendMessage
* Description : Start transmission of a message
* Input 1 : message object number, from 0 to 31
* Input 2 : pointer to the message structure containing data to transmit
* Output : None
* Return : 1 if transmission was OK, else 0
*******************************************************************************/
u32 CAN_SendMessage(u32 msgobj, canmsg* pCanMsg);
/*******************************************************************************
* Function Name : CAN_ReceiveMessage
* Description : Get the message, if received
* Input 1 : message object number, from 0 to 31
* Input 2 : if TRUE, the message object is released when getting the data
* if FALSE, the message object is not released
* Input 3 : pointer to the message structure where received data is stored
* Output : None
* Return : 1 if reception was OK, else 0 (no message pending)
*******************************************************************************/
u32 CAN_ReceiveMessage(u32 msgobj, bool release, canmsg* pCanMsg);
/*******************************************************************************
* Function Name : CAN_WaitEndOfTx
* Description : Wait until current transmission is finished
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void CAN_WaitEndOfTx(void);
/*******************************************************************************
* Function Name : CAN_BasicSendMessage
* Description : Start transmission of a message in BASIC mode
* Input 1 : pointer to the message structure containing data to transmit
* Output : None
* Return : 1 if transmission was OK, else 0
* Note : CAN must be in BASIC mode
*******************************************************************************/
u32 CAN_BasicSendMessage(canmsg* pCanMsg);
/*******************************************************************************
* Function Name : CAN_BasicReceiveMessage
* Description : Get the message in BASIC mode, if received
* Input 1 : pointer to the message structure where received data is stored
* Output : None
* Return : 1 if reception was OK, else 0 (no message pending)
* Note : CAN must be in BASIC mode
*******************************************************************************/
u32 CAN_BasicReceiveMessage(canmsg* pCanMsg);
/*******************************************************************************
* Function Name : CAN_IsMessageWaiting
* Description : Test the waiting status of a received message
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : A non-zero value if the corresponding message object has
* received a message waiting to be copied, else 0
*******************************************************************************/
inline u32 CAN_IsMessageWaiting(u32 msgobj)
{
return (msgobj < 16 ? CAN->ND1R & (1 << msgobj) : CAN->ND2R & (1 << (msgobj-16)));
}
/*******************************************************************************
* Function Name : CAN_IsTransmitRequested
* Description : Test the request status of a transmitted message
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : A non-zero value if the corresponding message is requested
* to transmit, else 0
*******************************************************************************/
inline u32 CAN_IsTransmitRequested(u32 msgobj)
{
return (msgobj < 16 ? CAN->TR1R & (1 << msgobj) : CAN->TR2R & (1 << (msgobj-16)));
}
/*******************************************************************************
* Function Name : CAN_IsInterruptPending
* Description : Test the interrupt status of a message object
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : A non-zero value if the corresponding message has an interrupt
* pending, else 0
*******************************************************************************/
inline u32 CAN_IsInterruptPending(u32 msgobj)
{
return (msgobj < 16 ? CAN->IP1R & (1 << msgobj) : CAN->IP2R & (1 << (msgobj-16)));
}
/*******************************************************************************
* Function Name : CAN_IsObjectValid
* Description : Test the validity of a message object (ready to use)
* Input 1 : message object number, from 0 to 31
* Output : None
* Return : A non-zero value if the corresponding message object is valid,
* else 0
*******************************************************************************/
inline u32 CAN_IsObjectValid(u32 msgobj)
{
return (msgobj < 16 ? CAN->MV1R & (1 << msgobj) : CAN->MV2R & (1 << (msgobj-16)));
}
#endif /* __can_H */
/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -