CAN library containing a CAN controller object handling a FIFO, and CAN peripherals attached to it.
Diff: PeripheralCAN.cpp
- Revision:
- 5:d1920eb1d63e
- Parent:
- 4:0ed21bbd917b
diff -r 0ed21bbd917b -r d1920eb1d63e PeripheralCAN.cpp --- a/PeripheralCAN.cpp Sat May 05 13:46:16 2018 +0000 +++ b/PeripheralCAN.cpp Sat Sep 12 12:36:45 2020 +0000 @@ -5,7 +5,7 @@ INSTITUTION : IUT de CACHAN - 9 av. de la div. Leclerc - 94230 CACHAN VERSIONS : v1 (03/07/2012) : FIFO organisation - v2 (18/02/2016) : Controller aand Peripheral organisation + v2 (18/02/2016) : Controller aand Peripheral organisation **************************************************************************** Copyright 2016 LARNAUDIE GARIVET @@ -36,13 +36,22 @@ IdsRead.push_back(Id); } -void PeripheralCAN::writeOnCAN(unsigned short Id, const char *data, char len){ - if (len != 0){ - while(!controllerCAN->writeData(Id, data, len)); - } - else{ - while(!controllerCAN->writeRemote(Id)); - } +bool PeripheralCAN::writeOnCAN(unsigned short Id, const char *data, char len, unsigned int timeout){ + uint32_t tickstart = 0; + + /* Get start tick value */ + tickstart = HAL_GetTick(); + + do{ + if (len != 0){ + if(controllerCAN->writeData(Id, data, len)) return true; + } + else{ + if(controllerCAN->writeRemote(Id)) return true; + } + } while((HAL_GetTick() - tickstart) < timeout); + + return false; } void PeripheralCAN::init(void){