Exemple #1
0
/*!
 * \brief Erases all unprotected pages of flash
 * \return ERR_OK if everything is ok; ERR_FAILED otherwise
 */
static byte BL_EraseApplicationFlash(void) {
  dword addr;

  /* erase application flash pages */
  for(addr=MIN_APP_FLASH_ADDRESS;addr<=MAX_APP_FLASH_ADDRESS;addr+=FLASH_PAGE_SIZE) {
    if(IFsh1_EraseSector(addr) != ERR_OK) { /* Error Erasing Flash */
      return ERR_FAILED;
    }
  }
  return ERR_OK;
}
Exemple #2
0
/* dword(32bit) programming */
static byte BL_Flash_Prog(dword flash_addr, dword data_addr, byte number) {
  /* only flash into application space. Everything else will be ignored */
#ifdef S08_CORE
  if (   ((flash_addr >= MIN_FLASH2_ADDRESS) && (flash_addr <= MAX_FLASH2_ADDRESS)) 
      || ((flash_addr >= MIN_FLASH1_ADDRESS) && (flash_addr < FLASH_PROTECTED_ADDRESS))
     ) 
  {
#elif defined CF_CORE
  if((flash_addr > FLASH_PROTECTED_ADDRESS) && (flash_addr <= MAX_FLASH1_ADDRESS)) {
#endif /* S08_CORE */
    if (IFsh1_SetBlockFlash((IFsh1_TDataAddress)data_addr, flash_addr, (word)(number*4)) != ERR_OK) {
      return ERR_FAILED; /* flash programming failed */
    }
  }
  return ERR_OK;
}
    
static byte Flash_Verify(dword dst_addr, dword data_addr, byte length) {
  do {
    if(*(dword *)dst_addr != *(dword *)data_addr) { /* compare two values */
      return ERR_FAILED;
    } 
    dst_addr +=4;
    data_addr +=4; 
  } while(--length);
  return 0x01;
}

/*********************************************************
* Name: EraseFlash
* Desc: Erases all unprotected pages of flash
* Parameter: None
* Return: None
**********************************************************/
static byte BL_EraseFlash(void) {
  dword addr;

  /* erase each page of flash */
  for(addr=MIN_FLASH1_ADDRESS;addr<=MAX_FLASH1_ADDRESS;addr+=FLASH_PAGE_SIZE) {
    if(addr > FLASH_PROTECTED_ADDRESS) {
      if(IFsh1_EraseSector(addr) != ERR_OK) {
        /* Error Erasing Flash */
        return ERR_FAILED;
      }
    } 
  }
  return ERR_OK;
}
Exemple #3
0
static void TestFlash(void) {
    //IFsh1_Init();
	LED3_On();
	WAIT1_Waitms(500);
#if 1
	if (IFsh1_EraseSector(FLASH_ADDR)!=ERR_OK) {
		  for(;;) {
			  LED1_Neg();
			  WAIT1_Waitms(50);
		  }
	}
	if (IFsh1_SetBlockFlash(&data[0], FLASH_ADDR, sizeof(data))!=ERR_OK) {
		  for(;;) {
			  LED2_Neg();
			  WAIT1_Waitms(100);
		  }
	}
#endif
	LED3_Off();
}