lol

Dependencies:   MMA8451Q

Fork of Application by Mateusz Kowalik

Committer:
Zaitsev
Date:
Tue Jan 10 20:42:26 2017 +0000
Revision:
10:41552d038a69
USB Serial bi-directional bridge

Who changed what in which revision?

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