From 5e09de3703b0170caf98fa1f3a3502450a17fc7f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 22 Feb 2017 06:35:20 -0600 Subject: [PATCH 1/3] drivers/tone.c: 50% duty needs to be expressed a a fixed precision number --- drivers/audio/tone.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/audio/tone.c b/drivers/audio/tone.c index 972de358b2..f9b5393f73 100644 --- a/drivers/audio/tone.c +++ b/drivers/audio/tone.c @@ -309,9 +309,9 @@ static void start_note(FAR struct tone_upperhalf_s *upper, uint8_t note) upper->tone.frequency = g_notes_freq[note - 1]; #ifdef CONFIG_PWM_MULTICHAN upper->tone.channels[0].channel = upper->channel; - upper->tone.channels[0].duty = 50; + upper->tone.channels[0].duty = b16HALF; #else - upper->tone.duty = 50; + upper->tone.duty = b16HALF; #endif /* REVISIT: Should check the return value */ From 22a8c2178dff4c4f876c072c548b0a181d1bfa01 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 22 Feb 2017 06:59:39 -0600 Subject: [PATCH 2/3] cstring: undefine macros defined in new strings.h. --- include/cxx/cstring | 13 +++++++++++++ include/strings.h | 6 +++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/cxx/cstring b/include/cxx/cstring index 7fca19c45a..e2b7367ab7 100644 --- a/include/cxx/cstring +++ b/include/cxx/cstring @@ -44,6 +44,19 @@ #include #include +//*************************************************************************** +// Pre-processor Definitions +//*************************************************************************** + +// Remove macros defined in strings.h. The index() definition, in +// particular, can cause naming collision problems. + +#undef bcmp +#undef bcopy +#undef bzero +#undef index +#undef rindex + //*************************************************************************** // Namespace //*************************************************************************** diff --git a/include/strings.h b/include/strings.h index bff724d9ba..e9812335f7 100644 --- a/include/strings.h +++ b/include/strings.h @@ -47,7 +47,11 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/* Compatibility definitions */ +/* Compatibility definitions + * + * Marked LEGACY in Open Group Base Specifications Issue 6/IEEE Std 1003.1-2004 + * Removed from Open Group Base Specifications Issue 7/IEEE Std 1003.1-2008 + */ #define bcmp(b1,b2,len) memcmp(b1,b2,(size_t)len) #define bcopy(b1,b2,len) (void)memmove(b2,b1,len) From cb7c5f9921c1228d4823dae492a37c18254c38ce Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 22 Feb 2017 10:20:58 -0600 Subject: [PATCH 3/3] Implement strings.h macros as inline functions when possible for better C++ compatibility. --- include/cxx/cstring | 18 +++----- include/strings.h | 68 ++++++++++++++++++++++++++----- sched/pthread/pthread_mutexlock.c | 2 +- 3 files changed, 63 insertions(+), 25 deletions(-) diff --git a/include/cxx/cstring b/include/cxx/cstring index e2b7367ab7..038080e75d 100644 --- a/include/cxx/cstring +++ b/include/cxx/cstring @@ -44,19 +44,6 @@ #include #include -//*************************************************************************** -// Pre-processor Definitions -//*************************************************************************** - -// Remove macros defined in strings.h. The index() definition, in -// particular, can cause naming collision problems. - -#undef bcmp -#undef bcopy -#undef bzero -#undef index -#undef rindex - //*************************************************************************** // Namespace //*************************************************************************** @@ -100,6 +87,11 @@ namespace std // Declared in legacy strings.h + using ::bcmp; + using ::bcopy; + using ::bzero; + using ::index; + using ::rindex; using ::ffs; using ::strcasecmp; using ::strncasecmp; diff --git a/include/strings.h b/include/strings.h index e9812335f7..6fdaec2275 100644 --- a/include/strings.h +++ b/include/strings.h @@ -47,24 +47,28 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ + +#if !defined(CONFIG_HAVE_INLINE) && !defined(__cplusplus) /* Compatibility definitions * * Marked LEGACY in Open Group Base Specifications Issue 6/IEEE Std 1003.1-2004 * Removed from Open Group Base Specifications Issue 7/IEEE Std 1003.1-2008 */ -#define bcmp(b1,b2,len) memcmp(b1,b2,(size_t)len) -#define bcopy(b1,b2,len) (void)memmove(b2,b1,len) +# define bcmp(b1,b2,len) memcmp(b1,b2,(size_t)len) +# define bcopy(b1,b2,len) (void)memmove(b2,b1,len) -#ifndef CONFIG_LIBC_ARCH_BZERO -# define bzero(s,n) (void)memset(s,0,n) -#endif +# ifndef CONFIG_LIBC_ARCH_BZERO +# define bzero(s,n) (void)memset(s,0,n) +# endif -#define index(s,c) strchr(s,c) -#define rindex(s,c) strrchr(s,c) +# define index(s,c) strchr(s,c) +# define rindex(s,c) strrchr(s,c) + +#endif /* !CONFIG_HAVE_INLINE && !__cplusplus */ /**************************************************************************** - * Public Function Prototypes + * Inline Functions ****************************************************************************/ #undef EXTERN @@ -76,9 +80,51 @@ extern "C" #define EXTERN extern #endif -int ffs(int j); -int strcasecmp(FAR const char *, FAR const char *); -int strncasecmp(FAR const char *, FAR const char *, size_t); +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +/* Compatibility inline functions. + * + * Marked LEGACY in Open Group Base Specifications Issue 6/IEEE Std 1003.1-2004 + * Removed from Open Group Base Specifications Issue 7/IEEE Std 1003.1-2008 + */ + +static inline int bcmp(FAR const void *b1, FAR const void *b2, size_t len) +{ + return memcmp(b1, b2, len); +} + +static inline void bcopy(FAR const void *b1, FAR void *b2, size_t len) +{ + (void)memmove(b1, b2, len); +} + +#ifndef CONFIG_LIBC_ARCH_BZERO +static inline void bzero(FAR void *s, size_t len) +{ + (void)memset(s, 0, len); +} +#endif + +static inline FAR char *index(FAR const char *s, int c) +{ + return strchr(s, c); +} + +static inline FAR char *rindex(FAR const char *s, int c) +{ + return strrchr(s, c); +} +#endif /* CONFIG_HAVE_INLINE || __cplusplus */ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef CONFIG_LIBC_ARCH_BZERO +void bzero(FAR void *s, size_t len); +#endif +int ffs(int j); +int strcasecmp(FAR const char *, FAR const char *); +int strncasecmp(FAR const char *, FAR const char *, size_t); #undef EXTERN #if defined(__cplusplus) diff --git a/sched/pthread/pthread_mutexlock.c b/sched/pthread/pthread_mutexlock.c index ebd650df6f..f94890505d 100644 --- a/sched/pthread/pthread_mutexlock.c +++ b/sched/pthread/pthread_mutexlock.c @@ -150,7 +150,7 @@ int pthread_mutex_lock(FAR pthread_mutex_t *mutex) ret = pthread_takesemaphore((FAR sem_t *)&mutex->sem); - /* If we succussfully obtained the semaphore, then indicate + /* If we successfully obtained the semaphore, then indicate * that we own it. */