void rt_task4_thread_entry(void* parameter) { extern void start_transmit(void); extern void stop_transmit(void); extern uint8_t check_parameter(void); // extern uint8_t self_check(void); // extern void cpu_usage_init(); rt_uint32_t ev; if((GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3) == 0)) { coil.usRegCoilBuf |= M(0); } else { coil.usRegCoilBuf &= ~M(0); } rt_event_init(&key_event, "key_event", RT_IPC_FLAG_FIFO ); while(1) { if( rt_event_recv( &key_event, FOOT_PUPD | KEY_PUPD, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &ev ) == RT_EOK ) { rt_thread_delay(6); if( (ev & FOOT_PUPD) && (coil.usRegCoilBuf & M(0)) &&(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == 0)&& \ (check_parameter()) && (coil.usRegCoilBuf & M(7))) { start_transmit(); } else { stop_transmit(); } if(ev & KEY_PUPD) { if((GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3) == 0)) { coil.usRegCoilBuf |= M(0); } else { coil.usRegCoilBuf &= ~M(0); } } } rt_event_recv( &key_event, FOOT_PUPD | KEY_PUPD, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 2, &ev ); rt_thread_delay(20); } }
BOOL xMBPortEventGet( eMBEventType * eEvent ) { rt_uint32_t recvedEvent; /* waiting forever OS event */ rt_event_recv(&xSlaveOsEvent, EV_READY | EV_FRAME_RECEIVED | EV_EXECUTE | EV_FRAME_SENT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &recvedEvent); switch (recvedEvent) { case EV_READY: *eEvent = EV_READY; break; case EV_FRAME_RECEIVED: *eEvent = EV_FRAME_RECEIVED; break; case EV_EXECUTE: *eEvent = EV_EXECUTE; break; case EV_FRAME_SENT: *eEvent = EV_FRAME_SENT; break; } return TRUE; }
/** * This function is wait for modbus master request finish and return result. * Waiting result include request process success, request respond timeout, * receive data error and execute function error.You can use the above callback function. * @note If you are use OS, you can use OS's event mechanism. Otherwise you have to run * much user custom delay for waiting. * * @return request error code */ eMBMasterReqErrCode eMBMasterWaitRequestFinish( void ) { eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR; rt_uint32_t recvedEvent; /* waiting for OS event */ rt_event_recv(&xMasterOsEvent, EV_MASTER_PROCESS_SUCESS | EV_MASTER_ERROR_RESPOND_TIMEOUT | EV_MASTER_ERROR_RECEIVE_DATA | EV_MASTER_ERROR_EXECUTE_FUNCTION, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &recvedEvent); switch (recvedEvent) { case EV_MASTER_PROCESS_SUCESS: break; case EV_MASTER_ERROR_RESPOND_TIMEOUT: { eErrStatus = MB_MRE_TIMEDOUT; break; } case EV_MASTER_ERROR_RECEIVE_DATA: { eErrStatus = MB_MRE_REV_DATA; break; } case EV_MASTER_ERROR_EXECUTE_FUNCTION: { eErrStatus = MB_MRE_EXE_FUN; break; } } return eErrStatus; }
void F_setBzTest(void) { rt_uint8_t keyCode = 0; rt_bool_t LongKeyStartFlg = 0; rt_uint32_t e; if (rt_event_recv(&sport_timer_event, 0xFFFF, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e) == RT_EOK) { if((e & time_20ms_val) == time_20ms_val) { F_ReadKeyCode(&keyCode,&LongKeyStartFlg,&ui_action.SleepTimer); switch(keyCode) { case stop_rest_KeyVal: bz_short(); F_EngineeringModeInit(BeeperTestEventVal); break; case enter_KeyVal: F_ChooseBzControl(); break; case resistance_up_KeyVal: if(LongKeyStartFlg == 0) { bz_short(); if(ui_action.Event > BzTest1EventVal) ui_action.Event--; else ui_action.Event = BzTest3EventVal; } break; case resistance_down_KeyVal: if(LongKeyStartFlg == 0) { bz_short(); ui_action.Event++; if(ui_action.Event>BzTest3EventVal) ui_action.Event = BzTest1EventVal; } break; } } //===================== if((e & time_100ms_val) == time_100ms_val) { F_SetDisplayRam(0); switch(ui_action.Event) { case BzTest1EventVal: F_ShowChooseBz1(); break; case BzTest2EventVal: F_ShowChooseBz2(); break; case BzTest3EventVal: F_ShowChooseBz3(); break; } F_Display(); } } }
void rt_can_thread_entry(void *parameter) { struct rt_can_msg msg; struct can_app_struct *canpara = (struct can_app_struct *) parameter; rt_device_t candev; rt_uint32_t e; candev = rt_device_find(canpara->name); RT_ASSERT(candev); rt_event_init(&canpara->event, canpara->name, RT_IPC_FLAG_FIFO); rt_device_open(candev, (RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX)); rt_device_control(candev, RT_CAN_CMD_SET_FILTER, canpara->filter); while (1) { if ( rt_event_recv(&canpara->event, ((1 << canpara->filter->items[0].hdr) | (1 << canpara->filter->items[1].hdr) | (1 << canpara->filter->items[2].hdr) | (1 << canpara->filter->items[3].hdr)), canpara->eventopt, RT_WAITING_FOREVER, &e) != RT_EOK ) { continue; } if (e & (1 << canpara->filter->items[0].hdr)) { msg.hdr = canpara->filter->items[0].hdr; while (rt_device_read(candev, 0, &msg, sizeof(msg)) == sizeof(msg)) { rt_device_write(candev, 0, &msg, sizeof(msg)); } } if (e & (1 << canpara->filter->items[1].hdr)) { msg.hdr = canpara->filter->items[1].hdr; while (rt_device_read(candev, 0, &msg, sizeof(msg)) == sizeof(msg)) { rt_device_write(candev, 0, &msg, sizeof(msg)); } } if (e & (1 << canpara->filter->items[2].hdr)) { msg.hdr = canpara->filter->items[2].hdr; while (rt_device_read(candev, 0, &msg, sizeof(msg)) == sizeof(msg)) { rt_device_write(candev, 0, &msg, sizeof(msg)); } } if (e & (1 << canpara->filter->items[3].hdr)) { msg.hdr = canpara->filter->items[3].hdr; while (rt_device_read(candev, 0, &msg, sizeof(msg)) == sizeof(msg)) { rt_device_write(candev, 0, &msg, sizeof(msg)); } } } }
BOOL xMBMasterPortEventGet( eMBMasterEventType * eEvent ) { rt_uint32_t recvedEvent; /* waiting forever OS event */ rt_event_recv(&xMasterOsEvent, EV_MASTER_READY | EV_MASTER_FRAME_RECEIVED | EV_MASTER_EXECUTE | EV_MASTER_FRAME_SENT | EV_MASTER_ERROR_PROCESS, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &recvedEvent); /* the enum type couldn't convert to int type */ switch (recvedEvent) { case EV_MASTER_READY: *eEvent = EV_MASTER_READY; break; case EV_MASTER_FRAME_RECEIVED: *eEvent = EV_MASTER_FRAME_RECEIVED; break; case EV_MASTER_EXECUTE: *eEvent = EV_MASTER_EXECUTE; break; case EV_MASTER_FRAME_SENT: *eEvent = EV_MASTER_FRAME_SENT; break; case EV_MASTER_ERROR_PROCESS: *eEvent = EV_MASTER_ERROR_PROCESS; break; } return TRUE; }
static int DownloadCommandToStation(WlanCard *cardinfo, HostCmd_DS_COMMAND * Cmd) { HostCmd_DS_COMMAND *CmdPtr; WlanCard *card = cardinfo; int ret = WLAN_STATUS_SUCCESS; rt_uint32_t event; CmdPtr = (HostCmd_DS_COMMAND *) Cmd; if (!CmdPtr || !CmdPtr->Size) { WlanDebug(WlanErr,"Download CMD parameter error\r\n"); ret = WLAN_STATUS_FAILURE; goto done; } card->CurCmd = Cmd; //WlanDebug(WlanCmd,"send CMD: 0x%x, len %d, Number %d\n",CmdPtr->Command, CmdPtr->Size, (CmdPtr->SeqNum)); ret = sbi_host_to_card(card, MVMS_CMD, (u8 *) CmdPtr, CmdPtr->Size); card->HisRegCpy &= ~HIS_TxDnLdRdy; rt_event_recv(&(cardinfo->cmdwaitevent), CmdWaitQWoken, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &event); ret = WLAN_STATUS_SUCCESS; done: return ret; }
//光流定点算法 void loiter(float x, float y, float yaw) { rt_uint32_t dump; if (check_safe(SAFE_ADNS3080)) { x_v_pid.out = 0; y_v_pid.out = 0; return; } if (rt_event_recv(&ahrs_event, AHRS_EVENT_ADNS3080, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, &dump) == RT_EOK) { PID_SetTarget(&x_d_pid, pos_X); PID_SetTarget(&y_d_pid, pos_y); PID_xUpdate(&x_d_pid, ahrs.x); PID_xUpdate(&y_d_pid, ahrs.y); PID_SetTarget(&x_v_pid, -RangeValue(x_d_pid.out, -10, 10)); PID_SetTarget(&y_v_pid, -RangeValue(y_d_pid.out, -10, 10)); PID_xUpdate(&x_v_pid, ahrs.dx); PID_xUpdate(&y_v_pid, ahrs.dy); } stable(+RangeValue(y_v_pid.out, -10, 10), -RangeValue(x_v_pid.out, -10, 10), yaw); }
void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c) { struct super_block *sb=OFNI_BS_2SFFJ(c); cyg_mtab_entry *mte; rt_uint32_t e; //RT_ASSERT(sb->s_gc_thread_handle); D1(printk("jffs2_stop_garbage_collect_thread\n")); /* Stop the thread and wait for it if necessary */ rt_event_send(&sb->s_gc_thread_flags,GC_THREAD_FLAG_STOP); D1(printk("jffs2_stop_garbage_collect_thread wait\n")); rt_event_recv(&sb->s_gc_thread_flags, GC_THREAD_FLAG_HAS_EXIT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e); // Kill and free the resources ... this is safe due to the flag // from the thread. rt_thread_detach(&sb->s_gc_thread); rt_sem_detach(&sb->s_lock); rt_event_detach(&sb->s_gc_thread_flags); }
void vMBPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable) { rt_uint32_t recved_event; if (xRxEnable) { /* enable RX interrupt */ serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX); /* switch 485 to receive mode */ rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_HIGH);//PIN_LOW); } else { /* switch 485 to transmit mode */ rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_LOW);//PIN_HIGH); /* disable RX interrupt */ serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX); } if (xTxEnable) { /* start serial transmit */ rt_event_send(&event_serial, EVENT_SERIAL_TRANS_START); } else { /* stop serial transmit */ rt_event_recv(&event_serial, EVENT_SERIAL_TRANS_START, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 0, &recved_event); } }
void correct_gryo() { rt_uint32_t e; rt_uint16_t i; rt_int16_t * mpu1, *mpu2, *mpu3; rt_int16_t m1, m2, m3; rt_kprintf("start sensors correct\n"); mpu1 = (rt_int16_t *)rt_calloc(255, sizeof(rt_int16_t)); mpu2 = (rt_int16_t *)rt_calloc(255, sizeof(rt_int16_t)); mpu3 = (rt_int16_t *)rt_calloc(255, sizeof(rt_int16_t)); for (i = 0;i < 255;i++) { if (rt_event_recv(&ahrs_event, AHRS_EVENT_Update, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e) == RT_EOK) { m1 = MoveAve_SMA(mpu_gryo_pitch, mpu1, 255); m2 = MoveAve_SMA(mpu_gryo_roll, mpu2, 255); m3 = MoveAve_SMA(mpu_gryo_yaw, mpu3, 255); } } MPU6050_Diff[0] -= m1; MPU6050_Diff[1] -= m2; MPU6050_Diff[2] -= m3; rt_free(mpu1); rt_free(mpu2); rt_free(mpu3); rt_kprintf("sensor correct finish.\n"); }
void fnAlarm(void) { rt_uint32_t e; uint8_t buf,int_m,t=0; uint16_t delay1,delay2,strength; rt_thread_delay_hmsm(0,0,3,0); int_m = (clock_m+5)%60; rt_kprintf("It is %d:%d now\nAlarm Level %d\n",clock_h,clock_m,t); rt_event_send(reg_event,REG_ALARM_MSK); while (rt_mq_recv(key_mq,&buf,sizeof(uint8_t),0)!=RT_EOK) { if (clock_m==int_m) { t+=1; int_m = (int_m+5)%60; rt_kprintf("Alarm Level %d\n",t); } switch (t) { case 0: delay1 = 500; delay2 = 4500; strength = 400; break; case 1: delay1 = 1000; delay2 = 2000; strength = 600; break; case 2: delay1 = 500; delay2 = 500; strength = 800; break; default: delay1 = 500; delay2 = 250; strength = 1000; break; } SetAlarm(strength); rt_thread_delay_hmsm(0,0,0,delay1); SetAlarm(0); Animate(delay2); } rt_event_recv(reg_event,REG_ALARM_MSK,RT_EVENT_FLAG_OR|RT_EVENT_FLAG_CLEAR,0,&e); return; }
/* 监视GPRS串口线程入口*/ void gprswatch_entry(void* parameter) { rt_err_t result = RT_EOK; rt_uint32_t event; char gprs_rx_buffer[512]={0x00}; while(1) { result = rt_event_recv(&rev_event, REV_MASK, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &event); if (result == RT_EOK) { if (event & REV_DATA) { rt_memset(gprs_rx_buffer,0x00,sizeof(gprs_rx_buffer)); rt_thread_delay(RT_TICK_PER_SECOND*2); rt_device_read(gprs_device, 0, gprs_rx_buffer, 512); rt_kprintf(gprs_rx_buffer); } if (event & REV_STOPWATCH) { return; } } } }
void F_setProfileInterval_2(void) { rt_uint8_t keyCode = 0; rt_bool_t LongKeyStartFlg = 0; rt_uint32_t e; rt_time_data_t SetWorkoutTime; if (rt_event_recv(&sport_timer_event, 0xFFFF, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e) == RT_EOK) { if((e & time_20ms_val) == time_20ms_val) { F_ReadKeyCode(&keyCode,&LongKeyStartFlg,&ui_action.SleepTimer); F_LongRestKey(keyCode); F_SeatPositionControlAllKey(&keyCode,LongKeyStartFlg); F_SetUserKey(keyCode); switch(ui_action.Event) { case setProfileLevelEventVal: F_setProfileLevelKey(keyCode,LongKeyStartFlg); break; case setProfileWorkOutTImeEventVal: F_setProfileWorkOutTImeKey(keyCode,LongKeyStartFlg); break; } } //===================== if((e & time_100ms_val) == time_100ms_val) { F_SetDisplayRam(0); if(ui_action.TemporarySeatPositionEvent == TemporarySeatPositionNormalEventVal) { switch(ui_action.Event) { case setProfileLevelEventVal: F_showProfileSetLeve(set_profile_data.interval_2_Level.number); F_ShowProgfileGraph(sport_data.progfileArry,ProgfileDataSizeVal,CommonModeVal,0,0); break; case setProfileWorkOutTImeEventVal: SetWorkoutTime.timeH = set_profile_data.interval_2_WorkoutMinTime.number; SetWorkoutTime.timeL = 0; F_showProfileSetWorkoutTime(SetWorkoutTime); break; } } else { F_showSeatPositionStatus(ui_action.TemporarySeatPositionEvent); } F_Display(); } //===================== if((e & time_1s_val) == time_1s_val) { F_SwitchingSeatPositionDisplayTimer(); } } }
static err_t low_level_output(struct netif *netif, struct pbuf *p) { struct pbuf *q; uint32_t Index, IndexNext; uint8_t *ptr; /* calculate next index */ IndexNext = LPC_EMAC->TxProduceIndex + 1; if(IndexNext > LPC_EMAC->TxDescriptorNumber) IndexNext = 0; #if 0 /* check whether block is full */ while (IndexNext == LPC_EMAC->TxConsumeIndex) { err_t result; uint32_t recved; /* there is no block yet, wait a flag */ result = rt_event_recv(&tx_event, 0x01, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &recved); } #endif Index = LPC_EMAC->TxProduceIndex; /* calculate next index */ IndexNext = LPC_EMAC->TxProduceIndex + 1; if(IndexNext > LPC_EMAC->TxDescriptorNumber) IndexNext = 0; #if ETH_PAD_SIZE pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ #endif /* copy data to tx buffer */ ptr = (uint8_t*)TX_BUF(Index); for(q = p; q != NULL; q = q->next) { MEMCPY(ptr, q->payload, q->len); ptr += q->len; } TX_DESC_CTRL(Index) = (p->tot_len - 1) & 0x7ff | EMAC_TCTRL_INT | EMAC_TCTRL_LAST; /* change index to the next */ LPC_EMAC->TxProduceIndex = IndexNext; #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif LINK_STATS_INC(link.xmit); return ERR_OK; }
/* transmit packet. */ rt_err_t lpc17xx_emac_tx( rt_device_t dev, struct pbuf* p) { rt_uint32_t Index, IndexNext; struct pbuf *q; rt_uint8_t *ptr; /* calculate next index */ IndexNext = LPC_EMAC->TxProduceIndex + 1; if(IndexNext > LPC_EMAC->TxDescriptorNumber) IndexNext = 0; /* check whether block is full */ while (IndexNext == LPC_EMAC->TxConsumeIndex) { rt_err_t result; rt_uint32_t recved; /* there is no block yet, wait a flag */ result = rt_event_recv(&tx_event, 0x01, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &recved); RT_ASSERT(result == RT_EOK); } /* lock EMAC device */ rt_sem_take(&sem_lock, RT_WAITING_FOREVER); /* get produce index */ Index = LPC_EMAC->TxProduceIndex; /* calculate next index */ IndexNext = LPC_EMAC->TxProduceIndex + 1; if(IndexNext > LPC_EMAC->TxDescriptorNumber) IndexNext = 0; /* copy data to tx buffer */ q = p; ptr = (rt_uint8_t*)TX_BUF(Index); while (q) { memcpy(ptr, q->payload, q->len); ptr += q->len; q = q->next; } TX_DESC_CTRL(Index) &= ~0x7ff; TX_DESC_CTRL(Index) |= (p->tot_len - 1) & 0x7ff; /* change index to the next */ LPC_EMAC->TxProduceIndex = IndexNext; /* unlock EMAC device */ rt_sem_release(&sem_lock); return RT_EOK; }
/** * Software simulation serial transmit IRQ handler. * * @param parameter parameter */ static void serial_soft_trans_irq(void* parameter) { rt_uint32_t recved_event; while (1) { /* waiting for serial transmit start */ rt_event_recv(&event_serial, EVENT_SERIAL_TRANS_START, RT_EVENT_FLAG_OR, RT_WAITING_FOREVER, &recved_event); /* execute modbus callback */ prvvUARTTxReadyISR(); } }
void F_setHeartRateTarget(void) { rt_uint8_t keyCode = 0; rt_bool_t LongKeyStartFlg = 0; rt_uint32_t e; rt_time_data_t SetWorkoutTime; if (rt_event_recv(&sport_timer_event, 0xFFFF, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e) == RT_EOK) { if((e & time_20ms_val) == time_20ms_val) { F_ReadKeyCode(&keyCode,&LongKeyStartFlg,&ui_action.SleepTimer); F_LongRestKey(keyCode); F_SeatPositionControlAllKey(&keyCode,LongKeyStartFlg); F_SportKey(keyCode); switch(ui_action.Event) { case showHeartRateSetTargetEventVal: F_setTargetKey(keyCode,LongKeyStartFlg); break; case showHeartRateWorkoutEventVal: F_setFatBurnWorkOutTImeKey(keyCode,LongKeyStartFlg); break; } } //===================== if((e & time_100ms_val) == time_100ms_val) { F_SetDisplayRam(0); if(ui_action.TemporarySeatPositionEvent == TemporarySeatPositionNormalEventVal) { switch(ui_action.Event) { case showHeartRateSetTargetEventVal: F_showSetTargetNum(profile_heartrate_data.TargetTarget.number,0); break; case showHeartRateWorkoutEventVal: SetWorkoutTime.timeH = profile_heartrate_data.TargetWorkoutMinTime.number; SetWorkoutTime.timeL = 0; F_showProfileSetWorkoutTime(SetWorkoutTime); break; } } else { F_showSeatPositionStatus(ui_action.TemporarySeatPositionEvent); } F_Display(); } //===================== if((e & time_1s_val) == time_1s_val) { F_SwitchingSeatPositionDisplayTimer(); } } }
int wait_int(int flag) { rt_uint32_t ev; if(flag) { /*wait for gdo0 to h */ #if 1 if( rt_event_recv( &cc1101_event, GDO0_H, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, 100, &ev ) != RT_EOK ) { rt_kprintf("wait for h failed\r\n"); cc1101_hw_init(); return RT_FALSE; } #else while(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_4)==RESET); #endif } else { /*wait for gdo0 to l */ #if 1 if( rt_event_recv( &cc1101_event, GDO0_L, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, 100, &ev ) != RT_EOK ) { rt_kprintf("wait for l failed\r\n"); cc1101_hw_init(); return RT_FALSE; } #else while(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_4)==SET); #endif } return RT_TRUE; }
void correct_thread_entry(void* parameter) { rt_uint32_t e; rt_uint16_t i; rt_int16_t * mpu1, *mpu2, *mpu3; rt_int16_t m1, m2, m3; rt_sem_init(&angle_fix_sem, "angle_fix", 0, RT_IPC_FLAG_FIFO); while (1) { rt_sem_take(&angle_fix_sem, RT_WAITING_FOREVER); rt_kprintf("start angle fix\n"); settings.angle_diff_pitch = 0; settings.angle_diff_roll = 0; settings.angle_diff_yaw = 0; mpu1 = (rt_int16_t *)rt_calloc(255, sizeof(rt_int16_t)); mpu2 = (rt_int16_t *)rt_calloc(255, sizeof(rt_int16_t)); mpu3 = (rt_int16_t *)rt_calloc(255, sizeof(rt_int16_t)); for (i = 0;i < 255;i++) { if (rt_event_recv(&ahrs_event, AHRS_EVENT_Update, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e) == RT_EOK) { m1 = MoveAve_SMA(ahrs.degree_pitch*1000.0f, mpu1, 255); m2 = MoveAve_SMA(ahrs.degree_roll *1000.0f, mpu2, 255); m3 = MoveAve_SMA(ahrs.degree_yaw *1000.0f, mpu3, 255); } } settings.angle_diff_pitch = -m1 / 1000.0f; settings.angle_diff_roll = -m2 / 1000.0f; settings.angle_diff_yaw = -m3 / 1000.0f; rt_free(mpu1); rt_free(mpu2); rt_free(mpu3); rt_kprintf("pitch:%d roll:%d yaw:%d\n", (s16)(settings.angle_diff_pitch), (s16)(settings.angle_diff_roll), (s16)(settings.angle_diff_yaw)); rt_kprintf("degree fix finish.\n"); save_settings(&settings, "/setting"); } }
rt_inline rt_err_t stm32_i2c_wait_ev(struct stm32_i2c_bus *bus, rt_uint32_t ev, rt_uint32_t timeout) { rt_uint32_t res = 0; rt_event_recv(&bus->ev, 0x01 << ev, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, timeout, &res); if(res != ev) { return RT_ERROR; } else { return RT_EOK; } }
static void rt_isr_event_entry(void* parameter) { rt_err_t err; rt_uint32_t e; printf_syn("rt_isr_event_entry()\n"); say_thread_start(); while (1) { err = rt_event_recv(&isr_event_set , EVENT_BIT_NEED_RUN_TIM2_IRQ | EVENT_BIT_NEED_RUN_TIM4_IRQ | EVENT_BIT_NEED_RUN_SI4432_MAC_EXTI_IRQ , RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e); if (RT_EOK != err) { printf_syn("recv isr event error(%d)", err); } else { #if RT_USING_SI4432_MAC if (is_bit_set(isr_event_var_flag, EVENT_BIT_NEED_RUN_SI4432_MAC_EXTI_IRQ)) { clr_bit(isr_event_var_flag, EVENT_BIT_NEED_RUN_SI4432_MAC_EXTI_IRQ); si4432_mac_exti_isr(); } #endif #if RT_USING_ADE7880 if (is_bit_set(isr_event_var_flag, EVENT_BIT_NEED_RUN_TIM4_IRQ)) { clr_bit(isr_event_var_flag, EVENT_BIT_NEED_RUN_TIM4_IRQ); #if 0 == ADE7880_USE_I2C_HSDC tim4_isr(); #endif } #endif #if RT_USING_SI4432_MAC if (is_bit_set(isr_event_var_flag, EVENT_BIT_NEED_RUN_SI4432_MAC_EXTI_IRQ)) { clr_bit(isr_event_var_flag, EVENT_BIT_NEED_RUN_SI4432_MAC_EXTI_IRQ); si4432_mac_exti_isr(); } if (is_bit_set(isr_event_var_flag, EVENT_BIT_NEED_RUN_TIM2_IRQ)) { clr_bit(isr_event_var_flag, EVENT_BIT_NEED_RUN_TIM2_IRQ); tim2_isr(); } #endif } } return; }
static void recv_thread_entry(void* parameter) { rt_uint32_t ev =0; rt_err_t ret = RT_EOK; rt_uint16_t recv_len = 0; while(1) { ret = rt_event_recv(cmd.recv_event,0x01,RT_EVENT_FLAG_AND|RT_EVENT_FLAG_CLEAR,RT_WAITING_FOREVER,&ev); if(ret == RT_EOK) { recv_len = rt_device_read(cmd.dev,0,cmd.recv_buf,1024); if (recv_len > 0) { int index =0; while(index <(recv_len-4)) { if((cmd.recv_buf[index]==0xaa)&&(cmd.recv_buf[index+1]==0xaf)&&(cmd.recv_buf[index+2]>0)&&(cmd.recv_buf[index+2]<0xf1)) { if(cmd.recv_buf[index+3]<50) { uint8_t cmd_len = cmd.recv_buf[index+3]; if(cmd_len+index<recv_len) { cmd.Data_Receive_Anl( &cmd.recv_buf[index],cmd_len+5); index+=cmd_len+5; } else { index++; } } else { index+=4; } } else { index++; } } } } } }
static void LD_thread_entry(void* parameter) { rt_uint32_t evt; // rt_base_t level; /* 关闭中断*/ rt_kprintf("进入LD专用线程!\r\n"); while(1) { if(rt_event_recv(&event,(1 << 0), RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR,50,&evt)== RT_EOK) { //level = rt_hw_interrupt_disable(); rt_enter_critical(); // rt_kprintf("mp3 playing..\r\n"); ProcessInt0(); // rt_hw_interrupt_enable(level); rt_exit_critical(); } } }
//定高算法 void althold(float height) { rt_uint32_t dump; if (check_safe(SAFE_SONAR)) { h_v_pid.out = 0; return; } //等待超声波模块信号 if (rt_event_recv(&ahrs_event, AHRS_EVENT_SONAR, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, &dump) == RT_EOK) { //双环定高 PID_SetTarget(&h_d_pid, 60.0f); PID_xUpdate(&h_d_pid, ahrs.height); PID_SetTarget(&h_v_pid, -RangeValue(h_d_pid.out, -50, +50)); PID_xUpdate(&h_v_pid, ahrs.height_v); h_v_pid.out = RangeValue(h_v_pid.out, -300, 300); } }
void F_eepromErrMode(void) { rt_uint32_t e; if (rt_event_recv(&sport_timer_event, 0xFFFF, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e) == RT_EOK) { if((e & time_20ms_val) == time_20ms_val) { } //===================== if((e & time_100ms_val) == time_100ms_val) { F_SetDisplayRam(0); F_ShowEepromErr(); F_Display(); } } }
void hm_heatcal_thread_entry(void* parameter) { rt_uint32_t event_set = 0; float heat_used = 0; cal_event = rt_event_create("H_cal", RT_IPC_FLAG_FIFO); RT_ASSERT(cal_event); while(1) { if(rt_event_recv(cal_event, TDC_DATA_FULL_EVENT, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &event_set)==RT_EOK) { if((rt_mutex_take(temp_lock, rt_tick_from_millisecond(LOCK_TACK_WAIT_TIME_MS)) || (rt_mutex_take(tof_lock, rt_tick_from_millisecond(LOCK_TACK_WAIT_TIME_MS)))) != RT_EOK) { rt_kprintf("TOF and temprature take lock error\n"); } heat_used += do_heat_cal(); rt_mutex_release(tof_lock); rt_mutex_release(temp_lock); heat_print(heat_used); } } }
static void jffs2_garbage_collect_thread(unsigned long data) { struct jffs2_sb_info *c=(struct jffs2_sb_info *)data; struct super_block *sb=OFNI_BS_2SFFJ(c); cyg_mtab_entry *mte; rt_uint32_t flag = 0; D1(printk("jffs2_garbage_collect_thread START\n")); while(1) { rt_event_recv(&sb->s_gc_thread_flags, GC_THREAD_FLAG_TRIG | GC_THREAD_FLAG_STOP, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, cyg_current_time() + CYGNUM_JFFS2_GS_THREAD_TICKS, &flag); if (flag & GC_THREAD_FLAG_STOP) break; D1(printk("jffs2: GC THREAD GC BEGIN\n")); mte=(cyg_dir *) sb->s_root; RT_ASSERT(mte != NULL); // rt_mutex_take(&mte->fs->syncmode, RT_WAITING_FOREVER); if (jffs2_garbage_collect_pass(c) == -ENOSPC) { printf("No space for garbage collection. " "Aborting JFFS2 GC thread\n"); break; } // rt_mutex_release(&mte->fs->syncmode); D1(printk("jffs2: GC THREAD GC END\n")); } D1(printk("jffs2_garbage_collect_thread EXIT\n")); rt_event_send(&sb->s_gc_thread_flags,GC_THREAD_FLAG_HAS_EXIT); }
/*GPRS串口发送和接收*/ rt_bool_t gprs_send_data_package(char *cmd,char *ack,uint16_t waittime, uint8_t retrytime) { rt_bool_t res = RT_FALSE; rt_err_t result = RT_EOK; rt_uint32_t event; char gprs_rx_buffer[512]={0x00}; rt_thread_t thread; thread = rt_thread_find("gprswatch"); if( thread != RT_NULL) rt_thread_delete(thread); do { rt_device_write(gprs_device, 0, cmd, rt_strlen(cmd)); result = rt_event_recv(&rev_event, REV_MASK, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, waittime*RT_TICK_PER_SECOND, &event); if (result == RT_EOK) { if (event & REV_DATA) { rt_memset(gprs_rx_buffer,0x00,sizeof(gprs_rx_buffer)); rt_thread_delay(RT_TICK_PER_SECOND*2); rt_device_read(gprs_device, 0, gprs_rx_buffer, 512); rt_kprintf(gprs_rx_buffer); if((rt_strstr(gprs_rx_buffer,ack))||(rt_strstr(gprs_rx_buffer,"OK"))) res = RT_TRUE; else res = RT_FALSE; } } retrytime--; }while((!res)&&(retrytime>=1)); gprswatch(); return res; }
void F_setProfileChoose(void) { rt_uint8_t keyCode = 0; rt_bool_t LongKeyStartFlg = 0; rt_uint32_t e; if (rt_event_recv(&sport_timer_event, 0xFFFF, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e) == RT_EOK) { if((e & time_20ms_val) == time_20ms_val) { F_ReadKeyCode(&keyCode,&LongKeyStartFlg,&ui_action.SleepTimer); F_LongRestKey(keyCode); F_SeatPositionControlAllKey(&keyCode,LongKeyStartFlg); F_SetUserKey(keyCode); switch(keyCode) { case quick_start_KeyVal: bz_short(); F_ProfileSportInit(ui_action.Event); break; case enter_KeyVal: bz_short(); F_SetProfileChooseMode(); break; case stop_rest_KeyVal: bz_short(); ui_action.ProfileEventSave = ui_action.Event; F_setProfileInit(setProfileEventVal); break; case resistance_up_KeyVal: if(LongKeyStartFlg == 0) { bz_short(); ui_action.Event++; if(ui_action.Event>setInterval_2_EventVal) ui_action.Event = setRollingHillEventVal; } break; case resistance_down_KeyVal: if(LongKeyStartFlg == 0) { bz_short(); if(ui_action.Event > setRollingHillEventVal) ui_action.Event--; else ui_action.Event = setInterval_2_EventVal; } break; } } //===================== if((e & time_100ms_val) == time_100ms_val) { F_SetDisplayRam(0); if(ui_action.TemporarySeatPositionEvent == TemporarySeatPositionNormalEventVal) { switch(ui_action.Event) { case setRollingHillEventVal: F_showRollingHillGraph(); F_RollingHillLevelCount(15,sport_data.progfileArry,ProgfileDataSizeVal); F_ShowProgfileGraph(sport_data.progfileArry,ProgfileDataSizeVal,CommonModeVal,0,0); break; case setPeakEventVal: F_showPeakGraph(); F_PeakLevelCount(15,sport_data.progfileArry,ProgfileDataSizeVal); F_ShowProgfileGraph(sport_data.progfileArry,ProgfileDataSizeVal,CommonModeVal,0,0); break; case setPlateauEventVal: F_showPlateauGraph(); F_PlateauLevelCount(15,sport_data.progfileArry,ProgfileDataSizeVal); F_ShowProgfileGraph(sport_data.progfileArry,ProgfileDataSizeVal,CommonModeVal,0,0); break; case setClimbEventVal: F_showClimbGraph(); F_ClimbLevelCount(15,sport_data.progfileArry,ProgfileDataSizeVal); F_ShowProgfileGraph(sport_data.progfileArry,ProgfileDataSizeVal,CommonModeVal,0,0); break; case setInterval_1_EventVal: F_showInterval_1_Graph(); F_Interval_1_LevelCount(15,sport_data.progfileArry,ProgfileDataSizeVal); F_ShowProgfileGraph(sport_data.progfileArry,ProgfileDataSizeVal,CommonModeVal,0,0); break; case setInterval_2_EventVal: F_showInterval_2_Graph(); F_Interval_2_LevelCount(15,sport_data.progfileArry,ProgfileDataSizeVal); F_ShowProgfileGraph(sport_data.progfileArry,ProgfileDataSizeVal,CommonModeVal,0,0); break; } } else { F_showSeatPositionStatus(ui_action.TemporarySeatPositionEvent); } F_Display(); } //===================== if((e & time_1s_val) == time_1s_val) { F_SwitchingSeatPositionDisplayTimer(); } } }