diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/includes/Core/common.h | 1 | ||||
-rw-r--r-- | 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 |