// This Code is for Read, Write and Erase
#include "xparameters.h"
#include "stdio.h"
#include "xutil.h"
#include "xuartlite_l.h"
#include "xio.h"
//#include "xgpio_l.h"
main()
{
Xuint16 send_emc16;
Xuint16 read_emc16;
Xuint8 read_uart_command,send_emc1,send_emc2,read_emc1,read_emc2;
int i,addr_c,addr_c1,j,l,k,m;
xil_printf("\n\rFlash read write erase\n\r");
while(1)
{
//XGpio_mSetDataReg(0x40000000, 1, 0); // ADV and clk GPIO_0
//Waiting for Command
read_uart_command = XUartLite_RecvByte ( XPAR_RS232_PORT_BASEADDR ) ; // UART
//unlocking blocks
if(read_uart_command == '~')
{
addr_c = XPAR_INTEL_FLASH_MEM0_BASEADDR;
for(i=0;i<4;i++)
{
XIo_Out16(addr_c, 0x60);
XIo_Out16(addr_c, 0xD0);
for(j=0;j<1000000;j++);
XIo_Out16(XPAR_INTEL_FLASH_MEM0_BASEADDR, 0x90);
read_emc16 = XIo_In16 (XPAR_INTEL_FLASH_MEM0_BASEADDR + 0x02);
xil_printf("\n\r0x%x ", read_emc16);
addr_c = addr_c + 0x4000;
}
xil_printf("\n\rFINISHED Unblocking\n\r");
}
//erasing FLASH
if(read_uart_command == '!')
{
XIo_Out16(XPAR_INTEL_FLASH_MEM0_BASEADDR, 0x20);
XIo_Out16(XPAR_INTEL_FLASH_MEM0_BASEADDR, 0xD0);
xil_printf("\n\rErasing FLASH\n\r"); // all loops below this line are written to provide delay and
for(l=0;l<1;l++) // formatting for ERASE operation only
{
for(j=0;j<6;j++)
{
for(k=0;k<5;k++)
{
xil_printf(".");
for(m=0;m<100000;m++);
}
xil_printf("\n\b\b\b\b\b");
}
}
xil_printf("\n\rFINISHED Erasing\n\r");
}
//reading flash
if(read_uart_command == '@')
{
xil_printf("\n\rreading flash\n\r");
addr_c = XPAR_INTEL_FLASH_MEM0_BASEADDR ;
//command
for(i=0;i<1000000;i++)
{
XIo_Out16 (addr_c, 0xFF);
}
// reading logic
for(i=0;i<3000;i++)
{
read_emc16 = XIo_In16 (addr_c);
read_emc1 = read_emc16;
read_emc2 = read_emc16 >> 8;
xil_printf("%d\n", read_emc1);
xil_printf("%d\n", read_emc2);
addr_c = addr_c + 2;
}
}
// writing FLASH
if(read_uart_command == '#')
{
xil_printf("\r\nWriting Flash chip");
addr_c = XPAR_INTEL_FLASH_MEM0_BASEADDR ;
for(i=0;i<3000;i++)
{
// send_emc1 = XUartLite_RecvByte (XPAR_RS232_PORT_BASEADDR);
// send_emc2 = XUartLite_RecvByte (XPAR_RS232_PORT_BASEADDR);
send_emc1 = 1;
send_emc2 = 2;
send_emc16 = ((send_emc1) | (send_emc2 << 8));
XIo_Out16 (addr_c, 0x40);
XIo_Out16 (addr_c, send_emc16);
addr_c = addr_c + 2;
for(m=0;m<100;m++);
}
xil_printf("\n\rFINISHED Writing\n\r");
}
//Status register data
if(read_uart_command == '$')
{
xil_printf("\r\nReading Status register data");
//XIo_Out16 (0x86000000, 0x70);
read_emc16 = XIo_In16 (0x86000000+0x00011);
xil_printf("\n\r0x%x ", read_emc16);
}
}// end while
}// end main()
Flash_Ram Iras es olvasas
- 4:58
- Write comment
Ki is mondta azt, hogy nem lehet a Flash Ramot programbol írni???
Feliratkozás:
Megjegyzések küldése (Atom)
0 megjegyzés:
Megjegyzés küldése