Skip to content

Commit 07c8b21

Browse files
authored
Merge pull request #4235 from ARMmbed/nanostack-libservice
Nanostack libservice
2 parents d98da40 + bb7eeca commit 07c8b21

File tree

24 files changed

+427
-1327
lines changed

24 files changed

+427
-1327
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SRCS := \
2+
source/IPv6_fcf_lib/ip_fsc.c \
3+
source/libBits/common_functions.c \
4+
source/libip6string/ip6tos.c \
5+
source/libip6string/stoip6.c \
6+
source/libList/ns_list.c \
7+
source/nsdynmemLIB/nsdynmemLIB.c \
8+
source/nvmHelper/ns_nvm_helper.c \
9+
10+
LIB := libservice.a
11+
EXPORT_HEADERS := mbed-client-libservice
12+
13+
include ../exported_rules.mk

features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/common_functions.h

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,41 @@ NS_INLINE uint_fast8_t common_count_bits(uint8_t byte);
172172
/*
173173
* Count leading zeros in a byte
174174
*
175+
* \deprecated Use common_count_leading_zeros_8
176+
*
175177
* \param byte byte to inspect
176178
*
177179
* \return number of leading zeros in byte (0-8)
178180
*/
179181
NS_INLINE uint_fast8_t common_count_leading_zeros(uint8_t byte);
180182

183+
/*
184+
* Count leading zeros in a byte
185+
*
186+
* \param byte byte to inspect
187+
*
188+
* \return number of leading zeros in byte (0-8)
189+
*/
190+
NS_INLINE uint_fast8_t common_count_leading_zeros_8(uint8_t byte);
191+
192+
/*
193+
* Count leading zeros in a 16-bit value
194+
*
195+
* \param value value to inspect
196+
*
197+
* \return number of leading zeros in byte (0-16)
198+
*/
199+
NS_INLINE uint_fast8_t common_count_leading_zeros_16(uint16_t value);
200+
201+
/*
202+
* Count leading zeros in a 32-bit value
203+
*
204+
* \param value value to inspect
205+
*
206+
* \return number of leading zeros in byte (0-32)
207+
*/
208+
NS_INLINE uint_fast8_t common_count_leading_zeros_32(uint32_t value);
209+
181210
/*
182211
* Compare 8-bit serial numbers
183212
*
@@ -434,6 +463,11 @@ COMMON_FUNCTIONS_FN uint_fast8_t common_count_bits(uint8_t byte)
434463
}
435464

436465
COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros(uint8_t byte)
466+
{
467+
return common_count_leading_zeros_8(byte);
468+
}
469+
470+
COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros_8(uint8_t byte)
437471
{
438472
#ifdef __CC_ARM
439473
return byte ? __clz((unsigned int) byte << 24) : 8;
@@ -460,6 +494,72 @@ COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros(uint8_t byte)
460494
#endif
461495
}
462496

497+
COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros_16(uint16_t value)
498+
{
499+
#ifdef __CC_ARM
500+
return value ? __clz((unsigned int) value << 16) : 16;
501+
#elif defined __GNUC__
502+
return value ? __builtin_clz((unsigned int) value << 16) : 16;
503+
#else
504+
uint_fast8_t cnt = 0;
505+
if (value == 0) {
506+
return 16;
507+
}
508+
if ((value & 0xFF00) == 0) {
509+
value <<= 8;
510+
cnt += 8;
511+
}
512+
if ((value & 0xF000) == 0) {
513+
value <<= 4;
514+
cnt += 4;
515+
}
516+
if ((value & 0xC000) == 0) {
517+
value <<= 2;
518+
cnt += 2;
519+
}
520+
if ((value & 0x8000) == 0) {
521+
cnt += 1;
522+
}
523+
524+
return cnt;
525+
#endif
526+
}
527+
528+
COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros_32(uint32_t value)
529+
{
530+
#ifdef __CC_ARM
531+
return __clz(value);
532+
#elif defined __GNUC__
533+
return value ? __builtin_clz(value) : 32;
534+
#else
535+
uint_fast8_t cnt = 0;
536+
if (value == 0) {
537+
return 32;
538+
}
539+
if ((value & 0xFFFF0000) == 0) {
540+
value <<= 16;
541+
cnt += 16;
542+
}
543+
if ((value & 0xFF000000) == 0) {
544+
value <<= 8;
545+
cnt += 8;
546+
}
547+
if ((value & 0xF0000000) == 0) {
548+
value <<= 4;
549+
cnt += 4;
550+
}
551+
if ((value & 0xC0000000) == 0) {
552+
value <<= 2;
553+
cnt += 2;
554+
}
555+
if ((value & 0x80000000) == 0) {
556+
cnt += 1;
557+
}
558+
559+
return cnt;
560+
#endif
561+
}
562+
463563
COMMON_FUNCTIONS_FN bool common_serial_number_greater_8(uint8_t s1, uint8_t s2)
464564
{
465565
return (s1 > s2 && s1 - s2 < UINT8_C(0x80)) || (s1 < s2 && s2 - s1 > UINT8_C(0x80));

features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/ip6string.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ extern "C" {
2020
#endif
2121

2222
#include "ns_types.h"
23+
24+
#define MAX_IPV6_STRING_LEN_WITH_TRAILING_NULL 40
25+
2326
/**
2427
* Print binary IPv6 address to a string.
2528
*

0 commit comments

Comments
 (0)