Skip to content

Add feature: Can specify the time to wait for the write to complete #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/CAN.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,20 @@ int CAN_write_frame(const CAN_frame_t *p_frame) {
return 0;
}

int CAN_write_frame_timeout(const CAN_frame_t *p_frame, int waitTicks) {
if (sem_tx_complete == NULL) {
return -1;
}

// Write the frame to the controller
CAN_write_frame_phy(p_frame);

// wait for the frame tx to complete
xSemaphoreTake(sem_tx_complete, waitTicks);

return 0;
}

int CAN_stop() {
// enter reset mode
MODULE_CAN->MOD.B.RM = 1;
Expand Down
9 changes: 9 additions & 0 deletions src/CAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ int CAN_init(void);
*/
int CAN_write_frame(const CAN_frame_t *p_frame);

/**
* \brief Send a can frame
*
* \param p_frame Pointer to the frame to be send, see #CAN_frame_t
* \param waitTicks Wait for write completion ticks
* \return 0 Frame has been written to the module
*/
int CAN_write_frame_timeout(const CAN_frame_t *p_frame, int waitTicks);

/**
* \brief Stops the CAN Module
*
Expand Down
5 changes: 5 additions & 0 deletions src/ESP32CAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ int ESP32CAN::CANWriteFrame(const CAN_frame_t* p_frame)
{
return CAN_write_frame(p_frame);
}

int ESP32CAN::CANWriteFrame(const CAN_frame_t *p_frame, int waitMs) {
return CAN_write_frame_timeout(p_frame, waitMs * portTICK_PERIOD_MS);
}

int ESP32CAN::CANStop()
{
return CAN_stop();
Expand Down
1 change: 1 addition & 0 deletions src/ESP32CAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ESP32CAN
int CANInit();
int CANConfigFilter(const CAN_filter_t* p_filter);
int CANWriteFrame(const CAN_frame_t* p_frame);
int CANWriteFrame(const CAN_frame_t* p_frame, int waitMs);
int CANStop();
};

Expand Down