lpc2119的can中断发送怎样发啊,现在感觉一直用的查询发送,效率太低了,有没有好的方案啊,
/* ******************************************************************************** **函数名称:startup_sendcan **函数功能:启动发送 **入口参数:cannum:CAN控制器通道号ptr:发送缓冲区指针 **出口参数:1: erro 0:right **函数说明: ** ******************************************************************************** */ uint32 startup_sendcan(uint32 cannum, struct txcanbuf *ptr) { uint32 status = 0; uCANCMR Temp; Temp.Word = 0; if (0 != CANSR(cannum).Bits.TBS1_BIT) { if (0 == CANSR(cannum).Bits.TS1_BIT) { CANTFI1(cannum) = ptr->txdbuf_can[ptr->end].TxFrameInfo; CANTID1(cannum) = ptr->txdbuf_can[ptr->end].TxCANID; CANTDA1(cannum) = ptr->txdbuf_can[ptr->end].CANTDA; CANTDB1(cannum) = ptr->txdbuf_can[ptr->end].CANTDB; Temp.Bits.STB1_BIT = 1; }else{ status = 1; } } else if (0 != CANSR(cannum).Bits.TBS2_BIT){ if (0== CANSR(cannum).Bits.TS2_BIT) { CANTFI2(cannum) = ptr->txdbuf_can[ptr->end].TxFrameInfo; CANTID2(cannum) = ptr->txdbuf_can[ptr->end].TxCANID; CANTDA3(cannum) = ptr->txdbuf_can[ptr->end].CANTDA; CANTDB2(cannum) = ptr->txdbuf_can[ptr->end].CANTDB; Temp.Bits.STB2_BIT = 1; }else{ status = 1; } }else if (0 != CANSR(cannum).Bits.TBS3_BIT){ if (0 == CANSR(cannum).Bits.TS3_BIT) { CANTFI3(cannum) = ptr->txdbuf_can[ptr->end].TxFrameInfo; CANTID3(cannum) = ptr->txdbuf_can[ptr->end].TxCANID; CANTDA3(cannum) = ptr->txdbuf_can[ptr->end].CANTDA; CANTDB3(cannum) = ptr->txdbuf_can[ptr->end].CANTDB; Temp.Bits.STB3_BIT = 1; }else{ status = 1; } }else{ status = 1; } if (status == 0){ if(CANMOD(cannum).Bits.SM_BIT != 0) { CanQuitSM(cannum); } Temp.Bits.TR_BIT = 1; CANCMR(cannum).Word = Temp.Word; } return status; }
/* ******************************************************************************** **函数名称:send2canbus **函数功能:发送缓冲区数据到CAN总线上 **入口参数:cannum:CAN控制器通道号 **出口参数:无 **函数说明: ** ******************************************************************************** */ void send2canbus(uint32 cannum) { uint8 length = 0; struct txcanbuf *ptr; if (CAN1 == cannum) { ptr = &can1buf_txd; length = MAX_TX_CAN1; } else if (CAN2 == cannum){ if (setup_total.type != REPEATERS) return; ptr = &can2buf_txd; length = MAX_TX_CAN2; }else return; if ((ptr->full == _FULL_) || (ptr->end != ptr->start)){ if (CANGSR(cannum).Bits.TBS_BIT != 0){ if (startup_sendcan(cannum,ptr) != 1){ TCAN_LEDGlint(); if (++ptr->end >= length) ptr->end = 0; ptr->full = _EMPTY_; } } } }
/* ******************************************************************************** **函数名称:can_isr **函数功能:can中断复位函数 **入口参数:无 **出口参数:无 **函数说明: ** ******************************************************************************** */ void __irq can_isr(void) { uint32 j = 0; uCANICR k; for (j=0; j<CAN_MAX_NUM; j++) { k = CANICR(j); if (k.Bits.RI_BIT != 0){ rcvdata_fromcanbus(j); } /* if ((k.Bits.TI1_BIT != 0) || (k.Bits.TI2_BIT != 0) || (k.Bits.TI3_BIT != 0)) { } */ if (k.Bits.BEI_BIT != 0) { CanBufOffLinePrg(j); } if (k.Bits.DOI_BIT != 0) { ClrCanDataOver(j); } } VICVectAddr = 0x00; } 应怎样像串口那样采用中断发送啊,只要吧数据丢到缓冲区就不用管它了,中断自动发送,效率肯定高很多!谢谢,有人用过吗 |