コード例 #1
0
ファイル: spiflash-program.c プロジェクト: DayUpWoniu/orpsoc
// Verify contents of SPI flash
void
verify_spi(int core, char slave_sel, char * data, unsigned int length)
{
  unsigned int i;
  unsigned int page_num = 0;
  unsigned int bytes_this_page;
  char verify_buf[256];
  int verify_error = 0;
  printf("* Verifying contents of SPI flash.\n");
  while(length)
    {
      bytes_this_page = (length >= 256) ? 256 : length;
      spi_read_block(spi_master, slave, (page_num<<8), bytes_this_page, 
		     verify_buf);
      for(i=0;i<bytes_this_page;i++)
	{
	  if (verify_buf[i] != data[i])
	    {
	      printf("* Verify error! Byte %d of page %d - was 0x%x, expected 0x%x\n", i, page_num, verify_buf[i] & 0xff, data[i] & 0xff);
	      verify_error=1;
	    }
	}
      data +=256;
      length -= (length >= 256) ? 256 : length;
      page_num++;
    }
  if (verify_error)
    printf("* SPI flash verify NOT OK\n");
  else
    printf("* SPI flash verify OK\n");
  
}
コード例 #2
0
ファイル: spiflash-program.c プロジェクト: DayUpWoniu/orpsoc
int 
main()
{

  uart_init(0); // init the UART before we can printf
  
  volatile char c;
  int i,j;
  char browse_buf[256];
  spi_master = 0;
  slave = 1;

  spi_core_slave_select(spi_master, 0); // Deselect slaves

  // Clear the read FIFO
  while (spi_core_data_avail(spi_master))
    c = spi_core_read_data(spi_master);
  
  programming_file_start = (unsigned long) &spiprogram_data;
  programming_file_end = (unsigned long) &end_spiprogram_data;
  programming_file_length = programming_file_end - programming_file_start;

  // SPI core 0, should already be configured to read out data
  // when we reset.

  printf("\n\n\tSPI flash programming app\n\n");

  while(1){
    printf("[p,v,s,h] > ");
    c = uart_getc(DEFAULT_UART);  
    printf("%c",c);
    printf("\n");
    
    if (c == 'h')
      printhelp();
    else if (c == 's')
      print_spi_status();
    else if (c == 'p')
      program_spi(spi_master, slave, (char *) &spiprogram_data, programming_file_length);
    else if (c == 'v')
      verify_spi(spi_master, slave, (char *) &spiprogram_data, programming_file_length);
    else if ( c== 'r')
    {
	    printf("Read page\n");
	    spi_read_block(spi_master, slave, ((console_get_num())<<8), 
			   256, 
			   browse_buf);
	    console_browse_buffer(browse_buf);
    }
    

  }
  
  return 0;

}
コード例 #3
0
ファイル: SPIway.c プロジェクト: hjudges/NORway
void handle_read_block() {
	uint16_t i;
	int16_t in_data;

	for (i = 0; i < BUF_SIZE_ADDR; i++) {
		if ((in_data = usb_serial_getchar()) != -1)
			buf_addr[i] = in_data;
		else
			break;
	}
	
	if (i < BUF_SIZE_ADDR) {	// timeout
		usb_serial_putchar('R');
		return;		// and exit
	}
	
	usb_serial_putchar('K');
	spi_read_block();
}