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

📄 window.c

📁 收集到的orion_ep93xx_wince_bsp_1-3-507 pcmcia卡驱动源码,未作测试
💻 C
📖 第 1 页 / 共 2 页
字号:
//**********************************************************************
//                                                                      
// Filename: window.c
//                                                                      
// Description: Gets/Sets the windows paramaters for attribute, common
//              and I/O memory.
//
// 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 <types.h>
#include <cardserv.h>
#include <sockserv.h>
#include <sockpd.h>
#include <hwdefs.h>
#include <clocks.h>


//
// Set the Minimum windows size and grainularity to 4096
//
#define MIN_WIN_SIZE    4096
#define MIN_WIN_GRAN    4096


//
// Current state of the memory and I/O windows.  This is how the windows are initially configured
// at startup.  Note that some parameters either WILL or COULD be altered by PDCardInitServices().
//
PDCARD_WINDOW_STATE v_WinState[PCMCIA_NUM_WINDOWS] = 
{
    {   // Window 0 - common memory
        0,                                                          // Socket number to which this window is mappped
        WIN_STATE_ENABLED,                                          // Bit encoded window state (could be updated by PDCardInitServices())
        0,                                                          // Bit encoded access speed (will be updated by PDCardInitServices())
        PCMCIACARD_MEMORY_SIZE,                                     // Size of window
        PCMCIACARD_MEMORY_PHYSICAL,                                 // Physical address of beginning of window
        0                                                           // Offset in PC card memory
    },
    {   // Window 1 - 8 bit I/O
        0,                                                          // Socket number to which this window is mappped
        WIN_STATE_ENABLED|WIN_STATE_MAPS_IO,                        // Bit encoded window state (could, but shouldn't be updated by PDCardInitServices())
        0,                                                          // Bit encoded access speed (will be updated by PDCardInitServices())
        PCMCIACARD_IO_SIZE,                                         // Size of window
        PCMCIACARD_IO_PHYSICAL,                                     // Physical address of beginning of window
        0                                                           // Offset in PC card memory
    },
    {   // Window 2 - attribute memory
        0,                                                          // Socket number to which this window is mappped
        WIN_STATE_ENABLED|WIN_STATE_ATTRIBUTE,                      // Bit encoded window state (could be updated by PDCardInitServices())
        0,                                                          // Bit encoded access speed (will be updated by PDCardInitServices())
        PCMCIACARD_ATTRIBUTE_SIZE,                                  // Size of window
        PCMCIACARD_ATTRIBUTE_PHYSICAL,                              // Physical address of beginning of window
        0                                                           // Offset in PC card memory
    }
};    



