/**
* @brief  This function writes data to internal EEPROM.
* @param  uint8_t *NVMparam: The pointer to the data to be written.
*         - uint8_t length: The length of the data to be written.  
* @retval None.
*/
void WMBus_PhyWriteNVMParam(uint8_t *NVMparam, uint8_t length)
{
  DATA_EEPROM_Unlock();
  for(uint8_t temp=0x00; temp<length;temp++)
    DATA_EEPROM_ProgramByte(EEPROM_NVM_BASE+temp, *(NVMparam+temp));
  DATA_EEPROM_Lock();
}
void Internal_EE_Write8(uint16_t position, uint8_t data){
	DATA_EEPROM_Unlock();
	FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_OPTVERRUSR);	
	DATA_EEPROM_ProgramByte(INTERNAL_8BIT_START_ADDRESS+position, data);
	DATA_EEPROM_Lock();
}
/**
* @brief  This function writes data to internal EEPROM.
* @param  uint8_t *buff: The pointer to the data to be written.
*         - uint16_t length: The length of the data to be written.  
* @retval None.
*/
void WMBus_WriteMeterDatabaseToEEPROM(uint8_t *buff, uint16_t length, uint32_t Saddress)
{
  DATA_EEPROM_Unlock();
  for(uint16_t temp=0x00; temp<length;temp++)
    DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
  DATA_EEPROM_Lock();
}
Beispiel #4
0
/**
  * @brief  Writes selected block of option structure memory to EEPROM.
  * @param  offset: beginning of block to write, length of block.
  * @retval void
  */
void WriteBlock(uint16_t offset, uint8_t len)
{
   uint8_t i;
   uint32_t eeprom_addr = DATA_EEPROM_START_ADDR + offset;
   uint8_t* ram_addr    = (uint8_t*)&options + offset;

   DATA_EEPROM_Unlock();
   for (i=0; i<len; i++)                                 // Erase
     DATA_EEPROM_EraseByte(eeprom_addr+i);
   for (i=0; i<len; i++)                                 // Program
     DATA_EEPROM_ProgramByte(eeprom_addr+i, *ram_addr++);
   DATA_EEPROM_Lock();
}
void Internal_EE_WriteM8(uint16_t start_position, uint8_t* data, uint16_t length){
	uint16_t i = 0;
	__IO FLASH_Status FLASHStatus = FLASH_COMPLETE;
	DATA_EEPROM_Unlock();
	FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_OPTVERRUSR);	
	while(i<length){
		FLASHStatus = DATA_EEPROM_ProgramByte(INTERNAL_8BIT_START_ADDRESS+start_position+i, data[i]);
		if(FLASHStatus == FLASH_COMPLETE){
			i++;
		}else{
			FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                           | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR);
		}
	}
	DATA_EEPROM_Lock();
}
Beispiel #6
0
/**
  * @brief  Function used to reset the DFU MODE flag on E2PROM.
  * @param  None
  * @retval None
  */
void SdkDfuResetDfuFlag(void){

  /* Unlock the FLASH PECR register and Data EEPROM memory */
  DATA_EEPROM_Unlock();

  /* Clear all pending flags */
  FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR);

  /* Write 0 on the E2PROM data address 0x08080000 */
  FLASH_Status FLASHStatus = DATA_EEPROM_ProgramByte(DATA_EEPROM_START_ADDR, 0);

  /* Clear all the Flash flags */
  if(FLASHStatus != FLASH_COMPLETE)
    FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                    | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR);


  /* Lock the FLASH PECR register and Data EEPROM memory */
  DATA_EEPROM_Lock();

}
Beispiel #7
0
/**
  * @brief  Function stores all options in EEPROM memory.
  * @param  void
  * @retval verification status
  */
uint8_t WriteOptions(void)
{
   uint16_t i;
   uint32_t eeprom_addr = DATA_EEPROM_START_ADDR;
   uint8_t* ram_addr    = (uint8_t*)&options;
   uint8_t  options_len = sizeof(options);
   uint8_t  ver_status  = 0;
   //FLASH_Status FLASHStatus = FLASH_COMPLETE;

   DATA_EEPROM_Unlock();                                                   // Unlock the FLASH PECR register and Data EEPROM memory
   FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR    // Clear all pending flags
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_OPTVERRUSR);

   for (i=0; i<options_len; i++)                                           // Erase
     DATA_EEPROM_EraseByte(eeprom_addr+i);
   for (i=0; i<options_len; i++)                                           // Program
     DATA_EEPROM_ProgramByte(eeprom_addr+i, *ram_addr++);
   ram_addr = (uint8_t*)&options;
   for (i=0; i<options_len; i++)                                           // Verify
   { if (*ram_addr++ != *(uint8_t*)(eeprom_addr+i)) ver_status = 1; }

   DATA_EEPROM_Lock();
   return ver_status;
}
/**
* @brief  This function writes data to internal EEPROM.
* @param  uint8_t *buff: The pointer to the data to be written.
*         - uint16_t length: The length of the data to be written.  
* @retval None.
*/
void WMBus_PhyWriteMeterDatabase(uint8_t *buff, uint16_t length, uint32_t Saddress)
{
  for(uint8_t eindex=0; eindex<10; eindex++)
  {
    switch(eindex)
    {
    case 0:
      WMBus_PhyReadMeterDatabase(EEPROM_METER1_DATABASE_START,26, EEPROM_METER1_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER1_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER1_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 1:
      WMBus_PhyReadMeterDatabase(EEPROM_METER2_DATABASE_START, 26, EEPROM_METER2_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER2_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER2_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 2:
      WMBus_PhyReadMeterDatabase(EEPROM_METER3_DATABASE_START, 26, EEPROM_METER3_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER3_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER3_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 3:
      WMBus_PhyReadMeterDatabase(EEPROM_METER4_DATABASE_START, 26, EEPROM_METER4_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER4_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER4_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 4:
      WMBus_PhyReadMeterDatabase(EEPROM_METER5_DATABASE_START, 26, EEPROM_METER5_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER5_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER5_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 5:
      WMBus_PhyReadMeterDatabase(EEPROM_METER6_DATABASE_START, 26, EEPROM_METER6_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER6_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER6_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 6:
      WMBus_PhyReadMeterDatabase(EEPROM_METER7_DATABASE_START, 26, EEPROM_METER7_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER7_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER7_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }      
      break;    
    case 7:
      WMBus_PhyReadMeterDatabase(EEPROM_METER8_DATABASE_START, 26, EEPROM_METER8_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER8_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER8_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }      
      break;
    case 8:
      WMBus_PhyReadMeterDatabase(EEPROM_METER9_DATABASE_START, 26, EEPROM_METER9_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER9_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER9_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }      
      break;
    case 9:
      WMBus_PhyReadMeterDatabase(EEPROM_METER_10_DATABASE_START, 26, EEPROM_METER_10_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER_10_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER_10_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }      
      break;      
    default:
      break;
    }
  }
}