示例#1
0
int do_fpga (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
    ulong addr = 0;
    int i;
    fpga_t* fpga;

    if (argc < 2)
	goto failure;

    if (strncmp(argv[1], "stat", 4) == 0) {		/* status */
	if (argc == 2) {
	    for (i = 0; i < fpga_count; i++) {
		fpga_status (&fpga_list[i]);
	    }
	}
	else if (argc == 3) {
	    if ((fpga = fpga_get(argv[2])) == 0)
		goto failure;
	    fpga_status (fpga);
	}
	else
	    goto failure;
    }
    else if (strcmp(argv[1],"load") == 0) {		/* load */
	if (argc == 3 && fpga_count == 1) {
	    fpga = &fpga_list[0];
	}
	else if (argc == 4) {
	    if ((fpga = fpga_get(argv[2])) == 0)
		goto failure;
	}
	else
	    goto failure;

	addr = simple_strtoul(argv[argc-1], NULL, 16);

	printf ("FPGA load %s: addr %08lx: ",
		fpga->name, addr);
	fpga_load (fpga, addr, 1);

    }
    else if (strncmp(argv[1], "rese", 4) == 0) {	/* reset */
	if (argc == 2 && fpga_count == 1) {
	    fpga = &fpga_list[0];
	}
	else if (argc == 3) {
	    if ((fpga = fpga_get(argv[2])) == 0)
		goto failure;
	}
	else
	    goto failure;

	printf ("FPGA reset %s: ", fpga->name);
	if (fpga_reset(fpga))
	    printf ("ERROR: Timeout\n");
	else
	    printf ("done\n");
    }
    else
	goto failure;

    return 0;

 failure:
    printf ("Usage:\n%s\n", cmdtp->usage);
    return 1;
}
示例#2
0
文件: msu1.c 项目: 69yuan/sd2snes
int msu1_loop() {
/* it is assumed that the MSU file is already opened by calling msu1_check(). */
  set_dac_vol(0x00);
  while(fpga_status() & 0x4000);
  uint16_t dac_addr = 0;
  uint16_t msu_addr = 0;
  uint8_t msu_repeat = 0;
  uint16_t msu_track = 0;
  uint32_t msu_offset = 0;
  fpga_status_prev = fpga_status();
  fpga_status_now = fpga_status();
  int msu_res;

/*  set_msu_addr(0x0);
  msu_reset(0x0);
  ff_sd_offload=1;
  sd_offload_tgt=2;
  f_lseek(&msufile, 0L);
  ff_sd_offload=1;
  sd_offload_tgt=2;
  f_read(&msufile, file_buf, 16384, &msu_data_bytes_read);
*/
  set_dac_addr(dac_addr);
  dac_pause();
  dac_reset();

  set_msu_addr(0x0);
  msu_reset(0x0);
  ff_sd_offload=1;
  sd_offload_tgt=2;
  f_lseek(&msufile, 0L);
  ff_sd_offload=1;
  sd_offload_tgt=2;
  f_read(&msufile, file_buf, 16384, &msu_data_bytes_read);

  prepare_audio_track(0);
  prepare_data(0);
/* audio_start, data_start, 0, audio_ctrl[1:0], ctrl_start */
  while((msu_res = msu1_check_reset()) == MSU_RESET_NONE){
    cli_entrycheck();
    fpga_status_now = fpga_status();

    /* Data buffer refill */
    if((fpga_status_now & 0x2000) != (fpga_status_prev & 0x2000)) {
      DBG_MSU1 printf("data\n");
      uint8_t pageno = 0;
      if(fpga_status_now & 0x2000) {
        msu_addr = 0x0;
        msu_page1_start = msu_page2_start + msu_page_size;
        pageno = 1;
      } else {
        msu_addr = 0x2000;
        msu_page2_start = msu_page1_start + msu_page_size;
        pageno = 2;
      }
      set_msu_addr(msu_addr);
      sd_offload_tgt=2;
      ff_sd_offload=1;
      msu_res = f_read(&msufile, file_buf, 8192, &msu_data_bytes_read);
      DBG_MSU1 printf("data buffer refilled. res=%d page1=%08lx page2=%08lx\n", msu_res, msu_page1_start, msu_page2_start);
    }

    /* Audio buffer refill */
    if((fpga_status_now & 0x4000) != (fpga_status_prev & 0x4000)) {
      if(fpga_status_now & 0x4000) {
        dac_addr = 0;
      } else {
        dac_addr = MSU_DAC_BUFSIZE/2;
      }
      set_dac_addr(dac_addr);
      sd_offload_tgt=1;
      ff_sd_offload=1;
      f_read(&file_handle, file_buf, MSU_DAC_BUFSIZE/2, &msu_audio_bytes_read);
    }

    if(fpga_status_now & 0x0020) {
      /* get trackno */
      msu_track = get_msu_track();
      DBG_MSU1 printf("Audio requested! Track=%d\n", msu_track);

      prepare_audio_track(msu_track);
    }

    if(fpga_status_now & 0x0010) {
      /* get address */
      msu_offset=get_msu_offset();
      prepare_data(msu_offset);
    }

    if(fpga_status_now & 0x0001) {
      if(fpga_status_now & 0x0004) {
        msu_repeat = 1;
        set_msu_status(0x04, 0x01); /* set bit 2, reset bit 0 */
        DBG_MSU1 printf("Repeat set!\n");
      } else {
        msu_repeat = 0;
        set_msu_status(0x00, 0x05); /* set no bits, reset bit 0+2 */
        DBG_MSU1 printf("Repeat clear!\n");
      }

      if(fpga_status_now & 0x0002) {
        DBG_MSU1 printf("PLAY!\n");
        set_msu_status(0x02, 0x01); /* set bit 0, reset bit 1 */
        dac_play();
      } else {
        DBG_MSU1 printf("PAUSE!\n");
        set_msu_status(0x00, 0x03); /* set no bits, reset bit 1+0 */
        dac_pause();
      }
    }

    fpga_status_prev = fpga_status_now;

    /* handle loop / end */
    if(msu_audio_bytes_read < MSU_DAC_BUFSIZE / 2) {
      ff_sd_offload=0;
      sd_offload=0;
      if(msu_repeat) {
        DBG_MSU1 printf("loop\n");
        ff_sd_offload=1;
        sd_offload_tgt=1;
        f_lseek(&file_handle, 8L+msu_loop_point*4);
        ff_sd_offload=1;
        sd_offload_tgt=1;
        f_read(&file_handle, file_buf, (MSU_DAC_BUFSIZE / 2) - msu_audio_bytes_read, &msu_audio_bytes_read);
      } else {
        set_msu_status(0x00, 0x02); /* clear play bit */
        dac_pause();
      }
      msu_audio_bytes_read = MSU_DAC_BUFSIZE;
    }
  }
  f_close(&file_handle);
  DBG_MSU1 printf("Reset ");
  if(msu_res == MSU_RESET_LONG) {
    f_close(&msufile);
    DBG_MSU1 printf("to menu\n");
    return 1;
  }
  DBG_MSU1 printf("game\n");
  return 0;
}
示例#3
0
文件: spi.c 项目: hitomi2500/SAROO
void fpga_config(void)
{
	FIL fp;
	int i, retv, addr;
	u32 rv;
	u8 fbuf[256];

	// 检查是否有升级文件. 如果有,就升级. 如果没有,就继续.
	retv = f_open(&fp, "/SSMaster.rbf", FA_READ);
	if(retv){
		printk("NO FPGA config file found!\n");
		return;
	}

	printk("Found FPGA config file.\n");
	printk("    Size %08x\n", f_size(&fp));

	// 发现升级文件
	spi1_init();

	// 启动配置
	fpga_set_config(0);
	os_dly_wait(1);
	fpga_set_config(1);
	while(fpga_status()==1);
	os_dly_wait(1);

	// 写配置数据
	for(addr=0; addr<f_size(&fp); addr+=256){
		rv = 0;
		f_read(&fp, fbuf, 256, &rv);
		for(i=0; i<rv; i++){
			spi1_trans(fbuf[i]);
		}
	}
	spi1_trans(0xff);


	// 等待FPGA配置完成
	for(i=0; i<10; i++){
		if(fpga_config_done())
			break;
		os_dly_wait(10);
	}
	if(i==10){
		printk("FPGA config timeout!\n");
	}else{
		printk("FPGA config done!\n");
	}

	for(i=0; i<10; i++){
		if(fpga_init_done())
			break;
		os_dly_wait(10);
	}
	if(i==10){
		printk("FPGA init timeout!\n");
	}else{
		printk("FPGA init done!\n");
	}

	// 关闭升级文件
	f_close(&fp);

	// FPGA_nRESET = 1;
	GPIOC->BSRR = 0x0020;

	printk("FPGA state:\n");
	printk("    config done: %d\n", fpga_config_done());
	printk("      init done: %d\n", fpga_init_done());
	printk("         status: %d\n", fpga_status());
	printk("\n");

}