Add nuttx to the system framework, which is 10.1.0

This commit is contained in:
TangYiwen123
2021-06-09 14:33:15 +08:00
parent 06c351e27c
commit 804bd57aa0
5000 changed files with 1488544 additions and 0 deletions
@@ -0,0 +1,77 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
menuconfig SYSTEM_CDCACM
tristate "USB CDC/ACM Device Commands"
default n
depends on LIB_BOARDCTL && CDCACM
select BOARDCTL_USBDEVCTRL
---help---
Enable the USB CDC/ACM class controls. These controls include:
sercon: Connect the mass storage device to the host
serdis: Disconnect the mass storage device to the host
if SYSTEM_CDCACM
config SYSTEM_CDCACM_DEVMINOR
int "CDC/ACM Minor Device Number"
default 0
---help---
The minor device number of the serial driver for the CDC/ACM device.
For example, N in /dev/ttyACMN. Used for registering the serial
driver. Default is zero.
config SYSTEM_CDCACM_TRACEINIT
bool "USB Trace Initialization"
default n
depends on USBDEV_TRACE || DEBUG_USB
---help---
If USBDEV_TRACE is enabled (or CONFIG_DEBUG_FEATURES and CONFIG_DEBUG_USB),
then the add-on code will also manage the USB trace output. The
amount of trace output can be controlled this configuration value:
This setting will show USB initialization events
config SYSTEM_CDCACM_TRACECLASS
bool "USB Trace Class"
default n
depends on USBDEV_TRACE || DEBUG_USB
---help---
If USBDEV_TRACE is enabled (or CONFIG_DEBUG_FEATURES and CONFIG_DEBUG_USB),
then the add-on code will also manage the USB trace output. The
amount of trace output can be controlled this configuration value:
This setting will show USB class driver events
config SYSTEM_CDCACM_TRACETRANSFERS
bool "USB Trace Transfers"
default n
depends on USBDEV_TRACE || DEBUG_USB
---help---
If USBDEV_TRACE is enabled (or CONFIG_DEBUG_FEATURES and CONFIG_DEBUG_USB),
then the add-on code will also manage the USB trace output. The
amount of trace output can be controlled this configuration value:
This setting will show USB data transfer events
config SYSTEM_CDCACM_TRACECONTROLLER
bool "USB Trace Device Controller Events"
default n
depends on USBDEV_TRACE || DEBUG_USB
---help---
If USBDEV_TRACE is enabled (or CONFIG_DEBUG_FEATURES and CONFIG_DEBUG_USB),
then the add-on code will also manage the USB trace output. The
amount of trace output can be controlled this configuration value:
This setting will show USB device controller events
config SYSTEM_CDCACM_TRACEINTERRUPTS
bool "USB Trace Device Controller Interrupt Events"
default n
depends on USBDEV_TRACE || DEBUG_USB
---help---
If USBDEV_TRACE is enabled (or CONFIG_DEBUG_FEATURES and CONFIG_DEBUG_USB),
then the add-on code will also manage the USB trace output. The
amount of trace output can be controlled this configuration value:
This setting will show USB device controller interrupt-related events.
endif
@@ -0,0 +1,39 @@
############################################################################
# apps/system/cdcacm/Make.defs
# Adds selected applications to apps/ build
#
# Copyright (C) 2016 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
ifneq ($(CONFIG_SYSTEM_CDCACM),)
CONFIGURED_APPS += $(APPDIR)/system/cdcacm
endif
@@ -0,0 +1,47 @@
############################################################################
# apps/system/cdcacm/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
include $(APPDIR)/Make.defs
# USB CDC/ACM serial mass storage add-on
MAINSRC = cdcacm_main.c
PROGNAME = sercon serdis
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
MODULE = $(CONFIG_SYSTEM_CDCACM)
include $(APPDIR)/Application.mk
@@ -0,0 +1,36 @@
# System / `cdcacm` USB CDC/ACM serial
This very simple add-on allows the USB CDC/ACM serial device can be dynamically
connected and disconnected from a host. This add-on can only be used as an NSH
built-in command. If built-in, then two new NSH commands will be supported:
1. `sercon` Connect the CDC/ACM serial device
2. `serdis` Disconnect the CDC/ACM serial device
Configuration prerequisites (not complete):
- `CONFIG_USBDEV=y` USB device support must be enabled
- `CONFIG_CDCACM=y` The CDC/ACM driver must be built
Configuration options specific to this add-on:
- `CONFIG_SYSTEM_CDCACM_DEVMINOR` The minor number of the CDC/ACM device,
i.e., the `x` in `/dev/ttyACMx`.
If `CONFIG_USBDEV_TRACE` is enabled (or `CONFIG_DEBUG_FEATURES` and
`CONFIG_DEBUG_USB`, or `CONFIG_USBDEV_TRACE`), then the add-on code will also
initialize the USB trace output. The amount of trace output can be controlled
using:
- `CONFIG_SYSTEM_CDCACM_TRACEINIT` Show initialization events.
- `CONFIG_SYSTEM_CDCACM_TRACECLASS` Show class driver events.
- `CONFIG_SYSTEM_CDCACM_TRACETRANSFERS` Show data transfer events.
- `CONFIG_SYSTEM_CDCACM_TRACECONTROLLER` Show controller events.
- `CONFIG_SYSTEM_CDCACM_TRACEINTERRUPTS` Show interrupt-related events.
**Note**: This add-on is only enables or disable USB CDC/ACM via the NSH
`sercon` and `serdis` command. It will enable and disable tracing per the
settings before enabling and after disabling the CDC/ACM device. It will not,
however, monitor buffered trace data in the interim. If `CONFIG_USBDEV_TRACE` is
defined (and the debug options are not), other application logic will need to
monitor the buffered trace data.
@@ -0,0 +1,133 @@
/****************************************************************************
* system/cdcacm/cdcacm.h
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __SYSTEM_CDCACM_CDCACM_H
#define __SYSTEM_CDCACM_CDCACM_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
#include <nuttx/usb/usbdev_trace.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* Prerequisites */
#ifndef CONFIG_USBDEV
# error "CONFIG_USBDEV is not defined"
#endif
#ifndef CONFIG_CDCACM
# error "CONFIG_CDCACM is not defined"
#endif
/* Default configuration values */
#ifndef CONFIG_SYSTEM_CDCACM_DEVMINOR
# define CONFIG_SYSTEM_CDCACM_DEVMINOR 0
#endif
/* Trace Configuration ******************************************************/
#ifdef CONFIG_SYSTEM_CDCACM_TRACEINIT
# define TRACE_INIT_BITS (TRACE_INIT_BIT)
#else
# define TRACE_INIT_BITS (0)
#endif
#define TRACE_ERROR_BITS (TRACE_DEVERROR_BIT|TRACE_CLSERROR_BIT)
#ifdef CONFIG_SYSTEM_CDCACM_TRACECLASS
# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|TRACE_CLASSSTATE_BIT)
#else
# define TRACE_CLASS_BITS (0)
#endif
#ifdef CONFIG_SYSTEM_CDCACM_TRACETRANSFERS
# define TRACE_TRANSFER_BITS (TRACE_OUTREQQUEUED_BIT|TRACE_INREQQUEUED_BIT|TRACE_READ_BIT|\
TRACE_WRITE_BIT|TRACE_COMPLETE_BIT)
#else
# define TRACE_TRANSFER_BITS (0)
#endif
#ifdef CONFIG_SYSTEM_CDCACM_TRACECONTROLLER
# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT)
#else
# define TRACE_CONTROLLER_BITS (0)
#endif
#ifdef CONFIG_SYSTEM_CDCACM_TRACEINTERRUPTS
# define TRACE_INTERRUPT_BITS (TRACE_INTENTRY_BIT|TRACE_INTDECODE_BIT|TRACE_INTEXIT_BIT)
#else
# define TRACE_INTERRUPT_BITS (0)
#endif
#define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|TRACE_CLASS_BITS|\
TRACE_TRANSFER_BITS|TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS)
/****************************************************************************
* Public Types
****************************************************************************/
/* All global variables used by this add-on are packed into a structure in
* order to avoid name collisions.
*/
struct cdcacm_state_s
{
/* This is the handle that references to this particular USB CDC/ACM driver
* instance. The value of the driver handle must be remembered between the
* 'sercon' and 'msdis' commands.
*/
FAR void *handle;
};
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
#endif /* __SYSTEM_CDCACM_CDCACM_H */
@@ -0,0 +1,153 @@
/****************************************************************************
* system/cdcacm/cdcacm_main.c
*
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/boardctl.h>
#include <stdio.h>
#include <debug.h>
#include <nuttx/usb/usbdev.h>
#include <nuttx/usb/cdcacm.h>
#include "cdcacm.h"
/****************************************************************************
* Private Data
****************************************************************************/
/* All global variables used by this add-on are packed into a structure in
* order to avoid name collisions.
*/
static struct cdcacm_state_s g_cdcacm;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* sercon_main
*
* Description:
* This is the main program that configures the CDC/ACM serial device.
*
****************************************************************************/
int main(int argc, FAR char *argv[])
{
struct boardioc_usbdev_ctrl_s ctrl;
int ret;
/* Check if there is a non-NULL USB mass storage device handle (meaning that the
* USB mass storage device is already configured).
*/
if (g_cdcacm.handle)
{
printf("sercon:: ERROR: Already connected\n");
return EXIT_FAILURE;
}
/* Then, in any event, enable trace data collection as configured BEFORE
* enabling the CDC/ACM device.
*/
usbtrace_enable(TRACE_BITSET);
/* Initialize the USB CDC/ACM serial driver */
printf("sercon: Registering CDC/ACM serial driver\n");
ctrl.usbdev = BOARDIOC_USBDEV_CDCACM;
ctrl.action = BOARDIOC_USBDEV_CONNECT;
ctrl.instance = CONFIG_SYSTEM_CDCACM_DEVMINOR;
ctrl.handle = &g_cdcacm.handle;
ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
if (ret < 0)
{
printf("sercon: ERROR: Failed to create the CDC/ACM serial device: %d\n", -ret);
return EXIT_FAILURE;
}
printf("sercon: Successfully registered the CDC/ACM serial driver\n");
return EXIT_SUCCESS;
}
/****************************************************************************
* serdis_main
*
* Description:
* This is a program entry point that will disconnect the CDC/ACM serial
* device.
****************************************************************************/
int serdis_main(int argc, char *argv[])
{
struct boardioc_usbdev_ctrl_s ctrl;
/* First check if the USB mass storage device is already connected */
if (!g_cdcacm.handle)
{
printf("serdis: ERROR: Not connected\n");
return EXIT_FAILURE;
}
/* Then, in any event, disable trace data collection as configured BEFORE
* enabling the CDC/ACM device.
*/
usbtrace_enable(0);
/* Then disconnect the device and uninitialize the USB mass storage driver */
ctrl.usbdev = BOARDIOC_USBDEV_CDCACM;
ctrl.action = BOARDIOC_USBDEV_DISCONNECT;
ctrl.instance = CONFIG_SYSTEM_CDCACM_DEVMINOR;
ctrl.handle = &g_cdcacm.handle;
boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
g_cdcacm.handle = NULL;
printf("serdis: Disconnected\n");
return EXIT_SUCCESS;
}