/** Return version string from NAP configuration build. * * \param git_hash char [] that version string will be written to. * \return Length of version string. */ u8 nap_conf_rd_version_string(char version_string[]) { u8 count = 0; char c; do { m25_read(NAP_FLASH_VERSION_STRING_ADDR + count, (u8 *)&c, 1); version_string[count] = c; count++; if (c && !isprint((u8)c)) { /* We have hit an unexpected character, this must not be an ASCII version * string. Fall back to old Git Hash style version. */ strcpy(version_string, "OLD "); for (count=0; count<20; count++) { m25_read(NAP_FLASH_GIT_HASH_ADDR + count, (u8 *)&c, 1); snprintf(&version_string[2*count + 4], 3, "%02x", c); } u8 unclean; m25_read(NAP_FLASH_GIT_UNCLEAN_ADDR, &unclean, 1); if (unclean) { strcpy(&version_string[44], " (unclean)"); } count = strlen(version_string); /* Make sure we exit the loop. */ break; } } while (c); return count; }
/** Return git repository cleanliness status from NAP configuration build. * Retrieves cleanliness status of HDL repository at the time FPGA * configuration was built. * * \return 1 if repository was unclean, 0 if clean */ u8 nap_conf_rd_git_unclean(void) { u8 unclean; m25_read(NAP_FLASH_GIT_UNCLEAN_ADDR, &unclean, 1); return unclean; }
/** Return Piksi hardware revision identifier. */ u32 nap_conf_rd_hw_rev() { u8 hw_rev_u8[4]; m25_read(NAP_FLASH_HW_REVISION_ADDR, hw_rev_u8, 4); u32 hw_rev = (hw_rev_u8[0] << 24) | (hw_rev_u8[1] << 16) | (hw_rev_u8[2] << 8) | (hw_rev_u8[3] << 0); return hw_rev; }
/** Return Piksi serial number from the configuration flash. */ s32 nap_conf_rd_serial_number() { u8 serial_num_u8[4]; m25_read(NAP_FLASH_SERIAL_NUMBER_ADDR, serial_num_u8, 4); s32 serial_num = (serial_num_u8[0] << 24) | (serial_num_u8[1] << 16) | (serial_num_u8[2] << 8) | (serial_num_u8[3] << 0); return serial_num; }
/** Get NAP configuration parameters from FPGA configuration flash. * Gets information about the NAP configuration (number of code phase taps in * the acquisition channel, number of tracking channels, etc). */ void nap_conf_rd_parameters(void) { /* Define parameters that need to be read from FPGA configuration flash. * Pointers in the array should be in the same order they're stored in the * configuration flash. */ u8 * nap_parameters[2] = { &nap_acq_n_taps, &nap_track_n_channels }; /* Get parameters from FPGA configuration flash */ for (u8 i = 0; i < (sizeof(nap_parameters) / sizeof(nap_parameters[0])); i++) m25_read(NAP_FLASH_PARAMS_ADDR + i, nap_parameters[i], 1); }
void flash_read_callback(u8 buff[]) { // Msg format: u32 addr, u32 len u32 addr, len; static char flash_data[16]; addr = *(u32 *)&buff[0]; len = *(u32 *)&buff[4]; printf("SPI Flash reading %d bytes from 0x%06X:\n", (int)len, (unsigned int)addr); while (len) { u8 chunk_len = 16; if (len < 16) chunk_len = len; m25_read(addr, chunk_len, (u8 *)flash_data); printf("%08X: ", (unsigned int)addr); for (u8 chunk_i = 0; chunk_i < chunk_len; chunk_i++) printf("%02X ", flash_data[chunk_i]); /* printf(" "); for (u8 chunk_i = 0; chunk_i < chunk_len; chunk_i++) if (flash_data[chunk_i] >= 32) printf("%c", flash_data[chunk_i]); else printf("."); */ printf("\n"); len -= chunk_len; addr += chunk_len; } }
/** Return git commit hash from NAP configuration build. * Retrieves commit hash of HDL repository at the time FPGA configuration was * built. * * \param git_hash Array of u8 (length 20) in which git hash will be put. */ void nap_conf_rd_git_hash(u8 git_hash[]) { m25_read(NAP_FLASH_GIT_HASH_ADDR, git_hash, 20); }