📄 vxworksnormal.c
字号:
STATUS myIntInitial(void)
{
(void) intConnect ((VOIDFUNCPTR *)INUM_TO_IVEC (INT_NUM_IRQ0+MYINTNUM),
(VOIDFUNCPTR)myIntHandle, 0) ;
sysIntEnablePIC (MYINTNUM);
/* create interrupt task */
if( myIntId == 0 ) {
myIntId = taskSpawn("MyTask",90,0,10000,(FUNCPTR)myIntTask,
0,0,0,0,0,0,0,0,0,0) ;
}
sysOutByte(0x21, 0) ;
sysOutByte(0xa1, 0) ;
return (OK);
}
/***************************************************************************
*
* ghbRun - an example test run
*
* This routine spawns two tasks.
*
* RETURNS: N/A
*
* ERRNO:
* NONE
*/
void ghbRun(void)
{
if (!myTaskId0) {
/* create user task */
myTaskId0 = taskSpawn("MyTask0",100,0,10000,(FUNCPTR)myPerform0,
0,0,0,0,0,0,0,0,0,0) ;
}
if (!myTaskId1) {
/* create user task */
myTaskId1 = taskSpawn("MyTask1",101,0,10000,(FUNCPTR)myPerform1,
0,0,0,0,0,0,0,0,0,0) ;
}
}
/***************************************************************************
*
* myPerform0 - the first task
*
* This routine tests send and receive message for the message queue.
*
* RETURNS: N/A
*
* ERRNO:
* NONE
*/
void myPerform0(void)
{
int len,i;
char sendbuf[10],recvbuf[10];
for (i=0;i<10;i++) sendbuf[i]=0x41+i;
i=0;
FOREVER {
i++;
if (!(i%5)) {
i=0;
msgQSend(myMsgQId,sendbuf,10,WAIT_FOREVER,MSG_PRI_NORMAL);
}
if ((len=msgQReceive(myMsgQIntId,recvbuf,10,NO_WAIT)) > 0) {
for (i=0;i<len;i++) printf("%c",recvbuf[i]);
}
printf("1");
taskDelay(20);
}
}
/***************************************************************************
*
* myPerform1 - the second task
*
* This routine tests send and receive message for the message queue.
*
* RETURNS: N/A
*
* ERRNO:
* NONE
*/
void myPerform1(void)
{
char recvbuf[10],sendbuf[10];
int len,i;
for (i=0;i<10;i++) sendbuf[i]=0x61+i;
i=0;
FOREVER {
i++;
if (!(i%5)) {
i=0;
msgQSend(myMsgQIntId,sendbuf,10,WAIT_FOREVER,MSG_PRI_URGENT);
}
if ((len=msgQReceive(myMsgQId,recvbuf,20,NO_WAIT)) > 0) {
for (i=0;i<len;i++) printf("%c",recvbuf[i]);
}
printf("2");
taskDelay(20);
}
}
/***************************************************************************
*
* myFunc - my routine
*
* This routine is called by myWDTask().
*
* RETURNS: N/A
*
* ERRNO:
* NONE
*/
void myFunc(int i)
{
if (i == 1)
printf("\nHello\n");
else printf("\nWAHAHA\n");
}
/***************************************************************************
*
* myWDTask - Watch Dog Task
*
* This routine tests send and receive message for the message queue.
*
* RETURNS: OK or ERROR if starting a Watch Dog failed.
*
* ERRNO:
* ERROR
*/
STATUS myWDTask(int myFuncParameter)
{
#ifdef MY_DEBUG_MSG
/* Set timer to go off in SECONDS - printing a message to stdout */
if (wdStart(myWatchDogId, sysClkRateGet() * SECONDS, logMsg,
(int)("Watchdog timer just expired\n")) == ERROR)
return (ERROR);
#endif /* MY_DEBUG_MSG */
/* Start a WatchDog Timer.
The 'myFuncParameter' is the parameter of Function myFunc() */
if (wdStart(myWatchDogId, sysClkRateGet() * SECONDS, (FUNCPTR)myFunc, myFuncParameter) == ERROR)
return (ERROR);
/* wdCancel(myWatchDogId);*/ /* Cancel the WatchDog Timer */
return (OK);
}
#ifdef NO_INCLUDE_TIME
struct timespec
{
/* interval = tv_sec*10**9 + tv_nsec */
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds (0 - 1,000,000,000) */
};
#endif /* NO_INCLUDE_TIME */
/***************************************************************************
*
* myDelay - the other Delay
*
* The Delay time of this routine is nano level( 10 exp (-9) ).
*
* RETURNS: N/A
*
* ERRNO:
* NONE
*/
void myDelay(void)
{
static struct timespec ts = {0, 1000};
printf("\nWaiting...");
nanosleep(&ts, 0);
printf("End.\n");
}
/***************************************************************************
*
* mydemo - one demo
*
* This routine display some debugging information.
*
* RETURNS: N/A
*
* ERRNO:
* NONE
*/
void mydemo(void)
{
char *name; /* for display information */
int num;
name = "GRONK";
num = 123;
logMsg("ERROR - name = %s, num = %d.\n", (int)name, num, 0, 0, 0, 0);
}
/************************************************************************
*
* pipeInitial - initialize two pipes
*
* RETURNS: OK or
ERROR if create or open the pipes failed.
*
* ERRNO:
* ERROR
*/
STATUS pipeInitial(void)
{
if (pipeDevCreate(PIPEHI, 5, 1024) == ERROR)
return (ERROR);
if (pipeDevCreate(PIPENORM, 5, 1024) == ERROR)
return (ERROR);
/* open file descriptors */
if ((fds[0] = open (PIPEHI, O_RDONLY, 0)) == ERROR)
return (ERROR);
if ((fds[1] = open (PIPENORM, O_RDONLY, 0)) == ERROR)
return (ERROR);
}
/************************************************************************
*
* selServer - reads data as it becomes available from two different pipes
*
* Opens two pipe fds, reading from whichever becomes available. The
* server code assumes the pipes have been created from either another
* task or the shell. To test this code from the shell do the following:
* -> ld < selServer.o
* -> pipeDevCreate ("/pipe/highPriority", 5, 1024)
* -> pipeDevCreate ("/pipe/normalPriority", 5, 1024)
* -> fdHi = open ("/pipe/highPriority", 1, 0)
* -> fdNorm = open ("/pipe/normalPriority", 1, 0)
* -> iosFdShow
* -> sp selServer
* -> i
* At this point you should see selServer's state as pended. You can now
* write to either pipe to make the selServer display your message.
* -> write fdNorm, "Howdy", 6
* -> write fdHi, "Urgent", 7
*
* RETURNS: N/A
*/
selServer (void)
{
int width; /* number of fds on which to pend */
int i; /* index for fd array */
char buffer[MAX_DATA]; /* buffer for data that is read */
/* loop forever reading data and servicing clients */
FOREVER
{
/* clear bits in read bit mask */
FD_ZERO (&readFds);
/* initialize bit mask */
FD_SET (fds[0], &readFds);
FD_SET (fds[1], &readFds);
width = (fds[0] > fds[1]) ? fds[0] : fds[1];
width++;
/* pend, waiting for one or more fds to become ready */
if (select (width, &readFds, NULL, NULL, NULL) == ERROR)
return (ERROR);
/* step through array and read from fds that are ready */
for (i=0; i< MAX_FDS; i++)
{
/* check if this fd has data to read */
if (FD_ISSET (fds[i], &readFds))
{
/* typically read from fd now that it is ready */
read (fds[i], buffer, MAX_DATA);
/* normally service request, for this example print it */
printf ("SELSERVER Reading from %s: %s\n",
(i == 0) ? PIPEHI : PIPENORM, buffer);
}
}
}
}
void demo0(void)
{
pipeInitial();
taskSpawn("SelTask",90,0,10000,(FUNCPTR)selServer,0,0,0,0,0,0,0,0,0,0);
}
void demo1(void)
{
write(fds[0], "abcde", 6);
}
void demo2(void)
{
write(fds[1], "123456", 7);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -