diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-09-12 21:38:20 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-09-12 21:38:20 +0200 |
commit | dccb6a80f52aaf45facc6ef5f9660eb3fd3cb4ac (patch) | |
tree | 149d16faed5432190eaa6a19ea4f874cf7775b1b /src | |
parent | 59f550c510fec87fc871514b34b19f9afade956a (diff) | |
download | glutte-o-matic-dccb6a80f52aaf45facc6ef5f9660eb3fd3cb4ac.tar.gz glutte-o-matic-dccb6a80f52aaf45facc6ef5f9660eb3fd3cb4ac.tar.bz2 glutte-o-matic-dccb6a80f52aaf45facc6ef5f9660eb3fd3cb4ac.zip |
Add timeout for cw_audio_queue push and new fault
Diffstat (limited to 'src')
-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 |