@@ -33,7 +33,8 @@ extern "C" void canfd_callback(can_callback_args_t * p_args);
33
33
namespace arduino
34
34
{
35
35
36
- canfd_afl_entry_t p_canfd0_afl[CANFD_CFG_AFL_CH0_RULE_NUM];
36
+ extern " C" canfd_afl_entry_t CANFD0_AFL[CANFD_CFG_AFL_CH0_RULE_NUM];
37
+ extern " C" canfd_afl_entry_t CANFD1_AFL[CANFD_CFG_AFL_CH1_RULE_NUM];
37
38
38
39
/* *************************************************************************************
39
40
* CTOR/DTOR
@@ -70,7 +71,7 @@ R7FA6M5_CAN::R7FA6M5_CAN(int const can_tx_pin, int const can_rx_pin)
70
71
}
71
72
, _canfd_extended_cfg
72
73
{
73
- .p_afl = p_canfd0_afl ,
74
+ .p_afl = nullptr ,
74
75
// .txmb_txi_enable = ((1ULL << 9) | (1ULL << 0) | 0ULL),
75
76
.txmb_txi_enable = 0xFFFFFFFFFFFFFFFF ,
76
77
.error_interrupts = (R_CANFD_CFDC_CTR_EWIE_Msk | R_CANFD_CFDC_CTR_EPIE_Msk | R_CANFD_CFDC_CTR_BOEIE_Msk | R_CANFD_CFDC_CTR_BORIE_Msk | R_CANFD_CFDC_CTR_OLIE_Msk | 0U ),
@@ -109,6 +110,14 @@ bool R7FA6M5_CAN::begin(CanBitRate const can_bitrate)
109
110
init_ok &= cfg_init_ok;
110
111
_canfd_cfg.channel = cfg_channel;
111
112
113
+ /* Set the pointer to the right filtering structure. */
114
+ if (_canfd_cfg.channel == 0 )
115
+ _canfd_extended_cfg.p_afl = CANFD0_AFL;
116
+ if (_canfd_cfg.channel == 1 )
117
+ _canfd_extended_cfg.p_afl = CANFD1_AFL;
118
+ else
119
+ init_ok &= false ;
120
+
112
121
/* Configure the interrupts.
113
122
*/
114
123
CanFdIrqReq_t irq_req
@@ -197,9 +206,30 @@ int R7FA6M5_CAN::write(CanMsg const & msg)
197
206
return 1 ;
198
207
}
199
208
200
- size_t R7FA6M5_CAN::available () const
209
+ size_t R7FA6M5_CAN::available ()
201
210
{
202
- 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 ;
203
233
}
204
234
205
235
CanMsg R7FA6M5_CAN::read ()
@@ -212,7 +242,7 @@ void R7FA6M5_CAN::onCanFDCallback(can_callback_args_t * p_args)
212
242
switch (p_args->event )
213
243
{
214
244
case CAN_EVENT_TX_COMPLETE: break ;
215
- 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.
216
246
{
217
247
/* Extract the received CAN message. */
218
248
CanMsg const msg
0 commit comments