VitroIO SDK
Software development kit for Vitro Shard.
Loading...
Searching...
No Matches
canbus.h
Go to the documentation of this file.
1#ifndef VITROIO_SDK_CANBUS_H
2#define VITROIO_SDK_CANBUS_H
3
4#include <mbed.h>
5
7
9
10namespace vitroio
11{
12
13namespace sdk
14{
15
27#define VITROIO_CANBUS_DEFAULT_FREQUENCY 500000
28
35#define VITROIO_CANBUS_DEFAULT_EVENT_QUEUE_SIZE 32
36
49class Canbus : private NonCopyable<Canbus>
50{
51public:
56 typedef Callback<void(const CanbusFrame&)> OnFrameReceivedCallback;
57
83 explicit Canbus(
84 PinName rd, PinName td,
85 EventQueue* targetQueue,
86 uint32_t eventQueueSize = VITROIO_CANBUS_DEFAULT_EVENT_QUEUE_SIZE,
88
105 explicit Canbus(
106 PinName rd, PinName td,
107 osPriority priority = osPriorityNormal,
108 uint32_t eventQueueSize = VITROIO_CANBUS_DEFAULT_EVENT_QUEUE_SIZE,
110
115
123 bool isValid() const;
124
133 int sendFrame(const CanbusFrame& frame);
134
154
175 void setNART(bool flag);
176
177private:
178 static const uint32_t onFramesReceivedCallbacksCnt_ = 4;
179
180 bool valid_;
181
182 impl::_CAN can_;
183 EventQueue evQueue_;
184 Thread* evQueueThread_;
185 OnFrameReceivedCallback onFrameReceivedUserCallbacks_[onFramesReceivedCallbacksCnt_];
186
187 void rxIrqHandler();
188 void onFrameReceivedCallback(CanbusFrame frame);
189};
190
195} // namespace sdk
196
197} // namespace vitroio
198
199#endif // VITROIO_SDK_CANBUS_H
Class is a wrapper for mbed::CANMessage. It provides interface allowing creation of frames complied w...
Definition canbus_frame.h:24
Class is a wrapper for mbed::CAN class and provides interface for CanbusFrame type.
Definition canbus.h:50
Callback< void(const CanbusFrame &)> OnFrameReceivedCallback
Type defines signature of callback function which is to be called when a new frame will be received.
Definition canbus.h:56
bool isValid() const
Function allows to check whether the bus is in valid state.
void setNART(bool flag)
Function allows to set NART bit on MCR register.
~Canbus()
Destructor.
int setOnFrameReceivedCallback(OnFrameReceivedCallback callback, int handle=-1)
Function allows to set callbacks which are to be called any time the frame received.
Canbus(PinName rd, PinName td, EventQueue *targetQueue, uint32_t eventQueueSize=VITROIO_CANBUS_DEFAULT_EVENT_QUEUE_SIZE, int hz=VITROIO_CANBUS_DEFAULT_FREQUENCY)
Constructor initializes CAN bus and chains an internal event queue to the targetQueue.
int sendFrame(const CanbusFrame &frame)
Functions sends frame over the bus.
Canbus(PinName rd, PinName td, osPriority priority=osPriorityNormal, uint32_t eventQueueSize=VITROIO_CANBUS_DEFAULT_EVENT_QUEUE_SIZE, int hz=VITROIO_CANBUS_DEFAULT_FREQUENCY)
Constructor initializes CAN bus and creates internal event loop using thread with priority priority.
The _CAN class is a simple extension of mbed::CAN class.
Definition _CAN.h:37
#define VITROIO_CANBUS_DEFAULT_FREQUENCY
Defines default communication frequency for Canbus .
Definition canbus.h:27
#define VITROIO_CANBUS_DEFAULT_EVENT_QUEUE_SIZE
Defines default size of internal event queue for Canbus .
Definition canbus.h:35
The namespace contains all of components of vitro-shard-sdk and components based on the sdk....
Definition can_layer.h:9