Exemple #1
0
void nrf_nvmc_write_bytes(uint32_t address, const uint8_t * src, uint32_t num_bytes)
{
    for (uint32_t i = 0; i < num_bytes; i++)
    {
       nrf_nvmc_write_byte(address + i, src[i]);
    }
}
Exemple #2
0
static void gzp_set_host_id(const uint8_t* src)
{
  if(*((uint8_t*)GZP_PARAMS_STORAGE_ADR) == 0xff)
  {
    nrf_nvmc_write_bytes(GZP_PARAMS_STORAGE_ADR + 1, src, GZP_HOST_ID_LENGTH);
    nrf_nvmc_write_byte(GZP_PARAMS_STORAGE_ADR, 0x00);
  }    
}
void gzp_host_chip_id_read(uint8_t *dst, uint8_t n)
{
  uint8_t i;
  uint8_t random_number;
  
  if( *((uint8_t*)(GZP_PARAMS_STORAGE_ADR + GZP_HOST_ID_LENGTH + 1)) == 0xff)
  {
    nrf_nvmc_write_byte((GZP_PARAMS_STORAGE_ADR + GZP_HOST_ID_LENGTH + 1) , 0x00);
  
    for(i = 0; i < n; i++) 
    {
      gzp_random_numbers_generate(&random_number, 1);
      nrf_nvmc_write_byte((GZP_PARAMS_STORAGE_ADR + GZP_HOST_ID_LENGTH + 2 + i) , random_number);
    }
  }
  
  for(i = 0; i < n; i++) 
  {
    *(dst++) = *((uint8_t*)(GZP_PARAMS_STORAGE_ADR + GZP_HOST_ID_LENGTH + 2 + i));
  }
}
Exemple #4
0
static void gzp_index_db_add(uint8_t val)
{
    int16_t i;
    uint8_t temp_val;
    uint32_t  addr;

    // Search for unwritten loacation in index DB
    for(i = 0; i < GZP_INDEX_DB_SIZE; i++)
    {
        temp_val = *(uint8_t*)(GZP_INDEX_DB_ADR + i);

        // Lower nibble
        if(i != (GZP_INDEX_DB_SIZE - 1))
        {
            if((temp_val & 0x0f) == 0x0f)
            {
                temp_val = (temp_val & 0xf0) | val;
                break;
            }
            // Upper nibble
            else if((temp_val & 0xf0) == 0xf0)
            {
                temp_val = (temp_val & 0x0f) | (val << 4);
                break;
            }
        }
        else
        {
            temp_val = (GZP_PARAMS_DB_MAX_ENTRIES << 4) | val;
            break;
        }
    }

    // Write index DB
    addr = (GZP_INDEX_DB_ADR + i);
    nrf_nvmc_write_byte(addr, temp_val);
}