Create Custom User App¶
Guidelines for generating custom user app code for the AMDC
Background¶
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.
Procedure¶
Define the application in the compiler symbols list
In the Project Explorer pane right click on app_cpu1 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
Enter
APP_APPNAME
whereAPPNAME
relates to our application purpose or functionClick 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 app_cpu1 -> usr -> user_apps.c
Using
APP_BLINK
as an example copy the#ifdef APP_BLINK
section and paste it below, replacingBLINK
withAPPNAME.
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
user_apps_init()
function.#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
blink
withappName
Delete the
task_vsi_init()
function callComment out the
task_appName_init()
function callIn the corresponding header file replace all references to
blink
withappName
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
blink
withappName
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.The define
TASK_APPNAME_INTERNAL_USEC (#)
is required. This is used by the system counters to know when to trigger our task callback functionEither utilize the
*PER_SEC
define or the*INTERNAL_USEC
define 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_TARGET
in the top of the source file, withintask_appname_deinit()
and withintask_appname_callback()
. Also remove the#include ...\hardware_targets.h
reference.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 byTASK_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
blink
withappName
See the
hello
text parse sections of code for examples of multi level command parsing.Remove
hello
parse section fromcmd_appName()
and from thecmd_help[]
struct.
Build the project. There should be no build errors, work through them if there are.
Summary¶
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!