PDCARD_WINDOW_INFO v_WinInfo[PCMCIA_NUM_WINDOWS] = {
{   // Capabilities of window 0
    1,                                                          // bit 0 -> socket 0, bit 1 -> socket 1, ...
    WIN_CAP_COMMON,                                             // Bit encoded window capabilities
    MEM_CAP_8BIT | MEM_CAP_16BIT,                               // Bit encoded memory window capabilities
    0,                                                          // Bit encoded I/O window capabilities
    PCMCIACARD_MEMORY_PHYSICAL,                                 // Physical address of first addressable byte
    PCMCIACARD_MEMORY_PHYSICAL + PCMCIACARD_MEMORY_SIZE - 1,    // Physical address of last addressable byte
    MIN_WIN_SIZE,                                               // Minimum size of window
    PCMCIACARD_MEMORY_SIZE,                                     // Maximum size of window
    MIN_WIN_GRAN,                                               // Required window granularity
    0,                                                          // Required window base address alignment
    0,                                                          // Required card offset alignment
    0,                                                          // Physical address of first addressable byte
    0,                                                          // Physical address of last addressable byte
    0,                                                          // Minimum size of window
    0,                                                          // Maximum size of window
    0,                                                          // Required window granularity
    0,                                                          // Number of I/O lines decoded
    WIN_SPEED_EXP_100NS | WIN_SPEED_MANT_60,                    // Bit encoded slowest access speed (WIN_SPEED_USE_WAIT will be updated by PDCardInitServices())
    WIN_SPEED_EXP_100NS | WIN_SPEED_MANT_10,                    // Bit encoded fastest access speed (WIN_SPEED_USE_WAIT will be updated by PDCardInitServices())
},
{   // Capabilities of window 1
    1,                                                          // bit 0 -> socket 0, bit 1 -> socket 1, ...
    WIN_CAP_IO | WIN_CAP_WAIT,                                  // Bit encoded window capabilities
    0,                                                          // Bit encoded memory window capabilities
    IO_CAP_8BIT | IO_CAP_16BIT,                                 // Bit encoded I/O window capabilities
    0,                                                          // Physical address of first addressable byte
    0,                                                          // Physical address of last addressable byte
    0,                                                          // Minimum size of window
    0,                                                          // Maximum size of window
    0,                                                          // Required window granularity
    0,                                                          // Required window base address alignment
    0,                                                          // Required card offset alignment
    PCMCIACARD_IO_PHYSICAL,                                     // Physical address of first addressable byte
    PCMCIACARD_IO_PHYSICAL + PCMCIACARD_IO_SIZE - 1,            // Physical address of last addressable byte
    MIN_WIN_SIZE,                                               // Minimum size of window
    PCMCIACARD_IO_SIZE,                                         // Maximum size of window
    MIN_WIN_GRAN,                                               // Required window granularity
    26,                                                         // Number of I/O lines decoded
    0,                                                          // Bit encoded slowest access speed
    0,                                                          // Bit encoded fastest access speed
},
{   // Capabilities of window 2
    1,                                                          // bit 0 -> socket 0, bit 1 -> socket 1, ...
    WIN_CAP_ATTRIBUTE,                                          // Bit encoded window capabilities
    MEM_CAP_8BIT | MEM_CAP_16BIT,                               // Bit encoded memory window capabilities
    0,                                                          // Bit encoded I/O window capabilities
    PCMCIACARD_ATTRIBUTE_PHYSICAL,                              // Physical address of first addressable byte
    PCMCIACARD_ATTRIBUTE_PHYSICAL +                             // Physical address of last addressable byte 
    PCMCIACARD_ATTRIBUTE_SIZE - 1,                              
    MIN_WIN_SIZE,                                               // Minimum size of window
    PCMCIACARD_ATTRIBUTE_SIZE,                                  // Maximum size of window
    MIN_WIN_GRAN,                                               // Required window granularity
    0,                                                          // Required window base address alignment
    0,                                                          // Required card offset alignment
    0,                                                          // Physical address of first addressable byte
    0,                                                          // Physical address of last addressable byte
    0,                                                          // Minimum size of window
    0,                                                          // Maximum size of window
    0,                                                          // Required window granularity
    0,                                                          // Number of I/O lines decoded
    WIN_SPEED_EXP_100NS | WIN_SPEED_MANT_60,                    // Bit encoded slowest access speed (WIN_SPEED_USE_WAIT will be updated by PDCardInitServices())
    WIN_SPEED_EXP_100NS | WIN_SPEED_MANT_25,                    // Bit encoded fastest access speed (WIN_SPEED_USE_WAIT will be updated by PDCardInitServices())
}
};

#define PCMCIA_BOARD_DELAY          10
#define PCCONFIG_TIME_MASK          ( PCCONFIG_ADDRESSTIME_MASK | PCCONFIG_HOLDTIME_MASK | PCCONFIG_ACCESSTIME_MASK )

//****************************************************************************
// fStateStr
//****************************************************************************
// Used to print out state debug messages.
// 
//
#if defined(DEBUGMSG)
char * fStateStr
(
    UINT8 fState
)
{
    static char s[32];

    // Note: This code is a little wacky concerning the strings because they need to be unicode
    // strings, but I am doing everything the old fashioned way for simplicity.

    strcpy(s, "C#M#N#-#E#-#0#8#\0\0");      // pre-init string for common memory, Enabled, and 8 bit access

    if (fState & WIN_STATE_MAPS_IO)
        s[0*2]='I', s[1*2]='/', s[2*2]='O';
    else if (fState & WIN_STATE_ATTRIBUTE)
        s[0*2] = 'A', s[1*2]='T', s[2*2]='R';
    else
        s[0*2] = 'C', s[1*2]='M', s[2*2]='N';

    if ((fState & WIN_STATE_ENABLED) == 0)
        s[4*2] = 'D';
    else
        s[4*2] = 'E';

    if (fState & WIN_STATE_16BIT)
        s[6*2]='1', s[7*2]='6';
    else
        s[6*2]='0', s[7*2]='8';

    return s;
}


//****************************************************************************
// fSpeedStr
//****************************************************************************
// Textual representation of Window Speed
// 
//
char * fSpeedStr
(
    UINT8 fSpeed
)
{
    static char s[32];

    // Note: This code is a little wacky concerning the strings because they need to be unicode
    // strings, but I am doing everything the old fashioned way for simplicity.

    strcpy(s, "W#a#i#t#|#x#x#0#n#s#\0\0");

    if ((fSpeed & WIN_SPEED_USE_WAIT) == 0)
        s[0*2]='N', s[1*2]='o', s[2*2]='W', s[3*2]='t';

    if ((fSpeed & WIN_SPEED_EXP_MASK) == WIN_SPEED_EXP_100NS)
        {
        switch (fSpeed & WIN_SPEED_MANT_MASK)
            {
            case WIN_SPEED_MANT_10: s[5*2]='1'; s[6*2]='0'; break;
            case WIN_SPEED_MANT_12: s[5*2]='1'; s[6*2]='2'; break;
            case WIN_SPEED_MANT_13: s[5*2]='1'; s[6*2]='3'; break;
            case WIN_SPEED_MANT_15: s[5*2]='1'; s[6*2]='5'; break;
            case WIN_SPEED_MANT_20: s[5*2]='2'; s[6*2]='0'; break;
            case WIN_SPEED_MANT_25: s[5*2]='2'; s[6*2]='5'; break;
            case WIN_SPEED_MANT_30: s[5*2]='3'; s[6*2]='0'; break;
            case WIN_SPEED_MANT_35: s[5*2]='3'; s[6*2]='5'; break;
            case WIN_SPEED_MANT_40: s[5*2]='4'; s[6*2]='0'; break;
            case WIN_SPEED_MANT_45: s[5*2]='4'; s[6*2]='5'; break;
            case WIN_SPEED_MANT_50: s[5*2]='5'; s[6*2]='0'; break;
            case WIN_SPEED_MANT_55: s[5*2]='5'; s[6*2]='5'; break;
            case WIN_SPEED_MANT_60: s[5*2]='6'; s[6*2]='0'; break;
            case WIN_SPEED_MANT_70: s[5*2]='7'; s[6*2]='0'; break;
            case WIN_SPEED_MANT_80: s[5*2]='8'; s[6*2]='0'; break;
            }
        }
    else if ((fSpeed & WIN_SPEED_EXP_MASK) < WIN_SPEED_EXP_100NS)
        {
        s[5*2]='<'; s[6*2]='<'; s[7*2]='<';         // signifies less than 100ns
        }
    else if ((fSpeed & WIN_SPEED_EXP_MASK) > WIN_SPEED_EXP_100NS)
        {
        s[5*2]='>'; s[6*2]='>'; s[7*2]='>';         // signifies greater than or equal to 1000ns
        }
    else
        {
        s[5*2]='-'; s[6*2]='-'; s[7*2]='-';         // should never happen
        }

    return s;
}
#endif 


//****************************************************************************
// PDCardGetWindow
//****************************************************************************
//
// @func    STATUS | PDCardGetWindow | Report the current state of a memory or I/O window
// @rdesc   Returns one of the CERR_* error codes in cardserv.h
//
STATUS PDCardGetWindow
(
    UINT32 uWindow,                     // @parm Window number (the first window is 0)
    PPDCARD_WINDOW_STATE pWindowState   // @parm Pointer to a PDCARD_WINDOW_STATE structure.
)
{
    if (uWindow >= PCMCIA_NUM_WINDOWS) 
    {
        return CERR_BAD_WINDOW;
    }

    memcpy(pWindowState, &(v_WinState[uWindow]), sizeof(PDCARD_WINDOW_STATE));
    return CERR_SUCCESS;
}


