From 8bed903557e598d3bfcbab8ceb1e706f0b4f18e1 Mon Sep 17 00:00:00 2001 From: swappad Date: Fri, 14 May 2021 17:26:03 +0200 Subject: [PATCH 1/3] uart tx ready fix; check if queue empty before immediate write to register --- uart.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/uart.c b/uart.c index 988a5dd..1261e30 100644 --- a/uart.c +++ b/uart.c @@ -17,7 +17,7 @@ #define SINGLE_UART 1 #endif -#define RING_BUFFER_SIZE 64 +#define RING_BUFFER_SIZE 128 #define MIN_U2X_BAUD (F_CPU/(16*(255 + 1)) + 1) @@ -120,11 +120,12 @@ void uart_send_byte(uint8_t id, uint8_t data) { #if SINGLE_UART id = 0; #endif - if (instances[id].ready) { // Can send directly - instances[id].ready = false; + if (instances[id].ready && (instances[id].head == instances[id].tail)) { // Can send directly + // instances[id].ready = false; // Luca: indicate queue not empty *instances[id].udr = data; } else if (instances[id].tail != instances[id].head || !instances[id].full) { // Not empty but needs to be added to queue + instances[id].ready = false; // Luca: indicate queue not empty instances[id].data[instances[id].head] = data; instances[id].head = (instances[id].head + 1) % RING_BUFFER_SIZE; if (instances[id].tail == instances[id].head) { From c81c288d021f13fd3fe401f892083bb5e8c38dd0 Mon Sep 17 00:00:00 2001 From: swappad Date: Wed, 19 May 2021 21:18:56 +0200 Subject: [PATCH 2/3] =?UTF-8?q?falsch=20auskommentiert=20r=C3=BCckg=C3=A4n?= =?UTF-8?q?gig=20gemacht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uart.c b/uart.c index 1261e30..5ff6651 100644 --- a/uart.c +++ b/uart.c @@ -121,7 +121,7 @@ void uart_send_byte(uint8_t id, uint8_t data) { id = 0; #endif if (instances[id].ready && (instances[id].head == instances[id].tail)) { // Can send directly - // instances[id].ready = false; // Luca: indicate queue not empty + instances[id].ready = false; // Luca: indicate queue not empty *instances[id].udr = data; } else if (instances[id].tail != instances[id].head || !instances[id].full) { // Not empty but needs to be added to queue From 737f3d4f42e1dc6879045bf095076fc37feb6040 Mon Sep 17 00:00:00 2001 From: Luca <6180505+swappad@users.noreply.github.com> Date: Thu, 20 May 2021 11:09:15 +0200 Subject: [PATCH 3/3] Update uart.c remove comment --- uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uart.c b/uart.c index 5ff6651..fc27689 100644 --- a/uart.c +++ b/uart.c @@ -121,7 +121,7 @@ void uart_send_byte(uint8_t id, uint8_t data) { id = 0; #endif if (instances[id].ready && (instances[id].head == instances[id].tail)) { // Can send directly - instances[id].ready = false; // Luca: indicate queue not empty + instances[id].ready = false; *instances[id].udr = data; } else if (instances[id].tail != instances[id].head || !instances[id].full) { // Not empty but needs to be added to queue