Skip to content

Commit f1c7384

Browse files
committed
CAN receive (polled) works.
1 parent c8debe0 commit f1c7384

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

libraries/CAN/src/R7FA6M5_CAN.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,30 @@ int R7FA6M5_CAN::write(CanMsg const & msg)
206206
return 1;
207207
}
208208

209-
size_t R7FA6M5_CAN::available() const
209+
size_t R7FA6M5_CAN::available()
210210
{
211-
return _can_rx_buf.available();
211+
can_info_t can_info;
212+
if (fsp_err_t const rc = R_CANFD_InfoGet(&_canfd_ctrl, &can_info); rc != FSP_SUCCESS)
213+
return 0;
214+
215+
if (can_info.rx_mb_status > 0)
216+
{
217+
can_frame_t frame;
218+
if (fsp_err_t const rc = R_CANFD_Read(&_canfd_ctrl, (can_info.rx_mb_status - 1), &frame); rc != FSP_SUCCESS)
219+
return 0;
220+
221+
/* Extract the received CAN message. */
222+
CanMsg const msg
223+
(
224+
frame.id,
225+
frame.data_length_code,
226+
frame.data
227+
);
228+
/* Store the received CAN message in the receive buffer. */
229+
_can_rx_buf.enqueue(msg);
230+
}
231+
232+
return can_info.rx_mb_status;
212233
}
213234

214235
CanMsg R7FA6M5_CAN::read()
@@ -221,7 +242,7 @@ void R7FA6M5_CAN::onCanFDCallback(can_callback_args_t * p_args)
221242
switch (p_args->event)
222243
{
223244
case CAN_EVENT_TX_COMPLETE: break;
224-
case CAN_EVENT_RX_COMPLETE: // Currently driver don't support this. This is unreachable code for now.
245+
case CAN_EVENT_RX_COMPLETE: // Currently driver don't support this. This is unreachable code for now. This is so true.
225246
{
226247
/* Extract the received CAN message. */
227248
CanMsg const msg

libraries/CAN/src/R7FA6M5_CAN.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class R7FA6M5_CAN
6161

6262

6363
int write(CanMsg const & msg);
64-
size_t available() const;
64+
size_t available();
6565
CanMsg read();
6666

6767

0 commit comments

Comments
 (0)