static void prvSchedulingTask( void *pvParameters ) { configASSERT( ( ( unsigned long ) pvParameters ) == SCHEDULING_PARAMETER ); TickType_t xLastWakeTime; const TickType_t xTimeToWait = 10; // Number entered here corresponds to the number of ticks we should wait. x = -1; spimem_read_sch(SCHEDULE_BASE, temp_arr, 4); // FDIR implemented for spimem_read num_commands = ((uint32_t)temp_arr[3]) << 24; num_commands = ((uint32_t)temp_arr[2]) << 16; num_commands = ((uint32_t)temp_arr[1]) << 8; num_commands = (uint32_t)temp_arr[0]; spimem_read_sch(SCHEDULE_BASE+4, temp_arr, 4); next_command_time = ((uint32_t)temp_arr[3]) << 24; next_command_time = ((uint32_t)temp_arr[2]) << 16; next_command_time = ((uint32_t)temp_arr[1]) << 8; next_command_time = (uint32_t)temp_arr[0]; spimem_read_sch(SCHEDULE_BASE + 4 + ((num_commands - 1) * 16), temp_arr, 4); furthest_command_time = ((uint32_t)temp_arr[3]) << 24; furthest_command_time = ((uint32_t)temp_arr[2]) << 16; furthest_command_time = ((uint32_t)temp_arr[1]) << 8; furthest_command_time = (uint32_t)temp_arr[0]; scheduling_on = 1; clear_schedule_buffers(); clear_temp_array(); clear_current_command(); /* @non-terminating@ */ for( ;; ) { exec_pus_commands(); check_schedule(); } }
static int lchannel(lua_State *L) { check_schedule(L); channelid id = schedule_newchannel(S); lua_pushinteger(L, id); return 1; }
static int ltask(lua_State *L) { lua_State *task = luaL_newstate(); if (task == NULL) return luaL_error(L, "luaL_newstate failed"); const char * filename = luaL_checkstring(L, 1); lua_pushcfunction(task, inittask); lua_pushlightuserdata(task, (void *)filename); int err = lua_pcall(task, 1, 1, 0); if (err != LUA_OK) { size_t sz; const char * msg = lua_tolstring(task, -1, &sz); if (msg) { lua_pushlstring(L, msg, sz); lua_close(task); lua_error(L); } else { lua_close(task); return luaL_error(L, "fail to new task %s", filename); } } lua_pushcfunction(L, seri_pack); lua_insert(L, 2); int top = lua_gettop(L); lua_call(L, top-2, 1); void * args = lua_touserdata(L, 2); lua_pushcfunction(task, seri_unpack); lua_pushlightuserdata(task, args); err = lua_pcall(task, 1, LUA_MULTRET, 0); if (err != LUA_OK) { lua_close(task); return luaL_error(L, "pass argments to new task %s", filename); } check_schedule(L); struct ltask *t = malloc(sizeof(*t)); t->L = task; t->id = 0; taskid id = schedule_opentask(S, t); t->id = id; lua_pushinteger(task, id); lua_rawsetp(task, LUA_REGISTRYINDEX, S); lua_pushinteger(L, id); return 1; }
static void exec_pus_commands(void) { uint16_t packet_id, psc; uint8_t status, kicked_count; if(xQueueReceive(obc_to_sched_fifo, current_command, (TickType_t)1000) == pdTRUE) // Only block for a single second. { packet_id = ((uint16_t)current_command[140]) << 8; packet_id += (uint16_t)current_command[139]; psc = ((uint16_t)current_command[138]) << 8; psc += (uint16_t)current_command[137]; switch(current_command[146]) { case ADD_SCHEDULE: x = modify_schedule(&status, &kicked_count); if(status == -1) send_tc_execution_verify(0xFF, packet_id, psc); // The Schedule modification failed if(status == 2) send_event_report(1, KICK_COM_FROM_SCHEDULE, kicked_count, 0); // the modification kicked out commands. if(status == 1) send_tc_execution_verify(1, packet_id, psc); // modification succeeded without a hitch check_schedule(); case CLEAR_SCHEDULE: if(clear_schedule() < 0) send_tc_execution_verify(0xFF, packet_id, psc); else send_tc_execution_verify(1, packet_id, psc); case SCHED_REPORT_REQUEST: if(report_schedule() < 0) send_tc_execution_verify(0xFF, packet_id, psc); else send_tc_execution_verify(1, packet_id, psc); case PAUSE_SCHEDULE: scheduling_on = 0; case RESUME_SCHEDULE: scheduling_on = 1; default: return; } } return; }
static int lrun(lua_State *L) { check_schedule(L); int threads = schedule_threads(S); struct worker w[threads]; struct thread t[threads]; struct workshop ws; ws.threads = threads; ws.w = w; int i; for (i=0;i<threads;i++) { w[i].id = i; w[i].suspend = 0; w[i].workshop = &ws; thread_event_create(&w[i].event); t[i].func = worker_func; t[i].ud = &w[i]; } thread_join(t,threads); for (i=0;i<threads;i++) { thread_event_release(&w[i].event); } return 0; }
int main(void) { watchdog_clear_status(); #ifdef USING_PRINTF serial_init(); #endif cli(); clear_radio_strings(); system_schedule = new_schedule(); //Be aware: order may matter, especially with si4703/5_init and nokia5110_init. (they all share a reset pin) watchdog_set(WD_INTERRUPT_AND_SYSTEM_RESET, WD_TIMEOUT_1_S); set_data_directions(); timer0_pwm_prescaler_compare_A(0, 3, true, false); timer1_pwm_prescaler_compare(0, MAX_BRIGHTNESS, 1, 1, false, false); timer2_ctc(0.001, true); nokia5110_spi_init(0x51); i2c_init(); nokia5110_power_on(); set_volume(0); ADC_init(ADC_PC3, ADC_NO_TRIGGER, ADC_REFERENCE_1V1, true, true); //ADC_TIMER0_OVERFLOW sei(); ds1307_getdate_s(&time); //If the clock isn't set, it reads all values as zero. Set a default time if (time.year == 0) { ds1307_setdate(14,10,21,12,28,30); } time_alarm_A.hour = eeprom_read_byte(&alarm_A_hours); time_alarm_A.minute = eeprom_read_byte(&alarm_A_minutes); alarm_A_is_beep = eeprom_read_byte(&alarm_A_tone_setting); if (time_alarm_A.hour >= time_limits[hours]) { time_alarm_A.hour = 0; eeprom_update_byte(&alarm_A_hours, time_alarm_A.hour); } if (time_alarm_A.minute >= time_limits[minutes]) { time_alarm_A.minute = 0; eeprom_update_byte(&alarm_A_minutes, time_alarm_A.minute); } if (alarm_A_is_beep > true) { alarm_A_is_beep = true; } time_alarm_B.hour = eeprom_read_byte(&alarm_B_hours); time_alarm_B.minute = eeprom_read_byte(&alarm_B_minutes); alarm_B_is_beep = eeprom_read_byte(&alarm_B_tone_setting); if (time_alarm_B.hour >= time_limits[hours]) { time_alarm_B.hour = 0; eeprom_update_byte(&alarm_B_hours, time_alarm_B.hour); } if (time_alarm_B.minute >= time_limits[minutes]) { time_alarm_B.minute = 0; eeprom_update_byte(&alarm_B_minutes, time_alarm_B.minute); } if (alarm_B_is_beep > true) { alarm_B_is_beep = true; } channel = eeprom_read_word(&saved_channel); if (channel < SI4705_FM_LOW || channel > SI4705_FM_HIGH) channel = 889; for (err = 0; err < NUMBER_OF_PRESETS; err++) { presets[err] = eeprom_read_word(&saved_presets[err]); if (presets[err] < SI4705_FM_LOW || presets[err] > SI4705_FM_HIGH) presets[err] = 945; } ms_clock = 0; while(true) { if (is_fresh) { is_fresh = false; check_schedule(); switch(state) { case home: home_state(); break; case menu: menu_state(); break; case set_clock: set_clock_state(); break; case set_alarm_A: case set_alarm_B: set_alarm_state(); break; case alarm_A: case alarm_B: alarm_state(); break; case radio: radio_state(); break; case preset: preset_state(); break; default: break; } init = false; state_handler(); watchdog_entertain(); } } }