mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-06 03:50:13 +02:00
Optimize CAN-Native driver and event handling
This commit is contained in:
parent
5a43a70992
commit
8d21930101
7 changed files with 44 additions and 23 deletions
|
@ -266,13 +266,13 @@ int CAN_init() {
|
|||
|
||||
int CAN_write_frame(const CAN_frame_t *p_frame) {
|
||||
if (sem_tx_complete == NULL) {
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Write the frame to the controller
|
||||
CAN_write_frame_phy(p_frame);
|
||||
|
||||
return xSemaphoreTake(sem_tx_complete, 20) == pdTRUE ? 0 : -1;
|
||||
return xSemaphoreTake(sem_tx_complete, 20) == pdTRUE ? 1 : 0;
|
||||
}
|
||||
|
||||
int CAN_stop() {
|
||||
|
|
|
@ -5,20 +5,14 @@
|
|||
int ESP32CAN::CANInit() {
|
||||
return CAN_init();
|
||||
}
|
||||
int ESP32CAN::CANWriteFrame(const CAN_frame_t* p_frame) {
|
||||
bool ESP32CAN::CANWriteFrame(const CAN_frame_t* p_frame) {
|
||||
static unsigned long start_time;
|
||||
int result = -1;
|
||||
bool result = false;
|
||||
if (tx_ok) {
|
||||
result = CAN_write_frame(p_frame);
|
||||
tx_ok = (result == 0) ? true : false;
|
||||
if (tx_ok == false) {
|
||||
#ifdef DEBUG_VIA_USB
|
||||
Serial.println("CAN failure! Check wires");
|
||||
#endif
|
||||
set_event(EVENT_CAN_NATIVE_TX_FAILURE, 0);
|
||||
tx_ok = result;
|
||||
if (!tx_ok) {
|
||||
start_time = millis();
|
||||
} else {
|
||||
clear_event(EVENT_CAN_NATIVE_TX_FAILURE);
|
||||
}
|
||||
} else {
|
||||
if ((millis() - start_time) >= 20) {
|
||||
|
@ -27,6 +21,7 @@ int ESP32CAN::CANWriteFrame(const CAN_frame_t* p_frame) {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int ESP32CAN::CANStop() {
|
||||
return CAN_stop();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ class ESP32CAN {
|
|||
bool tx_ok = true;
|
||||
int CANInit();
|
||||
int CANConfigFilter(const CAN_filter_t* p_filter);
|
||||
int CANWriteFrame(const CAN_frame_t* p_frame);
|
||||
bool CANWriteFrame(const CAN_frame_t* p_frame);
|
||||
int CANStop();
|
||||
void CANSetCfg(CAN_device_t* can_cfg);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue