ecos 怎样进入main

来源:互联网 发布:电子地图软件 编辑:程序博客网 时间:2024/06/04 18:17

从cyg_start  调用Cyg_Scheduler::start(), 使系统正式运转起来。

 

kernel/v3_0/src/common/thread.cxx 文件中定义了一个idle 线程,当系统空闲时,便会调用idle线程。

当使用posix时,compat/posix/v3_0/src/pthread.cxx 定义了cyg_posix_pthread_start, 函数末尾调用pthread_create创建了一个线程, 线程入口是call_main,定义在language/c/libc/startup/v3_0/src/invokemain.cxx中,

 

当使用default时,在language/c/libc/startup/mainthread.cxx中定义了cyg_libc_main_thread,thread的入口是cyg_libc_invoke_main, 定义在language/c/libc/startup/invokemain.cxx中,在cyg_libc_invoke_main中调用了main, 进入用户程序。

 

当使用minimal时,无法进入main, 只好用override cyg_start.

这是一个例子

#include <stdlib.h>
#include <cyg/hal/hal_io.h>
#include <cyg/hal/var_io.h>

#include <cyg/hal/hal_arch.h>
#include <cyg/kernel/kapi.h>


// These numbers depend entirely on your application
#define NUMBER_OF_WORKERS    4
#define PRODUCER_PRIORITY   10
#define WORKER_PRIORITY     11
#define PRODUCER_STACKSIZE  CYGNUM_HAL_STACK_SIZE_TYPICAL
#define WORKER_STACKSIZE    (CYGNUM_HAL_STACK_SIZE_MINIMUM + 1024)

static unsigned char producer_stack[PRODUCER_STACKSIZE];
static cyg_handle_t producer_handle;
static cyg_thread producer_thread;

static void
producer(cyg_addrword_t data)
{
    //while(1){
        static i;
        diag_printf("test!!!!!! %d/n",i++);
    //}
}



void
cyg_user_start(void)
{

    cyg_thread_create(PRODUCER_PRIORITY, &producer, 0, "producer",
                      producer_stack, PRODUCER_STACKSIZE,
                      &producer_handle, &producer_thread);
    cyg_thread_resume(producer_handle);
    cyg_scheduler_start();
}

原创粉丝点击