https://github.com/pilotak/nomutexcan
Mbed library for reading CAN bus in ISR
https://github.com/pilotak/nomutexcan
can can-bus mbed mbed-os-library mutex
Last synced: 3 months ago
JSON representation
Mbed library for reading CAN bus in ISR
- Host: GitHub
- URL: https://github.com/pilotak/nomutexcan
- Owner: pilotak
- License: mit
- Created: 2019-09-27T11:01:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-27T11:21:13.000Z (over 6 years ago)
- Last Synced: 2025-07-10T04:33:00.626Z (11 months ago)
- Topics: can, can-bus, mbed, mbed-os-library, mutex
- Language: C++
- Homepage:
- Size: 1.95 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NoMutexCAN
Standard mbed CAN library doesn't allow you to read messages in ISR. And when you try to use EventQueue (`can.attach(eQueue.event(canListen), CAN::RxIrq);`) it will give you `ISR overflow error` so the only chance is to override mutex, that's what this library do.
```cpp
#include "mbed.h"
#include "NoMutexCAN.h"
CircularBuffer queue;
NoMutexCAN can(PB_8, PB_9);
void canListen() { // ISR
CANMessage msg;
if (can.read(msg)) {
queue.push(msg);
}
}
int main(void) {
can.frequency(250000);
can.mode(CAN::Normal);
can.attach(&canListen, CAN::RxIrq);
while (1) {
while (!queue.empty()) {
CANMessage msg;
queue.pop(msg);
printf("ID: %X\n", msg.id);
}
}
}
```