コード例 #1
0
ファイル: flash.c プロジェクト: yiqixiaoxixi/ccslearning
void c6747_spi_AAI(Uint8 *src,Uint32 dst,Uint16 length)//地址自动增加连续写flash
{
	Uint8 *srcp;
	Uint8 spiflashbuf[7];
	Uint16 i;

	srcp=src;
	if(length>0)
	{
	spiflashbuf[0]=spiflash_CMD_WREN;//it must be done before any write operation
	spiflash_cycle(spiflashbuf,1);

	spiflashbuf[0]=spiflash_CMD_AAI;
	spiflashbuf[1]=(Uint8)(dst>>16);
	spiflashbuf[2]=(Uint8)(dst>>8);
	spiflashbuf[3]=(Uint8)(dst);
	spiflashbuf[4]=*srcp++;
	spiflashbuf[5]=*srcp++;//two-bytes of data
	spiflash_cycle(spiflashbuf,6);

	while (spiflash_status()&0x01);

	for(i=2;i<length;i=i+2)
	{
		spiflashbuf[0]=spiflash_CMD_AAI;
		spiflashbuf[1]=*srcp++;
		spiflashbuf[2]=*srcp++;
		spiflash_cycle(spiflashbuf,3);
		while (spiflash_status()&0x01);
	}

	spiflashbuf[0]=spiflash_CMD_WRDI;//software mode.请查看数据手册关于其硬件和软件两种模式的问题
	spiflash_cycle(spiflashbuf,1);
	while (spiflash_status()&0x01);
	}
コード例 #2
0
ファイル: spi.c プロジェクト: cyphunk/sectk
//! Read a block to a buffer.
void spiflash_pokeblock(unsigned long adr,
			unsigned char *buf,
			unsigned int len){
  unsigned char i;
  
  SETSS;
  
  spiflash_setstatus(0x02);
  spiflash_wrten();
  
  CLRSS; //Drop !SS to begin transaction.
  spitrans8(0x02); //Poke command.
  
  //Send address
  spitrans8((adr&0xFF0000)>>16);
  spitrans8((adr&0xFF00)>>8);
  spitrans8(adr&0xFF);

  for(i=0;i<len;i++)
    spitrans8(buf[i]);
  SETSS;  //Raise !SS to end transaction.
  
  while(spiflash_status()&0x01)
    ;
  
  return;
}
コード例 #3
0
ファイル: flash.c プロジェクト: yiqixiaoxixi/ccslearning
void c6747_spi_write(Uint8 *src0,Uint32 dst0,Uint16 length1)//写一个字节到flash
{
		Uint8 *src;
		Uint32 dst;
		Uint16 i;
		Uint8 spiflashbuf[6];

		dst=dst0;
		src=src0;
		for(i=0;i<length1;i++)//此处之所以更改为length1,是因为和下面length相同,运行时候出现错误。请查询真正原因,和存储方式应当有直接关系
		{
		spiflashbuf[0]=spiflash_CMD_WREN;
		spiflash_cycle(spiflashbuf,1);

		spiflashbuf[0]=spiflash_CMD_WRITE;  //Byte-Program instruction.
                                            //programs the bits in the selected byte to the desired data.
		spiflashbuf[1]=(Uint8)(dst>>16);
		spiflashbuf[2]=(Uint8)(dst>>8);
		spiflashbuf[3]=(Uint8)(dst);
		spiflashbuf[4]=*src++;
		dst++;

		spiflash_cycle(spiflashbuf,5);

		while (spiflash_status()&0x01);
		}
}
コード例 #4
0
ファイル: spi.c プロジェクト: cyphunk/sectk
//! Handles a monitor command.
void spihandle(unsigned char app,
	       unsigned char verb,
	       unsigned char len){
  unsigned char i;
  
  
  //Raise !SS to end transaction, just in case we forgot.
  P5OUT|=SS;  
  
  switch(verb){
    //PEEK and POKE might come later.
  case READ:
  case WRITE:
    P5OUT&=~SS; //Drop !SS to begin transaction.
    for(i=0;i<len;i++)
      cmddata[i]=spitrans8(cmddata[i]);
    P5OUT|=SS;  //Raise !SS to end transaction.
    txdata(app,verb,len);
    break;


  case SPI_JEDEC://Grab 3-byte JEDEC ID.
    P5OUT&=~SS; //Drop !SS to begin transaction.
    spitrans8(0x9f);
    len=3;
    for(i=0;i<len;i++)
      cmddata[i]=spitrans8(cmddata[i]);
    txdata(app,verb,len);
    P5OUT|=SS;  //Raise !SS to end transaction.
    break;


  case PEEK://Grab 128 bytes from an SPI Flash ROM
    spiflash_peek(app,verb,len);
    break;


  case POKE://Poke up bytes from an SPI Flash ROM.
    spiflash_setstatus(0x02);
    spiflash_wrten();
    
    P5OUT&=~SS; //Drop !SS to begin transaction.
    spitrans8(0x02); //Poke command.
    
    //First three bytes are address, then data.
    for(i=0;i<len;i++)
      spitrans8(cmddata[i]);
    P5OUT|=SS;  //Raise !SS to end transaction.
    
    
    while(spiflash_status()&0x01)//while busy
      P1OUT^=1;
    P1OUT&=~1;
    
    txdata(app,verb,len);
    break;


  case SPI_ERASE://Erase the SPI Flash ROM.
    spiflash_wrten();
    P5OUT&=~SS; //Drop !SS to begin transaction.
    spitrans8(0xC7);//Chip Erase
    P5OUT|=SS;  //Raise !SS to end transaction.
    
        
    while(spiflash_status()&0x01)//while busy
      P1OUT^=1;
    P1OUT&=~1;
    
    txdata(app,verb,0);
    break;

  case SETUP:
    spisetup();
    txdata(app,verb,0);
    break;
  }
  
}
コード例 #5
0
ファイル: spi_flash.c プロジェクト: Gozhack/firmware
/// Wait for a write or erase operation to complete
_ramfunc void spiflash_wait() {
	while(spiflash_status() & 0x1);
}