📄 mbxpcmcia.c
字号:
/* mbxPcmcia.c - PCMCIA Interface Initialization Module for MBX *//* Copyright 1984-1998 Wind River Systems, Inc. *//* Copyright 1997,1998 Motorola, Inc., All Rights Reserved *//*modification history--------------------01d,26mar98,map code cleanup.01c,20nov97,rhk cleanup of routine headers, changed routine names.01b,12may97,srr modified for VxWorks.01a,10apr97,tda created.*//*DESCRIPTIONThis module implements a very basic PCMCIA support, and is intended to be usedwith memory cards. This module does not attempt to read the attribute memoryof the device, but simply maps in 64M of space with the worst case timing.Future enhancements to this module may be made to read the attribute memory,tune the address space mappings and speed settings based on the deviceattributes.EXTERNAL INTERFACEThis module provides a interface, mbxPcmciaConfig, to scan the PCMCIA socketand to enable a memory card if it is present, and to disable itotherwise. This routine is called once by the BSP during startup, and shouldbe called by the user when a card is inserted or removed after boot up.EXTERNAL SUPPORT REQUIREMENTSThis module requires an external routine to provide a micro-second delay..IP sysMsDelay().CS void sysMsDelay(UINT uSecs).CE*//* include files, paths are dependent on makefile */#include "vxWorks.h" /* types */#include "vxLib.h"#if defined(INCLUDE_MBX_PCMCIA)/* externs */IMPORT void sysMsDelay(UINT);/* forward declarations */LOCAL void socketShutdown();LOCAL void socketStartup();LOCAL void vccApply();LOCAL BOOL cardPresent();LOCAL UINT vccNeeded();LOCAL UINT vccApplied();LOCAL UINT socketPinsCount();LOCAL void resetAssert();LOCAL void deassertReset();LOCAL void socketMapIn();LOCAL void socketEnable();LOCAL void socketDisable();/******************************************************************************* mbxPcmciaConfig - MBX PCMCIA configure routine** Scans PCMCIA sockets for cards present. Initializes and enables interface* to cards that are present. Disable interface to non-present cards.** This currently is only called once during startup. The code is written so* that it can be called periodically to deal with card insertion/removals.** This code also assumes only one socket is present although it has been* written to allow easy adaption to multiple socket hardware.** RETURNS: OK, always*/STATUS mbxPcmciaConfig (void) { int socket; int volts; for(socket = 0; socket < PCMCIA_MAX_SOCKS; socket++) { if(cardPresent(socket)) { volts = vccNeeded(socket); if(vccApplied(socket) != volts) { socketShutdown(socket); socketStartup(socket,volts); socketMapIn(socket); } } else socketShutdown(socket); } return OK; } /******************************************************************************* socketShutdown - pcmcia socket shutdown** This function provides the means to powerdown sockets.* socketShutdown() does all hardware initialization required to* powerdown a PCMCIA socket.** RETURNS: N/A*/LOCAL void socketShutdown ( int socket /* The socket of interest */ ) { socketDisable(socket); /* Disable socket transceivers */ vccApply(socket, 0); /* Remove voltage to the socket */ }/******************************************************************************* socketStartup - pcmcia socket startup routine* * This function provides the means to powerup sockets. The routine * does all hardware initialization required to powerup and enable a* PCMCIA socket hardware.* * RETURNS: N/A*/LOCAL void socketStartup ( int socket, /* The socket of interest */ int volts /* The voltage to apply to the socket */ ) { vccApply(socket, volts); /* Apply the requested volts */ sysMsDelay(300); /* Allow time to powerup */ resetAssert(socket); /* Assert socket reset */ socketEnable(socket); /* Enable socket transceivers */ sysMsDelay(2); /* Delay required reset time */ deassertReset(socket); /* Deassert socket reset */ sysMsDelay(20); /* Allow time for card to come out of reset */ }/******************************************************************************* vccApply - apply voltage to socket** This routine applies the requested voltage to the specified socket.** RETURNS: N/A**/LOCAL void vccApply ( int socket, /* The socket of interest */ int volts /* The voltage to apply to the socket */ ) { if(socket) return; /* MBX only has socket 0 */ switch(volts) { case 0: *BCSR2 = 0; break; case 3: *BCSR2 = BCSR2_PCMCIA_VCC_033 | BCSR2_PCMCIA_VPP_VCC; break; case 5: *BCSR2 = BCSR2_PCMCIA_VCC_050 | BCSR2_PCMCIA_VPP_VCC; break; } }/******************************************************************************* vccApplied - get socket voltage currently applied** This routine returns the value of the voltage currently* applied to the specified socket.** RETURNS: applied voltage level**/LOCAL UINT vccApplied ( int socket /* The socket of interest */ ) { if(socket) return(0); /* MBX only has socket 0 */ switch(*BCSR2 & BCSR2_PCMCIA_VCC_HZB) { case 0x00: return(0); case 0x40: return(5); case 0x80: return(3); case 0xC0: return(0); default: return(0); } }/******************************************************************************* vccNeeded - get voltage needed** This routine returns the value of the voltage needed by* the card present in the specified socket.** RETURNS: needed voltage level**/LOCAL UINT vccNeeded ( int socket /* The socket of interest */ ) { UINT pins; pins = socketPinsCount(socket); switch (pins & 0xC000) { case 0x0: return(0); case 0x4000: return(3); case 0x8000: return(0); case 0xC000: return(5); default: return(0); } }/******************************************************************************* socketPinsCount - get pin count** get the socket pin count from the PIPR register.** RETURNS: pin count**/LOCAL UINT socketPinsCount ( int socket /* The socket of interest */ ) { UINT pins; int immrVal; immrVal = vxImmrGet(); pins = *PIPR(immrVal); if (!socket) pins = pins >> 16; return(pins & 0xFFFF); }/******************************************************************************* cardPresent - is pcmcia card present** Determine if a card is present in the specified socket.** RETURNS: Flag indicating whether card is present or not.* non-zero means card is present. zero = not.**/LOCAL BOOL cardPresent ( int socket /* The socket of interest */ ) { UINT pins; pins = socketPinsCount(socket); pins &= 0x1800; return (pins == 0); }/******************************************************************************* socketDisable - disable socket** This function provides support for disabling the socket transceivers.** RETURNS: N/A*/LOCAL void socketDisable ( int socket /* The socket of interest */ ) { int immrVal; immrVal = vxImmrGet(); if(socket) *PGCRB(immrVal) |= 0x80; /* COE */ else *PGCRA(immrVal) |= 0x80; /* COE */ }/******************************************************************************* socketEnable - enable socket** This function provides support for enabling the socket transceivers.** RETURNS: N/A*/LOCAL void socketEnable ( int socket /* The socket of interest */ ) { int immrVal; immrVal = vxImmrGet(); if(socket) *PGCRB(immrVal) &= ~0x80; /* COE */ else *PGCRA(immrVal) &= ~0x80; /* COE */ }/******************************************************************************* resetAssert - assert reset signal** This function provides support to assert* the reset signal to the socket of interest.** RETURNS: N/A*/LOCAL void resetAssert ( int socket /* The socket of interest */ ) { int immrVal; immrVal = vxImmrGet(); if(socket) *PGCRB(immrVal) |= 0x40; /* CARESET */ else *PGCRA(immrVal) |= 0x40; /* CARESET */ }/******************************************************************************* deassertReset - de-assert reset signal** This function provides support to de-assert* the reset signal to the socket of interest.** RETURNS: N/A*/LOCAL void deassertReset ( int socket /* The socket of interest */ ) { int immrVal; immrVal = vxImmrGet(); if(socket) *PGCRB(immrVal) &= ~0x40; /* CARESET */ else *PGCRA(immrVal) &= ~0x40; /* CARESET */ }/******************************************************************************* socketMapIn - map in socket memory space** This function's purpose is to enable the socket memory* space into the processor space.* * NOTES:* The initial version of this function is very simple* minded. It simply maps in the card memory space into * a 64Meg window with the worst case speed timings. * * RETURNS: N/A*/LOCAL void socketMapIn ( int socket /* The socket of interest */ ) { int immrVal; immrVal = vxImmrGet(); if(socket) /* HELP */ { *PBR4(immrVal) = PCMCIA_MEMORY_BA; /* 64M Memory */ *POR4(immrVal) = 0xB80FF045; /* HELP */ *PBR5(immrVal) = PCMCIA_DMA_BA; /* 64M DMA */ *POR5(immrVal) = 0xB80FF065; /* HELP */ *PBR6(immrVal) = PCMCIA_ATTRIBUTE_BA; /* 64M Attribute */ *POR6(immrVal) = 0xB80FF055; /* HELP */ *PBR7(immrVal) = PCMCIA_IO_BA; /* 64M I/O */ *POR7(immrVal) = 0xB80FF05D; /* HELP */ } else { *PBR0(immrVal) = PCMCIA_MEMORY_BA; /* 64M Memory */ *POR0(immrVal) = 0xB80FF041; /* HELP */ *PBR1(immrVal) = PCMCIA_DMA_BA; /* 64M DMA */ *POR1(immrVal) = 0xB80FF061; /* HELP */ *PBR2(immrVal) = PCMCIA_ATTRIBUTE_BA; /* 64M Attribute */ *POR2(immrVal) = 0xB80FF051; /* HELP */ *PBR3(immrVal) = PCMCIA_IO_BA; /* 64M I/O */ *POR3(immrVal) = 0xB80FF059; /* HELP */ } }#endif /* defined(INCLUDE_MBX_PCMCIA) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -