projekty/Source/example1/src/MAM.c

Go to the documentation of this file.
00001 /*
00002  * $Id: MAM.c,v 1 2006/03/27 18:00:00 BorisK Exp $
00003  *
00004  * Copyright (C) 2006 ONTRACK s.r.o.
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA    
00019  * 02111-1307, USA.
00020  *
00021  * [1] ARM-based Microcontroller LPC2119/2129/2194/2292/9994, "Preliminary User Manual", February 03, 2004
00022  * [2] 3 Volt Synchronous Intel StrataFlash Memory, OrderNumber:290737-004, February 2002
00023  *
00024  * Written by Boris Kralik <kralikbo@yahoo.com>, 2006
00025  *
00026  */
00027 #include "MAM.h"
00028 void             SetGPIO_AD(uint32_t address,uint16_t data){
00029         int i;
00030         if (chain[nCE]==0) return;
00031         SetSignal("nCE",OUT,1);
00032         SetSignal("nCE",OUT,0);
00033         SetSignal("nWE",OUT,1);
00034         SetSignal("nOE",OUT,1);
00035         for(i=0;i<24;i++)if (((address & (1 << i)) >> i)  == 1){GPIO3_IOSET     |=      (1 << i);chain[AB_CHAIN_OFFSET+i]=1;}else {GPIO3_IOCLR  |=      (1 << i);chain[AB_CHAIN_OFFSET+i]=0;}
00036         for(i=0;i<16;i++)if (((data    & (1 << i)) >> i)  == 1){GPIO2_IOSET     |=      (1 << i);chain[DB_CHAIN_OFFSET+i]=1;}else {GPIO2_IOCLR  |=      (1 << i);chain[DB_CHAIN_OFFSET+i]=0;}
00037         SetSignal("nWE",OUT,0);
00038 }
00039 void             SetGPIOAddress(uint32_t address){//A23:1 (Memory), A23:1 (LPC)
00040         uint8_t i;
00041         for(i=0;i<24;i++)if (((address & (1 << i)) >> i)  == 1) {GPIO3_IOSET    |=      (1 << (i));chain[AB_CHAIN_OFFSET+i]=1;}else {GPIO3_IOCLR        |=      (1 << (i));chain[AB_CHAIN_OFFSET+i]=0;}
00042 }
00043 
00044 void             MemGPIOWE(short sStaff){
00045         switch(sStaff){//GPIO 3.27
00046                 case 0: GPIO3_IOCLR     |=      (1 << 27);break;
00047                 default:GPIO3_IOSET     |=      (1 << 27);break;
00048         }
00049 }
00050 void             MemGPIOOE(short sStaff){
00051         switch(sStaff)  //GPIO 1.1
00052         {
00053                 case 0: GPIO1_IOCLR     |=      (1 << 1);break;
00054                 default:GPIO1_IOSET     |=      (1 << 1);break;
00055         }
00056 }
00057 void             MemGPIOCE(short sStaff){
00058         switch(sStaff)  //GPIO 1.0
00059         {
00060                 case 0: GPIO1_IOCLR     |=      (1 << 0);break;
00061                 default:GPIO1_IOSET     |=      (1 << 0);break;
00062         }
00063 }
00064 
00065 void             SetSignal(char const *pName,short dir,uint32_t val){
00066         if (strlen(pName)==NULL){printf("\n\nEMam.c->strlen(%s)==NULL",pName);return;}else
00067                 //printf("\n\r\tSetSignal(%s,%s,0x%X)",pName,(dir ? "OUT" : "IN" ),(val & 0x1));
00068                                 WD_Reset();
00069                                 if ((pName[0] == 'A') && (pName[1] == 'B')){chain[(char2num(pName[3])+AB_CHAIN_OFFSET)] = ((val & 1) & 0x1);return;}
00070                                 if (strcmp(pName,"nWE")){MemGPIOWE((val & 1));chain[nWE]=((val & 1) & 0x1);return;}
00071                                 else    if (strcmp(pName,"nOE")){MemGPIOOE((val & 1));chain[nOE]=((val & 1) & 0x1);return;}
00072                                 else    if (strcmp(pName,"nCE")){MemGPIOCE((val & 1));chain[nCE]=((val & 1) & 0x1);return;}
00073                                 else printf("\n\rError [%s]",pName);
00074 }
00075 
00076 void             MemGPIOInit(void){     //P3.1-P3.23(AB) - OUT, P1.0(/CE), P1.1(OE), P3.27(WE), P2.0-P2.15(D0-15) - OUT
00077         short i;
00078         PCB_PINSEL2     &=      0xF07C163B;
00079         PCB_PINSEL2     |=      ((1 << 5)|(1 << 4));//P2.15:0, P3.27(WE), P1.0(CS0),P1.1(OE) as GPIO
00080 
00081         GPIO3_IODIR     =       0xFFFFFFF;      //P3.27,P3.AB(1-23) as OUTPUT
00082         GPIO3_IOCLR     =       0xFFFFFFF;      //Clear address wires
00083 
00084         GPIO1_IODIR     |=      ((1 << 0)|(1 << 1));    //Set /CE(P1.0), /OE(P1.1) as OUTPUT
00085 
00086         GPIO2_IODIR     |=      0xFFFF; //DB 2.(0-16) as OUTPUT
00087         GPIO2_IOCLR     |=      0xFFFF; //Clear data wires
00088 
00089         for(i=0;i<42;i++) chain[i]=0;
00090         SetSignal("nCE",OUT,1);WD_Reset();
00091         SetSignal("nWE",OUT,1);WD_Reset();
00092         SetSignal("nOE",OUT,1);WD_Reset();
00093 }
00094 void             SetGPIOData(uint16_t data){
00095         int i;
00096         GPIO2_IODIR     |=      0xFFFF; //DB(0:15) AS OUTPUT
00097         SetSignal("nCE",OUT,0);
00098         SetSignal("nOE",OUT,1);
00099         for(i=0;i<16;i++) if (((data & (1 << i)) >> i)  == 1){GPIO2_IOSET       |=      (1 << i);chain[DB_CHAIN_OFFSET+i]=1;}else {GPIO2_IOCLR  |=      (1 << i);chain[DB_CHAIN_OFFSET+i]=0;}
00100 }
00101 
00102 uint16_t         ReadNext(uint32_t address){
00103         uint16_t ret=0;
00104         SetSignal("nCE",OUT,1);WD_Reset();
00105         SetGPIOAddress(address);WD_Reset();
00106         SetSignal("nCE",OUT,0);WD_Reset();
00107         GPIO2_IODIR     &=      0x00;
00108         SetSignal("nOE",OUT,0);WD_Reset();
00109         ret = GPIO2_IOPIN;WD_Reset();
00110         SetSignal("nCE",OUT,1);WD_Reset();
00111         SetSignal("nOE",OUT,1);WD_Reset();
00112         return ret;
00113 }
00114 
00115 uint32_t         ReadDB(uint32_t address){
00116         ReadDBStart(address);return ReadDBEnd();
00117 }
00118 
00119 void             ReadDBStart(uint32_t address){//Read Data bus
00120                 SetSignal("nWE",OUT,1);
00121                 SetSignal("nCE",OUT,1);
00122                 SetSignal("nCE",OUT,0);
00123                 SetGPIOAddress((address));
00124                 SetSignal("nOE", OUT, 0);
00125 }
00126 uint32_t         ReadDBEnd(void){
00127                 uint32_t ret=GPIO2_IOPIN;
00128                 SetSignal("nOE", OUT, 1);
00129                 SetSignal("nCE", OUT, 1);
00130                 return ret;
00131 }
00132 
00133 pJEDEC           detect_jedec(void){
00134         pJEDEC  jedec={0,0};
00135         MemGPIOInit();
00136         SetGPIO_AD(0,0x9090);   //JEDEC
00137         jedec.sManufacturer     =       (ReadDB((0 << AB_LSB_16)) & 0xFF);
00138         jedec.sDevice           =       (ReadDB((1 << AB_LSB_16)) & 0xFF);
00139         return  jedec;
00140 }
00141 
00142 pCFI             detect_cfi(void){
00143         pCFI    cfi={0,0,0};
00144         MemGPIOInit();
00145         SetSignal("nCE",OUT,1);
00146         SetGPIOAddress((0x55 << AB_LSB_16));WD_Reset();
00147         SetSignal("nCE",OUT,0);WD_Reset();
00148         SetSignal("nWE",OUT,0);WD_Reset();
00149         SetGPIOData(0x98);WD_Reset();
00150         SetSignal("nWE",OUT,1);WD_Reset();
00151         SetSignal("nCE",OUT,1);WD_Reset();
00152 #if 0
00153                 printf("\n\r\t%c",(cfi.sQ=ReadNext((0x10 << AB_LSB_16))));WD_Reset();
00154                 printf("%c",(cfi.sR=ReadNext((0x11 << AB_LSB_16))));WD_Reset();
00155                 printf("%c",(cfi.sY=ReadNext((0x12 << AB_LSB_16))));WD_Reset();
00156 #else
00157                 cfi.sQ=ReadDB((0x10 << AB_LSB_16));WD_Reset();
00158                 cfi.sR=ReadNext((0x11 << AB_LSB_16));WD_Reset();
00159                 cfi.sY=ReadNext((0x12 << AB_LSB_16));WD_Reset();
00160                 cfi.qsi.vcc_min_wev = ReadNext((0x1B << AB_LSB_16));WD_Reset();
00161                 cfi.qsi.vcc_max_wev = ReadNext((0x1C << AB_LSB_16));WD_Reset();
00162 #endif
00163         return cfi;
00164 }

Generated on Fri Sep 21 13:41:54 2007 for example1 by  doxygen 1.4.7