Skip to content

Commit

Permalink
Add packet queue support to gea2 interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanplusplus committed Dec 14, 2024
1 parent c685f54 commit 853925f
Show file tree
Hide file tree
Showing 4 changed files with 370 additions and 290 deletions.
93 changes: 45 additions & 48 deletions include/tiny_gea2_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
* @file
* @brief
*
* This component is interrupt-aware and handles byte transmit/receive in the
* interrupt context. Publication of messages is done via a background task in
* tiny_gea2_interface_run() so the application does not have to do
* anything special.
*
* Additionally, this component does not do any queueing of packets. If a send
* is in progress and another message is sent, then the currently sending message
* is discarded. In order to prevent this, clients can check whether the interface
* is currently sending and wait before attempting to send a packet.
* This component is interrupt-aware and safely handles byte transmit/receive in
* an interrupt context. Publication of messages is done via a background task in
* tiny_gea2_interface_run() so the application does not have to do anything
* special to maintain context safety when receiving packets.
*
* If a message is received, all messages received after will be dropped until
* tiny_gea2_interface_run() is called.
Expand All @@ -28,71 +23,73 @@
#include "tiny_crc16.h"
#include "tiny_event.h"
#include "tiny_fsm.h"
#include "tiny_queue.h"
#include "tiny_timer.h"

typedef struct
{
i_tiny_gea_interface_t interface;

tiny_fsm_t fsm;
tiny_event_t on_receive;
tiny_event_t on_diagnostics_event;
tiny_event_subscription_t msec_interrupt_subscription;
tiny_event_subscription_t byte_received_subscription;
i_tiny_uart_t* uart;
tiny_timer_t timer;
uint8_t address;
bool ignore_destination_address;
uint8_t retries;
tiny_timer_group_t timer_group;

struct
{
tiny_fsm_t fsm;
tiny_event_t on_receive;
tiny_event_t on_diagnostics_event;
tiny_event_subscription_t msec_interrupt_subscription;
tiny_event_subscription_t byte_received_subscription;
i_tiny_uart_t* uart;
tiny_timer_t timer;
uint8_t address;
bool ignore_destination_address;
tiny_queue_t queue;
tiny_timer_t queue_timer;
uint8_t* buffer;
uint8_t buffer_size;
uint8_t state;
uint8_t offset;
uint16_t crc;
bool escaped;
volatile bool active;
volatile bool packet_queued_in_background;
uint8_t expected_reflection;
uint8_t retries;
tiny_timer_group_t timer_group;

struct
{
uint8_t* buffer;
uint8_t buffer_size;
uint8_t state;
uint8_t offset;
uint16_t crc;
bool escaped;
volatile bool active;
volatile bool packet_queued_in_background;
uint8_t expected_reflection;
uint8_t retries;
} send;
} send;

struct
{
uint8_t* buffer;
uint16_t crc;
uint8_t buffer_size;
uint8_t count;
bool escaped;
volatile bool packet_ready;
} receive;
} _private;
struct
{
uint8_t* buffer;
uint16_t crc;
uint8_t buffer_size;
uint8_t count;
bool escaped;
volatile bool packet_ready;
} receive;
} tiny_gea2_interface_t;

/*!
* Initialize a GEA2 interface.
*/
void tiny_gea2_interface_init(
tiny_gea2_interface_t* instance,
tiny_gea2_interface_t* self,
i_tiny_uart_t* uart,
i_tiny_time_source_t* time_source,
i_tiny_event_t* msec_interrupt,
uint8_t* receive_buffer,
uint8_t receive_buffer_size,
uint8_t address,
uint8_t* send_buffer,
uint8_t send_buffer_size,
uint8_t address,
uint8_t* receive_buffer,
uint8_t receive_buffer_size,
uint8_t* send_queue_buffer,
size_t send_queue_buffer_size,
bool ignore_destination_address,
uint8_t retries);

/*!
* Run the interface and publish received packets.
*/
void tiny_gea2_interface_run(tiny_gea2_interface_t* instance);
void tiny_gea2_interface_run(tiny_gea2_interface_t* self);

#endif
Loading

0 comments on commit 853925f

Please sign in to comment.