色yeye在线视频观看_亚洲人亚洲精品成人网站_一级毛片免费播放_91精品一区二区中文字幕_一区二区三区日本视频_成人性生交大免费看

當前位置:首頁 > 嵌入式培訓 > 嵌入式學習 > 講師博文 > 第1章 Contiki Hello World實驗

第1章 Contiki Hello World實驗 時間:2014-09-18      來源:未知

本實驗定期的打印“hello world”,并且計數打印的個數。第二線程被稱作“blink”,實現LEDs的高速閃爍(如果在Hello world線程里,可能實現不了這么快的速度)。

C++ Code

#include "contiki.h"
        #include "dev/leds.h"
        
        #include <stdio.h> /* For printf() */
        /*---------------------------------------------------------------------------*/
        /* We declare the two processes */
        PROCESS(hello_world_process, "Hello world process");
        PROCESS(blink_process, "LED blink process");
        
        /* We require the processes to be started automatically */
        AUTOSTART_PROCESSES(&hello_world_process, &blink_process);
        /*---------------------------------------------------------------------------*/
        /* Implementation of the first process */
        PROCESS_THREAD(hello_world_process, ev, data)
        {
                // variables are declared static to ensure their values are kept
                // between kernel calls.
                static struct etimer timer;
                static int count = 0;
        
                // any process mustt start with this.
                PROCESS_BEGIN();
                // set the etimer module to generate an event in one second.
                etimer_set(&timer, CLOCK_CONF_SECOND);
        
                while (1)
                {
                        // wait here for an event to happen
                        PROCESS_WAIT_EVENT();
        
                        // if the event is the timer event as expected...
                        if(ev == PROCESS_EVENT_TIMER)
                        {
                                // do the process work
                                printf("Hello, world #%i\n", count);
                                count ++;
        
                                // reset the timer so it will generate an other event
                                // the exact same time after it expired (periodicity guaranteed)
                                etimer_reset(&timer);
                        }
        
                        // and loop
                }
                // any process must end with this, even if it is never reached.
                PROCESS_END();
        }
        
        /*---------------------------------------------------------------------------*/
        /* Implementation of the second process */
        PROCESS_THREAD(blink_process, ev, data)
        {
                static struct etimer timer;
                static uint8_t leds_state = 0;
                PROCESS_BEGIN();
        
                while (1)
                {
                        // we set the timer from here every time
                        etimer_set(&timer, CLOCK_CONF_SECOND / 4);
                        // and wait until the vent we receive is the one we're waiting for
                        PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
        
                        // update the LEDs
                        leds_off(0xFF);
                        leds_on(leds_state);
                        leds_state += 1;
                }
                PROCESS_END();
        }
        /*---------------------------------------------------------------------------*/

1、線程啟動流程

a) 聲明線程PROCESS(name, strname),name線程名字,strname對線程名字的描述。

b) AUTOSTART_PROCESSES(&hello_world_process, &blink_process)開啟線程。

c) PROCESS_THREAD(hello_world_process, ev, data)線程宏定義。

第一個參數lc是英文全稱是local continuation(本地延續?,這個不好翻譯),它可以說就是protothread的控制參數,因為protothread的精華在C的switch控制語句,這個lc就是switch里面的參數;

第二個參數就是timer給這個進程傳遞的事件了,其實就是一個unsigned char類型的參數,具體的參數值在process .h中定義;

第三個參數也是給進程傳遞的一個參數(舉個例子,假如要退出一個進程的話,那么必須把這個進程所對應的timer也要從timer隊列timerlist清除掉,那么進程在死掉之前就要給etimer_process傳遞這個參數,參數的值就是進程本身,這樣才能是etimer_process在timer隊列里找到相應的etimer進而清除)。

上一篇:安卓程序解決網絡傳輸亂碼問題

下一篇:網絡超時檢測的三種方法

熱點文章推薦
華清學員就業榜單
高薪學員經驗分享
熱點新聞推薦
前臺專線:010-82525158 企業培訓洽談專線:010-82525379 院校合作洽談專線:010-82525379 Copyright © 2004-2022 北京華清遠見科技集團有限公司 版權所有 ,京ICP備16055225號-5京公海網安備11010802025203號

回到頂部

主站蜘蛛池模板: 一级毛片一级毛片 | 茄子在线看片免费人成视频 | 亚洲乱码无人区卡1卡2卡3 | 欧洲精品一卡2卡三卡4卡影视 | 欧美交换配乱吟粗大 | x8x8拨牐拨牐x8免费视频8午夜 | 蜜桃成人免费视频在线播放 | 成人AV一区二区三区无码金桔 | 内地级a艳片高清免费播放 性xxxfreexxxx性欧美 | 狠狠cao日日橹夜夜十橹 | 久久久久国色AV免费观看 | 亚洲精品乱码一区二区三区 | 强奷乱码中文字幕 | 中文字幕在线观看一区二区三区 | 日韩精品卡1卡二卡3卡四卡 | 国产精品激情av久久久青桔 | 狠狠色丁香婷婷久久综合蜜芽 | 国产性色强伦免费视频 | 午夜性影院在线观看视频播放 | 成年免费A级毛片 | 免费一级片在线播放 | 小sao货水好多真紧h无码视频 | 亚洲AV第一成肉网 | 久久久无码精品午夜 | 在线成人爽A毛片免费软件 在线观看片a免费观看岛国 | 久久久久无码精品国产情侣 | 亚洲一本大道av久在线播放 | 亚洲AV久久久噜噜噜熟女软件 | 国产精品热久久无码av | 无码亚洲成A∧人片在线播放 | 玩丰满女领导对白露脸视频 | 欧美人与动人物牲交免费观看久久 | 特级AV毛片免费观看 | 成人麻豆视频 | 男同GAY片AV网站猛男调教 | 国产永久免费观看视频 | 免费日本黄色片 | 两个人的www免费高清视频 | 在线欧美鲁香蕉94色 | 中文在线免费一区三区高中清不卡 | 国产精品自拍视频网站 |