CAN library containing a CAN controller object handling a FIFO, and CAN peripherals attached to it.
Diff: ControllerCAN.cpp
- Revision:
- 5:d1920eb1d63e
- Parent:
- 4:0ed21bbd917b
--- a/ControllerCAN.cpp Sat May 05 13:46:16 2018 +0000 +++ b/ControllerCAN.cpp Sat Sep 12 12:36:45 2020 +0000 @@ -5,7 +5,7 @@ INSTITUTION : IUT de CACHAN - 9 av. de la div. Leclerc - 94230 CACHAN VERSIONS : v1 (03/07/2012) : FIFO organisation - v2 (18/02/2016) : Controller aand Peripheral organisation + v2 (18/02/2016) : Controller and Peripheral organisation **************************************************************************** Copyright 2016 LARNAUDIE GARIVET @@ -25,11 +25,13 @@ #include "mbed.h" #include "ControllerCAN.h" -CAN ControllerCAN::can(PA_8, PA_9); - -ControllerCAN::ControllerCAN(){ - can.frequency(250000); // Baud rate : kbits/s +ControllerCAN::ControllerCAN(PinName rd, PinName td) : can(rd, td, 250000) { + // Enable bus off auto mangement + unsigned long* CAN_MCR = (unsigned long*) 0x40006400; + *CAN_MCR |= CAN_MCR_ABOM; + can.attach(callback(this, &ControllerCAN::can_ISR_Reader)); // CAN ISR + FIFO_ecriture = 0; FIFO_lecture = 0; FIFO_occupation = 0; @@ -64,9 +66,9 @@ if(FIFO_occupation!=0) { char res = 0; - for (int i = 0; i < peripherals.size(); i++){ + for (uint32_t i = 0; i < peripherals.size(); i++){ vector<unsigned short*> IdsRead = peripherals[i]->getIdsRead(); - for (int j = 0; j < IdsRead.size() ; j++){ + for (uint32_t j = 0; j < IdsRead.size() ; j++){ if (can_MsgRx[FIFO_lecture].id == *(IdsRead[j])){ peripherals[i]->update(*(IdsRead[j]), can_MsgRx[FIFO_lecture]); res = 1;