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

📄 adc_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, 2006, 2007, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//------------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//
//  File:  adc_test.cpp
//
//  This file contains test code for the ADC SDK APIs
//
//------------------------------------------------------------------------------
#pragma warning(push)
#pragma warning(disable: 4115)
#pragma warning(disable: 4201)
#pragma warning(disable: 4204)
#pragma warning(disable: 4214)
#include <windows.h>
#pragma warning(pop)
#include <Devload.h>
#include<Winbase.h>

#include <ceddk.h>
#include "main.h"
#include "globals.h"
#include "pmic_lla.h"
#include "pmic_regulator.h"

#include "csp.h"
#include "pmic_adc.h"
#include "regs_adc.h"

#include "pmic_battery.h"
#include "test.h"


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


//-----------------------------------------------------------------------------
// External Variables

//-----------------------------------------------------------------------------
// Defines
#define GPT_ZONE_INFO                  0
#define GPT_ZONE_ERROR                 0
#define GPT_ZONE_FUNCTION              0

#define GPT_TEST_FUNCTION_ENTRY() \
    g_pKato->Log(GPT_ZONE_FUNCTION, (TEXT("++%s\r\n"), __WFUNCTION__))
#define GPT_TEST_FUNCTION_EXIT() \
    g_pKato->Log(GPT_ZONE_FUNCTION, (TEXT("--%s\r\n"), __WFUNCTION__))

#define GPT_EVENT_NAME                   L"GptTest1"
#define THREAD_PRIORITY                  250
//-----------------------------------------------------------------------------
// Types

//-----------------------------------------------------------------------------
// Global Variables
UINT16 AdcTestChannels[16] =
{
    CSP_BITFMASK(MC13783_ADC_BATT),
    CSP_BITFMASK(MC13783_ADC_BATTISNS),
    CSP_BITFMASK(MC13783_ADC_BPSNS),
    CSP_BITFMASK(MC13783_ADC_CHRGRAW),
    CSP_BITFMASK(MC13783_ADC_CHRGISNS),
    CSP_BITFMASK(MC13783_ADC_RTHEN),
    CSP_BITFMASK(MC13783_ADC_LICELL),
    CSP_BITFMASK(MC13783_ADC_DTHEN),
    CSP_BITFMASK(MC13783_ADC_ADIN8),
    CSP_BITFMASK(MC13783_ADC_ADIN9),
    CSP_BITFMASK(MC13783_ADC_ADIN10),
    CSP_BITFMASK(MC13783_ADC_ADIN11),
    CSP_BITFMASK(MC13783_ADC_TSX1),
    CSP_BITFMASK(MC13783_ADC_TSX2),
    CSP_BITFMASK(MC13783_ADC_TSY1),
    CSP_BITFMASK(MC13783_ADC_TSY2)
};

WCHAR* AdcTestChannelNames[16] =
{
    TEXT("MC13783_ADC_BATT"),
    TEXT("MC13783_ADC_BATTISNS"),
    TEXT("MC13783_ADC_BPSNS"),
    TEXT("MC13783_ADC_CHRGRAW"),
    TEXT("MC13783_ADC_CHRGISNS"),
    TEXT("MC13783_ADC_RTHEN"),
    TEXT("MC13783_ADC_LICELL"),
    TEXT("MC13783_ADC_DTHEN"),
    TEXT("MC13783_ADC_ADIN8"),
    TEXT("MC13783_ADC_ADIN9"),
    TEXT("MC13783_ADC_ADIN10"),
    TEXT("MC13783_ADC_ADIN11"),
    TEXT("MC13783_ADC_TSX1"),
    TEXT("MC13783_ADC_TSX2"),
    TEXT("MC13783_ADC_TSY1"),
    TEXT("MC13783_ADC_TSY2"),
};
//-----------------------------------------------------------------------------
// Local Variables

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

//------------------------------------------------------------------------------
//
// Function: PMICAdcGetOneSample
//
// This function attempts to test PMIC Low-level APIs for read/write registers
//
// 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 PMICAdcGetOneSample(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
    UINT16 channel; 
    UINT16 result[16];
    int i;

    UNREFERENCED_PARAMETER(tpParam);
    UNREFERENCED_PARAMETER(lpFTE);

    memset(result, '\0', 16);
    
    // Validate that the shell wants the test to run
    if (uMsg != TPM_EXECUTE)
    {
        return TPR_NOT_HANDLED;
    }

    g_pKato->Log(LOG_COMMENT, TEXT("ADC -- PMICAdcGetOneSample() +\r\n"));

    // Read one sample for all channels, one channel at a time.
    for (i = 0; i < 16; i++)
    {
        channel = AdcTestChannels[i];//CSP_BITFMASK(MC13783_ADC_BATT);
        PmicADCGetSingleChannelOneSample(channel, &result[0]);
        g_pKato->Log(LOG_COMMENT, TEXT("%s Sample result is 0X%X\r\n"), AdcTestChannelNames[i], result[0]);
    }
   
    GPT_TEST_FUNCTION_EXIT();

    return TPR_PASS;
}


//------------------------------------------------------------------------------
//
// Function: PMICAdcGet8Samples
//
// This function attempts to test PMIC Low-level APIs for read/write registers
//
// 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 PMICAdcGet8Samples(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
    UINT16 channel; 
    UINT16 result[16];
    int i;

    UNREFERENCED_PARAMETER(tpParam);
    UNREFERENCED_PARAMETER(lpFTE);

    memset(result, '\0', 16);
    
    // Validate that the shell wants the test to run
    if (uMsg != TPM_EXECUTE)
    {
        return TPR_NOT_HANDLED;
    }

    g_pKato->Log(LOG_COMMENT, TEXT("ADC -- PMICAdcGet8Samples() +\r\n"));

    // Read eight samples for all channels, one channel at a time.
    for (i = 0; i < 16; i++)
    {
        channel = AdcTestChannels[i];//CSP_BITFMASK(MC13783_ADC_BATT);
        PmicADCGetSingleChannelEightSamples(channel, result);
        g_pKato->Log(LOG_COMMENT, 
            TEXT("%s Sample result is 0X%X 0X%X 0X%X 0X%X 0X%X 0X%X 0X%X 0X%X\r\n"), AdcTestChannelNames[i], 
            result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7]);
    }
   
    GPT_TEST_FUNCTION_EXIT();

    return TPR_PASS;
}

//------------------------------------------------------------------------------
//
// Function: PMICAdcGetMultiChannelSamples
//
// This function attempts to test PMIC Low-level APIs for read/write registers
//
// 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 PMICAdcGetMultiChannelSamples(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
    UINT16 channel; 
    UINT16 result[16];
    int i;

    UNREFERENCED_PARAMETER(tpParam);
    UNREFERENCED_PARAMETER(lpFTE);

    memset(result, '\0', 16);
    
    // Validate that the shell wants the test to run
    if (uMsg != TPM_EXECUTE)
    {
        return TPR_NOT_HANDLED;
    }

    g_pKato->Log(LOG_COMMENT, TEXT("ADC -- PMICAdcGetMultiChannelSamples() +\r\n"));


    channel = 0;
    for (i = 0; i < 16; i++)
    {
        channel |= AdcTestChannels[i];
    }

    // Read one sample for all channels.
    PmicADCGetMultipleChannelsSamples(channel, result);
    for (i = 0; i < 16; i++)
    {
        g_pKato->Log(LOG_COMMENT, 
            TEXT("%s Sample result is 0X%X\r\n"), AdcTestChannelNames[i], result[i]);
    }
   
    GPT_TEST_FUNCTION_EXIT();

    return TPR_PASS;
}

