ecos 怎样进入main

从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();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值