Add nuttx to the system framework, which is 10.1.0

This commit is contained in:
TangYiwen123
2021-06-09 14:33:15 +08:00
parent 06c351e27c
commit 804bd57aa0
5000 changed files with 1488544 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config SYSTEM_NTPC
tristate "NTP Daemon Commands"
default n
select NETUTILS_NTPCLIENT
depends on NET_UDP
---help---
Enable the NTP client 'start' and 'stop' commands
if SYSTEM_NTPC
config SYSTEM_NTPC_PRIORITY
int "NTPC task priority"
default 100
config SYSTEM_NTPC_STACKSIZE
int "NTPC stack size"
default DEFAULT_TASK_STACKSIZE
endif
@@ -0,0 +1,39 @@
############################################################################
# apps/system/ntpc/Make.defs
# Adds selected applications to apps/ build
#
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
ifneq ($(CONFIG_SYSTEM_NTPC),)
CONFIGURED_APPS += $(APPDIR)/system/ntpc
endif
@@ -0,0 +1,49 @@
############################################################################
# apps/system/ntpc/Makefile
#
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
include $(APPDIR)/Make.defs
# NTPC address renewal built-in application info
PROGNAME = ntpcstart ntpcstop ntpcstatus
PRIORITY = $(CONFIG_SYSTEM_NTPC_PRIORITY)
STACKSIZE = $(CONFIG_SYSTEM_NTPC_STACKSIZE)
MODULE = $(CONFIG_SYSTEM_NTPC)
# NTPC address renewal
MAINSRC = ntpcstart_main.c ntpcstop_main.c ntpcstatus_main.c
include $(APPDIR)/Application.mk
@@ -0,0 +1,66 @@
/****************************************************************************
* system/ntpc/ntpcstart_main.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
#include <stdio.h>
#include "netutils/ntpclient.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* ntpcstart_main
****************************************************************************/
int main(int argc, FAR char *argv[])
{
int pid = ntpc_start();
if (pid < 0)
{
fprintf(stderr, "ERROR: ntpc_start() failed\n");
return EXIT_FAILURE;
}
printf("Started the NTP daemon as PID=%d\n", pid);
return EXIT_SUCCESS;
}
@@ -0,0 +1,125 @@
/****************************************************************************
* system/ntpc/ntpc_status.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <inttypes.h>
#ifdef CONFIG_LIBC_NETDB
#include <netdb.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include "netutils/ntpclient.h"
/****************************************************************************
* Private Functions
****************************************************************************/
/* "-", uint64_t, ".", 9 digits fraction part, NUL */
#define NTP_TIME_STR_MAX_LEN (1 + 21 + 1 + 9 + 1)
static void
format_ntptimestamp(int64_t ts, FAR char *buf)
{
FAR const char *sign;
uint64_t absts;
if (ts < 0)
{
sign = "-";
absts = -ts;
}
else
{
sign = "";
absts = ts;
}
sprintf(buf, "%s%" PRIu64 ".%09" PRIu64,
sign, absts >> 32,
((absts & 0xffffffff) * NSEC_PER_SEC) >> 32);
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* ntpcstatus_main
****************************************************************************/
int main(int argc, FAR char *argv[])
{
struct ntpc_status_s status;
unsigned int i;
int ret;
ret = ntpc_status(&status);
if (ret < 0)
{
fprintf(stderr, "ERROR: ntpc_status() failed\n");
return EXIT_FAILURE;
}
printf("The number of last samples: %u\n", status.nsamples);
for (i = 0; i < status.nsamples; i++)
{
FAR const struct sockaddr *sa;
socklen_t salen;
FAR const char *name = "<noname>";
char offset_buf[NTP_TIME_STR_MAX_LEN];
char delay_buf[NTP_TIME_STR_MAX_LEN];
sa = status.samples[i].srv_addr;
salen = (sa->sa_family == AF_INET) ? sizeof(struct sockaddr_in)
: sizeof(struct sockaddr_in6);
#ifdef CONFIG_LIBC_NETDB
char hbuf[NI_MAXHOST];
ret = getnameinfo(sa, salen,
hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST);
if (ret == 0)
{
name = hbuf;
}
else
{
fprintf(stderr, "WARNING: getnameinfo failed: %s\n",
gai_strerror(ret));
}
#endif
format_ntptimestamp(status.samples[i].offset, offset_buf);
format_ntptimestamp(status.samples[i].delay, delay_buf);
printf("[%u] srv %s offset %s delay %s\n",
i, name, offset_buf, delay_buf);
}
return EXIT_SUCCESS;
}
@@ -0,0 +1,66 @@
/****************************************************************************
* system/ntpc/ntpc_main.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
#include <stdio.h>
#include "netutils/ntpclient.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* ntpcstop_main
****************************************************************************/
int main(int argc, FAR char *argv[])
{
int ret = ntpc_stop();
if (ret < 0)
{
fprintf(stderr, "ERROR: ntpc_stop() failed\n");
return EXIT_FAILURE;
}
printf("Stopped the NTP daemon\n");
return EXIT_SUCCESS;
}