?? exp2timer.c
字號:
#include "vxWorks.h"
#include "stdio.h"
#include "stdlib.h"
#include "taskLib.h"
#include "sysLib.h"
#include "tylib.h"
#define MAX_MSG_LEN (50) /* 消息隊列中消息的最大長度 */
void clk(void)
{
char key;
int cnt, tcnt;
int sysclkrate = sysClkRateGet()/20;
int task_stdin_fd, global_stdin_fd;
int consoleFd;
int stdIN, stdOUT; /* 標準輸入/輸出設備的文件描述符 */
char c; /* 字符變量 */
char aStr[MAX_MSG_LEN]; /* 字符串緩沖區(qū) */
char bStr[MAX_MSG_LEN]; /* string buffer */
/* 取標準輸入/輸出設備文件描述符 */
stdIN = ioGlobalStdGet(0);
stdOUT = ioGlobalStdGet(1);
/* 將標準輸出設備輸出模式設置為RAW */
ioctl(stdOUT, FIOSETOPTIONS, OPT_RAW); /* defined in iolib.h */
task_stdin_fd = ioTaskStdGet(0, STD_IN);
global_stdin_fd = ioGlobalStdGet(STD_IN);
consoleFd = global_stdin_fd;
ioctl (consoleFd, FIOFLUSH, 0);
tcnt = 0;
FOREVER
{
printf("timer value: %03d\r", tcnt++);
/* 清空消息接收緩沖 */
memset(aStr, 0, MAX_MSG_LEN);
sprintf(aStr, "timer value: %03d\r", tcnt);
write(stdOUT, aStr, sizeof(aStr));
taskDelay(sysclkrate);
ioctl (consoleFd, FIONREAD, (int) &cnt);
if(cnt)
{
read(stdIN,&c,1);
/* 判斷若輸入字符為"ESC鍵"則退出主循環(huán) */
if(c == '\e')
break;
else if(c == 'r')
{
tcnt=0;
}
else if (c == 'p')
{
printf("Pause .press any key to continue.....\r");
/* 清空消息接收緩沖 */
memset(bStr, 0, MAX_MSG_LEN);
sprintf(bStr, "Press any key to continue.....\n");
write(stdOUT, bStr, sizeof(bStr));
memset(bStr, 0, MAX_MSG_LEN);
sprintf(bStr, "Pause \r");
write(stdOUT, bStr, sizeof(bStr));
while(1){
ioctl (consoleFd, FIONREAD, (int) &cnt);
if(cnt)
{
break;
}
}
}
ioctl (consoleFd, FIOFLUSH, 0);
}
}
/* 輸出"end"字串 */
write(stdOUT, "\n\rend\n\r", 7);
ioctl (consoleFd, FIOFLUSH, 0);
ioctl (consoleFd, FIOSETOPTIONS, OPT_TERMINAL);
printf("\nTimer end\n");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -