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

📄 pcmciapower.c

📁 收集到的orion_ep93xx_wince_bsp_1-3-507 pcmcia卡驱动源码,未作测试
💻 C
字号:
//**********************************************************************
//                                                                      
// Filename: pcmciapower.c
//                                                                      
// Description: Routine to set the voltage on the PCMCIA card.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Use of this source code is subject to the terms of the Cirrus 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) Cirrus Logic Corporation 2002, All Rights Reserved                       
//                                                                      
//**********************************************************************
#include <windows.h>
#include <hwdefs.h>


static unsigned char Vcc  = 0;
static unsigned char Vpp1 = 0;
static unsigned char Vpp2 = 0;

#define ERROR_POWERPCCARD_INVALID_PARMS 1
#define ERROR_POWERPCCARD_TIMEOUT       2

//
// Definitions to program the TPS2202A PCMCIA controller.
//
#define     AVPP_0V         0x000
#define     AVPP_VCC        0x002
#define     AVPP_12V        0x001
#define     BVPP_0V         0x000
#define     BVPP_VCC        0x020
#define     BVPP_12V        0x010
#define     AVCC_0V         0x000
#define     AVCC_33V        0x004
#define     AVCC_5V         0x008
#define     BVCC_0V         0x000
#define     BVCC_33V        0x080
#define     BVCC_5V         0x040
#define     ENABLE          0x100
#define     EE_ADDRESS      (0x55<<9)

//
// The propagation delay of the EP931x board.  
// Don't know what this number is.  This number is probably high right now.
//
#define PCMCIA_BOARD_DELAY          40

//****************************************************************************
// DelayuS
//****************************************************************************
// Delays a certian number of microseconds.
// 
//
static void DelayInuSec(ULONG ulMicroSec)
{
    LARGE_INTEGER liStart, liCurrent;
    BOOL b;
    b = QueryPerformanceCounter(&liStart);
    ASSERT(b);
    
    do
    {
        Sleep(0);
        b = QueryPerformanceCounter(&liCurrent);
        ASSERT(b);
    } while((liStart.QuadPart + (LONGLONG)ulMicroSec) >=liCurrent.QuadPart);
}



//****************************************************************************
// PowerPCCardWrite
//****************************************************************************
// Sets the voltage levels to the PCMCIA cards.
// 
//
unsigned char PowerPCCardWrite
(
  unsigned char vccOut,
  unsigned char vpp1Out
)
{    
    unsigned char   retVal = 0;    // 0 = G_SUCCESS
    ULONG           ulSwitchSettings;
    int             i;
    
    ulSwitchSettings = EE_ADDRESS |ENABLE | BVPP_0V | BVCC_0V ;
    

    //
    // Set up VCC A and B.  This way we can set 
    // the battery volatage to anything.
    //
    switch( vccOut)
    {
        case 0:
            ulSwitchSettings |= AVCC_0V;
            break;

        case 33:
            ulSwitchSettings |= AVCC_33V;
            break;

        case 50:
            ulSwitchSettings |= AVCC_5V;
            break;

        default:
            return (ERROR_POWERPCCARD_INVALID_PARMS);
    }

    //
    // Set up the battery voltage vpp1.
    //
    if(vpp1Out == 0)
    {
        ulSwitchSettings |= AVPP_0V;
    }
    else if(vpp1Out == 120)
    {
        ulSwitchSettings |= AVPP_12V;
    }
    else if(vpp1Out == vccOut)
    {
        ulSwitchSettings |= AVPP_VCC;
    }
    else
    {
        return (ERROR_POWERPCCARD_INVALID_PARMS);
    }
    

    //
    // Update these variables while processing
    //
    Vcc = vccOut;      
    Vpp1 = vpp1Out;
    Vpp2 = 0;             


    //
    // TODO - Put I2C mutex here.
    //

    //
    // Turn on the power to the socket !!!
    //
    //  EECLK  -> Clock
    //  EEDATA -> Data
    //  SLA0   -> Latch
    //*EEPROM_CONFIG   =  CONFIG_S0DIR;
    //Sleep(20);
    //*EEPROM_CONFIG   =  CONFIG_S0DIR | CONFIG_DDIR | CONFIG_CDIR ;
    *GPIO_PGDDR         =  GPIOG_EECLK | GPIOG_EEDAT | GPIOG_SLA0;
 
    
    //
    // Clear all except EECLK
    // 
    //*EEPROM_DATA     = DATA_EECLK;
    *GPIO_PGDR          = GPIOG_EECLK;

    //
    // Raise the clock.
    //    
    DelayInuSec(50);
    //*EEPROM_DATA     = 0;
    *GPIO_PGDR          = 0;
    DelayInuSec(50);

    for (i=18; i>=0; --i)
    //for (i=9; i>=0; --i)
    {
        if((ulSwitchSettings >> i) & 1)
        {
            //
            // Put the data on the bus and lower the clock.
            //
            *GPIO_PGDR = GPIOG_EEDAT ;
            DelayInuSec(50);
        
            //
            // Raise the clock to latch the data in.
            //
            //*EEPROM_DATA    = DATA_EECLK | DATA_EEDAT;
            *GPIO_PGDR       = GPIOG_EECLK | GPIOG_EEDAT;
            DelayInuSec(50);

            //
            // Lower the clock again.
            //        
            //*EEPROM_DATA     = DATA_EEDAT;
            *GPIO_PGDR        = GPIOG_EEDAT;
            DelayInuSec(50);
        }
        else            
        {
            //
            // Put the data on the bus and lower the clock.
            //
            //*EEPROM_DATA    = 0 ;
            *GPIO_PGDR       = 0;
            DelayInuSec(50);
        
            //
            // Raise the clock to latch the data in.
            //
            //*EEPROM_DATA     = DATA_EECLK ;
            *GPIO_PGDR       = GPIOG_EECLK ;
            DelayInuSec(50);

            //
            // Lower the clock again.
            //        
            //*EEPROM_DATA     = 0;
            *GPIO_PGDR       = 0 ;
            DelayInuSec(50);
        }                    
    }
        
    //
    // Raise and lower the Latch.
    //
    *GPIO_PGDR       = GPIOG_SLA0;
    DelayInuSec(50);

    *GPIO_PGDR       = 0;
    *GPIO_PGDR       = GPIOG_EECLK;
    DelayInuSec(50);
    *GPIO_PGDR       = GPIOG_EECLK| GPIOG_EEDAT;
    DelayInuSec(50);
    
    //
    // Change the configuration back to zero.
    // This will cause the PCMCIA interface to reset.
    //
    //*EEPROM_CONFIG  = CONFIG_S0DIR;

    return(retVal);
}

⌨️ 快捷键说明

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