等待contiki中的事件时,执行将转移到第二个进程

问题描述 投票:0回答:1

我在Contiki中创建了两个过程。在第一个过程中,我想在设置一定的时间计时器之后继续调用函数,为此需要一定的时间。但是,在等待计时器到期的事件时,执行控制将转移到第二个进程。

代码:

PROCESS(hello_world_process, "Hello world process");
PROCESS(hello_world_process2, "Hello world process2");
AUTOSTART_PROCESSES(&hello_world_process,&hello_world_process2);
#define TIMEOUT              (CLOCK_SECOND / 4)
static struct etimer timer;

void setFlag(void)
{
    int i;
    i = random_rand();
    if (i>0 && i<32767)
    {
        printf("Setting flag\n");
        flag =1;
    } 

}
PROCESS_THREAD(hello_world_process, ev, data)
{
    PROCESS_BEGIN();
    printf("1st process started\n");
    do 
    {
        etimer_set(&timer, TIMEOUT);
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
        setFlag();
    } while(!flag);
    printf("1st process completed\n");
    PROCESS_END();
}
PROCESS_THREAD(hello_world_process2, ev, data)
{
    printf("2nd process started\n");
    PROCESS_BEGIN();
    printf("2nd process completed\n");
    PROCESS_END();
}

输出:

Contiki-list-1532-g2ca33d4 started with IPV6, RPL
Rime started with address 1.2.3.4.5.6.7.8
MAC nullmac RDC nullrdc NETWORK sicslowpan
Tentative link-local IPv6 address fe80:0000:0000:0000:0302:0304:0506:0708
1st process started
2nd process started
2nd process completed
Setting flag
1st process completed

我希望仅在第一个过程完全执行后才执行第二个过程,即在等待事件时,控件不应转移到第二个过程。

contiki contiki-process
1个回答
0
投票

尝试一下:

AUTOSTART_PROCESSES(&hello_world_process);

// ...

PROCESS_THREAD(hello_world_process, ev, data)
{
    PROCESS_BEGIN();
    printf("1st process started\n");
    do 
    {
        etimer_set(&timer, TIMEOUT);
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
        setFlag();
    } while(!flag);
    printf("1st process completed\n");
    process_start(&hello_world_process2, NULL); // start the second process
    PROCESS_END();
} 

请参见https://github.com/contiki-os/contiki/wiki/Processes

此外,请勿在PROCESS_BEGIN()之前放置任何可执行代码!您不会收到警告,但结果可能不是您期望的,因为该代码将在每次恢复过程时每次执行。

© www.soinside.com 2019 - 2024. All rights reserved.