/*********************************************************************
 * @fn      OADTarget_eraseFlash
 *
 * @brief   Erase selected flash page.
 *
 * @param   page - the page to erase.
 *
 * @return  None.
 */
void OADTarget_eraseFlash(uint8_t page)
{
  OADTarget_disableCache();
  
  ROM_FlashSectorErase((uint32_t)FLASH_ADDRESS(page, 0)); 
  
  OADTarget_enableCache();
}
/*********************************************************************
 * @fn      OADTarget_writeFlash
 *
 * @brief   Write data to flash.
 *
 * @param   page   - page to write to in flash
 * @param   offset - offset into flash page to begin writing
 * @param   pBuf   - pointer to buffer of data to write
 * @param   len    - length of data to write in bytes
 *
 * @return  None.
 */
void OADTarget_writeFlash(uint8_t page, uint32_t offset, uint8_t *pBuf, 
                          uint16_t len)
{
  OADTarget_disableCache();
  
  ROM_FlashProgram( pBuf, (uint32_t)FLASH_ADDRESS(page, offset), len );
  
  OADTarget_enableCache();
}
/*********************************************************************
 * @fn      OADTarget_eraseFlash
 *
 * @brief   Erase selected flash page.
 *
 * @param   page - the page to erase.
 *
 * @return  None.
 */
void OADTarget_eraseFlash(uint8_t page)
{
  uint8_t cacheState;
  
  cacheState = OADTarget_disableCache();
  
  FlashSectorErase((uint32_t)FLASH_ADDRESS(page, 0)); 
  
  OADTarget_enableCache(cacheState);
}
/*********************************************************************
 * @fn      OADTarget_readFlash
 *
 * @brief   Read data from flash.
 *
 * @param   page   - page to read from in flash
 * @param   offset - offset into flash page to begin reading
 * @param   pBuf   - pointer to buffer into which data is read.
 * @param   len    - length of data to read in bytes.
 *
 * @return  None.
 */
void OADTarget_readFlash(uint8_t page, uint32_t offset, uint8_t *pBuf, 
                         uint16_t len)
{
  halIntState_t cs;
  uint8_t *ptr = (uint8_t *)FLASH_ADDRESS(page, offset);
  
  // Enter critical section.
  HAL_ENTER_CRITICAL_SECTION(cs);
  
  // Read from pointer into buffer.
  while (len--)
  {
    *pBuf++ = *ptr++;
  }
  
  // Exit critical section.
  HAL_EXIT_CRITICAL_SECTION(cs);
}
/*********************************************************************
 * @fn      OADTarget_eraseFlash
 *
 * @brief   Erase selected flash page.
 *
 * @param   page - the page to erase.
 *
 * @return  None.
 */
void OADTarget_eraseFlash(uint8_t page)
{
  extFlashErase(FLASH_ADDRESS(page,0), HAL_FLASH_PAGE_SIZE);
}
/*********************************************************************
 * @fn      OADTarget_writeFlash
 *
 * @brief   Write data to flash.
 *
 * @param   page   - page to write to in flash
 * @param   offset - offset into flash page to begin writing
 * @param   pBuf   - pointer to buffer of data to write
 * @param   len    - length of data to write in bytes
 *
 * @return  None.
 */
void OADTarget_writeFlash(uint8_t page, uint32_t offset, uint8_t *pBuf, 
                          uint16_t len)
{
  extFlashWrite(FLASH_ADDRESS(page,offset), len, pBuf);
}
/*********************************************************************
 * @fn      OADTarget_readFlash
 *
 * @brief   Read data from flash.
 *
 * @param   page   - page to read from in flash
 * @param   offset - offset into flash page to begin reading
 * @param   pBuf   - pointer to buffer into which data is read.
 * @param   len    - length of data to read in bytes.
 *
 * @return  None.
 */
void OADTarget_readFlash(uint8_t page, uint32_t offset, uint8_t *pBuf, 
                         uint16_t len)
{
  extFlashRead(FLASH_ADDRESS(page,offset), len, pBuf);
}
/*********************************************************************
 * @fn      OADTarget_getCurrentImageHeader
 *
 * @brief   Get the current image's header.
 *
 * @param   pValue - pointer to the new image header
 *
 * @return  none
 */
void OADTarget_getCurrentImageHeader(img_hdr_t *pHdr)
{
  memcpy((uint8_t *)pHdr, 
         (uint8_t *)FLASH_ADDRESS(OAD_IMG_R_PAGE, OAD_IMG_R_OSET + OAD_IMG_HDR_OSET), 
         sizeof(img_hdr_t));
}
Esempio n. 9
0
uint32_t getFlashMemIndex(uint32_t address)
{
	return(FLASH_ADDRESS(ROW_WITHIN_FLASH(address), OFFSET_ADDRESS(address)));
}