From 0271943f511eb30661831ee5581655c326b3f78d Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Tue, 11 May 2021 15:41:16 +1000 Subject: [PATCH] freertos: cmd_channel: Add a default send/receive Add a default send and receive function that can be used. Currently cmd_channel_freertos.c includes a receive and send function, but these can't directly be called from struct cmd_channel. Let's add default implementations that can be used. The queue being global allows it to be accessed from interrupt service routines (ISRs) which is generally where the data will be processed, at least for receives. Signed-off-by: Alistair Francis --- projects/freertos/cmd_channel_freertos.c | 47 ++++++++++++++++++++++++ projects/freertos/cmd_channel_freertos.h | 3 ++ 2 files changed, 50 insertions(+) diff --git a/projects/freertos/cmd_channel_freertos.c b/projects/freertos/cmd_channel_freertos.c index ed9ef0f3..1513a693 100644 --- a/projects/freertos/cmd_channel_freertos.c +++ b/projects/freertos/cmd_channel_freertos.c @@ -61,3 +61,50 @@ int cmd_channel_freertos_send_packet (QueueHandle_t tx_queue, struct cmd_packet return 0; } + +/** + * Receive a command packet from a communication channel. + * This is an implementation of the receive_packet() function for + * the struct cmd_channel and uses the global I2CRequestQueue. + * + * @param channel The channel to receive a packet from. + * @param packet Output for the packet data being received. + * @param ms_timeout The amount of time to wait for a received packet, in milliseconds. A + * negative value will wait forever, and a value of 0 will return immediately. + * + * @return 0 if a packet was successfully received or an error code. + */ +static int cmd_channel_receive_packet (struct cmd_channel *channel, + struct cmd_packet *packet, int ms_timeout) +{ + return cmd_channel_freertos_receive_packet(I2CRequestQueue, packet, + ms_timeout); +} + +/** + * Send a command packet over a communication channel. + * This is an implementation of the send_packet() function for + * the struct cmd_channel and uses the global I2CResponseQueue. + * + * @param channel The channel to send a packet on. + * @param packet The packet to send. + * + * @return 0 if the the packet was successfully sent or an error code. + */ +static int cmd_channel_send_packet (struct cmd_channel *channel, + struct cmd_packet *packet) +{ + return cmd_channel_freertos_send_packet(I2CResponseQueue, packet, 0); +} + +/** + * Set the default receive_packet and send_packet function hooks. + * These use the global I2CRequestQueue and I2CResponseQueue. + * + * @param channel The channel to initialise. + */ +void cmd_channel_packet_default_init (struct cmd_channel *channel) +{ + channel->receive_packet = cmd_channel_receive_packet; + channel->send_packet = cmd_channel_send_packet; +} diff --git a/projects/freertos/cmd_channel_freertos.h b/projects/freertos/cmd_channel_freertos.h index e18fd212..768e030d 100644 --- a/projects/freertos/cmd_channel_freertos.h +++ b/projects/freertos/cmd_channel_freertos.h @@ -8,11 +8,14 @@ #include "queue.h" #include "cmd_interface/cmd_channel.h" +extern QueueHandle_t I2CRequestQueue; +extern QueueHandle_t I2CResponseQueue; int cmd_channel_freertos_receive_packet (QueueHandle_t rx_queue, struct cmd_packet *packet, int ms_timeout); int cmd_channel_freertos_send_packet (QueueHandle_t tx_queue, struct cmd_packet *packet, int ms_timeout); +void cmd_channel_packet_default_init (struct cmd_channel *channel); #endif /* CMD_CHANNEL_FREERTOS_H_ */