Nut/OS  4.10.3
API Reference
pcmcia.c
Go to the documentation of this file.
00001 /****************************************************************************
00002 *  This file is part of the WLAN-Ethernut driver.
00003 *
00004 *  Copyright (c) 2004 by Michael Fischer. All rights reserved.
00005 *
00006 *  Redistribution and use in source and binary forms, with or without 
00007 *  modification, are permitted provided that the following conditions 
00008 *  are met:
00009 *  
00010 *  1. Redistributions of source code must retain the above copyright 
00011 *     notice, this list of conditions and the following disclaimer.
00012 *  2. Redistributions in binary form must reproduce the above copyright
00013 *     notice, this list of conditions and the following disclaimer in the 
00014 *     documentation and/or other materials provided with the distribution.
00015 *  3. Neither the name of the author nor the names of its contributors may 
00016 *     be used to endorse or promote products derived from this software 
00017 *     without specific prior written permission.
00018 *
00019 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00020 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00021 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
00022 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00023 *  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
00024 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
00025 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 
00026 *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
00027 *  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
00028 *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
00029 *  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
00030 *  SUCH DAMAGE.
00031 *
00032 ****************************************************************************
00033 *  History:
00034 *
00035 *  07.02.04  mifi   First Version for the XC9572-PC84 ONLY!
00036 *                   The BASE_ADDRESS is 0x8800!!
00037 ****************************************************************************/
00038 #define __PCMCIA_C__
00039 
00040 /*
00041  * The PCMCIA interface works with a Xilinx XC9572-PC84 CPLD.
00042  * All the lines like CE1, CE2, WE, OE and so on must be control
00043  * separate by the latch.
00044  *
00045 */
00046 
00047 #include <compiler.h>
00048 
00049 #include <dev/wlantypes.h>
00050 #include <dev/pcmcia.h>
00051 
00052 /*==========================================================*/
00053 /*  DEFINE: All Structures and Common Constants             */
00054 /*==========================================================*/
00055 /*
00056  * Address offset, register index of the CPLD
00057 */
00058 #define BASE_ADDRESS  0x8800
00059 #define DATA_LOW      0
00060 #define DATA_HIGH     1
00061 #define ADDRESS_LOW   2
00062 #define ADDRESS_HIGH  3
00063 #define CTRL          4
00064 
00065 /*
00066  * CTRL bit definition
00067 */
00068 #define CTRL_CE1      0x01
00069 #define CTRL_CE2      0x02
00070 #define CTRL_OE       0x04
00071 #define CTRL_WE       0x08
00072 #define CTRL_IORD     0x10
00073 #define CTRL_IOWR     0x20
00074 #define CTRL_REGS     0x40
00075 #define CTRL_DATA_OUT 0x80
00076 
00077 #define DATA_LOW_REG      *((volatile BYTE *)BASE_ADDRESS+DATA_LOW)
00078 #define DATA_HIGH_REG     *((volatile BYTE *)BASE_ADDRESS+DATA_HIGH)
00079 #define ADDRESS_LOW_REG   *((volatile BYTE *)BASE_ADDRESS+ADDRESS_LOW)
00080 #define ADDRESS_HIGH_REG  *((volatile BYTE *)BASE_ADDRESS+ADDRESS_HIGH)
00081 #define CTRL_REG          *((volatile BYTE *)BASE_ADDRESS+CTRL)
00082 
00083 /*
00084  * Some delay values
00085 */
00086 #define DELAY_CE_WRITE()
00087 #define DELAY_WRITE()
00088 #define DELAY_WRITE_CE()
00089 
00090 #define DELAY_CE_READ()
00091 #define DELAY_READ()    _NOP();_NOP(); _NOP();_NOP()
00092 #define DELAY_READ_CE()
00093 
00094 typedef enum {
00095     TYPE_IO = 0,
00096     TYPE_MEM
00097 } MEMORY_TYPE;
00098 
00099 /*==========================================================*/
00100 /*  DEFINE: Prototypes                                      */
00101 /*==========================================================*/
00102 
00103 /*==========================================================*/
00104 /*  DEFINE: Definition of all local Data                    */
00105 /*==========================================================*/
00106 //static volatile BYTE *pCPLD = (volatile BYTE *) BASE_ADDRESS;
00107 //static BYTE gbCTRLValue = 0x7C;
00108 
00109 /*==========================================================*/
00110 /*  DEFINE: Definition of all local Procedures              */
00111 /*==========================================================*/
00112 /************************************************************/
00113 /*  WriteXXX                                                */
00114 /************************************************************/
00115 static void WriteXXX(WORD wAddress, WORD wData, MEMORY_TYPE eIO)
00116 {
00117     cli();
00118 
00119     /*
00120      * set ADDRESS
00121      */
00122     ADDRESS_LOW_REG = LOBYTE(wAddress);
00123     ADDRESS_HIGH_REG = HIBYTE(wAddress);
00124 
00125     /*
00126      * set DATA
00127      */
00128     DATA_LOW_REG = LOBYTE(wData);
00129     DATA_HIGH_REG = HIBYTE(wData);
00130 
00131     /*
00132      * set CE1, CE2
00133      */
00134     CTRL_REG = (CTRL_CE1 | CTRL_CE2 | CTRL_OE | CTRL_WE | CTRL_IORD | CTRL_IOWR | CTRL_DATA_OUT);
00135 
00136     DELAY_CE_WRITE();
00137 
00138     /*
00139      * set WR/IOWR
00140      */
00141     if (eIO == TYPE_MEM) {
00142         CTRL_REG = (CTRL_CE1 | CTRL_CE2 | CTRL_OE | CTRL_IORD | CTRL_IOWR | CTRL_DATA_OUT);
00143     } else {
00144         CTRL_REG = (CTRL_CE1 | CTRL_CE2 | CTRL_OE | CTRL_WE | CTRL_IORD | CTRL_DATA_OUT);
00145     }
00146 
00147     DELAY_WRITE();
00148 
00149     /*
00150      * check the WAIT signal
00151      */
00152 
00153     /*
00154      * remove WR/IOWR
00155      */
00156     CTRL_REG = (CTRL_CE1 | CTRL_CE2 | CTRL_OE | CTRL_WE | CTRL_IORD | CTRL_IOWR | CTRL_DATA_OUT);
00157 
00158     DELAY_WRITE_CE();
00159 
00160     /*
00161      * remove CE1, CE2
00162      */
00163     CTRL_REG = (CTRL_OE | CTRL_WE | CTRL_IORD | CTRL_IOWR);
00164 
00165     sei();
00166 }
00167 
00168 /************************************************************/
00169 /*  ReadXXX                                                 */
00170 /************************************************************/
00171 static WORD ReadXXX(WORD wAddress, MEMORY_TYPE eIO)
00172 {
00173     BYTE bLow;
00174     BYTE bHigh;
00175     WORD wData;
00176 
00177     cli();
00178 
00179     /*
00180      * set ADDRESS
00181      */
00182     ADDRESS_LOW_REG = LOBYTE(wAddress);
00183     ADDRESS_HIGH_REG = HIBYTE(wAddress);
00184 
00185     /*
00186      * set CE1, CE2
00187      */
00188     CTRL_REG = (CTRL_CE1 | CTRL_CE2 | CTRL_OE | CTRL_WE | CTRL_IORD | CTRL_IOWR);
00189 
00190     DELAY_CE_READ();
00191 
00192     /*
00193      * set OE/IORD
00194      */
00195     if (eIO == TYPE_MEM) {
00196         CTRL_REG = (CTRL_CE1 | CTRL_CE2 | CTRL_WE | CTRL_IORD | CTRL_IOWR);
00197     } else {
00198         CTRL_REG = (CTRL_CE1 | CTRL_CE2 | CTRL_OE | CTRL_WE | CTRL_IOWR);
00199     }
00200 
00201     DELAY_READ();
00202 
00203     /*
00204      * check the WAIT signal
00205      */
00206     bLow = DATA_LOW_REG;
00207     bHigh = DATA_HIGH_REG;
00208 
00209     /*
00210      * remove OE/IORD
00211      */
00212     CTRL_REG = (CTRL_CE1 | CTRL_CE2 | CTRL_OE | CTRL_WE | CTRL_IORD | CTRL_IOWR | CTRL_DATA_OUT);
00213 
00214     DELAY_READ_CE();
00215 
00216     /*
00217      * remove CE1, CE2
00218      */
00219     CTRL_REG = (CTRL_OE | CTRL_WE | CTRL_IORD | CTRL_IOWR);
00220 
00221     wData = (WORD) bHigh;
00222     wData = (wData << 8) | (WORD) bLow;
00223 
00224     sei();
00225 
00226     return (wData);
00227 }
00228 
00229 /*==========================================================*/
00230 /*  DEFINE: All code exported                               */
00231 /*==========================================================*/
00232 /************************************************************/
00233 /*  pcmcia_WriteMem                                         */
00234 /************************************************************/
00235 void pcmcia_WriteMem(WORD wAddress, WORD wData)
00236 {
00237     WriteXXX(wAddress, wData, TYPE_MEM);
00238 }
00239 
00240 /************************************************************/
00241 /*  pcmcia_WriteReg                                         */
00242 /************************************************************/
00243 void pcmcia_WriteReg(WORD wAddress, WORD wData)
00244 {
00245     WriteXXX(wAddress, wData, TYPE_IO);
00246 }
00247 
00248 /************************************************************/
00249 /*  pcmcia_ReadMem                                          */
00250 /************************************************************/
00251 WORD pcmcia_ReadMem(WORD wAddress)
00252 {
00253     return (ReadXXX(wAddress, TYPE_MEM));
00254 }
00255 
00256 /************************************************************/
00257 /*  pcmcia_ReadReg                                          */
00258 /************************************************************/
00259 WORD pcmcia_ReadReg(WORD wAddress)
00260 {
00261     return (ReadXXX(wAddress, TYPE_IO));
00262 }