Exemplo n.º 1
0
uchar usbFunctionRead(uchar *data, uchar len) {

	uchar i;

	/* check if programmer is in correct read state */
	if ((prog_state != PROG_STATE_READFLASH) && (prog_state
			!= PROG_STATE_READEEPROM) && (prog_state != PROG_STATE_TPI_READ)) {
		return 0xff;
	}

	/* fill packet TPI mode */
	if(prog_state == PROG_STATE_TPI_READ)
	{
		tpi_read_block(prog_address, data, len);
		prog_address += len;
		return len;
	}

	/* fill packet ISP mode */
	for (i = 0; i < len; i++) {
		if (prog_state == PROG_STATE_READFLASH) {
			data[i] = ispReadFlash(prog_address);
		} else {
			data[i] = ispReadEEPROM(prog_address);
		}
		prog_address++;
	}

	/* last packet? */
	if (len < 8) {
		prog_state = PROG_STATE_IDLE;
	}

	return len;
}
Exemplo n.º 2
0
uchar ispFlushPage(unsigned long address, uchar pollvalue) 
{
  ISP_transmit(0x4C);
  ISP_transmit(address >> 9);
  ISP_transmit(address >> 1);
  ISP_transmit(0);


  if (pollvalue == 0xFF) {
    TIMER_delay(5);
    return 0;
  } else {

    // polling flash 
    uchar retries = 30;
	TIMER_start(1);


    while (retries != 0) {
      if (ispReadFlash(address) != 0xFF) {
	return 0;
      };

      if (TIMER_timeout == 0) 
	    {
   	      TIMER_start(1);
	      retries --;
        }
    }

    return 1; // error 
  }
}
Exemplo n.º 3
0
uchar usbFunctionRead(uchar *data, uchar len)
{
 uchar i;
 int c;

  // check if programmer is in correct read state 
  if (
      (prog_state != PROG_STATE_READFLASH) 
   && (prog_state != PROG_STATE_READEEPROM)
   && (prog_state != STATE_READ_CDC)
     ) 
    return 0xff;

  // fill packet 
  for (i = 0; i < len; i++) 
    {
      if (prog_state == PROG_STATE_READFLASH) 
        data[i] = ispReadFlash(prog_address);
      else if (prog_state == PROG_STATE_READEEPROM) 
        data[i] = ispReadEEPROM(prog_address);
      else if (prog_state == STATE_READ_CDC) 
	    {
		  c = BUF_get(&debug_buffer);
		  if (c == -1) break;
		  data[i] = c;
		}
      prog_address++;
    }
  // last packet? 
  if (len < 8) 
    prog_state = PROG_STATE_IDLE;
  return i;
}
Exemplo n.º 4
0
uchar ispWriteFlash(unsigned long address, uchar data, uchar pollmode) 
{
  ISP_transmit(0x40 | ((address & 1) << 3));
  ISP_transmit(address >> 9);
  ISP_transmit(address >> 1);
  ISP_transmit(data);

  if (pollmode == 0)
    return 0;

  if (data == 0x7F) {
    TIMER_delay(5); // wait 4,8 ms 
    return 0;
  } else {

    // polling flash 
    uchar retries = 30;
	TIMER_start(1);
    while (retries != 0) {
      if (ispReadFlash(address) != 0x7F) {
	return 0;
      };
      
      if (TIMER_timeout == 0) 
	    {
   	      TIMER_start(1);
	      retries --;
        }

    }
    return 1; // error 
  }
}
Exemplo n.º 5
0
uint32_t flashAvr( uint8_t *data64, uint8_t *data2561, uint16_t size64, uint16_t size2561 )
{
	uint32_t i ;
	uint8_t *data ;
	uint16_t address ;
	uint16_t size ;
	uint8_t *verifyData ;

	ispConnect() ;
	clockWait( 64 ) ;	// 20mS
	wdt_reset() ;
	if ( ( IspStatus = ispEnterProgrammingMode() ) == 0 )
	{
		Signature[0] = ispReadSignature(0) ;
		Signature[1] = ispReadSignature(1) ;
		Signature[2] = ispReadSignature(2) ;
	}
	// choose file here
	data = data64 ;
	size = size64 ;
	if ( Signature[1] == 0x98 )
	{
		data = data2561 ;
		size = size2561 ;
	}
	verifyData = data ;

	ispChipErase() ;

	if ( Signature[1] == 0x98 )
	{
	  ispTransmit(0x4D) ;
  	ispTransmit(0) ;
	  ispTransmit(0) ;
  	ispTransmit(0) ;
	}

	for ( address = 0 ; address < size ; address += 256 )
	{
		i = 256 ;
		if ( address + 256 > size )
		{
			i = size - address ;
		}
		flashPage( data, address, i ) ;
		data += 256 ;
		wdt_reset() ;
	}
	for ( i = 0 ; i < 64 ; i += 1 )
	{
		M64Program[i] = ispReadFlash( i ) ;
	}
	ispDisconnect() ;
	clockWait(64) ;
	wdt_reset() ;

	for ( i = 0 ; i < 64 ; i += 1 )
	{
		if ( *verifyData++ != M64Program[i] )
		{
			return 1 ;
		}
	}
	return 0 ;
}