diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-12-06 23:38:02 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-12-06 23:38:02 +0100 |
commit | 8b44ef31f8c8520b9da03d7f7f5c91e86b6eb09f (patch) | |
tree | dbab60a2fea745280c382833e7d141a50386ce28 /src | |
parent | 8fc986d443a4ed9656d3c9479841de3e49d1abe4 (diff) | |
download | glutte-o-matic-8b44ef31f8c8520b9da03d7f7f5c91e86b6eb09f.tar.gz glutte-o-matic-8b44ef31f8c8520b9da03d7f7f5c91e86b6eb09f.tar.bz2 glutte-o-matic-8b44ef31f8c8520b9da03d7f7f5c91e86b6eb09f.zip |
Fix interrupt prio, add tone test
Diffstat (limited to 'src')
-rw-r--r-- | src/cw-example/audio.c | 2 | ||||
-rw-r--r-- | src/cw-example/cw.c | 37 | ||||
-rw-r--r-- | src/cw-example/main.c | 57 |
3 files changed, 59 insertions, 37 deletions
diff --git a/src/cw-example/audio.c b/src/cw-example/audio.c index 1f16edc..752ad12 100644 --- a/src/cw-example/audio.c +++ b/src/cw-example/audio.c @@ -176,7 +176,7 @@ void PlayAudioWithCallback(AudioCallbackFunction *callback, void *context) { StopAudioDMA(); NVIC_EnableIRQ(DMA1_Stream7_IRQn); - NVIC_SetPriority(DMA1_Stream7_IRQn, 4); + NVIC_SetPriority(DMA1_Stream7_IRQn, 5); SPI3 ->CR2 |= SPI_CR2_TXDMAEN; // Enable I2S TX DMA request. diff --git a/src/cw-example/cw.c b/src/cw-example/cw.c index 23f8717..6722c0a 100644 --- a/src/cw-example/cw.c +++ b/src/cw-example/cw.c @@ -199,11 +199,11 @@ void cw_push_message(const char* text, int dit_duration, int frequency) xQueueSendToBack(cw_queue, &msg, 0); /* Send Message */ } - size_t cw_fill_buffer(int16_t *buf, size_t bufsize) { if (cw_fill_msg_status == 0) { - if (xQueueReceiveFromISR(cw_queue, &cw_fill_msg_current, NULL)) { + if (uxQueueMessagesWaitingFromISR(cw_queue) > 0 && + xQueueReceiveFromISR(cw_queue, &cw_fill_msg_current, NULL)) { // Convert msg to audio samples and transmit cw_fill_msg_status = 1; cw_fill_audio_sent = 0; @@ -213,36 +213,40 @@ size_t cw_fill_buffer(int16_t *buf, size_t bufsize) } } +#if 0 const int samples_per_dit = (cw_samplerate * 1000) / cw_fill_msg_current.dit_duration; // Angular frequency of NCO - const float omega = 2 * FLOAT_PI * cw_fill_msg_current.freq / + const float omega = 2.0f * FLOAT_PI * cw_fill_msg_current.freq / (float)cw_samplerate; // Define start point int start_i = cw_fill_audio_sent / samples_per_dit; int start_t = cw_fill_audio_sent % samples_per_dit; + int pos = 0; + for (int i = start_i; i < cw_fill_msg_current.on_buffer_end; i++) { for (int t = start_t; t < samples_per_dit; t++) { int16_t s = 0; + int16_t dat[] = {0, 3000, 6000, 12000, 16000, 12000, 6000, 3000, + 0, -3000, -6000, -12000, -16000, -12000, -6000, -3000}; + if (cw_fill_msg_current.on_buffer[i]) { - s = 32768.0f * arm_sin_f32(omega * t); + //s = 32768.0f * arm_sin_f32(omega * t); + s = dat[t % 16]; } - if (i + 2 >= bufsize) { + if (pos + 2 >= bufsize) { goto cw_fill_buf_full; } // Stereo - buf[i++] = s; - buf[i++] = s; - - OutputAudioSample(s); - OutputAudioSample(s); + buf[pos++] = s; + buf[pos++] = s; cw_fill_audio_sent += 2; } @@ -254,6 +258,19 @@ size_t cw_fill_buffer(int16_t *buf, size_t bufsize) cw_fill_msg_status = 0; cw_fill_buf_full: +#else + const float omega = 2.0f * FLOAT_PI * 300.0f / + (float)cw_samplerate; + + for (int t = 0; t < bufsize; t++) { + int16_t s = 0; + + // TODO preserve oscillator phase + s = 32768.0f * arm_sin_f32(omega * t); + + buf[t] = s; + } +#endif return bufsize; } diff --git a/src/cw-example/main.c b/src/cw-example/main.c index ce1f9c6..456d4fe 100644 --- a/src/cw-example/main.c +++ b/src/cw-example/main.c @@ -97,50 +97,55 @@ static void detect_button_press(void *pvParameters) while (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 0) { vTaskDelay(100 / portTICK_RATE_MS); /* Button Debounce Delay */ } - } + taskYIELD(); } } #define AUDIO_BUF_LEN 4096 -static int16_t audio_buffer0[AUDIO_BUF_LEN]; -static int16_t audio_buffer1[AUDIO_BUF_LEN]; -static void audio_task(void *pvParameters) +static void audio_callback(void* context, int select_buffer) { + static int16_t audio_buffer0[AUDIO_BUF_LEN]; + static int16_t audio_buffer1[AUDIO_BUF_LEN]; + int16_t *samples; + + if (select_buffer == 0) { + samples = audio_buffer0; + GPIO_SetBits(GPIOD, GPIO_Pin_13); + GPIO_ResetBits(GPIOD, GPIO_Pin_14); + select_buffer = 1; + } else { + samples = audio_buffer1; + GPIO_SetBits(GPIOD, GPIO_Pin_14); + GPIO_ResetBits(GPIOD, GPIO_Pin_13); + select_buffer = 0; + } - int select_buffer = 0; + size_t samples_len = cw_fill_buffer(samples, AUDIO_BUF_LEN); - while (1) { - int16_t *samples; - - if (select_buffer == 0) { - samples = audio_buffer0; - GPIO_SetBits(GPIOD, GPIO_Pin_13); - GPIO_ResetBits(GPIOD, GPIO_Pin_14); - select_buffer = 1; - } else { - samples = audio_buffer1; - GPIO_SetBits(GPIOD, GPIO_Pin_14); - GPIO_ResetBits(GPIOD, GPIO_Pin_13); - select_buffer = 0; + if (samples_len == 0) { + for (int i = 0; i < AUDIO_BUF_LEN; i++) { + samples[i] = 0; } - size_t samples_len = cw_fill_buffer(samples, AUDIO_BUF_LEN); + samples_len = AUDIO_BUF_LEN; + } - if (samples_len == 0) { - for (int i = 0; i < AUDIO_BUF_LEN; i++) { - samples[i] = 0; - } + ProvideAudioBufferWithoutBlocking(samples, samples_len); +} - samples_len = AUDIO_BUF_LEN; - } +static void audio_task(void *pvParameters) +{ + int select_buffer = 0; - ProvideAudioBufferWithoutBlocking(samples, samples_len); + PlayAudioWithCallback(audio_callback, NULL); + while (1) { taskYIELD(); } } + void init() { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; |