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

📄 test.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
字号:
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//-----------------------------------------------------------------------------
//
//  Copyright (C) 2004, Freescale Semiconductor, Inc. All Rights Reserved
//  THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
//  BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
//  Freescale Semiconductor, Inc.
//
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//
//  File:  test.cpp
//
//  This file contains test code for the One-wire driver
//
//
//-----------------------------------------------------------------------------

#include <windows.h>
#include <Devload.h>
#include <ceddk.h>
#include "owire.h"
#include "csp.h"
#include "main.h"
#include "globals.h"

//-----------------------------------------------------------------------------
// External Functions

//-----------------------------------------------------------------------------
// External Variables
extern HANDLE hOwire;

//-----------------------------------------------------------------------------
// Defines
#define OWIRE_ZONE_INFO                  0
#define OWIRE_ZONE_ERROR                 0

//-----------------------------------------------------------------------------
// Types

//-----------------------------------------------------------------------------
// Global Variables

//-----------------------------------------------------------------------------
// Local Functions

//-----------------------------------------------------------------------------
// Local Variables


//------------------------------------------------------------------------------
//
// Function: CheckBytesRead
//
// This function compares a buffer of bytes read from the OWIRE
// to a buffer containing the expected result values, and returns
// an error if the values do not match up.  This method also
// outputs the bytes read and bytes expected.
//
// Parameters:
//      readBuf
//           [in] pointer to buffer containing bytes read.
//
//      checkBuf
//           [in] pointer to buffer containing expected result.
//
//      bytes
//           [in] number of bytes to compare.
//
// Returns:
//      TPR_PASS if the compared buffers are identical
//      TPR_FAIL if the compared buffers do not match up
//
//------------------------------------------------------------------------------
DWORD CheckBytesRead(BYTE* readBuf, BYTE* checkBuf, UINT32 bytes)
{
    UINT32 i;
    DWORD ret = TPR_PASS;

    for (i = 0; i < bytes; i++)
    {
        g_pKato->Log(OWIRE_ZONE_INFO, TEXT("Byte #%x read: %x, Correct Byte: %x\r\n"), i, readBuf[i], checkBuf[i]);
        if (readBuf[i] != checkBuf[i])
        {
            g_pKato->Log(OWIRE_ZONE_ERROR, TEXT("Read wrong byte!\r\n"));
            ret = TPR_FAIL;
        }
    }

    return ret;
}

//------------------------------------------------------------------------------
//
// Function: OwireResetTest
//
// This function tests the OWIRE software reset.
//
// Parameters:
//      uiMsg
//           [in] Ignored.
//
//      tpParam
//           [in] Ignored.
//
//      lpFTE
//           [in] Ignored.
//
// Returns:
//      Specifies if the test passed (TPR_PASS), failed (TPR_FAIL), or was
//      skipped (TPR_SKIP).
//
//------------------------------------------------------------------------------
TESTPROCAPI OwireResetTest(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
    // Validate that the shell wants the test to run
    if (uMsg != TPM_EXECUTE)
    {
        return TPR_NOT_HANDLED;
    }

    // issue the IOCTL to reset OWIRE
    if (!OwireReset(hOwire))
    {
        g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireResetTest: OwireReset failed!\r\n")));
        return TPR_FAIL;
    }

    g_pKato->Log(LOG_COMMENT, TEXT("OwireResetTest completed."));

    return TPR_PASS;
}

