contiki系统代码分析(二)

 

  1. 简介
  1. 创建一个简单的任务(helloworld)
  2. 简单的任务代码分析

 

 

2、helloworld.c代码分析

#include "contiki.h"

#include <stdio.h>

 

/*---------------------------------------------------------------------------*/

PROCESS(hello_world_process, "Hello world process");

AUTOSTART_PROCESSES(&hello_world_process);       //创建自启动的任务

/*---------------------------------------------------------------------------*/

PROCESS_THREAD(hello_world_process, ev, data)

{

  PROCESS_BEGIN();

  //1、初始化部分,比如网络部分,加速度芯片等

 //2、启动一些任务等process_start(&tcpip_process, NULL);

 //3、这个是自己的工程里面真正的开始干活的内容.实现自己的业务逻辑

 //4ledacci2cspiuartlighttemp、beep、gprs、gps等真正干活的

  While(1)

{

      printf("Hello, world\n");

}

 

  PROCESS_END();

}

 

启动上述的helloworld还需要在main函数中添加如下内容,main函数主要用来开始

  1. 初始化芯片部分的内容
  2. 初始化时钟
  3. 控制台部分
  4. 调用自启动任务
  5. 轮询任务链表中的任务。

int main()

{

     Stm32_init();

     Clock_init();

     Console();

     Watchdog();

     Fifo_init();

     Process_init();

     Ctime_inti();

     autostart_start(autostart_processes); //调用自启动的任务

     while(1)

     {

          do

          {

          }

          while(process_run() > 0);//不停的循环任务

     }

}

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章