⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validate.c

📁 如何将基于vxworks的应用程序移植到LINUX操作系统。
💻 C
📖 第 1 页 / 共 5 页
字号:
        */
        msg.msg.t_cycle = test_cycle;
        msg.msg.msg_no = message_num;
            
        msg.msg.qname[3] = '1';
        printf( "Task 1 sending msg %d to %s", message_num, msg.msg.qname );
        errno = 0;
        err = msgQSend( queue1_id, msg.blk, 16, NO_WAIT, MSG_PRI_NORMAL );
        if ( err != OK )
            printf( " returned error %x\r\n", errno );
        else
            printf( "\r\n" );
            
        msg.msg.qname[3] = '2';
        printf( "Task 1 sending msg %d to %s", message_num, msg.msg.qname );
        errno = 0;
        err = msgQSend( queue2_id, msg.blk, 16, NO_WAIT, MSG_PRI_NORMAL );
        if ( err != OK )
            printf( " returned error %x\r\n", errno );
        else
            printf( "\r\n" );
            
        msg.msg.qname[3] = '3';
        printf( "Task 1 sending msg %d to %s", message_num, msg.msg.qname );
        errno = 0;
        err = msgQSend( queue3_id, msg.blk, 16, NO_WAIT, MSG_PRI_NORMAL );
        if ( err != OK )
            printf( " returned error %x\r\n", errno );
        else
            printf( "\r\n" );
    }

    puts( "\n.......... Sending a message to a message queue which" );
    puts( "           is larger than the queue's maximum message size would" );
    puts( "           either have to truncate the message or cause buffer" );
    puts( "           overflow - neither of which is desirable.  For this" );
    puts( "           reason, an attempt to do this generates an error 0x410001." );
    puts( "           This tests the overlength message detection logic." );
    errno = 0;
    err = msgQSend( queue1_id, msg_string, 80, NO_WAIT, MSG_PRI_NORMAL );
    printf( "\nmsgQSend 80-byte msg for 16-byte MSQ1 returned error %x\r\n", errno );

    puts( "\n.......... Receiving a message from a message queue which" );
    puts( "           is larger than the caller's message buffer size would" );
    puts( "           either have to truncate the message or cause buffer" );
    puts( "           overflow - neither of which is desirable.  For this" );
    puts( "           reason, an attempt to do this generates an error 0x410001." );
    puts( "           This tests the underlength buffer detection logic." );

    errno = 0;
    err = msgQReceive( queue2_id, rcvd_msg.blk, 16, NO_WAIT );
    printf( "\n16-byte msgQReceive for 128-byte MSQ2 returned error %x\r\n", errno );
    /************************************************************************
    **  Waiting Task 'Queuing Order' (FIFO vs. PRIORITY) Test
    ************************************************************************/
    puts( "\n.......... Earlier we enabled Tasks 3, 6, and 9 to consume" );
    puts( "           messages from MSQ1 in reverse-priority order." );
    puts( "           The enables were sent to lowest-priority tasks first." );
    puts( "           Since the queues awaken tasks in PRIORITY order, this" );
    puts( "           tests the task queueing order logic.\r\n" );
    puts( "           Tasks 9, 6, and 3 - in that order - should each" );
    puts( "           receive 3 messages from MSQ1" );

    puts( "\r\nTask 1 blocking while messages are consumed..." );
    puts( "Task 1 waiting to receive ALL of complt3, complt6, complt9 tokens." );
    errno = 0;
    err = semTake( complt3, WAIT_FOREVER );
    err = semTake( complt6, WAIT_FOREVER );
    err = semTake( complt9, WAIT_FOREVER );

    puts( "\n.......... Next we send a message to zero-length MSQ3 with" );
    puts( "           Task 9 waiting on MSQ3... This should succeed." );
    puts( "           This tests the zero-length queue send logic." );

    puts( "Task 1 enabling Task 9 (priority 10) to consume MSQ3 messages.");
    errno = 0;
    err = semGive( enable9 );
    if ( err != OK )
    {
        printf( "semGive of enable9 returned error %x\r\n", errno );
    }

    puts( "Task 1 blocking for handshake from Task 9..." );
    errno = 0;
    err = semTake( complt9, WAIT_FOREVER );
    taskDelay( 2 );
            
    printf( "Task 1 Sending msg %d to %s", message_num, msg.msg.qname );
    msg.msg.msg_no = message_num;
    errno = 0;
    msgQSend( queue3_id, msg.blk, 16, NO_WAIT, MSG_PRI_NORMAL );
    if ( err != OK )
        printf( " returned error %x\r\n", errno );
    else
        printf( "\r\n" );

    puts( "\r\nTask 1 blocking while message is consumed..." );
    errno = 0;
    err = semTake( complt9, WAIT_FOREVER );

    /************************************************************************
    **  Message Queue-Delete Test
    ************************************************************************/
    puts( "\n.......... Next we enable Tasks 3, 6, and 9 to wait for" );
    puts( "           a message on MSQ1.  Then we delete MSQ1." );
    puts( "           This should wake each of Tasks 3, 6, and 9," );
    puts( "           and they should each return an error 0x3d0003." );
    puts( "           This tests the queue delete logic." );

    puts( "Task 1 enabling Tasks 3, 6, and 9 to consume MSQ1 messages.");
    errno = 0;
    err = semGive( enable3 );
    if ( err != OK )
    {
        printf( "semGive of enable3 returned error %x\r\n", errno );
    }
    err = semGive( enable6 );
    if ( err != OK )
    {
        printf( "semGive of enable6 returned error %x\r\n", errno );
    }
    errno = 0;
    err = semGive( enable9 );
    if ( err != OK )
    {
        printf( "semGive of enable9 returned error %x\r\n", errno );
    }

    puts( "Task 1 blocking for handshake from Tasks 3, 6, and 9..." );
    errno = 0;
    err = semTake( complt3, WAIT_FOREVER );
    err = semTake( complt6, WAIT_FOREVER );
    err = semTake( complt9, WAIT_FOREVER );
    taskDelay( 2 );
            
    puts( "\r\nTask 1 deleting MSQ1" );
    errno = 0;
    err = msgQDelete( queue1_id );
    if ( err != OK )
        printf( "Task 1 msgQDelete on MSQ1 returned error %x\r\n", errno );
    else
        printf( "\r\n" );

    puts( "\r\nTask 1 blocking until consumer tasks acknowledge deletion..." );
    puts( "Task 1 waiting to receive ALL of complt3, complt6, complt9 tokens." );
    errno = 0;
    err = semTake( complt3, WAIT_FOREVER );
    err = semTake( complt6, WAIT_FOREVER );
    err = semTake( complt9, WAIT_FOREVER );

    /************************************************************************
    **  Message Queue Wait-to-Send Test
    ************************************************************************/
    puts( "\n.......... During the queue-full tests above, four messages" );
    puts( "           were sent, filling message queue MSQ2." );
    puts( "           Now we will attempt to send another message and " );
    puts( "           Task 1 will block waiting on room in the queue for" );
    puts( "           the new message.  After a short delay, a consumer task" );
    puts( "           will receive the first message in the queue, creating" );
    puts( "           space for the new message and unblocking Task 1." );

    puts( "Task 1 enabling Task 3 to consume one MSQ2 message after delay.");
    errno = 0;
    err = semGive( enable3 );
    if ( err != OK )
         printf( "semGive of enable3 returned error %x\r\n", errno );
    puts( "Task 1 blocking for handshake from Task 3..." );
    errno = 0;
    err = semTake( complt3, WAIT_FOREVER );
            
    msg.msg.msg_no = ++message_num;
    msg.msg.qname[3] = '2';
    printf( "Task 1 waiting indefinitely to send msg %d to %s", message_num,
            msg.msg.qname );
    errno = 0;
    err = msgQSend( queue2_id, msg.blk, 16, WAIT_FOREVER, MSG_PRI_NORMAL );
    if ( err != OK )
        printf( " returned error %x\r\n", errno );
    else
        printf( "\r\nTask 1 sent msg %d to %s", message_num, msg.msg.qname );
    taskDelay( 10 );

    puts( "\n.......... Next we will attempt to send another message and " );
    puts( "           Task 1 will block waiting on room in the queue for" );
    puts( "           the new message.  After a 1 second delay, Task 1" );
    puts( "           will quit waiting for space and will return an error" );
    puts( "           message 0x3d0004." );

    msg.msg.msg_no = ++message_num;
    msg.msg.qname[3] = '2';
    printf( "Task 1 waiting up to 1 second to send msg %d to %s", message_num,
            msg.msg.qname );
    errno = 0;
    err = msgQSend( queue2_id, msg.blk, 16, 100, MSG_PRI_NORMAL );
    if ( err != OK )
        printf( " returned error %x\r\n", errno );
    else
        printf( "\r\n" );

    puts( "\n.......... Next Task 6 will attempt to send a message to MSQ3." );
    puts( "           Task 6 will block waiting on room in the queue for" );
    puts( "           the new message.  After a 1 second delay, Task 1" );
    puts( "           will delete MSQ3 and Task 6 will return an error" );
    puts( "           message 0x3d0003." );

    puts( "Task 1 enabling Task 6 to send one MSQ3 message.");
    errno = 0;
    err = semGive( enable6 );
    if ( err != OK )
         printf( "semGive of enable6 returned error %x\r\n", errno );
    puts( "Task 1 blocking for handshake from Task 6..." );
    errno = 0;
    err = semTake( complt6, WAIT_FOREVER );

    message_num++;
    taskDelay( 100 );
            
    puts( "Task 1 deleting MSQ3 with Task6 waiting for queue space" );
    errno = 0;
    err = msgQDelete( queue3_id );
    if ( err != OK )
        printf( "Task 1 msgQDelete on MSQ3 returned error %x\r\n", errno );
    else
        printf( "\r\n" );
            
    puts( "Task 1 blocking for handshake from Task 6..." );
    errno = 0;
    err = semTake( complt6, WAIT_FOREVER );

    /************************************************************************
    **  Message Queue Urgent Message Test
    ************************************************************************/
    puts( "\n.......... During the queue-full tests above, four messages" );
    puts( "           were sent, filling message queue MSQ2." );
    puts( "           Now we will send an urgent message and then enable" );
    puts( "           a consumer task to receive all the messages in MSQ2." );
    puts( "           The consumer task should receive five messages in all" );
    puts( "           from MSQ2, starting with the urgent message." );

    msg.msg.msg_no = ++message_num;
    msg.msg.qname[3] = '2';
    printf( "Task 1 Sending urgent msg %d to %s", message_num, msg.msg.qname );
    errno = 0;
    err = msgQSend( queue2_id, msg.blk, 16, NO_WAIT, MSG_PRI_URGENT );
    if ( err != OK )
        printf( " returned error %x\r\n", errno );
    else
        printf( "\r\n" );

    puts( "Task 1 enabling Task 6 to consume MSQ2 messages.");
    errno = 0;
    err = semGive( enable6 );
    if ( err != OK )
         printf( "semGive of enable6 returned error %x\r\n", errno );
    puts( "Task 1 blocking for handshake from Task 6..." );
    errno = 0;
    err = semTake( complt6, WAIT_FOREVER );
            
    puts( "\r\nTask 1 blocking while messages are consumed..." );
    errno = 0;
    err = semTake( complt6, WAIT_FOREVER );

    /************************************************************************
    **  Message Queue Number of Messages and Queue-Not_Found Test
    ************************************************************************/
    puts( "\n.......... Finally, we test the msgQNumMsgs logic..." );
    puts( "           Then we verify the error codes returned when" );
    puts( "           a non-existent queue is specified." );

    msg_count = msgQNumMsgs( queue2_id );
    if ( msg_count == ERROR )
        printf( "\nmsgQNumMsgs for MSQ2 returned error\r\n" );
    else
        printf( "\nmsgQNumMsgs for MSQ2 returned %d messages\r\n", msg_count );

    errno = 0;
    msg_count = msgQNumMsgs( queue1_id );
    if ( msg_count == ERROR )
        printf( "\nmsgQNumMsgs for MSQ1 returned error\r\n" );
    else
        printf( "\nmsgQNumMsgs for MSQ1 returned %d messages\r\n", msg_count );

    errno = 0;
    msgQSend( queue1_id, msg.blk, 16, NO_WAIT, MSG_PRI_NORMAL );
    printf( "\nmsgQSend for MSQ1 returned error %x\r\n", errno );

    errno = 0;
    msgQReceive( queue1_id, rcvd_msg.blk, 16, NO_WAIT );
    printf( "\nmsgQReceive for MSQ1 (no waiting) returned error %x\r\n", errno );

    errno = 0;
    msgQReceive( queue1_id, rcvd_msg.blk, 16, WAIT_FOREVER );
    printf( "\nmsgQReceive for MSQ1 (wait forever) returned error %x\r\n", errno );

    errno = 0;
    msgQDelete( queue1_id );
    printf( "\nmsgQDelete for MSQ1 returned error %x\r\n", errno );
}

/*****************************************************************************
**  t_250_msec
*****************************************************************************/
void t_250_msec( int dummy0 )
{
    wdStart( wdog2_id, 25, t_250_msec, 0 );
    
    wdog2_cycle += 250;
    
    semGive( enable8 );
}

/*****************************************************************************
**  t_500_msec
*****************************************************************************/
void t_500_msec( int dummy0 )
{
    wdStart( wdog1_id, 50, t_500_msec, 0 );
    
    wdog1_cycle += 500;
    
    semGive( enable5 );
}

/*****************************************************************************
**  t_1000_msec
*****************************************************************************/
void t_1000_msec( int dummy0 )
{
    wdog2_cycle += 1000;
    
    semGive( enable8 );
}

/*****************************************************************************
**  validate_watchdog_timers
**         This function sequences through a series of actions to exercise
**         the various features and characteristics of VxWorks message
**         queues.
**
*****************************************************************************/
void validate_watchdog_timers( void )
{
    STATUS err;

    puts( "\r\n********** Watchdog Timer validation:" );
    /************************************************************************
    **  WatchDog Timer Creation Test
    ************************************************************************/
    puts( "\n.......... First we create two inactive watchdog timers." );

    wdog1_cycle = 0;
    wdog2_cycle = 0;

    wdog1_id = wdCreate();
    if ( wdog1_id == (WDOG_ID)NULL )
        puts( "wdCreate failed to create Watchdog 1." );
    else
        puts( "wdCreate successfully created Watchdog 1." );

    wdog2_id = wdCreate();
    if ( wdog2_id == (WDOG_ID)NULL )
        puts( "wdCreate failed to create Watchdog 2." );
    else
        puts( "wdCreate successfully created Watchdog 2." );

    /************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -