コード例 #1
0
ファイル: progalgxc3s.cpp プロジェクト: Linux-enCaja/SIE
int ProgAlgXC3S::program(BitFile &file)
{
  jtag->shiftIR(&JPROGRAM);
  jtag->shiftIR(&CFG_IN);
  
  byte init[24];
  jtag->longToByteArray(0xffffffff,&init[0]); // Sync
  jtag->longToByteArray(0x66aa9955,&init[4]); // Sync
  jtag->longToByteArray(0x8001000c,&init[8]); // CMD
  jtag->longToByteArray(0xe0000000,&init[12]); // Clear CRC
  jtag->longToByteArray(0x00000000,&init[16]); // Flush
  jtag->longToByteArray(0x00000000,&init[20]); // Flush
  jtag->shiftDR(init,0,192,32); // Align to 32 bits.
  jtag->shiftIR(&JSHUTDOWN);
  io->cycleTCK(12);
  jtag->shiftIR(&CFG_IN);
  
  byte hdr[12];
  jtag->longToByteArray(0x8001000c,&hdr[0]); // CMD
  jtag->longToByteArray(0x10000000,&hdr[4]); // Assert GHIGH
  jtag->longToByteArray(0x00000000,&hdr[8]); // Flush
  jtag->shiftDR(hdr,0,96,32,false); // Align to 32 bits and do not goto EXIT1-DR
  jtag->shiftDR(file.getData(),0,file.getLength()); 
  io->tapTestLogicReset();
  io->setTapState(IOBase::RUN_TEST_IDLE);
  jtag->shiftIR(&JSTART);
  io->cycleTCK(12);
  jtag->shiftIR(&BYPASS); // Don't know why, but without this the FPGA will not reconfigure from Flash when PROG is asserted.
  printf("Done\n");
}
コード例 #2
0
void ProgAlgXC3S::flow_program_legacy(BitFile &file)
{
  byte data[2];
  struct timeval tv[2];
  gettimeofday(tv, NULL);

  jtag->shiftIR(&JSHUTDOWN);
  io->cycleTCK(tck_len);
  jtag->shiftIR(&CFG_IN);
  jtag->shiftDR((file.getData()),0,file.getLength());
  io->cycleTCK(1);
  jtag->shiftIR(&JSTART);
  io->cycleTCK(2*tck_len);
  jtag->shiftIR(&BYPASS);
  data[0]=0x0;
  jtag->shiftDR(data,0,1);
  io->cycleTCK(1);

  // Print the timing summary
  if (io->getVerbose())
    {
      gettimeofday(tv+1, NULL);
      printf("Done.\nProgramming time %.1f ms\n", (double)deltaT(tv, tv + 1)/1.0e3);
    }

}
コード例 #3
0
ファイル: progalgxc3s.cpp プロジェクト: ConicLabs/cl-xc3sprog
void ProgAlgXC3S::flow_program_legacy(BitFile &file)
{
  Timer timer;
  byte data[2];

  jtag->shiftIR(JSHUTDOWN);
  jtag->cycleTCK(tck_len);
  jtag->shiftIR(CFG_IN);
  jtag->shiftDR((file.getData()),0,file.getLength());
  jtag->cycleTCK(1);
  jtag->shiftIR(JSTART);
  jtag->cycleTCK(2*tck_len);
  jtag->shiftIR(BYPASS);
  data[0]=0x0;
  jtag->shiftDR(data,0,1);
  jtag->cycleTCK(1);
  
  // Print the timing summary
  if (jtag->getVerbose())
    {
      fprintf(stderr, "done. Programming time %.1f ms\n",
	      timer.elapsed() * 1000);
    }
 
}
コード例 #4
0
ファイル: progalgxc3s.cpp プロジェクト: ConicLabs/cl-xc3sprog
void ProgAlgXC3S::flow_program_xc2s(BitFile &file)
{
    byte data[2];
    byte xc2sbuf0[] =
        {
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00,
            0x55, 0x99, 0xaa, 0x66,
            0x0c, 0x80, 0x04, 0x80, /*Header: Write to COR*/
            0x00, 0x05, 0xfd, 0xbc, /* OR data sets SHUTDOWN = 1 */
            0x0c, 0x00, 0x01, 0x80, /*-> Header: Write to CMD*/
            0x00, 0x00, 0x00, 0xa0, /*Start Shutdown*/
            0x0c, 0x00, 0x01, 0x80, /* Header: Write to CMD*/
            0x00, 0x00, 0x00, 0xe0, /*RCRC command*/
            0x00, 0x00, 0x00, 0x00
        };
    byte xc2sbuf1[] =
        {
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00,
            0x55, 0x99, 0xaa, 0x66,
            0x0c, 0x00, 0x01, 0x80, /* Header: Write to CMD*/
            0x00, 0x00, 0x00, 0x10, /* Assert GHIGH */
            0x0c, 0x80, 0x04, 0x80, /*Header: Write to COR*/
            0x00, 0x05, 0xfc, 0xff, /* OR data sets SHUTDOWN = 0 */
            0x0c, 0x00, 0x01, 0x80, /* Header: Write to CMD*/
            0x00, 0x00, 0x00, 0xa0, /*Start command*/
            0x0c, 0x00, 0x01, 0x80, /* Header: Write to CMD*/
            0x00, 0x00, 0x00, 0xe0, /*RCRC command*/
            0x00, 0x00, 0x00, 0x00
        };
    jtag->shiftIR(CFG_IN);
    jtag->shiftDR(xc2sbuf0,0, sizeof(xc2sbuf0) *8);
    jtag->shiftIR(JSTART);
    jtag->cycleTCK(13);
    
    jtag->shiftIR(CFG_IN);
    jtag->shiftDR(xc2sbuf1,0, sizeof(xc2sbuf1) *8);
    jtag->shiftIR(JSTART);
    jtag->cycleTCK(13);
    
    jtag->shiftIR(CFG_IN);
    jtag->shiftDR(xc2sbuf0,0, sizeof(xc2sbuf0) *8);
    jtag->shiftIR(JSTART);
    jtag->cycleTCK(13);
    
    jtag->shiftIR(CFG_IN);
    jtag->shiftDR((file.getData()),0,file.getLength());
    jtag->cycleTCK(1);
    jtag->shiftIR(JSTART);
    jtag->cycleTCK(13);
    jtag->shiftIR(BYPASS);
    jtag->shiftDR(data,0,1);
    jtag->cycleTCK(1);
    return;
  }
