Microchip® Advanced Software Framework

task_dsp.c File Reference

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)
#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.

Parameters
stack_depth_wordsTask stack size in 32 bits word.
task_priorityTask 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 void dsp_clean_buffer ( uint16_t *  buffer,
uint32_t  size 
)
static

Clean the specified sound buffer with the 8 bits mediane value.

Parameters
bufferBuffer to clean..
sizeBuffer size.

Referenced by dsp_task().

static void dsp_configure_button2 ( void  )
static

Configure the push button 1.

Note
Configure the PIO as input and generate corresponding interrupt when pressed or released.

References dsp_event_button2(), INT_PRI_PUSHBUTTON, pio_enable_interrupt(), pio_set_debounce_filter(), and pmc_enable_periph_clk().

Referenced by dsp_task().

static void dsp_configure_tc ( void  )
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 void dsp_event_button2 ( uint32_t  id,
uint32_t  mask 
)
static

Handler for Button 1 rising edge interrupt.

Parameters
idThe pressed button ID.
maskButton mask.

References g_mode_select.

Referenced by dsp_configure_button2().

static void dsp_sin_init ( void  )
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 void dsp_sin_input ( float32_t  freq)
static

Generate a sinus input signal.

Parameters
freqSinus frequency.

References SAMPLE_BLOCK_SIZE, SAMPLING_FREQUENCY, and wav_in_buffer.

Referenced by dsp_task().

uint32_t adc_potentiometer_old = 0
static

Backup previous adc potentiometer value.

Referenced by dsp_task().

q15_t cfft_q15[SAMPLE_BLOCK_SIZE *2]
static

q15 cFFT buffer declaration

Referenced by dsp_task().

uint32_t cur_dac_buffer = 2
static

Pointer to current PDC buffer in use.

Referenced by DACC_Handler(), and dsp_task().

xSemaphoreHandle dacc_notification_semaphore = NULL

Notification semaphores.

uint16_t dacc_out_buffer[3][SAMPLE_BLOCK_SIZE]
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.

portBASE_TYPE higher_priority_task_woken = pdFALSE
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().

q15_t mag_in_buffer_q15[SAMPLE_BLOCK_SIZE]
static

q15 Magnitude buffer declaration

Referenced by dsp_task().

const portTickType max_block_time_ticks = 200UL / portTICK_RATE_MS
static

Referenced by dsp_task().

float32_t sin_buffer[SLIDER_SELECTOR_NB][SAMPLE_BLOCK_SIZE]
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().