PUBLIC void schedule(void) /* find another runnable thread */ { struct thread *t; int i; need_reschedule=0; again: check_alarms(); for (i=0; i < MAX_THREADS; i++) { last_run = (last_run+1) % MAX_THREADS; /* wrap around */ t = thread_table + last_run; if (t->status == THREAD_READY) break; } if (i == MAX_THREADS) { if (to_alarm) { sleep(1); /*!!!*/ goto again; } if (alive) panic("No thread runnable, %d alive\n", alive); else exit(0); /* All threads dead */ } if (DEBUG_LEVEL >=2) printf("Now scheduling %d\n", t - thread_table); else run_thread(t - thread_table); /* return to calling thread */ }
void do_tick() { if(!current_task || (kernel_state_flags&KSF_PANICING)) return; if(!(((cpu_t *)current_task->cpu)->flags & CPU_TASK)) return; if(current_task) { current_task->system ? (++current_task->stime) : (++current_task->utime); inc_parent_times(current_task->parent, current_task->system ? __SYS : __USR); } check_alarms(); if(current_task != kernel_task) { if(task_is_runable(current_task) && current_task->cur_ts>0 && --current_task->cur_ts) return; else if(current_task->cur_ts <= 0) current_task->cur_ts = GET_MAX_TS(current_task); } do_run_scheduler(); }
void Task_SmartPHTApp(void) { message_t msg; adc_voltages_t *v; sensor_data_t *c; byte_t comRecvByte; if (knl_mailbox_pend(&taskMailbox, &msg) == RV_OK) { switch (msg.MsgId) { case MSG_ID_SYS_VOLTAGE_UPDATE: v = (adc_voltages_t*) msg.Param0; //tiny_printf("SYS: Vbat=%dmV, Vcc=%dmV, Vdd=%dmV, Vtft=%dmV\n", v->vbat, v->vcc, v->vdd, v->vtft); // if(v->vdd < 3000) // tty_output("SYS: system voltage is low!\n"); // if(v->vbat < 3300) // tty_output("SYS: BATTERY LOW! replace or battery can be damaged\n"); break; case MSG_ID_SYS_BATTERY_STAT: // if(msg.Param0 == BAT_CHARGE_COMPLETE) // tty_output("SYS: battery charge complete.\n"); // if(msg.Param0 == BAT_CHARGING) // tty_output("SYS: charging...\n"); // if(msg.Param0 == BAT_SHUTDOWN) // tty_output("SYS: charger shtdn.\n"); // break; break; case MSG_ID_USB_STATE_CHANGED: handle_usb_change(msg.Param0); break; case MSG_ID_SENSOR_UPDATE: c = (sensor_data_t*) msg.Param0; filter(&dashboardData.pressure, c->compensated.hp_pressure); filter(&dashboardData.humidity, c->compensated.sht_humidity); filter(&dashboardData.temperature, c->compensated.sht_temperature); update_min_max(&dashboardData.pressure); update_min_max(&dashboardData.humidity); update_min_max(&dashboardData.temperature); check_alarms(); // update waveforms wfrm_put_sample(&wfrmPressure, dashboardData.pressure.val); wfrm_put_sample(&wfrmHumidity, dashboardData.humidity.val); wfrm_put_sample(&wfrmTemperature, dashboardData.temperature.val); // Write to file write_samples_to_file(c, (rtc_time_t*) msg.Param1); gui_invalidate(&dashb); gui_invalidate(&lineplot); break; case MSG_ID_MEDIA_DETECTED: //tty_output("SDCARD: inserted."); //if(msg.Param0) tty_output(" Card is write protected!"); //tty_output("\n"); sd_register(); f_close(&samplesFile); // Mount filesystem f_mount(0, &filesystem); // Try open file; sampleFileIsOpen = try_open_file(); // Change statusbar toolbar_set_status(&statusbar, STATUS_SDCARD_PRESENT); break; case MSG_ID_MEDIA_DISAPPEARED: //tty_output("SDCARD: removed\n"); // Dismount file system f_mount(0, NULL); // Change statusbar toolbar_clear_status(&statusbar, STATUS_SDCARD_PRESENT); break; case MSG_ID_WDG_PRESSED: handle_button_press_event(msg.Param0); break; case MSG_ID_WDG_DELAYED_OP: handle_delayed_operation_event(msg.Param0); break; case MSG_ID_WDG_CHECKED: handle_button_checked_event(msg.Param0); break; case MSG_ID_WDG_INVALIDATE: // GUI needs to be redrawn gui_draw(); break; case MSG_ID_LPM_REQUEST: enter_sleep_mode(); break; case MSG_ID_TOUCH_EVENT: // // Draw cursor // if(msg.Param0 == TOUCH_EVENT_PANEL_PRESSED) // { // uint16_t i, j; // i = msg.Param1; // j = msg.Param2; // // if(i < 12) i = 12; // else if(i > 467) i = 467; // if(j < 12) j = 12; // else if(j > 260) j = 260; // // gfx_set_color(COLOR_WHITE); // gfx_draw_circle(i, j , 10); // } if(!darkenScreen) { set_brightness(lightenBrightness); } darkenScreen = bTrue; // no break, gui must get this msg too default: gui_msg(&msg); break; } } // COMMAND PARSER if(usb_device_state == CONFIGURED_STATE) if (poll_getc_cdc(&comRecvByte)) { putc_cdc(comRecvByte); // echo CDC_Flush_In_Now(); cmd_parse_char(comRecvByte); } }