Exemple #1
0
int eth_system_device_init(void)
{
    Int32 result = RT_EOK;

    /* initialize Rx thread.
     * initialize mailbox and create Ethernet Rx thread */
    result = rt_mb_init(&eth_rx_thread_mb, "erxmb",
                        &eth_rx_thread_mb_pool[0], sizeof(eth_rx_thread_mb_pool)/4,
                        RT_IPC_FLAG_FIFO);
    assert(result == RT_EOK);

    result = rt_thread_init(&eth_rx_thread, "erx", eth_rx_thread_entry, NULL,
                            &eth_rx_thread_stack[0], sizeof(eth_rx_thread_stack),
                            RT_LWIP_ETHTHREAD_PRIORITY, 16);
    assert(result == RT_EOK);
    result = rt_thread_startup(&eth_rx_thread);
    assert(result == RT_EOK);

    /* initialize Tx thread */
    /* initialize mailbox and create Ethernet Tx thread */
    result = rt_mb_init(&eth_tx_thread_mb, "etxmb",
                        &eth_tx_thread_mb_pool[0], sizeof(eth_tx_thread_mb_pool)/4,
                        RT_IPC_FLAG_FIFO);
    assert(result == RT_EOK);

    result = rt_thread_init(&eth_tx_thread, "etx", eth_tx_thread_entry, NULL,
                            &eth_tx_thread_stack[0], sizeof(eth_tx_thread_stack),
                            RT_ETHERNETIF_THREAD_PREORITY, 16);
    assert(result == RT_EOK);

    result = rt_thread_startup(&eth_tx_thread);
    assert(result == RT_EOK);

	return 0;
}
Exemple #2
0
int rt_application_init()
{
    rt_thread_init(&thread_led1,
                   "led1",
                   thread_led1_entry, RT_NULL,
                   &thread_led1_stack[0], sizeof(thread_led1_stack),
                   20, 10);

    rt_thread_init(&thread_led2,
                   "led2",
                   thread_led2_entry, RT_NULL,
                   &thread_led2_stack[0], sizeof(thread_led2_stack),
                   25, 8);
    rt_thread_startup(&thread_led1);
    rt_thread_startup(&thread_led2);

    /* inint SD-crad and dm9000 */
    {
        rt_thread_t init_thread;

        init_thread = rt_thread_create("init",
                                       rt_init_thread_entry, RT_NULL,
                                       1024, 8, 5);
        rt_thread_startup(init_thread);
    }

    return 0;
}
int thread_static_simple_init()
{
	rt_err_t result;

	/* 初始化线程1 */
	result = rt_thread_init(&thread1, "t1", /* 线程名:t1 */
							thread_entry, (void*)1, /* 线程的入口是thread_entry,入口参数是1 */
							&thread1_stack[0], sizeof(thread1_stack), /* 线程栈是thread1_stack */
							THREAD_PRIORITY, 10);
	if (result == RT_EOK) /* 如果返回正确,启动线程1 */
		rt_thread_startup(&thread1);
	else
		tc_stat(TC_STAT_END | TC_STAT_FAILED);

	/* 初始化线程2 */
	result = rt_thread_init(&thread2, "t2", /* 线程名:t2 */
							thread_entry, RT_NULL, /* 线程的入口是thread_entry,入口参数是2 */
							&thread2_stack[0], sizeof(thread2_stack), /* 线程栈是thread2_stack */
							THREAD_PRIORITY + 1, 10);
	if (result == RT_EOK) /* 如果返回正确,启动线程2 */
		rt_thread_startup(&thread2);
	else
		tc_stat(TC_STAT_END | TC_STAT_FAILED);

	return 0;
}
rt_err_t thread_same_priority_init()
{
	rt_err_t result;

	result = rt_thread_init(&thread1,
							"t1",
							thread1_entry, RT_NULL,
							&thread1_stack[0], sizeof(thread1_stack),
							THREAD_PRIORITY, 10);
	if (result == RT_EOK)
		rt_thread_startup(&thread1);
	else
		tc_stat(TC_STAT_END | TC_STAT_FAILED);

	result = rt_thread_init(&thread2,
							"t2",
							thread2_entry, RT_NULL,
							&thread2_stack[0], sizeof(thread2_stack),
							THREAD_PRIORITY, 5);
	if (result == RT_EOK)
		rt_thread_startup(&thread2);
	else
		tc_stat(TC_STAT_END | TC_STAT_FAILED);

	return result;
}
int rt_application_init()
{
    rt_thread_t init_thread;
    rt_err_t result;

    /* 初始化静态互斥量 */
    result = rt_mutex_init(&static_mutex, "smutex", RT_IPC_FLAG_FIFO);
    if (result != RT_EOK)
    {
        rt_kprintf("init static mutex failed.\n");
        return -1;
    }

    /* 创建一个动态互斥量 */
    dynamic_mutex = rt_mutex_create("dmutex", RT_IPC_FLAG_FIFO);
    if (dynamic_mutex == RT_NULL)
    {
        rt_kprintf("create dynamic mutex failed.\n");
        return -1;
    }

#if (RT_THREAD_PRIORITY_MAX == 32)
    init_thread = rt_thread_create("init",
                                   rt_init_thread_entry, RT_NULL,
                                   2048, 8, 20);
#else
    init_thread = rt_thread_create("init",
                                   rt_init_thread_entry, RT_NULL,
                                   2048, 80, 20);
#endif

    if (init_thread != RT_NULL)
        rt_thread_startup(init_thread);

    rt_thread_init(&thread1,
                   "thread1",
                   rt_thread_entry1,
                   RT_NULL,
                   &thread1_stack[0],
                   sizeof(thread1_stack),11,5);
    rt_thread_startup(&thread1);


    rt_thread_init(&thread2,
                   "thread2",
                   rt_thread_entry2,
                   RT_NULL,
                   &thread2_stack[0],
                   sizeof(thread2_stack),10,5);
    rt_thread_startup(&thread2);
    return 0;
}
Exemple #6
0
void
jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c)
{
     struct super_block *sb=OFNI_BS_2SFFJ(c);
     cyg_mtab_entry *mte;
     int result;
	
     RT_ASSERT(c);
     //RT_ASSERT(!sb->s_gc_thread_handle);
	 
     mte=(cyg_dir *) sb->s_root;
     RT_ASSERT(mte);
	 
     rt_event_init(&sb->s_gc_thread_flags, "gc_event", RT_IPC_FLAG_FIFO);	 
     rt_mutex_init(&sb->s_lock, "gc_mutex", RT_IPC_FLAG_FIFO);
//     rt_mutex_init(&mte->fs->syncmode, "fs_lock", RT_IPC_FLAG_FIFO);
	 
     D1(printk("jffs2_start_garbage_collect_thread\n"));
     /* Start the thread. Doesn't matter if it fails -- it's only an
      * optimisation anyway */
     result =  rt_thread_init(&sb->s_gc_thread, 
	                   "jffs2_gc_thread",
                       jffs2_garbage_collect_thread,
                       (void *)c,
                       (void*)sb->s_gc_thread_stack,
                       sizeof(sb->s_gc_thread_stack),
					   CYGNUM_JFFS2_GC_THREAD_PRIORITY,
					   CYGNUM_JFFS2_GC_THREAD_TICKS
					   );
	 if (result != RT_EOK) {
		 rt_thread_startup(&sb->s_gc_thread);
		 /* how to deal with the following filed? */
		 /* sb->s_gc_thread_handle; */
	 }
}
static void rt_usb_vcom_init(struct ufunction *func)
{
    rt_err_t result = RT_EOK;
    struct serial_configure config;
    struct vcom *data = (struct vcom*)func->user_data;
    
    /* initialize ring buffer */
    rt_ringbuffer_init(&data->rx_ringbuffer, data->rx_rbp, CDC_RX_BUFSIZE);

    config.baud_rate = BAUD_RATE_115200;
    config.bit_order = BIT_ORDER_LSB;
    config.data_bits = DATA_BITS_8;
    config.parity = PARITY_NONE;
    config.stop_bits = STOP_BITS_1;
    config.invert = NRZ_NORMAL;

    data->serial.ops = &usb_vcom_ops;
    data->serial.int_rx = &data->vcom_int_rx;
    data->serial.config = config;

    /* register vcom device */
    rt_hw_serial_register(&data->serial, VCOM_DEVICE,
                          RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX,
                          func);

    /* create an vcom message queue */
    rt_mq_init(&vcom_tx_thread_mq, "vcomq", vcom_tx_thread_mq_pool, VCOM_MQ_MSG_SZ,
            sizeof(vcom_tx_thread_mq_pool), RT_IPC_FLAG_FIFO);

    /* init usb device thread */
    rt_thread_init(&vcom_thread, "vcom", vcom_tx_thread_entry, RT_NULL,
            vcom_thread_stack, 512, 8, 20);    
    result = rt_thread_startup(&vcom_thread);
    RT_ASSERT(result == RT_EOK);       
}
Exemple #8
0
void *ClockChrono_Write(void *args)
{
	RT_TASK *mytask;
	Display_tDest receiver;
	MenageHmsh_tChain11 chain;
	mqd_t Screen;
	struct mq_attr sc_attrs = { MAX_MSGS, 12, 0, 0 };

 	if (!(mytask = rt_thread_init(nam2num("WRITE"), 1, 0, SCHED_FIFO, 0xF))) {
		printf("CANNOT INIT TASK ClockChronoWrite\n");
		exit(1);
	}

	Screen = mq_open("SCREEN", O_WRONLY | O_CREAT | O_NONBLOCK, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, &sc_attrs);
	printf("INIT TASK ClockChronoWrite %p.\n", mytask);

	mlockall(MCL_CURRENT | MCL_FUTURE);

	while(1) {
		Display_Get(&chain, &receiver);
		if (chain.chain[1] == 'e') {
			goto end;
		}
		if (!hide && !Pause) {
			mq_send(Screen, chain.chain, 12, 0);
		}
	}
end:
	mq_close(Screen);
 	rt_task_delete(mytask);
	printf("END TASK ClockChronoWrite %p.\n", mytask);
	return 0;
}
Exemple #9
0
/**
 * @ingroup SystemInit
 *
 * This function will initialize system timer thread
 */
void rt_system_timer_thread_init(void)
{
#ifdef RT_USING_TIMER_SOFT
    int i;

    for (i = 0;
         i < sizeof(rt_soft_timer_list)/sizeof(rt_soft_timer_list[0]);
         i++)
    {
        rt_list_init(rt_soft_timer_list+i);
    }

    /* start software timer thread */
    rt_thread_init(&timer_thread,
                   "timer",
                   rt_thread_timer_entry,
                   RT_NULL,
                   &timer_thread_stack[0],
                   sizeof(timer_thread_stack),
                   RT_TIMER_THREAD_PRIO,
                   10);

    /* startup */
    rt_thread_startup(&timer_thread);
#endif
}
Exemple #10
0
int rt_application_init()
{
    rt_thread_init(&user_thread, "user1", user_thread_entry, RT_NULL,
            user_thread_stack, sizeof(user_thread_stack), 21, 20);
    rt_thread_startup(&user_thread);
    return 0;
}
Exemple #11
0
static void bfun(int t)
{
	RT_TASK *mytask;
	RT_MSGQ *smbx, *rmbx[NTASKS];
	int msg[MAXSIZ + 1], mtype, i, n;

	mytask = rt_thread_init(nam2num("BFUN"), 1, 0, SCHED_FIFO, 0xF);
	smbx = rt_msgq_init(nam2num("SMSG"), NTASKS, 0);
	for (i = 0; i < NTASKS; i++) {
		char mname[6] = "RMBX";
		mname[4] = i + '0';
		mname[5] = 0;
		rmbx[i] = rt_msgq_init(nam2num(mname), 1, 0);
	}
	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();

	while (!end) {
		rt_msg_receive(smbx, msg, sizeof(msg), &mtype);
		n = 0;
		for (i = 1; i < MAXSIZ; i++) {
			n += msg[i];
		}
		if (msg[MAXSIZ] != n) {
			rt_printk("SERVER RECEIVED AN UNKNOWN MSG.\n");
			goto prem;
		}
		msg[1] = 0xFFFFFFFF;
		rt_msg_send(rmbx[msg[0]], msg, 2*sizeof(int), 1);
	}
prem:
	rt_make_soft_real_time();
	rt_task_delete(mytask);
	printf("SERVER TASK ENDS.\n");
}
Exemple #12
0
int main(void)
{
	RT_TASK *task;

	signal(SIGTERM, catch_signal);
	signal(SIGINT,  catch_signal);

 	if (!(task = rt_thread_init(nam2num("SWITCH"), 0, 0, SCHED_FIFO, 0xF))) {
		printf("CANNOT INIT SWITCH TASK SIGNAL\n");
		exit(1);
	}

	start_rt_timer(0);
	rt_request_signal(SWITCH_SIGNAL, switch_handler);
	rt_task_signal_handler(task, (void *)SWITCH_SIGNAL);
	rt_make_hard_real_time();

	while (!end) {
		rt_sleep(nano2count(PERIOD));
	}

	rt_task_signal_handler(task, NULL);
	rt_release_signal(SWITCH_SIGNAL, task);

	rt_make_soft_real_time();
	stop_rt_timer();	
	rt_task_delete(task);

	return 0;
}
int signal_func(void *param)
{
    RT_TASK *rt_signal;
    //TODO: RTIME sampling;
    int value = 0;
    int rval = 0;
    char name[8];
    t_info *t = param;

    snprintf(name, 8, "S_%c", t->id);
    printf("%s\n", name);
    rt_signal = rt_thread_init(nam2num(name), 0, 0, SCHED_FIFO, CPUMAP);
    if (!rt_signal) {
        printf("Could not init real time signal %c\n", t->id);
        rval = -ENODEV;
        goto exit;
    }

    rt_task_make_periodic(rt_signal, rt_get_time() + t->period +
                          t->delay, t->period);
    while (!finish) {
        value = !value;
        printf("[%Ld] signal %c now in %s.\n",
               rt_get_time_ns(),
               t->id,
               value ? "up" : "down");
        rt_task_wait_period();
    }
    rt_task_delete(rt_signal);

exit:
    pthread_exit(NULL);
    return rval;
}
Exemple #14
0
void tc_start(const char* tc_prefix)
{
	rt_err_t result;

	/* tesecase prefix is null */
	if (tc_prefix == RT_NULL)
	{
		rt_kprintf("TestCase Usage: tc_start(prefix)\n\n");
		rt_kprintf("list_tc() can list all testcases.\n");
		return ;
	}

	/* init tc thread */
	if (_tc_stat & TC_STAT_RUNNING)
	{
		/* stop old tc thread */
		tc_stop();
	}

	rt_memset(_tc_prefix, 0, sizeof(_tc_prefix));
	rt_snprintf(_tc_prefix, sizeof(_tc_prefix), "_tc_%s", tc_prefix);

	result = rt_thread_init(&_tc_thread, "tc",
		tc_thread_entry, RT_NULL,
		&_tc_stack[0], sizeof(_tc_stack),
		TC_PRIORITY - 3, 5);

	/* set tc stat */
	_tc_stat = TC_STAT_RUNNING | TC_STAT_FAILED;

	if (result == RT_EOK)
		rt_thread_startup(&_tc_thread);
}
Exemple #15
0
int main(void)
{
	RT_TASK *Main_Task;
	long msg;

	if (!(Main_Task = rt_thread_init(nam2num("MNTSK"), 10, 0, SCHED_FIFO, 0xF))) {
		printf("CANNOT INIT MAIN TASK\n");
		exit(1);
	}

	if (!(hard_timer_running = rt_is_hard_timer_running())) {
		start_rt_timer(0);
	}
	barrier = rt_sem_init(nam2num("PREMS"), 4);
	latency_thread = rt_thread_create(latency_fun, NULL, 0);
	fast_thread    = rt_thread_create(fast_fun, NULL, 0);
	slow_thread    = rt_thread_create(slow_fun, NULL, 0);
	start = rt_get_time() + nano2count(200000000);
	rt_sem_wait_barrier(barrier);
	rt_receive(0, &msg);
	end = 1;
	rt_sem_wait_barrier(barrier);
	rt_thread_join(latency_thread);
	rt_thread_join(fast_thread);
	rt_thread_join(slow_thread);
	if (!hard_timer_running) {
		stop_rt_timer();
	}
	rt_sem_delete(barrier);
	rt_thread_delete(Main_Task);
	return 0;
}
Exemple #16
0
static void *fast_fun(void *arg)
{
	int jit, period;
	RTIME expected;

	if (!(Fast_Task = rt_thread_init(nam2num("FSTSK"), 2, 0, SCHED_FIFO, CPUMAP))) {
		printf("CANNOT INIT FAST TASK\n");
		exit(1);
	}

	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();
	rt_sem_wait_barrier(barrier);
	period = nano2count(FASTMUL*TICK_TIME);
	expected = start + 6*nano2count(TICK_TIME);
	rt_task_make_periodic(Fast_Task, expected, period);
	while (!end) {
		jit = abs(count2nano(rt_get_time() - expected));
		if (jit > fastjit) {
			fastjit = jit;
		}
		rt_busy_sleep((FASTMUL*TICK_TIME*USEDFRAC)/100);
		expected += period;
		END("FE\n");
		rt_task_wait_period();
		BEGIN("FB\n");
	}
	rt_sem_wait_barrier(barrier);
	rt_make_soft_real_time();
	rt_thread_delete(Fast_Task);
	return 0;
}
Exemple #17
0
/*RS485设备初始化*/
void RS485_init( void )
{
	//rt_sem_init( &sem_RS485, "sem_RS485", 0, 0 );
	rt_mq_init( &mq_RS485, "mq_RS485", &RS485_rawinfo[0], 128 - sizeof( void* ), RS485_RAWINFO_SIZE, RT_IPC_FLAG_FIFO );

	dev_RS485.type		= RT_Device_Class_Char;
	dev_RS485.init		= dev_RS485_init;
	dev_RS485.open		= dev_RS485_open;
	dev_RS485.close		= dev_RS485_close;
	dev_RS485.read		= dev_RS485_read;
	dev_RS485.write		= dev_RS485_write;
	dev_RS485.control	= dev_RS485_control;

	rt_device_register( &dev_RS485, "RS485", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE );
	rt_device_init( &dev_RS485 );
	Cam_Device_init( );

	rt_thread_init( &thread_RS485,
	                "RS485",
	                rt_thread_entry_RS485,
	                RT_NULL,
	                &thread_RS485_stack[0],
	                sizeof( thread_RS485_stack ), 9, 5 );
	rt_thread_startup( &thread_RS485 );
}
Exemple #18
0
int main(void)
{
	int i, srq, count = 0, nextcount = 0, repeat;

	rt_thread_init(nam2num("MNTSK"), 100, 0, SCHED_FIFO, 0x1);
	rt_printk("\nTESTING THE SCHEDULER WITH SRQs [%d LOOPs].\n", LOOPS);
	repeat = 1000000000LL/((long long)DELAY*(long long)PRINT_FREQ);
	srq = rtai_open_srq(0xcacca);
	start_rt_timer(0);
	rt_grow_and_lock_stack(100000);
#ifdef MAKE_HARD
	MAKE_HARD();
#endif

	for (i = 0; i < LOOPS; i++) {
		rtai_srq(srq, (unsigned long)nano2count(DELAY));
		if (++count > nextcount) {
			nextcount += repeat;
			rt_printk(">>> %d.\n", nextcount);
		}
	}

	rt_make_soft_real_time();
	stop_rt_timer();
        rt_task_delete(NULL);
	rt_printk("END SCHEDULER TEST WITH SRQs.\n\n");
	return 0;
}
int rt_application_init()
{
	rt_thread_t init_thread;

	rt_err_t result;

    /* init led thread */
	result = rt_thread_init(&led_thread, "led", led_thread_entry, RT_NULL, (rt_uint8_t*)&led_stack[0], sizeof(led_stack), 20, 5);
	if (result == RT_EOK)
	{
        rt_thread_startup(&led_thread);
	}

#if (RT_THREAD_PRIORITY_MAX == 32)
	init_thread = rt_thread_create("init",
								rt_init_thread_entry, RT_NULL,
								2048, 8, 20);
#else
	init_thread = rt_thread_create("init",
								rt_init_thread_entry, RT_NULL,
								2048, 80, 20);
#endif

	if (init_thread != RT_NULL)
		rt_thread_startup(init_thread);

	return 0;
}
Exemple #20
0
void *CommandClock_task(void *args)
{
	RT_TASK *mytask;
	unsigned long command;
	char R = 'R';
	int ackn = 0;
	RT_TASK *get = (RT_TASK *)0, *put = (RT_TASK *)0, *task;

 	if (!(mytask = rt_thread_init(nam2num("CLKTSK"), 1, 0, SCHED_FIFO, 0xF))) {
		printf("CANNOT INIT TASK CommandClock_task\n");
		exit(1);
	}
	printf("INIT TASK CommandClock_task %p.\n", mytask);
	mlockall(MCL_CURRENT | MCL_FUTURE);

	Clockstatus = stopped;
	while (ackn != ('a' + 'b')) {
		task = rt_receive((RT_TASK *)0, &command);
		switch (command) {
			case 'b':
				get = task;
				ackn += command;
				break;
			case 'a':
				put = task;
				ackn += command;
				break;
		}
	}
	rt_return(put, command);
	rt_return(get, command);

	while(1) {
		switch (Clockstatus) {
			case stopped:
				rt_receive(put, &command);
				if (command == 'R') {
					Clockstatus = running;
				}
				break;
			case running:
				if (rt_receive_if(put, &command)) {
					if (command == 'T') {
						Clockstatus = stopped;
					}
				} else {
					command = R;
				}
				break;
		}
		rt_send(get, command);
		if (command == 'F') {
			goto end;
		}
	}
end:
	rt_task_delete(mytask);
	printf("END TASK CommandClock_task %p.\n", mytask);
	return 0;
}
Exemple #21
0
int rt_application_init()
{
    rt_thread_t init_thread;

#if (RT_THREAD_PRIORITY_MAX == 32)
    init_thread = rt_thread_create("init",
                                   rt_init_thread_entry, RT_NULL,
                                   2048, 8, 20);
#else
    init_thread = rt_thread_create("init",
                                   rt_init_thread_entry, RT_NULL,
                                   2048, 80, 20);
#endif

    if (init_thread != RT_NULL)
        rt_thread_startup(init_thread);

    //------- init led1 thread
    rt_thread_init(&thread_led1,
                   "led1",
                   rt_thread_entry_led1,
                   RT_NULL,
                   &thread_led1_stack[0],
                   sizeof(thread_led1_stack),25,5);
    rt_thread_startup(&thread_led1);

		
    return 0;
}
Exemple #22
0
int rt_application_init()
{
#if (RT_THREAD_PRIORITY_MAX == 32)
    init_thread = rt_thread_create("init",
                                   rt_init_thread_entry, RT_NULL,
                                   256, 8, 20);
#else
    init_thread = rt_thread_create("init",
                                   rt_init_thread_entry, RT_NULL,
                                   1024, 80, 20);
#endif
    

    if (init_thread != RT_NULL)
        rt_thread_startup(init_thread);

    //------- init demo thread
    rt_thread_init(&demo,
                   "demo",
                   rt_thread_entry_demo,
                   RT_NULL,
                   &thread_demo_stack[0],
                   sizeof(thread_demo_stack),11,5);
    rt_thread_startup(&demo);
    return 0;
}
Exemple #23
0
int rt_application_init()
{
  rt_err_t result;
	/******************初始化usart2  留出uart2作为WIFI接口并*******************/
  uart2_config(115200);   
  /******************usart2初始化结束***************/

  /******************初始化信号量和邮箱**************/
  rt_mb_init(&mb,"mb",&mailpool[0],sizeof(mailpool)/4,RT_IPC_FLAG_FIFO);//按照先入先出的原则,申请了一个可以存放32封邮件的邮箱
  rt_mb_init(&dfs_mb,"dfs_mb",&dfs_mailpool[0],sizeof(dfs_mailpool)/4,RT_IPC_FLAG_FIFO);
	result = rt_event_init(&event, "event", RT_IPC_FLAG_FIFO);  //初始化事件机制 用于mp3播放
	if(result != RT_EOK)
	{
	rt_kprintf("init event failed.\r\n");
		return-1;
		}
  /***************************************************/

  /*初始化LED1  时间统计线程*/
	result = rt_thread_init(&led1_thread,"led1",led1_thread_entry,RT_NULL,&led1_stack[0],sizeof(led1_stack),7,3);
	if (result == RT_EOK)
	{	
        rt_thread_startup(&led1_thread);
	}
	/*初始化LED3  红外收发线程*/
	result = rt_thread_init(&led3_thread, "led3",led3_thread_entry,RT_NULL,&led3_stack[0],sizeof(led3_stack),	5,3	);
	/*如果初始化LED1线程成功*/
	if (result == RT_EOK)
	{	/*启动LED1线程*/
        rt_thread_startup(&led3_thread);
	}

                     
/***************初始化DFS线程***************************/
result=rt_thread_init(&dfs_thread, "dfs",dfs_thread_entry, RT_NULL,&dfs_stack[0], sizeof(dfs_stack),6,20);
if (result==RT_EOK)
{
  rt_thread_startup(&dfs_thread);
}
/***************初始化LD3320播放线程***************************/
result=rt_thread_init(&LD_thread,"ld_t",LD_thread_entry,RT_NULL,&LD_stack[0], sizeof(LD_stack), 4,50);
if (result==RT_EOK)
{
  rt_thread_startup(&LD_thread);
}
	return 0;
}
Exemple #24
0
void  rt_hw_pwm_vms_init(void)
{
	rt_err_t result;
  GPIO_InitTypeDef GPIO_InitStructure;
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  TIM_OCInitTypeDef  TIM_OCInitStructure;
  
  /* GPIOA Clocks enable */
  RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA, ENABLE);
  
  /* GPIOA Configuration: Channel 1 as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_2);
  
  /* TIM1 clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 , ENABLE);
  
  /* Time Base configuration */
  TIM_TimeBaseStructure.TIM_Period = 1200;										// 要分幾階在這裡設定  0.05ms(20khz) =>1200階    TimerCLK = 1200 * 20000 =24M 
  TIM_TimeBaseStructure.TIM_Prescaler = 2;										// (48M(SysCLK) / 24M) -1  = 除頻值 = 1
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
  
  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
  
  /* Channel 1, 2, 3 and 4 Configuration in PWM mode */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
  TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
  TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
  
  TIM_OCInitStructure.TIM_Pulse = 0;
  TIM_OC1Init(TIM1, &TIM_OCInitStructure);
  
  /* TIM1 counter enable */
  TIM_Cmd(TIM1, ENABLE);
  
  /* TIM1 Main Output Enable */
  //TIM_CtrlPWMOutputs(TIM1, ENABLE);
	
		result = rt_thread_init(&rt_vms_thread,"vms", vms_thread_entry, RT_NULL,
						(rt_uint8_t*)&vms_stack[0], sizeof(vms_stack),3,2);
		
		if(result == RT_EOK) 
		{ 
			rt_thread_startup(&rt_vms_thread); 
		}
}
Exemple #25
0
void *ClockChrono_Clock(void *args)
{
	RT_TASK *mytask;
	const int hundredthes = FALSE;
	MenageHmsh_tHour hour;
	MenageHmsh_tChain11 hourChain;
	char command;
	BOOLEAN display;

 	if (!(mytask = rt_thread_init(nam2num("CLOCK"), 1, 0, SCHED_FIFO, 0xF))) {
		printf("CANNOT INIT TASK ClockChronoClock\n");
		exit(1);
	}
	printf("INIT TASK ClockChronoClock %p.\n", mytask);
	mlockall(MCL_CURRENT | MCL_FUTURE);

	rt_make_hard_real_time();
	sem_wait(&sync_sem);
	MenageHmsh_Initialise(&hour);
	while(1) {
		CommandClock_Get(&command);
		switch(command) {
			case 'R':
				rt_fractionated_sleep(OneUnit);
				MenageHmsh_PlusOneUnit(&hour, &display);
				break;
			case 'T': 
				MenageHmsh_InitialiseHundredthes(&hour);
				display = FALSE;
				break;
			case 'H': 
				MenageHmsh_AdvanceHours(&hour);
				display = TRUE;
				break;
			case 'M':
				MenageHmsh_AdvanceMinutes(&hour);
				display = TRUE;
				break;
			case 'S':
				MenageHmsh_AdvanceSeconds(&hour);
				display = TRUE;
				break;
			case 'F':
				goto end;
			}
		if (display) {
			MenageHmsh_Convert(hour, hundredthes, &hourChain);
			Display_PutHour(hourChain);
		}
	}
end:
	rt_make_soft_real_time();
	hourChain.chain[1] = 'e';
	Display_PutHour(hourChain);
	rt_task_delete(mytask);
	printf("END TASK ClockChronoClock %p.\n", mytask);
	return 0;
}
Exemple #26
0
int rt_test_init(void)
{
	rt_thread_t init_thread;

	rt_err_t result;

    /* init led thread */
	result = rt_thread_init(&led_thread,
		"led",
		led_thread_entry, RT_NULL,
		(rt_uint8_t*)&led_stack[0], sizeof(led_stack), 20, 5);
	if (result == RT_EOK)
	{
        rt_thread_startup(&led_thread);
	}
////////////////////////////////////////////////////
////////////////////////////////////////////////////	
#if 1 
//Test IO3V3
    /* init test thread */
	result = rt_thread_init(&test_IO3V3_thread,
		"app",
		test_IO3V3_thread_entry, RT_NULL,
		(rt_uint8_t*)&app_stack[0], sizeof(app_stack), 20, 5);
	if (result == RT_EOK)
	{
        rt_thread_startup(&test_IO3V3_thread);
	}
#else	
//Test suspend
	    /* init test thread */
	result = rt_thread_init(&test_suspend_thread,
		"app",
		test_suspend_thread_entry, RT_NULL,
		(rt_uint8_t*)&app_stack[0], sizeof(app_stack), 20, 5);
	if (result == RT_EOK)
	{
        rt_thread_startup(&test_suspend_thread);
	}
#endif
////////////////////////////////////////////////////
////////////////////////////////////////////////////	

	return 0;
}
int rt_application_init()
{
    rt_thread_t init_thread;
    rt_err_t result;
    
	result = rt_sem_init(&sem, "sem", 0, RT_IPC_FLAG_FIFO);
	if (result != RT_EOK)
	{
        rt_kprintf("error, init sem failed!\n");
		return 0;
	}
    
#if (RT_THREAD_PRIORITY_MAX == 32)
    init_thread = rt_thread_create("init",
                                   rt_init_thread_entry, RT_NULL,
                                   2048, 8, 20);
#else
    init_thread = rt_thread_create("init",
                                   rt_init_thread_entry, RT_NULL,
                                   2048, 80, 20);
#endif

    if (init_thread != RT_NULL)
        rt_thread_startup(init_thread);

    //------- init thread1
    rt_thread_init(&thread1,
                   "keyp", //producer
                   rt_thread_entry1,
                   RT_NULL,
                   &thread1_stack[0],
                   sizeof(thread1_stack),11,25);
    rt_thread_startup(&thread1);
    
    //------- init thread2
    rt_thread_init(&thread2,
                   "keyc", //consumer
                   rt_thread_entry2,
                   RT_NULL,
                   &thread2_stack[0],
                   sizeof(thread2_stack),11,24);
    rt_thread_startup(&thread2);
    return 0;
}
Exemple #28
0
int rt_application_init(void)
{
    rt_thread_t init_thread;

    rt_err_t result;

#if (RT_THREAD_PRIORITY_MAX == 32)
    init_thread = rt_thread_create("init",
                                   rt_init_thread_entry, RT_NULL,
                                   2048, 8, 20);
#else
    init_thread = rt_thread_create("init",
                                   rt_init_thread_entry, RT_NULL,
                                   2048, 80, 20);
#endif

    if (init_thread != RT_NULL)
        rt_thread_startup(init_thread);


    /* init led thread */
    result = rt_thread_init(&adc_thread,
                            "adc",
                            adc_thread_entry,
                            RT_NULL,
                            (rt_uint8_t*)&adc_stack[0],
                            sizeof(adc_stack),
                            10,5);
     rt_thread_startup(&adc_thread);			

    /* init main thread */
    result = rt_thread_init(&main_thread,
                            "main",
                            main_thread_entry,
                            RT_NULL,
                            (rt_uint8_t*)&main_stack[0],
                            sizeof(main_stack),
                            2,1);
     rt_thread_startup(&main_thread);								


    return 0;
}
Exemple #29
0
//gps log initialization
void thread_slow_log_init(void)
{
	rt_thread_init(&thread_slow_log_handle,
                   "log slow",
                   entry_thread_slow_log,
                   RT_NULL,
                   &thread_slow_log_stack[0],
                   sizeof(thread_slow_log_stack),25,1);
    rt_thread_startup(&thread_slow_log_handle);
}
Exemple #30
0
static void *latency_fun(void *arg)
{
	struct sample { long min, max, avrg, jitters[2]; } samp;
	int diff;
	int skip;
	int average;
	int min_diff;
	int max_diff;
	int period;
	RT_TASK *chktsk;
	RTIME expected;

	min_diff = 1000000000;
	max_diff = -1000000000;
	if (!(Latency_Task = rt_thread_init(nam2num("PRETSK"), 0, 0, SCHED_FIFO, CPUMAP))) {
		printf("CANNOT INIT LATENCY TASK\n");
		exit(1);
	}

	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();
	rt_sem_wait_barrier(barrier);
	period = nano2count(TICK_TIME);
	expected = start + 3*period;
	rt_task_make_periodic(Latency_Task, expected, period);
	while (!end) {
		average = 0;
		for (skip = 0; skip < NAVRG && !end; skip++) {
			expected += period;
			END("HE\n");
			rt_task_wait_period();
			BEGIN("HB\n");
			diff = count2nano(rt_get_time() - expected);
			if (diff < min_diff) {
				min_diff = diff;
			}
			if (diff > max_diff) {
				max_diff = diff;
			}
			average += diff;
		}
		samp.min = min_diff;
		samp.max = max_diff;
		samp.avrg = average/NAVRG;
		samp.jitters[0] = fastjit;
		samp.jitters[1] = slowjit;
		if ((chktsk = rt_get_adr(nam2num("PRECHK")))) {
			rt_sendx_if(chktsk, &samp, sizeof(samp));
		}
	}
	rt_sem_wait_barrier(barrier);
	rt_make_soft_real_time();
	rt_thread_delete(Latency_Task);
	return 0;
}