mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
targets/TARGET_NUVOTON/nu_bitutil.h@174:b96e65c34a4d, 2017-10-02 (annotated)
- Committer:
- AnnaBridge
- Date:
- Mon Oct 02 15:33:19 2017 +0100
- Revision:
- 174:b96e65c34a4d
- Parent:
- 149:156823d33999
This updates the lib to the mbed lib v 152
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 144:ef7eb2e8f9f7 | 1 | /* mbed Microcontroller Library |
<> | 144:ef7eb2e8f9f7 | 2 | * Copyright (c) 2015-2016 Nuvoton |
<> | 144:ef7eb2e8f9f7 | 3 | * |
<> | 144:ef7eb2e8f9f7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
<> | 144:ef7eb2e8f9f7 | 5 | * you may not use this file except in compliance with the License. |
<> | 144:ef7eb2e8f9f7 | 6 | * You may obtain a copy of the License at |
<> | 144:ef7eb2e8f9f7 | 7 | * |
<> | 144:ef7eb2e8f9f7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 144:ef7eb2e8f9f7 | 9 | * |
<> | 144:ef7eb2e8f9f7 | 10 | * Unless required by applicable law or agreed to in writing, software |
<> | 144:ef7eb2e8f9f7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
<> | 144:ef7eb2e8f9f7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 144:ef7eb2e8f9f7 | 13 | * See the License for the specific language governing permissions and |
<> | 144:ef7eb2e8f9f7 | 14 | * limitations under the License. |
<> | 144:ef7eb2e8f9f7 | 15 | */ |
<> | 144:ef7eb2e8f9f7 | 16 | |
<> | 144:ef7eb2e8f9f7 | 17 | #ifndef NU_BIT_UTIL_H |
<> | 144:ef7eb2e8f9f7 | 18 | #define NU_BIT_UTIL_H |
<> | 144:ef7eb2e8f9f7 | 19 | |
AnnaBridge | 174:b96e65c34a4d | 20 | #if defined(__ICCARM__) && defined(TARGET_M0) |
AnnaBridge | 174:b96e65c34a4d | 21 | #include <arm_math.h> |
AnnaBridge | 174:b96e65c34a4d | 22 | #endif |
<> | 144:ef7eb2e8f9f7 | 23 | #include "cmsis.h" |
<> | 144:ef7eb2e8f9f7 | 24 | |
<> | 144:ef7eb2e8f9f7 | 25 | #ifdef __cplusplus |
<> | 144:ef7eb2e8f9f7 | 26 | extern "C" { |
<> | 144:ef7eb2e8f9f7 | 27 | #endif |
<> | 144:ef7eb2e8f9f7 | 28 | |
<> | 144:ef7eb2e8f9f7 | 29 | __STATIC_INLINE int nu_clz(uint32_t x) |
<> | 144:ef7eb2e8f9f7 | 30 | { |
<> | 144:ef7eb2e8f9f7 | 31 | return __CLZ(x); |
<> | 144:ef7eb2e8f9f7 | 32 | } |
<> | 144:ef7eb2e8f9f7 | 33 | |
<> | 144:ef7eb2e8f9f7 | 34 | __STATIC_INLINE int nu_clo(uint32_t x) |
<> | 144:ef7eb2e8f9f7 | 35 | { |
<> | 144:ef7eb2e8f9f7 | 36 | return nu_clz(~x); |
<> | 144:ef7eb2e8f9f7 | 37 | } |
<> | 144:ef7eb2e8f9f7 | 38 | |
<> | 144:ef7eb2e8f9f7 | 39 | __STATIC_INLINE int nu_ctz(uint32_t x) |
<> | 144:ef7eb2e8f9f7 | 40 | { |
<> | 144:ef7eb2e8f9f7 | 41 | int c = __CLZ(x & -x); |
<> | 144:ef7eb2e8f9f7 | 42 | return x ? 31 - c : c; |
<> | 144:ef7eb2e8f9f7 | 43 | } |
<> | 144:ef7eb2e8f9f7 | 44 | |
<> | 144:ef7eb2e8f9f7 | 45 | __STATIC_INLINE int nu_cto(uint32_t x) |
<> | 144:ef7eb2e8f9f7 | 46 | { |
<> | 144:ef7eb2e8f9f7 | 47 | return nu_ctz(~x); |
<> | 144:ef7eb2e8f9f7 | 48 | } |
<> | 144:ef7eb2e8f9f7 | 49 | |
<> | 144:ef7eb2e8f9f7 | 50 | |
<> | 144:ef7eb2e8f9f7 | 51 | __STATIC_INLINE uint16_t nu_get16_le(const uint8_t *pos) |
<> | 144:ef7eb2e8f9f7 | 52 | { |
<> | 144:ef7eb2e8f9f7 | 53 | uint16_t val; |
<> | 144:ef7eb2e8f9f7 | 54 | |
<> | 144:ef7eb2e8f9f7 | 55 | val = *pos ++; |
<> | 144:ef7eb2e8f9f7 | 56 | val += (*pos << 8); |
<> | 144:ef7eb2e8f9f7 | 57 | |
<> | 144:ef7eb2e8f9f7 | 58 | return val; |
<> | 144:ef7eb2e8f9f7 | 59 | } |
<> | 144:ef7eb2e8f9f7 | 60 | |
<> | 144:ef7eb2e8f9f7 | 61 | __STATIC_INLINE void nu_set16_le(uint8_t *pos, uint16_t val) |
<> | 144:ef7eb2e8f9f7 | 62 | { |
<> | 144:ef7eb2e8f9f7 | 63 | *pos ++ = val & 0xFF; |
<> | 144:ef7eb2e8f9f7 | 64 | *pos = val >> 8; |
<> | 144:ef7eb2e8f9f7 | 65 | } |
<> | 144:ef7eb2e8f9f7 | 66 | |
<> | 144:ef7eb2e8f9f7 | 67 | __STATIC_INLINE uint32_t nu_get32_le(const uint8_t *pos) |
<> | 144:ef7eb2e8f9f7 | 68 | { |
<> | 144:ef7eb2e8f9f7 | 69 | uint32_t val; |
<> | 144:ef7eb2e8f9f7 | 70 | |
<> | 144:ef7eb2e8f9f7 | 71 | val = *pos ++; |
<> | 144:ef7eb2e8f9f7 | 72 | val += (*pos ++ << 8); |
<> | 144:ef7eb2e8f9f7 | 73 | val += (*pos ++ << 16); |
<> | 144:ef7eb2e8f9f7 | 74 | val += (*pos ++ << 24); |
<> | 144:ef7eb2e8f9f7 | 75 | |
<> | 144:ef7eb2e8f9f7 | 76 | return val; |
<> | 144:ef7eb2e8f9f7 | 77 | } |
<> | 144:ef7eb2e8f9f7 | 78 | |
<> | 144:ef7eb2e8f9f7 | 79 | __STATIC_INLINE void nu_set32_le(uint8_t *pos, uint32_t val) |
<> | 144:ef7eb2e8f9f7 | 80 | { |
<> | 144:ef7eb2e8f9f7 | 81 | *pos ++ = val & 0xFF; |
<> | 144:ef7eb2e8f9f7 | 82 | *pos ++ = (val >> 8) & 0xFF; |
<> | 144:ef7eb2e8f9f7 | 83 | *pos ++ = (val >> 16) & 0xFF; |
<> | 144:ef7eb2e8f9f7 | 84 | *pos = (val >> 24) & 0xFF; |
<> | 144:ef7eb2e8f9f7 | 85 | } |
<> | 144:ef7eb2e8f9f7 | 86 | |
<> | 144:ef7eb2e8f9f7 | 87 | __STATIC_INLINE uint16_t nu_get16_be(const uint8_t *pos) |
<> | 144:ef7eb2e8f9f7 | 88 | { |
<> | 144:ef7eb2e8f9f7 | 89 | uint16_t val; |
<> | 144:ef7eb2e8f9f7 | 90 | |
<> | 144:ef7eb2e8f9f7 | 91 | val = *pos ++; |
<> | 144:ef7eb2e8f9f7 | 92 | val <<= 8; |
<> | 144:ef7eb2e8f9f7 | 93 | val += *pos; |
<> | 144:ef7eb2e8f9f7 | 94 | |
<> | 144:ef7eb2e8f9f7 | 95 | return val; |
<> | 144:ef7eb2e8f9f7 | 96 | } |
<> | 144:ef7eb2e8f9f7 | 97 | |
<> | 144:ef7eb2e8f9f7 | 98 | __STATIC_INLINE void nu_set16_be(uint8_t *pos, uint16_t val) |
<> | 144:ef7eb2e8f9f7 | 99 | { |
<> | 144:ef7eb2e8f9f7 | 100 | *pos ++ = val >> 8; |
<> | 144:ef7eb2e8f9f7 | 101 | *pos = (val & 0xFF); |
<> | 144:ef7eb2e8f9f7 | 102 | } |
<> | 144:ef7eb2e8f9f7 | 103 | |
<> | 144:ef7eb2e8f9f7 | 104 | __STATIC_INLINE uint32_t nu_get32_be(const uint8_t *pos) |
<> | 144:ef7eb2e8f9f7 | 105 | { |
<> | 144:ef7eb2e8f9f7 | 106 | uint32_t val; |
<> | 144:ef7eb2e8f9f7 | 107 | |
<> | 144:ef7eb2e8f9f7 | 108 | val = *pos ++; |
<> | 144:ef7eb2e8f9f7 | 109 | val <<= 8; |
<> | 144:ef7eb2e8f9f7 | 110 | val += *pos ++; |
<> | 144:ef7eb2e8f9f7 | 111 | val <<= 8; |
<> | 144:ef7eb2e8f9f7 | 112 | val += *pos ++; |
<> | 144:ef7eb2e8f9f7 | 113 | val <<= 8; |
<> | 144:ef7eb2e8f9f7 | 114 | val += *pos; |
<> | 144:ef7eb2e8f9f7 | 115 | |
<> | 144:ef7eb2e8f9f7 | 116 | return val; |
<> | 144:ef7eb2e8f9f7 | 117 | } |
<> | 144:ef7eb2e8f9f7 | 118 | |
<> | 144:ef7eb2e8f9f7 | 119 | __STATIC_INLINE void nu_set32_be(uint8_t *pos, uint32_t val) |
<> | 144:ef7eb2e8f9f7 | 120 | { |
<> | 144:ef7eb2e8f9f7 | 121 | *pos ++ = val >> 24; |
<> | 144:ef7eb2e8f9f7 | 122 | *pos ++ = val >> 16; |
<> | 144:ef7eb2e8f9f7 | 123 | *pos ++ = val >> 8; |
<> | 144:ef7eb2e8f9f7 | 124 | *pos ++ = (val & 0xFF); |
<> | 144:ef7eb2e8f9f7 | 125 | } |
<> | 144:ef7eb2e8f9f7 | 126 | |
<> | 144:ef7eb2e8f9f7 | 127 | #ifdef __cplusplus |
<> | 144:ef7eb2e8f9f7 | 128 | } |
<> | 144:ef7eb2e8f9f7 | 129 | #endif |
<> | 144:ef7eb2e8f9f7 | 130 | |
<> | 144:ef7eb2e8f9f7 | 131 | #endif |