Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate send buffer for gea interfaces #7

Merged
merged 11 commits into from
Dec 17, 2024
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
add_library(tiny_gea3 INTERFACE)

target_sources(tiny_gea3 INTERFACE
${CMAKE_CURRENT_LIST_DIR}/src/tiny_erd_client.c
${CMAKE_CURRENT_LIST_DIR}/src/tiny_gea3_interface.c
${CMAKE_CURRENT_LIST_DIR}/src/tiny_gea2_erd_client.c
${CMAKE_CURRENT_LIST_DIR}/src/tiny_gea3_erd_client.c
${CMAKE_CURRENT_LIST_DIR}/src/tiny_gea2_interface.c
${CMAKE_CURRENT_LIST_DIR}/src/tiny_gea3_interface.c
)

target_include_directories(tiny_gea3 INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
Expand Down
18 changes: 7 additions & 11 deletions include/tiny_gea2_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,16 @@ typedef struct
struct
{
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;
volatile bool in_progress; // Set and cleared by the non-ISR, read by the ISR
volatile bool completed; // Set by ISR, cleared by non-ISR
volatile bool packet_queued_in_background; // Set by ISR, cleared by non-ISR
uint8_t expected_reflection;
uint8_t retries;
uint8_t data_length;
} send;

struct
Expand All @@ -76,15 +74,13 @@ typedef struct
void tiny_gea2_interface_init(
tiny_gea2_interface_t* self,
i_tiny_uart_t* uart,
tiny_timer_group_t* timer_group,
i_tiny_time_source_t* time_source,
i_tiny_event_t* msec_interrupt,
uint8_t address,
uint8_t* send_buffer,
uint8_t send_buffer_size,
uint8_t* receive_buffer,
uint8_t receive_buffer_size,
uint8_t* send_queue_buffer,
size_t send_queue_buffer_size,
uint8_t* receive_buffer,
uint8_t receive_buffer_size,
bool ignore_destination_address,
uint8_t retries);

Expand Down
14 changes: 6 additions & 8 deletions include/tiny_gea3_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ typedef struct {
tiny_event_subscription_t byte_received_subscription;
tiny_event_subscription_t byte_sent_subscription;
i_tiny_uart_t* uart;
uint8_t* send_buffer;
uint8_t* receive_buffer;

tiny_queue_t send_queue;
Expand All @@ -38,13 +37,14 @@ typedef struct {

uint8_t address;

uint8_t send_buffer_size;
uint8_t send_offset;
volatile bool send_in_progress;
uint8_t send_data_length;
volatile bool send_in_progress; // Set and cleared by the non-ISR, read by the ISR
volatile bool send_completed; // Set by ISR, cleared by non-ISR

uint8_t receive_buffer_size;
uint8_t receive_count;
volatile bool receive_packet_ready; // Set by ISR, cleared by background
volatile bool receive_packet_ready; // Set by ISR, cleared by non-ISR

uint8_t send_state;
bool send_escaped;
Expand All @@ -61,12 +61,10 @@ void tiny_gea3_interface_init(
tiny_gea3_interface_t* self,
i_tiny_uart_t* uart,
uint8_t address,
uint8_t* send_buffer,
uint8_t send_buffer_size,
uint8_t* receive_buffer,
uint8_t receive_buffer_size,
uint8_t* send_queue_buffer,
size_t send_queue_buffer_size,
uint8_t* receive_buffer,
uint8_t receive_buffer_size,
bool ignore_destination_address);

/*!
Expand Down
2 changes: 1 addition & 1 deletion lib/tiny
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"maintainer": true
}
],
"version": "2.0.1",
"version": "3.0.0",
"frameworks": "*",
"platforms": "*",
"export": {
Expand All @@ -25,7 +25,7 @@
"dependencies": [
{
"name": "tiny",
"version": "^6.4.7"
"version": "^7.0.1"
}
]
}
12 changes: 6 additions & 6 deletions src/tiny_gea2_erd_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static void send_write_request_worker(void* context, tiny_gea_packet_t* packet)
reinterpret(payload, packet->payload, tiny_gea2_erd_api_write_request_payload_t*);

write_request_t request;
tiny_queue_peek_partial(&self->request_queue, &request, sizeof(request), 0);
tiny_queue_peek_partial(&self->request_queue, &request, sizeof(request), 0, 0);

uint16_t size;
tiny_queue_peek(&self->request_queue, packet->payload, &size, 0);
Expand All @@ -106,7 +106,7 @@ static void send_write_request_worker(void* context, tiny_gea_packet_t* packet)
static void send_write_request(self_t* self)
{
write_request_t request;
tiny_queue_peek_partial(&self->request_queue, &request, sizeof(request), 0);
tiny_queue_peek_partial(&self->request_queue, &request, sizeof(request), 0, 0);

tiny_gea_interface_send(
self->gea2_interface,
Expand Down Expand Up @@ -150,7 +150,7 @@ static request_type_t request_type(self_t* self)
{
if(request_pending(self)) {
request_t request;
tiny_queue_peek_partial(&self->request_queue, &request, sizeof(request), 0);
tiny_queue_peek_partial(&self->request_queue, &request, sizeof(request), 0, 0);
return request.type;
}
else {
Expand Down Expand Up @@ -234,7 +234,7 @@ static void handle_write_failure_worker(void* _context, void* allocated_block)
static void handle_write_failure(self_t* self)
{
write_request_t request;
tiny_queue_peek_partial(&self->request_queue, &request, offsetof(write_request_t, data), 0);
tiny_queue_peek_partial(&self->request_queue, &request, offsetof(write_request_t, data), 0, 0);

tiny_stack_allocator_allocate_aligned(request.data_size + offsetof(write_request_t, data), self, handle_write_failure_worker);
}
Expand Down Expand Up @@ -267,7 +267,7 @@ static void handle_read_response_packet(self_t* self, const tiny_gea_packet_t* p
{
if(request_type(self) == request_type_read) {
read_request_t request;
tiny_queue_peek_partial(&self->request_queue, &request, sizeof(request), 0);
tiny_queue_peek_partial(&self->request_queue, &request, sizeof(request), 0, 0);

if(packet->payload_length >= sizeof(tiny_gea2_erd_api_read_response_payload_t)) {
reinterpret(payload, packet->payload, const tiny_gea2_erd_api_read_response_payload_t*);
Expand Down Expand Up @@ -323,7 +323,7 @@ static void handle_write_response_packet(self_t* self, const tiny_gea_packet_t*
{
if(request_type(self) == request_type_write) {
write_request_t request;
tiny_queue_peek_partial(&self->request_queue, &request, offsetof(write_request_t, data), 0);
tiny_queue_peek_partial(&self->request_queue, &request, offsetof(write_request_t, data), 0, 0);

if(packet->payload_length == sizeof(tiny_gea2_erd_api_write_response_payload_t)) {
reinterpret(payload, packet->payload, const tiny_gea2_erd_api_write_response_payload_t*);
Expand Down
Loading
Loading