Skip to content

Commit

Permalink
Merge pull request ARMmbed#3492 from Nodraak/fix/3463/can_read_return…
Browse files Browse the repository at this point in the history
…_value

Fix ARMmbed#3463 CAN read() return value
  • Loading branch information
sg- committed Jan 9, 2017
2 parents ddcd3ad + 885b018 commit cefae22
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 14 deletions.
10 changes: 8 additions & 2 deletions targets/TARGET_STM/TARGET_STM32F0/can_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)

CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);

// check FPM0 which holds the pending message count in FIFO 0
// if no message is pending, return 0
if ((can->RF0R & CAN_RF0R_FMP0) == 0) {
return 0;
}

/* Get the Id */
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
if (!msg->format) {
Expand All @@ -261,10 +267,10 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
/* Release the FIFO */
if (handle == CAN_FIFO0) {
/* Release FIFO0 */
can->RF0R = CAN_RF0R_RFOM0;
can->RF0R |= CAN_RF0R_RFOM0;
} else { /* FIFONumber == CAN_FIFO1 */
/* Release FIFO1 */
can->RF1R = CAN_RF1R_RFOM1;
can->RF1R |= CAN_RF1R_RFOM1;
}

return 1;
Expand Down
10 changes: 8 additions & 2 deletions targets/TARGET_STM/TARGET_STM32F1/can_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)

CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);

// check FPM0 which holds the pending message count in FIFO 0
// if no message is pending, return 0
if ((can->RF0R & CAN_RF0R_FMP0) == 0) {
return 0;
}

/* Get the Id */
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
if (!msg->format) {
Expand All @@ -264,10 +270,10 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
/* Release the FIFO */
if(handle == CAN_FIFO0) {
/* Release FIFO0 */
can->RF0R = CAN_RF0R_RFOM0;
can->RF0R |= CAN_RF0R_RFOM0;
} else { /* FIFONumber == CAN_FIFO1 */
/* Release FIFO1 */
can->RF1R = CAN_RF1R_RFOM1;
can->RF1R |= CAN_RF1R_RFOM1;
}

return 1;
Expand Down
10 changes: 8 additions & 2 deletions targets/TARGET_STM/TARGET_STM32F2/can_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)

CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);

// check FPM0 which holds the pending message count in FIFO 0
// if no message is pending, return 0
if ((can->RF0R & CAN_RF0R_FMP0) == 0) {
return 0;
}

/* Get the Id */
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
if (!msg->format) {
Expand All @@ -274,10 +280,10 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
/* Release the FIFO */
if (handle == CAN_FIFO0) {
/* Release FIFO0 */
can->RF0R = CAN_RF0R_RFOM0;
can->RF0R |= CAN_RF0R_RFOM0;
} else { /* FIFONumber == CAN_FIFO1 */
/* Release FIFO1 */
can->RF1R = CAN_RF1R_RFOM1;
can->RF1R |= CAN_RF1R_RFOM1;
}

return 1;
Expand Down
10 changes: 8 additions & 2 deletions targets/TARGET_STM/TARGET_STM32F3/can_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)

CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);

// check FPM0 which holds the pending message count in FIFO 0
// if no message is pending, return 0
if ((can->RF0R & CAN_RF0R_FMP0) == 0) {
return 0;
}

/* Get the Id */
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
if (!msg->format) {
Expand All @@ -264,10 +270,10 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
/* Release the FIFO */
if(handle == CAN_FIFO0) {
/* Release FIFO0 */
can->RF0R = CAN_RF0R_RFOM0;
can->RF0R |= CAN_RF0R_RFOM0;
} else { /* FIFONumber == CAN_FIFO1 */
/* Release FIFO1 */
can->RF1R = CAN_RF1R_RFOM1;
can->RF1R |= CAN_RF1R_RFOM1;
}

return 1;
Expand Down
10 changes: 8 additions & 2 deletions targets/TARGET_STM/TARGET_STM32F4/can_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)

CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);

// check FPM0 which holds the pending message count in FIFO 0
// if no message is pending, return 0
if ((can->RF0R & CAN_RF0R_FMP0) == 0) {
return 0;
}

/* Get the Id */
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
if (!msg->format) {
Expand All @@ -277,10 +283,10 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
/* Release the FIFO */
if(handle == CAN_FIFO0) {
/* Release FIFO0 */
can->RF0R = CAN_RF0R_RFOM0;
can->RF0R |= CAN_RF0R_RFOM0;
} else { /* FIFONumber == CAN_FIFO1 */
/* Release FIFO1 */
can->RF1R = CAN_RF1R_RFOM1;
can->RF1R |= CAN_RF1R_RFOM1;
}

return 1;
Expand Down
10 changes: 8 additions & 2 deletions targets/TARGET_STM/TARGET_STM32F7/can_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)

CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);

// check FPM0 which holds the pending message count in FIFO 0
// if no message is pending, return 0
if ((can->RF0R & CAN_RF0R_FMP0) == 0) {
return 0;
}

/* Get the Id */
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
if (!msg->format) {
Expand All @@ -277,10 +283,10 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
/* Release the FIFO */
if(handle == CAN_FIFO0) {
/* Release FIFO0 */
can->RF0R = CAN_RF0R_RFOM0;
can->RF0R |= CAN_RF0R_RFOM0;
} else { /* FIFONumber == CAN_FIFO1 */
/* Release FIFO1 */
can->RF1R = CAN_RF1R_RFOM1;
can->RF1R |= CAN_RF1R_RFOM1;
}

return 1;
Expand Down
10 changes: 8 additions & 2 deletions targets/TARGET_STM/TARGET_STM32L4/can_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)

CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);

// check FPM0 which holds the pending message count in FIFO 0
// if no message is pending, return 0
if ((can->RF0R & CAN_RF0R_FMP0) == 0) {
return 0;
}

/* Get the Id */
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
if (!msg->format) {
Expand All @@ -264,10 +270,10 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
/* Release the FIFO */
if(handle == CAN_FIFO0) {
/* Release FIFO0 */
can->RF0R = CAN_RF0R_RFOM0;
can->RF0R |= CAN_RF0R_RFOM0;
} else { /* FIFONumber == CAN_FIFO1 */
/* Release FIFO1 */
can->RF1R = CAN_RF1R_RFOM1;
can->RF1R |= CAN_RF1R_RFOM1;
}

return 1;
Expand Down

0 comments on commit cefae22

Please sign in to comment.