////////////////////////////////////////////////////////////////////////////////
//
// Copyright(C) 2005 SigmaTel, Inc.
//
//! \file ddi_uartapp_unit_test.c
//! \brief Automated unit test program for the DDI layer of the application
//! UART device driver.
//!
////////////////////////////////////////////////////////////////////////////////
// Includes and external references
////////////////////////////////////////////////////////////////////////////////
#include <types.h>
#include <string.h>
#include <hw\hw_icoll.h>
#include <hw\hw_core.h>
#include <drivers\ddi_icoll.h>
#include <drivers\ddi_uartapp.h>
#include <os\tx_api.h>
#include <os\os_thi_api.h>
#include <os\os_dpc_api.h>
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
#define DELAY_TIME ( OS_MSECS_TO_TICKS ( 10 ) )
#define BUFFER_SIZE 40
#define QUEUE_SIZE 11
typedef struct _Node
{
struct _Node * pNext;
ddi_uartapp_request_and_response_t RequestResponse;
uint8_t data[BUFFER_SIZE];
} Node;
////////////////////////////////////////////////////////////////////////////////
// Variables
////////////////////////////////////////////////////////////////////////////////
#pragma ghs section bss=".ocram.data.ncnb"
Node Queue[QUEUE_SIZE];
#pragma ghs section bss=default
TX_SEMAPHORE g_ddi_uartapp_unit_test_semaphore;
////////////////////////////////////////////////////////////////////////////////
// Prototypes
////////////////////////////////////////////////////////////////////////////////
void ddi_uartapp_unit_test_RxCompleteHandler ( ddi_uartapp_request_and_response_t * );
void ddi_uartapp_unit_test_TxCompleteHandler ( ddi_uartapp_request_and_response_t * );
void ddi_uartapp_unit_test_GetSem ( void );
void ddi_uartapp_unit_test_PutSem ( void );
void ddi_uartapp_unit_test_InitializeQueue ( void );
void ddi_uartapp_unit_test_TestDDIFunctions ( bool bDMA );
////////////////////////////////////////////////////////////////////////////////
// Code
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//! \brief The main function for the automated unit test of the DDI layer
//! of the UART:APP driver.
//! \param[in] argc The count of variable arguments passed to the function
//! \param[in] argv[] The array of variable arguments.
//! \return should never return
////////////////////////////////////////////////////////////////////////////////
void ddi_uartapp_unit_test ( void )
{
RtStatus_t rtn;
// Initialize the DPC service.
if ( SUCCESS != os_dpc_Init() )
{
SystemHalt();
}
// Initializes the Queue for later use.
ddi_uartapp_unit_test_InitializeQueue();
// Attempt to create the global semaphore.
if ( TX_SUCCESS != tx_semaphore_create ( &g_ddi_uartapp_unit_test_semaphore,
"ddi_uartapp_unit_test_sem",
0 ) )
{
SystemHalt();
}
// Output a message to let the user know this test is starting.
printf ("\nddi_uartapp_unit_test() starting.\n");
// Output a message to the user.
printf ( "Testing driver initialization.....");
// Initialize the DDI layer of the application UART driver.
rtn = ddi_uartapp_Init ( 300,
UART_APP_WORD_7_BIT,
UART_APP_2_STOP_BITS,
UART_APP_EVEN_PARITY,
false,
false,
UART_APP_FIFO_half,
UART_APP_FIFO_half,
false,
0,
false,
false,
true );
// Check the return codes.
if ( SUCCESS != rtn )
SystemHalt();
// Output a message to the user.
printf ( "PASSED\nTesting *DUPLICATE* driver initialization.....");
// Initialize the DDI layer of the application UART driver.
rtn = ddi_uartapp_Init ( 300,
UART_APP_WORD_7_BIT,
UART_APP_2_STOP_BITS,
UART_APP_EVEN_PARITY,
true,
true,
UART_APP_FIFO_7_8th,
UART_APP_FIFO_1_8th,
true,
255,
true,
true,
true );
// Check the return codes.
assert ( ERROR_DDI_UART_DRIVER_ALREADY_INITIALIZED == rtn );
// Output a message to the user.
printf ( "PASSED\nTesting driver shutdown....." );
// Shut down the DDI layer of the application UART driver.
ddi_uartapp_Shutdown();
// Output a message to the user.
printf ( "PASSED\nTesting *DUPLICATE* driver shutdown....." );
// Shut down the DDI layer of the application UART driver.
ddi_uartapp_Shutdown();
// Output a message to the user.
printf ( "PASSED\nTesting driver re-initialization....." );
// Initialize the DDI layer of the application UART driver.
rtn = ddi_uartapp_Init ( 115200,
UART_APP_WORD_8_BIT,
UART_APP_1_STOP_BIT,
UART_APP_NO_PARITY,
true,
true,
UART_APP_FIFO_7_8th,
UART_APP_FIFO_1_8th,
true,
255,
false,
false,
true );
// Check the return codes.
assert ( SUCCESS == rtn );
// Output a message to the user.
printf ( "PASSED\n\n......The driver is in PIO mode......\n\n" );
// Exercise the DDI functions.
ddi_uartapp_unit_test_TestDDIFunctions ( false );
// Output a message to the user.
printf ( "\n\n......Shutting down the driver......" );
// Shut down the DDI layer of the application UART driver.
ddi_uartapp_Shutdown();
// Output a message to the user.
printf ( "PASSED\n\n......Switching to DMA mode......\n\n" );
// Initialize the DDI layer of the application UART driver.
rtn = ddi_uartapp_Init ( 115200,
UART_APP_WORD_8_BIT,
UART_APP_1_STOP_BIT,
UART_APP_NO_PARITY,
true,
true,
UART_APP_FIFO_7_8th,
UART_APP_FIFO_1_8th,
true,
255,
true,
true,
false );
// Check the return codes.
assert ( SUCCESS == rtn );
// The driver is in DMA mode.
ddi_uartapp_unit_test_TestDDIFunctions ( true );
// Output a message to the user.
printf ( "PASSED\n\n......Shutting down the driver......" );
// Shut down the DDI layer of the application UART driver.
ddi_uartapp_Shutdown();
// Output a message to the user.
printf ( "PASSED\n\n......ddi_uartapp_unit_test() complete......\n\n" );
}
////////////////////////////////////////////////////////////////////////////////
//! \brief A simple handler to test packet receives
////////////////////////////////////////////////////////////////////////////////
void ddi_uartapp_unit_test_RxCompleteHandler ( ddi_uartapp_request_and_response_t * pRequestResponse )
{
// Ensure passed in variables are valid.
assert ( pRequestResponse