Storage operations of EPCS configuration chip in NIOS II soft core[Copy link]
The video image overlay board made with CYCLONE FPGA needs to store some user configuration information. In addition to storing FPGA configuration information and NIOS II programs, the EPCS4 configuration chip has a lot of unused storage space, which can be used to store user configuration information. I spent a long time and read a lot of documents, but they only mentioned that the HAL function provided by ALTERA can be used to call EPCS related functions. In the end, I had to bite the bullet and read the "altera_avalon_epcs_flash_controller.c" function (path: \\altera\72\ip\sopc_builder_ip\altera_avalon_epcs_flash_controller\HAL\src). After reading it for two days, some parameters are still not very clear. Fortunately, I found a post written by a foreigner about the operation of CPCS devices under NIOS II. It took him more than a month to figure out how to operate it, and then gave a simple example. As he said in his post, I found his post, "very lucky". Maybe he used an earlier version of NIOS IDE, so some functions were not available to him at that time, and he needed to make some modifications and adjustments to it and the program. His post was written very simply, but it provided me with important information and saved me a lot of time. Experience is like this. Things that you have spent a lot of time to gain, you receive them in your own box and hide them. It is your own small wealth, and maybe you will never play its value again. But if you love it, write it out and copy it countless times, so that it can play its value as much as possible. J Haha, no more nonsense, let's get to the point. First take a look at this simple program #include#include #include "system.h" #include "alt_types.h" #include "sys/alt_flash.h" #include "sys/alt_flash_dev.h" alt_u8 epcsbuf[32]; int ret_code; alt_flash_fd* my_epcs;//Define handle main() {[/size ] my_epcs = alt_flash_open_dev("/dev/epcs_controller");//Open the FLASH device and get the handle ret_code = alt_epcs_flash_get_info (my_epcs, ions, &number_of_regions);//Get configuration chip information if(my_epcs) //Information obtained successfully { [size =4] //example application, read general data from epcs address 0x70000 ret_code = alt_epcs_flash_erase_block(my_epcs, regions->offset+0x70000); //Erase the 8th block ret_code = alt_epcs_flash_write(my_epcs, regions->offset+0x70000, epcsbuf, 32); //Write 32 Bytes ret_code = alt_epcs_flash_read(my_epcs, regions->offset+0x70000, epcsbuf, 32); //Read 32 bytes } while(1) { } } The above program is the process and method of operating the EPCS configuration chip. First, open the device and obtain the handle my_epcs , and then the read, write and erase operations are all operated through the handle my_epcs. The "epcs_controller" in "/dev/epcs_controller" is named by the user when configuring the NIOS core, which can be found in system.h, that is, "EPCS_CONTROLLER_NAME". You can view the FLASH related parameters pointed to by my_epcs through IDE debugging. EPCS devices have only one region (regions), and there are 8 blocks (blocks) in the EPCS4 region, each block is 65536 bytes. (Note: Only EPCS1 has 32768 bytes per block, and the rest of the configuration chips have 65536 bytes per block.) alt_epcs_flash_erase_block(my_epcs, regions->offset+0x70000); // Erase 8th This function is used to erase the entire block. The first parameter is the handle just obtained, which is used to indicate that the FLASH just opened is to be erased. The second parameter is regions->offset. The value is actually 0, which is managed by the EPCS control module itself. The FPGA configuration file and the program in the NIOS core are stored from the front, that is, from the address starting from regions->offset+0x00000. I used less than 4 Blocks, there are 4 blocks left for custom storage. To facilitate future functional expansion, try to keep low blocks free for future use, and give priority to using high address space (block 8, starting address is regions->offset+ 0x70000) to store user configuration information. alt_epcs_flash_write(my_epcs, regions->offset+0x70000, epcsbuf, 32); //Write 32 bytes alt_epcs_flash_write(my_epcs, regions->offset+0x70000, epcsbuf, 32); //Write 32 bytes If the address is 0x100 in block 6, then regions->offset+0x60100 can be used instead of regions->offset+0x70000. 4] alt_epcs_flash_read(my_epcs, regions->offset+0x70000, epcsbuf, 32); //Read 32 bytes Read continuous data from the starting point of the 8th segment in EPCS4 regions->offset+0x70000 32 bytes are stored in the epcsbuf array. During debugging, you can manually modify the values in the epcsbuf array before executing alt_epcs_flash_write, and change the values in the epcsbuf array to other values before executing alt_epcs_flash_read. If the values in the epcsbuf array are restored after executing alt_epcs_flash_read, To the value before executing alt_epcs_flash_write, the read and write operations on the EPCS chip have been successful.