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

📄 main.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        // TestProc() in the script is called.
        Debug(TEXT("ShellProc(SPM_START_SCRIPT, ...) called"));
        break;

    case SPM_STOP_SCRIPT:
        // Sent to the DLL when the script has stopped. This message is sent
        // when the script reaches its end, or because the user pressed
        // stopped prior to the end of the script. This message is sent to
        // all Tux DLLs, including loaded Tux DLLs that are not in the script.
        Debug(TEXT("ShellProc(SPM_STOP_SCRIPT, ...) called"));
        break;

    case SPM_BEGIN_GROUP:
        // Sent to the DLL before a group of tests from that DLL is about to
        // be executed. This gives the DLL a time to initialize or allocate
        // data for the tests to follow. Only the DLL that is next to run
        // receives this message. The prior DLL, if any, will first receive
        // a SPM_END_GROUP message. For global initialization and
        // de-initialization, the DLL should probably use SPM_START_SCRIPT
        // and SPM_STOP_SCRIPT, or even SPM_LOAD_DLL and SPM_UNLOAD_DLL.
        Debug(TEXT("ShellProc(SPM_BEGIN_GROUP, ...) called"));
        g_pKato->BeginLevel(0, TEXT("BEGIN GROUP: OnewireTest.DLL"));
        break;

    case SPM_END_GROUP:
        // Sent to the DLL after a group of tests from that DLL has completed
        // running. This gives the DLL a time to cleanup after it has been
        // run. This message does not mean that the DLL will not be called
        // again; it just means that the next test to run belongs to a
        // different DLL. SPM_BEGIN_GROUP and SPM_END_GROUP allow the DLL
        // to track when it is active and when it is not active.
        Debug(TEXT("ShellProc(SPM_END_GROUP, ...) called"));
        g_pKato->EndLevel(TEXT("END GROUP: OnewireTest.DLL"));
        break;

    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);
	// Added because Kato.dll cannot work properly now
	if (pET->dwResult == TPR_FAIL)
		Debug(TEXT("Failed!"));
	if (pET->dwResult == TPR_PASS)
		Debug(TEXT("Passed!"));
	// Added -
        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()
{
    Debug((TEXT("+%s()\r\n"), __WFUNCTION__));

// Create I2C File Handle
    {
        if(hI2C == NULL)
		{
            hI2C = CreateFile(I2CbusNr==1?CAM_I2C_PORT:USB_I2C_PORT,  // 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 unable to open the file handle
        if (hI2C == INVALID_HANDLE_VALUE)
        {
            Debug((TEXT("main.cpp:InitializeTests():CreateFile(%s): Unable to open file! \r\n"),
										I2CbusNr==1?CAM_I2C_PORT:USB_I2C_PORT));
            
            return 0;
        }

        // Clock frequency set at 81KHz, Slave Addr = 0x5A, Write at 0x5A, Read at 0x5B
        DWORD dwFrequency = 81000;
        BYTE bySelf = 0x20;

        // Initialize the device internal fields, one-time initialization is enough
        I2C_MACRO_SET_FREQUENCY(hI2C, dwFrequency);
        I2C_MACRO_SET_SELF_ADDR(hI2C, bySelf);
    }

    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()
{
    Debug((TEXT("+%s()\r\n"), __WFUNCTION__));

    // Close the file handle
    if (hI2C != NULL)
    {
        CloseHandle(hI2C);
        Debug((TEXT("main.cpp:FinishTests(%s):CloseHandle(hI2C): Closed file handle! \r\n"),
								I2CbusNr==1?CAM_I2C_PORT:USB_I2C_PORT));
		hI2C=NULL;
    }

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

static BOOL ProcessCmdLine(LPCTSTR cmdline)
{
	BOOL retval=TRUE ;
	if(cmdline!=NULL)
	{
// ok, cmd line is given, validate it now    
		if(1<_tcslen(cmdline)) 
        {
// something too short ?
            g_pKato->Log( LOG_FAIL, TEXT("FAIL : The I2C Ports can only be 1 (I2C1:) and 2 (I2C2:)\n"));
            DisplayHelp();
            retval=FALSE;
            goto cleanup;
        }; 
//since the com ports can only be 1 and 2
		if(0<=_tcsicmp(cmdline,L"1") && 0>=_tcsicmp(cmdline,L"2") ) 
		{
			I2CbusNr=_ttoi(cmdline);
            retval=TRUE;
            goto cleanup;
        }
        else 
        {
            DisplayHelp();
            retval=FALSE;
            goto cleanup;
        };
            
		retval=FALSE;        
	}
	else
// it may have no cmd line at all, so default to i2c bus one
		I2CbusNr=1;
cleanup:
	return retval;
}


void DisplayHelp(void)
{
	Debug(TEXT("Command line Usage : \n"));
	Debug(TEXT("<I2C bus number> Enter the bus number 1 (I2C1:) or 2 (I2C2:) to run the test on a specific I2C bus number. If no argument given default is bus 1\n"));
	return;   
}

⌨️ 快捷键说明

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