//****************************************************************************
// PDCardSetWindow
//****************************************************************************
// @func    STATUS | PDCardSetWindow | Change the characteristics of a memory or I/O window
// @rdesc   Returns one of the CERR_* error codes in cardserv.h
//
STATUS PDCardSetWindow
(
    UINT32 uWindow,                     // @parm Window number (the first window is 0)
    PPDCARD_WINDOW_STATE pWindowState   // @parm Pointer to a PDCARD_WINDOW_STATE structure.
)
{
    UINT    sock;
    BOOL    bUserMode = TRUE;
    volatile ULONG * pPcConfigReg;
    ULONG   ulPcConfig = 0;

    DEBUGMSG(1,(TEXT("++PDCardSetWindow #%x\n\r"), uWindow));

    DEBUGMSG(ZONE_PDD, (TEXT("^PCMCIA PDCardSetWindow: %x => fSpeed:%x(%s); uSize:%x; uOffset:%x; uBase:%x; fState:%x(%s)\r\n"),
                       uWindow,
                       (UINT32)v_WinState[uWindow].fSpeed,
                       fSpeedStr(v_WinState[uWindow].fSpeed),
                       (UINT32)v_WinState[uWindow].uSize,
                       (UINT32)v_WinState[uWindow].uOffset,
                       (UINT32)v_WinState[uWindow].uBase,
                       (UINT32)v_WinState[uWindow].fState,
                       fStateStr(v_WinState[uWindow].fState)));

    if (uWindow >= PCMCIA_NUM_WINDOWS)
        return CERR_BAD_WINDOW;

    DEBUGMSG(ZONE_PDD, (TEXT("                 Requested => fSpeed:%x(%s); uSize:%x; uOffset:%x; uBase:%x; fState:%x(%s)\r\n"),
                       (UINT32)pWindowState->fSpeed,
                       fSpeedStr(v_WinState[uWindow].fSpeed),
                       (UINT32)pWindowState->uSize,
                       (UINT32)pWindowState->uOffset,
                       (UINT32)pWindowState->uBase,
                       (UINT32)pWindowState->fState,
                       fStateStr(v_WinState[uWindow].fState)));


    if ( uWindow & ADP_STATE_KERNEL_MODE) 
    { 
        //
        // check the kernel-mode bit
        //
        ASSERT( !(PCMCIA_NUM_WINDOWS & ADP_STATE_KERNEL_MODE) );
        uWindow &= ~ADP_STATE_KERNEL_MODE;  // clear it
        bUserMode = FALSE;
    }
    
    //
    // No logic to set the uSize or uOffset because these can't really be changed
    // with the EP-93xx.  CE also should never request to change these with the EP-93xx
    // either; however, if CE does, tell CE it is an error.
    //
    if (v_WinState[uWindow].uSize != pWindowState->uSize)
    {
        DEBUGMSG(ZONE_PDD, (TEXT("Bad size, returning CERR_BAD_SIZE\r\n")));
        return CERR_BAD_SIZE;
    }
    if (v_WinState[uWindow].uOffset != pWindowState->uOffset)
    {
        DEBUGMSG(ZONE_PDD, (TEXT("Bad offset, returning CERR_BAD_OFFSET\r\n")));
        return CERR_BAD_OFFSET;
    }
    if (v_WinState[uWindow].uBase != pWindowState->uBase)
    {
        DEBUGMSG(ZONE_PDD, (TEXT("Bad Base, returning CERR_BAD_BASE\r\n")));
        return CERR_BAD_BASE;
    }

    //
    // Do some basic error checking.  These are errors because that characteristic of the window
    // can not be changed on EP-93xx platforms.
    //
    if (pWindowState->fState & WIN_STATE_MAPS_IO)
    {
        if (!(v_WinState[uWindow].fState & WIN_STATE_MAPS_IO))
        {
            DEBUGMSG(ZONE_PDD, (TEXT("Bad WIN_STATE_MAPS_IO, returning CERR_BAD_ATTRIBUTE\r\n")));
            return CERR_BAD_ATTRIBUTE;
        }
    }
    if (pWindowState->fState & WIN_STATE_ATTRIBUTE)
    {
        if (!(v_WinState[uWindow].fState & WIN_STATE_ATTRIBUTE))
        {
            DEBUGMSG(ZONE_PDD, (TEXT("Bad WIN_STATE_ATTRIBUTE, returning CERR_BAD_ATTRIBUTE\r\n")));
            return CERR_BAD_ATTRIBUTE;
        }
    }

    sock = v_WinState[uWindow].uSocket;
            
    //
    // Get correct register for the appropriate window.
    //
    if ( (v_WinInfo[uWindow].fWindowCaps & WIN_CAP_COMMON) == WIN_CAP_COMMON)
    {
        //
        // common memory
        //

⌨️ 快捷键说明

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