CAN library containing a CAN controller object handling a FIFO, and CAN peripherals attached to it.
ControllerCAN.h@1:b69d05604535, 2016-02-06 (annotated)
- Committer:
- garivetm
- Date:
- Sat Feb 06 14:18:08 2016 +0000
- Revision:
- 1:b69d05604535
- Parent:
- 0:ebe6f5e97160
- Child:
- 2:c81dff9c8a93
Naming corrections
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
garivetm | 0:ebe6f5e97160 | 1 | #ifndef CONTROLLERCAN_H |
garivetm | 0:ebe6f5e97160 | 2 | #define CONTROLLERCAN_H |
garivetm | 0:ebe6f5e97160 | 3 | |
garivetm | 0:ebe6f5e97160 | 4 | #include "mbed.h" |
garivetm | 1:b69d05604535 | 5 | #include "PeripheralCAN.h" |
garivetm | 0:ebe6f5e97160 | 6 | #include <vector> |
garivetm | 0:ebe6f5e97160 | 7 | |
garivetm | 0:ebe6f5e97160 | 8 | #define SIZE_FIFO 32 |
garivetm | 0:ebe6f5e97160 | 9 | |
garivetm | 1:b69d05604535 | 10 | class PeripheralCAN; |
garivetm | 0:ebe6f5e97160 | 11 | |
garivetm | 0:ebe6f5e97160 | 12 | /** My CAN Controller class |
garivetm | 0:ebe6f5e97160 | 13 | * Used to manage reading and writing procedures on a CAN Bus |
garivetm | 0:ebe6f5e97160 | 14 | * |
garivetm | 0:ebe6f5e97160 | 15 | * Examples : |
garivetm | 0:ebe6f5e97160 | 16 | * @code |
garivetm | 0:ebe6f5e97160 | 17 | * @endcode |
garivetm | 0:ebe6f5e97160 | 18 | */ |
garivetm | 0:ebe6f5e97160 | 19 | class ControllerCAN { |
garivetm | 0:ebe6f5e97160 | 20 | public : |
garivetm | 0:ebe6f5e97160 | 21 | /** Create ControllerCAN instance |
garivetm | 0:ebe6f5e97160 | 22 | */ |
garivetm | 0:ebe6f5e97160 | 23 | ControllerCAN(); |
garivetm | 0:ebe6f5e97160 | 24 | |
garivetm | 0:ebe6f5e97160 | 25 | /** Destroy ControllerCAN instance |
garivetm | 0:ebe6f5e97160 | 26 | */ |
garivetm | 0:ebe6f5e97160 | 27 | ~ControllerCAN(); |
garivetm | 0:ebe6f5e97160 | 28 | |
garivetm | 0:ebe6f5e97160 | 29 | /** Write a CANMessage on CAN Bus |
garivetm | 0:ebe6f5e97160 | 30 | * |
garivetm | 0:ebe6f5e97160 | 31 | * @param Id Id message |
garivetm | 0:ebe6f5e97160 | 32 | * @param data char array containing data to be send |
garivetm | 0:ebe6f5e97160 | 33 | * @param len size of the data array |
garivetm | 0:ebe6f5e97160 | 34 | * @returns |
garivetm | 0:ebe6f5e97160 | 35 | * 1 if write was successful, |
garivetm | 0:ebe6f5e97160 | 36 | * 0 if write failed |
garivetm | 0:ebe6f5e97160 | 37 | */ |
garivetm | 0:ebe6f5e97160 | 38 | long writeData(long Id, const char *data, char len); |
garivetm | 0:ebe6f5e97160 | 39 | |
garivetm | 0:ebe6f5e97160 | 40 | /** Write a remote CANMessage on CAN Bus |
garivetm | 0:ebe6f5e97160 | 41 | * |
garivetm | 0:ebe6f5e97160 | 42 | * @param Id Id message |
garivetm | 0:ebe6f5e97160 | 43 | * @returns |
garivetm | 0:ebe6f5e97160 | 44 | * 1 if write was successful, |
garivetm | 0:ebe6f5e97160 | 45 | * 0 if write failed |
garivetm | 0:ebe6f5e97160 | 46 | */ |
garivetm | 0:ebe6f5e97160 | 47 | long writeRemote(long Id); |
garivetm | 0:ebe6f5e97160 | 48 | |
garivetm | 1:b69d05604535 | 49 | /** Attach a PeripheralCAN instance to a ControllerCAN |
garivetm | 0:ebe6f5e97160 | 50 | * |
garivetm | 1:b69d05604535 | 51 | * @param peripheral Pointer on a PeripheralCAN instance |
garivetm | 0:ebe6f5e97160 | 52 | */ |
garivetm | 1:b69d05604535 | 53 | void attach(PeripheralCAN* peripheral); |
garivetm | 0:ebe6f5e97160 | 54 | |
garivetm | 0:ebe6f5e97160 | 55 | /** Read one message on the CAN FIFO |
garivetm | 0:ebe6f5e97160 | 56 | * |
garivetm | 0:ebe6f5e97160 | 57 | * @returns |
garivetm | 0:ebe6f5e97160 | 58 | * -1 if no match is found between the message Id and all Ids of |
garivetm | 1:b69d05604535 | 59 | * the PeripheralCAN instances attached to the ControllerCAN, |
garivetm | 0:ebe6f5e97160 | 60 | * 1 if a match is found |
garivetm | 0:ebe6f5e97160 | 61 | */ |
garivetm | 0:ebe6f5e97160 | 62 | char FIFOread(void); |
garivetm | 0:ebe6f5e97160 | 63 | //void FIFO_remove_msg(void); |
garivetm | 0:ebe6f5e97160 | 64 | |
garivetm | 0:ebe6f5e97160 | 65 | private : |
garivetm | 0:ebe6f5e97160 | 66 | |
garivetm | 0:ebe6f5e97160 | 67 | CAN can; |
garivetm | 1:b69d05604535 | 68 | vector<PeripheralCAN*> peripherals; |
garivetm | 0:ebe6f5e97160 | 69 | unsigned char FIFO_ecriture; |
garivetm | 0:ebe6f5e97160 | 70 | signed char FIFO_lecture; |
garivetm | 0:ebe6f5e97160 | 71 | signed char FIFO_occupation; |
garivetm | 0:ebe6f5e97160 | 72 | signed char FIFO_max_occupation; |
garivetm | 0:ebe6f5e97160 | 73 | CANMessage can_MsgRx[SIZE_FIFO]; |
garivetm | 0:ebe6f5e97160 | 74 | |
garivetm | 0:ebe6f5e97160 | 75 | /** Interrupt Service Routine called whenever a CAN frame received interrupt |
garivetm | 0:ebe6f5e97160 | 76 | * is generated. |
garivetm | 0:ebe6f5e97160 | 77 | */ |
garivetm | 0:ebe6f5e97160 | 78 | void can_ISR_Reader(void); |
garivetm | 0:ebe6f5e97160 | 79 | |
garivetm | 0:ebe6f5e97160 | 80 | //static void CAN_automate_reception(void); |
garivetm | 0:ebe6f5e97160 | 81 | }; |
garivetm | 0:ebe6f5e97160 | 82 | |
garivetm | 0:ebe6f5e97160 | 83 | #endif |