int main(void) { flash_led(LED1); // init logger log_init(&log, "main"); // init filesystem sdcard_mount(&sddisk, 0); // init networking net_config(&netconf, DEFAULT_RESOLV_CONF_PATH, DEFAULT_NETIF_CONF_PATH); net_init(&netconf); log_info(&log, "device init done..."); install_builtin_cmds(&shell); install_fs_cmds(&shell); install_net_cmds(&shell); install_os_cmds(&shell); register_command(&shell, &sh_custom_cmd, NULL, NULL, NULL); start_shell_threaded_server(&shell, NULL, DEFAULT_SHELL_CONFIG_PATH, true, -1, -1, 512); log_info(&log, "service init done..."); pthread_exit(0); return 0; }
int main(void) { // use the system led flasher to flash one of the leds flash_led(LED1); appdata_t appdata; log_init(&appdata.log, "main"); // initialise filesystem sdcard_mount(&sddisk, 0); // initialize the test usart device log_info(&appdata.log, "init %s on %s...", TEST_USART_DEV, "TEST_USART"); usart_create_dev(TEST_USART_DEV, TEST_USART, USART_FULLDUPLEX, 115200, TEST_USART_BUFSIZE); // start up the application pthread_t app_thread; pthread_attr_t app_attr; pthread_attr_init(&app_attr); pthread_attr_setstacksize(&app_attr, 384); pthread_attr_setdetachstate(&app_attr, PTHREAD_CREATE_DETACHED); pthread_create(&app_thread, &app_attr, (void*(*)(void*))test_task, &appdata); pthread_attr_destroy(&app_attr); pthread_exit(0); return 0; }
int main(void) { int i; if(sdcard_mount(&sddisk, 0) == FR_OK) { // open a new file for writing if(f_open(&appdata.file, TEST_FILENAME, FA_WRITE|FA_OPEN_ALWAYS) == FR_OK) { // flash twice appdata.flash = 2; // write a number to the file (no newline needed in this case) f_puts((const TCHAR *)TEST_FLASHES, &appdata.file); f_close(&appdata.file); } // open the new file for reading if(f_open(&appdata.file, TEST_FILENAME, FA_READ) == FR_OK) { // flash three times appdata.flash = 3; if(f_gets((TCHAR *)appdata.buffer, sizeof(appdata.buffer)-1, &appdata.file)) { // flash the number of times set in the file // decode the number in the file appdata.flash = atoi(appdata.buffer); } f_close(&appdata.file); } } while(1) { for(i = 0; i < appdata.flash; i++) { set_led(LED1); usleep(100000); clear_led(LED1); usleep(200000); } sleep(1); } return 0; }
int main(void) { flash_led(LED1); log_init(&log, "main"); // init filesystem sdcard_mount(&sddisk, 0); // start demo app pthread_t app_thread; pthread_attr_t app_attr; pthread_attr_init(&app_attr); pthread_attr_setstacksize(&app_attr, 384); pthread_attr_setdetachstate(&app_attr, PTHREAD_CREATE_DETACHED); pthread_create(&app_thread, &app_attr, (void*(*)(void*))test, NULL); pthread_attr_destroy(&app_attr); pthread_exit(0); return 0; }
esp_err_t periph_sdcard_mount(esp_periph_handle_t periph) { VALIDATE_SDCARD(periph, ESP_FAIL); periph_sdcard_t *sdcard = esp_periph_get_data(periph); int ret = sdcard_mount(sdcard->root); if (ret == ESP_OK) { ESP_LOGD(TAG, "Mount SDCARD success"); sdcard->is_mounted = true; return esp_periph_send_event(periph, SDCARD_STATUS_MOUNTED, NULL, 0); } else if (ret == ESP_ERR_INVALID_STATE) { ESP_LOGD(TAG, "periph sdcard handle already mounted!"); return ESP_OK; } else { esp_periph_send_event(periph, SDCARD_STATUS_MOUNT_ERROR, NULL, 0); sdcard->is_mounted = false; ESP_LOGE(TAG, "mount sdcard error!"); return ESP_FAIL; } }
int main(void) { halInit(); chSysInit(); timestamp_stm32_init(); board_io_pwr_en(true); board_sensor_pwr_en(true); error_init(); // standard output sdStart(&UART_CONN1, NULL); stdout = (BaseSequentialStream*)&UART_CONN1; chprintf(stdout, "\n\n\n"); log_init(); log_handler_register(&log_handler_stdout, LOG_LVL_DEBUG, log_handler_stdout_cb); log_info("=== boot ==="); led_start(); // mount SD card board_power_cycle_sdcard(); sdcStart(&SDCD1, NULL); sdcard_mount(); static char logdir[100]; if (sdcard_find_next_file_name_with_prefix("/", "log_", logdir, sizeof(logdir)) < 0) { log_error("could not determine log file directory"); } FRESULT res = f_mkdir(logdir); if (!(res == FR_OK || res == FR_EXIST)) { log_warning("could not create log directory %s", logdir); } size_t logdir_strlen = strlen(logdir); if (sdcard_is_mounted()) { // add .txt to logdir strncpy(&logdir[logdir_strlen], "/log.txt", sizeof(logdir) - logdir_strlen); logdir[sizeof(logdir)-1] = '\0'; sdcard_log_handler_init(logdir, LOG_LVL_INFO); logdir[logdir_strlen] = '\0'; // reset log dir string } log_boot_message(); // initialization parameter_namespace_declare(¶meters, NULL, NULL); // root namespace parameter_string_declare_with_default(&board_name, ¶meters, "name", board_name_p_buf, sizeof(board_name_p_buf), "ins-board"); msgbus_init(&bus); services_init(); // load parameters from SD card log_info("loading parameters from sd card"); sdcard_read_parameter(¶meters, "/config.msgpack"); chprintf(stdout, "current parameters:"); parameter_print(¶meters, (parameter_printfn_t)chprintf, stdout); // UART driver io_setup(); // USB serial driver sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(100); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); // start all services services_start(logdir); // shellInit(); // char buf[STREAM_DEV_STR_SIZE]; // parameter_string_get(&shell_port, buf, sizeof(buf)); // BaseSequentialStream* shell_dev = get_base_seq_stream_device_from_str(buf); // static thread_t *shelltp = NULL; // static ShellConfig shell_cfg; // shell_cfg.sc_channel = shell_dev; // shell_cfg.sc_commands = shell_commands; chThdSleepMilliseconds(500); while (true) { // if (shelltp == NULL && shell_dev != NULL) { // static THD_WORKING_AREA(shell_wa, 2048); // shelltp = shellCreateStatic(&shell_cfg, shell_wa, sizeof(shell_wa), THD_PRIO_SHELL); // } else if (shelltp != NULL && chThdTerminatedX(shelltp)) { // shelltp = NULL; // } log_debug("VCC %f", analog_get_vcc()); log_debug("Temp %f", analog_get_cpu_temp()); log_debug("V_DC %f", analog_get_vdc()); log_debug("CONN2_TX %f", analog_get_voltage(ANALOG_CH_CONN2_TX)); log_debug("CONN2_RX %f", analog_get_voltage(ANALOG_CH_CONN2_RX)); log_debug("CONN3_TX %f", analog_get_voltage(ANALOG_CH_CONN3_TX)); log_debug("CONN3_RX %f", analog_get_voltage(ANALOG_CH_CONN3_RX)); chThdSleepMilliseconds(500); } }