Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.

Upstream: https://github.com/ARMmbed/DAPLink

Committer:
Pawel Zarembski
Date:
Tue Apr 07 12:55:42 2020 +0200
Revision:
0:01f31e923fe2
hani: DAPLink with reset workaround

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pawel Zarembski 0:01f31e923fe2 1 /**
Pawel Zarembski 0:01f31e923fe2 2 * @file util.h
Pawel Zarembski 0:01f31e923fe2 3 * @brief useful things
Pawel Zarembski 0:01f31e923fe2 4 *
Pawel Zarembski 0:01f31e923fe2 5 * DAPLink Interface Firmware
Pawel Zarembski 0:01f31e923fe2 6 * Copyright (c) 2009-2020, ARM Limited, All Rights Reserved
Pawel Zarembski 0:01f31e923fe2 7 * SPDX-License-Identifier: Apache-2.0
Pawel Zarembski 0:01f31e923fe2 8 *
Pawel Zarembski 0:01f31e923fe2 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Pawel Zarembski 0:01f31e923fe2 10 * not use this file except in compliance with the License.
Pawel Zarembski 0:01f31e923fe2 11 * You may obtain a copy of the License at
Pawel Zarembski 0:01f31e923fe2 12 *
Pawel Zarembski 0:01f31e923fe2 13 * http://www.apache.org/licenses/LICENSE-2.0
Pawel Zarembski 0:01f31e923fe2 14 *
Pawel Zarembski 0:01f31e923fe2 15 * Unless required by applicable law or agreed to in writing, software
Pawel Zarembski 0:01f31e923fe2 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Pawel Zarembski 0:01f31e923fe2 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Pawel Zarembski 0:01f31e923fe2 18 * See the License for the specific language governing permissions and
Pawel Zarembski 0:01f31e923fe2 19 * limitations under the License.
Pawel Zarembski 0:01f31e923fe2 20 */
Pawel Zarembski 0:01f31e923fe2 21
Pawel Zarembski 0:01f31e923fe2 22 #ifndef UTIL_H
Pawel Zarembski 0:01f31e923fe2 23 #define UTIL_H
Pawel Zarembski 0:01f31e923fe2 24
Pawel Zarembski 0:01f31e923fe2 25 #include <stdbool.h>
Pawel Zarembski 0:01f31e923fe2 26 #include <stdint.h>
Pawel Zarembski 0:01f31e923fe2 27
Pawel Zarembski 0:01f31e923fe2 28 // Protect commonly-defined macros with ifdefs, to prevent conflicts if redefined
Pawel Zarembski 0:01f31e923fe2 29 // in imported sources (mostly vendor SDKs).
Pawel Zarembski 0:01f31e923fe2 30
Pawel Zarembski 0:01f31e923fe2 31 #if !defined(ARRAY_SIZE)
Pawel Zarembski 0:01f31e923fe2 32 //! @brief Get number of elements in the array.
Pawel Zarembski 0:01f31e923fe2 33 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
Pawel Zarembski 0:01f31e923fe2 34 #endif
Pawel Zarembski 0:01f31e923fe2 35
Pawel Zarembski 0:01f31e923fe2 36 #if !defined(MIN)
Pawel Zarembski 0:01f31e923fe2 37 #define MIN(a,b) ((a) < (b) ? (a) : (b))
Pawel Zarembski 0:01f31e923fe2 38 #endif
Pawel Zarembski 0:01f31e923fe2 39
Pawel Zarembski 0:01f31e923fe2 40 #if !defined(MAX)
Pawel Zarembski 0:01f31e923fe2 41 #define MAX(a,b) ((a) > (b) ? (a) : (b))
Pawel Zarembski 0:01f31e923fe2 42 #endif
Pawel Zarembski 0:01f31e923fe2 43
Pawel Zarembski 0:01f31e923fe2 44 #define MB(size) ((size) * 1024 * 1024)
Pawel Zarembski 0:01f31e923fe2 45
Pawel Zarembski 0:01f31e923fe2 46 #define KB(size) ((size) * 1024)
Pawel Zarembski 0:01f31e923fe2 47
Pawel Zarembski 0:01f31e923fe2 48 #define ROUND_UP(value, boundary) ((value) + ((boundary) - (value)) % (boundary))
Pawel Zarembski 0:01f31e923fe2 49
Pawel Zarembski 0:01f31e923fe2 50 #define ROUND_DOWN(value, boundary) ((value) - ((value) % (boundary)))
Pawel Zarembski 0:01f31e923fe2 51
Pawel Zarembski 0:01f31e923fe2 52 #ifdef __cplusplus
Pawel Zarembski 0:01f31e923fe2 53 extern "C" {
Pawel Zarembski 0:01f31e923fe2 54 #endif
Pawel Zarembski 0:01f31e923fe2 55
Pawel Zarembski 0:01f31e923fe2 56 // Write the value to the address specified and return the size
Pawel Zarembski 0:01f31e923fe2 57 uint32_t util_write_hex8(char *str, uint8_t value);
Pawel Zarembski 0:01f31e923fe2 58 uint32_t util_write_hex16(char *str, uint16_t value);
Pawel Zarembski 0:01f31e923fe2 59 uint32_t util_write_hex32(char *str, uint32_t value);
Pawel Zarembski 0:01f31e923fe2 60 uint32_t util_write_uint32(char *str, uint32_t value);
Pawel Zarembski 0:01f31e923fe2 61 uint32_t util_write_uint32(char *str, uint32_t value);
Pawel Zarembski 0:01f31e923fe2 62 uint32_t util_write_uint32_zp(char *str, uint32_t value, uint16_t total_size);
Pawel Zarembski 0:01f31e923fe2 63 uint32_t util_write_string(char *str, const char *data);
Pawel Zarembski 0:01f31e923fe2 64
Pawel Zarembski 0:01f31e923fe2 65 uint32_t util_div_round_up(uint32_t dividen, uint32_t divisor);
Pawel Zarembski 0:01f31e923fe2 66 uint32_t util_div_round_down(uint32_t dividen, uint32_t divisor);
Pawel Zarembski 0:01f31e923fe2 67 uint32_t util_div_round(uint32_t dividen, uint32_t divisor);
Pawel Zarembski 0:01f31e923fe2 68
Pawel Zarembski 0:01f31e923fe2 69 #if !(defined(DAPLINK_NO_ASSERT_FILENAMES) && defined(DAPLINK_BL))
Pawel Zarembski 0:01f31e923fe2 70 // With the filename enabled.
Pawel Zarembski 0:01f31e923fe2 71 #define util_assert(expression) _util_assert((expression), __FILE__, __LINE__)
Pawel Zarembski 0:01f31e923fe2 72 #else
Pawel Zarembski 0:01f31e923fe2 73 // Filename disabled to save code size.
Pawel Zarembski 0:01f31e923fe2 74 #define util_assert(expression) _util_assert((expression), "(file)", __LINE__)
Pawel Zarembski 0:01f31e923fe2 75 #endif
Pawel Zarembski 0:01f31e923fe2 76 void _util_assert(bool expression, const char *filename, uint16_t line);
Pawel Zarembski 0:01f31e923fe2 77
Pawel Zarembski 0:01f31e923fe2 78 void util_assert_clear(void);
Pawel Zarembski 0:01f31e923fe2 79
Pawel Zarembski 0:01f31e923fe2 80 #ifdef __cplusplus
Pawel Zarembski 0:01f31e923fe2 81 }
Pawel Zarembski 0:01f31e923fe2 82 #endif
Pawel Zarembski 0:01f31e923fe2 83
Pawel Zarembski 0:01f31e923fe2 84 #endif