int eth_system_device_init(void) { Int32 result = RT_EOK; /* initialize Rx thread. * initialize mailbox and create Ethernet Rx thread */ result = rt_mb_init(ð_rx_thread_mb, "erxmb", ð_rx_thread_mb_pool[0], sizeof(eth_rx_thread_mb_pool)/4, RT_IPC_FLAG_FIFO); assert(result == RT_EOK); result = rt_thread_init(ð_rx_thread, "erx", eth_rx_thread_entry, NULL, ð_rx_thread_stack[0], sizeof(eth_rx_thread_stack), RT_LWIP_ETHTHREAD_PRIORITY, 16); assert(result == RT_EOK); result = rt_thread_startup(ð_rx_thread); assert(result == RT_EOK); /* initialize Tx thread */ /* initialize mailbox and create Ethernet Tx thread */ result = rt_mb_init(ð_tx_thread_mb, "etxmb", ð_tx_thread_mb_pool[0], sizeof(eth_tx_thread_mb_pool)/4, RT_IPC_FLAG_FIFO); assert(result == RT_EOK); result = rt_thread_init(ð_tx_thread, "etx", eth_tx_thread_entry, NULL, ð_tx_thread_stack[0], sizeof(eth_tx_thread_stack), RT_ETHERNETIF_THREAD_PREORITY, 16); assert(result == RT_EOK); result = rt_thread_startup(ð_tx_thread); assert(result == RT_EOK); return 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; }
int eth_system_device_init(void) { rt_err_t result = RT_EOK; /* initialize Rx thread. */ #ifndef LWIP_NO_RX_THREAD /* initialize mailbox and create Ethernet Rx thread */ result = rt_mb_init(ð_rx_thread_mb, "erxmb", ð_rx_thread_mb_pool[0], sizeof(eth_rx_thread_mb_pool)/4, RT_IPC_FLAG_FIFO); RT_ASSERT(result == RT_EOK); result = rt_thread_init(ð_rx_thread, "erx", eth_rx_thread_entry, RT_NULL, ð_rx_thread_stack[0], sizeof(eth_rx_thread_stack), RT_ETHERNETIF_THREAD_PREORITY, 16); RT_ASSERT(result == RT_EOK); result = rt_thread_startup(ð_rx_thread); RT_ASSERT(result == RT_EOK); #endif /* initialize Tx thread */ #ifndef LWIP_NO_TX_THREAD /* initialize mailbox and create Ethernet Tx thread */ result = rt_mb_init(ð_tx_thread_mb, "etxmb", ð_tx_thread_mb_pool[0], sizeof(eth_tx_thread_mb_pool)/4, RT_IPC_FLAG_FIFO); RT_ASSERT(result == RT_EOK); result = rt_thread_init(ð_tx_thread, "etx", eth_tx_thread_entry, RT_NULL, ð_tx_thread_stack[0], sizeof(eth_tx_thread_stack), RT_ETHERNETIF_THREAD_PREORITY, 16); RT_ASSERT(result == RT_EOK); result = rt_thread_startup(ð_tx_thread); RT_ASSERT(result == RT_EOK); #endif return (int)result; }
Int32 eth_system_device_init() { Int32 result = RT_EOK; /* init rx thread */ /* init mailbox and create ethernet thread */ result = rt_mb_init(ð_rx_thread_mb, "erxmb", ð_rx_thread_mb_pool[0], sizeof(eth_rx_thread_mb_pool)/4, RT_IPC_FLAG_FIFO); assert(result == RT_EOK); result = rt_thread_init(ð_rx_thread, "erx", eth_rx_thread_entry, NULL, ð_rx_thread_stack[0], sizeof(eth_rx_thread_stack), RT_ETHERNETIF_THREAD_PREORITY, 16); assert(result == RT_EOK); result = rt_thread_startup(ð_rx_thread); assert(result == RT_EOK); /* init tx thread */ /* init mailbox and create ethernet thread */ result = rt_mb_init(ð_tx_thread_mb, "etxmb", ð_tx_thread_mb_pool[0], sizeof(eth_tx_thread_mb_pool)/4, RT_IPC_FLAG_FIFO); assert(result == RT_EOK); result = rt_thread_init(ð_tx_thread, "etx", eth_tx_thread_entry, NULL, ð_tx_thread_stack[0], sizeof(eth_tx_thread_stack), RT_ETHERNETIF_THREAD_PREORITY, 16); assert(result == RT_EOK); result = rt_thread_startup(ð_tx_thread); assert(result == RT_EOK); return result; }
void rt_mmcsd_core_init(void) { rt_err_t ret; /* init detect sd cart thread */ /* init mailbox and create detect sd card thread */ ret = rt_mb_init(&mmcsd_detect_mb, "mmcsdmb", &mmcsd_detect_mb_pool[0], sizeof(mmcsd_detect_mb_pool), RT_IPC_FLAG_FIFO); RT_ASSERT(ret == RT_EOK); ret = rt_thread_init(&mmcsd_detect_thread, "mmcsd_detect", mmcsd_detect, RT_NULL, &mmcsd_stack[0], RT_MMCSD_STACK_SIZE, RT_MMCSD_THREAD_PREORITY, 20); if (ret == RT_EOK) { rt_thread_startup(&mmcsd_detect_thread); } rt_sdio_init(); }
rt_err_t rtgui_send_sync(struct rtgui_app* app, rtgui_event_t *event, rt_size_t event_size) { rt_err_t r; rt_int32_t ack_buffer, ack_status; struct rt_mailbox ack_mb; RT_ASSERT(app != RT_NULL); RT_ASSERT(event != RT_NULL); RT_ASSERT(event_size != 0); rtgui_event_dump(app, event); /* init ack mailbox */ r = rt_mb_init(&ack_mb, "ack", &ack_buffer, 1, 0); if (r != RT_EOK) goto __return; event->ack = &ack_mb; r = rt_mq_send(app->mq, event, event_size); if (r != RT_EOK) { rt_kprintf("send sync event failed\n"); goto __return; } r = rt_mb_recv(&ack_mb, (rt_uint32_t *)&ack_status, RT_WAITING_FOREVER); if (r != RT_EOK) goto __return; if (ack_status != RTGUI_STATUS_OK) r = -RT_ERROR; else r = RT_EOK; __return: /* fini ack mailbox */ rt_mb_detach(&ack_mb); return r; }
rt_err_t rtgui_thread_send_sync(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size) { rt_err_t r; struct rtgui_thread* thread; rt_int32_t ack_buffer, ack_status; struct rt_mailbox ack_mb; rtgui_event_dump(tid, event); /* init ack mailbox */ r = rt_mb_init(&ack_mb, "ack", &ack_buffer, 1, 0); if ( r!= RT_EOK) goto __return; /* find rtgui_thread */ thread = (struct rtgui_thread*) (tid->user_data); if (thread == RT_NULL){ r = RT_ERROR; goto __return; } event->ack = &ack_mb; r = rt_mq_send(thread->mq, event, event_size); if (r != RT_EOK) { rt_kprintf("send sync event failed\n"); goto __return; } r = rt_mb_recv(&ack_mb, (rt_uint32_t*)&ack_status, RT_WAITING_FOREVER); if ( r!= RT_EOK) goto __return; if (ack_status != RTGUI_STATUS_OK) r = -RT_ERROR; else r = RT_EOK; /* fini ack mailbox */ rt_mb_detach(&ack_mb); __return: return r; }
int demo_init(void) { rt_err_t result; /* 初始化一个mailbox */ result = rt_mb_init(&mb, "mbt", /* 名称是mbt */ &mb_pool[0], /* 邮箱用到的内存池是mb_pool */ sizeof(mb_pool)/4, /* 邮箱中的邮件数目,因为一封邮件占4字节 */ RT_IPC_FLAG_FIFO); /* 采用FIFO方式进行线程等待 */ if (result != RT_EOK) { rt_kprintf("init mailbox failed.\n"); return -1; } rt_thread_init(&thread1, "thread1", thread1_entry, RT_NULL, &thread1_stack[0], sizeof(thread1_stack),10,5); rt_thread_startup(&thread1); rt_thread_init(&thread2, "thread2", thread2_entry, RT_NULL, &thread2_stack[0], sizeof(thread2_stack),10,5); rt_thread_startup(&thread2); return 0; }