112 lines
3.2 KiB
C
Executable File
112 lines
3.2 KiB
C
Executable File
/*
|
|
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
|
*
|
|
* SPDX-License-Identifier: CC0-1.0
|
|
*/
|
|
|
|
#include "esp_chip_info.h"
|
|
#include "esp_err.h"
|
|
#include "esp_flash.h"
|
|
#include "esp_log.h"
|
|
#include "esp_spi_flash.h"
|
|
#include "esp_system.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "nvs_flash.h"
|
|
#include "sdkconfig.h"
|
|
#include <inttypes.h>
|
|
#include <stdio.h>
|
|
|
|
#include "shell_port.h"
|
|
#include "main_app.h"
|
|
#include "main_common.h"
|
|
#include "imp_msg_queue.h"
|
|
|
|
static void _init_esp()
|
|
{
|
|
// Initialize NVS
|
|
esp_err_t ret = nvs_flash_init();
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES
|
|
|| ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
ret = nvs_flash_init();
|
|
}
|
|
ESP_ERROR_CHECK(ret);
|
|
}
|
|
|
|
void app_main(void)
|
|
{
|
|
_init_esp();
|
|
vTaskDelay(10);
|
|
cdc_acm_msc_init();
|
|
vTaskDelay(10);
|
|
userShellInit();
|
|
vTaskDelay(10);
|
|
cdc_printf("Hello world!\r\n");
|
|
|
|
/* Print chip information */
|
|
esp_chip_info_t chip_info;
|
|
uint32_t flash_size;
|
|
esp_chip_info(&chip_info);
|
|
cdc_printf("This is %s chip with %d CPU core(s), %s%s%s%s, ",
|
|
CONFIG_IDF_TARGET, chip_info.cores,
|
|
(chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "",
|
|
(chip_info.features & CHIP_FEATURE_BT) ? "BT" : "",
|
|
(chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "",
|
|
(chip_info.features & CHIP_FEATURE_IEEE802154)
|
|
? ", 802.15.4 (Zigbee/Thread)"
|
|
: "");
|
|
|
|
unsigned major_rev = chip_info.revision / 100;
|
|
unsigned minor_rev = chip_info.revision % 100;
|
|
cdc_printf("silicon revision v%d.%d, ", major_rev, minor_rev);
|
|
if (esp_flash_get_size(NULL, &flash_size) != ESP_OK) {
|
|
cdc_printf("Get flash size failed");
|
|
return;
|
|
}
|
|
|
|
cdc_printf("%" PRIu32 "MB %s flash\r\n",
|
|
flash_size / (uint32_t)(1024 * 1024),
|
|
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded"
|
|
: "external");
|
|
|
|
cdc_printf("Minimum free heap size: %" PRIu32 " bytes\r\n",
|
|
esp_get_minimum_free_heap_size());
|
|
|
|
// for (int i = 10; i >= 0; i--) {
|
|
// printf("Restarting in %d seconds...\n", i);
|
|
// vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
// }
|
|
cdc_printf("start run app:\r\n");
|
|
|
|
|
|
imp_msg_queue_init();
|
|
xTaskCreate(imp_main_app_task, "main", 2048, NULL, 10, NULL);
|
|
|
|
while (1) {
|
|
// cdc_printf("start run app:\r\n");
|
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
}
|
|
|
|
cdc_printf("Restarting now.\r\n");
|
|
fflush(stdout);
|
|
esp_restart();
|
|
}
|
|
|
|
static void _show_build_time(int argc, char** argv)
|
|
{
|
|
cdc_printf("build at %s %s\r\n", __DATE__, __TIME__);
|
|
}
|
|
|
|
static uint8_t imp_restart_esp()
|
|
{
|
|
cdc_printf("Restarting now.\r\n");
|
|
vTaskDelay(10);
|
|
esp_restart();
|
|
}
|
|
|
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
|
reboot, imp_restart_esp, restart esp);
|
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
|
show_build_time, _show_build_time, show the build time);
|