CAN library containing a CAN controller object handling a FIFO, and CAN peripherals attached to it.

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?

UserRevisionLine numberNew contents of line
garivetm 3:e6f72461e31f 1 /***************************************************************************
garivetm 3:e6f72461e31f 2 Copyright 2016 LARNAUDIE GARIVET
garivetm 3:e6f72461e31f 3
garivetm 3:e6f72461e31f 4 Licensed under the Apache License, Version 2.0 (the "License");
garivetm 3:e6f72461e31f 5 you may not use this file except in compliance with the License.
garivetm 3:e6f72461e31f 6 You may obtain a copy of the License at
garivetm 3:e6f72461e31f 7
garivetm 3:e6f72461e31f 8 http://www.apache.org/licenses/LICENSE-2.0
garivetm 3:e6f72461e31f 9
garivetm 3:e6f72461e31f 10 Unless required by applicable law or agreed to in writing, software
garivetm 3:e6f72461e31f 11 distributed under the License is distributed on an "AS IS" BASIS,
garivetm 3:e6f72461e31f 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
garivetm 3:e6f72461e31f 13 See the License for the specific language governing permissions and
garivetm 3:e6f72461e31f 14 limitations under the License.
garivetm 3:e6f72461e31f 15 ***************************************************************************/
garivetm 1:b69d05604535 16 #ifndef PeripheralCAN_H
garivetm 1:b69d05604535 17 #define PeripheralCAN_H
garivetm 1:b69d05604535 18
garivetm 1:b69d05604535 19 #include "mbed.h"
garivetm 1:b69d05604535 20 #include <vector>
garivetm 1:b69d05604535 21 #include "ControllerCAN.h"
garivetm 1:b69d05604535 22
garivetm 1:b69d05604535 23 class ControllerCAN;
garivetm 1:b69d05604535 24 /** My CAN Peripheral class
garivetm 1:b69d05604535 25 * Used as interface to create CAN Peripheral objets
garivetm 1:b69d05604535 26 *
garivetm 1:b69d05604535 27 * Examples :
garivetm 1:b69d05604535 28 * @code
garivetm 1:b69d05604535 29 * @endcode
garivetm 1:b69d05604535 30 */
garivetm 1:b69d05604535 31 class PeripheralCAN {
garivetm 1:b69d05604535 32 public :
garivetm 1:b69d05604535 33 /** Create PeripheralCAN instance
garivetm 1:b69d05604535 34 */
garivetm 1:b69d05604535 35 PeripheralCAN();
garivetm 1:b69d05604535 36
garivetm 1:b69d05604535 37 /** Create PeripheralCAN instance
garivetm 1:b69d05604535 38 *
garivetm 1:b69d05604535 39 * @param controller ControllerCAN instance controlling the PerpiherialCAN
garivetm 1:b69d05604535 40 */
garivetm 1:b69d05604535 41 PeripheralCAN(ControllerCAN* controller);
garivetm 1:b69d05604535 42
garivetm 1:b69d05604535 43 /** Initialize the instance
garivetm 1:b69d05604535 44 */
garivetm 1:b69d05604535 45 virtual void init(void);
garivetm 1:b69d05604535 46
garivetm 1:b69d05604535 47 /** Update the PeripheriamCAN instance
garivetm 1:b69d05604535 48 *
garivetm 1:b69d05604535 49 * @param Id Message Id to determine which variables are concerned,
garivetm 1:b69d05604535 50 * @param msg CANMessage instance containing data of interest
garivetm 1:b69d05604535 51 */
garivetm 1:b69d05604535 52 virtual void update(const unsigned short& Id, const CANMessage& msg);
garivetm 1:b69d05604535 53
garivetm 1:b69d05604535 54 /** Add an Id to the Id vector containing Ids of incoming message
garivetm 1:b69d05604535 55 * concerning the current instance
garivetm 1:b69d05604535 56 *
garivetm 1:b69d05604535 57 * @param Id Message Id to be added
garivetm 1:b69d05604535 58 */
garivetm 1:b69d05604535 59 void addIdRead(unsigned short* Id);
garivetm 1:b69d05604535 60
garivetm 1:b69d05604535 61 /** Write a message on CAN Bus
garivetm 1:b69d05604535 62 *
garivetm 1:b69d05604535 63 * @param Id Id message
garivetm 1:b69d05604535 64 * @param data char array containing data to be send
garivetm 1:b69d05604535 65 * @param len size of the data array
garivetm 5:d1920eb1d63e 66 * @param timeout timeout value in ms (if 0 only one write attempt)
garivetm 5:d1920eb1d63e 67 *
garivetm 5:d1920eb1d63e 68 * @returns Write status : true if message was successfully sent, false else.
garivetm 1:b69d05604535 69 */
garivetm 5:d1920eb1d63e 70 bool writeOnCAN(unsigned short Id, const char *data, char len, unsigned int timeout = 0);
garivetm 1:b69d05604535 71 //short readOnCAN(unsigned short Id, CANMessage& msg);
garivetm 1:b69d05604535 72
garivetm 1:b69d05604535 73 /** Get the IdsRead vector
garivetm 1:b69d05604535 74 *
garivetm 1:b69d05604535 75 * @returns IdsRead vector
garivetm 1:b69d05604535 76 */
garivetm 1:b69d05604535 77 vector<unsigned short*> getIdsRead(void);
garivetm 1:b69d05604535 78
garivetm 1:b69d05604535 79 private :
garivetm 1:b69d05604535 80 vector<unsigned short*> IdsRead;
garivetm 5:d1920eb1d63e 81
garivetm 5:d1920eb1d63e 82 protected:
garivetm 1:b69d05604535 83 ControllerCAN* controllerCAN;
garivetm 1:b69d05604535 84 };
garivetm 1:b69d05604535 85
garivetm 4:0ed21bbd917b 86 #endif