FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:dbad57390bd1 1 /*
ram54288 0:dbad57390bd1 2 * Copyright (c) 2016 ARM Limited. All rights reserved.
ram54288 0:dbad57390bd1 3 * SPDX-License-Identifier: Apache-2.0
ram54288 0:dbad57390bd1 4 * Licensed under the Apache License, Version 2.0 (the License); you may
ram54288 0:dbad57390bd1 5 * not use this file except in compliance with the License.
ram54288 0:dbad57390bd1 6 * You may obtain a copy of the License at
ram54288 0:dbad57390bd1 7 *
ram54288 0:dbad57390bd1 8 * http://www.apache.org/licenses/LICENSE-2.0
ram54288 0:dbad57390bd1 9 *
ram54288 0:dbad57390bd1 10 * Unless required by applicable law or agreed to in writing, software
ram54288 0:dbad57390bd1 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
ram54288 0:dbad57390bd1 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ram54288 0:dbad57390bd1 13 * See the License for the specific language governing permissions and
ram54288 0:dbad57390bd1 14 * limitations under the License.
ram54288 0:dbad57390bd1 15 */
ram54288 0:dbad57390bd1 16
ram54288 0:dbad57390bd1 17
ram54288 0:dbad57390bd1 18 #ifndef _PAL_MACROS_H
ram54288 0:dbad57390bd1 19 #define _PAL_MACROS_H
ram54288 0:dbad57390bd1 20
ram54288 0:dbad57390bd1 21 #ifdef __cplusplus
ram54288 0:dbad57390bd1 22 extern "C" {
ram54288 0:dbad57390bd1 23 #endif
ram54288 0:dbad57390bd1 24
ram54288 0:dbad57390bd1 25 #include "pal_errors.h"
ram54288 0:dbad57390bd1 26 // PAL success value
ram54288 0:dbad57390bd1 27 #define PAL_SUCCESS 0
ram54288 0:dbad57390bd1 28
ram54288 0:dbad57390bd1 29 // maximum integer types
ram54288 0:dbad57390bd1 30 #define PAL_MAX_UINT8 0xFFU
ram54288 0:dbad57390bd1 31 #define PAL_MAX_UINT16 0xFFFFU
ram54288 0:dbad57390bd1 32 #define PAL_MAX_UINT32 0xFFFFFFFFUL
ram54288 0:dbad57390bd1 33 #define PAL_MAX_INT32 0x7FFFFFFFL
ram54288 0:dbad57390bd1 34 #define PAL_MIN_INT32 0x80000000L
ram54288 0:dbad57390bd1 35 #define PAL_MAX_UINT64 0xFFFFFFFFFFFFFFFFULL
ram54288 0:dbad57390bd1 36 #define PAL_MAX_INT64 0x7FFFFFFFFFFFFFFFLL
ram54288 0:dbad57390bd1 37
ram54288 0:dbad57390bd1 38 // useful macros
ram54288 0:dbad57390bd1 39
ram54288 0:dbad57390bd1 40 #define PAL_MAX(a,b) ((a) > (b) ? (a) : (b))
ram54288 0:dbad57390bd1 41
ram54288 0:dbad57390bd1 42 #define PAL_MIN(a,b) ((a) < (b) ? (a) : (b))
ram54288 0:dbad57390bd1 43
ram54288 0:dbad57390bd1 44 #define PAL_DIVIDE_ROUND_UP(num, divider) (((num) + (divider) - 1) / (divider))
ram54288 0:dbad57390bd1 45
ram54288 0:dbad57390bd1 46 #if PAL_COMPILATION_ENDIANITY == 1
ram54288 0:dbad57390bd1 47 #define BIG__ENDIAN 1
ram54288 0:dbad57390bd1 48 #elif PAL_COMPILATION_ENDIANITY == 0
ram54288 0:dbad57390bd1 49 #define LITTLE__ENDIAN 1
ram54288 0:dbad57390bd1 50 #else
ram54288 0:dbad57390bd1 51 #error neither BIG__ENDIAN nor LITTLE__ENDIAN defined, cannot compile
ram54288 0:dbad57390bd1 52 #endif
ram54288 0:dbad57390bd1 53
ram54288 0:dbad57390bd1 54 // endianity macros
ram54288 0:dbad57390bd1 55 #ifdef LITTLE__ENDIAN
ram54288 0:dbad57390bd1 56
ram54288 0:dbad57390bd1 57 #define PAL_HTONS(x) (((((unsigned short)(x)) >> 8) & 0xff) | \
ram54288 0:dbad57390bd1 58 ((((unsigned short)(x)) & 0xff) << 8))
ram54288 0:dbad57390bd1 59 #define PAL_NTOHS(x) (((((unsigned short)(x)) >> 8) & 0xff) | \
ram54288 0:dbad57390bd1 60 ((((unsigned short)(x)) & 0xff) << 8) )
ram54288 0:dbad57390bd1 61 #define PAL_HTONL(x) ((((x)>>24) & 0xffL) | (((x)>>8) & 0xff00L) | \
ram54288 0:dbad57390bd1 62 (((x)<<8) & 0xff0000L) | (((x)<<24) & 0xff000000L))
ram54288 0:dbad57390bd1 63 #define PAL_NTOHL(x) ((((x)>>24) & 0xffL) | (((x)>>8) & 0xff00L) | \
ram54288 0:dbad57390bd1 64 (((x)<<8) & 0xff0000L) | (((x)<<24) & 0xff000000L))
ram54288 0:dbad57390bd1 65
ram54288 0:dbad57390bd1 66 #elif defined(BIG__ENDIAN)
ram54288 0:dbad57390bd1 67
ram54288 0:dbad57390bd1 68 #define PAL_HTONS(x) (x)
ram54288 0:dbad57390bd1 69 #define PAL_NTOHS(x) (x)
ram54288 0:dbad57390bd1 70 #define PAL_HTONL(x) (x)
ram54288 0:dbad57390bd1 71 #define PAL_NTOHL(x) (x)
ram54288 0:dbad57390bd1 72 #else
ram54288 0:dbad57390bd1 73 #error neither BIG__ENDIAN nor LITTLE__ENDIAN defined, cannot compile
ram54288 0:dbad57390bd1 74 #endif
ram54288 0:dbad57390bd1 75
ram54288 0:dbad57390bd1 76
ram54288 0:dbad57390bd1 77
ram54288 0:dbad57390bd1 78 #define PAL_INVERSE_UINT16_BYTES( val ) \
ram54288 0:dbad57390bd1 79 ( ((val) << 8) | (((val) & 0x0000FF00) >> 8))
ram54288 0:dbad57390bd1 80
ram54288 0:dbad57390bd1 81 #define PAL_INVERSE_UINT32_BYTES( val ) \
ram54288 0:dbad57390bd1 82 ( ((val) >> 24) | (((val) & 0x00FF0000) >> 8) | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24) )
ram54288 0:dbad57390bd1 83
ram54288 0:dbad57390bd1 84 #define PAL_INVERSE_UINT64_BYTES( val ) \
ram54288 0:dbad57390bd1 85 ((PAL_INVERSE_UINT32_BYTES( ((val >> 16) >> 16)) &0xffffffff) | ((((uint64_t)PAL_INVERSE_UINT32_BYTES(val & 0xffffffff))<<16)<<16))
ram54288 0:dbad57390bd1 86
ram54288 0:dbad57390bd1 87 /* Set of Macros similar to the HTONS/L, NTOHS/L ones but converting to/from little endian instead of big endian*/
ram54288 0:dbad57390bd1 88 #ifdef LITTLE__ENDIAN
ram54288 0:dbad57390bd1 89 #define PAL_LITTLE_ENDIAN_TO_HOST_16BIT(x) (x)
ram54288 0:dbad57390bd1 90 #define PAL_LITTLE_ENDIAN_TO_HOST_32BIT(x) (x)
ram54288 0:dbad57390bd1 91 #define PAL_LITTLE_ENDIAN_TO_HOST_64BIT(x) (x)
ram54288 0:dbad57390bd1 92 #define PAL_HOST_TO_LITTLE_ENDIAN_16BIT(x) (x)
ram54288 0:dbad57390bd1 93 #define PAL_HOST_TO_LITTLE_ENDIAN_32BIT(x) (x)
ram54288 0:dbad57390bd1 94 #define PAL_HOST_TO_LITTLE_ENDIAN_64BIT(x) (x)
ram54288 0:dbad57390bd1 95
ram54288 0:dbad57390bd1 96
ram54288 0:dbad57390bd1 97 #elif defined(BIG__ENDIAN)
ram54288 0:dbad57390bd1 98 #define PAL_LITTLE_ENDIAN_TO_HOST_16BIT(x) (PAL_INVERSE_UINT16_BYTES(((uint16_t)x)))
ram54288 0:dbad57390bd1 99 #define PAL_LITTLE_ENDIAN_TO_HOST_32BIT(x) (PAL_INVERSE_UINT32_BYTES(((uint32_t)x)))
ram54288 0:dbad57390bd1 100 #define PAL_LITTLE_ENDIAN_TO_HOST_64BIT(x) (PAL_INVERSE_UINT64_BYTES(((uint64_t)x)))
ram54288 0:dbad57390bd1 101 #define PAL_HOST_TO_LITTLE_ENDIAN_16BIT(x) (PAL_INVERSE_UINT16_BYTES(((uint16_t)x)))
ram54288 0:dbad57390bd1 102 #define PAL_HOST_TO_LITTLE_ENDIAN_32BIT(x) (PAL_INVERSE_UINT32_BYTES(((uint32_t)x)))
ram54288 0:dbad57390bd1 103 #define PAL_HOST_TO_LITTLE_ENDIAN_64BIT(x) (PAL_INVERSE_UINT64_BYTES(((uint64_t)x)))
ram54288 0:dbad57390bd1 104
ram54288 0:dbad57390bd1 105 #else
ram54288 0:dbad57390bd1 106 #error neither BIG__ENDIAN nor LITTLE__ENDIAN defined, cannot compile
ram54288 0:dbad57390bd1 107 #endif
ram54288 0:dbad57390bd1 108
ram54288 0:dbad57390bd1 109
ram54288 0:dbad57390bd1 110 #define PAL_MODULE_INIT(INIT) INIT= 1
ram54288 0:dbad57390bd1 111 #define PAL_MODULE_DEINIT(INIT) INIT= 0
ram54288 0:dbad57390bd1 112
ram54288 0:dbad57390bd1 113 #ifdef DEBUG
ram54288 0:dbad57390bd1 114 #include "pal.h"
ram54288 0:dbad57390bd1 115 #define DEBUG_PRINT(ARGS...) PAL_PRINTF(ARGS)
ram54288 0:dbad57390bd1 116
ram54288 0:dbad57390bd1 117 #define DEBUG_PRINT(ARGS...) PAL_PRINTF(ARGS)
ram54288 0:dbad57390bd1 118 #define PAL_MODULE_IS_INIT(INIT) if(!INIT) return PAL_ERR_NOT_INITIALIZED;
ram54288 0:dbad57390bd1 119
ram54288 0:dbad57390bd1 120
ram54288 0:dbad57390bd1 121 #else
ram54288 0:dbad57390bd1 122 #define PAL_MODULE_IS_INIT(INIT)
ram54288 0:dbad57390bd1 123
ram54288 0:dbad57390bd1 124 #define DEBUG_PRINT(ARGS...)
ram54288 0:dbad57390bd1 125
ram54288 0:dbad57390bd1 126 #endif //DEBUG
ram54288 0:dbad57390bd1 127
ram54288 0:dbad57390bd1 128 #ifdef __cplusplus
ram54288 0:dbad57390bd1 129 }
ram54288 0:dbad57390bd1 130 #endif
ram54288 0:dbad57390bd1 131 #endif //_PAL_MACROS_H