If you are wondering how to access the EPCS from the NIOS II directly, you have come to the right place. I believe you might have tried to read the NIOS II handbook that covers almost 600 pages to find out the answer. Nevertheless, it seems like there is no straight answer to the question in the NIOS II handbook. You might have even tried to look into the?Software Files?mentioned in the chapter named?EPCS Device Controller Core with Avalon Interface, which are?altera_avalon_epcs_controller_flash.c,altera_avalon_epcs_controller_flash.h,?epcs_commands.c?andepcs_commands.h. However, still, none of these files give you much clue how to access the EPCS from the NIOS II processor.
In fact, the handler that gives you the access to the EPCS device is notalt_flash_epcs_dev?(as you see inaltera_avalon_epcs_controller_flash.h), but?alt_flash_fd, which is the exact same handler that you use to access the common flash device like Spansion and Intel flash device. To my surprise, the NIOS II handbook does not mention about this. Perhaps this is a common sense to everybody else that the Spansion/Intel flash and the SPI Serial Flash should have a same handler, but NOT to a dummy user like me! After asking around, I believe I am not the only one who thinks like this! Therefore, I still see that there is some room for improvement in the next version of NIOS II handbook. Not every NIOS II user is a hardware designer. Not every NIOS II user is a software developer, either. Some NIOS II users like me have to do co-hardware/software design and development at the same time. Sometimes I just feel that the handbook couldn’t link me very well between?the hardware and software. For an example, my earlier frustration could have been resolved if there is a small piece of C code like the following included in the Chapter 3 of the Quartus II Handbook Volume 5 (a.k.a. NIOS II Handbook Volume 3).
//////////////////////////////////////////// // hello_epcs.cpp // date created: March 30, 2006 // author:?http://fpgaforum.blogspot.com //////////////////////////////////////////// #include?<iostream> #include?"system.h" #include?"sys/alt_flash.h" #include?"sys/alt_flash_dev.h" using namespace?std;
//check your (EPCS_CONTROLLER_NAME) from system.h my_epcs = alt_flash_open_dev(EPCS_CONTROLLER_NAME);
if(my_epcs) { ?? ?cout << "EPCS opened successfully!" << endl;
??//example application, read general data from epcs address 0x70000 int ?ret_code = alt_read_flash(my_epcs, 0x70000, my_data, 256); if(!ret_code) { ?? ? ? cout << my_data << endl; ?? ? ?return ?0; } else ?? ? ?return?-1; } else { ?? ?cout << "Error! EPCS not opened!" << endl; ?? ?return?-2; } } // The end /////////////////////////////////////////////////////////
Anyway, I just found out that if you are lucky, you might still be able to find out the code very similar like above from the software example calledmemtest.c?in the?<NIOS II Path>\examples\software\memtest?folder. By the way, you can only view the code after installing the NIOS II software tool.
用户240125 2010-1-29 00:33