Files
mbed-os/targets/TARGET_NUVOTON/nu_bitutil.h
Beslan 0ef1717155
Some checks failed
Basic Checks / license-check (push) Has been cancelled
Basic Checks / include-check (push) Has been cancelled
Basic Checks / style-check (push) Has been cancelled
Basic Checks / docs-check (push) Has been cancelled
Basic Checks / python-tests (push) Has been cancelled
Basic Checks / pin-validation (push) Has been cancelled
Basic Checks / cmake-checks (push) Has been cancelled
Basic Checks / frozen-tools-check (push) Has been cancelled
Publish or Update docker image for head of branch / prepare-tags (push) Has been cancelled
Release or update docker image for a released mbed-os version / prepare-tags (push) Has been cancelled
Publish or Update docker image for head of branch / build-container (push) Has been cancelled
Publish or Update docker image for head of branch / test-container (linux/amd64) (push) Has been cancelled
Publish or Update docker image for head of branch / test-container (linux/arm64) (push) Has been cancelled
Publish or Update docker image for head of branch / deploy-container (push) Has been cancelled
Release or update docker image for a released mbed-os version / build-container (push) Has been cancelled
Release or update docker image for a released mbed-os version / test-container (linux/amd64) (push) Has been cancelled
Release or update docker image for a released mbed-os version / test-container (linux/arm64) (push) Has been cancelled
Release or update docker image for a released mbed-os version / deploy-container (push) Has been cancelled
Prune temporary docker images / prune-images (push) Has been cancelled
Mirror mbed-os-6.15.0
2026-07-10 18:42:39 +03:00

129 lines
2.2 KiB
C

/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NU_BIT_UTIL_H
#define NU_BIT_UTIL_H
#include "cmsis.h"
#ifdef __cplusplus
extern "C" {
#endif
__STATIC_INLINE int nu_clz(uint32_t x)
{
return __CLZ(x);
}
__STATIC_INLINE int nu_clo(uint32_t x)
{
return nu_clz(~x);
}
__STATIC_INLINE int nu_ctz(uint32_t x)
{
int c = __CLZ(x & -x);
return x ? 31 - c : c;
}
__STATIC_INLINE int nu_cto(uint32_t x)
{
return nu_ctz(~x);
}
__STATIC_INLINE uint16_t nu_get16_le(const uint8_t *pos)
{
uint16_t val;
val = *pos ++;
val += (*pos << 8);
return val;
}
__STATIC_INLINE void nu_set16_le(uint8_t *pos, uint16_t val)
{
*pos ++ = val & 0xFF;
*pos = val >> 8;
}
__STATIC_INLINE uint32_t nu_get32_le(const uint8_t *pos)
{
uint32_t val;
val = *pos ++;
val += (*pos ++ << 8);
val += (*pos ++ << 16);
val += (*pos ++ << 24);
return val;
}
__STATIC_INLINE void nu_set32_le(uint8_t *pos, uint32_t val)
{
*pos ++ = val & 0xFF;
*pos ++ = (val >> 8) & 0xFF;
*pos ++ = (val >> 16) & 0xFF;
*pos = (val >> 24) & 0xFF;
}
__STATIC_INLINE uint16_t nu_get16_be(const uint8_t *pos)
{
uint16_t val;
val = *pos ++;
val <<= 8;
val += *pos;
return val;
}
__STATIC_INLINE void nu_set16_be(uint8_t *pos, uint16_t val)
{
*pos ++ = val >> 8;
*pos = (val & 0xFF);
}
__STATIC_INLINE uint32_t nu_get32_be(const uint8_t *pos)
{
uint32_t val;
val = *pos ++;
val <<= 8;
val += *pos ++;
val <<= 8;
val += *pos ++;
val <<= 8;
val += *pos;
return val;
}
__STATIC_INLINE void nu_set32_be(uint8_t *pos, uint32_t val)
{
*pos ++ = val >> 24;
*pos ++ = val >> 16;
*pos ++ = val >> 8;
*pos ++ = (val & 0xFF);
}
#ifdef __cplusplus
}
#endif
#endif