?? pc.c
字號:
* screen followed by a video attribute. An attribute of 0x07 displays the character in
* WHITE with a black background.
用于顯示一個ASCII碼字符串,實際上,可以顯示由255個ASCII字符所組成的任意字符串數組,只要該數組以NULL結束即可。
*
* Arguments : x corresponds to the desired column on the screen. Valid columns numbers are from
* 0 to 79. Column 0 corresponds to the leftmost column.
* y corresponds to the desired row on the screen. Valid row numbers are from 0 to 24.
* Line 0 corresponds to the topmost row.
x和y 指定所顯示字符串中第1個字符的坐標(列和行)。行的值為0~DISP_MAX_Y-1,而列的值為0~DISP_MAX_X-1,可參看文件PC.C
* s Is the ASCII string to display. You can also specify a string containing
* characters with numeric values higher than 128. In this case, special character
* based graphics will be displayed.
指向所需要顯示字符串的指針,字符串必須以NULL結束。可顯示0x00~0xFF的任何字符
* color specifies the foreground/background color to use (see PC.H for available choices)
* and whether the characters will blink or not.
指向所顯示字符的屬性,即字符的色彩組合。可添加一個DISP_FGND_???常數和一個DISP_BGND_???常數,以得到所需要的色彩組合。
這2個常數的定義見PC.H文件。
*
* Returns : None
注意:字符串數組中的所有字符都以相同的顏色屬性顯示。
*********************************************************************************************************
*/
void PC_DispStr (INT8U x, INT8U y, INT8U *s, INT8U color)
{
INT8U far *pscr;
INT16U offset;
offset = (INT16U)y * DISP_MAX_X * 2 + (INT16U)x * 2; /* Calculate position of 1st character */
pscr = (INT8U far *)MK_FP(DISP_BASE, offset);
while (*s) {
*pscr++ = *s++; /* Put character in video RAM */
*pscr++ = color; /* Put video attribute in video RAM */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* RETURN TO DOS
*
* Description : This functions returns control back to DOS by doing a 'long jump' back to the saved
* location stored in 'PC_JumpBuf'. The saved location was established by the function
* 'PC_DOSSaveReturn()'. After execution of the long jump, execution will resume at the
* line following the 'set jump' back in 'PC_DOSSaveReturn()'. Setting the flag
該函數讓程序返回DOS。前提是已經調用過PC_DOSSaveReturn()保存重要寄存器內容以保證正常返回DOS。
* 'PC_ExitFlag' to TRUE ensures that the 'if' statement in 'PC_DOSSaveReturn()' executes.
*
* Arguments : None
*
* Returns : None
注意:用戶必須保證:在調用PC_DOSReturn()函數前,已經調用過PC_DOSSaveReturn()函數。
*********************************************************************************************************
*/
void PC_DOSReturn (void)
{
PC_ExitFlag = TRUE; /* Indicate we are returning to DOS */
longjmp(PC_JumpBuf, 1); /* Jump back to saved environment希望可以返回DOS,只需調用
PC_DOSReturn()函數即可。在這個函數中,PC_ExitFlag被設定為TRUE,并且執行了跳轉函數longjmp()。*/
}
/*$PAGE*/
/*
*********************************************************************************************************
* SAVE DOS RETURN LOCATION
函數PC_DOSSaveReturn()用于保存當前DOS環境,主程序main()通過調用該函數完成一下功能:1 設置ucos的環境軟中斷向量,以實現任務
切換。2 設置時鐘中斷服務子程序ISR的中斷向量。3 保存DOS環境設置,使得在需要終止一個基于UCOS的應用程序時,可以返回DOS。
PC_DOSSaveReturn()函數的源代碼如下
*
* Description : This function saves the location of where we are in DOS so that it can be recovered.
* This allows us to abort multitasking under uC/OS-II and return back to DOS as if we had
* never left. When this function is called by 'main()', it sets 'PC_ExitFlag' to FALSE
* so that we don't take the 'if' branch. Instead, the CPU registers are saved in the
* long jump buffer 'PC_JumpBuf' and we simply return to the caller. If a 'long jump' is
* performed using the jump buffer then, execution would resume at the 'if' statement and
* this time, if 'PC_ExitFlag' is set to TRUE then we would execute the 'if' statements and
* restore the DOS environment.
*
* Arguments : None
*
* Returns : None
*********************************************************************************************************
*/
void PC_DOSSaveReturn (void)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
PC_ExitFlag = FALSE; /* Indicate that we are not exiting yet!PC_DOSSaveReturn()從設
定PC_ExitFlag標志位FALSE開始,標志著現在不希望返回DOS。*/
OSTickDOSCtr = 1; /* Initialize the DOS tick counter函數將OSTickDOSCtr初始化為1,
這個變量將在函數OSTickISR()中遞減。當其值為0時,下次遞減將會翻轉為255.*/
PC_TickISR = PC_VectGet(VECT_TICK); /* Get MS-DOS's tick vector */
PC_VectSet(VECT_DOS_CHAIN, PC_TickISR); /* Store MS-DOS's tick to chain;PC_DOSSaveReturn()把DOS中的時
鐘處理程序保存在一個空的中斷向量入口處,這樣UCOS的時鐘處理程序就可以調用它了 成為向量的轉移。*/
setjmp(PC_JumpBuf); /* Capture where we are in DOS;PC_DOSSaveReturn()調用函數
setjmp()。這個函數將得到處理器的狀態(各個主要寄存器的內容),并把它們保存在一個結構體PC_JumpBuf中。獲取處理器的狀態后,
setjmp()將返回PC_DOSSaveReturn()函數,然后從下一條語句繼續執行。因為PC_ExitFlag被初始化為FALSE,PC_DOSSaveReturn()將
會跳過if語句,返回到主函數main()。跳轉函數longjmp()使處理器返回到函數PC_DOSSaveReturn()(調用setjmp()函數的下一條語句)*/
if (PC_ExitFlag == TRUE) { /* See if we are exiting back to DOS */
OS_ENTER_CRITICAL();
PC_SetTickRate(18); /* Restore tick rate to 18.2 Hz因為PC_ExitFlag為TRUE,將執行if
語句后的代碼。*/
OS_EXIT_CRITICAL();
PC_VectSet(VECT_TICK, PC_TickISR); /* Restore DOS's tick vector */
PC_DispClrScr(DISP_FGND_WHITE + DISP_BGND_BLACK); /* Clear the display */
exit(0); /* Return to DOS;PC_DOSSaveReturn()把時鐘節拍改回18.2hz,恢復
PC原來的時鐘中斷服務子程序并清屏,通過exit(0)函數返回DOS命令行狀態。*/
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* ELAPSED TIME INITIALIZATION
程序運行時間測量函數用于確定函數的運行時間,這是通過PC機的82C54定時器#2完成的。在實際測量時,只需把被測量的代碼放在
PC_ElapsedStart()和PC_ElapsedStop()2個函數之間即可;但在使用這2個函數之前,必須先調用初始化函數PC_ElapsedInit(),以測量上
面2個函數本身執行所需要的時間。這樣,PC_ElapsedStop()函數返回的時間就是執行測量代碼所需要的實際時間。
注意:上面3個函數都不具備可重入性,所以,必須小心:不得有果個任務同時調用這些函數。
*
* 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.
*
* Arguments : None.
*
* Returns : None.
*********************************************************************************************************
*/
void PC_ElapsedInit(void)
{
PC_ElapsedOverhead = 0;
PC_ElapsedStart();
PC_ElapsedOverhead = PC_ElapsedStop();
}
/*$PAGE*/
/*
*********************************************************************************************************
* INITIALIZE PC'S TIMER #2
*
* Description : This function initialize the PC's Timer #2 to be used to measure the time between events.
* Timer #2 will be running when the function returns.
*
* Arguments : None.
*
* Returns : None.
注意:在調用PC_ElapsedStart()或PC_ElapsedStop()之前,一定要調用PC_ElapsedInit()函數。
本函數不具備可重入性,不能在沒有適當保護機制(信號量和調度鎖定等)的情況下,由多個任務同時調用。
用戶代碼的執行時間必須短于54.93ms,以保證時間測量函數能夠正常工作。
*********************************************************************************************************
*/
void PC_ElapsedStart(void)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
INT8U data;
OS_ENTER_CRITICAL();
data = (INT8U)inp(0x61); /* Disable timer #2 */
data &= 0xFE;
outp(0x61, data);
outp(TICK_T0_8254_CWR, TICK_T0_8254_CTR2_MODE0); /* Program timer #2 for Mode 0 */
outp(TICK_T0_8254_CTR2, 0xFF);
outp(TICK_T0_8254_CTR2, 0xFF);
data |= 0x01; /* Start the timer */
outp(0x61, data);
OS_EXIT_CRITICAL();
}
/*$PAGE*/
/*
*********************************************************************************************************
* STOP THE PC'S TIMER #2 AND GET ELAPSED TIME
*
* Description : This function stops the PC's Timer #2, obtains the elapsed counts from when it was
* started and converts the elapsed counts to micro-seconds.
*
* Arguments : None.
*
* 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.
* - 54926 represents 54926S-16 or, 0.838097 which is used to convert timer counts to
* micro-seconds. The clock source for the PC's timer #2 is 1.19318 MHz (or 0.838097 uS)
*********************************************************************************************************
*/
INT16U PC_ElapsedStop(void)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
INT8U data;
INT8U low;
INT8U high;
INT16U cnts;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -