DSP task for the FreeRTOS Web/DSP Demo.
Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
#include "task_demo.h"
#include "arm_math.h"
#include "sound.h"
#include "pdc.h"
#include "afec.h"
#include "tc.h"
#include "dacc.h"
#include "conf_uart_serial.h"
#include "pio.h"
#include "pio_handler.h"
#include <stdio_serial.h>
#include <serial.h>
Macros | |
#define | ADC_CHANNEL_MICROPHONE AFEC_CHANNEL_4 |
#define | ADC_CHANNEL_POTENTIOMETER AFEC_CHANNEL_5 |
ADC definitions. More... | |
#define | ADC_POTENTIOMETER_NOISE 10 |
#define | DACC_REFRESH 1 |
#define | INT_PRI_PUSHBUTTON (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 2) |
#define | INT_PRIORITY_DACC configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY |
Interrupt priorities. More... | |
#define | IRQ_PRIOR_PIO 5 |
IRQ priority for PIO (The lower the value, the greater the priority). More... | |
#define | SAMPLE_BLOCK_SIZE 256UL |
Numbers Definitions related to the FFT calculation. More... | |
#define | SAMPLING_FREQUENCY 22050UL |
Sound sampling frequency. More... | |
#define | SPEAKER_CHANNEL_L DACC_MR_USER_SEL_CHANNEL1 |
#define | SPEAKER_CHANNEL_R DACC_MR_USER_SEL_CHANNEL0 |
DACC related definitions. More... | |
#define | TC_RA (TC_RC / 2) |
#define | TC_RC (BOARD_MCK / 2 / SAMPLING_FREQUENCY) |
TC related definitions. More... | |
#define | VOICE_CHANGER_DELTA 100UL |
Voice changer step in hertz. More... | |
#define | WAVE_OFFSET (44 + 4) |
Wave file offset in bytes. More... | |
Functions | |
void | create_dsp_task (uint16_t stack_depth_words, unsigned portBASE_TYPE task_priority) |
Create the DSP task. More... | |
void | DACC_Handler (void) |
DACC interrupt handler. More... | |
static void | dsp_clean_buffer (uint16_t *buffer, uint32_t size) |
Clean the specified sound buffer with the 8 bits mediane value. More... | |
static void | dsp_configure_adc (void) |
AFEC(ADC) configuration. More... | |
static void | dsp_configure_button2 (void) |
Configure the push button 1. More... | |
static void | dsp_configure_dacc (void) |
DACC configuration. More... | |
static void | dsp_configure_tc (void) |
TC configuration. More... | |
static void | dsp_event_button2 (uint32_t id, uint32_t mask) |
Handler for Button 1 rising edge interrupt. More... | |
static void | dsp_sin_init (void) |
Generate sinusoidale signals for voice changing. More... | |
static void | dsp_sin_input (float32_t freq) |
Generate a sinus input signal. More... | |
static void | dsp_task (void *pvParameters) |
DSP task core function. More... | |
Variables | |
static uint32_t | adc_potentiometer_old = 0 |
Backup previous adc potentiometer value. More... | |
static q15_t | cfft_q15 [SAMPLE_BLOCK_SIZE *2] |
q15 cFFT buffer declaration More... | |
static uint32_t | cur_dac_buffer = 2 |
Pointer to current PDC buffer in use. More... | |
xSemaphoreHandle | dacc_notification_semaphore = NULL |
Notification semaphores. More... | |
static uint16_t | dacc_out_buffer [3][SAMPLE_BLOCK_SIZE] |
Output buffer for DACC. More... | |
Pdc * | dacc_pdc |
Pointer to PDC register base. More... | |
uint32_t | g_mode_select = 1 |
Wave/Sinus mode selection. More... | |
pdc_packet_t | g_pdc_nextpacket |
pdc_packet_t | g_pdc_packet |
PDC data packet. More... | |
xSemaphoreHandle | gfx_notification_semaphore = NULL |
GFX notification semaphore. More... | |
static portBASE_TYPE | higher_priority_task_woken = pdFALSE |
float32_t | mag_in_buffer [SAMPLE_BLOCK_SIZE] |
Magnitude buffer converted in float. More... | |
uint32_t | mag_in_buffer_int [SAMPLE_BLOCK_SIZE] |
Magnitude buffer converted in float. More... | |
static q15_t | mag_in_buffer_q15 [SAMPLE_BLOCK_SIZE] |
q15 Magnitude buffer declaration More... | |
static const portTickType | max_block_time_ticks = 200UL / portTICK_RATE_MS |
uint32_t | offset = WAVE_OFFSET |
Pointer to the wave file. More... | |
static float32_t | sin_buffer [SLIDER_SELECTOR_NB][SAMPLE_BLOCK_SIZE] |
Generated sinus signal for voice modulation. More... | |
uint8_t | slider_pos |
Slider position, used as sin_buffer table index. More... | |
float32_t | wav_in_buffer [SAMPLE_BLOCK_SIZE *2] |
Wave input buffer defined in DSP task. More... | |
#define ADC_CHANNEL_MICROPHONE AFEC_CHANNEL_4 |
Referenced by dsp_configure_adc().
#define ADC_CHANNEL_POTENTIOMETER AFEC_CHANNEL_5 |
ADC definitions.
Referenced by dsp_configure_adc(), and dsp_task().
#define ADC_POTENTIOMETER_NOISE 10 |
Referenced by dsp_task().
#define DACC_REFRESH 1 |
#define INT_PRI_PUSHBUTTON (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 2) |
Referenced by dsp_configure_button2().
#define INT_PRIORITY_DACC configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY |
Interrupt priorities.
(lowest value = highest priority) ISRs using FreeRTOS *FromISR APIs must have priorities below or equal to configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY.
Referenced by dsp_configure_dacc().
#define IRQ_PRIOR_PIO 5 |
IRQ priority for PIO (The lower the value, the greater the priority).
#define SAMPLE_BLOCK_SIZE 256UL |
Numbers Definitions related to the FFT calculation.
Referenced by DACC_Handler(), dsp_sin_init(), dsp_sin_input(), and dsp_task().
#define SAMPLING_FREQUENCY 22050UL |
Sound sampling frequency.
Referenced by dsp_sin_init(), and dsp_sin_input().
#define SPEAKER_CHANNEL_L DACC_MR_USER_SEL_CHANNEL1 |
Referenced by dsp_configure_dacc().
#define SPEAKER_CHANNEL_R DACC_MR_USER_SEL_CHANNEL0 |
DACC related definitions.
Referenced by dsp_configure_dacc().
#define TC_RA (TC_RC / 2) |
Referenced by dsp_configure_tc(), and tc_qdec_getresult().
#define TC_RC (BOARD_MCK / 2 / SAMPLING_FREQUENCY) |
TC related definitions.
Referenced by dsp_configure_tc().
#define VOICE_CHANGER_DELTA 100UL |
Voice changer step in hertz.
Referenced by dsp_sin_init().
#define WAVE_OFFSET (44 + 4) |
Wave file offset in bytes.
Referenced by dsp_task().
void create_dsp_task | ( | uint16_t | stack_depth_words, |
unsigned portBASE_TYPE | task_priority | ||
) |
Create the DSP task.
stack_depth_words | Task stack size in 32 bits word. |
task_priority | Task priority. |
References dsp_task(), NULL, vSemaphoreCreateBinary, xSemaphoreTake, and xTaskCreate.
Referenced by main().
void DACC_Handler | ( | void | ) |
DACC interrupt handler.
Check if one PDC buffer has been received.
Add cur_dac_buffer as next transfert for PDC.
Notify DSP task to start data processing.
Use next PDC buffer for ADC and DACC.
References cur_dac_buffer, dacc_get_interrupt_status(), dacc_out_buffer, dacc_pdc, higher_priority_task_woken, NULL, pdc_tx_init(), SAMPLE_BLOCK_SIZE, pdc_packet::ul_addr, pdc_packet::ul_size, and xSemaphoreGiveFromISR.
|
static |
Clean the specified sound buffer with the 8 bits mediane value.
buffer | Buffer to clean.. |
size | Buffer size. |
Referenced by dsp_task().
|
static |
AFEC(ADC) configuration.
References ADC_CHANNEL_MICROPHONE, ADC_CHANNEL_POTENTIOMETER, afec_ch_get_config_defaults(), afec_ch_set_config(), afec_channel_disable(), afec_channel_enable(), afec_channel_set_analog_offset(), afec_enable(), afec_get_config_defaults(), afec_get_interrupt_status(), afec_init(), afec_set_trigger(), afec_start_software_conversion(), afec_temp_sensor_get_config_defaults(), afec_temp_sensor_set_config(), AFEC_TRIG_SW, pmc_enable_periph_clk(), and afec_temp_sensor_config::rctc.
Referenced by dsp_task().
|
static |
Configure the push button 1.
References dsp_event_button2(), INT_PRI_PUSHBUTTON, pio_enable_interrupt(), pio_set_debounce_filter(), and pmc_enable_periph_clk().
Referenced by dsp_task().
|
static |
DACC configuration.
References dacc_enable_channel(), dacc_enable_flexible_selection(), dacc_enable_interrupt(), dacc_get_pdc_base(), dacc_pdc, dacc_set_channel_selection(), dacc_set_power_save(), dacc_set_timing(), dacc_set_transfer_mode(), dacc_set_trigger(), INT_PRIORITY_DACC, pmc_enable_periph_clk(), SPEAKER_CHANNEL_L, and SPEAKER_CHANNEL_R.
Referenced by dsp_task().
|
static |
TC configuration.
References pmc_enable_periph_clk(), tc_init(), TC_RA, TC_RC, tc_write_ra(), and tc_write_rc().
Referenced by dsp_task().
|
static |
Handler for Button 1 rising edge interrupt.
id | The pressed button ID. |
mask | Button mask. |
References g_mode_select.
Referenced by dsp_configure_button2().
|
static |
Generate sinusoidale signals for voice changing.
References SAMPLE_BLOCK_SIZE, SAMPLING_FREQUENCY, sin_buffer, SLIDER_SELECTOR_NB, and VOICE_CHANGER_DELTA.
Referenced by dsp_task().
|
static |
Generate a sinus input signal.
freq | Sinus frequency. |
References SAMPLE_BLOCK_SIZE, SAMPLING_FREQUENCY, and wav_in_buffer.
Referenced by dsp_task().
|
static |
DSP task core function.
pvParameters | Junk parameter. |
DSP task loop.
cFFT configuration instance declaration
References ADC_CHANNEL_POTENTIOMETER, ADC_POTENTIOMETER_NOISE, adc_potentiometer_old, afec_channel_get_value(), afec_start_software_conversion(), cfft_q15, cur_dac_buffer, dacc_out_buffer, dacc_pdc, dsp_clean_buffer(), dsp_configure_adc(), dsp_configure_button2(), dsp_configure_dacc(), dsp_configure_tc(), dsp_sfx, dsp_sfx_size, dsp_sin_init(), dsp_sin_input(), g_mode_select, mag_in_buffer, mag_in_buffer_int, mag_in_buffer_q15, max_block_time_ticks, offset, pdc_enable_transfer(), pdc_tx_init(), SAMPLE_BLOCK_SIZE, sin_buffer, slider_pos, tc_start(), pdc_packet::ul_addr, pdc_packet::ul_size, UNUSED, WAIT_FOR_TOUCH_EVENT, wav_in_buffer, WAVE_OFFSET, xSemaphoreGive, and xSemaphoreTake.
Referenced by create_dsp_task().
|
static |
Backup previous adc potentiometer value.
Referenced by dsp_task().
|
static |
q15 cFFT buffer declaration
Referenced by dsp_task().
|
static |
Pointer to current PDC buffer in use.
Referenced by DACC_Handler(), and dsp_task().
xSemaphoreHandle dacc_notification_semaphore = NULL |
Notification semaphores.
|
static |
Output buffer for DACC.
Referenced by DACC_Handler(), and dsp_task().
Pdc* dacc_pdc |
Pointer to PDC register base.
Referenced by DACC_Handler(), dsp_configure_dacc(), and dsp_task().
uint32_t g_mode_select = 1 |
Wave/Sinus mode selection.
Referenced by dsp_event_button2(), and dsp_task().
pdc_packet_t g_pdc_nextpacket |
pdc_packet_t g_pdc_packet |
PDC data packet.
xSemaphoreHandle gfx_notification_semaphore = NULL |
GFX notification semaphore.
Triggered from DSP task.
|
static |
Referenced by DACC_Handler().
float32_t mag_in_buffer[SAMPLE_BLOCK_SIZE] |
Magnitude buffer converted in float.
Magnitude input buffer defined in DSP task.
Referenced by dsp_task().
uint32_t mag_in_buffer_int[SAMPLE_BLOCK_SIZE] |
Magnitude buffer converted in float.
Referenced by cgi_status(), dsp_task(), and gfx_refresh_mag().
|
static |
q15 Magnitude buffer declaration
Referenced by dsp_task().
|
static |
Referenced by dsp_task().
uint32_t offset = WAVE_OFFSET |
Pointer to the wave file.
Referenced by dsp_task(), gfx_draw_bmpfile(), hx8347a_draw_char(), ili9325_draw_char(), ili93xx_draw_char(), nand_flash_spare_scheme_read_extra(), nand_flash_spare_scheme_write_extra(), pbuf_alloc(), pbuf_copy_partial(), pbuf_get_at(), pbuf_memcmp(), and tx_done_handling().
|
static |
Generated sinus signal for voice modulation.
Referenced by dsp_sin_init(), and dsp_task().
uint8_t slider_pos |
Slider position, used as sin_buffer table index.
Slider position, used as sin_buffer table index.
Referenced by demo_process_qt_status(), and dsp_task().
float32_t wav_in_buffer[SAMPLE_BLOCK_SIZE *2] |
Wave input buffer defined in DSP task.
Referenced by dsp_sin_input(), dsp_task(), and gfx_refresh_wav().