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

📄 main.cpp

📁 基于FPGA的SD控制器实现.目前实现读操作功能,可作参考.
💻 CPP
字号:
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <io.h>
#include "system.h"
#include "alt_types.h"
#include "sys/alt_irq.h"
#include "sys/alt_dma.h"


int ready=0;

//SD
void *psd = (void*) SD_BASE;
void isr_sd(void* context, alt_u32 id);

unsigned int buf[1024000];
unsigned int zerro[512];
int sdrdy=1;
unsigned int ardy=0, sdk=0;
int bn=0, b1e=1, b2e=1, an=0;


int main(void) 
{
  int i,j, j1, i1, i2, j2, k=0, f=0;
  unsigned short* scr2;
  unsigned int block=459;
  unsigned short colour;
  
  
  alt_irq_register(SD_IRQ, psd, isr_sd);
  .......
  
  //A small pause before a reading of the SD
  for(i=0;i<100000;i++) k++;
  //Is the SD card ready?
  while ((IORD(SD_BASE, 2))!=0x900) printf("%08x\n", IORD(SD_BASE, 2));
  printf("\n%08x\n", IORD(SD_BASE, 2));

  sdrdy = 0;
  k=0;
  printf("Start reading\n");
  //Reading from first sector of ROOT directory, data block length is 8000 sectors
  for (block=551; block < 8550; block ++) {
    IOWR(SD_BASE, 0, (int) &buf[k]);
    IOWR(SD_BASE, 3, (block << 4) | 0x1);
    sdrdy = 0;
    //printf("**************Sector: %d***************\n", block);  
    while (!sdrdy) f++;
    k+=128;
  }
  printf("Data was read\n");
  ......
  return 0;
}


void isr_sd(void* context, alt_u32 id)
{
  IOWR(SD_BASE, 1, 0); 
  sdrdy = 1; 
}


⌨️ 快捷键说明

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