这个程序为什么只有最后读出来的数才是正确的呢?是FLASH没写进去 #include "C2DSP_board_diag_std.h" #define DATA_OFFSET 0x0 #define DATA_OFFSET1 0x100 #define DATA_OFFSET2 0x200 #define ALT_STDIN "/dev/jtag_uart" #define EPCS_CONTROLLER_NAME "/dev/epcs_controller" alt_flash_fd* flash_handle; int main() { int A,B,y=0; alt_u16 a=10; alt_u16 b=20; alt_u16 x=30; // alt_u16 par[3]={10,20,30}; int *read_data=0; volatile int *q,*p = 0; IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xff); // init leds off IOWR_ALTERA_AVALON_PIO_DATA(SEVEN_SEG_PIO_BASE, 0xffff); // init hex display off //向FLASH中写数 flash_handle = alt_flash_open_dev(EPCS_CONTROLLER_NAME); usleep(10000); if(flash_handle) { printf("open flash device successed!!!\n"); usleep(10000); alt_write_flash(flash_handle, DATA_OFFSET, &a, 1); printf( "wirte_data = %d\n", a); usleep(10000); alt_write_flash(flash_handle, DATA_OFFSET1, &b, 1); printf( "wirte_data = %d\n", b); usleep(10000); alt_write_flash(flash_handle, DATA_OFFSET2, &x, 1); printf( "wirte_data = %d\n", x); usleep(10000); a=0;b=0;x=0; alt_read_flash(flash_handle, DATA_OFFSET, &a, 1); printf("read_data = %d\n", a); usleep(50000); alt_read_flash(flash_handle, DATA_OFFSET1, &b, 1); printf("read_data = %d\n", b); usleep(50000); alt_read_flash(flash_handle, DATA_OFFSET2, &x, 1); printf("read_data = %d\n", x); usleep(10000); // alt_write_flash(flash_handle,DATA_OFFSET,par, 3); /* usleep(10000); alt_write_flash(flash_handle,0,&a, 1); usleep(10000); alt_write_flash(flash_handle,1,&b, 1); usleep(10000); alt_write_flash(flash_handle,2,&x, 1); usleep(10000);
//读取FLASH // alt_read_flash(flash_handle, DATA_OFFSET, read_data, 3); alt_read_flash(flash_handle, 0, read_data, 1); printf(" a= %d\n", *read_data); usleep(10000); /* alt_read_flash(flash_handle, 1, read_data, 1); printf(" b= %d\n", *read_data); usleep(10000); alt_read_flash(flash_handle, 2, read_data, 1); printf(" x= %d\n", *read_data); usleep(10000); */ alt_flash_close_dev(flash_handle); printf("close flash device...\n"); //写入SDRAM p = (int*)( DDR2_SDRAM_BASE ); // DDR2_SDRAM_BASE 0x04000000 DDR2_SDRAM_SPAN q=p; *q++=*read_data++; *q++=*read_data++; *q++=*read_data++; //从SDRAM中读出 A=*p++; B=*p++; x=*p; y=A*x+B; printf(" y= %d\n", y); } else { printf( "open flash device failed!!!\n"); } return( 0 ); }
|