⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 code_to_spi.c

📁 此文档为采用FPGA实现的以太网MAC层
💻 C
字号:
// code_to_asmi.c// Jeremy Fox, Altera UK// 4/16/03// Use this file to copy code from a RAM buffer into the EPCS4 flash device on the Nios cyclone// development board.  This code defaults to copying 0x10000 bytes or code from 0x00800000 (which// is assumed to be SRAM) to the ASMI device.  Other buffer locations can be chosen if desired by// modifying the buffer_base #define to a different memory region.//// Important things to NOTE://// 1) Before downloading this code to the dev board you should have the code that you want to store// in the ASMI flash device already loaded into memory at the address indicated by the "buffer_base" // #define in this file.//// 2) When compiling this code it would be wise to use the nb -b option and have it compiled somewhere// other than the default base address of 0x00800000 as that is where the code we are going to copy// to the ASMI is assumed to be.  A likely place to run this code would be from SDRAM, ie..// use nb -b 0x01000000 code_to_asmi.c#include "excalibur.h"#include <stdio.h>#include "asmi_spi.h"extern int nr_jumptostart;unsigned char* error_string(int error_code){  switch (error_code)  {    case na_asmi_success: return "na_asmi_success";    case na_asmi_err_device_not_present: return "na_asmi_err_device_not_present";    case na_asmi_err_device_not_ready: return "na_asmi_err_device_not_ready";    case na_asmi_err_timedout: return "na_asmi_err_timedout";    case na_asmi_err_write_failed: return "na_asmi_err_write_failed";    case na_asmi_invalid_config: return "na_asmi_invalid_config";  }  return "unknown error code";}int main(void){	int s = 0;	volatile char buf[16];	for (s=0;s<16;s++) buf[s]=s*3;  // write the code and the header to the ASMI flash  //User code goes from offset 0 to offset na_sram_size - 0x1000	printf("Program base is at %X\n",&nr_jumptostart);  printf("Erasing Flash\n");  s = nr_spi_erase_bulk();  if (na_asmi_success != s)  {    printf("nr_asmi_erase_bulk() failed ('%s').\n\004", error_string(s));    return 0;  }  printf("Writing user code from RAM address %X to Flash address %X\n",usercode_base,flash_base);  printf("Code size: %X\n",usercode_size);  s = nr_spi_write_buffer(flash_base, usercode_size, usercode_base);     if (na_asmi_success != s)  {    printf("nr_spi_write_buffer() failed ('%s').\n\004", error_string(s));    return 0;  }  printf("Writing trailing header\n");  s = nr_spi_write_buffer(flash_base+usercode_size, 0x10, buf);   if (na_asmi_success != s)  {    printf("nr_spi_write_buffer() failed ('%s').\n\004", error_string(s));    return 0;  }  // read back the header just to check that I got written to the ASMI properly.  printf("reading back data header...\n");  s = nr_spi_read_buffer(flash_base+usercode_size, 16, buf);  printf("0x%X\n" ,buf[0]);  printf("0x%X\n" ,buf[4]);  printf("0x%X\n" ,buf[8]);  printf("0x%X\n" ,buf[12]);  if (na_asmi_success != s)  {    printf("nr_spi_read_buffer() failed ('%s').\n\004", error_string(s));    return 0;  }	return 0;}// end of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -