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

📄 cspiloopbacktest.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    case SPM_BEGIN_TEST:
        // Sent to the DLL immediately before a test executes. This gives
        // the DLL a chance to perform any common action that occurs at the
        // beginning of each test, such as entering a new logging level.
        // The spParam parameter will contain a pointer to a SPS_BEGIN_TEST
        // structure, which contains the function table entry and some other
        // useful information for the next test to execute. If the ShellProc
        // function returns SPR_SKIP, then the test case will not execute.
        Debug(TEXT("ShellProc(SPM_BEGIN_TEST, ...) called"));
        // Start our logging level.
        pBT = (LPSPS_BEGIN_TEST)spParam;
        g_pKato->BeginLevel(
            pBT->lpFTE->dwUniqueID,
            TEXT("BEGIN TEST: \"%s\", Threads=%u, Seed=%u"),
            pBT->lpFTE->lpDescription,
            pBT->dwThreadCount,
            pBT->dwRandomSeed);
        break;

    case SPM_END_TEST:
        // Sent to the DLL after a single test executes from the DLL.
        // This gives the DLL a time perform any common action that occurs at
        // the completion of each test, such as exiting the current logging
        // level. The spParam parameter will contain a pointer to a
        // SPS_END_TEST structure, which contains the function table entry and
        // some other useful information for the test that just completed. If
        // the ShellProc returned SPR_SKIP for a given test case, then the
        // ShellProc() will not receive a SPM_END_TEST for that given test case.
        Debug(TEXT("ShellProc(SPM_END_TEST, ...) called"));
        // End our logging level.
        pET = (LPSPS_END_TEST)spParam;
        g_pKato->EndLevel(
            TEXT("END TEST: \"%s\", %s, Time=%u.%03u"),
            pET->lpFTE->lpDescription,
            pET->dwResult == TPR_SKIP ? TEXT("SKIPPED") :
            pET->dwResult == TPR_PASS ? TEXT("PASSED") :
            pET->dwResult == TPR_FAIL ? TEXT("FAILED") : TEXT("ABORTED"),
            pET->dwExecutionTime / 1000, pET->dwExecutionTime % 1000);
        break;

    case SPM_EXCEPTION:
        // Sent to the DLL whenever code execution in the DLL causes and
        // exception fault. TUX traps all exceptions that occur while
        // executing code inside a test DLL.
        Debug(TEXT("ShellProc(SPM_EXCEPTION, ...) called"));
        g_pKato->Log(LOG_EXCEPTION, TEXT("Exception occurred!"));
        break;

    default:
        // Any messages that we haven't processed must, by default, cause us
        // to return SPR_NOT_HANDLED. This preserves compatibility with future
        // versions of the TUX shell protocol, even if new messages are added.
        return SPR_NOT_HANDLED;
    }

    return SPR_HANDLED;
}

////////////////////////////////////////////////////////////////////////////////

//----------------------------------------------------
// These two functions added To Framework Program
//----------------------------------------------------

//------------------------------------------------------------------------------
//
// Function: InitializeTests
//
// This function initializes the set of tests.  It maps the memory to the
// registers.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE if the memory map succeeds; FALSE if the memory map fails.
//
//------------------------------------------------------------------------------
static BOOL InitializeTests(void)
{
   Debug((TEXT("+%s()\r\n"), __WFUNCTION__));

	g_hCspi = CreateFile(TEXT("SPI1:"),    	   // name of device
		        GENERIC_READ|GENERIC_WRITE,      // desired access
      	    FILE_SHARE_READ|FILE_SHARE_WRITE,// sharing mode
      	    NULL,									           // security attributes (ignored)
      	    OPEN_EXISTING,							     // creation disposition
		        FILE_FLAG_RANDOM_ACCESS,				 // flags/attributes
		        NULL);                           // template file (ignored)
	if(g_hCspi == NULL)
	{
		RETAILMSG(1,
            (TEXT("main.cpp: FinishTests():InitializeTests(): Createfile failed!\r\n")));
		   return FALSE;
	}
	  // initialize CSPI bus configuration
    gBusCnfg.chipselect = CSPI_CONTROLREG_CS_SS0/*CSPI_CONREG_SS0*/; 
    gBusCnfg.freq = 4000000; // 4M 
    gBusCnfg.bitcount = CSPI_CONTROLREG_BITCOUNT_32BIT/*CSPI_CONREG_BITCOUNT_32BIT*/;  //only 32 bit is supported for SDMA based transaction
    gBusCnfg.sspol = CSPI_CONTROLREG_SSPOL_ACTIVE_HIGH/*CSPI_CONREG_SSPOL_ACTIVE_HIGH*/;
    gBusCnfg.ssctl = CSPI_CONTROLREG_SSCTL_ASSERT/*CSPI_CONREG_SSCTL_ASSERT*/;
    gBusCnfg.pol = CSPI_CONTROLREG_POL_ACTIVE_HIGH/*CSPI_CONREG_POL_ACTIVE_HIGH*/;
    gBusCnfg.pha = CSPI_CONTROLREG_PHA0/*CSPI_CONREG_PHA0*/;
    gBusCnfg.drctl = CSPI_CONTROLREG_DRCTL_DONTCARE/*CSPI_CONREG_DRCTL_DONTCARE*/;

    // fill entries in exchange packet with static information
    gXchPkt.pBusCnfg = &gBusCnfg;
    gXchPkt.pTxBuf = g_TXDATA;
    gXchPkt.pRxBuf = g_RXDATA;
    
   Debug((TEXT("-%s returning TRUE\r\n"), __WFUNCTION__));

   return TRUE;
}

