更换语言:
   Contact us
  • Follow CooCox
  •         
  • CooCox Market
  •         
  • Tech Support
  •     
Home  ›  CoOS › Getting started

CooCox CoOS getting started 

This section describes the usage of CooCox, here we use Keil RealView MDK 4.02 and LPC1114 to develop a simple demo based on CooCox CoOS.
      Here we assume that you are able to use Keil RealView MDK to do simple development. The following will introduce a simple example which includes three tasks:

taskA Increase a local variable, then delay 50 systicks.
taskB Increase a local variable, then delay 50 systicks.
taskC Increase a local variable, then delay 50 systicks.

    Next we will introduce how to achieve the above functions in the environment of  CoOS.

Step 1 Preparations
  • 1. Download The first CoOS program;
  • 2. First of all, create a folder named 'getting_start_sample'(Note: the name of the folder couldn't has spaces or Non-ASCII);
  • 3. And then enter the 'getting_start_sample' folder, a inc ,a src ,a ccrtos folder respectively which used to storing header files and source files;
  • 4. Copy files to the project directory:
       (1) Copy startup_LPC11xx.s in the directory of Demo\Sample to the 'Demo\getting_start_sample\src' folder;
       (2) Copy main.c in the directory of Demo\Sample to the 'Demo\getting_start_sample\src' folder;
       (3) Copy all the files in the directory of CoOS\kernel and CoOS\portable (except CoOS\portable\IAR and CoOS\portable\GCC) to the 'ccrtos' folder.

Step 2 Create Project
  • 1. Create an empty project used MDK software, device selects LPC1114 of NXP (do not choose the default startup code);
  • 2. Add application-driven code to the project:
           Add all the source files in 'src' folder to the project;
  • 3. Add CoOS source code to the project:
           Add all the source files in the 'ccrtos' folder to the project(Header files do not contain);
  • 4. Project Configuration
           Make the appropriate configuration to the project, add include path .\inc, .\ccrtos\kernel, .\ccrtos\portable, in C/C++. After that you should have been able to compile successfully, if not, please check whether the steps and the settings are correct.
(If you would like to use first rather than do the work above to save your time, you can use our ready-made project that we have prepared for you, the storage path is \Demo\getting_start_sample)

Step 3 Write application code

    Open 'main.c', you could find that we have done a part of works for you, including clock initialization, serial port 1 initialization, GPIOs used for the flickering of LEDs initialization. Next you need to do is adding task code and configuring CoOS step by step.

  • 1. Include CoOS header files

        To use CoOS, first of all is to add the source code to your project, this step has been completed in front, next is to include CoOS's header files in your user code, that is, adding the following statements in main.c:

    #include <CoOS.h>           /*!< CoOS header file */
  • 2. Write task code

        You need to specify the stack space for the task when it is created, for CoOS, the stack pointer of the task is designated by user, so we need define three arrays used for the stack of the three tasks:

    OS_STK     taskA_stk[128];         /*!< define "taskA" task stack  */
    OS_STK     taskB_stk[128];         /*!< define "taskB" task stack  */
    OS_STK     taskC_stk[128];        /*!< define "taskC" task stack  */

taskA:Increase a local variable, then delay 50 systicks,task code is as follows:

void taskA (void* pdata)
{
unsigned int led_num;

for (;;)
{
led_num++;
CoTickDelay (50);
}
}

taskB:Increase a local variable, then delay 50 systicks,task code is as follows:

void taskB (void* pdata)
{

unsigned int led_num;

for (;;)
{
led_num++;
CoTickDelay (50);
}
}

taskC:Increase a local variable, then delay 50 systicks,task code is as follows:

void taskC (void* pdata)
{

unsigned int led_num;

for (;;)
{
led_num++;
CoTickDelay (50);
}
}



Step 4 Create task and start CoOS

    Right now we have completed all the task code, next should be initializing OS, creating tasks, start multi-task scheduling. You should initialize CoOS before using CoOS or calling any CoOS API, that can be done by CoInitOS( ) function. After initialization, you could call the API functions of CoOS to create tasks、flags、 mutexes、semaphores and so on. At last, system will start the first scheduling through CoStartOS( ) function. The code after CoStartOS( ) will not be implemented, since OS will not return after the first scheduling.

    Add the following code after the initialization in main function:

  CoInitOS ( );                            /*!< Initial CooCox CoOS          */
  /*!< Create three tasks  */
  CoCreateTask (taskA,0,0,&taskA_stk[128-1],128);
  CoCreateTask (taskB,0,1,&taskB_stk[128-1],128);
  CoCreateTask (taskC,0,2,&taskC_stk[128-1],128);
  CoStartOS ( );                        /*!< Start multitask               */ 

Step 5 Configure and cut CoOS

   Open OsConfig.h, which contains all the items that can be configured and cut. Be sure you have known all the functions of every item before you modify it, there are detailed notes to explain the function of every item in the document.

    First of all, we must configure a few of the items which must be checked or modified:

    CFG_CHIP_TYPE  

    It implies chip type,cortex-m3(1), cortex-m0(2). For LPC1114, we choose cortex-m0(2).

    CFG_MAX_USER_TASKS  

    It implies the maximum tasks that users can create, we have only 3 tasks, so we modify it as 3 to save space.

    CFG_CPU_FREQ 

    It is the system clock that your system used, SystemInit ( ) initialized chip frequence as 50MHz before, so here we modify it as 50000000, corresponding to the operating frequence of the objective chip.

    CFG_SYSTICK_FREQ

    It is the frequency of system ticks, we set it as 100 for 10ms,100Hz's system clock.

    Have done all the work, your program should run normally. Compile your project, you could see the phenomenons we described above after downloading the program to the hardware by our Colink emulator.

CooCox CoOS

© 2009 -2011 CooCox - Terms of Use         Business Model         Market             About us             Terms and Conditions