CAN library containing a CAN controller object handling a FIFO, and CAN peripherals attached to it.
PeripheralCAN.cpp@5:d1920eb1d63e, 2020-09-12 (annotated)
- Committer:
- garivetm
- Date:
- Sat Sep 12 12:36:45 2020 +0000
- Revision:
- 5:d1920eb1d63e
- Parent:
- 4:0ed21bbd917b
Enable Bus Off auto management ; Pass Rx and TX as constructor parameters ; Add a timeout to the write method.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
garivetm | 2:c81dff9c8a93 | 1 | /*************************************************************************** |
garivetm | 2:c81dff9c8a93 | 2 | AUTHORS : BRUNO LARNAUDIE (Main functions) bruno.larnaudie@u-psud.fr |
garivetm | 2:c81dff9c8a93 | 3 | MATHIEU GARIVET (Object Oriented aspect) |
garivetm | 2:c81dff9c8a93 | 4 | * |
garivetm | 2:c81dff9c8a93 | 5 | INSTITUTION : IUT de CACHAN - 9 av. de la div. Leclerc - 94230 CACHAN |
garivetm | 2:c81dff9c8a93 | 6 | |
garivetm | 2:c81dff9c8a93 | 7 | VERSIONS : v1 (03/07/2012) : FIFO organisation |
garivetm | 5:d1920eb1d63e | 8 | v2 (18/02/2016) : Controller aand Peripheral organisation |
garivetm | 2:c81dff9c8a93 | 9 | |
garivetm | 2:c81dff9c8a93 | 10 | **************************************************************************** |
garivetm | 2:c81dff9c8a93 | 11 | Copyright 2016 LARNAUDIE GARIVET |
garivetm | 2:c81dff9c8a93 | 12 | |
garivetm | 2:c81dff9c8a93 | 13 | Licensed under the Apache License, Version 2.0 (the "License"); |
garivetm | 2:c81dff9c8a93 | 14 | you may not use this file except in compliance with the License. |
garivetm | 2:c81dff9c8a93 | 15 | You may obtain a copy of the License at |
garivetm | 2:c81dff9c8a93 | 16 | |
garivetm | 2:c81dff9c8a93 | 17 | http://www.apache.org/licenses/LICENSE-2.0 |
garivetm | 2:c81dff9c8a93 | 18 | |
garivetm | 2:c81dff9c8a93 | 19 | Unless required by applicable law or agreed to in writing, software |
garivetm | 2:c81dff9c8a93 | 20 | distributed under the License is distributed on an "AS IS" BASIS, |
garivetm | 2:c81dff9c8a93 | 21 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
garivetm | 2:c81dff9c8a93 | 22 | See the License for the specific language governing permissions and |
garivetm | 2:c81dff9c8a93 | 23 | limitations under the License. |
garivetm | 2:c81dff9c8a93 | 24 | ***************************************************************************/ |
garivetm | 1:b69d05604535 | 25 | #include "mbed.h" |
garivetm | 1:b69d05604535 | 26 | #include "PeripheralCAN.h" |
garivetm | 1:b69d05604535 | 27 | |
garivetm | 1:b69d05604535 | 28 | PeripheralCAN::PeripheralCAN(){ |
garivetm | 1:b69d05604535 | 29 | } |
garivetm | 1:b69d05604535 | 30 | |
garivetm | 1:b69d05604535 | 31 | PeripheralCAN::PeripheralCAN(ControllerCAN* controller) : controllerCAN(controller) { |
garivetm | 1:b69d05604535 | 32 | controllerCAN->attach(this); |
garivetm | 1:b69d05604535 | 33 | } |
garivetm | 1:b69d05604535 | 34 | |
garivetm | 1:b69d05604535 | 35 | void PeripheralCAN::addIdRead(unsigned short* Id){ |
garivetm | 1:b69d05604535 | 36 | IdsRead.push_back(Id); |
garivetm | 1:b69d05604535 | 37 | } |
garivetm | 1:b69d05604535 | 38 | |
garivetm | 5:d1920eb1d63e | 39 | bool PeripheralCAN::writeOnCAN(unsigned short Id, const char *data, char len, unsigned int timeout){ |
garivetm | 5:d1920eb1d63e | 40 | uint32_t tickstart = 0; |
garivetm | 5:d1920eb1d63e | 41 | |
garivetm | 5:d1920eb1d63e | 42 | /* Get start tick value */ |
garivetm | 5:d1920eb1d63e | 43 | tickstart = HAL_GetTick(); |
garivetm | 5:d1920eb1d63e | 44 | |
garivetm | 5:d1920eb1d63e | 45 | do{ |
garivetm | 5:d1920eb1d63e | 46 | if (len != 0){ |
garivetm | 5:d1920eb1d63e | 47 | if(controllerCAN->writeData(Id, data, len)) return true; |
garivetm | 5:d1920eb1d63e | 48 | } |
garivetm | 5:d1920eb1d63e | 49 | else{ |
garivetm | 5:d1920eb1d63e | 50 | if(controllerCAN->writeRemote(Id)) return true; |
garivetm | 5:d1920eb1d63e | 51 | } |
garivetm | 5:d1920eb1d63e | 52 | } while((HAL_GetTick() - tickstart) < timeout); |
garivetm | 5:d1920eb1d63e | 53 | |
garivetm | 5:d1920eb1d63e | 54 | return false; |
garivetm | 1:b69d05604535 | 55 | } |
garivetm | 1:b69d05604535 | 56 | |
garivetm | 1:b69d05604535 | 57 | void PeripheralCAN::init(void){ |
garivetm | 1:b69d05604535 | 58 | } |
garivetm | 1:b69d05604535 | 59 | |
garivetm | 1:b69d05604535 | 60 | void PeripheralCAN::update(const unsigned short& Id, const CANMessage& msg){ |
garivetm | 1:b69d05604535 | 61 | } |
garivetm | 1:b69d05604535 | 62 | |
garivetm | 1:b69d05604535 | 63 | vector<unsigned short*> PeripheralCAN::getIdsRead(void){ |
garivetm | 1:b69d05604535 | 64 | return IdsRead; |
garivetm | 4:0ed21bbd917b | 65 | } |