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

📄 can1.c

📁 M16C290FC can
💻 C
📖 第 1 页 / 共 2 页
字号:
  *--------------------------------------------------------------------
  *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"
  *                 :"define1.h"
  *                 :"declare1.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"
  *                 :"define1.h"
  *                 :"declare1.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"
  *                 :"define1.h"
  *                 :"declare1.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){}
    }
}


 /*""FUNC COMMENT""****************************************************
  *ID               :2.5
  *Description      :Transmit A/D data
  *--------------------------------------------------------------------
  *Include          :"sfr29.h"
  *                 :"define1.h"
  *                 :"declare1.h"
  *--------------------------------------------------------------------
  *Declaration      :void trm_can_ad(void)
  *--------------------------------------------------------------------
  *Function         :Transmit A/D data
  *--------------------------------------------------------------------
  *Arguments        :Nothing
  *--------------------------------------------------------------------
  *Returns          :Nothing
  *--------------------------------------------------------------------
  *Input            :trm_id             ;Transmint ID
  *                 :last_ad_data       ;A/D data
  *Ountput          :Nothing
  *--------------------------------------------------------------------
  *Call functions   :set_trm_std_dataframe_can0()   ;Set can slot transmit
  *--------------------------------------------------------------------
  *Note             :
  *--------------------------------------------------------------------
  *History          :
  *                 :
  *""FUNC COMMENT END""***********************************************/
void trm_can_ad(void)
{
    can_std_data_def in_send_data;
/* ID */
    in_send_data.id = trm_id;
/* DLC */
    in_send_data.dlc = 1;
/* data */
    in_send_data.data.data[0] = last_ad_data;
/* transmission */
    set_trm_std_dataframe_can0(TRM_SLOT,&in_send_data);
}

⌨️ 快捷键说明

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