//------------------------------------------------------------------------------
//
// Function: PMICAdcGetHandsetCurrent
//
// This function attempts to test PMIC Low-level APIs for read/write registers
//
// 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 PMICAdcGetHandsetCurrent(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
    UINT16 result[16];

    UNREFERENCED_PARAMETER(tpParam);
    UNREFERENCED_PARAMETER(lpFTE);

    memset(result, '\0', 16);
    
    // Validate that the shell wants the test to run
    if (uMsg != TPM_EXECUTE)
    {
        return TPR_NOT_HANDLED;
    }

    g_pKato->Log(LOG_COMMENT, TEXT("ADC -- PMICAdcGetHandsetCurrent() +\r\n"));

    // Get one sample value of handset current
    g_pKato->Log(LOG_COMMENT, TEXT("Get one value....."));
    PmicADCGetHandsetCurrent(ADC_8CHAN_1X, result);
    g_pKato->Log(LOG_COMMENT, TEXT("0x%x \r\n"), result[0]);

    // Get eight sample values of handset current
    g_pKato->Log(LOG_COMMENT, TEXT("Get eight values...."));
    PmicADCGetHandsetCurrent(ADC_1CHAN_8X, result);
    g_pKato->Log(LOG_COMMENT, TEXT("0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\r\n"), 
        result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7]);

    GPT_TEST_FUNCTION_EXIT();

    return TPR_PASS;
}

//------------------------------------------------------------------------------
//
// Function: PMICAdcTouchRead
//
// This function attempts to test PMIC Low-level APIs for read/write registers
//
// 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 PMICAdcTouchRead(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
    UINT16 x[3], y[3];

    UNREFERENCED_PARAMETER(tpParam);
    UNREFERENCED_PARAMETER(lpFTE);

    //memset(result, '\0', 16);
    
    // Validate that the shell wants the test to run
    if (uMsg != TPM_EXECUTE)
    {
        return TPR_NOT_HANDLED;
    }

    g_pKato->Log(LOG_COMMENT, TEXT("ADC -- PMICAdcTouchRead() +\r\n"));

    // Get 3 pairs of coordinates
    PmicADCTouchRead(x, y);
    
    g_pKato->Log(LOG_COMMENT, 
        TEXT("Read the values: (0x%x, 0x%x), (0x%x, 0x%x), (0x%x, 0x%x)\r\n"),
        x[0], y[0], x[1], y[1], x[2], y[2]);

    if (PmicADCTouchStandby(true) != PMIC_SUCCESS)
    {
        ERRORMSG(1, (_T("PmicTouchStandby failed\r\n")));
    }

    // Make sure pen down interrupt are unmasked
    if (PmicInterruptHandlingComplete(PMIC_MC13783_INT_TSI) != PMIC_SUCCESS)
    {
        ERRORMSG(1, (_T("PmicInterruptHandlingComplete failed\r\n")));
    }


    GPT_TEST_FUNCTION_EXIT();

    return TPR_PASS;
}

//------------------------------------------------------------------------------
//
// Function: PMICAdcToogleTouchStdby
//
// This function attempts to test PMIC Low-level APIs for read/write registers
//
// 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 PMICAdcToogleTouchStdby(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
    static int i = 0;

    UNREFERENCED_PARAMETER(tpParam);
    UNREFERENCED_PARAMETER(lpFTE);

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

    g_pKato->Log(LOG_COMMENT, TEXT("ADC -- PMICAdcToogleTouchStdby() +\r\n"));

    // if 0, Inactivate
    if (i == 0)
    {
        g_pKato->Log(LOG_COMMENT, TEXT("Setting to inactive\r\n"));
        PmicADCTouchStandby(FALSE); // set inactive
        i = 1;
    }
    else
    {
        g_pKato->Log(LOG_COMMENT, TEXT("Setting to interrupt\r\n"));
        PmicADCTouchStandby(TRUE); // set interrupt
        i = 0;
    }

    // To be fixed: As of now, this test case does not work as expected. 
    // (toggling logic does not work as static int i gets initialized again and again to 0,
    // since DLL gets loaded again and again for every run of the test)
    // It always sets the Standby mode to Inactive.
    GPT_TEST_FUNCTION_EXIT();

    return TPR_PASS;
}

⌨️ 快捷键说明

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