Skip to content

Commit cf7a166

Browse files
committed
projects/freertos: Use a global queue for cmd channels
The current implementation of changing the first argument to cmd_channel_freertos_receive_packet()/cmd_channel_freertos_send_packet() from a struct *cmd_channel (passed from cmd_channel_receive_and_process()) to a QueueHandle_t results in seg faults. Instead let's create a global queue that can be accessed from anywhere to allow data to be stored. 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 <[email protected]>
1 parent 769050d commit cf7a166

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

projects/freertos/cmd_channel_freertos.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "cmd_channel_freertos.h"
66
#include "task.h"
77

8-
98
/**
109
* Receive a packet from a command channel.
1110
*
@@ -16,7 +15,7 @@
1615
*
1716
* @return 0 if a packet was successfully received or an error code.
1817
*/
19-
int cmd_channel_freertos_receive_packet (QueueHandle_t rx_queue, struct cmd_packet *packet,
18+
int cmd_channel_freertos_receive_packet (struct cmd_channel *channel, struct cmd_packet *packet,
2019
int ms_timeout)
2120
{
2221
TickType_t timeout = (ms_timeout < 0) ? portMAX_DELAY : pdMS_TO_TICKS (ms_timeout);
@@ -26,7 +25,7 @@ int cmd_channel_freertos_receive_packet (QueueHandle_t rx_queue, struct cmd_pack
2625
return CMD_CHANNEL_INVALID_ARGUMENT;
2726
}
2827

29-
status = xQueueReceive (rx_queue, packet, timeout);
28+
status = xQueueReceive (I2CRequestQueue, packet, timeout);
3029
if (status == pdFALSE) {
3130
return CMD_CHANNEL_RX_TIMEOUT;
3231
}
@@ -44,7 +43,7 @@ int cmd_channel_freertos_receive_packet (QueueHandle_t rx_queue, struct cmd_pack
4443
*
4544
* @return 0 if the packet was successfully queued or an error code.
4645
*/
47-
int cmd_channel_freertos_send_packet (QueueHandle_t tx_queue, struct cmd_packet *packet,
46+
int cmd_channel_freertos_send_packet (struct cmd_channel *channel, struct cmd_packet *packet,
4847
int ms_timeout)
4948
{
5049
TickType_t timeout = (ms_timeout < 0) ? portMAX_DELAY : pdMS_TO_TICKS (ms_timeout);
@@ -54,7 +53,7 @@ int cmd_channel_freertos_send_packet (QueueHandle_t tx_queue, struct cmd_packet
5453
return CMD_CHANNEL_INVALID_ARGUMENT;
5554
}
5655

57-
status = xQueueSendToBack (tx_queue, packet, timeout);
56+
status = xQueueSendToBack (I2CResponseQueue, packet, timeout);
5857
if (status == pdFALSE) {
5958
return CMD_CHANNEL_TX_TIMEOUT;
6059
}

projects/freertos/cmd_channel_freertos.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
#include "queue.h"
99
#include "cmd_interface/cmd_channel.h"
1010

11+
extern QueueHandle_t I2CRequestQueue;
12+
extern QueueHandle_t I2CResponseQueue;
1113

12-
int cmd_channel_freertos_receive_packet (QueueHandle_t rx_queue, struct cmd_packet *packet,
14+
int cmd_channel_freertos_receive_packet (struct cmd_channel *channel, struct cmd_packet *packet,
1315
int ms_timeout);
14-
int cmd_channel_freertos_send_packet (QueueHandle_t tx_queue, struct cmd_packet *packet,
16+
int cmd_channel_freertos_send_packet (struct cmd_channel *channel, struct cmd_packet *packet,
1517
int ms_timeout);
1618

1719

0 commit comments

Comments
 (0)