コード例 #5
0
int main(int argc, char**args)
{
  BitFile file;
  if(argc>1){
    int length=file.load(args[1]);
    
    file.getData();
    if(length>0){
      printf("Created from NCD file: %s\n",file.getNCDFilename());
      printf("Target device: %s\n",file.getPartName());
      printf("Created: %s %s\n",file.getDate(),file.getTime());
      printf("Bitstream length: %d bits\n",length);
    }
    else return 1;
  }
  if(argc>2)if(file.saveAsBin(args[2])>0)printf("Bitstream saved in binary format in file: %s\n",args[2]);
  if(argc<2){
    fprintf(stderr,"Usage: %s infile.bit [outfile.bin]\n",args[0]);
  }
}
コード例 #6
0
ファイル: progalgxc3s.cpp プロジェクト: ConicLabs/cl-xc3sprog
void ProgAlgXC3S::flow_array_program(BitFile &file)
{
  Timer timer;
  unsigned int i;
  for(i=0; i<file.getLength(); i += array_transfer_len)
    {
      jtag->shiftIR(ISC_PROGRAM);
      jtag->shiftDR(&(file.getData())[i/8],0,array_transfer_len);
      jtag->cycleTCK(1);
      if((i % (10000*array_transfer_len)) == 0)
	{
	  fprintf(stderr,".");
	  fflush(stderr);
	}
    }
  
  // Print the timing summary
  if (jtag->getVerbose())
    fprintf(stderr, " done. Programming time %.1f ms\n",
	    timer.elapsed() * 1000);
}
コード例 #7
0
void ProgAlgXC3S::flow_array_program(BitFile &file)
{
  struct timeval tv[2];
  unsigned int i;
  gettimeofday(tv, NULL);
  for(i=0; i<file.getLength(); i= i+ array_transfer_len)
    {
      jtag->shiftIR(&ISC_PROGRAM);
      jtag->shiftDR(&(file.getData())[i/8],0,array_transfer_len);
      io->cycleTCK(1);
      if((i % (10000*array_transfer_len)) == 0)
	{
	  fprintf(stdout,".");
	  fflush(stdout);
	}
    }
  gettimeofday(tv+1, NULL);

  // Print the timing summary
  if (io->getVerbose())
    printf(" Done.\nProgramming time %.1f ms\n", (double)deltaT(tv, tv + 1)/1.0e3);
}
コード例 #8
0
void process(IOBase &io, BitFile &file, int chainpos)
{
  const byte IDCODE=0x09;
  const byte XCF_IDCODE=0xfe;

  Jtag jtag(&io);
  int num=jtag.getChain();
  DeviceDB db(DEVICEDB);
  for(int i=0; i<num; i++){
    int length=db.loadDevice(jtag.getDeviceID(i));
    if(length>0)jtag.setDeviceIRLength(i,length);
    else{
      byte *id=jtag.getDeviceID(i);
      fprintf(stderr,"Cannot find device having IDCODE=%02x%02x%02x%02x\n",id[0],id[1],id[2],id[3]);
      return;
    }
  }
  

  byte tdo[4];

  if(jtag.selectDevice(chainpos)<0){
    fprintf(stderr,"Invalid chain position %d, position must be less than <%d.\n",chainpos,num);
    return;
  }

  jtag.shiftIR(&IDCODE);
  jtag.shiftDR(0,tdo,32);
  printf("IDCODE: 0x%02x%02x%02x%02x\tDesc: %s\n",tdo[0],tdo[1],tdo[2],tdo[3],db.getDeviceDescription(chainpos)); 

  const byte JPROGRAM=0x0b;
  const byte CFG_IN=0x05;
  const byte JSHUTDOWN=0x0d;
  const byte JSTART=0x0c;
  const byte BYPASS=0x3f;

  jtag.shiftIR(&JPROGRAM);
  jtag.shiftIR(&CFG_IN);
  byte init[]={0x00, 0x00, 0x00, 0x00, // Flush
	       0x00, 0x00, 0x00, 0x00, // Flush
	       0xe0, 0x00, 0x00, 0x00, // Clear CRC
	       0x80, 0x01, 0x00, 0x0c, // CMD
	       0x66, 0xAA, 0x99, 0x55, // Sync
	       0xff, 0xff, 0xff, 0xff  // Sync
  };
  jtag.shiftDR(init,0,192,32); // Align to 32 bits.
  jtag.shiftIR(&JSHUTDOWN);
  io.cycleTCK(12);
  jtag.shiftIR(&CFG_IN);
  byte hdr[]={0x00, 0x00, 0x00, 0x00, // Flush
	      0x10, 0x00, 0x00, 0x00, // Assert GHIGH
	      0x80, 0x01, 0x00, 0x0c  // CMD
  };
  jtag.shiftDR(hdr,0,96,32,false); // Align to 32 bits and do not goto EXIT1-DR
  jtag.shiftDR(file.getData(),0,file.getLength()); 
  io.tapTestLogicReset();
  io.setTapState(IOBase::RUN_TEST_IDLE);
  jtag.shiftIR(&JSTART);
  io.cycleTCK(12);
  jtag.shiftIR(&BYPASS); // Don't know why, but without this the FPGA will not reconfigure from Flash when PROG is asserted.
}
コード例 #9
0
int main(int argc, char**args)
{

  FILE_STYLE in_style  = STYLE_BIT;
  FILE_STYLE out_style = STYLE_BIT;
  uint64_t sum = 0L;
  unsigned int i;

  const char * outfile = NULL;
  while(true)
    {
      switch(getopt(argc, args, "?i:vo:O:"))
	{
	case -1: goto args_done;
	case 'i':
          if (BitFile::styleFromString(optarg, &in_style))
	    {
	      fprintf(stderr, "Unknown format \"%s\"\n", optarg);
	      usage();
	    }
	  break;

	case 'o':
          if (BitFile::styleFromString(optarg, &out_style))
	    {
	      fprintf(stderr, "Unknown format \"%s\"\n", optarg);
	      usage();
	    }
	  break;

	case 'O':
	  outfile = optarg;
	  break;
	case '?':
	case 'h':
	default:
	  usage();
	}
    }
 args_done:
  argc -= optind;
  args += optind;
  if(argc < 1)
    usage();
  try {
    BitFile  file;
    FILE* fp;

    if (*args[0] == '-')
      fp = stdin;
    else
      {
	fp=fopen(args[0],"rb");
	if(!fp)
	  {
	    fprintf(stderr, "Can't open datafile %s: %s\n", args[0], 
		    strerror(errno));
	  return 1;
	  }
      }
    file.readFile(fp, in_style);
    fprintf(stderr, "Created from NCD file: %s\n",file.getNCDFilename());
    fprintf(stderr, "Target device: %s\n",file.getPartName());
    fprintf(stderr, "Created: %s %s\n",file.getDate(),file.getTime());
    fprintf(stderr, "Bitstream length: %u bits %u bytes(0x%06x)\n", 
            file.getLength(),file.getLength()/8,file.getLength()/8);

    for (i = 0; i < file.getLength()/8; i++)
    {
        /* Umprogrammed Bytes are 0xff, so invert
           to not count them
        */
        sum += (file.getData()[i]) ^0xff;
    }
    fprintf(stderr, "64-bit sum: %" PRIu64 "\n", sum);
    
    if(outfile) {
      if(outfile[0] == '-')
	fp = stdout;
      else
	fp = fopen(outfile,"wb");
      if (fp)
	{
	  file.saveAs(out_style,file.getPartName(), fp);
	  fprintf(stderr, "Bitstream saved in format %s as file: %s\n",
                  BitFile::styleToString(out_style), outfile);
	}
      else
	  fprintf(stderr," Can't open %s: %s  \n", outfile, strerror(errno));
      }
    }
    catch(io_exception& e) {
      fprintf(stderr, "IOException: %s", e.getMessage().c_str());
      return  1;
    }
}