uint32_t FlashIAP::get_page_size() const { return flash_get_page_size(&_flash); }
/** * Initializes the High Level System such as IO Pins and Drivers */ void high_level_init(void) { // Initialize all board pins (early) that are connected internally. board_io_pins_initialize(); /** * Initialize the Peripherals used in the system. * I2C2 : Used by LED Display, Acceleration Sensor, Temperature Sensor * ADC0 : Used by Light Sensor * SPI0 : Used by Nordic * SPI1 : Used by SD Card & External SPI Flash Memory */ adc0_init(); ssp1_init(); ssp0_init(SYS_CFG_SPI0_CLK_MHZ); if (!I2C2::getInstance().init(SYS_CFG_I2C2_CLK_KHZ)) { puts("ERROR: Possible short on SDA or SCL wire (I2C2)!"); } /** * This timer does several things: * - Makes delay_ms() and delay_us() methods functional. * - Provides run-time counter for FreeRTOS task statistics (cpu usage) * - Provides timer needed by SD card init() and mesh network: nordic driver uses delay_us() * * The slightly tricky part is that the mesh networking task will start to be serviced every * one millisecond, so initialize this and immediately initialize the wireless (mesh/nordic) * so by the time 1ms elapses, the pointers are initalized (and not NULL). */ lpc_sys_setup_system_timer(); /* After the Nordic SPI is initialized, initialize the wireless system asap otherwise * the background task may access NULL pointers of the mesh networking task. * * @warning Need SSP0 init before initializing nordic wireless. * @warning Nordic uses timer delay, so we need the timer setup. */ if (!wireless_init()) { puts("ERROR: Failed to initialize wireless"); } /* Add default telemetry components if telemetry is enabled */ #if SYS_CFG_ENABLE_TLM tlm_component_add(SYS_CFG_DISK_TLM_NAME); tlm_component_add(SYS_CFG_DEBUG_DLM_NAME); #endif /** * User configured startup delay to close Hyperload COM port and re-open it at Hercules serial window. * Since the timer is setup that is now resetting the watchdog, we can delay without a problem. */ delay_ms(SYS_CFG_STARTUP_DELAY_MS); hl_print_line(); /* Print out CPU speed and what caused the system boot */ hl_print_boot_info(); /** * If Flash is not mounted, it is probably a new board and the flash is not * formatted so format it, so alert the user, and try to re-mount it. */ if (!hl_mount_storage(Storage::getFlashDrive(), " Flash ")) { printf("Erasing and formatting SPI flash, this can take a while ... "); flash_chip_erase(); printf("%s\n", FR_OK == Storage::getFlashDrive().format() ? "Done" : "Error"); if (!hl_mount_storage(Storage::getFlashDrive(), " Flash ")) { printf("SPI FLASH is possibly damaged!\n"); printf("Page size: %u\n", (unsigned) flash_get_page_size()); printf("Mem size: %u (raw bytes)\n", (unsigned) (flash_get_page_count() * flash_get_page_size())); } } hl_mount_storage(Storage::getSDDrive(), "SD Card"); /* SD card initialization modifies the SPI speed, so after it has been initialized, reset desired speed for spi1 */ ssp1_set_max_clock(SYS_CFG_SPI1_CLK_MHZ); hl_print_line(); /* File I/O is up, so log the boot message if chosen by the user */ #ifdef SYS_CFG_LOG_BOOT_INFO_FILENAME log_boot_info(__DATE__); #endif /* File I/O is up, so initialize the logger if user chose the option */ #if SYS_CFG_INITIALIZE_LOGGER logger_init(SYS_CFG_LOGGER_TASK_PRIORITY); #endif /* Initialize all sensors of this board and display "--" on the LED display if an error has occurred. */ if(!hl_init_board_io()) { hl_print_line(); LD.setLeftDigit('-'); LD.setRightDigit('-'); LE.setAll(0xFF); } else { LD.setNumber(TS.getFarenheit()); } /* After Flash memory is mounted, try to set node address from a file */ hl_wireless_set_addr_from_file(); /* Feed the random seed to get random numbers from the rand() function */ srand(LS.getRawValue() + time(NULL)); /* Print memory information before we call main() */ do { char buff[512] = { 0 }; sys_get_mem_info_str(buff); printf("%s", buff); hl_print_line(); } while(0); /* Print miscellaneous info */ hl_handle_board_id(); hl_show_prog_info(); hl_print_line(); /* and finally ... call the user's main() method */ puts("Calling your main()"); hl_print_line(); }