diff --git a/boards/mips/pic32mx/mirtoo/src/Makefile b/boards/mips/pic32mx/mirtoo/src/Makefile index f9c20b171f9..7a8821c60c8 100644 --- a/boards/mips/pic32mx/mirtoo/src/Makefile +++ b/boards/mips/pic32mx/mirtoo/src/Makefile @@ -32,8 +32,4 @@ ifeq ($(CONFIG_PIC32MX_ADC),y) CSRCS += pic32_adc.c endif -ifeq ($(CONFIG_BOARDCTL),y) -CSRCS += pic32_appinit.c -endif - include $(TOPDIR)/boards/Board.mk diff --git a/boards/mips/pic32mx/mirtoo/src/pic32_appinit.c b/boards/mips/pic32mx/mirtoo/src/pic32_appinit.c deleted file mode 100644 index 7df470dd4a0..00000000000 --- a/boards/mips/pic32mx/mirtoo/src/pic32_appinit.c +++ /dev/null @@ -1,162 +0,0 @@ -/**************************************************************************** - * boards/mips/pic32mx/mirtoo/src/pic32_appinit.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * 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 - -#include -#include -#include -#include - -#include -#include - -#ifdef CONFIG_PIC32MX_SPI2 -# include -# include -# include -#endif - -#include "pic32mx.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Configuration ************************************************************/ - -/* Can't support the SST25 device if it SPI2/SST25 support is not enabled */ - -#define HAVE_SST25 1 -#if !defined(CONFIG_PIC32MX_SPI2) || !defined(CONFIG_MTD_SST25) -# undef HAVE_SST25 -#endif - -/* Can't support SST25 features if mountpoints are disabled */ - -#if defined(CONFIG_DISABLE_MOUNTPOINT) -# undef HAVE_SST25 -#endif - -/* Use minor device number 0 is not is provided */ - -#ifndef CONFIG_NSH_MMCSDMINOR -# define CONFIG_NSH_MMCSDMINOR 0 -#endif - -/* Can't support both FAT and NXFFS */ - -#if defined(CONFIG_FS_FAT) && defined(CONFIG_FS_NXFFS) -# warning "Can't support both FAT and NXFFS -- using FAT" -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: board_app_initialize - * - * Description: - * Perform architecture specific initialization - * - * Input Parameters: - * arg - The boardctl() argument is passed to the board_app_initialize() - * implementation without modification. The argument has no - * meaning to NuttX; the meaning of the argument is a contract - * between the board-specific initialization logic and the - * matching application logic. The value could be such things as a - * mode enumeration value, a set of DIP switch switch settings, a - * pointer to configuration data read from a file or serial FLASH, - * or whatever you would like to do with it. Every implementation - * should accept zero/NULL as a default configuration. - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned on - * any failure to indicate the nature of the failure. - * - ****************************************************************************/ - -int board_app_initialize(uintptr_t arg) -{ -#ifdef HAVE_SST25 - struct spi_dev_s *spi; - struct mtd_dev_s *mtd; - int ret; - - /* Get the SPI port */ - - spi = pic32mx_spibus_initialize(2); - if (!spi) - { - ferr("ERROR: Failed to initialize SPI port 2\n"); - return -ENODEV; - } - - /* Now bind the SPI interface to the SST 25 SPI FLASH driver */ - - mtd = sst25_initialize(spi); - if (!mtd) - { - ferr("ERROR: Failed to bind SPI port 2 to the SST 25 FLASH driver\n"); - return -ENODEV; - } - -#ifndef CONFIG_FS_NXFFS - /* Register the MTD driver */ - - char path[32]; - snprintf(path, sizeof(path), "/dev/mtdblock%d", CONFIG_NSH_MMCSDMINOR); - ret = register_mtddriver(path, mtd, 0755, NULL); - if (ret < 0) - { - ferr("ERROR: Failed to register the MTD driver %s, ret %d\n", - path, ret); - return ret; - } -#else - /* Initialize to provide NXFFS on the MTD interface */ - - ret = nxffs_initialize(mtd); - if (ret < 0) - { - ferr("ERROR: NXFFS initialization failed: %d\n", -ret); - return ret; - } - - /* Mount the file system at /mnt/sst25 */ - - ret = nx_mount(NULL, "/mnt/sst25", "nxffs", 0, NULL); - if (ret < 0) - { - ferr("ERROR: Failed to mount the NXFFS volume: %d\n", ret); - return ret; - } -#endif -#endif - - return OK; -} diff --git a/boards/mips/pic32mx/mirtoo/src/pic32_boot.c b/boards/mips/pic32mx/mirtoo/src/pic32_boot.c index 21f0f8dfd3e..1b4845471cc 100644 --- a/boards/mips/pic32mx/mirtoo/src/pic32_boot.c +++ b/boards/mips/pic32mx/mirtoo/src/pic32_boot.c @@ -28,7 +28,19 @@ #include +#include +#include +#include + +#include #include +#include + +#ifdef CONFIG_PIC32MX_SPI2 +# include +# include +# include +#endif #include "mips_internal.h" #include "pic32mx.h" @@ -45,6 +57,33 @@ #define GPIO_U2TX (GPIO_OUTPUT|GPIO_PORTB|GPIO_PIN10) #define GPIO_U2RX (GPIO_INPUT|GPIO_PORTB|GPIO_PIN11) +/* Configuration ************************************************************/ + +/* Can't support the SST25 device if it SPI2/SST25 support is not enabled */ + +#define HAVE_SST25 1 +#if !defined(CONFIG_PIC32MX_SPI2) || !defined(CONFIG_MTD_SST25) +# undef HAVE_SST25 +#endif + +/* Can't support SST25 features if mountpoints are disabled */ + +#if defined(CONFIG_DISABLE_MOUNTPOINT) +# undef HAVE_SST25 +#endif + +/* Use minor device number 0 is not is provided */ + +#ifndef CONFIG_NSH_MMCSDMINOR +# define CONFIG_NSH_MMCSDMINOR 0 +#endif + +/* Can't support both FAT and NXFFS */ + +#if defined(CONFIG_FS_FAT) && defined(CONFIG_FS_NXFFS) +# warning "Can't support both FAT and NXFFS -- using FAT" +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -149,3 +188,78 @@ void pic32mx_boardinitialize(void) pic32mx_led_initialize(); #endif } + +/**************************************************************************** + * Name: board_late_initialize + * + * Description: + * If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_late_initialize(). board_late_initialize() will be + * called immediately after up_initialize() is called and just before the + * initial application is started. This additional initialization phase + * may be used, for example, to initialize board-specific device drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_LATE_INITIALIZE +void board_late_initialize(void) +{ +#ifdef HAVE_SST25 + struct spi_dev_s *spi; + struct mtd_dev_s *mtd; + int ret; + + /* Get the SPI port */ + + spi = pic32mx_spibus_initialize(2); + if (!spi) + { + ferr("ERROR: Failed to initialize SPI port 2\n"); + return; + } + + /* Now bind the SPI interface to the SST 25 SPI FLASH driver */ + + mtd = sst25_initialize(spi); + if (!mtd) + { + ferr("ERROR: Failed to bind SPI port 2 to the SST 25 FLASH driver\n"); + return; + } + +#ifndef CONFIG_FS_NXFFS + /* Register the MTD driver */ + + char path[32]; + snprintf(path, sizeof(path), "/dev/mtdblock%d", CONFIG_NSH_MMCSDMINOR); + ret = register_mtddriver(path, mtd, 0755, NULL); + if (ret < 0) + { + ferr("ERROR: Failed to register the MTD driver %s, ret %d\n", + path, ret); + return; + } +#else + /* Initialize to provide NXFFS on the MTD interface */ + + ret = nxffs_initialize(mtd); + if (ret < 0) + { + ferr("ERROR: NXFFS initialization failed: %d\n", -ret); + return; + } + + /* Mount the file system at /mnt/sst25 */ + + ret = nx_mount(NULL, "/mnt/sst25", "nxffs", 0, NULL); + if (ret < 0) + { + ferr("ERROR: Failed to mount the NXFFS volume: %d\n", ret); + return; + } +#endif +#endif +} + +#endif /* CONFIG_BOARD_LATE_INITIALIZE */ diff --git a/boards/mips/pic32mx/pic32mx-starterkit/src/Makefile b/boards/mips/pic32mx/pic32mx-starterkit/src/Makefile index 5d183b47557..f7ce3c71283 100644 --- a/boards/mips/pic32mx/pic32mx-starterkit/src/Makefile +++ b/boards/mips/pic32mx/pic32mx-starterkit/src/Makefile @@ -28,10 +28,6 @@ ifeq ($(CONFIG_PIC32MX_USBDEV),y) CSRCS += pic32mx_usbdev.c endif -ifeq ($(CONFIG_BOARDCTL),y) -CSRCS += pic32mx_appinit.c -endif - ifeq ($(CONFIG_USBMSC),y) CSRCS += pic32mx_usbmsc.c endif diff --git a/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_appinit.c b/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_appinit.c deleted file mode 100644 index bbf13a39cad..00000000000 --- a/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_appinit.c +++ /dev/null @@ -1,390 +0,0 @@ -/**************************************************************************** - * boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_appinit.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * 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 - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "pic32mx.h" -#include "pic32mx-starterkit.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Configuration ************************************************************/ - -/* Assume that we have MMC/SD, USB host (and USB device) */ - -#define NSH_HAVEMMCSD 1 -#define NSH_HAVEUSBHOST 1 - -/* The PIC32 Ethernet Starter Kit does not have an SD slot on board. If one - * is added, then it must be specified by defining which SPI bus that it - * is connected on. - */ - -#ifndef CONFIG_PIC32MX_MMCSDSPIPORTNO -# undef NSH_HAVEMMCSD -#endif - -/* Make sure that the configuration will support the SD card */ - -#ifdef NSH_HAVEMMCSD - -/* Make sure that the NSH configuration uses the correct SPI */ - -# if !defined(CONFIG_NSH_MMCSDSPIPORTNO) -# define CONFIG_NSH_MMCSDSPIPORTNO CONFIG_PIC32MX_MMCSDSPIPORTNO -# elif CONFIG_NSH_MMCSDSPIPORTNO != CONFIG_PIC32MX_MMCSDSPIPORTNO -# warning "CONFIG_PIC32MX_MMCSDSPIPORTNO does not match CONFIG_NSH_MMCSDSPIPORTNO" -# undef CONFIG_NSH_MMCSDSPIPORTNO -# define CONFIG_NSH_MMCSDSPIPORTNO CONFIG_PIC32MX_MMCSDSPIPORTNO -# endif - -/* Make sure that the NSH configuration uses the slot */ - -# if !defined(CONFIG_NSH_MMCSDSLOTNO) -# define CONFIG_NSH_MMCSDSLOTNO 0 -# elif CONFIG_NSH_MMCSDSLOTNO != 0 -# warning "The PIC32 Starter Kit has only one slot (0)" -# undef CONFIG_NSH_MMCSDSLOTNO -# define CONFIG_NSH_MMCSDSLOTNO 0 -# endif - -/* Make sure that the correct SPI is enabled in the configuration */ - -# if CONFIG_PIC32MX_MMCSDSPIPORTNO == 1 && !defined(CONFIG_PIC32MX_SPI1) -# warning "CONFIG_PIC32MX_SPI1 is not enabled" -# undef NSH_HAVEMMCSD -# elif CONFIG_PIC32MX_MMCSDSPIPORTNO == 2 && !defined(CONFIG_PIC32MX_SPI2) -# warning "CONFIG_PIC32MX_SPI2 is not enabled" -# undef NSH_HAVEMMCSD -# elif CONFIG_PIC32MX_MMCSDSPIPORTNO == 3 && !defined(CONFIG_PIC32MX_SPI3) -# warning "CONFIG_PIC32MX_SPI3 is not enabled" -# undef NSH_HAVEMMCSD -# elif CONFIG_PIC32MX_MMCSDSPIPORTNO == 4 && !defined(CONFIG_PIC32MX_SPI4) -# warning "CONFIG_PIC32MX_SPI4 is not enabled" -# undef NSH_HAVEMMCSD -# endif -#endif - -/* Can't support MMC/SD features if mountpoints are disabled */ - -#if defined(CONFIG_DISABLE_MOUNTPOINT) -# undef NSH_HAVEMMCSD -#endif - -/* Select /dev/mmcsd0 if no other minor number is provided */ - -#ifndef CONFIG_NSH_MMCSDMINOR -# define CONFIG_NSH_MMCSDMINOR 0 -#endif - -/* USB Host */ - -#ifdef CONFIG_USBHOST -# ifndef CONFIG_PIC32MX_USBHOST -# error "CONFIG_PIC32MX_USBHOST is not selected" -# undef NSH_HAVEUSBHOST -# endif -#endif - -#ifdef CONFIG_PIC32MX_USBHOST -# ifndef CONFIG_USBHOST -# warning "CONFIG_USBHOST is not selected" -# undef NSH_HAVEUSBHOST -# endif -#endif - -#if !defined(CONFIG_USBHOST) || !defined(CONFIG_PIC32MX_USBHOST) -# undef NSH_HAVEUSBHOST -#endif - -#ifdef NSH_HAVEUSBHOST -# ifndef CONFIG_USBHOST_DEFPRIO -# define CONFIG_USBHOST_DEFPRIO 50 -# endif -# ifndef CONFIG_USBHOST_STACKSIZE -# ifdef CONFIG_USBHOST_HUB -# define CONFIG_USBHOST_STACKSIZE 1536 -# else -# define CONFIG_USBHOST_STACKSIZE 1024 -# endif -# endif -#endif - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#ifdef NSH_HAVEUSBHOST -static struct usbhost_connection_s *g_usbconn; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_waiter - * - * Description: - * Wait for USB devices to be connected. - * - ****************************************************************************/ - -#ifdef NSH_HAVEUSBHOST -static int nsh_waiter(int argc, char *argv[]) -{ - struct usbhost_hubport_s *hport; - - syslog(LOG_INFO, "nsh_waiter: Running\n"); - for (; ; ) - { - /* Wait for the device to change state */ - - DEBUGVERIFY(CONN_WAIT(g_usbconn, &hport)); - syslog(LOG_INFO, "nsh_waiter: %s\n", - hport->connected ? "connected" : "disconnected"); - - /* Did we just become connected? */ - - if (hport->connected) - { - /* Yes.. enumerate the newly connected device */ - - CONN_ENUMERATE(g_usbconn, hport); - } - } - - /* Keep the compiler from complaining */ - - return 0; -} -#endif - -/**************************************************************************** - * Name: nsh_sdinitialize - * - * Description: - * Initialize SPI-based microSD. - * - ****************************************************************************/ - -#ifdef NSH_HAVEMMCSD -static int nsh_sdinitialize(void) -{ - struct spi_dev_s *spi; - int ret; - - /* Get the SPI port */ - - spi = pic32mx_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO); - if (!spi) - { - syslog(LOG_ERR, "ERROR: Failed to initialize SPI port %d\n", - CONFIG_NSH_MMCSDSPIPORTNO); - ret = -ENODEV; - goto errout; - } - - syslog(LOG_INFO, "Successfully initialized SPI port %d\n", - CONFIG_NSH_MMCSDSPIPORTNO); - - /* Bind the SPI port to the slot */ - - ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, - CONFIG_NSH_MMCSDSLOTNO, spi); - if (ret < 0) - { - syslog(LOG_ERR, - "ERROR: Failed to bind SPI port %d to MMC/SD slot %d: %d\n", - CONFIG_NSH_MMCSDSPIPORTNO, - CONFIG_NSH_MMCSDSLOTNO, ret); - goto errout; - } - - syslog(LOG_INFO, "Successfully bound SPI port %d to MMC/SD slot %d\n", - CONFIG_NSH_MMCSDSPIPORTNO, - CONFIG_NSH_MMCSDSLOTNO); - return OK; - -errout: - return ret; -} -#else -# define nsh_sdinitialize() (OK) -#endif - -/**************************************************************************** - * Name: nsh_usbhostinitialize - * - * Description: - * Initialize SPI-based microSD. - * - ****************************************************************************/ - -#ifdef NSH_HAVEUSBHOST -static int nsh_usbhostinitialize(void) -{ - int ret; - - /* First, register all of the class drivers needed to support the drivers - * that we care about: - */ - - syslog(LOG_INFO, "Register class drivers\n"); - -#ifdef CONFIG_USBHOST_MSC - /* Register the USB host Mass Storage Class */ - - ret = usbhost_msc_initialize(); - if (ret != OK) - { - syslog(LOG_ERR, - "ERROR: Failed to register the mass storage class: %d\n", ret); - } -#endif - -#ifdef CONFIG_USBHOST_CDCACM - /* Register the CDC/ACM serial class */ - - ret = usbhost_cdcacm_initialize(); - if (ret != OK) - { - syslog(LOG_ERR, - "ERROR: Failed to register the CDC/ACM serial class: %d\n", - ret); - } -#endif - - /* Then get an instance of the USB host interface */ - - syslog(LOG_INFO, "Initialize USB host\n"); - g_usbconn = pic32_usbhost_initialize(0); - if (g_usbconn) - { - /* Start a thread to handle device connection. */ - - syslog(LOG_INFO, "Start nsh_waiter\n"); - - ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, - CONFIG_USBHOST_STACKSIZE, - nsh_waiter, NULL); - return ret < 0 ? -ENOEXEC : OK; - } - - return -ENODEV; -} -#else -# define nsh_usbhostinitialize() (OK) -#endif - -/**************************************************************************** - * Name: nsh_usbdevinitialize - * - * Description: - * Initialize SPI-based microSD. - * - ****************************************************************************/ - -#ifdef CONFIG_USBDEV -static int nsh_usbdevinitialize(void) -{ - /* The PIC32 Starter Kit has no way to know when the USB is connected. So - * we will fake it and tell the USB driver that the USB is connected now. - */ - - pic32mx_usbattach(); - return OK; -} -#else -# define nsh_usbdevinitialize() (OK) -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: board_app_initialize - * - * Description: - * Perform application specific initialization. This function is never - * called directly from application code, but only indirectly via the - * (non-standard) boardctl() interface using the command BOARDIOC_INIT. - * - * Input Parameters: - * arg - The boardctl() argument is passed to the board_app_initialize() - * implementation without modification. The argument has no - * meaning to NuttX; the meaning of the argument is a contract - * between the board-specific initialization logic and the - * matching application logic. The value could be such things as a - * mode enumeration value, a set of DIP switch switch settings, a - * pointer to configuration data read from a file or serial FLASH, - * or whatever you would like to do with it. Every implementation - * should accept zero/NULL as a default configuration. - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned on - * any failure to indicate the nature of the failure. - * - ****************************************************************************/ - -int board_app_initialize(uintptr_t arg) -{ - int ret; - - /* Initialize SPI-based microSD */ - - ret = nsh_sdinitialize(); - if (ret == OK) - { - /* Initialize USB host */ - - ret = nsh_usbhostinitialize(); - } - - if (ret == OK) - { - /* Initialize USB device */ - - ret = nsh_usbdevinitialize(); - } - - return ret; -} diff --git a/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_boot.c b/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_boot.c index b3b9a9d9538..05897f23f1a 100644 --- a/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_boot.c +++ b/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_boot.c @@ -28,7 +28,18 @@ #include +#include +#include +#include +#include +#include + #include +#include +#include +#include +#include +#include #include "mips_internal.h" #include "pic32mx.h" @@ -38,10 +49,297 @@ * Pre-processor Definitions ****************************************************************************/ +/* Configuration ************************************************************/ + +/* Assume that we have MMC/SD, USB host (and USB device) */ + +#define NSH_HAVEMMCSD 1 +#define NSH_HAVEUSBHOST 1 + +/* The PIC32 Ethernet Starter Kit does not have an SD slot on board. If one + * is added, then it must be specified by defining which SPI bus that it + * is connected on. + */ + +#ifndef CONFIG_PIC32MX_MMCSDSPIPORTNO +# undef NSH_HAVEMMCSD +#endif + +/* Make sure that the configuration will support the SD card */ + +#ifdef NSH_HAVEMMCSD + +/* Make sure that the NSH configuration uses the correct SPI */ + +# if !defined(CONFIG_NSH_MMCSDSPIPORTNO) +# define CONFIG_NSH_MMCSDSPIPORTNO CONFIG_PIC32MX_MMCSDSPIPORTNO +# elif CONFIG_NSH_MMCSDSPIPORTNO != CONFIG_PIC32MX_MMCSDSPIPORTNO +# warning "CONFIG_PIC32MX_MMCSDSPIPORTNO does not match CONFIG_NSH_MMCSDSPIPORTNO" +# undef CONFIG_NSH_MMCSDSPIPORTNO +# define CONFIG_NSH_MMCSDSPIPORTNO CONFIG_PIC32MX_MMCSDSPIPORTNO +# endif + +/* Make sure that the NSH configuration uses the slot */ + +# if !defined(CONFIG_NSH_MMCSDSLOTNO) +# define CONFIG_NSH_MMCSDSLOTNO 0 +# elif CONFIG_NSH_MMCSDSLOTNO != 0 +# warning "The PIC32 Starter Kit has only one slot (0)" +# undef CONFIG_NSH_MMCSDSLOTNO +# define CONFIG_NSH_MMCSDSLOTNO 0 +# endif + +/* Make sure that the correct SPI is enabled in the configuration */ + +# if CONFIG_PIC32MX_MMCSDSPIPORTNO == 1 && !defined(CONFIG_PIC32MX_SPI1) +# warning "CONFIG_PIC32MX_SPI1 is not enabled" +# undef NSH_HAVEMMCSD +# elif CONFIG_PIC32MX_MMCSDSPIPORTNO == 2 && !defined(CONFIG_PIC32MX_SPI2) +# warning "CONFIG_PIC32MX_SPI2 is not enabled" +# undef NSH_HAVEMMCSD +# elif CONFIG_PIC32MX_MMCSDSPIPORTNO == 3 && !defined(CONFIG_PIC32MX_SPI3) +# warning "CONFIG_PIC32MX_SPI3 is not enabled" +# undef NSH_HAVEMMCSD +# elif CONFIG_PIC32MX_MMCSDSPIPORTNO == 4 && !defined(CONFIG_PIC32MX_SPI4) +# warning "CONFIG_PIC32MX_SPI4 is not enabled" +# undef NSH_HAVEMMCSD +# endif +#endif + +/* Can't support MMC/SD features if mountpoints are disabled */ + +#if defined(CONFIG_DISABLE_MOUNTPOINT) +# undef NSH_HAVEMMCSD +#endif + +/* Select /dev/mmcsd0 if no other minor number is provided */ + +#ifndef CONFIG_NSH_MMCSDMINOR +# define CONFIG_NSH_MMCSDMINOR 0 +#endif + +/* USB Host */ + +#ifdef CONFIG_USBHOST +# ifndef CONFIG_PIC32MX_USBHOST +# error "CONFIG_PIC32MX_USBHOST is not selected" +# undef NSH_HAVEUSBHOST +# endif +#endif + +#ifdef CONFIG_PIC32MX_USBHOST +# ifndef CONFIG_USBHOST +# warning "CONFIG_USBHOST is not selected" +# undef NSH_HAVEUSBHOST +# endif +#endif + +#if !defined(CONFIG_USBHOST) || !defined(CONFIG_PIC32MX_USBHOST) +# undef NSH_HAVEUSBHOST +#endif + +#ifdef NSH_HAVEUSBHOST +# ifndef CONFIG_USBHOST_DEFPRIO +# define CONFIG_USBHOST_DEFPRIO 50 +# endif +# ifndef CONFIG_USBHOST_STACKSIZE +# ifdef CONFIG_USBHOST_HUB +# define CONFIG_USBHOST_STACKSIZE 1536 +# else +# define CONFIG_USBHOST_STACKSIZE 1024 +# endif +# endif +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifdef NSH_HAVEUSBHOST +static struct usbhost_connection_s *g_usbconn; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: nsh_waiter + * + * Description: + * Wait for USB devices to be connected. + * + ****************************************************************************/ + +#ifdef NSH_HAVEUSBHOST +static int nsh_waiter(int argc, char *argv[]) +{ + struct usbhost_hubport_s *hport; + + syslog(LOG_INFO, "nsh_waiter: Running\n"); + for (; ; ) + { + /* Wait for the device to change state */ + + DEBUGVERIFY(CONN_WAIT(g_usbconn, &hport)); + syslog(LOG_INFO, "nsh_waiter: %s\n", + hport->connected ? "connected" : "disconnected"); + + /* Did we just become connected? */ + + if (hport->connected) + { + /* Yes.. enumerate the newly connected device */ + + CONN_ENUMERATE(g_usbconn, hport); + } + } + + /* Keep the compiler from complaining */ + + return 0; +} +#endif + +/**************************************************************************** + * Name: nsh_sdinitialize + * + * Description: + * Initialize SPI-based microSD. + * + ****************************************************************************/ + +#ifdef NSH_HAVEMMCSD +static int nsh_sdinitialize(void) +{ + struct spi_dev_s *spi; + int ret; + + /* Get the SPI port */ + + spi = pic32mx_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO); + if (!spi) + { + syslog(LOG_ERR, "ERROR: Failed to initialize SPI port %d\n", + CONFIG_NSH_MMCSDSPIPORTNO); + ret = -ENODEV; + goto errout; + } + + syslog(LOG_INFO, "Successfully initialized SPI port %d\n", + CONFIG_NSH_MMCSDSPIPORTNO); + + /* Bind the SPI port to the slot */ + + ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, + CONFIG_NSH_MMCSDSLOTNO, spi); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to bind SPI port %d to MMC/SD slot %d: %d\n", + CONFIG_NSH_MMCSDSPIPORTNO, + CONFIG_NSH_MMCSDSLOTNO, ret); + goto errout; + } + + syslog(LOG_INFO, "Successfully bound SPI port %d to MMC/SD slot %d\n", + CONFIG_NSH_MMCSDSPIPORTNO, + CONFIG_NSH_MMCSDSLOTNO); + return OK; + +errout: + return ret; +} +#else +# define nsh_sdinitialize() (OK) +#endif + +/**************************************************************************** + * Name: nsh_usbhostinitialize + * + * Description: + * Initialize SPI-based microSD. + * + ****************************************************************************/ + +#ifdef NSH_HAVEUSBHOST +static int nsh_usbhostinitialize(void) +{ + int ret; + + /* First, register all of the class drivers needed to support the drivers + * that we care about: + */ + + syslog(LOG_INFO, "Register class drivers\n"); + +#ifdef CONFIG_USBHOST_MSC + /* Register the USB host Mass Storage Class */ + + ret = usbhost_msc_initialize(); + if (ret != OK) + { + syslog(LOG_ERR, + "ERROR: Failed to register the mass storage class: %d\n", ret); + } +#endif + +#ifdef CONFIG_USBHOST_CDCACM + /* Register the CDC/ACM serial class */ + + ret = usbhost_cdcacm_initialize(); + if (ret != OK) + { + syslog(LOG_ERR, + "ERROR: Failed to register the CDC/ACM serial class: %d\n", + ret); + } +#endif + + /* Then get an instance of the USB host interface */ + + syslog(LOG_INFO, "Initialize USB host\n"); + g_usbconn = pic32_usbhost_initialize(0); + if (g_usbconn) + { + /* Start a thread to handle device connection. */ + + syslog(LOG_INFO, "Start nsh_waiter\n"); + + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + CONFIG_USBHOST_STACKSIZE, + nsh_waiter, NULL); + return ret < 0 ? -ENOEXEC : OK; + } + + return -ENODEV; +} +#else +# define nsh_usbhostinitialize() (OK) +#endif + +/**************************************************************************** + * Name: nsh_usbdevinitialize + * + * Description: + * Initialize SPI-based microSD. + * + ****************************************************************************/ + +#ifdef CONFIG_USBDEV +static int nsh_usbdevinitialize(void) +{ + /* The PIC32 Starter Kit has no way to know when the USB is connected. So + * we will fake it and tell the USB driver that the USB is connected now. + */ + + pic32mx_usbattach(); + return OK; +} +#else +# define nsh_usbdevinitialize() (OK) +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -78,3 +376,41 @@ void pic32mx_boardinitialize(void) pic32mx_led_initialize(); #endif } + +/**************************************************************************** + * Name: board_late_initialize + * + * Description: + * If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_late_initialize(). board_late_initialize() will + * be called immediately after up_initialize() is called and just before + * the initial application is started. This additional initialization + * phase may be used, for example, to initialize board-specific device + * drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_LATE_INITIALIZE +void board_late_initialize(void) +{ + int ret; + + /* Initialize SPI-based microSD */ + + ret = nsh_sdinitialize(); + if (ret == OK) + { + /* Initialize USB host */ + + ret = nsh_usbhostinitialize(); + } + + if (ret == OK) + { + /* Initialize USB device */ + + ret = nsh_usbdevinitialize(); + } +} +#endif diff --git a/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_usbmsc.c b/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_usbmsc.c index e1db7b086ae..3496551850d 100644 --- a/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_usbmsc.c +++ b/boards/mips/pic32mx/pic32mx-starterkit/src/pic32mx_usbmsc.c @@ -45,9 +45,8 @@ int board_usbmsc_initialize(int port) { /* If system/usbmsc is built as an NSH command, then SD slot should - * already have been initialized in board_app_initialize() (see - * pic32mx_appinit.c). In this case, there is nothing further to be - * done here. + * already have been initialized. + * In this case, there is nothing further to be done here. */ #ifndef CONFIG_NSH_BUILTIN_APPS diff --git a/boards/mips/pic32mx/pic32mx7mmb/src/Makefile b/boards/mips/pic32mx/pic32mx7mmb/src/Makefile index d7d9a871b5f..18405dd0382 100644 --- a/boards/mips/pic32mx/pic32mx7mmb/src/Makefile +++ b/boards/mips/pic32mx/pic32mx7mmb/src/Makefile @@ -28,10 +28,6 @@ ifeq ($(CONFIG_PIC32MX_USBDEV),y) CSRCS += pic32_usbdev.c endif -ifeq ($(CONFIG_BOARDCTL),y) -CSRCS += pic32_appinit.c -endif - ifeq ($(CONFIG_USBMSC),y) CSRCS += pic32_usbmsc.c endif diff --git a/boards/mips/pic32mx/pic32mx7mmb/src/pic32_appinit.c b/boards/mips/pic32mx/pic32mx7mmb/src/pic32_appinit.c deleted file mode 100644 index 649a7b34486..00000000000 --- a/boards/mips/pic32mx/pic32mx7mmb/src/pic32_appinit.c +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** - * boards/mips/pic32mx/pic32mx7mmb/src/pic32_appinit.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * 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 - -#include -#include - -#include - -#include "pic32mx7mmb.h" - -#ifdef CONFIG_BOARDCTL - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: board_app_initialize - * - * Description: - * Perform application specific initialization. This function is never - * called directly from application code, but only indirectly via the - * (non-standard) boardctl() interface using the command BOARDIOC_INIT. - * - * CONFIG_BOARDCTL=y : - * Called from the NSH library - * - * CONFIG_BOARD_LATE_INITIALIZE=y, CONFIG_NSH_LIBRARY=y, && - * CONFIG_BOARDCTL=n : - * Called from board_late_initialize(). - * - * Input Parameters: - * arg - The boardctl() argument is passed to the board_app_initialize() - * implementation without modification. The argument has no - * meaning to NuttX; the meaning of the argument is a contract - * between the board-specific initialization logic and the - * matching application logic. The value could be such things as a - * mode enumeration value, a set of DIP switch switch settings, a - * pointer to configuration data read from a file or serial FLASH, - * or whatever you would like to do with it. Every implementation - * should accept zero/NULL as a default configuration. - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned on - * any failure to indicate the nature of the failure. - * - ****************************************************************************/ - -int board_app_initialize(uintptr_t arg) -{ - /* Did we already initialize via board_late_initialize()? */ - -#ifndef CONFIG_BOARD_LATE_INITIALIZE - return pic32mx_bringup(); -#else - return OK; -#endif -} - -#endif /* CONFIG_BOARDCTL */ diff --git a/boards/mips/pic32mx/pic32mx7mmb/src/pic32_usbmsc.c b/boards/mips/pic32mx/pic32mx7mmb/src/pic32_usbmsc.c index 1b7f98ca6e4..dac3593f627 100644 --- a/boards/mips/pic32mx/pic32mx7mmb/src/pic32_usbmsc.c +++ b/boards/mips/pic32mx/pic32mx7mmb/src/pic32_usbmsc.c @@ -45,8 +45,7 @@ int board_usbmsc_initialize(int port) { /* If system/usbmsc is built as an NSH command, then SD slot should - * already have been initialized in board_app_initialize() - * (see pic32_appinit.c). + * already have been initialized. * In this case, there is nothing further to be done here. */ diff --git a/boards/mips/pic32mx/sure-pic32mx/src/Makefile b/boards/mips/pic32mx/sure-pic32mx/src/Makefile index 460a369201f..e131c3158a8 100644 --- a/boards/mips/pic32mx/sure-pic32mx/src/Makefile +++ b/boards/mips/pic32mx/sure-pic32mx/src/Makefile @@ -45,8 +45,4 @@ ifeq ($(CONFIG_LCD_LCD1602),y) CSRCS += pic32mx_lcd1602.c endif -ifeq ($(CONFIG_BOARDCTL),y) -CSRCS += pic32mx_appinit.c -endif - include $(TOPDIR)/boards/Board.mk diff --git a/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_appinit.c b/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_appinit.c deleted file mode 100644 index 62d6d4e5d2b..00000000000 --- a/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_appinit.c +++ /dev/null @@ -1,405 +0,0 @@ -/**************************************************************************** - * boards/mips/pic32mx/sure-pic32mx/src/pic32mx_appinit.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * 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 - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#ifdef CONFIG_USBMONITOR -# include -#endif - -#include "pic32mx.h" -#include "sure-pic32mx.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Configuration ************************************************************/ - -/* PORT and SLOT number probably depend on the board configuration */ - -#define NSH_HAVE_MMCSD 1 -#define NSH_HAVE_USBHOST 1 -#define NSH_HAVE_USBMONITOR 1 - -/* Can't support MMC/SD if SPI2 is not enabled */ - -#ifndef CONFIG_PIC32MX_SPI2 -# undef NSH_HAVE_MMCSD -#endif - -/* Can't support MMC/SD features if mountpoints are disabled */ - -#if defined(CONFIG_DISABLE_MOUNTPOINT) -# undef NSH_HAVE_MMCSD -#endif - -/* MMC/SD configuration */ - -#ifdef NSH_HAVE_MMCSD -# undef CONFIG_NSH_MMCSDSPIPORTNO -# define CONFIG_NSH_MMCSDSPIPORTNO 2 -# undef CONFIG_NSH_MMCSDSLOTNO -# define CONFIG_NSH_MMCSDSLOTNO 0 -# undef CONFIG_NSH_MMCSDMINOR -# define CONFIG_NSH_MMCSDMINOR 0 -#endif - -/* USB Host */ - -#ifdef CONFIG_USBHOST -# ifndef CONFIG_PIC32MX_USBHOST -# warning "CONFIG_PIC32MX_USBHOST is not selected" -# undef CONFIG_USBHOST -# endif -#endif - -#ifdef CONFIG_PIC32MX_USBHOST -# ifndef CONFIG_USBHOST -# warning "CONFIG_USBHOST is not selected" -# undef CONFIG_PIC32MX_USBHOST -# endif -#endif - -#if !defined(CONFIG_USBHOST) || !defined(CONFIG_PIC32MX_USBHOST) -# undef NSH_HAVE_USBHOST -#endif - -#ifdef NSH_HAVE_USBHOST -# ifndef CONFIG_USBHOST_DEFPRIO -# define CONFIG_USBHOST_DEFPRIO 50 -# endif -# ifndef CONFIG_USBHOST_STACKSIZE -# ifdef CONFIG_USBHOST_HUB -# define CONFIG_USBHOST_STACKSIZE 1536 -# else -# define CONFIG_USBHOST_STACKSIZE 1024 -# endif -# endif -#endif - -/* USB Monitor */ - -/* Check if we should enable the USB monitor before starting NSH */ - -#ifndef CONFIG_USBMONITOR -# undef NSH_HAVE_USBMONITOR -#endif - -#ifndef NSH_HAVE_USBDEV -# undef CONFIG_USBDEV_TRACE -#endif - -#ifndef NSH_HAVE_USBHOST -# undef CONFIG_USBHOST_TRACE -#endif - -#if !defined(CONFIG_USBDEV_TRACE) && !defined(CONFIG_USBHOST_TRACE) -# undef NSH_HAVE_USBMONITOR -#endif - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#ifdef NSH_HAVE_USBHOST -static struct usbhost_connection_s *g_usbconn; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_waiter - * - * Description: - * Wait for USB devices to be connected. - * - ****************************************************************************/ - -#ifdef NSH_HAVE_USBHOST -static int nsh_waiter(int argc, char *argv[]) -{ - struct usbhost_hubport_s *hport; - - syslog(LOG_INFO, "nsh_waiter: Running\n"); - for (; ; ) - { - /* Wait for the device to change state */ - - DEBUGVERIFY(CONN_WAIT(g_usbconn, &hport)); - syslog(LOG_INFO, "nsh_waiter: %s\n", - hport->connected ? "connected" : "disconnected"); - - /* Did we just become connected? */ - - if (hport->connected) - { - /* Yes.. enumerate the newly connected device */ - - CONN_ENUMERATE(g_usbconn, hport); - } - } - - /* Keep the compiler from complaining */ - - return 0; -} -#endif - -/**************************************************************************** - * Name: nsh_sdinitialize - * - * Description: - * Initialize SPI-based microSD. - * - ****************************************************************************/ - -#ifdef NSH_HAVE_MMCSD -static int nsh_sdinitialize(void) -{ - struct spi_dev_s *spi; - int ret; - - /* Get the SPI port */ - - spi = pic32mx_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO); - if (!spi) - { - syslog(LOG_ERR, "ERROR: Failed to initialize SPI port %d\n", - CONFIG_NSH_MMCSDSPIPORTNO); - ret = -ENODEV; - goto errout; - } - - syslog(LOG_INFO, "Successfully initialized SPI port %d\n", - CONFIG_NSH_MMCSDSPIPORTNO); - - /* The SPI should be in 8-bit (default) and mode2: CKP=1, CKE=0. - * The MMC/SD driver will control the SPI frequency. WARNING: - * this is not the right way to do this... this should be done - * the MMC/SD driver: Other device on SPI1 may need other mode - * settings. - */ - - SPI_SETMODE(spi, SPIDEV_MODE2); - - /* Bind the SPI port to the slot */ - - ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, - CONFIG_NSH_MMCSDSLOTNO, spi); - if (ret < 0) - { - syslog(LOG_ERR, - "ERROR: Failed to bind SPI port %d to MMC/SD slot %d: %d\n", - CONFIG_NSH_MMCSDSPIPORTNO, - CONFIG_NSH_MMCSDSLOTNO, ret); - goto errout; - } - - syslog(LOG_INFO, "Successfully bound SPI port %d to MMC/SD slot %d\n", - CONFIG_NSH_MMCSDSPIPORTNO, - CONFIG_NSH_MMCSDSLOTNO); - return OK; - -errout: - return ret; -} -#else -# define nsh_sdinitialize() (OK) -#endif - -/**************************************************************************** - * Name: nsh_usbhostinitialize - * - * Description: - * Initialize USB Host - * - ****************************************************************************/ - -#ifdef NSH_HAVE_USBHOST -static int nsh_usbhostinitialize(void) -{ - int ret; - - /* First, register all of the class drivers needed to support the drivers - * that we care about: - */ - - syslog(LOG_INFO, "Register class drivers\n"); - -#ifdef CONFIG_USBHOST_MSC - /* Register the USB mass storage class class */ - - ret = usbhost_msc_initialize(); - if (ret != OK) - { - syslog(LOG_ERR, - "ERROR: Failed to register the mass storage class: %d\n", ret); - } -#endif - -#ifdef CONFIG_USBHOST_CDCACM - /* Register the CDC/ACM serial class */ - - ret = usbhost_cdcacm_initialize(); - if (ret != OK) - { - syslog(LOG_ERR, - "ERROR: Failed to register the CDC/ACM serial class: %d\n", - ret); - } -#endif - - /* Then get an instance of the USB host interface */ - - syslog(LOG_INFO, "Initialize USB host\n"); - - g_usbconn = pic32_usbhost_initialize(0); - if (g_usbconn) - { - /* Start a thread to handle device connection. */ - - syslog(LOG_INFO, "Start nsh_waiter\n"); - - ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, - CONFIG_USBHOST_STACKSIZE, - nsh_waiter, NULL); - return ret < 0 ? -ENOEXEC : OK; - } - - return -ENODEV; -} -#else -# define nsh_usbhostinitialize() (OK) -#endif - -/**************************************************************************** - * Name: nsh_usbdevinitialize - * - * Description: - * Initialize SPI-based microSD. - * - ****************************************************************************/ - -#ifdef CONFIG_USBDEV -static int nsh_usbdevinitialize(void) -{ - /* The Sure board has no way to know when the USB is connected. So we - * will fake it and tell the USB driver that the USB is connected now. - */ - - pic32mx_usbattach(); - return OK; -} -#else -# define nsh_usbdevinitialize() (OK) -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: board_app_initialize - * - * Description: - * Perform application specific initialization. This function is never - * called directly from application code, but only indirectly via the - * (non-standard) boardctl() interface using the command BOARDIOC_INIT. - * - * Input Parameters: - * arg - The boardctl() argument is passed to the board_app_initialize() - * implementation without modification. The argument has no - * meaning to NuttX; the meaning of the argument is a contract - * between the board-specific initialization logic and the - * matching application logic. The value could be such things as a - * mode enumeration value, a set of DIP switch switch settings, a - * pointer to configuration data read from a file or serial FLASH, - * or whatever you would like to do with it. Every implementation - * should accept zero/NULL as a default configuration. - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned on - * any failure to indicate the nature of the failure. - * - ****************************************************************************/ - -int board_app_initialize(uintptr_t arg) -{ - int ret; - - /* Initialize the LCD1602 and register the device as /dev/lcd1602 */ - -#ifdef CONFIG_LCD_LCD1602 - ret = up_lcd1602_initialize(); - if (ret == OK) -#endif - { - /* Initialize SPI-based microSD */ - - ret = nsh_sdinitialize(); - } - - if (ret == OK) - { - /* Initialize USB host */ - - ret = nsh_usbhostinitialize(); - } - - if (ret == OK) - { - /* Initialize USB device */ - - ret = nsh_usbdevinitialize(); - } - -#ifdef NSH_HAVE_USBMONITOR - if (ret == OK) - { - /* Start the USB Monitor */ - - ret = usbmonitor_start(); - } -#endif - - return ret; -} diff --git a/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_boot.c b/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_boot.c index 44ca7b5460b..3af4c8f9d2a 100644 --- a/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_boot.c +++ b/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_boot.c @@ -28,7 +28,23 @@ #include +#include +#include +#include +#include +#include + #include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_USBMONITOR +# include +#endif #include "mips_internal.h" #include "pic32mx.h" @@ -38,10 +54,289 @@ * Pre-processor Definitions ****************************************************************************/ +/* Configuration ************************************************************/ + +/* PORT and SLOT number probably depend on the board configuration */ + +#define NSH_HAVE_MMCSD 1 +#define NSH_HAVE_USBHOST 1 +#define NSH_HAVE_USBMONITOR 1 + +/* Can't support MMC/SD if SPI2 is not enabled */ + +#ifndef CONFIG_PIC32MX_SPI2 +# undef NSH_HAVE_MMCSD +#endif + +/* Can't support MMC/SD features if mountpoints are disabled */ + +#if defined(CONFIG_DISABLE_MOUNTPOINT) +# undef NSH_HAVE_MMCSD +#endif + +/* MMC/SD configuration */ + +#ifdef NSH_HAVE_MMCSD +# undef CONFIG_NSH_MMCSDSPIPORTNO +# define CONFIG_NSH_MMCSDSPIPORTNO 2 +# undef CONFIG_NSH_MMCSDSLOTNO +# define CONFIG_NSH_MMCSDSLOTNO 0 +# undef CONFIG_NSH_MMCSDMINOR +# define CONFIG_NSH_MMCSDMINOR 0 +#endif + +/* USB Host */ + +#ifdef CONFIG_USBHOST +# ifndef CONFIG_PIC32MX_USBHOST +# warning "CONFIG_PIC32MX_USBHOST is not selected" +# undef CONFIG_USBHOST +# endif +#endif + +#ifdef CONFIG_PIC32MX_USBHOST +# ifndef CONFIG_USBHOST +# warning "CONFIG_USBHOST is not selected" +# undef CONFIG_PIC32MX_USBHOST +# endif +#endif + +#if !defined(CONFIG_USBHOST) || !defined(CONFIG_PIC32MX_USBHOST) +# undef NSH_HAVE_USBHOST +#endif + +#ifdef NSH_HAVE_USBHOST +# ifndef CONFIG_USBHOST_DEFPRIO +# define CONFIG_USBHOST_DEFPRIO 50 +# endif +# ifndef CONFIG_USBHOST_STACKSIZE +# ifdef CONFIG_USBHOST_HUB +# define CONFIG_USBHOST_STACKSIZE 1536 +# else +# define CONFIG_USBHOST_STACKSIZE 1024 +# endif +# endif +#endif + +/* USB Monitor */ + +/* Check if we should enable the USB monitor before starting NSH */ + +#ifndef CONFIG_USBMONITOR +# undef NSH_HAVE_USBMONITOR +#endif + +#ifndef NSH_HAVE_USBDEV +# undef CONFIG_USBDEV_TRACE +#endif + +#ifndef NSH_HAVE_USBHOST +# undef CONFIG_USBHOST_TRACE +#endif + +#if !defined(CONFIG_USBDEV_TRACE) && !defined(CONFIG_USBHOST_TRACE) +# undef NSH_HAVE_USBMONITOR +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifdef NSH_HAVE_USBHOST +static struct usbhost_connection_s *g_usbconn; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: nsh_waiter + * + * Description: + * Wait for USB devices to be connected. + * + ****************************************************************************/ + +#ifdef NSH_HAVE_USBHOST +static int nsh_waiter(int argc, char *argv[]) +{ + struct usbhost_hubport_s *hport; + + syslog(LOG_INFO, "nsh_waiter: Running\n"); + for (; ; ) + { + /* Wait for the device to change state */ + + DEBUGVERIFY(CONN_WAIT(g_usbconn, &hport)); + syslog(LOG_INFO, "nsh_waiter: %s\n", + hport->connected ? "connected" : "disconnected"); + + /* Did we just become connected? */ + + if (hport->connected) + { + /* Yes.. enumerate the newly connected device */ + + CONN_ENUMERATE(g_usbconn, hport); + } + } + + /* Keep the compiler from complaining */ + + return 0; +} +#endif + +/**************************************************************************** + * Name: nsh_sdinitialize + * + * Description: + * Initialize SPI-based microSD. + * + ****************************************************************************/ + +#ifdef NSH_HAVE_MMCSD +static int nsh_sdinitialize(void) +{ + struct spi_dev_s *spi; + int ret; + + /* Get the SPI port */ + + spi = pic32mx_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO); + if (!spi) + { + syslog(LOG_ERR, "ERROR: Failed to initialize SPI port %d\n", + CONFIG_NSH_MMCSDSPIPORTNO); + ret = -ENODEV; + goto errout; + } + + syslog(LOG_INFO, "Successfully initialized SPI port %d\n", + CONFIG_NSH_MMCSDSPIPORTNO); + + /* The SPI should be in 8-bit (default) and mode2: CKP=1, CKE=0. + * The MMC/SD driver will control the SPI frequency. WARNING: + * this is not the right way to do this... this should be done + * the MMC/SD driver: Other device on SPI1 may need other mode + * settings. + */ + + SPI_SETMODE(spi, SPIDEV_MODE2); + + /* Bind the SPI port to the slot */ + + ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, + CONFIG_NSH_MMCSDSLOTNO, spi); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to bind SPI port %d to MMC/SD slot %d: %d\n", + CONFIG_NSH_MMCSDSPIPORTNO, + CONFIG_NSH_MMCSDSLOTNO, ret); + goto errout; + } + + syslog(LOG_INFO, "Successfully bound SPI port %d to MMC/SD slot %d\n", + CONFIG_NSH_MMCSDSPIPORTNO, + CONFIG_NSH_MMCSDSLOTNO); + return OK; + +errout: + return ret; +} +#else +# define nsh_sdinitialize() (OK) +#endif + +/**************************************************************************** + * Name: nsh_usbhostinitialize + * + * Description: + * Initialize USB Host + * + ****************************************************************************/ + +#ifdef NSH_HAVE_USBHOST +static int nsh_usbhostinitialize(void) +{ + int ret; + + /* First, register all of the class drivers needed to support the drivers + * that we care about: + */ + + syslog(LOG_INFO, "Register class drivers\n"); + +#ifdef CONFIG_USBHOST_MSC + /* Register the USB mass storage class class */ + + ret = usbhost_msc_initialize(); + if (ret != OK) + { + syslog(LOG_ERR, + "ERROR: Failed to register the mass storage class: %d\n", ret); + } +#endif + +#ifdef CONFIG_USBHOST_CDCACM + /* Register the CDC/ACM serial class */ + + ret = usbhost_cdcacm_initialize(); + if (ret != OK) + { + syslog(LOG_ERR, + "ERROR: Failed to register the CDC/ACM serial class: %d\n", + ret); + } +#endif + + /* Then get an instance of the USB host interface */ + + syslog(LOG_INFO, "Initialize USB host\n"); + + g_usbconn = pic32_usbhost_initialize(0); + if (g_usbconn) + { + /* Start a thread to handle device connection. */ + + syslog(LOG_INFO, "Start nsh_waiter\n"); + + ret = kthread_create("usbhost", CONFIG_USBHOST_DEFPRIO, + CONFIG_USBHOST_STACKSIZE, + nsh_waiter, NULL); + return ret < 0 ? -ENOEXEC : OK; + } + + return -ENODEV; +} +#else +# define nsh_usbhostinitialize() (OK) +#endif + +/**************************************************************************** + * Name: nsh_usbdevinitialize + * + * Description: + * Initialize SPI-based microSD. + * + ****************************************************************************/ + +#ifdef CONFIG_USBDEV +static int nsh_usbdevinitialize(void) +{ + /* The Sure board has no way to know when the USB is connected. So we + * will fake it and tell the USB driver that the USB is connected now. + */ + + pic32mx_usbattach(); + return OK; +} +#else +# define nsh_usbdevinitialize() (OK) +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -86,3 +381,58 @@ void pic32mx_boardinitialize(void) pic32mx_led_initialize(); #endif } + +/**************************************************************************** + * Name: board_late_initialize + * + * Description: + * If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_late_initialize(). board_late_initialize() will be + * called immediately after up_initialize() is called and just before the + * initial application is started. This additional initialization phase + * may be used, for example, to initialize board-specific device drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_LATE_INITIALIZE +void board_late_initialize(void) +{ + int ret; + + /* Initialize the LCD1602 and register the device as /dev/lcd1602 */ + +#ifdef CONFIG_LCD_LCD1602 + ret = up_lcd1602_initialize(); + if (ret == OK) +#endif + { + /* Initialize SPI-based microSD */ + + ret = nsh_sdinitialize(); + } + + if (ret == OK) + { + /* Initialize USB host */ + + ret = nsh_usbhostinitialize(); + } + + if (ret == OK) + { + /* Initialize USB device */ + + ret = nsh_usbdevinitialize(); + } + +#ifdef NSH_HAVE_USBMONITOR + if (ret == OK) + { + /* Start the USB Monitor */ + + ret = usbmonitor_start(); + } +#endif +} +#endif /* CONFIG_BOARD_LATE_INITIALIZE */ diff --git a/boards/mips/pic32mx/ubw32/src/Makefile b/boards/mips/pic32mx/ubw32/src/Makefile index e6ba5b6fdc9..f17022ae985 100644 --- a/boards/mips/pic32mx/ubw32/src/Makefile +++ b/boards/mips/pic32mx/ubw32/src/Makefile @@ -28,10 +28,6 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += pic32_buttons.c endif -ifeq ($(CONFIG_BOARDCTL),y) -CSRCS += pic32_appinit.c -endif - ifeq ($(CONFIG_PIC32MX_USBDEV),y) CSRCS += pic32_usbdev.c endif diff --git a/boards/mips/pic32mx/ubw32/src/pic32_appinit.c b/boards/mips/pic32mx/ubw32/src/pic32_appinit.c deleted file mode 100644 index fbdbc546b3f..00000000000 --- a/boards/mips/pic32mx/ubw32/src/pic32_appinit.c +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** - * boards/mips/pic32mx/ubw32/src/pic32_appinit.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * 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 - -#include -#include - -#include - -#include "pic32mx.h" -#include "ubw32.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: nsh_usbdevinitialize - * - * Description: - * Initialize SPI-based microSD. - * - ****************************************************************************/ - -#ifdef CONFIG_USBDEV -static int nsh_usbdevinitialize(void) -{ - /* The UBW32 has no way to know when the USB is connected. So we will fake - * it and tell the USB driver that the USB is connected now. - */ - - pic32mx_usbattach(); - return OK; -} -#else -# define nsh_usbdevinitialize() (OK) -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: board_app_initialize - * - * Description: - * Perform application specific initialization. This function is never - * called directly from application code, but only indirectly via the - * (non-standard) boardctl() interface using the command BOARDIOC_INIT. - * - * Input Parameters: - * arg - The boardctl() argument is passed to the board_app_initialize() - * implementation without modification. The argument has no - * meaning to NuttX; the meaning of the argument is a contract - * between the board-specific initialization logic and the - * matching application logic. The value could be such things as a - * mode enumeration value, a set of DIP switch switch settings, a - * pointer to configuration data read from a file or serial FLASH, - * or whatever you would like to do with it. Every implementation - * should accept zero/NULL as a default configuration. - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned on - * any failure to indicate the nature of the failure. - * - ****************************************************************************/ - -int board_app_initialize(uintptr_t arg) -{ - int ret; - - /* Initialize USB device */ - - ret = nsh_usbdevinitialize(); - return ret; -} diff --git a/boards/mips/pic32mx/ubw32/src/pic32_boot.c b/boards/mips/pic32mx/ubw32/src/pic32_boot.c index 14939f7ad6b..8d0b41911fe 100644 --- a/boards/mips/pic32mx/ubw32/src/pic32_boot.c +++ b/boards/mips/pic32mx/ubw32/src/pic32_boot.c @@ -28,6 +28,9 @@ #include +#include +#include + #include #include "mips_internal.h" @@ -42,6 +45,28 @@ * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: nsh_usbdevinitialize + * + * Description: + * Initialize SPI-based microSD. + * + ****************************************************************************/ + +#ifdef CONFIG_USBDEV +static int nsh_usbdevinitialize(void) +{ + /* The UBW32 has no way to know when the USB is connected. So we will fake + * it and tell the USB driver that the USB is connected now. + */ + + pic32mx_usbattach(); + return OK; +} +#else +# define nsh_usbdevinitialize() +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -76,3 +101,23 @@ void pic32mx_boardinitialize(void) pic32mx_led_initialize(); #endif } + +/**************************************************************************** + * Name: board_late_initialize + * + * Description: + * If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_late_initialize(). board_late_initialize() will be + * called immediately after up_initialize() is called and just before the + * initial application is started. This additional initialization phase + * may be used, for example, to initialize board-specific device drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_LATE_INITIALIZE +void board_late_initialize(void) +{ + nsh_usbdevinitialize(); +} +#endif /* CONFIG_BOARD_LATE_INITIALIZE */ diff --git a/boards/mips/pic32mz/chipkit-wifire/src/Makefile b/boards/mips/pic32mz/chipkit-wifire/src/Makefile index 5d678cf013a..60ba1392234 100644 --- a/boards/mips/pic32mz/chipkit-wifire/src/Makefile +++ b/boards/mips/pic32mz/chipkit-wifire/src/Makefile @@ -24,10 +24,6 @@ include $(TOPDIR)/Make.defs CSRCS = pic32mz_boot.c pic32mz_bringup.c pic32mz_userleds.c pic32mz_spi.c -ifeq ($(CONFIG_BOARDCTL),y) -CSRCS += pic32mz_appinit.c -endif - ifeq ($(CONFIG_ARCH_LEDS),y) CSRCS += pic32mz_autoleds.c endif diff --git a/boards/mips/pic32mz/chipkit-wifire/src/pic32mz_appinit.c b/boards/mips/pic32mz/chipkit-wifire/src/pic32mz_appinit.c deleted file mode 100644 index ce33b0c0320..00000000000 --- a/boards/mips/pic32mz/chipkit-wifire/src/pic32mz_appinit.c +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** - * boards/mips/pic32mz/chipkit-wifire/src/pic32mz_appinit.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * 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 - -#include - -#include "chipkit-wifire.h" - -#ifdef CONFIG_BOARDCTL - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: board_app_initialize - * - * Description: - * Perform application specific initialization. This function is never - * called directly from application code, but only indirectly via the - * (non-standard) boardctl() interface using the command BOARDIOC_INIT. - * - * Input Parameters: - * arg - The boardctl() argument is passed to the board_app_initialize() - * implementation without modification. The argument has no - * meaning to NuttX; the meaning of the argument is a contract - * between the board-specific initialization logic and the - * matching application logic. The value could be such things as a - * mode enumeration value, a set of DIP switch switch settings, a - * pointer to configuration data read from a file or serial FLASH, - * or whatever you would like to do with it. Every implementation - * should accept zero/NULL as a default configuration. - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned on - * any failure to indicate the nature of the failure. - * - ****************************************************************************/ - -int board_app_initialize(uintptr_t arg) -{ - /* If CONFIG_BOARD_LATE_INITIALIZE is selected then board initialization - * was already performed in board_late_initialize. - */ - -#ifndef CONFIG_BOARD_LATE_INITIALIZE - return pic32mz_bringup(); -#else - return OK; -#endif -} - -#endif /* CONFIG_BOARDCTL */ diff --git a/boards/mips/pic32mz/flipnclick-pic32mz/src/Makefile b/boards/mips/pic32mz/flipnclick-pic32mz/src/Makefile index 39147722ac6..d10aeea1856 100644 --- a/boards/mips/pic32mz/flipnclick-pic32mz/src/Makefile +++ b/boards/mips/pic32mz/flipnclick-pic32mz/src/Makefile @@ -24,10 +24,6 @@ include $(TOPDIR)/Make.defs CSRCS = pic32mz_boot.c pic32mz_bringup.c pic32mz_userleds.c pic32mz_spi.c -ifeq ($(CONFIG_BOARDCTL),y) -CSRCS += pic32mz_appinit.c -endif - ifeq ($(CONFIG_ARCH_LEDS),y) CSRCS += pic32mz_autoleds.c endif diff --git a/boards/mips/pic32mz/flipnclick-pic32mz/src/pic32mz_appinit.c b/boards/mips/pic32mz/flipnclick-pic32mz/src/pic32mz_appinit.c deleted file mode 100644 index 5d9d8c74d10..00000000000 --- a/boards/mips/pic32mz/flipnclick-pic32mz/src/pic32mz_appinit.c +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** - * boards/mips/pic32mz/flipnclick-pic32mz/src/pic32mz_appinit.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * 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 - -#include - -#include "flipnclick-pic32mz.h" - -#ifdef CONFIG_BOARDCTL - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: board_app_initialize - * - * Description: - * Perform application specific initialization. This function is never - * called directly from application code, but only indirectly via the - * (non-standard) boardctl() interface using the command BOARDIOC_INIT. - * - * Input Parameters: - * arg - The boardctl() argument is passed to the board_app_initialize() - * implementation without modification. The argument has no - * meaning to NuttX; the meaning of the argument is a contract - * between the board-specific initialization logic and the - * matching application logic. The value could be such things as a - * mode enumeration value, a set of DIP switch switch settings, a - * pointer to configuration data read from a file or serial FLASH, - * or whatever you would like to do with it. Every implementation - * should accept zero/NULL as a default configuration. - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned on - * any failure to indicate the nature of the failure. - * - ****************************************************************************/ - -int board_app_initialize(uintptr_t arg) -{ - /* If CONFIG_BOARD_LATE_INITIALIZE is selected then board initialization - * was already performed in board_late_initialize. - */ - -#ifndef CONFIG_BOARD_LATE_INITIALIZE - return pic32mz_bringup(); -#else - return OK; -#endif -} - -#endif /* CONFIG_BOARDCTL */ diff --git a/boards/mips/pic32mz/pic32mz-starterkit/src/Makefile b/boards/mips/pic32mz/pic32mz-starterkit/src/Makefile index 11ebe419778..353ca0340bf 100644 --- a/boards/mips/pic32mz/pic32mz-starterkit/src/Makefile +++ b/boards/mips/pic32mz/pic32mz-starterkit/src/Makefile @@ -34,8 +34,4 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += pic32mz_buttons.c endif -ifeq ($(CONFIG_BOARDCTL),y) -CSRCS += pic32mz_appinit.c -endif - include $(TOPDIR)/boards/Board.mk diff --git a/boards/mips/pic32mz/pic32mz-starterkit/src/pic32mz_appinit.c b/boards/mips/pic32mz/pic32mz-starterkit/src/pic32mz_appinit.c deleted file mode 100644 index 9c8456e66ec..00000000000 --- a/boards/mips/pic32mz/pic32mz-starterkit/src/pic32mz_appinit.c +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** - * boards/mips/pic32mz/pic32mz-starterkit/src/pic32mz_appinit.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * 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 - -#include - -#include "pic32mz-starterkit.h" - -#ifdef CONFIG_BOARDCTL - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: board_app_initialize - * - * Description: - * Perform application specific initialization. This function is never - * called directly from application code, but only indirectly via the - * (non-standard) boardctl() interface using the command BOARDIOC_INIT. - * - * Input Parameters: - * arg - The boardctl() argument is passed to the board_app_initialize() - * implementation without modification. The argument has no - * meaning to NuttX; the meaning of the argument is a contract - * between the board-specific initialization logic and the - * matching application logic. The value could be such things as a - * mode enumeration value, a set of DIP switch switch settings, a - * pointer to configuration data read from a file or serial FLASH, - * or whatever you would like to do with it. Every implementation - * should accept zero/NULL as a default configuration. - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned on - * any failure to indicate the nature of the failure. - * - ****************************************************************************/ - -int board_app_initialize(uintptr_t arg) -{ - /* If CONFIG_BOARD_LATE_INITIALIZE is selected then board initialization - * was already performed in board_late_initialize. - */ - -#ifndef CONFIG_BOARD_LATE_INITIALIZE - return pic32mz_bringup(); -#else - return OK; -#endif -} - -#endif /* CONFIG_BOARDCTL */