Exemplo n.º 1
0
/*
description:向eeprom读一个页内的部分或者全部数据
return:0--写数据正常结束
        1--I2C启动错误
        2--无ACK
*/
uint8_t eeprom_read_sequential(uint16_t addr,uint16_t  num,uint8_t *data)
{
  uint8_t result = 0;
  uint8_t temp = 0;
  uint16_t i = 0;

  while(is_eeprom_busy());
    
  result = TWI_START();
  if(result != TWI_READY)
    return 1;

#if(MEM_SIZE > SIZE_64K)
  if(eeprom_num == 1)
    temp = DEV_ADDR1|0;
  else
    temp = DEV_ADDR2|0;
#else
  temp = DEV_ADDR|0;
#endif
  result = TWI_SendByte(temp);
  if(result != TWI_ACK)
    return 2;

  result = TWI_SendByte((uint8_t)(addr>>8));
  result = TWI_SendByte((uint8_t)(addr));
  if(result != TWI_ACK)
    return 2;

  result = TWI_START();
#if(MEM_SIZE > SIZE_64K)
  if(eeprom_num == 1)
    temp = DEV_ADDR1|1;
  else
    temp = DEV_ADDR2|1;
#else
  temp = DEV_ADDR|1;
#endif
  result = TWI_SendByte(temp);
  if(result != TWI_ACK)
    return 2;

  for(i = 0; i < num; i++)
  {
    data[i] = TWI_ReceiveByte();
    if(i != num-1)
      TWI_SendACK();
    else
      TWI_SendNACK();
  }
            
  TWI_STOP();
//  delay_5ms();
  return 0;
}
Exemplo n.º 2
0
static int
eeprom_rdy(void)
{
	int i;

	for (i = 0; is_eeprom_busy(IS_BASE) && i < MAX_EEPROMBUSY; i++);
	if (i >= MAX_EEPROMBUSY) {
		printf("3c509: eeprom failed to come ready.\r\n");
		return 0;
	}
	return 1;
}
Exemplo n.º 3
0
static int
eeprom_rdy()
{
	int i;

	for (i = 0; is_eeprom_busy(BASE) && i < MAX_EEPROMBUSY; i++)
		udelay(1000);
	if (i >= MAX_EEPROMBUSY) {
	        /* printf("3c595: eeprom failed to come ready.\n"); */
		printf("3c595: eeprom is busy.\n"); /* memory in EPROM is tight */
		return (0);
	}
	return (1);
}
Exemplo n.º 4
0
static int
eeprom_rdy(struct ep_softc *sc)
{
    int i;

    for (i = 0; is_eeprom_busy(BASE) && i < MAX_EEPROMBUSY; i++) {
	DELAY(100);
    }
    if (i >= MAX_EEPROMBUSY) {
	if_printf(&sc->arpcom.ac_if, "eeprom failed to come ready.\n");
	return (0);
    }
    return (1);
}
Exemplo n.º 5
0
/*
description:向eeprom读一个字节数据
return:0--写数据正常结束
        1--I2C启动错误
        2--无ACK
*/
uint8_t eeprom_read_byte(uint16_t addr,uint8_t *data)
{
  uint8_t result = 0;
  uint8_t temp = 0;

  while(is_eeprom_busy());

  result = TWI_START();
  if(result != TWI_READY)
    return 1;

#if(MEM_SIZE > SIZE_64K)
  if(eeprom_num == 1)
    temp = DEV_ADDR1|0;
  else
    temp = DEV_ADDR2|0;
#else
  temp = DEV_ADDR|0;
#endif
  result = TWI_SendByte(temp);
  if(result != TWI_ACK)
    return 2;

  result = TWI_SendByte((uint8_t)(addr>>8));
  result = TWI_SendByte((uint8_t)(addr));
  if(result != TWI_ACK)
    return 2;

  result = TWI_START();
#if(MEM_SIZE > SIZE_64K)
  if(eeprom_num == 1)
    temp = DEV_ADDR1|1;
  else
    temp = DEV_ADDR2|1;
#else
  temp = DEV_ADDR|1;
#endif
  result = TWI_SendByte(temp);
  if(result != TWI_ACK)
    return 2;


  *data = TWI_ReceiveByte();

  TWI_SendNACK();            
  TWI_STOP();
  return 0;
}
Exemplo n.º 6
0
/*
description:向eeprom一页内写入部分或者全部数据
return:0--写数据正常结束
        1--I2C启动错误
        2--无ACK
*/
uint8_t eeprom_write_page(uint16_t page_num,uint8_t offshit,uint8_t num,uint8_t *data)
{
  uint8_t result = 0;
  uint8_t temp = 0;
  uint8_t i = 0;
  uint16_t addr = page_num*PAGE_SIZE+offshit;

  while(is_eeprom_busy());

  result = TWI_START();
  if(result != TWI_READY)
    return 1;

#if(MEM_SIZE > SIZE_64K)
  if(eeprom_num == 1)
    temp = DEV_ADDR1|0;
  else
    temp = DEV_ADDR2|0;
#else
  temp = DEV_ADDR|0;
#endif
  result = TWI_SendByte(temp);
  if(result != TWI_ACK)
    return 2;

  result = TWI_SendByte((uint8_t)(addr>>8));
  if(result != TWI_ACK)
    return 2;

  result = TWI_SendByte((uint8_t)(addr));
  if(result != TWI_ACK)
    return 2;

  for(i = 0; i < num; i++)
  {
    result = TWI_SendByte(data[i]);
    if(result != TWI_ACK)
      return 2;
  }
          
  TWI_STOP();
//  delay_5ms();
  return 0;
}
Exemplo n.º 7
0
/*
description:向eeprom写一个字节数据
return:0--写数据正常结束
        1--I2C启动错误
        2--无ACK
*/
uint8_t eeprom_write_byte(uint16_t addr,uint8_t data)
{
  uint8_t result = 0;
  uint8_t temp = 0;

  while(is_eeprom_busy());

  result = TWI_START();
  if(result != TWI_READY)
    return 1;

#if(MEM_SIZE > SIZE_64K)
  if(eeprom_num == 1)
    temp = DEV_ADDR1|0;
  else
    temp = DEV_ADDR2|0;
#else
  temp = DEV_ADDR|0;
#endif

  result = TWI_SendByte(temp);
  if(result != TWI_ACK)
    return 2;

  result = TWI_SendByte((uint8_t)(addr>>8));
  if(result != TWI_ACK)
    return 2;

  result = TWI_SendByte((uint8_t)(addr));
  if(result != TWI_ACK)
    return 2;

  result = TWI_SendByte(data);
  if(result != TWI_ACK)
    return 2;
           
  TWI_STOP();
//  delay_5ms();
  return 0;
}