Skip to content

Commit

Permalink
Merge pull request #6 from geappliances/add-packet-queue-for-gea2
Browse files Browse the repository at this point in the history
Add packet queue support to gea2 interface
  • Loading branch information
ryanplusplus authored Dec 15, 2024
2 parents c685f54 + 63aa8c6 commit 7d8bee5
Showing 5 changed files with 386 additions and 302 deletions.
96 changes: 47 additions & 49 deletions include/tiny_gea2_interface.h
Original file line number Diff line number Diff line change
@@ -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.
@@ -28,71 +23,74 @@
#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_group_t* queue_timer_group;
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,
tiny_timer_group_t* timer_group,
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
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
"maintainer": true
}
],
"version": "1.0.1",
"version": "2.0.0",
"frameworks": "*",
"platforms": "*",
"export": {
@@ -25,7 +25,7 @@
"dependencies": [
{
"name": "tiny",
"version": "^6.4.1"
"version": "^6.4.7"
}
]
}
Loading

0 comments on commit 7d8bee5

Please sign in to comment.