Create Custom User App¶
Guidelines for generating custom user app code for the AMDC
This document gives an overview of generating custom user app code for use with the AMDC.
AMDC utilizes an RTOS to coordinate system resources for the various tasks that need to be performed. It’s important to understand these concepts and can be reviewed here.
In short our application has some task (where the work actually gets done) and we, the end user manage the task via serial commands. This structure requires 3 files to be constructed in a manner that the AMDC RTOS will recognize. In order to do that we will be basing our custom application off of the Blink application that is included on a clean clone of the AMDC repo.
Define the application in the compiler symbols list
In the Project Explorer pane right click on bare and select Properties
Expand C/C++ Build and select Settings
Under ARM v7 gcc compiler select Symbols
Click the + icon in the upper right portion of the Defined Symbols (-D) pane
APPNAMErelates to our application purpose or function
Click OK, then click OK in the lower right of the Build Properties window
Add the application in user_apps.c
In the Project Explorer pane locate user_apps.c under bare -> usr -> user_apps.c
APP_BLINKas an example copy the
#ifdef APP_BLINKsection and paste it below, replacing
APPNAME.Don’t worry the folders and files don’t exist yet, we’ll be adding them shortly.
#ifdef APP_APPNAME #include "usr/appName/app_appName.h" #endif
Similiarly add a section within the
#ifdef APP_APPNAME app_appName_init(); #endif
Create the directory referenced in the user_apps.c file
In the Project Explorer pane right click the usr folder and select new -> folder
Name the folder appName
Create the application source and header files
Using the Blink application as an example copy and paste the app_blink.c and the app_blink.h files into the appName folder
Within app_appName.c replace all references to
Comment out the
In the corresponding header file replace all references to
Create the task files, where the work gets done
Using the Blink application as an example copy and paste the task_blink.c and the task_blink.h files into the appName folder
Starting with the header file, replace all references to
Note the define
TASK_APPNAME_UPDATES_PER_SEC (#)is a very useful feature that lets us define our repition rate of our task in Hz. It is not required.
TASK_APPNAME_INTERNAL_USEC (#)is required. This is used by the system counters to know when to trigger our task callback function
Either utilize the
*PER_SECdefine or the
*INTERNAL_USECdefine to trigger your task at the desired rate
Turning to the source file, unless you are using REV_C AMDC hardware remove all sections of code that refer to
USER_CONFIG_HARDWARE_TARGETin the top of the source file, within
task_appname_callback(). Also remove the
task_appname_init()is where you will place any initialization code for your task. This function will run once when we start the task.
task_appname_callback()will occur at the rate defined by
TASK_APPNAME_INTERNAL_USEC (#)This is where we will place any code that needs to be run based on the task frequency.
Create the command files for control via serial interface
Create the folder cmd under the appName folder. See blink example file structure
Copy and paste the cmd_blink.c and cmd_blink.h files into the newly created cmd folder and rename the files cmd_appname.c and *.h respectively.
Replace all instances of
hellotext parse sections of code for examples of multi level command parsing.
helloparse section from
cmd_appName()and from the
Build the project. There should be no build errors, work through them if there are.
We now have a template file structure for adding custom user applications and task, and the framework to control these applications with the serial interface!