📄 wdog.c
字号:
#include <vxWorks.h>
#include <taskLib.h>
#include <msgQLib.h>
#include <semLib.h>
#include <wdLib.h>
static int giTaskIdHighPri = ERROR;
static int giTaskIdLowPri = ERROR;
static MSG_Q_ID gMsgTest = NULL;
static SEM_ID gSemTest = NULL;
static WDOG_ID gDogTest = NULL;
int testInit( void );
int testDInit( void );
int taskHighPri( void );
int taskLowPri( void );
void WDOG_ISR ( void );
int testInit( void )
{
if( gMsgTest == NULL )
{
gMsgTest = msgQCreate( 100, 4, MSG_Q_FIFO );
if( gMsgTest == NULL )
{
printf(" Creat msgQ failed " );
testDInit( );
return ( 0 );
}
}
if( gSemTest == NULL )
{
gSemTest = semBCreate( SEM_Q_PRIORITY, SEM_FULL );
if( gSemTest == NULL)
{
printf(" Creat semM failed " );
testDInit( );
return ( 0 );
}
}
if( gDogTest == NULL )
{
if( ( gDogTest = wdCreate( ) ) == NULL )
{
printf( " create WDOG failed.\n ");
testDInit( );
return( 0 );
}
}
if( giTaskIdHighPri == ERROR )
{
if( ( giTaskIdHighPri = taskSpawn( "taskHighPri", 120, 0 , 0x20000 , ( FUNCPTR )taskHighPri,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) ) == ERROR )
{
printf( " Ceate task failed " );
testDInit( );
return( 0 );
}
}
if( giTaskIdLowPri == ERROR )
{
if( ( giTaskIdLowPri = taskSpawn( "taskLowPri", 121, 0 , 0x20000 , ( FUNCPTR )taskLowPri,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) ) == ERROR )
{
printf( " Ceate task failed " );
testDInit( );
return( 0 );
}
}
return( 1 );
}
int testDInit( void )
{
if( giTaskIdHighPri != ERROR )
{
if( taskDelete( giTaskIdHighPri ) == ERROR )
{
printf(" Delete task Error.\n");
}
giTaskIdHighPri = ERROR;
}
if( giTaskIdLowPri != ERROR )
{
if( taskDelete( giTaskIdLowPri ) == ERROR )
{
printf(" Delete task Error.\n");
}
giTaskIdLowPri = ERROR;
}
if( gMsgTest != NULL )
{
if( msgQDelete( gMsgTest ) == ERROR )
{
printf(" Delete gmsgQid Error.\n");
}
gMsgTest = NULL;
}
if( gSemTest != NULL )
{
if( semDelete( gSemTest ) == ERROR )
{
printf(" Delete sem Error. \n " );
}
gSemTest = NULL;
}
if( gDogTest != NULL)
{
if( wdDelete( gDogTest ) == ERROR )
{
printf( "Delete WDDOG ERROR\n" );
}
gDogTest = NULL;
}
return( 1 );
}
int taskHighPri( void )
{
int a = 100;
int b;
while( giTaskIdHighPri != ERROR )
{
if( wdStart( gDogTest,200, (FUNCPTR)WDOG_ISR, 0 ) == ERROR )
{
printf( " Start WDDOG ERROR.\n " );
return( 0 );
}
printf(" taskHighPri run 1 .\n " );
if( semTake( gSemTest,WAIT_FOREVER ) == ERROR )
{
printf( "semTake ERROR" );
return( 0 );
}
printf( " taskHighPri semTake sem\n " );
if( semTake( gSemTest,WAIT_FOREVER ) == ERROR )
{
printf( "semTake ERROR" );
return( 0 );
}
printf(" taskHighPri run 2 .\n " );
if( ( msgQSend( gMsgTest, ( char * )&a, 4, WAIT_FOREVER, MSG_PRI_NORMAL ) ) == ERROR )
{
printf( "msgQsend Error." );
}
if( ( msgQReceive( gMsgTest,( char * )&b, 4, WAIT_FOREVER ) ) == ERROR )
{
printf( "msgQRcv Error." );
}
printf( "b=%d\n",b );
if( ( msgQReceive( gMsgTest, ( char * )&b, 4, WAIT_FOREVER ) ) == ERROR )
{
printf( "msgQRcv Error." );
}
printf(" taskHighPri run 3 .\n " );
printf( "b=%d\n",b );
}
return ( 1 );
}
int taskLowPri( void )
{
int a = 200;
while( giTaskIdLowPri != ERROR )
{
printf( " taskLowPri run 1.\n ");
if( semGive( gSemTest ) == ERROR )
{
printf( " semGive ERROR " );
}
printf( " taskLowPri run 2.\n ");
if( ( msgQSend( gMsgTest, ( char * )&a, 4, WAIT_FOREVER, MSG_PRI_NORMAL ) ) == ERROR )
{
printf( "msgQsend Error." );
}
semGive( gSemTest );
}
return( 1 );
}
void WDOG_ISR ( void )
{
logMsg( " *************WDOG_ISR *************** \n " );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -