⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pc.c

📁 此源码为UCOS在WIN32环境下的移植版本
💻 C
📖 第 1 页 / 共 2 页
字号:
    lock = FALSE;}/*   *********************************************************************************************************   *                                              CLEAR SCREEN   *   * Description : This function clears the PC's screen by directly accessing video RAM instead of using   *               the BIOS.  It assumed that the video adapter is VGA compatible.  Video RAM starts at   *               absolute address 0x000B8000.  Each character on the screen is composed of two bytes:   *               the ASCII character to appear on the screen followed by a video attribute.  An attribute   *               of 0x07 displays the character in WHITE with a black background.   *   * Arguments   : color   specifies the foreground/background color combination to use   *                       (see PC.H for available choices)   *   * Returns     : None   ********************************************************************************************************* */void PC_DispClrScr(INT8U color){#ifdef DEBUG_PC    printf("PC_DispClrScr\n");    return;#endif    if (PC_CHECK_RECURSIVE_CALLS && lock)			// Check and avoid recursive calls    {   perror("Recursive call in PC_DispClrScr");        exit(-1);    } else if (lock)    {	return;    } else    {   lock = TRUE;    }    printf("\033[2J");						// Clear screen and move cursor to 1,1    setColor(color);						// Set foreground/background color    lock = FALSE;}/*   *********************************************************************************************************   * 	Helper functions for time measurement   **********************************************************************************************************/#define NTIMERS 16static INT64U PC_ElapsedOverhead=0;static INT64U PC_startTime[NTIMERS], PC_stopTime[NTIMERS], PC_frequency=0;//Read the x86 CPU time stamp counterINT64U readPentiumTimeStampCounter(void){   unsigned int hi, lo;    asm("rdtsc; movl %%edx,%0; movl %%eax,%1" 	//read and copy	 	: "=r" (hi), "=r" (lo) 		//output 		: 				//input 		: "%edx", "%eax");		//registers destroyed (globbered)    return (((INT64U) hi)<<32) | ((INT64U) lo);}//Read the x86 CPU time stamp frequency (aka: time stamp counter counts per second)INT64U countsPerSecond(void){  INT64U start = readPentiumTimeStampCounter();#ifdef __WIN32__   Sleep(1000);#else   sleep(1);#endif   return readPentiumTimeStampCounter() - start;}/*   *********************************************************************************************************   *                                       ELAPSED TIME INITIALIZATION   *   * Description : This function initialize the elapsed time module by determining how long the START and   *               STOP functions take to execute.  In other words, this function calibrates this module   *               to account for the processing time of the START and STOP functions.   *               Needs to be called only once before any of the timers is started with PC_ElapsedStart().   *   * Arguments   : None.   *   * Returns     : None.   ********************************************************************************************************* */void PC_ElapsedInit(void){   static BOOLEAN initDone=FALSE;    int i;        if (initDone)    	return;    printf("INFO: Please wait - timer calibration may take up to 4 secs\n");    for (i=0; i < 4; i++)    {    PC_frequency += countsPerSecond();    }    PC_frequency = PC_frequency >> 2;        PC_ElapsedOverhead = 0;					// Measure the overhead of PC_ElapsedStart    PC_ElapsedStart(0);						// ... and PC_ElapsedStop    PC_ElapsedOverhead = (INT16U) PC_ElapsedStop(0);    initDone=TRUE;}/*   *********************************************************************************************************   *                            START A TIMER FOR EXECUTION TIME MEASUREMENT   *   * Description : Trigger the timer to be used to measure the time between events.   *               Timer will be running when the function returns.   *		   Time measurement needs to be initalized before by calling PC_ElapsedInit, only   *               needed once for all timers together.   *   * Arguments   : n=0...NTIMERS-1 number of timer   *   * Returns     : None.   ********************************************************************************************************* */void PC_ElapsedStart(INT8U n){   if (n >= NTIMERS)        return;     PC_startTime[n]=readPentiumTimeStampCounter();		// Read the counter and store it}/*   *********************************************************************************************************   *                             STOP A TIMER FOR EXECUTION TIMER MEASUREMENT   *   * Description : This function stops the the timer for execution time measurement and computes the   *               time in microseconds since the timer was started with PC_ElapsedStart.   *   * Arguments   : n=0...NTIMERS-1 number of timer.   *   * Returns     : The number of micro-seconds since the timer was last started.   *   * Notes       : - The returned time accounts for the processing time of the START and STOP functions.   *   ********************************************************************************************************* */INT32U PC_ElapsedStop(INT8U n){    INT64U PC_diffTime;    FP64 PC_diffTime_usec;    if (n >= NTIMERS)        return 0;    PC_stopTime[n]=readPentiumTimeStampCounter();		// Read the counter and store it     PC_diffTime = PC_stopTime[n] - PC_startTime[n]; 		//Compute the difference and								// ... convert it into microseconds																    PC_diffTime_usec = PC_diffTime;    PC_diffTime_usec = PC_diffTime * 1000000.0 / PC_frequency - PC_ElapsedOverhead;    //  printf("val=%8u   %f   %u\n", (INT32U)PC_diffTime, PC_diffTime_usec, PC_frequency);    return (INT32U) PC_diffTime_usec;}/*   *********************************************************************************************************   *                                       GET THE CURRENT DATE AND TIME   *   * Description: This function obtains the current date and time from the PC.   *   * Arguments  : s     is a pointer to where the ASCII string of the current date and time will be stored.   *                    You must allocate at least 21 bytes (includes the NUL) of storage in the return   *                    string.  The date and time will be formatted as follows:   *   *                        "YYYY-MM-DD  HH:MM:SS"   *   * Returns    : none   ********************************************************************************************************* */void PC_GetDateTime(char *s){   struct tm *now;    time_t nowT;    char *pS;        nowT= time(NULL);    now = (struct tm*) localtime(&nowT);			// Get the local time    sprintf(s, "%04d-%02d-%02d  %02d:%02d:%02d",		// Convert into a string            now->tm_year + 1900,            now->tm_mon + 1,            now->tm_mday,            now->tm_hour,            now->tm_min,            now->tm_sec);}/***********************************************************************************************************                                        INSTALL INTERRUPT VECTOR** Description: This function sets an interrupt vector in the "simulated" interrupt vector table.** Arguments  : vect  is the desired interrupt vector number, a number between 1 and 7.*              isr   is a pointer to a function to execute when the interrupt or exception occurs.**              Interrupt 0 cannot be set, because it is reserved for the timer interrupt.** Returns    : none**********************************************************************************************************/void  PC_IntVectSet(INT8U irq, void (*isr)(void)){   if ((irq >0) && (irq < 8))       interruptTable[irq]=isr;}/***********************************************************************************************************                                        OBTAIN INTERRUPT VECTOR** Description: This function reads the pointer stored at the specified vector.** Arguments  : vect  is the desired interrupt vector number, a number between 0 and 7.** Returns    : The address of the Interrupt handler stored at the desired vector location.**********************************************************************************************************/void *PC_IntVectGet(INT8U irq){   if (irq < 8)       return interruptTable[irq];    else       return NULL;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -