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

📄 ddi_uartapp_unit_test.c

📁 sigmatel ARM926 里面使用的UART 通讯软件
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    // Check the return code is what was expected. -     assert ( SUCCESS == pRequestResponse->eRc || -              ERROR_DDI_UART_RX_TIMEOUT_ERROR_DETECTED == pRequestResponse->eRc ); - */    // Output the data received.    printf ( "\nddi_uartapp_unit_test_RxCompleteHandler::"             "u16NumSize = %d : "             "u16NumBytes = %d : "             "eRc = %d : "             "data = %*.*s\n",             pRequestResponse->u16Size,             pRequestResponse->u16Bytes,             pRequestResponse->eRc,             pRequestResponse->u16Bytes,             pRequestResponse->u16Bytes,             pRequestResponse->pBuffer );    // Sterilize the buffer.    memset ( pRequestResponse->pBuffer, 0, BUFFER_SIZE );    // Check if this was the last request.    if ( &(Queue[QUEUE_SIZE - 1].RequestResponse) == pRequestResponse )        ddi_uartapp_unit_test_PutSem();}//////////////////////////////////////////////////////////////////////////////////! \brief A simple handler to test packet transmits////////////////////////////////////////////////////////////////////////////////void ddi_uartapp_unit_test_TxCompleteHandler ( ddi_uartapp_request_and_response_t * pRequestResponse ){    // Ensure passed in variables are valid.    assert ( pRequestResponse );    // Check if this was the last request.    if ( BUFFER_SIZE == pRequestResponse->u16Size )        ddi_uartapp_unit_test_PutSem();}//////////////////////////////////////////////////////////////////////////////////! \brief Obtain the global semaphore.//! \internal////////////////////////////////////////////////////////////////////////////////void ddi_uartapp_unit_test_GetSem ( void ){    UINT status;#ifdef DEBUG    char          * name;    ULONG           current_value;    TX_THREAD     * first_suspended;    ULONG           suspended_count;    TX_SEMAPHORE  * next_sem;    // Get information on the semaphore.    status = tx_semaphore_info_get ( &g_ddi_uartapp_unit_test_semaphore,                                     &name,                                     &current_value,                                     &first_suspended,                                     &suspended_count,                                     &next_sem );    // Ensure that we don't have a programming error.    assert ( TX_SUCCESS == status && 2 > current_value );#endif    // Obtain the global driver semaphore.    status = tx_semaphore_get ( &g_ddi_uartapp_unit_test_semaphore, TX_WAIT_FOREVER );    // Ensure that we don't have a programming error.    assert ( status == TX_SUCCESS );}//////////////////////////////////////////////////////////////////////////////////! \brief Release the global semaphore.//! \internal////////////////////////////////////////////////////////////////////////////////void ddi_uartapp_unit_test_PutSem ( void ){    UINT status;#ifdef DEBUG    char          * name;    ULONG           current_value;    TX_THREAD     * first_suspended;    ULONG           suspended_count;    TX_SEMAPHORE  * next_sem;    // Get information on the semaphore.    status = tx_semaphore_info_get ( &g_ddi_uartapp_unit_test_semaphore,                                     &name,                                     &current_value,                                     &first_suspended,                                     &suspended_count,                                     &next_sem );    // Ensure that we don't have a programming error.    assert ( TX_SUCCESS == status && 0 == current_value );#endif    // Release the global driver semaphore.    status = tx_semaphore_put ( &g_ddi_uartapp_unit_test_semaphore );    // Ensure that we don't have a programming error.    assert ( status == TX_SUCCESS );}//////////////////////////////////////////////////////////////////////////////////! \brief Initializes the global Queue.//! \internal////////////////////////////////////////////////////////////////////////////////void ddi_uartapp_unit_test_InitializeQueue ( void ){    int       i;    // Initialize the Queue structure.    for ( i = 0; i < QUEUE_SIZE; i++ )    {        // Initialize the pointers to the next entry.        Queue[i].pNext = &(Queue[(i + 1) % QUEUE_SIZE]);        // Initialize data values.        Queue[i].RequestResponse.eRc      = SUCCESS;        Queue[i].RequestResponse.u16Bytes = NULL;        Queue[i].RequestResponse.u16Size  = BUFFER_SIZE;        Queue[i].RequestResponse.pCB      = NULL;        Queue[i].RequestResponse.pBuffer  = Queue[i].data;        // Initialize the data buffer space.        memset ( Queue[i].RequestResponse.pBuffer, NULL, BUFFER_SIZE );    }    // NULL terminate the queue.    Queue[i].pNext = NULL;    // Explicitly initialize the size of the requests for boundary values.    Queue[0].RequestResponse.u16Size  = 1;    Queue[1].RequestResponse.u16Size  = 7;    Queue[2].RequestResponse.u16Size  = 8;    Queue[3].RequestResponse.u16Size  = 9;    Queue[4].RequestResponse.u16Size  = 15;    Queue[5].RequestResponse.u16Size  = 16;    Queue[6].RequestResponse.u16Size  = 17;    Queue[7].RequestResponse.u16Size  = 31;    Queue[8].RequestResponse.u16Size  = 32;    Queue[9].RequestResponse.u16Size  = 33;    Queue[10].RequestResponse.u16Size = BUFFER_SIZE;}//////////////////////////////////////////////////////////////////////////////////! \brief A simple function to exercise the DDI functions.////////////////////////////////////////////////////////////////////////////////void ddi_uartapp_unit_test_TestDDIFunctions ( bool bDMA ){    int          i;    RtStatus_t   rtn;    char       * pTxData = "ddi_uartapp_unit_test Tx output string\r\n\0";    // Test the "write" function.    for ( i = 0; i < QUEUE_SIZE; i++ )    {        // Initialize the buffer space with a string.        memcpy ( Queue[i].RequestResponse.pBuffer,                 pTxData,                 Queue[i].RequestResponse.u16Size );        // Set the Callback handler.        Queue[i].RequestResponse.pCB = ddi_uartapp_unit_test_TxCompleteHandler;        // Output a message to the user.        printf ( "Transmitting ddi_uartapp_tx() of %d characters.....",                 Queue[i].RequestResponse.u16Size );        // Attempt to send a request.        do            // Attempt to transmit the characters.            rtn = ddi_uartapp_tx ( &(Queue[i].RequestResponse) );        while ( SUCCESS != rtn && ERROR_DDI_UART_XFER_IN_PROGRESS != rtn );        // Output a message to the user.        printf ( "PASSED.\n" );    }    // Wait until all the TX requests are completed.    ddi_uartapp_unit_test_GetSem();    // Re-initialize the data.    ddi_uartapp_unit_test_InitializeQueue();    // Output a message to the user.    printf ( "\nPlease enter the requested number of characters.....\n\n" );    // Test the "read" function.    for ( i = 0; i < QUEUE_SIZE; i++ )    {        // Set the Callback handler.        Queue[i].RequestResponse.pCB = ddi_uartapp_unit_test_RxCompleteHandler;        // Set the transfer size to multiples of four for DMA.        if ( bDMA )        {            // Ensure that request size is non-zero.            if ( ( ( i + 1 ) * 4 ) % BUFFER_SIZE )                Queue[i].RequestResponse.u16Size = ( ( i + 1 ) * 4 ) % BUFFER_SIZE;            else                Queue[i].RequestResponse.u16Size = 4;        }        // Attempt to send a request.        do            rtn = ddi_uartapp_rx ( &(Queue[i].RequestResponse) );        while ( SUCCESS != rtn && ERROR_DDI_UART_XFER_IN_PROGRESS != rtn );        // Output a message to the user.        printf ( "Requested ddi_uartapp_rx() of %d characters.....PASSED\n",                 Queue[i].RequestResponse.u16Size );    }    // Wait until all the TX requests are completed.    ddi_uartapp_unit_test_GetSem();}////////////////////////////////////////////////////////////////////////////////// End of file////////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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