Session 1: MQX Architecture and initialization - lab guides

Document created by Armando Velasco Cardenas Employee on Sep 5, 2014
Version 1Show Document
  • View in full screen mode

This video presentation is the first installment of the Essentials of MQX RTOS Application Development training course. In this session, you will be introduced to the MQX architecture, learn how MQX is initialized, and understand how to schedule and prioritize tasks.

This training was created by Embedded Access Inc., a Freescale sponsored training provider and proven partner.

Session 1 Course LineLab Topic
  • Creating tasks
  • Setting priorities
  • Scheduling
  • Synchronization concepts
  • Introduction to drivers
  • Creating the environment
  • Creating source code
  • Understanding results

 

First, watch the video for Session 1: MQX Architecture and Initialization at the Freescale Website.

Then, follow through with the interactive lab assignment below.

SESSION 1: LAB ASSIGNMENT

INTRODUCTION

This lab walks you through the basics of starting a new project from scratch and then creating all of the tasks that we'll need for our application. For now the tasks will just print out a unique message but getting the environment set up and the shell of our application in place is an important first step.

OBJECTIVE

The objective of this lab is to download and run your first MQX application on target hardware.

This objective will be accomplished by:

  • Using the CodeWarrior New project wizard to create an MQX project
  • Adding the stubs for all of the required tasks
  • Modifying the task template to autostart all of the tasks

New functions/ structures you will use:
      Printf, _task_block, TASK_TEMPLATE_LIST

ASSIGNMENT

CREATING THE ENVIRONMENT

      1. Create a new MQX project. When asked about which libraries will be used you should add the shell library to your project. The code will run from flash, be sure to use "int flash debug PnE Multilink".

      2. Import the BSP, PSP, and Shell for the tower K70 board and re-build these libraries.
      3. We now need to add .c files for the source code for each task. To do this we need a separate file for each task so in the source code folder you'll have HealthTask.c, DisplayTask.c, etc. At the end you'll have the new 8 files plus the main.c and main.h files created when the project was created. In CodeWarrior a new file should be added by right clicking on the source folder and selecting new > source. This will create a new file with a minimal amount of code to get you started including a function that prints a message to the default output stream and then aborts. Update the name of each function to be the function associated with this file (eg: Temp_task). If the tools you're using don't fill in a minimal amount of code when you create a new file create a simple 1 line function that prints out a message.
        /*
        * TempTask.c
        * Created on: Feb 6, 2014
        * Author: Embedded Access Inc 
        */
        #include "main.h"
        /*TASK*----------------
        * Task name : Temp_task
        * Comments :
        * This task prints "Hello World"
        *END*----------------*/
        
        void Temp_task(uint_32_t initial_data)
        {
        printf("\n Temp: Hello World\n")
        }
        
        
        
        
      4. We'll need a function prototype for each of our new functions which can be added in main.h
        /* Example function prototype */
        extern void Healt_task(uint32_t);
        
        
        
        
      5. Since we'll be using the printf () function you should include the stdint.h header file at the top of main.h.
      6. For a few reasons we will need a unique ID number for each task but of course just using a number is confusing and error prone so it's more practical to use a define with each set to a unique number. You can use a series of #define statements to do this but of course you can inadvertently assign two defines to the same number. This case can be avoided by using an enum structure and you'll see that throughout the course. Find the '#define MAIN_TASK 1' in the autogenerated code and replace it with an enum defining all 8 tasks HEALTH_TASK, DISPLAY_TASK, etc).

      7. To create the tasks you need to update the Task Template List found in main.c. The Template List will be covered in a later session of the course but essentially it is a table identifying all of the tasks that you'll have in your application and it provides MQX with some information about each task. The project generated source includes a starting task template list with a single task called "main_task." You don't need the main_task but you can use this entry as a guide for entering in the entries you need. Be sure to leave the entry of zeros in the template list to demark the end of the list. Create all 8 tasks that we'll have in our application: Health Task, Display Task, Accel Task, Temp Task, Input Task, CAN Task, UI Task, and Theft Task. All tasks should be set to priority 9, have a stack size of 1500, and be auto starting.


        /* EXAMPLE TASK TEMPLATE LIST ENTRY*/
        {HEALT_TASK,  Healt_task,  1500,  9,  "Health_task",  MQX_AUTO_START_TASK},
        
        
      8. Below the Template List in main.c you'll see the autogenerated code for a main_task. We don't have a task called main in our system so this can be removed.
      9. For each of our new tasks we need update the code a bit. Change the printf to 'printf("\n Function: Hello World \n");'. In your code, 'Function' will be the actual name of function in this file (e.g. Health, Display, Temp, etc). Replace the mqx_exit with the _task_block() function. Be sure to update any comments to reflect the name of this function. Also, each function should include the main.h header as this is where we'll have some defines and the function prototypes.

      10. Run the application to confirm that each task's message is printed out onto the console.

        Your print out souhld look like this

      11. Review the order of the print statements and explain why they came out in the order that they did.

        Explanation of the Result

        The tasks will be created and run in the order that they are listed in the Task Template List (TTL). So, the order of the print outs you see should match the order of the tasks listed in the TTL.

         

        Later in the course we'll look at what happens when tasks are at different priority levels, but for now, since all tasks are at the same priority level, they will start and run in the order that they are created in.

Need more help? The full source code for this lab can be found in the 'Lab Source Code' folder here.

Attachments

    Outcomes