Renesas Audio Record ADC Framework Application Note
Below you will find brief information for Audio Record ADC Framework. The Audio Record ADC Framework Module is a high-level API for audio recording applications and is implemented on sf_adc_periodic. The Audio Record ADC Framework module uses the ADC, GPT, and DTC peripherals on the Synergy MCU. A user-defined callback can be created to indicate that the sample count has been completed.
Advertisement
Advertisement
Application Note
Renesas Synergy™ Platform
Audio Record ADC Framework Module Guide
R30AN0312EU0100
Rev.1.00
Sep 12, 2017
Introduction
This module guide will enable you to effectively use a module in your own design. Upon completion of this guide you will be able to add this module to your own design, configure it correctly for the target application, and write code using the included application project code as a reference and efficient starting point. References to more detailed API descriptions and suggestions of other application projects that illustrate more advanced uses of the module are available in the Renesas Synergy Knowledge Base (as described in the References section at the end of this document) and should be valuable resources for creating more complex designs.
The Audio Record ADC Framework module is a high-level API for audio recording applications and is implemented on sf_adc_periodic
. The Audio Record ADC Framework module uses the ADC, GPT and DTC peripherals on the
Synergy MCU. A user-defined callback can be created to indicate that the sample count has been completed.
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 1 of 18
Renesas Synergy™ Platform
Contents
Audio Record ADC Framework Module Guide
1.
Audio Record ADC Framework Module Features .................................................................... 3
2.
Audio Record ADC Framework Module APIs Overview ........................................................... 3
3.
Audio Record ADC Framework Module Operational Overview ................................................ 4
4.
Including the Audio Record ADC Framework Module in an Application ................................... 5
5.
Configuring the Audio Record ADC Framework Module .......................................................... 5
6.
Using the Audio Record ADC Framework Module in an Application ...................................... 11
7.
The Audio Record ADC Framework Module Application Project ............................................ 12
8.
Customizing the Audio Record ADC Framework Module for a Target Application ................. 16
9.
Running the Audio Record ADC Framework Module Application Project ............................... 16
10.
Audio Record ADC Framework Module Conclusion ............................................................... 17
11.
Audio Record ADC Module Next Steps .................................................................................. 17
12.
Audio Record ADC Module Reference Information ................................................................ 17
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 2 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide
1. Audio Record ADC Framework Module Features
• Records data in 8 or 12-bit PCM
• Uses ADC Periodic Framework to simplify configuration and integration
• Uses ThreadX
®
object, like mutex, to protect hardware from improper access
• APIs for high-level functions simplify coding:
Open, start
Stop, infoGet
Close
Figure 1 Audio Record ADC Framework Module Organization, Options and Stack Implementations
2. Audio Record ADC Framework Module APIs Overview
The Audio Record ADC Framework module defines APIs for opening, closing, starting, and stopping the record process. A complete list of the available APIs, an example API call, and a short description of each can be found in the table below. A table of status return values follows.
Table 1 Audio Record ADC Framework Module API Summary
Function Name
.open
.start
.stop
.infoGet
Example API Call and Description
g_sf_audio_record_adc.p_api-
>open(g_sf_audio_record_adc.p_ctrl, g_sf_audio_record_adc.p_cfg);
Initialize the module. g_sf_audio_record_adc.p_api-
>start(g_sf_audio_record_adc.p_ctrl);
S
t
art audio recording. g_sf_audio_record_adc.p_api-
>stop(g_sf_audio_record_adc.p_ctrl);
Stop audio recording.
g_sf_audio_record_adc.p_api-
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 3 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide
.close
>infoGet(g_sf_audio_record_adc.p_api.p_ctrl);
Get the channel information (mono or Stereo). g_sf_audio_record_adc.p_api-
>close(g_sf_audio_record_adc.p_ctrl);
.versionGet
Close the module.
g_sf_audio_record_adc.p_api->versionGet(&version);
Retrieve the API version with the version pointer.
Note: For more complete descriptions of operation and definitions for the function data structures, typedefs, defines,
API data, API structures, and function variables, review the SSP User’s Manuals API References for the associated module.
Table 2 Status Return Values
Name
SSP_SUCCESS
SSP_ERR_INVALID_ARGUMENT
SSP_ERR_IN_USE
SSP_ERR_INTERNAL
Description
API Call Successful
Parameter has invalid value.
The adc periodic framework mutex may be unavailable for the unit requested. See HAL driver for other possible causes.
An internal ThreadX error has occurred. This is typically a failure to create/use a mutex or to create an internal thread.
SSP_ERR_NOT_OPEN
SSP_ERR_ASSERTION
SSP_ERR_UNSUPPORTED
Unit is not open
The parameter p_ctrl or p_sample is NULL.
This function is not supported by the HAL driver
(p_ctrl->p_api->close is NULL).
Note: Lower level drivers may return Common Error Codes. Refer to the SSP User’s Manual API References for the associated module for a definition of all relevant status return values.
3. Audio Record ADC Framework Module Operational Overview
The Audio Record ADC Framework Module samples audio analog data using the ADC Periodic Framework and the data samples captured are stored in the user buffer. The data is made available for further processing as needed by the application. The Audio Record ADC Framework Module has a configuration parameter that is initialized during the framework initialization, which also initializes the underlying ADC periodic framework for data capture.
The data is captured in a user defined buffer and this is done in the callback function as illustrated below assuming the name of the callback has been configured to be sf_audio_record_user_callback: uint16_t * audio_record_buffer; void sf_audio_record_user_callback (sf_audio_record_callback_args_t *p_args)
{ audio_record_buffer = ((uint16_t *)g_sf_audio_record_adc.
p_cfg -> p_capture_data_buffer + (p_args->buffer_index/2));
3.1 Audio Record ADC Framework Module Operational Notes
The Audio Record ADC Framework Module configuration data can specify the length of the data buffer, data width, sampling rate and the number of sampling iterations.
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 4 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide
3.2 Audio Record ADC Framework Module Limitations
• Currently the Audio Record ADC only supports the ADC Periodic Framework as the lower level and thus recording via I2S is not supported with the framework.
• The framework currently supports recording 8 bit or 12 bit PCM data.
• Refer to the most recent SSP Release Notes for any additional operational limitations for this module.
4. Including the Audio Record ADC Framework Module in an Application
This section describes how to include the Audio Record ADC Framework Module in an application using the SSP configurator.
Note: This section assumes you are familiar with creating a project, adding threads, adding a stack to a thread, and configuring a block within the stack. If you are unfamiliar with any of these items, refer to the first few chapters of the SSP User’s Manual to learn how to manage each of these important steps in creating SSP based applications.
To add the Audio Record ADC Framework Module to an application, simply add it to a thread using the Stacks
Selection Sequence given in the table below. (The default name for the Audio Record ADC Framework Module is g_audio_record_adc0
. This name can be changed in the associated Properties window.
Table 3 Audio Record ADC Framework Module Selection Sequence
Resource
g_audio_record_adc0 Audio
Record ADC Framework on sf_audio_record_adc
ISDE Tab
Threads
Stacks Selection Sequence
New Stack> Driver> Audio> Audio Record
ADC Framework on sf_audio_record_adc
When the Audio Record ADC on sf_audio_record_adc is added to the Thread Stack as shown in the figure below, the configurator automatically adds any needed lower level drivers.
Figure 2 Audio Record ADC Framework Module Stack
5. Configuring the Audio Record ADC Framework Module
The Audio Record ADC Framework Module must be configured by you for the desired operation. The SSP configuration window will automatically identify, by highlighting the block in red, any required configuration selections, such as Interrupts or Operating modes, which must be configured for lower level modules, for successful
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 5 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide operation. Only those properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the
Property window in the ISDE. This approach simplifies the configuration process and makes it much less error prone than previous manual approaches to configuration. The available configuration settings and defaults for all the user accessible properties are given in the properties tab within the SSP Configurator, and are shown in the following tables for easy reference.
One of the properties most often identified as requiring a change is the Interrupt Priority. This configuration setting is available with the Properties window of the associated module. Simply select the indicated module and then view the properties window. The Interrupt settings are often toward the bottom of the properties list, so scroll down until they become available. Also note that the Interrupt Priorities listed in the properties window in the ISDE will include an indication as to the validity of the setting based on the MCU targeted (CM4 or CM0+). This level of detail is not included in the below configuration properties tables, but is easily visible with the ISDE when configuring Interrupt
Priority levels.
Note: You may want to open your ISDE and create the module and explore the property settings in parallel with looking over the Configuration Table Settings given below. This will help orient you and can be a useful
hands-on approach to learning the ins and outs of developing with SSP.
Table 4 Configuration Settings for Audio Record ADC Framework Module on sf_audio_record_adc
ISDE Property Value
Parameter Checking Enabled, Disabled, BSP
Name
Name of the databuffer to store samples
Default: BSP g_sf_audio_record_adc0
P_capture_data_buffer
Description
Selects if code for parameter checking is to be included in the build
Module name
Name of the data buffer to store samples
Length of the databuffer
2048 Length of the buffer to which data is to be stored
Audio Record Data
Size
8-bit, 16-bit
Default: 8-bit
Data width
Sampling Rate in HZ 8000
Number of sampling iterations
Default: 256
Callback
Sampling rate
Number of samples captured per iteration g_audio_redord_framework_user_callback User function that will be called once the number of sampling iterations of data has been buffered.
Note: The above setting examples and defaults are for a project using the S7G2 Synergy MCU Group. Other MCUs may have different default values and available configuration settings.
In some cases, settings other than the defaults for stack modules can be desirable. For example, it might be useful to select different buffer sizes or sample rates. The configurable properties for the lower level stack modules are given in the below sections for completeness and as a reference.
Note: Most of the property settings for modules are fairly intuitive and usually can be determined by inspection of the associated properties window from the SSP Configurator.
5.1 Configuration Settings for the Audio Record ADC Framework Module Low
Level Drivers
Typically, only a small number of settings must be modified from the default for lower level drivers and these are indicated via the red text in the Thread Stack block. Notice that some of the configuration properties must be set to a certain value for proper framework operation and will be locked to prevent user modification. The tables below identify all the settings within the properties section for the module.
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 6 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide
Table 5 Configuration Settings for ADC Periodic Framework on sf_adc_periodic
ISDE Property Value
Parameter Checking Enabled, Disabled, BSP
Name
Default: BSP g_sf_adc_periodic0
Description
Selects if code for parameter checking is to be included in the build
Name of the databuffer to store samples
Length of the databuffer
Number of sampling iterations
GPT Timer channel used to trigger scan g_user_buffer
2048
256
Channel 0-12
Module name
Name of the data buffer to store samples
Length of the buffer to which data is to be stored
Number of samples captured per iteration
Channel number
Callback NULL
Table 6 Configuration Settings for the ADC HAL Module on r_adc
User function that will be called once the number of sampling iterations of data has been buffered.
ISDE Property
Parameter
Checking
Name
Unit
Resolution
Alignment
Clear after read
Value
BSP, Enabled, Disabled
Default: Enabled g_adc0
0, 1 (S7G2 Only)
Default: 0
14-Bit (S3A7/S124 Only), 12-Bit,
10-Bit (S7G2 Only), 8-Bit (S7G2
Only)
Default: 8-Bit (S7G2 Only)
Right, Left
Default: Right
Off, On
Default: On
Description
If selected code for parameter checking is included in the build.
Module name
Specify the ADC Unit to be used. The S7G2 has two units; 0 and 1.
Specify the conversion resolution for this unit.
Specify the conversion result alignment.
Mode
Channels 0-6
Single Scan
Unused, Use in Normal/Group A,
Use in Group B
Default: Unused
Specify if the result register must be automatically cleared after the conversion result is read.
Note: If this is enabled, then watching the result register using a debugger always results in a 0.
The ADC Framework preconfigures and locks this field.
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 7 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide
ISDE Property
Channels 7-10
(S3A7/S124 Only)
Channels 11-15
(S3A7 Only)
Channels 16-20
Channel 21 (Unit
0 Only)
Channel 22
(S3A7/S124 Only)
Channels 23-27
(S3A7 Only)
Temperature
Sensor
Voltage Sensor
Scan Mask Group
B
Normal/Group A
Trigger
Group B Trigger
(Valid Only in
Group Scan
Mode)
Value
Unused, Use in Normal/Group A,
Use in Group B
Default: Unused
Unused, Use in Normal/Group A,
Use in Group B
Default: Unused
Unused, Use in Normal/Group A,
Use in Group B
(Default: Unused)
Unused, Use in Normal/Group A,
Use in Group B
Default: Unused
Unused, Use in Normal/Group A,
Use in Group B
Default: Unused
Unused, Use in Normal/Group A,
Use in Group B
Default: Unused
Description
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
In Normal mode of operation, this bitmask field is used to specify the channels that are enabled in that ADC unit. For example if it is set to 0x101, then channels 0 and 2 are enabled. In group mode, this field is used to specify which channels belong to group A.
Temperature sensor use selection for Channel
Scan Mask
Unused, Use in Normal/Group A,
Use in Group B
Default: Unused
Unused, Use in Normal/Group A,
Use in Group B
Default: Unused
Use #define ADC_MASK_xxx which are defined in r_adc.h. Use
(ADC_MASK_xxx|ADC_MASK_xxx
) for multiple channels.
ELC Event
ELC Event (The only valid trigger for either group in Group Scan
Mode)
Voltage sensor use selection for Channel
Scan Mask
Do not use with ADC Framework since the mode is locked to Single Scan Mode.
The ADC Framework preconfigures and locks this field.
The ADC Framework preconfigures and locks this field.
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 8 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide
ISDE Property
Group Priority
(Valid only in
Group Scan
Mode)
Add/Average
Count
Channels 0-27
Temperature
Sensor
Voltage Sensor
Channels 0-2
Value
Group A cannot interrupt Group B,
Group A can interrupt Group B;
Group B scan restarts at next trigger, Group A can interrupt
Group B; Group B scan restarts immediately, Group A can interrupt
Group B; Group B scan restarts immediately and scans continuously
(Default: Group A cannot interrupt
Group B)
Disabled, Add two samples, Add three samples, Add four samples,
Add sixteen samples, Average two samples, Average four samples
Default: Disabled
Disabled, Enabled
(Default: Disabled)
Description
Do not use with ADC Framework since the mode is locked to Single Scan Mode.
Specify if addition or averaging needs to be done for any of the channels in this unit. The actual channels are specified by using a channel mask adc_channel_cfg_t::add_mask.
Disabled, Enabled
Default: Disabled
Disabled, Enabled
Default: Disabled
Disabled, Enabled
Default: Disabled
This field is valid only if adc_cfg_t::add_average_count is enabled.
This field determines what channels results are to be averaged or summed.
Temperature sensor use selection for
Addition/Averaging Mask
Voltage sensor use selection for
Addition/Averaging Mask
Determines which of channels 0, 1 and 2 are using the updated sample-and-hold states value specified in adc_channel_cfg_t::sample_hold_states. This field must only be set if it is desired to modify the default sample and hold count value for channels 0, 1 and 2.
If selected code for parameter checking is included in the build.
Sample Hold
States (Applies only to the 3 channels selected above)
Callback
Scan End
Interrupt Priority
Scan End Group
B Interrupt Priority
24
NULL
Priority 0 (highest), Priority 1:2,
Priority 3 (CM4: valid, CM0+: lowest- not valid if using ThreadX),
Priority 4:14 (CM4: valid, CM0+: invalid), Priority 15 (CM4 lowest - not valid if using ThreadX, CM0+: invalid)
Default: Disabled
Priority 0 (highest), Priority 1:2,
Priority 3 (CM4: valid, CM0+: lowest- not valid if using ThreadX),
Priority 4:14 (CM4: valid, CM0+: invalid), Priority 15 (CM4 lowest - not valid if using ThreadX, CM0+: invalid)
Default: Disabled
Module name
Specify the ADC Unit to be used. The S7G2 has two units; 0 and 1.
Specify the conversion resolution for this unit.
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 9 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide
Table 7: Configuration for the GPT HAL Module on r_gpt
ISDE Property Value
Parameter Checking BSP, Enabled, Disabled
Name
Channel
Mode
Default: BSP g_timer0
0
Periodic
Description
Enables or disables the parameter checking.
Module name.
The ADC Framework preconfigures and locks this field based on channel selected in the ADC
Framework.
The ADC Framework preconfigures and locks this field.
Configure timer period to trigger ADC scans.
Configure units of the timer period set above.
Period Value
Period Unit
Duty Cycle Value
Duty Cycle Unit
10
Raw Counts, Nanoseconds,
Microseconds, Milliseconds,
Seconds, Hertz, Kilohertz
Default: Milliseconds
50
Unit Raw Counts, Unit Percent,
Unit Percent x 1000
Default: Unit Raw Counts
Duty cycle value selection
Duty cycle unit selection
Auto Start
GTIOCA Output
Enabled
False
True, False
Default: False
The ADC Framework preconfigures and locks this field.
Set to true to output the timer signal on a port pin configured for GPT. Set to false for no output of the timer signal.
Controls output pin level when the timer is stopped.
GTIOCA Stop Level Pin Level Low, Pin Level High,
Pin Level Retained
Default: Pin Level Low
GTIOCB Output
Enabled
True, False
Default: False
GTIOCB Stop Level Pin Level Low, Pin Level High,
Pin Level Retained
Callback
Default: Pin Level Low
NULL
Set to true to output the timer signal on a port pin configured for GPT. Set to false for no output of the timer signal.
Controls output pin level when the timer is stopped.
The ADC Framework preconfigures and locks this field.
Interrupt priority selection Interrupt Priority Priority 0 (highest), Priority 1:2,
Priority 3 (CM4: valid, CM0+: lowest- not valid if using
ThreadX), Priority 4:14 (CM4: valid, CM0+: invalid), Priority 15
(CM4 lowest - not valid if using
ThreadX, CM0+: invalid)
Default: Disabled
Note: The above setting examples and defaults are for a project using the S7G2 Synergy MCU Group. Other MCUs may have different default values and available configuration settings.
5.2 Audio Record ADC Framework Module Clock Configuration
The ADC peripheral module uses PCLKC as its clock source.
5.3 Audio Record ADC Framework Module Pin Configuration
The ADC peripheral module uses pins on the MCU to communicate to external devices. I/O pins must be selected and configured as required by the external device. ADC pins must be configured as analog pins. The first table below
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 10 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide illustrates the method for selecting the pins within the SSP configuration window and the following table illustrates an example selection for the pins.
Note: For some peripherals, the Operation Mode selection mode determines what peripheral signals are available and thus what MCU pins are required.
Table 8 Pin Selection Sequence for ADC
Resource
ADC
ISDE Tab
Pins
Pin selection Sequence
Select Peripherals > Analog:ADC > ADC0
Note: The above selection sequence assumes ADC0 is the desired hardware target for the driver.
Table 9 Pin Configuration Settings for ADC
Pin Configuration
Property
Operation Mode
Value Description
ADTRG
AN00-19
PGAVSS0
Disabled, Custom
Default: Custom
None, P407, P102
Default: None
None, Pnnn, Pmmm
Default: None
None, P003
Default: None
Select operating mode for ADC
ADTRG Pin
Analog input pins
PGAVSS pin
Note: The above example settings are for a project using the S7G2 Synergy MCU Group and the SK-S7G2 Kit. Other
Synergy Kits and other Synergy MCUs may have different available pin configuration settings.
6. Using the Audio Record ADC Framework Module in an Application
The typical steps in using the Audio Record ADC Framework module in an application are:
1. Open the module using the open API
2. Start the recording using the start API
3. Buffer data in a user buffer with the callback
4. Operate on data as needed
5. Close the module using the close API
The above common steps are illustrated in a typical operational flow diagram in the figure below.
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 11 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide
Figure 3 Flow Diagram of a Typical Audio Record ADC Framework Module Application
7. The Audio Record ADC Framework Module Application Project
The Application Project demonstrates the above steps in an example application. You may want to import and open the
Application Project within ISDE and view the configuration settings for the Audio Record ADC Framework Module.
You can also read over the code, in audio_record_thread_entry.c, which is used to illustrate the Audio
Record ADC Framework Module APIs in a complete design.
The Application Project demonstrates the typical use of the Audio Record ADC Framework Module APIs. The application contains two threads, which are named Audio Playback Thread and Audio Record Thread. The first of them is responsible for providing the audio data. This will not be described in details in this document, please refer to the
Audio Playback Framework Module Guide. The Audio Record Thread, on the other hand, is responsible for recording the audio data on the USB mass storage device. Once the thread is started, the 3 LEDs are switched off, IRQ driver opens and an infinite loop is started. In the loop, the program checks if the S4 button is pressed – the button starts and stops the recording.
Once the recording is started, the program deletes the audio.wav file on the USB mass storage device, which should be inserted in USB_H port. Then the new file is created, opened and a WAV file header is written in the file. The red LED is switched on to indicate that the recording is on. If the recording is stopped, the LED is switched off, the data length is written to the appropriate bytes of the header file and the file itself is closed.
In the loop the program also checks if any new data appeared in the buffer. If so, it is saved in the file on the USB mass storage device.
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 12 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide
Table 10 Software and Hardware Resources Used by the Application Project
e2 studio ISDE
SSP
IAR EW for Renesas Synergy
5.4.0.018
1.2.1
7.71.2
SSC
SK-S7G2
USB mass storage device
Female to female jumper cable
5.4.0.018 v3.0 to v3.1
Integrated Solution Development Environment
Synergy Software Platform
IAR Embedded Workbench for Renesas Synergy
Synergy Standalone Configurator
Starter Kit
A mass storage device to save the audio file on
To connect ADC to DAC pins on the SK-S7G2 board
Headphones or speakers with
3.5 mm audio connector
Optional – used to play the audio sample
A simple flow diagram of the Application project is given in the figure below.
Figure 4 Framework Module Application Project Flow Diagram
The audio_record.c file is located in the project once it has been imported into the ISDE. You can open this file, within the ISDE, and follow along with the below description, to help identify key uses of APIs.
Use the below paragraph as a starting point for a specific description. It provides a guide for flow and level of detail.
Make sure the description matches the flow diagram and the code snippets above. Ideally main block of code map easily to the flow diagram. Refer to code snippets where they are used.
The first section of audio_record.c has the header files which references the Audio Record ADC Framework instance structure and other modules, after that a macro APP_ERR_TRAP is defined, it is used to handle errors. After that, the file buffer is declared.
The next section is an entry of the main thread function. In this function, the LEDs are switched off and the IRQ driver is opened. After that the infinite loop is started. Inside that loop, the program checks if the user has pressed the S4 button. Then the program starts or stops the recording. In the first situation, the audio.wav file is deleted and a new one is created and opened. In the file, the wav header is saved that defines the properties of the file (like bitrate, number of channels and so on.) After that the red LED is switched on to indicate the user that the record is on. In case the S4 button is pressed again, the program stops the recording, switches off the red LED and saves the file length to the
WAVE file header. Then the file is closed. In case the new data is recorded by the framework, which is indicated by the message queue, the data is saved in the file.
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 13 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide
The last section are the interrupt callbacks. IRQ Driver callback function indicates the S4 button being pressed. The
Audio Record ADC Framework is triggered when a set of an audio data is saved in the buffer. The data buffers store
16-bit unsigned integers even though the desired ADC resolution is 8 bits, the data is copied to 8 bits unsigned integer buffer, that will then be used to write the audio record in the file. The message queue is populated with an integer number indicating the buffer index that begins the latest recorded data.
Keep in mind that the project requires usage of USB Mass Storage device connected to USB_H port and connecting the
P000 and P014 ports with the jumper cable.
A few key properties are configured in this Application Project to support the required operations and the physical properties of the target board and MCU. Below are the properties with the values set for this specific project. You can also open the Application Project and view these settings in the property window as a hands-on exercise.
Provided are tables of settings required to configure the AP for the target MCU and Kit. Use the existing table for an example of standard format and content.
Table 11 Audio Record Framework ADC threads list and parameters
Symbol
audio_record_thread audio_playback_thread
Name
Audio Record Thread
Audio Playback Thread
Table 12 Audio Record Thread objects
Stack Size (bytes)
2048
2048
Priority
3
6
Object type
Semaphore
Name
Audio Record
Semaphore
Buffer Index Queue
Symbol
g_audio_record_semaphore
Properties
Initial count: 0
Queue g_buffer_index_queue Message Size (Words): 1
Queue Size (Bytes): 64
Table 13 Audio Playback Thread objects
Object type Name Symbol Properties
Semaphore Audio Playback
Semaphore g_audio_playback_semaphore Initial count: 0
Table 14 g_sf_audio_record_adc0 Audio Record ADC Framework on sf_audio_record_adc Module
Configuration Settings
ISDE Property
Length of the data-buffer
Sampling Rate
Number of sampling iterations
Resolution
Mode
Mask Channel 13
Value Set
16385
16000
1024
14-Bit (S3A7/S124 only)
Single Scan
Used in Normal/ Group A
Table 15 g_adc0 ADC Driver on r_adc Module Configuration Settings for the Application Project
ISDE Property
Channel 0
Value Set
Use in Normal/Group A
Scan End Interrupt Priority Priority 13 (CM4: valid, CM0+: invalid)
Table 16 g_timer0 Timer Driver on r_gpt Module Configuration Settings
ISDE Property
Period Value
Period Unit
Interrupt Priority
Value Set
16000
Hertz
Priority 10 (CM4: valid, CM0+: invalid)
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 14 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide
This project requires additional modules to be added to the Audio Record Thread. These are IRQ Driver on r_icu and
FileX
®
on USB Mass Storage. The user should add USBX Port HCD to the USBX Host Configuration g_ux_host_0 and choose new USBX Port HCD on sf_el_ux for USBHS. The proper configuration of those modules is shown in the tables below.
Table 17 g_external irq0 External IRQ Driver on r_icu Module Configuration Settings
ISDE Property
Channel
Digital Filtering
Callback
Value Set
11
Enabled g_irq_callback
Interrupt Priority Priority 4 (CM4: valid, CM0+: invalid)
Table 18 g_fx_media0 FileX on USB Mass Storage Module Configuration Settings
ISDE Property
Auto Media Initialization
Value Set
Enabled
Table 19 g_sf_el_ux_hcd_hs_0 USBX Port HCD on fs_el_ux for HSBHS Module Configuration Settings
ISDE Property
High Speed Interrupt Priority
Value Set
Priority 8(CM4: valid, CM0+: invalid)
Table 20 USBX on ux Module Configuration Settings
ISDE Property
USBX Pool Memory Size
Value Set
65536
The elements in the second thread, Audio Playback Thread, must be added and configured. To do that the user should add Audio Playback Framework on sf_audio_playback to this thread. The new Audio Playback Hardware
Framework shared on sf_audio_playback_hw_dac should be added under Add Audio Playback Hardware. Next, add a new Transfer Driver on r_dmac and a new Timer Driver on r_gpt. The proper configuration of those parameters is shown in the tables below.
Table 21 g_sf_audio_playback0 Audio Playback Framework on sf_audio_playback Module
Configuration Settings
ISDE Property
Buffer Size Bytes
Callback
Value Set
8192 g_audio_playback_callback
Table 22 g_sf_audio_playback_common0 Audio Playback Framework Shared on sf_audio_playback
Module Configuration Settings
ISDE Property Value Set
Audio Message Queue Name audio_playback_thread_message_queue
Table 23 g_sf_audio_playback_hw0 Audio Playback Hardware Framework Shared on sf_audio_playback_hw_dac Module Configuration Settings
ISDE Property
DMAC Support
Value Set
Enabled
Table 24 g_transfer1 Transfer Driver on r_dmac Module Configuration Settings
ISDE Property
Channel
Destination Pointer
Activation Source
Interrupt Priority
Value Set
1
&R_DAC->DADRn[0]
Event GP1 COUNTER OVERFLOW
Priority 9 (CM4: valid, CM0+: invalid)
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 15 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide
Table 25 g_timer1 Timer Driver on r_gpt Module Configuration Settings
ISDE Property
Channel
Period Value
Value Set
1
16000
Interrupt Priority Priority 9 (CM4: valid, CM0+: invalid)
The Audio Playback Thread must be added as a message subscriber to the Audio Playback Event Class. It can be done in the Messaging tab in the SSP Configurator.
8. Customizing the Audio Record ADC Framework Module for a Target Application
Provide a description of common configuration settings that a developer might typically change for a target application.
Use the below paragraph as a starting point.
Some configuration settings will normally be changed by the developer from those shown in the Application Project.
For example, you can easily change the length of the data buffer, sampling rate or audio data resolution. You can also change the ADC port pins to select the desired analog input. This can be done using the Pins tab in the configurator.
You can also change the timer that triggers the ADC scanning.
9. Running the Audio Record ADC Framework Module Application Project
To run the Audio Record ADC Framework Module Application Project and to see it executing on a target kit, you can simply import it into your ISDE, compile and run debug. Refer to the SSP Import Guide (11an0023eu0116-synergy-sspimport-guide.pdf, included in this package) for instructions on importing the project into e2 studio or IAR EW for
Synergy and build and run the application.
An optional description for building the project from scratch is provided here. Use this if you believe it will be helpful to the reader. Recommended for simpler projects.
To implement the Audio Record ADC Framework Module Application in a new project, follow the steps below for defining, configuring, auto-generating files, adding code, compiling, and debugging on the target kit. Following these steps is a hands-on approach that can help make the development process with SSP more practical.
Note: The below steps are described in sufficient detail for someone experienced with the basic flow through the
Synergy development process. If these steps are not familiar, refer to the first few chapters of the SSP User’s
Manual for a description of how to accomplish these steps.
To create and run the CGC application project simply follow these steps:
1. Create a new Renesas Synergy project for the S7G2-SK called AUDIO_RECORD_ADC_MG_AP.
2. Select the Threads tab.
4. To the Audio Record Thread add Audio Record ADC Framework on sf_audio_record_adc. External IRQ
Driver on r_icu and FileX on the USB Mass Storage. To USBX Host Configuration g_ux_host_0 add USB
Port HCD on fs_el_ux for USBHS. Adjust the parameters of the modules shown in Table 14 to Table 20.
5. To the Audio Playback Thread add Audio Playback Framework on sf_audio_playback. Under g_sf_audio_playback_common0,
Audio Playback Framework Shared on sf_audio_playback add new Audio Playback Hardware Framework Shared on sf_audio_playback_hw_dac. To this module the user
should add a new Transfer Driver on r_dmac and a new Timer Driver on r_gpt. Table 21 to Table 25 are
shown in the parameters of those modules.
6. Add the Audio Playback Thread as a message subscriber to the Audio Playback Event Class in the Messaging tab in SSP configuration.
7. Click on the Generate Project Content button.
8. Copy the files audio_playback.c, audio_record.c and audio_data.c to the project src directory. Modify the code in the audio_playback_thread_entry.c file so the audio_playback() function is called. Also modify the audio_record_thread_entry.c file so the function audio_record()
is called.
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 16 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide
9. Connect to the host PC via a micro USB cable to J19 on the SK-S7G2 Synegy MCU Group.
10. Connect P000 and P014 with the jumper cable.
11. Connect an USB Mass Storage device to the USB_H port. Note that if in the main directory of the device, there already exists a file named audio.wav, it will be overwritten.
12. Connect headphones to the audio J16 connector, if you wish to hear the audio data.
13. Start to debug the application.
14. When 3 LEDs are switched off, press the S4 button to start recording the audio data. After a while press the S4 button again. A red LED will indicate the recording.
15. The recorded audio is saved in the USB Mass Storage device in its main directory.
Figure 5 Example Output from Audio Record ADC Framework Application Project
Provide a screen capture or photo of the AP output above.
10. Audio Record ADC Framework Module Conclusion
This Module Guide has provided all the background information needed to select, add, configure, and use the module in an example project. Many of these steps were time consuming and error-prone activities in previous generations of embedded systems. The Renesas Synergy Platform makes these steps much less time consuming and removes the common errors like conflicting configuration settings or incorrect selection of low level drivers. The use of high level
APIs (as demonstrated in this Application Project) illustrates additional development-time savings by allowing work to begin at a high level and avoiding the time required in older development environments to use, and in some cases, create, low level drivers.
11. Audio Record ADC Module Next Steps
After you have mastered a simple Audio Record ADC Framework module project you may want to review a more complex example. The user may modify the ADC Driver so multiple channels are used to record the audio data to provide stereo or multi-channel audio recording.
12. Audio Record ADC Module Reference Information
SSP User Manual: Available in html format in the SSP distribution package and as a pdf from the Renesas Synergy
Gallery. Links to all the most up-to-date sf_adc_periodic module resource materials are available on: https://enus.knowledgebase.renesas.com/English_Content/Renesas_Synergy%E2%84%A2_Platform/Renesas_Synergy_Knowle dge_Base/sf_adc_periodic_Module_Guide_Resources
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 17 of 18
Renesas Synergy™ Platform Audio Record ADC Framework Module Guide
Website and Support
Support: https://synergygallery.renesas.com/support
Technical Contact Details:
• America: https://www.renesas.com/en-us/support/contact.html
• Europe:
• Japan: https://www.renesas.com/en-eu/support/contact.html
https://www.renesas.com/ja-jp/support/contact.html
All trademarks and registered trademarks are the property of their respective owners.
R30AN0312EU0100 Rev.1.00
Sep 12, 2017
Page 18 of 18
Revision History
Rev.
1.00
Date
Sep 12, 2017
Description
Page
-
Summary
Initial release
Notice
1.
Descriptions of circuits, software and other related information in this document are provided only to illustrate the operation of semiconductor products and application examples. You are fully responsible for the incorporation or any other use of the circuits, software, and information in the design of your product or system. Renesas Electronics disclaims any and all liability for any losses and damages incurred by you or third parties arising from the use of these circuits, software, or information.
2.
Renesas Electronics hereby expressly disclaims any warranties against and liability for infringement or any other disputes involving patents, copyrights, or other intellectual property rights of third parties, by or arising from the use of Renesas Electronics products or technical information described in this document, including but not limited to, the product data, drawing, chart, program, algorithm, application examples.
3.
No license, express, implied or otherwise, is granted hereby under any patents, copyrights or other intellectual property rights of Renesas Electronics or others.
4.
You shall not alter, modify, copy, or otherwise misappropriate any Renesas Electronics product, whether in whole or in part. Renesas Electronics disclaims any and all liability for any losses or damages incurred by you or third parties arising from such alteration, modification, copy or otherwise misappropriation of Renesas Electronics products.
5.
Renesas Electronics products are classified according to the following two quality grades: "Standard" and "High Quality". The intended applications for each Renesas Electronics product depends on the product’s quality grade, as indicated below.
"Standard": Computers; office equipment; communications equipment; test and measurement equipment; audio and visual equipment; home electronic appliances; machine tools; personal electronic equipment; and industrial robots etc.
"High Quality": Transportation equipment (automobiles, trains, ships, etc.); traffic control (traffic lights); large-scale communication equipment; key financial terminal systems; safety control equipment; etc.
Renesas Electronics products are neither intended nor authorized for use in products or systems that may pose a direct threat to human life or bodily injury (artificial life support devices or systems, surgical implantations etc.), or may cause serious property damages (space and undersea repeaters; nuclear power control systems; aircraft control systems; key plant systems; military equipment; etc.). Renesas
Electronics disclaims any and all liability for any damages or losses incurred by you or third parties arising from the use of any Renesas Electronics product for which the product is not intended by Renesas
Electronics.
6.
When using the Renesas Electronics products, refer to the latest product information (data sheets, user’s manuals, application notes, "General Notes for Handling and Using Semiconductor Devices" in the reliability handbook, etc.), and ensure that usage conditions are within the ranges specified by Renesas Electronics with respect to maximum ratings, operating power supply voltage range, heat radiation characteristics, installation, etc. Renesas Electronics disclaims any and all liability for any malfunctions or failure or accident arising out of the use of Renesas Electronics products beyond such specified ranges.
7.
Although Renesas Electronics endeavors to improve the quality and reliability of Renesas Electronics products, semiconductor products have specific characteristics such as the occurrence of failure at a certain rate and malfunctions under certain use conditions. Further, Renesas Electronics products are not subject to radiation resistance design. Please ensure to implement safety measures to guard them against the possibility of bodily injury, injury or damage caused by fire, and social damage in the event of failure or malfunction of Renesas Electronics products, such as safety design for hardware and software including but not limited to redundancy, fire control and malfunction prevention, appropriate treatment for aging degradation or any other appropriate measures by your own responsibility as warranty for your products/system. Because the evaluation of microcomputer software alone is very difficult and not practical, please evaluate the safety of the final products or systems manufactured by you.
8.
Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental compatibility of each Renesas Electronics product. Please investigate applicable laws and regulations that regulate the inclusion or use of controlled substances, including without limitation, the EU RoHS Directive carefully and sufficiently and use Renesas Electronics products in compliance with all these applicable laws and regulations. Renesas Electronics disclaims any and all liability for damages or losses occurring as a result of your noncompliance with applicable laws and regulations.
9.
Renesas Electronics products and technologies shall not be used for or incorporated into any products or systems whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. You shall not use Renesas Electronics products or technologies for (1) any purpose relating to the development, design, manufacture, use, stockpiling, etc., of weapons of mass destruction, such as nuclear weapons, chemical weapons, or biological weapons, or missiles (including unmanned aerial vehicles (UAVs)) for delivering such weapons, (2) any purpose relating to the development, design, manufacture, or use of conventional weapons, or (3) any other purpose of disturbing international peace and security, and you shall not sell, export, lease, transfer, or release Renesas Electronics products or technologies to any third party whether directly or indirectly with knowledge or reason to know that the third party or any other party will engage in the activities described above. When exporting, selling, transferring, etc., Renesas Electronics products or technologies, you shall comply with any applicable export control laws and regulations promulgated and administered by the governments of the countries asserting jurisdiction over the parties or transactions.
10. Please acknowledge and agree that you shall bear all the losses and damages which are incurred from the misuse or violation of the terms and conditions described in this document, including this notice, and hold Renesas Electronics harmless, if such misuse or violation results from your resale or making Renesas Electronics products available any third party.
11. This document shall not be reprinted, reproduced or duplicated in any form, in whole or in part, without prior written consent of Renesas Electronics.
12. Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this document or Renesas Electronics products.
(Note 1) "Renesas Electronics" as used in this document means Renesas Electronics Corporation and also includes its majority-owned subsidiaries.
(Note 2) "Renesas Electronics product(s)" means any product developed or manufactured by or for Renesas Electronics.
(Rev.3.0-1 November 2016)
SALES OFFICES
Refer to "http://www.renesas.com/" for the latest and detailed information.
Renesas Electronics America Inc.
2801 Scott Boulevard Santa Clara, CA 95050-2549, U.S.A.
Tel: +1-408-588-6000, Fax: +1-408-588-6130
Renesas Electronics Canada Limited
9251 Yonge Street, Suite 8309 Richmond Hill, Ontario Canada L4C 9T3
Tel: +1-905-237-2004
Renesas Electronics Europe Limited
Dukes Meadow, Millboard Road, Bourne End, Buckinghamshire, SL8 5FH, U.K
Tel: +44-1628-585-100, Fax: +44-1628-585-900
Renesas Electronics Europe GmbH
Arcadiastrasse 10, 40472 Düsseldorf, Germany
Tel: +49-211-6503-0, Fax: +49-211-6503-1327
Renesas Electronics (China) Co., Ltd.
Room 1709, Quantum Plaza, No.27 ZhiChunLu Haidian District, Beijing 100191, P.R.China
Tel: +86-10-8235-1155, Fax: +86-10-8235-7679
Renesas Electronics (Shanghai) Co., Ltd.
Unit 301, Tower A, Central Towers, 555 Langao Road, Putuo District, Shanghai, P. R. China 200333
Tel: +86-21-2226-0888, Fax: +86-21-2226-0999
Renesas Electronics Hong Kong Limited
Unit 1601-1611, 16/F., Tower 2, Grand Century Place, 193 Prince Edward Road West, Mongkok, Kowloon, Hong Kong
Tel: +852-2265-6688, Fax: +852 2886-9022
Renesas Electronics Taiwan Co., Ltd.
13F, No. 363, Fu Shing North Road, Taipei 10543, Taiwan
Tel: +886-2-8175-9600, Fax: +886 2-8175-9670
Renesas Electronics Singapore Pte. Ltd.
80 Bendemeer Road, Unit #06-02 Hyflux Innovation Centre, Singapore 339949
Tel: +65-6213-0200, Fax: +65-6213-0300
Renesas Electronics Malaysia Sdn.Bhd.
Unit 1207, Block B, Menara Amcorp, Amcorp Trade Centre, No. 18, Jln Persiaran Barat, 46050 Petaling Jaya, Selangor Darul Ehsan, Malaysia
Tel: +60-3-7955-9390, Fax: +60-3-7955-9510
Renesas Electronics India Pvt. Ltd.
No.777C, 100 Feet Road, HAL II Stage, Indiranagar, Bangalore, India
Tel: +91-80-67208700, Fax: +91-80-67208777
Renesas Electronics Korea Co., Ltd.
12F., 234 Teheran-ro, Gangnam-Gu, Seoul, 135-080, Korea
Tel: +82-2-558-3737, Fax: +82-2-558-5141 http://www.renesas.com
© 2017 Renesas Electronics Corporation. All rights reserved.
Colophon 6.0

Public link updated
The public link to your chat has been updated.
Advertisement
Key features
- Records data in 8 or 12-bit PCM
- Uses ADC Periodic Framework to simplify configuration and integration
- Uses ThreadX® object, like mutex, to protect hardware from improper access
- APIs for high-level functions simplify coding
- Open, start, stop, infoGet, close APIs
- User-defined callback for completed samples
- Supports recording 8 bit or 12 bit PCM data
- Uses ADC Periodic Framework as lower level