//------------------------------------------------------------------------------
//
// Function: OwireReadStatusTest
//
// This function attempts to perform a ReadStatus on the
// DS2502 module through the one-wire interface.
//
// Parameters:
//      uiMsg
//           [in] Ignored.
//
//      tpParam
//           [in] Ignored.
//
//      lpFTE
//           [in] Ignored.
//
// Returns:
//      Specifies if the test passed (TPR_PASS), failed (TPR_FAIL), or was
//      skipped (TPR_SKIP).
//
//------------------------------------------------------------------------------
TESTPROCAPI OwireReadStatusTest(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{

    BYTE readBuffer[8];
    BYTE writeBuffer[2] = {0x33, 0x00};
    BYTE compareBuffer[1] = {0x23};
    DWORD ret, SerialNum_Byte;

    // Validate that the shell wants the test to run
    if (uMsg != TPM_EXECUTE)
    {
        return TPR_NOT_HANDLED;
    }

    // Read status sequence - 0x33 0x00
    if (!OwireResetPresencePulse(hOwire))
    {
        g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireReadStatusTest: OwireResetPresencePulse() failed!\r\n")));
        return TPR_FAIL;
    }
    if (!OwireWrite(hOwire, writeBuffer, 1))
    {
        g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireReadStatusTest: OwireWrite() failed!\r\n")));
        return TPR_FAIL;
    }
    if (!OwireRead(hOwire, readBuffer, 8))
    {
        g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireReadStatusTest: OwireRead() failed!\r\n")));
        return TPR_FAIL;
    }
	g_pKato->Log(1,TEXT("Family code is : %X\r\n "),readBuffer[0]);
    ret = CheckBytesRead(readBuffer, compareBuffer, 1);
    
    if (ret == TPR_FAIL)
    {
        g_pKato->Log(1,(TEXT("Family code does not match\r\n")));
    }
    else
    {
        g_pKato->Log(1,TEXT("Family code is : %X\r\n "),readBuffer[0]);
    }
    
    g_pKato->Log(1,TEXT("Unique Serial Number:"));
    
    for (SerialNum_Byte = 1; SerialNum_Byte < 7; SerialNum_Byte++)
        g_pKato->Log(1,TEXT("%X"),readBuffer[SerialNum_Byte]);
    
    g_pKato->Log(1,TEXT("\nCRC Code: %X\r\n"),readBuffer[7]);

    g_pKato->Log(LOG_COMMENT, TEXT("OwireReadStatusTest completed."));

    return ret; 

}

//------------------------------------------------------------------------------
//
// Function: OwireReadWriteMemTest
//
// This function attempts to perform a WriteMem on the
// DS2433 module through the one-wire interface.
//
// Parameters:
//      uiMsg
//           [in] Ignored.
//
//      tpParam
//           [in] Ignored.
//
//      lpFTE
//           [in] Ignored.
//
// Returns:
//      Specifies if the test passed (TPR_PASS), failed (TPR_FAIL), or was
//      skipped (TPR_SKIP).
//
//------------------------------------------------------------------------------
TESTPROCAPI OwireReadWriteMemTest(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
    BYTE readBuffer[5];
    BYTE writeBuffer1[6] = {0xCC, 0x0F, 0x10, 0x00, 0x0c, 0xAB}; // write to scratchpad
	BYTE writeBuffer2[2] = {0xCC, 0xAA}; // read scratchpad
	BYTE writeBuffer3[5] = {0xCC, 0x55, 0x10, 0x00,0x00}; //copy scratchpad to memory
	BYTE writeBuffer4[4] = {0xCC, 0xF0, 0x10, 0x00};  // read memory
	BYTE compareBuffer[2] = {0x0c, 0xAB};  //data written for comaparison
    DWORD ret;

    // Validate that the shell wants the test to run
    if (uMsg != TPM_EXECUTE)
    {
        return TPR_NOT_HANDLED;
    }

	// Write Mem Sequence - 0x0c, 0xAB
    if (!OwireResetPresencePulse(hOwire))
    {
        g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireWriteMemTest: OwireResetPresencePulse() failed!\r\n")));
        return TPR_FAIL;
    }
    if (!OwireWrite(hOwire, writeBuffer1, 6))
    {
        g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireWriteMemTest: OwireWrite() failed!\r\n")));
        return TPR_FAIL;
    }
	Sleep(500);		
    if (!OwireResetPresencePulse(hOwire))
    {
        g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireWriteMemTest: OwireResetPresencePulse() failed!\r\n")));
        return TPR_FAIL;
    }

    if (!OwireWrite(hOwire, writeBuffer2, 2))
    {
        g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireWriteMemTest: OwireWrite() failed!\r\n")));
        return TPR_FAIL;
    }
    
	if (!OwireRead(hOwire, readBuffer, 5))
    {
        g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireWriteMemTest: OwireRead() failed!\r\n")));
        return TPR_FAIL;
    }
    if (CheckBytesRead(&readBuffer[3], compareBuffer, 2) == TPR_FAIL)
    {
		g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireWriteMemTest: CheckBytesRead() failed!\r\n")));
        return TPR_FAIL;
    }
	
	writeBuffer3[4] = readBuffer[2];

	Sleep(500);		

	if (!OwireResetPresencePulse(hOwire))
    {
        g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireWriteMemTest: OwireResetPresencePulse() failed!\r\n")));
        return TPR_FAIL;
    }

    if (!OwireWrite(hOwire, writeBuffer3, 5))
    {
        g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireWriteMemTest: OwireWrite() failed!\r\n")));
        return TPR_FAIL;
    }

	Sleep(500);		

	// Read Mem Sequence - 0x0c, 0xAB

	if (!OwireResetPresencePulse(hOwire))
    {
        g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireWriteMemTest: OwireResetPresencePulse() failed!\r\n")));
        return TPR_FAIL;
    }

    if (!OwireWrite(hOwire, writeBuffer4, 4))
    {
        g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireWriteMemTest: OwireWrite failed!\r\n")));
        return TPR_FAIL;
    }
    if (!OwireRead(hOwire, readBuffer, 2))
    {
        g_pKato->Log(OWIRE_ZONE_ERROR,
            (TEXT("OwireWriteMemTest: OwireRead failed!\r\n")));
        return TPR_FAIL;
    }
    ret = CheckBytesRead(readBuffer, compareBuffer, 2);

    g_pKato->Log(LOG_COMMENT, TEXT("OwireWriteMemTest completed."));

    return ret;
}


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

⌨️ 快捷键说明

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