summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2015-06-17 15:01:48 +0800
committerBernard Xiong <[email protected]>2015-06-17 15:01:48 +0800
commit562ac32e322faa38521087daa5370324320cd7d8 (patch)
tree349d0a82e9a1916d12ecddc8156946c842bd7c8c
parent2fc33973de23bbc32701e0d2db17a204bf9e405f (diff)
parent70aedb7a3436be153e6df25bd082f1edeb5f8e04 (diff)
Merge pull request #504 from AubrCool/fix-can.drv.errors
Fix can.drv.errors
-rw-r--r--bsp/stm32f10x/drivers/bxcan.c30
-rw-r--r--components/drivers/can/can.c4
2 files changed, 18 insertions, 16 deletions
diff --git a/bsp/stm32f10x/drivers/bxcan.c b/bsp/stm32f10x/drivers/bxcan.c
index 8c9b39ecf0..83d82d04fa 100644
--- a/bsp/stm32f10x/drivers/bxcan.c
+++ b/bsp/stm32f10x/drivers/bxcan.c
@@ -139,7 +139,7 @@ static void bxcan2_filter_init(struct rt_can_device *can)
CAN1->FMR |= FMR_FINIT;
mask = 0x01 << (i + 0);
off = i - BX_CAN2_FMRSTART;
- if(i < pbxcan->fifo1filteroff) {
+ if(off < pbxcan->fifo1filteroff) {
if(pbxcan->filtermap[0].id32mask_cnt && off < pbxcan->filtermap[0].id32mask_cnt) {
CAN1->FS1R |= mask;
CAN1->FM1R &= ~mask;
@@ -586,7 +586,7 @@ static rt_int32_t bxcanfindfilter(struct stm_bxcan *pbxcan,struct rt_can_filter_
if(pitem->rtr) {
thisid |= CAN_RTR_REMOTE;
}
- if((off == 0 && pfilterreg->FR1 == thisid) ||
+ if((*off == 0 && pfilterreg->FR1 == thisid) ||
(*off == 1 && pfilterreg->FR2 == thisid)
) {
found = 1;
@@ -959,14 +959,14 @@ static rt_err_t control(struct rt_can_device *can, int cmd, void *arg)
break;
case RT_CAN_CMD_SET_BAUD:
argval = (rt_uint32_t) arg;
- if(argval != CAN1MBaud ||
- argval != CAN800kBaud ||
- argval != CAN500kBaud ||
- argval != CAN250kBaud ||
- argval != CAN125kBaud ||
- argval != CAN100kBaud ||
- argval != CAN50kBaud ||
- argval != CAN20kBaud ||
+ if(argval != CAN1MBaud &&
+ argval != CAN800kBaud &&
+ argval != CAN500kBaud &&
+ argval != CAN250kBaud &&
+ argval != CAN125kBaud &&
+ argval != CAN100kBaud &&
+ argval != CAN50kBaud &&
+ argval != CAN20kBaud &&
argval != CAN10kBaud ) {
return RT_ERROR;
}
@@ -1063,7 +1063,7 @@ static int recvmsg(struct rt_can_device *can, void* buf, rt_uint32_t boxno)
pmsg->id = (uint32_t)0x1FFFFFFF & (pbxcan->sFIFOMailBox[boxno].RIR >> 3);
}
- pmsg->rtr = (uint8_t)0x02 & pbxcan->sFIFOMailBox[boxno].RIR;
+ pmsg->rtr = (uint8_t) ((0x02 & pbxcan->sFIFOMailBox[boxno].RIR) >> 1);
pmsg->len = (uint8_t)0x0F & pbxcan->sFIFOMailBox[boxno].RDTR;
pmsg->data[0] = (uint8_t)0xFF & pbxcan->sFIFOMailBox[boxno].RDLR;
pmsg->data[1] = (uint8_t)0xFF & (pbxcan->sFIFOMailBox[boxno].RDLR >> 8);
@@ -1127,7 +1127,7 @@ static struct stm_bxcan bxcan1data =
struct rt_can_device bxcan1;
void CAN1_RX0_IRQHandler(void)
{
- while(CAN1->RF0R & 0x11)
+ if(CAN1->RF0R & 0x03)
{
if ((CAN1->RF0R & CAN_RF0R_FOVR0) != 0)
{
@@ -1141,7 +1141,7 @@ void CAN1_RX0_IRQHandler(void)
}
void CAN1_RX1_IRQHandler(void)
{
- while(CAN1->RF1R & 0x11)
+ if(CAN1->RF1R & 0x03)
{
if ((CAN1->RF1R & CAN_RF1R_FOVR1) != 0)
{
@@ -1262,7 +1262,7 @@ static struct stm_bxcan bxcan2data =
struct rt_can_device bxcan2;
void CAN2_RX0_IRQHandler(void)
{
- while(CAN2->RF0R & 0x11)
+ if(CAN2->RF0R & 0x03)
{
if ((CAN2->RF0R & CAN_RF0R_FOVR0) != 0)
{
@@ -1276,7 +1276,7 @@ void CAN2_RX0_IRQHandler(void)
}
void CAN2_RX1_IRQHandler(void)
{
- while(CAN2->RF1R & 0x11)
+ if(CAN2->RF1R & 0x03)
{
if ((CAN2->RF1R & CAN_RF1R_FOVR1) != 0)
{
diff --git a/components/drivers/can/can.c b/components/drivers/can/can.c
index 8ac3029533..c31523c1a0 100644
--- a/components/drivers/can/can.c
+++ b/components/drivers/can/can.c
@@ -65,7 +65,7 @@ rt_inline int _can_int_rx(struct rt_can_device *can, struct rt_can_msg *data, in
can->hdr[hdr].msgs--;
}
listmsg->owner = RT_NULL;
- } else
+ } else if(hdr == -1)
#endif /*RT_CAN_USING_HDR*/
if (!rt_list_isempty(&rx_fifo->uselist))
{
@@ -97,6 +97,8 @@ rt_inline int _can_int_rx(struct rt_can_device *can, struct rt_can_msg *data, in
RT_ASSERT(rx_fifo->freenumbers <= can->config.msgboxsz);
rt_hw_interrupt_enable(level);
listmsg = RT_NULL;
+ } else {
+ break;
}
data ++; msgs -= sizeof(struct rt_can_msg);
}