Step 4: Include Application-Specific Source Files, Add Required Code and Build the Project

Last modified by Microchip on 2024/01/29 21:42

Copy the source files into your project's Source Files folder:

  • app_sdcard_reader_task.c
  • app_sdcard_reader_task.h
  • app_button_press_task.c
  • app_button_press_task.h

Copy them from the following folder:

apps/training/solutions/audio_player/audio_player_lab3/dev_files

to this one:

apps/training/solutions/dev/audio_player/audio_player_lab3/firmware/src

Copied source files

Back to Top


Add the copied source files to your project.

Add app_sdcard_reader_task.c and app_button_press_task.c to the Source Files folder (in the MPLAB® X IDE Projects pane) by right-clicking and selecting Add Existing Item…

Add existing item

Select items

Add app_sdcard_reader_task.h and app_button_press_task.h to the Header Files folder by right-clicking and selecting Add Existing Item…

Add existing item

Select item

The files under the project should look like this:

Files added to project

Back to Top


Open the app.c file and add the function prototypes for the SD card reader and button press tasks.

add the function prototypes

Back to Top


Add the initialization routines for the SD card reader and button press tasks.

Add the initialization routines

Back to Top


Modify the APP_Tasks function to add the two newly added tasks, under the APP_STATE_SERVICE_TASKS state.

Modify APP_Tasks

Add two functions that will set and get the current mode of the application. This will execute either the player functionality implemented by the APP_TONE_TEXTFILE_SDCARD_Tasks, or the SD card reader functionality implemented by the APP_SDCARD_READER_Tasks.

Add two functions

Back to Top


Now, open the app.h file and add the following enumeration. This will be used to manage the application modes.

add the following enumeration

Back to Top


Next, modify the APP_DATA structure to include the application's mode related information.

Modify structure

Back to Top


You also need to expose the set and get mode functions to other tasks. Include the following declarations in the app.h file.

Include declarations

Back to Top


Finally, open app_tone_textfile_sdcard.c and add the following include file and condition. This will ensure the APP_TONE_TEXTFILE_SDCARD_Tasks function runs only when the audio playback mode is selected.

Add include fileif condition

Note: You must also add the closing bracket for the if condition.

 

Back to Top


Save all the files before closing.

Back to Top


Now, you are ready to build the code. Click the Clean and Build rebuild project icon icon and verify that the project builds successfully.

Back to Top