Skip to content

Commit 0271943

Browse files
committed
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 <alistair.francis@wdc.com>
1 parent 2894b59 commit 0271943

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

projects/freertos/cmd_channel_freertos.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,50 @@ int cmd_channel_freertos_send_packet (QueueHandle_t tx_queue, struct cmd_packet
6161

6262
return 0;
6363
}
64+
65+
/**
66+
* Receive a command packet from a communication channel.
67+
* This is an implementation of the receive_packet() function for
68+
* the struct cmd_channel and uses the global I2CRequestQueue.
69+
*
70+
* @param channel The channel to receive a packet from.
71+
* @param packet Output for the packet data being received.
72+
* @param ms_timeout The amount of time to wait for a received packet, in milliseconds. A
73+
* negative value will wait forever, and a value of 0 will return immediately.
74+
*
75+
* @return 0 if a packet was successfully received or an error code.
76+
*/
77+
static int cmd_channel_receive_packet (struct cmd_channel *channel,
78+
struct cmd_packet *packet, int ms_timeout)
79+
{
80+
return cmd_channel_freertos_receive_packet(I2CRequestQueue, packet,
81+
ms_timeout);
82+
}
83+
84+
/**
85+
* Send a command packet over a communication channel.
86+
* This is an implementation of the send_packet() function for
87+
* the struct cmd_channel and uses the global I2CResponseQueue.
88+
*
89+
* @param channel The channel to send a packet on.
90+
* @param packet The packet to send.
91+
*
92+
* @return 0 if the the packet was successfully sent or an error code.
93+
*/
94+
static int cmd_channel_send_packet (struct cmd_channel *channel,
95+
struct cmd_packet *packet)
96+
{
97+
return cmd_channel_freertos_send_packet(I2CResponseQueue, packet, 0);
98+
}
99+
100+
/**
101+
* Set the default receive_packet and send_packet function hooks.
102+
* These use the global I2CRequestQueue and I2CResponseQueue.
103+
*
104+
* @param channel The channel to initialise.
105+
*/
106+
void cmd_channel_packet_default_init (struct cmd_channel *channel)
107+
{
108+
channel->receive_packet = cmd_channel_receive_packet;
109+
channel->send_packet = cmd_channel_send_packet;
110+
}

projects/freertos/cmd_channel_freertos.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
#include "queue.h"
99
#include "cmd_interface/cmd_channel.h"
1010

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

1214
int cmd_channel_freertos_receive_packet (QueueHandle_t rx_queue, struct cmd_packet *packet,
1315
int ms_timeout);
1416
int cmd_channel_freertos_send_packet (QueueHandle_t tx_queue, struct cmd_packet *packet,
1517
int ms_timeout);
1618

19+
void cmd_channel_packet_default_init (struct cmd_channel *channel);
1720

1821
#endif /* CMD_CHANNEL_FREERTOS_H_ */

0 commit comments

Comments
 (0)