Skip to content
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

Soft 389 can rx polling #289

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions libraries/ms-common/src/x86/can_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#define CAN_HW_DEV_INTERFACE "vcan0"
#define CAN_HW_MAX_FILTERS 14
#define CAN_HW_TX_FIFO_LEN 8
// Check for thread exit once every 10ms
#define CAN_HW_THREAD_EXIT_PERIOD_US 10000
// Check for thread exit once every 100ms
#define CAN_HW_THREAD_EXIT_PERIOD_US 100000

typedef struct CanHwEventHandler {
CanHwEventHandlerCb callback;
Expand Down Expand Up @@ -80,6 +80,8 @@ static void *prv_rx_thread(void *arg) {

select(s_socket_data.can_fd + 1, &input_fds, NULL, NULL, &timeout);

timeout.tv_usec = CAN_HW_THREAD_EXIT_PERIOD_US;

if (FD_ISSET(s_socket_data.can_fd, &input_fds)) {
int bytes =
read(s_socket_data.can_fd, &s_socket_data.rx_frame, sizeof(s_socket_data.rx_frame));
Expand All @@ -89,8 +91,6 @@ static void *prv_rx_thread(void *arg) {
s_socket_data.handlers[CAN_HW_EVENT_TX_READY].context);
}

// Wakes the main thread
x86_interrupt_wake();
// Limit how often we can receive messages to simulate bus speed
usleep(s_socket_data.delay_us);
}
Expand All @@ -112,7 +112,7 @@ static void *prv_tx_thread(void *arg) {
while (pthread_mutex_trylock(&s_keep_alive) != 0) {
// Wait until the producer has created an item
sem_wait(&s_tx_sem);
x86_interrupt_wake();

fifo_pop(&s_socket_data.tx_fifo, &frame);
int bytes = write(s_socket_data.can_fd, &frame, sizeof(frame));

Expand Down Expand Up @@ -145,6 +145,7 @@ StatusCode can_hw_init(const CanHwSettings *settings) {
sem_post(&s_tx_sem);

sem_destroy(&s_tx_sem);

pthread_join(s_tx_pthread_id, NULL);
}

Expand Down Expand Up @@ -255,7 +256,6 @@ StatusCode can_hw_transmit(uint32_t id, bool extended, const uint8_t *data, size
}
// Unblock TX thread
sem_post(&s_tx_sem);

return STATUS_CODE_OK;
}

Expand Down
6 changes: 3 additions & 3 deletions libraries/ms-common/src/x86/wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <signal.h>

void wait(void) {
sigset_t s_wait_sigset;
sigset_t wait_sigset;

sigemptyset(&s_wait_sigset);
sigsuspend(&s_wait_sigset);
sigemptyset(&wait_sigset);
sigsuspend(&wait_sigset);
}