//------------------------------------------------------------------------------
//
// Function: FinishTests
//
// This function performs the clean up after the tests have finished.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
static VOID FinishTests(void)
{
    Debug((TEXT("+%s()\r\n"), __WFUNCTION__));

    // Close the file handle
    if (g_hCspi != NULL)
    {
            CloseHandle(g_hCspi);
            Debug(TEXT("main.cpp: FinishTests():CloseHandle(g_hCspi): Closed file handle! \r\n"));
    }

    Debug((TEXT("-%s()\r\n"), __WFUNCTION__));
}

//-----------------------------------------------------------------------------
//
// Function: CSPILoopbackTest
//
// This function attempts to test CSPI Loopback capabilities.
//
// Parameters:
//      uiMsg
//           [in] to determine if the shell wants to execute the test.
//      tpParam
//           [in] Ignored.
//      lpFTE
//           [in] Ignored.
//
// Returns:
//      Specifies if the test passed (TPR_PASS), failed (TPR_FAIL)
//------------------------------------------------------------------------------
TESTPROCAPI CSPILoopbackTest(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
    UINT count;

    // Validate that the shell wants the test to run
    if (uMsg != TPM_EXECUTE)
    {
        return TPR_NOT_HANDLED;
    }
    
#if 0 // No this feature in RTM14-B
    // Enable Loop back first
    if (!DeviceIoControl(g_hCspi,   // file handle to the driver
        CSPI_IOCTL_ENABLE_LOOPBACK, // I/O control code
        NULL,                       // in buffer
        0,                          // in buffer size
        NULL,                       // out buffer
        0,                          // out buffer size
        0,                          // number of bytes returned
        NULL))                      // ignored (=NULL)
    {
        g_pKato->Log(LOG_ABORT, TEXT("CSPILoopbackTest CSPI_IOCTL_ENABLE_LOOPBACK failed \r\n"));
        return TPR_FAIL;
    }
#else
        g_pKato->Log(LOG_ABORT, TEXT("CSPILoopbackTest CSPI_IOCTL_ENABLE_LOOPBACK not support in RTM14-B \r\n"));
#endif

    // Function implementation goes here.
    for (g_Count = 1; g_Count <= 8; g_Count++ )
    {
        // reset exchange count for next exchange
        gXchPkt.xchCnt = g_Count ;

        // issue the IOCTL to request a CSPI transfer
        if (!DeviceIoControl(g_hCspi,   // file handle to the driver
            CSPI_IOCTL_EXCHANGE,        // I/O control code
            &gpXchPkt,                 // in buffer
            sizeof(gpXchPkt),          // in buffer size
            NULL,                      // out buffer
            0,                         // out buffer size
            0,                         // number of bytes returned
            NULL))                     // ignored (=NULL)
        {
            g_pKato->Log(LOG_COMMENT, TEXT("CSPILoopbackTest: CSPI_IOCTL_EXCHANGE Failed \r\n"));
            return TPR_FAIL;
        }

        // CSPI bus driver will update xchCnt when exchange is complete
        // check if exchange completed
	    if (gXchPkt.xchCnt != g_Count)
        {
            g_pKato->Log(LOG_COMMENT, TEXT("CSPILoopbackTest: exchange incomplete!! \r\n"));
            return FALSE;
        }

        for (count = 0; count < g_Count; count++)
        {
            if(g_RXDATA[count] != g_TXDATA[count])
            {
                g_pKato->Log(LOG_COMMENT, TEXT("CSPILoopbackTest: Wrong data received. Test Failed (%d:R%d,T%d)\r\n"),count,g_RXDATA[count] ,g_TXDATA[count] );
                return TPR_FAIL;
            }
        }
        g_pKato->Log(LOG_COMMENT, TEXT("CSPILoopbackTest: Test passed for exchange count %d \r\n"), g_Count);
    }

#if 0 // No this feature in RTM14-B
    // Disable Loop back 
    if (!DeviceIoControl(g_hCspi,    // file handle to the driver
        CSPI_IOCTL_DISABLE_LOOPBACK, // I/O control code
        NULL,                        // in buffer
        0,                           // in buffer size
        NULL,                        // out buffer
        0,                           // out buffer size
        0,                           // number of bytes returned
        NULL))                       // ignored (=NULL)
    {
        g_pKato->Log(LOG_ABORT, TEXT("CSPILoopbackTest CSPI_IOCTL_DISABLE_LOOPBACK failed \r\n"));
        return TPR_FAIL;
    }
#else
        g_pKato->Log(LOG_ABORT, TEXT("CSPILoopbackTest CSPI_IOCTL_DISABLE_LOOPBACK not support in RTM14-B \r\n"));
#endif

    return TPR_PASS;
}

⌨️ 快捷键说明

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