所使用的系统文件如下:上一博文只使用Contiki操作系统的核心,则只保留sys文件夹下8个文件就行了,实际上argc.h和argc.c没有使用,可用0字节的文件代替。或修改process.c删除对argc.h的引用,最精简的保留6个文件就行了。今天阅读源代码增加etimer的功能后,把sys文件如下所示。
|-[F]sys {
| |-arg.c
| |-arg.h
| |-cc.h
| |-clock.h
| |-etimer.c
| |-etimer.h
| |-lc-switch.h
| |-lc.h
| |-process.c
| |-process.h
| |-pt.h
| |-timer.c
| |-timer.h }
系统sys文件夹下的文件增加到了13个,clock.h是硬件平台的接口,必须在对应的平台上实现对应的clock.c文件,可参照 platform 文件夹下的文件修改。
hello_world.c如下:
#include "contiki.h"
struct etimer hello_etimer;
PROCESS(hello_world_process, "Hello world process");
PROCESS_THREAD(hello_world_process, ev, data)
{
static int i;
PROCESS_BEGIN();
for(i=0;i<3;i++){
PROCESS_YIELD();
etimer_restart(&hello_etimer);
printf("Hello, world\n");
}
PROCESS_END();
}
main.c如下:
#include "contiki.h"
PROCESS_NAME(hello_world_process);
extern struct etimer hello_etimer;
int main(int argc, char **argv)
{
process_init();
process_start(&hello_world_process, NULL);
process_start(&etimer_process, NULL);
etimer_set(&hello_etimer,3000);
while(process_list) {
do {
}
while(process_run()>0);
etimer_request_poll();
if(!etimer_pending()){
process_exit(&etimer_process);
}
}
return 0;
}
OK了,实现了三秒打印一次“Hello World”!打印3次后程序退出。