📄 can2.c
字号:
}
/*""FUNC COMMENT""****************************************************
*ID :2.0.3
*Description :Set can mask
*--------------------------------------------------------------------
*Include :"sfr29.h"
* :"define2.h"
* :"declare2.h"
*--------------------------------------------------------------------
*Declaration :void set_mask_can0(void)
*--------------------------------------------------------------------
*Function :Set can mask
*--------------------------------------------------------------------
*Arguments :Nothing
*--------------------------------------------------------------------
*Returns :Nothing
*--------------------------------------------------------------------
*Input :Nothing
*Ountput :Nothing
*--------------------------------------------------------------------
*Call functions :Nothing
*--------------------------------------------------------------------
*Note :
*--------------------------------------------------------------------
*History :
* :
*""FUNC COMMENT END""***********************************************/
void set_mask_can0(void)
{
c0lmar.ba.sidh = (MASK_14>>6) & 0x1f; //SID10-6
c0lmar.ba.sidl = MASK_14 & 0x3f; //SID5-0
c0lmbr.ba.sidh = (MASK_15>>6) & 0x1f; //SID10-6
c0lmbr.ba.sidl = MASK_15 & 0x3f; //SID5-0
}
/*""FUNC COMMENT""****************************************************
*ID :2.2
*Description :Get can data
*--------------------------------------------------------------------
*Include :"sfr29.h"
* :"define2.h"
* :"declare2.h"
*--------------------------------------------------------------------
*Declaration :void get_message_can0
* (unsigned short in_slot,can_std_data_def *in_rec_data)
*--------------------------------------------------------------------
*Function :Get can data
*--------------------------------------------------------------------
*Arguments :unsigned short in_slot ;slot number
* :can_std_data_def *in_rec_data ;receive data pointer
*--------------------------------------------------------------------
*Returns :Nothing
*--------------------------------------------------------------------
*Input :Nothing
*Ountput :Nothing
*--------------------------------------------------------------------
*Call functions :Nothing
*--------------------------------------------------------------------
*Note :
*--------------------------------------------------------------------
*History :
* :
*""FUNC COMMENT END""***********************************************/
void get_message_can0(
unsigned short in_slot,
can_std_data_def *in_rec_data)
{
unsigned char lp_dlc;
while(1){
/* check receive complete */
while(c0mctl[in_slot].receive.invaldata){}
c0mctl[in_slot].receive.newdata = 0;
/* overrun check */
if(c0mctl[in_slot].receive.msglost){
c0mctl[in_slot].receive.msglost = 0;
error_fnc(CAN_RCV_BUFF_ERROR);
break;
}
/* read message */
in_rec_data->id = ((unsigned short)c0slot[in_slot].ba.sidh<<6)
+ c0slot[in_slot].ba.sidl;
in_rec_data->dlc = c0slot[in_slot].ba.dlc;
for(lp_dlc=0; lp_dlc<c0slot[in_slot].ba.dlc; ++lp_dlc){
in_rec_data->data.data[lp_dlc] = c0slot[in_slot].ba.data[lp_dlc];
}
/* check new message */
if(! c0mctl[in_slot].receive.newdata){
break;
}
}
}
/*""FUNC COMMENT""****************************************************
*ID :2.3
*Description :Set can slot transmit
*--------------------------------------------------------------------
*Include :"sfr29.h"
* :"define2.h"
* :"declare2.h"
*--------------------------------------------------------------------
*Declaration :void set_trm_std_dataframe_can0
* (unsigned short in_slot,can_std_data_def *in_trm_data)
*--------------------------------------------------------------------
*Function :Set can slot transmit
*--------------------------------------------------------------------
*Arguments :unsigned short in_slot ;slot number
* :can_std_data_def *in_trm_data ;transmit data pointer
*--------------------------------------------------------------------
*Returns :Nothing
*--------------------------------------------------------------------
*Input :Nothing
*Ountput :Nothing
*--------------------------------------------------------------------
*Call functions :Nothing
*--------------------------------------------------------------------
*Note :
*--------------------------------------------------------------------
*History :
* :
*""FUNC COMMENT END""***********************************************/
void set_trm_std_dataframe_can0(
unsigned short in_slot,
can_std_data_def *in_trm_data)
{
unsigned char lp_dlc;
while(c0mctl[in_slot].transmit.trmactive){}
while(c0mctl[in_slot].byte != 0x00){
c0mctl[in_slot].byte = 0x00;
}
/* transmission */
c0icr &= ~(0x0001 << in_slot);
c0idr &= ~(0x0001 << in_slot);
//------------- set dataframe ----------------
c0slot[in_slot].ba.sidh = ((in_trm_data->id)>>6) & 0x1f;
//SID10-6
c0slot[in_slot].ba.sidl = (in_trm_data->id) & 0x3f;
//SID5-0
c0slot[in_slot].ba.dlc = in_trm_data->dlc; //DLC
for(lp_dlc = 0;lp_dlc<(in_trm_data->dlc) && (lp_dlc<8) ; lp_dlc++){
c0slot[in_slot].ba.data[lp_dlc] = in_trm_data->data.data[lp_dlc];
//Data
}
//-------------------------------------------------
c0mctl[in_slot].byte = 0x80;
}
/*""FUNC COMMENT""****************************************************
*ID :2.4
*Description :Abort can transmit
*--------------------------------------------------------------------
*Include :"sfr29.h"
* :"define2.h"
* :"declare2.h"
*--------------------------------------------------------------------
*Declaration :void abort_trm_can0(unsigned short in_slot)
*--------------------------------------------------------------------
*Function :Abort can transmit
*--------------------------------------------------------------------
*Arguments :unsigned short in_slot ;slot number
*--------------------------------------------------------------------
*Returns :Nothing
*--------------------------------------------------------------------
*Input :Nothing
*Ountput :Nothing
*--------------------------------------------------------------------
*Call functions :Nothing
*--------------------------------------------------------------------
*Note :
*--------------------------------------------------------------------
*History :
* :
*""FUNC COMMENT END""***********************************************/
void abort_trm_can0(unsigned short in_slot)
{
if(c0mctl[in_slot].transmit.trmreq
|| c0mctl[in_slot].receive.recreq){
c0mctl[in_slot].byte = 0;
while(c0mctl[in_slot].transmit.trmactive){}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -