From 7bb26d26150d2540d97d6e8a146309866d278ad5 Mon Sep 17 00:00:00 2001 From: Mark Schulte Date: Fri, 7 Apr 2017 07:03:00 -0600 Subject: [PATCH 01/48] pthreads: Adding rwlock implementation Adding an implementation for read/write locks into the pthread library. These locks are writer priority, such that if any writers come in they are given priority for writing. --- include/pthread.h | 43 +++++++- libc/pthread/Make.defs | 4 + libc/pthread/pthread_rwlock.c | 127 ++++++++++++++++++++++++ libc/pthread/pthread_rwlock_rdlock.c | 143 +++++++++++++++++++++++++++ libc/pthread/pthread_rwlock_wrlock.c | 133 +++++++++++++++++++++++++ sched/Kconfig | 6 ++ 6 files changed, 454 insertions(+), 2 deletions(-) create mode 100644 libc/pthread/pthread_rwlock.c create mode 100644 libc/pthread/pthread_rwlock_rdlock.c create mode 100644 libc/pthread/pthread_rwlock_wrlock.c diff --git a/include/pthread.h b/include/pthread.h index af6ef51e23e..cfa054cfcac 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -337,6 +337,28 @@ typedef struct pthread_barrier_s pthread_barrier_t; typedef bool pthread_once_t; #define __PTHREAD_ONCE_T_DEFINED 1 +#ifdef CONFIG_PTHREAD_RWLOCK +struct pthread_rwlock_s +{ + pthread_mutex_t lock; + pthread_cond_t cv; + unsigned int num_readers; + unsigned int num_writers; +}; + +typedef struct pthread_rwlock_s pthread_rwlock_t; + +typedef int pthread_rwlockattr_t; + +#define PTHREAD_RWLOCK_INITIALIZER {PTHREAD_MUTEX_INITIALIZER, \ + PTHREAD_COND_INITIALIZER, \ + 0, 0} + +#define PTHREAD_MUTEX_INITIALIZER {NULL, SEM_INITIALIZER(1), -1, \ + __PTHREAD_MUTEX_DEFAULT_FLAGS, \ + PTHREAD_MUTEX_DEFAULT, 0} +#endif + #ifdef CONFIG_PTHREAD_CLEANUP /* This type describes the pthread cleanup callback (non-standard) */ @@ -539,8 +561,8 @@ int pthread_barrierattr_setpshared(FAR pthread_barrierattr_t *attr, int pthread_barrier_destroy(FAR pthread_barrier_t *barrier); int pthread_barrier_init(FAR pthread_barrier_t *barrier, - FAR const pthread_barrierattr_t *attr, - unsigned int count); + FAR const pthread_barrierattr_t *attr, + unsigned int count); int pthread_barrier_wait(FAR pthread_barrier_t *barrier); /* Pthread initialization */ @@ -548,6 +570,23 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier); int pthread_once(FAR pthread_once_t *once_control, CODE void (*init_routine)(void)); +/* Pthread rwlock */ + +#ifdef CONFIG_PTHREAD_RWLOCK +int pthread_rwlock_destroy(FAR pthread_rwlock_t *rw_lock); +int pthread_rwlock_init(FAR pthread_rwlock_t *rw_lock, + FAR const pthread_rwlockattr_t *attr); +int pthread_rwlock_rdlock(pthread_rwlock_t *lock); +int pthread_rwlock_timedrdlock(FAR pthread_rwlock_t *lock, + FAR const struct timespec *abstime); +int pthread_rwlock_tryrdlock(FAR pthread_rwlock_t *lock); +int pthread_rwlock_wrlock(FAR pthread_rwlock_t *lock); +int pthread_rwlock_timedwrlock(FAR pthread_rwlock_t *lock, + FAR const struct timespec *abstime); +int pthread_rwlock_trywrlock(FAR pthread_rwlock_t *lock); +int pthread_rwlock_unlock(FAR pthread_rwlock_t *lock); +#endif /* CONFIG_PTHREAD_RWLOCK */ + /* Pthread signal management APIs */ int pthread_kill(pthread_t thread, int sig); diff --git a/libc/pthread/Make.defs b/libc/pthread/Make.defs index b8be2927d2f..1f6cacb88e0 100644 --- a/libc/pthread/Make.defs +++ b/libc/pthread/Make.defs @@ -53,6 +53,10 @@ CSRCS += pthread_mutexattr_setrobust.c pthread_mutexattr_getrobust.c CSRCS += pthread_setcancelstate.c pthread_setcanceltype.c CSRCS += pthread_testcancel.c +ifeq ($(CONFIG_PTHREAD_RWLOCK),y) +CSRCS += pthread_rwlock.c pthread_rwlock_rdlock.c pthread_rwlock_wrlock.c +endif + ifeq ($(CONFIG_SMP),y) CSRCS += pthread_attr_getaffinity.c pthread_attr_setaffinity.c endif diff --git a/libc/pthread/pthread_rwlock.c b/libc/pthread/pthread_rwlock.c new file mode 100644 index 00000000000..3f902089b00 --- /dev/null +++ b/libc/pthread/pthread_rwlock.c @@ -0,0 +1,127 @@ +/**************************************************************************** + * libc/pthread/pthread_rwlock.c + * + * Copyright (C) 2017 Mark Schulte. All rights reserved. + * Author: Mark Schulte + * + * 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 + +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int pthread_rwlock_init(FAR pthread_rwlock_t *lock, + FAR const pthread_rwlockattr_t *attr) +{ + int err; + + if (attr != NULL) + { + return -ENOSYS; + } + + lock->num_readers = 0; + lock->num_writers = 0; + + err = pthread_cond_init(&lock->cv, NULL); + if (err != 0) + { + return err; + } + + err = pthread_mutex_init(&lock->lock, NULL); + if (err != 0) + { + pthread_cond_destroy(&lock->cv); + return err; + } + + return err; +} + +int pthread_rwlock_destroy(FAR pthread_rwlock_t *lock) +{ + int cond_err = pthread_cond_destroy(&lock->cv); + int mutex_err = pthread_mutex_destroy(&lock->lock); + + if (mutex_err) + { + return mutex_err; + } + + return cond_err; +} + +int pthread_rwlock_unlock(FAR pthread_rwlock_t *rw_lock) +{ + int err; + + err = pthread_mutex_lock(&rw_lock->lock); + if (err != 0) + { + return err; + } + + if (rw_lock->num_readers > 0) + { + rw_lock->num_readers--; + + if (rw_lock->num_readers == 0) + { + err = pthread_cond_broadcast(&rw_lock->cv); + } + } + else if (rw_lock->num_writers > 0) + { + rw_lock->num_writers--; + + err = pthread_cond_broadcast(&rw_lock->cv); + } + else + { + err = EINVAL; + } + + pthread_mutex_unlock(&rw_lock->lock); + return err; +} diff --git a/libc/pthread/pthread_rwlock_rdlock.c b/libc/pthread/pthread_rwlock_rdlock.c new file mode 100644 index 00000000000..6270d2bbe4e --- /dev/null +++ b/libc/pthread/pthread_rwlock_rdlock.c @@ -0,0 +1,143 @@ +/**************************************************************************** + * libc/pthread/pthread_rwlockread.c + * + * Copyright (C) 2017 Mark Schulte. All rights reserved. + * Author: Mark Schulte + * + * 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 + +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int tryrdlock(FAR pthread_rwlock_t *rw_lock) +{ + int err; + + if (rw_lock->num_writers > 0) + { + err = EBUSY; + } + else if (rw_lock->num_readers == UINT_MAX) + { + err = EAGAIN; + } + else + { + rw_lock->num_readers++; + err = OK; + } + + return err; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pthread_rwlock_rdlock + * + * Description: + * Locks a read/write lock for reading + * + * Parameters: + * None + * + * Return Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_rwlock_tryrdlock(FAR pthread_rwlock_t *rw_lock) +{ + int err = pthread_mutex_trylock(&rw_lock->lock); + + if (err != 0) + { + return err; + } + + err = tryrdlock(rw_lock); + + pthread_mutex_unlock(&rw_lock->lock); + return err; +} + +int pthread_rwlock_timedrdlock(FAR pthread_rwlock_t *rw_lock, + FAR const struct timespec *ts) +{ + int err = pthread_mutex_lock(&rw_lock->lock); + + if (err != 0) + { + return err; + } + + while ((err = tryrdlock(rw_lock)) == EBUSY) + { + if (ts != NULL) + { + err = pthread_cond_timedwait(&rw_lock->cv, &rw_lock->lock, ts); + } + else + { + err = pthread_cond_wait(&rw_lock->cv, &rw_lock->lock); + } + + if (err != 0) + { + break; + } + } + + pthread_mutex_unlock(&rw_lock->lock); + return err; +} + +int pthread_rwlock_rdlock(FAR pthread_rwlock_t * rw_lock) +{ + return pthread_rwlock_timedrdlock(rw_lock, NULL); +} diff --git a/libc/pthread/pthread_rwlock_wrlock.c b/libc/pthread/pthread_rwlock_wrlock.c new file mode 100644 index 00000000000..dc2d155021e --- /dev/null +++ b/libc/pthread/pthread_rwlock_wrlock.c @@ -0,0 +1,133 @@ +/**************************************************************************** + * libc/pthread/pthread_rwlockwrite.c + * + * Copyright (C) 2017 Mark Schulte. All rights reserved. + * Author: Mark Schulte + * + * 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 + +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pthread_rwlock_rdlock + * + * Description: + * Locks a read/write lock for reading + * + * Parameters: + * None + * + * Return Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_rwlock_trywrlock(FAR pthread_rwlock_t *rw_lock) +{ + int err = pthread_mutex_trylock(&rw_lock->lock); + + if (err != 0) + { + return err; + } + + if (rw_lock->num_readers > 0 || rw_lock->num_writers > 0) + { + err = EBUSY; + } + else + { + rw_lock->num_writers++; + } + + pthread_mutex_unlock(&rw_lock->lock); + return err; +} + +int pthread_rwlock_timedwrlock(FAR pthread_rwlock_t *rw_lock, + FAR const struct timespec *ts) +{ + int err = pthread_mutex_lock(&rw_lock->lock); + int num_writers_current; + + if (err != 0) + { + return err; + } + + num_writers_current = rw_lock->num_writers++; + if (num_writers_current == 0) + { + goto exit_with_mutex; + } + + while (rw_lock->num_writers != num_writers_current) + { + if (ts != NULL) + { + err = pthread_cond_timedwait(&rw_lock->cv, &rw_lock->lock, ts); + } + else + { + err = pthread_cond_wait(&rw_lock->cv, &rw_lock->lock); + } + + if (err != 0) + { + break; + } + } + +exit_with_mutex: + pthread_mutex_unlock(&rw_lock->lock); + return err; +} + +int pthread_rwlock_wrlock(FAR pthread_rwlock_t *rw_lock) +{ + return pthread_rwlock_timedwrlock(rw_lock, NULL); +} diff --git a/sched/Kconfig b/sched/Kconfig index 50613fb44d3..02096b268d9 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -573,6 +573,12 @@ config PTHREAD_MUTEX_DEFAULT_UNSAFE endchoice # Default NORMAL mutex robustness +config PTHREAD_RWLOCK + bool "Enable pthread rwlock API" + default n + ---help--- + Add supports for the rwlock interfaces + config NPTHREAD_KEYS int "Maximum number of pthread keys" default 4 From b631dc886f3d1533b70d38385e42fabc9fde93fe Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 7 Apr 2017 07:34:22 -0600 Subject: [PATCH 02/48] Remove CONFIG_PTHREAD_RWLOCK. Rwlock interfaces built unconditionally. --- include/pthread.h | 4 ---- libc/pthread/Make.defs | 3 --- sched/Kconfig | 6 ------ 3 files changed, 13 deletions(-) diff --git a/include/pthread.h b/include/pthread.h index cfa054cfcac..be555fed75e 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -337,7 +337,6 @@ typedef struct pthread_barrier_s pthread_barrier_t; typedef bool pthread_once_t; #define __PTHREAD_ONCE_T_DEFINED 1 -#ifdef CONFIG_PTHREAD_RWLOCK struct pthread_rwlock_s { pthread_mutex_t lock; @@ -357,7 +356,6 @@ typedef int pthread_rwlockattr_t; #define PTHREAD_MUTEX_INITIALIZER {NULL, SEM_INITIALIZER(1), -1, \ __PTHREAD_MUTEX_DEFAULT_FLAGS, \ PTHREAD_MUTEX_DEFAULT, 0} -#endif #ifdef CONFIG_PTHREAD_CLEANUP /* This type describes the pthread cleanup callback (non-standard) */ @@ -572,7 +570,6 @@ int pthread_once(FAR pthread_once_t *once_control, /* Pthread rwlock */ -#ifdef CONFIG_PTHREAD_RWLOCK int pthread_rwlock_destroy(FAR pthread_rwlock_t *rw_lock); int pthread_rwlock_init(FAR pthread_rwlock_t *rw_lock, FAR const pthread_rwlockattr_t *attr); @@ -585,7 +582,6 @@ int pthread_rwlock_timedwrlock(FAR pthread_rwlock_t *lock, FAR const struct timespec *abstime); int pthread_rwlock_trywrlock(FAR pthread_rwlock_t *lock); int pthread_rwlock_unlock(FAR pthread_rwlock_t *lock); -#endif /* CONFIG_PTHREAD_RWLOCK */ /* Pthread signal management APIs */ diff --git a/libc/pthread/Make.defs b/libc/pthread/Make.defs index 1f6cacb88e0..291dfdfd4e6 100644 --- a/libc/pthread/Make.defs +++ b/libc/pthread/Make.defs @@ -52,10 +52,7 @@ CSRCS += pthread_mutexattr_settype.c pthread_mutexattr_gettype.c CSRCS += pthread_mutexattr_setrobust.c pthread_mutexattr_getrobust.c CSRCS += pthread_setcancelstate.c pthread_setcanceltype.c CSRCS += pthread_testcancel.c - -ifeq ($(CONFIG_PTHREAD_RWLOCK),y) CSRCS += pthread_rwlock.c pthread_rwlock_rdlock.c pthread_rwlock_wrlock.c -endif ifeq ($(CONFIG_SMP),y) CSRCS += pthread_attr_getaffinity.c pthread_attr_setaffinity.c diff --git a/sched/Kconfig b/sched/Kconfig index 02096b268d9..50613fb44d3 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -573,12 +573,6 @@ config PTHREAD_MUTEX_DEFAULT_UNSAFE endchoice # Default NORMAL mutex robustness -config PTHREAD_RWLOCK - bool "Enable pthread rwlock API" - default n - ---help--- - Add supports for the rwlock interfaces - config NPTHREAD_KEYS int "Maximum number of pthread keys" default 4 From 19f19e31ebac2ed592f38c3a707878c6ac649e70 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 7 Apr 2017 08:13:18 -0600 Subject: [PATCH 03/48] 6loWPAN: Correct some list handling logic. --- net/sixlowpan/sixlowpan_framelist.c | 1 + wireless/ieee802154/mac802154_loopback.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 8995048b007..6aca0069342 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -425,6 +425,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Add the next frame to the tail of the IOB queue */ qtail->io_flink = iob; + qtail = iob; /* Keep track of the total amount of data queue */ diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index 1f8dc4e8c38..9cb9f096413 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -185,23 +185,25 @@ static int lo_txpoll(FAR struct net_driver_s *dev) /* Find the tail of the IOB queue */ for (tail = NULL, iob = head; - iob != NULL; - tail = iob, iob = iob->io_flink); + iob != NULL; + tail = iob, iob = iob->io_flink); /* Loop while there frames to be sent, i.e., while the IOB list is not * emtpy. Sending, of course, just means relaying back through the network * for this driver. */ - while (!FRAME_IOB_EMPTY(&priv->lo_ieee)) + while (head != NULL) { /* Remove the IOB from the queue */ - FRAME_IOB_REMOVE(&priv->lo_ieee, iob); + iob = head; + head = iob->io_flink; + iob->io_flink = NULL; /* Is the queue now empty? */ - if (FRAME_IOB_EMPTY(&priv->lo_ieee)) + if (head == NULL) { tail = NULL; } @@ -239,8 +241,8 @@ static int lo_txpoll(FAR struct net_driver_s *dev) /* Find the new tail of the IOB queue */ for (tail = iob, iob = iob->io_flink; - iob != NULL; - tail = iob, iob = iob->io_flink); + iob != NULL; + tail = iob, iob = iob->io_flink); } priv->lo_txdone = true; From 47647eac8ffab8e66f32c8dfc079f17a731bfea0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 7 Apr 2017 09:49:10 -0600 Subject: [PATCH 04/48] 6loWPAN: Correct some fragmentation handling --- net/sixlowpan/sixlowpan_framelist.c | 156 ++++++++++++++++++++++------ net/sixlowpan/sixlowpan_globals.c | 9 -- net/sixlowpan/sixlowpan_input.c | 30 +++--- net/sixlowpan/sixlowpan_internal.h | 9 -- 4 files changed, 139 insertions(+), 65 deletions(-) diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 6aca0069342..994b7bfc7b4 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -101,17 +101,15 @@ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * Input Parameters: - * ieee - Pointer to IEEE802.15.4 MAC driver structure. - * destip - Pointer to the IPv6 header to "compress" - * fptr - Pointer to the beginning of the frame under construction + * ipv6hdr - Pointer to the IPv6 header to "compress" + * fptr - Pointer to the beginning of the frame under construction * * Returned Value: * None * ****************************************************************************/ -static void sixlowpan_compress_ipv6hdr(FAR struct ieee802154_driver_s *ieee, - FAR const struct ipv6_hdr_s *destip, +static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr, FAR uint8_t *fptr) { /* Indicate the IPv6 dispatch and length */ @@ -121,11 +119,93 @@ static void sixlowpan_compress_ipv6hdr(FAR struct ieee802154_driver_s *ieee, /* Copy the IPv6 header and adjust pointers */ - memcpy(&fptr[g_frame_hdrlen] , destip, IPv6_HDRLEN); + memcpy(&fptr[g_frame_hdrlen] , ipv6hdr, IPv6_HDRLEN); g_frame_hdrlen += IPv6_HDRLEN; g_uncomp_hdrlen += IPv6_HDRLEN; } +/**************************************************************************** + * Name: sixlowpan_copy_protohdr + * + * Description: + * The IPv6 header should have already been processed (as reflected in the + * g_uncomphdrlen). But we probably still need to copy the following + * protocol header. + * + * Input Parameters: + * ipv6hdr - Pointer to the IPv6 header to "compress" + * fptr - Pointer to the beginning of the frame under construction + * + * Returned Value: + * None. But g_frame_hdrlen and g_uncomp_hdrlen updated. + * + ****************************************************************************/ + +static void sixlowpan_copy_protohdr(FAR const struct ipv6_hdr_s *ipv6hdr, + FAR uint8_t *fptr) +{ + uint16_t combined; + uint16_t protosize; + uint16_t copysize; + + /* What is the total size of the IPv6 + protocol header? */ + + switch (ipv6hdr->proto) + { +#ifdef CONFIG_NET_TCP + case IP_PROTO_TCP: + combined = sizeof(struct ipv6tcp_hdr_s); + protosize = sizeof(struct tcp_hdr_s); + break; +#endif + +#ifdef CONFIG_NET_UDP + case IP_PROTO_UDP: + combined = sizeof(struct ipv6udp_hdr_s); + protosize = sizeof(struct udp_hdr_s); + break; +#endif + +#ifdef CONFIG_NET_ICMPv6 + case IP_PROTO_ICMP6: + combined = sizeof(struct ipv6icmp_hdr_s); + protosize = sizeof(struct icmpv6_hdr_s); + break; +#endif + + default: + nwarn("WARNING: Unrecognized proto: %u\n", ipv6hdr->proto); + combined = sizeof(struct ipv6_hdr_s); + protosize = 0; + break; + } + + /* Copy the remaining protocol header. */ + + if (g_uncomp_hdrlen > IPv6_HDRLEN) + { + nwarn("WARNING: Protocol header not copied: " + "g_uncomp_hdren=%u IPv6_HDRLEN=%u\n", + g_uncomp_hdrlen, IPv6_HDRLEN); + return; + } + + copysize = combined - g_uncomp_hdrlen; + if (copysize != protosize) + { + nwarn("WARNING: Protocol header size mismatch: " + "g_uncomp_hdren=%u copysize=%u protosize=%u\n", + g_uncomp_hdrlen, copysize, protosize); + return; + } + + memcpy(fptr + g_frame_hdrlen, (FAR uint8_t *)ipv6hdr + g_uncomp_hdrlen, + copysize); + + g_frame_hdrlen += copysize; + g_uncomp_hdrlen += copysize; +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -172,6 +252,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, FAR uint8_t *fptr; int framer_hdrlen; struct rimeaddr_s bcastmac; + uint16_t paysize; #ifdef CONFIG_NET_6LOWPAN_FRAG uint16_t outlen = 0; #endif @@ -267,7 +348,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, { /* Small.. use IPv6 dispatch (no compression) */ - sixlowpan_compress_ipv6hdr(ieee, destip, fptr); + sixlowpan_compress_ipv6hdr(destip, fptr); } ninfo("Header of length %d\n", g_frame_hdrlen); @@ -276,9 +357,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Check if we need to fragment the packet into several frames */ - if ((int)buflen - (int)g_uncomp_hdrlen > - (int)CONFIG_NET_6LOWPAN_MAXPAYLOAD - framer_hdrlen - - (int)g_frame_hdrlen) + if (buflen > (CONFIG_NET_6LOWPAN_MAXPAYLOAD - g_frame_hdrlen)) { #ifdef CONFIG_NET_6LOWPAN_FRAG /* ieee->i_framelist will hold the generated frames; frames will be @@ -295,7 +374,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, * The following fragments contain only the fragn dispatch. */ - ninfo("Fragmentation sending packet length %d\n", buflen); + ninfo("Sending fragmented packet length %d\n", buflen); /* Create 1st Fragment */ /* Add the frame header using the pre-allocated IOB. */ @@ -325,25 +404,28 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, PUTINT16(fptr, RIME_FRAG_DISPATCH_SIZE, ((SIXLOWPAN_DISPATCH_FRAG1 << 8) | buflen)); + PUTINT16(fptr, RIME_FRAG_TAG, ieee->i_dgramtag); ieee->i_dgramtag++; + g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; + + /* Copy protocol header that follows the IPv6 header */ + + sixlowpan_copy_protohdr(destip, fptr); + /* Copy payload and enqueue */ - g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; - g_rime_payloadlen = - (CONFIG_NET_6LOWPAN_MAXPAYLOAD - framer_hdrlen - g_frame_hdrlen) & 0xf8; - - memcpy(fptr + g_frame_hdrlen, - (FAR uint8_t *)destip + g_uncomp_hdrlen, g_rime_payloadlen); - iob->io_len += g_rime_payloadlen + g_frame_hdrlen; + paysize = (CONFIG_NET_6LOWPAN_MAXPAYLOAD - g_frame_hdrlen) & 0xf8; + memcpy(fptr + g_frame_hdrlen, buf, paysize); /* Set outlen to what we already sent from the IP payload */ - outlen = g_rime_payloadlen + g_uncomp_hdrlen; + iob->io_len = paysize + g_frame_hdrlen; + outlen = paysize; ninfo("First fragment: length %d, tag %d\n", - g_rime_payloadlen, ieee->i_dgramtag); + paysize, ieee->i_dgramtag); sixlowpan_dumpbuffer("Outgoing frame", (FAR const uint8_t *)iob->io_data, iob->io_len); @@ -394,30 +476,33 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, PUTINT16(fptr, RIME_FRAG_TAG, ieee->i_dgramtag); fptr[RIME_FRAG_OFFSET] = outlen >> 3; + /* Copy protocol header that follows the IPv6 header */ + + sixlowpan_copy_protohdr(destip, fptr); + /* Copy payload and enqueue */ + /* Check for the last fragment */ - if (buflen - outlen < g_rime_payloadlen) + if (buflen - outlen < paysize) { - /* Last fragment */ + /* Last fragment, truncate to the correct length */ - g_rime_payloadlen = buflen - outlen; + paysize = buflen - outlen; } else { - g_rime_payloadlen = - (CONFIG_NET_6LOWPAN_MAXPAYLOAD - framer_hdrlen - g_frame_hdrlen) & 0xf8; + paysize = (CONFIG_NET_6LOWPAN_MAXPAYLOAD - g_frame_hdrlen) & 0xf8; } - memcpy(fptr + g_frame_hdrlen, (FAR uint8_t *)destip + outlen, - g_rime_payloadlen); - iob->io_len = g_rime_payloadlen + g_frame_hdrlen; + memcpy(fptr + g_frame_hdrlen, buf + outlen, paysize); /* Set outlen to what we already sent from the IP payload */ - outlen += (g_rime_payloadlen + g_uncomp_hdrlen); + iob->io_len = paysize + g_frame_hdrlen; + outlen += paysize; - ninfo("sixlowpan output: fragment offset %d, length %d, tag %d\n", - outlen >> 3, g_rime_payloadlen, ieee->i_dgramtag); + ninfo("Fragment offset %d, length %d, tag %d\n", + outlen >> 3, paysize, ieee->i_dgramtag); sixlowpan_dumpbuffer("Outgoing frame", (FAR const uint8_t *)iob->io_data, iob->io_len); @@ -453,11 +538,14 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, DEBUGASSERT(verify == framer_hdrlen); UNUSED(verify); + /* Copy protocol header that follows the IPv6 header */ + + sixlowpan_copy_protohdr(destip, fptr); + /* Copy the payload and queue */ - memcpy(fptr + g_frame_hdrlen, (FAR uint8_t *)destip + g_uncomp_hdrlen, - buflen - g_uncomp_hdrlen); - iob->io_len = buflen - g_uncomp_hdrlen + g_frame_hdrlen; + memcpy(fptr + g_frame_hdrlen, buf, buflen); + iob->io_len = buflen + g_frame_hdrlen; ninfo("Non-fragmented: length %d\n", iob->io_len); sixlowpan_dumpbuffer("Outgoing frame", diff --git a/net/sixlowpan/sixlowpan_globals.c b/net/sixlowpan/sixlowpan_globals.c index 8f48ade9f2f..aac17f7eb9c 100644 --- a/net/sixlowpan/sixlowpan_globals.c +++ b/net/sixlowpan/sixlowpan_globals.c @@ -54,15 +54,6 @@ * during that processing */ -/* The length of the payload in the Rime buffer. - * - * The payload is what comes after the compressed or uncompressed headers - * (can be the IP payload if the IP header only is compressed or the UDP - * payload if the UDP header is also compressed) - */ - -uint8_t g_rime_payloadlen; - /* g_uncomp_hdrlen is the length of the headers before compression (if HC2 * is used this includes the UDP header in addition to the IP header). */ diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index 257e7b48c9e..95bb7c1cee2 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -213,6 +213,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, FAR uint8_t *hc1; /* Convenience pointer to HC1 data */ uint16_t fragsize = 0; /* Size of the IP packet (read from fragment) */ + uint16_t paysize; /* Size of the data payload */ uint8_t fragoffset = 0; /* Offset of the fragment in the IP packet */ int reqsize; /* Required buffer size */ int hdrsize; /* Size of the IEEE802.15.4 header */ @@ -282,12 +283,12 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, fragtag = GETINT16(payptr, RIME_FRAG_TAG); fragsize = GETINT16(payptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; - ninfo("FRAGN: size %d, tag %d, offset %d\n", + ninfo("FRAGN: size=%d tag=%d offset=%d\n", fragsize, fragtag, fragoffset); g_frame_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN; - ninfo("FRAGN: i_accumlen %d g_rime_payloadlen %d fragsize %d\n", + ninfo("FRAGN: i_accumlen=%d paysize=%u fragsize=%u\n", ieee->i_accumlen, iob->io_len - g_frame_hdrlen, fragsize); /* Indicate that this frame is a another fragment for reassembly */ @@ -501,28 +502,28 @@ copypayload: * and g_frame_hdrlen are non-zerio, fragoffset is. */ - g_rime_payloadlen = iob->io_len - g_frame_hdrlen; - if (g_rime_payloadlen > CONFIG_NET_6LOWPAN_MTU) + paysize = iob->io_len - g_frame_hdrlen; + if (paysize > CONFIG_NET_6LOWPAN_MTU) { nwarn("WARNING: Packet dropped due to payload (%u) > packet buffer (%u)\n", - g_rime_payloadlen, CONFIG_NET_6LOWPAN_MTU); + paysize, CONFIG_NET_6LOWPAN_MTU); return OK; } /* Sanity-check size of incoming packet to avoid buffer overflow */ - reqsize = g_uncomp_hdrlen + (uint16_t) (fragoffset << 3) + g_rime_payloadlen; + reqsize = g_uncomp_hdrlen + (uint16_t) (fragoffset << 3) + paysize; if (reqsize > CONFIG_NET_6LOWPAN_MTU) { ninfo("Required buffer size: %d+%d+%d=%d Available: %d\n", - g_uncomp_hdrlen, (int)(fragoffset << 3), g_rime_payloadlen, + g_uncomp_hdrlen, (int)(fragoffset << 3), paysize, reqsize, CONFIG_NET_6LOWPAN_MTU); return -ENOMEM; } memcpy((FAR uint8_t *)ieee->i_dev.d_buf + g_uncomp_hdrlen + (int)(fragoffset << 3), payptr + g_frame_hdrlen, - g_rime_payloadlen); + paysize); #ifdef CONFIG_NET_6LOWPAN_FRAG /* Update ieee->i_accumlen if the frame is a fragment, ieee->i_pktlen @@ -548,15 +549,14 @@ copypayload: } else { - ieee->i_accumlen += g_rime_payloadlen; + ieee->i_accumlen += paysize; } - ninfo("i_accumlen %d, g_rime_payloadlen %d\n", - ieee->i_accumlen, g_rime_payloadlen); + ninfo("i_accumlen %d, paysize %d\n", ieee->i_accumlen, paysize); } else { - ieee->i_pktlen = g_rime_payloadlen + g_uncomp_hdrlen; + ieee->i_pktlen = paysize + g_uncomp_hdrlen; } /* If we have a full IP packet in sixlowpan_buf, deliver it to @@ -580,7 +580,7 @@ copypayload: #else /* Deliver the packet to the IP stack */ - ieee->i_dev.d_len = g_rime_payloadlen + g_uncomp_hdrlen; + ieee->i_dev.d_len = paysize + g_uncomp_hdrlen; return INPUT_COMPLETE; #endif /* CONFIG_NET_6LOWPAN_FRAG */ } @@ -706,6 +706,10 @@ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee) ret = sixlowpan_frame_process(ieee, iob); + /* Free the IOB the held the consumed frame */ + + iob_free(iob); + /* Was the frame successfully processed? Is the packet in d_buf fully * reassembled? */ diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index d6a795c5540..bd366c884ec 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -409,15 +409,6 @@ struct frame802154_s extern FAR uint8_t *g_rimeptr; -/* The length of the payload in the Rime buffer. - * - * The payload is what comes after the compressed or uncompressed headers - * (can be the IP payload if the IP header only is compressed or the UDP - * payload if the UDP header is also compressed) - */ - -extern uint8_t g_rime_payloadlen; - /* g_uncomp_hdrlen is the length of the headers before compression (if HC2 * is used this includes the UDP header in addition to the IP header). */ From f264e6aec261c6f4996ba2ea2a990f13302eb750 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 7 Apr 2017 15:27:53 -0600 Subject: [PATCH 05/48] 6loWPAN: Fixes for fragmented packets. Change fixes some things, breaks other. Lots more to do. --- include/nuttx/net/sixlowpan.h | 8 +- net/sixlowpan/sixlowpan_framelist.c | 65 ++++++----- net/sixlowpan/sixlowpan_input.c | 172 +++++++++++++--------------- net/sixlowpan/sixlowpan_tcpsend.c | 7 +- 4 files changed, 129 insertions(+), 123 deletions(-) diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 0211d17ce6f..04b69da6048 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -80,7 +80,7 @@ #define SIXLOWPAN_DISPATCH_FRAG1 0xc0 /* 11000xxx */ #define SIXLOWPAN_DISPATCH_FRAGN 0xe0 /* 11100xxx */ -#define SIXLOWPAN_DISPATCH_FRAG_MASK 0xf1 /* 11111000 */ +#define SIXLOWPAN_DISPATCH_FRAG_MASK 0xf8 /* 11111000 */ /* HC1 encoding */ @@ -398,6 +398,12 @@ struct ieee802154_driver_s uint16_t i_reasstag; + /* i_boffset. Offset to the beginning of data in d_buf. As each fragment + * is received, data is placed at an appriate offset added to this. + */ + + uint16_t i_boffset; + /* The source MAC address of the fragments being merged */ struct rimeaddr_s i_fragsrc; diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 994b7bfc7b4..8d8900460f5 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -202,8 +202,8 @@ static void sixlowpan_copy_protohdr(FAR const struct ipv6_hdr_s *ipv6hdr, memcpy(fptr + g_frame_hdrlen, (FAR uint8_t *)ipv6hdr + g_uncomp_hdrlen, copysize); - g_frame_hdrlen += copysize; - g_uncomp_hdrlen += copysize; + g_frame_hdrlen += copysize; + g_uncomp_hdrlen += copysize; } /**************************************************************************** @@ -252,6 +252,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, FAR uint8_t *fptr; int framer_hdrlen; struct rimeaddr_s bcastmac; + uint16_t pktlen; uint16_t paysize; #ifdef CONFIG_NET_6LOWPAN_FRAG uint16_t outlen = 0; @@ -365,6 +366,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, */ FAR struct iob_s *qtail; + FAR uint8_t *frame1; int verify; /* The outbound IPv6 packet is too large to fit into a single 15.4 @@ -383,7 +385,9 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, DEBUGASSERT(verify == framer_hdrlen); UNUSED(verify); - /* Move HC1/HC06/IPv6 header */ + /* Move HC1/HC06/IPv6 header to make space for the FRAG1 header at the + * beginning of the frame. + */ memmove(fptr + SIXLOWPAN_FRAG1_HDR_LEN, fptr, g_frame_hdrlen); @@ -402,11 +406,10 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, * bytes for all subsequent headers. */ + pktlen = buflen + g_uncomp_hdrlen; PUTINT16(fptr, RIME_FRAG_DISPATCH_SIZE, - ((SIXLOWPAN_DISPATCH_FRAG1 << 8) | buflen)); - + ((SIXLOWPAN_DISPATCH_FRAG1 << 8) | pktlen)); PUTINT16(fptr, RIME_FRAG_TAG, ieee->i_dgramtag); - ieee->i_dgramtag++; g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; @@ -414,9 +417,11 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, sixlowpan_copy_protohdr(destip, fptr); - /* Copy payload and enqueue */ + /* Copy payload and enqueue. NOTE that the size is a multiple of eight + * bytes. + */ - paysize = (CONFIG_NET_6LOWPAN_MAXPAYLOAD - g_frame_hdrlen) & 0xf8; + paysize = (CONFIG_NET_6LOWPAN_MAXPAYLOAD - g_frame_hdrlen) & ~7; memcpy(fptr + g_frame_hdrlen, buf, paysize); /* Set outlen to what we already sent from the IP payload */ @@ -440,10 +445,11 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Create following fragments */ - g_frame_hdrlen = SIXLOWPAN_FRAGN_HDR_LEN; - + frame1 = iob->io_data; while (outlen < buflen) { + uint16_t fragn_hdrlen; + /* Allocate an IOB to hold the next fragment, waiting if * necessary. */ @@ -459,49 +465,44 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, iob->io_pktlen = 0; fptr = iob->io_data; - /* Add the frame header */ + /* Copy the frame header from first frame, into the correct + * location after the FRAGN header. + */ - verify = sixlowpan_framecreate(ieee, iob, ieee->i_panid); - DEBUGASSERT(verify == framer_hdrlen); - UNUSED(verify); + memmove(fptr + SIXLOWPAN_FRAGN_HDR_LEN, + frame1 + SIXLOWPAN_FRAG1_HDR_LEN, + framer_hdrlen); + fragn_hdrlen = framer_hdrlen; - /* Move HC1/HC06/IPv6 header */ - - memmove(fptr + SIXLOWPAN_FRAGN_HDR_LEN, fptr, g_frame_hdrlen); - - /* Setup up the fragment header */ + /* Setup up the FRAGN header at the beginning of the frame */ PUTINT16(fptr, RIME_FRAG_DISPATCH_SIZE, - ((SIXLOWPAN_DISPATCH_FRAGN << 8) | buflen)); + ((SIXLOWPAN_DISPATCH_FRAGN << 8) | pktlen)); PUTINT16(fptr, RIME_FRAG_TAG, ieee->i_dgramtag); fptr[RIME_FRAG_OFFSET] = outlen >> 3; - /* Copy protocol header that follows the IPv6 header */ - - sixlowpan_copy_protohdr(destip, fptr); + fragn_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN; /* Copy payload and enqueue */ /* Check for the last fragment */ + paysize = (CONFIG_NET_6LOWPAN_MAXPAYLOAD - fragn_hdrlen) & + SIXLOWPAN_DISPATCH_FRAG_MASK; if (buflen - outlen < paysize) { /* Last fragment, truncate to the correct length */ paysize = buflen - outlen; } - else - { - paysize = (CONFIG_NET_6LOWPAN_MAXPAYLOAD - g_frame_hdrlen) & 0xf8; - } - memcpy(fptr + g_frame_hdrlen, buf + outlen, paysize); + memcpy(fptr + fragn_hdrlen, buf + outlen, paysize); /* Set outlen to what we already sent from the IP payload */ - iob->io_len = paysize + g_frame_hdrlen; + iob->io_len = paysize + fragn_hdrlen; outlen += paysize; - ninfo("Fragment offset %d, length %d, tag %d\n", + ninfo("Fragment offset=%d, paysize=%d, i_dgramtag=%d\n", outlen >> 3, paysize, ieee->i_dgramtag); sixlowpan_dumpbuffer("Outgoing frame", (FAR const uint8_t *)iob->io_data, @@ -516,6 +517,10 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, ieee->i_framelist->io_pktlen += iob->io_len; } + + /* Update the datagram TAG value */ + + ieee->i_dgramtag++; #else nerr("ERROR: Packet too large: %d\n", buflen); nerr(" Cannot to be sent without fragmentation support\n"); diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index 95bb7c1cee2..7144d36e8b4 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -111,12 +111,26 @@ int sixlowpan_recv_hdrlen(FAR const uint8_t *fptr) { - uint16_t hdrlen; + uint16_t hdrlen = 0; uint8_t addrmode; + uint8_t tmp; + + /* Check for a fragment header preceding the IEEE802.15.4 FCF */ + + tmp = *fptr & SIXLOWPAN_DISPATCH_FRAG_MASK; + if (tmp == SIXLOWPAN_DISPATCH_FRAG1) + { + hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; + } + else if (tmp == SIXLOWPAN_DISPATCH_FRAGN) + { + hdrlen += SIXLOWPAN_FRAGN_HDR_LEN; + } /* Minimum header: 2 byte FCF + 1 byte sequence number */ - hdrlen = 3; + fptr += hdrlen; + hdrlen += 3; /* Account for destination address size */ @@ -209,9 +223,7 @@ int sixlowpan_recv_hdrlen(FAR const uint8_t *fptr) static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, FAR struct iob_s *iob) { - FAR uint8_t *payptr; /* Pointer to the frame payload */ FAR uint8_t *hc1; /* Convenience pointer to HC1 data */ - uint16_t fragsize = 0; /* Size of the IP packet (read from fragment) */ uint16_t paysize; /* Size of the data payload */ uint8_t fragoffset = 0; /* Offset of the fragment in the IP packet */ @@ -221,12 +233,13 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, #ifdef CONFIG_NET_6LOWPAN_FRAG bool isfrag = false; bool isfirstfrag = false; - bool islastfrag = false; uint16_t fragtag = 0; /* Tag of the fragment */ systime_t elapsed; /* Elapsed time */ #endif /* CONFIG_NET_6LOWPAN_FRAG */ - /* Get a pointer to the payload following the IEEE802.15.4 frame header. */ + /* Get a pointer to the payload following the IEEE802.15.4 frame header(s). + * This size includes both fragmentation and FCF headers. + */ hdrsize = sixlowpan_recv_hdrlen(iob->io_data); if (hdrsize < 0) @@ -242,16 +255,13 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, g_uncomp_hdrlen = 0; g_frame_hdrlen = hdrsize; - /* Payload starts after the IEEE802.15.4 header */ - - payptr = &iob->io_data[hdrsize]; - #ifdef CONFIG_NET_6LOWPAN_FRAG /* Since we don't support the mesh and broadcast header, the first header - * we look for is the fragmentation header + * we look for is the fragmentation header. NOTE that g_frame_hdrlen + * already includes the fragementation header, if presetn. */ - switch ((GETINT16(payptr, RIME_FRAG_DISPATCH_SIZE) & 0xf800) >> 8) + switch ((GETINT16(iob->io_data, RIME_FRAG_DISPATCH_SIZE) & 0xf800) >> 8) { /* First fragment of new reassembly */ @@ -259,15 +269,12 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, { /* Set up for the reassembly */ - fragoffset = 0; - fragsize = GETINT16(payptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; - fragtag = GETINT16(payptr, RIME_FRAG_TAG); + fragsize = GETINT16(iob->io_data, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; + fragtag = GETINT16(iob->io_data, RIME_FRAG_TAG); - ninfo("FRAG1: size %d, tag %d, offset %d\n", + ninfo("FRAG1: fragsize=%d fragtag=%d fragoffset=%d\n", fragsize, fragtag, fragoffset); - g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; - /* Indicate the first fragment of the reassembly */ isfirstfrag = true; @@ -279,32 +286,18 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, { /* Set offset, tag, size. Offset is in units of 8 bytes. */ - fragoffset = payptr[RIME_FRAG_OFFSET]; - fragtag = GETINT16(payptr, RIME_FRAG_TAG); - fragsize = GETINT16(payptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; + fragoffset = iob->io_data[RIME_FRAG_OFFSET]; + fragtag = GETINT16(iob->io_data, RIME_FRAG_TAG); + fragsize = GETINT16(iob->io_data, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; - ninfo("FRAGN: size=%d tag=%d offset=%d\n", + ninfo("FRAGN: fragsize=%d fragtag=%d fragoffset=%d\n", fragsize, fragtag, fragoffset); - - g_frame_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN; - ninfo("FRAGN: i_accumlen=%d paysize=%u fragsize=%u\n", ieee->i_accumlen, iob->io_len - g_frame_hdrlen, fragsize); /* Indicate that this frame is a another fragment for reassembly */ isfrag = true; - - /* Check if it is the last fragement to be processed. - * - * If this is the last fragment, we may shave off any extrenous - * bytes at the end. We must be liberal in what we accept. - */ - - if (ieee->i_accumlen + iob->io_len - g_frame_hdrlen >= fragsize) - { - islastfrag = true; - } } break; @@ -393,6 +386,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, * compression dispatch logic. */ + g_uncomp_hdrlen = ieee->i_boffset; goto copypayload; } } @@ -413,29 +407,22 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, return OK; } - /* Start reassembly if we received a non-zero length, first fragment */ + /* Drop the packet if it cannot fit into the d_buf */ - if (fragsize > 0) + if (fragsize > CONFIG_NET_6LOWPAN_MTU) { - /* Drop the packet if it cannot fit into the d_buf */ - - if (fragsize > CONFIG_NET_6LOWPAN_MTU) - { - nwarn("WARNING: Reassembled packet size exeeds CONFIG_NET_6LOWPAN_MTU\n"); - return OK; - } - - /* Set up for the reassembly */ - - ieee->i_pktlen = fragsize; - ieee->i_reasstag = fragtag; - ieee->i_time = clock_systimer(); - - ninfo("Starting reassembly: i_pktlen %d, i_pktlen %d\n", - ieee->i_pktlen, ieee->i_reasstag); - - rimeaddr_copy(&ieee->i_fragsrc, &g_pktaddrs[PACKETBUF_ADDR_SENDER]); + nwarn("WARNING: Reassembled packet size exeeds CONFIG_NET_6LOWPAN_MTU\n"); + return OK; } + + ieee->i_pktlen = fragsize; + ieee->i_reasstag = fragtag; + ieee->i_time = clock_systimer(); + + ninfo("Starting reassembly: i_pktlen %u, i_reasstag %d\n", + ieee->i_pktlen, ieee->i_reasstag); + + rimeaddr_copy(&ieee->i_fragsrc, &g_pktaddrs[PACKETBUF_ADDR_SENDER]); } #endif /* CONFIG_NET_6LOWPAN_FRAG */ @@ -446,7 +433,13 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06 if ((hc1[RIME_HC1_DISPATCH] & SIXLOWPAN_DISPATCH_IPHC_MASK) == SIXLOWPAN_DISPATCH_IPHC) { + FAR uint8_t *payptr; + ninfo("IPHC Dispatch\n"); + + /* Payload starts after the IEEE802.15.4 header(s) */ + + payptr = &iob->io_data[g_frame_hdrlen]; sixlowpan_uncompresshdr_hc06(ieee, fragsize, iob, payptr); } else @@ -455,7 +448,13 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1 if (hc1[RIME_HC1_DISPATCH] == SIXLOWPAN_DISPATCH_HC1) { + FAR uint8_t *payptr; + ninfo("HC1 Dispatch\n"); + + /* Payload starts after the IEEE802.15.4 header(s) */ + + payptr = &iob->io_data[g_frame_hdrlen]; sixlowpan_uncompresshdr_hc1(ieee, fragsize, iob, payptr); } else @@ -468,16 +467,9 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, ninfo("IPv6 Dispatch\n"); g_frame_hdrlen += SIXLOWPAN_IPV6_HDR_LEN; - /* payptr was set up to begin just after the IPHC bytes. However, - * those bytes are not present for the case of IPv6 dispatch. Just - * reset back to the begnning of the buffer. - */ - - payptr = iob->io_data; - /* Put uncompressed IP header in d_buf. */ - memcpy(ipv6, payptr + g_frame_hdrlen, IPv6_HDRLEN); + memcpy(ipv6, iob->io_data + g_frame_hdrlen, IPv6_HDRLEN); /* Update g_uncomp_hdrlen and g_frame_hdrlen. */ @@ -493,6 +485,18 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, } #ifdef CONFIG_NET_6LOWPAN_FRAG + /* Non-fragmented and FRAG1 frames pass through here. Remember the + * offset from the beginning of d_buf where be begin placing the data + * payload. + */ + + if (isfirstfrag) + { + ieee->i_boffset = g_uncomp_hdrlen; + } + + /* We branch to here on all good FRAGN frames */ + copypayload: #endif /* CONFIG_NET_6LOWPAN_FRAG */ @@ -512,17 +516,17 @@ copypayload: /* Sanity-check size of incoming packet to avoid buffer overflow */ - reqsize = g_uncomp_hdrlen + (uint16_t) (fragoffset << 3) + paysize; + reqsize = g_uncomp_hdrlen + (fragoffset << 3) + paysize; if (reqsize > CONFIG_NET_6LOWPAN_MTU) { - ninfo("Required buffer size: %d+%d+%d=%d Available: %d\n", - g_uncomp_hdrlen, (int)(fragoffset << 3), paysize, + ninfo("Required buffer size: %u+%u+%u=%u Available=%u\n", + g_uncomp_hdrlen, (fragoffset << 3), paysize, reqsize, CONFIG_NET_6LOWPAN_MTU); return -ENOMEM; } - memcpy((FAR uint8_t *)ieee->i_dev.d_buf + g_uncomp_hdrlen + - (int)(fragoffset << 3), payptr + g_frame_hdrlen, + memcpy(ieee->i_dev.d_buf + g_uncomp_hdrlen + (fragoffset << 3), + iob->io_data + g_frame_hdrlen, paysize); #ifdef CONFIG_NET_6LOWPAN_FRAG @@ -532,27 +536,13 @@ copypayload: if (isfrag) { - /* Add the size of the header only for the first fragment. */ - - if (isfirstfrag) - { - ieee->i_accumlen += g_uncomp_hdrlen; - } - - /* For the last fragment, we are OK if there is extraneous bytes at the - * end of the packet. + /* Check if it is the last fragment to be processed. + * + * If this is the last fragment, we may shave off any extrenous + * bytes at the end. We must be liberal in what we accept. */ - if (islastfrag) - { - ieee->i_accumlen = fragsize; - } - else - { - ieee->i_accumlen += paysize; - } - - ninfo("i_accumlen %d, paysize %d\n", ieee->i_accumlen, paysize); + ieee->i_accumlen = g_uncomp_hdrlen + (fragoffset << 3) + paysize; } else { @@ -563,10 +553,10 @@ copypayload: * the IP stack */ - ninfo("sixlowpan_init i_accumlen %d, ieee->i_pktlen %d\n", - ieee->i_accumlen, ieee->i_pktlen); + ninfo("i_accumlen=%d i_pktlen=%d paysize=%d\n", + ieee->i_accumlen, ieee->i_pktlen, paysize); - if (ieee->i_accumlen == 0 || ieee->i_accumlen == ieee->i_pktlen) + if (ieee->i_accumlen == 0 || ieee->i_accumlen >= ieee->i_pktlen) { ninfo("IP packet ready (length %d)\n", ieee->i_pktlen); diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index a34bfe0666e..a1a4a5847b8 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -403,6 +403,8 @@ void sixlowpan_tcp_send(FAR struct net_driver_s *dev) else { struct rimeaddr_s destmac; + FAR uint8_t *buf; + size_t buflen; /* Get the Rime MAC address of the destination. This assumes an * encoding of the MAC address in the IPv6 address. @@ -412,9 +414,12 @@ void sixlowpan_tcp_send(FAR struct net_driver_s *dev) /* Convert the outgoing packet into a frame list. */ + buf = dev->d_buf + sizeof(struct ipv6_hdr_s); + buflen = dev->d_len - sizeof(struct ipv6_hdr_s); + (void)sixlowpan_queue_frames( (FAR struct ieee802154_driver_s *)dev, ipv6hdr, - dev->d_buf, dev->d_len, &destmac); + buf, buflen, &destmac); } } From 2b1ca79b4b2549f63df9b1c77138e9ef1c848ee4 Mon Sep 17 00:00:00 2001 From: Mark Schulte Date: Fri, 7 Apr 2017 15:45:24 -0600 Subject: [PATCH 06/48] pthread rwlock bugfixes --- include/pthread.h | 1 + libc/pthread/pthread_rwlock.c | 9 +++++---- libc/pthread/pthread_rwlock_rdlock.c | 2 +- libc/pthread/pthread_rwlock_wrlock.c | 27 +++++++++++++++++++++------ 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/include/pthread.h b/include/pthread.h index be555fed75e..a75cd9e9015 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -343,6 +343,7 @@ struct pthread_rwlock_s pthread_cond_t cv; unsigned int num_readers; unsigned int num_writers; + bool write_in_progress; }; typedef struct pthread_rwlock_s pthread_rwlock_t; diff --git a/libc/pthread/pthread_rwlock.c b/libc/pthread/pthread_rwlock.c index 3f902089b00..b40b655b26d 100644 --- a/libc/pthread/pthread_rwlock.c +++ b/libc/pthread/pthread_rwlock.c @@ -60,8 +60,9 @@ int pthread_rwlock_init(FAR pthread_rwlock_t *lock, return -ENOSYS; } - lock->num_readers = 0; - lock->num_writers = 0; + lock->num_readers = 0; + lock->num_writers = 0; + lock->write_in_progress = false; err = pthread_cond_init(&lock->cv, NULL); if (err != 0) @@ -111,9 +112,9 @@ int pthread_rwlock_unlock(FAR pthread_rwlock_t *rw_lock) err = pthread_cond_broadcast(&rw_lock->cv); } } - else if (rw_lock->num_writers > 0) + else if (rw_lock->write_in_progress) { - rw_lock->num_writers--; + rw_lock->write_in_progress = false; err = pthread_cond_broadcast(&rw_lock->cv); } diff --git a/libc/pthread/pthread_rwlock_rdlock.c b/libc/pthread/pthread_rwlock_rdlock.c index 6270d2bbe4e..9fd461a758e 100644 --- a/libc/pthread/pthread_rwlock_rdlock.c +++ b/libc/pthread/pthread_rwlock_rdlock.c @@ -54,7 +54,7 @@ static int tryrdlock(FAR pthread_rwlock_t *rw_lock) { int err; - if (rw_lock->num_writers > 0) + if (rw_lock->num_writers > 0 || rw_lock->write_in_progress) { err = EBUSY; } diff --git a/libc/pthread/pthread_rwlock_wrlock.c b/libc/pthread/pthread_rwlock_wrlock.c index dc2d155021e..ecda4cb25be 100644 --- a/libc/pthread/pthread_rwlock_wrlock.c +++ b/libc/pthread/pthread_rwlock_wrlock.c @@ -75,13 +75,13 @@ int pthread_rwlock_trywrlock(FAR pthread_rwlock_t *rw_lock) return err; } - if (rw_lock->num_readers > 0 || rw_lock->num_writers > 0) + if (rw_lock->num_readers > 0 || rw_lock->write_in_progress) { err = EBUSY; } else { - rw_lock->num_writers++; + rw_lock->write_in_progress = true; } pthread_mutex_unlock(&rw_lock->lock); @@ -92,20 +92,21 @@ int pthread_rwlock_timedwrlock(FAR pthread_rwlock_t *rw_lock, FAR const struct timespec *ts) { int err = pthread_mutex_lock(&rw_lock->lock); - int num_writers_current; if (err != 0) { return err; } - num_writers_current = rw_lock->num_writers++; - if (num_writers_current == 0) + if (rw_lock->num_writers == UINT_MAX) { + err = EAGAIN; goto exit_with_mutex; } - while (rw_lock->num_writers != num_writers_current) + rw_lock->num_writers++; + + while (rw_lock->write_in_progress || rw_lock->num_readers > 0) { if (ts != NULL) { @@ -122,6 +123,20 @@ int pthread_rwlock_timedwrlock(FAR pthread_rwlock_t *rw_lock, } } + if (err == 0) + { + rw_lock->write_in_progress = true; + } + + else + { + /* In case of error, notify any blocked readers. */ + + (void) pthread_cond_broadcast(&rw_lock->cv); + } + + rw_lock->num_writers--; + exit_with_mutex: pthread_mutex_unlock(&rw_lock->lock); return err; From 60f018625896740015f334d7a7ba42cfaa8364c8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 7 Apr 2017 17:04:57 -0600 Subject: [PATCH 07/48] 6loWPAN: Add calculation of TCP header size. It is not a constant. --- net/sixlowpan/sixlowpan_framelist.c | 18 +++++++--- net/sixlowpan/sixlowpan_input.c | 13 +++++-- net/sixlowpan/sixlowpan_tcpsend.c | 53 +++++++++++++++++++++-------- 3 files changed, 63 insertions(+), 21 deletions(-) diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 8d8900460f5..552f394b786 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -154,29 +154,37 @@ static void sixlowpan_copy_protohdr(FAR const struct ipv6_hdr_s *ipv6hdr, { #ifdef CONFIG_NET_TCP case IP_PROTO_TCP: - combined = sizeof(struct ipv6tcp_hdr_s); - protosize = sizeof(struct tcp_hdr_s); + { + FAR struct tcp_hdr_s *tcp = &((FAR struct ipv6tcp_hdr_s *)ipv6hdr)->tcp; + + /* The TCP header length is encoded in the top 4 bits of the + * tcpoffset field (in units of 32-bit words). + */ + + protosize = ((uint16_t)tcp->tcpoffset >> 4) << 2; + combined = sizeof(struct ipv6_hdr_s) + protosize; + } break; #endif #ifdef CONFIG_NET_UDP case IP_PROTO_UDP: - combined = sizeof(struct ipv6udp_hdr_s); protosize = sizeof(struct udp_hdr_s); + combined = sizeof(struct ipv6udp_hdr_s); break; #endif #ifdef CONFIG_NET_ICMPv6 case IP_PROTO_ICMP6: - combined = sizeof(struct ipv6icmp_hdr_s); protosize = sizeof(struct icmpv6_hdr_s); + combined = sizeof(struct ipv6icmp_hdr_s); break; #endif default: nwarn("WARNING: Unrecognized proto: %u\n", ipv6hdr->proto); - combined = sizeof(struct ipv6_hdr_s); protosize = 0; + combined = sizeof(struct ipv6_hdr_s); break; } diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index 7144d36e8b4..6098a58251c 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -86,6 +86,7 @@ /* Buffer access helpers */ #define IPv6BUF(dev) ((FAR struct ipv6_hdr_s *)((dev)->d_buf)) +#define TCPBUF(dev) ((FAR struct tcp_hdr_s *)&(dev)->d_buf[IPv6_HDRLEN]) /**************************************************************************** * Private Functions @@ -728,7 +729,7 @@ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee) * layer protocol header. */ - ipv6hdr = (FAR struct ipv6_hdr_s *)(ieee->i_dev.d_buf); + ipv6hdr = IPv6BUF(&ieee->i_dev); /* Get the Rime MAC address of the destination. This * assumes an encoding of the MAC address in the IPv6 @@ -743,7 +744,15 @@ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee) if (ipv6hdr->proto != IP_PROTO_TCP) { - hdrlen = IPv6_HDRLEN + TCP_HDRLEN; + FAR struct tcp_hdr_s *tcp = TCPBUF(&ieee->i_dev); + uint16_t tcplen; + + /* The TCP header length is encoded in the top 4 bits + * of the tcpoffset field (in units of 32-bit words). + */ + + tcplen = ((uint16_t)tcp->tcpoffset >> 4) << 2; + hdrlen = IPv6_HDRLEN + tcplen; } else if (ipv6hdr->proto != IP_PROTO_UDP) { diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index a1a4a5847b8..3ee39e72ed6 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -88,6 +88,7 @@ static uint16_t sixlowpan_tcp_chksum(FAR struct ipv6tcp_hdr_s *ipv6tcp, FAR const uint8_t *buf, uint16_t buflen) { uint16_t upperlen; + uint16_t tcplen; uint16_t sum; /* The length reported in the IPv6 header is the length of the payload @@ -115,9 +116,14 @@ static uint16_t sixlowpan_tcp_chksum(FAR struct ipv6tcp_hdr_s *ipv6tcp, sum = chksum(sum, (FAR uint8_t *)ipv6tcp->ipv6.srcipaddr, 2 * sizeof(net_ipv6addr_t)); - /* Sum the TCP header */ + /* Sum the TCP header + * + * The TCP header length is encoded in the top 4 bits of the tcpoffset + * field (in units of 32-bit words). + */ - sum = chksum(sum, (FAR uint8_t *)&ipv6tcp->tcp, TCP_HDRLEN); + tcplen = ((uint16_t)ipv6tcp->tcp.tcpoffset >> 4) << 2; + sum = chksum(sum, (FAR uint8_t *)&ipv6tcp->tcp, tcplen); /* Sum payload data. */ @@ -383,43 +389,62 @@ void sixlowpan_tcp_send(FAR struct net_driver_s *dev) if (dev != NULL && dev->d_len > 0) { - FAR struct ipv6_hdr_s *ipv6hdr; + FAR struct ipv6tcp_hdr_s *ipv6hdr; /* The IPv6 header followed by a TCP headers should lie at the * beginning of d_buf since there is no link layer protocol header * and the TCP state machine should only response with TCP packets. */ - ipv6hdr = (FAR struct ipv6_hdr_s *)(dev->d_buf); + ipv6hdr = (FAR struct ipv6tcp_hdr_s *)(dev->d_buf); /* The TCP data payload should follow the IPv6 header plus the * protocol header. */ - if (ipv6hdr->proto != IP_PROTO_TCP) + if (ipv6hdr->ipv6.proto != IP_PROTO_TCP) { - nwarn("WARNING: Expected TCP protoype: %u\n", ipv6hdr->proto); + nwarn("WARNING: Expected TCP protoype: %u vs %s\n", + ipv6hdr->ipv6.proto, IP_PROTO_TCP); } else { struct rimeaddr_s destmac; FAR uint8_t *buf; - size_t buflen; + uint16_t hdrlen; + uint16_t buflen; /* Get the Rime MAC address of the destination. This assumes an * encoding of the MAC address in the IPv6 address. */ - sixlowpan_rimefromip(ipv6hdr->destipaddr, &destmac); + sixlowpan_rimefromip(ipv6hdr->ipv6.destipaddr, &destmac); - /* Convert the outgoing packet into a frame list. */ + /* Get the IPv6 + TCP combined header length. The size of the TCP + * header is encoded in the top 4 bits of the tcpoffset field (in + * units of 32-bit words). + */ - buf = dev->d_buf + sizeof(struct ipv6_hdr_s); - buflen = dev->d_len - sizeof(struct ipv6_hdr_s); + hdrlen = IPv6_HDRLEN + (((uint16_t)ipv6hdr->tcp.tcpoffset >> 4) << 2); - (void)sixlowpan_queue_frames( - (FAR struct ieee802154_driver_s *)dev, ipv6hdr, - buf, buflen, &destmac); + /* Drop the packet if the buffer length is less than this. */ + + if (hdrlen > dev->d_len) + { + nwarn("WARNING: Dropping small TCP packet: %u < %u\n", + buflen, hdrlen); + } + else + { + /* Convert the outgoing packet into a frame list. */ + + buf = dev->d_buf + hdrlen; + buflen = dev->d_len - hdrlen; + + (void)sixlowpan_queue_frames( + (FAR struct ieee802154_driver_s *)dev, &ipv6hdr->ipv6, + buf, buflen, &destmac); + } } } From ee6700dbc7556a3ca7c2f2c00cd6554ce713f700 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 8 Apr 2017 07:30:20 -0600 Subject: [PATCH 08/48] Update README's and some comments. --- Documentation/README.html | 4 +++- README.txt | 2 ++ include/nuttx/net/sixlowpan.h | 26 ++++++++++++++++++-------- net/sixlowpan/README.txt | 30 ++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 net/sixlowpan/README.txt diff --git a/Documentation/README.html b/Documentation/README.html index 01a27ce6446..8cc093715d4 100644 --- a/Documentation/README.html +++ b/Documentation/README.html @@ -8,7 +8,7 @@

NuttX README Files

-

Last Updated: March 23, 2017

+

Last Updated: April 8, 2017

@@ -362,6 +362,8 @@ nuttx/ | | `- README.txt | `- README.txt |- net/ + | |- sixlowpan/ + | | `- README.txt | `- README.txt |- syscall/ | `- README.txt diff --git a/README.txt b/README.txt index 5d3721f4c50..af17a2334dd 100644 --- a/README.txt +++ b/README.txt @@ -1750,6 +1750,8 @@ nuttx/ | | `- README.txt | `- README.txt |- net/ + | |- sixlowpan + | | `- README.txt | `- README.txt |- syscall/ | `- README.txt diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 04b69da6048..dfc8a13a764 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -376,28 +376,38 @@ struct ieee802154_driver_s /* i_dgramtag. Datagram tag to be put in the header of the set of * fragments. It is used by the recipient to match fragments of the * same payload. + * + * This is the sender's copy of the tag. It is incremented after each + * fragmented packet is sent so that it will be unique to that + * sequence fragmentation. Its value is then persistent, the values of + * other fragmentatin variables are valid on during a single + * fragmentation sequence (while i_accumlen > 0) */ uint16_t i_dgramtag; + /* i_reasstag. Each frame in the reassembly has a tag. That tag must + * match the reassembly tag in the fragments being merged. + * + * This is the same tag as i_dgramtag but is saved on the receiving + * side to match all of the fragments of the packet. + */ + + uint16_t i_reasstag; + /* i_pktlen. The total length of the IPv6 packet to be re-assembled in - * d_buf. + * d_buf. Used to determine when the re-assembly is complete. */ uint16_t i_pktlen; /* The current accumulated length of the packet being received in d_buf. - * Included IPv6 and protocol headers. + * Included IPv6 and protocol headers. Currently used only to determine + * there is a fragmentation sequence in progress. */ uint16_t i_accumlen; - /* i_reasstag. Each frame in the reassembly has a tag. That tag must - * match the reassembly tag in the fragments being merged. - */ - - uint16_t i_reasstag; - /* i_boffset. Offset to the beginning of data in d_buf. As each fragment * is received, data is placed at an appriate offset added to this. */ diff --git a/net/sixlowpan/README.txt b/net/sixlowpan/README.txt new file mode 100644 index 00000000000..b9968c318b9 --- /dev/null +++ b/net/sixlowpan/README.txt @@ -0,0 +1,30 @@ +Optimal 6loWPAN Configuration: + +1. Link local IP addresses: + + 128 112 96 80 64 48 32 16 + fe80 0000 0000 0000 xxxx xxxx xxxx xxxx + +2. MAC-based IP addresses: + + 128 112 96 80 64 48 32 16 + ---- ---- ---- ---- ---- ---- ---- ---- + xxxx xxxx xxxx xxxx xxxx 00ff fe00 MMMM 2-byte Rime address IEEE 48-bit MAC + fe80 0000 0000 0000 NNNN NNNN NNNN NNNN 8-byte Rime address IEEE EUI-64 + + Where MMM is the 2-byte rime address XOR 0x0200. For example, the MAC + address of 0xabcd would be 0xa9cd. And NNNN NNNN NNNN NNNN is the 8-byte + rime address address XOR 02000 0000 0000 0000 + +3. MAC based link-local addresses + + 128 112 96 80 64 48 32 16 + ---- ---- ---- ---- ---- ---- ---- ---- + fe80 0000 0000 0000 0000 00ff fe00 MMMM 2-byte Rime address IEEE 48-bit MAC + fe80 0000 0000 0000 NNNN NNNN NNNN NNNN 8-byte Rime address IEEE EUI-64 + +4. Compressable port numbers in the rangs 0xf0b0-0xf0bf + +5. IOBs: Must be big enough to hold one IEEE802.15.4 frame (CONFIG_NET_6LOWPAN_FRAMELEN, + typically 127). There must be enough IOBs to decompose the largest IPv6 + packet (CONFIG_NET_6LOWPAN_MTU, default 1294, plus per frame overhead). \ No newline at end of file From a35845bd095194b7ce9030a72feb8b82bea131fc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 8 Apr 2017 07:48:37 -0600 Subject: [PATCH 09/48] Restore TCP_HDRLEN to MSS calculation. Also add to UDP MSS calculation where it never appearred. Add some missing MSS and RDVWNDO definitinos for 6loWOPAN. --- include/nuttx/net/netconfig.h | 91 +++++++++++++++++------------------ 1 file changed, 45 insertions(+), 46 deletions(-) diff --git a/include/nuttx/net/netconfig.h b/include/nuttx/net/netconfig.h index 9bbd0e9929c..99f00e38563 100644 --- a/include/nuttx/net/netconfig.h +++ b/include/nuttx/net/netconfig.h @@ -295,16 +295,13 @@ #endif /* The UDP maximum packet size. This is should not be to set to more - * than NET_DEV_MTU(d) - NET_LL_HDRLEN(dev) - IPv*_HDRLEN. - * - * REVISIT: It is unclear to me if the UDP_HDRLEN should subtracted - * or not. + * than NET_DEV_MTU(d) - NET_LL_HDRLEN(dev) - UDP_HDRLEN - IPv*_HDRLEN. */ -#define UDP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) (h)) +#define UDP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) - UDP_HDRLEN (h)) #ifdef CONFIG_NET_ETHERNET -# define ETH_UDP_MSS(h) (CONFIG_NET_ETH_MTU - ETH_HDRLEN - (h)) +# define ETH_UDP_MSS(h) (CONFIG_NET_ETH_MTU - ETH_HDRLEN - UDP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_UDP_MSS(h) ETH_UDP_MSS(h) # define __MAX_UDP_MSS(h) ETH_UDP_MSS(h) @@ -312,7 +309,7 @@ #endif #ifdef CONFIG_NET_6LOWPAN -# define IEEE802154_UDP_MSS(h) (CONFIG_NET_6LOWPAN_MAXPAYLOAD - (h)) +# define IEEE802154_UDP_MSS(h) (CONFIG_NET_6LOWPAN_MAXPAYLOAD - UDP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_UDP_MSS(h) IEEE802154_UDP_MSS(h) # define __MAX_UDP_MSS(h) IEEE802154_UDP_MSS(h) @@ -320,7 +317,7 @@ #endif #ifdef CONFIG_NET_LOOPBACK -# define LO_UDP_MSS(h) (NET_LO_MTU - (h)) +# define LO_UDP_MSS(h) (NET_LO_MTU - UDP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_UDP_MSS(h) LO_UDP_MSS(h) # define __MAX_UDP_MSS(h) LO_UDP_MSS(h) @@ -328,7 +325,7 @@ #endif #ifdef CONFIG_NET_SLIP -# define SLIP_UDP_MSS(h) (CONFIG_NET_SLIP_MTU - (h)) +# define SLIP_UDP_MSS(h) (CONFIG_NET_SLIP_MTU - UDP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_UDP_MSS(h) SLIP_UDP_MSS(h) # define __MAX_UDP_MSS(h) SLIP_UDP_MSS(h) @@ -383,27 +380,25 @@ # endif #endif -/* NOTE: MSS calcuation excludes the UDP_HDRLEN. */ - #ifdef CONFIG_NET_IPv4 -# define UDP_IPv4_MSS(d) UDP_MSS(d,IPv4_HDRLEN) -# define ETH_IPv4_UDP_MSS ETH_UDP_MSS(IPv4_HDRLEN) -# define SLIP_IPv4_UDP_MSS SLIP_UDP_MSS(IPv4_HDRLEN) +# define UDP_IPv4_MSS(d) UDP_MSS(d,IPv4_HDRLEN) +# define ETH_IPv4_UDP_MSS ETH_UDP_MSS(IPv4_HDRLEN) +# define SLIP_IPv4_UDP_MSS SLIP_UDP_MSS(IPv4_HDRLEN) -# define MIN_IPv4_UDP_MSS __MIN_UDP_MSS(IPv4_HDRLEN) -# define MIN_UDP_MSS __MIN_UDP_MSS(IPv4_HDRLEN) +# define MIN_IPv4_UDP_MSS __MIN_UDP_MSS(IPv4_HDRLEN) +# define MIN_UDP_MSS __MIN_UDP_MSS(IPv4_HDRLEN) # undef MAX_UDP_MSS -# define MAX_IPv4_UDP_MSS __MAX_UDP_MSS(IPv4_HDRLEN) -# define MAX_UDP_MSS __MAX_UDP_MSS(IPv4_HDRLEN) +# define MAX_IPv4_UDP_MSS __MAX_UDP_MSS(IPv4_HDRLEN) +# define MAX_UDP_MSS __MAX_UDP_MSS(IPv4_HDRLEN) #endif /* If IPv6 is support, it will have the smaller MSS */ #ifdef CONFIG_NET_IPv6 # undef MIN_UDP_MSS -# define MIN_IPv6_UDP_MSS __MIN_UDP_MSS(IPv6_HDRLEN) -# define MIN_UDP_MSS __MIN_UDP_MSS(IPv6_HDRLEN) +# define MIN_IPv6_UDP_MSS __MIN_UDP_MSS(IPv6_HDRLEN) +# define MIN_UDP_MSS __MIN_UDP_MSS(IPv6_HDRLEN) #endif /* TCP configuration options */ @@ -473,17 +468,15 @@ * may support a different UDP MSS value. Here we arbitrarily select * the minimum MSS for that case. * - * REVISIT: It is unclear to me if the TCP_HDRLEN should subtracted - * or not. + * REVISIT: TCP_HDRLEN is not really a constant! */ -#define TCP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) - (h)) -#define LO_TCP_MSS(h) (NET_LO_MTU - (h)) +#define TCP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) - TCP_HDRLEN - (h)) /* Get the smallest and largest MSS */ #ifdef CONFIG_NET_ETHERNET -# define ETH_TCP_MSS(h) (CONFIG_NET_ETH_MTU - ETH_HDRLEN - (h)) +# define ETH_TCP_MSS(h) (CONFIG_NET_ETH_MTU - ETH_HDRLEN - TCP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_TCP_MSS(h) ETH_TCP_MSS(h) # define __MAX_TCP_MSS(h) ETH_TCP_MSS(h) @@ -491,7 +484,7 @@ #endif #ifdef CONFIG_NET_6LOWPAN -# define IEEE802154_TCP_MSS(h) CONFIG_NET_6LOWPAN_MAXPAYLOAD +# define IEEE802154_TCP_MSS(h) (CONFIG_NET_6LOWPAN_MAXPAYLOAD - TCP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_TCP_MSS(h) IEEE802154_TCP_MSS(h) # define __MAX_TCP_MSS(h) IEEE802154_TCP_MSS(h) @@ -499,7 +492,7 @@ #endif #ifdef CONFIG_NET_LOOPBACK -# define LO_TCP_MSS(h) (NET_LO_MTU - (h)) +# define LO_TCP_MSS(h) (NET_LO_MTU - TCP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_TCP_MSS(h) LO_TCP_MSS(h) # define __MAX_TCP_MSS(h) LO_TCP_MSS(h) @@ -507,7 +500,7 @@ #endif #ifdef CONFIG_NET_SLIP -# define SLIP_TCP_MSS(h) (CONFIG_NET_SLIP_MTU - (h)) +# define SLIP_TCP_MSS(h) (CONFIG_NET_SLIP_MTU - TCP_HDRLEN - (h)) # ifndef CONFIG_NET_MULTILINK # define __MIN_TCP_MSS(h) SLIP_TCP_MSS(h) # define __MAX_TCP_MSS(h) SLIP_TCP_MSS(h) @@ -568,26 +561,26 @@ */ #ifdef CONFIG_NET_IPv6 -# define TCP_IPv6_MSS(d) TCP_MSS(d,IPv6_HDRLEN) -# define ETH_IPv6_TCP_MSS ETH_TCP_MSS(IPv6_HDRLEN) -# define SLIP_IPv6_TCP_MSS SLIP_TCP_MSS(IPv6_HDRLEN) -# define MAX_TCP_MSS __MAX_TCP_MSS(IPv6_HDRLEN) +# define TCP_IPv6_MSS(d) TCP_MSS(d,IPv6_HDRLEN) +# define ETH_IPv6_TCP_MSS ETH_TCP_MSS(IPv6_HDRLEN) +# define SLIP_IPv6_TCP_MSS SLIP_TCP_MSS(IPv6_HDRLEN) +# define MAX_TCP_MSS __MAX_TCP_MSS(IPv6_HDRLEN) #endif #ifdef CONFIG_NET_IPv4 -# define TCP_IPv4_MSS(d) TCP_MSS(d,IPv4_HDRLEN) -# define ETH_IPv4_TCP_MSS ETH_TCP_MSS(IPv4_HDRLEN) -# define SLIP_IPv4_TCP_MSS SLIP_TCP_MSS(IPv4_HDRLEN) -# define MIN_TCP_MSS __MIN_TCP_MSS(IPv4_HDRLEN) +# define TCP_IPv4_MSS(d) TCP_MSS(d,IPv4_HDRLEN) +# define ETH_IPv4_TCP_MSS ETH_TCP_MSS(IPv4_HDRLEN) +# define SLIP_IPv4_TCP_MSS SLIP_TCP_MSS(IPv4_HDRLEN) +# define MIN_TCP_MSS __MIN_TCP_MSS(IPv4_HDRLEN) # undef MAX_TCP_MSS -# define MAX_TCP_MSS __MAX_TCP_MSS(IPv4_HDRLEN) +# define MAX_TCP_MSS __MAX_TCP_MSS(IPv4_HDRLEN) #endif /* If IPv6 is supported, it will have the smaller MSS */ #ifdef CONFIG_NET_IPv6 # undef MIN_TCP_MSS -# define MIN_TCP_MSS __MIN_TCP_MSS(IPv6_HDRLEN) +# define MIN_TCP_MSS __MIN_TCP_MSS(IPv6_HDRLEN) #endif /* The size of the advertised receiver's window. @@ -614,22 +607,28 @@ #endif #if defined(CONFIG_NET_MULTILINK) - /* We are supporting multiple network devices using different link layer - * protocols. Get the size of the receive window from the device structure. - */ + /* We are supporting multiple network devices using different link layer + * protocols. Get the size of the receive window from the device + * structure. + */ # define NET_DEV_RCVWNDO(d) ((d)->d_recvwndo) -#elif defined(CONFIG_NET_SLIP) - /* Only SLIP.. use the configured SLIP receive window size */ - -# define NET_DEV_RCVWNDO(d) CONFIG_NET_SLIP_TCP_RECVWNDO - #elif defined(CONFIG_NET_ETHERNET) /* Only Ethernet.. use the configured SLIP receive window size */ # define NET_DEV_RCVWNDO(d) CONFIG_NET_ETH_TCP_RECVWNDO +#elif defined(CONFIG_NET_6LOWPAN) + /* Only 6loWPAN.. use the configured 6loWPAN receive window size */ + +# define NET_DEV_RCVWNDO(d) CONFIG_NET_6LOWPAN_TCP_RECVWNDO + +#elif defined(CONFIG_NET_SLIP) + /* Only SLIP.. use the configured SLIP receive window size */ + +# define NET_DEV_RCVWNDO(d) CONFIG_NET_SLIP_TCP_RECVWNDO + #else /* if defined(CONFIG_NET_LOOPBACK) */ /* Only loal loopback.. use the fixed loopback receive window size */ From dea251783a8cdc12cdeb27655dd159e56a416176 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 8 Apr 2017 08:14:11 -0600 Subject: [PATCH 10/48] pthread.h: Remove duplicate, possible erroneous definitino of PTHREAD_MUTEX_INITIALIZER that crept in with some recent changes. --- include/pthread.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/pthread.h b/include/pthread.h index a75cd9e9015..225a7ef8b03 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -354,10 +354,6 @@ typedef int pthread_rwlockattr_t; PTHREAD_COND_INITIALIZER, \ 0, 0} -#define PTHREAD_MUTEX_INITIALIZER {NULL, SEM_INITIALIZER(1), -1, \ - __PTHREAD_MUTEX_DEFAULT_FLAGS, \ - PTHREAD_MUTEX_DEFAULT, 0} - #ifdef CONFIG_PTHREAD_CLEANUP /* This type describes the pthread cleanup callback (non-standard) */ From fe722e44b98818440e57433cd59d7d0bc0747778 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 8 Apr 2017 08:14:42 -0600 Subject: [PATCH 11/48] 6loWPAN: Fix a faulty assumption about relationship between some sizes and offsets. --- arch/sim/src/up_initialize.c | 2 +- net/sixlowpan/sixlowpan_framelist.c | 34 +++++------------------------ 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/arch/sim/src/up_initialize.c b/arch/sim/src/up_initialize.c index fa8468196e0..5b3f1c0e9f9 100644 --- a/arch/sim/src/up_initialize.c +++ b/arch/sim/src/up_initialize.c @@ -187,7 +187,7 @@ void up_initialize(void) * separately. */ - syslog(LOG_INFO, "SIM: Initializing"); + syslog(LOG_INFO, "SIM: Initializing\n"); #endif #ifdef CONFIG_PM diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 552f394b786..7b36219205f 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -144,9 +144,7 @@ static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr, static void sixlowpan_copy_protohdr(FAR const struct ipv6_hdr_s *ipv6hdr, FAR uint8_t *fptr) { - uint16_t combined; uint16_t protosize; - uint16_t copysize; /* What is the total size of the IPv6 + protocol header? */ @@ -162,7 +160,6 @@ static void sixlowpan_copy_protohdr(FAR const struct ipv6_hdr_s *ipv6hdr, */ protosize = ((uint16_t)tcp->tcpoffset >> 4) << 2; - combined = sizeof(struct ipv6_hdr_s) + protosize; } break; #endif @@ -170,48 +167,27 @@ static void sixlowpan_copy_protohdr(FAR const struct ipv6_hdr_s *ipv6hdr, #ifdef CONFIG_NET_UDP case IP_PROTO_UDP: protosize = sizeof(struct udp_hdr_s); - combined = sizeof(struct ipv6udp_hdr_s); break; #endif #ifdef CONFIG_NET_ICMPv6 case IP_PROTO_ICMP6: protosize = sizeof(struct icmpv6_hdr_s); - combined = sizeof(struct ipv6icmp_hdr_s); break; #endif default: nwarn("WARNING: Unrecognized proto: %u\n", ipv6hdr->proto); - protosize = 0; - combined = sizeof(struct ipv6_hdr_s); - break; + return; } - /* Copy the remaining protocol header. */ - - if (g_uncomp_hdrlen > IPv6_HDRLEN) - { - nwarn("WARNING: Protocol header not copied: " - "g_uncomp_hdren=%u IPv6_HDRLEN=%u\n", - g_uncomp_hdrlen, IPv6_HDRLEN); - return; - } - - copysize = combined - g_uncomp_hdrlen; - if (copysize != protosize) - { - nwarn("WARNING: Protocol header size mismatch: " - "g_uncomp_hdren=%u copysize=%u protosize=%u\n", - g_uncomp_hdrlen, copysize, protosize); - return; - } + /* Copy the protocol header. */ memcpy(fptr + g_frame_hdrlen, (FAR uint8_t *)ipv6hdr + g_uncomp_hdrlen, - copysize); + protosize); - g_frame_hdrlen += copysize; - g_uncomp_hdrlen += copysize; + g_frame_hdrlen += protosize; + g_uncomp_hdrlen += protosize; } /**************************************************************************** From 143b8f9591f39ecc0f1b61cad0c6387fc688de55 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 8 Apr 2017 09:34:30 -0600 Subject: [PATCH 12/48] 6loWPAN: Fix more frame offsets. Reorder some logic that was appropriate only for IPv6 dispatch. --- net/sixlowpan/sixlowpan_framelist.c | 35 +++------------------------- net/sixlowpan/sixlowpan_hc06.c | 18 +++++++-------- net/sixlowpan/sixlowpan_hc1.c | 8 +++---- net/sixlowpan/sixlowpan_input.c | 36 ++++++++++++----------------- net/sixlowpan/sixlowpan_internal.h | 8 +++---- 5 files changed, 35 insertions(+), 70 deletions(-) diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 7b36219205f..d8b751e8a75 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -112,6 +112,8 @@ static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr, FAR uint8_t *fptr) { + uint16_t protosize; + /* Indicate the IPv6 dispatch and length */ fptr[g_frame_hdrlen] = SIXLOWPAN_DISPATCH_IPV6; @@ -122,31 +124,8 @@ static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr, memcpy(&fptr[g_frame_hdrlen] , ipv6hdr, IPv6_HDRLEN); g_frame_hdrlen += IPv6_HDRLEN; g_uncomp_hdrlen += IPv6_HDRLEN; -} -/**************************************************************************** - * Name: sixlowpan_copy_protohdr - * - * Description: - * The IPv6 header should have already been processed (as reflected in the - * g_uncomphdrlen). But we probably still need to copy the following - * protocol header. - * - * Input Parameters: - * ipv6hdr - Pointer to the IPv6 header to "compress" - * fptr - Pointer to the beginning of the frame under construction - * - * Returned Value: - * None. But g_frame_hdrlen and g_uncomp_hdrlen updated. - * - ****************************************************************************/ - -static void sixlowpan_copy_protohdr(FAR const struct ipv6_hdr_s *ipv6hdr, - FAR uint8_t *fptr) -{ - uint16_t protosize; - - /* What is the total size of the IPv6 + protocol header? */ + /* Copy the following protocol header, */ switch (ipv6hdr->proto) { @@ -397,10 +376,6 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; - /* Copy protocol header that follows the IPv6 header */ - - sixlowpan_copy_protohdr(destip, fptr); - /* Copy payload and enqueue. NOTE that the size is a multiple of eight * bytes. */ @@ -527,10 +502,6 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, DEBUGASSERT(verify == framer_hdrlen); UNUSED(verify); - /* Copy protocol header that follows the IPv6 header */ - - sixlowpan_copy_protohdr(destip, fptr); - /* Copy the payload and queue */ memcpy(fptr + g_frame_hdrlen, buf, buflen); diff --git a/net/sixlowpan/sixlowpan_hc06.c b/net/sixlowpan/sixlowpan_hc06.c index 9e51f88c17b..d449f829360 100644 --- a/net/sixlowpan/sixlowpan_hc06.c +++ b/net/sixlowpan/sixlowpan_hc06.c @@ -440,7 +440,7 @@ void sixlowpan_hc06_initialize(void) * ipv6 - The IPv6 header to be compressed * destmac - L2 destination address, needed to compress the IP * destination field - * fptr - Pointer to frame data payload. + * fptr - Pointer to frame to be compressed. * * Returned Value: * None @@ -840,7 +840,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, * inferred from the L2 length), non 0 if the packet is a first * fragment. * iob - Pointer to the IOB containing the received frame. - * payptr - Pointer to the frame data payload. + * fptr - Pointer to frame to be compressed. * * Returned Value: * None @@ -849,7 +849,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee, uint16_t iplen, FAR struct iob_s *iob, - FAR uint8_t *payptr) + FAR uint8_t *fptr) { FAR struct ipv6_hdr_s *ipv6 = IPv6BUF(ieee); FAR uint8_t *iphc; @@ -857,18 +857,18 @@ void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee, uint8_t iphc1; uint8_t tmp; - /* payptr points to IPHC. At least two byte will be used for the encoding. */ + /* iphc points to IPHC. At least two byte will be used for the encoding. */ - iphc = payptr; + iphc = fptr + g_frame_hdrlen; iphc0 = iphc[0]; iphc1 = iphc[1]; /* g_hc96ptr points to just after the 2-byte minimum IPHC */ - g_hc06ptr = payptr + 2; + g_hc06ptr = iphc + 2; - ninfo("payptr=%p g_frame_hdrlen=%u iphc=%02x:%02x:%02x g_hc06ptr=%p\n", - payptr, g_frame_hdrlen, iphc[0], iphc[1], iphc[2], g_hc06ptr); + ninfo("fptr=%p g_frame_hdrlen=%u iphc=%02x:%02x:%02x g_hc06ptr=%p\n", + fptr, g_frame_hdrlen, iphc[0], iphc[1], iphc[2], g_hc06ptr); /* Another if the CID flag is set */ @@ -1171,7 +1171,7 @@ void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee, } } - g_frame_hdrlen = g_hc06ptr - payptr; + g_frame_hdrlen = g_hc06ptr - fptr; /* IP length field. */ diff --git a/net/sixlowpan/sixlowpan_hc1.c b/net/sixlowpan/sixlowpan_hc1.c index 6626501363c..9f657a12dc6 100644 --- a/net/sixlowpan/sixlowpan_hc1.c +++ b/net/sixlowpan/sixlowpan_hc1.c @@ -258,7 +258,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, * inferred from the L2 length), non 0 if the packet is a 1st * fragment. * iob - Pointer to the IOB containing the received frame. - * payptr - Pointer to the frame data payload. + * fptr - Pointer to frame to be uncompressed. * * Returned Value: * Zero (OK) is returned on success, on failure a negater errno value is @@ -268,10 +268,10 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee, uint16_t iplen, FAR struct iob_s *iob, - FAR uint8_t *payptr) + FAR uint8_t *fptr) { FAR struct ipv6_hdr_s *ipv6 = IPv6BUF(&ieee->i_dev); - FAR uint8_t *hc1 = payptr + g_frame_hdrlen; + FAR uint8_t *hc1 = fptr + g_frame_hdrlen; /* Format the IPv6 header in the device d_buf */ /* Set version, traffic clase, and flow label */ @@ -312,7 +312,7 @@ int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee, case SIXLOWPAN_HC1_NH_UDP: { FAR struct udp_hdr_s *udp = UDPIPv6BUF(&ieee->i_dev); - FAR uint8_t *hcudp = payptr + g_frame_hdrlen; + FAR uint8_t *hcudp = fptr + g_frame_hdrlen; ipv6->proto = IP_PROTO_UDP; if ((hcudp[RIME_HC1_HC_UDP_HC1_ENCODING] & 0x01) != 0) diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index 6098a58251c..e491394c7b3 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -224,6 +224,7 @@ int sixlowpan_recv_hdrlen(FAR const uint8_t *fptr) static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, FAR struct iob_s *iob) { + FAR uint8_t *fptr; /* Convenience pointer to beginning of the frame */ FAR uint8_t *hc1; /* Convenience pointer to HC1 data */ uint16_t fragsize = 0; /* Size of the IP packet (read from fragment) */ uint16_t paysize; /* Size of the data payload */ @@ -242,7 +243,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, * This size includes both fragmentation and FCF headers. */ - hdrsize = sixlowpan_recv_hdrlen(iob->io_data); + fptr = iob->io_data; + hdrsize = sixlowpan_recv_hdrlen(fptr); if (hdrsize < 0) { nwarn("Invalid IEEE802.15.2 header: %d\n", hdrsize); @@ -262,7 +264,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, * already includes the fragementation header, if presetn. */ - switch ((GETINT16(iob->io_data, RIME_FRAG_DISPATCH_SIZE) & 0xf800) >> 8) + switch ((GETINT16(fptr, RIME_FRAG_DISPATCH_SIZE) & 0xf800) >> 8) { /* First fragment of new reassembly */ @@ -270,8 +272,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, { /* Set up for the reassembly */ - fragsize = GETINT16(iob->io_data, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; - fragtag = GETINT16(iob->io_data, RIME_FRAG_TAG); + fragsize = GETINT16(fptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; + fragtag = GETINT16(fptr, RIME_FRAG_TAG); ninfo("FRAG1: fragsize=%d fragtag=%d fragoffset=%d\n", fragsize, fragtag, fragoffset); @@ -287,9 +289,9 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, { /* Set offset, tag, size. Offset is in units of 8 bytes. */ - fragoffset = iob->io_data[RIME_FRAG_OFFSET]; - fragtag = GETINT16(iob->io_data, RIME_FRAG_TAG); - fragsize = GETINT16(iob->io_data, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; + fragoffset = fptr[RIME_FRAG_OFFSET]; + fragtag = GETINT16(fptr, RIME_FRAG_TAG); + fragsize = GETINT16(fptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; ninfo("FRAGN: fragsize=%d fragtag=%d fragoffset=%d\n", fragsize, fragtag, fragoffset); @@ -429,19 +431,16 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, /* Process next dispatch and headers */ - hc1 = &iob->io_data[g_frame_hdrlen]; + hc1 = fptr + g_frame_hdrlen; #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06 if ((hc1[RIME_HC1_DISPATCH] & SIXLOWPAN_DISPATCH_IPHC_MASK) == SIXLOWPAN_DISPATCH_IPHC) { - FAR uint8_t *payptr; - ninfo("IPHC Dispatch\n"); /* Payload starts after the IEEE802.15.4 header(s) */ - payptr = &iob->io_data[g_frame_hdrlen]; - sixlowpan_uncompresshdr_hc06(ieee, fragsize, iob, payptr); + sixlowpan_uncompresshdr_hc06(ieee, fragsize, iob, fptr); } else #endif /* CONFIG_NET_6LOWPAN_COMPRESSION_HC06 */ @@ -449,14 +448,11 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1 if (hc1[RIME_HC1_DISPATCH] == SIXLOWPAN_DISPATCH_HC1) { - FAR uint8_t *payptr; - ninfo("HC1 Dispatch\n"); /* Payload starts after the IEEE802.15.4 header(s) */ - payptr = &iob->io_data[g_frame_hdrlen]; - sixlowpan_uncompresshdr_hc1(ieee, fragsize, iob, payptr); + sixlowpan_uncompresshdr_hc1(ieee, fragsize, iob, fptr); } else #endif /* CONFIG_NET_6LOWPAN_COMPRESSION_HC1 */ @@ -470,7 +466,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, /* Put uncompressed IP header in d_buf. */ - memcpy(ipv6, iob->io_data + g_frame_hdrlen, IPv6_HDRLEN); + memcpy(ipv6, fptr + g_frame_hdrlen, IPv6_HDRLEN); /* Update g_uncomp_hdrlen and g_frame_hdrlen. */ @@ -527,8 +523,7 @@ copypayload: } memcpy(ieee->i_dev.d_buf + g_uncomp_hdrlen + (fragoffset << 3), - iob->io_data + g_frame_hdrlen, - paysize); + fptr + g_frame_hdrlen, paysize); #ifdef CONFIG_NET_6LOWPAN_FRAG /* Update ieee->i_accumlen if the frame is a fragment, ieee->i_pktlen @@ -690,8 +685,7 @@ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee) FRAME_IOB_REMOVE(ieee, iob); DEBUGASSERT(iob != NULL); - sixlowpan_dumpbuffer("Incoming frame", - (FAR const uint8_t *)iob->io_data, iob->io_len); + sixlowpan_dumpbuffer("Incoming frame", iob->io_data, iob->io_len); /* Process the frame, decompressing it into the packet buffer */ diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index bd366c884ec..0f04a068b21 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -641,7 +641,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, * inferred from the L2 length), non 0 if the packet is a first * fragment. * iob - Pointer to the IOB containing the received frame. - * payptr - Pointer to the frame data payload. + * fptr - Pointer to frame to be uncompressed. * * Returned Value: * None @@ -651,7 +651,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06 void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee, uint16_t iplen, FAR struct iob_s *iob, - FAR uint8_t *payptr); + FAR uint8_t *fptr); #endif /**************************************************************************** @@ -701,7 +701,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, * inferred from the L2 length), non 0 if the packet is a first * fragment. * iob - Pointer to the IOB containing the received frame. - * payptr - Pointer to the frame data payload. + * fptr - Pointer to frame to be uncompressed. * * Returned Value: * None @@ -711,7 +711,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1 int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee, uint16_t ip_len, FAR struct iob_s *iob, - FAR uint8_t *payptr); + FAR uint8_t *fptr); #endif /**************************************************************************** From 3f51180ccab2de01fcd10e1e14f1c74332afc190 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 8 Apr 2017 10:18:44 -0600 Subject: [PATCH 13/48] 6loWPAN: Fix breakage in IPv6 dispatch caused by fixes to HC1 dispatch; Move some standard definitions from internal header file to include/nuttx/net/sixlowpan.h. Update a README. --- include/nuttx/net/sixlowpan.h | 143 ++++++++++++++++++++++++++++- net/sixlowpan/README.txt | 47 +++++++++- net/sixlowpan/sixlowpan_input.c | 106 +++++++++++++++++---- net/sixlowpan/sixlowpan_internal.h | 139 ---------------------------- 4 files changed, 273 insertions(+), 162 deletions(-) diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index dfc8a13a764..a98cfa457cd 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -63,6 +63,83 @@ * Pre-processor Definitions ****************************************************************************/ +/* Frame format definitions *************************************************/ +/* Fragment header. + * + * The fragment header is used when the payload is too large to fit in a + * single IEEE 802.15.4 frame. The fragment header contains three fields: + * Datagram size, datagram tag and datagram offset. + * + * 1. Datagram size describes the total (un-fragmented) payload. + * 2. Datagram tag identifies the set of fragments and is used to match + * fragments of the same payload. + * 3. Datagram offset identifies the fragment’s offset within the un- + * fragmented payload. + * + * The fragment header length is 4 bytes for the first header and 5 + * bytes for all subsequent headers. + */ + +#define RIME_FRAG_DISPATCH_SIZE 0 /* 16 bit */ +#define RIME_FRAG_TAG 2 /* 16 bit */ +#define RIME_FRAG_OFFSET 4 /* 8 bit */ + +/* Define the Rime buffer as a byte array */ + +#define RIME_HC1_DISPATCH 0 /* 8 bit */ +#define RIME_HC1_ENCODING 1 /* 8 bit */ +#define RIME_HC1_TTL 2 /* 8 bit */ + +#define RIME_HC1_HC_UDP_DISPATCH 0 /* 8 bit */ +#define RIME_HC1_HC_UDP_HC1_ENCODING 1 /* 8 bit */ +#define RIME_HC1_HC_UDP_UDP_ENCODING 2 /* 8 bit */ +#define RIME_HC1_HC_UDP_TTL 3 /* 8 bit */ +#define RIME_HC1_HC_UDP_PORTS 4 /* 8 bit */ +#define RIME_HC1_HC_UDP_CHKSUM 5 /* 16 bit */ + +/* These are some definitions of element values used in the FCF. See the + * IEEE802.15.4 spec for details. + */ + +#define FRAME802154_FRAMETYPE_SHIFT (0) /* Bits 0-2: Frame type */ +#define FRAME802154_FRAMETYPE_MASK (7 << FRAME802154_FRAMETYPE_SHIFT) +#define FRAME802154_SECENABLED_SHIFT (3) /* Bit 3: Security enabled */ +#define FRAME802154_FRAMEPENDING_SHIFT (4) /* Bit 4: Frame pending */ +#define FRAME802154_ACKREQUEST_SHIFT (5) /* Bit 5: ACK request */ +#define FRAME802154_PANIDCOMP_SHIFT (6) /* Bit 6: PANID compression */ + /* Bits 7-9: Reserved */ +#define FRAME802154_DSTADDR_SHIFT (2) /* Bits 10-11: Dest address mode */ +#define FRAME802154_DSTADDR_MASK (3 << FRAME802154_DSTADDR_SHIFT) +#define FRAME802154_VERSION_SHIFT (4) /* Bit 12-13: Frame version */ +#define FRAME802154_VERSION_MASK (3 << FRAME802154_VERSION_SHIFT) +#define FRAME802154_SRCADDR_SHIFT (6) /* Bits 14-15: Source address mode */ +#define FRAME802154_SRCADDR_MASK (3 << FRAME802154_SRCADDR_SHIFT) + +/* Unshifted values for use in struct frame802154_fcf_s */ + +#define FRAME802154_BEACONFRAME (0) +#define FRAME802154_DATAFRAME (1) +#define FRAME802154_ACKFRAME (2) +#define FRAME802154_CMDFRAME (3) + +#define FRAME802154_BEACONREQ (7) + +#define FRAME802154_IEEERESERVED (0) +#define FRAME802154_NOADDR (0) /* Only valid for ACK or Beacon frames */ +#define FRAME802154_SHORTADDRMODE (2) +#define FRAME802154_LONGADDRMODE (3) + +#define FRAME802154_NOBEACONS 0x0f + +#define FRAME802154_BROADCASTADDR 0xffff +#define FRAME802154_BROADCASTPANDID 0xffff + +#define FRAME802154_IEEE802154_2003 (0) +#define FRAME802154_IEEE802154_2006 (1) + +#define FRAME802154_SECURITY_LEVEL_NONE (0) +#define FRAME802154_SECURITY_LEVEL_128 (3) + /* Min and Max compressible UDP ports - HC06 */ #define SIXLOWPAN_UDP_4_BIT_PORT_MIN 0xf0b0 @@ -171,9 +248,71 @@ #define SIXLOWPAN_MAC_STDFRAME 127 -/* Frame buffer helper macros. +/* Address compressibility test macros **************************************/ + +/* Check whether we can compress the IID in address 'a' to 16 bits. This is + * used for unicast addresses only, and is true if the address is on the + * format ::0000:00ff:fe00:XXXX * - * The IEEE802.15.4 MAC driver structures includes a list of IOB + * NOTE: we currently assume 64-bits prefixes + */ + +/* Check whether we can compress the IID in address 'a' to 16 bits. This is + * used for unicast addresses only, and is true if the address is on the + * format ::0000:00ff:fe00:XXXX. + * + * NOTE: we currently assume 64-bits prefixes. Big-endian, network order is + * assumed. + */ + +#define SIXLOWPAN_IS_IID_16BIT_COMPRESSABLE(a) \ + ((((a)[4]) == 0x0000) && (((a)[5]) == HTONS(0x00ff)) && \ + (((a)[6]) == 0xfe00)) + +/* Check whether the 9-bit group-id of the compressed multicast address is + * known. It is true if the 9-bit group is the all nodes or all routers + * group. Parameter 'a' is typed uint8_t * + */ + +#define SIXLOWPAN_IS_MCASTADDR_DECOMPRESSABLE(a) \ + (((*a & 0x01) == 0) && \ + ((*(a + 1) == 0x01) || (*(a + 1) == 0x02))) + +/* Check whether the 112-bit group-id of the multicast address is mappable + * to a 9-bit group-id. It is true if the group is the all nodes or all + * routers group: + * + * XXXX:0000:0000:0000:0000:0000:0000:0001 All nodes address + * XXXX:0000:0000:0000:0000:0000:0000:0002 All routers address + */ + +#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE(a) \ + ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ + (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && \ + ((a)[7] == HTONS(0x0001) || (a)[7] == HTONS(0x0002))) + +/* FFXX:0000:0000:0000:0000:00XX:XXXX:XXXX */ + +#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE48(a) \ + ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ + (a)[4] == 0 && (((a)[5] & HTONS(0xff00)) == 0)) + +/* FFXX:0000:0000:0000:0000:0000:00XX:XXXX */ + +#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE32(a) \ + ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ + (a)[4] == 0 && (a)[5] == 0 && ((a)[6] & HTONS(0xff00)) == 0) + +/* FF02:0000:0000:0000:0000:0000:0000:00XX */ + +#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE8(a) \ + ((((a)[0] & HTONS(0x00ff)) == HTONS(0x0002)) && \ + (a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ + (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && \ + (((a)[7] & HTONS(0xff00)) == 0x0000)) + +/* Frame buffer helper macros ***********************************************/ +/* The IEEE802.15.4 MAC driver structures includes a list of IOB * structures, i_framelist, containing frames to be sent by the driver or * that were received by the driver. The IOB structure is defined in * include/nuttx/net/iob.h. The length of data in the IOB is provided by diff --git a/net/sixlowpan/README.txt b/net/sixlowpan/README.txt index b9968c318b9..643735dd869 100644 --- a/net/sixlowpan/README.txt +++ b/net/sixlowpan/README.txt @@ -1,4 +1,5 @@ -Optimal 6loWPAN Configuration: +Optimal 6loWPAN Configuration +----------------------------- 1. Link local IP addresses: @@ -27,4 +28,46 @@ Optimal 6loWPAN Configuration: 5. IOBs: Must be big enough to hold one IEEE802.15.4 frame (CONFIG_NET_6LOWPAN_FRAMELEN, typically 127). There must be enough IOBs to decompose the largest IPv6 - packet (CONFIG_NET_6LOWPAN_MTU, default 1294, plus per frame overhead). \ No newline at end of file + packet (CONFIG_NET_6LOWPAN_MTU, default 1294, plus per frame overhead). + +Fragmentation Headers +--------------------- +A fragment header is placed at the beginning of the outgoing packet when the +payload is too large to fit in a single IEEE 802.15.4 frame. The fragment +header contains three fields: Datagram size, datagram tag and datagram +offset. + +1. Datagram size describes the total (un-fragmented) payload. +2. Datagram tag identifies the set of fragments and is used to match + fragments of the same payload. +3. Datagram offset identifies the fragment’s offset within the un- + fragmented payload (in units of 8 bytes). + +The length of the fragment header length is four bytes for the first header +(FRAG1) and five bytes for all subsequent headers (FRAGN). For example, +this is a HC1 compressed first frame of a packet + + c50e 000b ### 4-byte FRAG1 header + 01 08 01 0000 3412 ### 7-byte FCF header + 42 ### SIXLOWPAN_DISPATCH_HC1 + fb ### RIME_HC1_HC_UDP_HC1_ENCODING + e0 ### RIME_HC1_HC_UDP_UDP_ENCODING + 00 ### RIME_HC1_HC_UDP_TTL + 10 ### RIME_HC1_HC_UDP_PORTS + 0000 ### RIME_HC1_HC_UDP_CHKSUM + 4f4e452064617920 48656e6e792d7065 6e6e792077617320 7069636b696e6720 ### 80 byte payload + 757020636f726e20 696e207468652063 6f726e7961726420 7768656e2d2d7768 + 61636b212d2d736f 6d657468696e6720 g + +This is the second frame of the same transfer: + + e50e 000b 0a ### 5 byte FRAGN header + 01 08 01 0000 3412 ### 7-byte FCF header + 6869742068657220 75706f6e20746865 20686561642e2027 476f6f646e657373 ### 88 byte payload + 2067726163696f75 73206d6521272073 6169642048656e6e 792d70656e6e793b + 202774686520736b 79277320612d676f 696e6720746f2066 + +The payload length is encoded in the LS 11-bits of the first 16-bit value: +In this example the payload size is 0x050e or 1,294. The tag is 0x000b. In +the second frame, the fifth byte contains the offset 0x0a which is 10 << 3 = +80 bytes, the size of the payload on the first packet. diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index e491394c7b3..b19fa8ffba0 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -190,6 +190,91 @@ int sixlowpan_recv_hdrlen(FAR const uint8_t *fptr) return 0; } +/**************************************************************************** + * Name: sixlowpan_compress_ipv6hdr + * + * Description: + * IPv6 dispatch "compression" function. Packets "Compression" when only + * IPv6 dispatch is used + * + * There is no compression in this case, all fields are sent + * inline. We just add the IPv6 dispatch byte before the packet. + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | IPv6 Dsp | IPv6 header and payload ... + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + * Input Parameters: + * ieee - The IEEE802.15.4 MAC network driver interface. + * fptr - Pointer to the beginning of the frame under construction + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void sixlowpan_uncompress_ipv6hdr(FAR struct ieee802154_driver_s *ieee, + FAR uint8_t *fptr) +{ + FAR struct ipv6_hdr_s *ipv6 = IPv6BUF(&ieee->i_dev); + uint16_t protosize; + + /* Put uncompressed IPv6 header in d_buf. */ + + g_frame_hdrlen += SIXLOWPAN_IPV6_HDR_LEN; + memcpy(ipv6, fptr + g_frame_hdrlen, IPv6_HDRLEN); + + /* Update g_uncomp_hdrlen and g_frame_hdrlen. */ + + g_frame_hdrlen += IPv6_HDRLEN; + g_uncomp_hdrlen += IPv6_HDRLEN; + + /* Copy the following protocol header, */ + + switch (ipv6->proto) + { +#ifdef CONFIG_NET_TCP + case IP_PROTO_TCP: + { + FAR struct tcp_hdr_s *tcp = &((FAR struct ipv6tcp_hdr_s *)ipv6)->tcp; + + /* The TCP header length is encoded in the top 4 bits of the + * tcpoffset field (in units of 32-bit words). + */ + + protosize = ((uint16_t)tcp->tcpoffset >> 4) << 2; + } + break; +#endif + +#ifdef CONFIG_NET_UDP + case IP_PROTO_UDP: + protosize = sizeof(struct udp_hdr_s); + break; +#endif + +#ifdef CONFIG_NET_ICMPv6 + case IP_PROTO_ICMP6: + protosize = sizeof(struct icmpv6_hdr_s); + break; +#endif + + default: + nwarn("WARNING: Unrecognized proto: %u\n", ipv6->proto); + return; + } + + /* Copy the protocol header. */ + + memcpy((FAR uint8_t *)ipv6 + g_uncomp_hdrlen, fptr + g_frame_hdrlen, + protosize); + + g_frame_hdrlen += protosize; + g_uncomp_hdrlen += protosize; +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -437,9 +522,6 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, if ((hc1[RIME_HC1_DISPATCH] & SIXLOWPAN_DISPATCH_IPHC_MASK) == SIXLOWPAN_DISPATCH_IPHC) { ninfo("IPHC Dispatch\n"); - - /* Payload starts after the IEEE802.15.4 header(s) */ - sixlowpan_uncompresshdr_hc06(ieee, fragsize, iob, fptr); } else @@ -449,29 +531,15 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, if (hc1[RIME_HC1_DISPATCH] == SIXLOWPAN_DISPATCH_HC1) { ninfo("HC1 Dispatch\n"); - - /* Payload starts after the IEEE802.15.4 header(s) */ - - sixlowpan_uncompresshdr_hc1(ieee, fragsize, iob, fptr); + sixlowpan_uncompresshdr_hc1(ieee, fragsize, iob, fptr); } else #endif /* CONFIG_NET_6LOWPAN_COMPRESSION_HC1 */ if (hc1[RIME_HC1_DISPATCH] == SIXLOWPAN_DISPATCH_IPV6) { - FAR struct ipv6_hdr_s *ipv6 = IPv6BUF(&ieee->i_dev); - ninfo("IPv6 Dispatch\n"); - g_frame_hdrlen += SIXLOWPAN_IPV6_HDR_LEN; - - /* Put uncompressed IP header in d_buf. */ - - memcpy(ipv6, fptr + g_frame_hdrlen, IPv6_HDRLEN); - - /* Update g_uncomp_hdrlen and g_frame_hdrlen. */ - - g_frame_hdrlen += IPv6_HDRLEN; - g_uncomp_hdrlen += IPv6_HDRLEN; + sixlowpan_uncompress_ipv6hdr(ieee, fptr); } else { diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index 0f04a068b21..54456863736 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -84,82 +84,6 @@ /* Pointers in the Rime buffer */ -/* Fragment header. - * - * The fragment header is used when the payload is too large to fit in a - * single IEEE 802.15.4 frame. The fragment header contains three fields: - * Datagram size, datagram tag and datagram offset. - * - * 1. Datagram size describes the total (un-fragmented) payload. - * 2. Datagram tag identifies the set of fragments and is used to match - * fragments of the same payload. - * 3. Datagram offset identifies the fragment’s offset within the un- - * fragmented payload. - * - * The fragment header length is 4 bytes for the first header and 5 - * bytes for all subsequent headers. - */ - -#define RIME_FRAG_DISPATCH_SIZE 0 /* 16 bit */ -#define RIME_FRAG_TAG 2 /* 16 bit */ -#define RIME_FRAG_OFFSET 4 /* 8 bit */ - -/* Define the Rime buffer as a byte array */ - -#define RIME_HC1_DISPATCH 0 /* 8 bit */ -#define RIME_HC1_ENCODING 1 /* 8 bit */ -#define RIME_HC1_TTL 2 /* 8 bit */ - -#define RIME_HC1_HC_UDP_DISPATCH 0 /* 8 bit */ -#define RIME_HC1_HC_UDP_HC1_ENCODING 1 /* 8 bit */ -#define RIME_HC1_HC_UDP_UDP_ENCODING 2 /* 8 bit */ -#define RIME_HC1_HC_UDP_TTL 3 /* 8 bit */ -#define RIME_HC1_HC_UDP_PORTS 4 /* 8 bit */ -#define RIME_HC1_HC_UDP_CHKSUM 5 /* 16 bit */ - -/* These are some definitions of element values used in the FCF. See the - * IEEE802.15.4 spec for details. - */ - -#define FRAME802154_FRAMETYPE_SHIFT (0) /* Bits 0-2: Frame type */ -#define FRAME802154_FRAMETYPE_MASK (7 << FRAME802154_FRAMETYPE_SHIFT) -#define FRAME802154_SECENABLED_SHIFT (3) /* Bit 3: Security enabled */ -#define FRAME802154_FRAMEPENDING_SHIFT (4) /* Bit 4: Frame pending */ -#define FRAME802154_ACKREQUEST_SHIFT (5) /* Bit 5: ACK request */ -#define FRAME802154_PANIDCOMP_SHIFT (6) /* Bit 6: PANID compression */ - /* Bits 7-9: Reserved */ -#define FRAME802154_DSTADDR_SHIFT (2) /* Bits 10-11: Dest address mode */ -#define FRAME802154_DSTADDR_MASK (3 << FRAME802154_DSTADDR_SHIFT) -#define FRAME802154_VERSION_SHIFT (4) /* Bit 12-13: Frame version */ -#define FRAME802154_VERSION_MASK (3 << FRAME802154_VERSION_SHIFT) -#define FRAME802154_SRCADDR_SHIFT (6) /* Bits 14-15: Source address mode */ -#define FRAME802154_SRCADDR_MASK (3 << FRAME802154_SRCADDR_SHIFT) - -/* Unshifted values for use in struct frame802154_fcf_s */ - -#define FRAME802154_BEACONFRAME (0) -#define FRAME802154_DATAFRAME (1) -#define FRAME802154_ACKFRAME (2) -#define FRAME802154_CMDFRAME (3) - -#define FRAME802154_BEACONREQ (7) - -#define FRAME802154_IEEERESERVED (0) -#define FRAME802154_NOADDR (0) /* Only valid for ACK or Beacon frames */ -#define FRAME802154_SHORTADDRMODE (2) -#define FRAME802154_LONGADDRMODE (3) - -#define FRAME802154_NOBEACONS 0x0f - -#define FRAME802154_BROADCASTADDR 0xffff -#define FRAME802154_BROADCASTPANDID 0xffff - -#define FRAME802154_IEEE802154_2003 (0) -#define FRAME802154_IEEE802154_2006 (1) - -#define FRAME802154_SECURITY_LEVEL_NONE (0) -#define FRAME802154_SECURITY_LEVEL_128 (3) - /* Packet buffer Definitions */ #define PACKETBUF_ATTR_PACKET_TYPE_DATA 0 @@ -215,69 +139,6 @@ #define PACKETBUF_NUM_ADDRS 4 -/* Address compressibility test macros **************************************/ - -/* Check whether we can compress the IID in address 'a' to 16 bits. This is - * used for unicast addresses only, and is true if the address is on the - * format ::0000:00ff:fe00:XXXX - * - * NOTE: we currently assume 64-bits prefixes - */ - -/* Check whether we can compress the IID in address 'a' to 16 bits. This is - * used for unicast addresses only, and is true if the address is on the - * format ::0000:00ff:fe00:XXXX. - * - * NOTE: we currently assume 64-bits prefixes. Big-endian, network order is - * assumed. - */ - -#define SIXLOWPAN_IS_IID_16BIT_COMPRESSABLE(a) \ - ((((a)[4]) == 0x0000) && (((a)[5]) == HTONS(0x00ff)) && \ - (((a)[6]) == 0xfe00)) - -/* Check whether the 9-bit group-id of the compressed multicast address is - * known. It is true if the 9-bit group is the all nodes or all routers - * group. Parameter 'a' is typed uint8_t * - */ - -#define SIXLOWPAN_IS_MCASTADDR_DECOMPRESSABLE(a) \ - (((*a & 0x01) == 0) && \ - ((*(a + 1) == 0x01) || (*(a + 1) == 0x02))) - -/* Check whether the 112-bit group-id of the multicast address is mappable - * to a 9-bit group-id. It is true if the group is the all nodes or all - * routers group: - * - * XXXX:0000:0000:0000:0000:0000:0000:0001 All nodes address - * XXXX:0000:0000:0000:0000:0000:0000:0002 All routers address - */ - -#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE(a) \ - ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ - (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && \ - ((a)[7] == HTONS(0x0001) || (a)[7] == HTONS(0x0002))) - -/* FFXX:0000:0000:0000:0000:00XX:XXXX:XXXX */ - -#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE48(a) \ - ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ - (a)[4] == 0 && (((a)[5] & HTONS(0xff00)) == 0)) - -/* FFXX:0000:0000:0000:0000:0000:00XX:XXXX */ - -#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE32(a) \ - ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ - (a)[4] == 0 && (a)[5] == 0 && ((a)[6] & HTONS(0xff00)) == 0) - -/* FF02:0000:0000:0000:0000:0000:0000:00XX */ - -#define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE8(a) \ - ((((a)[0] & HTONS(0x00ff)) == HTONS(0x0002)) && \ - (a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ - (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && \ - (((a)[7] & HTONS(0xff00)) == 0x0000)) - /* General helper macros ****************************************************/ #define GETINT16(ptr,index) \ From 35ca7331084bd79f1e2fcb5b05eb3b82af9a287d Mon Sep 17 00:00:00 2001 From: Mark Schulte Date: Sat, 8 Apr 2017 12:34:08 -0600 Subject: [PATCH 14/48] pthread.h: Fix rwlock initializer --- configs/sim/sixlowpan/defconfig | 2 +- include/nuttx/net/sixlowpan.h | 13 ++- include/pthread.h | 2 +- net/netdev/netdev_ioctl.c | 4 +- net/procfs/netdev_statistics.c | 30 +++--- net/sixlowpan/Kconfig | 11 ++- net/sixlowpan/sixlowpan_framer.c | 20 ++-- net/sixlowpan/sixlowpan_internal.h | 6 +- net/sixlowpan/sixlowpan_utils.c | 24 ++--- wireless/ieee802154/mac802154_loopback.c | 113 +++++++++++++---------- 10 files changed, 122 insertions(+), 103 deletions(-) diff --git a/configs/sim/sixlowpan/defconfig b/configs/sim/sixlowpan/defconfig index ac4d9e35ded..0c6809ad43e 100644 --- a/configs/sim/sixlowpan/defconfig +++ b/configs/sim/sixlowpan/defconfig @@ -539,7 +539,7 @@ CONFIG_NET_6LOWPAN_MAXADDRCONTEXT=1 CONFIG_NET_6LOWPAN_MAXADDRCONTEXT_PREFIX_0_0=0xaa CONFIG_NET_6LOWPAN_MAXADDRCONTEXT_PREFIX_0_1=0xaa # CONFIG_NET_6LOWPAN_MAXADDRCONTEXT_PREINIT_1 is not set -CONFIG_NET_6LOWPAN_RIMEADDR_SIZE=2 +# CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED is not set CONFIG_NET_6LOWPAN_MAXAGE=20 CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS=4 CONFIG_NET_6LOWPAN_MAXPAYLOAD=102 diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index a98cfa457cd..e2f3eaf1f7d 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -63,6 +63,17 @@ * Pre-processor Definitions ****************************************************************************/ +/* By default, a 2-byte Rime address is used for the IEEE802.15.4 MAC + * device's link layer address. If CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED + * is selected, then an 8-byte Rime address will be used. + */ + +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED +# define NET_6LOWPAN_RIMEADDR_SIZE 8 +#else +# define NET_6LOWPAN_RIMEADDR_SIZE 2 +#endif + /* Frame format definitions *************************************************/ /* Fragment header. * @@ -374,7 +385,7 @@ struct rimeaddr_s { - uint8_t u8[CONFIG_NET_6LOWPAN_RIMEADDR_SIZE]; + uint8_t u8[NET_6LOWPAN_RIMEADDR_SIZE]; }; /* The device structure for IEEE802.15.4 MAC network device differs from the diff --git a/include/pthread.h b/include/pthread.h index 225a7ef8b03..e70ad06e5be 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -352,7 +352,7 @@ typedef int pthread_rwlockattr_t; #define PTHREAD_RWLOCK_INITIALIZER {PTHREAD_MUTEX_INITIALIZER, \ PTHREAD_COND_INITIALIZER, \ - 0, 0} + 0, 0, false} #ifdef CONFIG_PTHREAD_CLEANUP /* This type describes the pthread cleanup callback (non-standard) */ diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 413a5d10fc8..1a845774fcd 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -739,7 +739,7 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd, req->ifr_hwaddr.sa_family = AF_INETX; memcpy(req->ifr_hwaddr.sa_data, ieee->i_nodeaddr.u8, - CONFIG_NET_6LOWPAN_RIMEADDR_SIZE); + NET_6LOWPAN_RIMEADDR_SIZE); ret = OK; } else @@ -782,7 +782,7 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd, req->ifr_hwaddr.sa_family = AF_INETX; memcpy(ieee->i_nodeaddr.u8, req->ifr_hwaddr.sa_data, - CONFIG_NET_6LOWPAN_RIMEADDR_SIZE); + NET_6LOWPAN_RIMEADDR_SIZE); ret = OK; } else diff --git a/net/procfs/netdev_statistics.c b/net/procfs/netdev_statistics.c index d7673507b73..b2b83da8012 100644 --- a/net/procfs/netdev_statistics.c +++ b/net/procfs/netdev_statistics.c @@ -151,12 +151,7 @@ static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile) { ieee = (FAR struct ieee802154_driver_s *)dev; -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - len += snprintf(&netfile->line[len], NET_LINELEN - len, - "%s\tLink encap:6loWPAN HWaddr %02x:%02x", - dev->d_ifname, - ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1]); -#else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED len += snprintf(&netfile->line[len], NET_LINELEN - len, "%s\tLink encap:6loWPAN HWaddr " "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", @@ -165,6 +160,11 @@ static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile) ieee->i_nodeaddr.u8[2], ieee->i_nodeaddr.u8[3], ieee->i_nodeaddr.u8[4], ieee->i_nodeaddr.u8[5], ieee->i_nodeaddr.u8[6], ieee->i_nodeaddr.u8[7]); +#else + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:6loWPAN HWaddr %02x:%02x", + dev->d_ifname, + ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1]); #endif } break; @@ -215,22 +215,22 @@ static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile) #elif defined(CONFIG_NET_6LOWPAN) ieee = (FAR struct ieee802154_driver_s *)dev; -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - len += snprintf(&netfile->line[len], NET_LINELEN - len, - "%s\tLink encap:6loWPAN HWaddr %02x:%02x at %s", - dev->d_ifname, - ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1], - status); -#else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED len += snprintf(&netfile->line[len], NET_LINELEN - len, "%s\tLink encap:6loWPAN HWaddr " - "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x at %s", + "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x at %s\n", dev->d_ifname, ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1], ieee->i_nodeaddr.u8[2], ieee->i_nodeaddr.u8[3], ieee->i_nodeaddr.u8[4], ieee->i_nodeaddr.u8[5], ieee->i_nodeaddr.u8[6], ieee->i_nodeaddr.u8[7], status); +#else + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:6loWPAN HWaddr %02x:%02x at %s\n", + dev->d_ifname, + ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1], + status); #endif #elif defined(CONFIG_NET_LOOPBACK) len += snprintf(&netfile->line[len], NET_LINELEN - len, @@ -443,7 +443,7 @@ static int netprocfs_txstatistics_header(FAR struct netprocfs_file_s *netfile) DEBUGASSERT(netfile != NULL); return snprintf(netfile->line, NET_LINELEN, "\tTX: %-8s %-8s %-8s %-8s\n", - "Queued", "Sent", "Erorts", "Timeouts"); + "Queued", "Sent", "Errors", "Timeouts"); } #endif /* CONFIG_NETDEV_STATISTICS */ diff --git a/net/sixlowpan/Kconfig b/net/sixlowpan/Kconfig index 02d17a42f1c..a5eed25dd76 100644 --- a/net/sixlowpan/Kconfig +++ b/net/sixlowpan/Kconfig @@ -133,12 +133,13 @@ config NET_6LOWPAN_MAXADDRCONTEXT_PREFIX_2_1 endif # NET_6LOWPAN_MAXADDRCONTEXT_PREINIT_0 endif # NET_6LOWPAN_COMPRESSION_HC06 -config NET_6LOWPAN_RIMEADDR_SIZE - int "Rime address size" - default 2 - range 2 8 +config NET_6LOWPAN_RIMEADDR_EXTENDED + int "Extended Rime address" + default n ---help--- - Only the values 2 and 8 are supported + By default, a 2-byte Rime address is used for the IEEE802.15.4 MAC + device's link layer address. If this option is selected, then an + 8-byte Rime address will be used. config NET_6LOWPAN_MAXAGE int "Packet reassembly timeout" diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index b0953db648c..746d6dc1139 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -125,11 +125,7 @@ static inline uint8_t sixlowpan_addrlen(uint8_t addrmode) static bool sixlowpan_addrnull(FAR uint8_t *addr) { -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - int i = 2; -#else - int i = 8; -#endif + int i = NET_6LOWPAN_RIMEADDR_SIZE; while (i-- > 0) { @@ -354,10 +350,10 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee, /* Use short address mode if so configured */ -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - params->fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; -#else +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED params->fcf.dest_addr_mode = FRAME802154_LONGADDRMODE; +#else + params->fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; #endif } @@ -543,14 +539,14 @@ int sixlowpan_framecreate(FAR struct ieee802154_driver_s *ieee, wlinfo("Frame type: %02x hdrlen: %d\n", params.fcf.frame_type, hdrlen); -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - wlinfo("Dest address: %02x:%02x\n", - params.dest_addr[0], params.dest_addr[1]); -#else +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED wlinfo("Dest address: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", params.dest_addr[0], params.dest_addr[1], params.dest_addr[2], params.dest_addr[3], params.dest_addr[4], params.dest_addr[5], params.dest_addr[6], params.dest_addr[7]); +#else + wlinfo("Dest address: %02x:%02x\n", + params.dest_addr[0], params.dest_addr[1]); #endif return hdrlen; diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index 54456863736..da104f89be5 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -74,13 +74,13 @@ /* Rime addres macros */ /* Copy a Rime address */ -#define rimeaddr_copy(dest,src) \ - memcpy(dest, src, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE) +#define rimeaddr_copy(dest,src) \ + memcpy(dest, src, NET_6LOWPAN_RIMEADDR_SIZE) /* Compare two Rime addresses */ #define rimeaddr_cmp(addr1,addr2) \ - (memcmp(addr1, addr2, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE) == 0) + (memcmp(addr1, addr2, NET_6LOWPAN_RIMEADDR_SIZE) == 0) /* Pointers in the Rime buffer */ diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index fc322ec38e1..dcda6be652d 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -88,14 +88,14 @@ void sixlowpan_ipfromrime(FAR const struct rimeaddr_s *rime, memset(ipaddr, 0, sizeof(net_ipv6addr_t)); ipaddr[0] = HTONS(0xfe80); -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED + memcpy(&ipaddr[4], rime, NET_6LOWPAN_RIMEADDR_SIZE); + ipaddr[4] ^= HTONS(0x0200); +#else ipaddr[5] = HTONS(0x00ff); ipaddr[6] = HTONS(0xfe00); - memcpy(&ipaddr[7], rime, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE); + memcpy(&ipaddr[7], rime, NET_6LOWPAN_RIMEADDR_SIZE); ipaddr[7] ^= HTONS(0x0200); -#else - memcpy(&ipaddr[4], rime, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE); - ipaddr[4] ^= HTONS(0x0200); #endif } @@ -119,10 +119,10 @@ void sixlowpan_rimefromip(const net_ipv6addr_t ipaddr, DEBUGASSERT(ipaddr[0] == HTONS(0xfe80)); -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - memcpy(rime, &ipaddr[7], CONFIG_NET_6LOWPAN_RIMEADDR_SIZE); +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED + memcpy(rime, &ipaddr[4], NET_6LOWPAN_RIMEADDR_SIZE); #else - memcpy(rime, &ipaddr[4], CONFIG_NET_6LOWPAN_RIMEADDR_SIZE); + memcpy(rime, &ipaddr[7], NET_6LOWPAN_RIMEADDR_SIZE); #endif rime->u8[0] ^= 0x02; } @@ -145,14 +145,14 @@ bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, { FAR const uint8_t *rimeptr = rime->u8; -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - return (ipaddr[5] == HTONS(0x00ff) && ipaddr[6] == HTONS(0xfe00) && - ipaddr[7] == htons((GETINT16(rimeptr, 0) ^ 0x0200))); -#else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED return (ipaddr[4] == htons((GETINT16(rimeptr, 0) ^ 0x0200)) && ipaddr[5] == GETINT16(rimeptr, 2) && ipaddr[6] == GETINT16(rimeptr, 4) && ipaddr[7] == GETINT16(rimeptr, 6)); +#else + return (ipaddr[5] == HTONS(0x00ff) && ipaddr[6] == HTONS(0xfe00) && + ipaddr[7] == htons((GETINT16(rimeptr, 0) ^ 0x0200))); #endif } diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index 9cb9f096413..994289642b3 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -195,57 +195,68 @@ static int lo_txpoll(FAR struct net_driver_s *dev) while (head != NULL) { - /* Remove the IOB from the queue */ + /* Increment statistics */ - iob = head; - head = iob->io_flink; - iob->io_flink = NULL; + NETDEV_RXPACKETS(&priv->lo_ieee.i_dev); - /* Is the queue now empty? */ + /* Remove the IOB from the queue */ - if (head == NULL) - { - tail = NULL; - } + iob = head; + head = iob->io_flink; + iob->io_flink = NULL; - /* Return the next frame to the network */ + /* Is the queue now empty? */ - iob->io_flink = NULL; - priv->lo_ieee.i_framelist = iob; + if (head == NULL) + { + tail = NULL; + } - ninfo("Send frame %p to the network. Length=%u\n", iob, iob->io_len); - ret = sixlowpan_input(&priv->lo_ieee); - if (ret < 0) - { - nerr("ERROR: sixlowpan_input returned %d\n", ret); - } + /* Return the next frame to the network */ - /* What if the network responds with more frames to send? */ + iob->io_flink = NULL; + priv->lo_ieee.i_framelist = iob; - if (priv->lo_ieee.i_framelist != NULL) - { - /* Append the new list to the tail of the queue */ + ninfo("Send frame %p to the network. Length=%u\n", iob, iob->io_len); + ret = sixlowpan_input(&priv->lo_ieee); - iob = priv->lo_ieee.i_framelist; - priv->lo_ieee.i_framelist = NULL; + /* Increment statistics */ - if (tail == NULL) - { - head = iob; - } - else - { - tail->io_flink = iob; - } + NETDEV_TXPACKETS(&priv->lo_ieee.i_dev); - /* Find the new tail of the IOB queue */ + if (ret < 0) + { + nerr("ERROR: sixlowpan_input returned %d\n", ret); + NETDEV_TXERRORS(&priv->lo_ieee.i_dev); + NETDEV_ERRORS(&priv->lo_ieee.i_dev); + } - for (tail = iob, iob = iob->io_flink; - iob != NULL; - tail = iob, iob = iob->io_flink); - } + /* What if the network responds with more frames to send? */ - priv->lo_txdone = true; + if (priv->lo_ieee.i_framelist != NULL) + { + /* Append the new list to the tail of the queue */ + + iob = priv->lo_ieee.i_framelist; + priv->lo_ieee.i_framelist = NULL; + + if (tail == NULL) + { + head = iob; + } + else + { + tail->io_flink = iob; + } + + /* Find the new tail of the IOB queue */ + + for (tail = iob, iob = iob->io_flink; + iob != NULL; + tail = iob, iob = iob->io_flink); + } + + priv->lo_txdone = true; } return 0; @@ -352,17 +363,17 @@ static int lo_ifup(FAR struct net_driver_s *dev) dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5], dev->d_ipv6addr[6], dev->d_ipv6addr[7]); -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - ninfo(" Node: %02x:%02x PANID=%04x\n", - priv->lo_ieee.i_nodeaddr.u8[0], priv->lo_ieee.i_nodeaddr.u8[1], - priv->lo_ieee.i_panid); -#else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED ninfo(" Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x PANID=%04x\n", priv->lo_ieee.i_nodeaddr.u8[0], priv->lo_ieee.i_nodeaddr.u8[1], priv->lo_ieee.i_nodeaddr.u8[2], priv->lo_ieee.i_nodeaddr.u8[3], priv->lo_ieee.i_nodeaddr.u8[4], priv->lo_ieee.i_nodeaddr.u8[5], priv->lo_ieee.i_nodeaddr.u8[6], priv->lo_ieee.i_nodeaddr.u8[7], priv->lo_ieee.i_panid); +#else + ninfo(" Node: %02x:%02x PANID=%04x\n", + priv->lo_ieee.i_nodeaddr.u8[0], priv->lo_ieee.i_nodeaddr.u8[1], + priv->lo_ieee.i_panid); #endif /* Set and activate a timer process */ @@ -508,12 +519,12 @@ static int lo_txavail(FAR struct net_driver_s *dev) #if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) { -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - ninfo("MAC: %02x:%02x\n", - mac[0], mac[1]); -#else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED ninfo("MAC: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], mac[6], mac[7]); +#else + ninfo("MAC: %02x:%02x\n", + mac[0], mac[1]); #endif /* There is no multicast support in the loopback driver */ @@ -543,12 +554,12 @@ static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) #ifdef CONFIG_NET_IGMP static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) { -#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - ninfo("MAC: %02x:%02x\n", - mac[0], mac[1]); -#else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ +#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED ninfo("MAC: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], mac[6], mac[7]); +#else + ninfo("MAC: %02x:%02x\n", + mac[0], mac[1]); #endif /* There is no multicast support in the loopback driver */ From 8b8ddd05c28a3ba25e8ae2f7fb19330bfb89bdf0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 8 Apr 2017 13:30:30 -0600 Subject: [PATCH 15/48] Fix some old-style interrupt handling logic in drivers/net/skeleton.c --- drivers/net/skeleton.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index d354ab8130b..9a8d4e8eedd 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -136,6 +136,10 @@ struct skel_driver_s /* A single packet buffer per device is used here. There might be multiple * packet buffers in a more complex, pipelined design. + * + * NOTE that if CONFIG_skeleton_NINTERFACES were greater than 1, you would + * need a minimum on one packetbuffer per instance. Much better to be + * allocated dynamically. */ static uint8_t g_pktbuf[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE]; @@ -557,7 +561,9 @@ static void skel_interrupt_work(FAR void *arg) static int skel_interrupt(int irq, FAR void *context, FAR void *arg) { - FAR struct skel_driver_s *priv = &g_skel[0]; + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg; + + DEBUGASSERT(priv != NULL); /* Disable further Ethernet interrupts. Because Ethernet interrupts are * also disabled if the TX timeout event occurs, there can be no race @@ -1101,7 +1107,7 @@ int skel_initialize(int intf) /* Attach the IRQ to the driver */ - if (irq_attach(CONFIG_skeleton_IRQ, skel_interrupt, NULL)) + if (irq_attach(CONFIG_skeleton_IRQ, skel_interrupt, priv)) { /* We could not attach the ISR to the interrupt */ From a1aca89d6115301f153de280b3587184ed248079 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 8 Apr 2017 13:55:23 -0600 Subject: [PATCH 16/48] drivers/net/skeleton.c: Use more common 'Name:' vs. 'Function:' --- drivers/net/skeleton.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index 9a8d4e8eedd..bb1a543ff93 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -196,7 +196,7 @@ static void skel_ipv6multicast(FAR struct skel_driver_s *priv); ****************************************************************************/ /**************************************************************************** - * Function: skel_transmit + * Name: skel_transmit * * Description: * Start hardware transmission. Called either from the txdone interrupt @@ -237,7 +237,7 @@ static int skel_transmit(FAR struct skel_driver_s *priv) } /**************************************************************************** - * Function: skel_txpoll + * Name: skel_txpoll * * Description: * The transmitter is available, check if the network has any outgoing @@ -309,7 +309,7 @@ static int skel_txpoll(FAR struct net_driver_s *dev) } /**************************************************************************** - * Function: skel_receive + * Name: skel_receive * * Description: * An interrupt was received indicating the availability of a new RX packet @@ -451,7 +451,7 @@ static void skel_receive(FAR struct skel_driver_s *priv) } /**************************************************************************** - * Function: skel_txdone + * Name: skel_txdone * * Description: * An interrupt was received indicating that the last TX packet(s) is done @@ -491,7 +491,7 @@ static void skel_txdone(FAR struct skel_driver_s *priv) } /**************************************************************************** - * Function: skel_interrupt_work + * Name: skel_interrupt_work * * Description: * Perform interrupt related work from the worker thread @@ -543,7 +543,7 @@ static void skel_interrupt_work(FAR void *arg) } /**************************************************************************** - * Function: skel_interrupt + * Name: skel_interrupt * * Description: * Hardware interrupt handler @@ -590,7 +590,7 @@ static int skel_interrupt(int irq, FAR void *context, FAR void *arg) } /**************************************************************************** - * Function: skel_txtimeout_work + * Name: skel_txtimeout_work * * Description: * Perform TX timeout related work from the worker thread @@ -631,7 +631,7 @@ static void skel_txtimeout_work(FAR void *arg) } /**************************************************************************** - * Function: skel_txtimeout_expiry + * Name: skel_txtimeout_expiry * * Description: * Our TX watchdog timed out. Called from the timer interrupt handler. @@ -666,7 +666,7 @@ static void skel_txtimeout_expiry(int argc, wdparm_t arg, ...) } /**************************************************************************** - * Function: skel_poll_process + * Name: skel_poll_process * * Description: * Perform the periodic poll. This may be called either from watchdog @@ -687,7 +687,7 @@ static inline void skel_poll_process(FAR struct skel_driver_s *priv) } /**************************************************************************** - * Function: skel_poll_work + * Name: skel_poll_work * * Description: * Perform periodic polling from the worker thread @@ -736,7 +736,7 @@ static void skel_poll_work(FAR void *arg) } /**************************************************************************** - * Function: skel_poll_expiry + * Name: skel_poll_expiry * * Description: * Periodic timer handler. Called from the timer interrupt handler. @@ -763,7 +763,7 @@ static void skel_poll_expiry(int argc, wdparm_t arg, ...) } /**************************************************************************** - * Function: skel_ifup + * Name: skel_ifup * * Description: * NuttX Callback: Bring up the Ethernet interface when an IP address is @@ -818,7 +818,7 @@ static int skel_ifup(FAR struct net_driver_s *dev) } /**************************************************************************** - * Function: skel_ifdown + * Name: skel_ifdown * * Description: * NuttX Callback: Stop the interface. @@ -861,7 +861,7 @@ static int skel_ifdown(FAR struct net_driver_s *dev) } /**************************************************************************** - * Function: skel_txavail_work + * Name: skel_txavail_work * * Description: * Perform an out-of-cycle poll on the worker thread. @@ -904,7 +904,7 @@ static void skel_txavail_work(FAR void *arg) } /**************************************************************************** - * Function: skel_txavail + * Name: skel_txavail * * Description: * Driver callback invoked when new TX data is available. This is a @@ -942,7 +942,7 @@ static int skel_txavail(FAR struct net_driver_s *dev) } /**************************************************************************** - * Function: skel_addmac + * Name: skel_addmac * * Description: * NuttX Callback: Add the specified MAC address to the hardware multicast @@ -971,7 +971,7 @@ static int skel_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) #endif /**************************************************************************** - * Function: skel_rmmac + * Name: skel_rmmac * * Description: * NuttX Callback: Remove the specified MAC address from the hardware multicast @@ -1000,7 +1000,7 @@ static int skel_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) #endif /**************************************************************************** - * Function: skel_ipv6multicast + * Name: skel_ipv6multicast * * Description: * Configure the IPv6 multicast MAC address. @@ -1078,7 +1078,7 @@ static void skel_ipv6multicast(FAR struct skel_driver_s *priv) ****************************************************************************/ /**************************************************************************** - * Function: skel_initialize + * Name: skel_initialize * * Description: * Initialize the Ethernet controller and driver From 5a0636d8bce3ed39669cdcfad58ccbf53e8e5bb4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 9 Apr 2017 05:49:30 -0600 Subject: [PATCH 17/48] Trivial change to spacing --- wireless/ieee802154/mac802154_loopback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index 994289642b3..71255f0d604 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -603,7 +603,7 @@ int ieee8021514_loopback(void) memset(priv, 0, sizeof(struct lo_driver_s)); - dev = &priv->lo_ieee.i_dev; + dev = &priv->lo_ieee.i_dev; dev->d_ifup = lo_ifup; /* I/F up (new IP address) callback */ dev->d_ifdown = lo_ifdown; /* I/F down callback */ dev->d_txavail = lo_txavail; /* New TX data callback */ From f9e402018bb922b11af957c4cb606f54f5e91c55 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 9 Apr 2017 07:22:49 -0600 Subject: [PATCH 18/48] Buttons: Change return value of board_buttons() and the type of btn_buttonset_t to uint32_t so that more than 8 buttons can be supported. --- configs/avr32dev1/src/avr32_buttons.c | 4 ++-- configs/bambino-200e/src/lpc43_buttons.c | 4 ++-- configs/clicker2-stm32/src/stm32_buttons.c | 4 ++-- configs/cloudctrl/src/stm32_buttons.c | 4 ++-- configs/demo9s12ne64/src/m9s12_buttons.c | 2 +- configs/dk-tm4c129x/src/tm4c_buttons.c | 4 ++-- configs/ea3131/src/lpc31_buttons.c | 14 +------------- configs/ea3152/src/lpc31_buttons.c | 14 +------------- configs/ez80f910200zco/src/ez80_buttons.c | 2 +- configs/fire-stm32v2/src/stm32_buttons.c | 4 ++-- configs/freedom-k64f/src/k64_buttons.c | 4 ++-- configs/freedom-k66f/src/k66_buttons.c | 4 ++-- configs/hymini-stm32v/src/stm32_buttons.c | 4 ++-- configs/kwikstik-k40/src/k40_buttons.c | 2 +- configs/launchxl-tms57004/src/tms570_buttons.c | 2 +- configs/lincoln60/src/lpc17_buttons.c | 4 ++-- configs/lpc4330-xplorer/src/lpc43_buttons.c | 4 ++-- configs/lpc4357-evb/src/lpc43_buttons.c | 4 ++-- configs/ne64badge/src/m9s12_buttons.c | 4 ++-- configs/nucleo-144/src/stm32_buttons.c | 2 +- configs/nucleo-f303re/src/stm32_buttons.c | 2 +- configs/nucleo-f4x1re/src/stm32_buttons.c | 2 +- configs/nucleo-l476rg/src/stm32_buttons.c | 2 +- .../olimex-efm32g880f128-stk/src/efm32_buttons.c | 4 ++-- configs/olimex-lpc1766stk/src/lpc17_buttons.c | 4 ++-- configs/olimex-stm32-e407/src/stm32_buttons.c | 4 ++-- configs/olimex-stm32-h405/src/stm32_buttons.c | 4 ++-- configs/olimex-stm32-h407/src/stm32_buttons.c | 4 ++-- configs/olimex-stm32-p207/src/stm32_buttons.c | 4 ++-- configs/olimex-stm32-p407/src/stm32_buttons.c | 4 ++-- configs/olimex-strp711/src/str71_buttons.c | 4 ++-- configs/olimexino-stm32/src/stm32_buttons.c | 2 +- configs/open1788/src/lpc17_buttons.c | 4 ++-- configs/pcduino-a10/src/a1x_buttons.c | 2 +- configs/photon/src/stm32_buttons.c | 2 +- configs/pic32mz-starterkit/src/pic32mz_buttons.c | 4 ++-- configs/sam3u-ek/src/sam_buttons.c | 4 ++-- configs/sam4e-ek/src/sam_buttons.c | 4 ++-- configs/sam4l-xplained/src/sam_buttons.c | 6 +----- configs/sam4s-xplained-pro/src/sam_buttons.c | 2 +- configs/sam4s-xplained/src/sam_buttons.c | 2 +- configs/sama5d2-xult/src/sam_buttons.c | 2 +- configs/sama5d3-xplained/src/sam_buttons.c | 2 +- configs/sama5d3x-ek/src/sam_buttons.c | 2 +- configs/sama5d4-ek/src/sam_buttons.c | 2 +- configs/samd20-xplained/src/sam_buttons.c | 2 +- configs/samd21-xplained/src/sam_buttons.c | 2 +- configs/same70-xplained/src/sam_buttons.c | 2 +- configs/saml21-xplained/src/sam_buttons.c | 2 +- configs/samv71-xult/src/sam_buttons.c | 4 ++-- configs/shenzhou/src/stm32_buttons.c | 4 ++-- configs/skp16c26/src/m16c_buttons.c | 4 ++-- configs/spark/src/stm32_buttons.c | 2 +- configs/stm3210e-eval/src/stm32_buttons.c | 4 ++-- configs/stm3220g-eval/src/stm32_buttons.c | 4 ++-- configs/stm3240g-eval/src/stm32_buttons.c | 4 ++-- configs/stm32butterfly2/src/stm32_buttons.c | 4 ++-- configs/stm32f103-minimum/src/stm32_buttons.c | 4 ++-- configs/stm32f3discovery/src/stm32_buttons.c | 4 ++-- configs/stm32f429i-disco/src/stm32_buttons.c | 4 ++-- configs/stm32f4discovery/src/stm32_buttons.c | 4 ++-- configs/stm32f746g-disco/src/stm32_buttons.c | 2 +- configs/stm32l476-mdk/src/stm32_buttons.c | 4 ++-- configs/stm32l476vg-disco/src/stm32_buttons.c | 4 ++-- configs/stm32ldiscovery/src/stm32_buttons.c | 4 ++-- configs/stm32vldiscovery/src/stm32_buttons.c | 4 ++-- configs/sure-pic32mx/src/pic32mx_buttons.c | 4 ++-- configs/tm4c123g-launchpad/src/tm4c_buttons.c | 4 ++-- configs/tm4c1294-launchpad/src/tm4c_buttons.c | 4 ++-- configs/twr-k60n512/src/k60_buttons.c | 4 ++-- configs/ubw32/src/pic32_buttons.c | 4 ++-- configs/viewtool-stm32f107/src/stm32_buttons.c | 4 ++-- configs/xmc4500-relax/src/xmc4_buttons.c | 2 +- configs/zkit-arm-1769/src/lpc17_buttons.c | 4 ++-- include/nuttx/board.h | 2 +- include/nuttx/input/buttons.h | 2 +- net/sixlowpan/sixlowpan_internal.h | 4 ++-- 77 files changed, 125 insertions(+), 153 deletions(-) diff --git a/configs/avr32dev1/src/avr32_buttons.c b/configs/avr32dev1/src/avr32_buttons.c index 72191bb5855..427a19d8352 100644 --- a/configs/avr32dev1/src/avr32_buttons.c +++ b/configs/avr32dev1/src/avr32_buttons.c @@ -126,9 +126,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t retval; + uint32_t retval; retval = at32uc3_gpioread(PINMUX_GPIO_BUTTON1) ? 0 : BUTTON1; retval |= at32uc3_gpioread(PINMUX_GPIO_BUTTON2) ? 0 : BUTTON2; diff --git a/configs/bambino-200e/src/lpc43_buttons.c b/configs/bambino-200e/src/lpc43_buttons.c index 8aaeac3c95c..8f96dafd274 100644 --- a/configs/bambino-200e/src/lpc43_buttons.c +++ b/configs/bambino-200e/src/lpc43_buttons.c @@ -120,9 +120,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/clicker2-stm32/src/stm32_buttons.c b/configs/clicker2-stm32/src/stm32_buttons.c index 14da26b9646..922007dcf6d 100644 --- a/configs/clicker2-stm32/src/stm32_buttons.c +++ b/configs/clicker2-stm32/src/stm32_buttons.c @@ -79,9 +79,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key. A low value will be sensed when the * button is pressed. diff --git a/configs/cloudctrl/src/stm32_buttons.c b/configs/cloudctrl/src/stm32_buttons.c index b62dbeb719c..6603ce1d078 100644 --- a/configs/cloudctrl/src/stm32_buttons.c +++ b/configs/cloudctrl/src/stm32_buttons.c @@ -104,9 +104,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/demo9s12ne64/src/m9s12_buttons.c b/configs/demo9s12ne64/src/m9s12_buttons.c index 2452139174f..addf4af1714 100644 --- a/configs/demo9s12ne64/src/m9s12_buttons.c +++ b/configs/demo9s12ne64/src/m9s12_buttons.c @@ -77,7 +77,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return 0; } diff --git a/configs/dk-tm4c129x/src/tm4c_buttons.c b/configs/dk-tm4c129x/src/tm4c_buttons.c index f5b65bee71b..7ef91a768be 100644 --- a/configs/dk-tm4c129x/src/tm4c_buttons.c +++ b/configs/dk-tm4c129x/src/tm4c_buttons.c @@ -103,9 +103,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/ea3131/src/lpc31_buttons.c b/configs/ea3131/src/lpc31_buttons.c index de80fdf1bc5..8b0822e649b 100644 --- a/configs/ea3131/src/lpc31_buttons.c +++ b/configs/ea3131/src/lpc31_buttons.c @@ -49,18 +49,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -77,7 +65,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return 0; } diff --git a/configs/ea3152/src/lpc31_buttons.c b/configs/ea3152/src/lpc31_buttons.c index 28b349abb0b..577692c1a15 100644 --- a/configs/ea3152/src/lpc31_buttons.c +++ b/configs/ea3152/src/lpc31_buttons.c @@ -49,18 +49,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -77,7 +65,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return 0; } diff --git a/configs/ez80f910200zco/src/ez80_buttons.c b/configs/ez80f910200zco/src/ez80_buttons.c index 6bc2aa9462b..ee76218d0d8 100644 --- a/configs/ez80f910200zco/src/ez80_buttons.c +++ b/configs/ez80f910200zco/src/ez80_buttons.c @@ -168,7 +168,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return inp(EZ80_PB_DDR) & 7; } diff --git a/configs/fire-stm32v2/src/stm32_buttons.c b/configs/fire-stm32v2/src/stm32_buttons.c index d2dd07cd8ef..5c041230f98 100644 --- a/configs/fire-stm32v2/src/stm32_buttons.c +++ b/configs/fire-stm32v2/src/stm32_buttons.c @@ -91,9 +91,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key. A LOW value means that the key is pressed, */ diff --git a/configs/freedom-k64f/src/k64_buttons.c b/configs/freedom-k64f/src/k64_buttons.c index 0c9f22e8c86..d6f6ea44d6d 100644 --- a/configs/freedom-k64f/src/k64_buttons.c +++ b/configs/freedom-k64f/src/k64_buttons.c @@ -92,9 +92,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; if (kinetis_gpioread(GPIO_SW2)) { diff --git a/configs/freedom-k66f/src/k66_buttons.c b/configs/freedom-k66f/src/k66_buttons.c index de70f31dc5f..ce63345c856 100644 --- a/configs/freedom-k66f/src/k66_buttons.c +++ b/configs/freedom-k66f/src/k66_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; if (kinetis_gpioread(GPIO_SW2)) { diff --git a/configs/hymini-stm32v/src/stm32_buttons.c b/configs/hymini-stm32v/src/stm32_buttons.c index d92be06ab9d..757f159af74 100644 --- a/configs/hymini-stm32v/src/stm32_buttons.c +++ b/configs/hymini-stm32v/src/stm32_buttons.c @@ -79,9 +79,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; bool pinValue; /* Check that state of each key */ diff --git a/configs/kwikstik-k40/src/k40_buttons.c b/configs/kwikstik-k40/src/k40_buttons.c index 7057ab1bd83..35f673d0ea0 100644 --- a/configs/kwikstik-k40/src/k40_buttons.c +++ b/configs/kwikstik-k40/src/k40_buttons.c @@ -74,7 +74,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { /* The KwikStik-K40 board has no standard GPIO contact buttons */ diff --git a/configs/launchxl-tms57004/src/tms570_buttons.c b/configs/launchxl-tms57004/src/tms570_buttons.c index c0f307d2feb..3ee9e0eb31d 100644 --- a/configs/launchxl-tms57004/src/tms570_buttons.c +++ b/configs/launchxl-tms57004/src/tms570_buttons.c @@ -159,7 +159,7 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return tms570_gioread(GIO_BUTTON) ? BUTTON_GIOA7_BIT : 0; } diff --git a/configs/lincoln60/src/lpc17_buttons.c b/configs/lincoln60/src/lpc17_buttons.c index bcee2e34f0f..48ea4298262 100644 --- a/configs/lincoln60/src/lpc17_buttons.c +++ b/configs/lincoln60/src/lpc17_buttons.c @@ -127,9 +127,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/lpc4330-xplorer/src/lpc43_buttons.c b/configs/lpc4330-xplorer/src/lpc43_buttons.c index 0d0f5db695c..9e09ce07dc0 100644 --- a/configs/lpc4330-xplorer/src/lpc43_buttons.c +++ b/configs/lpc4330-xplorer/src/lpc43_buttons.c @@ -126,9 +126,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/lpc4357-evb/src/lpc43_buttons.c b/configs/lpc4357-evb/src/lpc43_buttons.c index c62229d35c5..2ed50974959 100644 --- a/configs/lpc4357-evb/src/lpc43_buttons.c +++ b/configs/lpc4357-evb/src/lpc43_buttons.c @@ -129,10 +129,10 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { #if 0 /* Not yet implemented */ - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/ne64badge/src/m9s12_buttons.c b/configs/ne64badge/src/m9s12_buttons.c index 522d402c491..964b7114b5d 100644 --- a/configs/ne64badge/src/m9s12_buttons.c +++ b/configs/ne64badge/src/m9s12_buttons.c @@ -94,9 +94,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; if (hcs12_gpioread(NE64BADGE_BUTTON1)) { diff --git a/configs/nucleo-144/src/stm32_buttons.c b/configs/nucleo-144/src/stm32_buttons.c index ea520e84731..5d47aa30bd9 100644 --- a/configs/nucleo-144/src/stm32_buttons.c +++ b/configs/nucleo-144/src/stm32_buttons.c @@ -77,7 +77,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return stm32_gpioread(GPIO_BTN_USER) ? 1 : 0; } diff --git a/configs/nucleo-f303re/src/stm32_buttons.c b/configs/nucleo-f303re/src/stm32_buttons.c index 65b046b819e..8ae6081f489 100644 --- a/configs/nucleo-f303re/src/stm32_buttons.c +++ b/configs/nucleo-f303re/src/stm32_buttons.c @@ -88,7 +88,7 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { /* Check the state of the USER button. A LOW value means that the key is * pressed. diff --git a/configs/nucleo-f4x1re/src/stm32_buttons.c b/configs/nucleo-f4x1re/src/stm32_buttons.c index ab019d2a5c3..30fd294fc59 100644 --- a/configs/nucleo-f4x1re/src/stm32_buttons.c +++ b/configs/nucleo-f4x1re/src/stm32_buttons.c @@ -78,7 +78,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { /* Check that state of each USER button. A LOW value means that the key is * pressed. diff --git a/configs/nucleo-l476rg/src/stm32_buttons.c b/configs/nucleo-l476rg/src/stm32_buttons.c index 7da458ffb3c..55f99e8192b 100644 --- a/configs/nucleo-l476rg/src/stm32_buttons.c +++ b/configs/nucleo-l476rg/src/stm32_buttons.c @@ -78,7 +78,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { /* Check that state of each USER button. A LOW value means that the key is * pressed. diff --git a/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c b/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c index e2bcba1a58f..9637b125550 100644 --- a/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c +++ b/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c @@ -125,9 +125,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret; + uint32_t ret; int i; /* Check each button */ diff --git a/configs/olimex-lpc1766stk/src/lpc17_buttons.c b/configs/olimex-lpc1766stk/src/lpc17_buttons.c index 37326a82773..179a6785841 100644 --- a/configs/olimex-lpc1766stk/src/lpc17_buttons.c +++ b/configs/olimex-lpc1766stk/src/lpc17_buttons.c @@ -130,9 +130,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/olimex-stm32-e407/src/stm32_buttons.c b/configs/olimex-stm32-e407/src/stm32_buttons.c index 870b1ff8a98..c57c54f42df 100644 --- a/configs/olimex-stm32-e407/src/stm32_buttons.c +++ b/configs/olimex-stm32-e407/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key */ diff --git a/configs/olimex-stm32-h405/src/stm32_buttons.c b/configs/olimex-stm32-h405/src/stm32_buttons.c index c3b6aa92fee..e7bd98cf23e 100644 --- a/configs/olimex-stm32-h405/src/stm32_buttons.c +++ b/configs/olimex-stm32-h405/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key */ diff --git a/configs/olimex-stm32-h407/src/stm32_buttons.c b/configs/olimex-stm32-h407/src/stm32_buttons.c index ed33810dd47..976157d1170 100644 --- a/configs/olimex-stm32-h407/src/stm32_buttons.c +++ b/configs/olimex-stm32-h407/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key */ diff --git a/configs/olimex-stm32-p207/src/stm32_buttons.c b/configs/olimex-stm32-p207/src/stm32_buttons.c index 0002098298f..9400b7456c0 100644 --- a/configs/olimex-stm32-p207/src/stm32_buttons.c +++ b/configs/olimex-stm32-p207/src/stm32_buttons.c @@ -102,9 +102,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key */ diff --git a/configs/olimex-stm32-p407/src/stm32_buttons.c b/configs/olimex-stm32-p407/src/stm32_buttons.c index 6add698e0fa..3d98c9eab7f 100644 --- a/configs/olimex-stm32-p407/src/stm32_buttons.c +++ b/configs/olimex-stm32-p407/src/stm32_buttons.c @@ -104,9 +104,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key */ diff --git a/configs/olimex-strp711/src/str71_buttons.c b/configs/olimex-strp711/src/str71_buttons.c index 98537be3883..ec1b18b4d43 100644 --- a/configs/olimex-strp711/src/str71_buttons.c +++ b/configs/olimex-strp711/src/str71_buttons.c @@ -112,9 +112,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; if ((getreg16(STR71X_GPIO0_PD) & STR71X_WAKEUPBUTTON_GPIO0) != 0) { diff --git a/configs/olimexino-stm32/src/stm32_buttons.c b/configs/olimexino-stm32/src/stm32_buttons.c index 971bdb79f22..cc6ea25509c 100644 --- a/configs/olimexino-stm32/src/stm32_buttons.c +++ b/configs/olimexino-stm32/src/stm32_buttons.c @@ -102,7 +102,7 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return stm32_gpioread(BUTTON_BOOT0n) ? 0 : BUTTON_BOOT0_MASK; } diff --git a/configs/open1788/src/lpc17_buttons.c b/configs/open1788/src/lpc17_buttons.c index e7a7cf88517..f2e2fb5f27a 100644 --- a/configs/open1788/src/lpc17_buttons.c +++ b/configs/open1788/src/lpc17_buttons.c @@ -149,9 +149,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/pcduino-a10/src/a1x_buttons.c b/configs/pcduino-a10/src/a1x_buttons.c index a690ae866dc..c7d10891352 100644 --- a/configs/pcduino-a10/src/a1x_buttons.c +++ b/configs/pcduino-a10/src/a1x_buttons.c @@ -84,7 +84,7 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { # warning Missing logic } diff --git a/configs/photon/src/stm32_buttons.c b/configs/photon/src/stm32_buttons.c index 7c695dd5efa..7a9297eb6b3 100644 --- a/configs/photon/src/stm32_buttons.c +++ b/configs/photon/src/stm32_buttons.c @@ -66,7 +66,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { /* Check the state of the only button */ diff --git a/configs/pic32mz-starterkit/src/pic32mz_buttons.c b/configs/pic32mz-starterkit/src/pic32mz_buttons.c index a51ca05f08d..206be294c31 100644 --- a/configs/pic32mz-starterkit/src/pic32mz_buttons.c +++ b/configs/pic32mz-starterkit/src/pic32mz_buttons.c @@ -105,9 +105,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/sam3u-ek/src/sam_buttons.c b/configs/sam3u-ek/src/sam_buttons.c index 520f05e1a54..107c7036a66 100644 --- a/configs/sam3u-ek/src/sam_buttons.c +++ b/configs/sam3u-ek/src/sam_buttons.c @@ -133,9 +133,9 @@ void board_button_initialize(void) * ************************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t retval; + uint32_t retval; retval = sam_gpioread(GPIO_BUTTON1) ? 0 : BUTTON1; retval |= sam_gpioread(GPIO_BUTTON2) ? 0 : BUTTON2; diff --git a/configs/sam4e-ek/src/sam_buttons.c b/configs/sam4e-ek/src/sam_buttons.c index d9fbabeb6d8..53626290b7b 100644 --- a/configs/sam4e-ek/src/sam_buttons.c +++ b/configs/sam4e-ek/src/sam_buttons.c @@ -135,9 +135,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t retval; + uint32_t retval; retval = sam_gpioread(GPIO_SCROLLUP) ? 0 : BUTTON_SCROLLUP; retval |= sam_gpioread(GPIO_SCROLLDWN) ? 0 : BUTTON_SCROLLDOWN; diff --git a/configs/sam4l-xplained/src/sam_buttons.c b/configs/sam4l-xplained/src/sam_buttons.c index 619f7d658ba..8d306bb3117 100644 --- a/configs/sam4l-xplained/src/sam_buttons.c +++ b/configs/sam4l-xplained/src/sam_buttons.c @@ -53,10 +53,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -88,7 +84,7 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_gpioread(GPIO_SW0) ? 0 : BUTTON_SW0_BIT; } diff --git a/configs/sam4s-xplained-pro/src/sam_buttons.c b/configs/sam4s-xplained-pro/src/sam_buttons.c index daae49b89e6..3b9b4fe3597 100644 --- a/configs/sam4s-xplained-pro/src/sam_buttons.c +++ b/configs/sam4s-xplained-pro/src/sam_buttons.c @@ -86,7 +86,7 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_gpioread(GPIO_SW0) ? 0 : BUTTON_SW0_BIT; } diff --git a/configs/sam4s-xplained/src/sam_buttons.c b/configs/sam4s-xplained/src/sam_buttons.c index 940f97edae5..314e8e1818a 100644 --- a/configs/sam4s-xplained/src/sam_buttons.c +++ b/configs/sam4s-xplained/src/sam_buttons.c @@ -85,7 +85,7 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_gpioread(GPIO_BP2) ? 0 : BUTTON_BP2_BIT; } diff --git a/configs/sama5d2-xult/src/sam_buttons.c b/configs/sama5d2-xult/src/sam_buttons.c index c93fa6b904e..0939ddaa11d 100644 --- a/configs/sama5d2-xult/src/sam_buttons.c +++ b/configs/sama5d2-xult/src/sam_buttons.c @@ -96,7 +96,7 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_pioread(PIO_BTN_USER) ? 0 : BUTTON_USER_BIT; } diff --git a/configs/sama5d3-xplained/src/sam_buttons.c b/configs/sama5d3-xplained/src/sam_buttons.c index b7fd8245567..43794b374da 100644 --- a/configs/sama5d3-xplained/src/sam_buttons.c +++ b/configs/sama5d3-xplained/src/sam_buttons.c @@ -100,7 +100,7 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_pioread(PIO_USER) ? 0 : BUTTON_USER_BIT; } diff --git a/configs/sama5d3x-ek/src/sam_buttons.c b/configs/sama5d3x-ek/src/sam_buttons.c index 5b7ccc9b908..dbdaa310f67 100644 --- a/configs/sama5d3x-ek/src/sam_buttons.c +++ b/configs/sama5d3x-ek/src/sam_buttons.c @@ -100,7 +100,7 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_pioread(PIO_USER1) ? 0 : BUTTON_USER1_BIT; } diff --git a/configs/sama5d4-ek/src/sam_buttons.c b/configs/sama5d4-ek/src/sam_buttons.c index 5696d96de5b..4ccae619f60 100644 --- a/configs/sama5d4-ek/src/sam_buttons.c +++ b/configs/sama5d4-ek/src/sam_buttons.c @@ -96,7 +96,7 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_pioread(PIO_BTN_USER) ? 0 : BUTTON_USER_BIT; } diff --git a/configs/samd20-xplained/src/sam_buttons.c b/configs/samd20-xplained/src/sam_buttons.c index 88c24aced7a..fc8f14bd0ce 100644 --- a/configs/samd20-xplained/src/sam_buttons.c +++ b/configs/samd20-xplained/src/sam_buttons.c @@ -85,7 +85,7 @@ void board_button_initialize(void) * ************************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_portread(PORT_SW0) ? 0 : BUTTON_SW0_BIT; } diff --git a/configs/samd21-xplained/src/sam_buttons.c b/configs/samd21-xplained/src/sam_buttons.c index aa19ddc008b..e4c31aa941e 100644 --- a/configs/samd21-xplained/src/sam_buttons.c +++ b/configs/samd21-xplained/src/sam_buttons.c @@ -85,7 +85,7 @@ void board_button_initialize(void) * ************************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_portread(PORT_SW0) ? 0 : BUTTON_SW0_BIT; } diff --git a/configs/same70-xplained/src/sam_buttons.c b/configs/same70-xplained/src/sam_buttons.c index 669a6d3bfe4..7e66905c8a1 100644 --- a/configs/same70-xplained/src/sam_buttons.c +++ b/configs/same70-xplained/src/sam_buttons.c @@ -147,7 +147,7 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_gpioread(GPIO_SW0) ? 0 : BUTTON_SW0_BIT; } diff --git a/configs/saml21-xplained/src/sam_buttons.c b/configs/saml21-xplained/src/sam_buttons.c index 437c4d7ec85..909fa58a7a7 100644 --- a/configs/saml21-xplained/src/sam_buttons.c +++ b/configs/saml21-xplained/src/sam_buttons.c @@ -85,7 +85,7 @@ void board_button_initialize(void) * ************************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return sam_portread(PORT_SW0) ? 0 : BUTTON_SW0_BIT; } diff --git a/configs/samv71-xult/src/sam_buttons.c b/configs/samv71-xult/src/sam_buttons.c index 7c9a98b52cd..1a06c840342 100644 --- a/configs/samv71-xult/src/sam_buttons.c +++ b/configs/samv71-xult/src/sam_buttons.c @@ -163,9 +163,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t retval; + uint32_t retval; retval = sam_gpioread(GPIO_SW0) ? 0 : BUTTON_SW0_BIT; retval |= sam_gpioread(GPIO_SW1) ? 0 : BUTTON_SW1_BIT; diff --git a/configs/shenzhou/src/stm32_buttons.c b/configs/shenzhou/src/stm32_buttons.c index 515cad297f1..139d517956f 100644 --- a/configs/shenzhou/src/stm32_buttons.c +++ b/configs/shenzhou/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/skp16c26/src/m16c_buttons.c b/configs/skp16c26/src/m16c_buttons.c index 4841fefe82c..78832b9c598 100644 --- a/configs/skp16c26/src/m16c_buttons.c +++ b/configs/skp16c26/src/m16c_buttons.c @@ -89,9 +89,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t swset = 0; + uint32_t swset = 0; uint8_t regval = getreg8(M16C_P8); if (SW_PRESSED(regval, SW1_BIT)) diff --git a/configs/spark/src/stm32_buttons.c b/configs/spark/src/stm32_buttons.c index e41463d6c9f..3ab2f3c8546 100644 --- a/configs/spark/src/stm32_buttons.c +++ b/configs/spark/src/stm32_buttons.c @@ -80,7 +80,7 @@ void board_button_initialize(void) * N.B The return state in true logic, the button polarity is dealt here in ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return stm32_gpioread(GPIO_BTN)==0 ? BUTTON_USER_BIT : 0; } diff --git a/configs/stm3210e-eval/src/stm32_buttons.c b/configs/stm3210e-eval/src/stm32_buttons.c index 043535444c8..b9f48228143 100644 --- a/configs/stm3210e-eval/src/stm32_buttons.c +++ b/configs/stm3210e-eval/src/stm32_buttons.c @@ -108,9 +108,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/stm3220g-eval/src/stm32_buttons.c b/configs/stm3220g-eval/src/stm32_buttons.c index 115fea249ea..669b460b032 100644 --- a/configs/stm3220g-eval/src/stm32_buttons.c +++ b/configs/stm3220g-eval/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/stm3240g-eval/src/stm32_buttons.c b/configs/stm3240g-eval/src/stm32_buttons.c index a20c03f16ae..4682ffb1a9f 100644 --- a/configs/stm3240g-eval/src/stm32_buttons.c +++ b/configs/stm3240g-eval/src/stm32_buttons.c @@ -104,9 +104,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/stm32butterfly2/src/stm32_buttons.c b/configs/stm32butterfly2/src/stm32_buttons.c index 85e7a0751c4..612776adc59 100644 --- a/configs/stm32butterfly2/src/stm32_buttons.c +++ b/configs/stm32butterfly2/src/stm32_buttons.c @@ -92,9 +92,9 @@ void board_button_initialize(void) * Reads keys ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t rv = 0; + uint32_t rv = 0; int i; for (i = 0; i != NUM_BUTTONS; ++i) diff --git a/configs/stm32f103-minimum/src/stm32_buttons.c b/configs/stm32f103-minimum/src/stm32_buttons.c index ebca1469f1d..6891b3db0a6 100644 --- a/configs/stm32f103-minimum/src/stm32_buttons.c +++ b/configs/stm32f103-minimum/src/stm32_buttons.c @@ -104,9 +104,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/stm32f3discovery/src/stm32_buttons.c b/configs/stm32f3discovery/src/stm32_buttons.c index f89fd207a3b..a0ecada6a5a 100644 --- a/configs/stm32f3discovery/src/stm32_buttons.c +++ b/configs/stm32f3discovery/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/stm32f429i-disco/src/stm32_buttons.c b/configs/stm32f429i-disco/src/stm32_buttons.c index a6ffed5433d..d2e9ba2e095 100644 --- a/configs/stm32f429i-disco/src/stm32_buttons.c +++ b/configs/stm32f429i-disco/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/stm32f4discovery/src/stm32_buttons.c b/configs/stm32f4discovery/src/stm32_buttons.c index 449001f13ad..2d86ea80cf7 100644 --- a/configs/stm32f4discovery/src/stm32_buttons.c +++ b/configs/stm32f4discovery/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/stm32f746g-disco/src/stm32_buttons.c b/configs/stm32f746g-disco/src/stm32_buttons.c index ec08616aa6c..b8a46a8dacd 100644 --- a/configs/stm32f746g-disco/src/stm32_buttons.c +++ b/configs/stm32f746g-disco/src/stm32_buttons.c @@ -77,7 +77,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { return stm32_gpioread(GPIO_BTN_USER) ? 1 : 0; } diff --git a/configs/stm32l476-mdk/src/stm32_buttons.c b/configs/stm32l476-mdk/src/stm32_buttons.c index 955cba926d3..7debe3c5970 100644 --- a/configs/stm32l476-mdk/src/stm32_buttons.c +++ b/configs/stm32l476-mdk/src/stm32_buttons.c @@ -103,9 +103,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/stm32l476vg-disco/src/stm32_buttons.c b/configs/stm32l476vg-disco/src/stm32_buttons.c index 1d85b278756..f3c4d50c9c5 100644 --- a/configs/stm32l476vg-disco/src/stm32_buttons.c +++ b/configs/stm32l476vg-disco/src/stm32_buttons.c @@ -261,9 +261,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/stm32ldiscovery/src/stm32_buttons.c b/configs/stm32ldiscovery/src/stm32_buttons.c index f599b0c8517..f766017d150 100644 --- a/configs/stm32ldiscovery/src/stm32_buttons.c +++ b/configs/stm32ldiscovery/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/stm32vldiscovery/src/stm32_buttons.c b/configs/stm32vldiscovery/src/stm32_buttons.c index 259cfee756e..9784b19d773 100644 --- a/configs/stm32vldiscovery/src/stm32_buttons.c +++ b/configs/stm32vldiscovery/src/stm32_buttons.c @@ -75,9 +75,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; ret = (stm32_gpioread(g_buttons[i]) == false ? 1 : 0); diff --git a/configs/sure-pic32mx/src/pic32mx_buttons.c b/configs/sure-pic32mx/src/pic32mx_buttons.c index 6c378dd0a6f..bf5ca03429e 100644 --- a/configs/sure-pic32mx/src/pic32mx_buttons.c +++ b/configs/sure-pic32mx/src/pic32mx_buttons.c @@ -157,9 +157,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int id; /* Configure input pins */ diff --git a/configs/tm4c123g-launchpad/src/tm4c_buttons.c b/configs/tm4c123g-launchpad/src/tm4c_buttons.c index a61c7e9c78d..96370046f48 100644 --- a/configs/tm4c123g-launchpad/src/tm4c_buttons.c +++ b/configs/tm4c123g-launchpad/src/tm4c_buttons.c @@ -118,9 +118,9 @@ void board_button_initialize(void) * ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; /* Check that state of each key. A LOW value means that the key is * pressed. diff --git a/configs/tm4c1294-launchpad/src/tm4c_buttons.c b/configs/tm4c1294-launchpad/src/tm4c_buttons.c index 17d83c81f36..5b72e5bb29d 100644 --- a/configs/tm4c1294-launchpad/src/tm4c_buttons.c +++ b/configs/tm4c1294-launchpad/src/tm4c_buttons.c @@ -102,9 +102,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/twr-k60n512/src/k60_buttons.c b/configs/twr-k60n512/src/k60_buttons.c index a952f64828d..d9206f2c71a 100644 --- a/configs/twr-k60n512/src/k60_buttons.c +++ b/configs/twr-k60n512/src/k60_buttons.c @@ -94,9 +94,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; if (kinetis_gpioread(GPIO_SW1)) { diff --git a/configs/ubw32/src/pic32_buttons.c b/configs/ubw32/src/pic32_buttons.c index f612e1eea4b..69b1deeb442 100644 --- a/configs/ubw32/src/pic32_buttons.c +++ b/configs/ubw32/src/pic32_buttons.c @@ -132,9 +132,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int id; /* Configure input pins */ diff --git a/configs/viewtool-stm32f107/src/stm32_buttons.c b/configs/viewtool-stm32f107/src/stm32_buttons.c index 9039e72e091..9e39a2d72c4 100644 --- a/configs/viewtool-stm32f107/src/stm32_buttons.c +++ b/configs/viewtool-stm32f107/src/stm32_buttons.c @@ -96,9 +96,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; int i; /* Check that state of each key */ diff --git a/configs/xmc4500-relax/src/xmc4_buttons.c b/configs/xmc4500-relax/src/xmc4_buttons.c index 24f9e05a206..881467f11c9 100644 --- a/configs/xmc4500-relax/src/xmc4_buttons.c +++ b/configs/xmc4500-relax/src/xmc4_buttons.c @@ -59,7 +59,7 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { #warning Missing logic return 0; diff --git a/configs/zkit-arm-1769/src/lpc17_buttons.c b/configs/zkit-arm-1769/src/lpc17_buttons.c index 6c984650323..ffa76466861 100644 --- a/configs/zkit-arm-1769/src/lpc17_buttons.c +++ b/configs/zkit-arm-1769/src/lpc17_buttons.c @@ -109,9 +109,9 @@ void board_button_initialize(void) * Name: board_buttons ****************************************************************************/ -uint8_t board_buttons(void) +uint32_t board_buttons(void) { - uint8_t ret = 0; + uint32_t ret = 0; bool released; int i; diff --git a/include/nuttx/board.h b/include/nuttx/board.h index 0525499021f..310a973c341 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -593,7 +593,7 @@ void board_button_initialize(void); ****************************************************************************/ #ifdef CONFIG_ARCH_BUTTONS -uint8_t board_buttons(void); +uint32_t board_buttons(void); #endif /**************************************************************************** diff --git a/include/nuttx/input/buttons.h b/include/nuttx/input/buttons.h index 3012ba98577..13ba28c3aae 100644 --- a/include/nuttx/input/buttons.h +++ b/include/nuttx/input/buttons.h @@ -96,7 +96,7 @@ * from the button driver. */ -typedef uint8_t btn_buttonset_t; +typedef uint32_t btn_buttonset_t; /* A reference to this structure is provided with the BTNIOC_POLLEVENTS IOCTL * command and describes the conditions under which the client would like diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index da104f89be5..be29abc8cae 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -92,7 +92,7 @@ #define PACKETBUF_ATTR_PACKET_TYPE_STREAM_END 3 #define PACKETBUF_ATTR_PACKET_TYPE_TIMESTAMP 4 -/* Packet buffer attributes (indices into i_pktattr) */ +/* Packet buffer attributes (indices into g_pktattrs) */ #define PACKETBUF_ATTR_NONE 0 @@ -130,7 +130,7 @@ #define PACKETBUF_NUM_ATTRS 24 -/* Addresses (indices into i_pktaddr) */ +/* Addresses (indices into g_pktaddrs) */ #define PACKETBUF_ADDR_SENDER 0 #define PACKETBUF_ADDR_RECEIVER 1 From 55b32430e16a6f8727f196650ef7b46689a7ad01 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 9 Apr 2017 07:48:40 -0600 Subject: [PATCH 19/48] Fix photon/nsh/defconfig, was turning on non-existent LED support when the configuration was refreshed. --- configs/photon/nsh/defconfig | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/configs/photon/nsh/defconfig b/configs/photon/nsh/defconfig index f11b644af39..c82bde94e97 100644 --- a/configs/photon/nsh/defconfig +++ b/configs/photon/nsh/defconfig @@ -90,6 +90,7 @@ CONFIG_ARCH="arm" # CONFIG_ARCH_CHIP_LPC2378 is not set # CONFIG_ARCH_CHIP_LPC31XX is not set # CONFIG_ARCH_CHIP_LPC43XX is not set +# CONFIG_ARCH_CHIP_MOXART is not set # CONFIG_ARCH_CHIP_NUC1XX is not set # CONFIG_ARCH_CHIP_SAMA5 is not set # CONFIG_ARCH_CHIP_SAMD is not set @@ -101,7 +102,7 @@ CONFIG_ARCH_CHIP_STM32=y # CONFIG_ARCH_CHIP_STM32L4 is not set # CONFIG_ARCH_CHIP_STR71X is not set # CONFIG_ARCH_CHIP_TMS570 is not set -# CONFIG_ARCH_CHIP_MOXART is not set +# CONFIG_ARCH_CHIP_XMC4 is not set # CONFIG_ARCH_ARM7TDMI is not set # CONFIG_ARCH_ARM926EJS is not set # CONFIG_ARCH_ARM920T is not set @@ -371,9 +372,13 @@ CONFIG_STM32_HAVE_ADC3=y # CONFIG_STM32_HAVE_SDADC3_DMA is not set CONFIG_STM32_HAVE_CAN1=y CONFIG_STM32_HAVE_CAN2=y +# CONFIG_STM32_HAVE_COMP1 is not set # CONFIG_STM32_HAVE_COMP2 is not set +# CONFIG_STM32_HAVE_COMP3 is not set # CONFIG_STM32_HAVE_COMP4 is not set +# CONFIG_STM32_HAVE_COMP5 is not set # CONFIG_STM32_HAVE_COMP6 is not set +# CONFIG_STM32_HAVE_COMP7 is not set CONFIG_STM32_HAVE_DAC1=y CONFIG_STM32_HAVE_DAC2=y CONFIG_STM32_HAVE_RNG=y @@ -387,7 +392,10 @@ CONFIG_STM32_HAVE_SPI3=y # CONFIG_STM32_HAVE_SPI6 is not set # CONFIG_STM32_HAVE_SAIPLL is not set # CONFIG_STM32_HAVE_I2SPLL is not set -# CONFIG_STM32_HAVE_OPAMP is not set +# CONFIG_STM32_HAVE_OPAMP1 is not set +# CONFIG_STM32_HAVE_OPAMP2 is not set +# CONFIG_STM32_HAVE_OPAMP3 is not set +# CONFIG_STM32_HAVE_OPAMP4 is not set # CONFIG_STM32_ADC1 is not set # CONFIG_STM32_ADC2 is not set # CONFIG_STM32_ADC3 is not set @@ -401,6 +409,7 @@ CONFIG_STM32_HAVE_SPI3=y # CONFIG_STM32_I2C1 is not set # CONFIG_STM32_I2C2 is not set # CONFIG_STM32_I2C3 is not set +# CONFIG_STM32_OPAMP is not set # CONFIG_STM32_OTGFS is not set # CONFIG_STM32_OTGHS is not set # CONFIG_STM32_PWR is not set @@ -436,6 +445,7 @@ CONFIG_STM32_IWDG=y # # Alternate Pin Mapping # +# CONFIG_STM32_FLASH_WORKAROUND_DATA_CACHE_CORRUPTION_ON_RWW is not set # CONFIG_STM32_JTAG_DISABLE is not set # CONFIG_STM32_JTAG_FULL_ENABLE is not set # CONFIG_STM32_JTAG_NOJNTRST_ENABLE is not set @@ -569,6 +579,11 @@ CONFIG_ARCH_BOARD="photon" # # Common Board Options # +CONFIG_ARCH_HAVE_LEDS=y +# CONFIG_ARCH_LEDS is not set +CONFIG_ARCH_HAVE_BUTTONS=y +# CONFIG_ARCH_BUTTONS is not set +CONFIG_ARCH_HAVE_IRQBUTTONS=y # # Board-Specific Options @@ -638,6 +653,8 @@ CONFIG_SCHED_WAITPID=y # # CONFIG_PTHREAD_MUTEX_TYPES is not set CONFIG_PTHREAD_MUTEX_ROBUST=y +# CONFIG_PTHREAD_MUTEX_UNSAFE is not set +# CONFIG_PTHREAD_MUTEX_BOTH is not set CONFIG_NPTHREAD_KEYS=4 # CONFIG_PTHREAD_CLEANUP is not set # CONFIG_CANCELLATION_POINTS is not set @@ -755,6 +772,7 @@ CONFIG_WATCHDOG_DEVPATH="/dev/watchdog0" # # LED Support # +# CONFIG_USERLED is not set # CONFIG_RGBLED is not set # CONFIG_PCA9635PW is not set # CONFIG_NCP5623C is not set @@ -818,6 +836,7 @@ CONFIG_USART1_2STOP=0 # CONFIG_PSEUDOTERM is not set # CONFIG_USBDEV is not set # CONFIG_USBHOST is not set +# CONFIG_USBMISC is not set # CONFIG_HAVE_USBTRACE is not set # CONFIG_DRIVERS_WIRELESS is not set # CONFIG_DRIVERS_CONTACTLESS is not set @@ -1042,10 +1061,6 @@ CONFIG_HAVE_CXXINITIALIZE=y # Application Configuration # -# -# NxWidgets/NxWM -# - # # Built-In Applications # @@ -1058,6 +1073,7 @@ CONFIG_BUILTIN_PROXY_STACKSIZE=1024 # # Examples # +# CONFIG_EXAMPLES_BUTTONS is not set # CONFIG_EXAMPLES_CCTYPE is not set # CONFIG_EXAMPLES_CHAT is not set # CONFIG_EXAMPLES_CONFIGDATA is not set @@ -1072,6 +1088,7 @@ CONFIG_BUILTIN_PROXY_STACKSIZE=1024 # CONFIG_EXAMPLES_IGMP is not set # CONFIG_EXAMPLES_JSON is not set # CONFIG_EXAMPLES_KEYPADTEST is not set +# CONFIG_EXAMPLES_LEDS is not set # CONFIG_EXAMPLES_MEDIA is not set # CONFIG_EXAMPLES_MM is not set # CONFIG_EXAMPLES_MODBUS is not set @@ -1106,9 +1123,9 @@ CONFIG_EXAMPLES_NSH=y # CONFIG_EXAMPLES_TIFF is not set # CONFIG_EXAMPLES_TOUCHSCREEN is not set # CONFIG_EXAMPLES_USBSERIAL is not set -# CONFIG_EXAMPLES_USBTERM is not set # CONFIG_EXAMPLES_WATCHDOG is not set # CONFIG_EXAMPLES_WEBSERVER is not set +# CONFIG_EXAMPLES_XBC_TEST is not set # # File System Utilities @@ -1249,6 +1266,10 @@ CONFIG_NSH_ARCHINIT=y # CONFIG_NSH_LOGIN is not set # CONFIG_NSH_CONSOLE_LOGIN is not set +# +# NxWidgets/NxWM +# + # # Platform-specific Support # From dedc3c15d44232684089a7ae5313b3787c2b98d0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 9 Apr 2017 09:19:25 -0600 Subject: [PATCH 20/48] Add support for NuttX controlled LEDS and for board_initialize. Separate initialize logic to stm32_bringup.c so that in initialization can occur either through board_initialize() or through board_app_initialize(). Same as with most other newer board configurations. --- configs/photon/include/board.h | 33 +++++ configs/photon/src/Makefile | 16 ++- configs/photon/src/photon.h | 15 ++ configs/photon/src/stm32_appinit.c | 83 ++--------- configs/photon/src/stm32_autoleds.c | 116 +++++++++++++++ configs/photon/src/stm32_boot.c | 28 ++++ configs/photon/src/stm32_bringup.c | 132 ++++++++++++++++++ configs/photon/src/stm32_usb.c | 12 -- .../src/{stm32_leds.c => stm32_userleds.c} | 6 +- configs/photon/src/stm32_wdt.c | 5 - configs/photon/src/stm32_wlan.c | 17 ++- configs/same70-xplained/src/sam_autoleds.c | 2 +- 12 files changed, 362 insertions(+), 103 deletions(-) create mode 100644 configs/photon/src/stm32_autoleds.c create mode 100644 configs/photon/src/stm32_bringup.c rename configs/photon/src/{stm32_leds.c => stm32_userleds.c} (97%) diff --git a/configs/photon/include/board.h b/configs/photon/include/board.h index 8c2fc655e3f..96115ca57f0 100644 --- a/configs/photon/include/board.h +++ b/configs/photon/include/board.h @@ -152,11 +152,44 @@ #undef BOARD_ENABLE_USBOTG_HSULPI /* LED definitions ******************************************************************/ +/* LEDs + * + * A single LED is available driven by PA13. + */ + +/* LED index values for use with board_userled() */ #define BOARD_LED1 0 #define BOARD_NLEDS 1 + +/* LED bits for use with board_userled_all() */ + #define BOARD_LED1_BIT (1 << BOARD_LED1) +/* These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is + * defined. In that case, the usage by the board port is defined in + * include/board.h and src/sam_autoleds.c. The LEDs are used to encode + * OS-related events as follows: + * + * ------------------- ---------------------------- ------ + * SYMBOL Meaning LED + * ------------------- ---------------------------- ------ */ + +#define LED_STARTED 0 /* NuttX has been started OFF */ +#define LED_HEAPALLOCATE 0 /* Heap has been allocated OFF */ +#define LED_IRQSENABLED 0 /* Interrupts enabled OFF */ +#define LED_STACKCREATED 1 /* Idle stack created ON */ +#define LED_INIRQ 2 /* In an interrupt N/C */ +#define LED_SIGNAL 2 /* In a signal handler N/C */ +#define LED_ASSERTION 2 /* An assertion failed N/C */ +#define LED_PANIC 3 /* The system has crashed FLASH */ +#undef LED_IDLE /* MCU is is sleep mode Not used */ + +/* Thus if LED is statically on, NuttX has successfully booted and is, + * apparently, running normally. If LED is flashing at approximately + * 2Hz, then a fatal error has been detected and the system has halted. + */ + /* Button definitions ***************************************************************/ #define BOARD_BUTTON1 0 diff --git a/configs/photon/src/Makefile b/configs/photon/src/Makefile index 5d9501759c7..23f31b44899 100644 --- a/configs/photon/src/Makefile +++ b/configs/photon/src/Makefile @@ -35,18 +35,24 @@ -include $(TOPDIR)/Make.defs ASRCS = -CSRCS = stm32_boot.c +CSRCS = stm32_boot.c stm32_bringup.c ifeq ($(CONFIG_PHOTON_DFU_BOOTLOADER),y) CSRCS += dfu_signature.c endif +ifeq ($(CONFIG_LIB_BOARDCTL),y) +CSRCS += stm32_appinit.c +endif + ifeq ($(CONFIG_BUTTONS),y) CSRCS += stm32_buttons.c endif -ifeq ($(CONFIG_USERLED),y) -CSRCS += stm32_leds.c +ifeq ($(CONFIG_ARCH_LEDS),y) +CSRCS += stm32_autoleds.c +else +CSRCS += stm32_userleds.c endif ifeq ($(CONFIG_PHOTON_WDG),y) @@ -61,8 +67,4 @@ ifeq ($(CONFIG_STM32_OTGHS),y) CSRCS += stm32_usb.c endif -ifeq ($(CONFIG_NSH_LIBRARY),y) -CSRCS += stm32_appinit.c -endif - include $(TOPDIR)/configs/Board.mk diff --git a/configs/photon/src/photon.h b/configs/photon/src/photon.h index 4e0f312b6c4..5628d1b69c1 100644 --- a/configs/photon/src/photon.h +++ b/configs/photon/src/photon.h @@ -89,6 +89,21 @@ * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Called either by board_intialize() if CONFIG_BOARD_INITIALIZE or by + * board_app_initialize if CONFIG_LIB_BOARDCTL is selected. This function + * initializes and configures all on-board features appropriate for the + * selected configuration. + * + ****************************************************************************/ + +#if defined(CONFIG_LIB_BOARDCTL) || defined(CONFIG_BOARD_INITIALIZE) +int stm32_bringup(void); +#endif + /**************************************************************************** * Name: photon_watchdog_initialize() * diff --git a/configs/photon/src/stm32_appinit.c b/configs/photon/src/stm32_appinit.c index dc2899789fe..946dfbe8e2b 100644 --- a/configs/photon/src/stm32_appinit.c +++ b/configs/photon/src/stm32_appinit.c @@ -2,7 +2,7 @@ * config/photon/src/stm32_appinit.c * * Copyright (C) 2017 Gregory Nutt. All rights reserved. - * Author: Simon Piriou + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,23 +38,14 @@ ****************************************************************************/ #include -#include -#include -#include +#include + +#include #include "photon.h" -#include "stm32_wdg.h" -#include -#include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef OK -# define OK 0 -#endif +#ifdef CONFIG_LIB_BOARDCTL /**************************************************************************** * Public Functions @@ -87,65 +78,13 @@ int board_app_initialize(uintptr_t arg) { - int ret = OK; +#ifndef CONFIG_BOARD_INITIALIZE + /* Perform board initialization */ -#ifdef CONFIG_USERLED -#ifdef CONFIG_USERLED_LOWER - /* Register the LED driver */ - - ret = userled_lower_initialize("/dev/userleds"); - if (ret != OK) - { - syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret); - return ret; - } + return stm32_bringup(); #else - board_userled_initialize(); -#endif /* CONFIG_USERLED_LOWER */ -#endif /* CONFIG_USERLED */ - -#ifdef CONFIG_BUTTONS -#ifdef CONFIG_BUTTONS_LOWER - /* Register the BUTTON driver */ - - ret = btn_lower_initialize("/dev/buttons"); - if (ret != OK) - { - syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); - return ret; - } -#else - board_button_initialize(); -#endif /* CONFIG_BUTTONS_LOWER */ -#endif /* CONFIG_BUTTONS */ - -#ifdef CONFIG_STM32_IWDG - stm32_iwdginitialize("/dev/watchdog0", STM32_LSI_FREQUENCY); + return OK; #endif - -#ifdef CONFIG_PHOTON_WDG - - /* Start WDG kicker thread */ - - ret = photon_watchdog_initialize(); - if (ret != OK) - { - syslog(LOG_ERR, "Failed to start watchdog thread: %d\n", ret); - return ret; - } -#endif - -#ifdef CONFIG_PHOTON_WLAN - - /* Initialize wlan driver and hardware */ - - ret = photon_wlan_initialize(); - if (ret != OK) - { - syslog(LOG_ERR, "Failed to initialize wlan: %d\n", ret); - return ret; - } -#endif - - return ret; } + +#endif /* CONFIG_LIB_BOARDCTL */ diff --git a/configs/photon/src/stm32_autoleds.c b/configs/photon/src/stm32_autoleds.c new file mode 100644 index 00000000000..a490fa5432f --- /dev/null +++ b/configs/photon/src/stm32_autoleds.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * configs/photon/src/stm32_autoleds.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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. + * + ****************************************************************************/ + +/* LEDs + * + * A single LED is available driven by PA13. + * + * These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is + * defined. In that case, the usage by the board port is defined in + * include/board.h and src/sam_autoleds.c. The LEDs are used to encode + * OS-related events as follows: + * + * ------------------- ----------------------- ------ + * SYMBOL Meaning LED + * ------------------- ----------------------- ------ + * LED_STARTED NuttX has been started OFF + * LED_HEAPALLOCATE Heap has been allocated OFF + * LED_IRQSENABLED Interrupts enabled OFF + * LED_STACKCREATED Idle stack created ON + * LED_INIRQ In an interrupt N/C + * LED_SIGNAL In a signal handler N/C + * LED_ASSERTION An assertion failed N/C + * LED_PANIC The system has crashed FLASH + * + * Thus is LED is statically on, NuttX has successfully booted and is, + * apparently, running normally. If LED is flashing at approximately + * 2Hz, then a fatal error has been detected and the system has halted. + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include + +#include "stm32_gpio.h" +#include "photon.h" + +#ifdef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_autoled_initialize + ****************************************************************************/ + +void board_autoled_initialize(void) +{ + /* Configure Photon LED gpio as output */ + + stm32_configgpio(GPIO_LED1); +} + +/**************************************************************************** + * Name: board_autoled_on + ****************************************************************************/ + +void board_autoled_on(int led) +{ + if (led == 1 || led == 3) + { + stm32_gpiowrite(GPIO_LED1, true); + } +} + +/**************************************************************************** + * Name: board_autoled_off + ****************************************************************************/ + +void board_autoled_off(int led) +{ + if (led == 3) + { + stm32_gpiowrite(GPIO_LED1, false); + } +} + +#endif /* CONFIG_ARCH_LEDS */ diff --git a/configs/photon/src/stm32_boot.c b/configs/photon/src/stm32_boot.c index c9dfe28729a..5adc28f31c2 100644 --- a/configs/photon/src/stm32_boot.c +++ b/configs/photon/src/stm32_boot.c @@ -73,4 +73,32 @@ void stm32_boardinitialize(void) stm32_usbinitialize(); } #endif + +#ifdef CONFIG_ARCH_LEDS + /* Configure on-board LEDs if LED support has been selected. */ + + board_autoled_initialize(); +#endif } + +/**************************************************************************** + * Name: board_initialize + * + * Description: + * If CONFIG_BOARD_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_initialize(). board_initialize() will be + * called immediately after up_intitialize() is called and just before the + * initial application is started. This additional initialization phase + * may be used, for example, to initialize board-specific device drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_INITIALIZE +void board_initialize(void) +{ + /* Perform board initialization */ + + (void)stm32_bringup(); +} +#endif /* CONFIG_BOARD_INITIALIZE */ diff --git a/configs/photon/src/stm32_bringup.c b/configs/photon/src/stm32_bringup.c new file mode 100644 index 00000000000..d83e0493edd --- /dev/null +++ b/configs/photon/src/stm32_bringup.c @@ -0,0 +1,132 @@ +/**************************************************************************** + * config/photon/src/stm32_bringup.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Simon Piriou + * + * 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 + +#include +#include + +#include +#include +#include + +#include + +#include "photon.h" +#include "stm32_wdg.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Called either by board_intialize() if CONFIG_BOARD_INITIALIZE or by + * board_app_initialize if CONFIG_LIB_BOARDCTL is selected. This function + * initializes and configures all on-board features appropriate for the + * selected configuration. + * + ****************************************************************************/ + +int stm32_bringup(void) +{ + int ret = OK; + +#ifdef CONFIG_USERLED +#ifdef CONFIG_USERLED_LOWER + /* Register the LED driver */ + + ret = userled_lower_initialize("/dev/userleds"); + if (ret != OK) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret); + return ret; + } +#else + board_userled_initialize(); +#endif /* CONFIG_USERLED_LOWER */ +#endif /* CONFIG_USERLED */ + +#ifdef CONFIG_BUTTONS +#ifdef CONFIG_BUTTONS_LOWER + /* Register the BUTTON driver */ + + ret = btn_lower_initialize("/dev/buttons"); + if (ret != OK) + { + syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); + return ret; + } +#else + board_button_initialize(); +#endif /* CONFIG_BUTTONS_LOWER */ +#endif /* CONFIG_BUTTONS */ + +#ifdef CONFIG_STM32_IWDG + stm32_iwdginitialize("/dev/watchdog0", STM32_LSI_FREQUENCY); +#endif + +#ifdef CONFIG_PHOTON_WDG + + /* Start WDG kicker thread */ + + ret = photon_watchdog_initialize(); + if (ret != OK) + { + syslog(LOG_ERR, "Failed to start watchdog thread: %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_PHOTON_WLAN + + /* Initialize wlan driver and hardware */ + + ret = photon_wlan_initialize(); + if (ret != OK) + { + syslog(LOG_ERR, "Failed to initialize wlan: %d\n", ret); + return ret; + } +#endif + + return ret; +} diff --git a/configs/photon/src/stm32_usb.c b/configs/photon/src/stm32_usb.c index 5dc24d5ed84..6f361a2c3fa 100644 --- a/configs/photon/src/stm32_usb.c +++ b/configs/photon/src/stm32_usb.c @@ -43,18 +43,6 @@ #include #include -/************************************************************************************ - * Pre-processor Definitions - ************************************************************************************/ - -/************************************************************************************ - * Private Data - ************************************************************************************/ - -/************************************************************************************ - * Private Functions - ************************************************************************************/ - /************************************************************************************ * Public Functions ************************************************************************************/ diff --git a/configs/photon/src/stm32_leds.c b/configs/photon/src/stm32_userleds.c similarity index 97% rename from configs/photon/src/stm32_leds.c rename to configs/photon/src/stm32_userleds.c index 076df40ad6c..8c7366f8a99 100644 --- a/configs/photon/src/stm32_leds.c +++ b/configs/photon/src/stm32_userleds.c @@ -1,5 +1,5 @@ /**************************************************************************** - * configs/photon/src/stm32_leds.c + * configs/photon/src/stm32_userleds.c * * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Author: Simon Piriou @@ -45,6 +45,8 @@ #include "stm32_gpio.h" +#ifndef CONFIG_ARCH_LEDS + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -80,3 +82,5 @@ void board_userled_all(uint8_t ledset) { stm32_gpiowrite(GPIO_LED1, !!(ledset & BOARD_LED1_BIT)); } + +#endif /* !CONFIG_ARCH_LEDS */ diff --git a/configs/photon/src/stm32_wdt.c b/configs/photon/src/stm32_wdt.c index 1df96707c6d..8ea352925c5 100644 --- a/configs/photon/src/stm32_wdt.c +++ b/configs/photon/src/stm32_wdt.c @@ -53,11 +53,6 @@ #include #include -/************************************************************************************ - * Pre-processor Definitions - ************************************************************************************/ -/* Configuration *******************************************************************/ - /************************************************************************************ * Public Functions ************************************************************************************/ diff --git a/configs/photon/src/stm32_wlan.c b/configs/photon/src/stm32_wlan.c index a0b19e4e0fb..068561d63a4 100644 --- a/configs/photon/src/stm32_wlan.c +++ b/configs/photon/src/stm32_wlan.c @@ -38,16 +38,19 @@ ****************************************************************************/ #include + #include -#include #include #include -#include "photon.h" + +#include #include "stm32_gpio.h" #include "stm32_sdio.h" +#include "photon.h" + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -105,25 +108,29 @@ int photon_wlan_initialize() struct sdio_dev_s *sdio_dev; /* Initialize sdio interface */ - _info("Initializing SDIO slot %d\n", SDIO_WLAN0_SLOTNO); + + wlinfo("Initializing SDIO slot %d\n", SDIO_WLAN0_SLOTNO); sdio_dev = sdio_initialize(SDIO_WLAN0_SLOTNO); if (!sdio_dev) { - _err("ERROR: Failed to initialize SDIO with slot %d\n", + wlerr("ERROR: Failed to initialize SDIO with slot %d\n", SDIO_WLAN0_SLOTNO); return ERROR; } /* Bind the SDIO interface to the bcmf driver */ + ret = bcmf_sdio_initialize(SDIO_WLAN0_MINOR, sdio_dev); if (ret != OK) { - _err("ERROR: Failed to bind SDIO to bcmf driver\n"); + wlerr("ERROR: Failed to bind SDIO to bcmf driver\n"); + /* FIXME deinitialize sdio device */ return ERROR; } + return OK; } diff --git a/configs/same70-xplained/src/sam_autoleds.c b/configs/same70-xplained/src/sam_autoleds.c index 64fd6b663c3..51e5272a19c 100644 --- a/configs/same70-xplained/src/sam_autoleds.c +++ b/configs/same70-xplained/src/sam_autoleds.c @@ -1,5 +1,5 @@ /**************************************************************************** - * configs/same70-xplained/include/sam_autoleds.c + * configs/same70-xplained/src/sam_autoleds.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt From f3b10eb073c06b2cd426ccc340d5fedb064d1cc6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 9 Apr 2017 11:06:21 -0600 Subject: [PATCH 21/48] net procfs: Some long lines were being generated that cause buffer-related problems and corrupted output --- net/procfs/netdev_statistics.c | 40 +++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/net/procfs/netdev_statistics.c b/net/procfs/netdev_statistics.c index b2b83da8012..f4927eab2fe 100644 --- a/net/procfs/netdev_statistics.c +++ b/net/procfs/netdev_statistics.c @@ -62,7 +62,9 @@ static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile); static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile); - +#ifdef CONFIG_NET_IPv6 +static int netprocfs_dripaddress(FAR struct netprocfs_file_s *netfile); +#endif #ifdef CONFIG_NETDEV_STATISTICS static int netprocfs_rxstatistics_header(FAR struct netprocfs_file_s *netfile); static int netprocfs_rxstatistics(FAR struct netprocfs_file_s *netfile); @@ -83,6 +85,9 @@ static const linegen_t g_linegen[] = { netprocfs_linklayer, netprocfs_ipaddresses +#ifdef CONFIG_NET_IPv6 + , netprocfs_dripaddress +#endif #ifdef CONFIG_NETDEV_STATISTICS , netprocfs_rxstatistics_header, netprocfs_rxstatistics, @@ -292,7 +297,7 @@ static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile) addr.s_addr = dev->d_netmask; len += snprintf(&netfile->line[len], NET_LINELEN - len, - "Mask:%s\n", inet_ntoa(addr)); + "Mask:%s\n\n", inet_ntoa(addr)); #endif #ifdef CONFIG_NET_IPv6 @@ -307,19 +312,42 @@ static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile) len += snprintf(&netfile->line[len], NET_LINELEN - len, "\tinet6 addr:%s/%d\n", addrstr, preflen); } +#endif - /* REVISIT: Show the IPv6 default router address */ + return len; +} + +/**************************************************************************** + * Name: netprocfs_dripaddress + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv6 +static int netprocfs_dripaddress(FAR struct netprocfs_file_s *netfile) +{ + FAR struct net_driver_s *dev; + char addrstr[INET6_ADDRSTRLEN]; + uint8_t preflen; + int len = 0; + + DEBUGASSERT(netfile != NULL && netfile->dev != NULL); + dev = netfile->dev; + + /* Convert the 128 network mask to a human friendly prefix length */ + + preflen = net_ipv6_mask2pref(dev->d_ipv6netmask); + + + /* Show the IPv6 default router address */ if (inet_ntop(AF_INET6, dev->d_ipv6draddr, addrstr, INET6_ADDRSTRLEN)) { len += snprintf(&netfile->line[len], NET_LINELEN - len, - "\tinet6 DRaddr:%s/%d\n", addrstr, preflen); + "\tinet6 DRaddr:%s/%d\n\n", addrstr, preflen); } -#endif - len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n"); return len; } +#endif /**************************************************************************** * Name: netprocfs_rxstatistics_header From ebd2416f9d5d76b793ffcdbf56c47fce815b021a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 9 Apr 2017 11:47:57 -0600 Subject: [PATCH 22/48] stm32 COMP: Logic in stm32_comp.h must be configured on CONFIG_STM32_COMP or otherwise it causes an error via #error on every platform without COMP support. --- arch/arm/src/stm32/stm32_comp.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm/src/stm32/stm32_comp.h b/arch/arm/src/stm32/stm32_comp.h index 16a0ad69713..ab28cac186a 100644 --- a/arch/arm/src/stm32/stm32_comp.h +++ b/arch/arm/src/stm32/stm32_comp.h @@ -44,6 +44,8 @@ #include "chip.h" +#ifdef CONFIG_STM32_COMP + #if defined(CONFIG_STM32_STM32F30XX) # error "COMP support for STM32F30XX not implemented yet" #elif defined(CONFIG_STM32_STM32F33XX) @@ -211,4 +213,5 @@ FAR struct comp_dev_s* stm32_compinitialize(int intf); #endif #endif /* __ASSEMBLY__ */ +#endif /* CONFIG_STM23_COMP */ #endif /* __ARCH_ARM_SRC_STM32_STM32_COMP_H */ From de2c368249f74d719917f002cf696dc0738fd60f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 9 Apr 2017 12:13:47 -0600 Subject: [PATCH 23/48] Eliminate a warning about garbage at the end of the line. --- configs/tm4c123g-launchpad/src/tm4c_ssi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/tm4c123g-launchpad/src/tm4c_ssi.c b/configs/tm4c123g-launchpad/src/tm4c_ssi.c index 7b295f76aa8..ce8ce7021c6 100644 --- a/configs/tm4c123g-launchpad/src/tm4c_ssi.c +++ b/configs/tm4c123g-launchpad/src/tm4c_ssi.c @@ -59,7 +59,7 @@ * Pre-processor Definitions ************************************************************************************/ -#ifdef CONFIG_DEBUG_SPI_INFO) +#ifdef CONFIG_DEBUG_SPI_INFO # define ssi_dumpgpio(m) tiva_dumpgpio(SDCCS_GPIO, m) #else # define ssi_dumpgpio(m) From 5104eb530f4e48cccb65e71064a9fa8e73ec0a00 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 9 Apr 2017 13:46:27 -0600 Subject: [PATCH 24/48] Photon: Add logic to automatically mount the procfs file system on startup. Fix some LED-related configuration conflicts. --- configs/photon/src/stm32_bringup.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/configs/photon/src/stm32_bringup.c b/configs/photon/src/stm32_bringup.c index d83e0493edd..d55f3bc2915 100644 --- a/configs/photon/src/stm32_bringup.c +++ b/configs/photon/src/stm32_bringup.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -70,7 +71,17 @@ int stm32_bringup(void) { int ret = OK; -#ifdef CONFIG_USERLED +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = mount(NULL, "/proc", "procfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount procfs at /proc: %d\n", ret); + } +#endif + +#if defined(CONFIG_USERLED) && !defined(CONFIG_ARCH_LEDS) #ifdef CONFIG_USERLED_LOWER /* Register the LED driver */ @@ -81,9 +92,11 @@ int stm32_bringup(void) return ret; } #else + /* Enable USER LED support for some other purpose */ + board_userled_initialize(); #endif /* CONFIG_USERLED_LOWER */ -#endif /* CONFIG_USERLED */ +#endif /* CONFIG_USERLED && !CONFIG_ARCH_LEDS */ #ifdef CONFIG_BUTTONS #ifdef CONFIG_BUTTONS_LOWER @@ -96,16 +109,19 @@ int stm32_bringup(void) return ret; } #else + /* Enable BUTTON support for some other purpose */ + board_button_initialize(); #endif /* CONFIG_BUTTONS_LOWER */ #endif /* CONFIG_BUTTONS */ #ifdef CONFIG_STM32_IWDG + /* Initialize the watchdog timer */ + stm32_iwdginitialize("/dev/watchdog0", STM32_LSI_FREQUENCY); #endif #ifdef CONFIG_PHOTON_WDG - /* Start WDG kicker thread */ ret = photon_watchdog_initialize(); @@ -117,7 +133,6 @@ int stm32_bringup(void) #endif #ifdef CONFIG_PHOTON_WLAN - /* Initialize wlan driver and hardware */ ret = photon_wlan_initialize(); From 77f980e676c11c1cb2303d28d73f4c5f5dcfd682 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 9 Apr 2017 14:44:49 -0600 Subject: [PATCH 25/48] Buttons: Correct some comments left after last button-related change: 32- vs 8-bit bit set. --- configs/avr32dev1/src/avr32_buttons.c | 2 +- configs/clicker2-stm32/src/stm32_buttons.c | 2 +- configs/cloudctrl/src/stm32_buttons.c | 2 +- configs/dk-tm4c129x/src/tm4c_buttons.c | 2 +- configs/fire-stm32v2/src/stm32_buttons.c | 2 +- configs/freedom-k64f/src/k64_buttons.c | 2 +- configs/freedom-k66f/src/k66_buttons.c | 2 +- configs/hymini-stm32v/src/stm32_buttons.c | 2 +- configs/kwikstik-k40/src/k40_buttons.c | 2 +- configs/launchxl-tms57004/src/tms570_buttons.c | 2 +- configs/nucleo-144/src/stm32_buttons.c | 2 +- configs/nucleo-f303re/src/stm32_buttons.c | 2 +- configs/nucleo-f4x1re/src/stm32_buttons.c | 2 +- configs/nucleo-l476rg/src/stm32_buttons.c | 2 +- configs/olimex-efm32g880f128-stk/src/efm32_buttons.c | 2 +- configs/olimex-stm32-e407/src/stm32_buttons.c | 2 +- configs/olimex-stm32-h405/src/stm32_buttons.c | 2 +- configs/olimex-stm32-h407/src/stm32_buttons.c | 2 +- configs/olimex-stm32-p207/src/stm32_buttons.c | 2 +- configs/olimex-stm32-p407/src/stm32_buttons.c | 2 +- configs/olimexino-stm32/src/stm32_buttons.c | 4 ++-- configs/pcduino-a10/src/a1x_buttons.c | 2 +- configs/pic32mz-starterkit/src/pic32mz_buttons.c | 2 +- configs/sam3u-ek/src/sam_buttons.c | 2 +- configs/sam4e-ek/src/sam_buttons.c | 2 +- configs/sam4l-xplained/src/sam_buttons.c | 2 +- configs/sam4s-xplained-pro/src/sam_buttons.c | 2 +- configs/sam4s-xplained/src/sam_buttons.c | 2 +- configs/sama5d2-xult/src/sam_buttons.c | 2 +- configs/sama5d3-xplained/src/sam_buttons.c | 2 +- configs/sama5d3x-ek/src/sam_buttons.c | 2 +- configs/sama5d4-ek/src/sam_buttons.c | 2 +- configs/samd20-xplained/src/sam_buttons.c | 2 +- configs/samd21-xplained/src/sam_buttons.c | 2 +- configs/same70-xplained/src/sam_buttons.c | 2 +- configs/saml21-xplained/src/sam_buttons.c | 2 +- configs/samv71-xult/src/sam_buttons.c | 2 +- configs/shenzhou/src/stm32_buttons.c | 2 +- configs/spark/src/stm32_buttons.c | 2 +- configs/stm3210e-eval/src/stm32_buttons.c | 2 +- configs/stm3220g-eval/src/stm32_buttons.c | 2 +- configs/stm3240g-eval/src/stm32_buttons.c | 2 +- configs/stm32f103-minimum/src/stm32_buttons.c | 2 +- configs/stm32f3discovery/src/stm32_buttons.c | 2 +- configs/stm32f429i-disco/src/stm32_buttons.c | 2 +- configs/stm32f4discovery/src/stm32_buttons.c | 2 +- configs/stm32f746g-disco/src/stm32_buttons.c | 2 +- configs/stm32l476-mdk/src/stm32_buttons.c | 2 +- configs/stm32l476vg-disco/src/stm32_buttons.c | 2 +- configs/stm32ldiscovery/src/stm32_buttons.c | 2 +- configs/stm32vldiscovery/src/stm32_buttons.c | 2 +- configs/sure-pic32mx/src/pic32mx_buttons.c | 2 +- configs/tm4c123g-launchpad/src/tm4c_buttons.c | 2 +- configs/twr-k60n512/src/k60_buttons.c | 2 +- configs/ubw32/src/pic32_buttons.c | 2 +- configs/viewtool-stm32f107/src/stm32_buttons.c | 2 +- configs/zkit-arm-1769/src/lpc17_buttons.c | 2 +- include/nuttx/board.h | 2 +- 58 files changed, 59 insertions(+), 59 deletions(-) diff --git a/configs/avr32dev1/src/avr32_buttons.c b/configs/avr32dev1/src/avr32_buttons.c index 427a19d8352..4514a800a5e 100644 --- a/configs/avr32dev1/src/avr32_buttons.c +++ b/configs/avr32dev1/src/avr32_buttons.c @@ -120,7 +120,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions in the board.h header file for the meaning of each bit in * the returned value. * diff --git a/configs/clicker2-stm32/src/stm32_buttons.c b/configs/clicker2-stm32/src/stm32_buttons.c index 922007dcf6d..00a571c817b 100644 --- a/configs/clicker2-stm32/src/stm32_buttons.c +++ b/configs/clicker2-stm32/src/stm32_buttons.c @@ -110,7 +110,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/cloudctrl/src/stm32_buttons.c b/configs/cloudctrl/src/stm32_buttons.c index 6603ce1d078..574e6a15817 100644 --- a/configs/cloudctrl/src/stm32_buttons.c +++ b/configs/cloudctrl/src/stm32_buttons.c @@ -145,7 +145,7 @@ uint32_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the + * 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning * of each bit. * diff --git a/configs/dk-tm4c129x/src/tm4c_buttons.c b/configs/dk-tm4c129x/src/tm4c_buttons.c index 7ef91a768be..7a85cda8e84 100644 --- a/configs/dk-tm4c129x/src/tm4c_buttons.c +++ b/configs/dk-tm4c129x/src/tm4c_buttons.c @@ -137,7 +137,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/fire-stm32v2/src/stm32_buttons.c b/configs/fire-stm32v2/src/stm32_buttons.c index 5c041230f98..d1fcbda1833 100644 --- a/configs/fire-stm32v2/src/stm32_buttons.c +++ b/configs/fire-stm32v2/src/stm32_buttons.c @@ -121,7 +121,7 @@ uint32_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the + * 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning * of each bit. * diff --git a/configs/freedom-k64f/src/k64_buttons.c b/configs/freedom-k64f/src/k64_buttons.c index d6f6ea44d6d..53caa760b83 100644 --- a/configs/freedom-k64f/src/k64_buttons.c +++ b/configs/freedom-k64f/src/k64_buttons.c @@ -120,7 +120,7 @@ uint32_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may * be called to collect the state of all buttons. board_buttons() returns - * an 8-bit bit set with each bit associated with a button. See the + * an 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning * of each bit. * diff --git a/configs/freedom-k66f/src/k66_buttons.c b/configs/freedom-k66f/src/k66_buttons.c index ce63345c856..b186d40b412 100644 --- a/configs/freedom-k66f/src/k66_buttons.c +++ b/configs/freedom-k66f/src/k66_buttons.c @@ -124,7 +124,7 @@ uint32_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may * be called to collect the state of all buttons. board_buttons() returns - * an 8-bit bit set with each bit associated with a button. See the + * an 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning * of each bit. * diff --git a/configs/hymini-stm32v/src/stm32_buttons.c b/configs/hymini-stm32v/src/stm32_buttons.c index 757f159af74..4dac6fc8f41 100644 --- a/configs/hymini-stm32v/src/stm32_buttons.c +++ b/configs/hymini-stm32v/src/stm32_buttons.c @@ -120,7 +120,7 @@ uint32_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the + * 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning * of each bit. * diff --git a/configs/kwikstik-k40/src/k40_buttons.c b/configs/kwikstik-k40/src/k40_buttons.c index 35f673d0ea0..c66c2d858cf 100644 --- a/configs/kwikstik-k40/src/k40_buttons.c +++ b/configs/kwikstik-k40/src/k40_buttons.c @@ -92,7 +92,7 @@ uint32_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the + * 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT and JOYSTICK_*_BIT definitions in board.h for the meaning * of each bit. * diff --git a/configs/launchxl-tms57004/src/tms570_buttons.c b/configs/launchxl-tms57004/src/tms570_buttons.c index 3ee9e0eb31d..d84de8f63a4 100644 --- a/configs/launchxl-tms57004/src/tms570_buttons.c +++ b/configs/launchxl-tms57004/src/tms570_buttons.c @@ -154,7 +154,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ diff --git a/configs/nucleo-144/src/stm32_buttons.c b/configs/nucleo-144/src/stm32_buttons.c index 5d47aa30bd9..a8783b4e20c 100644 --- a/configs/nucleo-144/src/stm32_buttons.c +++ b/configs/nucleo-144/src/stm32_buttons.c @@ -92,7 +92,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/nucleo-f303re/src/stm32_buttons.c b/configs/nucleo-f303re/src/stm32_buttons.c index 8ae6081f489..e40db64c282 100644 --- a/configs/nucleo-f303re/src/stm32_buttons.c +++ b/configs/nucleo-f303re/src/stm32_buttons.c @@ -83,7 +83,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit unsigned integer with each bit associated with a button. See the + * 32-bit unsigned integer with each bit associated with a button. See the * BUTTON_*_BIT definitions in board.h for the meaning of each bit. * ****************************************************************************/ diff --git a/configs/nucleo-f4x1re/src/stm32_buttons.c b/configs/nucleo-f4x1re/src/stm32_buttons.c index 30fd294fc59..fe18b0b2163 100644 --- a/configs/nucleo-f4x1re/src/stm32_buttons.c +++ b/configs/nucleo-f4x1re/src/stm32_buttons.c @@ -98,7 +98,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/nucleo-l476rg/src/stm32_buttons.c b/configs/nucleo-l476rg/src/stm32_buttons.c index 55f99e8192b..456795c304e 100644 --- a/configs/nucleo-l476rg/src/stm32_buttons.c +++ b/configs/nucleo-l476rg/src/stm32_buttons.c @@ -98,7 +98,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c b/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c index 9637b125550..2863a332c18 100644 --- a/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c +++ b/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c @@ -120,7 +120,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ diff --git a/configs/olimex-stm32-e407/src/stm32_buttons.c b/configs/olimex-stm32-e407/src/stm32_buttons.c index c57c54f42df..e52d296079b 100644 --- a/configs/olimex-stm32-e407/src/stm32_buttons.c +++ b/configs/olimex-stm32-e407/src/stm32_buttons.c @@ -121,7 +121,7 @@ uint32_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON_*_BIT + * 32-bit bit set with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * * board_button_irq() may be called to register an interrupt handler that diff --git a/configs/olimex-stm32-h405/src/stm32_buttons.c b/configs/olimex-stm32-h405/src/stm32_buttons.c index e7bd98cf23e..abcac85c801 100644 --- a/configs/olimex-stm32-h405/src/stm32_buttons.c +++ b/configs/olimex-stm32-h405/src/stm32_buttons.c @@ -120,7 +120,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/olimex-stm32-h407/src/stm32_buttons.c b/configs/olimex-stm32-h407/src/stm32_buttons.c index 976157d1170..1155069e5ef 100644 --- a/configs/olimex-stm32-h407/src/stm32_buttons.c +++ b/configs/olimex-stm32-h407/src/stm32_buttons.c @@ -121,7 +121,7 @@ uint32_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON_*_BIT + * 32-bit bit set with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * * board_button_irq() may be called to register an interrupt handler that diff --git a/configs/olimex-stm32-p207/src/stm32_buttons.c b/configs/olimex-stm32-p207/src/stm32_buttons.c index 9400b7456c0..bde278810b0 100644 --- a/configs/olimex-stm32-p207/src/stm32_buttons.c +++ b/configs/olimex-stm32-p207/src/stm32_buttons.c @@ -156,7 +156,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/olimex-stm32-p407/src/stm32_buttons.c b/configs/olimex-stm32-p407/src/stm32_buttons.c index 3d98c9eab7f..a7bf89714df 100644 --- a/configs/olimex-stm32-p407/src/stm32_buttons.c +++ b/configs/olimex-stm32-p407/src/stm32_buttons.c @@ -158,7 +158,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/olimexino-stm32/src/stm32_buttons.c b/configs/olimexino-stm32/src/stm32_buttons.c index cc6ea25509c..092383cadeb 100644 --- a/configs/olimexino-stm32/src/stm32_buttons.c +++ b/configs/olimexino-stm32/src/stm32_buttons.c @@ -63,7 +63,7 @@ * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. + * 32-bit bit set with each bit associated with a button. * See the BUTTON_*_BIT definitions in board.h for the meaning of each bit. * * board_button_irq() may be called to register an interrupt handler that @@ -97,7 +97,7 @@ void board_button_initialize(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. + * 32-bit bit set with each bit associated with a button. * See the BUTTON_*_BIT definitions in board.h for the meaning of each bit. * ****************************************************************************/ diff --git a/configs/pcduino-a10/src/a1x_buttons.c b/configs/pcduino-a10/src/a1x_buttons.c index c7d10891352..4d4feccc0f9 100644 --- a/configs/pcduino-a10/src/a1x_buttons.c +++ b/configs/pcduino-a10/src/a1x_buttons.c @@ -78,7 +78,7 @@ void board_button_initialize(void) * * Description: * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON* definitions * above for the meaning of each bit in the returned value. * diff --git a/configs/pic32mz-starterkit/src/pic32mz_buttons.c b/configs/pic32mz-starterkit/src/pic32mz_buttons.c index 206be294c31..639844a953b 100644 --- a/configs/pic32mz-starterkit/src/pic32mz_buttons.c +++ b/configs/pic32mz-starterkit/src/pic32mz_buttons.c @@ -140,7 +140,7 @@ uint32_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the + * 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT definitions in board.h for the meaning of each bit. * * board_button_irq() may be called to register an interrupt handler that diff --git a/configs/sam3u-ek/src/sam_buttons.c b/configs/sam3u-ek/src/sam_buttons.c index 107c7036a66..19a00d97ece 100644 --- a/configs/sam3u-ek/src/sam_buttons.c +++ b/configs/sam3u-ek/src/sam_buttons.c @@ -127,7 +127,7 @@ void board_button_initialize(void) * * Description: * After board_button_initialize() has been called, board_buttons() may be called to collect - * the state of all buttons. board_buttons() returns an 8-bit bit set with each bit + * the state of all buttons. board_buttons() returns an 32-bit bit set with each bit * associated with a button. See the BUTTON* definitions above for the meaning of * each bit in the returned value. * diff --git a/configs/sam4e-ek/src/sam_buttons.c b/configs/sam4e-ek/src/sam_buttons.c index 53626290b7b..ed3690782a2 100644 --- a/configs/sam4e-ek/src/sam_buttons.c +++ b/configs/sam4e-ek/src/sam_buttons.c @@ -130,7 +130,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ diff --git a/configs/sam4l-xplained/src/sam_buttons.c b/configs/sam4l-xplained/src/sam_buttons.c index 8d306bb3117..78949a1cde0 100644 --- a/configs/sam4l-xplained/src/sam_buttons.c +++ b/configs/sam4l-xplained/src/sam_buttons.c @@ -79,7 +79,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ diff --git a/configs/sam4s-xplained-pro/src/sam_buttons.c b/configs/sam4s-xplained-pro/src/sam_buttons.c index 3b9b4fe3597..f19f29894ea 100644 --- a/configs/sam4s-xplained-pro/src/sam_buttons.c +++ b/configs/sam4s-xplained-pro/src/sam_buttons.c @@ -81,7 +81,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ diff --git a/configs/sam4s-xplained/src/sam_buttons.c b/configs/sam4s-xplained/src/sam_buttons.c index 314e8e1818a..5b979a1aa95 100644 --- a/configs/sam4s-xplained/src/sam_buttons.c +++ b/configs/sam4s-xplained/src/sam_buttons.c @@ -80,7 +80,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ diff --git a/configs/sama5d2-xult/src/sam_buttons.c b/configs/sama5d2-xult/src/sam_buttons.c index 0939ddaa11d..56548f34804 100644 --- a/configs/sama5d2-xult/src/sam_buttons.c +++ b/configs/sama5d2-xult/src/sam_buttons.c @@ -91,7 +91,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ diff --git a/configs/sama5d3-xplained/src/sam_buttons.c b/configs/sama5d3-xplained/src/sam_buttons.c index 43794b374da..768b7b5db7c 100644 --- a/configs/sama5d3-xplained/src/sam_buttons.c +++ b/configs/sama5d3-xplained/src/sam_buttons.c @@ -95,7 +95,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ diff --git a/configs/sama5d3x-ek/src/sam_buttons.c b/configs/sama5d3x-ek/src/sam_buttons.c index dbdaa310f67..e76fcd2a0ab 100644 --- a/configs/sama5d3x-ek/src/sam_buttons.c +++ b/configs/sama5d3x-ek/src/sam_buttons.c @@ -95,7 +95,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ diff --git a/configs/sama5d4-ek/src/sam_buttons.c b/configs/sama5d4-ek/src/sam_buttons.c index 4ccae619f60..90dff73b160 100644 --- a/configs/sama5d4-ek/src/sam_buttons.c +++ b/configs/sama5d4-ek/src/sam_buttons.c @@ -91,7 +91,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ diff --git a/configs/samd20-xplained/src/sam_buttons.c b/configs/samd20-xplained/src/sam_buttons.c index fc8f14bd0ce..334bf8b4038 100644 --- a/configs/samd20-xplained/src/sam_buttons.c +++ b/configs/samd20-xplained/src/sam_buttons.c @@ -79,7 +79,7 @@ void board_button_initialize(void) * * Description: * After board_button_initialize() has been called, board_buttons() may be called to collect - * the state of all buttons. board_buttons() returns an 8-bit bit set with each bit + * the state of all buttons. board_buttons() returns an 32-bit bit set with each bit * associated with a button. See the BUTTON* definitions above for the meaning of * each bit in the returned value. * diff --git a/configs/samd21-xplained/src/sam_buttons.c b/configs/samd21-xplained/src/sam_buttons.c index e4c31aa941e..8e1789d1c9d 100644 --- a/configs/samd21-xplained/src/sam_buttons.c +++ b/configs/samd21-xplained/src/sam_buttons.c @@ -79,7 +79,7 @@ void board_button_initialize(void) * * Description: * After board_button_initialize() has been called, board_buttons() may be called to collect - * the state of all buttons. board_buttons() returns an 8-bit bit set with each bit + * the state of all buttons. board_buttons() returns an 32-bit bit set with each bit * associated with a button. See the BUTTON* definitions above for the meaning of * each bit in the returned value. * diff --git a/configs/same70-xplained/src/sam_buttons.c b/configs/same70-xplained/src/sam_buttons.c index 7e66905c8a1..ab7dfeb8cfc 100644 --- a/configs/same70-xplained/src/sam_buttons.c +++ b/configs/same70-xplained/src/sam_buttons.c @@ -142,7 +142,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ diff --git a/configs/saml21-xplained/src/sam_buttons.c b/configs/saml21-xplained/src/sam_buttons.c index 909fa58a7a7..407b24bb4d9 100644 --- a/configs/saml21-xplained/src/sam_buttons.c +++ b/configs/saml21-xplained/src/sam_buttons.c @@ -79,7 +79,7 @@ void board_button_initialize(void) * * Description: * After board_button_initialize() has been called, board_buttons() may be called to collect - * the state of all buttons. board_buttons() returns an 8-bit bit set with each bit + * the state of all buttons. board_buttons() returns an 32-bit bit set with each bit * associated with a button. See the BUTTON* definitions above for the meaning of * each bit in the returned value. * diff --git a/configs/samv71-xult/src/sam_buttons.c b/configs/samv71-xult/src/sam_buttons.c index 1a06c840342..adcd280d73f 100644 --- a/configs/samv71-xult/src/sam_buttons.c +++ b/configs/samv71-xult/src/sam_buttons.c @@ -158,7 +158,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ diff --git a/configs/shenzhou/src/stm32_buttons.c b/configs/shenzhou/src/stm32_buttons.c index 139d517956f..57053359b8f 100644 --- a/configs/shenzhou/src/stm32_buttons.c +++ b/configs/shenzhou/src/stm32_buttons.c @@ -136,7 +136,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/spark/src/stm32_buttons.c b/configs/spark/src/stm32_buttons.c index 3ab2f3c8546..3534eeeb6ac 100644 --- a/configs/spark/src/stm32_buttons.c +++ b/configs/spark/src/stm32_buttons.c @@ -95,7 +95,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm3210e-eval/src/stm32_buttons.c b/configs/stm3210e-eval/src/stm32_buttons.c index b9f48228143..f6a8575881f 100644 --- a/configs/stm3210e-eval/src/stm32_buttons.c +++ b/configs/stm3210e-eval/src/stm32_buttons.c @@ -148,7 +148,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm3220g-eval/src/stm32_buttons.c b/configs/stm3220g-eval/src/stm32_buttons.c index 669b460b032..9bec8f3c10b 100644 --- a/configs/stm3220g-eval/src/stm32_buttons.c +++ b/configs/stm3220g-eval/src/stm32_buttons.c @@ -136,7 +136,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm3240g-eval/src/stm32_buttons.c b/configs/stm3240g-eval/src/stm32_buttons.c index 4682ffb1a9f..c543a0b6acb 100644 --- a/configs/stm3240g-eval/src/stm32_buttons.c +++ b/configs/stm3240g-eval/src/stm32_buttons.c @@ -144,7 +144,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm32f103-minimum/src/stm32_buttons.c b/configs/stm32f103-minimum/src/stm32_buttons.c index 6891b3db0a6..154f24225e8 100644 --- a/configs/stm32f103-minimum/src/stm32_buttons.c +++ b/configs/stm32f103-minimum/src/stm32_buttons.c @@ -140,7 +140,7 @@ uint32_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns - * an 8-bit bit set with each bit associated with a button. See the + * an 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT definitions in board.h for the meaning of each bit. * * board_button_irq() may be called to register an interrupt handler that diff --git a/configs/stm32f3discovery/src/stm32_buttons.c b/configs/stm32f3discovery/src/stm32_buttons.c index a0ecada6a5a..a17912bdbd6 100644 --- a/configs/stm32f3discovery/src/stm32_buttons.c +++ b/configs/stm32f3discovery/src/stm32_buttons.c @@ -131,7 +131,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm32f429i-disco/src/stm32_buttons.c b/configs/stm32f429i-disco/src/stm32_buttons.c index d2e9ba2e095..c5ce618d0c7 100644 --- a/configs/stm32f429i-disco/src/stm32_buttons.c +++ b/configs/stm32f429i-disco/src/stm32_buttons.c @@ -131,7 +131,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm32f4discovery/src/stm32_buttons.c b/configs/stm32f4discovery/src/stm32_buttons.c index 2d86ea80cf7..2b805075e00 100644 --- a/configs/stm32f4discovery/src/stm32_buttons.c +++ b/configs/stm32f4discovery/src/stm32_buttons.c @@ -131,7 +131,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm32f746g-disco/src/stm32_buttons.c b/configs/stm32f746g-disco/src/stm32_buttons.c index b8a46a8dacd..42faf1d90f3 100644 --- a/configs/stm32f746g-disco/src/stm32_buttons.c +++ b/configs/stm32f746g-disco/src/stm32_buttons.c @@ -92,7 +92,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm32l476-mdk/src/stm32_buttons.c b/configs/stm32l476-mdk/src/stm32_buttons.c index 7debe3c5970..58e9079153d 100644 --- a/configs/stm32l476-mdk/src/stm32_buttons.c +++ b/configs/stm32l476-mdk/src/stm32_buttons.c @@ -138,7 +138,7 @@ uint32_t board_buttons(void) * * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the + * 32-bit bit set with each bit associated with a button. See the * BUTTON_*_BIT definitions in board.h for the meaning of each bit. * * board_button_irq() may be called to register an interrupt handler that diff --git a/configs/stm32l476vg-disco/src/stm32_buttons.c b/configs/stm32l476vg-disco/src/stm32_buttons.c index f3c4d50c9c5..18b984d2c1f 100644 --- a/configs/stm32l476vg-disco/src/stm32_buttons.c +++ b/configs/stm32l476vg-disco/src/stm32_buttons.c @@ -306,7 +306,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm32ldiscovery/src/stm32_buttons.c b/configs/stm32ldiscovery/src/stm32_buttons.c index f766017d150..d985c9f4d3d 100644 --- a/configs/stm32ldiscovery/src/stm32_buttons.c +++ b/configs/stm32ldiscovery/src/stm32_buttons.c @@ -131,7 +131,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/stm32vldiscovery/src/stm32_buttons.c b/configs/stm32vldiscovery/src/stm32_buttons.c index 9784b19d773..95d9f1590c5 100644 --- a/configs/stm32vldiscovery/src/stm32_buttons.c +++ b/configs/stm32vldiscovery/src/stm32_buttons.c @@ -94,7 +94,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/sure-pic32mx/src/pic32mx_buttons.c b/configs/sure-pic32mx/src/pic32mx_buttons.c index bf5ca03429e..e2ee0ac2195 100644 --- a/configs/sure-pic32mx/src/pic32mx_buttons.c +++ b/configs/sure-pic32mx/src/pic32mx_buttons.c @@ -185,7 +185,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/tm4c123g-launchpad/src/tm4c_buttons.c b/configs/tm4c123g-launchpad/src/tm4c_buttons.c index 96370046f48..24eb21ea04a 100644 --- a/configs/tm4c123g-launchpad/src/tm4c_buttons.c +++ b/configs/tm4c123g-launchpad/src/tm4c_buttons.c @@ -113,7 +113,7 @@ void board_button_initialize(void) * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. See the BUTTON* + * 32-bit bit set with each bit associated with a button. See the BUTTON* * definitions above for the meaning of each bit in the returned value. * ****************************************************************************/ diff --git a/configs/twr-k60n512/src/k60_buttons.c b/configs/twr-k60n512/src/k60_buttons.c index d9206f2c71a..99bee759102 100644 --- a/configs/twr-k60n512/src/k60_buttons.c +++ b/configs/twr-k60n512/src/k60_buttons.c @@ -121,7 +121,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/ubw32/src/pic32_buttons.c b/configs/ubw32/src/pic32_buttons.c index 69b1deeb442..469167f1379 100644 --- a/configs/ubw32/src/pic32_buttons.c +++ b/configs/ubw32/src/pic32_buttons.c @@ -160,7 +160,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT definitions in * board.h for the meaning of each bit. * diff --git a/configs/viewtool-stm32f107/src/stm32_buttons.c b/configs/viewtool-stm32f107/src/stm32_buttons.c index 9e39a2d72c4..086a321755a 100644 --- a/configs/viewtool-stm32f107/src/stm32_buttons.c +++ b/configs/viewtool-stm32f107/src/stm32_buttons.c @@ -132,7 +132,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/configs/zkit-arm-1769/src/lpc17_buttons.c b/configs/zkit-arm-1769/src/lpc17_buttons.c index ffa76466861..e93f27734f7 100644 --- a/configs/zkit-arm-1769/src/lpc17_buttons.c +++ b/configs/zkit-arm-1769/src/lpc17_buttons.c @@ -142,7 +142,7 @@ uint32_t board_buttons(void) * handlers. * * After board_button_initialize() has been called, board_buttons() may be called to - * collect the state of all buttons. board_buttons() returns an 8-bit bit set + * collect the state of all buttons. board_buttons() returns an 32-bit bit set * with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT * definitions in board.h for the meaning of each bit. * diff --git a/include/nuttx/board.h b/include/nuttx/board.h index 310a973c341..c00d09ce3c2 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -581,7 +581,7 @@ void board_button_initialize(void); * Description: * After board_button_initialize() has been called, board_buttons() may be * called to collect the state of all buttons. board_buttons() returns an - * 8-bit bit set with each bit associated with a button. A bit set to + * 32-bit bit set with each bit associated with a button. A bit set to * "1" means that the button is depressed; a bit set to "0" means that * the button is released. The correspondence of the each button bit * and physical buttons is board-specific. From 755e9312b51f8a03f38d9287e1e2bfbae285cfbe Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Mon, 10 Apr 2017 07:18:16 -0600 Subject: [PATCH 26/48] pthread: use cancel cleanup handlers in rwlock --- libc/pthread/pthread_rwlock_rdlock.c | 17 ++++++++++++++++- libc/pthread/pthread_rwlock_wrlock.c | 27 +++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/libc/pthread/pthread_rwlock_rdlock.c b/libc/pthread/pthread_rwlock_rdlock.c index 9fd461a758e..19979f79bb2 100644 --- a/libc/pthread/pthread_rwlock_rdlock.c +++ b/libc/pthread/pthread_rwlock_rdlock.c @@ -1,5 +1,5 @@ /**************************************************************************** - * libc/pthread/pthread_rwlockread.c + * libc/pthread/pthread_rwlock_rdlock.c * * Copyright (C) 2017 Mark Schulte. All rights reserved. * Author: Mark Schulte @@ -50,6 +50,15 @@ * Private Functions ****************************************************************************/ +#ifdef CONFIG_PTHREAD_CLEANUP +static void rdlock_cleanup(FAR void *arg) +{ + FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg; + + pthread_mutex_unlock(&rw_lock->lock); +} +#endif + static int tryrdlock(FAR pthread_rwlock_t *rw_lock) { int err; @@ -116,6 +125,9 @@ int pthread_rwlock_timedrdlock(FAR pthread_rwlock_t *rw_lock, return err; } +#ifdef CONFIG_PTHREAD_CLEANUP + pthread_cleanup_push(&rdlock_cleanup, rw_lock); +#endif while ((err = tryrdlock(rw_lock)) == EBUSY) { if (ts != NULL) @@ -132,6 +144,9 @@ int pthread_rwlock_timedrdlock(FAR pthread_rwlock_t *rw_lock, break; } } +#ifdef CONFIG_PTHREAD_CLEANUP + pthread_cleanup_pop(0); +#endif pthread_mutex_unlock(&rw_lock->lock); return err; diff --git a/libc/pthread/pthread_rwlock_wrlock.c b/libc/pthread/pthread_rwlock_wrlock.c index ecda4cb25be..fcda35cb4f5 100644 --- a/libc/pthread/pthread_rwlock_wrlock.c +++ b/libc/pthread/pthread_rwlock_wrlock.c @@ -1,5 +1,5 @@ /**************************************************************************** - * libc/pthread/pthread_rwlockwrite.c + * libc/pthread/pthread_rwlock_wrlock.c * * Copyright (C) 2017 Mark Schulte. All rights reserved. * Author: Mark Schulte @@ -46,15 +46,29 @@ #include +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#ifdef CONFIG_PTHREAD_CLEANUP +static void wrlock_cleanup(FAR void *arg) +{ + FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg; + + rw_lock->num_writers--; + pthread_mutex_unlock(&rw_lock->lock); +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: pthread_rwlock_rdlock + * Name: pthread_rwlock_wrlock * * Description: - * Locks a read/write lock for reading + * Locks a read/write lock for writing * * Parameters: * None @@ -106,6 +120,9 @@ int pthread_rwlock_timedwrlock(FAR pthread_rwlock_t *rw_lock, rw_lock->num_writers++; +#ifdef CONFIG_PTHREAD_CLEANUP + pthread_cleanup_push(&wrlock_cleanup, rw_lock); +#endif while (rw_lock->write_in_progress || rw_lock->num_readers > 0) { if (ts != NULL) @@ -122,12 +139,14 @@ int pthread_rwlock_timedwrlock(FAR pthread_rwlock_t *rw_lock, break; } } +#ifdef CONFIG_PTHREAD_CLEANUP + pthread_cleanup_pop(0); +#endif if (err == 0) { rw_lock->write_in_progress = true; } - else { /* In case of error, notify any blocked readers. */ From b51b72b2dba6dc7350cddfa40ca93203ebbc6932 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 10 Apr 2017 08:11:16 -0600 Subject: [PATCH 27/48] pthreads: Re-order some operations so that mutexes are placed in the inconsistent state BEFORE the clean-up callbacks are called. --- sched/Kconfig | 4 ++-- sched/pthread/pthread_cancel.c | 12 ++++++------ sched/pthread/pthread_exit.c | 12 ++++++------ sched/pthread/pthread_mutexconsistent.c | 4 +++- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/sched/Kconfig b/sched/Kconfig index 50613fb44d3..6cefe0e121f 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -601,8 +601,6 @@ config PTHREAD_CLEANUP_STACKSIZE 8 for a CPU with 32-bit addressing and 4 for a CPU with 16-bit addressing. -endmenu # Pthread Options - config CANCELLATION_POINTS bool "Cancellation points" default n @@ -611,6 +609,8 @@ config CANCELLATION_POINTS cancellation points will also used with the () task_delete() API even if pthreads are not enabled. +endmenu # Pthread Options + menu "Performance Monitoring" config SCHED_CPULOAD diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c index e2cad60ebbf..f68d272e03a 100644 --- a/sched/pthread/pthread_cancel.c +++ b/sched/pthread/pthread_cancel.c @@ -145,6 +145,12 @@ int pthread_cancel(pthread_t thread) pthread_exit(PTHREAD_CANCELED); } +#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE + /* Recover any mutexes still held by the canceled thread */ + + pthread_mutex_inconsistent(tcb); +#endif + #ifdef CONFIG_PTHREAD_CLEANUP /* Perform any stack pthread clean-up callbacks. * @@ -162,12 +168,6 @@ int pthread_cancel(pthread_t thread) (void)pthread_completejoin((pid_t)thread, PTHREAD_CANCELED); -#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE - /* Recover any mutexes still held by the canceled thread */ - - pthread_mutex_inconsistent(tcb); -#endif - /* Then let task_terminate do the real work */ return task_terminate((pid_t)thread, false); diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c index bcc8e79c855..4929db94cb5 100644 --- a/sched/pthread/pthread_exit.c +++ b/sched/pthread/pthread_exit.c @@ -105,6 +105,12 @@ void pthread_exit(FAR void *exit_value) tcb->cpcount = 0; #endif +#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE + /* Recover any mutexes still held by the canceled thread */ + + pthread_mutex_inconsistent((FAR struct pthread_tcb_s *)tcb); +#endif + #ifdef CONFIG_PTHREAD_CLEANUP /* Perform any stack pthread clean-up callbacks */ @@ -123,12 +129,6 @@ void pthread_exit(FAR void *exit_value) exit(EXIT_FAILURE); } -#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE - /* Recover any mutexes still held by the canceled thread */ - - pthread_mutex_inconsistent((FAR struct pthread_tcb_s *)tcb); -#endif - /* Perform common task termination logic. This will get called again later * through logic kicked off by _exit(). However, we need to call it before * calling _exit() in order certain operations if this is the last thread diff --git a/sched/pthread/pthread_mutexconsistent.c b/sched/pthread/pthread_mutexconsistent.c index 77d9bede3e5..e374083021f 100644 --- a/sched/pthread/pthread_mutexconsistent.c +++ b/sched/pthread/pthread_mutexconsistent.c @@ -119,7 +119,6 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex) /* The thread associated with the PID no longer exists */ mutex->pid = -1; - mutex->flags &= _PTHREAD_MFLAGS_ROBUST; #ifdef CONFIG_PTHREAD_MUTEX_TYPES mutex->nlocks = 0; #endif @@ -132,6 +131,9 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex) } } + /* Clear the inconsistent flag in any case */ + + mutex->flags &= _PTHREAD_MFLAGS_ROBUST; sched_unlock(); ret = OK; } From 84849cfc5ec7b74bab3c7a21b2babed14c89e37d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 10 Apr 2017 08:44:08 -0600 Subject: [PATCH 28/48] examples/ostest: pthread rwlock cleanup handlers must call pthread_consistent, not pthread_mutex_unlock() on cancellation if robust mutexes are enabled. --- libc/pthread/pthread_rwlock_rdlock.c | 13 ++++++++++++- libc/pthread/pthread_rwlock_wrlock.c | 14 +++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libc/pthread/pthread_rwlock_rdlock.c b/libc/pthread/pthread_rwlock_rdlock.c index 19979f79bb2..29dcf7daae1 100644 --- a/libc/pthread/pthread_rwlock_rdlock.c +++ b/libc/pthread/pthread_rwlock_rdlock.c @@ -55,7 +55,18 @@ static void rdlock_cleanup(FAR void *arg) { FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg; - pthread_mutex_unlock(&rw_lock->lock); +#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE + /* Check if this is a robust mutex in an inconsistent state */ + + if ((rw_lock->lock.flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0) + { + (void)pthread_mutex_consistent(&rw_lock->lock); + } + else +#endif + { + (void)pthread_mutex_unlock(&rw_lock->lock); + } } #endif diff --git a/libc/pthread/pthread_rwlock_wrlock.c b/libc/pthread/pthread_rwlock_wrlock.c index fcda35cb4f5..93a6a238582 100644 --- a/libc/pthread/pthread_rwlock_wrlock.c +++ b/libc/pthread/pthread_rwlock_wrlock.c @@ -56,7 +56,19 @@ static void wrlock_cleanup(FAR void *arg) FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg; rw_lock->num_writers--; - pthread_mutex_unlock(&rw_lock->lock); + +#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE + /* Check if this is a robust mutex in an inconsistent state */ + + if ((rw_lock->lock.flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0) + { + (void)pthread_mutex_consistent(&rw_lock->lock); + } + else +#endif + { + (void)pthread_mutex_unlock(&rw_lock->lock); + } } #endif From 948332ca343f596acf7af0b434812a2bb7f90079 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 10 Apr 2017 09:51:03 -0600 Subject: [PATCH 29/48] pthreads: Backed most of last pthread changes. Found the 'real' root poblem. A one like error in pthread_mutex.c. --- libc/pthread/pthread_rwlock_rdlock.c | 13 +------------ libc/pthread/pthread_rwlock_wrlock.c | 14 +------------- sched/pthread/pthread_cancel.c | 12 ++++++------ sched/pthread/pthread_exit.c | 12 ++++++------ sched/pthread/pthread_mutex.c | 6 ++++-- 5 files changed, 18 insertions(+), 39 deletions(-) diff --git a/libc/pthread/pthread_rwlock_rdlock.c b/libc/pthread/pthread_rwlock_rdlock.c index 29dcf7daae1..4eadfedccb5 100644 --- a/libc/pthread/pthread_rwlock_rdlock.c +++ b/libc/pthread/pthread_rwlock_rdlock.c @@ -55,18 +55,7 @@ static void rdlock_cleanup(FAR void *arg) { FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg; -#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE - /* Check if this is a robust mutex in an inconsistent state */ - - if ((rw_lock->lock.flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0) - { - (void)pthread_mutex_consistent(&rw_lock->lock); - } - else -#endif - { - (void)pthread_mutex_unlock(&rw_lock->lock); - } + (void)pthread_mutex_unlock(&rw_lock->lock); } #endif diff --git a/libc/pthread/pthread_rwlock_wrlock.c b/libc/pthread/pthread_rwlock_wrlock.c index 93a6a238582..c9f4f3a7c56 100644 --- a/libc/pthread/pthread_rwlock_wrlock.c +++ b/libc/pthread/pthread_rwlock_wrlock.c @@ -56,19 +56,7 @@ static void wrlock_cleanup(FAR void *arg) FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg; rw_lock->num_writers--; - -#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE - /* Check if this is a robust mutex in an inconsistent state */ - - if ((rw_lock->lock.flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0) - { - (void)pthread_mutex_consistent(&rw_lock->lock); - } - else -#endif - { - (void)pthread_mutex_unlock(&rw_lock->lock); - } + (void)pthread_mutex_unlock(&rw_lock->lock); } #endif diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c index f68d272e03a..e2cad60ebbf 100644 --- a/sched/pthread/pthread_cancel.c +++ b/sched/pthread/pthread_cancel.c @@ -145,12 +145,6 @@ int pthread_cancel(pthread_t thread) pthread_exit(PTHREAD_CANCELED); } -#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE - /* Recover any mutexes still held by the canceled thread */ - - pthread_mutex_inconsistent(tcb); -#endif - #ifdef CONFIG_PTHREAD_CLEANUP /* Perform any stack pthread clean-up callbacks. * @@ -168,6 +162,12 @@ int pthread_cancel(pthread_t thread) (void)pthread_completejoin((pid_t)thread, PTHREAD_CANCELED); +#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE + /* Recover any mutexes still held by the canceled thread */ + + pthread_mutex_inconsistent(tcb); +#endif + /* Then let task_terminate do the real work */ return task_terminate((pid_t)thread, false); diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c index 4929db94cb5..bcc8e79c855 100644 --- a/sched/pthread/pthread_exit.c +++ b/sched/pthread/pthread_exit.c @@ -105,12 +105,6 @@ void pthread_exit(FAR void *exit_value) tcb->cpcount = 0; #endif -#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE - /* Recover any mutexes still held by the canceled thread */ - - pthread_mutex_inconsistent((FAR struct pthread_tcb_s *)tcb); -#endif - #ifdef CONFIG_PTHREAD_CLEANUP /* Perform any stack pthread clean-up callbacks */ @@ -129,6 +123,12 @@ void pthread_exit(FAR void *exit_value) exit(EXIT_FAILURE); } +#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE + /* Recover any mutexes still held by the canceled thread */ + + pthread_mutex_inconsistent((FAR struct pthread_tcb_s *)tcb); +#endif + /* Perform common task termination logic. This will get called again later * through logic kicked off by _exit(). However, we need to call it before * calling _exit() in order certain operations if this is the last thread diff --git a/sched/pthread/pthread_mutex.c b/sched/pthread/pthread_mutex.c index f11a5b01f6f..afd296407ef 100644 --- a/sched/pthread/pthread_mutex.c +++ b/sched/pthread/pthread_mutex.c @@ -125,10 +125,12 @@ int pthread_mutex_take(FAR struct pthread_mutex_s *mutex, bool intr) } else { - /* Take semaphore underlying the mutex */ + /* Take semaphore underlying the mutex. pthread_takesemaphore + * returns zero on success and a positive errno value on failue. + */ ret = pthread_takesemaphore(&mutex->sem, intr); - if (ret < OK) + if (ret != OK) { ret = get_errno(); } From 6935d44405284ee9d680a79b8669143dd96faca3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 10 Apr 2017 09:58:34 -0600 Subject: [PATCH 30/48] Update TODO list --- TODO | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index d19ac0f067a..8998fb1a464 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated March 26, 2017) +NuttX TODO List (Last updated April 10, 2017) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -108,9 +108,10 @@ o Task/Scheduler (sched/) 2. They run in supervisor mode (if applicable), and 3. They do not obey any setup of PIC or address environments. Do they need to? - 4. In the case of task_delete() and pthread_cancel(), these - callbacks will run on the thread of execution and address - context of the caller of task. That is very bad! + 4. In the case of task_delete() and pthread_cancel() without + defferred cancellation, these callbacks will run on the + thread of execution and address context of the caller of + task_delete() or pthread_cancel(). That is very bad! The fix for all of these issues it to have the callbacks run on the caller's thread as is currently done with From c36bf090f09c50be36022a4678e4ce4d8f9eb7ee Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 10 Apr 2017 10:10:41 -0600 Subject: [PATCH 31/48] pthread: Minor logic fix in pthread_mutex_consistent. Updat some comments. --- sched/pthread/pthread_mutexconsistent.c | 30 ++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/sched/pthread/pthread_mutexconsistent.c b/sched/pthread/pthread_mutexconsistent.c index e374083021f..dac4fcf0438 100644 --- a/sched/pthread/pthread_mutexconsistent.c +++ b/sched/pthread/pthread_mutexconsistent.c @@ -104,13 +104,14 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex) DEBUGASSERT(mutex->pid != 0); /* < 0: available, >0 owned, ==0 error */ if (mutex->pid >= 0) { - /* No.. Verify that the PID still exists. We may be destroying - * the mutex after cancelling a pthread and the mutex may have - * been in a bad state owned by the dead pthread. NOTE: The - * folling is unspecified behavior (see pthread_mutex_consistent()). + /* No.. Verify that the thread associated with the PID still + * exists. We may be destroying the mutex after cancelling a + * pthread and the mutex may have been in a bad state owned by + * the dead pthread. NOTE: The following is unspecified behavior + * (see pthread_mutex_consistent()). * * If the holding thread is still valid, then we should be able to - * map its PID to the underlying TCB. That is what sched_gettcb() + * map its PID to the underlying TCB. That is what sched_gettcb() * does. */ @@ -119,6 +120,7 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex) /* The thread associated with the PID no longer exists */ mutex->pid = -1; + mutex->flags &= _PTHREAD_MFLAGS_ROBUST; #ifdef CONFIG_PTHREAD_MUTEX_TYPES mutex->nlocks = 0; #endif @@ -129,11 +131,23 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex) status = sem_reset((FAR sem_t *)&mutex->sem, 1); ret = (status != OK) ? get_errno() : OK; } + + /* Otherwise the mutex is held by some active thread. Let's not + * touch anything! + */ + } + else + { + /* There is no holder of the mutex. Just make sure the + * inconsistent flag is cleared and the number of locks is zero. + */ + + mutex->flags &= _PTHREAD_MFLAGS_ROBUST; +#ifdef CONFIG_PTHREAD_MUTEX_TYPES + mutex->nlocks = 0; +#endif } - /* Clear the inconsistent flag in any case */ - - mutex->flags &= _PTHREAD_MFLAGS_ROBUST; sched_unlock(); ret = OK; } From c08ba10d325c0d01c5985cd613ab3cc9404e19b6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 10 Apr 2017 14:56:23 -0600 Subject: [PATCH 32/48] include/: Add some definitions needed by apps/wireless/wapi --- include/nuttx/wireless/wireless.h | 20 ++++++++++++++++++-- sched/pthread/pthread_cancel.c | 6 +++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/nuttx/wireless/wireless.h b/include/nuttx/wireless/wireless.h index 6ab0b0b3d11..74908e7350b 100644 --- a/include/nuttx/wireless/wireless.h +++ b/include/nuttx/wireless/wireless.h @@ -203,6 +203,22 @@ #define IW_ESSID_MAX_SIZE 32 +/* Modes of operation */ + +#define IW_MODE_AUTO 0 /* Let the driver decides */ +#define IW_MODE_ADHOC 1 /* Single cell network */ +#define IW_MODE_INFRA 2 /* Multi cell network, roaming, ... */ +#define IW_MODE_MASTER 3 /* Synchronisation master or Access Point */ +#define IW_MODE_REPEAT 4 /* Wireless Repeater (forwarder) */ +#define IW_MODE_SECOND 5 /* Secondary master/repeater (backup) */ +#define IW_MODE_MONITOR 6 /* Passive monitor (listen only) */ +#define IW_MODE_MESH 7 /* Mesh (IEEE 802.11s) network */ + +/* Frequency flags */ + +#define IW_FREQ_AUTO 0x00 /* Let the driver decides */ +#define IW_FREQ_FIXED 0x01 /* Force a specific value */ + /************************************************************************************ * Public Types ************************************************************************************/ @@ -303,8 +319,8 @@ union iwreq_data struct iwreq { - char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "eth0" */ - union iwreq_data u; /* Data payload */ + char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "eth0" */ + union iwreq_data u; /* Data payload */ }; #endif /* CONFIG_DRIVERS_WIRELESS */ diff --git a/sched/pthread/pthread_cancel.c b/sched/pthread/pthread_cancel.c index e2cad60ebbf..20e6f838b73 100644 --- a/sched/pthread/pthread_cancel.c +++ b/sched/pthread/pthread_cancel.c @@ -150,9 +150,9 @@ int pthread_cancel(pthread_t thread) * * REVISIT: In this case, the clean-up callback will execute on the * thread of the caller of pthread cancel, not on the thread of - * the thread-to-be-canceled. Is that an issue? Presumably they - * are both within the same group and within the same process address - * space. + * the thread-to-be-canceled. This is a problem when deferred + * cancellation is not supported because, for example, the clean-up + * function will be unable to unlock its own mutexes. */ pthread_cleanup_popall(tcb); From 4f35f196b1617b543f24aedc945b9907f7f28b28 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 10 Apr 2017 16:14:12 -0600 Subject: [PATCH 33/48] included/nuttx/wireless/wireless.h: Fix/add a few things needed by apps/wireless/wapi --- include/nuttx/wireless/wireless.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/nuttx/wireless/wireless.h b/include/nuttx/wireless/wireless.h index 74908e7350b..362b991d18d 100644 --- a/include/nuttx/wireless/wireless.h +++ b/include/nuttx/wireless/wireless.h @@ -313,13 +313,22 @@ union iwreq_data struct iw_point data; /* Other large parameters */ }; +/* A Wireless Event. */ + +struct iw_event +{ + uint16_t len; /* Real length of ata */ + uint16_t cmd; /* Wireless IOCTL command*/ + union iwreq_data u; /* Fixed IOCTL payload */ +}; + /* This is the structure used to exchange data in wireless IOCTLs. This structure * is the same as 'struct ifreq', but defined for use with wireless IOCTLs. */ struct iwreq { - char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "eth0" */ + char ifr_name[IFNAMSIZ]; /* Interface name, e.g. "eth0" */ union iwreq_data u; /* Data payload */ }; From e9a8dc7c6ecf9d3b642cb968c757b9c102bc7422 Mon Sep 17 00:00:00 2001 From: Jussi Kivilinna Date: Tue, 11 Apr 2017 06:39:27 -0600 Subject: [PATCH 34/48] STM32F7: serial: disallow broken configuration combination of CONFIG_STM32F7_FLOWCONTROL_BROKEN=y and CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS not set. --- arch/arm/src/stm32f7/Kconfig | 2 +- arch/arm/src/stm32f7/stm32_serial.c | 63 +++++++++++++++++------------ 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/arch/arm/src/stm32f7/Kconfig b/arch/arm/src/stm32f7/Kconfig index d8eabdcd4bd..2c21fadf610 100644 --- a/arch/arm/src/stm32f7/Kconfig +++ b/arch/arm/src/stm32f7/Kconfig @@ -1634,7 +1634,7 @@ config SERIAL_DISABLE_REORDERING config STM32F7_FLOWCONTROL_BROKEN bool "Use Software UART RTS flow control" - depends on STM32F7_USART + depends on STM32F7_USART && SERIAL_IFLOWCONTROL_WATERMARKS default n ---help--- Enable UART RTS flow control using Software. Because STM diff --git a/arch/arm/src/stm32f7/stm32_serial.c b/arch/arm/src/stm32f7/stm32_serial.c index ec97ec7096c..ea67ddb4dbd 100644 --- a/arch/arm/src/stm32f7/stm32_serial.c +++ b/arch/arm/src/stm32f7/stm32_serial.c @@ -220,43 +220,56 @@ /* Warnings for potentially unsafe configuration combinations. */ +#if defined(CONFIG_STM32F7_FLOWCONTROL_BROKEN) && \ + !defined(CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS) +# error "CONFIG_STM32F7_FLOWCONTROL_BROKEN requires \ + CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS to be enabled." +#endif + +#ifndef CONFIG_STM32F7_FLOWCONTROL_BROKEN /* Combination of RXDMA + IFLOWCONTROL does not work as one might expect. * Since RXDMA uses circular DMA-buffer, DMA will always keep reading new * data from USART peripheral even if DMA buffer underruns. Thus this * combination only does following: RTS is asserted on USART setup and * deasserted on shutdown and does not perform actual RTS flow-control. + * + * With SW flow-control, RTS is asserted before UART receive buffer fully + * fills, thus preventing data loss if application is slow to process data + * from serial device node. However, if RxDMA interrupt is blocked for too + * long, data loss is still possible as SW flow-control would also be + * blocked. */ -#if defined(CONFIG_USART1_RXDMA) && defined(CONFIG_USART1_IFLOWCONTROL) -# warning "RXDMA and IFLOWCONTROL both enabled for USART1. \ - This combination can lead to data loss." -#endif +# if defined(CONFIG_USART1_RXDMA) && defined(CONFIG_USART1_IFLOWCONTROL) +# warning "RXDMA and IFLOWCONTROL both enabled for USART1. \ + This combination can lead to data loss." +# endif -#if defined(CONFIG_USART2_RXDMA) && defined(CONFIG_USART2_IFLOWCONTROL) -# warning "RXDMA and IFLOWCONTROL both enabled for USART2. \ - This combination can lead to data loss." -#endif +# if defined(CONFIG_USART2_RXDMA) && defined(CONFIG_USART2_IFLOWCONTROL) +# warning "RXDMA and IFLOWCONTROL both enabled for USART2. \ + This combination can lead to data loss." +# endif -#if defined(CONFIG_USART3_RXDMA) && defined(CONFIG_USART3_IFLOWCONTROL) -# warning "RXDMA and IFLOWCONTROL both enabled for USART3. \ - This combination can lead to data loss." -#endif +# if defined(CONFIG_USART3_RXDMA) && defined(CONFIG_USART3_IFLOWCONTROL) +# warning "RXDMA and IFLOWCONTROL both enabled for USART3. \ + This combination can lead to data loss." +# endif -#if defined(CONFIG_USART6_RXDMA) && defined(CONFIG_USART6_IFLOWCONTROL) -# warning "RXDMA and IFLOWCONTROL both enabled for USART6. \ - This combination can lead to data loss." -#endif +# if defined(CONFIG_USART6_RXDMA) && defined(CONFIG_USART6_IFLOWCONTROL) +# warning "RXDMA and IFLOWCONTROL both enabled for USART6. \ + This combination can lead to data loss." +# endif -#if defined(CONFIG_UART7_RXDMA) && defined(CONFIG_UART7_IFLOWCONTROL) -# warning "RXDMA and IFLOWCONTROL both enabled for UART7. \ - This combination can lead to data loss." -#endif - -#if defined(CONFIG_UART8_RXDMA) && defined(CONFIG_UART8_IFLOWCONTROL) -# warning "RXDMA and IFLOWCONTROL both enabled for UART8. \ - This combination can lead to data loss." -#endif +# if defined(CONFIG_UART7_RXDMA) && defined(CONFIG_UART7_IFLOWCONTROL) +# warning "RXDMA and IFLOWCONTROL both enabled for UART7. \ + This combination can lead to data loss." +# endif +# if defined(CONFIG_UART8_RXDMA) && defined(CONFIG_UART8_IFLOWCONTROL) +# warning "RXDMA and IFLOWCONTROL both enabled for UART8. \ + This combination can lead to data loss." +# endif +#endif /* CONFIG_STM32F7_FLOWCONTROL_BROKEN */ /**************************************************************************** * Private Types From 4c99a6aeec03e3b83f34cc90a968a9a1937ed526 Mon Sep 17 00:00:00 2001 From: Jussi Kivilinna Date: Tue, 11 Apr 2017 06:40:44 -0600 Subject: [PATCH 35/48] STM32F7: serial: do not stop processing input in SW flow-control mode --- arch/arm/src/stm32f7/stm32_serial.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/arm/src/stm32f7/stm32_serial.c b/arch/arm/src/stm32f7/stm32_serial.c index ea67ddb4dbd..5c2b8b74bcc 100644 --- a/arch/arm/src/stm32f7/stm32_serial.c +++ b/arch/arm/src/stm32f7/stm32_serial.c @@ -2224,6 +2224,22 @@ static bool up_rxflowcontrol(struct uart_dev_s *dev, /* Assert/de-assert nRTS set it high resume/stop sending */ stm32_gpiowrite(priv->rts_gpio, upper); + + if (upper) + { + /* With heavy Rx traffic, RXNE might be set and data pending. + * Returning 'true' in such case would cause RXNE left unhandled + * and causing interrupt storm. Sending end might be also be slow + * to react on nRTS, and returning 'true' here would prevent + * processing that data. + * + * Therefore, return 'false' so input data is still being processed + * until sending end reacts on nRTS signal and stops sending more. + */ + + return false; + } + return upper; } From a58823c4493255ad30348bc8d9b0d212f1930440 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Tue, 11 Apr 2017 06:45:45 -0600 Subject: [PATCH 36/48] STM32XX: Fix Pending Register definition --- arch/arm/src/stm32/chip/stm32_exti.h | 6 +++--- arch/arm/src/stm32f7/chip/stm32_exti.h | 6 +++--- arch/arm/src/stm32l4/chip/stm32l4_exti.h | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/arm/src/stm32/chip/stm32_exti.h b/arch/arm/src/stm32/chip/stm32_exti.h index 791bed1f174..e18b60cf71b 100644 --- a/arch/arm/src/stm32/chip/stm32_exti.h +++ b/arch/arm/src/stm32/chip/stm32_exti.h @@ -188,9 +188,9 @@ /* Pending register */ -#define EXTI_IMR_BIT(n) STM32_EXTI_BIT(n) /* 1=Selected trigger request occurred */ -#define EXTI_IMR_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ -#define EXTI_IMR_MASK STM32_EXTI_MASK +#define EXTI_PR_BIT(n) STM32_EXTI_BIT(n) /* 1=Selected trigger request occurred */ +#define EXTI_PR_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ +#define EXTI_PR_MASK STM32_EXTI_MASK /* Compatibility Definitions ********************************************************/ diff --git a/arch/arm/src/stm32f7/chip/stm32_exti.h b/arch/arm/src/stm32f7/chip/stm32_exti.h index 288f51b228c..8663d2f08e7 100644 --- a/arch/arm/src/stm32f7/chip/stm32_exti.h +++ b/arch/arm/src/stm32f7/chip/stm32_exti.h @@ -125,9 +125,9 @@ /* Pending register */ -#define EXTI_IMR_BIT(n) STM32_EXTI_BIT(n) /* 1=Selected trigger request occurred */ -#define EXTI_IMR_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ -#define EXTI_IMR_MASK STM32_EXTI_MASK +#define EXTI_PR_BIT(n) STM32_EXTI_BIT(n) /* 1=Selected trigger request occurred */ +#define EXTI_PR_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ +#define EXTI_PR_MASK STM32_EXTI_MASK #endif /* CONFIG_STM32F7_STM32F74XX || CONFIG_STM32F7_STM32F75XX || CONFIG_STM32F7_STM32F76XX || CONFIG_STM32F7_STM32F77XX */ #endif /* __ARCH_ARM_SRC_STM32F7_CHIP_STM32_EXTI_H */ diff --git a/arch/arm/src/stm32l4/chip/stm32l4_exti.h b/arch/arm/src/stm32l4/chip/stm32l4_exti.h index 1fb1628a7a9..f9f087a051e 100644 --- a/arch/arm/src/stm32l4/chip/stm32l4_exti.h +++ b/arch/arm/src/stm32l4/chip/stm32l4_exti.h @@ -167,13 +167,13 @@ /* Pending register */ -#define EXTI_IMR1_BIT(n) STM32L4_EXTI1_BIT(n) /* 1=Selected trigger request occurred */ -#define EXTI_IMR1_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ -#define EXTI_IMR1_MASK STM32L4_EXTI1_MASK +#define EXTI_PR1_BIT(n) STM32L4_EXTI1_BIT(n) /* 1=Selected trigger request occurred */ +#define EXTI_PR1_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ +#define EXTI_PR1_MASK STM32L4_EXTI1_MASK -#define EXTI_IMR2_BIT(n) STM32L4_EXTI2_BIT(n) /* 1=Selected trigger request occurred */ -#define EXTI_IMR2_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ -#define EXTI_IMR2_MASK STM32L4_EXTI2_MASK +#define EXTI_PR2_BIT(n) STM32L4_EXTI2_BIT(n) /* 1=Selected trigger request occurred */ +#define EXTI_PR2_SHIFT (0) /* Bits 0-X: Pending bit for all lines */ +#define EXTI_PR2_MASK STM32L4_EXTI2_MASK #endif /* __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4_EXTI_H */ From 3fb730040b9327aa951c3bd6c5edf34fc5f7d9a7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Apr 2017 10:23:46 -0600 Subject: [PATCH 37/48] include/nuttx/wireless/wireless.h: Add a few more definitions needed by apps/wireless/wapi --- include/nuttx/wireless/wireless.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/nuttx/wireless/wireless.h b/include/nuttx/wireless/wireless.h index 362b991d18d..044315be7bd 100644 --- a/include/nuttx/wireless/wireless.h +++ b/include/nuttx/wireless/wireless.h @@ -213,11 +213,17 @@ #define IW_MODE_SECOND 5 /* Secondary master/repeater (backup) */ #define IW_MODE_MONITOR 6 /* Passive monitor (listen only) */ #define IW_MODE_MESH 7 /* Mesh (IEEE 802.11s) network */ +#define IW_MODE_NFLAGS 8 /* Frequency flags */ #define IW_FREQ_AUTO 0x00 /* Let the driver decides */ #define IW_FREQ_FIXED 0x01 /* Force a specific value */ +#define IW_FREQ_NFLAGS 2 + +/* Scan-related */ + +#define IW_SCAN_MAX_DATA 4096 /* Maximum size of returned data */ /************************************************************************************ * Public Types From b4747286b19d3b15193b2a5e8a0fe48fa0a8638c Mon Sep 17 00:00:00 2001 From: "Juha Niskanen (Haltian)" Date: Tue, 11 Apr 2017 11:03:25 -0600 Subject: [PATCH 38/48] Add logic to disable cancellation points within the OS. This is useful when an internal OS function that is NOT a cancellation point calls an OS function which is a cancellation point. In that case, irrecoverable states may occur if the cancellation is within the OS. --- sched/pthread/pthread.h | 8 +++ sched/pthread/pthread_condtimedwait.c | 7 ++- sched/pthread/pthread_condwait.c | 11 +++- sched/pthread/pthread_mutex.c | 83 +++++++++++++++++++++++---- 4 files changed, 96 insertions(+), 13 deletions(-) diff --git a/sched/pthread/pthread.h b/sched/pthread/pthread.h index b4e87d95339..69e08e1445a 100644 --- a/sched/pthread/pthread.h +++ b/sched/pthread/pthread.h @@ -121,6 +121,14 @@ void pthread_mutex_inconsistent(FAR struct pthread_tcb_s *tcb); # define pthread_mutex_give(m) pthread_givesemaphore(&(m)->sem) #endif +#ifdef CONFIG_CANCELLATION_POINTS +uint16_t pthread_disable_cancel(void); +void pthread_enable_cancel(uint16_t oldstate); +#else +# define pthread_disable_cancel() (0) +# define pthread_enable_cancel(s) UNUSED(s) +#endif + #ifdef CONFIG_PTHREAD_MUTEX_TYPES int pthread_mutexattr_verifytype(int type); #endif diff --git a/sched/pthread/pthread_condtimedwait.c b/sched/pthread/pthread_condtimedwait.c index 4ed8c5aed6e..22ce470770a 100644 --- a/sched/pthread/pthread_condtimedwait.c +++ b/sched/pthread/pthread_condtimedwait.c @@ -167,9 +167,10 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, FAR const struct timespec *abstime) { FAR struct tcb_s *rtcb = this_task(); + irqstate_t flags; + uint16_t oldstate; int ticks; int mypid = (int)getpid(); - irqstate_t flags; int ret = OK; int status; @@ -316,7 +317,11 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, /* Reacquire the mutex (retaining the ret). */ sinfo("Re-locking...\n"); + + oldstate = pthread_disable_cancel(); status = pthread_mutex_take(mutex, false); + pthread_enable_cancel(oldstate); + if (status == OK) { mutex->pid = mypid; diff --git a/sched/pthread/pthread_condwait.c b/sched/pthread/pthread_condwait.c index 9bcba234a5f..91138215fa3 100644 --- a/sched/pthread/pthread_condwait.c +++ b/sched/pthread/pthread_condwait.c @@ -95,6 +95,8 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex) } else { + uint16_t oldstate; + /* Give up the mutex */ sinfo("Give up mutex / take cond\n"); @@ -117,12 +119,17 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex) /* Reacquire the mutex. * - * REVISIT: When cancellation points are enabled, we will almost - * certainly hold the mutex when the pthread is canceled. + * When cancellation points are enabled, we need to + * hold the mutex when the pthread is canceled and + * cleanup handlers, if any, are entered. */ sinfo("Reacquire mutex...\n"); + + oldstate = pthread_disable_cancel(); status = pthread_mutex_take(mutex, false); + pthread_enable_cancel(oldstate); + if (ret == OK) { /* Report the first failure that occurs */ diff --git a/sched/pthread/pthread_mutex.c b/sched/pthread/pthread_mutex.c index afd296407ef..45c4ffd3fa8 100644 --- a/sched/pthread/pthread_mutex.c +++ b/sched/pthread/pthread_mutex.c @@ -95,8 +95,8 @@ static void pthread_mutex_add(FAR struct pthread_mutex_s *mutex) * mutex to the list of mutexes held by this thread. * * Parameters: - * mutex - The mux to be locked - * intr - false: ignore EINTR errors when locking; true tread EINTR as + * mutex - The mutex to be locked + * intr - false: ignore EINTR errors when locking; true treat EINTR as * other errors by returning the errno value * * Return Value: @@ -126,15 +126,11 @@ int pthread_mutex_take(FAR struct pthread_mutex_s *mutex, bool intr) else { /* Take semaphore underlying the mutex. pthread_takesemaphore - * returns zero on success and a positive errno value on failue. + * returns zero on success and a positive errno value on failure. */ ret = pthread_takesemaphore(&mutex->sem, intr); - if (ret != OK) - { - ret = get_errno(); - } - else + if (ret == OK) { /* Check if the holder of the mutex has terminated without * releasing. In that case, the state of the mutex is @@ -169,8 +165,8 @@ int pthread_mutex_take(FAR struct pthread_mutex_s *mutex, bool intr) * mutex to the list of mutexes held by this thread. * * Parameters: - * mutex - The mux to be locked - * intr - false: ignore EINTR errors when locking; true tread EINTR as + * mutex - The mutex to be locked + * intr - false: ignore EINTR errors when locking; true treat EINTR as * other errors by returning the errno value * * Return Value: @@ -283,3 +279,70 @@ int pthread_mutex_give(FAR struct pthread_mutex_s *mutex) return ret; } +/**************************************************************************** + * Name: pthread_disable_cancel() and pthread_enable_cancel() + * + * Description: + * Temporarily disable cancellation and return old cancel state, which + * can later be restored. This is useful when a cancellation point + * function is called from within the OS by a non-cancellation point: + * In certain such cases, we need to defer the cancellation to prevent + * bad things from happening. + * + * Parameters: + * saved cancel flags for pthread_enable_cancel() + * + * Return Value: + * old cancel flags for pthread_disable_cancel() + * + ****************************************************************************/ + +#ifdef CONFIG_CANCELLATION_POINTS +uint16_t pthread_disable_cancel(void) +{ + FAR struct pthread_tcb_s *tcb = (FAR struct pthread_tcb_s *)this_task(); + irqstate_t flags; + uint16_t old; + + /* We need perform the following operations from within a critical section + * because it can compete with interrupt level activity. + */ + + flags = enter_critical_section(); + old = tcb->cmn.flags & (TCB_FLAG_CANCEL_PENDING | TCB_FLAG_NONCANCELABLE); + tcb->cmn.flags &= ~(TCB_FLAG_CANCEL_PENDING | TCB_FLAG_NONCANCELABLE); + leave_critical_section(flags); + return old; +} + +void pthread_enable_cancel(uint16_t cancelflags) +{ + FAR struct pthread_tcb_s *tcb = (FAR struct pthread_tcb_s *)this_task(); + irqstate_t flags; + + /* We need perform the following operations from within a critical section + * because it can compete with interrupt level activity. + */ + + flags = enter_critical_section(); + tcb->cmn.flags |= cancelflags; + + /* What should we do if there is a pending cancellation? + * + * If the thread is executing with deferred cancellation, we need do + * nothing more; the cancellation cannot occur until the next + * cancellation point. + * + * However, if the thread is executing in asynchronous cancellation mode, + * then we need to terminate now by simply calling pthread_exit(). + */ + + if ((tcb->cmn.flags & TCB_FLAG_CANCEL_DEFERRED) == 0 && + (tcb->cmn.flags & TCB_FLAG_CANCEL_PENDING) != 0) + { + pthread_exit(NULL); + } + + leave_critical_section(flags); +} +#endif /* CONFIG_CANCELLATION_POINTS */ From 6560db912bd45027a9ad1606e7340001f4087d96 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Apr 2017 12:41:30 -0600 Subject: [PATCH 39/48] Add more definitions needed by apps/examples/wapi --- include/nuttx/net/arp.h | 1 + include/nuttx/wireless/wireless.h | 39 ++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/include/nuttx/net/arp.h b/include/nuttx/net/arp.h index 4a33994a1b7..477240a5d68 100644 --- a/include/nuttx/net/arp.h +++ b/include/nuttx/net/arp.h @@ -69,6 +69,7 @@ */ #define ARPHRD_ETHER 1 /* Ethernet */ +#define ARPHRD_IEEE80211    801 /* IEEE 802.11 */ #define ARPHRD_IEEE802154 804 /* IEEE 802.15.4 */ /**************************************************************************** diff --git a/include/nuttx/wireless/wireless.h b/include/nuttx/wireless/wireless.h index 044315be7bd..bd9f93ba8f7 100644 --- a/include/nuttx/wireless/wireless.h +++ b/include/nuttx/wireless/wireless.h @@ -217,10 +217,19 @@ /* Frequency flags */ -#define IW_FREQ_AUTO 0x00 /* Let the driver decides */ -#define IW_FREQ_FIXED 0x01 /* Force a specific value */ +#define IW_FREQ_AUTO 0 /* Let the driver decides */ +#define IW_FREQ_FIXED 1 /* Force a specific value */ #define IW_FREQ_NFLAGS 2 +#define IW_MAX_FREQUENCIES 32 /* Max. frequencies in struct iw_range */ + +/* Transmit Power flags available */ + +#define IW_TXPOW_DBM 0 /* Value is in dBm */ +#define IW_TXPOW_MWATT 1 /* Value is in mW */ +#define IW_TXPOW_RELATIVE 2 /* Value is in arbitrary units */ +#define IW_TXPOW_NFLAGS 3 + /* Scan-related */ #define IW_SCAN_MAX_DATA 4096 /* Maximum size of returned data */ @@ -318,15 +327,6 @@ union iwreq_data struct iw_param param; /* Other small parameters */ struct iw_point data; /* Other large parameters */ }; - -/* A Wireless Event. */ - -struct iw_event -{ - uint16_t len; /* Real length of ata */ - uint16_t cmd; /* Wireless IOCTL command*/ - union iwreq_data u; /* Fixed IOCTL payload */ -}; /* This is the structure used to exchange data in wireless IOCTLs. This structure * is the same as 'struct ifreq', but defined for use with wireless IOCTLs. @@ -338,5 +338,22 @@ struct iwreq union iwreq_data u; /* Data payload */ }; +/* Range of parameters (currently only frequencies) */ + +struct iw_range +{ + uint8_t num_frequency; /* Number of frequencies in the freq[] list */ + struct iw_freq freq[IW_MAX_FREQUENCIES]; +}; + +/* A Wireless Event. */ + +struct iw_event +{ + uint16_t len; /* Real length of ata */ + uint16_t cmd; /* Wireless IOCTL command*/ + union iwreq_data u; /* Fixed IOCTL payload */ +}; + #endif /* CONFIG_DRIVERS_WIRELESS */ #endif /* __INCLUDE_NUTTX_WIRELESS_H */ From dced088ff53dae4c8005f445e71a555c0c72d1b4 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Tue, 11 Apr 2017 13:07:11 -0600 Subject: [PATCH 40/48] Fix LLVM libc++ undefined reference to __cxa_guard_* --- libxx/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libxx/Makefile b/libxx/Makefile index 766bd5d62d3..9f5ba9c9ac7 100644 --- a/libxx/Makefile +++ b/libxx/Makefile @@ -50,13 +50,19 @@ endif ifeq (,$(findstring y,$(CONFIG_UCLIBCXX) $(CONFIG_LIBCXX))) CXXSRCS += libxx_delete.cxx libxx_deletea.cxx libxx_new.cxx libxx_newa.cxx -CXXSRCS += libxx_stdthrow.cxx libxx_cxa_guard.cxx +CXXSRCS += libxx_stdthrow.cxx else ifeq (,$(findstring y,$(CONFIG_UCLIBCXX_EXCEPTION) $(CONFIG_LIBCXX_EXCEPTION))) CXXSRCS += libxx_stdthrow.cxx endif endif +# uClibc++ doesn't need this file + +ifneq ($(CONFIG_UCLIBCXX),y) +CXXSRCS += libxx_cxa_guard.cxx +endif + # Paths DEPPATH = --dep-path . From eab139a5390d0f8da61d47970978233ae0cfe8d1 Mon Sep 17 00:00:00 2001 From: Ritajina Date: Wed, 12 Apr 2017 06:41:08 -0600 Subject: [PATCH 41/48] libc/netdb: in dns_query_callback, ret != -EADDRNOTAVAIL condition consumes error returns including EAGAIN in this case, dns query retransmission doesn't work --- libc/netdb/lib_dnsquery.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libc/netdb/lib_dnsquery.c b/libc/netdb/lib_dnsquery.c index 21ed201ba80..3602a5c8dd5 100644 --- a/libc/netdb/lib_dnsquery.c +++ b/libc/netdb/lib_dnsquery.c @@ -494,7 +494,7 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr, nerr("ERROR: IPv4 dns_recv_response failed: %d\n", ret); - if (ret != -EADDRNOTAVAIL) + if (ret == -EADDRNOTAVAIL) { /* The IPv4 address is not available. Return zero to * continue the tranversal with the next nameserver @@ -575,7 +575,7 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr, nerr("ERROR: IPv6 dns_recv_response failed: %d\n", ret); - if (ret != -EADDRNOTAVAIL) + if (ret == -EADDRNOTAVAIL) { /* The IPv6 address is not available. Return zero to * continue the tranversal with the next nameserver From d9b1b3f824f29b80e28f66382058769cf372a157 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 12 Apr 2017 07:28:11 -0600 Subject: [PATCH 42/48] Update TODO list --- TODO | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 8998fb1a464..93db26ced47 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -NuttX TODO List (Last updated April 10, 2017) +NuttX TODO List (Last updated April 12, 2017) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This file summarizes known NuttX bugs, limitations, inconsistencies with @@ -9,7 +9,7 @@ issues related to each board port. nuttx/: - (10) Task/Scheduler (sched/) + (11) Task/Scheduler (sched/) (1) SMP (1) Memory Management (mm/) (0) Power Management (drivers/pm) @@ -186,6 +186,47 @@ o Task/Scheduler (sched/) Priority: Low. Things are just the way that we want them for the way that NuttX is used today. + Title: INTERNAL VERSIONS OF USER FUNCTIONS + Description: The internal NuttX logic uses the same interfaces as does + the application. That sometime produces a problem because + there is "overloaded" functionality in those user interfaces + that are not desireable. + + For example, having cancellation points hidden inside of the + OS can cause non-cancellation point interfaces to behave + strangely. There was a change recently in pthread_cond_wait() + and pthread_cond_timedwait() recently to effectively disable + the cancellation point behavior of sem_init(). This was + accomplished with two functions: pthread_disable_cancel() + and pthread_enable_cancel() + + Here is another issue:  Internal OS functions should not set + errno and should never have to look at the errno value to + determine the cause of the failure.  The errno is provided + for compatibility with POSIX application interface + requirements and really doesn't need to be used within the + OS. + + Both of these could be fixed if there were special internal + versions these functions.  For example, there could be a an + nx_sem_wait() that does all of the same things as sem_wait() + was does not create a cancellation point and does not set + the errno value on failures. + + Everything inside the OS would use nx_sem_wait(). + Applications would call sem_wait() which would just be a + wrapper around nx_sem_wait() that adds the cancellation point + and that sets the errno value on failures. + + Changes like that could clean up some of this internal + craziness.  The condition variable change described above is + really a "bandaid" to handle the case that sem_wait() is a + cancellation point. + Status: Open + Priority: Low. Things are working OK the way they are. But the design + could be improved and made a little more efficient with this + change. + o SMP ^^^ From dc2890904df0cb7a1d0e4c1b2a029ddc8697f953 Mon Sep 17 00:00:00 2001 From: Sebastien Lorquet Date: Wed, 12 Apr 2017 10:25:51 -0600 Subject: [PATCH 43/48] STM32L4 DMA: Correct bad channel definition. --- arch/arm/src/stm32l4/chip/stm32l4x6xx_dma.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/arm/src/stm32l4/chip/stm32l4x6xx_dma.h b/arch/arm/src/stm32l4/chip/stm32l4x6xx_dma.h index ab63195d2f2..6e7afac9af1 100644 --- a/arch/arm/src/stm32l4/chip/stm32l4x6xx_dma.h +++ b/arch/arm/src/stm32l4/chip/stm32l4x6xx_dma.h @@ -306,7 +306,12 @@ #define STM32L4_DMA2_CHAN6 (12) #define STM32L4_DMA2_CHAN7 (13) -#define DMACHAN_SETTING(chan, sel) ( ( ( (sel) & 0xff) << 8) | ( (chan) & 0xff) ) +/* DMA Channel settings include a channel and an alternative function. + * Channel is in bits 0..7 + * Request number is in bits 8..15 + */ + +#define DMACHAN_SETTING(chan, req) ((((req) & 0xff) << 8) | ((chan) & 0xff)) #define DMACHAN_SETTING_CHANNEL_MASK 0x00FF #define DMACHAN_SETTING_CHANNEL_SHIFT (0) #define DMACHAN_SETTING_FUNCTION_MASK 0xFF00 @@ -384,7 +389,7 @@ #define DMACHAN_SPI1_RX_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN2, 1) #define DMACHAN_SPI1_RX_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN3, 4) -#define DMACHAN_SPI1_TX_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN3, 0) +#define DMACHAN_SPI1_TX_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN3, 1) #define DMACHAN_SPI1_TX_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN4, 4) #define DMACHAN_SPI2_RX DMACHAN_SETTING(STM32L4_DMA1_CHAN4, 1) From 1a9403313ee597868ed6754081c3770d75312c7e Mon Sep 17 00:00:00 2001 From: Brian Webb Date: Wed, 12 Apr 2017 20:33:32 -0700 Subject: [PATCH 44/48] Adds USB host support to stm32f411-disco board. --- configs/stm32f411e-disco/Kconfig | 11 + configs/stm32f411e-disco/src/Makefile | 6 +- configs/stm32f411e-disco/src/stm32_boot.c | 17 +- configs/stm32f411e-disco/src/stm32_bringup.c | 123 ++++++ configs/stm32f411e-disco/src/stm32_usb.c | 352 ++++++++++++++++++ .../stm32f411e-disco/src/stm32f411e-disco.h | 81 +++- 6 files changed, 574 insertions(+), 16 deletions(-) create mode 100644 configs/stm32f411e-disco/src/stm32_bringup.c create mode 100644 configs/stm32f411e-disco/src/stm32_usb.c diff --git a/configs/stm32f411e-disco/Kconfig b/configs/stm32f411e-disco/Kconfig index c8983191836..205dc95fa2b 100644 --- a/configs/stm32f411e-disco/Kconfig +++ b/configs/stm32f411e-disco/Kconfig @@ -5,4 +5,15 @@ if ARCH_BOARD_STM32F411E_DISCO +config STM32F411DISCO_USBHOST_STACKSIZE + int "USB host waiter stack size" + default 1024 + depends on USBHOST + +config STM32F411DISCO_USBHOST_PRIO + int "USB host waiter task priority" + default 100 + depends on USBHOST + + endif diff --git a/configs/stm32f411e-disco/src/Makefile b/configs/stm32f411e-disco/src/Makefile index 2ee3b640163..3635386d27a 100644 --- a/configs/stm32f411e-disco/src/Makefile +++ b/configs/stm32f411e-disco/src/Makefile @@ -36,10 +36,14 @@ -include $(TOPDIR)/Make.defs ASRCS = -CSRCS = stm32_boot.c +CSRCS = stm32_boot.c stm32_bringup.c ifeq ($(CONFIG_NSH_LIBRARY),y) CSRCS += stm32_appinit.c endif +ifeq ($(CONFIG_STM32_OTGFS),y) +CSRCS += stm32_usb.c +endif + include $(TOPDIR)/configs/Board.mk diff --git a/configs/stm32f411e-disco/src/stm32_boot.c b/configs/stm32f411e-disco/src/stm32_boot.c index dec40d4b70b..6de88de6a99 100644 --- a/configs/stm32f411e-disco/src/stm32_boot.c +++ b/configs/stm32f411e-disco/src/stm32_boot.c @@ -80,10 +80,9 @@ void stm32_boardinitialize(void) stm32_spidev_initialize(); #endif -#if defined(CONFIG_USBDEV) && defined(CONFIG_STM32_USB) - /* Initialize USB is 1) USBDEV is selected, 2) the USB controller is not - * disabled, and 3) the weak function stm32_usbinitialize() has been brought - * into the build. +#ifdef CONFIG_STM32_OTGFS + /* Initialize USB if the 1) OTG FS controller is in the configuration and 2) + * disabled. Presumably either CONFIG_USBDEV or CONFIG_USBHOST is also selected. */ stm32_usbinitialize(); @@ -106,14 +105,8 @@ void stm32_boardinitialize(void) #ifdef CONFIG_BOARD_INITIALIZE void board_initialize(void) { -#if defined(CONFIG_NSH_LIBRARY) && !defined(CONFIG_LIB_BOARDCTL) - /* Perform NSH initialization here instead of from the NSH. This - * alternative NSH initialization is necessary when NSH is ran in user-space - * but the initialization function must run in kernel space. - */ - - board_app_initialize(0); -#endif + /* Perform board-specific initialization */ + (void)stm32_bringup(); } #endif diff --git a/configs/stm32f411e-disco/src/stm32_bringup.c b/configs/stm32f411e-disco/src/stm32_bringup.c new file mode 100644 index 00000000000..be0d587123d --- /dev/null +++ b/configs/stm32f411e-disco/src/stm32_bringup.c @@ -0,0 +1,123 @@ +/**************************************************************************** + * config/stm32f4discovery/src/stm32_bringup.c + * + * Copyright (C) 2012, 2014-2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include + +#ifdef CONFIG_USBMONITOR +# include +#endif + +#include + +#include "stm32.h" + +#ifdef CONFIG_STM32_OTGFS +# include "stm32_usbhost.h" +#endif + +#include "stm32f411e-disco.h" + +/* Conditional logic in stm32f4discover.h will determine if certain features + * are supported. Tests for these features need to be made after including + * stm32f4discovery.h. + */ + +#ifdef HAVE_RTC_DRIVER +# include +# include "stm32_rtc.h" +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_INITIALIZE=y : + * Called from board_initialize(). + * + * CONFIG_BOARD_INITIALIZE=n && CONFIG_LIB_BOARDCTL=y : + * Called from the NSH library + * + ****************************************************************************/ + +int stm32_bringup(void) +{ + int ret = OK; + +#ifdef HAVE_USBHOST + /* Initialize USB host operation. stm32_usbhost_initialize() starts a thread + * will monitor for USB connection and disconnection events. + */ + + ret = stm32_usbhost_initialize(); + if (ret != OK) + { + uerr("ERROR: Failed to initialize USB host: %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = mount(NULL, STM32_PROCFS_MOUNTPOINT, "procfs", 0, NULL); + if (ret < 0) + { + serr("ERROR: Failed to mount procfs at %s: %d\n", + STM32_PROCFS_MOUNTPOINT, ret); + } +#endif + + return ret; +} diff --git a/configs/stm32f411e-disco/src/stm32_usb.c b/configs/stm32f411e-disco/src/stm32_usb.c new file mode 100644 index 00000000000..cd0a5afee1e --- /dev/null +++ b/configs/stm32f411e-disco/src/stm32_usb.c @@ -0,0 +1,352 @@ +/************************************************************************************ + * configs/stm32f411e-disco/src/stm32_usb.c + * + * Copyright (C) 2012-2013, 2015, 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Copyright (C) 2017 Brian Webb. All rights reserved. + * Author: Brian Webb + * + * 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 + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "up_arch.h" +#include "stm32.h" +#include "stm32_otgfs.h" +#include "stm32f411e-disco.h" + +#ifdef CONFIG_STM32_OTGFS + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +#if defined(CONFIG_USBDEV) || defined(CONFIG_USBHOST) +# define HAVE_USB 1 +#else +# warning "CONFIG_STM32_OTGFS is enabled but neither CONFIG_USBDEV nor CONFIG_USBHOST" +# undef HAVE_USB +#endif + +#ifndef CONFIG_STM32F411DISCO_USBHOST_PRIO +# define CONFIG_STM32F411DISCO_USBHOST_PRIO 100 +#endif + +#ifndef CONFIG_STM32F411DISCO_USBHOST_STACKSIZE +# define CONFIG_STM32F411DISCO_USBHOST_STACKSIZE 1024 +#endif + +/************************************************************************************ + * Private Data + ************************************************************************************/ + +#ifdef CONFIG_USBHOST +static struct usbhost_connection_s *g_usbconn; +#endif + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: usbhost_waiter + * + * Description: + * Wait for USB devices to be connected. + * + ************************************************************************************/ + +#ifdef CONFIG_USBHOST +static int usbhost_waiter(int argc, char *argv[]) +{ + struct usbhost_hubport_s *hport; + + uinfo("Running\n"); + for (;;) + { + /* Wait for the device to change state */ + + DEBUGVERIFY(CONN_WAIT(g_usbconn, &hport)); + uinfo("%s\n", hport->connected ? "connected" : "disconnected"); + + /* Did we just become connected? */ + + if (hport->connected) + { + /* Yes.. enumerate the newly connected device */ + + (void)CONN_ENUMERATE(g_usbconn, hport); + } + } + + /* Keep the compiler from complaining */ + + return 0; +} +#endif + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: stm32_usbinitialize + * + * Description: + * Called from stm32_usbinitialize very early in inialization to setup USB-related + * GPIO pins for the STM32F411 Discovery board. + * + ************************************************************************************/ + +void stm32_usbinitialize(void) +{ + /* The OTG FS has an internal soft pull-up. No GPIO configuration is required */ + + /* Configure the OTG FS VBUS sensing GPIO, Power On, and Overcurrent GPIOs */ + +#ifdef CONFIG_STM32_OTGFS + stm32_configgpio(GPIO_OTGFS_VBUS); + stm32_configgpio(GPIO_OTGFS_PWRON); + stm32_configgpio(GPIO_OTGFS_OVER); +#endif +} + +/*********************************************************************************** + * Name: stm32_usbhost_initialize + * + * Description: + * Called at application startup time to initialize the USB host functionality. + * This function will start a thread that will monitor for device + * connection/disconnection events. + * + ***********************************************************************************/ + +#ifdef CONFIG_USBHOST +int stm32_usbhost_initialize(void) +{ + int pid; +#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ + defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) || \ + defined(CONFIG_USBHOST_XBOXCONTROLLER) + int ret; +#endif + + /* First, register all of the class drivers needed to support the drivers + * that we care about: + */ + + uinfo("Register class drivers\n"); + +#ifdef CONFIG_USBHOST_HUB + /* Initialize USB hub class support */ + + ret = usbhost_hub_initialize(); + if (ret < 0) + { + uerr("ERROR: usbhost_hub_initialize failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_USBHOST_MSC + /* Register the USB mass storage class class */ + + ret = usbhost_msc_initialize(); + if (ret != OK) + { + uerr("ERROR: Failed to register the mass storage class: %d\n", ret); + } +#endif + +#ifdef CONFIG_USBHOST_CDCACM + /* Register the CDC/ACM serial class */ + + ret = usbhost_cdcacm_initialize(); + if (ret != OK) + { + uerr("ERROR: Failed to register the CDC/ACM serial class: %d\n", ret); + } +#endif + +#ifdef CONFIG_USBHOST_HIDKBD + /* Initialize the HID keyboard class */ + + ret = usbhost_kbdinit(); + if (ret != OK) + { + uerr("ERROR: Failed to register the HID keyboard class\n"); + } +#endif + +#ifdef CONFIG_USBHOST_HIDMOUSE + /* Initialize the HID mouse class */ + + ret = usbhost_mouse_init(); + if (ret != OK) + { + uerr("ERROR: Failed to register the HID mouse class\n"); + } +#endif + +#ifdef CONFIG_USBHOST_XBOXCONTROLLER + /* Initialize the HID mouse class */ + + ret = usbhost_xboxcontroller_init(); + if (ret != OK) + { + uerr("ERROR: Failed to register the XBox Controller class\n"); + } +#endif + + /* Then get an instance of the USB host interface */ + + uinfo("Initialize USB host\n"); + g_usbconn = stm32_otgfshost_initialize(0); + if (g_usbconn) + { + /* Start a thread to handle device connection. */ + + uinfo("Start usbhost_waiter\n"); + + pid = task_create("usbhost", CONFIG_STM32F411DISCO_USBHOST_PRIO, + CONFIG_STM32F411DISCO_USBHOST_STACKSIZE, + (main_t)usbhost_waiter, (FAR char * const *)NULL); + return pid < 0 ? -ENOEXEC : OK; + } + + return -ENODEV; +} +#endif + +/*********************************************************************************** + * Name: stm32_usbhost_vbusdrive + * + * Description: + * Enable/disable driving of VBUS 5V output. This function must be provided be + * each platform that implements the STM32 OTG FS host interface + * + * "On-chip 5 V VBUS generation is not supported. For this reason, a charge pump + * or, if 5 V are available on the application board, a basic power switch, must + * be added externally to drive the 5 V VBUS line. The external charge pump can + * be driven by any GPIO output. When the application decides to power on VBUS + * using the chosen GPIO, it must also set the port power bit in the host port + * control and status register (PPWR bit in OTG_FS_HPRT). + * + * "The application uses this field to control power to this port, and the core + * clears this bit on an overcurrent condition." + * + * Input Parameters: + * iface - For future growth to handle multiple USB host interface. Should be zero. + * enable - true: enable VBUS power; false: disable VBUS power + * + * Returned Value: + * None + * + ***********************************************************************************/ + +#ifdef CONFIG_USBHOST +void stm32_usbhost_vbusdrive(int iface, bool enable) +{ + DEBUGASSERT(iface == 0); + + if (enable) + { + /* Enable the Power Switch by driving the enable pin low */ + + stm32_gpiowrite(GPIO_OTGFS_PWRON, false); + } + else + { + /* Disable the Power Switch by driving the enable pin high */ + + stm32_gpiowrite(GPIO_OTGFS_PWRON, true); + } +} +#endif + +/************************************************************************************ + * Name: stm32_setup_overcurrent + * + * Description: + * Setup to receive an interrupt-level callback if an overcurrent condition is + * detected. + * + * Input Parameter: + * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler + * + * Returned value: + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. + * + ************************************************************************************/ + +#ifdef CONFIG_USBHOST +int stm32_setup_overcurrent(xcpt_t handler, void *arg) +{ + return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, arg); +} +#endif + +/************************************************************************************ + * Name: stm32_usbsuspend + * + * Description: + * Board logic must provide the stm32_usbsuspend logic if the USBDEV driver is + * used. This function is called whenever the USB enters or leaves suspend mode. + * This is an opportunity for the board logic to shutdown clocks, power, etc. + * while the USB is suspended. + * + ************************************************************************************/ + +#ifdef CONFIG_USBDEV +void stm32_usbsuspend(FAR struct usbdev_s *dev, bool resume) +{ + uinfo("resume: %d\n", resume); +} +#endif + +#endif /* CONFIG_STM32_OTGFS */ diff --git a/configs/stm32f411e-disco/src/stm32f411e-disco.h b/configs/stm32f411e-disco/src/stm32f411e-disco.h index 5425f291bd3..e679b03a4e5 100644 --- a/configs/stm32f411e-disco/src/stm32f411e-disco.h +++ b/configs/stm32f411e-disco/src/stm32f411e-disco.h @@ -85,6 +85,48 @@ #define GPIO_SPI1_SCK_OFF (GPIO_INPUT | GPIO_PULLDOWN | \ GPIO_PORTA | GPIO_PIN5) +/* Assume that we have everything */ + +#define HAVE_USBDEV 1 +#define HAVE_USBHOST 1 +#define HAVE_USBMONITOR 1 +#define HAVE_SDIO 1 +#define HAVE_RTC_DRIVER 1 +#define HAVE_ELF 1 +#define HAVE_NETMONITOR 1 + +/* USB OTG FS + * + * PA9 OTG_FS_VBUS VBUS sensing (also connected to the green LED) + * PC0 OTG_FS_PowerSwitchOn + * PD5 OTG_FS_Overcurrent + */ + +#define GPIO_OTGFS_VBUS (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|\ + GPIO_OPENDRAIN|GPIO_PORTA|GPIO_PIN9) +#define GPIO_OTGFS_PWRON (GPIO_OUTPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|\ + GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN0) + +#ifdef CONFIG_USBHOST +# define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_EXTI|GPIO_FLOAT|\ + GPIO_SPEED_100MHz|GPIO_PUSHPULL|\ + GPIO_PORTD|GPIO_PIN5) + +#else +# define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|\ + GPIO_PUSHPULL|GPIO_PORTD|GPIO_PIN5) +#endif + +/* procfs File System */ + +#ifdef CONFIG_FS_PROCFS +# ifdef CONFIG_NSH_PROC_MOUNTPOINT +# define STM32_PROCFS_MOUNTPOINT CONFIG_NSH_PROC_MOUNTPOINT +# else +# define STM32_PROCFS_MOUNTPOINT "/proc" +# endif +#endif + /************************************************************************************ * Public Data ************************************************************************************/ @@ -112,14 +154,47 @@ extern struct spi_dev_s *g_spi2; void stm32_spidev_initialize(void); -/************************************************************************************ +/**************************************************************************** * Name: stm32_usbinitialize * * Description: - * Called to setup USB-related GPIO pins. + * Called from stm32_usbinitialize very early in initialization to setup + * USB-related GPIO pins for the STM32F4Discovery board. * - ************************************************************************************/ + ****************************************************************************/ +#ifdef CONFIG_STM32_OTGFS void stm32_usbinitialize(void); +#endif + +/**************************************************************************** + * Name: stm32_usbhost_initialize + * + * Description: + * Called at application startup time to initialize the USB host + * functionality. This function will start a thread that will monitor for + * device connection/disconnection events. + * + ****************************************************************************/ + +#if defined(CONFIG_STM32_OTGFS) && defined(CONFIG_USBHOST) +int stm32_usbhost_initialize(void); +#endif + +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_INITIALIZE=y : + * Called from board_initialize(). + * + * CONFIG_BOARD_INITIALIZE=y && CONFIG_LIB_BOARDCTL=y : + * Called from the NSH library + * + ****************************************************************************/ + +int stm32_bringup(void); #endif /* __CONFIGS_STM32F411E_DISCO_SRC_STM32F411E_DISCO_H */ From 7e293b28eeafae0be9e711e53317f9607d5c1d9c Mon Sep 17 00:00:00 2001 From: Thomas Keh Date: Thu, 13 Apr 2017 13:07:03 +0200 Subject: [PATCH 45/48] TUN driver: Implement TAP (OSI layer 2) mode. Enable by setting the IFF_TAP flag instead of the IFF_TUN flag in ifr_flags. --- drivers/net/tun.c | 17 ++++++++++++++++- net/netdev/netdev_register.c | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 47630871627..65d60e9fe02 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1159,7 +1159,7 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg) int intf; FAR struct ifreq *ifr = (FAR struct ifreq *)arg; - if (!ifr || (ifr->ifr_flags & IFF_MASK) != IFF_TUN) + if (!ifr || ((ifr->ifr_flags & IFF_MASK) != IFF_TUN && (ifr->ifr_flags & IFF_MASK) != IFF_TAP)) { return -EINVAL; } @@ -1191,6 +1191,21 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg) priv = filep->f_priv; strncpy(ifr->ifr_name, priv->dev.d_ifname, IFNAMSIZ); + if ((ifr->ifr_flags & IFF_MASK) == IFF_TAP) + { + /* TAP device -> handling raw Ethernet packets + * -> set appropriate Ethernet header length + */ + priv->dev.d_llhdrlen = ETH_HDRLEN; + } + else if ((ifr->ifr_flags & IFF_MASK) == IFF_TUN) + { + /* TUN device -> handling an application data stream + * -> no header + */ + priv->dev.d_llhdrlen = 0; + } + tundev_unlock(tun); return OK; diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index 737d51195ba..a3de997c853 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -251,7 +251,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) #ifdef CONFIG_NET_TUN case NET_LL_TUN: /* Virtual Network Device (TUN) */ - dev->d_llhdrlen = 0; + dev->d_llhdrlen = 0; /* this will be overwritten by tun_ioctl if used as a TAP (layer 2) device */ dev->d_mtu = CONFIG_NET_TUN_MTU; #ifdef CONFIG_NET_TCP dev->d_recvwndo = CONFIG_NET_TUN_TCP_RECVWNDO; From ad9321b7b75f434de7a203b29e83ed3da66ac4d3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Apr 2017 06:16:03 -0600 Subject: [PATCH 46/48] Trivial changes from review of last PR --- drivers/net/tun.c | 11 ++++++++++- net/netdev/netdev_register.c | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 65d60e9fe02..968a9e21221 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1159,7 +1159,12 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg) int intf; FAR struct ifreq *ifr = (FAR struct ifreq *)arg; - if (!ifr || ((ifr->ifr_flags & IFF_MASK) != IFF_TUN && (ifr->ifr_flags & IFF_MASK) != IFF_TAP)) +#ifdef CONFIG_NET_MULTILINK + if (!ifr || ((ifr->ifr_flags & IFF_MASK) != IFF_TUN && + (ifr->ifr_flags & IFF_MASK) != IFF_TAP)) +#else + if (!ifr || (ifr->ifr_flags & IFF_MASK) != IFF_TUN) +#endif { return -EINVAL; } @@ -1191,11 +1196,13 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg) priv = filep->f_priv; strncpy(ifr->ifr_name, priv->dev.d_ifname, IFNAMSIZ); +#ifdef CONFIG_NET_MULTILINK if ((ifr->ifr_flags & IFF_MASK) == IFF_TAP) { /* TAP device -> handling raw Ethernet packets * -> set appropriate Ethernet header length */ + priv->dev.d_llhdrlen = ETH_HDRLEN; } else if ((ifr->ifr_flags & IFF_MASK) == IFF_TUN) @@ -1203,8 +1210,10 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg) /* TUN device -> handling an application data stream * -> no header */ + priv->dev.d_llhdrlen = 0; } +#endif tundev_unlock(tun); diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index a3de997c853..01a61b5b8ec 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -251,7 +251,8 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) #ifdef CONFIG_NET_TUN case NET_LL_TUN: /* Virtual Network Device (TUN) */ - dev->d_llhdrlen = 0; /* this will be overwritten by tun_ioctl if used as a TAP (layer 2) device */ + dev->d_llhdrlen = 0; /* This will be overwritten by tun_ioctl + * if used as a TAP (layer 2) device */ dev->d_mtu = CONFIG_NET_TUN_MTU; #ifdef CONFIG_NET_TCP dev->d_recvwndo = CONFIG_NET_TUN_TCP_RECVWNDO; From 39b62c6b46780fd7f1d383a63c1edf74002659f8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Apr 2017 06:50:33 -0600 Subject: [PATCH 47/48] Changes from review of last PR --- configs/nucleo-f4x1re/src/stm32_appinit.c | 6 --- configs/nucleo-l476rg/src/stm32_appinit.c | 6 --- configs/stm32f411e-disco/Kconfig | 1 - configs/stm32f411e-disco/src/Makefile | 2 +- configs/stm32f411e-disco/src/stm32_appinit.c | 10 ++-- configs/stm32f411e-disco/src/stm32_boot.c | 11 +++-- configs/stm32f411e-disco/src/stm32_bringup.c | 31 ++----------- configs/stm32f411e-disco/src/stm32_usb.c | 7 +-- .../stm32f411e-disco/src/stm32f411e-disco.h | 46 ++++++++----------- configs/stm32l476-mdk/src/stm32_appinit.c | 6 --- configs/stm32l476vg-disco/src/stm32_appinit.c | 18 +++----- 11 files changed, 42 insertions(+), 102 deletions(-) diff --git a/configs/nucleo-f4x1re/src/stm32_appinit.c b/configs/nucleo-f4x1re/src/stm32_appinit.c index 5845ad169f3..a76eba4b59e 100644 --- a/configs/nucleo-f4x1re/src/stm32_appinit.c +++ b/configs/nucleo-f4x1re/src/stm32_appinit.c @@ -102,12 +102,6 @@ int board_app_initialize(uintptr_t arg) { int ret = OK; - /* Configure CPU load estimation */ - -#ifdef CONFIG_SCHED_INSTRUMENTATION - cpuload_initialize_once(); -#endif - #ifdef HAVE_MMCSD /* First, get an instance of the SDIO interface */ diff --git a/configs/nucleo-l476rg/src/stm32_appinit.c b/configs/nucleo-l476rg/src/stm32_appinit.c index ceaa3a76f52..f66fcdb1eca 100644 --- a/configs/nucleo-l476rg/src/stm32_appinit.c +++ b/configs/nucleo-l476rg/src/stm32_appinit.c @@ -120,12 +120,6 @@ int board_app_initialize(uintptr_t arg) (void)ret; -#ifdef CONFIG_SCHED_INSTRUMENTATION - /* Configure CPU load estimation */ - - cpuload_initialize_once(); -#endif - #ifdef HAVE_PROC /* Mount the proc filesystem */ diff --git a/configs/stm32f411e-disco/Kconfig b/configs/stm32f411e-disco/Kconfig index 205dc95fa2b..4e51f7f5dd3 100644 --- a/configs/stm32f411e-disco/Kconfig +++ b/configs/stm32f411e-disco/Kconfig @@ -15,5 +15,4 @@ config STM32F411DISCO_USBHOST_PRIO default 100 depends on USBHOST - endif diff --git a/configs/stm32f411e-disco/src/Makefile b/configs/stm32f411e-disco/src/Makefile index 3635386d27a..7cc95d6a5d9 100644 --- a/configs/stm32f411e-disco/src/Makefile +++ b/configs/stm32f411e-disco/src/Makefile @@ -1,7 +1,7 @@ ############################################################################ # configs/stm32f411e-disco/src/Makefile # -# Copyright (C) 2016 Gregory Nutt. All rights reserved. +# Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without diff --git a/configs/stm32f411e-disco/src/stm32_appinit.c b/configs/stm32f411e-disco/src/stm32_appinit.c index 9228ec0366e..984a3d9ab48 100644 --- a/configs/stm32f411e-disco/src/stm32_appinit.c +++ b/configs/stm32f411e-disco/src/stm32_appinit.c @@ -84,11 +84,11 @@ int board_app_initialize(uintptr_t arg) { -#ifdef CONFIG_SCHED_INSTRUMENTATION - /* Configure CPU load estimation */ - - cpuload_initialize_once(); -#endif +#ifndef CONFIG_BOARD_INITIALIZE + /* Perform board-specific initialization */ + return stm32_bringup(); +#else return OK; +#endif } diff --git a/configs/stm32f411e-disco/src/stm32_boot.c b/configs/stm32f411e-disco/src/stm32_boot.c index 6de88de6a99..208f9b9a75d 100644 --- a/configs/stm32f411e-disco/src/stm32_boot.c +++ b/configs/stm32f411e-disco/src/stm32_boot.c @@ -72,17 +72,18 @@ void stm32_boardinitialize(void) board_autoled_initialize(); #endif -#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || defined(CONFIG_STM32_SPI3) - /* Configure SPI chip selects if 1) SP2 is not disabled, and 2) the weak function - * stm32_spidev_initialize() has been brought into the link. +#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || \ + defined(CONFIG_STM32_SPI3) + /* Configure SPI chip selects if 1) SP2 is not disabled, and 2) the + * weak function stm32_spidev_initialize() has been brought into the link. */ stm32_spidev_initialize(); #endif #ifdef CONFIG_STM32_OTGFS - /* Initialize USB if the 1) OTG FS controller is in the configuration and 2) - * disabled. Presumably either CONFIG_USBDEV or CONFIG_USBHOST is also selected. + /* Initialize USB if the OTG FS controller is in the configuration. + * Presumably either CONFIG_USBDEV or CONFIG_USBHOST is also selected. */ stm32_usbinitialize(); diff --git a/configs/stm32f411e-disco/src/stm32_bringup.c b/configs/stm32f411e-disco/src/stm32_bringup.c index be0d587123d..22c0ef501d6 100644 --- a/configs/stm32f411e-disco/src/stm32_bringup.c +++ b/configs/stm32f411e-disco/src/stm32_bringup.c @@ -1,7 +1,7 @@ /**************************************************************************** - * config/stm32f4discovery/src/stm32_bringup.c + * config/stm32f411e-disco/src/stm32_bringup.c * - * Copyright (C) 2012, 2014-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,16 +40,7 @@ #include #include -#include -#include #include -#include - -#ifdef CONFIG_USBMONITOR -# include -#endif - -#include #include "stm32.h" @@ -59,20 +50,6 @@ #include "stm32f411e-disco.h" -/* Conditional logic in stm32f4discover.h will determine if certain features - * are supported. Tests for these features need to be made after including - * stm32f4discovery.h. - */ - -#ifdef HAVE_RTC_DRIVER -# include -# include "stm32_rtc.h" -#endif - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -95,7 +72,7 @@ int stm32_bringup(void) { int ret = OK; -#ifdef HAVE_USBHOST +#if defined(CONFIG_STM32_OTGFS) && defined(CONFIG_USBHOST) /* Initialize USB host operation. stm32_usbhost_initialize() starts a thread * will monitor for USB connection and disconnection events. */ @@ -114,7 +91,7 @@ int stm32_bringup(void) ret = mount(NULL, STM32_PROCFS_MOUNTPOINT, "procfs", 0, NULL); if (ret < 0) { - serr("ERROR: Failed to mount procfs at %s: %d\n", + ferr("ERROR: Failed to mount procfs at %s: %d\n", STM32_PROCFS_MOUNTPOINT, ret); } #endif diff --git a/configs/stm32f411e-disco/src/stm32_usb.c b/configs/stm32f411e-disco/src/stm32_usb.c index cd0a5afee1e..95cc3da81dc 100644 --- a/configs/stm32f411e-disco/src/stm32_usb.c +++ b/configs/stm32f411e-disco/src/stm32_usb.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/stm32f411e-disco/src/stm32_usb.c * - * Copyright (C) 2012-2013, 2015, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Copyright (C) 2017 Brian Webb. All rights reserved. @@ -65,11 +65,8 @@ * Pre-processor Definitions ************************************************************************************/ -#if defined(CONFIG_USBDEV) || defined(CONFIG_USBHOST) -# define HAVE_USB 1 -#else +#if !defined(CONFIG_USBDEV) && !defined(CONFIG_USBHOST) # warning "CONFIG_STM32_OTGFS is enabled but neither CONFIG_USBDEV nor CONFIG_USBHOST" -# undef HAVE_USB #endif #ifndef CONFIG_STM32F411DISCO_USBHOST_PRIO diff --git a/configs/stm32f411e-disco/src/stm32f411e-disco.h b/configs/stm32f411e-disco/src/stm32f411e-disco.h index e679b03a4e5..1d78f4c6b36 100644 --- a/configs/stm32f411e-disco/src/stm32f411e-disco.h +++ b/configs/stm32f411e-disco/src/stm32f411e-disco.h @@ -1,4 +1,4 @@ -/************************************************************************************ +/**************************************************************************** * configs/stm32f411e-disco/src/stm32f411e-disco.h * * Copyright (C) 2016 Gregory Nutt. All rights reserved. @@ -32,28 +32,28 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************************/ + ****************************************************************************/ #ifndef __CONFIGS_STM32F411E_DISCO_SRC_STM32F411E_DISCO_H #define __CONFIGS_STM32F411E_DISCO_SRC_STM32F411E_DISCO_H -/************************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************************/ + ****************************************************************************/ #include #include #include -/************************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************************/ -/* Configuration ********************************************************************/ + ****************************************************************************/ +/* Configuration ************************************************************/ -/* LED. User LD2: the green LED is a user LED connected to Arduino signal D13 - * corresponding to MCU I/O PA5 (pin 21) or PB13 (pin 34) depending on the STM32 - * target. +/* LED. User LD2: the green LED is a user LED connected to Arduino signal + * D13 corresponding to MCU I/O PA5 (pin 21) or PB13 (pin 34) depending on + * the STM32 target. * * - When the I/O is HIGH value, the LED is on. * - When the I/O is LOW, the LED is off. @@ -85,16 +85,6 @@ #define GPIO_SPI1_SCK_OFF (GPIO_INPUT | GPIO_PULLDOWN | \ GPIO_PORTA | GPIO_PIN5) -/* Assume that we have everything */ - -#define HAVE_USBDEV 1 -#define HAVE_USBHOST 1 -#define HAVE_USBMONITOR 1 -#define HAVE_SDIO 1 -#define HAVE_RTC_DRIVER 1 -#define HAVE_ELF 1 -#define HAVE_NETMONITOR 1 - /* USB OTG FS * * PA9 OTG_FS_VBUS VBUS sensing (also connected to the green LED) @@ -127,9 +117,9 @@ # endif #endif -/************************************************************************************ +/**************************************************************************** * Public Data - ************************************************************************************/ + ****************************************************************************/ /* Global driver instances */ @@ -140,17 +130,17 @@ extern struct spi_dev_s *g_spi1; extern struct spi_dev_s *g_spi2; #endif -/************************************************************************************ +/**************************************************************************** * Public Functions - ************************************************************************************/ + ****************************************************************************/ -/************************************************************************************ +/**************************************************************************** * Name: stm32_spidev_initialize * * Description: * Called to configure SPI chip select GPIO pins. * - ************************************************************************************/ + ****************************************************************************/ void stm32_spidev_initialize(void); @@ -158,7 +148,7 @@ void stm32_spidev_initialize(void); * Name: stm32_usbinitialize * * Description: - * Called from stm32_usbinitialize very early in initialization to setup + * Called from stm32_boardinitialize very early in initialization to setup * USB-related GPIO pins for the STM32F4Discovery board. * ****************************************************************************/ @@ -172,7 +162,7 @@ void stm32_usbinitialize(void); * * Description: * Called at application startup time to initialize the USB host - * functionality. This function will start a thread that will monitor for + * functionality. This function will start a thread that will monitor for * device connection/disconnection events. * ****************************************************************************/ diff --git a/configs/stm32l476-mdk/src/stm32_appinit.c b/configs/stm32l476-mdk/src/stm32_appinit.c index 99a42e0a4a4..2633d47302d 100644 --- a/configs/stm32l476-mdk/src/stm32_appinit.c +++ b/configs/stm32l476-mdk/src/stm32_appinit.c @@ -113,12 +113,6 @@ int board_app_initialize(uintptr_t arg) (void)ret; -#ifdef CONFIG_SCHED_INSTRUMENTATION - /* Configure CPU load estimation */ - - cpuload_initialize_once(); -#endif - #ifdef HAVE_PROC /* mount the proc filesystem */ diff --git a/configs/stm32l476vg-disco/src/stm32_appinit.c b/configs/stm32l476vg-disco/src/stm32_appinit.c index 4cccfd50392..40b204e59ee 100644 --- a/configs/stm32l476vg-disco/src/stm32_appinit.c +++ b/configs/stm32l476vg-disco/src/stm32_appinit.c @@ -140,12 +140,6 @@ FAR struct mtd_dev_s *mtd_temp; int ret; (void)ret; - -#ifdef CONFIG_SCHED_INSTRUMENTATION - /* Configure CPU load estimation */ - - cpuload_initialize_once(); -#endif #ifdef HAVE_PROC /* mount the proc filesystem */ @@ -208,7 +202,7 @@ FAR struct mtd_dev_s *mtd_temp; return ret; } g_mtd_fs = mtd_temp; - + #ifdef CONFIG_MTD_PARTITION { FAR struct mtd_geometry_s geo; @@ -342,7 +336,7 @@ int board_ioctl(unsigned int cmd, uintptr_t arg) * 6 = CONFIG_N25QXXX_DUMMIES; * 0xeb = N25QXXX_FAST_READ_QUADIO; */ - + meminfo.flags = QSPIMEM_READ | QSPIMEM_QUADIO; meminfo.addrlen = 3; meminfo.dummies = 6; //CONFIG_N25QXXX_DUMMIES; @@ -350,17 +344,17 @@ int board_ioctl(unsigned int cmd, uintptr_t arg) meminfo.addr = 0; meminfo.buflen = 0; meminfo.buffer = NULL; - + stm32l4_qspi_enter_memorymapped(g_qspi, &meminfo, 80000000); } break; - + case BIOC_EXIT_MEMMAP: stm32l4_qspi_exit_memorymapped(g_qspi); break; - + #endif - + default: return -EINVAL; break; From 55c95442e17d968d62cc275ba9d57c7f2a8feb77 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Apr 2017 09:53:38 -0600 Subject: [PATCH 48/48] drivers/net/skeleton.c: Add support for IOCTL handling. --- drivers/net/skeleton.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/net/skeleton.c b/drivers/net/skeleton.c index bb1a543ff93..94380212f67 100644 --- a/drivers/net/skeleton.c +++ b/drivers/net/skeleton.c @@ -190,6 +190,9 @@ static int skel_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); static void skel_ipv6multicast(FAR struct skel_driver_s *priv); #endif #endif +#ifdef CONFIG_NETDEV_IOCTL +static int skel_ioctl(FAR struct net_driver_s *dev, int cmd, long arg); +#endif /**************************************************************************** * Private Functions @@ -1073,6 +1076,45 @@ static void skel_ipv6multicast(FAR struct skel_driver_s *priv) } #endif /* CONFIG_NET_ICMPv6 */ +/**************************************************************************** + * Name: skel_ioctl + * + * Description: + * Handle network IOCTL commands directed to this device. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * cmd - The IOCTL command + * arg - The argument for the IOCTL command + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_IOCTL +static int skel_ioctl(FAR struct net_driver_s *dev, int cmd, long arg) +{ + FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)dev->d_private; + int ret; + + /* Decode and dispatch the driver-specific IOCTL command */ + + switch (cmd) + { + /* Add cases here to support the IOCTL commands */ + + default: + nerr("ERROR: Unrecognized IOCTL command: %d\n", command); + return -ENOTTY; /* Special return value for this case */ + } + + return OK; +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -1124,6 +1166,9 @@ int skel_initialize(int intf) #ifdef CONFIG_NET_IGMP priv->sk_dev.d_addmac = skel_addmac; /* Add multicast MAC address */ priv->sk_dev.d_rmmac = skel_rmmac; /* Remove multicast MAC address */ +#endif +#ifdef CONFIG_NETDEV_IOCTL + priv->sk_dev.d_ioctl = skel_ioctl; /* Handle network IOCTL commands */ #endif priv->sk_dev.d_private = (FAR void *)g_skel; /* Used to recover private state from dev */