none
gpio code??? RRS feed

  • General discussion

  • //////////////////////////////////////////////////////////////////////////////// // // CETK_GPIO TUX DLL // // Module: gpiotest.cpp // Contains the test functions. // // Revision History: // //////////////////////////////////////////////////////////////////////////////// #include "main.h" #include "globals.h" #include "gpio.h" #include "kernelgpio.h" #define LOGTYPE_NONE 0 #define LOGTYPE_ERROR 1 #define LOGTYPE_INFO 2 #define LOGTYPE_WARNING 3 #define GPIO_TEST1 GPIO_0_00 enum GPIO_TEST_MODE { GPIO_READ_ALL = 0, GPIO_READ_ONE, GPIO_READ_ALL_BUT_ONE, GPIO_WRITE_ALL, GPIO_WRITE_ONE, GPIO_WRITE_ALL_BUT_ONE, GPIO_VERIFY_ALL, GPIO_VERIFY_ONE, GPIO_VERIFY_ALL_BUT_ONE, } ; /////////////////////////////////////////////////////// // Global structure defining tests // also stores state information for later comparison /////////////////////////////////////////////////////// typedef struct { UINT32 Id; LPCTSTR Name; BOOL IsOutput; BOOL CanChange; GPIO_DIRECTION Direction; GPIO_STATE State; } GPIO_TEST_DATA; GPIO_TEST_DATA g_GpioTestData[] = { { GPIO_0_00, TEXT("J30-Pin92"), TRUE, TRUE, GPIO_DIRECTION_INPUT, GPIO_STATE_LOW }, { GPIO_0_07, TEXT("J30-Pin90"), TRUE, TRUE, GPIO_DIRECTION_INPUT, GPIO_STATE_LOW }, { GPIO_2_15, TEXT("LCD-BLPwr"), TRUE, TRUE, GPIO_DIRECTION_INPUT, GPIO_STATE_LOW }, { GPIO_4_00, TEXT("SD-INS"), FALSE, TRUE, GPIO_DIRECTION_INPUT, GPIO_STATE_LOW }, { GPIO_4_01, TEXT("SD-WP"), FALSE, TRUE, GPIO_DIRECTION_INPUT, GPIO_STATE_LOW }, { 0, NULL, FALSE, FALSE, GPIO_DIRECTION_INPUT, GPIO_STATE_LOW }, }; int TestKernelIoControl(int iTestNum, TCHAR *pIoControlCodeText, DWORD IoControlCode, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer, UINT32 outSize, LPDWORD pOutSize, BOOL bExpectedResult = TRUE, BOOL bExceptionExpected = FALSE ); //////////////////////////////////////////////////////////////////////////////// // LogResult // Abstracts logging to make calling and formatting easier // // Parameters: // dwVerbosity Kato logging verbosity. // dwType Defines text prefix to be added to log entry. // wszFormat PRINTF-type format string for log entry. // ... Optional paramaters used by PRINTF format string. // // Return value: // None // //////////////////////////////////////////////////////////////////////////////// void LogResult(DWORD dwVerbosity, DWORD dwType, LPCWSTR wszFormat, ...) { va_list pArgs; TCHAR msgFormat[300]; TCHAR *prefix; switch(dwType) { case LOGTYPE_ERROR: prefix = TEXT("ERROR: "); break; case LOGTYPE_WARNING: prefix = TEXT("WARNING: "); break; case LOGTYPE_INFO: prefix = TEXT("INFO: "); break; case LOGTYPE_NONE: default: prefix = TEXT(""); break; } wsprintf(msgFormat, TEXT("%s%s"), prefix, wszFormat); va_start(pArgs, wszFormat); g_pKato->LogV(dwVerbosity, msgFormat, pArgs); va_end(pArgs); // Increment global error counter if (dwVerbosity == LOG_FAIL || dwType == LOGTYPE_ERROR) { g_dwNumTestErrors++; } } //////////////////////////////////////////////////////////////////////////////// // TestGetPtrToGpioData // Get pointer to test data info for the specified GPIO id // // Parameters: // GpioId GPIO Id defined in gpiodefs.h // // Return value: // Pointer to suitable test data structure // //////////////////////////////////////////////////////////////////////////////// GPIO_TEST_DATA * TestGetPtrToGpioData(UINT32 GpioId) { static GPIO_TEST_DATA DefaultData = { 0, TEXT("Unknown"), FALSE, FALSE, GPIO_DIRECTION_INPUT, GPIO_STATE_LOW }; UINT32 pos; pos = 0; while ( g_GpioTestData[pos].Name != NULL ) { if ( g_GpioTestData[pos].Id == GpioId ) { return &g_GpioTestData[pos]; } pos++; } return &DefaultData; } //////////////////////////////////////////////////////////////////////////////// // TestSetGpioDirection // Set the direction for the specified GPIO line and verify the new setting. // // Parameters: // GpioLine GPIO Id defined in gpiodefs.h // Direction The direction to set. // // Return value: // TPR_PASS if successful // TPR_FAIL if problem // //////////////////////////////////////////////////////////////////////////////// int TestSetGpioDirection(UINT32 GpioLine, GPIO_DIRECTION Direction) { int iTestResult = TPR_PASS; GPIO_DIRECTION ActualDirection; GPIOSetDirection(GpioLine, Direction); ActualDirection = GPIOGetDirection(GpioLine); if ( ActualDirection != Direction ) { LogResult(LOG_FAIL, LOGTYPE_ERROR, TEXT("Verification of %s line direction change failed (wanted %d, got %d)"), TestGetPtrToGpioData(GpioLine)->Name, (int)Direction, (int)ActualDirection); iTestResult = TPR_FAIL; } return iTestResult; } //////////////////////////////////////////////////////////////////////////////// // TestSetGpioState // Set the state for the specified GPIO line and verify the new setting. // // Parameters: // GpioLine GPIO Id defined in gpiodefs.h // State The state to set. // // Return value: // TPR_PASS if successful // TPR_FAIL if problem // //////////////////////////////////////////////////////////////////////////////// int TestSetGpioState(UINT32 GpioLine, GPIO_STATE State) { int iTestResult = TPR_PASS; GPIO_STATE ActualState; GPIOSetOutputState(GpioLine, State); ActualState = GPIOGetInputState(GpioLine); if ( ActualState != State ) { LogResult(LOG_FAIL, LOGTYPE_ERROR, TEXT("Verification of %s line state change failed (wanted %d, got %d)"), TestGetPtrToGpioData(GpioLine)->Name, State, ActualState); iTestResult = TPR_FAIL; } return iTestResult; } //////////////////////////////////////////////////////////////////////////////// // TestCurrentGpioCondition // Get/Set/Verify current state of GPIO lines defined in the test data structure. // // Parameters: // Mode What to do // GpioLine GPIO Id defined in gpiodefs.h // // Return value: // TPR_PASS if successful // TPR_FAIL if problem // //////////////////////////////////////////////////////////////////////////////// int TestCurrentGpioCondition(enum GPIO_TEST_MODE Mode, UINT32 GpioLine = 0) { int iTestResult = TPR_PASS; GPIO_TEST_DATA *lineData; UINT32 pos; BOOL bInclude; pos = 0; while ( g_GpioTestData[pos].Name != NULL ) { lineData = &g_GpioTestData[pos]; bInclude = TRUE; if ( (Mode == GPIO_READ_ALL_BUT_ONE) || (Mode == GPIO_WRITE_ALL_BUT_ONE) || (Mode == GPIO_VERIFY_ALL_BUT_ONE) ) { bInclude = ( lineData->Id != GpioLine ); } if ( (Mode == GPIO_READ_ONE) || (Mode == GPIO_WRITE_ONE) || (Mode == GPIO_VERIFY_ONE) ) { bInclude = ( lineData->Id == GpioLine ); } if ( bInclude ) { if ( (Mode == GPIO_READ_ONE) || (Mode == GPIO_READ_ALL) || (Mode == GPIO_READ_ALL_BUT_ONE) ) { // Store line state lineData->Direction = GPIOGetDirection(lineData->Id); lineData->State = GPIOGetInputState(lineData->Id); if (!lineData->IsOutput) LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT(" %s State: %s"), lineData->Name, lineData->State == GPIO_STATE_LOW ? L"LOW" : L"HIGH"); } else if ( (Mode == GPIO_WRITE_ONE) || (Mode == GPIO_WRITE_ALL) || (Mode == GPIO_WRITE_ALL_BUT_ONE) ) { // Restore stored line state if ( TestSetGpioDirection(lineData->Id, lineData->Direction)!= TPR_PASS ) { iTestResult = TPR_FAIL; } if ( TestSetGpioState(lineData->Id, lineData->State) != TPR_PASS ) { iTestResult = TPR_FAIL; } } else { // Confirm line is in same state as before if ( lineData->Direction != GPIOGetDirection(lineData->Id) ) { LogResult(LOG_FAIL, LOGTYPE_ERROR, TEXT("Verification of %s line direction failed"), lineData->Name ); iTestResult = TPR_FAIL; } if ( lineData->State != GPIOGetInputState(lineData->Id) ) { LogResult(LOG_FAIL, LOGTYPE_ERROR, TEXT("Verification of %s line state failed"), lineData->Name ); iTestResult = TPR_FAIL; } } } pos++; } return iTestResult; } //////////////////////////////////////////////////////////////////////////////// // TestKernelIoControl // Use KernelIoControl to perform an action. // Also checks that the expected result was returned. // // Parameters: // iTestNum Number used in logging // pIoControlCodeText Test info text // .... Parameters needed for IOCL call // bExpectedResult Expected result from IOCTL call // bExceptionExpected If exception expected from IOCTL call // // Return value: // TRUE if successful, FALSE if problem // //////////////////////////////////////////////////////////////////////////////// int TestKernelIoControl(int iTestNum, TCHAR *pIoControlCodeText, DWORD IoControlCode, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer, UINT32 outSize, LPDWORD pOutSize, BOOL bExpectedResult, BOOL bExceptionExpected ) { int iTestResult = TPR_PASS; BOOL bGotException = FALSE; BOOL bIoctlResult; TCHAR msgText[512]; if ( pIoControlCodeText != NULL ) LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT("KernelIoControl: TestNum %d, %s"), iTestNum, pIoControlCodeText); __try { bIoctlResult = KernelIoControl(IoControlCode, pInpBuffer, inpSize, pOutBuffer, outSize, pOutSize); } __except (EXCEPTION_EXECUTE_HANDLER) { if ( !bExceptionExpected ) { wsprintf(msgText, TEXT("Unexpected exception, wanted %s result"), (bExpectedResult ? TEXT("Pass") : TEXT("Fail")) ); iTestResult = TPR_FAIL; } bGotException = TRUE; } if ( !bGotException ) { if ( bExceptionExpected ) { wsprintf(msgText, TEXT("Did not get expected exception, got %s result"), (bIoctlResult ? TEXT("Pass") : TEXT("Fail")) ); iTestResult = TPR_FAIL; } else if ( bIoctlResult != bExpectedResult ) { wsprintf(msgText, TEXT("Unexpected %s result"), (bIoctlResult ? TEXT("Pass") : TEXT("Fail")) ); iTestResult = TPR_FAIL; } } if ( iTestResult == TPR_FAIL ) { LogResult(LOG_FAIL, LOGTYPE_ERROR, TEXT("KernelIoControl API check %d failed - %s\r\n"), iTestNum, msgText); if ( pIoControlCodeText != NULL ) { LogResult(LOG_FAIL, LOGTYPE_ERROR, TEXT(" Test Type ............: %s\r\n"), pIoControlCodeText); } LogResult(LOG_FAIL, LOGTYPE_ERROR, TEXT(" ControlCode ..........: %d\r\n"), pIoControlCodeText, IoControlCode); LogResult(LOG_FAIL, LOGTYPE_ERROR, TEXT(" Input Buffer .........: 0x%p\r\n"), pInpBuffer); LogResult(LOG_FAIL, LOGTYPE_ERROR, TEXT(" Input Buffer Length ..: %d\r\n"), inpSize); LogResult(LOG_FAIL, LOGTYPE_ERROR, TEXT(" Output Buffer ........: 0x%p\r\n"), pOutBuffer); LogResult(LOG_FAIL, LOGTYPE_ERROR, TEXT(" Output Buffer Length .: %d\r\n"), outSize); LogResult(LOG_FAIL, LOGTYPE_ERROR, TEXT(" Output Buffer Used ...: 0x%p\r\n"), pOutSize); } return iTestResult; } //////////////////////////////////////////////////////////////////////////////// // TestToggleGpio // Toggle GPIO output for the specified period. // // Parameters: // iTestNum Number used in logging // GpioLine GPIO Id defined in gpiodefs.h // LoopCount How many state changes will occur (*2) // StateChangeDelay mS to wait between each state change // // Return value: // TPR_PASS if successful // TPR_FAIL if problem // //////////////////////////////////////////////////////////////////////////////// int TestToggleGpio(int iTestNum, UINT32 GpioLine, UINT32 LoopCount, UINT32 StateChangeDelay) { int iTestResult; DWORD dwResult; UINT32 inParams[8]; UINT32 outBuffer[8]; UINT32 oldDir; iTestNum *= 100; inParams[0] = GPIO_CMD_GET_DIRECTION; inParams[1] = GpioLine; iTestResult = TestKernelIoControl(iTestNum + 1, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_GET_DIRECTION"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32) * 2, &oldDir, sizeof(oldDir), &dwResult); if ( iTestResult == TPR_PASS ) { inParams[0] = GPIO_CMD_SET_DIRECTION; inParams[1] = GpioLine; inParams[2] = GPIO_DIRECTION_OUTPUT; iTestResult = TestKernelIoControl(iTestNum + 2, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_SET_DIRECTION"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32) * 3, &oldDir, sizeof(oldDir), &dwResult); if ( iTestResult == TPR_PASS ) { inParams[0] = GPIO_CMD_GET_DIRECTION; inParams[1] = GpioLine; iTestResult = TestKernelIoControl(iTestNum + 3, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_GET_DIRECTION"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32) * 2, outBuffer, sizeof(oldDir), &dwResult); if ( iTestResult == TPR_PASS ) { if ( outBuffer[0] != GPIO_DIRECTION_OUTPUT ) { LogResult(LOG_FAIL, LOGTYPE_ERROR, TEXT("Setting line direction failed")); iTestResult = TPR_FAIL; } } } } while ( (iTestResult == TPR_PASS) && (LoopCount > 0) ) { inParams[0] = GPIO_CMD_SET_OUTPUT_STATE; inParams[1] = GpioLine; inParams[2] = GPIO_STATE_HIGH; iTestResult = TestKernelIoControl(iTestNum + 5, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_SET_OUTPUT_STATE"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32) * 3, NULL, 0, &dwResult); if ( iTestResult == TPR_PASS ) { Sleep(StateChangeDelay); inParams[0] = GPIO_CMD_SET_OUTPUT_STATE; inParams[1] = GpioLine; inParams[2] = GPIO_STATE_LOW; iTestResult = TestKernelIoControl(iTestNum + 6, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_SET_OUTPUT_STATE"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32) * 3, NULL, 0, &dwResult); if ( iTestResult == TPR_PASS ) { Sleep(StateChangeDelay); } } LoopCount--; } if ( iTestResult == TPR_PASS ) { inParams[0] = GPIO_CMD_SET_DIRECTION; inParams[1] = GpioLine; inParams[2] = oldDir; iTestResult = TestKernelIoControl(iTestNum + 7, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_SET_DIRECTION"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32) * 3, NULL, 0, &dwResult); } return iTestResult; } //////////////////////////////////////////////////////////////////////////////// // TestProc_API // Performs basic tests on the GPIO IOCTL API. // // Parameters: // uMsg Message code. // tpParam Additional message-dependent data. // lpFTE Function table entry that generated this call. // // Return value: // TPR_PASS if the test passed // TPR_FAIL if the test fails // //////////////////////////////////////////////////////////////////////////////// TESTPROCAPI TestProc_IOCTL_API(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE) { int iTestResult = TPR_PASS; // The shell doesn't necessarily want us to execute the test. Make sure // first. if (uMsg != TPM_EXECUTE) { iTestResult = TPR_NOT_HANDLED; } // ============================================================== // Test KernelIoControl // ============================================================== if ( iTestResult == TPR_PASS ) { UINT32 inParams[8]; UINT32 outBuffer[8]; DWORD dwResult; LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT("Testing KernelIoControl API's")); // One valid call to ensure KernelIoControl callable inParams[0] = GPIO_CMD_GET_DIRECTION; inParams[1] = GPIO_TEST1; iTestResult = TestKernelIoControl(0, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_GET_DIRECTION"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32) * 2, &outBuffer, sizeof(UINT32), &dwResult); // Invalid parameters inParams[0] = 0; inParams[1] = GPIO_TEST1; outBuffer[0] = 0; if ( iTestResult != TPR_FAIL ) { iTestResult = TestKernelIoControl(1, TEXT("IOCTL_KERNELGPIO_COMMAND"), IOCTL_KERNELGPIO_COMMAND, NULL, 0, NULL, 0, NULL, FALSE); } if ( iTestResult != TPR_FAIL ) { iTestResult = TestKernelIoControl(2, TEXT("IOCTL_KERNELGPIO_COMMAND"), IOCTL_KERNELGPIO_COMMAND, inParams, 0, outBuffer, 0, NULL, FALSE); } if ( iTestResult != TPR_FAIL ) { iTestResult = TestKernelIoControl(3, TEXT("IOCTL_KERNELGPIO_COMMAND"), IOCTL_KERNELGPIO_COMMAND, NULL, 5, NULL, 5, NULL, FALSE); } if ( iTestResult != TPR_FAIL ) { iTestResult = TestKernelIoControl(4, TEXT("IOCTL_KERNELGPIO_COMMAND"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32), outBuffer, sizeof(UINT32), &dwResult, FALSE); } if ( iTestResult != TPR_FAIL ) { inParams[0] = GPIO_CMD_GET_DIRECTION; inParams[1] = GPIO_TEST1; outBuffer[0] = 0; iTestResult = TestKernelIoControl(5, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_GET_DIRECTION"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32), outBuffer, sizeof(UINT32), &dwResult, FALSE); } if ( iTestResult != TPR_FAIL ) { inParams[0] = GPIO_CMD_GET_DIRECTION; inParams[1] = GPIO_TEST1; outBuffer[0] = 0; iTestResult = TestKernelIoControl(6, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_GET_DIRECTION"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32)*3, outBuffer, sizeof(UINT32), &dwResult, FALSE); } if ( iTestResult != TPR_FAIL ) { inParams[0] = GPIO_CMD_GET_DIRECTION; inParams[1] = GPIO_TEST1; outBuffer[0] = 0; outBuffer[1] = 0; iTestResult = TestKernelIoControl(7, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_GET_DIRECTION"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32)*2, outBuffer, sizeof(UINT32)*2, &dwResult, FALSE); } if ( iTestResult != TPR_FAIL ) { inParams[0] = GPIO_CMD_SET_DIRECTION; inParams[1] = GPIO_TEST1; outBuffer[0] = 0; iTestResult = TestKernelIoControl(8, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_SET_DIRECTION"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32), outBuffer, sizeof(UINT32), &dwResult, FALSE); } if ( iTestResult != TPR_FAIL ) { inParams[0] = GPIO_CMD_SET_DIRECTION; inParams[1] = GPIO_TEST1; outBuffer[0] = 0; iTestResult = TestKernelIoControl(9, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_SET_DIRECTION"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32)*2, outBuffer, sizeof(UINT32), &dwResult, FALSE); } if ( iTestResult != TPR_FAIL ) { inParams[0] = GPIO_CMD_SET_DIRECTION; inParams[1] = GPIO_TEST1; outBuffer[0] = 0; iTestResult = TestKernelIoControl(10, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_SET_DIRECTION"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32)*4, outBuffer, sizeof(UINT32), &dwResult, FALSE); } if ( iTestResult != TPR_FAIL ) { inParams[0] = GPIO_CMD_GET_INPUT_STATE; inParams[1] = GPIO_TEST1; outBuffer[0] = 0; iTestResult = TestKernelIoControl(14, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_GET_INPUT_STATE"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32), outBuffer, sizeof(UINT32), &dwResult, FALSE); } if ( iTestResult != TPR_FAIL ) { inParams[0] = GPIO_CMD_GET_INPUT_STATE; inParams[1] = GPIO_TEST1; outBuffer[0] = 0; iTestResult = TestKernelIoControl(15, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_GET_INPUT_STATE"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32)*3, outBuffer, sizeof(UINT32), &dwResult, FALSE); } if ( iTestResult != TPR_FAIL ) { inParams[0] = GPIO_CMD_GET_INPUT_STATE; inParams[1] = GPIO_TEST1; outBuffer[0] = 0; iTestResult = TestKernelIoControl(16, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_GET_INPUT_STATE"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32)*2, outBuffer, sizeof(UINT32)*2, &dwResult, FALSE); } if ( iTestResult != TPR_FAIL ) { inParams[0] = GPIO_CMD_SET_OUTPUT_STATE; inParams[1] = GPIO_TEST1; outBuffer[0] = GPIO_STATE_LOW; iTestResult = TestKernelIoControl(17, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_SET_OUTPUT_STATE"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32), outBuffer, sizeof(UINT32), &dwResult, FALSE); } if ( iTestResult != TPR_FAIL ) { inParams[0] = GPIO_CMD_SET_OUTPUT_STATE; inParams[1] = GPIO_TEST1; outBuffer[0] = GPIO_STATE_HIGH; iTestResult = TestKernelIoControl(18, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_SET_OUTPUT_STATE"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32)*2, outBuffer, sizeof(UINT32), &dwResult, FALSE); } if ( iTestResult != TPR_FAIL ) { inParams[0] = GPIO_CMD_SET_OUTPUT_STATE; inParams[1] = GPIO_TEST1; outBuffer[0] = GPIO_STATE_HIGH; iTestResult = TestKernelIoControl(19, TEXT("IOCTL_KERNELGPIO_COMMAND - GPIO_CMD_SET_OUTPUT_STATE"), IOCTL_KERNELGPIO_COMMAND, inParams, sizeof(UINT32)*4, outBuffer, sizeof(UINT32), &dwResult, FALSE); } } return iTestResult; } //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // TestProc_API // Performs basic tests on the GPIO Inline API. // // Parameters: // uMsg Message code. // tpParam Additional message-dependent data. // lpFTE Function table entry that generated this call. // // Return value: // TPR_PASS if the test passed // TPR_FAIL if the test fails // TESTPROCAPI TestProc_Inline_API(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE) { int iTestResult = TPR_PASS; UINT32 pos; // The shell doesn't necessarily want us to execute the test. Make sure // first. if (uMsg != TPM_EXECUTE) { iTestResult = TPR_NOT_HANDLED; } // ============================================================== // Test GPIOSetDirection // ============================================================== if ( iTestResult == TPR_PASS ) { GPIO_DIRECTION newDirection; LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT("Testing GPIOSetDirection API's")); TestCurrentGpioCondition(GPIO_READ_ALL); pos = 0; while ( g_GpioTestData[pos].Name != NULL ) { LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT(" Testing %s GPIO line"), g_GpioTestData[pos].Name); // Change the direction newDirection = ( (g_GpioTestData[pos].Direction == GPIO_DIRECTION_OUTPUT) ? GPIO_DIRECTION_INPUT : GPIO_DIRECTION_OUTPUT ); if ( TestSetGpioDirection(g_GpioTestData[pos].Id, newDirection) == TPR_FAIL ) { iTestResult = TPR_FAIL; } // Make sure nothing else changed if ( TestCurrentGpioCondition(GPIO_VERIFY_ALL_BUT_ONE, g_GpioTestData[pos].Id) == TPR_FAIL ) { iTestResult = TPR_FAIL; } // Set it back to the original direction if ( TestSetGpioDirection(g_GpioTestData[pos].Id, g_GpioTestData[pos].Direction) == TPR_FAIL ) { iTestResult = TPR_FAIL; } pos++; } } // ============================================================== // Set line directions for subsequent tests // ============================================================== LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT("Setting GPIO line directions")); pos = 0; while ( g_GpioTestData[pos].Name != NULL ) { if ( TestSetGpioDirection(g_GpioTestData[pos].Id, (g_GpioTestData[pos].IsOutput ? GPIO_DIRECTION_OUTPUT : GPIO_DIRECTION_INPUT) ) != TPR_PASS ) { iTestResult = TPR_FAIL; } pos++; } // ============================================================== // Test GPIOSetOutputState // ============================================================== if ( iTestResult == TPR_PASS ) { GPIO_STATE newState; LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT("Testing GPIOSetOutputState API's")); // Save all the current settings for comparison TestCurrentGpioCondition(GPIO_READ_ALL); pos = 0; while ( g_GpioTestData[pos].Name != NULL ) { LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT(" Testing %s GPIO line"), g_GpioTestData[pos].Name); if ( g_GpioTestData[pos].IsOutput ) { // Change the state newState = ( (g_GpioTestData[pos].State == GPIO_STATE_LOW) ? GPIO_STATE_HIGH : GPIO_STATE_LOW ); if ( TestSetGpioState(g_GpioTestData[pos].Id, newState) == TPR_FAIL ) { iTestResult = TPR_FAIL; } } // Make sure nothing else changed if ( TestCurrentGpioCondition(GPIO_VERIFY_ALL_BUT_ONE, g_GpioTestData[pos].Id) == TPR_FAIL ) { iTestResult = TPR_FAIL; } // Set it back to the original state if ( g_GpioTestData[pos].IsOutput ) { if ( TestSetGpioState(g_GpioTestData[pos].Id, g_GpioTestData[pos].State) == TPR_FAIL ) { iTestResult = TPR_FAIL; } } pos++; } } return iTestResult; } //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // TestProc_ReadWrite // Tests that GPIO lines can be acessed correctly. // // Parameters: // uMsg Message code. // tpParam Additional message-dependent data. // lpFTE Function table entry that generated this call. // // Return value: // TPR_PASS if the test passed // TPR_FAIL if the test fails // TESTPROCAPI TestProc_ReadWrite(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE) { int status = TPR_PASS; LPTPS_EXECUTE tExecute = (LPTPS_EXECUTE)tpParam; UINT32 pos; GPIO_TEST_DATA *pTestData; DWORD dwTmp; DWORD dwPeriod; DWORD dwDuration; if ( uMsg != TPM_EXECUTE ) { status = TPR_NOT_HANDLED; } else { // Make a different toggle period for time run dwPeriod = (DWORD)tpParam; dwPeriod ^= tExecute->dwRandomSeed; dwPeriod %= 150; dwPeriod += 500; LogResult(LOG_DETAIL, LOGTYPE_NONE, TEXT("")); LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT("Manually verify that the following actions occured")); LogResult(LOG_DETAIL, LOGTYPE_NONE, TEXT("")); Sleep(2000); // Turn all outputs off LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT("Turning off all known outputs")); pos = 0; while ( g_GpioTestData[pos].Name != NULL ) { pTestData = &g_GpioTestData[pos]; if ( pTestData->IsOutput ) { if ( TestSetGpioState(pTestData->Id, GPIO_STATE_LOW) == TPR_FAIL ) { status = TPR_FAIL; } } pos++; } // Toggle each output LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT("Toggling all known outputs sequentially")); pos = 0; while ( g_GpioTestData[pos].Name != NULL ) { pTestData = &g_GpioTestData[pos]; if ( pTestData->IsOutput ) { dwTmp = 4000; // 4 seconds for each dwDuration = dwTmp / (dwPeriod * 2); // toggle period LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT(" %s GPIO for %d seconds"), pTestData->Name, (dwTmp / 1000)); if ( TestToggleGpio(pos+1, pTestData->Id, dwDuration, dwPeriod) == TPR_FAIL ) { status = TPR_FAIL; } } pos++; } // Toggle all outputs on/off LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT("Toggling all known outputs 3 times at same time")); for (dwTmp = 0; dwTmp < 3; dwTmp++) { pos = 0; while ( g_GpioTestData[pos].Name != NULL ) { pTestData = &g_GpioTestData[pos]; if ( pTestData->IsOutput ) { if ( TestSetGpioState(pTestData->Id, GPIO_STATE_HIGH) == TPR_FAIL ) { status = TPR_FAIL; } } pos++; } Sleep(dwPeriod); pos = 0; while ( g_GpioTestData[pos].Name != NULL ) { pTestData = &g_GpioTestData[pos]; if ( pTestData->IsOutput ) { if ( TestSetGpioState(pTestData->Id, GPIO_STATE_LOW) == TPR_FAIL ) { status = TPR_FAIL; } } pos++; } Sleep(dwPeriod); } } return status; } //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // TestProc_MultiThread // Tests that a IO lines can be acessed correctly. // // Parameters: // uMsg Message code. // tpParam Additional message-dependent data. // lpFTE Function table entry that generated this call. // // Return value: // TPR_PASS if the test passed // TPR_FAIL if the test fails // TESTPROCAPI TestProc_MultiThread(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE) { int status = TPR_PASS; LPTPS_EXECUTE tExecute = (LPTPS_EXECUTE)tpParam; UINT32 uNumTestCases; GPIO_TEST_DATA *pTestData; DWORD dwTmp; // Calculate the number of test to perform at the same time uNumTestCases = 0; while ( g_GpioTestData[uNumTestCases].Name != NULL ) { uNumTestCases++; } // See what the shell want us to do if ( uMsg == TPM_QUERY_THREAD_COUNT ) { LPTPS_QUERY_THREAD_COUNT tCount; tCount = (LPTPS_QUERY_THREAD_COUNT)tpParam; // One test thread per GPIO we know about tCount->dwThreadCount = uNumTestCases; status = TPR_HANDLED; } else if ( uMsg != TPM_EXECUTE ) { status = TPR_NOT_HANDLED; } else if ( (tExecute->dwThreadNumber) < 1 || (tExecute->dwThreadNumber > uNumTestCases) ) { // We got an invalid thread number LogResult(LOG_FAIL, LOGTYPE_ERROR, TEXT("Invalid thread number %d found"), tExecute->dwThreadNumber); status = TPR_FAIL; } else { if ( tExecute->dwThreadNumber == 1 ) { LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT("Testing all known outputs concurrently (low speed)")); } // The thread number will be the index into the test table pTestData = &g_GpioTestData[tExecute->dwThreadNumber-1]; if ( pTestData->IsOutput ) { DWORD dwPeriod; DWORD dwDuration; // Create a different pause before starting each test dwTmp = (DWORD)tpParam; dwTmp ^= tExecute->dwRandomSeed; dwTmp += tExecute->dwThreadNumber; Sleep(500 + (dwTmp %= 250)); // Make a different toggle period for each line dwTmp = 15000; // 15 seconds dwPeriod = 200 + (tExecute->dwThreadNumber * 5); dwDuration = dwTmp / (dwPeriod * 2); // Test its own output LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT(" Thread %d toggling %s GPIO for %d seconds at %dmS toggle rate"), tExecute->dwThreadNumber, pTestData->Name, (dwTmp / 1000), dwPeriod); if ( TestToggleGpio(tExecute->dwThreadNumber, pTestData->Id, dwDuration, dwPeriod) == TPR_FAIL ) { status = TPR_FAIL; } // Then everyone test the same output LogResult(LOG_DETAIL, LOGTYPE_INFO, TEXT(" Thread %d toggling GPIO_TEST1 GPIO for %d seconds at %dmS toggle rate"), tExecute->dwThreadNumber, (dwTmp / 1000), dwPeriod); if ( TestToggleGpio(tExecute->dwThreadNumber, GPIO_TEST1, dwDuration, dwPeriod) == TPR_FAIL ) { status = TPR_FAIL; } } } return status; } ////////////////////////////////////////////////////////////////////////////////
    Wednesday, July 14, 2010 12:29 PM

All replies

  • Vinoth:

    Quit creating new threads to discuss this issue.  You now have three going which is difficult to follow and respond.

    What is this mess that you posted here?  Do you have the license to post this publicly?


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com
    Wednesday, July 14, 2010 12:35 PM
    Moderator
  • sorry am not creating when i try to post that code in the reply its not adding so i started dis . am want to tell wat i ve done

     

    1. i ve a gpiotest.cpp i added the main function to that and i executed as a exe file.

    2.i copied tat .exe to the pendrive and run on the omapL138 kit when i try to run tat exe am getting dat mess in the o/p window.

     

    Wednesday, July 14, 2010 12:41 PM