Beispiel #1
0
/*---------------------------------------------------------------------------*/
static const char *
program_page(unsigned long offset, const unsigned char *p, int nbytes)
{
  const unsigned char *end = p + nbytes;
  int s;

  wait_ready();

  write_enable();

  s = splhigh();
  SPI_FLASH_ENABLE();
  
  spi_tx(SPI_FLASH_INS_PP);
  spi_tx(offset >> 16);	/* MSB */
  spi_tx(offset >> 8);
  spi_tx(offset >> 0);	/* LSB */

  for(; p < end; p++) {
    spi_tx(~*p);
  }

  SPI_FLASH_DISABLE();
  splx(s);

  return p;
}
Beispiel #2
0
/*---------------------------------------------------------------------------*/
int
xmem_pread(void *_p, int size, unsigned long offset)
{
  unsigned char *p = _p;
  const unsigned char *end = p + size;
  int s;
  wait_ready();

  ENERGEST_ON(ENERGEST_TYPE_FLASH_READ);

  s = splhigh();
  SPI_FLASH_ENABLE();

  SPI_WRITE_FAST(SPI_FLASH_INS_READ);
  SPI_WRITE_FAST(offset >> 16);	/* MSB */
  SPI_WRITE_FAST(offset >> 8);
  SPI_WRITE_FAST(offset >> 0);	/* LSB */
  SPI_WAITFORTx_ENDED();
  
  SPI_FLUSH();
  for(; p < end; p++) {
    unsigned char u;
    SPI_READ(u);
    *p = ~u;
  }

  SPI_FLASH_DISABLE();
  splx(s);

  ENERGEST_OFF(ENERGEST_TYPE_FLASH_READ);

  return size;
}
Beispiel #3
0
/*---------------------------------------------------------------------------*/
int
xmem_pread(void *_p, int size, unsigned long offset)
{
  unsigned char *p = _p;
  const unsigned char *end = p + size;
  int s;
  wait_ready();

  ENERGEST_ON(ENERGEST_TYPE_FLASH_READ);

  s = splhigh();
  SPI_FLASH_ENABLE();

  spi_tx(SPI_FLASH_INS_READ);
  spi_tx(offset >> 16);	/* MSB */
  spi_tx(offset >> 8);
  spi_tx(offset >> 0);	/* LSB */
  
  FASTSPI_CLEAR_RX();
  for(; p < end; p++) {
    unsigned char u;
    FASTSPI_RX(u);
    *p = ~u;
  }

  SPI_FLASH_DISABLE();
  splx(s);

  ENERGEST_OFF(ENERGEST_TYPE_FLASH_READ);

  return size;
}
Beispiel #4
0
/*---------------------------------------------------------------------------*/
static void
write_enable(void)
{
  int s;

  s = splhigh();
  SPI_FLASH_ENABLE();
  
  spi_tx(SPI_FLASH_INS_WREN);

  SPI_FLASH_DISABLE();
  splx(s);
}
Beispiel #5
0
/*---------------------------------------------------------------------------*/
static void
write_enable(void)
{
  int s;

  s = splhigh();
  SPI_FLASH_ENABLE();
  
  FASTSPI_TX(SPI_FLASH_INS_WREN);
  SPI_WAITFORTx_ENDED();

  SPI_FLASH_DISABLE();
  splx(s);
}
Beispiel #6
0
/*
 * Erase 64k bytes of data. It takes about 1s before WIP goes low!
 */
static void
erase_sector(unsigned long offset)
{
  int s;
  wait_ready();

  write_enable();

  s = splhigh();
  SPI_FLASH_ENABLE();
  
  spi_tx(SPI_FLASH_INS_SE);
  spi_tx(offset >> 16);	/* MSB */
  spi_tx(offset >> 8);
  spi_tx(offset >> 0);	/* LSB */

  SPI_FLASH_DISABLE();
  splx(s);
}
Beispiel #7
0
/*
 * Initialize external flash *and* SPI bus!
 */
void
xmem_init(void)
{
  int s;
  spi_init();

  P4DIR |= BV(FLASH_CS) | BV(FLASH_HOLD) | BV(FLASH_PWR);
  P4OUT |= BV(FLASH_PWR);       /* P4.3 Output, turn on power! */

  /* Release from Deep Power-down */
  s = splhigh();
  SPI_FLASH_ENABLE();
  SPI_WRITE_FAST(SPI_FLASH_INS_RES);
  SPI_WAITFORTx_ENDED();
  SPI_FLASH_DISABLE();		/* Unselect flash. */
  splx(s);

  SPI_FLASH_UNHOLD();
}
Beispiel #8
0
/*---------------------------------------------------------------------------*/
static unsigned
read_status_register(void)
{
  unsigned char u;

  int s;

  s = splhigh();
  SPI_FLASH_ENABLE();
  
  spi_tx(SPI_FLASH_INS_RDSR);

  FASTSPI_CLEAR_RX();
  FASTSPI_RX(u);

  SPI_FLASH_DISABLE();
  splx(s);

  return u;
}
Beispiel #9
0
/*---------------------------------------------------------------------------*/
static unsigned
read_status_register(void)
{
  unsigned char u;

  int s;

  s = splhigh();
  SPI_FLASH_ENABLE();
  
  SPI_WRITE(SPI_FLASH_INS_RDSR);

  SPI_FLUSH();
  SPI_READ(u);

  SPI_FLASH_DISABLE();
  splx(s);

  return u;
}
Beispiel #10
0
/*
 * Erase 64k bytes of data. It takes about 1s before WIP goes low!
 */
static void
erase_sector(unsigned long offset)
{
  int s;
  wait_ready();

  write_enable();

  s = splhigh();
  SPI_FLASH_ENABLE();
  
  FASTSPI_TX(SPI_FLASH_INS_SE);
  FASTSPI_TX(offset >> 16);	/* MSB */
  FASTSPI_TX(offset >> 8);
  FASTSPI_TX(offset >> 0);	/* LSB */
  SPI_WAITFORTx_ENDED();

  SPI_FLASH_DISABLE();
  splx(s);
}