/** * This function reads data from flash memory. * this function should be treated carefully!!!!!!! * never read from both flashes at the same time!!! */ void read_flash(uint32_t saddr, uint32_t len, uint8_t *pval) { if (saddr < DATA_E_ADDR_EMBEDDED) { // read from embedded flash uint8_t *paddr = (uint8_t*)((vu32*)saddr); //pointer to start adress uint8_t *peaddr = (uint8_t*)((vu32*)(saddr+len)); //pointer to end address //while start address is less then end address while(paddr < peaddr){ *pval = *paddr; //value of pval is value at beginning adress paddr++; //increase beginning address by 8 bytes pval++; //increase pval by 8 bytes } } else { // read from external flash spi_flash_read_data(saddr-DATA_E_ADDR_EMBEDDED, pval, len); } }
bool nvds_read_bdaddr_from_da14583_flash(void) { struct product_header ph; bool status = false; // Power up peripherals' power domain SetBits16(PMU_CTRL_REG, PERIPH_SLEEP, 0); while (!(GetWord16(SYS_STAT_REG) & PER_IS_UP)) ; // Enable the pads SetBits16(SYS_CTRL_REG, PAD_LATCH_EN, 1); // Initialize DA14583 internal flash da14583_spi_flash_init(); // Zero out product header variable memset(&ph, 0, sizeof(struct product_header)); // Read product header from SPI flash spi_flash_read_data((uint8_t*)&ph, (unsigned long)PRODUCT_HEADER_OFFSET, (unsigned long)sizeof(struct product_header)); // If product header is valid if( (ph.signature[0] == PRODUCT_HEADER_SIGNATURE1) || (ph.signature[1] == PRODUCT_HEADER_SIGNATURE2)) { // if BD address field of product header is not equal to all zeros or all 0xFFs if ( (0 != memcmp(&ph.bd_addr, &all_ones_bdaddr, 6)) && (0 != memcmp(&ph.bd_addr, &co_null_bdaddr, 6)) ) { // Set the product header BD address field as the device's BD address memcpy(&dev_bdaddr, &ph.bd_addr, sizeof(dev_bdaddr)); status = true; } } // Release DA14583 internal flash da14583_spi_flash_release(); return status; }