| /**************************************************************************** |
| * boards/risc-v/espressif/esp32h2-generic/src/esp32h2_bringup.c |
| * |
| * Licensed to the Apache Software Foundation (ASF) under one or more |
| * contributor license agreements. See the NOTICE file distributed with |
| * this work for additional information regarding copyright ownership. The |
| * ASF licenses this file to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance with the |
| * License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| * License for the specific language governing permissions and limitations |
| * under the License. |
| * |
| ****************************************************************************/ |
| |
| /**************************************************************************** |
| * Included Files |
| ****************************************************************************/ |
| |
| #include <nuttx/config.h> |
| |
| #include <debug.h> |
| #include <fcntl.h> |
| #include <syslog.h> |
| #include <sys/ioctl.h> |
| #include <sys/stat.h> |
| #include <sys/types.h> |
| #include <unistd.h> |
| |
| #include <nuttx/fs/fs.h> |
| |
| #include "esp_board_ledc.h" |
| |
| #ifdef CONFIG_WATCHDOG |
| # include "esp_wdt.h" |
| #endif |
| |
| #ifdef CONFIG_TIMER |
| # include "esp_timer.h" |
| #endif |
| |
| #ifdef CONFIG_ONESHOT |
| # include "esp_oneshot.h" |
| #endif |
| |
| #ifdef CONFIG_RTC_DRIVER |
| # include "esp_rtc.h" |
| #endif |
| |
| #ifdef CONFIG_DEV_GPIO |
| # include "esp_gpio.h" |
| #endif |
| |
| #ifdef CONFIG_INPUT_BUTTONS |
| # include <nuttx/input/buttons.h> |
| #endif |
| |
| #include "esp32h2-generic.h" |
| |
| /**************************************************************************** |
| * Pre-processor Definitions |
| ****************************************************************************/ |
| |
| /**************************************************************************** |
| * Public Functions |
| ****************************************************************************/ |
| |
| /**************************************************************************** |
| * Name: esp_bringup |
| * |
| * Description: |
| * Perform architecture-specific initialization. |
| * |
| * CONFIG_BOARD_LATE_INITIALIZE=y : |
| * Called from board_late_initialize(). |
| * |
| * CONFIG_BOARD_LATE_INITIALIZE=y && CONFIG_BOARDCTL=y : |
| * Called from the NSH library via board_app_initialize(). |
| * |
| * Input Parameters: |
| * None. |
| * |
| * Returned Value: |
| * Zero (OK) is returned on success; A negated errno value is returned on |
| * any failure. |
| * |
| ****************************************************************************/ |
| |
| int esp_bringup(void) |
| { |
| int ret = OK; |
| |
| #ifdef CONFIG_FS_PROCFS |
| /* Mount the procfs file system */ |
| |
| ret = nx_mount(NULL, "/proc", "procfs", 0, NULL); |
| if (ret < 0) |
| { |
| _err("Failed to mount procfs at /proc: %d\n", ret); |
| } |
| #endif |
| |
| #ifdef CONFIG_FS_TMPFS |
| /* Mount the tmpfs file system */ |
| |
| ret = nx_mount(NULL, CONFIG_LIBC_TMPDIR, "tmpfs", 0, NULL); |
| if (ret < 0) |
| { |
| _err("Failed to mount tmpfs at %s: %d\n", CONFIG_LIBC_TMPDIR, ret); |
| } |
| #endif |
| |
| #ifdef CONFIG_WATCHDOG |
| ret = esp_wdt_initialize(); |
| if (ret < 0) |
| { |
| _err("Failed to initialize WDT: %d\n", ret); |
| } |
| #endif |
| |
| #ifdef CONFIG_TIMER |
| ret = esp_timer_initialize(0); |
| if (ret < 0) |
| { |
| _err("Failed to initialize Timer 0: %d\n", ret); |
| } |
| |
| #ifndef CONFIG_ONESHOT |
| ret = esp_timer_initialize(1); |
| if (ret < 0) |
| { |
| _err("Failed to initialize Timer 1: %d\n", ret); |
| } |
| #endif |
| #endif |
| |
| #ifdef CONFIG_ONESHOT |
| ret = esp_oneshot_initialize(); |
| if (ret < 0) |
| { |
| _err("Failed to initialize Oneshot Timer: %d\n", ret); |
| } |
| #endif |
| |
| #ifdef CONFIG_RTC_DRIVER |
| /* Initialize the RTC driver */ |
| |
| ret = esp_rtc_driverinit(); |
| if (ret < 0) |
| { |
| _err("Failed to initialize the RTC driver: %d\n", ret); |
| } |
| #endif |
| |
| #ifdef CONFIG_DEV_GPIO |
| ret = esp_gpio_init(); |
| if (ret < 0) |
| { |
| ierr("Failed to initialize GPIO Driver: %d\n", ret); |
| } |
| #endif |
| |
| #if defined(CONFIG_INPUT_BUTTONS) && defined(CONFIG_INPUT_BUTTONS_LOWER) |
| /* Register the BUTTON driver */ |
| |
| ret = btn_lower_initialize("/dev/buttons"); |
| if (ret < 0) |
| { |
| ierr("ERROR: btn_lower_initialize() failed: %d\n", ret); |
| } |
| #endif |
| |
| #ifdef CONFIG_ESPRESSIF_LEDC |
| ret = board_ledc_setup(); |
| if (ret < 0) |
| { |
| syslog(LOG_ERR, "ERROR: board_ledc_setup() failed: %d\n", ret); |
| } |
| #endif /* CONFIG_ESPRESSIF_LEDC */ |
| |
| /* If we got here then perhaps not all initialization was successful, but |
| * at least enough succeeded to bring-up NSH with perhaps reduced |
| * capabilities. |
| */ |
| |
| return ret; |
| } |