Using the XdkApplicationTemplate

  1. XdkApplicationTemplate for XDK Workbenches below 3.4.0
  2. XdkApplicationTemplate for XDK Workbench 3.4.0
    1. AppControllerSetup
    2. AppControllerEnable
    3. AppControllerFire

XdkApplicationTemplate for XDK Workbenches below 340

XdkApplicationTemplate for XDK Workbenches below 3.4.0

This chapter gives a short introduction on how programming with the XdkApplicationTemplate example can be done and what is necessary to keep in mind.

The XdkApplicationTemplate comes in with only the implementation of the function appInitSystem(). This function is used as the entry point for every XDK application.

The code below shows such an example implementation:

void appInitSystem(void * CmdProcessorHandle, uint32_t param2) {

    if (CmdProcessorHandle == NULL) {
        printf("Command processor handle is null \n\r");
        assert(false);
    }
    BCDS_UNUSED(param2);

    // Start implementing your own functionality here
    //Please note, this following initialization is only a placeholder.
    callModuleInitialization();
    // ...
}

Within the function body of appInitSystem(), where callModuleInitialization() is called, the implementation of own code can begin.

The function call of callModuleInitialization() serves as a placeholder. To suit the own implementation, it should be exchanged with existing function calls.

To ensure a clean code and avoid XDK-Workbench triggered errors, keep in mind that every further implementation of own functionality needs to be placed above the appInitSystem().

XdkApplicationTemplate for XDK Workbench 340

XdkApplicationTemplate for XDK Workbench 3.4.0

This chapter gives an overview of how to use the XdkApplicationTemplate in the XDK-Workbench 3.4.0.

With the XDK-Workbench 3.4.0, the application flow of the XdkApplicationTemplate example received a complete rework. The entry point in the XdkApplicationTemplate changed to the function AppController_Init(), instead of appInitSystem(). To improve the application flow, the XdkApplicationTemplate has been divided into additional three basic functions:

  • AppControllerSetup()
  • AppControllerEnable()
  • AppControllerFire()

The following three subchapters reveal a deeper look their functionalities and usage. On that behalf, please note that every XdkApplicationTemplate executes an initial call of the function AppController_Init(). This special function is used to start the application flow, based on the mentioned functions and can be ignored for any further implementation progress.

AppControllerSetup

To suit all initializations, the basic function AppControllerSetup() gets created with enough data space. As such, it is the perfect function to add initialization functions as shown below:

static void AppControllerSetup(void * param1, uint32_t param2) {

    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);
    Retcode_T retcode = RETCODE_OK;

    // Add initialization function calls here
    //Please note, this following initialization is only a placeholder.
    callModuleInitialization();

    retcode = CmdProcessor_Enqueue(AppCmdProcessor, AppControllerEnable, NULL, UINT32_C(0));

    if (RETCODE_OK != retcode) {

        printf("AppControllerSetup : Failed \r\n");
        Retcode_RaiseError(retcode);
        assert(0);
    }
}

Within the previous code snippet, the example function callModuleInitialization() is called to initialize a used module. Additional module initializations can be called afterwards.

Now that module initializations are made, module enabling can proceed.

AppControllerEnable

The function AppControllerEnable() is designed to enable the previously initialized modules, which are used in the XDK application. The following code shows an example of how that is done.

Please note, not every module requires an enabling step. As such, also one-time function calls for the application flow can be called in the context of AppControllerEnable().

static void AppControllerEnable(void * param1, uint32_t param2) {

    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);
    Retcode_T retcode = RETCODE_OK;

    // Add enabling function calls here
    //Please note, this following initialization is only a placeholder.
    callModuleEnable();

    if (RETCODE_OK == retcode) {

        if (pdPASS != xTaskCreate(AppControllerFire, (const char * const ) "AppController", TASK_STACK_SIZE_APP_CONTROLLER, NULL, TASK_PRIO_APP_CONTROLLER, &AppControllerHandle)) {
            retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_OUT_OF_RESOURCES);
        }
    }
    if (RETCODE_OK != retcode) {

        printf("AppControllerEnable : Failed \r\n");
        Retcode_RaiseError(retcode);
        assert(0);
    }
}

In the previous code snippet, the example function callModuleEnable() is called to enable a used module. Additional module enabling functions can be called afterwards.

Now the modules are enabled, implementing the application flow can proceed.

AppControllerFire

For implementing the application flow, the function AppControllerFire() is used. This function contains a while loop, where periodic function calls can be inserted to. If a function which should only run once needs to be called, it should be executed before the while loop engages.

The code snippet below shows how this can be done.

static void AppControllerFire(void* pvParameters) {

    BCDS_UNUSED(pvParameters);

    // Add once time function calls for the application flow here
    callOneTimeFunction();

    while (1) {

        // Add periodic function calls for the application flow here
        callPeriodicFunction();
    }
}

To avoid XDK-Workbench errors, it is very important to place every further implementation of own functionality above the respective functions AppControllerSetup(), AppControllerEnable() and AppControllerFire().