打印
[CAN-bus/DeviceNet]

请教版主,CAN接收中断不能正确退出的问题

[复制链接]
2850|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
玉玟|  楼主 | 2007-1-4 10:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
CAN, ic, TI, rc, os
我用LPC2119上的CAN,程序用了UCOS,CAN接收中断采用IRQ向量中断,能正常产生接收中断,但在UCOS退出中断时总是进入数据中止,请问是什么原因?
程序员如下:
void CAN1RX_Exception(void)//CAN接收中断
{
    CANRxBUF buf;
    INT8U i,j;
    uCANICR k;
    static volatile INT8U *pt;
    static INT8U count=0;
    static INT8U lon=0;
    
    OS_ENTER_CRITICAL();
    
    k=CANICR(1);/*清中断标志*/
    
    buf.CANRcvFS = CANRFS(1);
    buf.RxCANID = CANRID(1);
    buf.CANRDA = CANRDA(1);
    buf.CANRDB = CANRDB(1); 
    
    count=buf.RxCANID.Word&&0x07;
    switch(count)
    {    
        case 0://第一帧
            if(buf.CANRcvFS.Bits.DLC_BIT<8)
                break;
            if(buf.CANRDA.Bytes.Data1==0x68 &&   buf.CANRDB.Bytes.Data4==0x68)
            {    
                pt=CANRx_buf+1;
                memcpy((void *)pt,&buf.CANRDA,8);
                pt+=8;
                CANRx_buf[0]=8;
            }
            break;
        case 1:
            if(buf.CANRcvFS.Bits.DLC_BIT<4)//不是一帧完整的数据
            {    
                count=0;
                break;
            }
            lon=buf.CANRDA.Bytes.Data2;//数长
            
            if(buf.CANRcvFS.Bits.DLC_BIT<8)
            {
                memcpy((void *)pt,&buf.CANRDA,buf.CANRcvFS.Bits.DLC_BIT);
                pt+=buf.CANRcvFS.Bits.DLC_BIT;
                CANRx_buf[0]+=buf.CANRcvFS.Bits.DLC_BIT;
            }
            else 
            {
                memcpy((void *)pt,&buf.CANRDA,8);
                pt+=8;
                CANRx_buf[0]+=8;
            }
            
            if(lon<=4)
            {    
                count=0;
                pt=CANRx_buf+1;
                if(*(pt+11+lon)==0x16)
                {    
                    pt=CANRx_buf+10;
                    for(i=0;i<lon;i++)
                    {
                        *pt=*pt-0x33;
                        pt++;
                    }
                    pt=CANRx_buf+9;
                    j=0;
                    for(i=0;i<lon+2;i++)
                    {
                        j+=*pt;
                        pt++;
                    }
                    if(j==*pt)
                        OSSemPost(CANRxFlag);
                }
            }
            break;
        default:
            count=0;
            break;
    }
    RelCanRecBuf(1);/*释放接收缓冲区 CANCMR(1).Bits.RRB_BIT=1*/    
    VICVectAddr=0;
    OS_EXIT_CRITICAL();
}

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

5

主题

10

帖子

0

粉丝