Fork of mbed-dev build 137, last build before FAT file system appears to be broken. Also reduced HSE timeout time in STM4XX HAL
Fork of mbed-dev by
targets/TARGET_NUVOTON/nu_bitutil.h@167:356ef919c855, 2017-06-20 (annotated)
- Committer:
- kkado
- Date:
- Tue Jun 20 11:06:37 2017 +0000
- Revision:
- 167:356ef919c855
- Parent:
- 149:156823d33999
Build 137 with reduced HSE timeout
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 | |
<> | 144:ef7eb2e8f9f7 | 20 | #include "cmsis.h" |
<> | 144:ef7eb2e8f9f7 | 21 | |
<> | 144:ef7eb2e8f9f7 | 22 | #ifdef __cplusplus |
<> | 144:ef7eb2e8f9f7 | 23 | extern "C" { |
<> | 144:ef7eb2e8f9f7 | 24 | #endif |
<> | 144:ef7eb2e8f9f7 | 25 | |
<> | 144:ef7eb2e8f9f7 | 26 | __STATIC_INLINE int nu_clz(uint32_t x) |
<> | 144:ef7eb2e8f9f7 | 27 | { |
<> | 144:ef7eb2e8f9f7 | 28 | return __CLZ(x); |
<> | 144:ef7eb2e8f9f7 | 29 | } |
<> | 144:ef7eb2e8f9f7 | 30 | |
<> | 144:ef7eb2e8f9f7 | 31 | __STATIC_INLINE int nu_clo(uint32_t x) |
<> | 144:ef7eb2e8f9f7 | 32 | { |
<> | 144:ef7eb2e8f9f7 | 33 | return nu_clz(~x); |
<> | 144:ef7eb2e8f9f7 | 34 | } |
<> | 144:ef7eb2e8f9f7 | 35 | |
<> | 144:ef7eb2e8f9f7 | 36 | __STATIC_INLINE int nu_ctz(uint32_t x) |
<> | 144:ef7eb2e8f9f7 | 37 | { |
<> | 144:ef7eb2e8f9f7 | 38 | int c = __CLZ(x & -x); |
<> | 144:ef7eb2e8f9f7 | 39 | return x ? 31 - c : c; |
<> | 144:ef7eb2e8f9f7 | 40 | } |
<> | 144:ef7eb2e8f9f7 | 41 | |
<> | 144:ef7eb2e8f9f7 | 42 | __STATIC_INLINE int nu_cto(uint32_t x) |
<> | 144:ef7eb2e8f9f7 | 43 | { |
<> | 144:ef7eb2e8f9f7 | 44 | return nu_ctz(~x); |
<> | 144:ef7eb2e8f9f7 | 45 | } |
<> | 144:ef7eb2e8f9f7 | 46 | |
<> | 144:ef7eb2e8f9f7 | 47 | |
<> | 144:ef7eb2e8f9f7 | 48 | __STATIC_INLINE uint16_t nu_get16_le(const uint8_t *pos) |
<> | 144:ef7eb2e8f9f7 | 49 | { |
<> | 144:ef7eb2e8f9f7 | 50 | uint16_t val; |
<> | 144:ef7eb2e8f9f7 | 51 | |
<> | 144:ef7eb2e8f9f7 | 52 | val = *pos ++; |
<> | 144:ef7eb2e8f9f7 | 53 | val += (*pos << 8); |
<> | 144:ef7eb2e8f9f7 | 54 | |
<> | 144:ef7eb2e8f9f7 | 55 | return val; |
<> | 144:ef7eb2e8f9f7 | 56 | } |
<> | 144:ef7eb2e8f9f7 | 57 | |
<> | 144:ef7eb2e8f9f7 | 58 | __STATIC_INLINE void nu_set16_le(uint8_t *pos, uint16_t val) |
<> | 144:ef7eb2e8f9f7 | 59 | { |
<> | 144:ef7eb2e8f9f7 | 60 | *pos ++ = val & 0xFF; |
<> | 144:ef7eb2e8f9f7 | 61 | *pos = val >> 8; |
<> | 144:ef7eb2e8f9f7 | 62 | } |
<> | 144:ef7eb2e8f9f7 | 63 | |
<> | 144:ef7eb2e8f9f7 | 64 | __STATIC_INLINE uint32_t nu_get32_le(const uint8_t *pos) |
<> | 144:ef7eb2e8f9f7 | 65 | { |
<> | 144:ef7eb2e8f9f7 | 66 | uint32_t val; |
<> | 144:ef7eb2e8f9f7 | 67 | |
<> | 144:ef7eb2e8f9f7 | 68 | val = *pos ++; |
<> | 144:ef7eb2e8f9f7 | 69 | val += (*pos ++ << 8); |
<> | 144:ef7eb2e8f9f7 | 70 | val += (*pos ++ << 16); |
<> | 144:ef7eb2e8f9f7 | 71 | val += (*pos ++ << 24); |
<> | 144:ef7eb2e8f9f7 | 72 | |
<> | 144:ef7eb2e8f9f7 | 73 | return val; |
<> | 144:ef7eb2e8f9f7 | 74 | } |
<> | 144:ef7eb2e8f9f7 | 75 | |
<> | 144:ef7eb2e8f9f7 | 76 | __STATIC_INLINE void nu_set32_le(uint8_t *pos, uint32_t val) |
<> | 144:ef7eb2e8f9f7 | 77 | { |
<> | 144:ef7eb2e8f9f7 | 78 | *pos ++ = val & 0xFF; |
<> | 144:ef7eb2e8f9f7 | 79 | *pos ++ = (val >> 8) & 0xFF; |
<> | 144:ef7eb2e8f9f7 | 80 | *pos ++ = (val >> 16) & 0xFF; |
<> | 144:ef7eb2e8f9f7 | 81 | *pos = (val >> 24) & 0xFF; |
<> | 144:ef7eb2e8f9f7 | 82 | } |
<> | 144:ef7eb2e8f9f7 | 83 | |
<> | 144:ef7eb2e8f9f7 | 84 | __STATIC_INLINE uint16_t nu_get16_be(const uint8_t *pos) |
<> | 144:ef7eb2e8f9f7 | 85 | { |
<> | 144:ef7eb2e8f9f7 | 86 | uint16_t val; |
<> | 144:ef7eb2e8f9f7 | 87 | |
<> | 144:ef7eb2e8f9f7 | 88 | val = *pos ++; |
<> | 144:ef7eb2e8f9f7 | 89 | val <<= 8; |
<> | 144:ef7eb2e8f9f7 | 90 | val += *pos; |
<> | 144:ef7eb2e8f9f7 | 91 | |
<> | 144:ef7eb2e8f9f7 | 92 | return val; |
<> | 144:ef7eb2e8f9f7 | 93 | } |
<> | 144:ef7eb2e8f9f7 | 94 | |
<> | 144:ef7eb2e8f9f7 | 95 | __STATIC_INLINE void nu_set16_be(uint8_t *pos, uint16_t val) |
<> | 144:ef7eb2e8f9f7 | 96 | { |
<> | 144:ef7eb2e8f9f7 | 97 | *pos ++ = val >> 8; |
<> | 144:ef7eb2e8f9f7 | 98 | *pos = (val & 0xFF); |
<> | 144:ef7eb2e8f9f7 | 99 | } |
<> | 144:ef7eb2e8f9f7 | 100 | |
<> | 144:ef7eb2e8f9f7 | 101 | __STATIC_INLINE uint32_t nu_get32_be(const uint8_t *pos) |
<> | 144:ef7eb2e8f9f7 | 102 | { |
<> | 144:ef7eb2e8f9f7 | 103 | uint32_t val; |
<> | 144:ef7eb2e8f9f7 | 104 | |
<> | 144:ef7eb2e8f9f7 | 105 | val = *pos ++; |
<> | 144:ef7eb2e8f9f7 | 106 | val <<= 8; |
<> | 144:ef7eb2e8f9f7 | 107 | val += *pos ++; |
<> | 144:ef7eb2e8f9f7 | 108 | val <<= 8; |
<> | 144:ef7eb2e8f9f7 | 109 | val += *pos ++; |
<> | 144:ef7eb2e8f9f7 | 110 | val <<= 8; |
<> | 144:ef7eb2e8f9f7 | 111 | val += *pos; |
<> | 144:ef7eb2e8f9f7 | 112 | |
<> | 144:ef7eb2e8f9f7 | 113 | return val; |
<> | 144:ef7eb2e8f9f7 | 114 | } |
<> | 144:ef7eb2e8f9f7 | 115 | |
<> | 144:ef7eb2e8f9f7 | 116 | __STATIC_INLINE void nu_set32_be(uint8_t *pos, uint32_t val) |
<> | 144:ef7eb2e8f9f7 | 117 | { |
<> | 144:ef7eb2e8f9f7 | 118 | *pos ++ = val >> 24; |
<> | 144:ef7eb2e8f9f7 | 119 | *pos ++ = val >> 16; |
<> | 144:ef7eb2e8f9f7 | 120 | *pos ++ = val >> 8; |
<> | 144:ef7eb2e8f9f7 | 121 | *pos ++ = (val & 0xFF); |
<> | 144:ef7eb2e8f9f7 | 122 | } |
<> | 144:ef7eb2e8f9f7 | 123 | |
<> | 144:ef7eb2e8f9f7 | 124 | #ifdef __cplusplus |
<> | 144:ef7eb2e8f9f7 | 125 | } |
<> | 144:ef7eb2e8f9f7 | 126 | #endif |
<> | 144:ef7eb2e8f9f7 | 127 | |
<> | 144:ef7eb2e8f9f7 | 128 | #endif |