Skip to content

Commit

Permalink
adding uart device parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
tanneberger committed Jan 22, 2025
1 parent b98efc4 commit 14dfa43
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions include/reactor-uc/network_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ struct NetworkChannel {
struct SyncNetworkChannel {
NetworkChannel super;

/**
* @brief Polls for new data and calls the callback handler if a message is successfully decoded
*/
void (*poll)(NetworkChannel *self);
};

Expand Down
4 changes: 2 additions & 2 deletions include/reactor-uc/platform/riot/uart_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ struct UARTAsyncChannel {
cond_t receive_cv;
};

void UARTSyncChannel_ctor(UARTSyncChannel *self, Environment *env, uint32_t baud);
void UARTSyncChannel_ctor(UARTSyncChannel *self, Environment *env, uint32_t uart_device, uint32_t baud);

void UARTAsyncChannel_ctor(UARTAsyncChannel *self, Environment *env, uint32_t baud);
void UARTAsyncChannel_ctor(UARTAsyncChannel *self, Environment *env, uint32_t uart_device, uint32_t baud);

#endif
3 changes: 2 additions & 1 deletion include/reactor-uc/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
(tag_t) { .time = FOREVER, .microstep = FOREVER_MICROSTEP }
// Need a separate initializer expression to comply with some C compilers
#define FOREVER_TAG_INITIALIZER {FOREVER, FOREVER_MICROSTEP}
#define ZERO_TAG (tag_t){.time = 0LL, .microstep = 0u}
#define ZERO_TAG \
(tag_t) { .time = 0LL, .microstep = 0u }

// Returns true if timeout has elapsed.
#define CHECK_TIMEOUT(start, duration) (lf_time_physical() > ((start) + (duration)))
Expand Down
10 changes: 6 additions & 4 deletions src/platform/riot/uart_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,18 @@ void *_UARTAsyncChannel_decode_loop(void *arg) {
cond_wait(&self->receive_cv, &self->receive_lock);

UARTSyncChannel_poll((NetworkChannel *)&self->super);

thread_yield_higher();
}

return NULL;
}

void UARTSyncChannel_ctor(UARTSyncChannel *self, Environment *env, uint32_t baud) {
void UARTSyncChannel_ctor(UARTSyncChannel *self, Environment *env, uint32_t uart_device, uint32_t baud) {
assert(self != NULL);
assert(env != NULL);

self->uart_dev = UART_DEV(0);
self->uart_dev = UART_DEV(uart_device);

int result = uart_init(self->uart_dev, baud, _UARTSyncChannel_receive_callback, self);

Expand Down Expand Up @@ -144,8 +146,8 @@ void UARTSyncChannel_ctor(UARTSyncChannel *self, Environment *env, uint32_t baud
self->state = NETWORK_CHANNEL_STATE_CONNECTED;
}

void UARTAsyncChannel_ctor(UARTAsyncChannel *self, Environment *env, uint32_t baud) {
UARTSyncChannel_ctor(&self->super, env, baud);
void UARTAsyncChannel_ctor(UARTAsyncChannel *self, Environment *env, uint32_t uart_device, uint32_t baud) {
UARTSyncChannel_ctor(&self->super, env, uart_device, baud);

cond_init(&self->receive_cv);
mutex_init(&self->receive_lock);
Expand Down

0 comments on commit 14dfa43

Please sign in to comment.