rusefi/firmware/hw_layer/drivers/gpio/can_gpio.cpp

52 lines
1.1 KiB
C++
Raw Normal View History

2023-03-04 19:11:45 -08:00
/**
* can_gpio.cpp
*/
#include "pch.h"
2023-03-04 21:52:57 -08:00
#include "gpio/gpio_ext.h"
2023-03-04 19:11:45 -08:00
#include "can_gpio.h"
2023-03-04 21:52:57 -08:00
#if EFI_CAN_GPIO
static SEMAPHORE_DECL(wakeSemaphore, 3 /* todo: is that right number? probably not. */);
2023-03-04 19:11:45 -08:00
static THD_WORKING_AREA(canGpio_thread_1_wa, 256);
2023-03-04 21:52:57 -08:00
struct CanOutputs : public GpioChip {
uint8_t state[4];
CanOutputs() {
memset(&state, 0, sizeof(state));
}
void wakeThread() {
/* Entering a reentrant critical zone.*/
chibios_rt::CriticalSectionLocker csl;
chSemSignalI(&wakeSemaphore);
}
/* pin argument is pin number within gpio chip, not a global number */
int writePad(size_t pin, int value) override {
state[pin] = value;
wakeThread();
return 0;
}
};
2023-03-04 19:11:45 -08:00
static THD_FUNCTION(canGpio_driver_thread, p) {
(void)p;
chRegSetThreadName("CanGpio");
2023-03-04 21:52:57 -08:00
while (1) {
chSemWaitTimeout(&wakeSemaphore, TIME_MS2I(1200 /*random number, ms*/));
}
2023-03-04 19:11:45 -08:00
}
void initCanGpio() {
2023-03-04 21:52:57 -08:00
// CAN_PIN_0
2023-03-04 19:11:45 -08:00
chThdCreateStatic(canGpio_thread_1_wa, sizeof(canGpio_thread_1_wa),
PRIO_GPIOCHIP, canGpio_driver_thread, NULL);
}
#endif // EFI_CAN_GPIO