/* * Fetch data from a mbox.Wait for at most timeout millisecs * Return -1 if timed out otherwise time spent waiting. */ u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **data, u32_t timeout) { long addr=0L; int end_time = 0, start_time = 0; if (timeout) { start_time = OS_GetTime(); if(OS_GetMailTimed (mbox, &addr,timeout)) { *data = NULL; return SYS_ARCH_TIMEOUT; } end_time = OS_GetTime(); } else { OS_GetMail(mbox,&addr); } if(data) { if (addr == (long)&dummy_msg) *data = NULL; else *data=(void*)addr; //printf("fetch mbox:0x%x = 0x%x\r\n",mbox,*data); }else{ //printf("fetch mbox:0x%x\r\n",mbox); } return (end_time - start_time); }
static void OnServerAck(PACKET* pAck) { for (;;) { PACKET* p = Dequeue(QT_Ack); if (p == NULL) { break; } if (p->Header.Id != pAck->Ack.PacketId) { DEBUG_PRINT("Mismatched packet ID, expecting %d, actual %d\n", p->Header.Id, pAck->Ack.PacketId); PACKET_FREE(p); continue; } else { DEBUG_PRINT("Packet %d acknowledged\n", p->Header.Id); PACKET_FREE(p); break; } } uint_t timediff = abs((int64_t)OS_GetTime() - pAck->Header.Timestamp); if (timediff > 10) { DEBUG_PRINT("System time incorrect, %08X, %08X, adjusting system time\n", OS_GetTime(), pAck->Header.Timestamp); OS_SetTime(pAck->Header.Timestamp); DEBUG_PRINT("System time after adjustment:%08X\n", OS_GetTime()); } PACKET_FREE(pAck); }
/********************************************************************* * * _FSTask */ static void _FSTask(void) { FS_FILE * pFile; if (FS_IsLLFormatted("") == 0) { printf("Low level formatting"); FS_FormatLow(""); /* Erase & Low-level format the flash */ } if (FS_IsHLFormatted("") == 0) { printf("High level formatting\n"); FS_Format("", NULL); /* High-level format the flash */ } FS_SetAutoMount("", 0); FS_Mount(""); while (1) { while (1) { char ac[30]; if (FS_IsVolumeMounted("")) { pFile = FS_FOpen("Log.txt", "a+"); sprintf(ac, "OS_Time = %.8d\r\n", OS_GetTime()); FS_Write(pFile, ac, 20); FS_FClose(pFile); } OS_Delay(1000); } } }
/********************************************************************* * * HPTask */ static void HPTask(void) { int Cnt; int TestTime; while(1) { Cnt = 0; OS_Delay(1); // Sync to tick TestTime = OS_GetTime32() + 1000; while ((TestTime - OS_GetTime()) >= 0) { _CalcPrimes(sizeof(aIsPrime)); Cnt++; } _PrintResult(Cnt); } }
extern "C" void RunKeyboardTask(void) { int task_timer; U16 temp, temp1; int right_arrow_key_counter = 0; bool right_arrow_key = false; bool right_arrow_key_rep = false; int question_key_counter = 0; bool question_key = false; bool question_key_rep = false; int contrast_key_counter = 0; bool contrast_key = false; bool contrast_key_rep = false; int plus_key_counter = 0; bool plus_key = false; bool plus_key_rep = false; int minus_key_counter = 0; bool minus_key = false; bool minus_key_rep = false; int home_key_counter = 0; bool home_key = false; bool home_key_rep = false; int up_key_counter = 0; bool up_key = false; bool up_key_rep = false; int down_key_counter = 0; bool down_key = false; bool down_key_rep = false; int ok_key_counter = 0; bool ok_key = false; bool ok_key_rep = false; int esc_key_counter = 0; bool esc_key = false; bool esc_key_rep = false; int plus_key_rep_number = 0; int minus_key_rep_number = 0; U16 temp_keys = 0; int number_of_keys; int plus_key_repeated = 0; int minus_key_repeated = 0; InitKeyboardHw(); while (1) { task_timer = OS_GetTime(); temp = REGISTER16(KIUDAT0_MPC); temp1 = REGISTER16(KIUDAT1_MPC); temp_keys = 0; number_of_keys = 0; if (!(temp & 0x0001)) // > { temp_keys |= 0x0001; HandleKey(right_arrow_key,right_arrow_key_counter,right_arrow_key_rep,true); number_of_keys++; } else { HandleKey(right_arrow_key,right_arrow_key_counter,right_arrow_key_rep,false); } if (!(temp & 0x0100)) // ? { temp_keys |= 0x0002; HandleKey(question_key,question_key_counter,question_key_rep,true); number_of_keys++; } else { HandleKey(question_key,question_key_counter,question_key_rep,false); } if (!(temp & 0x0002)) // + { temp_keys |= 0x0010; HandleKey(plus_key,plus_key_counter,plus_key_rep,true); number_of_keys++; plus_key_repeated = 0; } else if (!plus_key_rep || ++plus_key_repeated > KEY_REP_IDLE_IN_COUNTS) { HandleKey(plus_key,plus_key_counter,plus_key_rep,false); plus_key_rep_number = 0; plus_key_repeated = 0; } if (!(temp & 0x0200)) // - { temp_keys |= 0x0020; HandleKey(minus_key,minus_key_counter,minus_key_rep,true); number_of_keys++; minus_key_repeated = 0; } else if (!minus_key_rep || ++minus_key_repeated > KEY_REP_IDLE_IN_COUNTS) { HandleKey(minus_key,minus_key_counter,minus_key_rep,false); minus_key_rep_number = 0; minus_key_repeated = 0; } if (!(temp & 0x0004)) // home { temp_keys |= 0x0100; HandleKey(home_key,home_key_counter,home_key_rep,true); number_of_keys++; } else { HandleKey(home_key,home_key_counter,home_key_rep,false); } if (!(temp & 0x0400)) // contrast { temp_keys |= 0x0200; HandleKey(contrast_key,contrast_key_counter,contrast_key_rep,true); number_of_keys++; } else { HandleKey(contrast_key,contrast_key_counter,contrast_key_rep,false); } if (!(temp1 & 0x0001)) // up { temp_keys |= 0x0004; HandleKey(up_key,up_key_counter,up_key_rep,true); number_of_keys++; } else { HandleKey(up_key,up_key_counter,up_key_rep,false); } if (!(temp1 & 0x0100)) // down { temp_keys |= 0x0008; HandleKey(down_key,down_key_counter,down_key_rep,true); number_of_keys++; } else { HandleKey(down_key,down_key_counter,down_key_rep,false); } if (!(temp1 & 0x0002)) // esc { temp_keys |= 0x0040; HandleKey(esc_key,esc_key_counter,esc_key_rep,true); number_of_keys++; } else { HandleKey(esc_key,esc_key_counter,esc_key_rep,false); } if (!(temp1 & 0x0200)) // ok { temp_keys |= 0x0080; HandleKey(ok_key,ok_key_counter,ok_key_rep,true); number_of_keys++; } else { HandleKey(ok_key,ok_key_counter,ok_key_rep,false); } keys = temp_keys; if ( number_of_keys == 1 ) { if (contrast_key) { GUI_StoreKey('c'); contrast_key = false; } if (ok_key) { GUI_StoreKey(GUI_KEY_ENTER); ok_key = false; } if (esc_key) { GUI_StoreKey(GUI_KEY_ESCAPE); esc_key = false; } if (home_key) { GUI_StoreKey(GUI_KEY_HOME); home_key = false; } if (right_arrow_key) { GUI_StoreKey(GUI_KEY_RIGHT); right_arrow_key = false; } if (question_key) { GUI_StoreKey('?'); question_key = false; } if (up_key) { GUI_StoreKey(GUI_KEY_UP); up_key = false; } if (down_key) { GUI_StoreKey(GUI_KEY_DOWN); down_key = false; } if (plus_key) { if ( plus_key_rep ) { if (++plus_key_rep_number > KEY_REP_NUMBER_IN_COUNTS) { GUI_StoreKey('*'); plus_key_rep_number = KEY_REP_NUMBER_IN_COUNTS; } else { GUI_StoreKey('+'); } } else { GUI_StoreKey('+'); } plus_key = false; } if (minus_key) { if ( minus_key_rep ) { if (++minus_key_rep_number > KEY_REP_NUMBER_IN_COUNTS) { GUI_StoreKey('/'); minus_key_rep_number = KEY_REP_NUMBER_IN_COUNTS; } else { GUI_StoreKey('-'); } } else { GUI_StoreKey('-'); } minus_key = false; } } if (contrast_key) { contrast_key_down = true; } else { contrast_key_down = false; } REGISTER16(KIUSCANREP_MPC) = 0x8036; // new scan start OS_DelayUntil (task_timer + KEYBORAD_SAMPLE_TIME); } }
int GUI_X_GetTime(void) { return OS_GetTime(); }
extern "C" void DisplayMainTask(void) { int start_task_time, end_task_time, task_time_diff; #ifndef __PC__ int i; for (i = 4*INITIAL_BACKLIGHT; i > 0; i -= 4) { SetDutyCycleHW_1(i); GUI_Delay(1); } #endif #ifdef __PC__ // Kill the rest of the system running on PC HWND main_wnd_handle = PcDevToolService::GetInstance()->GetControllerWindow(); if(main_wnd_handle) { ShowWindow(main_wnd_handle, SW_SHOWNORMAL); } #endif // __PC__ while (display_running) { start_task_time = OS_GetTime(); mpc::display::DisplayController::GetInstance()->Run(); GUI_Delay(5); #ifdef __PC__ if( HasOSMessage() ) { OS_EnterRegion(); OS_IncDI(); OSMessage* msg; // Get message from queue without removing it. msg = PeekOSMessage(); switch(msg->message) { case 0: break; case OSMSG_LOAD_DISPLAY: msg->rc = PcDevToolService::GetInstance()->LoadDisplay((const char*)(msg->data)); break; case OSMSG_LOAD_DISPLAY_ID: msg->rc = PcDevToolService::GetInstance()->LoadDisplay(*(int*)(msg->data)); break; case OSMSG_SET_LANGUAGE: Languages::GetInstance()->SetLanguage(*((LANGUAGE_TYPE*)msg->data)); msg->rc = 0; break; case OSMSG_GET_LANGUAGE: msg->rc = Languages::GetInstance()->GetLanguage(); break; case OSMSG_DUMP_SCREEN: mpc::display::DisplayDumper::GetInstance()->DumpScreen(false); msg->rc = 0; break; case OSMSG_DUMP_SCREENS: mpc::display::DisplayDumper::GetInstance()->DumpScreens(true, false); msg->rc = 0; break; case OSMSG_SET_SUBJECT_VALUE: msg->rc = PcDevToolService::GetInstance()->SetSubjectValue( ((SubjectValueParameters*)msg->data) ); break; case OSMSG_GET_SUBJECT_VALUE_AS_FLOAT: msg->rc = PcDevToolService::GetInstance()->GetSubjectValue( ((SubjectValueParameters*)msg->data) ); break; case OSMSG_SET_SUBJECT_QUALITY: msg->rc = PcDevToolService::GetInstance()->SetSubjectQuality( ((QualityParameters*)msg->data) ); break; case OSMSG_SET_DI_VALUE: msg->rc = PcSimulatorService::GetInstance()->SetDiValue( ((DiParameters*)msg->data) ); break; case OSMSG_SET_AI_VALUE_PERCENT: msg->rc = PcSimulatorService::GetInstance()->SetAiValueInPercent( ((AiParameters*)msg->data) ); break; case OSMSG_SET_AI_VALUE_INTERNAL: msg->rc = PcSimulatorService::GetInstance()->SetAiValueInInternalUnit( ((AiParameters*)msg->data) ); break; case OSMSG_SELECT_LISTVIEW_ITEM_BY_INDEX: msg->rc = PcDevToolService::GetInstance()->SelectListViewItem(*(int*)(msg->data)); break; case OSMSG_KEY_PRESS: GUI_StoreKey(*(int*)(msg->data)); msg->rc = 0; break; case OSMSG_SET_ERROR_PRESENT: msg->rc = PcSimulatorService::GetInstance()->SimulateAlarm( ((AlarmParameters*)msg->data) ); break; case OSMSG_EXPORT_STRING_LENGTHS: mpc::display::StringWidthCalculator::GetInstance()->ExportStringWidths((const char*)(msg->data)); msg->rc = 0; break; case OSMSG_EXPORT_STRING_LENGTHS_ADV: mpc::display::StringWidthCalculator::GetInstance()->ExportStringWidthsAdv(((mpc::display::StringWidthParameters*)(msg->data))); msg->rc = 0; break; case OSMSG_SET_IO111_VALUES: msg->rc = PcSimulatorService::GetInstance()->SetIO111Values( ((Io111Parameters*)msg->data) ); break; default: msg->rc = -1; break; } // Remove message from queue DisposeOSMessage(); OS_DecRI(); OS_LeaveRegion(); OS_Delay(1); } #endif //__PC__ // calculate time to wait end_task_time = OS_GetTime(); task_time_diff = end_task_time - start_task_time; if( task_time_diff <= 1 ) OS_WaitSingleEventTimed( POWER_DOWN_EVENT, DISPLAY_SAMPLE_TIME ); // We will skip ... else if ( task_time_diff > (DISPLAY_SAMPLE_TIME-1) ) OS_WaitSingleEventTimed( POWER_DOWN_EVENT, 1 ); // Run again, now else OS_WaitSingleEventTimed( POWER_DOWN_EVENT, DISPLAY_SAMPLE_TIME - task_time_diff ); } #ifndef __PC__ LCDPowerDown(); // TODO: Check the for-loops !! It takes a lot of time #endif SignalEventToPowerDown(DISPLAY_POWERED_DOWN_EVENT); #ifndef __PC__ while (1) // We will die anyway { GUI_Delay(1000); } #endif }