From 07b589fe3f8aa165604d01ee1b44b9b1c530ac38 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 29 Jan 2019 21:58:35 +0100 Subject: [PATCH] 2400 baud optimisations --- device.h | 2 +- hardware/AFSK.c | 5 ++++- hardware/AFSK.h | 4 ++-- hardware/Serial.c | 9 --------- hardware/UserIO.c | 34 +++++++++++++++++++++++++++++++--- protocol/KISS.c | 36 +++++++++++++++++------------------- 6 files changed, 55 insertions(+), 35 deletions(-) diff --git a/device.h b/device.h index 3c4bd47..af08522 100755 --- a/device.h +++ b/device.h @@ -11,7 +11,7 @@ // Voltage references // TODO: Determine best defaults #define CONFIG_ADC_REF 255 -#define CONFIG_DAC_REF 255 +#define CONFIG_DAC_REF 128 // TODO: Change this back to default #define CONFIG_LED_INTENSITY 35 diff --git a/hardware/AFSK.c b/hardware/AFSK.c index eb8c1ed..bd2cd4d 100755 --- a/hardware/AFSK.c +++ b/hardware/AFSK.c @@ -601,8 +601,11 @@ void AFSK_adc_isr(Afsk *afsk, int8_t currentSample) { } +uint8_t timed_functions_timer = 0; inline void timed_functions(void) { - if (_clock % CLOCK_TICKS_PER_10_MS == 0) { + timed_functions_timer++; + if (timed_functions_timer >= CLOCK_TICKS_PER_10_MS) { + timed_functions_timer = 0; sd_scheduler(); } } diff --git a/hardware/AFSK.h b/hardware/AFSK.h index 5c6fae3..4c9d2c6 100755 --- a/hardware/AFSK.h +++ b/hardware/AFSK.h @@ -40,7 +40,7 @@ inline static uint8_t sinSample(uint16_t i) { #define CPU_FREQ F_CPU -#define BITRATE 2400 +#define BITRATE 1200 #if BITRATE == 300 #define CONFIG_ADC_SAMPLERATE 9600UL @@ -69,7 +69,7 @@ inline static uint8_t sinSample(uint16_t i) { #define CONFIG_AFSK_PREAMBLE_LEN 150UL #define CONFIG_AFSK_TRAILER_LEN 10UL #elif BITRATE == 2400 - #define CONFIG_AFSK_PREAMBLE_LEN 200UL + #define CONFIG_AFSK_PREAMBLE_LEN 230UL #define CONFIG_AFSK_TRAILER_LEN 25UL #endif diff --git a/hardware/Serial.c b/hardware/Serial.c index b94406d..1788f9c 100755 --- a/hardware/Serial.c +++ b/hardware/Serial.c @@ -52,15 +52,6 @@ ISR(USART0_RX_vect) { if (!fifo_isfull(&serialFIFO)) { char c = uart0_getchar_nowait(); fifo_push(&serialFIFO, c); - } else { - // TODO: Remove this - printf("SERIAL FIFO OVERRUN\r\n"); - printf("QH: %d", queue_height); - while(true) { - LED_TX_ON(); - LED_RX_ON(); - LED_COM_ON(); - } } } } diff --git a/hardware/UserIO.c b/hardware/UserIO.c index f4e8287..e02de1a 100644 --- a/hardware/UserIO.c +++ b/hardware/UserIO.c @@ -79,10 +79,38 @@ void usrio_4_off(void) { } void usrio_1_toggle(void) { - if (usrio_1()) { - usrio_1_off(); + if (!bluetooth_enabled()) { + if (usrio_1()) { + usrio_1_off(); + } else { + usrio_1_on(); + } + } +} + +void usrio_2_toggle(void) { + if (!bluetooth_enabled()) { + if (usrio_2()) { + usrio_2_off(); + } else { + usrio_2_on(); + } + } +} + +void usrio_3_toggle(void) { + if (usrio_3()) { + usrio_3_off(); } else { - usrio_1_on(); + usrio_3_on(); + } +} + +void usrio_4_toggle(void) { + if (usrio_4()) { + usrio_4_off(); + } else { + usrio_4_on(); } } diff --git a/protocol/KISS.c b/protocol/KISS.c index 3210c16..e8c6583 100755 --- a/protocol/KISS.c +++ b/protocol/KISS.c @@ -111,22 +111,22 @@ void kiss_csma(void) { } // TODO: Remove this -void kiss_flushQueueDebug(void) { - printf("Queue height %d\r\n", queue_height); - for (size_t n = 0; n < queue_height; n++) { - size_t start = fifo16_pop(&packet_starts); - size_t length = fifo16_pop(&packet_lengths); +// void kiss_flushQueueDebug(void) { +// printf("Queue height %d\r\n", queue_height); +// for (size_t n = 0; n < queue_height; n++) { +// size_t start = fifo16_pop(&packet_starts); +// size_t length = fifo16_pop(&packet_lengths); - printf("--- Packet %d, %d bytes ---\r\n", n+1, length); - for (size_t i = 0; i < length; i++) { - size_t pos = (start+i)%CONFIG_QUEUE_SIZE; - printf("%02x", packet_queue[pos]); - } - printf("\r\n\r\n"); - } - queue_height = 0; - queued_bytes = 0; -} +// printf("--- Packet %d, %d bytes ---\r\n", n+1, length); +// for (size_t i = 0; i < length; i++) { +// size_t pos = (start+i)%CONFIG_QUEUE_SIZE; +// printf("%02x", packet_queue[pos]); +// } +// printf("\r\n\r\n"); +// } +// queue_height = 0; +// queued_bytes = 0; +// } volatile bool queue_flushing = false; void kiss_flushQueue(void) { @@ -154,7 +154,6 @@ void kiss_flushQueue(void) { LED_RX_ON(); } } - //printf("Processed %d\r\n", processed); queue_height = 0; queued_bytes = 0; @@ -176,7 +175,6 @@ void kiss_serialCallback(uint8_t sbyte) { fifo16_push_locked(&packet_lengths, l); current_packet_start = queue_cursor; - printf("Queue height %d\r\n", queue_height); } } else if (sbyte == FEND) { @@ -217,8 +215,8 @@ void kiss_serialCallback(uint8_t sbyte) { } else if (command == CMD_FLUSHQUEUE) { kiss_flushQueue(); // TODO: Remove this - } else if (command == CMD_FLUSHQUEUE_DEBUG) { - kiss_flushQueueDebug(); + //} else if (command == CMD_FLUSHQUEUE_DEBUG) { + // kiss_flushQueueDebug(); } else if (command == CMD_LED_INTENSITY) { if (sbyte == FESC) { ESCAPE = true;