Src/EEPROM_Emul/eeprom_emul.c
static EE_Status SetPageState(uint32_t Page, EE_State_type State)
{
  uint32_t header1 = 0U, header2 = 0U, header3 = 0U, header4 = 0U;

  header1 = PAGE_ADDRESS(Page);
  header2 = PAGE_ADDRESS(Page) + EE_ELEMENT_SIZE;
  header3 = PAGE_ADDRESS(Page) + (EE_ELEMENT_SIZE*2U);
  header4 = PAGE_ADDRESS(Page) + (EE_ELEMENT_SIZE*3U);

#if defined (DUALCORE_FLASH_SHARING)
  EE_Status ee_status;
  switch(State)
  {
  case STATE_PAGE_RECEIVE:
    {
      /* Set new Page status to STATE_PAGE_RECEIVE status */
      ee_status = FI_WriteDoubleWord(header1, EE_PAGESTAT_RECEIVE, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
      ubCurrentActivePage = Page;
    }
    break;
  case STATE_PAGE_ACTIVE:
    {
      /* Set new Page status to STATE_PAGE_ACTIVE status */
      ee_status = FI_WriteDoubleWord(header2, EE_PAGESTAT_ACTIVE, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
      ubCurrentActivePage = Page;
    }
    break;
  case STATE_PAGE_VALID:
    {
      /* Set new Page status to STATE_PAGE_VALID status */
      ee_status = FI_WriteDoubleWord(header3, EE_PAGESTAT_VALID, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
    }
    break;
  case STATE_PAGE_ERASING:
    {
      /* Set new Page status to STATE_PAGE_ERASING status */
      ee_status = FI_WriteDoubleWord(header4, EE_PAGESTAT_ERASING, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
    }
    break;
  default:
    break;
  }
#elif defined (FLASH_LINES_128B)
  EE_Status ee_status;
  uint64_t pagestat = 0;
  switch(State)
  {
  case STATE_PAGE_RECEIVE:
    {
      /* Set new Page status to STATE_PAGE_RECEIVE status */
      pagestat = EE_PAGESTAT_RECEIVE;
      ee_status = FI_WriteDoubleWord(header1, &pagestat, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
      ubCurrentActivePage = Page;
    }
    break;
  case STATE_PAGE_ACTIVE:
    {
      /* Set new Page status to STATE_PAGE_ACTIVE status */
      pagestat = EE_PAGESTAT_ACTIVE;
      ee_status = FI_WriteDoubleWord(header2, &pagestat, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
      ubCurrentActivePage = Page;
    }
    break;
  case STATE_PAGE_VALID:
    {
      /* Set new Page status to STATE_PAGE_VALID status */
      pagestat = EE_PAGESTAT_VALID;
      ee_status = FI_WriteDoubleWord(header3, &pagestat, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
    }
    break;
  case STATE_PAGE_ERASING:
    {
      /* Set new Page status to STATE_PAGE_ERASING status */
      pagestat = EE_PAGESTAT_ERASING;
      ee_status = FI_WriteDoubleWord(header4, &pagestat, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
    }
    break;
  default:
    break;
  }
#else
  switch(State)
  {
  case STATE_PAGE_RECEIVE:
    {
      /* Set new Page status to STATE_PAGE_RECEIVE status */
      if (FI_WriteDoubleWord(header1, EE_PAGESTAT_RECEIVE) != HAL_OK)
      {
        return EE_WRITE_ERROR;
      }
      ubCurrentActivePage = Page;
    }
    break;
  case STATE_PAGE_ACTIVE:
    {
      /* Set new Page status to STATE_PAGE_ACTIVE status */
      if (FI_WriteDoubleWord(header2, EE_PAGESTAT_ACTIVE) != HAL_OK)
      {
        return EE_WRITE_ERROR;
      }
      ubCurrentActivePage = Page;
    }
    break;
  case STATE_PAGE_VALID:
    {
      /* Set new Page status to STATE_PAGE_VALID status */
      if (FI_WriteDoubleWord(header3, EE_PAGESTAT_VALID) != HAL_OK)
      {
        return EE_WRITE_ERROR;
      }
    }
    break;
  case STATE_PAGE_ERASING:
    {
      /* Set new Page status to STATE_PAGE_ERASING status */
      if (FI_WriteDoubleWord(header4, EE_PAGESTAT_ERASING) != HAL_OK)
      {
        return EE_WRITE_ERROR;
      }
    }
    break;
  default:
    break;
  }
#endif

  /* Return last operation flash status */
  return EE_OK;
}
/**
  * @brief  Set page state in page header
  * @param  Page Index of the page
  * @param  State State of the page
  * @retval EE_Status
  *           - EE_OK: on success
  *           - EE error code: if an error occurs
  */
@brief  Set page state in page header
@param  Page Index of the page
@param  State State of the page
@retval EE_Status
- EE_OK: on success
- EE error code: if an error occurs
@brief Set page state in page header @param Page Index of the page @param State State of the page @retval EE_Status - EE_OK : on success - EE error code : if an error occurs
static EE_Status SetPageState(uint32_t Page, EE_State_type State)
{
  uint32_t header1 = 0U, header2 = 0U, header3 = 0U, header4 = 0U;
  header1 = PAGE_ADDRESS(Page);
  header2 = PAGE_ADDRESS(Page) + EE_ELEMENT_SIZE;
  header3 = PAGE_ADDRESS(Page) + (EE_ELEMENT_SIZE*2U);
  header4 = PAGE_ADDRESS(Page) + (EE_ELEMENT_SIZE*3U);
#if defined (DUALCORE_FLASH_SHARING)
  EE_Status ee_status;
  switch(State)
  {
  case STATE_PAGE_RECEIVE:
    {
      ee_status = FI_WriteDoubleWord(header1, EE_PAGESTAT_RECEIVE, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
      ubCurrentActivePage = Page;
    }
    break;
  case STATE_PAGE_ACTIVE:
    {
      ee_status = FI_WriteDoubleWord(header2, EE_PAGESTAT_ACTIVE, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
      ubCurrentActivePage = Page;
    }
    break;
  case STATE_PAGE_VALID:
    {
      ee_status = FI_WriteDoubleWord(header3, EE_PAGESTAT_VALID, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
    }
    break;
  case STATE_PAGE_ERASING:
    {
      ee_status = FI_WriteDoubleWord(header4, EE_PAGESTAT_ERASING, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
    }
    break;
  default:
    break;
  }
#elif defined (FLASH_LINES_128B)
  EE_Status ee_status;
  uint64_t pagestat = 0;
  switch(State)
  {
  case STATE_PAGE_RECEIVE:
    {
      pagestat = EE_PAGESTAT_RECEIVE;
      ee_status = FI_WriteDoubleWord(header1, &pagestat, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
      ubCurrentActivePage = Page;
    }
    break;
  case STATE_PAGE_ACTIVE:
    {
      pagestat = EE_PAGESTAT_ACTIVE;
      ee_status = FI_WriteDoubleWord(header2, &pagestat, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
      ubCurrentActivePage = Page;
    }
    break;
  case STATE_PAGE_VALID:
    {
      pagestat = EE_PAGESTAT_VALID;
      ee_status = FI_WriteDoubleWord(header3, &pagestat, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
    }
    break;
  case STATE_PAGE_ERASING:
    {
      pagestat = EE_PAGESTAT_ERASING;
      ee_status = FI_WriteDoubleWord(header4, &pagestat, EE_SET_PAGE);
      if (ee_status != EE_OK) return ee_status;
    }
    break;
  default:
    break;
  }
#else
  switch(State)
  {
  case STATE_PAGE_RECEIVE:
    {
      if (FI_WriteDoubleWord(header1, EE_PAGESTAT_RECEIVE) != HAL_OK)
      {
        return EE_WRITE_ERROR;
      }
      ubCurrentActivePage = Page;
    }
    break;
  case STATE_PAGE_ACTIVE:
    {
      if (FI_WriteDoubleWord(header2, EE_PAGESTAT_ACTIVE) != HAL_OK)
      {
        return EE_WRITE_ERROR;
      }
      ubCurrentActivePage = Page;
    }
    break;
  case STATE_PAGE_VALID:
    {
      if (FI_WriteDoubleWord(header3, EE_PAGESTAT_VALID) != HAL_OK)
      {
        return EE_WRITE_ERROR;
      }
    }
    break;
  case STATE_PAGE_ERASING:
    {
      if (FI_WriteDoubleWord(header4, EE_PAGESTAT_ERASING) != HAL_OK)
      {
        return EE_WRITE_ERROR;
      }
    }
    break;
  default:
    break;
  }
#endif
  return EE_OK;
}
static EE_Status SetPageState ( uint32_t Page , EE_State_type State ) { uint32_t header1 = 0U , header2 = 0U , header3 = 0U , header4 = 0U ; header1 = PAGE_ADDRESS ( Page ) ; header2 = PAGE_ADDRESS ( Page ) + EE_ELEMENT_SIZE ; header3 = PAGE_ADDRESS ( Page ) + ( EE_ELEMENT_SIZE * 2U ) ; header4 = PAGE_ADDRESS ( Page ) + ( EE_ELEMENT_SIZE * 3U ) ; #if defined ( DUALCORE_FLASH_SHARING ) EE_Status ee_status ; switch ( State ) { case STATE_PAGE_RECEIVE : { ee_status = FI_WriteDoubleWord ( header1 , EE_PAGESTAT_RECEIVE , EE_SET_PAGE ) ; if ( ee_status != EE_OK ) return ee_status ; ubCurrentActivePage = Page ; } break ; case STATE_PAGE_ACTIVE : { ee_status = FI_WriteDoubleWord ( header2 , EE_PAGESTAT_ACTIVE , EE_SET_PAGE ) ; if ( ee_status != EE_OK ) return ee_status ; ubCurrentActivePage = Page ; } break ; case STATE_PAGE_VALID : { ee_status = FI_WriteDoubleWord ( header3 , EE_PAGESTAT_VALID , EE_SET_PAGE ) ; if ( ee_status != EE_OK ) return ee_status ; } break ; case STATE_PAGE_ERASING : { ee_status = FI_WriteDoubleWord ( header4 , EE_PAGESTAT_ERASING , EE_SET_PAGE ) ; if ( ee_status != EE_OK ) return ee_status ; } break ; default : break ; } #elif defined ( FLASH_LINES_128B ) EE_Status ee_status ; uint64_t pagestat = 0 ; switch ( State ) { case STATE_PAGE_RECEIVE : { pagestat = EE_PAGESTAT_RECEIVE ; ee_status = FI_WriteDoubleWord ( header1 , & pagestat , EE_SET_PAGE ) ; if ( ee_status != EE_OK ) return ee_status ; ubCurrentActivePage = Page ; } break ; case STATE_PAGE_ACTIVE : { pagestat = EE_PAGESTAT_ACTIVE ; ee_status = FI_WriteDoubleWord ( header2 , & pagestat , EE_SET_PAGE ) ; if ( ee_status != EE_OK ) return ee_status ; ubCurrentActivePage = Page ; } break ; case STATE_PAGE_VALID : { pagestat = EE_PAGESTAT_VALID ; ee_status = FI_WriteDoubleWord ( header3 , & pagestat , EE_SET_PAGE ) ; if ( ee_status != EE_OK ) return ee_status ; } break ; case STATE_PAGE_ERASING : { pagestat = EE_PAGESTAT_ERASING ; ee_status = FI_WriteDoubleWord ( header4 , & pagestat , EE_SET_PAGE ) ; if ( ee_status != EE_OK ) return ee_status ; } break ; default : break ; } #else switch ( State ) { case STATE_PAGE_RECEIVE : { if ( FI_WriteDoubleWord ( header1 , EE_PAGESTAT_RECEIVE ) != HAL_OK ) { return EE_WRITE_ERROR ; } ubCurrentActivePage = Page ; } break ; case STATE_PAGE_ACTIVE : { if ( FI_WriteDoubleWord ( header2 , EE_PAGESTAT_ACTIVE ) != HAL_OK ) { return EE_WRITE_ERROR ; } ubCurrentActivePage = Page ; } break ; case STATE_PAGE_VALID : { if ( FI_WriteDoubleWord ( header3 , EE_PAGESTAT_VALID ) != HAL_OK ) { return EE_WRITE_ERROR ; } } break ; case STATE_PAGE_ERASING : { if ( FI_WriteDoubleWord ( header4 , EE_PAGESTAT_ERASING ) != HAL_OK ) { return EE_WRITE_ERROR ; } } break ; default : break ; } #endif return EE_OK ; }
@brief  Set page state in page header
 @param  Page Index of the page
 @param  State State of the page
 @retval EE_Status
           - EE_OK: on success
           - EE error code: if an error occurs
@brief Set page state in page header @param Page Index of the page @param State State of the page @retval EE_Status - EE_OK : on success - EE error code : if an error occurs
/* Set new Page status to STATE_PAGE_RECEIVE status */ /* Set new Page status to STATE_PAGE_ACTIVE status */ /* Set new Page status to STATE_PAGE_VALID status */ /* Set new Page status to STATE_PAGE_ERASING status */ /* Set new Page status to STATE_PAGE_RECEIVE status */ /* Set new Page status to STATE_PAGE_ACTIVE status */ /* Set new Page status to STATE_PAGE_VALID status */ /* Set new Page status to STATE_PAGE_ERASING status */ /* Set new Page status to STATE_PAGE_RECEIVE status */ /* Set new Page status to STATE_PAGE_ACTIVE status */ /* Set new Page status to STATE_PAGE_VALID status */ /* Set new Page status to STATE_PAGE_ERASING status */ /* Return last operation flash status */