Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

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