static void pw1_pid(void) { rt_uint32_t key_value; // static double coefy2a = 0.8; while(1) { LCD_Clear(); LCD_SetXY(0,0); LCD_WriteString("=====sonic_test====="); LCD_SetXY(0, 1); LCD_WriteString("1.front pid"); LCD_SetXY(0, 2); LCD_WriteString("2.f->pid"); LCD_SetXY(0, 3); LCD_WriteString("3.side pid"); LCD_SetXY(0, 4); LCD_WriteString("4.s->pid"); LCD_SetXY(10, 1); LCD_WriteString("5.fs pid"); if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK) { switch(key_value) { case key1: pole_sonic(0x01); break; case key2: _input_pid(&sPos_Pid[eF_sonic]); break; case key3: pole_sonic(0x02); break; case key4: _input_pid(&sPos_Pid[eS_sonic]); break; case key5: pole_sonic(0x03); break; case keyback: return; } } Delay_ms(10); } }
/* ethernet buffer */ void eth_tx_thread_entry(void* parameter) { struct eth_tx_msg* msg; while (1) { if (rt_mb_recv(ð_tx_thread_mb, (UInt32*)&msg, RT_WAITING_FOREVER) == RT_EOK) { struct eth_device* enetif; assert(msg->netif != NULL); assert(msg->buf != NULL); enetif = (struct eth_device*)msg->netif->state; if (enetif != NULL) { /* call driver's interface */ if (enetif->eth_tx(&(enetif->parent), msg->buf) != RT_EOK) { printf("transmit eth packet failed\n"); } } /* send ack */ rt_sem_release(&(enetif->tx_ack)); } } }
/* Ethernet Tx Thread */ static void eth_tx_thread_entry(void* parameter) { struct eth_tx_msg* msg; while (1) { if (rt_mb_recv(ð_tx_thread_mb, (rt_uint32_t*)&msg, RT_WAITING_FOREVER) == RT_EOK) { struct eth_device* enetif; RT_ASSERT(msg->netif != RT_NULL); RT_ASSERT(msg->buf != RT_NULL); enetif = (struct eth_device*)msg->netif->state; if (enetif != RT_NULL) { /* call driver's interface */ if (enetif->eth_tx(&(enetif->parent), msg->buf) != RT_EOK) { /* transmit eth packet failed */ } } /* send ACK */ rt_sem_release(&(enetif->tx_ack)); } } }
//打印在显示器上 void sys_Timer(void) { rt_uint32_t key_value; while(1) { LCD_Clear(); LCD_SetXY(0,0); LCD_WriteString("======Timer======="); LCD_SetXY(0,1); LCD_WriteString("M_TIME:"); LCD_WriteDouble(M_TIME); LCD_SetXY(0,2); LCD_WriteString("S_TIME:"); LCD_WriteDouble(S_TIME); LCD_SetXY(0,6); LCD_WriteString("1.Init_Timer"); if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK) { switch(key_value) { case key1: Init_Timer(); break; case keyback: return; } } Delay_ms(1); } }
rt_err_t gsm_send_wait_func( char *AT_cmd_string, uint32_t timeout, RESP_FUNC respfunc, uint8_t no_of_attempts ) { rt_err_t err; uint8_t i; char *pmsg; uint32_t tick_start, tick_end; uint32_t tm; __IO uint8_t flag_wait; char * pinfo; uint16_t len; err = rt_sem_take( &sem_at, timeout ); if( err != RT_EOK ) { return err; } for( i = 0; i < no_of_attempts; i++ ) { tick_start = rt_tick_get( ); tick_end = tick_start + timeout; tm = timeout; flag_wait = 1; rt_kprintf( "%08d gsm>%s\r\n", tick_start, AT_cmd_string ); m66_write( &dev_gsm, 0, AT_cmd_string, strlen( AT_cmd_string ) ); while( flag_wait ) { err = rt_mb_recv( &mb_gsmrx, (rt_uint32_t*)&pmsg, tm ); if( err == RT_EOK ) /*没有超时,判断信息是否正确*/ { len = ( *pmsg << 8 ) | ( *( pmsg + 1 ) ); pinfo = pmsg + 2; if( respfunc( pinfo, len ) == RT_EOK ) /*找到了*/ { rt_free( pmsg ); /*释放*/ rt_sem_release( &sem_at ); return RT_EOK; } rt_free( pmsg ); /*释放*/ /*计算剩下的超时时间,由于其他任务执行的延时,会溢出,要判断*/ if( rt_tick_get( ) < tick_end ) /*还没有超时*/ { tm = tick_end - rt_tick_get( ); }else { flag_wait = 0; } }else /*已经超时*/ { flag_wait = 0; } } } rt_sem_release( &sem_at ); return ( -RT_ETIMEOUT ); }
static rt_err_t spi_wifi_transfer(struct spi_wifi_eth *dev) { struct pbuf *p = RT_NULL; struct cmd_request cmd; struct response resp; rt_err_t result; const struct spi_data_packet *data_packet = RT_NULL; struct spi_wifi_eth *wifi_device = (struct spi_wifi_eth *)dev; struct rt_spi_device *rt_spi_device = wifi_device->rt_spi_device; spi_wifi_int_cmd(0); while (spi_wifi_is_busy()); WIFI_DEBUG("sequence start!\n"); memset(&cmd, 0, sizeof(struct cmd_request)); cmd.magic1 = CMD_MAGIC1; cmd.magic2 = CMD_MAGIC2; cmd.flag |= CMD_FLAG_MRDY; result = rt_mb_recv(&wifi_device->spi_tx_mb, (rt_uint32_t *)&data_packet, 0); if ((result == RT_EOK) && (data_packet != RT_NULL) && (data_packet->data_len > 0)) { cmd.M2S_len = data_packet->data_len + member_offset(struct spi_data_packet, buffer); //WIFI_DEBUG("cmd.M2S_len = %d\n", cmd.M2S_len); }
struct pbuf *pcap_netif_rx(rt_device_t dev) { struct pbuf* p = RT_NULL; rt_mb_recv(packet_mb, (rt_uint32_t*)&p, 0); return p; }
/*********************************************************** * Function: * Description: * Input: * Input: * Output: * Return: * Others: ***********************************************************/ rt_err_t gsm_send_wait_str_ok( char *AT_cmd_string, uint32_t timeout, char * respstr, uint8_t no_of_attempts ) { rt_err_t err; uint8_t i = 0; char *pmsg; uint32_t tick_start, tick_end; uint32_t tm; __IO uint8_t flag_wait = 1; err = rt_sem_take( &sem_at, timeout ); if( err != RT_EOK ) { return err; } for( i = 0; i < no_of_attempts; i++ ) { tick_start = rt_tick_get( ); tick_end = tick_start + timeout; tm = timeout; flag_wait = 1; rt_kprintf( "%08d gsm>%s\r\n", tick_start, AT_cmd_string ); m66_write( &dev_gsm, 0, AT_cmd_string, strlen( AT_cmd_string ) ); while( flag_wait ) { err = rt_mb_recv( &mb_gsmrx, (rt_uint32_t*)&pmsg, tm ); if( err == RT_EOK ) /*没有超时,判断信息是否正确*/ { if( strstr( pmsg + 2, respstr ) != RT_NULL ) /*找到了*/ { rt_free( pmsg ); /*释放*/ goto lbl_send_wait_ok; } rt_free( pmsg ); /*释放*/ /*计算剩下的超时时间,由于其他任务执行的延时,会溢出,要判断*/ if( rt_tick_get( ) < tick_end ) /*还没有超时*/ { tm = tick_end - rt_tick_get( ); }else { flag_wait = 0; } }else /*已经超时*/ { flag_wait = 0; } } } rt_sem_release( &sem_at ); return -RT_ETIMEOUT; lbl_send_wait_ok: err = gsm_wait_str( "OK", RT_TICK_PER_SECOND * 2 ); rt_sem_release( &sem_at ); return err; }
/* * 函数名: HallTest * 描 述: * 输 入: 无 * 输 出: 无 * 调 用: 外部调用 */ void HallTest(void) { rt_uint32_t key_value; extern u8 Hall_Count; while(1) { LCD_Clear(); LCD_SetXY(0,0); LCD_WriteString("========Hall========"); LCD_SetXY(0,1); LCD_WriteString("1.SS_init"); LCD_SetXY(0,2); LCD_WriteString("2.open hand_SS"); LCD_SetXY(0,3); LCD_WriteString("3.leg_on"); LCD_SetXY(0,4); LCD_WriteString("4.leg_off"); LCD_SetXY(0,5); LCD_WriteString("5.open hand_SW"); LCD_SetXY(0,6); LCD_WriteString("6.PW_init"); LCD_SetXY(0,7); LCD_WriteInt(Hall_Count-1); if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK) { switch(key_value) { case key1: Hall_Send(1); break; case key2: Hall_Send(2); break; case key3: Hall_Send(3); break; case key4: Hall_Send(4); break; case key5: Hall_Send(5); break; case key6: Hall_Send(6); break; case keyback: return; } } Delay_ms(10); } }
void sys_ImgSave(void) { rt_uint32_t key_value; while(1) { LCD_Clear(); LCD_SetXY(0,0); LCD_WriteString("======Img Save======"); LCD_SetXY(0,1); LCD_WriteString("1.b_seesaw"); LCD_SetXY(0,2); LCD_WriteString("2.b_polewalk"); LCD_SetXY(0,3); LCD_WriteString("3.b_whitetape"); LCD_SetXY(0,4); LCD_Printf("4.Handover"); if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK) { switch(key_value) { u8 res; case key1: /* save image from camera1 ,file name is "b_seesaw.txt" */ res = Save_Img("b_seesaw", 1); _show_res(res); break; case key2: res = Save_Img("b_polewalk", 4); _show_res(res); break; case key3: res = Save_Img("b_whitetape", 2); _show_res(res); res = Save_Img("b_whitetape", 1); _show_res(res); break; case key4: res = Save_Img("Handover",5); _show_res(res); break; case keyback: return; } } Delay_ms(10); } }
/* Ethernet Rx Thread */ static void eth_rx_thread_entry(void* parameter) { struct eth_device* device; while (1) { if (rt_mb_recv(ð_rx_thread_mb, (UInt32*)&device, RT_WAITING_FOREVER) == RT_EOK) { struct pbuf *p; /* check link status */ if (device->link_changed) { int status; UInt32 level; level = rt_hw_interrupt_disable(); status = device->link_status; device->link_changed = 0x00; rt_hw_interrupt_enable(level); if (status) netifapi_netif_set_link_up(device->netif); else netifapi_netif_set_link_down(device->netif); } /* receive all of buffer */ while (1) { p = device->eth_rx(&(device->parent)); if (p != NULL) { /* notify to upper layer */ if( device->netif->input(p, device->netif) != ERR_OK ) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: Input error\n")); pbuf_free(p); p = NULL; } } else break; } } else { LWIP_ASSERT("Should not happen!\n",0); } } }
/* * 函数名: RadarTest * 描 述: 激光雷达数据显示 * 输 入: 无 * 输 出: 无 * 调 用: 外部调用 */ void RadarTest(void) { rt_uint32_t key_value; while(1) { LCD_Clear(); LCD_SetXY(0,0); LCD_WriteString("=======Radar========"); LCD_SetXY(0,1); LCD_Printf("%d",sonic_data[0].data); LCD_SetXY(10, 1); LCD_Printf("%d",sonic_data[0].count); LCD_SetXY(0,2); LCD_Printf("%d",sonic_data[3].data); LCD_SetXY(10,2); LCD_Printf("%d",sonic_data[3].count); if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK) { switch(key_value) { case key1: break; case key2: break; case key3: break; case key4: break; case key5: break; case key6: break; case keyback: return; default: break; } } Delay_ms(10); } }
/* * 函数名: LBTest * 描 述: 灯板测试函数 * 输 入: 无 * 输 出: 无 * 调 用: 外部调用 */ void LBTest(void) { rt_uint32_t key_value; while(1) { LCD_Clear(); LCD_SetXY(0,0); LCD_WriteString("=========LB========="); LCD_SetXY(0,1); LCD_WriteString("LB1:"); LCD_WriteInt(LB_Count(1)); LCD_SetXY(10,1); LCD_WriteString("LB2:"); LCD_WriteInt(LB_Count(2)); LCD_SetXY(0,2); LCD_WriteString("LB1:"); LCD_Printf("%s",itob(LB_recv[0].v)); LCD_SetXY(0,4); LCD_WriteString("LB2:"); LCD_Printf("%s",itob(LB_recv[1].v)); LCD_SetXY(0,6); LCD_WriteString("1.LB_Init"); LCD_SetXY(10,6); LCD_WriteString("2.LB_State"); LCD_SetXY(0,7); LCD_WriteString("3.LB_Test"); if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK) { switch(key_value) { case key1: LB_Init(); break; case key2: LB_State(); break; case key3: LB_Test(); break; case keyback: return; } } Delay_ms(10); } }
/** Wait for a new message to arrive in the mbox * @param mbox mbox to get a message from * @param msg pointer where the message is stored * @param timeout maximum time (in milliseconds) to wait for a message * @return 0 (milliseconds) if a message has been received * or SYS_MBOX_EMPTY if the mailbox is empty */ u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) { int ret; ret = rt_mb_recv(*mbox, (rt_uint32_t *)msg, 0); if(ret == -RT_ETIMEOUT) return SYS_ARCH_TIMEOUT; else { if (ret == RT_EOK) ret = 1; } return ret; }
/* * 函数名: RecKin * 描 述: 测试 Kinect 接受 * 输 入: 无 * 输 出: 无 * 调 用: 外部调用 */ void RecKin_Print(void) { rt_uint32_t key_value; while(1) { LCD_Clear(); LCD_SetXY(0,0); LCD_WriteString("========Receiving========"); LCD_SetXY(0,1); LCD_Printf("x = %d",(int)uart_data.x); LCD_SetXY(0,2); LCD_Printf("y = %d",(int)uart_data.y); LCD_SetXY(0,3); LCD_Printf("z = %d",(int)uart_data.z); LCD_SetXY(0,4); LCD_Printf("Now Angle:%g %g %g",Motor_Pos[W_MOTOR1_OLD_ID-W_MOTOR1_OLD_ID]*360,\ Motor_Pos[W_MOTOR2_OLD_ID-W_MOTOR1_OLD_ID]*360,Motor_Pos[W_MOTOR3_OLD_ID-W_MOTOR1_OLD_ID]*360); LCD_SetXY(0,5); LCD_Printf("1.STOP %d %d %d",(int)(Motor_RealAim[W_MOTOR1_OLD_ID-W_MOTOR1_OLD_ID]*360/1000),\ (int)(Motor_RealAim[W_MOTOR2_OLD_ID-W_MOTOR1_OLD_ID]*360/1000),(int)(Motor_RealAim[W_MOTOR3_OLD_ID-W_MOTOR1_OLD_ID]*360/1000)); LCD_SetXY(0,7); LCD_WriteString("1.Set_XYZ"); if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK) { switch(key_value) { case key1: Input_DoubleValue(&uart_data.x,"x"); Input_DoubleValue(&uart_data.y,"y"); Input_DoubleValue(&uart_data.z,"z"); Input_IntValue(&pos_speed.v_A,"v_A"); Input_IntValue(&pos_speed.v_B,"v_B"); // Input_IntValue(&pos_speed.v_C,"v_C"); Data_Processing(); W_MOTOR_OLD_FUNC(W_MOTOR2_OLD_ID, (float)pos_speed.pos_A , (int16_t)pos_speed.v_A , CMD_SET_PSG); W_MOTOR_OLD_FUNC(W_MOTOR2_OLD_ID, (float)pos_speed.pos_B , (int16_t)pos_speed.v_B , CMD_SET_PSG); // W_MOTOR_OLD_FUNC(W_MOTOR3_OLD_ID, (float)pos_speed.pos_C , (int16_t)pos_speed.v_C , CMD_SET_PSG); break; case keyback: return; } } Delay_ms(10); } }
/* * 函数名: DataBack * 描 述: 数据回传函数 * 输 入: 无 * 输 出: 无 * 调 用: 外部调用 */ void DataBackTest(void) { // rt_uint32_t key_value; while(1) { LCD_Clear(); LCD_SetXY(0,0); LCD_WriteString("======DataBack======"); LCD_SetXY(0,1); #if DataBackEnable LCD_WriteString("DataNumber:"); LCD_WriteInt(DataBack_GetCount()); LCD_SetXY(0,2); LCD_WriteString("Press OK to send"); if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK) { switch(key_value) { case keyOK: LCD_Clear(); LCD_SetXY(5,3); LCD_WriteString("Waiting..."); DataBack_Write(DataBack_GetCount()); DataBack_Send(); Com_SendByte(2,'$'); LCD_Clear(); LCD_SetXY(7,3); LCD_WriteString("Done~!"); Delay_ms(500); break; case keyback: return; } } #else LCD_WriteString("Please Enable the DataBack Function"); #endif Delay_ms(10); } }
void mmcsd_detect(void *param) { struct rt_mmcsd_host *host; rt_uint32_t ocr; rt_int32_t err; while (1) { if (rt_mb_recv(&mmcsd_detect_mb, (rt_uint32_t*)&host, RT_WAITING_FOREVER) == RT_EOK) { if (host->card == RT_NULL) { mmcsd_host_lock(host); mmcsd_power_up(host); mmcsd_go_idle(host); mmcsd_send_if_cond(host, host->valid_ocr); err = sdio_io_send_op_cond(host, 0, &ocr); if (!err) { if (init_sdio(host, ocr)) mmcsd_power_off(host); mmcsd_host_unlock(host); continue; } /* * detect SD card */ err = mmcsd_send_app_op_cond(host, 0, &ocr); if (!err) { if (init_sd(host, ocr)) mmcsd_power_off(host); mmcsd_host_unlock(host); continue; } mmcsd_host_unlock(host); } } } }
/* ethernet buffer */ void eth_rx_thread_entry(void* parameter) { struct eth_device* device; err_t err_ret; while (1) { if (rt_mb_recv(ð_rx_thread_mb, (rt_uint32_t*)&device, RT_WAITING_FOREVER) == RT_EOK) { struct pbuf *p; /* check link status */ if (device->link_changed) { int status; rt_uint32_t level; level = rt_hw_interrupt_disable(); status = device->link_status; device->link_changed = 0x00; rt_hw_interrupt_enable(level); if (status) netifapi_netif_set_link_up(device->netif); else netifapi_netif_set_link_down(device->netif); } /* receive all of buffer */ while (1) { p = device->eth_rx(&(device->parent)); if (p != RT_NULL) { /* notify to upper layer */ if( (err_ret=device->netif->input(p, device->netif)) != ERR_OK ) { printf_syn("ethernetif_input: Input error(%d)\n", err_ret); pbuf_free(p); p = NULL; } } else { break; } } } } }
u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout) { rt_err_t ret; s32_t t; u32_t tick; /* get the begin tick */ tick = rt_tick_get(); if(timeout == 0) t = RT_WAITING_FOREVER; else { /* convirt msecond to os tick */ if (timeout < (1000/RT_TICK_PER_SECOND)) t = 1; else t = timeout / (1000/RT_TICK_PER_SECOND); } ret = rt_mb_recv(mbox, (rt_uint32_t *)msg, t); if(ret == -RT_ETIMEOUT) return SYS_ARCH_TIMEOUT; else if (ret == RT_EOK) ret = 1; #if SYS_DEBUG { struct rt_thread *thread; thread = rt_thread_self(); LWIP_DEBUGF(SYS_DEBUG, ("%s, Fetch mail: %s , 0x%x\n",thread->name, mbox->parent.parent.name, *(rt_uint32_t **)msg)); } #endif /* get elapse msecond */ tick = rt_tick_get() - tick; /* convert tick to msecond */ tick = tick * (1000/RT_TICK_PER_SECOND); if (tick == 0) tick = 1; return tick; }
/** Wait for a new message to arrive in the mbox * @param mbox mbox to get a message from * @param msg pointer where the message is stored * @param timeout maximum time (in milliseconds) to wait for a message * @return time (in milliseconds) waited for a message, may be 0 if not waited or SYS_ARCH_TIMEOUT on timeout * The returned time has to be accurate to prevent timer jitter! */ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) { rt_err_t ret; s32_t t; u32_t tick; RT_DEBUG_NOT_IN_INTERRUPT; /* get the begin tick */ tick = rt_tick_get(); if(timeout == 0) t = RT_WAITING_FOREVER; else { /* convirt msecond to os tick */ if (timeout < (1000/RT_TICK_PER_SECOND)) t = 1; else t = timeout / (1000/RT_TICK_PER_SECOND); } ret = rt_mb_recv(*mbox, (rt_uint32_t *)msg, t); if(ret == -RT_ETIMEOUT) return SYS_ARCH_TIMEOUT; else { LWIP_ASSERT("rt_mb_recv returned with error!", ret == RT_EOK); } /* get elapse msecond */ tick = rt_tick_get() - tick; /* convert tick to msecond */ tick = tick * (1000 / RT_TICK_PER_SECOND); if (tick == 0) tick = 1; return tick; }
void sys_sonic(void) { rt_uint32_t key_value; while(1) { LCD_Clear(); LCD_SetXY(0,0); LCD_WriteString("====pole_test===="); LCD_SetXY(0, 1); LCD_WriteString("1.step1"); LCD_SetXY(0, 2); LCD_WriteString("2.xypid"); LCD_SetXY(0, 3); LCD_WriteString("3.pw1"); LCD_SetXY(0, 4); LCD_WriteString("4.dis"); LCD_SetXY(10, 1); LCD_WriteString("5.sd save"); LCD_SetXY(10, 2); LCD_WriteString("6."); LCD_SetXY(10, 3); LCD_WriteString("7."); LCD_SetXY(10, 4); LCD_WriteString("8."); if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK) { switch(key_value) { case key1: _step1(); break; case key2: pw1_pid(); break; case key3: sonic_pw1(); break; case key4: Input_DoubleValue(&std_fdis, "f dis"); Input_DoubleValue(&std_sdis, "s dis"); case key5: { int _sonicx = 0 ; Input_IntValue(&_sonicx, "_sonicx"); sonic_SDsave(_sonicx, "sonic_data", 500); } break; case keyback: return; } } Delay_ms(10); } }
u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg) { int ret; ret = rt_mb_recv(mbox, (rt_uint32_t *)msg, 0); if(ret == -RT_ETIMEOUT) return SYS_ARCH_TIMEOUT; else if (ret == RT_EOK) ret = 1; #if SYS_DEBUG { struct rt_thread *thread; thread = rt_thread_self(); LWIP_DEBUGF(SYS_DEBUG, ("%s, Fetch mail: %s , 0x%x\n",thread->name, mbox->parent.parent.name, *(rt_uint32_t **)msg)); } #endif return ret; }
/*等待固定字符串的返回*/ rt_err_t gsm_wait_str( char *respstr, uint32_t timeout ) { rt_err_t err; uint8_t *pmsg; uint32_t tick_start, tick_end; uint32_t tm; __IO uint8_t flag_wait = 1; tick_start = rt_tick_get( ); tick_end = tick_start + timeout; tm = timeout; while( flag_wait ) { err = rt_mb_recv( &mb_gsmrx, (rt_uint32_t*)&pmsg, tm ); if( err != -RT_ETIMEOUT ) /*没有超时,判断信息是否正确*/ { if( strstr( pmsg + 2, respstr ) != RT_NULL ) /*前两个字节为长度,找到了*/ { rt_free( pmsg ); /*释放*/ return RT_EOK; } rt_free( pmsg ); /*释放*/ /*计算剩下的超时时间,由于其他任务执行的延时,会溢出,要判断*/ if( rt_tick_get( ) < tick_end ) /*还没有超时*/ { tm = tick_end - rt_tick_get( ); }else { flag_wait = 0; } }else /*已经超时*/ { flag_wait = 0; } } return RT_ETIMEOUT; }
/* 线程1入口 */ static void thread1_entry(void* parameter) { char* str; while (1) { rt_kprintf("thread1: try to recv a mail\n"); /* 从邮箱中收取邮件 */ if (rt_mb_recv(&mb, (rt_uint32_t*)&str, RT_WAITING_FOREVER) == RT_EOK) { rt_kprintf("thread1: get a mail from mailbox, the content:%s\n", str); if (str == mb_str3) break; /* 延时10个OS Tick */ rt_thread_delay(10); } } /* 执行邮箱对象脱离 */ rt_mb_detach(&mb); }
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; }
void LookIt(void) { rt_uint32_t key_value; // int i; while(1) { LCD_Clear(); LCD_SetXY(0,0);LCD_Printf("1.AngleSwing %d",AngleSwing); LCD_SetXY(0,1);LCD_Printf("2.AngleHit %d",AngleHit); LCD_SetXY(0,2);LCD_Printf("3.pos_A %f",pos_speed.pos_A); LCD_SetXY(0,3);LCD_Printf("4.pos_B %f",pos_speed.pos_B); if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK) { if(key_value == keyback) { return ; } } Delay_ms(10); } }
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; }
/* ethernet buffer */ void eth_rx_thread_entry(void* parameter) { struct eth_device* device; while (1) { if (rt_mb_recv(ð_rx_thread_mb, (UInt32*)&device, RT_WAITING_FOREVER) == RT_EOK) { struct pbuf *p; /* receive all of buffer */ while (1) { p = device->eth_rx(&(device->parent)); if (p != NULL) { /* notify to upper layer */ eth_input(p, device->netif); } else break; } } } }
void dfs_thread_entry(void* parameter) { char *rev_meail;//定义指针,用来保存邮件内容 /******************启动文件系统***************/ /* init the device filesystem */ dfs_init(); elm_init(); /* mount sd card fat partition 1 as root directory */ if (dfs_mount("sd0", "/", "elm", 0, 0) == 0) { rt_kprintf("文件系统初始化成功!\n"); } else rt_kprintf("文件系统初始化失败!\n"); /*************************初始化LD3320***********************/ ld3320_gpio_configuration(); ld3320_nvic_cfg(); ld3320_spi_init(); LD_reset(); nAsrStatus = LD_ASR_NONE; bMp3Play=0; if(wugege_read_ini(sys_ini_name)!=1) rt_kprintf("读取系统配置文件失败,语音识别将受到严重影响\n"); rt_kprintf("读取系统配置文件成功\n"); if(PlayDemoSound_mp3(sys_shi_mp3)<0) rt_kprintf(" 播放初始化音乐失败,请确认是否能使用LD3320!\n"); rt_kprintf("播放初始化音乐成功!\n"); rt_thread_delay(10);//延迟该线程10ms sys_wake=1; sys_wake_count=0; while(1) { if(RT_EOK==(rt_mb_recv(&mb,(rt_uint32_t*)&rev_meail,RT_WAITING_NO))) { rt_kprintf("接收到邮件,播放音乐%s\r\n",rev_meail); if(PlayDemoSound_mp3(rev_meail)<0) rt_kprintf("播放音乐失败%s \r\n",rev_meail); rt_kprintf("接收到邮件,播放音乐完毕\r\n"); // *rev_meail=NULL; nAsrStatus = LD_ASR_NONE; } rt_thread_delay(5);//延迟该线程5ms while(bMp3Play != 0) rt_thread_delay(5); switch (nAsrStatus) { case LD_ASR_RUNING: // LD3320芯片正在语音识别中 break; case LD_ASR_ERROR: // LD3320芯片发生错误 break; case LD_ASR_NONE: // LD3320芯片无动作 { nAsrStatus=LD_ASR_RUNING; if (RunASR(sys_wake)==0) // 启动一次ASR识别流程:ASR初始化,ASR添加关键词语,启动ASR运算 { nAsrStatus = LD_ASR_ERROR; } break; } case LD_ASR_FOUNDOK: // LD3320芯片识别到语音 { char mp3_name[25]; //mp3文件名缓冲区 char action[15]; char ini_name[20]; int nAsrRes = LD_GetResult(); // 一次ASR识别流程结束,去取ASR识别结果 if(nAsrRes==49) { sys_wake=1; sys_wake_count=0; PlayDemoSound_mp3(sys_shi_mp3); rt_kprintf("系统唤醒成功 \n"); } else if(sys_wake) { get_mps_ini_file(mp3_name,ini_name,action,nAsrRes); rt_kprintf("识别用户的mp3名字 %s 配置文件%s 命令%s 原始码%d\r\n",mp3_name,ini_name,action,nAsrRes); sys_wake_count=0; sys_wake=1; deal_action(action); if(PlayDemoSound_mp3(mp3_name)<0) rt_kprintf("播放音乐失败%s \r\n",mp3_name); if(0!=strcmp(ini_name,sys_ini_name)) { strcpy(sys_ini_name,ini_name); rt_kprintf("重新载入配置文件%s \r\n",sys_ini_name); if(wugege_read_ini(sys_ini_name)!=1) rt_kprintf("读取系统配置文件失败,语音识别将受到严重影响\r\n"); } } rt_kprintf("\r\n识别到用户关键字为:%d \r\n",nAsrRes); nAsrStatus = LD_ASR_NONE; break; } case LD_ASR_FOUNDZERO: //无识别结果 nAsrStatus = LD_ASR_NONE; break; default: nAsrStatus = LD_ASR_NONE; break; } } }
static void led3_thread_entry(void* parameter) { rt_kprintf ( "\r\n led3_thread_entry!!\r\n"); irmp_init(); // initialize irmp irsnd_init(); timer2_init(); // initialize timer2 rt_kprintf ( "\r\n 红外收发系统初始化完成!\r\n"); for (;;) { char *str; // rt_kprintf ( "IRMP is going!!!\r\n"); rt_thread_delay(1); if(RT_EOK== (rt_mb_recv(&dfs_mb,(rt_uint32_t*)&str,RT_WAITING_NO))) {rt_kprintf("接收到控制邮件,数据为 %s",str); // TIM_Cmd(TIM2, ENABLE); if(strcmp(str,"getremote")==0) hot_remote_state=1; if(strcmp(str,"sendremote")==0) hot_remote_send=1; } if (irmp_get_data (&irmp_data)) { rt_kprintf("接收红外信号编码方式: %s",irmp_protocol_names[irmp_data.protocol]); rt_kprintf(" 编码地址: 0x%2X",irmp_data.address); rt_kprintf(" 命令: 0x%2X",irmp_data.command); rt_kprintf(" 标志位: 0x%2X\r\n",irmp_data.flags ); if(1==hot_remote_state) { hot_remote_state=2; irmp_data1=irmp_data; rt_mb_send(&mb,(rt_uint32_t)get_remot1_mp3);//发送邮件 rt_kprintf("红外接收完成第一次\n" ); } else if(2==hot_remote_state) { if(irmp_data1.command==irmp_data.command) { rt_kprintf("红外接收完成第二次,验证通过\n" ); rt_mb_send(&mb,(rt_uint32_t)get_remot2_mp3);//发送邮件 hot_remote_state=0; // TIM_Cmd(TIM2, DISABLE); } else { rt_kprintf("红外接收完成第二次,验证不通过,再次接收红外数据\n" ); rt_mb_send(&mb,(rt_uint32_t)check_fail_mp3);//发送邮件 hot_remote_state=1; } } } if(hot_remote_send) { hot_remote_send=0; // TIM_Cmd(TIM2, ENABLE); /* irmp_data.protocol = IRMP_SAMSUNG32_PROTOCOL; // use NEC protocol irmp_data.address = 0x0e0e; // set address to 0x00FF irmp_data.command = 0xf30c; // set command to 0x0001 irmp_data.flags = 0; // don't repeat frame*/ irsnd_send_data (&irmp_data, TRUE); // send frame, wait for completion // don't repeat frame rt_mb_send(&mb,(rt_uint32_t)sen_remot_mp3); rt_kprintf("发送红外数据完成\n"); rt_kprintf("发射红外信号编码方式: %s",irmp_protocol_names[irmp_data.protocol]); rt_kprintf(" 编码地址: 0x%2X",irmp_data.address); rt_kprintf(" 命令: 0x%2X",irmp_data.command); rt_kprintf(" 标志位: 0x%2X\r\n",irmp_data.flags ); // TIM_Cmd(TIM2, DISABLE); } } }