@@ -30,10 +30,14 @@ CAN::CAN(PinName rd, PinName td) : _can(), _irq()
3030 can_irq_init (&_can, (&CAN::_irq_handler), reinterpret_cast <uintptr_t >(this ));
3131}
3232
33- CAN::CAN (PinName rd, PinName td, int hz) : _can(), _irq()
33+ CAN::CAN (PinName rd, PinName td, int hz, int data_hz ) : _can(), _irq()
3434{
3535 // No lock needed in constructor
36+ #ifdef DEVICE_CAN_FD
37+ canfd_init_freq (&_can, rd, td, hz, data_hz);
38+ #else
3639 can_init_freq (&_can, rd, td, hz);
40+ #endif
3741 can_irq_init (&_can, (&CAN::_irq_handler), reinterpret_cast <uintptr_t >(this ));
3842}
3943
@@ -44,10 +48,14 @@ CAN::CAN(const can_pinmap_t &pinmap) : _can(), _irq()
4448 can_irq_init (&_can, (&CAN::_irq_handler), reinterpret_cast <uintptr_t >(this ));
4549}
4650
47- CAN::CAN (const can_pinmap_t &pinmap, int hz) : _can(), _irq()
51+ CAN::CAN (const can_pinmap_t &pinmap, int hz, int data_hz ) : _can(), _irq()
4852{
4953 // No lock needed in constructor
54+ #ifdef DEVICE_CAN_FD
55+ canfd_init_freq_direct (&_can, &pinmap, hz, data_hz);
56+ #else
5057 can_init_freq_direct (&_can, &pinmap, hz);
58+ #endif
5159 can_irq_init (&_can, (&CAN::_irq_handler), reinterpret_cast <uintptr_t >(this ));
5260}
5361
@@ -63,10 +71,14 @@ CAN::~CAN()
6371 can_free (&_can);
6472}
6573
66- int CAN::frequency (int f)
74+ int CAN::frequency (int f, int data_f )
6775{
6876 lock ();
77+ #ifdef DEVICE_CAN_FD
78+ int ret = canfd_frequency (&_can, f, data_f);
79+ #else
6980 int ret = can_frequency (&_can, f);
81+ #endif
7082 unlock ();
7183 return ret;
7284}
@@ -90,6 +102,29 @@ int CAN::read(CANMessage &msg, int handle)
90102 return ret;
91103}
92104
105+ #ifdef DEVICE_CAN_FD
106+
107+ int CAN::write (CANFDMessage msg)
108+ {
109+ lock ();
110+ int ret = canfd_write (&_can, msg, 0 );
111+ unlock ();
112+ return ret;
113+ }
114+
115+ int CAN::read (CANFDMessage &msg, int handle)
116+ {
117+ lock ();
118+ int ret = canfd_read (&_can, &msg, handle);
119+ if (msg.len > 64 ) {
120+ MBED_ERROR (MBED_MAKE_ERROR (MBED_MODULE_DRIVER_CAN, MBED_ERROR_CODE_READ_FAILED), " Read tried to write more than 64 bytes" );
121+ }
122+ unlock ();
123+ return ret;
124+ }
125+
126+ #endif
127+
93128void CAN::reset ()
94129{
95130 lock ();
0 commit comments