patacongo commented on a change in pull request #1728: URL: https://github.com/apache/incubator-nuttx/pull/1728#discussion_r489471395
########## File path: boards/arm/sama5/giant-board/src/sam_bringup.c ########## @@ -0,0 +1,400 @@ +/**************************************************************************** + * boards/arm/sama5/giant-board/src/sam_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 <sys/mount.h> +#include <stdlib.h> +#include <syslog.h> +#include <debug.h> +#include <string.h> + +#include <nuttx/irq.h> +#include <nuttx/kthread.h> +#include <nuttx/usb/usbdev.h> +#include <nuttx/usb/usbhost.h> +#include <nuttx/usb/usbdev_trace.h> + +#include "giant-board.h" + +#ifdef CONFIG_CDCACM +# include <nuttx/usb/cdcacm.h> +#endif + +#ifdef CONFIG_NET_CDCECM +# include <nuttx/usb/cdcecm.h> +# include <net/if.h> +#endif + +#ifdef CONFIG_USBMONITOR +# include <nuttx/usb/usbmonitor.h> +#endif + +#ifdef CONFIG_RNDIS +# include <nuttx/usb/rndis.h> +#endif + +#ifdef CONFIG_MMCSD +# include <nuttx/mmcsd.h> +# include "sam_sdmmc.h" +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define NSECTORS(n) \ + (((n)+CONFIG_GIANTBOARD_ROMFS_ROMDISK_SECTSIZE-1) / \ + CONFIG_GIANTBOARD_ROMFS_ROMDISK_SECTSIZE) + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sam_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void sam_i2c_register(int bus) +{ + FAR struct i2c_master_s *i2c; + int ret; + + i2c = sam_i2cbus_initialize(bus); + if (i2c == NULL) + { + i2cerr("ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + i2cerr("ERROR: Failed to register I2C%d driver: %d\n", bus, ret); + sam_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: sam_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void sam_i2ctool(void) +{ +#ifdef CONFIG_SAMA5_TWI0 + sam_i2c_register(0); +#endif +#ifdef CONFIG_SAMA5_TWI1 + sam_i2c_register(1); +#endif +#ifdef CONFIG_SAMA5_TWI2 + sam_i2c_register(2); +#endif +#ifdef CONFIG_SAMA5_TWI3 + sam_i2c_register(3); +#endif +} +#else +# define sam_i2ctool() +#endif + +/**************************************************************************** + * Name: nsh_sdmmc_initialize + * + * Description: + * Initialize SDMMC drivers + * + ****************************************************************************/ + +#ifdef CONFIG_SAMA5_SDMMC + +static int nsh_sdmmc_initialize(void) +{ + struct sdio_dev_s *sdmmc0; + struct sdio_dev_s *sdmmc1; + int ret = 0; + + /* Get an instance of the SDIO interface */ + +#ifdef CONFIG_SAMA5_SDMMC0 + sdmmc0 = sam_sdmmc_sdio_initialize(SDMMC0_SLOTNO); + if (!sdmmc0) + { + mcerr("ERROR: Failed to initialize SD/MMC\n"); + } + else + { + /* Bind the SDIO interface to the MMC/SD driver */ + + ret = mmcsd_slotinitialize(SDMMC0_MINOR, sdmmc0); + if (ret != OK) + { + mcerr("ERROR: Failed to bind SDIO to the MMC/SD driver (slot 0): " + "%d\n", + ret); + } + } + +#ifdef CONFIG_SAMA5D27_SDMMC0_MOUNT + /* Mount the volume on SDMMC0 */ + + ret = mount(CONFIG_SAMA5D27_SDMMC0_MOUNT_BLKDEV, + CONFIG_SAMA5D27_SDMMC0_MOUNT_MOUNTPOINT, + CONFIG_SAMA5D27_SDMMC0_MOUNT_FSTYPE, + 0, NULL); + + if (ret < 0) + { + mcerr("ERROR: Failed to mount %s: %d\n", + CONFIG_SAMA5D27_SDMMC0_MOUNT_MOUNTPOINT, errno); + } +#endif +#endif + +#ifdef CONFIG_SAMA5_SDMMC1 + sdmmc1 = sam_sdmmc_sdio_initialize(SDMMC1_SLOTNO); + if (!sdmmc1) + { + syslog(LOG_ERR, "ERROR: Failed to initialize SD/MMC\n"); + } + else + { + /* Bind the SDIO interface to the MMC/SD driver */ + + ret = mmcsd_slotinitialize(SDMMC1_MINOR, sdmmc1); + if (ret != OK) + { + syslog(LOG_ERR, + "ERROR: Failed to bind SDIO to the MMC/SD driver (slot 0): " + "%d\n", + ret); + } + } + +#ifdef CONFIG_SAMA5D27_SDMMC1_MOUNT + /* Mount the volume on SDMMC1 */ + + ret = mount(CONFIG_SAMA5D27_SDMMC1_MOUNT_BLKDEV, + CONFIG_SAMA5D27_SDMMC1_MOUNT_MOUNTPOINT, + CONFIG_SAMA5D27_SDMMC1_MOUNT_FSTYPE, + 0, NULL); + + if (ret < 0) + { + mcerr("ERROR: Failed to mount %s: %d\n", + CONFIG_SAMA5D27_SDMMC1_MOUNT_MOUNTPOINT, errno); + } +#endif +#endif + + return OK; +} +#else +# define nsh_sdmmc_initialize() (OK) +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sam_bringup + * + * Description: + * Bring up board features + * + ****************************************************************************/ + +int sam_bringup(void) +{ + int ret; + + /* Register I2C drivers on behalf of the I2C tool */ + + sam_i2ctool(); + +#ifdef HAVE_SDMMC +#ifdef CONFIG_SAMA5_SDMMC + /* Initialize SDMCC-based MMC/SD card support */ + + nsh_sdmmc_initialize(); +#endif +#endif + +#ifdef HAVE_AUTOMOUNTER + /* Initialize the auto-mounter */ + + sam_automount_initialize(); +#endif + +#ifdef HAVE_ROMFS + /* Create a ROM disk for the /etc filesystem */ + + ret = romdisk_register(CONFIG_GIANT_BOARD_ROMFS_ROMDISK_MINOR, romfs_img, + NSECTORS(romfs_img_len), + CONFIG_GIANT_BOARD_ROMFS_ROMDISK_SECTSIZE); + if (ret < 0) + { + fserr("ERROR: romdisk_register failed: %d\n", -ret); + } + else + { + /* Mount the file system */ + + ret = mount(CONFIG_GIANT_BOARD_ROMFS_ROMDISK_DEVNAME, + CONFIG_GIANT_BOARD_ROMFS_MOUNT_MOUNTPOINT, + "romfs", MS_RDONLY, NULL); + if (ret < 0) + { + fserr("ERROR: mount(%s,%s,romfs) failed: %d\n", + CONFIG_GIANT_BOARD_ROMFS_ROMDISK_DEVNAME, + CONFIG_GIANT_BOARD_ROMFS_MOUNT_MOUNTPOINT, errno); + } + } +#endif + +#ifdef HAVE_USBHOST + /* Initialize USB host operation. sam_usbhost_initialize() starts a thread + * will monitor for USB connection and disconnection events. + */ + + ret = sam_usbhost_initialize(); + if (ret != OK) + { + uerr("ERROR: Failed to initialize USB host: %d\n", ret); + } +#endif + +#ifdef HAVE_USBMONITOR + /* Start the USB Monitor */ + + ret = usbmonitor_start(); + if (ret != OK) + { + _uerr("ERROR: Failed to start the USB monitor: %d\n", ret); + } +#endif + +#ifdef HAVE_MAXTOUCH + /* Initialize the touchscreen */ + + ret = sam_tsc_setup(0); + if (ret < 0) + { + tmrerr("ERROR: sam_tsc_setup failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_PWM + /* Initialize PWM and register the PWM device. */ + + ret = sam_pwm_setup(); + if (ret < 0) + { + pwmerr("ERROR: sam_pwm_setup() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_ADC + /* Initialize ADC and register the ADC driver. */ + + ret = sam_adc_setup(); + if (ret < 0) + { + aerr("ERROR: sam_adc_setup failed: %d\n", ret); + } +#endif + +#ifdef HAVE_WM8904 + /* Configure WM8904 audio */ + + ret = sam_wm8904_initialize(0); + if (ret != OK) + { + auderr("ERROR: Failed to initialize WM8904 audio: %d\n", ret); + } +#endif + Review comment: R ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org