Skip to content

Nanostack libservice #4235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions features/FEATURE_COMMON_PAL/nanostack-libservice/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SRCS := \
source/IPv6_fcf_lib/ip_fsc.c \
source/libBits/common_functions.c \
source/libip6string/ip6tos.c \
source/libip6string/stoip6.c \
source/libList/ns_list.c \
source/nsdynmemLIB/nsdynmemLIB.c \
source/nvmHelper/ns_nvm_helper.c \

LIB := libservice.a
EXPORT_HEADERS := mbed-client-libservice

include ../exported_rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,41 @@ NS_INLINE uint_fast8_t common_count_bits(uint8_t byte);
/*
* Count leading zeros in a byte
*
* \deprecated Use common_count_leading_zeros_8
*
* \param byte byte to inspect
*
* \return number of leading zeros in byte (0-8)
*/
NS_INLINE uint_fast8_t common_count_leading_zeros(uint8_t byte);

/*
* Count leading zeros in a byte
*
* \param byte byte to inspect
*
* \return number of leading zeros in byte (0-8)
*/
NS_INLINE uint_fast8_t common_count_leading_zeros_8(uint8_t byte);

/*
* Count leading zeros in a 16-bit value
*
* \param value value to inspect
*
* \return number of leading zeros in byte (0-16)
*/
NS_INLINE uint_fast8_t common_count_leading_zeros_16(uint16_t value);

/*
* Count leading zeros in a 32-bit value
*
* \param value value to inspect
*
* \return number of leading zeros in byte (0-32)
*/
NS_INLINE uint_fast8_t common_count_leading_zeros_32(uint32_t value);

/*
* Compare 8-bit serial numbers
*
Expand Down Expand Up @@ -434,6 +463,11 @@ COMMON_FUNCTIONS_FN uint_fast8_t common_count_bits(uint8_t byte)
}

COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros(uint8_t byte)
{
return common_count_leading_zeros_8(byte);
}

COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros_8(uint8_t byte)
{
#ifdef __CC_ARM
return byte ? __clz((unsigned int) byte << 24) : 8;
Expand All @@ -460,6 +494,72 @@ COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros(uint8_t byte)
#endif
}

COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros_16(uint16_t value)
{
#ifdef __CC_ARM
return value ? __clz((unsigned int) value << 16) : 16;
#elif defined __GNUC__
return value ? __builtin_clz((unsigned int) value << 16) : 16;
#else
uint_fast8_t cnt = 0;
if (value == 0) {
return 16;
}
if ((value & 0xFF00) == 0) {
value <<= 8;
cnt += 8;
}
if ((value & 0xF000) == 0) {
value <<= 4;
cnt += 4;
}
if ((value & 0xC000) == 0) {
value <<= 2;
cnt += 2;
}
if ((value & 0x8000) == 0) {
cnt += 1;
}

return cnt;
#endif
}

COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros_32(uint32_t value)
{
#ifdef __CC_ARM
return __clz(value);
#elif defined __GNUC__
return value ? __builtin_clz(value) : 32;
#else
uint_fast8_t cnt = 0;
if (value == 0) {
return 32;
}
if ((value & 0xFFFF0000) == 0) {
value <<= 16;
cnt += 16;
}
if ((value & 0xFF000000) == 0) {
value <<= 8;
cnt += 8;
}
if ((value & 0xF0000000) == 0) {
value <<= 4;
cnt += 4;
}
if ((value & 0xC0000000) == 0) {
value <<= 2;
cnt += 2;
}
if ((value & 0x80000000) == 0) {
cnt += 1;
}

return cnt;
#endif
}

COMMON_FUNCTIONS_FN bool common_serial_number_greater_8(uint8_t s1, uint8_t s2)
{
return (s1 > s2 && s1 - s2 < UINT8_C(0x80)) || (s1 < s2 && s2 - s1 > UINT8_C(0x80));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ extern "C" {
#endif

#include "ns_types.h"

#define MAX_IPV6_STRING_LEN_WITH_TRAILING_NULL 40

/**
* Print binary IPv6 address to a string.
*
Expand Down
Loading