📄 sample_app.c
字号:
/***********************************************************************/
/* */
/* MODULE. : sample_app.c */
/* */
/* DATE... : 12/18/96 */
/* */
/* PURPOSE : Sample application for WRS vxWorks environment */
/* */
/***********************************************************************/
/* */
/* Include files. */
/* */
#include "vxWorks.h"
#include "msgQLib.h"
#include "stdio.h"
/* */
/* Function Prototypes */
/* */
LOCAL void ping ( void ) ;
LOCAL void pong ( void ) ;
LOCAL void pang ( void ) ;
/* */
/* Usefull defines */
/* */
#define MAX_MSGS 10
#define MAX_MSG_LEN 20
/* */
/* Global Data Used */
/* */
MSG_Q_ID queue_ping ;
MSG_Q_ID queue_pang ;
MSG_Q_ID queue_pong ;
char wake_ping[ MAX_MSG_LEN ] = "WAKEPING" ;
char wake_pang[ MAX_MSG_LEN ] = "WAKEPANG" ;
char wake_pong[ MAX_MSG_LEN ] = "WAKEPONG" ;
/***********************************************************************/
/* */
/* Function name : sample_app( void ) */
/* */
/* Description.. : Main task which creates the PING/PANG/PONG tasks & */
/* the message queues that they use to communicate and */
/* synchronize with. */
/* */
/***********************************************************************/
void sample_app(void)
{
#ifdef FLOAT_TEST
float var_1, var_2, var_3;
/* */
/* Perform some floating point work */
/* */
var_1 = 2.0000004 ;
var_2 = 4.0000008 ;
var_3 = var_2 / var_1 ;
#endif
/* */
/* Indicate we are starting */
/* */
printf( "\nHello, I'm a demo program...\n" ) ;
printf( "\nDo you Known Ping/Pong\n\n" ) ;
/* */
/* Create the message queues. */
/* */
queue_ping = msgQCreate( MAX_MSGS , MAX_MSG_LEN , MSG_Q_PRIORITY ) ;
queue_pang = msgQCreate( MAX_MSGS , MAX_MSG_LEN , MSG_Q_PRIORITY ) ;
queue_pong = msgQCreate( MAX_MSGS , MAX_MSG_LEN , MSG_Q_PRIORITY ) ;
/* */
/* Create PING/PANG/PONG. */
/* */
taskSpawn( "PING", 20, 0, 2000, (FUNCPTR) ping, 0,0,0,0,0,0,0,0,0,0 ) ;
taskSpawn( "PONG", 20, 0, 2000, (FUNCPTR) pong, 0,0,0,0,0,0,0,0,0,0 ) ;
taskSpawn( "PANG", 20, 0, 2000, (FUNCPTR) pang, 0,0,0,0,0,0,0,0,0,0 ) ;
/* */
/* We are no longer needed. Lets go to sleep. */
/* */
taskSuspend( 0 ) ;
}
/***********************************************************************/
/* */
/* Function name : ping( void ) */
/* */
/* Description.. : Sends a message to PANG. */
/* */
/***********************************************************************/
LOCAL void ping( void )
{
char msgbuf[ MAX_MSG_LEN ] ;
/* */
/* Loop forever. */
/* */
for ( ; ; )
{
/* */
/* Indicate we are running. */
/* */
printf( "Ping\n" ) ;
/* */
/* Lets wait for a reasonable time. */
/* */
taskDelay( 30 ) ; /* About 1/2 second */
/* */
/* Send a message to PONG. */
/* */
msgQSend( queue_pang ,
wake_pang ,
sizeof( wake_pang ) ,
WAIT_FOREVER ,
MSG_PRI_NORMAL ) ;
/* */
/* Wait until told to run. */
/* */
msgQReceive( queue_ping , msgbuf , MAX_MSG_LEN , WAIT_FOREVER ) ;
}
}
/***********************************************************************/
/* */
/* Function name : pang( void ) */
/* */
/* Description.. : Sends a message to PONG. */
/* */
/***********************************************************************/
LOCAL void pang( void )
{
char msgbuf[ MAX_MSG_LEN ] ;
/* */
/* Loop forever. */
/* */
for ( ; ; )
{
/* */
/* Wait until told to run. */
/* */
msgQReceive( queue_pang , msgbuf , MAX_MSG_LEN , WAIT_FOREVER ) ;
/* */
/* Indicate we are running. */
/* */
printf( " Pang\n" ) ;
/* */
/* Lets wait for a reasonable time. */
/* */
taskDelay( 30 ) ; /* About 1/2 second */
/* */
/* Send a message to PONG. */
/* */
msgQSend( queue_pong ,
wake_pong ,
sizeof( wake_pong ) ,
WAIT_FOREVER ,
MSG_PRI_NORMAL ) ;
}
}
/***********************************************************************/
/* */
/* Function name : pong( void ) */
/* */
/* Description.. : Sends a message to PING. */
/* */
/***********************************************************************/
LOCAL void pong( void )
{
char msgbuf[ MAX_MSG_LEN ] ;
/* */
/* Loop forever. */
/* */
for ( ; ; )
{
/* */
/* Wait until told to run. */
/* */
msgQReceive( queue_pong , msgbuf , MAX_MSG_LEN , WAIT_FOREVER ) ;
/* */
/* Indicate we are running. */
/* */
printf( " Pong\n" ) ;
/* */
/* Lets wait for a reasonable time. */
/* */
taskDelay( 30 ) ; /* About 1/2 second */
/* */
/* Send a message to PING. */
/* */
msgQSend( queue_ping ,
wake_ping ,
sizeof( wake_ping ) ,
WAIT_FOREVER ,
MSG_PRI_NORMAL ) ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -