Add an mbed API that allows the initialization of the CAN at the correct

CAN bus frequency
pull/4165/head
adustm 2017-04-11 15:36:05 +02:00
parent 5ebe295364
commit f740d2f3bc
3 changed files with 24 additions and 3 deletions

View File

@ -34,6 +34,17 @@ CAN::CAN(PinName rd, PinName td) : _can(), _irq() {
can_irq_init(&_can, (&CAN::_irq_handler), (uint32_t)this);
}
CAN::CAN(PinName rd, PinName td, int f) : _can(), _irq() {
// No lock needed in constructor
for (int i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
_irq[i].attach(donothing);
}
can_init_freq(&_can, rd, td, f);
can_irq_init(&_can, (&CAN::_irq_handler), (uint32_t)this);
}
CAN::~CAN() {
// No lock needed in destructor
can_irq_free(&_can);

View File

@ -111,6 +111,15 @@ public:
* @endcode
*/
CAN(PinName rd, PinName td);
/** Initialize CAN interface and set the frequency
*
* @param rd the rd pin
* @param td the td pin
* @param f the bus frequency in hertz
*/
CAN(PinName rd, PinName td, int f);
virtual ~CAN();
/** Set the frequency of the CAN interface

View File

@ -58,6 +58,7 @@ typedef void (*can_irq_handler)(uint32_t id, CanIrqType type);
typedef struct can_s can_t;
void can_init (can_t *obj, PinName rd, PinName td);
void can_init_freq (can_t *obj, PinName rd, PinName td, int hz);
void can_free (can_t *obj);
int can_frequency (can_t *obj, int hz);