flash_test_simple.c

来自「压缩包内包含了:FPGA设计初级班和提高班培训课堂PPT;实验的源代码;实验指导」· C语言 代码 · 共 38 行

C
38
字号
#include <stdio.h>
#include <string.h>
#include "sys/alt_flash.h"
#define BUF_SIZE 30
int main ()
{
alt_flash_fd* fd;
int ret_code;
char source[BUF_SIZE]="welcome to red logic world";
printf("the source is:%s\n",source);
char dest[BUF_SIZE];
/* Initialize the source buffer to all 0xAA */
//memset(source, 0xa, BUF_SIZE);
fd = alt_flash_open_dev("/dev/ext_flash");
if (fd)
{
  printf("flash open success.\n");
  ret_code = alt_write_flash(fd, 0, source, BUF_SIZE);
  if (!ret_code)
  {
    printf("data write to flash success.\n");
    ret_code = alt_read_flash(fd, 0, dest, BUF_SIZE);
    if (!ret_code)
    {
      printf("data read Success.\n");
      printf("data read is:");
      printf("%s\n",dest);
      printf("flash_test_simple end\n");
    }
  }   
  alt_flash_close_dev(fd);
}
else
{
printf("Can't open flash device\n");
}
return 0;
}

⌨️ 快捷键说明

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