From dccb6a80f52aaf45facc6ef5f9660eb3fd3cb4ac Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 12 Sep 2016 21:38:20 +0200 Subject: Add timeout for cw_audio_queue push and new fault --- src/common/includes/Core/common.h | 1 + src/common/src/Audio/cw.c | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/common/includes/Core/common.h b/src/common/includes/Core/common.h index 5703cbd..adf08ea 100644 --- a/src/common/includes/Core/common.h +++ b/src/common/includes/Core/common.h @@ -61,6 +61,7 @@ int random_bool(void); #define FAULT_SOURCE_I2C 3 #define FAULT_SOURCE_USART 4 #define FAULT_SOURCE_TASK_OVERFLOW 5 +#define FAULT_SOURCE_CW_AUDIO_QUEUE 6 void trigger_fault(int source); int find_last_sunday(const struct tm*); diff --git a/src/common/src/Audio/cw.c b/src/common/src/Audio/cw.c index ac6adaf..667d459 100644 --- a/src/common/src/Audio/cw.c +++ b/src/common/src/Audio/cw.c @@ -568,19 +568,20 @@ static void cw_psk31_task(void __attribute__ ((unused))*pvParameters) int16_t s = cw_generate_audio(omega, i, t); #endif - - if (buf_pos == AUDIO_BUF_LEN) { - xQueueSendToBack(cw_audio_queue, &cw_audio_buf, portMAX_DELAY); - buf_pos = 0; - } - cw_audio_buf[buf_pos++] = s; - // Stereo - if (buf_pos == AUDIO_BUF_LEN) { - xQueueSendToBack(cw_audio_queue, &cw_audio_buf, portMAX_DELAY); - buf_pos = 0; + for (int channel = 0; channel < 2; channel++) { + if (buf_pos == AUDIO_BUF_LEN) { + // It should take AUDIO_BUF_LEN/cw_psk31_samplerate seconds to send one buffer. + // If it takes more than 4 times as long, we think there is a problem. + const TickType_t reasonable_delay = pdMS_TO_TICKS(4000 * AUDIO_BUF_LEN / cw_psk31_samplerate); + if (xQueueSendToBack(cw_audio_queue, &cw_audio_buf, reasonable_delay) != pdTRUE) { + trigger_fault(FAULT_SOURCE_CW_AUDIO_QUEUE); + } + buf_pos = 0; + } + cw_audio_buf[buf_pos++] = s; } - cw_audio_buf[buf_pos++] = s; + } #if ENABLE_PSK31 -- cgit v1.2.3