modify nuttx bug of lack of files
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
/****************************************************************************
|
||||
* include/aio.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_AIO_H
|
||||
#define __INCLUDE_AIO_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <nuttx/signal.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
/* These interfaces are not available to kernel code */
|
||||
|
||||
#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)
|
||||
# undef CONFIG_FS_AIO
|
||||
#endif
|
||||
|
||||
/* Work queue support is required. The low-priority work queue is required
|
||||
* so that the asynchronous I/O does not interfere with high priority driver
|
||||
* operations. If this pre-requisite is met, then asynchronous I/O support
|
||||
* can be enabled with CONFIG_FS_AIO
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_FS_AIO
|
||||
|
||||
#ifndef CONFIG_SCHED_WORKQUEUE
|
||||
# error Asynchronous I/O requires CONFIG_SCHED_WORKQUEUE
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SCHED_LPWORK
|
||||
# error Asynchronous I/O requires CONFIG_SCHED_LPWORK
|
||||
#endif
|
||||
|
||||
/* Standard Definitions *****************************************************/
|
||||
|
||||
/* aio_cancel return values
|
||||
*
|
||||
* AIO_ALLDONE - Indicates that none of the requested operations could
|
||||
* be cancelled since they are already complete.
|
||||
* AIO_CANCELED - Indicates that all requested operations have been
|
||||
* cancelled.
|
||||
* AIO_NOTCANCELED - Indicates that some of the requested operations could
|
||||
* not be cancelled since they are in progress.
|
||||
*/
|
||||
|
||||
#define AIO_CANCELED 0
|
||||
#define AIO_ALLDONE 1
|
||||
#define AIO_NOTCANCELED 2
|
||||
|
||||
/* lio_listio element operations
|
||||
*
|
||||
* LIO_NOP - Indicates that no transfer is requested.
|
||||
* LIO_READ - Requests a read operation.
|
||||
* LIO_WRITE - Requests a write operation.
|
||||
*/
|
||||
|
||||
#define LIO_NOP 0
|
||||
#define LIO_READ 1
|
||||
#define LIO_WRITE 2
|
||||
|
||||
/* lio_listio modes
|
||||
*
|
||||
* LIO_NOWAIT - Indicates that the calling thread is to continue
|
||||
* execution while the lio_listio() operation is being
|
||||
* performed, and no notification is given when the
|
||||
* operation is complete.
|
||||
* LIO_WAIT - Indicates that the calling thread is to suspend until
|
||||
* the lio_listio() operation is complete.
|
||||
*/
|
||||
|
||||
#define LIO_NOWAIT 0
|
||||
#define LIO_WAIT 1
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
struct aiocb
|
||||
{
|
||||
/* Standard fields required by POSIX */
|
||||
|
||||
struct sigevent aio_sigevent; /* Signal number and value */
|
||||
FAR volatile void *aio_buf; /* Location of buffer */
|
||||
off_t aio_offset; /* File offset */
|
||||
size_t aio_nbytes; /* Length of transfer */
|
||||
int16_t aio_fildes; /* File descriptor (should be int) */
|
||||
int8_t aio_reqprio; /* Request priority offset (not used, should be int) */
|
||||
uint8_t aio_lio_opcode; /* Operation to be performed (should be int) */
|
||||
|
||||
/* Non-standard, implementation-dependent data. For portability reasons,
|
||||
* application code should never reference these elements.
|
||||
*/
|
||||
|
||||
struct sigwork_s aio_sigwork; /* Signal work */
|
||||
volatile ssize_t aio_result; /* Support for aio_error() and aio_return() */
|
||||
FAR void *aio_priv; /* Used by signal handlers */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
int aio_cancel(int fildes, FAR struct aiocb *aiocbp);
|
||||
int aio_error(FAR const struct aiocb *aiocbp);
|
||||
int aio_fsync(int op, FAR struct aiocb *aiocbp);
|
||||
int aio_read(FAR struct aiocb *aiocbp);
|
||||
ssize_t aio_return(FAR struct aiocb *aiocbp);
|
||||
int aio_suspend(FAR const struct aiocb * const list[], int nent,
|
||||
FAR const struct timespec *timeout);
|
||||
int aio_write(FAR struct aiocb *aiocbp);
|
||||
int lio_listio(int mode, FAR struct aiocb * const list[], int nent,
|
||||
FAR struct sigevent *sig);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_FS_AIO */
|
||||
#endif /* __INCLUDE_AIO_H */
|
||||
@@ -0,0 +1,37 @@
|
||||
/****************************************************************************
|
||||
* include/alloca.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_ALLOCA_H
|
||||
#define __INCLUDE_ALLOCA_H
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 3
|
||||
/* Use GCC >=3 Built-in for alloca */
|
||||
|
||||
# undef alloca
|
||||
# undef __alloca
|
||||
# define alloca(size) __alloca(size)
|
||||
# define __alloca(size) __builtin_alloca(size)
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_ALLOCA_H */
|
||||
@@ -0,0 +1,115 @@
|
||||
/****************************************************************************
|
||||
* include/arpa/inet.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_ARPA_INET_H
|
||||
#define __INCLUDE_ARPA_INET_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* This macro to convert a 16/32-bit constant values quantity from host byte
|
||||
* order to network byte order. The 16-bit version of this macro is required
|
||||
* for uIP:
|
||||
*
|
||||
* Author Adam Dunkels <adam@dunkels.com>
|
||||
* Copyright (c) 2001-2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ENDIAN_BIG
|
||||
# define HTONS(ns) (ns)
|
||||
# define HTONL(nl) (nl)
|
||||
#else
|
||||
# define HTONS(ns) \
|
||||
(unsigned short) \
|
||||
(((((unsigned short)(ns)) & 0x00ff) << 8) | \
|
||||
((((unsigned short)(ns)) >> 8) & 0x00ff))
|
||||
# define HTONL(nl) \
|
||||
(unsigned long) \
|
||||
(((((unsigned long)(nl)) & 0x000000ffUL) << 24) | \
|
||||
((((unsigned long)(nl)) & 0x0000ff00UL) << 8) | \
|
||||
((((unsigned long)(nl)) & 0x00ff0000UL) >> 8) | \
|
||||
((((unsigned long)(nl)) & 0xff000000UL) >> 24))
|
||||
#endif
|
||||
|
||||
#define NTOHS(hs) HTONS(hs)
|
||||
#define NTOHL(hl) HTONL(hl)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* Functions to convert between host and network byte ordering.
|
||||
*
|
||||
* REVISIT: Since network order is defined as big-endian, the following
|
||||
* functions are equivalent to functions declared in endian.h:
|
||||
*
|
||||
* htonl htobe32
|
||||
* htons htobe16
|
||||
* ntohl be32toh
|
||||
* ntohs be16toh
|
||||
*/
|
||||
|
||||
uint32_t ntohl(uint32_t nl);
|
||||
uint16_t ntohs(uint16_t ns);
|
||||
uint32_t htonl(uint32_t hl);
|
||||
uint16_t htons(uint16_t hs);
|
||||
|
||||
/* Functions to manipulate address representations */
|
||||
|
||||
int inet_aton(FAR const char *cp, FAR struct in_addr *inp);
|
||||
in_addr_t inet_addr(FAR const char *cp);
|
||||
in_addr_t inet_network(FAR const char *cp);
|
||||
|
||||
FAR char *inet_ntoa(struct in_addr in);
|
||||
in_addr_t inet_lnaof(struct in_addr in);
|
||||
in_addr_t inet_netof(struct in_addr in);
|
||||
|
||||
struct in_addr inet_makeaddr(in_addr_t net, in_addr_t host);
|
||||
|
||||
int inet_pton(int af, FAR const char *src, FAR void *dst);
|
||||
const char *inet_ntop(int af, FAR const void *src, FAR char *dst,
|
||||
socklen_t size);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_ARPA_INET_H */
|
||||
@@ -0,0 +1,128 @@
|
||||
/****************************************************************************
|
||||
* include/assert.h
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011-2013, 2015-2016 Gregory Nutt.
|
||||
* All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Copyright (C) 2016 Omni Hoverboards Inc. All rights reserved.
|
||||
* Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
||||
*
|
||||
* 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 __INCLUDE_ASSERT_H
|
||||
#define __INCLUDE_ASSERT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/compiler.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Macro Name: PANIC, ASSERT, VERIFY, et al. */
|
||||
|
||||
#undef PANIC /* Unconditional abort */
|
||||
#undef ASSERT /* Assert if the condition is not true */
|
||||
#undef VERIFY /* Assert if a function returns a negative value */
|
||||
#undef DEBUGPANIC /* Like PANIC, but only if CONFIG_DEBUG_ASSERTIONS is defined */
|
||||
#undef DEBUGASSERT /* Like ASSERT, but only if CONFIG_DEBUG_ASSERTIONS is defined */
|
||||
#undef DEBUGVERIFY /* Like VERIFY, but only if CONFIG_DEBUG_ASSERTIONS is defined */
|
||||
|
||||
#ifdef CONFIG_HAVE_FILENAME
|
||||
# define PANIC() _assert(__FILE__, __LINE__)
|
||||
#else
|
||||
# define PANIC() _assert("unknown", 0)
|
||||
#endif
|
||||
|
||||
#define ASSERT(f) do { if (!(f)) PANIC(); } while (0)
|
||||
#define VERIFY(f) do { if ((f) < 0) PANIC(); } while (0)
|
||||
|
||||
#ifdef CONFIG_DEBUG_ASSERTIONS
|
||||
# define DEBUGPANIC() PANIC()
|
||||
# define DEBUGASSERT(f) ASSERT(f)
|
||||
# define DEBUGVERIFY(f) VERIFY(f)
|
||||
#else
|
||||
# define DEBUGPANIC()
|
||||
# define DEBUGASSERT(f) UNUSED(f)
|
||||
# define DEBUGVERIFY(f) ((void)(f))
|
||||
#endif
|
||||
|
||||
/* The C standard states that if NDEBUG is defined, assert will do nothing.
|
||||
* Users can define and undefine NDEBUG as they see fit to choose when assert
|
||||
* does something or does not do anything.
|
||||
*/
|
||||
|
||||
#ifdef NDEBUG
|
||||
# define assert(f) UNUSED(f)
|
||||
#else
|
||||
# define assert(f) ASSERT(f)
|
||||
#endif
|
||||
|
||||
/* Definition required for C11 compile-time assertion checking. The
|
||||
* static_assert macro simply expands to the _Static_assert keyword.
|
||||
*/
|
||||
|
||||
#ifndef __cplusplus
|
||||
# define static_assert _Static_assert
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
void _assert(FAR const char *filename, int linenum) noreturn_function;
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_ASSERT_H */
|
||||
@@ -0,0 +1,68 @@
|
||||
/****************************************************************************
|
||||
* include/crc16.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_CRC16_H
|
||||
#define __INCLUDE_CRC16_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: crc16part
|
||||
*
|
||||
* Description:
|
||||
* Continue CRC calculation on a part of the buffer.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint16_t crc16part(FAR const uint8_t *src, size_t len, uint16_t crc16val);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: crc16
|
||||
*
|
||||
* Description:
|
||||
* Return a 16-bit CRC of the contents of the 'src' buffer, length 'len'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint16_t crc16(FAR const uint8_t *src, size_t len);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_CRC16_H */
|
||||
@@ -0,0 +1,68 @@
|
||||
/****************************************************************************
|
||||
* include/crc32.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_CRC32_H
|
||||
#define __INCLUDE_CRC32_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: crc32part
|
||||
*
|
||||
* Description:
|
||||
* Continue CRC calculation on a part of the buffer.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t crc32part(FAR const uint8_t *src, size_t len, uint32_t crc32val);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: crc32
|
||||
*
|
||||
* Description:
|
||||
* Return a 32-bit CRC of the contents of the 'src' buffer, length 'len'
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t crc32(FAR const uint8_t *src, size_t len);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_CRC32_H */
|
||||
@@ -0,0 +1,109 @@
|
||||
/****************************************************************************
|
||||
* include/crc64.h
|
||||
*
|
||||
* Copyright (C) 2016 Omni Hoverboards Inc. All rights reserved.
|
||||
* Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
||||
*
|
||||
* 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 __INCLUDE_CRC64_H
|
||||
#define __INCLUDE_CRC64_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* CRC64_CHECK is the CRC64 of the string "123456789" without the null byte.
|
||||
*
|
||||
* const uint8_t checkbuf[] =
|
||||
* {
|
||||
* '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
||||
* };
|
||||
*
|
||||
* assert(crc64(checkbuf, sizeof(checkbuf)) == CRC64_CHECK);
|
||||
*/
|
||||
|
||||
/* CRC-64/WE */
|
||||
|
||||
#define CRC64_POLY ((uint64_t)0x42f0e1eba9ea3693ull)
|
||||
#define CRC64_INIT ((uint64_t)0xffffffffffffffffull)
|
||||
#define CRC64_XOROUT ((uint64_t)0xffffffffffffffffull)
|
||||
#define CRC64_CHECK ((uint64_t)0x62ec59e3f1a4f00aull)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: crc64part
|
||||
*
|
||||
* Description:
|
||||
* Continue CRC calculation on a part of the buffer.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint64_t crc64part(FAR const uint8_t *src, size_t len, uint64_t crc64val);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: crc64
|
||||
*
|
||||
* Description:
|
||||
* Return a 64-bit CRC of the contents of the 'src' buffer, length 'len'.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint64_t crc64(FAR const uint8_t *src, size_t len);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_HAVE_LONG_LONG */
|
||||
#endif /* __INCLUDE_CRC64_H */
|
||||
@@ -0,0 +1,107 @@
|
||||
/****************************************************************************
|
||||
* include/crc8.h
|
||||
*
|
||||
* Copyright (C) 2014 Ken Pettit. All rights reserved.
|
||||
* Author: Ken Pettit <pettitkd@gmail.com>
|
||||
*
|
||||
* 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 __INCLUDE_CRC8_H
|
||||
#define __INCLUDE_CRC8_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: crc8part
|
||||
*
|
||||
* Description:
|
||||
* Continue CRC calculation on a part of the buffer using the polynomial
|
||||
* x^8+x^6+x^3+x^2+1 (Koopman, et al. "0xA6" poly).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint8_t crc8part(FAR const uint8_t *src, size_t len, uint8_t crc8val);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: crc8
|
||||
*
|
||||
* Description:
|
||||
* Return an 8-bit CRC of the contents of the 'src' buffer, length 'len'
|
||||
* using the polynomial x^8+x^6+x^3+x^2+1 (Koopman, et al. "0xA6" poly).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint8_t crc8(FAR const uint8_t *src, size_t len);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: crc8ccitt
|
||||
*
|
||||
* Description:
|
||||
* Return an 8-bit CRC of the contents of the 'src' buffer, length 'len'
|
||||
* using the polynomial x^8+x^2+x^1+1 (aka "0x07" poly).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint8_t crc8ccitt(FAR const uint8_t *src, size_t len);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: crc8part
|
||||
*
|
||||
* Description:
|
||||
* Continue CRC calculation on a part of the buffer using the polynomial
|
||||
* x^8+x^2+x^1+1 (aka "0x07" poly).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint8_t crc8ccittpart(FAR const uint8_t *src, size_t len, uint8_t crc8val);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_CRC8_H */
|
||||
@@ -0,0 +1,314 @@
|
||||
/****************************************************************************
|
||||
* include/ctype.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_CTYPE_H
|
||||
#define __INCLUDE_CTYPE_H
|
||||
|
||||
/* There is no consistent ctype implementation, just a smattering of
|
||||
* functions. Individually, they are okay, but a more standard, data lookup
|
||||
* approach would make more sense if used extensively.
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: isspace
|
||||
*
|
||||
* Description:
|
||||
* Checks for white-space characters. In the "C" and "POSIX" locales,
|
||||
* these are: space, form-feed ('\f'), newline ('\n'), carriage return
|
||||
* ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int isspace(int c)
|
||||
{
|
||||
return c == ' ' || c == '\t' || c == '\n' || c == '\r' ||
|
||||
c == '\f' || c == '\v';
|
||||
}
|
||||
#else
|
||||
int isspace(int c);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: isascii
|
||||
*
|
||||
* Description:
|
||||
* Checks whether c is a 7-bit unsigned char value that fits into the
|
||||
* ASCII character set.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int isascii(int c)
|
||||
{
|
||||
return c >= 0 && c <= 0x7f;
|
||||
}
|
||||
#else
|
||||
int isascii(int c);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: isprint
|
||||
*
|
||||
* Description:
|
||||
* Checks for a printable character (including space)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int isprint(int c)
|
||||
{
|
||||
return c >= 0x20 && c < 0x7f;
|
||||
}
|
||||
#else
|
||||
int isprint(int c);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: isgraph
|
||||
*
|
||||
* Description:
|
||||
* Checks for a printable character (excluding space)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int isgraph(int c)
|
||||
{
|
||||
return c > 0x20 && c < 0x7f;
|
||||
}
|
||||
#else
|
||||
int isgraph(int c);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: iscntrl
|
||||
*
|
||||
* Description:
|
||||
* Checks for control character.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int iscntrl(int c)
|
||||
{
|
||||
return c < 0x20 || c == 0x7f;
|
||||
}
|
||||
#else
|
||||
int iscntrl(int c);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: islower
|
||||
*
|
||||
* Description:
|
||||
* Checks for an lowercase letter.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int islower(int c)
|
||||
{
|
||||
return c >= 'a' && c <= 'z';
|
||||
}
|
||||
#else
|
||||
int islower(int c);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: isupper
|
||||
*
|
||||
* Description:
|
||||
* Checks for an uppercase letter.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int isupper(int c)
|
||||
{
|
||||
return c >= 'A' && c <= 'Z';
|
||||
}
|
||||
#else
|
||||
int isupper(int c);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: isalpha
|
||||
*
|
||||
* Description:
|
||||
* Checks for an alphabetic character
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int isalpha(int c)
|
||||
{
|
||||
return islower(c) || isupper(c);
|
||||
}
|
||||
#else
|
||||
int isalpha(int c);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: isblank
|
||||
*
|
||||
* Description:
|
||||
* Checks for blank characters (space or tab). C++11
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int isblank(int c)
|
||||
{
|
||||
return c == ' ' || c == '\t';
|
||||
}
|
||||
#else
|
||||
int isblank(int c);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: isdigit
|
||||
*
|
||||
* Description:
|
||||
* ANSI standard isdigit implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int isdigit(int c)
|
||||
{
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
#else
|
||||
int isdigit(int c);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: isalnum
|
||||
*
|
||||
* Description:
|
||||
* Checks for an alphanumeric character
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int isalnum(int c)
|
||||
{
|
||||
return isalpha(c) || isdigit(c);
|
||||
}
|
||||
#else
|
||||
int isalnum(int c);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ispunct
|
||||
*
|
||||
* Description:
|
||||
* Checks for a printable character which is not a space or an
|
||||
* alphanumeric character
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int ispunct(int c)
|
||||
{
|
||||
return isgraph(c) && !isalnum(c);
|
||||
}
|
||||
#else
|
||||
int ispunct(int c);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: isxdigit
|
||||
*
|
||||
* Description:
|
||||
* isxdigit() checks for a hexadecimal digits, i.e. one of {0-9,a-f,A-F}
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int isxdigit(int c)
|
||||
{
|
||||
return (c >= '0' && c <= '9') ||
|
||||
(c >= 'a' && c <= 'f') ||
|
||||
(c >= 'A' && c <= 'F');
|
||||
}
|
||||
#else
|
||||
int isxdigit(int c);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: toupper
|
||||
*
|
||||
* Description:
|
||||
* toupper() converts the letter c to upper case, if possible.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int toupper(int c)
|
||||
{
|
||||
return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c;
|
||||
}
|
||||
#else
|
||||
int toupper(int c);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tolower
|
||||
*
|
||||
* Description:
|
||||
* tolower() converts the letter c to lower case, if possible.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
static inline int tolower(int c)
|
||||
{
|
||||
return (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c;
|
||||
}
|
||||
#else
|
||||
int tolower(int c);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_CTYPE_H */
|
||||
@@ -0,0 +1,34 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cassert
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CASSERT
|
||||
#define __INCLUDE_CXX_CASSERT
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
#endif // __INCLUDE_CXX_CASSERT
|
||||
@@ -0,0 +1,53 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cctype
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CCTYPE
|
||||
#define __INCLUDE_CXX_CCTYPE
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
using ::isspace;
|
||||
using ::isascii;
|
||||
using ::isprint;
|
||||
using ::isgraph;
|
||||
using ::iscntrl;
|
||||
using ::islower;
|
||||
using ::isupper;
|
||||
using ::isalpha;
|
||||
using ::isblank;
|
||||
using ::isdigit;
|
||||
using ::isalnum;
|
||||
using ::ispunct;
|
||||
using ::isxdigit;
|
||||
using ::toupper;
|
||||
using ::tolower;
|
||||
}
|
||||
|
||||
#endif // __INCLUDE_CXX_CCTYPE
|
||||
@@ -0,0 +1,34 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cerrno
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CERRNO
|
||||
#define __INCLUDE_CXX_CERRNO
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
#endif // __INCLUDE_CXX_CERRNO
|
||||
@@ -0,0 +1,42 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cfcntl
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CFCNTL
|
||||
#define __INCLUDE_CXX_CFCNTL
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
using ::flock;
|
||||
//using ::creat;
|
||||
using ::open;
|
||||
using ::fcntl;
|
||||
}
|
||||
|
||||
#endif // __INCLUDE_CXX_CFCNTL
|
||||
@@ -0,0 +1,34 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/climits
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CLIMITS
|
||||
#define __INCLUDE_CXX_CLIMITS
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
#endif // __INCLUDE_CXX_CLIMITS
|
||||
@@ -0,0 +1,41 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/clocale
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CLOCALE
|
||||
#define __INCLUDE_CXX_CLOCALE
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <locale.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
using ::locale_t;
|
||||
using ::setlocale;
|
||||
using ::localeconv;
|
||||
}
|
||||
|
||||
#endif // __INCLUDE_CXX_CLOCALE
|
||||
@@ -0,0 +1,127 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cmath
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CMATH
|
||||
#define __INCLUDE_CXX_CMATH
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
using ::float_t;
|
||||
using ::double_t;
|
||||
|
||||
#ifdef CONFIG_HAVE_FLOAT
|
||||
using ::acosf;
|
||||
using ::asinf;
|
||||
using ::atanf;
|
||||
using ::atan2f;
|
||||
using ::ceilf;
|
||||
using ::cosf;
|
||||
using ::coshf;
|
||||
using ::expf;
|
||||
using ::fabsf;
|
||||
using ::floorf;
|
||||
using ::fmodf;
|
||||
using ::frexpf;
|
||||
using ::ldexpf;
|
||||
using ::logf;
|
||||
using ::log10f;
|
||||
using ::log2f;
|
||||
using ::modff;
|
||||
using ::roundf;
|
||||
using ::powf;
|
||||
using ::sinf;
|
||||
using ::sinhf;
|
||||
using ::sqrtf;
|
||||
using ::tanf;
|
||||
using ::tanhf;
|
||||
using ::gamma;
|
||||
using ::lgamma;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_DOUBLE
|
||||
using ::acos;
|
||||
using ::asin;
|
||||
using ::atan;
|
||||
using ::atan2;
|
||||
using ::ceil;
|
||||
using ::cos;
|
||||
using ::cosh;
|
||||
using ::exp;
|
||||
using ::fabs;
|
||||
using ::floor;
|
||||
using ::fmod;
|
||||
using ::frexp;
|
||||
using ::ldexp;
|
||||
using ::log;
|
||||
using ::log10;
|
||||
using ::log2;
|
||||
using ::modf;
|
||||
using ::round;
|
||||
using ::pow;
|
||||
using ::sin;
|
||||
using ::sinh;
|
||||
using ::sqrt;
|
||||
using ::tan;
|
||||
using ::tanh;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
using ::acosl;
|
||||
using ::asinl;
|
||||
using ::atanl;
|
||||
using ::atan2l;
|
||||
using ::ceill;
|
||||
using ::cosl;
|
||||
using ::coshl;
|
||||
using ::expl;
|
||||
using ::fabsl;
|
||||
using ::floorl;
|
||||
using ::fmodl;
|
||||
using ::frexpl;
|
||||
using ::ldexpl;
|
||||
using ::logl;
|
||||
using ::log10l;
|
||||
using ::log2l;
|
||||
using ::modfl;
|
||||
using ::roundl;
|
||||
using ::powl;
|
||||
using ::sinl;
|
||||
using ::sinhl;
|
||||
using ::sqrtl;
|
||||
using ::tanl;
|
||||
using ::tanhl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif // __INCLUDE_CXX_CMATH
|
||||
@@ -0,0 +1,52 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/csched
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CSCHED
|
||||
#define __INCLUDE_CXX_CSCHED
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <sched.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
using ::sched_param;
|
||||
using ::task_create;
|
||||
using ::task_delete;
|
||||
using ::task_restart;
|
||||
using ::sched_setparam;
|
||||
using ::sched_getparam;
|
||||
using ::sched_setscheduler;
|
||||
using ::sched_getscheduler;
|
||||
using ::sched_get_priority_max;
|
||||
using ::sched_get_priority_min;
|
||||
using ::sched_rr_get_interval;
|
||||
using ::sched_lock;
|
||||
using ::sched_unlock;
|
||||
using ::sched_lockcount;
|
||||
}
|
||||
|
||||
#endif // __INCLUDE_CXX_CSCHED
|
||||
@@ -0,0 +1,65 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/csignal
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CSIGNAL
|
||||
#define __INCLUDE_CXX_CSIGNAL
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
using ::sigset_t;
|
||||
using ::sig_atomic_t;
|
||||
using ::sigval;
|
||||
using ::sigevent;
|
||||
using ::siginfo;
|
||||
using ::siginfo_t;
|
||||
using ::sigaction;
|
||||
using ::kill;
|
||||
using ::raise;
|
||||
using ::sigaction;
|
||||
using ::sigaddset;
|
||||
using ::sigdelset;
|
||||
using ::sigemptyset;
|
||||
using ::sigfillset;
|
||||
using ::sighold;
|
||||
using ::sigismember;
|
||||
using ::sigignore;
|
||||
using ::signal;
|
||||
using ::sigpause;
|
||||
using ::sigpending;
|
||||
using ::sigprocmask;
|
||||
using ::sigqueue;
|
||||
using ::sigrelse;
|
||||
using ::sigset;
|
||||
using ::sigtimedwait;
|
||||
using ::sigsuspend;
|
||||
using ::sigwaitinfo;
|
||||
}
|
||||
|
||||
#endif // CSIGNAL_HEADER
|
||||
@@ -0,0 +1,34 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cstdarg
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CSTDARG
|
||||
#define __INCLUDE_CXX_CSTDARG
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
#endif // __INCLUDE_CXX_CSTDARG
|
||||
@@ -0,0 +1,45 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cstdbool
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CSTDBOOL
|
||||
#define __INCLUDE_CXX_CSTDBOOL
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef CONFIG_C99_BOOL8
|
||||
namespace std
|
||||
{
|
||||
using ::_Bool8;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __INCLUDE_CXX_CSTDBOOL
|
||||
@@ -0,0 +1,61 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cstddef
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CSTDDEF
|
||||
#define __INCLUDE_CXX_CSTDDEF
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
// Standard types
|
||||
|
||||
using ::mode_t;
|
||||
using ::size_t;
|
||||
using ::ssize_t;
|
||||
using ::off_t;
|
||||
using ::blksize_t;
|
||||
using ::blkcnt_t;
|
||||
using ::fpos_t;
|
||||
using ::uid_t;
|
||||
using ::gid_t;
|
||||
using ::dev_t;
|
||||
using ::ino_t;
|
||||
using ::pid_t;
|
||||
|
||||
using ::socklen_t;
|
||||
using ::sa_family_t;
|
||||
#if __cplusplus >= 201103L
|
||||
using nullptr_t = decltype(nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // __INCLUDE_CXX_CSTDDEF
|
||||
@@ -0,0 +1,66 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cstdint
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CSTDINT
|
||||
#define __INCLUDE_CXX_CSTDINT
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
using ::int8_t;
|
||||
using ::int16_t;
|
||||
using ::int32_t;
|
||||
using ::int64_t;
|
||||
using ::int_fast8_t;
|
||||
using ::int_fast16_t;
|
||||
using ::int_fast32_t;
|
||||
using ::int_fast64_t;
|
||||
using ::int_least8_t;
|
||||
using ::int_least16_t;
|
||||
using ::int_least32_t;
|
||||
using ::int_least64_t;
|
||||
using ::intmax_t;
|
||||
using ::intptr_t;
|
||||
using ::uint8_t;
|
||||
using ::uint16_t;
|
||||
using ::uint32_t;
|
||||
using ::uint64_t;
|
||||
using ::uint_fast8_t;
|
||||
using ::uint_fast16_t;
|
||||
using ::uint_fast32_t;
|
||||
using ::uint_fast64_t;
|
||||
using ::uint_least8_t;
|
||||
using ::uint_least16_t;
|
||||
using ::uint_least32_t;
|
||||
using ::uint_least64_t;
|
||||
using ::uintmax_t;
|
||||
using ::uintptr_t;
|
||||
}
|
||||
|
||||
#endif // __INCLUDE_CXX_CSTDINT
|
||||
@@ -0,0 +1,99 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cstdio
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CSTDIO
|
||||
#define __INCLUDE_CXX_CSTDIO
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
using ::FILE;
|
||||
using ::fpos_t;
|
||||
using ::size_t;
|
||||
|
||||
// Operations on streams (FILE)
|
||||
|
||||
using ::clearerr;
|
||||
using ::fclose;
|
||||
using ::fflush;
|
||||
using ::feof;
|
||||
using ::ferror;
|
||||
using ::fileno;
|
||||
using ::fgetc;
|
||||
using ::fgetpos;
|
||||
using ::fgets;
|
||||
using ::fopen;
|
||||
using ::fprintf;
|
||||
using ::fputc;
|
||||
using ::fputs;
|
||||
using ::fread;
|
||||
using ::freopen;
|
||||
using ::fseek;
|
||||
using ::fsetpos;
|
||||
using ::ftell;
|
||||
using ::fwrite;
|
||||
using ::gets;
|
||||
using ::gets_s;
|
||||
using ::setbuf;
|
||||
using ::setvbuf;
|
||||
using ::ungetc;
|
||||
|
||||
// Operations on the stdout stream, buffers, paths, and the whole printf-family
|
||||
|
||||
using ::printf;
|
||||
using ::puts;
|
||||
using ::rename;
|
||||
using ::sprintf;
|
||||
using ::asprintf;
|
||||
using ::snprintf;
|
||||
using ::sscanf;
|
||||
using ::perror;
|
||||
|
||||
using ::vprintf;
|
||||
using ::vfprintf;
|
||||
using ::vsprintf;
|
||||
using ::vasprintf;
|
||||
using ::vsnprintf;
|
||||
using ::vsscanf;
|
||||
|
||||
// Operations on file descriptors including:
|
||||
|
||||
using ::fdopen;
|
||||
using ::dprintf;
|
||||
using ::vdprintf;
|
||||
|
||||
// Operations on paths
|
||||
|
||||
using ::tmpnam;
|
||||
using ::tempnam;
|
||||
using ::remove;
|
||||
}
|
||||
|
||||
#endif // __INCLUDE_CXX_CSTDIO
|
||||
@@ -0,0 +1,142 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cstdlib
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CSTDLIB
|
||||
#define __INCLUDE_CXX_CSTDLIB
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
// Random number generation
|
||||
|
||||
using ::srand;
|
||||
using ::rand;
|
||||
using ::random;
|
||||
|
||||
// Environment variable support
|
||||
|
||||
using ::get_environ_ptr;
|
||||
using ::getenv;
|
||||
using ::putenv;
|
||||
using ::clearenv;
|
||||
using ::setenv;
|
||||
using ::unsetenv;
|
||||
|
||||
// Process exit functions
|
||||
|
||||
using ::exit;
|
||||
using ::abort;
|
||||
using ::atexit;
|
||||
using ::on_exit;
|
||||
|
||||
#ifndef __KERNEL__
|
||||
// System command
|
||||
|
||||
using ::system;
|
||||
#endif
|
||||
|
||||
// String to binary conversions
|
||||
|
||||
using ::atof;
|
||||
using ::atoi;
|
||||
using ::atol;
|
||||
using ::strtol;
|
||||
using ::strtoul;
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
using ::strtoll;
|
||||
using ::strtoull;
|
||||
#endif
|
||||
using ::strtof;
|
||||
#ifdef CONFIG_HAVE_DOUBLE
|
||||
using ::strtod;
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
using ::strtold;
|
||||
#endif
|
||||
|
||||
// Binary to string conversions
|
||||
|
||||
using ::itoa;
|
||||
|
||||
// Wide character operations
|
||||
|
||||
#ifdef CONFIG_LIBC_WCHAR
|
||||
using ::mbtowc;
|
||||
using ::wctomb;
|
||||
#endif
|
||||
|
||||
// Memory Management
|
||||
|
||||
using ::malloc;
|
||||
using ::free;
|
||||
using ::realloc;
|
||||
using ::memalign;
|
||||
using ::zalloc;
|
||||
using ::calloc;
|
||||
|
||||
#ifdef CONFIG_PSEUDOTERM
|
||||
// Pseudo-Terminals
|
||||
|
||||
#ifdef CONFIG_PSEUDOTERM_SUSV1
|
||||
using ::ptsname;
|
||||
using ::ptsname_r;
|
||||
#endif
|
||||
using ::unlockpt;
|
||||
#endif
|
||||
|
||||
// Arithmetic
|
||||
|
||||
using ::abs;
|
||||
using ::labs;
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
using ::llabs;
|
||||
#endif
|
||||
|
||||
using ::div;
|
||||
using ::ldiv;
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
using ::lldiv;
|
||||
#endif
|
||||
|
||||
// Temporary files
|
||||
|
||||
using ::mktemp;
|
||||
using ::mkstemp;
|
||||
|
||||
// Sorting
|
||||
|
||||
using ::qsort;
|
||||
|
||||
// Binary search
|
||||
|
||||
using ::bsearch;
|
||||
}
|
||||
|
||||
#endif // __INCLUDE_CXX_CSTDLIB
|
||||
@@ -0,0 +1,81 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cstring
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CSTRING
|
||||
#define __INCLUDE_CXX_CSTRING
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
using ::size_t;
|
||||
|
||||
// Declared in string.h
|
||||
|
||||
using ::strdup;
|
||||
using ::strndup;
|
||||
using ::strerror;
|
||||
using ::strerror_r;
|
||||
using ::strlen;
|
||||
using ::strnlen;
|
||||
using ::strcat;
|
||||
using ::strncat;
|
||||
using ::strcmp;
|
||||
using ::strncmp;
|
||||
using ::strcoll;
|
||||
using ::stpcpy;
|
||||
using ::strcpy;
|
||||
using ::strncpy;
|
||||
using ::strpbrk;
|
||||
using ::strchr;
|
||||
using ::strrchr;
|
||||
using ::strspn;
|
||||
using ::strcspn;
|
||||
using ::strstr;
|
||||
using ::strcasestr;
|
||||
using ::strtok;
|
||||
using ::strtok_r;
|
||||
using ::strxfrm;
|
||||
|
||||
using ::memchr;
|
||||
using ::memccpy;
|
||||
using ::memcmp;
|
||||
using ::memcpy;
|
||||
using ::memmove;
|
||||
using ::memset;
|
||||
|
||||
// Declared in legacy strings.h
|
||||
|
||||
using ::ffs;
|
||||
using ::strcasecmp;
|
||||
using ::strncasecmp;
|
||||
}
|
||||
|
||||
#endif // __INCLUDE_CXX_CSTRING
|
||||
@@ -0,0 +1,55 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/ctime
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CTIME
|
||||
#define __INCLUDE_CXX_CTIME
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <time.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
using ::size_t;
|
||||
using ::time_t;
|
||||
using ::clockid_t;
|
||||
using ::timer_t;
|
||||
using ::timespec;
|
||||
using ::tm;
|
||||
using ::itimerspec;
|
||||
using ::sigevent;
|
||||
using ::clock_settime;
|
||||
using ::clock_gettime;
|
||||
using ::mktime;
|
||||
using ::gmtime_r;
|
||||
using ::timer_create;
|
||||
using ::timer_delete;
|
||||
using ::timer_settime;
|
||||
using ::timer_gettime;
|
||||
using ::timer_getoverrun;
|
||||
}
|
||||
|
||||
#endif // __INCLUDE_CXX_CTIME
|
||||
@@ -0,0 +1,114 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cunistd
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CUNISTD
|
||||
#define __INCLUDE_CXX_CUNISTD
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
// Task control interfaces
|
||||
|
||||
using ::vfork;
|
||||
using ::getpid;
|
||||
using ::_exit;
|
||||
using ::sleep;
|
||||
using ::usleep;
|
||||
using ::pause;
|
||||
|
||||
// File descriptor operations
|
||||
|
||||
using ::close;
|
||||
using ::dup;
|
||||
using ::dup2;
|
||||
using ::fsync;
|
||||
using ::lseek;
|
||||
using ::read;
|
||||
using ::write;
|
||||
using ::pread;
|
||||
using ::pwrite;
|
||||
|
||||
// Terminal I/O
|
||||
|
||||
#ifdef CONFIG_SERIAL_TERMIOS
|
||||
using ::isatty;
|
||||
#endif
|
||||
|
||||
// Memory management
|
||||
|
||||
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_MM_PGALLOC) && \
|
||||
defined(CONFIG_ARCH_USE_MMU)
|
||||
using sbrk;
|
||||
#endif
|
||||
|
||||
// Special devices
|
||||
|
||||
using ::pipe;
|
||||
|
||||
// Operations on working directories
|
||||
|
||||
using ::chdir;
|
||||
using ::getcwd;
|
||||
|
||||
// Operations on file paths
|
||||
|
||||
using ::access;
|
||||
using ::rmdir;
|
||||
using ::unlink;
|
||||
using ::symlink;
|
||||
using ::readlink;
|
||||
|
||||
// Execution of program files
|
||||
|
||||
#ifdef CONFIG_LIBC_EXECFUNCS
|
||||
using ::execl;
|
||||
using ::execv;
|
||||
#endif
|
||||
|
||||
// Byte operations
|
||||
|
||||
using ::swab;
|
||||
|
||||
// getopt and friends
|
||||
|
||||
using ::getopt;
|
||||
|
||||
// Non-standard accessor functions
|
||||
|
||||
using ::getoptargp;
|
||||
using ::getoptindp;
|
||||
using ::getoptoptp;
|
||||
|
||||
// Networking
|
||||
|
||||
using ::gethostname;
|
||||
using ::sethostname;
|
||||
}
|
||||
|
||||
#endif // __INCLUDE_CXX_CUNISTD
|
||||
@@ -0,0 +1,132 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cwchar
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CWCHAR
|
||||
#define __INCLUDE_CXX_CWCHAR
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
using ::mbstate_t;
|
||||
using ::wint_t;
|
||||
using ::wctype_t;
|
||||
using ::size_t;
|
||||
|
||||
#ifdef CONFIG_LIBC_WCHAR
|
||||
using ::btowc;
|
||||
using ::fwprintf;
|
||||
using ::fwscanf;
|
||||
using ::iswalnum;
|
||||
using ::iswalpha;
|
||||
using ::iswcntrl;
|
||||
using ::iswdigit;
|
||||
using ::iswgraph;
|
||||
using ::iswlower;
|
||||
using ::iswprint;
|
||||
using ::iswpunct;
|
||||
using ::iswspace;
|
||||
using ::iswupper;
|
||||
using ::iswxdigit;
|
||||
using ::iswctype;
|
||||
using ::fgetwc;
|
||||
using ::fgetws;
|
||||
using ::fputwc;
|
||||
using ::fputws;
|
||||
using ::fwide;
|
||||
using ::getwc;
|
||||
using ::getwchar;
|
||||
using ::mbsinit;
|
||||
using ::mbrlen;
|
||||
using ::mbrtowc;
|
||||
using ::mbsrtowcs;
|
||||
using ::mbtowc;
|
||||
using ::putwc;
|
||||
using ::putwchar;
|
||||
using ::swprintf;
|
||||
using ::swscanf;
|
||||
using ::towlower;
|
||||
using ::towupper;
|
||||
using ::ungetwc;
|
||||
using ::vfwprintf;
|
||||
using ::vwprintf;
|
||||
using ::vswprintf;
|
||||
using ::wcstold;
|
||||
using ::wcrtomb;
|
||||
using ::wcscat;
|
||||
using ::wcschr;
|
||||
using ::wcscmp;
|
||||
using ::wcscoll;
|
||||
using ::wcscpy;
|
||||
using ::wcscspn;
|
||||
using ::wcsftime;
|
||||
using ::wcslen;
|
||||
using ::wcslcpy;
|
||||
using ::wcslcat;
|
||||
using ::wcsncat;
|
||||
using ::wcsncmp;
|
||||
using ::wcsncpy;
|
||||
using ::wcspbrk;
|
||||
using ::wcsrchr;
|
||||
using ::wcsrtombs;
|
||||
using ::wcsspn;
|
||||
using ::wcsstr;
|
||||
#ifdef CONFIG_HAVE_DOUBLE
|
||||
using ::wcstod;
|
||||
#endif
|
||||
using ::wcstof;
|
||||
using ::wcstok;
|
||||
using ::wcstol;
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
using ::wcstold;
|
||||
#endif
|
||||
using ::wcstoll;
|
||||
using ::wcstoul;
|
||||
using ::wcstoull;
|
||||
using ::wcswcs;
|
||||
using ::wcswidth;
|
||||
using ::wcsxfrm;
|
||||
using ::wctob;
|
||||
using ::wctomb;
|
||||
using ::wctype;
|
||||
using ::wcwidth;
|
||||
using ::wmemchr;
|
||||
using ::wmemcmp;
|
||||
using ::wmemcpy;
|
||||
using ::wmemmove;
|
||||
using ::wmemset;
|
||||
using ::wprintf;
|
||||
using ::wscanf;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // __INCLUDE_CXX_CWCHAR
|
||||
@@ -0,0 +1,61 @@
|
||||
//***************************************************************************
|
||||
// include/cxx/cwctype
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
#ifndef __INCLUDE_CXX_CWCTYPE
|
||||
#define __INCLUDE_CXX_CWCTYPE
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <wctype.h>
|
||||
|
||||
//***************************************************************************
|
||||
// Namespace
|
||||
//***************************************************************************
|
||||
|
||||
namespace std
|
||||
{
|
||||
using ::wint_t;
|
||||
using ::wctrans_t;
|
||||
using ::wctype_t;
|
||||
|
||||
using ::iswalnum;
|
||||
using ::iswalpha;
|
||||
using ::iswblank;
|
||||
using ::iswcntrl;
|
||||
using ::iswctype;
|
||||
using ::iswdigit;
|
||||
using ::iswgraph;
|
||||
using ::iswlower;
|
||||
using ::iswprint;
|
||||
using ::iswpunct;
|
||||
using ::iswspace;
|
||||
using ::iswupper;
|
||||
using ::iswxdigit;
|
||||
using ::towctrans;
|
||||
using ::towlower;
|
||||
using ::towupper;
|
||||
using ::wctrans;
|
||||
using ::iswctype;
|
||||
using ::wctype;
|
||||
};
|
||||
|
||||
#endif // __INCLUDE_CXX_CWCTYPE
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,148 @@
|
||||
/****************************************************************************
|
||||
* include/dirent.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_DIRENT_H
|
||||
#define __INCLUDE_DIRENT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* File type code for the d_type field in dirent structure.
|
||||
* Note that because of the simplified filesystem organization of the NuttX,
|
||||
* top-level, pseudo-file system, an inode can be BOTH a file and a directory
|
||||
*/
|
||||
|
||||
#define DTYPE_UNKNOWN 0
|
||||
#define DTYPE_FIFO 1
|
||||
#define DTYPE_CHR 2
|
||||
#define DTYPE_SEM 3
|
||||
#define DTYPE_DIRECTORY 4
|
||||
#define DTYPE_MQ 5
|
||||
#define DTYPE_BLK 6
|
||||
#define DTYPE_SHM 7
|
||||
#define DTYPE_FILE 8
|
||||
#define DTYPE_MTD 9
|
||||
#define DTYPE_LINK 10
|
||||
#define DTYPE_SOCK 12
|
||||
|
||||
#define DIRENT_ISUNKNOWN(dtype) ((dtype) == DTYPE_UNKNOWN)
|
||||
#define DIRENT_ISFIFO(dtype) ((dtype) == DTYPE_FIFO)
|
||||
#define DIRENT_ISCHR(dtype) ((dtype) == DTYPE_CHR)
|
||||
#define DIRENT_ISSEM(dtype) ((dtype) == DTYPE_SEM)
|
||||
#define DIRENT_ISDIRECTORY(dtype) ((dtype) == DTYPE_DIRECTORY)
|
||||
#define DIRENT_ISMQ(dtype) ((dtype) == DTYPE_MQ)
|
||||
#define DIRENT_ISBLK(dtype) ((dtype) == DTYPE_BLK)
|
||||
#define DIRENT_ISSHM(dtype) ((dtype) == DTYPE_SHM)
|
||||
#define DIRENT_ISFILE(dtype) ((dtype) == DTYPE_FILE)
|
||||
#define DIRENT_ISMTD(dtype) ((dtype) == DTYPE_MTD)
|
||||
#define DIRENT_ISLINK(dtype) ((dtype) == DTYPE_LINK)
|
||||
#define DIRENT_ISSOCK(dtype) ((dtype) == DTYPE_SOCK)
|
||||
|
||||
/* The d_type field of the dirent structure is not specified by POSIX. It
|
||||
* is a non-standard, 4.5BSD extension that is implemented by most OSs. A
|
||||
* POSIX compliant OS may not implement the d_type field at all. Many OS's
|
||||
* (including glibc) may use the following alternative naming for the file
|
||||
* type names:
|
||||
*/
|
||||
|
||||
#define DT_UNKNOWN DTYPE_UNKNOWN
|
||||
#define DT_FIFO DTYPE_FIFO
|
||||
#define DT_CHR DTYPE_CHR
|
||||
#define DT_SEM DTYPE_SEM
|
||||
#define DT_DIR DTYPE_DIRECTORY
|
||||
#define DT_MQ DTYPE_MQ
|
||||
#define DT_BLK DTYPE_BLK
|
||||
#define DT_SHM DTYPE_SHM
|
||||
#define DT_REG DTYPE_FILE
|
||||
#define DT_MTD DTYPE_MTD
|
||||
#define DT_LNK DTYPE_LINK
|
||||
#define DT_SOCK DTYPE_SOCK
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* The POSIX specification requires that the caller of readdir_r provide
|
||||
* storage "large enough for a dirent with the d_name member and an array
|
||||
* of char containing at least {NAME_MAX} plus one elements.
|
||||
*
|
||||
* POSIX also requires the field d_ino (type ino_t) that provides the file
|
||||
* serial number. This functionality is not implemented in NuttX.
|
||||
*/
|
||||
|
||||
struct dirent
|
||||
{
|
||||
uint8_t d_type; /* Type of file */
|
||||
char d_name[NAME_MAX + 1]; /* File name */
|
||||
};
|
||||
|
||||
typedef void DIR;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* POSIX-like File System Interfaces */
|
||||
|
||||
int closedir(FAR DIR *dirp);
|
||||
FAR DIR *opendir(FAR const char *path);
|
||||
FAR struct dirent *readdir(FAR DIR *dirp);
|
||||
int readdir_r(FAR DIR *dirp, FAR struct dirent *entry,
|
||||
FAR struct dirent **result);
|
||||
void rewinddir(FAR DIR *dirp);
|
||||
void seekdir(FAR DIR *dirp, off_t loc);
|
||||
off_t telldir(FAR DIR *dirp);
|
||||
int scandir(FAR const char *path, FAR struct dirent ***namelist,
|
||||
CODE int (*filter)(FAR const struct dirent *),
|
||||
CODE int (*compar)(FAR const struct dirent **,
|
||||
FAR const struct dirent **));
|
||||
int alphasort(FAR const struct dirent **a,
|
||||
FAR const struct dirent **b);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_DIRENT_H */
|
||||
@@ -0,0 +1,317 @@
|
||||
/****************************************************************************
|
||||
* include/dlfcn.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_DLFCN_H
|
||||
#define __INCLUDE_DLFCN_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* The dlfcn.h header defines at least the following macros for use in the
|
||||
* construction of a dlopen() mode argument:
|
||||
*
|
||||
* RTLD_LAZY - Relocations are performed at an implementation-dependent
|
||||
* time, ranging from the time of the dlopen() call until
|
||||
* the first reference to a given symbol occurs. Specifying
|
||||
* RTLD_LAZY should improve performance on implementations
|
||||
* supporting dynamic symbol binding as a process may not
|
||||
* reference all of the functions in any given object. And,
|
||||
* for systems supporting dynamic symbol resolution for
|
||||
* normal process execution, this behaviour mimics the
|
||||
* normal handling of process execution.
|
||||
* RTLD_NOW - All necessary relocations are performed when the object
|
||||
* is first loaded. This may waste some processing if
|
||||
* relocations are performed for functions that are never
|
||||
* referenced. This behaviour may be useful for
|
||||
* applications that need to know as soon as an object is
|
||||
* loaded that all symbols referenced during execution will
|
||||
* be available.
|
||||
*
|
||||
* Any object loaded by dlopen() that requires relocations against global
|
||||
* symbols can reference the symbols in the original process image file,
|
||||
* any objects loaded at program startup, from the object itself as well as
|
||||
* any other object included in the same dlopen() invocation, and any
|
||||
* objects that were loaded in any dlopen() invocation and which specified
|
||||
* the RTLD_GLOBAL flag. To determine the scope of visibility for the
|
||||
* symbols loaded with a dlopen() invocation, the mode parameter should be
|
||||
* bitwise or'ed with one of the following values:
|
||||
*
|
||||
* RTLD_GLOBAL - The object's symbols are made available for the
|
||||
* relocation processing of any other object. In addition,
|
||||
* symbol lookup using dlopen(0, mode) and an associated
|
||||
* dlsym() allows objects loaded with this mode to be
|
||||
* searched.
|
||||
* RTLD_LOCAL - All symbols are not made available for relocation
|
||||
* processing by other modules.
|
||||
*
|
||||
* Reference: OpenGroup.org
|
||||
*/
|
||||
|
||||
#define RTLD_LAZY (0 << 0)
|
||||
#define RTLD_NOW (1 << 0)
|
||||
#define RTLD_GLOBAL (1 << 1)
|
||||
#define RTLD_LOCAL (1 << 2)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dlsymtab
|
||||
*
|
||||
* Description:
|
||||
* dlsymtab() is a non-standard shared library interface. It selects the
|
||||
* symbol table to use when binding a shared library to the base firmware
|
||||
* which may be in FLASH memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* symtab - The new symbol table.
|
||||
* nsymbols - The number of symbols in the symbol table.
|
||||
*
|
||||
* Returned Value:
|
||||
* Always returns OK.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct symtab_s;
|
||||
int dlsymtab(FAR const struct symtab_s *symtab, int nsymbols);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dlopen
|
||||
*
|
||||
* Description:
|
||||
* dlopen() makes an executable object file specified by file available to
|
||||
* the calling program. The class of files eligible for this operation and
|
||||
* the manner of their construction are specified by the implementation,
|
||||
* though typically such files are executable objects such as shared
|
||||
* libraries, relocatable files or programs. Note that some implementations
|
||||
* permit the construction of dependencies between such objects that are
|
||||
* embedded within files. In such cases, a dlopen() operation will load
|
||||
* such dependencies in addition to the object referenced by file.
|
||||
* Implementations may also impose specific constraints on the construction
|
||||
* of programs that can employ dlopen() and its related services.
|
||||
*
|
||||
* If a file is specified in multiple dlopen() invocations, mode is
|
||||
* interpreted at each invocation. Note, however, that once RTLD_NOW has
|
||||
* been specified all relocations will have been completed rendering
|
||||
* further RTLD_NOW operations redundant and any further RTLD_LAZY
|
||||
* operations irrelevant. Similarly note that once RTLD_GLOBAL has been
|
||||
* specified the object will maintain the RTLD_GLOBAL status regardless
|
||||
* of any previous or future specification of RTLD_LOCAL, so long as the
|
||||
* object remains in the address space (see dlclose()).
|
||||
*
|
||||
* Symbols introduced into a program through calls to dlopen() may be
|
||||
* used in relocation activities. Symbols so introduced may duplicate
|
||||
* symbols already defined by the program or previous dlopen()
|
||||
* operations. To resolve the ambiguities such a situation might
|
||||
* present, the resolution of a symbol reference to symbol definition is
|
||||
* based on a symbol resolution order. Two such resolution orders are
|
||||
* defined: load or dependency ordering. Load order establishes an
|
||||
* ordering among symbol definitions, such that the definition first
|
||||
* loaded (including definitions from the image file and any dependent
|
||||
* objects loaded with it) has priority over objects added later (via
|
||||
* dlopen()). Load ordering is used in relocation processing. Dependency
|
||||
* ordering uses a breadth-first order starting with a given object,
|
||||
* then all of its dependencies, then any dependents of those, iterating
|
||||
* until all dependencies are satisfied. With the exception of the global
|
||||
* symbol object obtained via a dlopen() operation on a file of 0,
|
||||
* dependency ordering is used by the dlsym() function. Load ordering is
|
||||
* used in dlsym() operations upon the global symbol object.
|
||||
*
|
||||
* When an object is first made accessible via dlopen() it and its
|
||||
* dependent objects are added in dependency order. Once all the objects
|
||||
* are added, relocations are performed using load order. Note that if an
|
||||
* object or its dependencies had been previously loaded, the load and
|
||||
* dependency orders may yield different resolutions.
|
||||
*
|
||||
* The symbols introduced by dlopen() operations, and available through
|
||||
* dlsym() are at a minimum those which are exported as symbols of global
|
||||
* scope by the object. Typically such symbols will be those that were
|
||||
* specified in (for example) C source code as having extern linkage. The
|
||||
* precise manner in which an implementation constructs the set of
|
||||
* exported symbols for a dlopen() object is specified by that
|
||||
* implementation.
|
||||
*
|
||||
* Input Parameters:
|
||||
* file - Used to construct a pathname to the object file. If file
|
||||
* contains a slash character, the file argument is used as the
|
||||
* pathname for the file. Otherwise, file is used in an
|
||||
* implementation-dependent manner to yield a pathname.
|
||||
*
|
||||
* If the value of file is 0, dlopen() provides a handle on a
|
||||
* global symbol object. This object provides access to the symbols
|
||||
* from an ordered set of objects consisting of the original
|
||||
* program image file, together with any objects loaded at program
|
||||
* startup as specified by that process image file (for example,
|
||||
* shared libraries), and the set of objects loaded using a
|
||||
* dlopen() operation together with the RTLD_GLOBAL flag. As the
|
||||
* latter set of objects can change during execution, the set
|
||||
* identified by handle can also change dynamically.
|
||||
*
|
||||
* Only a single copy of an object file is brought into the address
|
||||
* space, even if dlopen() is invoked multiple times in reference
|
||||
* to the file, and even if different pathnames are used to
|
||||
* reference the file.
|
||||
* mode - Describes how dlopen() will operate upon file with respect to
|
||||
* the processing of relocations and the scope of visibility of the
|
||||
* symbols provided within file. When an object is brought into the
|
||||
* address space of a process, it may contain references to symbols
|
||||
* whose addresses are not known until the object is loaded. These
|
||||
* references must be relocated before the symbols can be accessed.
|
||||
* The mode parameter governs when these relocations take place.
|
||||
* See definitions above for values of the mode parameter:.
|
||||
*
|
||||
* Returned Value:
|
||||
* A successful dlopen() returns a handle which the caller may use on
|
||||
* subsequent calls to dlsym() and dlclose(). The value of this handle
|
||||
* should not be interpreted in any way by the caller.
|
||||
*
|
||||
* If file cannot be found, cannot be opened for reading, is not of an
|
||||
* appropriate object format for processing by dlopen(), or if an error
|
||||
* occurs during the process of loading file or relocating its symbolic
|
||||
* references, dlopen() will return NULL. More detailed diagnostic
|
||||
* information will be available through dlerror().
|
||||
*
|
||||
* Reference: OpenGroup.org
|
||||
*
|
||||
* **************************************************************************/
|
||||
|
||||
FAR void *dlopen(FAR const char *file, int mode);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dlsym
|
||||
*
|
||||
* Description:
|
||||
* dlsym() allows a process to obtain the address of a symbol defined
|
||||
* within an object made accessible through a dlopen() call. handle is the
|
||||
* value returned from a call to dlopen() (and which has not since been
|
||||
* released via a call to dlclose()), name is the symbol's name as a
|
||||
* character string.
|
||||
*
|
||||
* dlsym() will search for the named symbol in all objects loaded
|
||||
* automatically as a result of loading the object referenced by handle
|
||||
* (see dlopen()). Load ordering is used in dlsym() operations upon the
|
||||
* global symbol object. The symbol resolution algorithm used will be
|
||||
* dependency order as described in dlopen().
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The opaque, non-NULL value returned by a previous successful
|
||||
* call to dlopen().
|
||||
* name - A pointer to the symbol name string.
|
||||
*
|
||||
* Returned Value:
|
||||
* If handle does not refer to a valid object opened by dlopen(), or if
|
||||
* the named symbol cannot be found within any of the objects associated
|
||||
* with handle, dlsym() will return NULL. More detailed diagnostic
|
||||
* information will be available through dlerror().
|
||||
*
|
||||
* Reference: OpenGroup.org
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *dlsym(FAR void *handle, FAR const char *name);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dlclose
|
||||
*
|
||||
* Description:
|
||||
* dlclose() is used to inform the system that the object referenced by a
|
||||
* handle returned from a previous dlopen() invocation is no longer needed
|
||||
* by the application.
|
||||
*
|
||||
* The use of dlclose() reflects a statement of intent on the part of the
|
||||
* process, but does not create any requirement upon the implementation,
|
||||
* such as removal of the code or symbols referenced by handle. Once an
|
||||
* object has been closed using dlclose() an application should assume
|
||||
* that its symbols are no longer available to dlsym(). All objects loaded
|
||||
* automatically as a result of invoking dlopen() on the referenced object
|
||||
* are also closed.
|
||||
*
|
||||
* Although a dlclose() operation is not required to remove structures
|
||||
* from an address space, neither is an implementation prohibited from
|
||||
* doing so. The only restriction on such a removal is that no object will
|
||||
* be removed to which references have been relocated, until or unless all
|
||||
* such references are removed. For instance, an object that had been
|
||||
* loaded with a dlopen() operation specifying the RTLD_GLOBAL flag might
|
||||
* provide a target for dynamic relocations performed in the processing of
|
||||
* other objects - in such environments, an application may assume that no
|
||||
* relocation, once made, will be undone or remade unless the object
|
||||
* requiring the relocation has itself been removed.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The opaque, non-NULL value returned by a previous successful
|
||||
* call to dlopen().
|
||||
*
|
||||
* Returned Value:
|
||||
* If the referenced object was successfully closed, dlclose() returns 0.
|
||||
* If the object could not be closed, or if handle does not refer to an
|
||||
* open object, dlclose() returns a non-zero value. More detailed
|
||||
* diagnostic information will be available through dlerror().
|
||||
*
|
||||
* Reference: OpenGroup.org
|
||||
* *************************************************************************/
|
||||
|
||||
int dlclose(FAR void *handle);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dlerror
|
||||
*
|
||||
* Description:
|
||||
* dlerror() returns a null-terminated character string (with no trailing
|
||||
* newline) that describes the last error that occurred during dynamic
|
||||
* linking processing. If no dynamic linking errors have occurred since
|
||||
* the last invocation of dlerror(), dlerror() returns NULL. Thus,
|
||||
* invoking dlerror() a second time, immediately following a prior
|
||||
* invocation, will result in NULL being returned.
|
||||
*
|
||||
* Input Parameters:
|
||||
* If successful, dlerror() returns a null-terminated character string.
|
||||
* Otherwise, NULL is returned.
|
||||
*
|
||||
* Returned Value:
|
||||
*
|
||||
* Reference: OpenGroup.org
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR char *dlerror(void);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_DLFCN_H */
|
||||
@@ -0,0 +1,574 @@
|
||||
/****************************************************************************
|
||||
* include/dsp.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_DSP_H
|
||||
#define __INCLUDE_DSP_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Disable DEBUGASSERT macro if LIBDSP debug is not enabled */
|
||||
|
||||
#ifdef CONFIG_LIBDSP_DEBUG
|
||||
# ifndef CONFIG_DEBUG_ASSERTIONS
|
||||
# warning "Need CONFIG_DEBUG_ASSERTIONS to work properly"
|
||||
# endif
|
||||
# define LIBDSP_DEBUGASSERT(x) DEBUGASSERT(x)
|
||||
#else
|
||||
# undef LIBDSP_DEBUGASSERT
|
||||
# define LIBDSP_DEBUGASSERT(x)
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LIBDSP_PRECISION
|
||||
# define CONFIG_LIBDSP_PRECISION 0
|
||||
#endif
|
||||
|
||||
/* Phase rotation direction */
|
||||
|
||||
#define DIR_NONE (0.0f)
|
||||
#define DIR_CW (1.0f)
|
||||
#define DIR_CCW (-1.0f)
|
||||
|
||||
/* Some math constants ******************************************************/
|
||||
|
||||
#define SQRT3_BY_TWO_F (0.866025f)
|
||||
#define SQRT3_BY_THREE_F (0.57735f)
|
||||
#define ONE_BY_SQRT3_F (0.57735f)
|
||||
#define TWO_BY_SQRT3_F (1.15470f)
|
||||
|
||||
/* Some lib constants *******************************************************/
|
||||
|
||||
/* Motor electrical angle is in range 0.0 to 2*PI */
|
||||
|
||||
#define MOTOR_ANGLE_E_MAX (2.0f*M_PI_F)
|
||||
#define MOTOR_ANGLE_E_MIN (0.0f)
|
||||
#define MOTOR_ANGLE_E_RANGE (MOTOR_ANGLE_E_MAX - MOTOR_ANGLE_E_MIN)
|
||||
|
||||
/* Motor mechanical angle is in range 0.0 to 2*PI */
|
||||
|
||||
#define MOTOR_ANGLE_M_MAX (2.0f*M_PI_F)
|
||||
#define MOTOR_ANGLE_M_MIN (0.0f)
|
||||
#define MOTOR_ANGLE_M_RANGE (MOTOR_ANGLE_M_MAX - MOTOR_ANGLE_M_MIN)
|
||||
|
||||
/* Some useful macros *******************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: LP_FILTER
|
||||
*
|
||||
* Description:
|
||||
* Simple single-pole digital low pass filter:
|
||||
* Y(n) = (1-beta)*Y(n-1) + beta*X(n) = (beta * (Y(n-1) - X(n)))
|
||||
*
|
||||
* filter - (0.0 - 1.0) where 1.0 gives unfiltered values
|
||||
* filter = T * (2*PI) * f_c
|
||||
*
|
||||
* phase shift = -arctan(f_in/f_c)
|
||||
*
|
||||
* T - period at which the digital filter is being calculated
|
||||
* f_in - input frequency of the filter
|
||||
* f_c - cutoff frequency of the filter
|
||||
*
|
||||
* REFERENCE: https://www.embeddedrelated.com/showarticle/779.php
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define LP_FILTER(val, sample, filter) val -= (filter * (val - sample))
|
||||
|
||||
/****************************************************************************
|
||||
* Name: SVM3_BASE_VOLTAGE_GET
|
||||
*
|
||||
* Description:
|
||||
* Get maximum voltage for SVM3 without overmodulation
|
||||
*
|
||||
* Notes:
|
||||
* max possible phase voltage for 3-phase power inverter:
|
||||
* Vd = (2/3)*Vdc
|
||||
* max phase reference voltage according to SVM modulation diagram:
|
||||
* Vrefmax = Vd * cos(30*) = SQRT3_BY_2 * Vd
|
||||
* which give us:
|
||||
* Vrefmax = SQRT3_BY_3 * Vdc
|
||||
*
|
||||
* Vdc - bus voltage
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define SVM3_BASE_VOLTAGE_GET(vbus) (vbus * SQRT3_BY_THREE_F)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure represents phase angle.
|
||||
* Besides angle value it also stores sine and cosine values for given angle.
|
||||
*/
|
||||
|
||||
struct phase_angle_f32_s
|
||||
{
|
||||
float angle; /* Phase angle in radians <0, 2PI> */
|
||||
float sin; /* Phase angle sine */
|
||||
float cos; /* Phase angle cosine */
|
||||
};
|
||||
|
||||
typedef struct phase_angle_f32_s phase_angle_f32_t;
|
||||
|
||||
/* This structure stores motor angles and corresponding sin and cos values
|
||||
*
|
||||
* th_el = th_m * pole_pairs
|
||||
* th_m = th_el/pole_pairs
|
||||
*
|
||||
* where:
|
||||
* th_el - motor electrical angle
|
||||
* th_m - motor mechanical angle
|
||||
* pole_pairs - motor pole pairs
|
||||
*
|
||||
* NOTE: pole_pairs = poles_total/2
|
||||
*/
|
||||
|
||||
struct motor_angle_f32_s
|
||||
{
|
||||
phase_angle_f32_t angle_el; /* Electrical angle */
|
||||
float anglem; /* Mechanical angle in radians <0, 2PI> */
|
||||
float one_by_p; /* Aux variable */
|
||||
uint8_t p; /* Number of the motor pole pairs */
|
||||
int8_t i; /* Pole counter */
|
||||
};
|
||||
|
||||
/* Float number saturaton */
|
||||
|
||||
struct float_sat_f32_s
|
||||
{
|
||||
float min; /* Lower limit */
|
||||
float max; /* Upper limit */
|
||||
};
|
||||
|
||||
typedef struct float_sat_f32_s float_sat_f32_t;
|
||||
|
||||
/* PI/PID controller state structure */
|
||||
|
||||
struct pid_controller_f32_s
|
||||
{
|
||||
bool aw_en; /* Integral part decay if saturated */
|
||||
bool ireset_en; /* Intergral part reset if saturated */
|
||||
bool pisat_en; /* PI saturation enabled */
|
||||
bool pidsat_en; /* PID saturation enabled */
|
||||
bool _res; /* Reserved */
|
||||
float out; /* Controller output */
|
||||
float_sat_f32_t sat; /* Output saturation */
|
||||
float err; /* Current error value */
|
||||
float err_prev; /* Previous error value */
|
||||
float KP; /* Proportional coefficient */
|
||||
float KI; /* Integral coefficient */
|
||||
float KD; /* Derivative coefficient */
|
||||
float part[3]; /* 0 - proporitonal part
|
||||
* 1 - integral part
|
||||
* 2 - derivative part
|
||||
*/
|
||||
float KC; /* Integral anti-windup decay coefficient */
|
||||
float aw; /* Integral anti-windup decay part */
|
||||
};
|
||||
|
||||
typedef struct pid_controller_f32_s pid_controller_f32_t;
|
||||
|
||||
/* This structure represents the ABC frame (3 phase vector) */
|
||||
|
||||
struct abc_frame_f32_s
|
||||
{
|
||||
float a; /* A component */
|
||||
float b; /* B component */
|
||||
float c; /* C component */
|
||||
};
|
||||
|
||||
typedef struct abc_frame_f32_s abc_frame_f32_t;
|
||||
|
||||
/* This structure represents the alpha-beta frame (2 phase vector) */
|
||||
|
||||
struct ab_frame_f32_s
|
||||
{
|
||||
float a; /* Alpha component */
|
||||
float b; /* Beta component */
|
||||
};
|
||||
|
||||
typedef struct ab_frame_f32_s ab_frame_f32_t;
|
||||
|
||||
/* This structure represent the direct-quadrature frame */
|
||||
|
||||
struct dq_frame_f32_s
|
||||
{
|
||||
float d; /* Driect component */
|
||||
float q; /* Quadrature component */
|
||||
};
|
||||
|
||||
typedef struct dq_frame_f32_s dq_frame_f32_t;
|
||||
|
||||
/* Space Vector Modulation data for 3-phase system */
|
||||
|
||||
struct svm3_state_f32_s
|
||||
{
|
||||
uint8_t sector; /* Current space vector sector */
|
||||
float d_u; /* Duty cycle for phase U */
|
||||
float d_v; /* Duty cycle for phase V */
|
||||
float d_w; /* Duty cycle for phase W */
|
||||
};
|
||||
|
||||
/* Motor open-loop control data */
|
||||
|
||||
struct openloop_data_f32_s
|
||||
{
|
||||
float angle; /* Open-loop current angle normalized to <0.0, 2PI> */
|
||||
float per; /* Open-loop control execution period */
|
||||
};
|
||||
|
||||
/* Common motor observer structure */
|
||||
|
||||
struct motor_observer_f32_s
|
||||
{
|
||||
float angle; /* Estimated observer angle */
|
||||
float speed; /* Estimated observer speed */
|
||||
float per; /* Observer execution period */
|
||||
|
||||
float angle_err; /* Observer angle error.
|
||||
* This can be used to gradually eliminate
|
||||
* error between openloop angle and observer
|
||||
* angle
|
||||
*/
|
||||
|
||||
/* There are different types of motor observers which different
|
||||
* sets of private data.
|
||||
*/
|
||||
|
||||
void *so; /* Speed estimation observer data */
|
||||
void *ao; /* Angle estimation observer data */
|
||||
};
|
||||
|
||||
/* Speed observer division method data */
|
||||
|
||||
struct motor_sobserver_div_f32_s
|
||||
{
|
||||
float angle_diff; /* Mechanical angle difference */
|
||||
float angle_acc; /* Accumulated mechanical angle */
|
||||
float angle_prev; /* Previous mechanical angle */
|
||||
float one_by_dt; /* Frequency of observer execution */
|
||||
float cntr; /* Sample counter */
|
||||
float samples; /* Number of samples for observer */
|
||||
float filter; /* Low-pass filter for final omega */
|
||||
};
|
||||
|
||||
/* Speed observer PLL method data */
|
||||
#if 0
|
||||
struct motor_sobserver_pll_f32_s
|
||||
{
|
||||
/* TODO */
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Motor Sliding Mode Observer private data */
|
||||
|
||||
struct motor_observer_smo_f32_s
|
||||
{
|
||||
float k_slide; /* Bang-bang controller gain */
|
||||
float err_max; /* Linear mode threshold */
|
||||
float one_by_err_max; /* One by err_max */
|
||||
float F; /* Current observer F gain (1-Ts*R/L) */
|
||||
float G; /* Current observer G gain (Ts/L) */
|
||||
float emf_lp_filter1; /* Adaptive first low pass EMF filter */
|
||||
float emf_lp_filter2; /* Adaptive second low pass EMF filter */
|
||||
ab_frame_f32_t emf; /* Estimated back-EMF */
|
||||
ab_frame_f32_t emf_f; /* Fitlered estimated back-EMF */
|
||||
ab_frame_f32_t z; /* Correction factor */
|
||||
ab_frame_f32_t i_est; /* Estimated idq current */
|
||||
ab_frame_f32_t v_err; /* v_err = v_ab - emf */
|
||||
ab_frame_f32_t i_err; /* i_err = i_est - i_dq */
|
||||
ab_frame_f32_t sign; /* Bang-bang controller sign */
|
||||
};
|
||||
|
||||
/* FOC initialize data */
|
||||
|
||||
struct foc_initdata_f32_s
|
||||
{
|
||||
float id_kp; /* KP for d current */
|
||||
float id_ki; /* KI for d current */
|
||||
float iq_kp; /* KP for q current */
|
||||
float iq_ki; /* KI for q current */
|
||||
};
|
||||
|
||||
/* Field Oriented Control (FOC) data */
|
||||
|
||||
struct foc_data_f32_s
|
||||
{
|
||||
abc_frame_f32_t v_abc; /* Voltage in ABC frame */
|
||||
ab_frame_f32_t v_ab; /* Voltage in alpha-beta frame */
|
||||
dq_frame_f32_t v_dq; /* Requested voltage in dq frame */
|
||||
ab_frame_f32_t v_ab_mod; /* Modulation voltage normalized to
|
||||
* magnitude (0.0, 1.0)
|
||||
*/
|
||||
|
||||
abc_frame_f32_t i_abc; /* Current in ABC frame */
|
||||
ab_frame_f32_t i_ab; /* Current in alpha-beta frame */
|
||||
dq_frame_f32_t i_dq; /* Current in dq frame */
|
||||
dq_frame_f32_t i_dq_err; /* DQ current error */
|
||||
|
||||
dq_frame_f32_t i_dq_ref; /* Requested current for the FOC
|
||||
* current controler
|
||||
*/
|
||||
|
||||
pid_controller_f32_t id_pid; /* Current d-axis component PI controller */
|
||||
pid_controller_f32_t iq_pid; /* Current q-axis component PI controller */
|
||||
|
||||
float vdq_mag_max; /* Maximum dq voltage magnitude */
|
||||
float vab_mod_scale; /* Voltage alpha-beta modulation scale */
|
||||
|
||||
phase_angle_f32_t angle; /* Phase angle */
|
||||
};
|
||||
|
||||
/* Motor physical parameters.
|
||||
* This data structure was designed to work with BLDC/PMSM motors,
|
||||
* but probably can be used to describe different types of motors.
|
||||
*/
|
||||
|
||||
struct motor_phy_params_f32_s
|
||||
{
|
||||
uint8_t p; /* Number of the motor pole pairs */
|
||||
float res; /* Phase-to-neutral resistance */
|
||||
float ind; /* Average phase-to-neutral inductance */
|
||||
float one_by_ind; /* Inverse phase-to-neutral inductance */
|
||||
};
|
||||
|
||||
/* PMSM motor physcial parameters */
|
||||
|
||||
struct pmsm_phy_params_f32_s
|
||||
{
|
||||
struct motor_phy_params_f32_s motor; /* Motor common PHY */
|
||||
float iner; /* Rotor inertia */
|
||||
float flux_link; /* Flux linkage */
|
||||
float ind_d; /* d-inductance */
|
||||
float ind_q; /* q-inductance */
|
||||
float one_by_iner; /* One by intertia */
|
||||
float one_by_indd; /* One by Ld */
|
||||
float one_by_indq; /* One by Lq */
|
||||
};
|
||||
|
||||
/* PMSM motor model state */
|
||||
|
||||
struct pmsm_model_state_f32_s
|
||||
{
|
||||
/* Motor model phase current */
|
||||
|
||||
abc_frame_f32_t i_abc;
|
||||
ab_frame_f32_t i_ab;
|
||||
dq_frame_f32_t i_dq;
|
||||
|
||||
/* Motor model phase voltage */
|
||||
|
||||
abc_frame_f32_t v_abc;
|
||||
ab_frame_f32_t v_ab;
|
||||
dq_frame_f32_t v_dq;
|
||||
|
||||
/* Motor model angle */
|
||||
|
||||
struct motor_angle_f32_s angle;
|
||||
|
||||
/* Angular speed */
|
||||
|
||||
float omega_e;
|
||||
float omega_m;
|
||||
};
|
||||
|
||||
/* PMSM motor model external conditions */
|
||||
|
||||
struct pmsm_model_ext_f32_s
|
||||
{
|
||||
float load; /* Motor model load torque */
|
||||
};
|
||||
|
||||
/* PMSM motor model */
|
||||
|
||||
struct pmsm_model_f32_s
|
||||
{
|
||||
struct pmsm_phy_params_f32_s phy; /* Motor model physical parameters */
|
||||
struct pmsm_model_state_f32_s state; /* Motor model state */
|
||||
struct pmsm_model_ext_f32_s ext; /* Motor model external conditions */
|
||||
float per; /* Control period */
|
||||
float id_int; /* Id integral part */
|
||||
float iq_int; /* Iq integral part */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* Math functions */
|
||||
|
||||
float fast_sin(float angle);
|
||||
float fast_sin2(float angle);
|
||||
float fast_cos(float angle);
|
||||
float fast_cos2(float angle);
|
||||
float fast_atan2(float y, float x);
|
||||
|
||||
void f_saturate(FAR float *val, float min, float max);
|
||||
|
||||
float vector2d_mag(float x, float y);
|
||||
void vector2d_saturate(FAR float *x, FAR float *y, float max);
|
||||
|
||||
void dq_saturate(FAR dq_frame_f32_t *dq, float max);
|
||||
float dq_mag(FAR dq_frame_f32_t *dq);
|
||||
|
||||
/* PID controller functions */
|
||||
|
||||
void pid_controller_init(FAR pid_controller_f32_t *pid,
|
||||
float KP, float KI, float KD);
|
||||
void pi_controller_init(FAR pid_controller_f32_t *pid,
|
||||
float KP, float KI);
|
||||
void pid_saturation_set(FAR pid_controller_f32_t *pid, float min, float max);
|
||||
void pi_saturation_set(FAR pid_controller_f32_t *pid, float min, float max);
|
||||
void pid_integral_reset(FAR pid_controller_f32_t *pid);
|
||||
void pi_integral_reset(FAR pid_controller_f32_t *pid);
|
||||
float pi_controller(FAR pid_controller_f32_t *pid, float err);
|
||||
float pid_controller(FAR pid_controller_f32_t *pid, float err);
|
||||
void pi_antiwindup_enable(FAR pid_controller_f32_t *pid, float KC,
|
||||
bool enable);
|
||||
void pi_ireset_enable(FAR pid_controller_f32_t *pid, bool enable);
|
||||
|
||||
/* Transformation functions */
|
||||
|
||||
void clarke_transform(FAR abc_frame_f32_t *abc, FAR ab_frame_f32_t *ab);
|
||||
void inv_clarke_transform(FAR ab_frame_f32_t *ab, FAR abc_frame_f32_t *abc);
|
||||
void park_transform(FAR phase_angle_f32_t *angle, FAR ab_frame_f32_t *ab,
|
||||
FAR dq_frame_f32_t *dq);
|
||||
void inv_park_transform(FAR phase_angle_f32_t *angle, FAR dq_frame_f32_t *dq,
|
||||
FAR ab_frame_f32_t *ab);
|
||||
|
||||
/* Phase angle related functions */
|
||||
|
||||
void angle_norm(FAR float *angle, float per, float bottom, float top);
|
||||
void angle_norm_2pi(FAR float *angle, float bottom, float top);
|
||||
void phase_angle_update(FAR struct phase_angle_f32_s *angle, float val);
|
||||
|
||||
/* 3-phase system space vector modulation */
|
||||
|
||||
void svm3_init(FAR struct svm3_state_f32_s *s);
|
||||
void svm3(FAR struct svm3_state_f32_s *s, FAR ab_frame_f32_t *ab);
|
||||
void svm3_current_correct(FAR struct svm3_state_f32_s *s,
|
||||
float *c0, float *c1, float *c2);
|
||||
|
||||
/* Field Oriented Control */
|
||||
|
||||
void foc_init(FAR struct foc_data_f32_s *foc,
|
||||
FAR struct foc_initdata_f32_s *init);
|
||||
void foc_vbase_update(FAR struct foc_data_f32_s *foc, float vbase);
|
||||
void foc_angle_update(FAR struct foc_data_f32_s *foc,
|
||||
FAR phase_angle_f32_t *angle);
|
||||
void foc_iabc_update(FAR struct foc_data_f32_s *foc,
|
||||
FAR abc_frame_f32_t *i_abc);
|
||||
void foc_voltage_control(FAR struct foc_data_f32_s *foc,
|
||||
FAR dq_frame_f32_t *vdq_ref);
|
||||
void foc_current_control(FAR struct foc_data_f32_s *foc,
|
||||
FAR dq_frame_f32_t *idq_ref,
|
||||
FAR dq_frame_f32_t *vdq_comp,
|
||||
FAR dq_frame_f32_t *v_dq_ref);
|
||||
void foc_vabmod_get(FAR struct foc_data_f32_s *foc,
|
||||
FAR ab_frame_f32_t *v_ab_mod);
|
||||
void foc_vdq_mag_max_get(FAR struct foc_data_f32_s *foc, FAR float *max);
|
||||
|
||||
/* BLDC/PMSM motor observers */
|
||||
|
||||
void motor_observer_init(FAR struct motor_observer_f32_s *observer,
|
||||
FAR void *ao, FAR void *so, float per);
|
||||
float motor_observer_speed_get(FAR struct motor_observer_f32_s *o);
|
||||
float motor_observer_angle_get(FAR struct motor_observer_f32_s *o);
|
||||
|
||||
void motor_observer_smo_init(FAR struct motor_observer_smo_f32_s *smo,
|
||||
float kslide, float err_max);
|
||||
void motor_observer_smo(FAR struct motor_observer_f32_s *o,
|
||||
FAR ab_frame_f32_t *i_ab, FAR ab_frame_f32_t *v_ab,
|
||||
FAR struct motor_phy_params_f32_s *phy, float dir);
|
||||
|
||||
void motor_sobserver_div_init(FAR struct motor_sobserver_div_f32_s *so,
|
||||
uint8_t samples, float filer, float per);
|
||||
void motor_sobserver_div(FAR struct motor_observer_f32_s *o,
|
||||
float angle, float dir);
|
||||
|
||||
/* Motor openloop control */
|
||||
|
||||
void motor_openloop_init(FAR struct openloop_data_f32_s *op, float per);
|
||||
void motor_openloop(FAR struct openloop_data_f32_s *op, float speed,
|
||||
float dir);
|
||||
float motor_openloop_angle_get(FAR struct openloop_data_f32_s *op);
|
||||
|
||||
/* Motor angle */
|
||||
|
||||
void motor_angle_init(FAR struct motor_angle_f32_s *angle, uint8_t p);
|
||||
void motor_angle_e_update(FAR struct motor_angle_f32_s *angle,
|
||||
float angle_new, float dir);
|
||||
void motor_angle_m_update(FAR struct motor_angle_f32_s *angle,
|
||||
float angle_new, float dir);
|
||||
float motor_angle_m_get(FAR struct motor_angle_f32_s *angle);
|
||||
float motor_angle_e_get(FAR struct motor_angle_f32_s *angle);
|
||||
|
||||
/* Motor physical parameters */
|
||||
|
||||
void motor_phy_params_init(FAR struct motor_phy_params_f32_s *phy,
|
||||
uint8_t poles, float res, float ind);
|
||||
|
||||
/* PMSM physical parameters functions */
|
||||
|
||||
void pmsm_phy_params_init(FAR struct pmsm_phy_params_f32_s *phy,
|
||||
uint8_t poles, float res, float ind,
|
||||
float iner, float flux,
|
||||
float ind_d, float ind_q);
|
||||
|
||||
/* PMSM motor model */
|
||||
|
||||
int pmsm_model_initialize(FAR struct pmsm_model_f32_s *model,
|
||||
FAR struct pmsm_phy_params_f32_s *phy,
|
||||
float per);
|
||||
int pmsm_model_elec(FAR struct pmsm_model_f32_s *model,
|
||||
FAR ab_frame_f32_t *vab);
|
||||
int pmsm_model_mech(FAR struct pmsm_model_f32_s *model, float load);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_DSP_H */
|
||||
@@ -0,0 +1,495 @@
|
||||
/****************************************************************************
|
||||
* include/dspb16.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_DSPB16_H
|
||||
#define __INCLUDE_DSPB16_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <fixedmath.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Disable DEBUGASSERT macro if LIBDSP debug is not enabled */
|
||||
|
||||
#ifdef CONFIG_LIBDSP_DEBUG
|
||||
# ifndef CONFIG_DEBUG_ASSERTIONS
|
||||
# warning "Need CONFIG_DEBUG_ASSERTIONS to work properly"
|
||||
# endif
|
||||
# define LIBDSP_DEBUGASSERT(x) DEBUGASSERT(x)
|
||||
#else
|
||||
# undef LIBDSP_DEBUGASSERT
|
||||
# define LIBDSP_DEBUGASSERT(x)
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LIBDSP_PRECISION
|
||||
# define CONFIG_LIBDSP_PRECISION 0
|
||||
#endif
|
||||
|
||||
/* Phase rotation direction */
|
||||
|
||||
#define DIR_NONE_B16 ftob16(0.0f)
|
||||
#define DIR_CW_B16 ftob16(1.0f)
|
||||
#define DIR_CCW_B16 ftob16(-1.0f)
|
||||
|
||||
/* Some math constants ******************************************************/
|
||||
|
||||
#define SQRT3_BY_TWO_B16 ftob16(0.866025f)
|
||||
#define SQRT3_BY_THREE_B16 ftob16(0.57735f)
|
||||
#define ONE_BY_SQRT3_B16 ftob16(0.57735f)
|
||||
#define TWO_BY_SQRT3_B16 ftob16(1.15470f)
|
||||
|
||||
/* Some lib constants *******************************************************/
|
||||
|
||||
/* Motor electrical angle is in range 0.0 to 2*PI */
|
||||
|
||||
#define MOTOR_ANGLE_E_MAX_B16 (b16TWOPI)
|
||||
#define MOTOR_ANGLE_E_MIN_B16 (0)
|
||||
#define MOTOR_ANGLE_E_RANGE_B16 (MOTOR_ANGLE_E_MAX_B16 - MOTOR_ANGLE_E_MIN_B16)
|
||||
|
||||
/* Motor mechanical angle is in range 0.0 to 2*PI */
|
||||
|
||||
#define MOTOR_ANGLE_M_MAX_B16 (b16TWOPI)
|
||||
#define MOTOR_ANGLE_M_MIN_B16 (0)
|
||||
#define MOTOR_ANGLE_M_RANGE_B16 (MOTOR_ANGLE_M_MAX_B16 - MOTOR_ANGLE_M_MIN_B16)
|
||||
|
||||
/* Some useful macros *******************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: LP_FILTER_B16
|
||||
*
|
||||
* Description:
|
||||
* Simple single-pole digital low pass filter:
|
||||
* Y(n) = (1-beta)*Y(n-1) + beta*X(n) = (beta * (Y(n-1) - X(n)))
|
||||
*
|
||||
* filter - (0.0 - 1.0) where 1.0 gives unfiltered values
|
||||
* filter = T * (2*PI) * f_c
|
||||
*
|
||||
* phase shift = -arctan(f_in/f_c)
|
||||
*
|
||||
* T - period at which the digital filter is being calculated
|
||||
* f_in - input frequency of the filter
|
||||
* f_c - cutoff frequency of the filter
|
||||
*
|
||||
* REFERENCE: https://www.embeddedrelated.com/showarticle/779.php
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define LP_FILTER_B16(val, sample, filter) val -= (b16mulb16(filter, (val - sample)))
|
||||
|
||||
/****************************************************************************
|
||||
* Name: SVM3_BASE_VOLTAGE_GET_B16
|
||||
*
|
||||
* Description:
|
||||
* Get maximum voltage for SVM3 without overmodulation
|
||||
*
|
||||
* Notes:
|
||||
* max possible phase voltage for 3-phase power inverter:
|
||||
* Vd = (2/3)*Vdc
|
||||
* max phase reference voltage according to SVM modulation diagram:
|
||||
* Vrefmax = Vd * cos(30*) = SQRT3_BY_2 * Vd
|
||||
* which give us:
|
||||
* Vrefmax = SQRT3_BY_3 * Vdc
|
||||
*
|
||||
* Vdc - bus voltage
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define SVM3_BASE_VOLTAGE_GET_B16(vbus) (b16mulb16(vbus, SQRT3_BY_THREE_B16))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure represents phase angle.
|
||||
* Besides angle value it also stores sine and cosine values for given angle.
|
||||
*/
|
||||
|
||||
struct phase_angle_b16_s
|
||||
{
|
||||
b16_t angle; /* Phase angle in radians <0, 2PI> */
|
||||
b16_t sin; /* Phase angle sine */
|
||||
b16_t cos; /* Phase angle cosine */
|
||||
};
|
||||
|
||||
typedef struct phase_angle_b16_s phase_angle_b16_t;
|
||||
|
||||
/* This structure stores motor angles and corresponding sin and cos values
|
||||
*
|
||||
* th_el = th_m * pole_pairs
|
||||
* th_m = th_el/pole_pairs
|
||||
*
|
||||
* where:
|
||||
* th_el - motor electrical angle
|
||||
* th_m - motor mechanical angle
|
||||
* pole_pairs - motor pole pairs
|
||||
*
|
||||
* NOTE: pole_pairs = poles_total/2
|
||||
*/
|
||||
|
||||
struct motor_angle_b16_s
|
||||
{
|
||||
phase_angle_b16_t angle_el; /* Electrical angle */
|
||||
b16_t anglem; /* Mechanical angle in radians <0, 2PI> */
|
||||
b16_t one_by_p; /* Aux variable */
|
||||
uint8_t p; /* Number of the motor pole pairs */
|
||||
int8_t i; /* Pole counter */
|
||||
};
|
||||
|
||||
/* Float number saturaton */
|
||||
|
||||
struct float_sat_b16_s
|
||||
{
|
||||
b16_t min; /* Lower limit */
|
||||
b16_t max; /* Upper limit */
|
||||
};
|
||||
|
||||
typedef struct float_sat_b16_s float_sat_b16_t;
|
||||
|
||||
/* PI/PID controller state structure */
|
||||
|
||||
struct pid_controller_b16_s
|
||||
{
|
||||
bool aw_en; /* Integral part decay if saturated */
|
||||
bool ireset_en; /* Intergral part reset if saturated */
|
||||
bool pisat_en; /* PI saturation enabled */
|
||||
bool pidsat_en; /* PID saturation enabled */
|
||||
bool _res; /* Reserved */
|
||||
b16_t out; /* Controller output */
|
||||
float_sat_b16_t sat; /* Output saturation */
|
||||
b16_t err; /* Current error value */
|
||||
b16_t err_prev; /* Previous error value */
|
||||
b16_t KP; /* Proportional coefficient */
|
||||
b16_t KI; /* Integral coefficient */
|
||||
b16_t KD; /* Derivative coefficient */
|
||||
b16_t part[3]; /* 0 - proporitonal part
|
||||
* 1 - integral part
|
||||
* 2 - derivative part
|
||||
*/
|
||||
b16_t KC; /* Integral anti-windup decay coefficient */
|
||||
b16_t aw; /* Integral anti-windup decay part */
|
||||
};
|
||||
|
||||
typedef struct pid_controller_b16_s pid_controller_b16_t;
|
||||
|
||||
/* This structure represents the ABC frame (3 phase vector) */
|
||||
|
||||
struct abc_frame_b16_s
|
||||
{
|
||||
b16_t a; /* A component */
|
||||
b16_t b; /* B component */
|
||||
b16_t c; /* C component */
|
||||
};
|
||||
|
||||
typedef struct abc_frame_b16_s abc_frame_b16_t;
|
||||
|
||||
/* This structure represents the alpha-beta frame (2 phase vector) */
|
||||
|
||||
struct ab_frame_b16_s
|
||||
{
|
||||
b16_t a; /* Alpha component */
|
||||
b16_t b; /* Beta component */
|
||||
};
|
||||
|
||||
typedef struct ab_frame_b16_s ab_frame_b16_t;
|
||||
|
||||
/* This structure represent the direct-quadrature frame */
|
||||
|
||||
struct dq_frame_b16_s
|
||||
{
|
||||
b16_t d; /* Driect component */
|
||||
b16_t q; /* Quadrature component */
|
||||
};
|
||||
|
||||
typedef struct dq_frame_b16_s dq_frame_b16_t;
|
||||
|
||||
/* Space Vector Modulation data for 3-phase system */
|
||||
|
||||
struct svm3_state_b16_s
|
||||
{
|
||||
uint8_t sector; /* Current space vector sector */
|
||||
b16_t d_u; /* Duty cycle for phase U */
|
||||
b16_t d_v; /* Duty cycle for phase V */
|
||||
b16_t d_w; /* Duty cycle for phase W */
|
||||
};
|
||||
|
||||
/* Motor open-loop control data */
|
||||
|
||||
struct openloop_data_b16_s
|
||||
{
|
||||
b16_t angle; /* Open-loop current angle normalized to <0.0, 2PI> */
|
||||
b16_t per; /* Open-loop control execution period */
|
||||
};
|
||||
|
||||
/* FOC initialize data */
|
||||
|
||||
struct foc_initdata_b16_s
|
||||
{
|
||||
b16_t id_kp; /* KP for d current */
|
||||
b16_t id_ki; /* KI for d current */
|
||||
b16_t iq_kp; /* KP for q current */
|
||||
b16_t iq_ki; /* KI for q current */
|
||||
};
|
||||
|
||||
/* Field Oriented Control (FOC) data */
|
||||
|
||||
struct foc_data_b16_s
|
||||
{
|
||||
abc_frame_b16_t v_abc; /* Voltage in ABC frame */
|
||||
ab_frame_b16_t v_ab; /* Voltage in alpha-beta frame */
|
||||
dq_frame_b16_t v_dq; /* Requested voltage in dq frame */
|
||||
ab_frame_b16_t v_ab_mod; /* Modulation voltage normalized to
|
||||
* magnitude (0.0, 1.0)
|
||||
*/
|
||||
|
||||
abc_frame_b16_t i_abc; /* Current in ABC frame */
|
||||
ab_frame_b16_t i_ab; /* Current in alpha-beta frame */
|
||||
dq_frame_b16_t i_dq; /* Current in dq frame */
|
||||
dq_frame_b16_t i_dq_err; /* DQ current error */
|
||||
|
||||
dq_frame_b16_t i_dq_ref; /* Requested current for the FOC
|
||||
* current controler
|
||||
*/
|
||||
|
||||
pid_controller_b16_t id_pid; /* Current d-axis component PI controller */
|
||||
pid_controller_b16_t iq_pid; /* Current q-axis component PI controller */
|
||||
|
||||
b16_t vdq_mag_max; /* Maximum dq voltage magnitude */
|
||||
b16_t vab_mod_scale; /* Voltage alpha-beta modulation scale */
|
||||
|
||||
phase_angle_b16_t angle; /* Phase angle */
|
||||
};
|
||||
|
||||
/* Motor physical parameters.
|
||||
* This data structure was designed to work with BLDC/PMSM motors,
|
||||
* but probably can be used to describe different types of motors.
|
||||
*/
|
||||
|
||||
struct motor_phy_params_b16_s
|
||||
{
|
||||
uint8_t p; /* Number of the motor pole pairs */
|
||||
b16_t res; /* Phase-to-neutral temperature compensated
|
||||
* resistance
|
||||
*/
|
||||
b16_t ind; /* Average phase-to-neutral inductance */
|
||||
b16_t one_by_ind; /* Inverse phase-to-neutral inductance */
|
||||
};
|
||||
|
||||
/* PMSM motor physcial parameters */
|
||||
|
||||
struct pmsm_phy_params_b16_s
|
||||
{
|
||||
struct motor_phy_params_b16_s motor; /* Motor common PHY */
|
||||
b16_t iner; /* Rotor inertia */
|
||||
b16_t flux_link; /* Flux linkage */
|
||||
b16_t ind_d; /* d-inductance */
|
||||
b16_t ind_q; /* q-inductance */
|
||||
b16_t one_by_iner; /* One by J */
|
||||
b16_t one_by_indd; /* One by Ld */
|
||||
b16_t one_by_indq; /* One by Lq */
|
||||
};
|
||||
|
||||
/* PMSM motor model state */
|
||||
|
||||
struct pmsm_model_state_b16_s
|
||||
{
|
||||
/* Motor model phase current */
|
||||
|
||||
abc_frame_b16_t i_abc;
|
||||
ab_frame_b16_t i_ab;
|
||||
dq_frame_b16_t i_dq;
|
||||
|
||||
/* Motor model phase voltage */
|
||||
|
||||
abc_frame_b16_t v_abc;
|
||||
ab_frame_b16_t v_ab;
|
||||
dq_frame_b16_t v_dq;
|
||||
|
||||
/* Motor model angle */
|
||||
|
||||
struct motor_angle_b16_s angle;
|
||||
|
||||
/* Angular speed */
|
||||
|
||||
b16_t omega_e;
|
||||
b16_t omega_m;
|
||||
};
|
||||
|
||||
/* PMSM motor model external conditions */
|
||||
|
||||
struct pmsm_model_ext_b16_s
|
||||
{
|
||||
b16_t load; /* Motor model load torque */
|
||||
};
|
||||
|
||||
/* PMSM motor model */
|
||||
|
||||
struct pmsm_model_b16_s
|
||||
{
|
||||
struct pmsm_phy_params_b16_s phy; /* Motor model physical parameters */
|
||||
struct pmsm_model_state_b16_s state; /* Motor model state */
|
||||
struct pmsm_model_ext_b16_s ext; /* Motor model external conditions */
|
||||
b16_t per; /* Control period */
|
||||
b16_t id_int; /* Id integral part */
|
||||
b16_t iq_int; /* Iq integral part */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* Math functions */
|
||||
|
||||
b16_t fast_sin_b16(b16_t angle);
|
||||
b16_t fast_sin2_b16(b16_t angle);
|
||||
b16_t fast_cos_b16(b16_t angle);
|
||||
b16_t fast_cos2_b16(b16_t angle);
|
||||
b16_t fast_atan2_b16(b16_t y, b16_t x);
|
||||
void f_saturate_b16(FAR b16_t *val, b16_t min, b16_t max);
|
||||
b16_t vector2d_mag_b16(b16_t x, b16_t y);
|
||||
void vector2d_saturate_b16(FAR b16_t *x, FAR b16_t *y, b16_t max);
|
||||
void dq_saturate_b16(FAR dq_frame_b16_t *dq, b16_t max);
|
||||
b16_t dq_mag_b16(FAR dq_frame_b16_t *dq);
|
||||
|
||||
/* PID controller functions */
|
||||
|
||||
void pid_controller_init_b16(FAR pid_controller_b16_t *pid,
|
||||
b16_t KP, b16_t KI, b16_t KD);
|
||||
void pi_controller_init_b16(FAR pid_controller_b16_t *pid,
|
||||
b16_t KP, b16_t KI);
|
||||
void pid_saturation_set_b16(FAR pid_controller_b16_t *pid, b16_t min,
|
||||
b16_t max);
|
||||
void pi_saturation_set_b16(FAR pid_controller_b16_t *pid, b16_t min,
|
||||
b16_t max);
|
||||
void pid_integral_reset_b16(FAR pid_controller_b16_t *pid);
|
||||
void pi_integral_reset_b16(FAR pid_controller_b16_t *pid);
|
||||
b16_t pi_controller_b16(FAR pid_controller_b16_t *pid, b16_t err);
|
||||
b16_t pid_controller_b16(FAR pid_controller_b16_t *pid, b16_t err);
|
||||
void pi_antiwindup_enable_b16(FAR pid_controller_b16_t *pid, b16_t KC,
|
||||
bool enable);
|
||||
void pi_ireset_enable_b16(FAR pid_controller_b16_t *pid, bool enable);
|
||||
|
||||
/* Transformation functions */
|
||||
|
||||
void clarke_transform_b16(FAR abc_frame_b16_t *abc, FAR ab_frame_b16_t *ab);
|
||||
void inv_clarke_transform_b16(FAR ab_frame_b16_t *ab,
|
||||
FAR abc_frame_b16_t *abc);
|
||||
void park_transform_b16(FAR phase_angle_b16_t *angle, FAR ab_frame_b16_t *ab,
|
||||
FAR dq_frame_b16_t *dq);
|
||||
void inv_park_transform_b16(FAR phase_angle_b16_t *angle,
|
||||
FAR dq_frame_b16_t *dq, FAR ab_frame_b16_t *ab);
|
||||
|
||||
/* Phase angle related functions */
|
||||
|
||||
void angle_norm_b16(FAR b16_t *angle, b16_t per, b16_t bottom, b16_t top);
|
||||
void angle_norm_2pi_b16(FAR b16_t *angle, b16_t bottom, b16_t top);
|
||||
void phase_angle_update_b16(FAR struct phase_angle_b16_s *angle, b16_t val);
|
||||
|
||||
/* 3-phase system space vector modulation */
|
||||
|
||||
void svm3_init_b16(FAR struct svm3_state_b16_s *s);
|
||||
void svm3_b16(FAR struct svm3_state_b16_s *s, FAR ab_frame_b16_t *ab);
|
||||
void svm3_current_correct_b16(FAR struct svm3_state_b16_s *s,
|
||||
b16_t *c0, b16_t *c1, b16_t *c2);
|
||||
|
||||
/* Field Oriented Control */
|
||||
|
||||
void foc_init_b16(FAR struct foc_data_b16_s *foc,
|
||||
FAR struct foc_initdata_b16_s *init);
|
||||
void foc_vbase_update_b16(FAR struct foc_data_b16_s *foc, b16_t vbase);
|
||||
void foc_angle_update_b16(FAR struct foc_data_b16_s *foc,
|
||||
FAR phase_angle_b16_t *angle);
|
||||
void foc_iabc_update_b16(FAR struct foc_data_b16_s *foc,
|
||||
FAR abc_frame_b16_t *i_abc);
|
||||
void foc_voltage_control_b16(FAR struct foc_data_b16_s *foc,
|
||||
FAR dq_frame_b16_t *vdq_ref);
|
||||
void foc_current_control_b16(FAR struct foc_data_b16_s *foc,
|
||||
FAR dq_frame_b16_t *idq_ref,
|
||||
FAR dq_frame_b16_t *vdq_comp,
|
||||
FAR dq_frame_b16_t *v_dq_ref);
|
||||
void foc_vabmod_get_b16(FAR struct foc_data_b16_s *foc,
|
||||
FAR ab_frame_b16_t *v_ab_mod);
|
||||
void foc_vdq_mag_max_get_b16(FAR struct foc_data_b16_s *foc, FAR b16_t *max);
|
||||
|
||||
/* Motor openloop control */
|
||||
|
||||
void motor_openloop_init_b16(FAR struct openloop_data_b16_s *op, b16_t per);
|
||||
void motor_openloop_b16(FAR struct openloop_data_b16_s *op, b16_t speed,
|
||||
b16_t dir);
|
||||
b16_t motor_openloop_angle_get_b16(FAR struct openloop_data_b16_s *op);
|
||||
|
||||
/* Motor angle */
|
||||
|
||||
void motor_angle_init_b16(FAR struct motor_angle_b16_s *angle, uint8_t p);
|
||||
void motor_angle_e_update_b16(FAR struct motor_angle_b16_s *angle,
|
||||
b16_t angle_new, b16_t dir);
|
||||
void motor_angle_m_update_b16(FAR struct motor_angle_b16_s *angle,
|
||||
b16_t angle_new, b16_t dir);
|
||||
b16_t motor_angle_m_get_b16(FAR struct motor_angle_b16_s *angle);
|
||||
b16_t motor_angle_e_get_b16(FAR struct motor_angle_b16_s *angle);
|
||||
|
||||
/* Motor physical parameters */
|
||||
|
||||
void motor_phy_params_init_b16(FAR struct motor_phy_params_b16_s *phy,
|
||||
uint8_t poles, b16_t res, b16_t ind);
|
||||
|
||||
/* PMSM physical parameters functions */
|
||||
|
||||
void pmsm_phy_params_init_b16(FAR struct pmsm_phy_params_b16_s *phy,
|
||||
uint8_t poles, b16_t res, b16_t ind,
|
||||
b16_t iner, b16_t flux,
|
||||
b16_t ind_d, b16_t ind_q);
|
||||
|
||||
/* PMSM motor model */
|
||||
|
||||
int pmsm_model_initialize_b16(FAR struct pmsm_model_b16_s *model,
|
||||
FAR struct pmsm_phy_params_b16_s *phy,
|
||||
b16_t per);
|
||||
int pmsm_model_elec_b16(FAR struct pmsm_model_b16_s *model,
|
||||
FAR ab_frame_b16_t *vab);
|
||||
int pmsm_model_mech_b16(FAR struct pmsm_model_b16_s *model, b16_t load);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_DSPB16_H */
|
||||
@@ -0,0 +1,226 @@
|
||||
/****************************************************************************
|
||||
* include/elf.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_ELF_H
|
||||
#define __INCLUDE_ELF_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define EI_NIDENT 16 /* Size of e_ident[] */
|
||||
|
||||
/* NOTE: elf64.h and elf32.h refer EI_NIDENT defined above */
|
||||
|
||||
#ifdef CONFIG_LIBC_ARCH_ELF_64BIT
|
||||
# include <elf64.h>
|
||||
#else
|
||||
# include <elf32.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Values for Elf_Ehdr::e_type */
|
||||
|
||||
#define ET_NONE 0 /* No file type */
|
||||
#define ET_REL 1 /* Relocatable file */
|
||||
#define ET_EXEC 2 /* Executable file */
|
||||
#define ET_DYN 3 /* Shared object file */
|
||||
#define ET_CORE 4 /* Core file */
|
||||
#define ET_LOPROC 0xff00 /* Processor-specific */
|
||||
#define ET_HIPROC 0xffff /* Processor-specific */
|
||||
|
||||
/* Values for Elf_Ehdr::e_machine (most of this were not included in the
|
||||
* original SCO document but have been gleaned from elsewhere).
|
||||
*/
|
||||
|
||||
#define EM_NONE 0 /* No machine */
|
||||
#define EM_M32 1 /* AT&T WE 32100 */
|
||||
#define EM_SPARC 2 /* SPARC */
|
||||
#define EM_386 3 /* Intel 80386 */
|
||||
#define EM_68K 4 /* Motorola 68000 */
|
||||
#define EM_88K 5 /* Motorola 88000 */
|
||||
#define EM_486 6 /* Intel 486+ */
|
||||
#define EM_860 7 /* Intel 80860 */
|
||||
#define EM_MIPS 8 /* MIPS R3000 Big-Endian */
|
||||
#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
|
||||
#define EM_PARISC 15 /* HPPA */
|
||||
#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
|
||||
#define EM_PPC 20 /* PowerPC */
|
||||
#define EM_PPC64 21 /* PowerPC64 */
|
||||
#define EM_ARM 40 /* ARM */
|
||||
#define EM_SH 42 /* SuperH */
|
||||
#define EM_SPARCV9 43 /* SPARC v9 64-bit */
|
||||
#define EM_H8_300 46
|
||||
#define EM_IA_64 50 /* HP/Intel IA-64 */
|
||||
#define EM_X86_64 62 /* AMD x86-64 */
|
||||
#define EM_S390 22 /* IBM S/390 */
|
||||
#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */
|
||||
#define EM_V850 87 /* NEC v850 */
|
||||
#define EM_M32R 88 /* Renesas M32R */
|
||||
#define EM_XTENSA 94 /* Tensilica Xtensa */
|
||||
#define EM_RISCV 243 /* RISC-V */
|
||||
#define EM_ALPHA 0x9026
|
||||
#define EM_CYGNUS_V850 0x9080
|
||||
#define EM_CYGNUS_M32R 0x9041
|
||||
#define EM_S390_OLD 0xa390
|
||||
#define EM_FRV 0x5441
|
||||
|
||||
/* Values for Elf_Ehdr::e_version */
|
||||
|
||||
#define EV_NONE 0 /* Invalid version */
|
||||
#define EV_CURRENT 1 /* The current version */
|
||||
|
||||
/* Table 2. Ehe ELF identifier */
|
||||
|
||||
#define EI_MAG0 0 /* File identification */
|
||||
#define EI_MAG1 1
|
||||
#define EI_MAG2 2
|
||||
#define EI_MAG3 3
|
||||
#define EI_CLASS 4 /* File class */
|
||||
#define EI_DATA 5 /* Data encoding */
|
||||
#define EI_VERSION 6 /* File version */
|
||||
#define EI_PAD 7 /* Start of padding bytes */
|
||||
|
||||
/* EI_NIDENT is defined in "Included Files" section */
|
||||
|
||||
#define EI_MAGIC_SIZE 4
|
||||
#define EI_MAGIC {0x7f, 'E', 'L', 'F'}
|
||||
|
||||
/* Table 3. Values for EI_CLASS */
|
||||
|
||||
#define ELFCLASSNONE 0 /* Invalid class */
|
||||
#define ELFCLASS32 1 /* 32-bit objects */
|
||||
#define ELFCLASS64 2 /* 64-bit objects */
|
||||
|
||||
/* Table 4. Values for EI_DATA */
|
||||
|
||||
#define ELFDATANONE 0 /* Invalid data encoding */
|
||||
#define ELFDATA2LSB 1 /* Least significant byte occupying the lowest address */
|
||||
#define ELFDATA2MSB 2 /* Most significant byte occupying the lowest address */
|
||||
|
||||
/* Table 7: Special Section Indexes */
|
||||
|
||||
#define SHN_UNDEF 0
|
||||
#define SHN_LOPROC 0xff00
|
||||
#define SHN_HIPROC 0xff1f
|
||||
#define SHN_ABS 0xfff1
|
||||
#define SHN_COMMON 0xfff2
|
||||
|
||||
/* Figure 4-9: Section Types, sh_type */
|
||||
|
||||
#define SHT_NULL 0
|
||||
#define SHT_PROGBITS 1
|
||||
#define SHT_SYMTAB 2
|
||||
#define SHT_STRTAB 3
|
||||
#define SHT_RELA 4
|
||||
#define SHT_HASH 5
|
||||
#define SHT_DYNAMIC 6
|
||||
#define SHT_NOTE 7
|
||||
#define SHT_NOBITS 8
|
||||
#define SHT_REL 9
|
||||
#define SHT_SHLIB 10
|
||||
#define SHT_DYNSYM 11
|
||||
#define SHT_LOPROC 0x70000000
|
||||
#define SHT_HIPROC 0x7fffffff
|
||||
#define SHT_LOUSER 0x80000000
|
||||
#define SHT_HIUSER 0xffffffff
|
||||
|
||||
/* Figure 4-11: Section Attribute Flags, sh_flags */
|
||||
|
||||
#define SHF_WRITE 1
|
||||
#define SHF_ALLOC 2
|
||||
#define SHF_EXECINSTR 4
|
||||
#define SHF_MASKPROC 0xf0000000
|
||||
|
||||
/* Figure 4-16: Symbol Binding, ELF_ST_BIND */
|
||||
|
||||
#define STB_LOCAL 0
|
||||
#define STB_GLOBAL 1
|
||||
#define STB_WEAK 2
|
||||
#define STB_LOPROC 13
|
||||
#define STB_HIPROC 15
|
||||
|
||||
/* Figure 4-17: Symbol Types, ELF_ST_TYPE */
|
||||
|
||||
#define STT_NOTYPE 0
|
||||
#define STT_OBJECT 1
|
||||
#define STT_FUNC 2
|
||||
#define STT_SECTION 3
|
||||
#define STT_FILE 4
|
||||
#define STT_LOPROC 13
|
||||
#define STT_HIPROC 15
|
||||
|
||||
/* Figure 5-2: Segment Types, p_type */
|
||||
|
||||
#define PT_NULL 0
|
||||
#define PT_LOAD 1
|
||||
#define PT_DYNAMIC 2
|
||||
#define PT_INTERP 3
|
||||
#define PT_NOTE 4
|
||||
#define PT_SHLIB 5
|
||||
#define PT_PHDR 6
|
||||
#define PT_LOPROC 0x70000000
|
||||
#define PT_HIPROC 0x7fffffff
|
||||
|
||||
/* Figure 5-3: Segment Flag Bits, p_flags */
|
||||
|
||||
#define PF_X 1 /* Execute */
|
||||
#define PF_W 2 /* Write */
|
||||
#define PF_R 4 /* Read */
|
||||
#define PF_MASKPROC 0xf0000000 /* Unspecified */
|
||||
|
||||
/* Figure 5-10: Dynamic Array Tags, d_tag */
|
||||
|
||||
#define DT_NULL 0 /* d_un=ignored */
|
||||
#define DT_NEEDED 1 /* d_un=d_val */
|
||||
#define DT_PLTRELSZ 2 /* d_un=d_val */
|
||||
#define DT_PLTGOT 3 /* d_un=d_ptr */
|
||||
#define DT_HASH 4 /* d_un=d_ptr */
|
||||
#define DT_STRTAB 5 /* d_un=d_ptr */
|
||||
#define DT_SYMTAB 6 /* d_un=d_ptr */
|
||||
#define DT_RELA 7 /* d_un=d_ptr */
|
||||
#define DT_RELASZ 8 /* d_un=d_val */
|
||||
#define DT_RELAENT 9 /* d_un=d_val */
|
||||
#define DT_STRSZ 10 /* d_un=d_val */
|
||||
#define DT_SYMENT 11 /* d_un=d_val */
|
||||
#define DT_INIT 12 /* d_un=d_ptr */
|
||||
#define DT_FINI 13 /* d_un=d_ptr */
|
||||
#define DT_SONAME 14 /* d_un=d_val */
|
||||
#define DT_RPATH 15 /* d_un=d_val */
|
||||
#define DT_SYMBOLIC 16 /* d_un=ignored */
|
||||
#define DT_REL 17 /* d_un=d_ptr */
|
||||
#define DT_RELSZ 18 /* d_un=d_val */
|
||||
#define DT_RELENT 19 /* d_un=d_val */
|
||||
#define DT_PLTREL 20 /* d_un=d_val */
|
||||
#define DT_DEBUG 21 /* d_un=d_ptr */
|
||||
#define DT_TEXTREL 22 /* d_un=ignored */
|
||||
#define DT_JMPREL 23 /* d_un=d_ptr */
|
||||
#define DT_BINDNOW 24 /* d_un=ignored */
|
||||
#define DT_LOPROC 0x70000000 /* d_un=unspecified */
|
||||
#define DT_HIPROC 0x7fffffff /* d_un= unspecified */
|
||||
|
||||
#endif /* __INCLUDE_ELF_H */
|
||||
@@ -0,0 +1,158 @@
|
||||
/****************************************************************************
|
||||
* include/elf32.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_ELF32_H
|
||||
#define __INCLUDE_ELF32_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <elf.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define ELF32_ST_BIND(i) ((i) >> 4)
|
||||
#define ELF32_ST_TYPE(i) ((i) & 0xf)
|
||||
#define ELF32_ST_INFO(b,t) (((b) << 4) | ((t) & 0xf))
|
||||
|
||||
/* Definitions for Elf32_Rel*::r_info */
|
||||
|
||||
#define ELF32_R_SYM(i) ((i) >> 8)
|
||||
#define ELF32_R_TYPE(i) ((i) & 0xff)
|
||||
#define ELF32_R_INFO(s,t) (((s)<< 8) | ((t) & 0xff))
|
||||
|
||||
#define ELF_R_SYM(i) ELF32_R_SYM(i)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Figure 4.2: 32-Bit Data Types */
|
||||
|
||||
typedef uint32_t Elf32_Addr; /* Unsigned program address */
|
||||
typedef uint16_t Elf32_Half; /* Unsigned medium integer */
|
||||
typedef uint32_t Elf32_Off; /* Unsigned file offset */
|
||||
typedef int32_t Elf32_Sword; /* Signed large integer */
|
||||
typedef uint32_t Elf32_Word; /* Unsigned large integer */
|
||||
|
||||
/* Figure 4-3: ELF Header */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned char e_ident[EI_NIDENT];
|
||||
Elf32_Half e_type;
|
||||
Elf32_Half e_machine;
|
||||
Elf32_Word e_version;
|
||||
Elf32_Addr e_entry;
|
||||
Elf32_Off e_phoff;
|
||||
Elf32_Off e_shoff;
|
||||
Elf32_Word e_flags;
|
||||
Elf32_Half e_ehsize;
|
||||
Elf32_Half e_phentsize;
|
||||
Elf32_Half e_phnum;
|
||||
Elf32_Half e_shentsize;
|
||||
Elf32_Half e_shnum;
|
||||
Elf32_Half e_shstrndx;
|
||||
} Elf32_Ehdr;
|
||||
|
||||
/* Figure 4-8: Section Header */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Word sh_name;
|
||||
Elf32_Word sh_type;
|
||||
Elf32_Word sh_flags;
|
||||
Elf32_Addr sh_addr;
|
||||
Elf32_Off sh_offset;
|
||||
Elf32_Word sh_size;
|
||||
Elf32_Word sh_link;
|
||||
Elf32_Word sh_info;
|
||||
Elf32_Word sh_addralign;
|
||||
Elf32_Word sh_entsize;
|
||||
} Elf32_Shdr;
|
||||
|
||||
/* Figure 4-15: Symbol Table Entry */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Word st_name;
|
||||
Elf32_Addr st_value;
|
||||
Elf32_Word st_size;
|
||||
unsigned char st_info;
|
||||
unsigned char st_other;
|
||||
Elf32_Half st_shndx;
|
||||
} Elf32_Sym;
|
||||
|
||||
/* Figure 4-19: Relocation Entries */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Addr r_offset;
|
||||
Elf32_Word r_info;
|
||||
} Elf32_Rel;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Addr r_offset;
|
||||
Elf32_Word r_info;
|
||||
Elf32_Sword r_addend;
|
||||
} Elf32_Rela;
|
||||
|
||||
/* Figure 5-1: Program Header */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Word p_type;
|
||||
Elf32_Off p_offset;
|
||||
Elf32_Addr p_vaddr;
|
||||
Elf32_Addr p_paddr;
|
||||
Elf32_Word p_filesz;
|
||||
Elf32_Word p_memsz;
|
||||
Elf32_Word p_flags;
|
||||
Elf32_Word p_align;
|
||||
} Elf32_Phdr;
|
||||
|
||||
/* Figure 5-9: Dynamic Structure */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Sword d_tag;
|
||||
union
|
||||
{
|
||||
Elf32_Word d_val;
|
||||
Elf32_Addr d_ptr;
|
||||
} d_un;
|
||||
} Elf32_Dyn;
|
||||
|
||||
typedef Elf32_Addr Elf_Addr;
|
||||
typedef Elf32_Ehdr Elf_Ehdr;
|
||||
typedef Elf32_Rel Elf_Rel;
|
||||
typedef Elf32_Rela Elf_Rela;
|
||||
typedef Elf32_Sym Elf_Sym;
|
||||
typedef Elf32_Shdr Elf_Shdr;
|
||||
typedef Elf32_Word Elf_Word;
|
||||
|
||||
#endif /* __INCLUDE_ELF32_H */
|
||||
@@ -0,0 +1,158 @@
|
||||
/****************************************************************************
|
||||
* include/elf64.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_ELF64_H
|
||||
#define __INCLUDE_ELF64_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <elf.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* See ELF-64 Object File Format: Version 1.5 Draft 2 */
|
||||
|
||||
/* Definitions for Elf64_Rel*::r_info */
|
||||
|
||||
#define ELF64_R_SYM(i) ((i) >> 32)
|
||||
#define ELF64_R_TYPE(i) ((i) & 0xffffffffL)
|
||||
#define ELF64_R_INFO(s,t) (((s)<< 32) + ((t) & 0xffffffffL))
|
||||
|
||||
#define ELF_R_SYM(i) ELF64_R_SYM(i)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Table 1: ELF-64 Data Types */
|
||||
|
||||
typedef uint64_t Elf64_Addr; /* Unsigned program address */
|
||||
typedef uint64_t Elf64_Off; /* Unsigned file offset */
|
||||
typedef uint16_t Elf64_Half; /* Unsigned medium integer */
|
||||
typedef uint32_t Elf64_Word; /* Unsigned long integer */
|
||||
typedef int32_t Elf64_Sword; /* Signed integer */
|
||||
typedef uint64_t Elf64_Xword; /* Unsigned long integer */
|
||||
typedef int64_t Elf64_Sxword; /* Signed large integer */
|
||||
|
||||
/* Figure 2: ELF-64 Header */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned char e_ident[EI_NIDENT]; /* ELF identification */
|
||||
Elf64_Half e_type; /* Object file type */
|
||||
Elf64_Half e_machine; /* Machine type */
|
||||
Elf64_Word e_version; /* Object file version */
|
||||
Elf64_Addr e_entry; /* Entry point address */
|
||||
Elf64_Off e_phoff; /* Program header offset */
|
||||
Elf64_Off e_shoff; /* Section header offset */
|
||||
Elf64_Word e_flags; /* Processor-specific flags */
|
||||
Elf64_Half e_ehsize; /* ELF header size */
|
||||
Elf64_Half e_phentsize; /* Size of program header entry */
|
||||
Elf64_Half e_phnum; /* Number of program header entry */
|
||||
Elf64_Half e_shentsize; /* Size of section header entry */
|
||||
Elf64_Half e_shnum; /* Number of section header entries */
|
||||
Elf64_Half e_shstrndx; /* Section name string table index */
|
||||
} Elf64_Ehdr;
|
||||
|
||||
/* Figure 3: ELF-64 Section Header */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf64_Word sh_name; /* Section name */
|
||||
Elf64_Word sh_type; /* Section type */
|
||||
Elf64_Xword sh_flags; /* Section attributes */
|
||||
Elf64_Addr sh_addr; /* Virtual address in memory */
|
||||
Elf64_Off sh_offset; /* Offset in file */
|
||||
Elf64_Xword sh_size; /* Size of section */
|
||||
Elf64_Word sh_link; /* Link to other section */
|
||||
Elf64_Word sh_info; /* Miscellaneous information */
|
||||
Elf64_Xword sh_addralign; /* Address alignment boundary */
|
||||
Elf64_Xword sh_entsize; /* Size of entries, if section has table */
|
||||
} Elf64_Shdr;
|
||||
|
||||
/* Figure 4: ELF-64 Symbol Table Entry */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf64_Word st_name; /* Symbol name */
|
||||
unsigned char st_info; /* Type and Binding attributes */
|
||||
unsigned char st_other; /* Reserved */
|
||||
Elf64_Half st_shndx; /* Section table index */
|
||||
Elf64_Addr st_value; /* Symbol value */
|
||||
Elf64_Xword st_size; /* Size of object (e.g., common) */
|
||||
} Elf64_Sym;
|
||||
|
||||
/* Figure 5: ELF-64 Relocation Entries */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf64_Addr r_offset; /* Address of reference */
|
||||
Elf64_Xword r_info; /* Symbol index and type of relocation */
|
||||
} Elf64_Rel;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf64_Addr r_offset; /* Address of reference */
|
||||
Elf64_Xword r_info; /* Symbol index and type of relocation */
|
||||
Elf64_Sxword r_addend; /* Constant part of expression */
|
||||
} Elf64_Rela;
|
||||
|
||||
/* Figure 6: ELF-64 Program Header Table Entry */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf64_Word p_type; /* Type of segment */
|
||||
Elf64_Word p_flags; /* Segment attributes */
|
||||
Elf64_Off p_offset; /* Offset in file */
|
||||
Elf64_Addr p_vaddr; /* Virtual address in memory */
|
||||
Elf64_Addr p_paddr; /* Reserved */
|
||||
Elf64_Word p_filesz; /* Size of segment in file */
|
||||
Elf64_Word p_memsz; /* Size of segment in memory */
|
||||
Elf64_Word p_align; /* Alignment of segment */
|
||||
} Elf64_Phdr;
|
||||
|
||||
/* Figure 8: Dynamic Table Structure */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf64_Sxword d_tag;
|
||||
union
|
||||
{
|
||||
Elf64_Xword d_val;
|
||||
Elf64_Addr d_ptr;
|
||||
} d_un;
|
||||
} Elf64_Dyn;
|
||||
|
||||
typedef Elf64_Addr Elf_Addr;
|
||||
typedef Elf64_Ehdr Elf_Ehdr;
|
||||
typedef Elf64_Rel Elf_Rel;
|
||||
typedef Elf64_Rela Elf_Rela;
|
||||
typedef Elf64_Sym Elf_Sym;
|
||||
typedef Elf64_Shdr Elf_Shdr;
|
||||
typedef Elf64_Word Elf_Word;
|
||||
|
||||
#endif /* __INCLUDE_ELF64_H */
|
||||
@@ -0,0 +1,136 @@
|
||||
/****************************************************************************
|
||||
* include/endian.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_ENDIAN_H
|
||||
#define __INCLUDE_ENDIAN_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Preprocessor definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* The endian.h header must define at least the following macros for use in
|
||||
* determining host byte order for integer types:
|
||||
*
|
||||
* BYTE_ORDER This macro will have a value equal to one of the *_ENDIAN
|
||||
* macros in this header.
|
||||
* LITTLE_ENDIAN If BYTE_ORDER == LITTLE_ENDIAN, the host byte order is
|
||||
* from least significant to most significant.
|
||||
* BIG_ENDIAN If BYTE_ORDER == BIG_ENDIAN, the host byte order is from
|
||||
* most significant to least significant.
|
||||
*/
|
||||
|
||||
#define LITTLE_ENDIAN 1234
|
||||
#define BIG_ENDIAN 4321
|
||||
|
||||
/* Common byte swapping macros */
|
||||
|
||||
#define __SWAP_UINT16_ISMACRO 1
|
||||
#undef __SWAP_UINT32_ISMACRO
|
||||
|
||||
#ifdef __SWAP_UINT16_ISMACRO
|
||||
# define __swap_uint16(n) \
|
||||
(uint16_t)(((((uint16_t)(n)) & 0x00ff) << 8) | \
|
||||
((((uint16_t)(n)) >> 8) & 0x00ff))
|
||||
#endif
|
||||
|
||||
#ifdef __SWAP_UINT32_ISMACRO
|
||||
# define __swap_uint32(n) \
|
||||
(uint32_t)(((((uint32_t)(n)) & 0x000000ffUL) << 24) | \
|
||||
((((uint32_t)(n)) & 0x0000ff00UL) << 8) | \
|
||||
((((uint32_t)(n)) & 0x00ff0000UL) >> 8) | \
|
||||
((((uint32_t)(n)) & 0xff000000UL) >> 24))
|
||||
#endif
|
||||
|
||||
/* Endian-specific definitions */
|
||||
|
||||
#ifdef CONFIG_ENDIAN_BIG
|
||||
/* Big-endian byte order */
|
||||
|
||||
# define BYTE_ORDER BIG_ENDIAN
|
||||
|
||||
/* Big-endian byte order macros */
|
||||
|
||||
# define htobe16(n) (n)
|
||||
# define htole16(n) __swap_uint16((uint16_t)n)
|
||||
# define be16toh(n) (n)
|
||||
# define le16toh(n) __swap_uint16((uint16_t)n)
|
||||
|
||||
# define htobe32(n) (n)
|
||||
# define htole32(n) __swap_uint32((uint32_t)n)
|
||||
# define be32toh(n) (n)
|
||||
# define le32toh(n) __swap_uint32(n)
|
||||
|
||||
# ifdef CONFIG_HAVE_LONG_LONG
|
||||
# define htobe64(n) (n)
|
||||
# define htole64(n) __swap_uint64((uint64_t)n)
|
||||
# define be64toh(n) (n)
|
||||
# define le64toh(n) __swap_uint64((uint64_t)n)
|
||||
# endif
|
||||
|
||||
#else
|
||||
/* Little-endian byte order */
|
||||
|
||||
# define BYTE_ORDER LITTLE_ENDIAN
|
||||
|
||||
/* Little-endian byte order macros */
|
||||
|
||||
# define htobe16(n) __swap_uint16((uint16_t)n)
|
||||
# define htole16(n) (n)
|
||||
# define be16toh(n) __swap_uint16((uint16_t)n)
|
||||
# define le16toh(n) (n)
|
||||
|
||||
# define htobe32(n) __swap_uint32((uint32_t)n)
|
||||
# define htole32(n) (n)
|
||||
# define be32toh(n) __swap_uint32((uint32_t)n)
|
||||
# define le32toh(n) (n)
|
||||
|
||||
# ifdef CONFIG_HAVE_LONG_LONG
|
||||
# define htobe64(n) __swap_uint64((uint64_t)n)
|
||||
# define htole64(n) (n)
|
||||
# define be64toh(n) __swap_uint64((uint64_t)n)
|
||||
# define le64toh(n) (n)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __SWAP_UINT16_ISMACRO
|
||||
uint16_t __swap_uint16(uint16_t n);
|
||||
#endif
|
||||
|
||||
#ifndef __SWAP_UINT32_ISMACRO
|
||||
uint32_t __swap_uint32(uint32_t n);
|
||||
#endif
|
||||
|
||||
#if CONFIG_HAVE_LONG_LONG
|
||||
uint64_t __swap_uint64(uint64_t n);
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_ENDIAN_H */
|
||||
@@ -0,0 +1,342 @@
|
||||
/****************************************************************************
|
||||
* include/errno.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_ERRNO_H
|
||||
#define __INCLUDE_ERRNO_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Convenience/compatibility definition. If the errno is accessed from the
|
||||
* internal OS code, then the OS code should use the set_errno() and
|
||||
* get_errno(). Currently, those are just placeholders but would be needed
|
||||
* in the KERNEL mode build in order to instantiate the process address
|
||||
* environment as necessary to access the TLS-based errno variable.
|
||||
*/
|
||||
|
||||
#define errno *__errno()
|
||||
#define set_errno(e) \
|
||||
do \
|
||||
{ \
|
||||
errno = (int)(e); \
|
||||
} \
|
||||
while (0)
|
||||
#define get_errno() errno
|
||||
|
||||
/* Definitions of error numbers and the string that would be
|
||||
* returned by strerror().
|
||||
*/
|
||||
|
||||
#define EPERM 1
|
||||
#define EPERM_STR "Operation not permitted"
|
||||
#define ENOENT 2
|
||||
#define ENOENT_STR "No such file or directory"
|
||||
#define ESRCH 3
|
||||
#define ESRCH_STR "No such process"
|
||||
#define EINTR 4
|
||||
#define EINTR_STR "Interrupted system call"
|
||||
#define EIO 5
|
||||
#define EIO_STR "I/O error"
|
||||
#define ENXIO 6
|
||||
#define ENXIO_STR "No such device or address"
|
||||
#define E2BIG 7
|
||||
#define E2BIG_STR "Arg list too long"
|
||||
#define ENOEXEC 8
|
||||
#define ENOEXEC_STR "Exec format error"
|
||||
#define EBADF 9
|
||||
#define EBADF_STR "Bad file number"
|
||||
#define ECHILD 10
|
||||
#define ECHILD_STR "No child processes"
|
||||
#define EAGAIN 11
|
||||
#define EWOULDBLOCK EAGAIN
|
||||
#define EAGAIN_STR "Try again"
|
||||
#define ENOMEM 12
|
||||
#define ENOMEM_STR "Out of memory"
|
||||
#define EACCES 13
|
||||
#define EACCES_STR "Permission denied"
|
||||
#define EFAULT 14 /* Linux errno extension */
|
||||
#define EFAULT_STR "Bad address"
|
||||
#define ENOTBLK 15
|
||||
#define ENOTBLK_STR "Block device required"
|
||||
#define EBUSY 16
|
||||
#define EBUSY_STR "Device or resource busy"
|
||||
#define EEXIST 17
|
||||
#define EEXIST_STR "File exists"
|
||||
#define EXDEV 18
|
||||
#define EXDEV_STR "Cross-device link"
|
||||
#define ENODEV 19
|
||||
#define ENODEV_STR "No such device"
|
||||
#define ENOTDIR 20
|
||||
#define ENOTDIR_STR "Not a directory"
|
||||
#define EISDIR 21
|
||||
#define EISDIR_STR "Is a directory"
|
||||
#define EINVAL 22
|
||||
#define EINVAL_STR "Invalid argument"
|
||||
#define ENFILE 23
|
||||
#define ENFILE_STR "File table overflow"
|
||||
#define EMFILE 24
|
||||
#define EMFILE_STR "Too many open files"
|
||||
#define ENOTTY 25
|
||||
#define ENOTTY_STR "Not a typewriter"
|
||||
#define ETXTBSY 26
|
||||
#define ETXTBSY_STR "Text file busy"
|
||||
#define EFBIG 27
|
||||
#define EFBIG_STR "File too large"
|
||||
#define ENOSPC 28
|
||||
#define ENOSPC_STR "No space left on device"
|
||||
#define ESPIPE 29
|
||||
#define ESPIPE_STR "Illegal seek"
|
||||
#define EROFS 30
|
||||
#define EROFS_STR "Read-only file system"
|
||||
#define EMLINK 31
|
||||
#define EMLINK_STR "Too many links"
|
||||
#define EPIPE 32
|
||||
#define EPIPE_STR "Broken pipe"
|
||||
#define EDOM 33
|
||||
#define EDOM_STR "Math argument out of domain of func"
|
||||
#define ERANGE 34
|
||||
#define ERANGE_STR "Math result not representable"
|
||||
#define ENOMSG 35
|
||||
#define ENOMSG_STR "No message of desired type"
|
||||
#define EIDRM 36
|
||||
#define EIDRM_STR "Identifier removed"
|
||||
#define ECHRNG 37 /* Linux errno extension */
|
||||
#define ECHRNG_STR "Channel number out of range"
|
||||
#define EL2NSYNC 38 /* Linux errno extension */
|
||||
#define EL2NSYNC_STR "Level 2 not synchronized"
|
||||
#define EL3HLT 39 /* Linux errno extension */
|
||||
#define EL3HLT_STR "Level 3 halted"
|
||||
#define EL3RST 40 /* Linux errno extension */
|
||||
#define EL3RST_STR "Level 3 reset"
|
||||
#define ELNRNG 41 /* Linux errno extension */
|
||||
#define ELNRNG_STR "Link number out of range"
|
||||
#define EUNATCH 42 /* Linux errno extension */
|
||||
#define EUNATCH_STR "Protocol driver not attached"
|
||||
#define ENOCSI 43 /* Linux errno extension */
|
||||
#define ENOCSI_STR "No CSI structure available"
|
||||
#define EL2HLT 44 /* Linux errno extension */
|
||||
#define EL2HLT_STR "Level 2 halted"
|
||||
#define EDEADLK 45
|
||||
#define EDEADLK_STR "Resource deadlock would occur"
|
||||
#define ENOLCK 46
|
||||
#define ENOLCK_STR "No record locks available"
|
||||
|
||||
#define EBADE 50 /* Linux errno extension */
|
||||
#define EBADE_STR "Invalid exchange"
|
||||
#define EBADR 51 /* Linux errno extension */
|
||||
#define EBADR_STR "Invalid request descriptor"
|
||||
#define EXFULL 52 /* Linux errno extension */
|
||||
#define EXFULL_STR "Exchange full"
|
||||
#define ENOANO 53 /* Linux errno extension */
|
||||
#define ENOANO_STR "No anode"
|
||||
#define EBADRQC 54 /* Linux errno extension */
|
||||
#define EBADRQC_STR "Invalid request code"
|
||||
#define EBADSLT 55 /* Linux errno extension */
|
||||
#define EBADSLT_STR "Invalid slot"
|
||||
#define EDEADLOCK 56 /* Linux errno extension */
|
||||
#define EDEADLOCK_STR "File locking deadlock error"
|
||||
#define EBFONT 57 /* Linux errno extension */
|
||||
#define EBFONT_STR "Bad font file format"
|
||||
|
||||
#define ENOSTR 60
|
||||
#define ENOSTR_STR "Device not a stream"
|
||||
#define ENODATA 61
|
||||
#define ENODATA_STR "No data available"
|
||||
#define ETIME 62
|
||||
#define ETIME_STR "Timer expired"
|
||||
#define ENOSR 63
|
||||
#define ENOSR_STR "Out of streams resources"
|
||||
#define ENONET 64 /* Linux errno extension */
|
||||
#define ENONET_STR "Machine is not on the network"
|
||||
#define ENOPKG 65 /* Linux errno extension */
|
||||
#define ENOPKG_STR "Package not installed"
|
||||
#define EREMOTE 66 /* Linux errno extension */
|
||||
#define EREMOTE_STR "Object is remote"
|
||||
#define ENOLINK 67
|
||||
#define ENOLINK_STR "Link has been severed"
|
||||
#define EADV 68 /* Linux errno extension */
|
||||
#define EADV_STR "Advertise error"
|
||||
#define ESRMNT 69 /* Linux errno extension */
|
||||
#define ESRMNT_STR "Srmount error"
|
||||
#define ECOMM 70 /* Linux errno extension */
|
||||
#define ECOMM_STR "Communication error on send"
|
||||
#define EPROTO 71
|
||||
#define EPROTO_STR "Protocol error"
|
||||
|
||||
#define EMULTIHOP 74
|
||||
#define EMULTIHOP_STR "Multihop attempted"
|
||||
#define ELBIN 75 /* Linux errno extension */
|
||||
#define ELBIN_STR "Inode is remote"
|
||||
#define EDOTDOT 76 /* Linux errno extension */
|
||||
#define EDOTDOT_STR "RFS specific error"
|
||||
#define EBADMSG 77
|
||||
#define EBADMSG_STR "Not a data message"
|
||||
|
||||
#define EFTYPE 79
|
||||
#define EFTYPE_STR "Inappropriate file type or format"
|
||||
#define ENOTUNIQ 80 /* Linux errno extension */
|
||||
#define ENOTUNIQ_STR "Name not unique on network"
|
||||
#define EBADFD 81 /* Linux errno extension */
|
||||
#define EBADFD_STR "File descriptor in bad state"
|
||||
#define EREMCHG 82 /* Linux errno extension */
|
||||
#define EREMCHG_STR "Remote address changed"
|
||||
#define ELIBACC 83 /* Linux errno extension */
|
||||
#define ELIBACC_STR "Can not access a needed shared library"
|
||||
#define ELIBBAD 84 /* Linux errno extension */
|
||||
#define ELIBBAD_STR "Accessing a corrupted shared library"
|
||||
#define ELIBSCN 85 /* Linux errno extension */
|
||||
#define ELIBSCN_STR ".lib section in a.out corrupted"
|
||||
#define ELIBMAX 86 /* Linux errno extension */
|
||||
#define ELIBMAX_STR "Attempting to link in too many shared libraries"
|
||||
#define ELIBEXEC 87 /* Linux errno extension */
|
||||
#define ELIBEXEC_STR "Cannot exec a shared library directly"
|
||||
#define ENOSYS 88
|
||||
#define ENOSYS_STR "Function not implemented"
|
||||
#define ENMFILE 89 /* Cygwin */
|
||||
#define ENMFILE_STR "No more files"
|
||||
#define ENOTEMPTY 90
|
||||
#define ENOTEMPTY_STR "Directory not empty"
|
||||
#define ENAMETOOLONG 91
|
||||
#define ENAMETOOLONG_STR "File name too long"
|
||||
#define ELOOP 92
|
||||
#define ELOOP_STR "Too many symbolic links encountered"
|
||||
|
||||
#define EOPNOTSUPP 95
|
||||
#define EOPNOTSUPP_STR "Operation not supported on transport endpoint"
|
||||
#define EPFNOSUPPORT 96
|
||||
#define EPFNOSUPPORT_STR "Protocol family not supported"
|
||||
|
||||
#define ECONNRESET 104
|
||||
#define ECONNRESET_STR "Connection reset by peer"
|
||||
#define ENOBUFS 105
|
||||
#define ENOBUFS_STR "No buffer space available"
|
||||
#define EAFNOSUPPORT 106
|
||||
#define EAFNOSUPPORT_STR "Address family not supported by protocol"
|
||||
#define EPROTOTYPE 107
|
||||
#define EPROTOTYPE_STR "Protocol wrong type for socket"
|
||||
#define ENOTSOCK 108
|
||||
#define ENOTSOCK_STR "Socket operation on non-socket"
|
||||
#define ENOPROTOOPT 109
|
||||
#define ENOPROTOOPT_STR "Protocol not available"
|
||||
#define ESHUTDOWN 110 /* Linux errno extension */
|
||||
#define ESHUTDOWN_STR "Cannot send after transport endpoint shutdown"
|
||||
#define ECONNREFUSED 111
|
||||
#define ECONNREFUSED_STR "Connection refused"
|
||||
#define EADDRINUSE 112
|
||||
#define EADDRINUSE_STR "Address already in use"
|
||||
#define ECONNABORTED 113
|
||||
#define ECONNABORTED_STR "Software caused connection abort"
|
||||
#define ENETUNREACH 114
|
||||
#define ENETUNREACH_STR "Network is unreachable"
|
||||
#define ENETDOWN 115
|
||||
#define ENETDOWN_STR "Network is down"
|
||||
#define ETIMEDOUT 116
|
||||
#define ETIMEDOUT_STR "Connection timed out"
|
||||
#define EHOSTDOWN 117
|
||||
#define EHOSTDOWN_STR "Host is down"
|
||||
#define EHOSTUNREACH 118
|
||||
#define EHOSTUNREACH_STR "No route to host"
|
||||
#define EINPROGRESS 119
|
||||
#define EINPROGRESS_STR "Operation now in progress"
|
||||
#define EALREADY 120
|
||||
#define EALREADY_STR "Socket already connected"
|
||||
#define EDESTADDRREQ 121
|
||||
#define EDESTADDRREQ_STR "Destination address required"
|
||||
#define EMSGSIZE 122
|
||||
#define EMSGSIZE_STR "Message too long"
|
||||
#define EPROTONOSUPPORT 123
|
||||
#define EPROTONOSUPPORT_STR "Protocol not supported"
|
||||
#define ESOCKTNOSUPPORT 124 /* Linux errno extension */
|
||||
#define ESOCKTNOSUPPORT_STR "Socket type not supported"
|
||||
#define EADDRNOTAVAIL 125
|
||||
#define EADDRNOTAVAIL_STR "Cannot assign requested address"
|
||||
#define ENETRESET 126
|
||||
#define ENETRESET_STR "Network dropped connection because of reset"
|
||||
#define EISCONN 127
|
||||
#define EISCONN_STR "Transport endpoint is already connected"
|
||||
#define ENOTCONN 128
|
||||
#define ENOTCONN_STR "Transport endpoint is not connected"
|
||||
#define ETOOMANYREFS 129
|
||||
#define ETOOMANYREFS_STR "Too many references: cannot splice"
|
||||
#define EPROCLIM 130
|
||||
#define EPROCLIM_STR "Limit would be exceeded by attempted fork"
|
||||
#define EUSERS 131
|
||||
#define EUSERS_STR "Too many users"
|
||||
#define EDQUOT 132
|
||||
#define EDQUOT_STR "Quota exceeded"
|
||||
#define ESTALE 133
|
||||
#define ESTALE_STR "Stale NFS file handle"
|
||||
#define ENOTSUP 134
|
||||
#define ENOTSUP_STR "Not supported"
|
||||
#define ENOMEDIUM 135 /* Linux errno extension */
|
||||
#define ENOMEDIUM_STR "No medium found"
|
||||
#define ENOSHARE 136 /* Cygwin */
|
||||
#define ENOSHARE_STR "No such host or network path"
|
||||
#define ECASECLASH 137 /* Cygwin */
|
||||
#define ECASECLASH_STR "Filename exists with different case"
|
||||
#define EILSEQ 138
|
||||
#define EILSEQ_STR "Illegal byte sequence"
|
||||
#define EOVERFLOW 139
|
||||
#define EOVERFLOW_STR "Value too large for defined data type"
|
||||
#define ECANCELED 140
|
||||
#define ECANCELED_STR "Operation cancelled"
|
||||
#define ENOTRECOVERABLE 141
|
||||
#define ENOTRECOVERABLE_STR "State not recoverable"
|
||||
#define EOWNERDEAD 142
|
||||
#define EOWNERDEAD_STR "Previous owner died"
|
||||
#define ESTRPIPE 143 /* Linux errno extension */
|
||||
#define ESTRPIPE_STR "Streams pipe error"
|
||||
|
||||
#define __ELASTERROR 2000 /* Users can add values starting here */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* Return a pointer to the thread specific errno. */
|
||||
|
||||
FAR int *__errno(void);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_ERRNO_H */
|
||||
@@ -0,0 +1,169 @@
|
||||
/********************************************************************************
|
||||
* include/fcntl.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_FCNTL_H
|
||||
#define __INCLUDE_FCNTL_H
|
||||
|
||||
/********************************************************************************
|
||||
* Included Files
|
||||
********************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/********************************************************************************
|
||||
* Pre-processor Definitions
|
||||
********************************************************************************/
|
||||
|
||||
/* open flag settings for open() (and related APIs) */
|
||||
|
||||
#define O_RDONLY (1 << 0) /* Open for read access (only) */
|
||||
#define O_RDOK O_RDONLY /* Read access is permitted (non-standard) */
|
||||
#define O_WRONLY (1 << 1) /* Open for write access (only) */
|
||||
#define O_WROK O_WRONLY /* Write access is permitted (non-standard) */
|
||||
#define O_RDWR (O_RDOK|O_WROK) /* Open for both read & write access */
|
||||
#define O_CREAT (1 << 2) /* Create file/sem/mq object */
|
||||
#define O_EXCL (1 << 3) /* Name must not exist when opened */
|
||||
#define O_APPEND (1 << 4) /* Keep contents, append to end */
|
||||
#define O_TRUNC (1 << 5) /* Delete contents */
|
||||
#define O_NONBLOCK (1 << 6) /* Don't wait for data */
|
||||
#define O_NDELAY O_NONBLOCK /* Synonym for O_NONBLOCK */
|
||||
#define O_SYNC (1 << 7) /* Synchronize output on write */
|
||||
#define O_DSYNC O_SYNC /* Equivalent to OSYNC in NuttX */
|
||||
#define O_BINARY (1 << 8) /* Open the file in binary (untranslated) mode. */
|
||||
#define O_DIRECT (1 << 9) /* Avoid caching, write directly to hardware */
|
||||
#define O_CLOEXEC (1 << 10) /* Close on execute */
|
||||
|
||||
/* Unsupported, but required open flags */
|
||||
|
||||
#define O_RSYNC 0 /* Synchronize input on read */
|
||||
#define O_ACCMODE O_RDWR /* Mask for access mode */
|
||||
#define O_NOCTTY 0 /* Required by POSIX */
|
||||
#define O_TEXT 0 /* Open the file in text (translated) mode. */
|
||||
|
||||
/* This is the highest bit number used in the open flags bitset. Bits above
|
||||
* this bit number may be used within NuttX for other, internal purposes.
|
||||
*/
|
||||
|
||||
#define _O_MAXBIT 8
|
||||
|
||||
/* Synonyms historically used as F_SETFL flags (BSD). */
|
||||
|
||||
#define FNDELAY O_NONBLOCK /* Don't wait for data */
|
||||
#define FNONBLOCK O_NONBLOCK /* Don't wait for data */
|
||||
#define FAPPEND O_APPEND /* Keep contents, append to end */
|
||||
#define FSYNC O_SYNC /* Synchronize output on write */
|
||||
#define FASYNC 0 /* No counterpart in NuttX */
|
||||
|
||||
/* FFCNTL is all the bits that may be set via fcntl. */
|
||||
|
||||
#define FFCNTL (FNONBLOCK | FNDELAY | FAPPEND | FSYNC | FASYNC)
|
||||
|
||||
/* fcntl() commands */
|
||||
|
||||
#define F_DUPFD 0 /* Duplicate a file descriptor */
|
||||
#define F_GETFD 1 /* Read the file descriptor flags */
|
||||
#define F_GETFL 2 /* Read the file status flags */
|
||||
#define F_GETLEASE 3 /* Indicates what type of lease is held on fd (linux) */
|
||||
#define F_GETLK 4 /* Check if we could place a lock */
|
||||
#define F_GETOWN 5 /* Get the pid receiving SIGIO and SIGURG signals for fd */
|
||||
#define F_GETSIG 6 /* Get the signal sent */
|
||||
#define F_NOTIFY 7 /* Provide notification when directory referred to by fd changes (linux)*/
|
||||
#define F_SETFD 8 /* Set the file descriptor flags to value */
|
||||
#define F_SETFL 9 /* Set the file status flags to the value */
|
||||
#define F_SETLEASE 10 /* Set or remove file lease (linux) */
|
||||
#define F_SETLK 11 /* Acquire or release a lock on range of bytes */
|
||||
#define F_SETLKW 12 /* Like F_SETLK, but wait for lock to become available */
|
||||
#define F_SETOWN 13 /* Set pid that will receive SIGIO and SIGURG signals for fd */
|
||||
#define F_SETSIG 14 /* Set the signal to be sent */
|
||||
|
||||
/* For posix fcntl() and lockf() */
|
||||
|
||||
#define F_RDLCK 0 /* Take out a read lease */
|
||||
#define F_WRLCK 1 /* Take out a write lease */
|
||||
#define F_UNLCK 2 /* Remove a lease */
|
||||
|
||||
/* close-on-exec flag for F_GETRL and F_SETFL */
|
||||
|
||||
#define FD_CLOEXEC 1
|
||||
|
||||
/* These are the notifications that can be received from F_NOTIFY (linux) */
|
||||
|
||||
#define DN_ACCESS 0 /* A file was accessed */
|
||||
#define DN_MODIFY 1 /* A file was modified */
|
||||
#define DN_CREATE 2 /* A file was created */
|
||||
#define DN_DELETE 3 /* A file was unlinked */
|
||||
#define DN_RENAME 4 /* A file was renamed */
|
||||
#define DN_ATTRIB 5 /* Attributes of a file were changed */
|
||||
|
||||
/* int creat(const char *path, mode_t mode);
|
||||
*
|
||||
* is equivalent to open with O_WRONLY|O_CREAT|O_TRUNC.
|
||||
*/
|
||||
|
||||
#define creat(path, mode) open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)
|
||||
|
||||
/********************************************************************************
|
||||
* Public Type Definitions
|
||||
********************************************************************************/
|
||||
|
||||
/* struct flock is the third argument for F_GETLK, F_SETLK and F_SETLKW */
|
||||
|
||||
struct flock
|
||||
{
|
||||
int16_t l_type; /* Type of lock: F_RDLCK, F_WRLCK, F_UNLCK */
|
||||
int16_t l_whence; /* How to interpret l_start: SEEK_SET, SEEK_CUR, SEEK_END */
|
||||
off_t l_start; /* Starting offset for lock */
|
||||
off_t l_len; /* Number of bytes to lock */
|
||||
pid_t l_pid; /* PID of process blocking our lock (F_GETLK only) */
|
||||
};
|
||||
|
||||
/********************************************************************************
|
||||
* Public Function Prototypes
|
||||
********************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/********************************************************************************
|
||||
* Public Data
|
||||
********************************************************************************/
|
||||
|
||||
/* POSIX-like File System Interfaces */
|
||||
|
||||
int open(FAR const char *path, int oflag, ...);
|
||||
int fcntl(int fd, int cmd, ...);
|
||||
|
||||
int posix_fallocate(int fd, off_t offset, off_t len);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_FCNTL_H */
|
||||
@@ -0,0 +1,264 @@
|
||||
/****************************************************************************
|
||||
* include/fixedmath.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_FIXEDMATH_H
|
||||
#define __INCLUDE_FIXEDMATH_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/compiler.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Common numbers */
|
||||
|
||||
#define b8HUNDRED 0x6400 /* 100 */
|
||||
#define b8TEN 0x0a00 /* 10 */
|
||||
#define b8ONE 0x0100 /* 1 */
|
||||
#define b8HALF 0x0080 /* 0.5 */
|
||||
#define b8ONETENTH 0x001a /* 0.1 (actually 0.1015625) */
|
||||
#define b8ONEHUNDRTH 0x0003 /* 0.01 (actually 0.0117198765) */
|
||||
#define b8HALFPI 0x0192 /* 1.5703125 */
|
||||
#define b8PI 0x0324 /* 3.1406250 */
|
||||
#define b8TWOPI 0x0648 /* 6.2812500 */
|
||||
|
||||
#define b8MAX 0x7fff /* Max value of b8_t */
|
||||
#define ub8MAX 0xffff /* Max value of rb8_t */
|
||||
#define b8MIN 0x8000 /* Min value of b8_t */
|
||||
#define ub8MIN 0x0000 /* Min value of ub8_t */
|
||||
|
||||
#define b16THOUSAND 0x03e80000 /* 1000 */
|
||||
#define b16HUNDRED 0x00640000 /* 100 */
|
||||
#define b16TEN 0x000a0000 /* 10 */
|
||||
#define b16ONE 0x00010000 /* 1 */
|
||||
#define b16HALF 0x00008000 /* 0.5 */
|
||||
#define b16ONETENTH 0x0000199a /* 0.1 (actually 0.100006..) */
|
||||
#define b16ONEHUNDRTH 0x0000028f /* 0.01 (actually 0.0099945..) */
|
||||
#define b16ONETHOUSTH 0x00000042 /* 0.001 (actually 0.000100708..)*/
|
||||
#define b16HALFPI 0x0001921f /* 1.57078552246 */
|
||||
#define b16PI 0x0003243f /* 3.14158630371 */
|
||||
#define b16TWOPI 0x0006487b /* 6.28312683105 */
|
||||
|
||||
#define b16MAX 0x7fffffff /* Max value of b16_t */
|
||||
#define ub16MAX 0xffffffff /* Max value of ub16_t */
|
||||
#define b16MIN 0x80000000 /* Min value of b16_t */
|
||||
#define ub16MIN 0x00000000 /* Min value of ub16_t */
|
||||
|
||||
#define b32MILLION 0x000f424000000000LL /* 1000000 */
|
||||
#define b32THOUSAND 0x000003e800000000LL /* 1000 */
|
||||
#define b32HUNDRED 0x0000006400000000LL /* 100 */
|
||||
#define b32TEN 0x0000000a00000000LL /* 10 */
|
||||
#define b32ONE 0x0000000100000000LL /* 1 */
|
||||
#define b32HALF 0x0000000080000000LL /* 0.5 */
|
||||
#define b32ONETENTH 0x000000001999999aLL /* 0.1 */
|
||||
#define b32ONEHUNDRTH 0x00000000028f5c29LL /* 0.01 */
|
||||
#define b32ONETHOUSTH 0x0000000000418937LL /* 0.001 */
|
||||
#define b32ONETENTHOU 0x0000000000068db9LL /* 0.0001 */
|
||||
#define b32HALFPI 0x00000001921eb9ffLL /* 1.57078134990 */
|
||||
#define b32PI 0x00000003243f6b4fLL /* 3.14159269980 */
|
||||
#define b32TWOPI 0x00000006487ae7fdLL /* 6.28312539984 */
|
||||
|
||||
#define b32MAX 0x7fffffffffffffffLL /* Max value of b32_t */
|
||||
#define ub32MAX 0xffffffffffffffffLL /* Max value of ub32_t */
|
||||
#define b32MIN 0x8000000000000000LL /* Min value of b32_t */
|
||||
#define ub32MIN 0x0000000000000000LL /* Min value of ub32_t */
|
||||
|
||||
/* Conversions between b32, b16, and b8 *************************************/
|
||||
|
||||
#define b8tob16(b) (((b16_t)(b)) << 8)
|
||||
#define ub8toub16(b) (((ub16_t)(b)) << 8)
|
||||
#define b16tob8(b) (b8_t)(((b)+0x0080)>>8)
|
||||
#define ub16toub8(b) (ub8_t)(((b)+0x0080)>>8)
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
# define b8tob32(b) (((b32_t)(b)) << 24)
|
||||
# define ub8toub32(b) (((ub32_t)(b)) << 24)
|
||||
# define b16tob32(b) (((b32_t)(b)) << 16)
|
||||
# define ub16toub32(b) (((ub32_t)(b)) << 16)
|
||||
# define b32tob16(b) (b16_t)(((b) + 0x0000000000008000)>>16)
|
||||
# define ub32toub16(b) (ub16_t)(((b) + 0x0000000000008000)>>16)
|
||||
# define b32tob8(b) (b8_t)(((b) + 0x0000000000000080)>>8)
|
||||
#endif
|
||||
|
||||
/* 16-bit values with 8 bits of precision ***********************************/
|
||||
|
||||
/* Conversions */
|
||||
|
||||
#define b8toi(a) ((a) >> 8) /* Conversion to integer */
|
||||
#define ub8toi(a) ((a) >> 8) /* Conversion to unsigned integer */
|
||||
#define itob8(i) (((b8_t)(i)) << 8) /* Conversion from integer */
|
||||
#define uitoub8(i) (((ub8_t)(i)) << 8) /* Conversion from unsigned integer */
|
||||
#define b8tof(b) (((float)(b))/256.0f) /* Conversion to float */
|
||||
#define ftob8(f) (b8_t)(((f)*256.0f)) /* Conversion from float */
|
||||
#define b8trunc(a) ((a) & 0xff00) /* Truncate to integer b8 */
|
||||
#define b8round(a) (((a)+0x0080) & 0xff00) /* Round to integer b8 */
|
||||
#define b8frac(a) ((a) & 0x00ff) /* Take fractional part */
|
||||
|
||||
/* Operators */
|
||||
|
||||
#define ub8inv(b) (0x8000/((b)>>1)) /* Inversion (b8=b15/b7) */
|
||||
#define b8inv(b) (0x4000/((b)>>2)) /* Inversion (b8=b14/b6) */
|
||||
#define b8addb8(a,b) ((a)+(b)) /* Addition */
|
||||
#define b8addi(a,i) ((a)+itob8(i)) /* Add integer from b16 */
|
||||
#define b8subb8(a,b) ((a)-(b)) /* Subtraction */
|
||||
#define b8subi(a,i) ((a)-itob8(i)) /* Subtract integer from b8 */
|
||||
#define b8mulb8(a,b) (b16tob8((b16_t)(a)*(b16_t)(b)) /* Muliplication */
|
||||
#define ub8mulub8(a,b) (ub16toub8((ub16_t)(a)*(ub16_t)(b)) /* Muliplication */
|
||||
#define b8muli(a,i) ((a)*(i)) /* Simple multiplication by integer */
|
||||
#define b8sqr(a) b8mulb8(a,a) /* Square */
|
||||
#define ub8sqr(a) ub8mulub8(a,a) /* Square */
|
||||
#define b8divb8(a,b) (b8tob16(a)/(b16_t)(b)) /* Division */
|
||||
#define ub8divub8(a,b) (ub8toub16(a)/(ub16_t)(b)) /* Division */
|
||||
#define b8divi(a,i) ((a)/(i)) /* Simple division by integer */
|
||||
#define b8idiv(i,j) (((i)<<8)/j) /* Division of integer, b8 result */
|
||||
|
||||
/* 32-bit values with 16 bits of precision **********************************/
|
||||
|
||||
/* Conversions */
|
||||
|
||||
#define b16toi(a) ((a) >> 16) /* Conversion to integer */
|
||||
#define ub16toi(a) ((a) >> 16) /* Conversion to unsgined integer */
|
||||
#define itob16(i) (((b16_t)(i)) << 16) /* Conversion from integer */
|
||||
#define uitoub16(i) (((ub16_t)(i)) << 16) /* Conversion from unsigned integer */
|
||||
#define b16tof(b) (((float)(b))/65536.0f) /* Conversion to float */
|
||||
#define ftob16(f) (b16_t)(((f)*65536.0f)) /* Conversion from float */
|
||||
#define b16tod(b) (((double)(b))/65536.0) /* Conversion to double */
|
||||
#define dtob16(f) (b16_t)(((f)*65536.0)) /* Conversion from double */
|
||||
#define b16trunc(a) ((a) & 0xffff0000) /* Truncate to integer */
|
||||
#define b16round(a) (((a)+0x00008000) & 0xffff0000)
|
||||
#define b16frac(a) ((a) & 0x0000ffff) /* Take fractional part */
|
||||
|
||||
/* Operators */
|
||||
|
||||
#define ub16inv(b) (0x80000000/((b)>>1)) /* Inversion (b16=b31/b15) */
|
||||
#define b16inv(b) (0x40000000/((b)>>2)) /* Inversion (b16=b30/b14) */
|
||||
#define b16addb16(a,b) ((a)+(b)) /* Addition */
|
||||
#define b16addi(a,i) ((a)+itob16(i)) /* Add integer to b16 */
|
||||
#define b16subb16(a,b) ((a)-(b)) /* Subtraction */
|
||||
#define b16subi(a,i) ((a)-itob16(i)) /* Subtract integer from b16 */
|
||||
#define b16muli(a,i) ((a)*(i)) /* Simple multiplication by integer */
|
||||
#define b16divi(a,i) ((a)/(i)) /* Simple division by integer*/
|
||||
#define b16idiv(i,j) (((i)<<16)/j) /* Division of integer, b16 result */
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
/* Multiplication operators */
|
||||
|
||||
# define b16mulb16(a,b) b32tob16((b32_t)(a)*(b32_t)(b))
|
||||
# define ub16mulub16(a,b) ub32toub16((ub32_t)(a)*(ub32_t)(b))
|
||||
|
||||
/* Square operators */
|
||||
|
||||
# define b16sqr(a) b16mulb16(a,a)
|
||||
# define ub16sqr(a) ub16mulub16(a,a)
|
||||
|
||||
/* Division operators */
|
||||
|
||||
# define b16divb16(a,b) (b16_t)(b16tob32(a)/(b32_t)(b))
|
||||
# define ub16divub16(a,b) (ub16_t)(ub16toub32(a)/(ub32_t)(b))
|
||||
|
||||
/* Square root operators */
|
||||
|
||||
# define ub16sqrtub16(a) ub32sqrtub16(ub16toub32(a))
|
||||
#else
|
||||
# define ub16sqrtub16(a) ub8toub16(ub16sqrtub8(a))
|
||||
#endif
|
||||
|
||||
/* 64-bit values with 32 bits of precision **********************************/
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
/* Conversions */
|
||||
|
||||
#define b32toi(a) ((a) >> 32) /* Conversion to integer */
|
||||
#define itob32(i) (((b32_t)(i)) << 32) /* Conversion from integer */
|
||||
#define uitoub32(i) (((ub32_t)(i)) << 32) /* Conversion from unsigned integer */
|
||||
#define b32tod(b) (((double)(b))/b32ONE) /* Conversion to double */
|
||||
#define dtob32(f) (b32_t)(((f)*(double)b32ONE)) /* Conversion from double */
|
||||
#define b32trunc(a) ((a) & 0xffffffff00000000) /* Truncate to integer */
|
||||
#define b32round(a) (((a)+0x0000000080000000) & 0xffffffff00000000)
|
||||
#define b32frac(a) ((a) & 0x00000000ffffffff) /* Take fractional part */
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
typedef int16_t b8_t;
|
||||
typedef uint16_t ub8_t;
|
||||
typedef int32_t b16_t;
|
||||
typedef uint32_t ub16_t;
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
typedef int64_t b32_t;
|
||||
typedef uint64_t ub32_t;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_HAVE_LONG_LONG
|
||||
/* Multiplication operators */
|
||||
|
||||
b16_t b16mulb16(b16_t m1, b16_t m2);
|
||||
ub16_t ub16mulub16(ub16_t m1, ub16_t m2);
|
||||
|
||||
/* Square operators */
|
||||
|
||||
b16_t b16sqr(b16_t a);
|
||||
ub16_t ub16sqr(ub16_t a);
|
||||
|
||||
/* Division operators */
|
||||
|
||||
b16_t b16divb16(b16_t num, b16_t denom);
|
||||
ub16_t ub16divub16(ub16_t num, ub16_t denom);
|
||||
#endif
|
||||
|
||||
/* Trigonometric Functions */
|
||||
|
||||
b16_t b16sin(b16_t rad);
|
||||
b16_t b16cos(b16_t rad);
|
||||
b16_t b16atan2(b16_t y, b16_t x);
|
||||
|
||||
/* Square root operators */
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
ub16_t ub32sqrtub16(ub32_t a);
|
||||
#endif
|
||||
ub8_t ub16sqrtub8(ub16_t a);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_FIXEDMATH_H */
|
||||
@@ -0,0 +1,222 @@
|
||||
/****************************************************************************
|
||||
* include/ftw.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_FTW_H
|
||||
#define __INCLUDE_FTW_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/* The <ftw.h> header defines the stat structure and the symbolic names for
|
||||
* st_mode and the file type test macros as described in sys/stat.h.
|
||||
*
|
||||
* Inclusion of the <ftw.h> header may also make visible all symbols from
|
||||
* sys/stat.h.
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Macros for use as values of the third argument to the application-supplied
|
||||
* function that is passed as the second argument to ftw() and nftw():
|
||||
*/
|
||||
|
||||
#define FTW_F 0 /* File */
|
||||
#define FTW_D 1 /* Directory */
|
||||
#define FTW_DNR 2 /* Directory without read permission */
|
||||
#define FTW_DP 3 /* Directory with subdirectories visited */
|
||||
#define FTW_NS 4 /* Unknown type; stat() failed */
|
||||
#define FTW_SL 5 /* Symbolic link */
|
||||
#define FTW_SLN 6 /* Symbolic link that names a nonexistent file */
|
||||
|
||||
/* Macros for use as values of the fourth argument to nftw() */
|
||||
|
||||
#define FTW_PHYS 1 /* Physical walk, does not follow symbolic links.
|
||||
* Otherwise, nftw() follows links but does not walk
|
||||
* down any path that crosses itself. */
|
||||
#define FTW_MOUNT 2 /* The walk does not cross a mount point. */
|
||||
#define FTW_DEPTH 4 /* All subdirectories are visited before the directory
|
||||
* itself. */
|
||||
#ifndef CONFIG_DISABLE_ENVIRON
|
||||
#define FTW_CHDIR 8 /* The walk changes to each directory before reading
|
||||
* it. */
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* The fourth argument of the ftw/nftw callback is a pointer to an FTW
|
||||
* structure. The value of base is the offset of the object's filename in
|
||||
* the pathname passed as the first argument to the callback. The value of
|
||||
* level indicates depth relative to the root of the walk, where the root
|
||||
* level is 0.
|
||||
*/
|
||||
|
||||
struct FTW
|
||||
{
|
||||
int base; /* Offset of object's filename in the pathname */
|
||||
int level; /* Depth relative to the root of the walk */
|
||||
};
|
||||
|
||||
/* This is the type of the ftw callback */
|
||||
|
||||
typedef int (*ftw_cb_t)(FAR const char *path, FAR const struct stat *buf,
|
||||
int info);
|
||||
|
||||
/* This is the type of the nftw callback */
|
||||
|
||||
typedef int (*nftw_cb_t)(FAR const char *path, FAR const struct stat *buf,
|
||||
int info, FAR struct FTW *pftw);
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ftw
|
||||
*
|
||||
* Description:
|
||||
* The ftw() function will recursively descend the directory hierarchy
|
||||
* rooted in 'path'. For each object in the hierarchy, ftw() will call
|
||||
* the function pointed to by 'fn', passing it a pointer to a null-
|
||||
* terminated character string containing the name of the object, a
|
||||
* pointer to a stat structure containing information about the object,
|
||||
* and an integer that characterizes object.
|
||||
*
|
||||
* The ftw() function will visit a directory before visiting any of its
|
||||
* descendants.
|
||||
*
|
||||
* The ftw() function will use at most one file descriptor for each level
|
||||
* in the tree.
|
||||
*
|
||||
* The tree traversal will continue until either the tree is exhausted, an
|
||||
* invocation of 'fn' returns a non-zero value, or some error, other than
|
||||
* EACCES, is detected within ftw().
|
||||
*
|
||||
* When ftw() returns it will close any directory streams and file
|
||||
* descriptors it uses not counting any opened by the application-supplied
|
||||
* 'fn' function.
|
||||
*
|
||||
* The results are unspecified if the application-supplied 'fn' function
|
||||
* does not preserve the current working directory.
|
||||
*
|
||||
* The ftw() function need not be reentrant. A function that is not
|
||||
* required to be reentrant is not required to be thread-safe.
|
||||
*
|
||||
* Input Parameters:
|
||||
* path - The 'root' of the directory hierarchy to descend
|
||||
* fn - The callback function to be invoked as each object in the
|
||||
* hierarchy is encountered.
|
||||
* fdlimit - The fdlimit argument specifies the maximum number of directory
|
||||
* streams or file descriptors or both available for use by ftw()
|
||||
* while traversing the tree.The maximum depth of the directories
|
||||
* to visit. The fdlimit argument should be in the range [1,
|
||||
* {OPEN_MAX}].
|
||||
*
|
||||
* Returned Value:
|
||||
* If the tree is exhausted, ftw() will return 0. If the function pointed
|
||||
* to by fn returns a non-zero value, ftw() will stop its tree traversal
|
||||
* and return whatever value was returned by the function pointed to by
|
||||
* 'fn'. If ftw() detects an error, it will return -1 and set errno to
|
||||
* indicate the error.
|
||||
*
|
||||
* If ftw() encounters an error other than EACCES (see FTW_DNR and FTW_NS),
|
||||
* it will return -1 and set errno to indicate the error. The external
|
||||
* variable errno may contain any error value that is possible when a
|
||||
* directory is opened or when one of the stat functions is executed on a
|
||||
* directory or file.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int ftw(FAR const char *path, ftw_cb_t fn, int fdlimit);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nftw
|
||||
*
|
||||
* Description:
|
||||
* The nftw() function will recursively descend the directory hierarchy
|
||||
* rooted in 'path'. The nftw() function has a similar effect to ftw()
|
||||
* except that it takes an additional argument 'flags'
|
||||
*
|
||||
* Input Parameters:
|
||||
*
|
||||
* path - The 'root' of the directory hierarchy to descend
|
||||
* fn - The callback function to be invoked as each object in the
|
||||
* hierarchy is encountered.
|
||||
* fdlimit - The fdlimit argument specifies the maximum number of directory
|
||||
* streams or file descriptors or both available for use by
|
||||
* nftw() while traversing the tree.The maximum depth of the
|
||||
* directories to visit. The fdlimit argument should be in the
|
||||
* range [1, {OPEN_MAX}].
|
||||
* flags - A bitwise-inclusive OR of zero or more of the following flags:
|
||||
*
|
||||
* FTW_CHDIR
|
||||
* If set, nftw() will change the current working directory to each
|
||||
* directory as it reports files in that directory. If clear, nftw()
|
||||
* will not change the current working directory.
|
||||
* FTW_DEPTH
|
||||
* If set, nftw() will report all files in a directory before
|
||||
* reporting the directory itself. If clear, nftw() will report any
|
||||
* directory before reporting the files in that directory.
|
||||
* FTW_MOUNT
|
||||
* If set, nftw() will only report files in the same file system as
|
||||
* path. If clear, nftw() will report all files encountered during
|
||||
* the walk.
|
||||
* FTW_PHYS
|
||||
* If set, nftw() will perform a physical walk and will not follow
|
||||
* symbolic links.
|
||||
*
|
||||
* Returned Value:
|
||||
* If the tree is exhausted, nftw() will return 0. If the function pointed
|
||||
* to by fn returns a non-zero value, nftw() will stop its tree traversal
|
||||
* and return whatever value was returned by the function pointed to by
|
||||
* 'fn'. If nftw() detects an error, it will return -1 and set errno to
|
||||
* indicate the error.
|
||||
*
|
||||
* If nftw() encounters an error other than EACCES (see FTW_DNR and
|
||||
* FTW_NS), it will return -1 and set errno to indicate the error. The
|
||||
* external variable errno may contain any error value that is possible
|
||||
* when a directory is opened or when one of the stat functions is
|
||||
* executed on a directory or file.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int nftw(FAR const char *path, nftw_cb_t fn, int fdlimit, int flags);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_FTW_H */
|
||||
@@ -0,0 +1,104 @@
|
||||
/****************************************************************************
|
||||
* include/getopt.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_GETOPT_H
|
||||
#define __INCLUDE_GETOPT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define no_argument 0
|
||||
#define required_argument 1
|
||||
#define optional_argument 2
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
struct option
|
||||
{
|
||||
FAR const char *name;
|
||||
int has_arg;
|
||||
FAR int *flag;
|
||||
int val;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: getopt_long
|
||||
*
|
||||
* Description:
|
||||
* The getopt_long() function works like getopt() except that it also
|
||||
* accepts long options, started with two dashes. (If the program accepts
|
||||
* only long options, then optstring should be specified as an empty
|
||||
* string (""), not NULL.) Long option names may be abbreviated if the
|
||||
* abbreviation is unique or is an exact match for some defined option
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int getopt_long(int argc, FAR char * const argv[],
|
||||
FAR const char *optstring,
|
||||
FAR const struct option *longopts,
|
||||
FAR int *longindex);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: getopt_long_only
|
||||
*
|
||||
* Description:
|
||||
* getopt_long_only() is like getopt_long(), but '-' as well as "--" can
|
||||
* indicate a long option. If an option that starts with '-' (not "--")
|
||||
* doesn't match a long option, but does match a short option, it is
|
||||
* parsed as a short option instead.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int getopt_long_only(int argc, FAR char * const argv[],
|
||||
FAR const char *optstring,
|
||||
FAR const struct option *longopts,
|
||||
FAR int *longindex);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_GETOPT_H */
|
||||
@@ -0,0 +1,79 @@
|
||||
/****************************************************************************
|
||||
* include/grp.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_GRP_H
|
||||
#define __INCLUDE_GRP_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
struct group
|
||||
{
|
||||
FAR char *gr_name;
|
||||
FAR char *gr_passwd;
|
||||
gid_t gr_gid;
|
||||
FAR char **gr_mem;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
FAR struct group *getgrnam(FAR const char *name);
|
||||
FAR struct group *getgrgid(gid_t gid);
|
||||
int getgrnam_r(FAR const char *name,
|
||||
FAR struct group *grp,
|
||||
FAR char *buf,
|
||||
size_t buflen,
|
||||
FAR struct group **result);
|
||||
int getgrgid_r(gid_t gid, FAR struct group *grp,
|
||||
FAR char *buf, size_t buflen,
|
||||
FAR struct group **result);
|
||||
int initgroups(FAR const char *user, gid_t group);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_GRP_H */
|
||||
@@ -0,0 +1,230 @@
|
||||
/****************************************************************************
|
||||
* include/hex2bin.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_HEX2BIN_H
|
||||
#define __INCLUDE_HEX2BIN_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef CONFIG_LIB_HEX2BIN
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Some environments may return CR as end-of-line, others LF, and others
|
||||
* both. If not specified, the logic here assumes either (but not both) as
|
||||
* the default.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_EOL_IS_CR)
|
||||
# undef CONFIG_EOL_IS_LF
|
||||
# undef CONFIG_EOL_IS_BOTH_CRLF
|
||||
# undef CONFIG_EOL_IS_EITHER_CRLF
|
||||
#elif defined(CONFIG_EOL_IS_LF)
|
||||
# undef CONFIG_EOL_IS_CR
|
||||
# undef CONFIG_EOL_IS_BOTH_CRLF
|
||||
# undef CONFIG_EOL_IS_EITHER_CRLF
|
||||
#elif defined(CONFIG_EOL_IS_BOTH_CRLF)
|
||||
# undef CONFIG_EOL_IS_CR
|
||||
# undef CONFIG_EOL_IS_LF
|
||||
# undef CONFIG_EOL_IS_EITHER_CRLF
|
||||
#elif defined(CONFIG_EOL_IS_EITHER_CRLF)
|
||||
# undef CONFIG_EOL_IS_CR
|
||||
# undef CONFIG_EOL_IS_LF
|
||||
# undef CONFIG_EOL_IS_BOTH_CRLF
|
||||
#else
|
||||
# undef CONFIG_EOL_IS_CR
|
||||
# undef CONFIG_EOL_IS_LF
|
||||
# undef CONFIG_EOL_IS_BOTH_CRLF
|
||||
# define CONFIG_EOL_IS_EITHER_CRLF 1
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Intel HEX data streams are normally in big endian order. The following
|
||||
* enumeration selects other ordering.
|
||||
*/
|
||||
|
||||
enum hex2bin_swap_e
|
||||
{
|
||||
HEX2BIN_NOSWAP = 0, /* No swap, stream is in the correct byte order */
|
||||
HEX2BIN_SWAP16 = 1, /* Swap bytes in 16-bit values */
|
||||
HEX2BIN_SWAP32 = 2 /* Swap bytes in 32-bit values */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hex2bin
|
||||
*
|
||||
* Description:
|
||||
* Read the Intel HEX ASCII data provided on the serial IN stream and write
|
||||
* the binary to the seek-able serial OUT stream.
|
||||
*
|
||||
* These streams may be files or, in another usage example, the IN stream
|
||||
* could be a serial port and the OUT stream could be a memory stream.
|
||||
* This would decode and write the serial input to memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* instream - The incoming stream from which Intel HEX data will be
|
||||
* received.
|
||||
* outstream - The outgoing stream in which binary data will be written.
|
||||
* baseaddr - The base address of the outgoing stream. Seeking in the
|
||||
* output stream will be relative to this address.
|
||||
* endpaddr - The end address (plus 1) of the outgoing stream. This
|
||||
* value is used only for range checking. endpaddr must
|
||||
* be larger than baseaddr. A zero value for endpaddr
|
||||
* disables range checking.
|
||||
* swap - Controls byte ordering. See enum hex2bin_swap_e for
|
||||
* description of the values.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct lib_instream_s;
|
||||
struct lib_sostream_s;
|
||||
int hex2bin(FAR struct lib_instream_s *instream,
|
||||
FAR struct lib_sostream_s *outstream, uint32_t baseaddr,
|
||||
uint32_t endpaddr, enum hex2bin_swap_e swap);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hex2mem
|
||||
*
|
||||
* Description:
|
||||
* Read the Intel HEX ASCII data provided on the file descriptor 'fd' and
|
||||
* write the binary to memory.
|
||||
*
|
||||
* If, for example, fd is zero (corresponding to stdin), then the HEX
|
||||
* ASCII data would be taken from the console and written to memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fd - The file descriptor from which Intel HEX data will be
|
||||
* received.
|
||||
* baseaddr - The base address of the memory region stream.
|
||||
* endpaddr - The end address (plus 1) of the memory region.
|
||||
* swap - Controls byte ordering. See enum hex2bin_swap_e for
|
||||
* description of the values.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int hex2mem(int fd, uint32_t baseaddr, uint32_t endpaddr,
|
||||
enum hex2bin_swap_e swap);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fhex2mem
|
||||
*
|
||||
* Description:
|
||||
* Read the Intel HEX ASCII data provided on the standard stream
|
||||
* 'instream' and write the binary to memory.
|
||||
*
|
||||
* If, for example, instream is stdin, then the HEX ASCII data would be
|
||||
* taken from the console and written to memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* instream - The incoming standard stream from which Intel HEX data
|
||||
* will be received.
|
||||
* baseaddr - The base address of the memory region stream.
|
||||
* endpaddr - The end address (plus 1) of the memory region.
|
||||
* swap - Controls byte ordering. See enum hex2bin_swap_e for
|
||||
* description of the values.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int fhex2mem(FAR FILE *instream, uint32_t baseaddr, uint32_t endpaddr,
|
||||
enum hex2bin_swap_e swap);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hex2bin_main
|
||||
*
|
||||
* Description:
|
||||
* Main entry point when hex2bin is built as an NSH built-in task.
|
||||
*
|
||||
* Input Parameters:
|
||||
* Standard task inputs
|
||||
*
|
||||
* Returned Value:
|
||||
* EXIT_SUCCESS on success; EXIT_FAILURE on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SYSTEM_HEX2BIN_BUILTIN
|
||||
int hex2bin_main(int argc, char **argv);
|
||||
#endif /* CONFIG_SYSTEM_HEX2BIN_BUILTIN */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: hex2mem_main
|
||||
*
|
||||
* Description:
|
||||
* Main entry point when hex2mem is built as an NSH built-in task.
|
||||
*
|
||||
* Input Parameters:
|
||||
* Standard task inputs
|
||||
*
|
||||
* Returned Value:
|
||||
* EXIT_SUCCESS on success; EXIT_FAILURE on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SYSTEM_HEX2MEM_BUILTIN
|
||||
int hex2mem_main(int argc, char **argv);
|
||||
#endif /* CONFIG_SYSTEM_HEX2MEM_BUILTIN */
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_SYSTEM_HEX2BIN */
|
||||
#endif /* __INCLUDE_HEX2BIN_H */
|
||||
@@ -0,0 +1,352 @@
|
||||
/****************************************************************************
|
||||
* include/inttypes.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_INTTYPES_H
|
||||
#define __INCLUDE_INTTYPES_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stddef.h> /* for wchar_t */
|
||||
|
||||
/* Notes from www.opengroup.org:
|
||||
*
|
||||
* "The <inttypes.h> header shall include the <stdint.h> header."
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <arch/inttypes.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* "The following macros shall be defined. Each expands to a character string
|
||||
* literal containing a conversion specifier, possibly modified by a length
|
||||
* modifier, suitable for use within the format argument of a formatted
|
||||
* input/output function when converting the corresponding integer type.
|
||||
* These macros have the general form of PRI (character string literals for
|
||||
* the fprintf() and fwprintf() family of functions) or SCN (character
|
||||
* string literals for the fscanf() and fwscanf() family of functions),
|
||||
* followed by the conversion specifier, followed by a name corresponding
|
||||
* to a similar type name in <stdint.h>. In these names, N represents the
|
||||
* width of the type as described in <stdint.h>. For example, PRIdFAST32
|
||||
* can be used in a format string to print the value of an integer of type
|
||||
* int_fast32_t.
|
||||
*
|
||||
* "The fprintf() macros for signed integers are:
|
||||
*
|
||||
* PRIdN
|
||||
* PRIdLEASTN
|
||||
* PRIdFASTN
|
||||
* PRIdMAX
|
||||
* PRIdPTR
|
||||
*
|
||||
* PRIiN
|
||||
* PRIiLEASTN
|
||||
* PRIiFASTN
|
||||
* PRIiMAX
|
||||
* PRIiPTR
|
||||
*
|
||||
* "The fprintf() macros for unsigned integers are:
|
||||
*
|
||||
* PRIoN
|
||||
* PRIoLEASTN
|
||||
* PRIoFASTN
|
||||
* PRIoMAX
|
||||
* PRIoPTR
|
||||
*
|
||||
* PRIuN
|
||||
* PRIuLEASTN
|
||||
* PRIuFASTN
|
||||
* PRIuMAX
|
||||
* PRIuPTR
|
||||
*
|
||||
* PRIxN
|
||||
* PRIxLEASTN
|
||||
* PRIxFASTN
|
||||
* PRIxMAX
|
||||
* PRIxPTR
|
||||
*
|
||||
* PRIXN
|
||||
* PRIXLEASTN
|
||||
* PRIXFASTN
|
||||
* PRIXMAX
|
||||
* PRIXPTR
|
||||
*
|
||||
* "The fscanf() macros for signed integers are:
|
||||
*
|
||||
* SCNdN
|
||||
* SCNdLEASTN
|
||||
* SCNdFASTN
|
||||
* SCNdMAX
|
||||
* SCNdPTR
|
||||
*
|
||||
* SCNiN
|
||||
* SCNiLEASTN
|
||||
* SCNiFASTN
|
||||
* SCNiMAX
|
||||
* SCNiPTR
|
||||
*
|
||||
* "The fscanf() macros for unsigned integers are:
|
||||
*
|
||||
* SCNoN
|
||||
* SCNoLEASTN
|
||||
* SCNoFASTN
|
||||
* SCNoMAX
|
||||
* SCNoPTR
|
||||
*
|
||||
* SCNuN
|
||||
* SCNuLEASTN
|
||||
* SCNuFASTN
|
||||
* SCNuMAX
|
||||
* SCNuPTR
|
||||
*
|
||||
* SCNxN
|
||||
* SCNxLEASTN
|
||||
* SCNxFASTN
|
||||
* SCNxMAX
|
||||
* SCNxPTR
|
||||
*
|
||||
* "For each type that the implementation provides in <stdint.h>, the
|
||||
* corresponding fprintf() and fwprintf() macros shall be defined and the
|
||||
* corresponding fscanf() and fwscanf() macros shall be defined unless the
|
||||
* implementation does not have a suitable modifier for the type.
|
||||
*/
|
||||
|
||||
/* On NuttX, least and fast types are aliases of the exact type.
|
||||
* (See stdint.h)
|
||||
*/
|
||||
|
||||
#define PRIdLEAST8 PRId8
|
||||
#define PRIdLEAST16 PRId16
|
||||
#define PRIdLEAST32 PRId32
|
||||
#if defined(PRId64)
|
||||
#define PRIdLEAST64 PRId64
|
||||
#endif
|
||||
|
||||
#define PRIdFAST8 PRId8
|
||||
#define PRIdFAST16 PRId16
|
||||
#define PRIdFAST32 PRId32
|
||||
#if defined(PRId64)
|
||||
#define PRIdFAST64 PRId64
|
||||
#endif
|
||||
|
||||
#define PRIiLEAST8 PRIi8
|
||||
#define PRIiLEAST16 PRIi16
|
||||
#define PRIiLEAST32 PRIi32
|
||||
#if defined(PRIi64)
|
||||
#define PRIiLEAST64 PRIi64
|
||||
#endif
|
||||
|
||||
#define PRIiFAST8 PRIi8
|
||||
#define PRIiFAST16 PRIi16
|
||||
#define PRIiFAST32 PRIi32
|
||||
#if defined(PRIi64)
|
||||
#define PRIiFAST64 PRIi64
|
||||
#endif
|
||||
|
||||
#define PRIoLEAST8 PRIo8
|
||||
#define PRIoLEAST16 PRIo16
|
||||
#define PRIoLEAST32 PRIo32
|
||||
#if defined(PRIo64)
|
||||
#define PRIoLEAST64 PRIo64
|
||||
#endif
|
||||
|
||||
#define PRIoFAST8 PRIo8
|
||||
#define PRIoFAST16 PRIo16
|
||||
#define PRIoFAST32 PRIo32
|
||||
#if defined(PRIo64)
|
||||
#define PRIoFAST64 PRIo64
|
||||
#endif
|
||||
|
||||
#define PRIuLEAST8 PRIu8
|
||||
#define PRIuLEAST16 PRIu16
|
||||
#define PRIuLEAST32 PRIu32
|
||||
#if defined(PRIu64)
|
||||
#define PRIuLEAST64 PRIu64
|
||||
#endif
|
||||
|
||||
#define PRIuFAST8 PRIu8
|
||||
#define PRIuFAST16 PRIu16
|
||||
#define PRIuFAST32 PRIu32
|
||||
#if defined(PRIu64)
|
||||
#define PRIuFAST64 PRIu64
|
||||
#endif
|
||||
|
||||
#define PRIxLEAST8 PRIx8
|
||||
#define PRIxLEAST16 PRIx16
|
||||
#define PRIxLEAST32 PRIx32
|
||||
#if defined(PRIx64)
|
||||
#define PRIxLEAST64 PRIx64
|
||||
#endif
|
||||
|
||||
#define PRIxFAST8 PRIx8
|
||||
#define PRIxFAST16 PRIx16
|
||||
#define PRIxFAST32 PRIx32
|
||||
#if defined(PRIx64)
|
||||
#define PRIxFAST64 PRIx64
|
||||
#endif
|
||||
|
||||
#define PRIXLEAST8 PRIX8
|
||||
#define PRIXLEAST16 PRIX16
|
||||
#define PRIXLEAST32 PRIX32
|
||||
#if defined(PRIX64)
|
||||
#define PRIXLEAST64 PRIX64
|
||||
#endif
|
||||
|
||||
#define PRIXFAST8 PRIX8
|
||||
#define PRIXFAST16 PRIX16
|
||||
#define PRIXFAST32 PRIX32
|
||||
#if defined(PRIX64)
|
||||
#define PRIXFAST64 PRIX64
|
||||
#endif
|
||||
|
||||
#define SCNdLEAST8 SCNd8
|
||||
#define SCNdLEAST16 SCNd16
|
||||
#define SCNdLEAST32 SCNd32
|
||||
#if defined(SCNd64)
|
||||
#define SCNdLEAST64 SCNd64
|
||||
#endif
|
||||
|
||||
#define SCNdFAST8 SCNd8
|
||||
#define SCNdFAST16 SCNd16
|
||||
#define SCNdFAST32 SCNd32
|
||||
#if defined(SCNd64)
|
||||
#define SCNdFAST64 SCNd64
|
||||
#endif
|
||||
|
||||
#define SCNiLEAST8 SCNi8
|
||||
#define SCNiLEAST16 SCNi16
|
||||
#define SCNiLEAST32 SCNi32
|
||||
#if defined(SCNi64)
|
||||
#define SCNiLEAST64 SCNi64
|
||||
#endif
|
||||
|
||||
#define SCNiFAST8 SCNi8
|
||||
#define SCNiFAST16 SCNi16
|
||||
#define SCNiFAST32 SCNi32
|
||||
#if defined(SCNi64)
|
||||
#define SCNiFAST64 SCNi64
|
||||
#endif
|
||||
|
||||
#define SCNoLEAST8 SCNo8
|
||||
#define SCNoLEAST16 SCNo16
|
||||
#define SCNoLEAST32 SCNo32
|
||||
#if defined(SCNo64)
|
||||
#define SCNoLEAST64 SCNo64
|
||||
#endif
|
||||
|
||||
#define SCNoFAST8 SCNo8
|
||||
#define SCNoFAST16 SCNo16
|
||||
#define SCNoFAST32 SCNo32
|
||||
#if defined(SCNo64)
|
||||
#define SCNoFAST64 SCNo64
|
||||
#endif
|
||||
|
||||
#define SCNuLEAST8 SCNu8
|
||||
#define SCNuLEAST16 SCNu16
|
||||
#define SCNuLEAST32 SCNu32
|
||||
#if defined(SCNu64)
|
||||
#define SCNuLEAST64 SCNu64
|
||||
#endif
|
||||
|
||||
#define SCNuFAST8 SCNu8
|
||||
#define SCNuFAST16 SCNu16
|
||||
#define SCNuFAST32 SCNu32
|
||||
#if defined(SCNu64)
|
||||
#define SCNuFAST64 SCNu64
|
||||
#endif
|
||||
|
||||
#define SCNxLEAST8 SCNx8
|
||||
#define SCNxLEAST16 SCNx16
|
||||
#define SCNxLEAST32 SCNx32
|
||||
#if defined(SCNx64)
|
||||
#define SCNxLEAST64 SCNx64
|
||||
#endif
|
||||
|
||||
#define SCNxFAST8 SCNx8
|
||||
#define SCNxFAST16 SCNx16
|
||||
#define SCNxFAST32 SCNx32
|
||||
#if defined(SCNx64)
|
||||
#define SCNxFAST64 SCNx64
|
||||
#endif
|
||||
|
||||
/* intmax_t/uintmax_t */
|
||||
|
||||
#define PRIdMAX "jd"
|
||||
#define PRIiMAX "ji"
|
||||
#define PRIoMAX "jo"
|
||||
#define PRIuMAX "ju"
|
||||
#define PRIxMAX "jx"
|
||||
#define PRIXMAX "jX"
|
||||
|
||||
#define SCNdMAX "jd"
|
||||
#define SCNiMAX "ji"
|
||||
#define SCNoMAX "jo"
|
||||
#define SCNuMAX "ju"
|
||||
#define SCNxMAX "jx"
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* "The <inttypes.h> header shall include a definition of at least the
|
||||
* following type:
|
||||
*
|
||||
* imaxdiv_t
|
||||
* Structure type that is the type of the value returned by the imaxdiv()
|
||||
* function.
|
||||
*/
|
||||
|
||||
typedef void *imaxdiv_t; /* Dummy type since imaxdiv is not yet supported */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* "The following shall be declared as functions and may also be defined as
|
||||
* macros. Function prototypes shall be provided."
|
||||
*/
|
||||
|
||||
intmax_t imaxabs(intmax_t j);
|
||||
imaxdiv_t imaxdiv(intmax_t number, intmax_t denom);
|
||||
intmax_t strtoimax(FAR const char *nptr, FAR char **endptr, int base);
|
||||
uintmax_t strtoumax(FAR const char *nptr, FAR char **endptr, int base);
|
||||
|
||||
intmax_t wcstoimax(FAR const wchar_t *nptr, FAR wchar_t **endptr, int base);
|
||||
uintmax_t wcstoumax(FAR const wchar_t *nptr, FAR wchar_t **endptr, int base);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_INTTYPES_H */
|
||||
@@ -0,0 +1,71 @@
|
||||
/****************************************************************************
|
||||
* include/iso646.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_ISO646_H
|
||||
#define __INCLUDE_ISO646_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* The <iso646.h> header shall define the following eleven macros
|
||||
* (on the left) that expand to the corresponding tokens (on the right):
|
||||
*
|
||||
* and &&
|
||||
* and_eq &=
|
||||
* bitand &
|
||||
* bitor |
|
||||
* compl ~
|
||||
* not !
|
||||
* not_eq !=
|
||||
* or ||
|
||||
* or_eq |=
|
||||
* xor ^
|
||||
* xor_eq ^=
|
||||
*
|
||||
* Reference: Opengroup.org
|
||||
*/
|
||||
|
||||
#define and &&
|
||||
#define and_eq &=
|
||||
#define bitand &
|
||||
#define bitor |
|
||||
#define compl ~
|
||||
#define not !
|
||||
#define not_eq !=
|
||||
#define or ||
|
||||
#define or_eq |=
|
||||
#define xor ^
|
||||
#define xor_eq ^=
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_ISO646_H */
|
||||
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
* include/libgen.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_LIBGEN_H
|
||||
#define __INCLUDE_LIBGEN_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
FAR char *basename(FAR char *path);
|
||||
FAR char *dirname(FAR char *path);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_LIBGEN_H */
|
||||
@@ -0,0 +1,305 @@
|
||||
/********************************************************************************
|
||||
* include/limits.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_LIMITS_H
|
||||
#define __INCLUDE_LIMITS_H
|
||||
|
||||
/********************************************************************************
|
||||
* Included Files
|
||||
********************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/* Architecture specific limits */
|
||||
|
||||
#include <arch/limits.h>
|
||||
|
||||
/********************************************************************************
|
||||
* Pre-processor Definitions
|
||||
********************************************************************************/
|
||||
|
||||
/* Default values for user configurable limits **********************************/
|
||||
|
||||
/* Maximum number of bytes in a filename (not including terminating null). */
|
||||
|
||||
#ifndef CONFIG_NAME_MAX
|
||||
# define CONFIG_NAME_MAX 32
|
||||
#endif
|
||||
|
||||
/* Maximum number of bytes in a pathname, including the terminating null
|
||||
* character.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_PATH_MAX
|
||||
# if CONFIG_NAME_MAX < 64
|
||||
# define CONFIG_PATH_MAX (4*CONFIG_NAME_MAX + 1)
|
||||
# else
|
||||
# define CONFIG_PATH_MAX 256
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Maximum length of any multibyte character in any locale.
|
||||
* We define this value here since the gcc header does not define
|
||||
* the correct value.
|
||||
*/
|
||||
|
||||
#define MB_LEN_MAX 1
|
||||
|
||||
/* Configurable limits required by POSIX ****************************************
|
||||
*
|
||||
* Required for all implementations:
|
||||
*
|
||||
* _POSIX_ARG_MAX Total length of string arguments
|
||||
* _POSIX_CHILD_MAX Number of child tasks active
|
||||
* _POSIX_LINK_MAX The number of links a file can have
|
||||
* _POSIX_MAX_CANON Number bytes in TTY canonical input queue
|
||||
* _POSIX_MAX_INPUT Number bytes in TTY canonical input queue
|
||||
* _POSIX_NAME_MAX Number of bytes in a file or pathname component
|
||||
* _POSIX_NGROUPS_MAX Number supplementary group IDs
|
||||
* _POSIX_OPEN_MAX Number of files a task can have open at once
|
||||
* _POSIX_PATH_MAX Number of bytes in a full pathname (including NULL)
|
||||
* _POSIX_PIPE_BUF Number of bytes for atomic write into pipe
|
||||
* _POSIX_SSIZE_MAX Largest filesystem write; also max value of ssize_t
|
||||
* _POSIX_STREAM_MAX Number of std I/O streams open at once
|
||||
* _POSIX_TZNAME_MAX Max number of bytes of a timezone name
|
||||
*
|
||||
* Required for sigqueue
|
||||
*
|
||||
* _POSIX_RTSIG_MAX Difference between SIGRTMIN and SIGRTMAX
|
||||
* _POSIX_SIGQUEUE_MAX Max number signals a task can queue
|
||||
*
|
||||
* Required for POSIX timers
|
||||
*
|
||||
* _POSIX_DELAYTIMER_MAX Max number timer overruns
|
||||
* _POSIX_TIMER_MAX Max number of timers per task
|
||||
* _POSIX_CLOCKRES_MIN Clock resolution in nanoseconds
|
||||
*
|
||||
* Required for asynchronous I/O
|
||||
*
|
||||
* _POSIX_AIO_LISTIO_MAX Max number of AIOs in single listio call
|
||||
* _POSIX_AIO_MAX Max number of simultaneous AIO operations
|
||||
*
|
||||
* Required for POSIX message passing
|
||||
*
|
||||
* _POSIX_MQ_OPEN_MAX Max number message queues task may open (mq_open)
|
||||
* _POSIX_MQ_PRIO_MAX Max message priority (mq_send)
|
||||
*
|
||||
* Required for POSIX semaphores
|
||||
*
|
||||
* _POSIX_SEM_NSEMS_MAX Max number of open semaphores per task
|
||||
* _POSIX_SEM_VALUE_MAX Max value a semaphore may have
|
||||
*
|
||||
* Required for symbolic links
|
||||
* _POSIX_SYMLOOP_MAX Maximum number of symbolic links that can be
|
||||
* reliably traversed in the resolution of a pathname
|
||||
* in the absence of a loop.
|
||||
*
|
||||
*/
|
||||
|
||||
#define _POSIX_ARG_MAX 4096
|
||||
#define _POSIX_CHILD_MAX 6
|
||||
#define _POSIX_LINK_MAX 8
|
||||
#define _POSIX_MAX_CANON 255
|
||||
#define _POSIX_MAX_INPUT 255
|
||||
#define _POSIX_NAME_MAX CONFIG_NAME_MAX
|
||||
#define _POSIX_NGROUPS_MAX 0
|
||||
#define _POSIX_OPEN_MAX 16
|
||||
#define _POSIX_PATH_MAX CONFIG_PATH_MAX
|
||||
#define _POSIX_PIPE_BUF 512
|
||||
#define _POSIX_STREAM_MAX 16
|
||||
#define _POSIX_TZNAME_MAX 3
|
||||
|
||||
#ifdef CONFIG_SMALL_MEMORY
|
||||
|
||||
#define _POSIX_SIZE_MAX 65535 /* See sys/types.h */
|
||||
#define _POSIX_SIZE_MIN 0
|
||||
|
||||
#define _POSIX_SSIZE_MAX 32767 /* See sys/types.h */
|
||||
#define _POSIX_SSIZE_MIN -32768
|
||||
|
||||
#else /* CONFIG_SMALL_MEMORY */
|
||||
|
||||
#define _POSIX_SIZE_MAX 4294967295UL /* See sys/types.h */
|
||||
#define _POSIX_SIZE_MIN 0
|
||||
|
||||
#define _POSIX_SSIZE_MAX 2147483647L /* See sys/types.h */
|
||||
#define _POSIX_SSIZE_MIN -2147483648L
|
||||
|
||||
#endif /* CONFIG_SMALL_MEMORY */
|
||||
|
||||
/* Required for sigqueue */
|
||||
|
||||
#define _POSIX_RTSIG_MAX 31
|
||||
#define _POSIX_SIGQUEUE_MAX 32
|
||||
|
||||
/* Required for symbolic links */
|
||||
|
||||
#define _POSIX_SYMLOOP_MAX 8
|
||||
|
||||
/* Required for POSIX timers.
|
||||
*
|
||||
* _POSIX_DELAYTIMER_MAX is the number of timer expiration overruns.
|
||||
*
|
||||
* _POSIX_TIMER_MAX is the per-process number of timers.
|
||||
*
|
||||
* _POSIX_CLOCKRES_MIN is the resolution of the CLOCK_REALTIME clock in
|
||||
* nanoseconds. CLOCK_REALTIME is controlled by the NuttX system time.
|
||||
* The default value is the system timer which has a resolution of 1000
|
||||
* microseconds. This default setting can be overridden by defining the
|
||||
* clock interval in microseconds as CONFIG_USEC_PER_TICK in the NuttX
|
||||
* configuration file.
|
||||
*/
|
||||
|
||||
#define _POSIX_DELAYTIMER_MAX 32
|
||||
#define _POSIX_TIMER_MAX 32
|
||||
|
||||
#ifdef CONFIG_USEC_PER_TICK
|
||||
# define _POSIX_CLOCKRES_MIN ((CONFIG_USEC_PER_TICK)*1000)
|
||||
#else
|
||||
# define _POSIX_CLOCKRES_MIN (10*1000000)
|
||||
#endif
|
||||
|
||||
/* Required for asynchronous I/O */
|
||||
|
||||
#define _POSIX_AIO_LISTIO_MAX 2
|
||||
#define _POSIX_AIO_MAX 1
|
||||
|
||||
/* Required for POSIX message passing */
|
||||
|
||||
#define _POSIX_MQ_OPEN_MAX 8
|
||||
#define _POSIX_MQ_PRIO_MAX UCHAR_MAX
|
||||
|
||||
/* Required for POSIX semaphores */
|
||||
|
||||
#define _POSIX_SEM_NSEMS_MAX INT_MAX
|
||||
#define _POSIX_SEM_VALUE_MAX 0x7fff
|
||||
|
||||
/* Numerical limits. These values may be increased from the POSIX minimum
|
||||
* values above or made indeterminate
|
||||
*/
|
||||
|
||||
#define ARG_MAX _POSIX_ARG_MAX
|
||||
#define CHILD_MAX _POSIX_CHILD_MAX
|
||||
#define LINK_MAX _POSIX_LINK_MAX
|
||||
#define MAX_CANON _POSIX_MAX_CANON
|
||||
#define MAX_INPUT _POSIX_MAX_INPUT
|
||||
#define NAME_MAX _POSIX_NAME_MAX
|
||||
#define NGROUPS_MAX _POSIX_NGROUPS_MAX
|
||||
#define OPEN_MAX _POSIX_OPEN_MAX
|
||||
#define PATH_MAX _POSIX_PATH_MAX
|
||||
#define PIPE_BUF _POSIX_PIPE_BUF
|
||||
#define SIZE_MAX _POSIX_SIZE_MAX
|
||||
#define SIZE_MIN _POSIX_SIZE_MIN
|
||||
#define RSIZE_MAX _POSIX_SIZE_MAX
|
||||
#define SSIZE_MAX _POSIX_SSIZE_MAX
|
||||
#define SSIZE_MIN _POSIX_SSIZE_MIN
|
||||
#define STREAM_MAX _POSIX_STREAM_MAX
|
||||
#define TZNAME_MAX _POSIX_TZNAME_MAX
|
||||
#define TZ_MAX_TIMES CONFIG_LIBC_TZ_MAX_TIMES
|
||||
#define TZ_MAX_TYPES CONFIG_LIBC_TZ_MAX_TYPES
|
||||
|
||||
#define RTSIG_MAX _POSIX_RTSIG_MAX
|
||||
#define SIGQUEUE_MAX _POSIX_SIGQUEUE_MAX
|
||||
|
||||
#define SYMLOOP_MAX _POSIX_SYMLOOP_MAX
|
||||
|
||||
#define DELAYTIMER_MAX _POSIX_DELAYTIMER_MAX
|
||||
#define TIMER_MAX _POSIX_TIMER_MAX
|
||||
#define CLOCKRES_MIN _POSIX_CLOCKRES_MIN
|
||||
|
||||
/* Other invariant values */
|
||||
|
||||
/* CHARCLASS_NAME_MAX
|
||||
* Maximum number of bytes in a character class name. Minimum Acceptable
|
||||
* Value: 14
|
||||
*/
|
||||
|
||||
#define CHARCLASS_NAME_MAX 14
|
||||
|
||||
/* Maximum value of digit in calls to the printf() and scanf() functions.
|
||||
* Minimum Acceptable Value: 9
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_LIBC_NUMBERED_ARGS
|
||||
# ifdef CONFIG_LIBC_NL_ARGMAX
|
||||
# define NL_ARGMAX CONFIG_LIBC_NL_ARGMAX
|
||||
# else
|
||||
# define NL_ARGMAX 9
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* NL_LANGMAX
|
||||
* Maximum number of bytes in a LANG name. Minimum Acceptable Value: 14
|
||||
*/
|
||||
|
||||
#define NL_LANGMAX 14
|
||||
|
||||
/* NL_MSGMAX
|
||||
* Maximum message number. Minimum Acceptable Value: 32 67
|
||||
*/
|
||||
|
||||
#define NL_MSGMAX 32767
|
||||
|
||||
/* NL_NMAX
|
||||
* Maximum number of bytes in an N-to-1 collation mapping. Minimum
|
||||
* Acceptable Value: *
|
||||
*/
|
||||
|
||||
/* NL_SETMAX
|
||||
* Maximum set number. Minimum Acceptable Value: 255
|
||||
*/
|
||||
|
||||
#define NL_SETMAX 255
|
||||
|
||||
/* NL_TEXTMAX
|
||||
* Maximum number of bytes in a message string. Minimum Acceptable Value:
|
||||
* _POSIX2_LINE_MAX
|
||||
*/
|
||||
|
||||
#define NL_TEXTMAX _POSIX2_LINE_MAX
|
||||
|
||||
/* NZERO
|
||||
* Default process priority. Minimum Acceptable Value: 20
|
||||
*/
|
||||
|
||||
#define NZERO 20
|
||||
|
||||
/* Required for asynchronous I/O */
|
||||
|
||||
#define AIO_LISTIO_MAX _POSIX_AIO_LISTIO_MAX
|
||||
#define AIO_MAX _POSIX_AIO_MAX
|
||||
|
||||
/* Required for POSIX message passing */
|
||||
|
||||
#define MQ_OPEN_MAX _POSIX_MQ_OPEN_MAX
|
||||
#define MQ_PRIO_MAX _POSIX_MQ_PRIO_MAX
|
||||
|
||||
/* Required for POSIX semaphores */
|
||||
|
||||
#define SEM_NSEMS_MAX _POSIX_SEM_NSEMS_MAX
|
||||
#define SEM_VALUE_MAX _POSIX_SEM_VALUE_MAX
|
||||
|
||||
/* Required for readv() and writev() */
|
||||
|
||||
/* There really is no upper limit on the number of vectors */
|
||||
|
||||
#define IOV_MAX INT_MAX
|
||||
|
||||
#endif /* __INCLUDE_LIMITS_H */
|
||||
@@ -0,0 +1,122 @@
|
||||
/****************************************************************************
|
||||
* include/locale.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_LOCALE_H
|
||||
#define __INCLUDE_LOCALE_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define LC_ALL 0
|
||||
#define LC_COLLATE 1
|
||||
#define LC_CTYPE 2
|
||||
#define LC_MONETARY 3
|
||||
#define LC_NUMERIC 4
|
||||
#define LC_TIME 5
|
||||
#define LC_MESSAGES 6
|
||||
|
||||
#define LC_COLLATE_MASK (1 << LC_COLLATE)
|
||||
#define LC_CTYPE_MASK (1 << LC_CTYPE)
|
||||
#define LC_MONETARY_MASK (1 << LC_MONETARY)
|
||||
#define LC_NUMERIC_MASK (1 << LC_NUMERIC)
|
||||
#define LC_TIME_MASK (1 << LC_TIME)
|
||||
#define LC_MESSAGES_MASK (1 << LC_MESSAGES)
|
||||
|
||||
#define LC_ALL_MASK (LC_COLLATE_MASK | LC_CTYPE_MASK | \
|
||||
LC_MONETARY_MASK | LC_NUMERIC_MASK | \
|
||||
LC_TIME_MASK | LC_MESSAGES_MASK)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* OpenGroup.org: "The locale.h header shall define the lconv structure,
|
||||
* which shall include at least the following members. ..."
|
||||
*/
|
||||
|
||||
struct lconv
|
||||
{
|
||||
FAR char *decimal_point;
|
||||
FAR char *thousands_sep;
|
||||
FAR char *grouping;
|
||||
FAR char *int_curr_symbol;
|
||||
FAR char *currency_symbol;
|
||||
FAR char *mon_decimal_point;
|
||||
FAR char *mon_thousands_sep;
|
||||
FAR char *mon_grouping;
|
||||
FAR char *positive_sign;
|
||||
FAR char *negative_sign;
|
||||
FAR char int_frac_digits;
|
||||
FAR char frac_digits;
|
||||
FAR char p_cs_precedes;
|
||||
FAR char p_sep_by_space;
|
||||
FAR char n_cs_precedes;
|
||||
FAR char n_sep_by_space;
|
||||
FAR char p_sign_posn;
|
||||
FAR char n_sign_posn;
|
||||
FAR char int_n_cs_precedes;
|
||||
FAR char int_n_sep_by_space;
|
||||
FAR char int_n_sign_posn;
|
||||
FAR char int_p_cs_precedes;
|
||||
FAR char int_p_sep_by_space;
|
||||
FAR char int_p_sign_posn;
|
||||
};
|
||||
|
||||
/* OpenGroup.org: The locale.h header shall define the locale_t type,
|
||||
* representing a locale object
|
||||
*/
|
||||
|
||||
typedef FAR void *locale_t;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
FAR char *setlocale(int category, FAR const char *locale);
|
||||
FAR struct lconv *localeconv(void);
|
||||
|
||||
locale_t newlocale(int category_mask, FAR const char *locale, locale_t base);
|
||||
locale_t duplocale(locale_t locobj);
|
||||
void freelocale(locale_t locobj);
|
||||
|
||||
locale_t uselocale(locale_t newloc);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_LOCALE_H */
|
||||
@@ -0,0 +1,154 @@
|
||||
/****************************************************************************
|
||||
* include/lzf.h
|
||||
* http://liblzf.plan9.de/
|
||||
*
|
||||
* Copyright (c) 2000-2008 Marc Alexander Lehmann <schmorp@schmorp.de>
|
||||
* This algorithm is believed to be patent-free.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 __INCLUDE_LZF_H
|
||||
#define __INCLUDE_LZF_H
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define LZF_VERSION 0x0105 /* 1.5, API version */
|
||||
#define HLOG CONFIG_LIBC_LZF_HLOG
|
||||
|
||||
#define LZF_TYPE0_HDR 0
|
||||
#define LZF_TYPE1_HDR 1
|
||||
|
||||
#define LZF_TYPE0_HDR_SIZE 5
|
||||
#define LZF_TYPE1_HDR_SIZE 7
|
||||
|
||||
#define LZF_MAX_HDR_SIZE 7
|
||||
#define LZF_MIN_HDR_SIZE 5
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* LZF headers */
|
||||
|
||||
struct lzf_header_s /* Common data header */
|
||||
{
|
||||
uint8_t lzf_magic[2]; /* [0]='Z', [1]='V' */
|
||||
uint8_t lzf_type; /* LZF_TYPE0_HDR or LZF_TYPE1_HDR */
|
||||
};
|
||||
|
||||
struct lzf_type0_header_s /* Uncompressed data header */
|
||||
{
|
||||
uint8_t lzf_magic[2]; /* [0]='Z', [1]='V' */
|
||||
uint8_t lzf_type; /* LZF_TYPE0_HDR */
|
||||
uint8_t lzf_len[2]; /* Data length (big-endian) */
|
||||
};
|
||||
|
||||
struct lzf_type1_header_s /* Compressed data header */
|
||||
{
|
||||
uint8_t lzf_magic[2]; /* [0]='Z', [1]='V' */
|
||||
uint8_t lzf_type; /* LZF_TYPE1_HDR */
|
||||
uint8_t lzf_clen[2]; /* Compressed data length (big-endian) */
|
||||
uint8_t lzf_ulen[2]; /* Uncompressed data length (big-endian) */
|
||||
};
|
||||
|
||||
/* LZF hash table */
|
||||
|
||||
#if LZF_USE_OFFSETS
|
||||
# define LZF_HSLOT_BIAS ((const uint8_t *)in_data)
|
||||
typedef unsigned int lzf_hslot_t;
|
||||
#else
|
||||
# define LZF_HSLOT_BIAS 0
|
||||
typedef const uint8_t *lzf_hslot_t;
|
||||
#endif
|
||||
|
||||
typedef lzf_hslot_t lzf_state_t[1 << HLOG];
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lzf_compress
|
||||
*
|
||||
* Description:
|
||||
* Compress in_len bytes stored at the memory block starting at
|
||||
* in_data and write the result to out_data, up to a maximum length
|
||||
* of out_len bytes.
|
||||
*
|
||||
* If the output buffer is not large enough or any error occurs return 0,
|
||||
* otherwise return the number of bytes used, which might be considerably
|
||||
* more than in_len (but less than 104% of the original size), so it
|
||||
* makes sense to always use out_len == in_len - 1), to ensure _some_
|
||||
* compression, and store the data uncompressed otherwise (with a flag, of
|
||||
* course.
|
||||
*
|
||||
* lzf_compress might use different algorithms on different systems and
|
||||
* even different runs, thus might result in different compressed strings
|
||||
* depending on the phase of the moon or similar factors. However, all
|
||||
* these strings are architecture-independent and will result in the
|
||||
* original data when decompressed using lzf_decompress.
|
||||
*
|
||||
* The buffers must not be overlapping.
|
||||
*
|
||||
* Compressed format:
|
||||
*
|
||||
* 000LLLLL <L+1> ; literal, L+1=1..33 octets
|
||||
* LLLooooo oooooooo ; backref L+1=1..7 octets, o+1=1..4096 offset
|
||||
* 111ooooo LLLLLLLL oooooooo ; backref L+8 octets, o+1=1..4096 offset
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
size_t lzf_compress(FAR const void *const in_data,
|
||||
unsigned int in_len, FAR void *out_data,
|
||||
unsigned int out_len, lzf_state_t htab,
|
||||
FAR struct lzf_header_s **reshdr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lzf_decompress
|
||||
*
|
||||
* Description:
|
||||
* Decompress data compressed with some version of the lzf_compress
|
||||
* function and stored at location in_data and length in_len. The result
|
||||
* will be stored at out_data up to a maximum of out_len characters.
|
||||
*
|
||||
* If the output buffer is not large enough to hold the decompressed
|
||||
* data, a 0 is returned and errno is set to E2BIG. Otherwise the number
|
||||
* of decompressed bytes (i.e. the original length of the data) is
|
||||
* returned.
|
||||
*
|
||||
* If an error in the compressed data is detected, a zero is returned and
|
||||
* errno is set to EINVAL.
|
||||
*
|
||||
* This function is very fast, about as fast as a copying loop.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
unsigned int lzf_decompress(FAR const void *const in_data,
|
||||
unsigned int in_len, FAR void *out_data,
|
||||
unsigned int out_len);
|
||||
|
||||
#endif /* __INCLUDE_LZF_H */
|
||||
@@ -0,0 +1,66 @@
|
||||
/****************************************************************************
|
||||
* include/malloc.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_MALLOC_H
|
||||
#define __INCLUDE_MALLOC_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
struct mallinfo
|
||||
{
|
||||
int arena; /* This is the total size of memory allocated
|
||||
* for use by malloc in bytes. */
|
||||
int ordblks; /* This is the number of free (not in use) chunks */
|
||||
int mxordblk; /* Size of the largest free (not in use) chunk */
|
||||
int uordblks; /* This is the total size of memory occupied by
|
||||
* chunks handed out by malloc. */
|
||||
int fordblks; /* This is the total size of memory occupied
|
||||
* by free (not in use) chunks. */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct mallinfo mallinfo(void);
|
||||
size_t malloc_usable_size(FAR void *ptr);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_MALLOC_H */
|
||||
@@ -0,0 +1,93 @@
|
||||
/********************************************************************************
|
||||
* include/mqueue.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_MQUEUE_H
|
||||
#define __INCLUDE_MQUEUE_H
|
||||
|
||||
/********************************************************************************
|
||||
* Included Files
|
||||
********************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
|
||||
/********************************************************************************
|
||||
* Pre-processor Definitions
|
||||
********************************************************************************/
|
||||
|
||||
#define MQ_NONBLOCK O_NONBLOCK
|
||||
|
||||
/********************************************************************************
|
||||
* Public Type Declarations
|
||||
********************************************************************************/
|
||||
|
||||
/* Message queue attributes */
|
||||
|
||||
struct mq_attr
|
||||
{
|
||||
size_t mq_maxmsg; /* Max number of messages in queue */
|
||||
size_t mq_msgsize; /* Max message size */
|
||||
unsigned mq_flags; /* Queue flags */
|
||||
size_t mq_curmsgs; /* Number of messages currently in queue */
|
||||
};
|
||||
|
||||
/* Message queue descriptor */
|
||||
|
||||
typedef int mqd_t;
|
||||
|
||||
/********************************************************************************
|
||||
* Public Data
|
||||
********************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/********************************************************************************
|
||||
* Public Function Prototypes
|
||||
********************************************************************************/
|
||||
|
||||
mqd_t mq_open(FAR const char *mq_name, int oflags, ...);
|
||||
int mq_close(mqd_t mqdes);
|
||||
int mq_unlink(FAR const char *mq_name);
|
||||
int mq_send(mqd_t mqdes, FAR const char *msg, size_t msglen,
|
||||
unsigned int prio);
|
||||
int mq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen,
|
||||
unsigned int prio, FAR const struct timespec *abstime);
|
||||
ssize_t mq_receive(mqd_t mqdes, FAR char *msg, size_t msglen,
|
||||
FAR unsigned int *prio);
|
||||
ssize_t mq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen,
|
||||
FAR unsigned int *prio,
|
||||
FAR const struct timespec *abstime);
|
||||
int mq_notify(mqd_t mqdes, FAR const struct sigevent *notification);
|
||||
int mq_setattr(mqd_t mqdes, FAR const struct mq_attr *mq_stat,
|
||||
FAR struct mq_attr *oldstat);
|
||||
int mq_getattr(mqd_t mqdes, FAR struct mq_attr *mq_stat);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_MQUEUE_H */
|
||||
@@ -0,0 +1,56 @@
|
||||
/****************************************************************************
|
||||
* include/net/ethernet.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NET_ETHERNET_H
|
||||
#define __INCLUDE_NET_ETHERNET_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define ETHER_ADDR_LEN 6
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
struct ether_addr
|
||||
{
|
||||
uint8_t ether_addr_octet[6]; /* 48-bit Ethernet address */
|
||||
};
|
||||
|
||||
struct ether_header
|
||||
{
|
||||
uint8_t ether_dhost[ETHER_ADDR_LEN]; /* Destination Ethernet address */
|
||||
uint8_t ether_shost[ETHER_ADDR_LEN]; /* Source Ethernet address */
|
||||
uint16_t ether_type; /* Ethernet packet type */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __INCLUDE_NET_ETHERNET_H */
|
||||
@@ -0,0 +1,306 @@
|
||||
/****************************************************************************
|
||||
* include/net/if.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NET_IF_H
|
||||
#define __INCLUDE_NET_IF_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <signal.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Sizing parameters */
|
||||
|
||||
#define IFNAMSIZ 16 /* Older naming standard */
|
||||
#define IF_NAMESIZE 16 /* Newer naming standard */
|
||||
#define IFHWADDRLEN 6
|
||||
|
||||
/* Interface flag bits */
|
||||
|
||||
#define IFF_DOWN (1 << 0) /* Interface is down */
|
||||
#define IFF_UP (1 << 1) /* Interface is up */
|
||||
#define IFF_RUNNING (1 << 2) /* Carrier is available */
|
||||
#define IFF_IPv6 (1 << 3) /* Configured for IPv6 packet (vs ARP or IPv4) */
|
||||
#define IFF_BOUND (1 << 4) /* Bound to a socket */
|
||||
#define IFF_NOARP (1 << 7) /* ARP is not required for this packet */
|
||||
|
||||
/* Interface flag helpers */
|
||||
|
||||
#define IFF_SET_DOWN(f) do { (f) |= IFF_DOWN; } while (0)
|
||||
#define IFF_SET_UP(f) do { (f) |= IFF_UP; } while (0)
|
||||
#define IFF_SET_RUNNING(f) do { (f) |= IFF_RUNNING; } while (0)
|
||||
#define IFF_SET_BOUND(f) do { (f) |= IFF_BOUND; } while (0)
|
||||
#define IFF_SET_NOARP(f) do { (f) |= IFF_NOARP; } while (0)
|
||||
|
||||
#define IFF_CLR_DOWN(f) do { (f) &= ~IFF_DOWN; } while (0)
|
||||
#define IFF_CLR_UP(f) do { (f) &= ~IFF_UP; } while (0)
|
||||
#define IFF_CLR_RUNNING(f) do { (f) &= ~IFF_RUNNING; } while (0)
|
||||
#define IFF_CLR_BOUND(f) do { (f) &= ~IFF_BOUND; } while (0)
|
||||
#define IFF_CLR_NOARP(f) do { (f) &= ~IFF_NOARP; } while (0)
|
||||
|
||||
#define IFF_IS_DOWN(f) (((f) & IFF_DOWN) != 0)
|
||||
#define IFF_IS_UP(f) (((f) & IFF_UP) != 0)
|
||||
#define IFF_IS_RUNNING(f) (((f) & IFF_RUNNING) != 0)
|
||||
#define IFF_IS_BOUND(f) (((f) & IFF_BOUND) != 0)
|
||||
#define IFF_IS_NOARP(f) (((f) & IFF_NOARP) != 0)
|
||||
|
||||
/* We only need to manage the IPv6 bit if both IPv6 and IPv4 are supported.
|
||||
* Otherwise, we can save a few bytes by ignoring it.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||
# define IFF_SET_IPv6(f) do { (f) |= IFF_IPv6; } while (0)
|
||||
# define IFF_CLR_IPv6(f) do { (f) &= ~IFF_IPv6; } while (0)
|
||||
# define IFF_IS_IPv6(f) (((f) & IFF_IPv6) != 0)
|
||||
|
||||
# define IFF_SET_IPv4(f) IFF_CLR_IPv6(f)
|
||||
# define IFF_CLR_IPv4(f) IFF_SET_IPv6(f)
|
||||
# define IFF_IS_IPv4(f) (!IFF_IS_IPv6(f))
|
||||
|
||||
#elif defined(CONFIG_NET_IPv6)
|
||||
# define IFF_SET_IPv6(f)
|
||||
# define IFF_CLR_IPv6(f)
|
||||
# define IFF_IS_IPv6(f) (1)
|
||||
|
||||
# define IFF_SET_IPv4(f)
|
||||
# define IFF_CLR_IPv4(f)
|
||||
# define IFF_IS_IPv4(f) (0)
|
||||
|
||||
#else /* if defined(CONFIG_NET_IPv4) */
|
||||
# define IFF_SET_IPv6(f)
|
||||
# define IFF_CLR_IPv6(f)
|
||||
# define IFF_IS_IPv6(f) (0)
|
||||
|
||||
# define IFF_SET_IPv4(f)
|
||||
# define IFF_CLR_IPv4(f)
|
||||
# define IFF_IS_IPv4(f) (1)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Structure passed with the SIOCMIINOTIFY ioctl command to enable
|
||||
* notification of of PHY state changes.
|
||||
*/
|
||||
|
||||
struct mii_ioctl_notify_s
|
||||
{
|
||||
pid_t pid; /* PID of the task to receive the signal. Zero means "this task" */
|
||||
struct sigevent event; /* Describe the way a task is to be notified */
|
||||
};
|
||||
|
||||
/* Structure passed to read from or write to the MII/PHY management
|
||||
* interface via the SIOCxMIIREG ioctl commands.
|
||||
*/
|
||||
|
||||
struct mii_ioctl_data_s
|
||||
{
|
||||
uint16_t phy_id; /* PHY device address */
|
||||
uint16_t reg_num; /* PHY register address */
|
||||
uint16_t val_in; /* PHY input data */
|
||||
uint16_t val_out; /* PHY output data */
|
||||
};
|
||||
|
||||
/* Structure passed to get or set the CAN bitrate
|
||||
* SIOCxCANBITRATE ioctl commands.
|
||||
*/
|
||||
|
||||
struct can_ioctl_data_s
|
||||
{
|
||||
uint16_t arbi_bitrate; /* Classic CAN / Arbitration phase bitrate kbit/s */
|
||||
uint16_t arbi_samplep; /* Classic CAN / Arbitration phase input % */
|
||||
uint16_t data_bitrate; /* Data phase bitrate kbit/s */
|
||||
uint16_t data_samplep; /* Data phase sample point % */
|
||||
};
|
||||
|
||||
/* There are two forms of the I/F request structure.
|
||||
* One for IPv6 and one for IPv4.
|
||||
* Notice that they are (and must be) cast compatible and really different
|
||||
* only in the size of the structure allocation.
|
||||
*
|
||||
* This is the I/F request that should be used with IPv6.
|
||||
*/
|
||||
|
||||
struct lifreq
|
||||
{
|
||||
char lifr_name[IFNAMSIZ]; /* Network device name (e.g. "eth0") */
|
||||
union
|
||||
{
|
||||
struct sockaddr_storage lifru_addr; /* IP Address */
|
||||
struct sockaddr_storage lifru_dstaddr; /* P-to-P Address */
|
||||
struct sockaddr_storage lifru_broadaddr; /* Broadcast address */
|
||||
struct sockaddr_storage lifru_netmask; /* Netmask */
|
||||
struct sockaddr lifru_hwaddr; /* MAC address */
|
||||
int lifru_count; /* Number of devices */
|
||||
int lifru_mtu; /* MTU size */
|
||||
uint8_t lifru_flags; /* Interface flags */
|
||||
struct mii_ioctl_notify_s llfru_mii_notify; /* PHY event notification */
|
||||
struct mii_ioctl_data_s lifru_mii_data; /* MII request data */
|
||||
struct can_ioctl_data_s lifru_can_data; /* CAN bitrate request data */
|
||||
} lifr_ifru;
|
||||
};
|
||||
|
||||
#define lifr_addr lifr_ifru.lifru_addr /* IP address */
|
||||
#define lifr_dstaddr lifr_ifru.lifru_dstaddr /* P-to-P Address */
|
||||
#define lifr_broadaddr lifr_ifru.lifru_broadaddr /* Broadcast address */
|
||||
#define lifr_netmask lifr_ifru.lifru_netmask /* Interface net mask */
|
||||
#define lifr_hwaddr lifr_ifru.lifru_hwaddr /* MAC address */
|
||||
#define lifr_mtu lifr_ifru.lifru_mtu /* MTU */
|
||||
#define lifr_count lifr_ifru.lifru_count /* Number of devices */
|
||||
#define lifr_flags lifr_ifru.lifru_flags /* interface flags */
|
||||
#define lifr_mii_notify_pid lifr_ifru.llfru_mii_notify.pid /* PID to be notified */
|
||||
#define lifr_mii_notify_event lifr_ifru.llfru_mii_notify.event /* Describes notification */
|
||||
#define lifr_mii_phy_id lifr_ifru.lifru_mii_data.phy_id /* PHY device address */
|
||||
#define lifr_mii_reg_num lifr_ifru.lifru_mii_data.reg_num /* PHY register address */
|
||||
#define lifr_mii_val_in lifr_ifru.lifru_mii_data.val_in /* PHY input data */
|
||||
#define lifr_mii_val_out lifr_ifru.lifru_mii_data.val_out /* PHY output data */
|
||||
|
||||
/* Used only with the SIOCGLIFCONF IOCTL command */
|
||||
|
||||
struct lifconf
|
||||
{
|
||||
size_t lifc_len; /* Size of buffer */
|
||||
union
|
||||
{
|
||||
FAR char *lifcu_buf; /* Buffer address */
|
||||
FAR struct lifreq *lifcu_req; /* Array of ifreq structures */
|
||||
} lifc_ifcu;
|
||||
};
|
||||
|
||||
#define lifc_buf lifc_ifcu.lifcu_buf /* Buffer address */
|
||||
#define lifc_req lifc_ifcu.lifcu_req /* Array of ifreq structures */
|
||||
|
||||
/* This is the I/F request that should be used with IPv4. */
|
||||
|
||||
struct ifreq
|
||||
{
|
||||
char ifr_name[IFNAMSIZ]; /* Network device name (e.g. "eth0") */
|
||||
int16_t ifr_ifindex; /* Interface index */
|
||||
union
|
||||
{
|
||||
struct sockaddr ifru_addr; /* IP Address */
|
||||
struct sockaddr ifru_dstaddr; /* P-to-P Address */
|
||||
struct sockaddr ifru_broadaddr; /* Broadcast address */
|
||||
struct sockaddr ifru_netmask; /* Netmask */
|
||||
struct sockaddr ifru_hwaddr; /* MAC address */
|
||||
int ifru_count; /* Number of devices */
|
||||
int ifru_mtu; /* MTU size */
|
||||
uint8_t ifru_flags; /* Interface flags */
|
||||
struct mii_ioctl_notify_s ifru_mii_notify; /* PHY event notification */
|
||||
struct mii_ioctl_data_s ifru_mii_data; /* MII request data */
|
||||
struct can_ioctl_data_s ifru_can_data; /* CAN bitrate request data */
|
||||
} ifr_ifru;
|
||||
};
|
||||
|
||||
#define ifr_addr ifr_ifru.ifru_addr /* IP address */
|
||||
#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* P-to-P Address */
|
||||
#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* Broadcast address */
|
||||
#define ifr_netmask ifr_ifru.ifru_netmask /* Interface net mask */
|
||||
#define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
|
||||
#define ifr_mtu ifr_ifru.ifru_mtu /* MTU */
|
||||
#define ifr_count ifr_ifru.ifru_count /* Number of devices */
|
||||
#define ifr_flags ifr_ifru.ifru_flags /* interface flags */
|
||||
#define ifr_mii_notify_pid ifr_ifru.ifru_mii_notify.pid /* PID to be notified */
|
||||
#define ifr_mii_notify_event ifr_ifru.ifru_mii_notify.event /* Describes notification */
|
||||
#define ifr_mii_phy_id ifr_ifru.ifru_mii_data.phy_id /* PHY device address */
|
||||
#define ifr_mii_reg_num ifr_ifru.ifru_mii_data.reg_num /* PHY register address */
|
||||
#define ifr_mii_val_in ifr_ifru.ifru_mii_data.val_in /* PHY input data */
|
||||
#define ifr_mii_val_out ifr_ifru.ifru_mii_data.val_out /* PHY output data */
|
||||
|
||||
/* Used only with the SIOCGIFCONF IOCTL command */
|
||||
|
||||
struct ifconf
|
||||
{
|
||||
size_t ifc_len; /* Size of buffer */
|
||||
union
|
||||
{
|
||||
FAR char *ifcu_buf; /* Buffer address */
|
||||
FAR struct ifreq *ifcu_req; /* Array of ifreq structures */
|
||||
} ifc_ifcu;
|
||||
};
|
||||
|
||||
#define ifc_buf ifc_ifcu.ifcu_buf /* Buffer address */
|
||||
#define ifc_req ifc_ifcu.ifcu_req /* Array of ifreq structures */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: if_nametoindex
|
||||
*
|
||||
* Description:
|
||||
* The if_nametoindex() function returns the interface index corresponding
|
||||
* to name ifname.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ifname - The interface name
|
||||
*
|
||||
* Returned Value:
|
||||
* The corresponding index if ifname is the name of an interface;
|
||||
* otherwise, zero.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
unsigned int if_nametoindex(FAR const char *ifname);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: if_indextoname
|
||||
*
|
||||
* Description:
|
||||
* The if_indextoname() function maps an interface index to its
|
||||
* corresponding name.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ifname - Points to a buffer of at least IF_NAMESIZE bytes.
|
||||
* if_indextoname() will place in this buffer the name
|
||||
* of the interface with index ifindex.
|
||||
*
|
||||
* Returned Value:
|
||||
* If ifindex is an interface index, then the function will return the
|
||||
* value supplied by ifname.
|
||||
* Otherwise, the function returns a NULL pointer and sets errno to
|
||||
* indicate the error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR char *if_indextoname(unsigned int ifindex, FAR char *ifname);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NET_IF_H */
|
||||
@@ -0,0 +1,119 @@
|
||||
/****************************************************************************
|
||||
* include/net/route.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NET_ROUTE_H
|
||||
#define __INCLUDE_NET_ROUTE_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <nuttx/net/ioctl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure describes the route information passed with the SIOCADDRT
|
||||
* and SIOCDELRT ioctl commands (see include/nuttx/net/ioctl.h).
|
||||
*/
|
||||
|
||||
struct rtentry
|
||||
{
|
||||
struct sockaddr_storage rt_dst; /* Address of the network */
|
||||
struct sockaddr_storage rt_gateway; /* Gateway address associated with
|
||||
* the hop */
|
||||
struct sockaddr_storage rt_genmask; /* Network mask defining the sub-net */
|
||||
uint16_t rt_flags;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_addroute
|
||||
*
|
||||
* Description:
|
||||
* Add a new route to the routing table. This is just a convenience
|
||||
* wrapper for the SIOCADDRT ioctl call.
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd - Any socket descriptor
|
||||
* target - Target address on external network(required)
|
||||
* netmask - Network mask defining the external network (required)
|
||||
* router - Router address that on our network that can forward to the
|
||||
* external network.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; -1 on failure with the errno variable set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int addroute(int sockfd, FAR struct sockaddr_storage *target,
|
||||
FAR struct sockaddr_storage *netmask,
|
||||
FAR struct sockaddr_storage *router);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_delroute
|
||||
*
|
||||
* Description:
|
||||
* Delete a route from the routing table. This is just a convenience
|
||||
* wrapper for the SIOCDELRT ioctl call.
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd - Any socket descriptor
|
||||
* target - Target address on the remote network (required)
|
||||
* netmask - Network mask defining the external network (required)
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; -1 on failure with the errno variable set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int delroute(int sockfd, FAR struct sockaddr_storage *target,
|
||||
FAR struct sockaddr_storage *netmask);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NET_ROUTE_H */
|
||||
@@ -0,0 +1,350 @@
|
||||
/****************************************************************************
|
||||
* include/netdb.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NETDB_H
|
||||
#define __INCLUDE_NETDB_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
/* Inclusion of the <netdb.h> header may also make visible all symbols from
|
||||
* <netinet/in.h>, <sys/socket.h>, and <inttypes.h>.
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* The <netdb.h> header shall define the IPPORT_RESERVED macro with the
|
||||
* value of the highest reserved Internet port number.
|
||||
*/
|
||||
|
||||
#define IPPORT_RESERVED 0xffff /* No reserved port numbers */
|
||||
|
||||
/* The <netdb.h> header shall define the following macros that evaluate to
|
||||
* bitwise-distinct integer constants for use in the flags field of the
|
||||
* addrinfo structure:
|
||||
*
|
||||
* AI_PASSIVE - Socket address is intended for bind().
|
||||
* AI_CANONNAME - Request for canonical name.
|
||||
* AI_NUMERICHOST - Return numeric host address as name.
|
||||
* AI_NUMERICSERV - Inhibit service name resolution.
|
||||
* AI_V4MAPPED - If no IPv6 addresses are found, query for IPv4
|
||||
* addresses and return them to the caller as IPv4-mapped
|
||||
* IPv6 addresses.
|
||||
* AI_ALL - Query for both IPv4 and IPv6 addresses.
|
||||
* AI_ADDRCONFIG - Query for IPv4 addresses only when an IPv4 address is
|
||||
* configured; query for IPv6 addresses only when an IPv6
|
||||
* address is configured.
|
||||
*/
|
||||
|
||||
#define AI_PASSIVE (1 << 0)
|
||||
#define AI_CANONNAME (1 << 1)
|
||||
#define AI_NUMERICHOST (1 << 2)
|
||||
#define AI_NUMERICSERV (1 << 3)
|
||||
#define AI_V4MAPPED (1 << 4)
|
||||
#define AI_ALL (1 << 5)
|
||||
#define AI_ADDRCONFIG (1 << 6)
|
||||
|
||||
/* The <netdb.h> header shall define the following macros that evaluate to
|
||||
* bitwise-distinct integer constants for use in the flags argument to
|
||||
* getnameinfo():
|
||||
*
|
||||
* NI_NOFQDN - Only the nodename portion of the FQDN is returned for
|
||||
* local hosts.
|
||||
* NI_NUMERICHOST - The numeric form of the node's address is returned
|
||||
* instead of its name.
|
||||
* NI_NAMEREQD - Return an error if the node's name cannot be located
|
||||
* in the database.
|
||||
* NI_NUMERICSERV - The numeric form of the service address is returned
|
||||
* instead of its name.
|
||||
* NI_NUMERICSCOPE - For IPv6 addresses, the numeric form of the scope
|
||||
* identifier is returned instead of its name.
|
||||
* NI_DGRAM - Indicates that the service is a datagram service
|
||||
* (SOCK_DGRAM).
|
||||
*/
|
||||
|
||||
#define NI_NOFQDN (1 << 0)
|
||||
#define NI_NUMERICHOST (1 << 1)
|
||||
#define NI_NAMEREQD (1 << 2)
|
||||
#define NI_NUMERICSERV (1 << 3)
|
||||
#define NI_NUMERICSCOPE (1 << 4)
|
||||
#define NI_DGRAM (1 << 5)
|
||||
|
||||
/* Address Information Errors. The <netdb.h> header shall define the
|
||||
* following macros for use as error values for getaddrinfo() and
|
||||
* getnameinfo():
|
||||
*
|
||||
* EAI_AGAIN - The name could not be resolved at this time. Future
|
||||
* attempts may succeed.
|
||||
* EAI_BADFLAGS - The flags had an invalid value.
|
||||
* EAI_FAIL - A non-recoverable error occurred.
|
||||
* EAI_FAMILY - The address family was not recognized or the address
|
||||
* length was invalid for the specified family.
|
||||
* EAI_MEMORY - There was a memory allocation failure.
|
||||
* EAI_NONAME - The name does not resolve for the supplied
|
||||
* parameters. NI_NAMEREQD is set and the host's name
|
||||
* cannot be located, or both nodename and servname were
|
||||
* null.
|
||||
* EAI_SERVICE - The service passed was not recognized for the
|
||||
* specified socket type.
|
||||
* EAI_SOCKTYPE - The intended socket type was not recognized.
|
||||
* EAI_SYSTEM - A system error occurred. The error code can be found
|
||||
* in errno.
|
||||
* EAI_OVERFLOW - An argument buffer overflowed.
|
||||
*/
|
||||
|
||||
#define EAI_AGAIN 1
|
||||
#define EAI_BADFLAGS 2
|
||||
#define EAI_FAIL 3
|
||||
#define EAI_FAMILY 4
|
||||
#define EAI_MEMORY 5
|
||||
#define EAI_NONAME 6
|
||||
#define EAI_SERVICE 7
|
||||
#define EAI_SOCKTYPE 8
|
||||
#define EAI_SYSTEM 9
|
||||
#define EAI_OVERFLOW 10
|
||||
|
||||
/* h_errno values that may be returned by gethosbyname(), gethostbyname_r(),
|
||||
* gethostbyaddr(), or gethostbyaddr_r()
|
||||
*
|
||||
* HOST_NOT_FOUND - No such host is known.
|
||||
*
|
||||
* NO_DATA - The server recognized the request and the name, but no
|
||||
* address is available. Another type of request to the name server
|
||||
* for the domain might return an answer.
|
||||
*
|
||||
* NO_RECOVERY - An unexpected server failure occurred which cannot be
|
||||
* recovered.
|
||||
*
|
||||
* TRY_AGAIN - A temporary and possibly transient error occurred, such as
|
||||
* a failure of a server to respond.
|
||||
*
|
||||
* These are obsolete and were removed in the Open Group Base Specifications
|
||||
* Issue 7, 2018 edition.
|
||||
*/
|
||||
|
||||
#define HOST_NOT_FOUND 1
|
||||
#define NO_DATA 2
|
||||
#define NO_ADDRESS NO_DATA
|
||||
#define NO_RECOVERY 3
|
||||
#define TRY_AGAIN 4
|
||||
|
||||
/* NI_MAXHOST is the max of
|
||||
*
|
||||
* CONFIG_NETDB_DNSCLIENT_NAMESIZE + 1
|
||||
* INET6_ADDRSTRLEN
|
||||
* INET_ADDRSTRLEN
|
||||
*
|
||||
* Note: INETxxx_ADDRSTRLEN already includes the terminating NUL.
|
||||
* Note: INET6_ADDRSTRLEN > INET_ADDRSTRLEN is assumed.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_NET_IPv6)
|
||||
#define _INET_ADDRSTRLEN INET6_ADDRSTRLEN
|
||||
#else
|
||||
#define _INET_ADDRSTRLEN INET_ADDRSTRLEN
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NETDB_DNSCLIENT) && \
|
||||
(CONFIG_NETDB_DNSCLIENT_NAMESIZE + 1) > _INET_ADDRSTRLEN
|
||||
#define NI_MAXHOST (CONFIG_NETDB_DNSCLIENT_NAMESIZE + 1)
|
||||
#else
|
||||
#define NI_MAXHOST _INET_ADDRSTRLEN
|
||||
#endif
|
||||
|
||||
/* Right now, g_services_db[] only has "ntp".
|
||||
* 16 should be large enough.
|
||||
*/
|
||||
|
||||
#define NI_MAXSERV 16
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct hostent
|
||||
{
|
||||
FAR char *h_name; /* Official name of the host. */
|
||||
FAR char **h_aliases; /* A pointer to an array of pointers to the
|
||||
* alternative host names, terminated by a
|
||||
* null pointer. */
|
||||
int h_addrtype; /* Address type. */
|
||||
int h_length; /* The length, in bytes, of the address. */
|
||||
FAR char **h_addr_list; /* A pointer to an array of pointers to network
|
||||
* addresses (in network byte order) for the host,
|
||||
* terminated by a null pointer. */
|
||||
};
|
||||
|
||||
#define h_addr h_addr_list[0] /* For backward compatibility */
|
||||
|
||||
struct netent
|
||||
{
|
||||
FAR char *n_name; /* Official, fully-qualified(including the domain)
|
||||
* name of the host. */
|
||||
FAR char **n_aliases; /* A pointer to an array of pointers to the
|
||||
* alternative network names, terminated by a
|
||||
* null pointer. */
|
||||
int n_addrtype; /* The address type of the network. */
|
||||
uint32_t n_net; /* The network number, in host byte order. */
|
||||
};
|
||||
|
||||
struct protoent
|
||||
{
|
||||
FAR char *p_name; /* Official name of the protocol. */
|
||||
FAR char **p_aliases; /* A pointer to an array of pointers to
|
||||
* alternative protocol names, terminated by a
|
||||
* null pointer. */
|
||||
int p_proto; /* The protocol number. */
|
||||
};
|
||||
|
||||
struct servent
|
||||
{
|
||||
FAR char *s_name; /* Official name of the service. */
|
||||
FAR char **s_aliases; /* A pointer to an array of pointers to
|
||||
* alternative service names, terminated by a
|
||||
* null pointer. */
|
||||
int s_port; /* The port number at which the service resides,
|
||||
* in network byte order. */
|
||||
FAR char *s_proto; /* The name of the protocol to use when
|
||||
* contacting the service. */
|
||||
};
|
||||
|
||||
struct addrinfo
|
||||
{
|
||||
int ai_flags; /* Input flags. */
|
||||
int ai_family; /* Address family of socket. */
|
||||
int ai_socktype; /* Socket type. */
|
||||
int ai_protocol; /* Protocol of socket. */
|
||||
socklen_t ai_addrlen; /* Length of socket address. */
|
||||
|
||||
FAR struct sockaddr *ai_addr; /* Socket address of socket. */
|
||||
FAR char *ai_canonname; /* Canonical name of service location. */
|
||||
FAR struct addrinfo *ai_next; /* Pointer to next in list. */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* When the <netdb.h> header is included, h_errno shall be available as a
|
||||
* modifiable lvalue of type int. It is unspecified whether h_errno is a
|
||||
* macro or an identifier declared with external linkage.
|
||||
*
|
||||
* h_errno is obsolete and was removed in the Open Group Base Specifications
|
||||
* Issue 7, 2018 edition.
|
||||
*/
|
||||
|
||||
/* REVISIT: This should at least be per-task? */
|
||||
|
||||
EXTERN int h_errno;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_LIBC_NETDB
|
||||
#if 0 /* None of these are yet supported */
|
||||
|
||||
void endhostent(void);
|
||||
void endnetent(void);
|
||||
void endprotoent(void);
|
||||
void endservent(void);
|
||||
#endif
|
||||
void freeaddrinfo(FAR struct addrinfo *ai);
|
||||
FAR const char *gai_strerror(int);
|
||||
int getaddrinfo(FAR const char *nodename,
|
||||
FAR const char *servname,
|
||||
FAR const struct addrinfo *hints,
|
||||
FAR struct addrinfo **res);
|
||||
int getnameinfo(FAR const struct sockaddr *sa,
|
||||
socklen_t salen, FAR char *node,
|
||||
socklen_t nodelen, FAR char *service,
|
||||
socklen_t servicelen, int flags);
|
||||
|
||||
FAR struct hostent *gethostbyaddr(FAR const void *addr, socklen_t len,
|
||||
int type);
|
||||
FAR struct hostent *gethostbyname(FAR const char *name);
|
||||
FAR struct hostent *gethostbyname2(FAR const char *name, int type);
|
||||
FAR struct servent *getservbyport(int port, FAR const char *proto);
|
||||
FAR struct servent *getservbyname(FAR const char *name,
|
||||
FAR const char *proto);
|
||||
|
||||
#if 0 /* None of these are yet supported */
|
||||
FAR struct hostent *gethostent(void);
|
||||
FAR struct netent *getnetbyaddr(uint32_t net, int type);
|
||||
FAR struct netent *getnetbyname(FAR const char *name);
|
||||
FAR struct netent *getnetent(void);
|
||||
FAR struct protoent *getprotobyname(FAR const char *name);
|
||||
FAR struct protoent *getprotobynumber(int proto);
|
||||
FAR struct protoent *getprotoent(void);
|
||||
FAR struct servent *getservent(void);
|
||||
void sethostent(int);
|
||||
void setnetent(int stayopen);
|
||||
void setprotoent(int stayopen);
|
||||
void setservent(int);
|
||||
#endif /* None of these are yet supported */
|
||||
|
||||
/* Non-standard interfaces similar to Glibc 2 interfaces */
|
||||
|
||||
int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type,
|
||||
FAR struct hostent *host, FAR char *buf,
|
||||
size_t buflen, FAR struct hostent **result,
|
||||
FAR int *h_errnop);
|
||||
int gethostbyname_r(FAR const char *name,
|
||||
FAR struct hostent *host, FAR char *buf,
|
||||
size_t buflen, FAR struct hostent **result,
|
||||
FAR int *h_errnop);
|
||||
int gethostbyname2_r(FAR const char *name, int type,
|
||||
FAR struct hostent *host, FAR char *buf,
|
||||
size_t buflen, FAR struct hostent **result,
|
||||
FAR int *h_errnop);
|
||||
int getservbyport_r(int port, FAR const char *proto,
|
||||
FAR struct servent *result_buf, FAR char *buf,
|
||||
size_t buflen, FAR struct servent **result);
|
||||
int getservbyname_r(FAR const char *name, FAR const char *proto,
|
||||
FAR struct servent *result_buf, FAR char *buf,
|
||||
size_t buflen, FAR struct servent **result);
|
||||
|
||||
#endif /* CONFIG_LIBC_NETDB */
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NETDB_H */
|
||||
@@ -0,0 +1,95 @@
|
||||
/****************************************************************************
|
||||
* include/netinet/arp.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NETINET_ARP_H
|
||||
#define __INCLUDE_NETINET_ARP_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Three ioctls are available on all PF_INET sockets. Each ioctl takes a
|
||||
* pointer to a 'struct arpreq' as its parameter.
|
||||
*/
|
||||
|
||||
#define SIOCSARP _ARPIOC(1) /* Set a ARP mapping */
|
||||
#define SIOCDARP _ARPIOC(2) /* Delete an ARP mapping */
|
||||
#define SIOCGARP _ARPIOC(3) /* Get an ARP mapping */
|
||||
|
||||
/* Definitions for bits in field arp_flags of struct arpreq. If the
|
||||
* ATF_NETMASK flag is set, then arp_netmask should be valid. This should
|
||||
* be set to 0xffffffff, or 0 to remove an existing arp entry.
|
||||
*/
|
||||
|
||||
#define ATF_COM (1 << 0) /* Lookup complete */
|
||||
#define ATF_PERM (1 << 1) /* Permanent entry */
|
||||
#define ATF_PUBL (1 << 2) /* Publish entry */
|
||||
#define ATF_USETRAILERS (1 << 3) /* Trailers requested (obsolete) */
|
||||
#define ATF_NETMASK (1 << 4) /* Use a netmask */
|
||||
#define ATF_DONTPUB (1 << 5) /* Don't answer */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* All ARP ioctls take a pointer to a struct arpreq as their parameter: */
|
||||
|
||||
struct arpreq
|
||||
{
|
||||
struct sockaddr arp_pa; /* Protocol address */
|
||||
struct sockaddr arp_ha; /* Hardware address */
|
||||
struct sockaddr arp_netmask; /* Netmask of protocol address */
|
||||
uint8_t arp_flags; /* Flags */
|
||||
uint8_t arp_dev[IFNAMSIZ + 1]; /* Device name (zero terminated) */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NETINET_ARP_H */
|
||||
@@ -0,0 +1,66 @@
|
||||
/****************************************************************************
|
||||
* include/netinet/ether.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NETINET_ETHER_H
|
||||
#define __INCLUDE_NETINET_ETHER_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <net/ethernet.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
FAR char *ether_ntoa(FAR const struct ether_addr *addr);
|
||||
FAR struct ether_addr *ether_aton(FAR const char *asc);
|
||||
int ether_ntohost(FAR char *hostname, FAR const struct ether_addr *addr);
|
||||
int ether_hostton(FAR const char *hostname, FAR struct ether_addr *addr);
|
||||
int ether_line(FAR const char *line, FAR struct ether_addr *addr,
|
||||
FAR char *hostname);
|
||||
FAR struct ether_addr *ether_aton_r(FAR const char *asc,
|
||||
FAR struct ether_addr *addr);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NETINET_ETHER_H */
|
||||
@@ -0,0 +1,316 @@
|
||||
/****************************************************************************
|
||||
* include/netinet/in.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NETINET_IN_H
|
||||
#define __INCLUDE_NETINET_IN_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Values for protocol argument to socket() */
|
||||
|
||||
#define IPPROTO_IP 0 /* Default protocol */
|
||||
#define IPPROTO_HOPOPTS 0 /* IPv6 Hop-by-Hop options. */
|
||||
#define IPPROTO_ICMP 1 /* Internet Control Message Protocol */
|
||||
#define IPPROTO_IGMP 2 /* Internet Group Management Protocol */
|
||||
#define IPPROTO_IPIP 4 /* IPIP tunnels (older KA9Q tunnels use 94) */
|
||||
#define IPPROTO_TCP 6 /* Transmission Control Protocol */
|
||||
#define IPPROTO_EGP 8 /* Exterior Gateway Protocol */
|
||||
#define IPPROTO_PUP 12 /* PUP protocol */
|
||||
#define IPPROTO_UDP 17 /* User Datagram Protocol */
|
||||
#define IPPROTO_IDP 22 /* XNS IDP protocol */
|
||||
#define IPPROTO_TP 29 /* SO Transport Protocol Class 4. */
|
||||
#define IPPROTO_DCCP 33 /* Datagram Congestion Control Protocol */
|
||||
#define IPPROTO_IPV6 41 /* IPv6-in-IPv4 tunnelling */
|
||||
#define IPPROTO_ROUTING 43 /* IPv6 routing header. */
|
||||
#define IPPROTO_FRAGMENT 44 /* IPv6 fragmentation header. */
|
||||
#define IPPROTO_RSVP 46 /* Reservation Protocol. */
|
||||
#define IPPROTO_GRE 47 /* General Routing Encapsulation. */
|
||||
#define IPPROTO_ESP 50 /* Encapsulation Security Payload protocol */
|
||||
#define IPPROTO_AH 51 /* Authentication Header protocol */
|
||||
#define IPPROTO_ICMP6 58 /* Internal Control Message Protocol v6 */
|
||||
#define IPPROTO_NONE 59 /* IPv6 no next header. */
|
||||
#define IPPROTO_DSTOPTS 60 /* IPv6 destination options. */
|
||||
#define IPPROTO_MTP 92 /* Multicast Transport Protocol. */
|
||||
#define IPPROTO_ENCAP 98 /* Encapsulation Header. */
|
||||
#define IPPROTO_BEETPH 94 /* IP option pseudo header for BEET */
|
||||
#define IPPROTO_PIM 103 /* Protocol Independent Multicast */
|
||||
#define IPPROTO_COMP 108 /* Compression Header protocol */
|
||||
#define IPPROTO_SCTP 132 /* Stream Control Transport Protocol */
|
||||
#define IPPROTO_UDPLITE 136 /* UDP-Lite (RFC 3828) */
|
||||
#define IPPROTO_MPLS 137 /* MPLS in IP (RFC 4023) */
|
||||
#define IPPROTO_RAW 255 /* Raw IP packets */
|
||||
|
||||
/* SOL_IP protocol-level socket options. */
|
||||
|
||||
#define IP_MULTICAST_IF (__SO_PROTOCOL + 1) /* Set local device for a
|
||||
* multicast socket */
|
||||
#define IP_MULTICAST_TTL (__SO_PROTOCOL + 2) /* Set/read the time-to-
|
||||
* live value of outgoing
|
||||
* multicast packets */
|
||||
#define IP_MULTICAST_LOOP (__SO_PROTOCOL + 3) /* Set/read boolean that
|
||||
* determines whether sent
|
||||
* multicast packets should
|
||||
* be looped back to local
|
||||
* sockets. */
|
||||
#define IP_ADD_MEMBERSHIP (__SO_PROTOCOL + 4) /* Join a multicast group */
|
||||
#define IP_DROP_MEMBERSHIP (__SO_PROTOCOL + 5) /* Leave a multicast group */
|
||||
#define IP_UNBLOCK_SOURCE (__SO_PROTOCOL + 6) /* Unblock previously
|
||||
* blocked multicast source */
|
||||
#define IP_BLOCK_SOURCE (__SO_PROTOCOL + 7) /* Stop receiving multicast
|
||||
* data from source */
|
||||
|
||||
#define IP_ADD_SOURCE_MEMBERSHIP (__SO_PROTOCOL + 8) /* Join a multicast group;
|
||||
* allow receive only from
|
||||
* source */
|
||||
|
||||
#define IP_DROP_SOURCE_MEMBERSHIP (__SO_PROTOCOL + 9) /* Leave a source-specific
|
||||
* group. Stop receiving
|
||||
* data from a given
|
||||
* multicast group that come
|
||||
* from a given source */
|
||||
|
||||
#define IP_MSFILTER (__SO_PROTOCOL + 10) /* Access advanced, full-
|
||||
* state filtering API */
|
||||
#define IP_MULTICAST_ALL (__SO_PROTOCOL + 11) /* Modify the delivery policy
|
||||
* of multicast messages bound
|
||||
* to INADDR_ANY */
|
||||
#define IP_PKTINFO (__SO_PROTOCOL + 12) /* Get some information about
|
||||
* the incoming packet */
|
||||
#define IP_TOS (__SO_PROTOCOL + 13) /* Access the Type-Of-Service
|
||||
* (TOS) field */
|
||||
|
||||
/* SOL_IPV6 protocol-level socket options. */
|
||||
|
||||
#define IPV6_JOIN_GROUP (__SO_PROTOCOL + 1) /* Join a multicast group */
|
||||
#define IPV6_LEAVE_GROUP (__SO_PROTOCOL + 2) /* Quit a multicast group */
|
||||
#define IPV6_MULTICAST_HOPS (__SO_PROTOCOL + 3) /* Multicast hop limit */
|
||||
#define IPV6_MULTICAST_IF (__SO_PROTOCOL + 4) /* Interface to use for
|
||||
* outgoing multicast packets */
|
||||
#define IPV6_MULTICAST_LOOP (__SO_PROTOCOL + 5) /* Multicast packets are
|
||||
* delivered back to the local
|
||||
* application */
|
||||
#define IPV6_UNICAST_HOPS (__SO_PROTOCOL + 6) /* Unicast hop limit */
|
||||
#define IPV6_V6ONLY (__SO_PROTOCOL + 7) /* Restrict AF_INET6 socket
|
||||
* to IPv6 communications only */
|
||||
#define IPV6_PKTINFO (__SO_PROTOCOL + 8) /* Get some information about
|
||||
* the incoming packet */
|
||||
|
||||
/* Values used with SIOCSIFMCFILTER and SIOCGIFMCFILTER ioctl's */
|
||||
|
||||
#define MCAST_EXCLUDE 0
|
||||
#define MCAST_INCLUDE 1
|
||||
|
||||
/* Test if an IPv4 address is a multicast address */
|
||||
|
||||
#define IN_CLASSD(i) (((uint32_t)(i) & 0xf0000000) == 0xe0000000)
|
||||
#define IN_MULTICAST(i) IN_CLASSD(i)
|
||||
|
||||
/* Special values of in_addr_t */
|
||||
|
||||
#define INADDR_ANY ((in_addr_t)0x00000000) /* Address to accept any
|
||||
* incoming messages */
|
||||
#define INADDR_BROADCAST ((in_addr_t)0xffffffff) /* Address to send to
|
||||
* all hosts */
|
||||
#define INADDR_NONE ((in_addr_t)0xffffffff) /* Address indicating an
|
||||
* error return */
|
||||
#define INADDR_LOOPBACK ((in_addr_t)0x7f000001) /* Inet 127.0.0.1. */
|
||||
|
||||
/* Special initializer for in6_addr_t */
|
||||
|
||||
#define IN6ADDR_ANY_INIT {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}}
|
||||
#define IN6ADDR_LOOPBACK_INIT {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}}
|
||||
|
||||
/* Sizes of addresses (per OpenGroup.org) */
|
||||
|
||||
#define INET_ADDRSTRLEN 16 /* nnn.nnn.nnn.nnn */
|
||||
#define INET6_ADDRSTRLEN 46 /* xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx */
|
||||
|
||||
/* struct in6_addr union selectors */
|
||||
|
||||
#define s6_addr in6_u.u6_addr8
|
||||
#define s6_addr16 in6_u.u6_addr16
|
||||
#define s6_addr32 in6_u.u6_addr32
|
||||
|
||||
/* Checks for special IPv6 addresses */
|
||||
|
||||
#define IN6_IS_ADDR_MULTICAST(a) \
|
||||
((a)->s6_addr[0] == 0xff)
|
||||
|
||||
#define IN6_IS_ADDR_LOOPBACK(a) \
|
||||
((a)->s6_addr32[0] == 0 && \
|
||||
(a)->s6_addr32[1] == 0 && \
|
||||
(a)->s6_addr32[2] == 0 && \
|
||||
(a)->s6_addr32[3] == HTONL(1))
|
||||
|
||||
#define IN6_IS_ADDR_UNSPECIFIED(a) \
|
||||
((a)->s6_addr32[0] == 0 && \
|
||||
(a)->s6_addr32[1] == 0 && \
|
||||
(a)->s6_addr32[2] == 0 && \
|
||||
(a)->s6_addr32[3] == 0)
|
||||
|
||||
#define IN6_IS_ADDR_V4COMPAT(a) \
|
||||
((a)->s6_addr32[0] == 0 && \
|
||||
(a)->s6_addr32[1] == 0 && \
|
||||
(a)->s6_addr32[2] == 0 && \
|
||||
(a)->s6_addr32[3] != 0 && \
|
||||
(a)->s6_addr32[3] != NTOHL(1))
|
||||
|
||||
#define IN6_IS_ADDR_V4MAPPED(a) \
|
||||
((a)->s6_addr32[0] == 0 && \
|
||||
(a)->s6_addr32[1] == 0 && \
|
||||
(a)->s6_addr32[2] == HTONL(0xffff))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* IPv4/IPv6 port number */
|
||||
|
||||
typedef uint16_t in_port_t;
|
||||
|
||||
/* IPv4 Internet address */
|
||||
|
||||
typedef uint32_t in_addr_t;
|
||||
|
||||
struct in_addr
|
||||
{
|
||||
in_addr_t s_addr; /* Address (network byte order) */
|
||||
};
|
||||
|
||||
struct sockaddr_in
|
||||
{
|
||||
sa_family_t sin_family; /* Address family: AF_INET */
|
||||
in_port_t sin_port; /* Port in network byte order */
|
||||
struct in_addr sin_addr; /* Internet address */
|
||||
uint8_t sin_zero[8];
|
||||
};
|
||||
|
||||
/* Used with certain IPv4 socket options */
|
||||
|
||||
struct ip_mreq
|
||||
{
|
||||
struct in_addr imr_multiaddr; /* IPv4 multicast address of group */
|
||||
struct in_addr imr_interface; /* Local IPv4 address of interface */
|
||||
};
|
||||
|
||||
struct ip_mreqn
|
||||
{
|
||||
struct in_addr imr_multiaddr; /* IPv4 multicast address of group */
|
||||
struct in_addr imr_interface; /* Local IPv4 address of interface */
|
||||
unsigned int imr_ifindex; /* Local interface index */
|
||||
};
|
||||
|
||||
struct ip_mreq_source
|
||||
{
|
||||
struct in_addr imr_multiaddr; /* IPv4 multicast group address */
|
||||
struct in_addr imr_interface; /* IPv4 address of local interface */
|
||||
struct in_addr imr_sourceaddr; /* IPv4 address of multicast source */
|
||||
};
|
||||
|
||||
struct ip_msfilter
|
||||
{
|
||||
struct in_addr imsf_multiaddr; /* IPv4 multicast group address */
|
||||
struct in_addr imsf_interface; /* IPv4 address of local interface */
|
||||
uint32_t imsf_fmode; /* Filter mode */
|
||||
uint32_t imsf_numsrc; /* Number of sources in the following array */
|
||||
struct in_addr imsf_slist[1]; /* Array of source addresses */
|
||||
};
|
||||
|
||||
struct in_pktinfo
|
||||
{
|
||||
int ipi_ifindex; /* Interface index */
|
||||
struct in_addr ipi_spec_dst; /* Local address */
|
||||
struct in_addr ipi_addr; /* Header Destination address */
|
||||
};
|
||||
|
||||
/* IPv6 Internet address */
|
||||
|
||||
struct in6_addr
|
||||
{
|
||||
union
|
||||
{
|
||||
uint8_t u6_addr8[16];
|
||||
uint16_t u6_addr16[8];
|
||||
uint32_t u6_addr32[4];
|
||||
} in6_u;
|
||||
};
|
||||
|
||||
struct sockaddr_in6
|
||||
{
|
||||
sa_family_t sin6_family; /* Address family: AF_INET6 */
|
||||
in_port_t sin6_port; /* Port in network byte order */
|
||||
uint32_t sin6_flowinfo; /* IPv6 traffic class and flow information */
|
||||
struct in6_addr sin6_addr; /* IPv6 Internet address */
|
||||
uint32_t sin6_scope_id; /* Set of interfaces for a scope */
|
||||
};
|
||||
|
||||
/* Used with certain IPv6 socket options */
|
||||
|
||||
struct ipv6_mreq
|
||||
{
|
||||
struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast address of group */
|
||||
unsigned int ipv6mr_interface; /* Local interface index */
|
||||
};
|
||||
|
||||
struct in6_pktinfo
|
||||
{
|
||||
struct in6_addr ipi6_addr; /* src/dst IPv6 address */
|
||||
int ipi6_ifindex; /* send/recv interface index */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* Global IPv6 in6addr_any */
|
||||
|
||||
EXTERN const struct in6_addr in6addr_any;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NETINET_IN_H */
|
||||
@@ -0,0 +1,39 @@
|
||||
/****************************************************************************
|
||||
* include/netinet/ip.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NETINET_IP_H
|
||||
#define __INCLUDE_NETINET_IP_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __INCLUDE_NETINET_IP_H */
|
||||
@@ -0,0 +1,39 @@
|
||||
/****************************************************************************
|
||||
* include/netinet/ip6.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NETINET_IP6_H
|
||||
#define __INCLUDE_NETINET_IP6_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __INCLUDE_NETINET_IP6_H */
|
||||
@@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
* include/netinet/tcp.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NETINET_TCP_H
|
||||
#define __INCLUDE_NETINET_TCP_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Per OpenGroup.org:
|
||||
*
|
||||
* "The netinet/tcp.h header shall define the following macro for use as a
|
||||
* socket option at the IPPROTO_TCP level:" -- OpenGroup.org
|
||||
*/
|
||||
|
||||
#define TCP_NODELAY (__SO_PROTOCOL + 0) /* Avoid coalescing of small segments. */
|
||||
|
||||
/* "The macro shall be defined in the header. The implementation need not
|
||||
* allow the value of the option to be set via setsockopt() or retrieved
|
||||
* via getsockopt()."
|
||||
*/
|
||||
|
||||
/* Additional TCP protocol socket operations not specified at OpenGroup.org */
|
||||
|
||||
/* TCP protocol socket operations needed to support TCP Keep-Alive: */
|
||||
|
||||
#define TCP_KEEPIDLE (__SO_PROTOCOL + 1) /* Start keeplives after this IDLE period
|
||||
* Argument: struct timeval */
|
||||
#define TCP_KEEPINTVL (__SO_PROTOCOL + 2) /* Interval between keepalives
|
||||
* Argument: struct timeval */
|
||||
#define TCP_KEEPCNT (__SO_PROTOCOL + 3) /* Number of keepalives before death
|
||||
* Argument: max retry count */
|
||||
#define TCP_MAXSEG (__SO_PROTOCOL + 4) /* The maximum segment size */
|
||||
|
||||
#endif /* __INCLUDE_NETINET_TCP_H */
|
||||
@@ -0,0 +1,40 @@
|
||||
/****************************************************************************
|
||||
* include/netinet/udp.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NETINET_UDP_H
|
||||
#define __INCLUDE_NETINET_UDP_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* UDP protocol (SOL_UDP) socket options */
|
||||
|
||||
#define UDP_BINDTODEVICE (__SO_PROTOCOL + 0) /* Bind this UDP socket to a
|
||||
* specific network device.
|
||||
*/
|
||||
|
||||
#endif /* __INCLUDE_NETINET_UDP_H */
|
||||
@@ -0,0 +1,306 @@
|
||||
/****************************************************************************
|
||||
* include/netpacket/bluetooth.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NETPACKET_BLUETOOTH_H
|
||||
#define __INCLUDE_NETPACKET_BLUETOOTH_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <nuttx/wireless/bluetooth/bt_hci.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Well known addresses: */
|
||||
|
||||
#define BT_ADDR_ANY {0, 0, 0, 0, 0, 0}
|
||||
#define BT_ADDR_LOCAL {0, 0, 0, 0xff, 0xff, 0xff}
|
||||
|
||||
/* Any channel, any PSM */
|
||||
|
||||
#define BT_CHANNEL_ANY 0
|
||||
#define BT_PSM_ANY 0
|
||||
|
||||
/* Socket protocols.
|
||||
*
|
||||
* All Bluetooth sockets should select address family = AF_BLUETOOTH and
|
||||
* type = SOCK_RAW. Protocol options are listed here (from NetBSD):
|
||||
*
|
||||
* BTPROTO_HCI
|
||||
* This gives raw access to the Host Controller Interface of local devices
|
||||
* using the HCI protocol as described in the Bluetooth Core Specification.
|
||||
* The local address specified by bind() may be used to select the device
|
||||
* that the socket will receive packets from. If BDADDR_ANY is specified
|
||||
* then the socket will receive packets from all devices on the system.
|
||||
* connect() may be used to create connections such that packets sent with
|
||||
* send() will be delivered to the specified device, otherwise sendto()
|
||||
* should be used.
|
||||
* BTPROTO_L2CAP
|
||||
* L2CAP sockets give sequential packet access over channels to other
|
||||
* Bluetooth devices and make use of the bt_psm field in the sockaddr_l2
|
||||
* structure to select the Protocol/Service Multiplexer to specify when
|
||||
* making connections. If the special value of L2CAP_PSM_ANY is bound
|
||||
* when the listen() call is made, the next available PSM from the
|
||||
* dynamic range above 0x1001 will be selected and may be discovered
|
||||
* using the getsockname() call.
|
||||
* BTPROTO_RFCOMM
|
||||
* RFCOMM sockets provide streamed data over Bluetooth connection and
|
||||
* make use of the l2_cid field in the sockaddr_rc structure.
|
||||
* The channel number must be between 1 and 30 inclusive except that if
|
||||
* the special value RFCOMM_CHANNEL_ANY is bound, when the listen() call
|
||||
* is made, the first unused channel for the relevant bdaddr will be
|
||||
* allocated and may be discovered using the getsockname(2) call.
|
||||
*
|
||||
* BTPROTO_NONE
|
||||
* This is to be used internally to indicate unconfigured protocol. Not
|
||||
* to be used on sockets by user.
|
||||
*/
|
||||
|
||||
#define BTPROTO_L2CAP 0
|
||||
#define BTPROTO_HCI 1
|
||||
#define BTPROTO_SCO 2
|
||||
#define BTPROTO_RFCOMM 3
|
||||
#define BTPROTO_BNEP 4
|
||||
#define BTPROTO_CMTP 5
|
||||
#define BTPROTO_HIDP 6
|
||||
#define BTPROTO_AVDTP 7
|
||||
#define BTPROTO_NONE 255
|
||||
|
||||
/* HCI socket options (SOL_HCI, see include/sys/socket.h):
|
||||
*
|
||||
* SO_HCI_EVT_FILTER
|
||||
* Controls which events will be received at the socket. By default,
|
||||
* Command_Complete and Command_Status events only are enabled.
|
||||
* SO_HCI_PKT_FILTER [struct hci_filter]
|
||||
* This filter controls the type of packets that will be received at
|
||||
* the socket. By default, Event packets only are enabled.
|
||||
* SO_HCI_DIRECTION [int]
|
||||
* When set, this enables control messages on packets received at the
|
||||
* socket indicating the direction of travel of the packet.
|
||||
*/
|
||||
|
||||
#define SO_HCI_EVT_FILTER (__SO_PROTOCOL + 0)
|
||||
#define SO_HCI_PKT_FILTER (__SO_PROTOCOL + 1)
|
||||
#define SO_HCI_DIRECTION (__SO_PROTOCOL + 2)
|
||||
|
||||
/* L2CAP socket options (SOL_L2CAP, see include/sys/socket.h):
|
||||
|
||||
* SO_L2CAP_IMTU [uint16_t]
|
||||
* Incoming MTU
|
||||
* SO_L2CAP_OMTU [uint16_t]
|
||||
* Outgoing MTU (read-only)
|
||||
* SO_L2CAP_LM [int]
|
||||
* Link Mode. The following bits may be set:
|
||||
*
|
||||
* L2CAP_LM_AUTH Request authentication (pairing).
|
||||
* L2CAP_LM_ENCRYPT Request encryption (includes authentication).
|
||||
* L2CAP_LM_SECURE Request secured link (encryption, plus
|
||||
* change link key).
|
||||
*
|
||||
* Link mode settings will be applied to the baseband link during L2CAP
|
||||
* connection establishment. If the L2CAP connection is already
|
||||
* established, EINPROGRESS may be returned, and it is not possible to
|
||||
* guarantee that data already queued (from either end) will not be
|
||||
* delivered. If the mode change fails, the L2CAP connection will be
|
||||
* aborted.
|
||||
*/
|
||||
|
||||
#define SO_L2CAP_IMTU (__SO_PROTOCOL + 3)
|
||||
#define SO_L2CAP_OMTU (__SO_PROTOCOL + 4)
|
||||
#define SO_L2CAP_LM (__SO_PROTOCOL + 5)
|
||||
# define L2CAP_LM_AUTH (1 << 0)
|
||||
# define L2CAP_LM_ENCRYPT (1 << 1)
|
||||
# define L2CAP_LM_SECURE (1 << 2)
|
||||
|
||||
/* RFCOMM socket options (SOL_RFCOMM, see include/sys/socket.h):
|
||||
*
|
||||
* SO_RFCOMM_MTU [uint16_t]
|
||||
* Maximum Frame Size to use for this link.
|
||||
* SO_RFCOMM_LM [int]
|
||||
* Link Mode. The following bits may be set at any time:
|
||||
*
|
||||
* RFCOMM_LM_AUTH Request authentication (pairing).
|
||||
* RFCOMM_LM_ENCRYPT Request encryption (includes authentication).
|
||||
* RFCOMM_LM_SECURE Request secured link (encryption, plus
|
||||
* change link key).
|
||||
*
|
||||
* Link mode settings will be applied to the baseband link during RFCOMM
|
||||
* connection establishment. If the RFCOMM connection is already
|
||||
* established, EINPROGRESS may be returned, and it is not possible to
|
||||
* guarantee that data already queued (from either end) will not be
|
||||
* delivered. If the mode change fails, the RFCOMM connection will be
|
||||
* aborted.
|
||||
*/
|
||||
|
||||
#define SO_RFCOMM_MTU (__SO_PROTOCOL + 6)
|
||||
#define SO_RFCOMM_LM (__SO_PROTOCOL + 7)
|
||||
# define RFCOMM_LM_AUTH (1 << 0)
|
||||
# define RFCOMM_LM_ENCRYPT (1 << 1)
|
||||
# define RFCOMM_LM_SECURE (1 << 2)
|
||||
|
||||
/* SCO socket options (SOL_SCO, see include/sys/socket.h):
|
||||
*
|
||||
* SO_SCO_MTU [uint16_t]
|
||||
* Maximum packet size for use on this link. This is read-only and will
|
||||
* be set by the protocol code when a connection is made.
|
||||
* SO_SCO_HANDLE [uint16_t]
|
||||
* Connection handle for this link. This is read-only and provided for
|
||||
* informational purposes only.
|
||||
*/
|
||||
|
||||
#define SO_SCO_MTU (__SO_PROTOCOL + 8)
|
||||
#define SO_SCO_HANDLE (__SO_PROTOCOL + 9)
|
||||
|
||||
/* The CID name space for the ACL-U, ASB-C, and AMP-U logical links is as
|
||||
* follows:
|
||||
*/
|
||||
|
||||
#define BT_CID_NULL 0x0000 /* Null identifier */
|
||||
#define BT_CID_L2CAP 0x0001 /* L2CAP Signaling channel */
|
||||
#define BT_CID_CONNECTIONLESS 0x0002 /* Connectionless channel */
|
||||
#define BT_CID_AMP 0x0003 /* AMP Manager Protocol */
|
||||
/* 0x0004-0x0006 Reserved for future
|
||||
* use */
|
||||
#define BT_CID_BREDR 0x0007 /* BR/EDR Security Manager */
|
||||
/* 0x0008-0x003e Reserved for future
|
||||
* use */
|
||||
#define BT_CID_AMPTEST 0x003f /* AMP Test Manager */
|
||||
/* 0x0040-0xffff Dynamically
|
||||
* allocated */
|
||||
|
||||
/* The CID name space for the LE-U logical link is as follows:
|
||||
*
|
||||
* NOTE: 0x0004, 0x0005, and 0x0006 are used internally by ATT, L2CAP, and
|
||||
* and SMP. These are unavailable for use use in socket connection.
|
||||
*/
|
||||
|
||||
#define BT_LE_CID_NULL 0x0000 /* Null identifier */
|
||||
/* 0x0001-0x0003 Reserved for future
|
||||
* use */
|
||||
#define BT_LE_CID_ATT 0x0004 /* Attribute Protocol */
|
||||
#define BT_LE_CID_L2CAP 0x0005 /* Low Energy L2CAP Signaling channel */
|
||||
#define BT_LE_CID_SMP 0x0006 /* Security Manager Protocol */
|
||||
/* 0x0007-0x001f Reserved for future */
|
||||
/* 0x0020-0x003e Assigned Numbers */
|
||||
/* 0x003f Reserved for future use */
|
||||
/* 0x0040-0x007f Dynamically allocated
|
||||
* using the L2CAP LE credit based
|
||||
* connection mechanism */
|
||||
/* Others reserved for future use */
|
||||
|
||||
/* Protocol and Service Multiplexers (PSMs) */
|
||||
|
||||
#define BT_PSM_SDP 0x0001 /* Bluetooth Service Discovery
|
||||
* Protocol (SDP), Bluetooth SIG */
|
||||
#define BT_PSM_RFCOMM 0x0003 /* RFCOMM with TS 07.10, Bluetooth
|
||||
* SIG */
|
||||
#define BT_PSM_TCS_BIN 0x0005 /* Bluetooth Telephony Control
|
||||
* Specification / TCS Binary,
|
||||
* Bluetooth SIG */
|
||||
#define BT_PSM_TCS_BIN_CORDLESS 0x0007 /* Bluetooth Telephony Control
|
||||
* Specification / TCS Binary,
|
||||
* Bluetooth SIG */
|
||||
#define BT_PSM_BNEP 0x000f /* Bluetooth Network Encapsulation
|
||||
* Protocol, Bluetooth SIG */
|
||||
#define BT_PSM_HID_CTRL 0x0011 /* Human Interface Device, Bluetooth
|
||||
* SIG */
|
||||
#define BT_PSM_HID_INT 0x0013 /* Human Interface Device, Bluetooth
|
||||
* SIG */
|
||||
#define BT_PSM_UPnP 0x0015 /* [ESDP] , Bluetooth SIG */
|
||||
#define BT_PSM_AVCTP 0x0017 /* Audio/Video Control Transport
|
||||
* Protocol, Bluetooth SIG */
|
||||
#define BT_PSM_AVDTP 0x0019 /* Audio/Video Distribution Transport
|
||||
* Protocol, Bluetooth SIG */
|
||||
#define BT_PSM_AVCTP_BROWSING 0x001b /* Audio/Video Remote Control
|
||||
* Profile, Bluetooth SIG */
|
||||
#define BT_PSM_UDI_CPLANE 0x001d /* Unrestricted Digital Information
|
||||
* Profile [UDI], Bluetooth SIG */
|
||||
#define BT_PSM_ATT 0x001f /* Bluetooth Core Specification */
|
||||
#define BT_PSM_3DSP 0x0021 /* 3D Synchronization Profile,
|
||||
* Bluetooth SIG. */
|
||||
#define BT_PSM_LE_PSM_IPSP 0x0023 /* Internet Protocol Support Profile
|
||||
* (IPSP), Bluetooth SIG */
|
||||
#define BT_PSM_OTS 0x0025 /* Object Transfer Service (OTS),
|
||||
* Bluetooth SIG */
|
||||
|
||||
/* Channels for a BTPROTO_HCI socket */
|
||||
|
||||
#define HCI_CHANNEL_RAW 0x0
|
||||
#define HCI_CHANNEL_USER 0x1
|
||||
|
||||
/* Packets types send over the network layer for BTPROTO_HCI */
|
||||
|
||||
#define HCI_COMMAND_PKT 0x01
|
||||
#define HCI_ACLDATA_PKT 0x02
|
||||
#define HCI_SCODATA_PKT 0x03
|
||||
#define HCI_EVENT_PKT 0x04
|
||||
#define HCI_VENDOR_PKT 0xff
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* See include/nuttx/wireless/bluetooth/bt_hci.h for address definitions. In
|
||||
* particular, type bt_addr_t
|
||||
*/
|
||||
|
||||
/* Socket address used with:
|
||||
*
|
||||
* bind() - Associates local address with socket
|
||||
* connect() - Associates a remote address with the socket (for send())
|
||||
* sendto() - Send to specified remote address
|
||||
* recvfrom()- Receive from indicated remote address.
|
||||
*
|
||||
*/
|
||||
|
||||
struct sockaddr_l2
|
||||
{
|
||||
sa_family_t l2_family; /* Must be AF_BLUETOOTH */
|
||||
uint16_t l2_psm; /* Protocol Service Multiplexer (PSM) */
|
||||
bt_addr_t l2_bdaddr; /* 6-byte Bluetooth address */
|
||||
uint16_t l2_cid; /* Channel identifier (CID) */
|
||||
uint8_t l2_bdaddr_type; /* Bluetooth address type */
|
||||
};
|
||||
|
||||
struct sockaddr_hci
|
||||
{
|
||||
sa_family_t hci_family; /* Must be AF_BLUETOOTH */
|
||||
uint16_t hci_dev; /* Network Device ID */
|
||||
uint16_t hci_channel; /* Channel: USER, MONITOR, CONTROL, etc... */
|
||||
};
|
||||
|
||||
struct sockaddr_rc
|
||||
{
|
||||
sa_family_t rc_family; /* Must be AF_BLUETOOTH */
|
||||
bt_addr_t rc_bdaddr; /* 6-byte Bluetooth address */
|
||||
uint8_t rc_channel; /* Channel number */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __INCLUDE_NETPACKET_BLUETOOTH_H */
|
||||
@@ -0,0 +1,144 @@
|
||||
/****************************************************************************
|
||||
* include/netpacket/can.h
|
||||
* Definitions for use with AF_PACKET sockets
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NETPACKET_CAN_H
|
||||
#define __INCLUDE_NETPACKET_CAN_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Special address description flags for the CAN_ID */
|
||||
|
||||
#define CAN_EFF_FLAG 0x80000000 /* EFF/SFF is set in the MSB */
|
||||
#define CAN_RTR_FLAG 0x40000000 /* Remote transmission request */
|
||||
#define CAN_ERR_FLAG 0x20000000 /* Error message frame */
|
||||
|
||||
/* Valid bits in CAN ID for frame formats */
|
||||
|
||||
#define CAN_SFF_MASK 0x000007ff /* Standard frame format (SFF) */
|
||||
#define CAN_EFF_MASK 0x1fffffff /* Extended frame format (EFF) */
|
||||
#define CAN_ERR_MASK 0x1fffffff /* Omit EFF, RTR, ERR flags */
|
||||
|
||||
#define CAN_MTU (sizeof(struct can_frame))
|
||||
#define CANFD_MTU (sizeof(struct canfd_frame))
|
||||
|
||||
/* PF_CAN protocols */
|
||||
|
||||
#define CAN_RAW 1 /* RAW sockets */
|
||||
#define CAN_BCM 2 /* Broadcast Manager */
|
||||
#define CAN_TP16 3 /* VAG Transport Protocol v1.6 */
|
||||
#define CAN_TP20 4 /* VAG Transport Protocol v2.0 */
|
||||
#define CAN_MCNET 5 /* Bosch MCNet */
|
||||
#define CAN_ISOTP 6 /* ISO 15765-2 Transport Protocol */
|
||||
#define CAN_J1939 7 /* SAE J1939 */
|
||||
#define CAN_NPROTO 8
|
||||
|
||||
#define SOL_CAN_BASE 100
|
||||
|
||||
#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
|
||||
|
||||
/* CAN_RAW socket options */
|
||||
|
||||
#define CAN_RAW_FILTER (__SO_PROTOCOL + 0)
|
||||
/* set 0 .. n can_filter(s) */
|
||||
#define CAN_RAW_ERR_FILTER (__SO_PROTOCOL + 1)
|
||||
/* set filter for error frames */
|
||||
#define CAN_RAW_LOOPBACK (__SO_PROTOCOL + 2)
|
||||
/* local loopback (default:on) */
|
||||
#define CAN_RAW_RECV_OWN_MSGS (__SO_PROTOCOL + 3)
|
||||
/* receive my own msgs (default:off) */
|
||||
#define CAN_RAW_FD_FRAMES (__SO_PROTOCOL + 4)
|
||||
/* allow CAN FD frames (default:off) */
|
||||
#define CAN_RAW_JOIN_FILTERS (__SO_PROTOCOL + 5)
|
||||
/* all filters must match to trigger */
|
||||
#define CAN_RAW_TX_DEADLINE (__SO_PROTOCOL + 6)
|
||||
/* Abort frame when deadline passed */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Controller Area Network Identifier structure
|
||||
*
|
||||
* Bit 0-28: CAN identifier (11/29 bit)
|
||||
* Bit 29: Error message frame flag (0 = data frame, 1 = error message)
|
||||
* Bit 30: Remote transmission request flag (1 = rtr frame)
|
||||
* Bit 31: Frame format flag (0 = standard 11 bit, 1 = extended 29 bit)
|
||||
*/
|
||||
|
||||
typedef uint32_t canid_t;
|
||||
|
||||
/* The sockaddr structure for CAN sockets
|
||||
*
|
||||
* can_family: Address family number AF_CAN.
|
||||
* can_ifindex: CAN network interface index.
|
||||
* can_addr: Protocol specific address information
|
||||
*/
|
||||
|
||||
struct sockaddr_can
|
||||
{
|
||||
sa_family_t can_family;
|
||||
int16_t can_ifindex;
|
||||
union
|
||||
{
|
||||
/* Transport protocol class address information */
|
||||
|
||||
struct
|
||||
{
|
||||
canid_t rx_id;
|
||||
canid_t tx_id;
|
||||
} tp;
|
||||
|
||||
/* J1939 address information */
|
||||
|
||||
struct
|
||||
{
|
||||
/* 8 byte name when using dynamic addressing */
|
||||
|
||||
uint64_t name;
|
||||
|
||||
/* pgn:
|
||||
* 8 bit: PS in PDU2 case, else 0
|
||||
* 8 bit: PF
|
||||
* 1 bit: DP
|
||||
* 1 bit: reserved
|
||||
*/
|
||||
|
||||
uint32_t pgn;
|
||||
|
||||
/* 1 byte address */
|
||||
|
||||
uint8_t addr;
|
||||
} j1939;
|
||||
} can_addr;
|
||||
};
|
||||
|
||||
#endif /* __INCLUDE_NETPACKET_CAN_H */
|
||||
@@ -0,0 +1,86 @@
|
||||
/****************************************************************************
|
||||
* include/netpacket/ieee802154.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NETPACKET_IEEE802154_H
|
||||
#define __INCLUDE_NETPACKET_IEEE802154_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Well known address */
|
||||
|
||||
#define IEEE802154_PANID_BROADCAST 0xffff
|
||||
#define IEEE802154_ADDR_BROADCAST 0xffff
|
||||
#define IEEE802154_ADDR_UNDEF 0xfffe
|
||||
|
||||
/* struct sockaddr_ieee802154_s union selectors */
|
||||
|
||||
#define s_saddr s_u.saddr
|
||||
#define s_eaddr s_u.eaddr
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* See include/uttx/wireless/ieee802154/ieee802154_mac.h for address
|
||||
* definitions. Particularly, enum ieee802154_addrmode_e, the address type
|
||||
*
|
||||
* See also the definitions above for portable union selectors.
|
||||
*/
|
||||
|
||||
struct ieee802154_saddr_s
|
||||
{
|
||||
uint8_t s_mode; /* Address mode (see enum
|
||||
* ieee802154_addrmode_e) */
|
||||
uint8_t s_panid[IEEE802154_PANIDSIZE]; /* PAN identifier */
|
||||
union
|
||||
{
|
||||
uint8_t saddr[IEEE802154_SADDRSIZE]; /* Short address */
|
||||
uint8_t eaddr[IEEE802154_EADDRSIZE]; /* Extended address */
|
||||
} s_u;
|
||||
};
|
||||
|
||||
/* Socket address used with:
|
||||
*
|
||||
* bind() - Associates local address with socket
|
||||
* connect() - Associates a remote address with the socket (for send())
|
||||
* sendto() - Send to specified remote address
|
||||
* recvfrom()- Receive from indicated remote address.
|
||||
*/
|
||||
|
||||
struct sockaddr_ieee802154_s
|
||||
{
|
||||
sa_family_t sa_family; /* AF_IEEE802154 */
|
||||
struct ieee802154_saddr_s sa_addr; /* Radio address */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __INCLUDE_NETPACKET_IEEE802154_H */
|
||||
@@ -0,0 +1,112 @@
|
||||
/****************************************************************************
|
||||
* include/netpacket/if_addr.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NETPACKET_IF_ADDR_H
|
||||
#define __INCLUDE_NETPACKET_IF_ADDR_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <netpacket/netlink.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define IFA_MAX (__IFA_MAX - 1)
|
||||
|
||||
/* ifa_flags */
|
||||
|
||||
#define IFA_F_SECONDARY 0x01
|
||||
#define IFA_F_TEMPORARY IFA_F_SECONDARY
|
||||
|
||||
#define IFA_F_NODAD 0x02
|
||||
#define IFA_F_OPTIMISTIC 0x04
|
||||
#define IFA_F_DADFAILED 0x08
|
||||
#define IFA_F_HOMEADDRESS 0x10
|
||||
#define IFA_F_DEPRECATED 0x20
|
||||
#define IFA_F_TENTATIVE 0x40
|
||||
#define IFA_F_PERMANENT 0x80
|
||||
#define IFA_F_MANAGETEMPADDR 0x100
|
||||
#define IFA_F_NOPREFIXROUTE 0x200
|
||||
#define IFA_F_MCAUTOJOIN 0x400
|
||||
#define IFA_F_STABLE_PRIVACY 0x800
|
||||
|
||||
/* backwards compatibility for userspace */
|
||||
|
||||
#define IFA_RTA(r) ((FAR struct rtattr *)(((FAR char *)(r)) + \
|
||||
NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
|
||||
#define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct ifaddrmsg))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* RTM_NEWADDR, RTM_DELADDR, RTM_GETADDR
|
||||
*
|
||||
* Add, remove or receive information about an IP address associated with
|
||||
* an interface. These messages contain an ifaddrmsg structure, optionally
|
||||
* followed by rtattr routing attributes.
|
||||
*/
|
||||
|
||||
struct ifaddrmsg
|
||||
{
|
||||
uint8_t ifa_family; /* Address type: AF_INET or AF_INET6 */
|
||||
uint8_t ifa_prefixlen; /* Prefix length of address */
|
||||
uint8_t ifa_flags; /* Address flags. See IFA_F_* definitions */
|
||||
uint8_t ifa_scope; /* Address scope */
|
||||
int32_t ifa_index; /* Unique interface index */
|
||||
};
|
||||
|
||||
/* Important comment:
|
||||
* IFA_ADDRESS is prefix address, rather than local interface address.
|
||||
* It makes no difference for normally configured broadcast interfaces,
|
||||
* but for point-to-point IFA_ADDRESS is DESTINATION address,
|
||||
* local address is supplied in IFA_LOCAL attribute.
|
||||
*
|
||||
* IFA_FLAGS is a u32 attribute that extends the u8 field ifa_flags.
|
||||
* If present, the value from struct ifaddrmsg will be ignored.
|
||||
*/
|
||||
|
||||
enum
|
||||
{
|
||||
IFA_UNSPEC,
|
||||
IFA_ADDRESS,
|
||||
IFA_LOCAL,
|
||||
IFA_LABEL,
|
||||
IFA_BROADCAST,
|
||||
IFA_ANYCAST,
|
||||
IFA_CACHEINFO,
|
||||
IFA_MULTICAST,
|
||||
IFA_FLAGS,
|
||||
__IFA_MAX,
|
||||
};
|
||||
|
||||
struct ifa_cacheinfo
|
||||
{
|
||||
uint32_t ifa_prefered;
|
||||
uint32_t ifa_valid;
|
||||
uint32_t cstamp; /* created timestamp, hundredths of seconds */
|
||||
uint32_t tstamp; /* updated timestamp, hundredths of seconds */
|
||||
};
|
||||
|
||||
#endif /* __INCLUDE_NETPACKET_IF_ADDR_H */
|
||||
@@ -0,0 +1,493 @@
|
||||
/****************************************************************************
|
||||
* include/netpacket/netlink.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NETPACKET_NETLINK_H
|
||||
#define __INCLUDE_NETPACKET_NETLINK_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <netpacket/if_addr.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Netlink socket protocols *************************************************/
|
||||
|
||||
/* The AF_NETLINK family offers multiple protocol subsets. Each interfaces
|
||||
* to a different kernel component and has a different messaging subset. The
|
||||
* subset is referenced by the protocol field in the socket call:
|
||||
*
|
||||
* int socket(AF_NETLINK, SOCK_DGRAM or SOCK_RAW, protocol)
|
||||
*
|
||||
* Ref. Wikipedia.org
|
||||
*
|
||||
* Namespace is Linux compatible.
|
||||
*/
|
||||
|
||||
#define NETLINK_ROUTE 0 /* Routing/device hook for user-space
|
||||
* routing daemons (default) */
|
||||
#define NETLINK_UNUSED 1 /* Unused number */
|
||||
#define NETLINK_USERSOCK 2 /* Reserved for user mode socket protocols */
|
||||
#define NETLINK_FIREWALL 3 /* Interface to receive packets from
|
||||
* the firewall */
|
||||
#define NETLINK_SOCK_DIAG 4 /* Socket monitoring */
|
||||
#define NETLINK_NFLOG 5 /* netfilter/iptables ULOG */
|
||||
#define NETLINK_XFRM 6 /* Interface to IPsec security databases
|
||||
* for key-manager daemons using the
|
||||
* Internet Key Exchange protocol. */
|
||||
#define NETLINK_SELINUX 7 /* SELinux event notifications */
|
||||
#define NETLINK_ISCSI 8 /* Open-iSCSI */
|
||||
#define NETLINK_AUDIT 9 /* Interface to auditing sub-system */
|
||||
#define NETLINK_FIB_LOOKUP 10
|
||||
#define NETLINK_CONNECTOR 11
|
||||
#define NETLINK_NETFILTER 12 /* netfilter subsystem */
|
||||
#define NETLINK_IP6_FW 13 /* Interface to transport packets from
|
||||
* netfilter to user-space. */
|
||||
#define NETLINK_DNRTMSG 14 /* DECnet routing messages */
|
||||
#define NETLINK_KOBJECT_UEVENT 15 /* Kernel messages to userspace */
|
||||
#define NETLINK_GENERIC 16
|
||||
/* NETLINK_DM (DM Events) */
|
||||
#define NETLINK_SCSITRANSPORT 18 /* SCSI Transports */
|
||||
#define NETLINK_ECRYPTFS 19
|
||||
#define NETLINK_RDMA 20
|
||||
#define NETLINK_CRYPTO 21 /* Crypto layer */
|
||||
#define NETLINK_SMC 22 /* SMC monitoring */
|
||||
|
||||
/* Definitions associated with struct sockaddr_nl ***************************/
|
||||
|
||||
/* Flags values */
|
||||
|
||||
#define NLM_F_REQUEST 0x0001 /* It is request message. */
|
||||
#define NLM_F_MULTI 0x0002 /* Multipart message, terminated by NLMSG_DONE */
|
||||
#define NLM_F_ACK 0x0004 /* Reply with ack, with zero or error code */
|
||||
#define NLM_F_ECHO 0x0008 /* Echo this request */
|
||||
#define NLM_F_DUMP_INTR 0x0010 /* Dump was inconsistent due to sequence change */
|
||||
#define NLM_F_DUMP_FILTERED 0x0020 /* Dump was filtered as requested */
|
||||
|
||||
/* Modifiers to GET request */
|
||||
|
||||
#define NLM_F_ROOT 0x0100 /* specify tree root */
|
||||
#define NLM_F_MATCH 0x0200 /* return all matching */
|
||||
#define NLM_F_ATOMIC 0x0400 /* atomic GET */
|
||||
#define NLM_F_DUMP (NLM_F_ROOT | NLM_F_MATCH)
|
||||
|
||||
/* Modifiers to NEW request */
|
||||
|
||||
#define NLM_F_REPLACE 0x0100 /* Override existing */
|
||||
#define NLM_F_EXCL 0x0200 /* Do not touch, if it exists */
|
||||
#define NLM_F_CREATE 0x0400 /* Create, if it does not exist */
|
||||
#define NLM_F_APPEND 0x0800 /* Add to end of list */
|
||||
|
||||
/* Modifiers to DELETE request */
|
||||
|
||||
#define NLM_F_NONREC 0x0100 /* Do not delete recursively */
|
||||
|
||||
/* Flags for ACK message */
|
||||
|
||||
#define NLM_F_CAPPED 0x0100 /* request was capped */
|
||||
#define NLM_F_ACK_TLVS 0x0200 /* extended ACK TVLs were included */
|
||||
|
||||
/* Definitions for struct nlmsghdr ******************************************/
|
||||
|
||||
#define NLMSG_MASK (sizeof(uint32_t) - 1)
|
||||
#define NLMSG_ALIGN(n) (((n) + NLMSG_MASK) & ~NLMSG_MASK)
|
||||
#define NLMSG_HDRLEN sizeof(struct nlmsghdr)
|
||||
#define NLMSG_LENGTH(n) (NLMSG_HDRLEN + (n))
|
||||
#define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
|
||||
#define NLMSG_DATA(hdr) ((FAR void *)(((FAR char *)hdr) + NLMSG_HDRLEN))
|
||||
#define NLMSG_NEXT(hdr, n) \
|
||||
((n) -= NLMSG_ALIGN((hdr)->nlmsg_len), \
|
||||
(FAR struct nlmsghdr *) \
|
||||
(((FAR char *)(hdr)) + NLMSG_ALIGN((hdr)->nlmsg_len)))
|
||||
#define NLMSG_OK(nlh, len) \
|
||||
((len) >= (int)sizeof(struct nlmsghdr) && \
|
||||
(nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
|
||||
(nlh)->nlmsg_len <= (len))
|
||||
#define NLMSG_PAYLOAD(hdr, len) \
|
||||
((hdr)->nlmsg_len - NLMSG_SPACE(len))
|
||||
|
||||
#define NLMSG_NOOP 1 /* Nothing */
|
||||
#define NLMSG_ERROR 2 /* Error */
|
||||
#define NLMSG_DONE 3 /* End of a dump */
|
||||
#define NLMSG_OVERRUN 4 /* Data lost */
|
||||
#define NLMSG_MIN_TYPE 16 /* < 16: Reserved control messages */
|
||||
|
||||
/* Attribute definitions for struct rtattr **********************************/
|
||||
|
||||
/* Macros to handle attribute lists */
|
||||
|
||||
#define RTA_MASK (sizeof(uint32_t) - 1)
|
||||
#define RTA_ALIGN(n) (((n) + RTA_MASK) & ~RTA_MASK)
|
||||
#define RTA_OK(rta, n) \
|
||||
((n) >= (int)sizeof(struct rtattr) && \
|
||||
(rta)->rta_len >= sizeof(struct rtattr) && \
|
||||
(rta)->rta_len <= (n))
|
||||
#define RTA_NEXT(rta, attrlen) \
|
||||
((attrlen) -= RTA_ALIGN((rta)->rta_len), \
|
||||
(FAR struct rtattr *)(((FAR char *)(rta)) + RTA_ALIGN((rta)->rta_len)))
|
||||
#define RTA_LENGTH(n) (sizeof(struct rtattr) + (n))
|
||||
#define RTA_SPACE(n) RTA_ALIGN(RTA_LENGTH(n))
|
||||
#define RTA_DATA(rta) ((FAR void *)(((FAR char *)(rta)) + RTA_LENGTH(0)))
|
||||
#define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
|
||||
|
||||
/* NETLINK_ROUTE: Routing table attributes */
|
||||
|
||||
#define RTA_UNSPEC 0 /* Inored */
|
||||
#define RTA_DST 1 /* Argument: Route destination address */
|
||||
#define RTA_SRC 2 /* Argument: Route source address */
|
||||
#define RTA_IIF 3 /* Argument: Input interface index */
|
||||
#define RTA_OIF 4 /* Argument: Output interface index */
|
||||
#define RTA_GATEWAY 5 /* Argument: Gateway address of the route */
|
||||
#define RTA_GENMASK 6 /* Argument: Network address mask of sub-net */
|
||||
|
||||
/* NETLINK_ROUTE protocol message types *************************************/
|
||||
|
||||
/* Link layer:
|
||||
*
|
||||
* RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK
|
||||
* Create, remove or get information about a specific network interface.
|
||||
* These messages contain an ifinfomsg structure followed by a series
|
||||
* of rtattr structures.
|
||||
*/
|
||||
|
||||
#define RTM_NEWLINK 16
|
||||
#define RTM_DELLINK 17
|
||||
#define RTM_GETLINK 18
|
||||
#define RTM_SETLINK 19
|
||||
|
||||
/* Address settings:
|
||||
*
|
||||
* RTM_NEWADDR, RTM_DELADDR, RTM_GETADDR
|
||||
* Add, remove or receive information about an IP address associated with
|
||||
* an interface. These messages contain an ifaddrmsg structure, optionally
|
||||
* followed by rtattr routing attributes.
|
||||
*/
|
||||
|
||||
#define RTM_NEWADDR 20
|
||||
#define RTM_DELADDR 21
|
||||
#define RTM_GETADDR 22
|
||||
|
||||
/* Routing tables:
|
||||
*
|
||||
* RTM_NEWROUTE, RTM_DELROUTE, RTM_GETROUTE
|
||||
* Create, remove or receive information about a network route. These
|
||||
* messages contain an rtmsg structure with an optional sequence of
|
||||
* rtattr structures following.
|
||||
*
|
||||
* For RTM_GETROUTE, setting rtm_dst_len and rtm_src_len to 0 means you
|
||||
* get all entries for the specified routing table. For the other fields,
|
||||
* except rtm_table and rtm_protocol, 0 is the wildcard.
|
||||
*/
|
||||
|
||||
#define RTM_NEWROUTE 24
|
||||
#define RTM_DELROUTE 25
|
||||
#define RTM_GETROUTE 26
|
||||
|
||||
/* Neighbor cache:
|
||||
*
|
||||
* RTM_NEWNEIGH, RTM_DELNEIGH, RTM_GETNEIGH
|
||||
* Add, remove or receive information about a neighbor table entry (e.g.,
|
||||
* an ARP entry). The message contains an ndmsg structure.
|
||||
*/
|
||||
|
||||
#define RTM_NEWNEIGH 28
|
||||
#define RTM_DELNEIGH 29
|
||||
#define RTM_GETNEIGH 30
|
||||
|
||||
/* Routing rules:
|
||||
*
|
||||
* RTM_NEWRULE, RTM_DELRULE, RTM_GETRULE
|
||||
* Add, delete or retrieve a routing rule. Carries a struct rtmsg
|
||||
*/
|
||||
|
||||
#define RTM_NEWRULE 32
|
||||
#define RTM_DELRULE 33
|
||||
#define RTM_GETRULE 34
|
||||
|
||||
/* Queuing discipline settings:
|
||||
*
|
||||
* RTM_NEWQDISC, RTM_DELQDISC, RTM_GETQDISC
|
||||
* Add, remove or get a queuing discipline. The message contains a
|
||||
* struct tcmsg and may be followed by a series of attributes.
|
||||
*/
|
||||
|
||||
#define RTM_NEWQDISC 36
|
||||
#define RTM_DELQDISC 37
|
||||
#define RTM_GETQDISC 38
|
||||
|
||||
/* Traffic classes used with queues:
|
||||
*
|
||||
* RTM_NEWTCLASS, RTM_DELTCLASS, RTM_GETTCLASS
|
||||
* Add, remove or get a traffic class. These messages contain a struct
|
||||
* tcmsg as described above.
|
||||
*/
|
||||
|
||||
#define RTM_NEWTCLASS 40
|
||||
#define RTM_DELTCLASS 41
|
||||
#define RTM_GETTCLASS 42
|
||||
|
||||
/* Traffic filters:
|
||||
*
|
||||
* RTM_NEWTFILTER, RTM_DELTFILTER, RTM_GETTFILTER
|
||||
* Add, remove or receive information about a traffic filter. These
|
||||
* messages contain a struct tcmsg as described above.
|
||||
*/
|
||||
|
||||
#define RTM_NEWTFILTER 44
|
||||
#define RTM_DELTFILTER 45
|
||||
#define RTM_GETTFILTER 46
|
||||
|
||||
/* Others: */
|
||||
|
||||
#define RTM_NEWACTION 48
|
||||
#define RTM_DELACTION 49
|
||||
#define RTM_GETACTION 50
|
||||
#define RTM_NEWPREFIX 52
|
||||
#define RTM_GETMULTICAST 58
|
||||
#define RTM_GETANYCAST 62
|
||||
#define RTM_NEWNEIGHTBL 64
|
||||
#define RTM_GETNEIGHTBL 66
|
||||
#define RTM_SETNEIGHTBL 67
|
||||
|
||||
#define RTM_BASE 16
|
||||
#define RTM_MAX 67
|
||||
|
||||
/* Definitions for struct ifinfomsg *****************************************/
|
||||
|
||||
#define IFLA_RTA(r) ((FAR struct rtattr *) \
|
||||
(((FAR char *)(r)) + \
|
||||
NLMSG_ALIGN(sizeof(struct ifinfomsg))))
|
||||
#define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct ifinfomsg))
|
||||
|
||||
/* Values for rta_type */
|
||||
|
||||
#define IFLA_IFNAME 1
|
||||
|
||||
/* Definitions for struct rtmsg *********************************************/
|
||||
|
||||
#define RTM_RTA(r) ((FAR struct rtattr *)\
|
||||
(((FAR char *)(r)) + \
|
||||
NLMSG_ALIGN(sizeof(struct rtmsg))))
|
||||
#define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct rtmsg))
|
||||
|
||||
/* rtm_table. Routing table identifiers */
|
||||
|
||||
#define RT_TABLE_UNSPEC 0
|
||||
/* 1-251: User defined values */
|
||||
#define RT_TABLE_MAIN 254
|
||||
#define RT_TABLE_MAX 0xffffffff
|
||||
|
||||
/* rtm_type */
|
||||
|
||||
#define RTN_UNSPEC 0
|
||||
#define RTN_UNICAST 1 /* Gateway or direct route */
|
||||
#define RTN_LOCAL 2 /* Accept locally */
|
||||
#define RTN_BROADCAST 3 /* Accept locally as broadcast;
|
||||
* send as broadcast */
|
||||
#define RTN_ANYCAST 4 /* Accept locally as broadcast
|
||||
* but send as unicast */
|
||||
#define RTN_MULTICAST 5 /* Multicast route */
|
||||
|
||||
/* rtm_protocol */
|
||||
|
||||
#define RTPROT_UNSPEC 0
|
||||
#define RTPROT_REDIRECT 1 /* Route installed by ICMP redirects */
|
||||
#define RTPROT_KERNEL 2 /* Route installed by kernel */
|
||||
#define RTPROT_BOOT 3 /* Route installed during boot */
|
||||
#define RTPROT_STATIC 4 /* Route installed by administrator */
|
||||
#define RTPROT_RA 9 /* RDISC/ND router advertisements */
|
||||
#define RTPROT_DHCP 16 /* DHCP client */
|
||||
|
||||
/* rtm_scope */
|
||||
|
||||
#define RT_SCOPE_UNIVERSE 0 /* Global route */
|
||||
/* 1-199: User defined values */
|
||||
#define RT_SCOPE_SITE 200 /* Interior route in local system */
|
||||
#define RT_SCOPE_LINK 253 /* Route on this link */
|
||||
#define RT_SCOPE_HOST 254 /* Route on local host */
|
||||
#define RT_SCOPE_NOWHERE 255 /* Destination does not exist */
|
||||
|
||||
/* RTnetlink multicast groups (userspace) */
|
||||
|
||||
#define RTMGRP_LINK 1
|
||||
#define RTMGRP_NOTIFY 2
|
||||
#define RTMGRP_NEIGH 4
|
||||
#define RTMGRP_TC 8
|
||||
|
||||
#define RTMGRP_IPV4_IFADDR 0x10
|
||||
#define RTMGRP_IPV4_MROUTE 0x20
|
||||
#define RTMGRP_IPV4_ROUTE 0x40
|
||||
#define RTMGRP_IPV4_RULE 0x80
|
||||
|
||||
#define RTMGRP_IPV6_IFADDR 0x100
|
||||
#define RTMGRP_IPV6_MROUTE 0x200
|
||||
#define RTMGRP_IPV6_ROUTE 0x400
|
||||
#define RTMGRP_IPV6_IFINFO 0x800
|
||||
|
||||
#define RTMGRP_DECnet_IFADDR 0x1000
|
||||
#define RTMGRP_DECnet_ROUTE 0x4000
|
||||
|
||||
#define RTMGRP_IPV6_PREFIX 0x20000
|
||||
|
||||
/* RTnetlink multicast groups */
|
||||
|
||||
#define RTNLGRP_NONE 0
|
||||
#define RTNLGRP_LINK 1
|
||||
#define RTNLGRP_NOTIFY 2
|
||||
#define RTNLGRP_NEIGH 3
|
||||
#define RTNLGRP_TC 4
|
||||
#define RTNLGRP_IPV4_IFADDR 5
|
||||
#define RTNLGRP_IPV4_MROUTE 6
|
||||
#define RTNLGRP_IPV4_ROUTE 7
|
||||
#define RTNLGRP_IPV4_RULE 8
|
||||
#define RTNLGRP_IPV6_IFADDR 9
|
||||
#define RTNLGRP_IPV6_MROUTE 10
|
||||
#define RTNLGRP_IPV6_ROUTE 11
|
||||
#define RTNLGRP_IPV6_IFINFO 12
|
||||
#define RTNLGRP_DECnet_IFADDR 13
|
||||
#define RTNLGRP_NOP2 14
|
||||
#define RTNLGRP_DECnet_ROUTE 15
|
||||
#define RTNLGRP_DECnet_RULE 16
|
||||
#define RTNLGRP_NOP4 17
|
||||
#define RTNLGRP_IPV6_PREFIX 18
|
||||
#define RTNLGRP_IPV6_RULE 19
|
||||
#define RTNLGRP_ND_USEROPT 20
|
||||
#define RTNLGRP_PHONET_IFADDR 21
|
||||
#define RTNLGRP_PHONET_ROUTE 22
|
||||
#define RTNLGRP_DCB 23
|
||||
#define RTNLGRP_IPV4_NETCONF 24
|
||||
#define RTNLGRP_IPV6_NETCONF 25
|
||||
#define RTNLGRP_MDB 26
|
||||
#define RTNLGRP_MPLS_ROUTE 27
|
||||
#define RTNLGRP_NSID 28
|
||||
#define RTNLGRP_MAX 29
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Netlink socket address type. */
|
||||
|
||||
struct sockaddr_nl
|
||||
{
|
||||
sa_family_t nl_family; /* AF_NETLINK */
|
||||
uint16_t nl_pad; /* Zero */
|
||||
uint32_t nl_pid; /* Port ID */
|
||||
uint32_t nl_groups; /* Multicast groups mask */
|
||||
};
|
||||
|
||||
/* Packet structure. The Netlink message header, struct nlmsghdr, must be
|
||||
* prepared by the caller. The Netlink socket generally works in a SOCK_RAW-
|
||||
* like mode (even if SOCK_DGRAM was used to create it).
|
||||
*
|
||||
* The data portion then contains a subsystem-specific message that may be
|
||||
* further nested.
|
||||
*/
|
||||
|
||||
struct nlmsghdr
|
||||
{
|
||||
uint32_t nlmsg_len; /* Length of message including header */
|
||||
uint16_t nlmsg_type; /* Message content */
|
||||
uint16_t nlmsg_flags; /* Additional flags */
|
||||
uint32_t nlmsg_seq; /* Sequence number */
|
||||
uint32_t nlmsg_pid; /* Sending process port ID */
|
||||
/* Data follows */
|
||||
};
|
||||
|
||||
/* NETLINK_ROUTE Message Structures *****************************************/
|
||||
|
||||
/* RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK
|
||||
*
|
||||
* Create, remove or get information about a specific network interface.
|
||||
* These messages contain an ifinfomsg structure followed by a series
|
||||
* of rtattr structures.
|
||||
*
|
||||
* These attributes should be manipulated using only the RTA_*
|
||||
*/
|
||||
|
||||
struct rtattr
|
||||
{
|
||||
uint16_t rta_len; /* Length of option */
|
||||
uint16_t rta_type; /* Type of option */
|
||||
/* Data follows */
|
||||
};
|
||||
|
||||
struct ifinfomsg
|
||||
{
|
||||
uint8_t ifi_family; /* AF_UNSPEC */
|
||||
uint8_t ifi_pad;
|
||||
uint16_t ifi_type; /* Device type (ARPHRD) */
|
||||
int32_t ifi_index; /* Unique interface index */
|
||||
uint32_t ifi_flags; /* Device IFF_* flags */
|
||||
uint32_t ifi_change; /* Change mask, must always be 0xffffffff */
|
||||
};
|
||||
|
||||
/* General form of address family dependent message. */
|
||||
|
||||
struct rtgenmsg
|
||||
{
|
||||
uint8_t rtgen_family;
|
||||
};
|
||||
|
||||
/* RTM_NEWNEIGH, RTM_DELNEIGH, RTM_GETNEIGH
|
||||
* Add, remove or receive information about a neighbor table entry (e.g.,
|
||||
* an ARP entry). The message contains an ndmsg structure.
|
||||
*/
|
||||
|
||||
struct ndmsg
|
||||
{
|
||||
uint8_t ndm_family;
|
||||
uint8_t ndm_pad1;
|
||||
uint16_t ndm_pad2;
|
||||
int32_t ndm_ifindex;
|
||||
uint16_t ndm_state;
|
||||
uint8_t ndm_flags;
|
||||
uint8_t ndm_type;
|
||||
};
|
||||
|
||||
/* Structures used in routing table administration. */
|
||||
|
||||
struct rtmsg
|
||||
{
|
||||
uint8_t rtm_family;
|
||||
uint8_t rtm_dst_len;
|
||||
uint8_t rtm_src_len;
|
||||
uint8_t rtm_tos;
|
||||
uint8_t rtm_table; /* Routing table id */
|
||||
uint8_t rtm_protocol; /* Routing protocol; See RTPROT_ definitions. */
|
||||
uint8_t rtm_scope; /* See RT_SCOPE_* definitions */
|
||||
uint8_t rtm_type; /* See RTN_* definitions */
|
||||
uint32_t rtm_flags;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __INCLUDE_NETPACKET_NETLINK_H */
|
||||
@@ -0,0 +1,61 @@
|
||||
/****************************************************************************
|
||||
* include/netpacket/packet.h
|
||||
* Definitions for use with AF_PACKET sockets
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Daniel Laszlo Sitzer <dlsitzer@gmail.com>
|
||||
*
|
||||
* Includes some definitions that a compatible with the LGPL GNU C Library
|
||||
* header file of the same name.
|
||||
*
|
||||
* 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 __INCLUDE_NETPACKET_PACKET_H
|
||||
#define __INCLUDE_NETPACKET_PACKET_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct sockaddr_ll
|
||||
{
|
||||
uint16_t sll_family;
|
||||
uint16_t sll_protocol;
|
||||
int16_t sll_ifindex;
|
||||
};
|
||||
|
||||
#endif /* __INCLUDE_NETPACKET_PACKET_H */
|
||||
@@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
* include/netpacket/rpmsg.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NETPACKET_RPMSG_H
|
||||
#define __INCLUDE_NETPACKET_RPMSG_H
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define RPMSG_SOCKET_CPU_SIZE 16
|
||||
#define RPMSG_SOCKET_NAME_SIZE 32
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
struct sockaddr_rpmsg
|
||||
{
|
||||
sa_family_t rp_family;
|
||||
char rp_cpu[RPMSG_SOCKET_CPU_SIZE];
|
||||
char rp_name[RPMSG_SOCKET_NAME_SIZE];
|
||||
};
|
||||
|
||||
#endif /* __INCLUDE_NETPACKET_RPMSG_H */
|
||||
@@ -0,0 +1,141 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/1wire/ds28e17.h
|
||||
*
|
||||
* Copyright (C) 2018 Haltian Ltd. All rights reserved.
|
||||
* Author: Juha Niskanen <juha.niskanen@haltian.com>
|
||||
*
|
||||
* 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 __INCLUDE_NUTTX_1WIRE_DS28E17_H
|
||||
#define __INCLUDE_NUTTX_1WIRE_DS28E17_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nuttx/drivers/1wire.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Default how many converters in a bus. */
|
||||
|
||||
#define DS_DEFAULT_MAXSLAVES 10
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct ds28e17_dev_s;
|
||||
struct i2c_master_s;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ds28e17_search
|
||||
*
|
||||
* Description:
|
||||
* Search all DS28E17 devices from a 1-wire network.
|
||||
*
|
||||
* Input Parameters:
|
||||
* priv - Pointer to the associated DS28E17
|
||||
* cb_search - Callback to call on each device found
|
||||
* arg - Argument passed to cb_search
|
||||
*
|
||||
* Return Value:
|
||||
* Number of DS28E17 devices present.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int ds28e17_search(FAR struct ds28e17_dev_s *priv,
|
||||
CODE void (*cb_search)(int family,
|
||||
uint64_t romcode,
|
||||
FAR void *arg),
|
||||
FAR void *arg);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ds28e17_lower_half
|
||||
*
|
||||
* Description:
|
||||
* Initialize the lower half of the DS28E17 by creating a i2c_master_s
|
||||
* for the virtual i2c master and link it to the associated DS28E17 and
|
||||
* its port.
|
||||
*
|
||||
* Input Parameters:
|
||||
* priv - Pointer to the associated DS28E17
|
||||
* romcode - The unique 64-bit address in 1-wire network.
|
||||
* Use zero for skip-ROM mode.
|
||||
*
|
||||
* Returned Value:
|
||||
* i2c device instance; NULL on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct i2c_master_s *ds28e17_lower_half(FAR struct ds28e17_dev_s *priv,
|
||||
uint64_t romcode);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ds28e17_lower_half_unregister
|
||||
*
|
||||
* Description:
|
||||
* Put back the lower half of the DS28E17.
|
||||
*
|
||||
* Input Parameters:
|
||||
* priv - Pointer to the associated DS28E17
|
||||
* i2cdev - i2c device instance from ds28e17_lower_half()
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int ds28e17_lower_half_unregister(FAR struct ds28e17_dev_s *priv,
|
||||
FAR struct i2c_master_s *i2cdev);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ds28e17_initialize
|
||||
*
|
||||
* Description:
|
||||
* Returns a common DS28E17 device from 1-wire lower half device
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - The allocated 1-wire lower half
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct ds28e17_dev_s *ds28e17_initialize(FAR struct onewire_dev_s *dev);
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_1WIRE_DS28E17_H */
|
||||
@@ -0,0 +1,346 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/addrenv.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_ADDRENV_H
|
||||
#define __INCLUDE_NUTTX_ADDRENV_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
# include <signal.h>
|
||||
# include <nuttx/mm/mm.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
/* Pre-requisites */
|
||||
|
||||
#ifndef CONFIG_MM_PGALLOC
|
||||
# error CONFIG_MM_PGALLOC not defined
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_MM_PGSIZE
|
||||
# error CONFIG_MM_PGSIZE not defined
|
||||
#endif
|
||||
|
||||
/* .text region */
|
||||
|
||||
#ifndef CONFIG_ARCH_TEXT_VBASE
|
||||
# error CONFIG_ARCH_TEXT_VBASE not defined
|
||||
# define CONFIG_ARCH_TEXT_VBASE 0
|
||||
#endif
|
||||
|
||||
#if (CONFIG_ARCH_TEXT_VBASE & CONFIG_MM_MASK) != 0
|
||||
# error CONFIG_ARCH_TEXT_VBASE not aligned to page boundary
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ARCH_TEXT_NPAGES
|
||||
# warning CONFIG_ARCH_TEXT_NPAGES not defined
|
||||
# define CONFIG_ARCH_TEXT_NPAGES 1
|
||||
#endif
|
||||
|
||||
#define ARCH_TEXT_SIZE (CONFIG_ARCH_TEXT_NPAGES * CONFIG_MM_PGSIZE)
|
||||
#define ARCH_TEXT_VEND (CONFIG_ARCH_TEXT_VBASE + ARCH_TEXT_SIZE)
|
||||
|
||||
/* .bss/.data region */
|
||||
|
||||
#ifndef CONFIG_ARCH_DATA_VBASE
|
||||
# error CONFIG_ARCH_DATA_VBASE not defined
|
||||
# define CONFIG_ARCH_DATA_VBASE ARCH_TEXT_VEND
|
||||
#endif
|
||||
|
||||
#if (CONFIG_ARCH_DATA_VBASE & CONFIG_MM_MASK) != 0
|
||||
# error CONFIG_ARCH_DATA_VBASE not aligned to page boundary
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ARCH_DATA_NPAGES
|
||||
# warning CONFIG_ARCH_DATA_NPAGES not defined
|
||||
# define CONFIG_ARCH_DATA_NPAGES 1
|
||||
#endif
|
||||
|
||||
#define ARCH_DATA_SIZE (CONFIG_ARCH_DATA_NPAGES * CONFIG_MM_PGSIZE)
|
||||
#define ARCH_DATA_VEND (CONFIG_ARCH_DATA_VBASE + ARCH_DATA_SIZE)
|
||||
|
||||
/* Reserved .bss/.data region. In the kernel build (CONFIG_BUILD_KERNEL),
|
||||
* the region at the beginning of the .bss/.data region is reserved for use
|
||||
* by the OS. This reserved region contains support for:
|
||||
*
|
||||
* 1. The task group's heap memory management data structures and
|
||||
* 2. Support for delivery of signals.
|
||||
*
|
||||
* We don't use sizeof(struct addrenv_reserve_s) but, instead, a nice
|
||||
* even number that we must be assure is greater than or equal to
|
||||
* sizeof(struct addrenv_reserve_s)
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
# define ARCH_DATA_RESERVE_SIZE 512
|
||||
#else
|
||||
# define ARCH_DATA_RESERVE_SIZE 0
|
||||
#endif
|
||||
|
||||
/* Heap region */
|
||||
|
||||
#ifndef CONFIG_ARCH_HEAP_VBASE
|
||||
# error CONFIG_ARCH_HEAP_VBASE not defined
|
||||
# define CONFIG_ARCH_HEAP_VBASE ARCH_DATA_VEND
|
||||
#endif
|
||||
|
||||
#if (CONFIG_ARCH_HEAP_VBASE & CONFIG_MM_MASK) != 0
|
||||
# error CONFIG_ARCH_HEAP_VBASE not aligned to page boundary
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ARCH_HEAP_NPAGES
|
||||
# warning CONFIG_ARCH_HEAP_NPAGES not defined
|
||||
# define CONFIG_ARCH_HEAP_NPAGES 1
|
||||
#endif
|
||||
|
||||
#define ARCH_HEAP_SIZE (CONFIG_ARCH_HEAP_NPAGES * CONFIG_MM_PGSIZE)
|
||||
#define ARCH_HEAP_VEND (CONFIG_ARCH_HEAP_VBASE + ARCH_HEAP_SIZE)
|
||||
|
||||
#ifdef CONFIG_ARCH_STACK_DYNAMIC
|
||||
/* User stack region */
|
||||
|
||||
# ifndef CONFIG_ARCH_STACK_VBASE
|
||||
# error CONFIG_ARCH_STACK_VBASE not defined
|
||||
# define CONFIG_ARCH_STACK_VBASE ARCH_HEAP_VEND
|
||||
# endif
|
||||
|
||||
# if (CONFIG_ARCH_STACK_VBASE & CONFIG_MM_MASK) != 0
|
||||
# error CONFIG_ARCH_STACK_VBASE not aligned to page boundary
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_ARCH_STACK_NPAGES
|
||||
# warning CONFIG_ARCH_STACK_NPAGES not defined
|
||||
# define CONFIG_ARCH_STACK_NPAGES 1
|
||||
# endif
|
||||
|
||||
# define ARCH_STACK_SIZE (CONFIG_ARCH_STACK_NPAGES * CONFIG_MM_PGSIZE)
|
||||
# define ARCH_STACK_VEND (CONFIG_ARCH_STACK_VBASE + ARCH_STACK_SIZE)
|
||||
|
||||
#ifdef CONFIG_ARCH_KERNEL_STACK
|
||||
/* Kernel stack */
|
||||
|
||||
# ifndef CONFIG_ARCH_KERNEL_STACKSIZE
|
||||
# define CONFIG_ARCH_KERNEL_STACKSIZE 1568
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* A single page scratch region used for temporary mappings */
|
||||
|
||||
# define __ARCH_SHM_VBASE ARCH_STACK_VEND
|
||||
#else
|
||||
/* A single page scratch region used for temporary mappings */
|
||||
|
||||
# define __ARCH_SHM_VBASE ARCH_HEAP_VEND
|
||||
#endif
|
||||
|
||||
/* Shared memory regions */
|
||||
|
||||
#ifdef CONFIG_MM_SHM
|
||||
# ifndef CONFIG_ARCH_SHM_VBASE
|
||||
# error CONFIG_ARCH_SHM_VBASE not defined
|
||||
# define CONFIG_ARCH_SHM_VBASE __ARCH_SHM_VBASE
|
||||
# endif
|
||||
|
||||
# if (CONFIG_ARCH_SHM_VBASE & CONFIG_MM_MASK) != 0
|
||||
# error CONFIG_ARCH_SHM_VBASE not aligned to page boundary
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_ARCH_SHM_MAXREGIONS
|
||||
# warning CONFIG_ARCH_SHM_MAXREGIONS not defined
|
||||
# define CONFIG_ARCH_SHM_MAXREGIONS 1
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_ARCH_SHM_NPAGES
|
||||
# warning CONFIG_ARCH_SHM_NPAGES not defined
|
||||
# define CONFIG_ARCH_SHM_NPAGES 1
|
||||
# endif
|
||||
|
||||
# define ARCH_SHM_MAXPAGES (CONFIG_ARCH_SHM_NPAGES * CONFIG_ARCH_SHM_MAXREGIONS)
|
||||
# define ARCH_SHM_REGIONSIZE (CONFIG_ARCH_SHM_NPAGES * CONFIG_MM_PGSIZE)
|
||||
# define ARCH_SHM_SIZE (CONFIG_ARCH_SHM_MAXREGIONS * ARCH_SHM_REGIONSIZE)
|
||||
# define ARCH_SHM_VEND (CONFIG_ARCH_SHM_VBASE + ARCH_SHM_SIZE)
|
||||
|
||||
# define ARCH_SCRATCH_VBASE ARCH_SHM_VEND
|
||||
#else
|
||||
# define ARCH_SCRATCH_VBASE __ARCH_SHM_VBASE
|
||||
#endif
|
||||
|
||||
/* There is no need to use the scratch memory region if the page pool memory
|
||||
* is statically mapped.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ARCH_PGPOOL_MAPPING
|
||||
|
||||
# ifndef CONFIG_ARCH_PGPOOL_PBASE
|
||||
# error CONFIG_ARCH_PGPOOL_PBASE not defined
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_ARCH_PGPOOL_VBASE
|
||||
# error CONFIG_ARCH_PGPOOL_VBASE not defined
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_ARCH_PGPOOL_SIZE
|
||||
# error CONFIG_ARCH_PGPOOL_SIZE not defined
|
||||
# endif
|
||||
|
||||
# define CONFIG_ARCH_PGPOOL_PEND \
|
||||
(CONFIG_ARCH_PGPOOL_PBASE + CONFIG_ARCH_PGPOOL_SIZE)
|
||||
# define CONFIG_ARCH_PGPOOL_VEND \
|
||||
(CONFIG_ARCH_PGPOOL_VBASE + CONFIG_ARCH_PGPOOL_SIZE)
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/* Reserved .bss/.data region. In the kernel build (CONFIG_BUILD_KERNEL),
|
||||
* the region at the beginning of the .bss/.data region is reserved for use
|
||||
* by the OS. This reserved region contains support for:
|
||||
*
|
||||
* 1. The task group's heap memory management data structures and
|
||||
* 2. Support for delivery of signals.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
/* This is the type of the signal handler trampoline routine. This
|
||||
* trampoline is called directly from kernel logic. It simply forwards the
|
||||
* signal information to the real signal handler. When the signal handler
|
||||
* returns, this function issues a system call in order to return in kernel
|
||||
* mode.
|
||||
*/
|
||||
|
||||
typedef CODE void (*addrenv_sigtramp_t)(_sa_sigaction_t sighand, int signo,
|
||||
FAR siginfo_t *info,
|
||||
FAR void *ucontext);
|
||||
|
||||
/* This structure describes the format of the .bss/.data reserved area */
|
||||
|
||||
struct addrenv_reserve_s
|
||||
{
|
||||
addrenv_sigtramp_t ar_sigtramp; /* Signal trampoline */
|
||||
struct mm_heap_s ar_usrheap; /* User space heap structure */
|
||||
};
|
||||
|
||||
/* Each instance of this structure resides at the beginning of the user-
|
||||
* space .bss/.data region. This macro is provided to simplify access:
|
||||
*/
|
||||
|
||||
#define ARCH_DATA_RESERVE \
|
||||
((FAR struct addrenv_reserve_s *)CONFIG_ARCH_DATA_VBASE)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Address Environment Interfaces
|
||||
*
|
||||
* Low-level interfaces used in binfmt/ to instantiate tasks with address
|
||||
* environments. These interfaces all operate on type group_addrenv_t which
|
||||
* is an abstract representation of a task group's address environment and
|
||||
* must be defined in arch/arch.h if CONFIG_ARCH_ADDRENV is defined.
|
||||
*
|
||||
* up_addrenv_create - Create an address environment
|
||||
* up_addrenv_destroy - Destroy an address environment.
|
||||
* up_addrenv_vtext - Returns the virtual base address of the .text
|
||||
* address environment
|
||||
* up_addrenv_vdata - Returns the virtual base address of the .bss/.data
|
||||
* address environment
|
||||
* up_addrenv_heapsize - Returns the size of the initial heap allocation.
|
||||
* up_addrenv_select - Instantiate an address environment
|
||||
* up_addrenv_restore - Restore an address environment
|
||||
* up_addrenv_clone - Copy an address environment from one location to
|
||||
* another.
|
||||
*
|
||||
* Higher-level interfaces used by the tasking logic. These interfaces are
|
||||
* used by the functions in sched/ and all operate on the thread which whose
|
||||
* group been assigned an address environment by up_addrenv_clone().
|
||||
*
|
||||
* up_addrenv_attach - Clone the address environment assigned to one TCB
|
||||
* to another. This operation is done when a pthread
|
||||
* is created that share's the same group address
|
||||
* environment.
|
||||
* up_addrenv_detach - Release the thread's reference to an address
|
||||
* environment when a task/thread exits.
|
||||
*
|
||||
* CONFIG_ARCH_STACK_DYNAMIC=y indicates that the user process stack resides
|
||||
* in its own address space. This options is also *required* if
|
||||
* CONFIG_BUILD_KERNEL and CONFIG_LIBC_EXECFUNCS are selected. Why?
|
||||
* Because the caller's stack must be preserved in its own address space
|
||||
* when we instantiate the environment of the new process in order to
|
||||
* initialize it.
|
||||
*
|
||||
* NOTE: The naming of the CONFIG_ARCH_STACK_DYNAMIC selection implies that
|
||||
* dynamic stack allocation is supported. Certainly this option must be set
|
||||
* if dynamic stack allocation is supported by a platform. But the more
|
||||
* general meaning of this configuration environment is simply that the
|
||||
* stack has its own address space.
|
||||
*
|
||||
* If CONFIG_ARCH_STACK_DYNAMIC=y is selected then the platform specific
|
||||
* code must export these additional interfaces:
|
||||
*
|
||||
* up_addrenv_ustackalloc - Create a stack address environment
|
||||
* up_addrenv_ustackfree - Destroy a stack address environment.
|
||||
* up_addrenv_vustack - Returns the virtual base address of the stack
|
||||
* up_addrenv_ustackselect - Instantiate a stack address environment
|
||||
*
|
||||
* If CONFIG_ARCH_KERNEL_STACK is selected, then each user process will have
|
||||
* two stacks: (1) a large (and possibly dynamic) user stack and (2) a
|
||||
* smaller kernel stack. However, this option is *required* if both
|
||||
* CONFIG_BUILD_KERNEL and CONFIG_LIBC_EXECFUNCS are selected. Why? Because
|
||||
* when we instantiate and initialize the address environment of the new
|
||||
* user process, we will temporarily lose the address environment of the old
|
||||
* user process, including its stack contents. The kernel C logic will crash
|
||||
* immediately with no valid stack in place.
|
||||
*
|
||||
* If CONFIG_ARCH_STACK_DYNAMIC=y is selected then the platform specific
|
||||
* code must export these additional interfaces:
|
||||
*
|
||||
* up_addrenv_kstackalloc - Create a stack in the kernel address
|
||||
* environment
|
||||
* up_addrenv_kstackfree - Destroy the kernel stack.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* Prototyped in include/nuttx/arch.h as part of the OS/platform interface */
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* CONFIG_ARCH_ADDRENV */
|
||||
#endif /* __INCLUDE_NUTTX_ADDRENV_H */
|
||||
@@ -0,0 +1,321 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/analog/adc.h
|
||||
*
|
||||
* Copyright (C) 2016-2017 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2011 Li Zhuoyi. All rights reserved.
|
||||
* Author: Li Zhuoyi <lzyy.cn@gmail.com>
|
||||
* Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Derived from include/nuttx/can/can.h
|
||||
*
|
||||
* Copyright (C) 2008, 2009, 2018 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 __INCLUDE_NUTTX_ANALOG_ADC_H
|
||||
#define __INCLUDE_NUTTX_ANALOG_ADC_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <poll.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/semaphore.h>
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Default configuration settings that may be overridden in the NuttX
|
||||
* configuration file. The configured size is limited to 255 to fit into a
|
||||
* uint8_t.
|
||||
*/
|
||||
|
||||
#if !defined(CONFIG_ADC_FIFOSIZE)
|
||||
# define CONFIG_ADC_FIFOSIZE 8
|
||||
#elif CONFIG_ADC_FIFOSIZE > 255
|
||||
# undef CONFIG_ADC_FIFOSIZE
|
||||
# define CONFIG_ADC_FIFOSIZE 255
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_ADC_NPOLLWAITERS)
|
||||
# define CONFIG_ADC_NPOLLWAITERS 2
|
||||
#endif
|
||||
|
||||
#define ADC_RESET(dev) ((dev)->ad_ops->ao_reset((dev)))
|
||||
#define ADC_SETUP(dev) ((dev)->ad_ops->ao_setup((dev)))
|
||||
#define ADC_SHUTDOWN(dev) ((dev)->ad_ops->ao_shutdown((dev)))
|
||||
#define ADC_RXINT(dev) ((dev)->ad_ops->ao_rxint((dev)))
|
||||
#define ADC_IOCTL(dev,cmd,arg) ((dev)->ad_ops->ao_ioctl((dev),(cmd),(arg)))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* These are callbacks to notify the upper-half driver of ADC events */
|
||||
|
||||
struct adc_dev_s;
|
||||
struct adc_callback_s
|
||||
{
|
||||
/* This method is called from the lower half, platform-specific ADC logic
|
||||
* when new ADC sample data is available.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - The ADC device structure that was previously registered by
|
||||
* adc_register()
|
||||
* ch - And ID for the ADC channel number that generated the data
|
||||
* data - The actual converted data from the channel.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*/
|
||||
|
||||
CODE int (*au_receive)(FAR struct adc_dev_s *dev, uint8_t ch,
|
||||
int32_t data);
|
||||
};
|
||||
|
||||
/* This describes on ADC message */
|
||||
|
||||
begin_packed_struct struct adc_msg_s
|
||||
{
|
||||
uint8_t am_channel; /* The 8-bit ADC Channel */
|
||||
int32_t am_data; /* ADC convert result (4 bytes) */
|
||||
} end_packed_struct;
|
||||
|
||||
/* This describes a FIFO of ADC messages */
|
||||
|
||||
struct adc_fifo_s
|
||||
{
|
||||
sem_t af_sem; /* Counting semaphore */
|
||||
uint8_t af_head; /* Index to the head [IN] index in the circular buffer */
|
||||
uint8_t af_tail; /* Index to the tail [OUT] index in the circular buffer */
|
||||
/* Circular buffer of CAN messages */
|
||||
struct adc_msg_s af_buffer[CONFIG_ADC_FIFOSIZE];
|
||||
};
|
||||
|
||||
/* This structure defines all of the operations provided by the architecture
|
||||
* specific logic. All fields must be provided with non-NULL function
|
||||
* pointers by the caller of adc_register().
|
||||
*/
|
||||
|
||||
struct adc_dev_s;
|
||||
struct adc_ops_s
|
||||
{
|
||||
/* Bind the upper-half driver callbacks to the lower-half implementation.
|
||||
* This must be called early in order to receive ADC event notifications.
|
||||
*/
|
||||
|
||||
CODE int (*ao_bind)(FAR struct adc_dev_s *dev,
|
||||
FAR const struct adc_callback_s *callback);
|
||||
|
||||
/* Reset the ADC device. Called early to initialize the hardware. This
|
||||
* is called, before ao_setup() and on error conditions.
|
||||
*/
|
||||
|
||||
CODE void (*ao_reset)(FAR struct adc_dev_s *dev);
|
||||
|
||||
/* Configure the ADC. This method is called the first time that the ADC
|
||||
* device is opened. This will occur when the port is first opened.
|
||||
* This setup includes configuring and attaching ADC interrupts.
|
||||
* Interrupts are all disabled upon return.
|
||||
*/
|
||||
|
||||
CODE int (*ao_setup)(FAR struct adc_dev_s *dev);
|
||||
|
||||
/* Disable the ADC. This method is called when the ADC device is closed.
|
||||
* This method reverses the operation of the setup method.
|
||||
*/
|
||||
|
||||
CODE void (*ao_shutdown)(FAR struct adc_dev_s *dev);
|
||||
|
||||
/* Call to enable or disable RX interrupts */
|
||||
|
||||
CODE void (*ao_rxint)(FAR struct adc_dev_s *dev, bool enable);
|
||||
|
||||
/* All ioctl calls will be routed through this method */
|
||||
|
||||
CODE int (*ao_ioctl)(FAR struct adc_dev_s *dev, int cmd,
|
||||
unsigned long arg);
|
||||
};
|
||||
|
||||
/* This is the device structure used by the driver. The caller of
|
||||
* adc_register() must allocate and initialize this structure. The calling
|
||||
* logic needs to set all fields to zero except:
|
||||
*
|
||||
* The elements of 'ad_ops', and 'ad_priv'
|
||||
*
|
||||
* The common logic will initialize all semaphores.
|
||||
*/
|
||||
|
||||
struct adc_dev_s
|
||||
{
|
||||
#ifdef CONFIG_ADC
|
||||
/* Fields managed by common upper half ADC logic */
|
||||
|
||||
uint8_t ad_ocount; /* The number of times the device has been opened */
|
||||
uint8_t ad_nrxwaiters; /* Number of threads waiting to enqueue a message */
|
||||
sem_t ad_closesem; /* Locks out new opens while close is in progress */
|
||||
sem_t ad_recvsem; /* Used to wakeup user waiting for space in ad_recv.buffer */
|
||||
struct adc_fifo_s ad_recv; /* Describes receive FIFO */
|
||||
|
||||
/* The following is a list of poll structures of threads waiting for
|
||||
* driver events. The 'struct pollfd' reference for each open is also
|
||||
* retained in the f_priv field of the 'struct file'.
|
||||
*/
|
||||
|
||||
struct pollfd *fds[CONFIG_ADC_NPOLLWAITERS];
|
||||
#endif /* CONFIG_ADC */
|
||||
|
||||
/* Fields provided by lower half ADC logic */
|
||||
|
||||
FAR const struct adc_ops_s *ad_ops; /* Arch-specific operations */
|
||||
FAR void *ad_priv; /* Used by the arch-specific logic */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* "Upper-Half" ADC Driver Interfaces
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: adc_register
|
||||
*
|
||||
* Description:
|
||||
* Register a ADC driver. This function binds an instance of a "lower half"
|
||||
* ADC driver with the "upper half" ADC device and registers that device
|
||||
* so that can be used by application code.
|
||||
*
|
||||
* Input Parameters:
|
||||
* path - The full path to the driver to be registers in the NuttX pseudo-
|
||||
* filesystem. The recommended convention is to name all PWM drivers
|
||||
* as "/dev/adc", "/dev/adc1", etc. where the driver path differs only
|
||||
* in the "minor" number at the end of the device name.
|
||||
* dev - A pointer to an instance of lower half ADC driver. This instance
|
||||
* is bound to the upper half ADC driver and must persists as long as the
|
||||
* upper half driver driver persists.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int adc_register(FAR const char *path, FAR struct adc_dev_s *dev);
|
||||
|
||||
/****************************************************************************
|
||||
* Platform-Independent "Lower Half" ADC Driver Interfaces
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_ads1255initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the TI ADS 125X lower half driver
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct adc_dev_s *up_ads1255initialize(FAR struct spi_dev_s *spi,
|
||||
unsigned int devno);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lmp92001_adc_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize ADC
|
||||
*
|
||||
* Input Parameters:
|
||||
* I2C Port number
|
||||
* Device address
|
||||
*
|
||||
* Returned Value:
|
||||
* Valid LM92001 device structure reference on success; a NULL on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct adc_dev_s *lmp92001_adc_initialize(FAR struct i2c_master_s *i2c,
|
||||
uint8_t addr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ads7828_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize ADC
|
||||
*
|
||||
* Input Parameters:
|
||||
* i2c - Pointer to a valid I2C master struct.
|
||||
* addr - I2C device address.
|
||||
*
|
||||
* Returned Value:
|
||||
* Valid ADS7828 device structure reference on success; a NULL on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct adc_dev_s *ads7828_initialize(FAR struct i2c_master_s *i2c,
|
||||
uint8_t addr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: max1161x_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize ADC
|
||||
*
|
||||
* Input Parameters:
|
||||
* i2c - Pointer to a valid I2C master struct.
|
||||
*
|
||||
* Returned Value:
|
||||
* Valid MX1161X device structure reference on success; a NULL on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct adc_dev_s *max1161x_initialize(FAR struct i2c_master_s *i2c);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_ANALOG_ADC_H */
|
||||
@@ -0,0 +1,196 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/analog/ads1242.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_ANALOG_ADS1242_H
|
||||
#define __INCLUDE_NUTTX_ANALOG_ADS1242_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/analog/ioctl.h>
|
||||
#include <nuttx/spi/spi.h>
|
||||
|
||||
#if defined(CONFIG_SPI) && defined(CONFIG_ADC_ADS1242)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* IOCTL Commands ***********************************************************/
|
||||
|
||||
/* Cmd: ANIOC_ADS2142_READ Arg: uint32_t *value
|
||||
* Cmd: ANIOC_ADS2142_SET_GAIN Arg: uint8_t value
|
||||
* Cmd: ANIOC_ADS2142_SET_POSITIVE_INPUT Arg: uint8_t value
|
||||
* Cmd: ANIOC_ADS2142_SET_NEGATIVE_INPUT Arg: uint8_t value
|
||||
* Cmd: ANIOC_ADS2142_IS_DATA_READY Arg: bool *value
|
||||
* Cmd: ANIOC_ADS2142_DO_SYSTEM_OFFSET_CALIB Arg: None
|
||||
*/
|
||||
|
||||
#define ANIOC_ADS2142_READ _ANIOC(AN_ADS2142_FIRST + 0)
|
||||
#define ANIOC_ADS2142_SET_GAIN _ANIOC(AN_ADS2142_FIRST + 1)
|
||||
#define ANIOC_ADS2142_SET_POSITIVE_INPUT _ANIOC(AN_ADS2142_FIRST + 2)
|
||||
#define ANIOC_ADS2142_SET_NEGATIVE_INPUT _ANIOC(AN_ADS2142_FIRST + 3)
|
||||
#define ANIOC_ADS2142_IS_DATA_READY _ANIOC(AN_ADS2142_FIRST + 4)
|
||||
#define ANIOC_ADS2142_DO_SYSTEM_OFFSET_CALIB _ANIOC(AN_ADS2142_FIRST + 5)
|
||||
|
||||
/* ADS1242 REGISTER *********************************************************/
|
||||
|
||||
#define ADS1242_REG_SETUP (0x00) /* Setup Register */
|
||||
#define ADS1242_REG_MUX (0x01) /* Multiplexer Control Register */
|
||||
#define ADS1242_REG_ACR (0x02) /* Analog Control Register */
|
||||
#define ADS1242_REG_ODAC (0x03) /* Offset DAC */
|
||||
#define ADS1242_REG_DIO (0x04) /* Data I/O */
|
||||
#define ADS1242_REG_DIR (0x05) /* Direction Control for Data I/O */
|
||||
#define ADS1242_REG_IOCON (0x06) /* I/O Configuration Register */
|
||||
|
||||
/* ADS1242 REGISTER Bit Definitions *****************************************/
|
||||
|
||||
/* SETUP */
|
||||
#define ADS1242_REG_SETUP_BIT_BOCS (1 << 3)
|
||||
#define ADS1242_REG_SETUP_BIT_PGA2 (1 << 2)
|
||||
#define ADS1242_REG_SETUP_BIT_PGA1 (1 << 1)
|
||||
#define ADS1242_REG_SETUP_BIT_PGA0 (1 << 0)
|
||||
/* MUX */
|
||||
#define ADS1242_REG_MUX_BIT_PSEL3 (1 << 7)
|
||||
#define ADS1242_REG_MUX_BIT_PSEL2 (1 << 6)
|
||||
#define ADS1242_REG_MUX_BIT_PSEL1 (1 << 5)
|
||||
#define ADS1242_REG_MUX_BIT_PSEL0 (1 << 4)
|
||||
#define ADS1242_REG_MUX_BIT_NSEL3 (1 << 3)
|
||||
#define ADS1242_REG_MUX_BIT_NSEL2 (1 << 2)
|
||||
#define ADS1242_REG_MUX_BIT_NSEL1 (1 << 1)
|
||||
#define ADS1242_REG_MUX_BIT_NSEL0 (1 << 0)
|
||||
/* ACR */
|
||||
#define ADS1242_REG_ACR_BIT_NDRDY (1 << 7)
|
||||
#define ADS1242_REG_ACR_BIT_UnB (1 << 6)
|
||||
#define ADS1242_REG_ACR_BIT_SPEED (1 << 5)
|
||||
#define ADS1242_REG_ACR_BIT_BUFEN (1 << 4)
|
||||
#define ADS1242_REG_ACR_BIT_BITORDER (1 << 3)
|
||||
#define ADS1242_REG_ACR_BIT_RANGE (1 << 2)
|
||||
#define ADS1242_REG_ACR_BIT_DR1 (1 << 1)
|
||||
#define ADS1242_REG_ACR_BIT_DR0 (1 << 0)
|
||||
|
||||
/* ADS1242 SPI COMMANDS *****************************************************/
|
||||
|
||||
#define ADS1242_CMD_READ_DATA (0x01)
|
||||
#define ADS1242_CMD_READ_REGISTER (0x10)
|
||||
#define ADS1242_CMD_WRITE_REGISTER (0x50)
|
||||
#define ADS1242_CMD_SELF_OFFSET_CALIB (0xF1)
|
||||
#define ADS1242_CMD_SELF_GAIN_CALIB (0xf2)
|
||||
#define ADS1242_CMD_SYSTEM_OFFSET_CALIB (0xf3)
|
||||
#define ADS1242_CMD_RESET (0xfe)
|
||||
|
||||
/* SPI BUS PARAMETERS *******************************************************/
|
||||
|
||||
/* 100 kHz, SCLK period has to be at least 4 x tOsc period of ADS1242
|
||||
* oscillator circuit.
|
||||
*/
|
||||
|
||||
#define ADS1242_SPI_FREQUENCY (100000)
|
||||
|
||||
/* Device uses SPI Mode 1: CKPOL = 0, CKPHA = 1 */
|
||||
|
||||
#define ADS1242_SPI_MODE (SPIDEV_MODE1)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ADS1242_X1 = 0,
|
||||
ADS1242_X2 = ADS1242_REG_SETUP_BIT_PGA0,
|
||||
ADS1242_X4 = ADS1242_REG_SETUP_BIT_PGA1,
|
||||
ADS1242_X8 = ADS1242_REG_SETUP_BIT_PGA1 | ADS1242_REG_SETUP_BIT_PGA0,
|
||||
ADS1242_X16 = ADS1242_REG_SETUP_BIT_PGA2,
|
||||
ADS1242_X32 = ADS1242_REG_SETUP_BIT_PGA2 | ADS1242_REG_SETUP_BIT_PGA0,
|
||||
ADS1242_X64 = ADS1242_REG_SETUP_BIT_PGA2 | ADS1242_REG_SETUP_BIT_PGA1,
|
||||
ADS1242_X128 = ADS1242_REG_SETUP_BIT_PGA2 | ADS1242_REG_SETUP_BIT_PGA1 |
|
||||
ADS1242_REG_SETUP_BIT_PGA0
|
||||
} ADS1242_GAIN_SELECTION;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ADS1242_P_AIN0 = 0,
|
||||
ADS1242_P_AIN1 = ADS1242_REG_MUX_BIT_PSEL0,
|
||||
ADS1242_P_AIN2 = ADS1242_REG_MUX_BIT_PSEL1,
|
||||
ADS1242_P_AIN3 = ADS1242_REG_MUX_BIT_PSEL1 | ADS1242_REG_MUX_BIT_PSEL0,
|
||||
ADS1242_P_AIN4 = ADS1242_REG_MUX_BIT_PSEL2,
|
||||
ADS1242_P_AIN5 = ADS1242_REG_MUX_BIT_PSEL2 | ADS1242_REG_MUX_BIT_PSEL0,
|
||||
ADS1242_P_AIN6 = ADS1242_REG_MUX_BIT_PSEL2 | ADS1242_REG_MUX_BIT_PSEL1,
|
||||
ADS1242_P_AIN7 = ADS1242_REG_MUX_BIT_PSEL2 | ADS1242_REG_MUX_BIT_PSEL1 |
|
||||
ADS1242_REG_MUX_BIT_PSEL0,
|
||||
} ADS1242_POSITIVE_INPUT_SELECTION;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ADS1242_N_AIN0 = 0,
|
||||
ADS1242_N_AIN1 = ADS1242_REG_MUX_BIT_NSEL0,
|
||||
ADS1242_N_AIN2 = ADS1242_REG_MUX_BIT_NSEL1,
|
||||
ADS1242_N_AIN3 = ADS1242_REG_MUX_BIT_NSEL1 | ADS1242_REG_MUX_BIT_NSEL0,
|
||||
ADS1242_N_AIN4 = ADS1242_REG_MUX_BIT_NSEL2,
|
||||
ADS1242_N_AIN5 = ADS1242_REG_MUX_BIT_NSEL2 | ADS1242_REG_MUX_BIT_NSEL0,
|
||||
ADS1242_N_AIN6 = ADS1242_REG_MUX_BIT_NSEL2 | ADS1242_REG_MUX_BIT_NSEL1,
|
||||
ADS1242_N_AIN7 = ADS1242_REG_MUX_BIT_NSEL2 | ADS1242_REG_MUX_BIT_NSEL1 |
|
||||
ADS1242_REG_MUX_BIT_NSEL0,
|
||||
} ADS1242_NEGATIVE_INPUT_SELECTION;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ads1242_register
|
||||
*
|
||||
* Description:
|
||||
* Register the ADS1242 character device as 'devpath'
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the driver to register. E.g., "/dev/ads1242"
|
||||
* spi - An instance of the SPI interface to use to communicate with
|
||||
* ADS1242
|
||||
* osc_freq_hz - The frequency of the ADS1242 oscillator in Hz. Required
|
||||
* for calculating the minimum delay periods when accessing
|
||||
* the device via SPI.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int ads1242_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
|
||||
uint32_t const osc_freq_hz);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_SPI && CONFIG_ADC_ADS1242 */
|
||||
#endif /* __INCLUDE_NUTTX_ANALOG_ADS1242_H */
|
||||
@@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/analog/ads7828.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_ANALOG_ADS7828_H
|
||||
#define __INCLUDE_NUTTX_ANALOG_ADS7828_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/analog/ioctl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* IOCTL Commands
|
||||
* Cmd: ANIOC_ADS7828_SET_REF Arg: enum ads7828_ref_e
|
||||
* Cmd: ANIOC_ADS7828_MODE Arg: ads7828_mode_e
|
||||
* Cmd: ANIOC_ADS7828_POWER_SAVE Arg: bool value
|
||||
* Cmd: ANIOC_ADS7828_ADD_CHAN Arg: uint8_t value
|
||||
* Cmd: ANIOC_ADS7828_REMOVE_CHAN ARG: uint8_t value
|
||||
* Cmd: ANIOC_ADS7828_READ_CHANNEL Arg: struct adc_msg_s *channel
|
||||
*/
|
||||
|
||||
#define ANIOC_ADS7828_SET_REF _ANIOC(AN_ADS7828_FIRST + 0)
|
||||
#define ANIOC_ADS7828_MODE _ANIOC(AN_ADS7828_FIRST + 1)
|
||||
#define ANIOC_ADS7828_POWER_SAVE _ANIOC(AN_ADS7828_FIRST + 2)
|
||||
#define ANIOC_ADS7828_ADD_CHAN _ANIOC(AN_ADS7828_FIRST + 3)
|
||||
#define ANIOC_ADS7828_REMOVE_CHAN _ANIOC(AN_ADS7828_FIRST + 4)
|
||||
#define ANIOC_ADS7828_READ_CHANNEL _ANIOC(AN_ADS7828_FIRST + 5)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
enum ads7828_ref_e
|
||||
{
|
||||
ADS7828_REF_EXTERNAL = 0u,
|
||||
ADS7828_REF_INTERNAL
|
||||
};
|
||||
|
||||
enum ads7828_mode_e
|
||||
{
|
||||
ADS7828_DIFFERENTIAL = 0u,
|
||||
ADS7828_SINGLE_ENDED
|
||||
};
|
||||
|
||||
enum ads7828_diffch_e
|
||||
{
|
||||
ADS7828_DIFF_PCH0_NCH1 = 0u,
|
||||
ADS7828_DIFF_PCH2_NCH3,
|
||||
ADS7828_DIFF_PCH4_NCH5,
|
||||
ADS7828_DIFF_PCH6_NCH7,
|
||||
ADS7828_DIFF_PCH1_NCH0,
|
||||
ADS7828_DIFF_PCH3_NCH2,
|
||||
ADS7828_DIFF_PCH5_NCH4,
|
||||
ADS7828_DIFF_PCH7_NCH6
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_ANALOG_ADS7828_H */
|
||||
@@ -0,0 +1,133 @@
|
||||
/************************************************************************************
|
||||
* include/nuttx/analog/comp.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_ANALOG_COMP_H
|
||||
#define __INCLUDE_NUTTX_ANALOG_COMP_H
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/semaphore.h>
|
||||
|
||||
#ifndef CONFIG_DEV_COMP_NPOLLWAITERS
|
||||
# define CONFIG_DEV_COMP_NPOLLWAITERS 2
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Public Types
|
||||
************************************************************************************/
|
||||
|
||||
struct comp_dev_s;
|
||||
struct comp_callback_s
|
||||
{
|
||||
/* This method is called from the lower half, platform-specific COMP logic when
|
||||
* comparator output state changes.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - The COMP device structure that was previously registered by
|
||||
* adc_register()
|
||||
* val - The actual value of the comparator output.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*/
|
||||
|
||||
CODE int (*au_notify)(FAR struct comp_dev_s *dev, uint8_t val);
|
||||
};
|
||||
|
||||
struct comp_ops_s
|
||||
{
|
||||
/* Bind the upper-half driver callbacks to the lower-half implementation. This
|
||||
* must be called early in order to receive COMP event notifications.
|
||||
*/
|
||||
|
||||
CODE int (*ao_bind)(FAR struct comp_dev_s *dev,
|
||||
FAR const struct comp_callback_s *callback);
|
||||
|
||||
/* Configure the COMP. This method is called the first time that the COMP
|
||||
* device is opened. This will occur when the port is first opened.
|
||||
* This setup includes configuring and attaching COMP interrupts. Interrupts
|
||||
* are all disabled upon return.
|
||||
*/
|
||||
|
||||
CODE int (*ao_setup)(FAR struct comp_dev_s *dev);
|
||||
|
||||
/* Disable the COMP. This method is called when the COMP device is closed.
|
||||
* This method reverses the operation of the setup method.
|
||||
* Works only if COMP device is not locked.
|
||||
*/
|
||||
|
||||
CODE void (*ao_shutdown)(FAR struct comp_dev_s *dev);
|
||||
|
||||
/* Read COMP output state */
|
||||
|
||||
CODE int (*ao_read)(FAR struct comp_dev_s *dev);
|
||||
|
||||
/* All ioctl calls will be routed through this method */
|
||||
|
||||
CODE int (*ao_ioctl)(FAR struct comp_dev_s *dev, int cmd, unsigned long arg);
|
||||
};
|
||||
|
||||
struct comp_dev_s
|
||||
{
|
||||
#ifdef CONFIG_COMP
|
||||
/* Fields managed by common upper half COMP logic */
|
||||
|
||||
uint8_t ad_ocount; /* The number of times the device has been opened */
|
||||
uint8_t val; /* Comparator value after output transition event */
|
||||
sem_t ad_sem; /* Used to serialize access */
|
||||
sem_t ad_readsem; /* Blocking read */
|
||||
|
||||
/* pollfd's for output transition events */
|
||||
|
||||
struct pollfd *d_fds[CONFIG_DEV_COMP_NPOLLWAITERS];
|
||||
#endif
|
||||
|
||||
/* Fields provided by lower half COMP logic */
|
||||
|
||||
FAR const struct comp_ops_s *ad_ops; /* Arch-specific operations */
|
||||
FAR void *ad_priv; /* Used by the arch-specific logic */
|
||||
};
|
||||
|
||||
/************************************************************************************
|
||||
* Public Function Prototypes
|
||||
************************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int comp_register(FAR const char *path, FAR struct comp_dev_s *dev);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_ANALOG_COMP_H */
|
||||
@@ -0,0 +1,250 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/analog/dac.h
|
||||
*
|
||||
* Copyright (C) 2017, 2018 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2011 Li Zhuoyi. All rights reserved.
|
||||
* Author: Li Zhuoyi <lzyy.cn@gmail.com>
|
||||
* History: 0.1 2011-08-04 initial version
|
||||
*
|
||||
* Derived from include/nuttx/can/can.h
|
||||
*
|
||||
* Copyright (C) 2008, 2009, 2018 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 __INCLUDE_NUTTX_ANALOG_DAC_H
|
||||
#define __INCLUDE_NUTTX_ANALOG_DAC_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
#include <nuttx/semaphore.h>
|
||||
#include <nuttx/spi/spi.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Default configuration settings that may be overridden in the board
|
||||
* configuration file. The configured size is limited to 255 to fit into a
|
||||
* uint8_t.
|
||||
*/
|
||||
|
||||
#if !defined(CONFIG_DAC_FIFOSIZE)
|
||||
# define CONFIG_DAC_FIFOSIZE 8
|
||||
#elif CONFIG_DAC_FIFOSIZE > 255
|
||||
# undef CONFIG_DAC_FIFOSIZE
|
||||
# define CONFIG_DAC_FIFOSIZE 255
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
begin_packed_struct struct dac_msg_s
|
||||
{
|
||||
uint8_t am_channel; /* The 8-bit DAC Channel */
|
||||
int32_t am_data; /* DAC convert result (4 bytes) */
|
||||
} end_packed_struct;
|
||||
|
||||
struct dac_fifo_s
|
||||
{
|
||||
sem_t af_sem; /* Counting semaphore */
|
||||
uint8_t af_head; /* Index to the head [IN] index
|
||||
* in the circular buffer */
|
||||
uint8_t af_tail; /* Index to the tail [OUT] index
|
||||
* in the circular buffer */
|
||||
/* Circular buffer of DAC messages */
|
||||
struct dac_msg_s af_buffer[CONFIG_DAC_FIFOSIZE];
|
||||
};
|
||||
|
||||
/* This structure defines all of the operations provided by the architecture
|
||||
* specific logic. All fields must be provided with non-NULL function
|
||||
* pointers by the caller of dac_register().
|
||||
*/
|
||||
|
||||
struct dac_dev_s;
|
||||
struct dac_ops_s
|
||||
{
|
||||
/* Reset the DAC device. Called early to initialize the hardware. This
|
||||
* is called, before ao_setup() and on error conditions.
|
||||
*/
|
||||
|
||||
CODE void (*ao_reset)(FAR struct dac_dev_s *dev);
|
||||
|
||||
/* Configure the DAC. This method is called the first time that the DAC
|
||||
* device is opened. This will occur when the port is first opened.
|
||||
* This setup includes configuring and attaching DAC interrupts.
|
||||
* Interrupts are all disabled upon return.
|
||||
*/
|
||||
|
||||
CODE int (*ao_setup)(FAR struct dac_dev_s *dev);
|
||||
|
||||
/* Disable the DAC. This method is called when the DAC device is closed.
|
||||
* This method reverses the operation of the setup method.
|
||||
*/
|
||||
|
||||
CODE void (*ao_shutdown)(FAR struct dac_dev_s *dev);
|
||||
|
||||
/* Call to enable or disable TX interrupts */
|
||||
|
||||
CODE void (*ao_txint)(FAR struct dac_dev_s *dev, bool enable);
|
||||
|
||||
/* This method will send one message on the DAC */
|
||||
|
||||
CODE int (*ao_send)(FAR struct dac_dev_s *dev, FAR struct dac_msg_s *msg);
|
||||
|
||||
/* All ioctl calls will be routed through this method */
|
||||
|
||||
CODE int (*ao_ioctl)(FAR struct dac_dev_s *dev, int cmd,
|
||||
unsigned long arg);
|
||||
};
|
||||
|
||||
/* This is the device structure used by the driver. The caller of
|
||||
* dac_register() must allocate and initialize this structure. The
|
||||
* calling logic needs to set all fields to zero except:
|
||||
*
|
||||
* The elements of 'ad_ops', and 'ad_priv'
|
||||
*
|
||||
* The common logic will initialize all semaphores.
|
||||
*/
|
||||
|
||||
struct dac_dev_s
|
||||
{
|
||||
uint8_t ad_ocount; /* The number of times the device has
|
||||
* been opened */
|
||||
uint8_t ad_nchannel; /* Number of dac channel */
|
||||
sem_t ad_closesem; /* Locks out new opens while close is
|
||||
* in progress */
|
||||
struct dac_fifo_s ad_xmit; /* Describes receive FIFO */
|
||||
const struct dac_ops_s *ad_ops; /* Arch-specific operations */
|
||||
void *ad_priv; /* Used by the arch-specific logic */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dac_register
|
||||
*
|
||||
* Description:
|
||||
* Register a dac driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* path - The full path to the DAC device to be registered. This could
|
||||
* be, as an example, "/dev/dac0"
|
||||
* dev - An instance of the device-specific DAC interface
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; A negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int dac_register(FAR const char *path, FAR struct dac_dev_s *dev);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dac_txdone
|
||||
*
|
||||
* Description:
|
||||
* Called from the DAC interrupt handler at the completion of a send
|
||||
* operation.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - An instance of the device-specific DAC interface
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; a negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int dac_txdone(FAR struct dac_dev_s *dev);
|
||||
|
||||
/****************************************************************************
|
||||
* DAC Initialization functions
|
||||
*
|
||||
* Architecture-specific versions will have prototypes in architect-specific
|
||||
* header files. Common DAC implementations in drivers/analog will have
|
||||
* prototypes listed below.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct dac_dev_s *up_ad5410initialize(FAR struct spi_dev_s *spi,
|
||||
unsigned int devno);
|
||||
|
||||
FAR struct dac_dev_s *dac7571_initialize(FAR struct i2c_master_s *i2c,
|
||||
uint8_t addr);
|
||||
|
||||
FAR struct dac_dev_s *dac7554_initialize(FAR struct spi_dev_s *spi,
|
||||
int spidev);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lmp92001_dac_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize DAC
|
||||
*
|
||||
* Input Parameters:
|
||||
* I2C Port number
|
||||
* Device address
|
||||
*
|
||||
* Returned Value:
|
||||
* Valid LM92001 device structure reference on success; a NULL on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct dac_dev_s *lmp92001_dac_initialize(FAR struct i2c_master_s *i2c,
|
||||
uint8_t addr);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_ANALOG_DAC_H */
|
||||
@@ -0,0 +1,105 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/analog/ioctl.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_ANALOG_IOCTL_H
|
||||
#define __INCLUDE_NUTTX_ANALOG_IOCTL_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* The analog driver sub-system uses the standard character driver framework.
|
||||
* However, since the driver is a devices control interface rather than a
|
||||
* data transfer interface, the majority of the functionality is implemented
|
||||
* in driver ioctl calls. Standard ioctl commands are listed below:
|
||||
*/
|
||||
|
||||
/* DAC/ADC */
|
||||
|
||||
#define ANIOC_TRIGGER _ANIOC(0x0001) /* Trigger one conversion
|
||||
* IN: None
|
||||
* OUT: None */
|
||||
#define ANIOC_WDOG_UPPER _ANIOC(0x0002) /* Set upper threshold for watchdog
|
||||
* IN: Threshold value
|
||||
* OUT: None */
|
||||
#define ANIOC_WDOG_LOWER _ANIOC(0x0003) /* Set lower threshold for watchdog
|
||||
* IN: Threshold value
|
||||
* OUT: None */
|
||||
|
||||
#define AN_FIRST 0x0001 /* First common command */
|
||||
#define AN_NCMDS 3 /* Number of common commands */
|
||||
|
||||
/* User defined ioctl commands are also supported. These will be forwarded
|
||||
* by the upper-half driver to the lower-half driver via the ioctl()
|
||||
* method of the lower-half interface. However, the lower-half driver
|
||||
* must reserve a block of commands as follows in order prevent IOCTL
|
||||
* command numbers from overlapping.
|
||||
*/
|
||||
|
||||
/* See include/nuttx/analog/ads1242.h */
|
||||
|
||||
#define AN_ADS2142_FIRST (AN_FIRST + AN_NCMDS)
|
||||
#define AN_ADS2142_NCMDS 6
|
||||
|
||||
/* See include/nuttx/analog/lm92001.h */
|
||||
|
||||
#define AN_LMP92001_FIRST (AN_ADS2142_FIRST + AN_ADS2142_NCMDS)
|
||||
#define AN_LMP92001_NCMDS 7
|
||||
|
||||
/* See include/nuttx/analog/ads7828.h */
|
||||
|
||||
#define AN_ADS7828_FIRST (AN_LMP92001_FIRST + AN_LMP92001_NCMDS)
|
||||
#define AN_ADS7828_NCMDS 6
|
||||
|
||||
/* See arch/arm/src/stm32l4/stm32l4_adc.h */
|
||||
|
||||
#define AN_STM32L4_FIRST (AN_ADS7828_FIRST + AN_ADS7828_NCMDS)
|
||||
#define AN_STM32L4_NCMDS 2
|
||||
|
||||
/* See include/nuttx/analog/max1161x.h */
|
||||
|
||||
#define AN_MAX1161X_FIRST (AN_STM32L4_FIRST + AN_STM32L4_NCMDS)
|
||||
#define AN_MAX1161X_NCMDS 8
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_ANALOG_IOCTL_H */
|
||||
@@ -0,0 +1,112 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/analog/lmp92001.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_ANALOG_LMP92001_H
|
||||
#define __INCLUDE_NUTTX_ANALOG_LMP92001_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/analog/ioctl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* IOCTL Commands ***********************************************************/
|
||||
|
||||
/* Cmd: ANIOC_LMP92001_DAC_SET_REF Arg: bool value
|
||||
* Cmd: ANIOC_LMP92001_DAC_UPDATEALL Arg: uint16_t value
|
||||
* Cmd: ANIOC_LMP92001_ADC_SET_REF Arg: bool value
|
||||
* Cmd: ANIOC_LMP92001_ADC_ENABLE Arg: lmp92001_adc_enable_e channel
|
||||
* Cmd: ANIOC_LMP92001_ADC_SINGLESHOT_CONV Arg: none
|
||||
* Cmd: ANIOC_LMP92001_ADC_CONTINUOUS_CONV Arg: none
|
||||
* Cmd: ANIOC_LMP92001_ADC_READ_CHANNEL Arg: struct adc_msg_s *channel
|
||||
*/
|
||||
|
||||
#define ANIOC_LMP92001_DAC_SET_REF _ANIOC(AN_LMP92001_FIRST + 0)
|
||||
#define ANIOC_LMP92001_DAC_UPDATEALL _ANIOC(AN_LMP92001_FIRST + 1)
|
||||
#define ANIOC_LMP92001_ADC_SET_REF _ANIOC(AN_LMP92001_FIRST + 2)
|
||||
#define ANIOC_LMP92001_ADC_ENABLE _ANIOC(AN_LMP92001_FIRST + 3)
|
||||
#define ANIOC_LMP92001_ADC_SINGLESHOT_CONV _ANIOC(AN_LMP92001_FIRST + 4)
|
||||
#define ANIOC_LMP92001_ADC_CONTINUOUS_CONV _ANIOC(AN_LMP92001_FIRST + 5)
|
||||
#define ANIOC_LMP92001_ADC_READ_CHANNEL _ANIOC(AN_LMP92001_FIRST + 6)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
enum lmp92001_ref_e
|
||||
{
|
||||
LMP92001_REF_INTERNAL = 0U,
|
||||
LMP92001_REF_EXTERNAL
|
||||
};
|
||||
|
||||
enum lmp92001_adc_enable_e
|
||||
{
|
||||
LMP92001_ADC_EN_CH1 = 1 << 0U,
|
||||
LMP92001_ADC_EN_CH2 = 1 << 1U,
|
||||
LMP92001_ADC_EN_CH3 = 1 << 2U,
|
||||
LMP92001_ADC_EN_CH4 = 1 << 3U,
|
||||
LMP92001_ADC_EN_CH5 = 1 << 4U,
|
||||
LMP92001_ADC_EN_CH6 = 1 << 5U,
|
||||
LMP92001_ADC_EN_CH7 = 1 << 6U,
|
||||
LMP92001_ADC_EN_CH8 = 1 << 7U,
|
||||
LMP92001_ADC_EN_CH9 = 1 << 8U,
|
||||
LMP92001_ADC_EN_CH10 = 1 << 9U,
|
||||
LMP92001_ADC_EN_CH11 = 1 << 10U,
|
||||
LMP92001_ADC_EN_CH12 = 1 << 11U,
|
||||
LMP92001_ADC_EN_CH13 = 1 << 12U,
|
||||
LMP92001_ADC_EN_CH14 = 1 << 13U,
|
||||
LMP92001_ADC_EN_CH15 = 1 << 14U,
|
||||
LMP92001_ADC_EN_CH16 = 1 << 15U,
|
||||
LMP92001_ADC_EN_CH17 = 1 << 16U,
|
||||
LMP92001_ADC_EN_ALL = 0x1ffffu
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lmp92001_gpio_initialize
|
||||
*
|
||||
* Description:
|
||||
* Instantiate and configure the LMP92001 device driver to use the provided
|
||||
* I2C device instance.
|
||||
*
|
||||
* Input Parameters:
|
||||
* i2c - An I2C driver instance
|
||||
* minor - The device i2c address
|
||||
*
|
||||
* Returned Value:
|
||||
* An ioexpander_dev_s instance on success, NULL on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct i2c_master_s; /* Forward reference */
|
||||
struct ioexpander_dev_s; /* Forward reference */
|
||||
|
||||
FAR struct ioexpander_dev_s *
|
||||
lmp92001_gpio_initialize(FAR struct i2c_master_s *i2c, uint8_t addr);
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_ANALOG_LMP92001_H */
|
||||
@@ -0,0 +1,155 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/analog/ltc1867l.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_ANALOG_LTC1867L_H
|
||||
#define __INCLUDE_NUTTX_ANALOG_LTC1867L_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(CONFIG_ADC_LTC1867L)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* LTC1867L Configuration ***************************************************/
|
||||
|
||||
#define LTC1867L_CONFIG_BIT_SLP (1 << 1)
|
||||
#define LTC1867L_CONFIG_BIT_UNI (1 << 2)
|
||||
#define LTC1867L_CONFIG_BIT_COM (1 << 3)
|
||||
#define LTC1867L_CONFIG_BIT_S0 (1 << 4)
|
||||
#define LTC1867L_CONFIG_BIT_S1 (1 << 5)
|
||||
#define LTC1867L_CONFIG_BIT_OS (1 << 6)
|
||||
#define LTC1867L_CONFIG_BIT_SD (1 << 7)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
enum ltc1867l_analog_multiplexer_config_e
|
||||
{
|
||||
LTC1867L_P_CH0_M_CH1 = 0,
|
||||
LTC1867L_P_CH2_M_CH3 = LTC1867L_CONFIG_BIT_S0,
|
||||
LTC1867L_P_CH4_M_CH5 = LTC1867L_CONFIG_BIT_S1,
|
||||
LTC1867L_P_CH6_M_CH7 = LTC1867L_CONFIG_BIT_S1 |
|
||||
LTC1867L_CONFIG_BIT_S0,
|
||||
LTC1867L_P_CH1_M_CH0 = LTC1867L_CONFIG_BIT_OS,
|
||||
LTC1867L_P_CH3_M_CH2 = LTC1867L_CONFIG_BIT_OS |
|
||||
LTC1867L_CONFIG_BIT_S0,
|
||||
LTC1867L_P_CH5_M_CH4 = LTC1867L_CONFIG_BIT_OS |
|
||||
LTC1867L_CONFIG_BIT_S1,
|
||||
LTC1867L_P_CH7_M_CH6 = LTC1867L_CONFIG_BIT_OS |
|
||||
LTC1867L_CONFIG_BIT_S1 |
|
||||
LTC1867L_CONFIG_BIT_S0,
|
||||
LTC1867L_P_CH0_M_GND = LTC1867L_CONFIG_BIT_SD,
|
||||
LTC1867L_P_CH2_M_GND = LTC1867L_CONFIG_BIT_SD |
|
||||
LTC1867L_CONFIG_BIT_S0,
|
||||
LTC1867L_P_CH4_M_GND = LTC1867L_CONFIG_BIT_SD |
|
||||
LTC1867L_CONFIG_BIT_S1,
|
||||
LTC1867L_P_CH6_M_GND = LTC1867L_CONFIG_BIT_SD |
|
||||
LTC1867L_CONFIG_BIT_S1 |
|
||||
LTC1867L_CONFIG_BIT_S0,
|
||||
LTC1867L_P_CH1_M_GND = LTC1867L_CONFIG_BIT_SD |
|
||||
LTC1867L_CONFIG_BIT_OS,
|
||||
LTC1867L_P_CH3_M_GND = LTC1867L_CONFIG_BIT_SD |
|
||||
LTC1867L_CONFIG_BIT_OS |
|
||||
LTC1867L_CONFIG_BIT_S0,
|
||||
LTC1867L_P_CH5_M_GND = LTC1867L_CONFIG_BIT_SD |
|
||||
LTC1867L_CONFIG_BIT_OS |
|
||||
LTC1867L_CONFIG_BIT_S1,
|
||||
LTC1867L_P_CH7_M_GND = LTC1867L_CONFIG_BIT_SD |
|
||||
LTC1867L_CONFIG_BIT_OS |
|
||||
LTC1867L_CONFIG_BIT_S1 |
|
||||
LTC1867L_CONFIG_BIT_S0,
|
||||
LTC1867L_P_CH0_M_CH7COM = LTC1867L_CONFIG_BIT_SD |
|
||||
LTC1867L_CONFIG_BIT_COM,
|
||||
LTC1867L_P_CH2_M_CH7COM = LTC1867L_CONFIG_BIT_SD |
|
||||
LTC1867L_CONFIG_BIT_S0 |
|
||||
LTC1867L_CONFIG_BIT_COM,
|
||||
LTC1867L_P_CH4_M_CH7COM = LTC1867L_CONFIG_BIT_SD |
|
||||
LTC1867L_CONFIG_BIT_S1 |
|
||||
LTC1867L_CONFIG_BIT_COM,
|
||||
LTC1867L_P_CH6_M_CH7COM = LTC1867L_CONFIG_BIT_SD |
|
||||
LTC1867L_CONFIG_BIT_S1 |
|
||||
LTC1867L_CONFIG_BIT_S0 |
|
||||
LTC1867L_CONFIG_BIT_COM,
|
||||
LTC1867L_P_CH1_M_CH7COM = LTC1867L_CONFIG_BIT_SD |
|
||||
LTC1867L_CONFIG_BIT_OS |
|
||||
LTC1867L_CONFIG_BIT_COM,
|
||||
LTC1867L_P_CH3_M_CH7COM = LTC1867L_CONFIG_BIT_SD |
|
||||
LTC1867L_CONFIG_BIT_OS |
|
||||
LTC1867L_CONFIG_BIT_S0 |
|
||||
LTC1867L_CONFIG_BIT_COM,
|
||||
LTC1867L_P_CH5_M_CH7COM = LTC1867L_CONFIG_BIT_SD |
|
||||
LTC1867L_CONFIG_BIT_OS |
|
||||
LTC1867L_CONFIG_BIT_S1 |
|
||||
LTC1867L_CONFIG_BIT_COM
|
||||
};
|
||||
|
||||
enum ltc1867l_analog_input_mode_e
|
||||
{
|
||||
LTC1867L_UNIPOLAR = LTC1867L_CONFIG_BIT_UNI,
|
||||
LTC1867L_BIPOLAR = 0,
|
||||
};
|
||||
|
||||
begin_packed_struct struct ltc1867l_channel_config_s
|
||||
{
|
||||
uint8_t channel; /* This will be the channel number returned in struct adc_msg_s for a conversion */
|
||||
enum ltc1867l_analog_multiplexer_config_e analog_multiplexer_config; /* Analog multiplexer configuration */
|
||||
enum ltc1867l_analog_input_mode_e analog_inputmode; /* Analog input mode */
|
||||
} end_packed_struct;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ltc1867l_register
|
||||
*
|
||||
* Description:
|
||||
* Register the LTC1867L character device as 'devpath'
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the driver to register. E.g., "/dev/adc0"
|
||||
* spi - An instance of the SPI interface to use to communicate with
|
||||
* LTC1867L
|
||||
* devno - SPI device number
|
||||
* channel_config - A pointer to an array which holds the configuration
|
||||
* for each sampled channel.
|
||||
* channel_config_count - Number of channels to sample
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int ltc1867l_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
|
||||
unsigned int devno,
|
||||
FAR struct ltc1867l_channel_config_s *channel_config,
|
||||
int channel_config_count);
|
||||
|
||||
#endif /* CONFIG_ADC_LTC1867L */
|
||||
#endif /* __INCLUDE_NUTTX_ANALOG_LTC1867L_H */
|
||||
@@ -0,0 +1,122 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/analog/max1161x.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_ANALOG_MAX1161X_H
|
||||
#define __INCLUDE_NUTTX_ANALOG_MAX1161X_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/analog/ioctl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* IOCTL Commands
|
||||
* Cmd: ANIOC_MAX1161X_SET_REF Arg: enum max1161x_ref_e
|
||||
* Cmd: ANIOC_MAX1161X_SET_CLOCK Arg: enum max1161x_clock_e
|
||||
* Cmd: ANIOC_MAX1161X_SET_UNIBIP Arg: enum max1161x_unibip_e
|
||||
* Cmd: ANIOC_MAX1161X_SET_SCAN Arg: enum max1161x_scan_e
|
||||
* Cmd: ANIOC_MAX1161X_ADD_CHAN Arg: uint8_t value
|
||||
* Cmd: ANIOC_MAX1161X_REMOVE_CHAN Arg: uint8_t value
|
||||
* Cmd: ANIOC_MAX1161X_SET_SNGDIF Arg: enum max1161x_sngdif_e
|
||||
* Cmd: ANIOC_MAX1161X_READ_CHANNEL Arg: struct adc_msg_s *channel
|
||||
*/
|
||||
|
||||
#define ANIOC_MAX1161X_SET_REF _ANIOC(AN_MAX1161X_FIRST + 0)
|
||||
#define ANIOC_MAX1161X_SET_CLOCK _ANIOC(AN_MAX1161X_FIRST + 1)
|
||||
#define ANIOC_MAX1161X_SET_UNIBIP _ANIOC(AN_MAX1161X_FIRST + 2)
|
||||
#define ANIOC_MAX1161X_SET_SCAN _ANIOC(AN_MAX1161X_FIRST + 3)
|
||||
#define ANIOC_MAX1161X_ADD_CHAN _ANIOC(AN_MAX1161X_FIRST + 4)
|
||||
#define ANIOC_MAX1161X_REMOVE_CHAN _ANIOC(AN_MAX1161X_FIRST + 5)
|
||||
#define ANIOC_MAX1161X_SET_SNGDIF _ANIOC(AN_MAX1161X_FIRST + 6)
|
||||
#define ANIOC_MAX1161X_READ_CHANNEL _ANIOC(AN_MAX1161X_FIRST + 7)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Setup Byte */
|
||||
|
||||
/****************************************************************************
|
||||
* +----+----+----+------+---------+---------+---------------+
|
||||
* |SEL2|SEL1|SEL0| VREF | Ref Pin | Ref Dir | Int Ref State |
|
||||
* +----+----+----+------+---------+---------+---------------+
|
||||
* | 0 | 0 | x | VDD | AIN | NC | off |
|
||||
* | 0 | 1 | x | EXT | RIN | IN | off |
|
||||
* | 1 | 0 | 0 | INT | AIN | NC | off |
|
||||
* | 1 | 0 | 1 | INT | AIN | NC | on |
|
||||
* | 1 | 1 | 0 | INT | ROUT | OUT | off |
|
||||
* | 1 | 1 | 1 | INT | ROUT | OUT | on |
|
||||
* +----+----+----+------+---------+---------+---------------+
|
||||
****************************************************************************/
|
||||
|
||||
enum max1161x_ref_e
|
||||
{
|
||||
MAX1161X_REF_VDD_AIN_NC_OFF = 0u,
|
||||
MAX1161X_REF_EXT_RIN_IN_OFF = 2u,
|
||||
MAX1161X_REF_INT_AIN_NC_OFF = 4u,
|
||||
MAX1161X_REF_INT_AIN_NC_ON = 5u,
|
||||
MAX1161X_REF_INT_ROUT_OUT_OFF = 6u,
|
||||
MAX1161X_REF_INT_ROUT_OUT_ON = 7u,
|
||||
};
|
||||
|
||||
enum max1161x_clock_e
|
||||
{
|
||||
MAX1161X_CLOCK_INT = 0u,
|
||||
MAX1161X_CLOCK_EXT
|
||||
};
|
||||
|
||||
enum max1161x_unibip_e
|
||||
{
|
||||
MAX1161X_UNIPOLAR = 0u,
|
||||
MAX1161X_BIPOLAR
|
||||
};
|
||||
|
||||
enum max1161x_reset_e
|
||||
{
|
||||
MAX1161X_NO_RESET = 0u,
|
||||
MAX1161X_RESET
|
||||
};
|
||||
|
||||
/* Configuration Byte */
|
||||
|
||||
enum max1161x_scan_e
|
||||
{
|
||||
MAX1161X_SCAN_FROM_ZERO = 0u,
|
||||
MAX1161X_SCAN_EIGHT_TIMES,
|
||||
MAX1161X_SCAN_UPPER,
|
||||
MAX1161X_SCAN_NONE
|
||||
};
|
||||
|
||||
enum max1161x_sngdif_e
|
||||
{
|
||||
MAX1161X_DIFFERENTIAL = 0u,
|
||||
MAX1161X_SINGLE_ENDED
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_ANALOG_MAX1161X_H */
|
||||
@@ -0,0 +1,95 @@
|
||||
/************************************************************************************
|
||||
* include/nuttx/analog/opamp.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_ANALOG_OPAMP_H
|
||||
#define __INCLUDE_NUTTX_ANALOG_OPAMP_H
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/semaphore.h>
|
||||
|
||||
/************************************************************************************
|
||||
* Public Types
|
||||
************************************************************************************/
|
||||
|
||||
struct opamp_dev_s;
|
||||
struct opamp_ops_s
|
||||
{
|
||||
/* Configure the OPAMP. This method is called the first time that the OPAMP
|
||||
* device is opened. This will occur when the port is first opened.
|
||||
* This setup includes configuring and attaching OPAMP interrupts. Interrupts
|
||||
* are all disabled upon return.
|
||||
*/
|
||||
|
||||
CODE int (*ao_setup)(FAR struct opamp_dev_s *dev);
|
||||
|
||||
/* Disable the OPAMP. This method is called when the OPAMP device is closed.
|
||||
* This method reverses the operation of the setup method.
|
||||
* Works only if OPAMP device is not locked.
|
||||
*/
|
||||
|
||||
CODE void (*ao_shutdown)(FAR struct opamp_dev_s *dev);
|
||||
|
||||
/* All ioctl calls will be routed through this method */
|
||||
|
||||
CODE int (*ao_ioctl)(FAR struct opamp_dev_s *dev, int cmd, unsigned long arg);
|
||||
};
|
||||
|
||||
struct opamp_dev_s
|
||||
{
|
||||
#ifdef CONFIG_OPAMP
|
||||
/* Fields managed by common upper half OPAMP logic */
|
||||
|
||||
uint8_t ad_ocount; /* The number of times the device has been opened */
|
||||
sem_t ad_closesem; /* Locks out new opens while close is in progress */
|
||||
#endif
|
||||
|
||||
/* Fields provided by lower half OPAMP logic */
|
||||
|
||||
FAR const struct opamp_ops_s *ad_ops; /* Arch-specific operations */
|
||||
FAR void *ad_priv; /* Used by the arch-specific logic */
|
||||
};
|
||||
|
||||
/************************************************************************************
|
||||
* Public Function Prototypes
|
||||
************************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int opamp_register(FAR const char *path, FAR struct opamp_dev_s *dev);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_ANALOG_OPAMP_H */
|
||||
@@ -0,0 +1,372 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/analog/pga11x.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_ANALOG_PGA11X_H
|
||||
#define __INCLUDE_NUTTX_ANALOG_PGA11X_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/spi/spi.h>
|
||||
|
||||
#if defined(CONFIG_ADC) && defined(CONFIG_ADC_PGA11X)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
/* Prerequisites:
|
||||
* CONFIG_ADC=y is needed to enable support for analog input devices
|
||||
*
|
||||
* CONFIG_ADC_PGA11X
|
||||
* Enables support for the PGA11X driver (Needs CONFIG_ADC)
|
||||
* CONFIG_PGA11X_SPIFREQUENCY
|
||||
* SPI frequency. Default 1MHz
|
||||
* CONFIG_PGA11X_DAISYCHAIN
|
||||
* Use two PGA116/7's in Daisy Chain commands.
|
||||
* CONFIG_PGA11X_SPIMODE
|
||||
* SPI Mode. The specification says that the device operates in Mode 0 or
|
||||
* Mode 3. But sometimes you need to tinker with this to get things to
|
||||
* work correctly. Default: Mode 0
|
||||
* CONFIG_PGA11X_MULTIPLE
|
||||
* Can be defined to support multiple PGA11X devices on board. Each
|
||||
* device will require a customized SPI interface to distinguish them
|
||||
* When SPI_SELECT is called with devid=SPIDEV_MUX(n).
|
||||
*
|
||||
* Other settings that effect the driver:
|
||||
* CONFIG_DEBUG_SPI_ERR/WARN/INFO -- This will enable debug output from
|
||||
* the PGA117 driver.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_PGA11X_SPIFREQUENCY
|
||||
# define CONFIG_PGA11X_SPIFREQUENCY 1000000
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_PGA11X_SPIMODE
|
||||
# define CONFIG_PGA11X_SPIMODE SPIDEV_MODE0
|
||||
#endif
|
||||
|
||||
/* PGA11x Commands **********************************************************/
|
||||
|
||||
/* Write command Gain Selection Bits (PGA112/PGA113)
|
||||
*
|
||||
* the PGA112 and PGA116 provide binary gain selections (1, 2, 4, 8, 16, 32,
|
||||
* 64, 128); the PGA113 and PGA117 provide scope gain selections (1, 2, 5,
|
||||
* 10, 20, 50, 100, 200).
|
||||
*/
|
||||
|
||||
#define PGA11X_GAIN_1 (0) /* Gain=1: Scope Gain=1 */
|
||||
#define PGA11X_GAIN_2 (1) /* Gain=2: Scope Gain=2 */
|
||||
#define PGA11X_GAIN_4 (2) /* Gain=4: Scope Gain=5 */
|
||||
#define PGA11X_GAIN_5 (2) /* Gain=4: Scope Gain=5 */
|
||||
#define PGA11X_GAIN_8 (3) /* Gain=8: Scope Gain=10 */
|
||||
#define PGA11X_GAIN_10 (3) /* Gain=8: Scope Gain=10 */
|
||||
#define PGA11X_GAIN_16 (4) /* Gain=16: Scope Gain=20 */
|
||||
#define PGA11X_GAIN_20 (4) /* Gain=16: Scope Gain=20 */
|
||||
#define PGA11X_GAIN_32 (5) /* Gain=32: Scope Gain=50 */
|
||||
#define PGA11X_GAIN_50 (5) /* Gain=32: Scope Gain=50 */
|
||||
#define PGA11X_GAIN_64 (6) /* Gain=64: Scope Gain=100 */
|
||||
#define PGA11X_GAIN_100 (6) /* Gain=64: Scope Gain=100 */
|
||||
#define PGA11X_GAIN_128 (7) /* Gain=128: Scope Gain=200 */
|
||||
#define PGA11X_GAIN_200 (7) /* Gain=128: Scope Gain=200 */
|
||||
|
||||
/* Write command Mux Channel Selection Bits
|
||||
*
|
||||
* The PGA112/PGA113 have a two-channel input MUX; the PGA116/PGA117 have a
|
||||
* 10-channel input MUX.
|
||||
*/
|
||||
|
||||
#define PGA11X_CHAN_VCAL (0) /* VCAL/CH0 */
|
||||
#define PGA11X_CHAN_CH0 (0) /* VCAL/CH0 */
|
||||
#define PGA11X_CHAN_CH1 (1) /* CH1 */
|
||||
#define PGA11X_CHAN_CH2 (2) /* CH2 (PGA116/PGA117 only) */
|
||||
#define PGA11X_CHAN_CH3 (3) /* CH3 (PGA116/PGA117 only) */
|
||||
#define PGA11X_CHAN_CH4 (4) /* CH4 (PGA116/PGA117 only) */
|
||||
#define PGA11X_CHAN_CH5 (5) /* CH5 (PGA116/PGA117 only) */
|
||||
#define PGA11X_CHAN_CH6 (6) /* CH6 (PGA116/PGA117 only) */
|
||||
#define PGA11X_CHAN_CH7 (7) /* CH7 (PGA116/PGA117 only) */
|
||||
#define PGA11X_CHAN_CH8 (8) /* CH8 (PGA116/PGA117 only) */
|
||||
#define PGA11X_CHAN_CH9 (9) /* CH9 (PGA116/PGA117 only) */
|
||||
#define PGA11X_CHAN_CAL1 (12) /* CAL1: connects to GND */
|
||||
#define PGA11X_CHAN_CAL2 (13) /* CAL2: connects to 0.9VCAL */
|
||||
#define PGA11X_CHAN_CAL3 (14) /* CAL3: connects to 0.1VCAL */
|
||||
#define PGA11X_CHAN_CAL4 (15) /* CAL4: connects to VREF */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Handle used to reference the particular PGA11X instance */
|
||||
|
||||
typedef FAR void *PGA11X_HANDLE;
|
||||
|
||||
/* Settings for one device in a daisy-chain */
|
||||
|
||||
#ifdef CONFIG_PGA11X_DAISYCHAIN
|
||||
struct pga11x_usettings_s
|
||||
{
|
||||
uint8_t channel; /* See PGA11X_CHAN_* definitions */
|
||||
uint8_t gain; /* See PGA11X_GAIN_* definitions */
|
||||
};
|
||||
#endif
|
||||
|
||||
/* These structures are used to encode gain and channel settings. This
|
||||
* includes both devices in the case of a daisy-chained configuration.
|
||||
* NOTE: This logic is currently limited to only 2 devices in the daisy-
|
||||
* chain.
|
||||
*/
|
||||
|
||||
struct pga11x_settings_s
|
||||
{
|
||||
#ifndef CONFIG_PGA11X_DAISYCHAIN
|
||||
uint8_t channel; /* See PGA11X_CHAN_* definitions */
|
||||
uint8_t gain; /* See PGA11X_GAIN_* definitions */
|
||||
#else
|
||||
struct
|
||||
{
|
||||
uint8_t channel; /* See PGA11X_CHAN_* definitions */
|
||||
uint8_t gain; /* See PGA11X_GAIN_* definitions */
|
||||
} u1;
|
||||
|
||||
struct
|
||||
{
|
||||
uint8_t channel; /* See PGA11X_CHAN_* definitions */
|
||||
uint8_t gain; /* See PGA11X_GAIN_* definitions */
|
||||
} u2;
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pga11x_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the PGA117 amplifier/multiplexer(s).
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - An SPI "bottom half" device driver instance
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, a non-NULL opaque handle is returned; a NULL is returned
|
||||
* on any failure. This handle may be used with the other PGA117 interface
|
||||
* functions to control the multiplexer
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
PGA11X_HANDLE pga11x_initialize(FAR struct spi_dev_s *spi);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pga11x_select
|
||||
*
|
||||
* Description:
|
||||
* Select an input channel and gain for all PGA11xs.
|
||||
*
|
||||
* If CONFIG_PGA11X_DAISYCHAIN is defined, then pga11x_select() configures
|
||||
* both chips in the daisy-chain. pga11x_uselect() is provided to support
|
||||
* configuring the parts in the daisychain independently.
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - An SPI "bottom half" device driver instance
|
||||
* settings - New channel and gain settings
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int pga11x_select(PGA11X_HANDLE handle,
|
||||
FAR const struct pga11x_settings_s *settings);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pga11x_uselect
|
||||
*
|
||||
* Description:
|
||||
* Select an input channel and gain for one PGA11x.
|
||||
*
|
||||
* If CONFIG_PGA11X_DAISYCHAIN is defined, then pga11x_uselect() configures
|
||||
* one chips in the daisy-chain.
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - An SPI "bottom half" device driver instance
|
||||
* pos - Position of the chip in the daisy chain (0 or 1)
|
||||
* settings - New channel and gain settings
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_PGA11X_DAISYCHAIN
|
||||
int pga11x_uselect(PGA11X_HANDLE handle, int pos,
|
||||
FAR const struct pga11x_usettings_s *settings);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pga11x_read
|
||||
*
|
||||
* Description:
|
||||
* Read from all PGA117 amplifier/multiplexers.
|
||||
*
|
||||
* If CONFIG_PGA11X_DAISYCHAIN is defined, then pga11x_read() reads from
|
||||
* both chips in the daisy-chain. pga11x_uread() is provided to support
|
||||
* accessing the parts independently.
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - An SPI "bottom half" device driver instance
|
||||
* settings - Returned channel and gain settings
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int pga11x_read(PGA11X_HANDLE handle,
|
||||
FAR struct pga11x_settings_s *settings);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pga11x_uread
|
||||
*
|
||||
* Description:
|
||||
* Read from one PGA117 amplifier/multiplexer.
|
||||
*
|
||||
* If CONFIG_PGA11X_DAISYCHAIN is defined, then pga11x_read() reads
|
||||
* the parts independently.
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - An SPI "bottom half" device driver instance
|
||||
* pos - Position of the chip in the daisy chain (0 or 1)
|
||||
* settings - Returned channel and gain settings
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_PGA11X_DAISYCHAIN
|
||||
int pga11x_uread(PGA11X_HANDLE handle, int pos,
|
||||
FAR struct pga11x_usettings_s *settings);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pga11x_shutdown
|
||||
*
|
||||
* Description:
|
||||
* Put all PGA11x;'s in shutdown down mode.
|
||||
*
|
||||
* If CONFIG_PGA11X_DAISYCHAIN is defined, then pga11x_shutdown() controls
|
||||
* both chips in the daisy-chain. pga11x_ushutdown() is provided to
|
||||
* control the parts independently.
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - An SPI "bottom half" device driver instance
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int pga11x_shutdown(PGA11X_HANDLE handle);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pga11x_ushutdown
|
||||
*
|
||||
* Description:
|
||||
* Put one PGA11x in shutdown down mode.
|
||||
*
|
||||
* If CONFIG_PGA11X_DAISYCHAIN is defined, then pga11x_ushutdown() is
|
||||
* provided to shutdown the parts independently.
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - An SPI "bottom half" device driver instance
|
||||
* pos - Position of the chip in the daisy chain (0 or 1)
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_PGA11X_DAISYCHAIN
|
||||
int pga11x_ushutdown(PGA11X_HANDLE handle, int pos);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pga11x_enable
|
||||
*
|
||||
* Description:
|
||||
* Take all PGA11x's out of shutdown down mode.
|
||||
*
|
||||
* If CONFIG_PGA11X_DAISYCHAIN is defined, then pga11x_enable() controls
|
||||
* both chips in the daisy-chain. pga11x_uenable() is provided to
|
||||
* control the parts independently.
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - An SPI "bottom half" device driver instance
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int pga11x_enable(PGA11X_HANDLE handle);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pga11x_uenable
|
||||
*
|
||||
* Description:
|
||||
* Take one PGA11x out of shutdown down mode.
|
||||
*
|
||||
* If CONFIG_PGA11X_DAISYCHAIN is defined, then pga11x_uenable() is
|
||||
* provided to enable the parts independently.
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - An SPI "bottom half" device driver instance
|
||||
* pos - Position of the chip in the daisy chain (0 or 1)
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_PGA11X_DAISYCHAIN
|
||||
int pga11x_uenable(PGA11X_HANDLE handle, int pos);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_ADC && CONFIG_ADC_PGA11X */
|
||||
#endif /* __INCLUDE_NUTTX_ANALOG_PGA11X_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,188 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/ascii.h
|
||||
* ASCII Control Codes
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_ASCII_H
|
||||
#define __INCLUDE_NUTTX_ASCII_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* All 7-bit ASCII codes */
|
||||
|
||||
#define ASCII_NUL 0x00 /* Null character (^@) */
|
||||
#define ASCII_SOH 0x01 /* Start of header (^A) */
|
||||
#define ASCII_STX 0x02 /* Start of tex (^B) */
|
||||
#define ASCII_ETX 0x03 /* End of text (^C) */
|
||||
#define ASCII_EOT 0x04 /* End of transmission (^D) */
|
||||
#define ASCII_ENQ 0x05 /* Enquiry (^E) */
|
||||
#define ASCII_ACK 0x06 /* Acknowledge (^F) */
|
||||
#define ASCII_BEL 0x07 /* Bell (^G) */
|
||||
#define ASCII_BS 0x08 /* Backspace (^H) */
|
||||
#define ASCII_TAB 0x09 /* Horizontal tab (^I) */
|
||||
#define ASCII_LF 0x0a /* Line Feed (^J) */
|
||||
#define ASCII_VT 0x0b /* Vertical tab(^K) */
|
||||
#define ASCII_FF 0x0c /* Form Feed (^L) */
|
||||
#define ASCII_CR 0x0d /* Carriage Return (^M) */
|
||||
#define ASCII_SO 0x0e /* Shift Out (^N) */
|
||||
#define ASCII_SI 0x0f /* Shift In (^O) */
|
||||
|
||||
#define ASCII_DLE 0x10 /* Data link escape (^P) */
|
||||
#define ASCII_DC1 0x11 /* Device control 1, XON (^Q) */
|
||||
#define ASCII_XON ASCII_DC1
|
||||
#define ASCII_DC2 0x12 /* Device control 2, block-mode flow control (^R) */
|
||||
#define ASCII_DC3 0x13 /* Device control 3, XOFF (^S) */
|
||||
#define ASCII_XOFF ASCII_DC3
|
||||
#define ASCII_DC4 0x14 /* Device control 4 (^T) */
|
||||
#define ASCII_NAK 0x15 /* Negative acknowledge (^U) */
|
||||
#define ASCII_SYN 0x16 /* Synchronous idle (^V) */
|
||||
#define ASCII_ETB 0x17 /* End transmission block(^W) */
|
||||
#define ASCII_CAN 0x18 /* Cancel line(^X) */
|
||||
#define ASCII_EM 0x19 /* End of medium(^Y) */
|
||||
#define ASCII_SUB 0x1a /* Substitute (^Z) */
|
||||
#define ASCII_ESC 0x1b /* Escape (^[) */
|
||||
#define ASCII_FS 0x1c /* File separator (^\) */
|
||||
#define ASCII_GS 0x1d /* Group separator (^]) */
|
||||
#define ASCII_RS 0x1e /* Record separator, block-mode terminator (^^) */
|
||||
#define ASCII_US 0x1f /* Unit separator (^_) */
|
||||
|
||||
#define ASCII_SPACE 0x20 /* Space ( ) */
|
||||
#define ASCII_EXCLAM 0x21 /* Exclamation mark (!) */
|
||||
#define ASCII_QUOTE 0x22 /* Quotation mark (") */
|
||||
#define ASCII_NUMBER 0x23 /* Number sign (#) */
|
||||
#define ASCII_HASH 0x23 /* Hash (#) */
|
||||
#define ASCII_DOLLAR 0x24 /* Dollar sign ($) */
|
||||
#define ASCII_PERCENT 0x25 /* Percent sign (%) */
|
||||
#define ASCII_AMPERSAND 0x26 /* Ampersand (&) */
|
||||
#define ASCII_SQUOTE 0x27 /* Single quote (') */
|
||||
#define ASCII_APOSTROPHE 0x27 /* Apostrophe (') */
|
||||
#define ASCII_LPAREN 0x28 /* Opening parenthesis (() */
|
||||
#define ASCII_RPAREN 0x29 /* Closing parenthesis ()) */
|
||||
#define ASCII_ASTERISK 0x2a /* Asterisk (*) */
|
||||
#define ASCII_PLUS 0x2b /* Plus sign (+) */
|
||||
#define ASCII_COMMA 0x2c /* Comma (,) */
|
||||
#define ASCII_HYPHEN 0x2d /* Hyphen (-) */
|
||||
#define ASCII_DASH 0x2d /* Dash (-) */
|
||||
#define ASCII_MINUS 0x2d /* Minus sign (-) */
|
||||
#define ASCII_PERIOD 0x2e /* Period (.) */
|
||||
#define ASCII_SLASH 0x2f /* Forward Slash (/) */
|
||||
#define ASCII_DIVIDE 0x2f /* Divide (/) */
|
||||
|
||||
#define ASCII_0 0x30 /* Numbers */
|
||||
#define ASCII_1 0x31 /* " " */
|
||||
#define ASCII_2 0x32 /* " " */
|
||||
#define ASCII_3 0x33 /* " " */
|
||||
#define ASCII_4 0x34 /* " " */
|
||||
#define ASCII_5 0x35 /* " " */
|
||||
#define ASCII_6 0x36 /* " " */
|
||||
#define ASCII_7 0x37 /* " " */
|
||||
#define ASCII_8 0x38 /* " " */
|
||||
#define ASCII_9 0x39 /* " " */
|
||||
#define ASCII_COLON 0x3a /* Colon (:) */
|
||||
#define ASCII_SEMICOLON 0x3b /* Semicolon (;) */
|
||||
#define ASCII_LT 0x3c /* Less than (<) */
|
||||
#define ASCII_EQUAL 0x3d /* Equal (=) */
|
||||
#define ASCII_GT 0x3e /* Greater than (>) */
|
||||
#define ASCII_QUESTION 0x3f /* Question mark (?) */
|
||||
|
||||
#define ASCII_AT 0x40 /* At sign (@) */
|
||||
#define ASCII_A 0x41 /* Upper case letters */
|
||||
#define ASCII_B 0x42 /* " " " " " " */
|
||||
#define ASCII_C 0x43 /* " " " " " " */
|
||||
#define ASCII_D 0x44 /* " " " " " " */
|
||||
#define ASCII_E 0x45 /* " " " " " " */
|
||||
#define ASCII_F 0x46 /* " " " " " " */
|
||||
#define ASCII_G 0x47 /* " " " " " " */
|
||||
#define ASCII_H 0x48 /* " " " " " " */
|
||||
#define ASCII_I 0x49 /* " " " " " " */
|
||||
#define ASCII_J 0x4a /* " " " " " " */
|
||||
#define ASCII_K 0x4b /* " " " " " " */
|
||||
#define ASCII_L 0x4c /* " " " " " " */
|
||||
#define ASCII_M 0x4d /* " " " " " " */
|
||||
#define ASCII_N 0x4e /* " " " " " " */
|
||||
#define ASCII_O 0x4f /* " " " " " " */
|
||||
|
||||
#define ASCII_P 0x50 /* " " " " " " */
|
||||
#define ASCII_Q 0x51 /* " " " " " " */
|
||||
#define ASCII_R 0x52 /* " " " " " " */
|
||||
#define ASCII_S 0x53 /* " " " " " " */
|
||||
#define ASCII_T 0x54 /* " " " " " " */
|
||||
#define ASCII_U 0x55 /* " " " " " " */
|
||||
#define ASCII_V 0x56 /* " " " " " " */
|
||||
#define ASCII_W 0x57 /* " " " " " " */
|
||||
#define ASCII_X 0x58 /* " " " " " " */
|
||||
#define ASCII_Y 0x59 /* " " " " " " */
|
||||
#define ASCII_Z 0x5a /* " " " " " " */
|
||||
#define ASCII_LBRACKET 0x5b /* Left bracket ([) */
|
||||
#define ASCII_BACKSLASH 0x5c /* Back slash (\) */
|
||||
#define ASCII_RBRACKET 0x5d /* Right bracket (]) */
|
||||
#define ASCII_CARET 0x5e /* Caret (^) */
|
||||
#define ASCII_CIRCUMFLEX 0x5e /* Circumflex (^) */
|
||||
#define ASCII_UNDERSCORE 0x5f /* Underscore (_) */
|
||||
|
||||
#define ASCII_RSQUOTE 0x60 /* Closing single quote */
|
||||
#define ASCII_a 0x61 /* Lower case letters */
|
||||
#define ASCII_b 0x62 /* " " " " " " */
|
||||
#define ASCII_c 0x63 /* " " " " " " */
|
||||
#define ASCII_d 0x64 /* " " " " " " */
|
||||
#define ASCII_e 0x65 /* " " " " " " */
|
||||
#define ASCII_f 0x66 /* " " " " " " */
|
||||
#define ASCII_g 0x67 /* " " " " " " */
|
||||
#define ASCII_h 0x68 /* " " " " " " */
|
||||
#define ASCII_i 0x69 /* " " " " " " */
|
||||
#define ASCII_j 0x6a /* " " " " " " */
|
||||
#define ASCII_k 0x6b /* " " " " " " */
|
||||
#define ASCII_l 0x6c /* " " " " " " */
|
||||
#define ASCII_m 0x6d /* " " " " " " */
|
||||
#define ASCII_n 0x6e /* " " " " " " */
|
||||
#define ASCII_o 0x6f /* " " " " " " */
|
||||
|
||||
#define ASCII_p 0x70 /* " " " " " " */
|
||||
#define ASCII_q 0x71 /* " " " " " " */
|
||||
#define ASCII_r 0x72 /* " " " " " " */
|
||||
#define ASCII_s 0x73 /* " " " " " " */
|
||||
#define ASCII_t 0x74 /* " " " " " " */
|
||||
#define ASCII_u 0x75 /* " " " " " " */
|
||||
#define ASCII_v 0x76 /* " " " " " " */
|
||||
#define ASCII_w 0x77 /* " " " " " " */
|
||||
#define ASCII_x 0x78 /* " " " " " " */
|
||||
#define ASCII_y 0x79 /* " " " " " " */
|
||||
#define ASCII_z 0x7a /* " " " " " " */
|
||||
#define ASCII_LBRACE 0x7b /* Left brace ({) */
|
||||
#define ASCII_VERTBAR 0x7c /* Vertical bar (|) */
|
||||
#define ASCII_PIPE 0x7c /* Pipe (|) */
|
||||
#define ASCII_RBRACE 0x7d /* Right brace (}) */
|
||||
#define ASCII_TILDE 0x7e /* Tilde (~) */
|
||||
#define ASCII_DEL 0x7f /* Delete (rubout) */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_ASCII_H */
|
||||
@@ -0,0 +1,805 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/audio/audio.h
|
||||
*
|
||||
* Copyright (C) 2017, 2019 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2013 Ken Pettit. All rights reserved.
|
||||
* Author: Ken Pettit <pettitkd@gmail.com>
|
||||
*
|
||||
* 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 __INCLUDE_NUTTX_AUDIO_AUDIO_H
|
||||
#define __INCLUDE_NUTTX_AUDIO_AUDIO_H
|
||||
|
||||
/* For the purposes of this driver, an Audio device is any device that
|
||||
* generates, records, mixes, or otherwise modifies audio data in any format,
|
||||
* such as PCM, MP3, AAC, etc.
|
||||
*
|
||||
* The Audio driver is split into two parts:
|
||||
*
|
||||
* 1) An "upper half", generic driver that provides the common Audio
|
||||
* interface to application level code, and
|
||||
* 2) A "lower half", platform-specific driver that implements the
|
||||
* low-level controls to configure and communicate with the audio
|
||||
* device(s).
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
#include <nuttx/semaphore.h>
|
||||
#include <nuttx/spi/spi.h>
|
||||
|
||||
#include <queue.h>
|
||||
|
||||
#ifdef CONFIG_AUDIO
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
/* CONFIG_AUDIO - Enables Audio driver support
|
||||
* CONFIG_DEBUG_AUDIO - If enabled (with CONFIG_DEBUG_FEATURES and,
|
||||
* optionally, CONFIG_DEBUG_INFO), this will generate output that can
|
||||
* be used to debug Audio drivers.
|
||||
*/
|
||||
|
||||
/* IOCTL Commands ***********************************************************/
|
||||
|
||||
/* The Audio module uses a standard character driver framework. However, a
|
||||
* lot of the Audio driver functionality is configured via a device control
|
||||
* interface, such as sampling rate, volume, data format, etc.
|
||||
* The Audio ioctl commands are listed below:
|
||||
*
|
||||
* AUDIOIOC_GETCAPS - Get the Audio Device Capabilities
|
||||
*
|
||||
* ioctl argument: Pointer to the audio_caps_s structure to receive the
|
||||
* capabilities info. The "len" and "type" fields should
|
||||
* be filled in prior to calling this ioctl. To get
|
||||
* overall capabilities, specify the type as
|
||||
* AUDIO_TYPE_QUERY, otherwise specify any type that was
|
||||
* reported by the device during the QUERY.
|
||||
*
|
||||
* AUDIOIOC_CONFIGURE - Configure device for the specified mode
|
||||
*
|
||||
* ioctl argument: Pointer to the audio_caps_s structure which identifies
|
||||
* the capabilities to configure for.
|
||||
*
|
||||
* AUDIOIOC_SHUTDOWN - Shutdown the device.
|
||||
*
|
||||
* ioctl argument: None
|
||||
*
|
||||
* AUDIOIOC_START - Start Audio streaming
|
||||
*
|
||||
* ioctl argument: None
|
||||
*
|
||||
* AUDIOIOC_STOP - Stop Audio streaming
|
||||
*
|
||||
* ioctl argument: None
|
||||
*/
|
||||
|
||||
#define AUDIOIOC_GETCAPS _AUDIOIOC(1)
|
||||
#define AUDIOIOC_RESERVE _AUDIOIOC(2)
|
||||
#define AUDIOIOC_RELEASE _AUDIOIOC(3)
|
||||
#define AUDIOIOC_CONFIGURE _AUDIOIOC(4)
|
||||
#define AUDIOIOC_SHUTDOWN _AUDIOIOC(5)
|
||||
#define AUDIOIOC_START _AUDIOIOC(6)
|
||||
#define AUDIOIOC_STOP _AUDIOIOC(7)
|
||||
#define AUDIOIOC_PAUSE _AUDIOIOC(8)
|
||||
#define AUDIOIOC_RESUME _AUDIOIOC(9)
|
||||
#define AUDIOIOC_GETBUFFERINFO _AUDIOIOC(10)
|
||||
#define AUDIOIOC_ALLOCBUFFER _AUDIOIOC(11)
|
||||
#define AUDIOIOC_FREEBUFFER _AUDIOIOC(12)
|
||||
#define AUDIOIOC_ENQUEUEBUFFER _AUDIOIOC(13)
|
||||
#define AUDIOIOC_REGISTERMQ _AUDIOIOC(14)
|
||||
#define AUDIOIOC_UNREGISTERMQ _AUDIOIOC(15)
|
||||
#define AUDIOIOC_HWRESET _AUDIOIOC(16)
|
||||
#define AUDIOIOC_SETBUFFERINFO _AUDIOIOC(17)
|
||||
|
||||
/* Audio Device Types *******************************************************/
|
||||
|
||||
/* The NuttX audio interface support different types of audio devices for
|
||||
* input, output, synthesis, and manipulation of audio data. A given driver/
|
||||
* device could support a combination of these device type. The following
|
||||
* is a list of bit-field definitions for defining the device type.
|
||||
*/
|
||||
|
||||
#define AUDIO_TYPE_QUERY 0x00
|
||||
#define AUDIO_TYPE_INPUT 0x01
|
||||
#define AUDIO_TYPE_OUTPUT 0x02
|
||||
#define AUDIO_TYPE_MIXER 0x04
|
||||
#define AUDIO_TYPE_SELECTOR 0x08
|
||||
#define AUDIO_TYPE_FEATURE 0x10
|
||||
#define AUDIO_TYPE_EFFECT 0x20
|
||||
#define AUDIO_TYPE_PROCESSING 0x40
|
||||
#define AUDIO_TYPE_EXTENSION 0x80
|
||||
|
||||
/* Audio Format Types *******************************************************/
|
||||
|
||||
/* The following defines the audio data format types in NuttX. During a
|
||||
* format query, these will be converted to bit positions within the
|
||||
* ac_format field, meaning we currently only support up to 16 formats. To
|
||||
* support more than that, we will use the FMT_OTHER entry, and the
|
||||
* interfacing software can perform a second query to get the other formats.
|
||||
*/
|
||||
|
||||
#define AUDIO_FMT_UNDEF 0x00
|
||||
#define AUDIO_FMT_OTHER 0x01
|
||||
#define AUDIO_FMT_MPEG 0x02
|
||||
#define AUDIO_FMT_AC3 0x03
|
||||
#define AUDIO_FMT_WMA 0x04
|
||||
#define AUDIO_FMT_DTS 0x05
|
||||
#define AUDIO_FMT_PCM 0x06
|
||||
#define AUDIO_FMT_WAV 0x07
|
||||
#define AUDIO_FMT_MP3 0x08
|
||||
#define AUDIO_FMT_MIDI 0x09
|
||||
#define AUDIO_FMT_OGG_VORBIS 0x0a
|
||||
#define AUDIO_FMT_FLAC 0x0b
|
||||
|
||||
/* Audio Sub-Format Types ***************************************************/
|
||||
|
||||
#define AUDIO_SUBFMT_END 0x00
|
||||
#define AUDIO_SUBFMT_PCM_MP1 0x01
|
||||
#define AUDIO_SUBFMT_PCM_MP2 0x02
|
||||
#define AUDIO_SUBFMT_PCM_MP3 0x03
|
||||
#define AUDIO_SUBFMT_PCM_MU_LAW 0x04
|
||||
#define AUDIO_SUBFMT_PCM_A_LAW 0x05
|
||||
#define AUDIO_SUBFMT_PCM_U8 0x06
|
||||
#define AUDIO_SUBFMT_PCM_S8 0x07
|
||||
#define AUDIO_SUBFMT_PCM_U16_LE 0x08
|
||||
#define AUDIO_SUBFMT_PCM_S16_BE 0x09
|
||||
#define AUDIO_SUBFMT_PCM_S16_LE 0x0a
|
||||
#define AUDIO_SUBFMT_PCM_U16_BE 0x0b
|
||||
#define AUDIO_SUBFMT_MIDI_0 0x0c
|
||||
#define AUDIO_SUBFMT_MIDI_1 0x0d
|
||||
#define AUDIO_SUBFMT_MIDI_2 0x0e
|
||||
|
||||
/* Audio Hardware-Format Types **********************************************/
|
||||
|
||||
#define AUDIO_HWFMT_I2S (1 << 0)
|
||||
#define AUDIO_HWFMT_RIGHT_J (2 << 0)
|
||||
#define AUDIO_HWFMT_LEFT_J (3 << 0)
|
||||
#define AUDIO_HWFMT_DSP_A (4 << 0)
|
||||
#define AUDIO_HWFMT_DSP_B (5 << 0)
|
||||
#define AUDIO_HWFMT_AC97 (6 << 0)
|
||||
#define AUDIO_HWFMT_PDM (7 << 0)
|
||||
|
||||
#define AUDIO_HWFMT_NB_NF (0 << 8)
|
||||
#define AUDIO_HWFMT_NB_IF (2 << 8)
|
||||
#define AUDIO_HWFMT_IB_NF (3 << 8)
|
||||
#define AUDIO_HWFMT_IB_IF (4 << 8)
|
||||
|
||||
#define AUDIO_HWFMT_CBM_CFM (1 << 12)
|
||||
#define AUDIO_HWFMT_CBS_CFM (2 << 12)
|
||||
#define AUDIO_HWFMT_CBM_CFS (3 << 12)
|
||||
#define AUDIO_HWFMT_CBS_CFS (4 << 12)
|
||||
|
||||
#define AUDIO_HWFMT_FORMAT_MASK 0x000f
|
||||
#define AUDIO_HWFMT_CLOCK_MASK 0x00f0
|
||||
#define AUDIO_HWFMT_INV_MASK 0x0f00
|
||||
#define AUDIO_HWFMT_MASTER_MASK 0xf000
|
||||
|
||||
/* Supported Sampling Rates *************************************************/
|
||||
|
||||
#define AUDIO_SAMP_RATE_8K 0x0001
|
||||
#define AUDIO_SAMP_RATE_11K 0x0002
|
||||
#define AUDIO_SAMP_RATE_16K 0x0004
|
||||
#define AUDIO_SAMP_RATE_22K 0x0008
|
||||
#define AUDIO_SAMP_RATE_32K 0x0010
|
||||
#define AUDIO_SAMP_RATE_44K 0x0020
|
||||
#define AUDIO_SAMP_RATE_48K 0x0040
|
||||
#define AUDIO_SAMP_RATE_96K 0x0080
|
||||
#define AUDIO_SAMP_RATE_128K 0x0100
|
||||
#define AUDIO_SAMP_RATE_160K 0x0200
|
||||
#define AUDIO_SAMP_RATE_172K 0x0400
|
||||
#define AUDIO_SAMP_RATE_192K 0x0800
|
||||
|
||||
/* Audio Sub-sampling Ratios ***********************************************/
|
||||
|
||||
#define AUDIO_SUBSAMPLE_NONE 0
|
||||
#define AUDIO_SUBSAMPLE_2X 2
|
||||
#define AUDIO_SUBSAMPLE_4X 4
|
||||
#define AUDIO_SUBSAMPLE_8X 8
|
||||
#define AUDIO_SUBSAMPLE_16X 16
|
||||
|
||||
#define AUDIO_SUBSAMPLE_MIN AUDIO_SUBSAMPLE_2X
|
||||
#define AUDIO_SUBSAMPLE_MAX AUDIO_SUBSAMPLE_16X
|
||||
|
||||
/* Supported Bit Rates ******************************************************/
|
||||
|
||||
#define AUDIO_BIT_RATE_22K 0x01
|
||||
#define AUDIO_BIT_RATE_44K 0x02
|
||||
#define AUDIO_BIT_RATE_48K 0x04
|
||||
#define AUDIO_BIT_RATE_96K 0x08
|
||||
#define AUDIO_BIT_RATE_128K 0x10
|
||||
#define AUDIO_BIT_RATE_160K 0x20
|
||||
#define AUDIO_BIT_RATE_172K 0x40
|
||||
#define AUDIO_BIT_RATE_192K 0x80
|
||||
|
||||
/* Supported Feature Units controls *****************************************/
|
||||
|
||||
#define AUDIO_FU_UNDEF 0x0000
|
||||
#define AUDIO_FU_MUTE 0x0001
|
||||
#define AUDIO_FU_VOLUME 0x0002
|
||||
#define AUDIO_FU_BASS 0x0004
|
||||
#define AUDIO_FU_MID 0x0008
|
||||
#define AUDIO_FU_TREBLE 0x0010
|
||||
#define AUDIO_FU_EQUALIZER 0x0020
|
||||
#define AUDIO_FU_AGC 0x0040
|
||||
#define AUDIO_FU_DELAY 0x0080
|
||||
#define AUDIO_FU_BASS_BOOST 0x0100
|
||||
#define AUDIO_FU_LOUDNESS 0x0200
|
||||
#define AUDIO_FU_INP_GAIN 0x0400
|
||||
#define AUDIO_FU_BALANCE 0x0800
|
||||
#define AUDIO_FU_PHASE_INVERT 0x1000
|
||||
#define AUDIO_FU_UNDERFLOW 0x2000
|
||||
#define AUDIO_FU_OVERFLOW 0x4000
|
||||
#define AUDIO_FU_LATENCY 0x8000
|
||||
|
||||
/* Processing Unit controls *************************************************/
|
||||
|
||||
#define AUDIO_PU_UNDEF 0x00
|
||||
#define AUDIO_PU_UPDOWNMIX 0x01
|
||||
#define AUDIO_PU_DOLBY_PROLOGIC 0x02
|
||||
#define AUDIO_PU_STEREO_EXTENDER 0x03
|
||||
#define AUDIO_PU_SUBSAMPLE_FORWARD 0x04
|
||||
#define AUDIO_PU_SUBSAMPLE_REWIND 0x05
|
||||
|
||||
/* Stereo Extender PU Controls **********************************************/
|
||||
|
||||
#define AUDIO_STEXT_UNDEF 0x00
|
||||
#define AUDIO_STEXT_ENABLE 0x01
|
||||
#define AUDIO_STEXT_WIDTH 0x02
|
||||
#define AUDIO_STEXT_UNDERFLOW 0x03
|
||||
#define AUDIO_STEXT_OVERFLOW 0x04
|
||||
#define AUDIO_STEXT_LATENCY 0x05
|
||||
|
||||
/* Extension Unit controls **************************************************/
|
||||
|
||||
#define AUDIO_EU_HW_FORMAT 0x0001
|
||||
#define AUDIO_EU_LOAD_MODULE 0x0002
|
||||
|
||||
/* Audio Callback Reasons ***************************************************/
|
||||
|
||||
#define AUDIO_CALLBACK_UNDEF 0x00
|
||||
#define AUDIO_CALLBACK_DEQUEUE 0x01
|
||||
#define AUDIO_CALLBACK_IOERR 0x02
|
||||
#define AUDIO_CALLBACK_COMPLETE 0x03
|
||||
#define AUDIO_CALLBACK_MESSAGE 0x04
|
||||
|
||||
/* Audio Pipeline Buffer (AP Buffer) flags **********************************/
|
||||
|
||||
#define AUDIO_ABP_ALIGNMENT 0x000f /* Mask to define buffer alignment */
|
||||
#define AUDIO_ABP_CANDMA 0x0010 /* Set if the data is DMA'able */
|
||||
#define AUDIO_ABP_STATIC 0x0020 /* Set if statically allocated */
|
||||
#define AUDIO_ABP_ACTIVE 0x0040 /* Set if this buffer is still active.
|
||||
* A buffer could become inactive
|
||||
* if it is processed by an output
|
||||
* device or a processing device
|
||||
* that replaces it with an alternate
|
||||
* buffer as a result of some DSP
|
||||
* operation, etc.
|
||||
*/
|
||||
|
||||
/* Standard Audio Message Queue message IDs */
|
||||
|
||||
#define AUDIO_MSG_NONE 0
|
||||
#define AUDIO_MSG_DEQUEUE 1
|
||||
#define AUDIO_MSG_START 2
|
||||
#define AUDIO_MSG_STOP 3
|
||||
#define AUDIO_MSG_PAUSE 4
|
||||
#define AUDIO_MSG_RESUME 5
|
||||
#define AUDIO_MSG_DATA_REQUEST 6
|
||||
#define AUDIO_MSG_ENQUEUE 7
|
||||
#define AUDIO_MSG_COMPLETE 8
|
||||
#define AUDIO_MSG_WAKEUP 9
|
||||
#define AUDIO_MSG_COMMAND 10
|
||||
#define AUDIO_MSG_SLIENCE 11
|
||||
#define AUDIO_MSG_USER 64
|
||||
|
||||
/* Audio Pipeline Buffer flags */
|
||||
|
||||
#define AUDIO_APB_OUTPUT_ENQUEUED (1 << 0)
|
||||
#define AUDIO_APB_OUTPUT_PROCESS (1 << 1)
|
||||
#define AUDIO_APB_DEQUEUED (1 << 2)
|
||||
#define AUDIO_APB_FINAL (1 << 3) /* Last buffer in the stream */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Define the size of AP Buffer sample count base on CONFIG */
|
||||
|
||||
#ifdef CONFIG_AUDIO_LARGE_BUFFERS
|
||||
typedef uint32_t apb_samp_t;
|
||||
#else
|
||||
typedef uint16_t apb_samp_t;
|
||||
#endif
|
||||
|
||||
/* This structure is used to describe the audio device capabilities */
|
||||
|
||||
struct audio_caps_s
|
||||
{
|
||||
uint8_t ac_len; /* Length of the structure */
|
||||
uint8_t ac_type; /* Capabilities (device) type */
|
||||
uint8_t ac_subtype; /* Capabilities sub-type, if needed */
|
||||
uint8_t ac_channels; /* Number of channels (1, 2, 3, ... 8) */
|
||||
uint8_t ac_chmap; /* Channel map, each ch for each bit,
|
||||
* zero means don't care */
|
||||
uint8_t reserved; /* Reserved for future use */
|
||||
|
||||
/* Audio data format(s) for this device */
|
||||
|
||||
union
|
||||
{
|
||||
uint8_t b[2];
|
||||
uint16_t hw;
|
||||
} ac_format;
|
||||
|
||||
/* Specific controls for AUDIO_DEVICE_QUERY
|
||||
* this field reports the device type supported
|
||||
* by this lower-half driver.
|
||||
*/
|
||||
|
||||
union
|
||||
{
|
||||
uint8_t b[4];
|
||||
uint16_t hw[2];
|
||||
uint32_t w;
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
uint64_t qw;
|
||||
#endif
|
||||
} ac_controls;
|
||||
};
|
||||
|
||||
struct audio_caps_desc_s
|
||||
{
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
FAR void *session; /* Associated session */
|
||||
#endif
|
||||
struct audio_caps_s caps; /* The capabilities struct */
|
||||
};
|
||||
|
||||
/* This structure describes the characteristics of the Audio samples */
|
||||
|
||||
struct audio_info_s
|
||||
{
|
||||
uint8_t samplerate; /* Sample Rate of the audio data */
|
||||
uint8_t channels; /* Number of channels (1, 2, 5, 7) */
|
||||
uint8_t format; /* Audio data format */
|
||||
uint8_t subformat; /* Audio subformat
|
||||
* (maybe should be combined with format?
|
||||
*/
|
||||
};
|
||||
|
||||
/* This structure describes the preferred number and size of
|
||||
* audio pipeline buffers for the audio device. Each device
|
||||
* may have unique needs regarding size and qty of buffers,
|
||||
* so this info is queried from the lower-half driver.
|
||||
*/
|
||||
|
||||
struct ap_buffer_info_s
|
||||
{
|
||||
apb_samp_t nbuffers; /* Preferred qty of buffers */
|
||||
apb_samp_t buffer_size; /* Preferred size of the buffers */
|
||||
};
|
||||
|
||||
/* This structure describes an Audio Pipeline Buffer */
|
||||
|
||||
struct ap_buffer_s
|
||||
{
|
||||
struct dq_entry_s dq_entry; /* Double linked queue entry */
|
||||
struct audio_info_s i; /* The info for samples in this buffer */
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
FAR void *session; /* Associated session */
|
||||
#endif
|
||||
apb_samp_t nmaxbytes; /* The maximum number of bytes */
|
||||
apb_samp_t nbytes; /* The number of bytes used */
|
||||
apb_samp_t curbyte; /* Next byte to be processed */
|
||||
sem_t sem; /* Reference locking semaphore */
|
||||
uint16_t flags; /* Buffer flags */
|
||||
uint16_t crefs; /* Number of reference counts */
|
||||
FAR uint8_t *samp; /* Offset of the first sample */
|
||||
};
|
||||
|
||||
/* Structure defining the messages passed to a listening audio thread
|
||||
* for dequeuing buffers and other operations. Also used to allocate
|
||||
* and enqueue buffers via the AUDIOIOC_ALLOCBUFFER, AUDIOIOC_FREEBUFFER,
|
||||
* and AUDIOIOC_ENQUEUEBUFFER ioctls.
|
||||
*/
|
||||
|
||||
struct audio_msg_s
|
||||
{
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
FAR void *session; /* Associated channel */
|
||||
#endif
|
||||
uint16_t msg_id; /* Message ID */
|
||||
union
|
||||
{
|
||||
FAR void *ptr; /* Buffer being dequeued */
|
||||
uint32_t data; /* Message data */
|
||||
} u;
|
||||
};
|
||||
|
||||
/* Structure defining the built-in sounds */
|
||||
|
||||
#ifdef CONFIG_AUDIO_BUILTIN_SOUNDS
|
||||
struct audio_sound_s
|
||||
{
|
||||
const char *name; /* Name of the sound */
|
||||
uint32_t id; /* ID of the sound */
|
||||
uint32_t type; /* Type of sound */
|
||||
uint32_t size; /* Number of bytes in the sound */
|
||||
const uint8_t *data; /* Pointer to the data */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* Structure for allocating, freeing and enqueueing audio pipeline
|
||||
* buffers via the AUDIOIOC_ALLOCBUFFER, AUDIOIOC_FREEBUFFER,
|
||||
* and AUDIOIOC_ENQUEUEBUFFER ioctls.
|
||||
*/
|
||||
|
||||
struct audio_buf_desc_s
|
||||
{
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
FAR void *session; /* Associated channel */
|
||||
#endif
|
||||
uint16_t numbytes; /* Number of bytes to allocate */
|
||||
union
|
||||
{
|
||||
FAR struct ap_buffer_s *buffer; /* Buffer to free / enqueue */
|
||||
FAR struct ap_buffer_s **pbuffer; /* Pointer to receive allocated buffer */
|
||||
} u;
|
||||
};
|
||||
|
||||
/* Typedef for lower-level to upper-level callback for buffer dequeuing */
|
||||
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
typedef CODE void (*audio_callback_t)(FAR void *priv, uint16_t reason,
|
||||
FAR struct ap_buffer_s *apb, uint16_t status, FAR void *session);
|
||||
#else
|
||||
typedef CODE void (*audio_callback_t)(FAR void *priv, uint16_t reason,
|
||||
FAR struct ap_buffer_s *apb, uint16_t status);
|
||||
#endif
|
||||
|
||||
/* This structure is a set a callback functions used to call from the upper-
|
||||
* half, generic Audo driver into lower-half, platform-specific logic that
|
||||
* supports the low-level functionality.
|
||||
*/
|
||||
|
||||
struct audio_lowerhalf_s;
|
||||
struct audio_ops_s
|
||||
{
|
||||
/* This method is called to retrieve the lower-half device capabilities.
|
||||
* It will be called with device type AUDIO_TYPE_QUERY to request the
|
||||
* overall capabilities, such as to determine the types of devices
|
||||
* supported audio formats supported, etc.
|
||||
* Then it may be called once or more with reported supported device types
|
||||
* to determine the specific capabilities of that device type
|
||||
* (such as MP3 encoder, WMA encoder, PCM output, etc.).
|
||||
*/
|
||||
|
||||
CODE int (*getcaps)(FAR struct audio_lowerhalf_s *dev, int type,
|
||||
FAR struct audio_caps_s *caps);
|
||||
|
||||
/* This method is called to bind the lower-level driver to the upper-level
|
||||
* driver and to configure the driver for a specific mode of
|
||||
* operation defined by the parameters selected in supplied device caps
|
||||
* structure. The lower-level device should perform any initialization
|
||||
* needed to prepare for operations in the specified mode. It should not,
|
||||
* however, process any audio data until the start method is called.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
CODE int (*configure)(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR void *session, FAR const struct audio_caps_s *caps);
|
||||
#else
|
||||
CODE int (*configure)(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR const struct audio_caps_s *caps);
|
||||
#endif
|
||||
|
||||
/* This method is called when the driver is closed. The lower half driver
|
||||
* should stop processing audio data, including terminating any active
|
||||
* output generation. It should also disable the audio hardware and put
|
||||
* it into the lowest possible power usage state.
|
||||
*
|
||||
* Any enqueued Audio Pipeline Buffers that have not been
|
||||
* processed / dequeued should be dequeued by this function.
|
||||
*/
|
||||
|
||||
CODE int (*shutdown)(FAR struct audio_lowerhalf_s *dev);
|
||||
|
||||
/* Start audio streaming in the configured mode. For input and synthesis
|
||||
* devices, this means it should begin sending streaming audio data.
|
||||
* For output or processing type device, it means it should begin
|
||||
* processing of any enqueued Audio Pipeline Buffers.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
CODE int (*start)(FAR struct audio_lowerhalf_s *dev, FAR void *session);
|
||||
#else
|
||||
CODE int (*start)(FAR struct audio_lowerhalf_s *dev);
|
||||
#endif
|
||||
|
||||
/* Stop audio streaming and/or processing of enqueued
|
||||
* Audio Pipeline Buffers
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
CODE int (*stop)(FAR struct audio_lowerhalf_s *dev, FAR void *session);
|
||||
#else
|
||||
CODE int (*stop)(FAR struct audio_lowerhalf_s *dev);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Pause the audio stream.
|
||||
* Should keep current playback context active in case a resume is issued.
|
||||
* Could be called and then followed by a stop.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
CODE int (*pause)(FAR struct audio_lowerhalf_s *dev, FAR void *session);
|
||||
#else
|
||||
CODE int (*pause)(FAR struct audio_lowerhalf_s *dev);
|
||||
#endif
|
||||
|
||||
/* Resumes audio streaming after a pause */
|
||||
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
CODE int (*resume)(FAR struct audio_lowerhalf_s *dev, FAR void *session);
|
||||
#else
|
||||
CODE int (*resume)(FAR struct audio_lowerhalf_s *dev);
|
||||
#endif
|
||||
#endif /* CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME */
|
||||
|
||||
/* Allocate an audio pipeline buffer. This routine provides the
|
||||
* lower-half driver with the opportunity to perform special buffer
|
||||
* allocation if needed, such as allocating from a specific memory
|
||||
* region (DMA-able, etc.). If not supplied, then the top-half
|
||||
* driver will perform a standard kumm_malloc using normal user-space
|
||||
* memory region.
|
||||
*/
|
||||
|
||||
CODE int (*allocbuffer)(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR struct audio_buf_desc_s *apb);
|
||||
|
||||
/* Free an audio pipeline buffer. If the lower-level driver
|
||||
* provides an allocbuffer routine, it should also provide the
|
||||
* freebuffer routine to perform the free operation.
|
||||
*/
|
||||
|
||||
CODE int (*freebuffer)(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR struct audio_buf_desc_s *apb);
|
||||
|
||||
/* Enqueue a buffer for processing.
|
||||
* This is a non-blocking enqueue operation.
|
||||
* If the lower-half driver's buffer queue is full, then it should return
|
||||
* an error code of -ENOMEM, and the upper-half driver can decide to either
|
||||
* block the calling thread or deal with it in a non-blocking manner.
|
||||
|
||||
* For each call to enqueuebuffer, the lower-half driver must call
|
||||
* audio_dequeuebuffer when it is finished processing the bufferr, passing
|
||||
* the previously enqueued apb and a dequeue status so that the upper-half
|
||||
* driver can decide if a waiting thread needs to be release, if the
|
||||
* dequeued buffer should be passed to the next block in the
|
||||
* Audio Pipeline, etc.
|
||||
*/
|
||||
|
||||
CODE int (*enqueuebuffer)(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR struct ap_buffer_s *apb);
|
||||
|
||||
/* Cancel a previously enqueued buffer. */
|
||||
|
||||
CODE int (*cancelbuffer)(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR struct ap_buffer_s *apb);
|
||||
|
||||
/* Lower-half logic may support platform-specific ioctl commands */
|
||||
|
||||
CODE int (*ioctl)(FAR struct audio_lowerhalf_s *dev,
|
||||
int cmd, unsigned long arg);
|
||||
|
||||
/* Lower-half logic may support platform-specific read commands */
|
||||
|
||||
CODE int (*read)(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR char *buffer, size_t buflen);
|
||||
|
||||
/* Lower-half logic may support platform-specific write commands */
|
||||
|
||||
CODE int (*write)(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR const char *buffer, size_t buflen);
|
||||
|
||||
/* Reserve a session (may only be one per device or may be multiple) for
|
||||
* use by a client. Client software can open audio devices and issue
|
||||
* AUDIOIOC_GETCAPS calls freely, but other operations require a
|
||||
* reservation. A session reservation will assign a context that must
|
||||
* be passed with
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
CODE int (*reserve)(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR void **psession);
|
||||
#else
|
||||
CODE int (*reserve)(FAR struct audio_lowerhalf_s *dev);
|
||||
#endif
|
||||
|
||||
/* Release a session. */
|
||||
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
CODE int (*release)(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR void *session);
|
||||
#else
|
||||
CODE int (*release)(FAR struct audio_lowerhalf_s *dev);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* This structure is the generic form of state structure used by lower half
|
||||
* Audio driver. This state structure is passed to the Audio driver when the
|
||||
* driver is initialized. Then, on subsequent callbacks into the lower half
|
||||
* Audio logic, this structure is provided so that the Audio logic can
|
||||
* maintain state information.
|
||||
*
|
||||
* Normally that Audio logic will have its own, custom state structure
|
||||
* that is simply cast to struct audio_lowerhalf_s. In order to perform such
|
||||
* casts, the initial fields of the custom state structure match the initial
|
||||
* fields of the following generic Audio state structure.
|
||||
*/
|
||||
|
||||
struct audio_lowerhalf_s
|
||||
{
|
||||
/* The first field of this state structure must be a pointer to the Audio
|
||||
* callback structure:
|
||||
*/
|
||||
|
||||
FAR const struct audio_ops_s *ops;
|
||||
|
||||
/* The bind data to the upper-half driver used for callbacks of dequeuing
|
||||
* buffer, reporting asynchronous event, reporting errors, etc.
|
||||
*/
|
||||
|
||||
FAR audio_callback_t upper;
|
||||
|
||||
/* The private opaque pointer to be passed to upper-layer during
|
||||
* callbacks
|
||||
*/
|
||||
|
||||
FAR void *priv;
|
||||
|
||||
/* The custom Audio device state structure may include additional fields
|
||||
* after the pointer to the Audio callback structure.
|
||||
*/
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* "Upper-Half" Audio Driver Interfaces
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: audio_register
|
||||
*
|
||||
* Description:
|
||||
* This function binds an instance of a "lower half" Audio driver with the
|
||||
* "upper half" Audio device and registers that device so that can be used
|
||||
* by application code.
|
||||
*
|
||||
* When this function is called, the "lower half" driver should be in the
|
||||
* reset state (as if the shutdown() method had already been called).
|
||||
*
|
||||
* Input Parameters:
|
||||
* name - The name of the audio device. This name will be used to generate
|
||||
* a full path to the driver in the format "/dev/audio/[name]" in the
|
||||
* NuttX filesystem (i.e. the path "/dev/audio" will be prepended to the
|
||||
* supplied device name. The recommended convention is to name Audio
|
||||
* drivers based on the type of functionality they provide, such as
|
||||
* "/dev/audio/pcm0", "/dev/audio/midi0", "/dev/audio/mp30, etc.
|
||||
* dev - A pointer to an instance of lower half audio driver. This instance
|
||||
* is bound to the Audio driver and must persists as long as the driver
|
||||
* persists.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int audio_register(FAR const char *name, FAR struct audio_lowerhalf_s *dev);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: abp_alloc
|
||||
*
|
||||
* Description:
|
||||
* Allocated an AP Buffer and prepares it for use.
|
||||
* This allocates a dynamically allocated buffer that has no special
|
||||
* DMA capabilities.
|
||||
*
|
||||
* Input Parameters:
|
||||
* bufdesc: Pointer to a buffer descriptor
|
||||
*
|
||||
* Returned Value:
|
||||
* Pointer to the allocated buffer or NULL if no memory.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int apb_alloc(FAR struct audio_buf_desc_s *bufdesc);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: apb_free
|
||||
*
|
||||
* Free's a previously allocated or referenced Audio Pipeline Buffer
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void apb_free(FAR struct ap_buffer_s *apb);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: apb_reference
|
||||
*
|
||||
* Claim a reference to an Audio Pipeline Buffer. Each call to apb_reference
|
||||
* will increment the reference count and must have a matching apb_free
|
||||
* call. When the refcount decrements to zero, the buffer will be freed.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void apb_reference(FAR struct ap_buffer_s *apb);
|
||||
|
||||
/****************************************************************************
|
||||
* Platform-Dependent "Lower-Half" Audio Driver Interfaces
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_AUDIO */
|
||||
#endif /* __INCLUDE_NUTTX_AUDIO_AUDIO_H */
|
||||
@@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/audio/audio_comp.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_AUDIO_AUDIO_COMP_H
|
||||
#define __INCLUDE_NUTTX_AUDIO_AUDIO_COMP_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#ifdef CONFIG_AUDIO_COMP
|
||||
#include <nuttx/audio/audio.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: audio_comp_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the composite audio device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* name - The name of the audio device.
|
||||
* ... - The list of the lower half audio driver.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
* Note
|
||||
* The variable argument list must be NULL terminated.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int audio_comp_initialize(FAR const char *name, ...);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_AUDIO_COMP */
|
||||
#endif /* __INCLUDE_NUTTX_AUDIO_AUDIO_COMP_H */
|
||||
@@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/audio/audio_i2s.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_AUDIO_AUDIO_I2S_H
|
||||
#define __INCLUDE_NUTTX_AUDIO_AUDIO_I2S_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#ifdef CONFIG_AUDIO_I2S
|
||||
|
||||
#include <nuttx/audio/audio.h>
|
||||
#include <nuttx/audio/i2s.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct audio_lowerhalf_s *audio_i2s_initialize(FAR struct i2s_dev_s *i2s,
|
||||
bool playback);
|
||||
|
||||
#endif /* CONFIG_AUDIO_I2S */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,122 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/audio/audio_null.h
|
||||
* A do-nothinig audio device driver to simplify testing of audio decoders.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_AUDIO_AUDIO_NULL_H
|
||||
#define __INCLUDE_NUTTX_AUDIO_AUDIO_NULL_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#ifdef CONFIG_AUDIO_NULL
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************
|
||||
*
|
||||
* CONFIG_AUDIO_NULL - Enabled NULL audio device support
|
||||
* CONFIG_AUDIO_NULL_MSG_PRIO - Priority of messages sent to the NULL audio
|
||||
* device worker thread.
|
||||
* CONFIG_AUDIO_NULL_BUFFER_SIZE - Preferred buffer size
|
||||
* CONFIG_AUDIO_NULL_NUM_BUFFERS - Preferred number of buffers
|
||||
* CONFIG_AUDIO_NULL_WORKER_STACKSIZE - Stack size to use when creating the
|
||||
* NULL audio device worker thread.
|
||||
*/
|
||||
|
||||
/* Pre-requisites */
|
||||
|
||||
#ifndef CONFIG_AUDIO
|
||||
# error CONFIG_AUDIO is required for audio subsystem support
|
||||
#endif
|
||||
|
||||
/* Default configuration values */
|
||||
|
||||
#ifndef CONFIG_AUDIO_NULL_MSG_PRIO
|
||||
# define CONFIG_AUDIO_NULL_MSG_PRIO 1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_AUDIO_NULL_BUFFER_SIZE
|
||||
# define CONFIG_AUDIO_NULL_BUFFER_SIZE 8192
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_AUDIO_NULL_NUM_BUFFERS
|
||||
# define CONFIG_AUDIO_NULL_NUM_BUFFERS 4
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_AUDIO_NULL_WORKER_STACKSIZE
|
||||
# define CONFIG_AUDIO_NULL_WORKER_STACKSIZE 768
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: audio_null_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the null audio device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* i2c - An I2C driver instance
|
||||
* i2s - An I2S driver instance
|
||||
* lower - Persistent board configuration data
|
||||
*
|
||||
* Returned Value:
|
||||
* A new lower half audio interface for the NULL audio device is returned
|
||||
* on success; NULL is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct audio_lowerhalf_s; /* Forward reference. Defined in nuttx/audio/audio.h */
|
||||
|
||||
FAR struct audio_lowerhalf_s *audio_null_initialize(void);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_AUDIO_NULL */
|
||||
#endif /* __INCLUDE_NUTTX_AUDIO_AUDIO_NULL_H */
|
||||
@@ -0,0 +1,141 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/audio/cs4344.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_AUDIO_CS4344_H
|
||||
#define __INCLUDE_NUTTX_AUDIO_CS4344_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#ifdef CONFIG_AUDIO_CS4344
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************
|
||||
*
|
||||
* CONFIG_AUDIO_CS4344 - Enables CS4344 support
|
||||
* CONFIG_CS4344_INFLIGHT - Maximum number of buffers that the CS4344
|
||||
* driver will send to the I2S driver before any have completed.
|
||||
* CONFIG_CS4344_MSG_PRIO - Priority of messages sent to the CS4344
|
||||
* worker thread.
|
||||
* CONFIG_CS4344_BUFFER_SIZE - Preferred buffer size
|
||||
* CONFIG_CS4344_NUM_BUFFERS - Preferred number of buffers
|
||||
* CONFIG_CS4344_WORKER_STACKSIZE - Stack size to use when creating the the
|
||||
* CS4344 worker thread.
|
||||
* CONFIG_CS4344_REGDUMP - Enable logic to dump all CS4344 registers to
|
||||
* the SYSLOG device.
|
||||
*/
|
||||
|
||||
/* Pre-requisites */
|
||||
|
||||
#ifndef CONFIG_AUDIO
|
||||
# error CONFIG_AUDIO is required for audio subsystem support
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_I2S
|
||||
# error CONFIG_I2S is required by the CS4344 driver
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SCHED_WORKQUEUE
|
||||
# error CONFIG_SCHED_WORKQUEUE is required by the CS4344 driver
|
||||
#endif
|
||||
|
||||
/* Default configuration values */
|
||||
|
||||
#ifndef CONFIG_CS4344_INFLIGHT
|
||||
# define CONFIG_CS4344_INFLIGHT 2
|
||||
#endif
|
||||
|
||||
#if CONFIG_CS4344_INFLIGHT > 255
|
||||
# error CONFIG_CS4344_INFLIGHT must fit in a uint8_t
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_CS4344_MSG_PRIO
|
||||
# define CONFIG_CS4344_MSG_PRIO 1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_CS4344_BUFFER_SIZE
|
||||
# define CONFIG_CS4344_BUFFER_SIZE 8192
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_CS4344_NUM_BUFFERS
|
||||
# define CONFIG_CS4344_NUM_BUFFERS 4
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_CS4344_WORKER_STACKSIZE
|
||||
# define CONFIG_CS4344_WORKER_STACKSIZE 768
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cs4344_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the CS4344 device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* i2s - An I2S driver instance
|
||||
* lower - Persistent board configuration data
|
||||
*
|
||||
* Returned Value:
|
||||
* A new lower half audio interface for the CS4344 device is returned on
|
||||
* success; NULL is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct i2s_dev_s; /* Forward reference. Defined in include/nuttx/audio/i2s.h */
|
||||
struct audio_lowerhalf_s; /* Forward reference. Defined in nuttx/audio/audio.h */
|
||||
|
||||
FAR struct audio_lowerhalf_s * cs4344_initialize(FAR struct i2s_dev_s *i2s);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_AUDIO_CS4344 */
|
||||
#endif /* __INCLUDE_NUTTX_AUDIO_CS4344_H */
|
||||
@@ -0,0 +1,265 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/audio/cs43l22.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_AUDIO_CS43L22_H
|
||||
#define __INCLUDE_NUTTX_AUDIO_CS43L22_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#ifdef CONFIG_AUDIO_CS43L22
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************
|
||||
*
|
||||
* CONFIG_AUDIO_CS43L22 - Enables CS43L22 support
|
||||
* CONFIG_CS43L22_INITVOLUME - The initial volume level
|
||||
* in the range {0..1000}
|
||||
* CONFIG_CS43L22_INFLIGHT - Maximum number of buffers that the CS43L22
|
||||
* driver will send to the I2S driver before any have completed.
|
||||
* CONFIG_CS43L22_MSG_PRIO - Priority of messages sent to the CS43L22
|
||||
* worker thread.
|
||||
* CONFIG_CS43L22_BUFFER_SIZE - Preferred buffer size
|
||||
* CONFIG_CS43L22_NUM_BUFFERS - Preferred number of buffers
|
||||
* CONFIG_CS43L22_WORKER_STACKSIZE - Stack size to use when creating the the
|
||||
* CS43L22 worker thread.
|
||||
* CONFIG_CS43L22_REGDUMP - Enable logic to dump all CS43L22 registers to
|
||||
* the SYSLOG device.
|
||||
*/
|
||||
|
||||
/* Pre-requisites */
|
||||
|
||||
#ifndef CONFIG_AUDIO
|
||||
# error CONFIG_AUDIO is required for audio subsystem support
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_I2S
|
||||
# error CONFIG_I2S is required by the CS43L22 driver
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_I2C
|
||||
# error CONFIG_I2C is required by the CS43L22 driver
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SCHED_WORKQUEUE
|
||||
# error CONFIG_SCHED_WORKQUEUE is required by the CS43L22 driver
|
||||
#endif
|
||||
|
||||
/* Default configuration values */
|
||||
|
||||
#ifndef CONFIG_CS43L22_INITVOLUME
|
||||
# define CONFIG_CS43L22_INITVOLUME 400
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_CS43L22_INFLIGHT
|
||||
# define CONFIG_CS43L22_INFLIGHT 2
|
||||
#endif
|
||||
|
||||
#if CONFIG_CS43L22_INFLIGHT > 255
|
||||
# error CONFIG_CS43L22_INFLIGHT must fit in a uint8_t
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_CS43L22_MSG_PRIO
|
||||
# define CONFIG_CS43L22_MSG_PRIO 1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_CS43L22_BUFFER_SIZE
|
||||
# define CONFIG_CS43L22_BUFFER_SIZE 8192
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_CS43L22_NUM_BUFFERS
|
||||
# define CONFIG_CS43L22_NUM_BUFFERS 4
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_CS43L22_WORKER_STACKSIZE
|
||||
# define CONFIG_CS43L22_WORKER_STACKSIZE 768
|
||||
#endif
|
||||
|
||||
/* Helper macros ************************************************************/
|
||||
|
||||
#define CS43L22_ATTACH(s,isr,arg) ((s)->attach(s,isr,arg))
|
||||
#define CS43L22_DETACH(s) ((s)->attach(s,NULL,NULL))
|
||||
#define CS43L22_ENABLE(s) ((s)->enable(s,true))
|
||||
#define CS43L22_DISABLE(s) ((s)->enable(s,false))
|
||||
#define CS43L22_RESTORE(s,e) ((s)->enable(s,e))
|
||||
#define CS43L22_HW_RESET(s) ((s)->reset(s))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This is the type of the CS43L22 interrupt handler. The lower level code
|
||||
* will intercept the interrupt and provide the upper level with the private
|
||||
* data that was provided when the interrupt was attached.
|
||||
*/
|
||||
|
||||
struct cs43l22_lower_s; /* Forward reference. Defined below */
|
||||
|
||||
typedef CODE int (*cs43l22_handler_t)
|
||||
(FAR const struct cs43l22_lower_s *lower,
|
||||
FAR void *arg);
|
||||
|
||||
/* A reference to a structure of this type must be passed to the CS43L22
|
||||
* driver. This structure provides information about the configuration
|
||||
* of the CS43L22 and provides some board-specific hooks.
|
||||
*
|
||||
* Memory for this structure is provided by the caller. It is not copied
|
||||
* by the driver and is presumed to persist while the driver is active.
|
||||
*/
|
||||
|
||||
struct cs43l22_lower_s
|
||||
{
|
||||
/* I2C characterization */
|
||||
|
||||
uint32_t frequency; /* Initial I2C frequency */
|
||||
uint8_t address; /* 7-bit I2C address (only bits 0-6 used) */
|
||||
|
||||
/* Clocking is provided via MCLK. The CS43L22 driver will need to know
|
||||
* the frequency of MCLK in order to generate the correct bitrates.
|
||||
*/
|
||||
|
||||
uint32_t mclk; /* CS43L22 Master clock frequency */
|
||||
|
||||
/* IRQ/GPIO access callbacks. These operations all hidden behind
|
||||
* callbacks to isolate the CS43L22 driver from differences in GPIO
|
||||
* interrupt handling by varying boards and MCUs. If possible,
|
||||
* interrupts should be configured on both rising and falling edges
|
||||
* so that contact and loss-of-contact events can be detected.
|
||||
*
|
||||
* attach - Attach or detach the CS43L22 interrupt handler to the GPIO
|
||||
* interrupt
|
||||
* enable - Enable or disable the GPIO interrupt. Returns the
|
||||
* previous interrupt state.
|
||||
* reset - HW reset of the CS43L22 chip
|
||||
*/
|
||||
|
||||
CODE int (*attach)(FAR const struct cs43l22_lower_s *lower,
|
||||
cs43l22_handler_t isr, FAR void *arg);
|
||||
CODE bool (*enable)(FAR const struct cs43l22_lower_s *lower, bool enable);
|
||||
CODE void (*reset)(FAR const struct cs43l22_lower_s *lower);
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cs43l22_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the CS43L22 device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* i2c - An I2C driver instance
|
||||
* i2s - An I2S driver instance
|
||||
* lower - Persistent board configuration data
|
||||
*
|
||||
* Returned Value:
|
||||
* A new lower half audio interface for the CS43L22 device is returned on
|
||||
* success; NULL is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct i2c_master_s; /* Forward reference. Defined in include/nuttx/i2c/i2c_master.h */
|
||||
struct i2s_dev_s; /* Forward reference. Defined in include/nuttx/audio/i2s.h */
|
||||
struct audio_lowerhalf_s; /* Forward reference. Defined in nuttx/audio/audio.h */
|
||||
|
||||
FAR struct audio_lowerhalf_s *
|
||||
cs43l22_initialize(FAR struct i2c_master_s *i2c, FAR struct i2s_dev_s *i2s,
|
||||
FAR const struct cs43l22_lower_s *lower);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cs43l22_dump_registers
|
||||
*
|
||||
* Description:
|
||||
* Dump the contents of all CS43L22 registers to the syslog device
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - The device instance returned by cs43l22_initialize
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_CS43L22_REGDUMP
|
||||
void cs43l22_dump_registers(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR const char *msg);
|
||||
#else
|
||||
/* This eliminates the need for any conditional compilation in the
|
||||
* including file.
|
||||
*/
|
||||
|
||||
# define cs43l22_dump_registers(d,m)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cs43l22_clock_analysis
|
||||
*
|
||||
* Description:
|
||||
* Analyze the settings in the clock chain and dump to syslog.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - The device instance returned by cs43l22_initialize
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_CS43L22_CLKDEBUG
|
||||
void cs43l22_clock_analysis(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR const char *msg);
|
||||
#else
|
||||
/* This eliminates the need for any conditional compilation in the
|
||||
* including file.
|
||||
*/
|
||||
|
||||
# define cs43l22_clock_analysis(d,m)
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_AUDIO_CS43L22 */
|
||||
#endif /* __INCLUDE_NUTTX_AUDIO_CS43L22_H */
|
||||
@@ -0,0 +1,71 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/audio/cxd56.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_AUDIO_CXD56_H
|
||||
#define __INCLUDE_NUTTX_AUDIO_CXD56_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#if defined(CONFIG_AUDIO_CXD56) || defined(CONFIG_CXD56_AUDIO)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct cxd56_lower_s
|
||||
{
|
||||
int dma_handle;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
struct audio_lowerhalf_s;
|
||||
|
||||
FAR struct audio_lowerhalf_s *
|
||||
cxd56_initialize(FAR const struct cxd56_lower_s *lower);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_CXD56_AUDIO */
|
||||
#endif /* __INCLUDE_NUTTX_AUDIO_CXD56_H */
|
||||
@@ -0,0 +1,353 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/audio/i2s.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_AUDIO_I2S_H
|
||||
#define __INCLUDE_NUTTX_AUDIO_I2S_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/audio/audio.h>
|
||||
|
||||
#ifdef CONFIG_I2S
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Access macros ************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: I2S_RXCHANNELS
|
||||
*
|
||||
* Description:
|
||||
* Set the I2S RX channel num. NOTE: This may also have unexpected side-
|
||||
* effects of the RX channel num is coupled with the TX channel num.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* channel - The I2S channel num
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define I2S_RXCHANNELS(d,c) \
|
||||
((d)->ops->i2s_rxchannels ? (d)->ops->i2s_rxchannels(d,c) : -ENOTTY)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: I2S_RXSAMPLERATE
|
||||
*
|
||||
* Description:
|
||||
* Set the I2S RX sample rate. NOTE: This will have no effect if (1) the
|
||||
* driver does not support an I2S receiver or if (2) the sample rate is
|
||||
* driven by the I2S frame clock. This may also have unexpected side-
|
||||
* effects of the RX sample is coupled with the TX sample rate.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* rate - The I2S sample rate in samples (not bits) per second
|
||||
*
|
||||
* Returned Value:
|
||||
* Returns the resulting bitrate
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define I2S_RXSAMPLERATE(d,r) \
|
||||
((d)->ops->i2s_rxsamplerate ? (d)->ops->i2s_rxsamplerate(d,r) : -ENOTTY)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: I2S_RXDATAWIDTH
|
||||
*
|
||||
* Description:
|
||||
* Set the I2S RX data width. The RX bitrate is determined by
|
||||
* sample_rate * data_width.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* width - The I2S data with in bits.
|
||||
*
|
||||
* Returned Value:
|
||||
* Returns the resulting bitrate
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define I2S_RXDATAWIDTH(d,b) \
|
||||
((d)->ops->i2s_rxdatawidth ? (d)->ops->i2s_rxdatawidth(d,b) : -ENOTTY)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: I2S_RECEIVE
|
||||
*
|
||||
* Description:
|
||||
* Receive a block of data from I2S.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* apb - A pointer to the audio buffer in which to receive data
|
||||
* callback - A user provided callback function that will be called at
|
||||
* the completion of the transfer. The callback will be
|
||||
* performed in the context of the worker thread.
|
||||
* arg - An opaque argument that will be provided to the callback
|
||||
* when the transfer complete.
|
||||
* timeout - The timeout value to use. The transfer will be canceled
|
||||
* and an ETIMEDOUT error will be reported if this timeout
|
||||
* elapsed without completion of the DMA transfer. Units
|
||||
* are system clock ticks. Zero means no timeout.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; a negated errno value on failure. NOTE: This function
|
||||
* only enqueues the transfer and returns immediately. Success here only
|
||||
* means that the transfer was enqueued correctly.
|
||||
*
|
||||
* When the transfer is complete, a 'result' value will be provided as
|
||||
* an argument to the callback function that will indicate if the transfer
|
||||
* failed.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define I2S_RECEIVE(d,b,c,a,t) \
|
||||
((d)->ops->i2s_receive ? (d)->ops->i2s_receive(d,b,c,a,t) : -ENOTTY)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: I2S_RXCHANNELS
|
||||
*
|
||||
* Description:
|
||||
* Set the I2S TX channel num. NOTE: This may also have unexpected side-
|
||||
* effects of the TX channel num is coupled with the RX channel num.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* channel - The I2S channel num
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define I2S_TXCHANNELS(d,c) \
|
||||
((d)->ops->i2s_txchannels ? (d)->ops->i2s_txchannels(d,c) : -ENOTTY)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: I2S_TXSAMPLERATE
|
||||
*
|
||||
* Description:
|
||||
* Set the I2S TX sample rate. NOTE: This will have no effect if (1) the
|
||||
* driver does not support an I2S transmitter or if (2) the sample rate is
|
||||
* driven by the I2S frame clock. This may also have unexpected side-
|
||||
* effects of the TX sample is coupled with the RX sample rate.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* rate - The I2S sample rate in samples (not bits) per second
|
||||
*
|
||||
* Returned Value:
|
||||
* Returns the resulting bitrate
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define I2S_TXSAMPLERATE(d,r) \
|
||||
((d)->ops->i2s_txsamplerate ? (d)->ops->i2s_txsamplerate(d,r) : -ENOTTY)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: I2S_TXDATAWIDTH
|
||||
*
|
||||
* Description:
|
||||
* Set the I2S TX data width. The TX bitrate is determined by
|
||||
* sample_rate * data_width.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* width - The I2S data with in bits.
|
||||
*
|
||||
* Returned Value:
|
||||
* Returns the resulting bitrate
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define I2S_TXDATAWIDTH(d,b) \
|
||||
((d)->ops->i2s_txdatawidth ? (d)->ops->i2s_txdatawidth(d,b) : -ENOTTY)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: I2S_SEND
|
||||
*
|
||||
* Description:
|
||||
* Send a block of data on I2S.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* apb - A pointer to the audio buffer from which to send data
|
||||
* callback - A user provided callback function that will be called at
|
||||
* the completion of the transfer. The callback will be
|
||||
* performed in the context of the worker thread.
|
||||
* arg - An opaque argument that will be provided to the callback
|
||||
* when the transfer completes.
|
||||
* timeout - The timeout value to use. The transfer will be cancelled
|
||||
* and an ETIMEDOUT error will be reported if this timeout
|
||||
* elapsed without completion of the DMA transfer. Units
|
||||
* are system clock ticks. Zero means no timeout.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; a negated errno value on failure. NOTE: This function
|
||||
* only enqueues the transfer and returns immediately. Success here only
|
||||
* means that the transfer was enqueued correctly.
|
||||
*
|
||||
* When the transfer is complete, a 'result' value will be provided as
|
||||
* an argument to the callback function that will indicate if the transfer
|
||||
* failed.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define I2S_SEND(d,b,c,a,t) \
|
||||
((d)->ops->i2s_send ? (d)->ops->i2s_send(d,b,c,a,t) : -ENOTTY)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: I2S_IOCTL
|
||||
*
|
||||
* Description:
|
||||
* IOCTL of I2S.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* cmd - A pointer to the audio buffer from which to send data
|
||||
* arg - An opaque argument that will be provided to the callback
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define I2S_IOCTL(d,c,a) \
|
||||
((d)->ops->i2s_ioctl ? (d)->ops->i2s_ioctl(d,c,a) : -ENOTTY)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Transfer complete callbacks */
|
||||
|
||||
struct i2s_dev_s;
|
||||
typedef CODE void (*i2s_callback_t)(FAR struct i2s_dev_s *dev,
|
||||
FAR struct ap_buffer_s *apb, FAR void *arg, int result);
|
||||
|
||||
/* The I2S vtable */
|
||||
|
||||
struct i2s_ops_s
|
||||
{
|
||||
/* Receiver methods */
|
||||
|
||||
CODE int (*i2s_rxchannels)(FAR struct i2s_dev_s *dev,
|
||||
uint8_t channels);
|
||||
CODE uint32_t (*i2s_rxsamplerate)(FAR struct i2s_dev_s *dev,
|
||||
uint32_t rate);
|
||||
CODE uint32_t (*i2s_rxdatawidth)(FAR struct i2s_dev_s *dev,
|
||||
int bits);
|
||||
CODE int (*i2s_receive)(FAR struct i2s_dev_s *dev,
|
||||
FAR struct ap_buffer_s *apb,
|
||||
i2s_callback_t callback,
|
||||
FAR void *arg,
|
||||
uint32_t timeout);
|
||||
|
||||
/* Transmitter methods */
|
||||
|
||||
CODE int (*i2s_txchannels)(FAR struct i2s_dev_s *dev,
|
||||
uint8_t channels);
|
||||
CODE uint32_t (*i2s_txsamplerate)(FAR struct i2s_dev_s *dev,
|
||||
uint32_t rate);
|
||||
CODE uint32_t (*i2s_txdatawidth)(FAR struct i2s_dev_s *dev,
|
||||
int bits);
|
||||
CODE int (*i2s_send)(FAR struct i2s_dev_s *dev,
|
||||
FAR struct ap_buffer_s *apb,
|
||||
i2s_callback_t callback,
|
||||
FAR void *arg,
|
||||
uint32_t timeout);
|
||||
|
||||
/* Ioctl */
|
||||
|
||||
CODE int (*i2s_ioctl)(FAR struct i2s_dev_s *dev,
|
||||
int cmd, unsigned long arg);
|
||||
};
|
||||
|
||||
/* I2S private data. This structure only defines the initial fields of the
|
||||
* structure visible to the I2S client. The specific implementation may
|
||||
* add additional, device specific fields
|
||||
*/
|
||||
|
||||
struct i2s_dev_s
|
||||
{
|
||||
FAR const struct i2s_ops_s *ops;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2schar_register
|
||||
*
|
||||
* Description:
|
||||
* Create and register the I2S character driver.
|
||||
*
|
||||
* The I2S character driver is a simple character driver that supports I2S
|
||||
* transfers via a read() and write(). The intent of this driver is to
|
||||
* support I2S testing. It is not an audio driver but does conform to some
|
||||
* of the buffer management heuristics of an audio driver. It is not
|
||||
* suitable for use in any real driver application in its current form.
|
||||
*
|
||||
* Input Parameters:
|
||||
* i2s - An instance of the lower half I2S driver
|
||||
* minor - The device minor number. The I2S character device will be
|
||||
* registers as /dev/i2scharN where N is the minor number
|
||||
*
|
||||
* Returned Value:
|
||||
* OK if the driver was successfully register; A negated errno value is
|
||||
* returned on any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int i2schar_register(FAR struct i2s_dev_s *i2s, int minor);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_I2S */
|
||||
#endif /* __INCLUDE_NUTTX_AUDIO_I2S_H */
|
||||
@@ -0,0 +1,154 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/audio/pcm.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_AUDIO_PCM_H
|
||||
#define __INCLUDE_NUTTX_AUDIO_PCM_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#ifdef CONFIG_AUDIO_FORMAT_PCM
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************
|
||||
*
|
||||
* CONFIG_AUDIO_FORMAT_PCM - Enabled PCM support
|
||||
*/
|
||||
|
||||
/* Pre-requisites */
|
||||
|
||||
#ifndef CONFIG_AUDIO
|
||||
# error CONFIG_AUDIO is required for PCM support
|
||||
#endif
|
||||
|
||||
/* Default configuration values */
|
||||
|
||||
/* WAVE Header Definitions **************************************************/
|
||||
|
||||
/* All values are little 32-bit or 16-bit endian */
|
||||
|
||||
#define WAV_HDR_CHUNKID 0x46464952 /* "RIFF" */
|
||||
#define WAV_HDR_FORMAT 0x45564157 /* "WAVE" */
|
||||
#define WAV_FMT_CHUNKID 0x20746d66 /* "fmt " */
|
||||
#define WAV_FMT_CHUNKLEN 16 /* Size of a PCM subchunk */
|
||||
#define WAV_FMT_FORMAT 1 /* Linear quantization */
|
||||
#define WAV_FMT_MONO 1 /* nchannels=1 */
|
||||
#define WAV_FMT_STEREO 2 /* nchannels=2 */
|
||||
#define WAV_DATA_CHUNKID 0x61746164 /* "data" */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* The standard WAV header consist of three chunks
|
||||
*
|
||||
* 1. A WAV header chunk,
|
||||
* 2. A format chunk, and
|
||||
* 3. A data chunk.
|
||||
*/
|
||||
|
||||
struct wav_hdrchunk_s
|
||||
{
|
||||
uint32_t chunkid; /* Contains the letters "RIFF" in ASCII form. */
|
||||
uint32_t chunklen; /* Size of the rest of the following chunk */
|
||||
uint32_t format; /* Contains the letters "WAVE" */
|
||||
};
|
||||
|
||||
struct wav_formatchunk_s
|
||||
{
|
||||
uint32_t chunkid; /* Contains the letters "fmt " */
|
||||
uint32_t chunklen; /* Size of the following chunk (16 for PCM) */
|
||||
uint16_t format; /* PCM=1 (i.e. Linear quantization) */
|
||||
uint16_t nchannels; /* Mono=1, Stereo=2 */
|
||||
uint32_t samprate; /* 8000, 44100, ... */
|
||||
uint32_t byterate; /* samprate * nchannels * bpsamp / 8 */
|
||||
uint16_t align; /* nchannels * bpsamp / 8 */
|
||||
uint16_t bpsamp; /* Bits per sample: 8 bits = 8, 16 bits = 16 */
|
||||
};
|
||||
|
||||
struct wav_datachunk_s
|
||||
{
|
||||
uint32_t chunkid; /* Contains the letters "data" */
|
||||
uint32_t chunklen; /* Number of bytes in the data */
|
||||
};
|
||||
|
||||
/* The standard WAV file header format is then these three chunks */
|
||||
|
||||
struct wav_header_s
|
||||
{
|
||||
struct wav_hdrchunk_s hdr;
|
||||
struct wav_formatchunk_s fmt;
|
||||
struct wav_datachunk_s data;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pcm_decode_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the PCM device. The PCM device accepts and contains a
|
||||
* low-level audio DAC-type device. It then returns a new audio lower
|
||||
* half interface at adds a PCM decoding from end to the low-level
|
||||
* audio device
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - A reference to the low-level audio DAC-type device to contain.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, a new audio device instance is returned that wraps the
|
||||
* low-level device and provides a PCM decoding front end. NULL is
|
||||
* returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct audio_lowerhalf_s *
|
||||
pcm_decode_initialize(FAR struct audio_lowerhalf_s *dev);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_AUDIO_FORMAT_PCM */
|
||||
#endif /* __INCLUDE_NUTTX_AUDIO_PCM_H */
|
||||
@@ -0,0 +1,88 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/audio/tone.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_AUDIO_TONE_H
|
||||
#define __INCLUDE_NUTTX_AUDIO_TONE_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <fixedmath.h>
|
||||
|
||||
#include <nuttx/timers/pwm.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
|
||||
#ifdef CONFIG_AUDIO_TONE
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: tone_register
|
||||
*
|
||||
* Description:
|
||||
* This function binds an instance of a "lower half" PWM driver with
|
||||
* the "upper half" Audio Tone device and registers that device so that can
|
||||
* be used by application code.
|
||||
*
|
||||
*
|
||||
* Input Parameters:
|
||||
* path - The full path to the driver to be registers in the NuttX pseudo-
|
||||
* filesystem. The recommended convention is to name all PWM drivers
|
||||
* as "/dev/tone0", "/dev/tone1", etc. where the driver path
|
||||
* differs only in the "minor" number at the end of the device name.
|
||||
* channel - The the PWM peripheral supports multiple output channels, then
|
||||
* this value must be provided to indicate the output channel that drives
|
||||
* the tone.
|
||||
* tone - A pointer to an instance of lower half PWM driver tone. This
|
||||
* instance will be bound to the Audio Tone driver and must persists as
|
||||
* long as that driver persists.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int tone_register(FAR const char *path, FAR struct pwm_lowerhalf_s *tone,
|
||||
#ifdef CONFIG_PWM_MULTICHAN
|
||||
int channel,
|
||||
#endif
|
||||
FAR struct oneshot_lowerhalf_s *oneshot);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_AUDIO_TONE */
|
||||
#endif /* __INCLUDE_NUTTX_AUDIO_TONE_H */
|
||||
@@ -0,0 +1,127 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/audio/vs1053.h
|
||||
*
|
||||
* Copyright (C) 2013 Ken Pettit. All rights reserved.
|
||||
* Author: Ken Pettit <pettitkd@gmail.com>
|
||||
*
|
||||
* 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 __INCLUDE_NUTTX_AUDIO_VS1053_H
|
||||
#define __INCLUDE_NUTTX_AUDIO_VS1053_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* VS1053 Configuration Settings:
|
||||
*
|
||||
* CONFIG_AUDIO_VS1053 - Enabled VS1053 support
|
||||
* CONFIG_VS1053_SPIMODE - Controls the SPI mode
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* The VS1053 provides Data Request (DREQ) interrupts to the MCU via a GPIO
|
||||
* pin and also has a chip reset GPIO. The following structure provides an
|
||||
* MCU-independent mechanism for controlling the VS1053 GPIOs.
|
||||
*/
|
||||
|
||||
struct vs1053_lower_s
|
||||
{
|
||||
int (*attach)(FAR const struct vs1053_lower_s *lower, xcpt_t handler,
|
||||
FAR void *arg);
|
||||
void (*enable)(FAR const struct vs1053_lower_s *lower);
|
||||
void (*disable)(FAR const struct vs1053_lower_s *lower);
|
||||
void (*reset)(FAR const struct vs1053_lower_s *lower, bool state);
|
||||
int (*read_dreq)(FAR const struct vs1053_lower_s *lower);
|
||||
int irq;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: vs1053_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the VS1053 driver. This will perform a chip reset of the
|
||||
* device as part of initialization.
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - A reference to the platform's SPI driver for the VS1053
|
||||
* lower - The MCU-specific interrupt used to control low-level MCU
|
||||
* functions (i.e., VS1053 GPIO interrupts).
|
||||
* devno - If more than one VS1053 is supported, then this is the
|
||||
* zero based number that identifies the VS1053;
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct spi_dev_s; /* See nuttx/spi/spi.h */
|
||||
struct audio_lowerhalf_s; /* See nuttx/audio/audio.h */
|
||||
|
||||
FAR struct audio_lowerhalf_s *vs1053_initialize(FAR struct spi_dev_s *spi,
|
||||
FAR const struct vs1053_lower_s *lower,
|
||||
unsigned int devno);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_AUDIO_VS1053_H */
|
||||
@@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/audio/wm8776.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_AUDIO_WM8776_H
|
||||
#define __INCLUDE_NUTTX_AUDIO_WM8776_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#ifdef CONFIG_AUDIO_WM8776
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct wm8776_lower_s;
|
||||
|
||||
struct wm8776_lower_s
|
||||
{
|
||||
/* I2C characterization */
|
||||
|
||||
uint32_t frequency; /* Initial I2C frequency */
|
||||
uint8_t address; /* 7-bit I2C address (only bits 0-6 used) */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
struct i2c_master_s;
|
||||
struct i2s_dev_s;
|
||||
struct audio_lowerhalf_s;
|
||||
|
||||
FAR struct audio_lowerhalf_s *
|
||||
wm8776_initialize(FAR struct i2c_master_s *i2c,
|
||||
FAR struct i2s_dev_s *i2s,
|
||||
FAR const struct wm8776_lower_s *lower);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_AUDIO_WM8776 */
|
||||
#endif /* __INCLUDE_NUTTX_AUDIO_WM8776_H */
|
||||
@@ -0,0 +1,260 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/audio/wm8904.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_AUDIO_WM8904_H
|
||||
#define __INCLUDE_NUTTX_AUDIO_WM8904_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#ifdef CONFIG_AUDIO_WM8904
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************
|
||||
*
|
||||
* CONFIG_AUDIO_WM8904 - Enables WM8904 support
|
||||
* CONFIG_WM8904_INITVOLUME - The initial volume level in the range {0..1000}
|
||||
* CONFIG_WM8904_INFLIGHT - Maximum number of buffers that the WM8904 driver
|
||||
* will send to the I2S driver before any have completed.
|
||||
* CONFIG_WM8904_MSG_PRIO - Priority of messages sent to the WM8904 worker
|
||||
* thread.
|
||||
* CONFIG_WM8904_BUFFER_SIZE - Preferred buffer size
|
||||
* CONFIG_WM8904_NUM_BUFFERS - Preferred number of buffers
|
||||
* CONFIG_WM8904_WORKER_STACKSIZE - Stack size to use when creating the
|
||||
* WM8904 worker thread.
|
||||
* CONFIG_WM8904_REGDUMP - Enable logic to dump all WM8904 registers to
|
||||
* the SYSLOG device.
|
||||
*/
|
||||
|
||||
/* Pre-requisites */
|
||||
|
||||
#ifndef CONFIG_AUDIO
|
||||
# error CONFIG_AUDIO is required for audio subsystem support
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_I2S
|
||||
# error CONFIG_I2S is required by the WM8904 driver
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_I2C
|
||||
# error CONFIG_I2C is required by the WM8904 driver
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SCHED_WORKQUEUE
|
||||
# error CONFIG_SCHED_WORKQUEUE is required by the WM8904 driver
|
||||
#endif
|
||||
|
||||
/* Default configuration values */
|
||||
|
||||
#ifndef CONFIG_WM8904_INITVOLUME
|
||||
# define CONFIG_WM8904_INITVOLUME 250
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_WM8904_INFLIGHT
|
||||
# define CONFIG_WM8904_INFLIGHT 2
|
||||
#endif
|
||||
|
||||
#if CONFIG_WM8904_INFLIGHT > 255
|
||||
# error CONFIG_WM8904_INFLIGHT must fit in a uint8_t
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_WM8904_MSG_PRIO
|
||||
# define CONFIG_WM8904_MSG_PRIO 1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_WM8904_BUFFER_SIZE
|
||||
# define CONFIG_WM8904_BUFFER_SIZE 8192
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_WM8904_NUM_BUFFERS
|
||||
# define CONFIG_WM8904_NUM_BUFFERS 4
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_WM8904_WORKER_STACKSIZE
|
||||
# define CONFIG_WM8904_WORKER_STACKSIZE 768
|
||||
#endif
|
||||
|
||||
/* Helper macros ************************************************************/
|
||||
|
||||
#define WM8904_ATTACH(s,isr,arg) ((s)->attach(s,isr,arg))
|
||||
#define WM8904_DETACH(s) ((s)->attach(s,NULL,NULL))
|
||||
#define WM8904_ENABLE(s) ((s)->enable(s,true))
|
||||
#define WM8904_DISABLE(s) ((s)->enable(s,false))
|
||||
#define WM8904_RESTORE(s,e) ((s)->enable(s,e))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This is the type of the WM8904 interrupt handler. The lower level code
|
||||
* will intercept the interrupt and provide the upper level with the private
|
||||
* data that was provided when the interrupt was attached.
|
||||
*/
|
||||
|
||||
struct wm8904_lower_s; /* Forward reference. Defined below */
|
||||
|
||||
typedef CODE int (*wm8904_handler_t)(FAR const struct wm8904_lower_s *lower,
|
||||
FAR void *arg);
|
||||
|
||||
/* A reference to a structure of this type must be passed to the WM8904
|
||||
* driver. This structure provides information about the configuration
|
||||
* of the WM8904 and provides some board-specific hooks.
|
||||
*
|
||||
* Memory for this structure is provided by the caller. It is not copied
|
||||
* by the driver and is presumed to persist while the driver is active.
|
||||
*/
|
||||
|
||||
struct wm8904_lower_s
|
||||
{
|
||||
/* I2C characterization */
|
||||
|
||||
uint32_t frequency; /* Initial I2C frequency */
|
||||
uint8_t address; /* 7-bit I2C address (only bits 0-6 used) */
|
||||
|
||||
/* Clocking is provided via MCLK. The WM8904 driver will need to know
|
||||
* the frequency of MCLK in order to generate the correct bitrates.
|
||||
*/
|
||||
|
||||
uint32_t mclk; /* W8904 Master clock frequency */
|
||||
|
||||
/* IRQ/GPIO access callbacks. These operations all hidden behind
|
||||
* callbacks to isolate the WM8904 driver from differences in GPIO
|
||||
* interrupt handling by varying boards and MCUs. If possible,
|
||||
* interrupts should be configured on both rising and falling edges
|
||||
* so that contact and loss-of-contact events can be detected.
|
||||
*
|
||||
* attach - Attach or detach the WM8904 interrupt handler to the GPIO
|
||||
* interrupt
|
||||
* enable - Enable or disable the GPIO interrupt. Returns the
|
||||
* previous interrupt state.
|
||||
*/
|
||||
|
||||
CODE int (*attach)(FAR const struct wm8904_lower_s *lower,
|
||||
wm8904_handler_t isr, FAR void *arg);
|
||||
CODE bool (*enable)(FAR const struct wm8904_lower_s *lower, bool enable);
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wm8904_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the WM8904 device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* i2c - An I2C driver instance
|
||||
* i2s - An I2S driver instance
|
||||
* lower - Persistent board configuration data
|
||||
*
|
||||
* Returned Value:
|
||||
* A new lower half audio interface for the WM8904 device is returned on
|
||||
* success; NULL is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct i2c_master_s; /* Forward reference. Defined in include/nuttx/i2c/i2c_master.h */
|
||||
struct i2s_dev_s; /* Forward reference. Defined in include/nuttx/audio/i2s.h */
|
||||
struct audio_lowerhalf_s; /* Forward reference. Defined in nuttx/audio/audio.h */
|
||||
|
||||
FAR struct audio_lowerhalf_s *
|
||||
wm8904_initialize(FAR struct i2c_master_s *i2c, FAR struct i2s_dev_s *i2s,
|
||||
FAR const struct wm8904_lower_s *lower);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wm8904_dump_registers
|
||||
*
|
||||
* Description:
|
||||
* Dump the contents of all WM8904 registers to the syslog device
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - The device instance returned by wm8904_initialize
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_WM8904_REGDUMP
|
||||
void wm8904_dump_registers(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR const char *msg);
|
||||
#else
|
||||
/* This eliminates the need for any conditional compilation in the
|
||||
* including file.
|
||||
*/
|
||||
|
||||
# define wm8904_dump_registers(d,m)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wm8904_clock_analysis
|
||||
*
|
||||
* Description:
|
||||
* Analyze the settings in the clock chain and dump to syslog.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - The device instance returned by wm8904_initialize
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_WM8904_CLKDEBUG
|
||||
void wm8904_clock_analysis(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR const char *msg);
|
||||
#else
|
||||
/* This eliminates the need for any conditional compilation in the
|
||||
* including file.
|
||||
*/
|
||||
|
||||
# define wm8904_clock_analysis(d,m)
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_AUDIO_WM8904 */
|
||||
#endif /* __INCLUDE_NUTTX_AUDIO_WM8904_H */
|
||||
@@ -0,0 +1,260 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/audio/wm8994.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_AUDIO_WM8994_H
|
||||
#define __INCLUDE_NUTTX_AUDIO_WM8994_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#ifdef CONFIG_AUDIO_WM8994
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************
|
||||
*
|
||||
* CONFIG_AUDIO_WM8994 - Enables WM8994 support
|
||||
* CONFIG_WM8994_INITVOLUME - The initial volume level in the range {0..1000}
|
||||
* CONFIG_WM8994_INFLIGHT - Maximum number of buffers that the WM8994 driver
|
||||
* will send to the I2S driver before any have completed.
|
||||
* CONFIG_WM8994_MSG_PRIO - Priority of messages sent to the WM8994 worker
|
||||
* thread.
|
||||
* CONFIG_WM8994_BUFFER_SIZE - Preferred buffer size
|
||||
* CONFIG_WM8994_NUM_BUFFERS - Preferred number of buffers
|
||||
* CONFIG_WM8994_WORKER_STACKSIZE - Stack size to use when creating the
|
||||
* WM8994 worker thread.
|
||||
* CONFIG_WM8994_REGDUMP - Enable logic to dump all WM8994 registers to
|
||||
* the SYSLOG device.
|
||||
*/
|
||||
|
||||
/* Pre-requisites */
|
||||
|
||||
#ifndef CONFIG_AUDIO
|
||||
# error CONFIG_AUDIO is required for audio subsystem support
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_I2S
|
||||
# error CONFIG_I2S is required by the WM8994 driver
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_I2C
|
||||
# error CONFIG_I2C is required by the WM8994 driver
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SCHED_WORKQUEUE
|
||||
# error CONFIG_SCHED_WORKQUEUE is required by the WM8994 driver
|
||||
#endif
|
||||
|
||||
/* Default configuration values */
|
||||
|
||||
#ifndef CONFIG_WM8994_INITVOLUME
|
||||
# define CONFIG_WM8994_INITVOLUME 250
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_WM8994_INFLIGHT
|
||||
# define CONFIG_WM8994_INFLIGHT 2
|
||||
#endif
|
||||
|
||||
#if CONFIG_WM8994_INFLIGHT > 255
|
||||
# error CONFIG_WM8994_INFLIGHT must fit in a uint8_t
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_WM8994_MSG_PRIO
|
||||
# define CONFIG_WM8994_MSG_PRIO 1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_WM8994_BUFFER_SIZE
|
||||
# define CONFIG_WM8994_BUFFER_SIZE 8192
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_WM8994_NUM_BUFFERS
|
||||
# define CONFIG_WM8994_NUM_BUFFERS 4
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_WM8994_WORKER_STACKSIZE
|
||||
# define CONFIG_WM8994_WORKER_STACKSIZE 768
|
||||
#endif
|
||||
|
||||
/* Helper macros ************************************************************/
|
||||
|
||||
#define WM8994_ATTACH(s,isr,arg) ((s)->attach(s,isr,arg))
|
||||
#define WM8994_DETACH(s) ((s)->attach(s,NULL,NULL))
|
||||
#define WM8994_ENABLE(s) ((s)->enable(s,true))
|
||||
#define WM8994_DISABLE(s) ((s)->enable(s,false))
|
||||
#define WM8994_RESTORE(s,e) ((s)->enable(s,e))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This is the type of the WM8994 interrupt handler. The lower level code
|
||||
* will intercept the interrupt and provide the upper level with the private
|
||||
* data that was provided when the interrupt was attached.
|
||||
*/
|
||||
|
||||
struct wm8994_lower_s; /* Forward reference. Defined below */
|
||||
|
||||
typedef CODE int (*wm8994_handler_t)(FAR const struct wm8994_lower_s *lower,
|
||||
FAR void *arg);
|
||||
|
||||
/* A reference to a structure of this type must be passed to the WM8994
|
||||
* driver. This structure provides information about the configuration
|
||||
* of the WM8994 and provides some board-specific hooks.
|
||||
*
|
||||
* Memory for this structure is provided by the caller. It is not copied
|
||||
* by the driver and is presumed to persist while the driver is active.
|
||||
*/
|
||||
|
||||
struct wm8994_lower_s
|
||||
{
|
||||
/* I2C characterization */
|
||||
|
||||
uint32_t frequency; /* Initial I2C frequency */
|
||||
uint8_t address; /* 7-bit I2C address (only bits 0-6 used) */
|
||||
|
||||
/* Clocking is provided via MCLK. The WM8994 driver will need to know
|
||||
* the frequency of MCLK in order to generate the correct bitrates.
|
||||
*/
|
||||
|
||||
uint32_t mclk; /* W8994 Master clock frequency */
|
||||
|
||||
/* IRQ/GPIO access callbacks. These operations all hidden behind
|
||||
* callbacks to isolate the WM8994 driver from differences in GPIO
|
||||
* interrupt handling by varying boards and MCUs. If possible,
|
||||
* interrupts should be configured on both rising and falling edges
|
||||
* so that contact and loss-of-contact events can be detected.
|
||||
*
|
||||
* attach - Attach or detach the WM8994 interrupt handler to the GPIO
|
||||
* interrupt
|
||||
* enable - Enable or disable the GPIO interrupt. Returns the
|
||||
* previous interrupt state.
|
||||
*/
|
||||
|
||||
CODE int (*attach)(FAR const struct wm8994_lower_s *lower,
|
||||
wm8994_handler_t isr, FAR void *arg);
|
||||
CODE bool (*enable)(FAR const struct wm8994_lower_s *lower, bool enable);
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wm8994_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the WM8994 device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* i2c - An I2C driver instance
|
||||
* i2s - An I2S driver instance
|
||||
* lower - Persistent board configuration data
|
||||
*
|
||||
* Returned Value:
|
||||
* A new lower half audio interface for the WM8994 device is returned on
|
||||
* success; NULL is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct i2c_master_s; /* Forward reference. Defined in include/nuttx/i2c/i2c_master.h */
|
||||
struct i2s_dev_s; /* Forward reference. Defined in include/nuttx/audio/i2s.h */
|
||||
struct audio_lowerhalf_s; /* Forward reference. Defined in nuttx/audio/audio.h */
|
||||
|
||||
FAR struct audio_lowerhalf_s *
|
||||
wm8994_initialize(FAR struct i2c_master_s *i2c, FAR struct i2s_dev_s *i2s,
|
||||
FAR const struct wm8994_lower_s *lower);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wm8994_dump_registers
|
||||
*
|
||||
* Description:
|
||||
* Dump the contents of all WM8994 registers to the syslog device
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - The device instance returned by wm8994_initialize
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_WM8994_REGDUMP
|
||||
void wm8994_dump_registers(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR const char *msg);
|
||||
#else
|
||||
/* This eliminates the need for any conditional compilation in the
|
||||
* including file.
|
||||
*/
|
||||
|
||||
# define wm8994_dump_registers(d,m)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wm8994_clock_analysis
|
||||
*
|
||||
* Description:
|
||||
* Analyze the settings in the clock chain and dump to syslog.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - The device instance returned by wm8994_initialize
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_WM8994_CLKDEBUG
|
||||
void wm8994_clock_analysis(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR const char *msg);
|
||||
#else
|
||||
/* This eliminates the need for any conditional compilation in the
|
||||
* including file.
|
||||
*/
|
||||
|
||||
# define wm8994_clock_analysis(d,m)
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_AUDIO_WM8994 */
|
||||
#endif /* __INCLUDE_NUTTX_AUDIO_WM8994_H */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user