00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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){
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){
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)
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)
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
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){
00077 short i;
00078 PCB_PINSEL2 &= 0xF07C163B;
00079 PCB_PINSEL2 |= ((1 << 5)|(1 << 4));
00080
00081 GPIO3_IODIR = 0xFFFFFFF;
00082 GPIO3_IOCLR = 0xFFFFFFF;
00083
00084 GPIO1_IODIR |= ((1 << 0)|(1 << 1));
00085
00086 GPIO2_IODIR |= 0xFFFF;
00087 GPIO2_IOCLR |= 0xFFFF;
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;
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){
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);
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 }