Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
util.h
00001 /** 00002 * @file util.h 00003 * @brief useful things 00004 * 00005 * DAPLink Interface Firmware 00006 * Copyright (c) 2009-2020, ARM Limited, All Rights Reserved 00007 * SPDX-License-Identifier: Apache-2.0 00008 * 00009 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00010 * not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00017 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 */ 00021 00022 #ifndef UTIL_H 00023 #define UTIL_H 00024 00025 #include <stdbool.h> 00026 #include <stdint.h> 00027 00028 // Protect commonly-defined macros with ifdefs, to prevent conflicts if redefined 00029 // in imported sources (mostly vendor SDKs). 00030 00031 #if !defined(ARRAY_SIZE) 00032 //! @brief Get number of elements in the array. 00033 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) 00034 #endif 00035 00036 #if !defined(MIN) 00037 #define MIN(a,b) ((a) < (b) ? (a) : (b)) 00038 #endif 00039 00040 #if !defined(MAX) 00041 #define MAX(a,b) ((a) > (b) ? (a) : (b)) 00042 #endif 00043 00044 #define MB(size) ((size) * 1024 * 1024) 00045 00046 #define KB(size) ((size) * 1024) 00047 00048 #define ROUND_UP(value, boundary) ((value) + ((boundary) - (value)) % (boundary)) 00049 00050 #define ROUND_DOWN(value, boundary) ((value) - ((value) % (boundary))) 00051 00052 #ifdef __cplusplus 00053 extern "C" { 00054 #endif 00055 00056 // Write the value to the address specified and return the size 00057 uint32_t util_write_hex8(char *str, uint8_t value); 00058 uint32_t util_write_hex16(char *str, uint16_t value); 00059 uint32_t util_write_hex32(char *str, uint32_t value); 00060 uint32_t util_write_uint32(char *str, uint32_t value); 00061 uint32_t util_write_uint32(char *str, uint32_t value); 00062 uint32_t util_write_uint32_zp(char *str, uint32_t value, uint16_t total_size); 00063 uint32_t util_write_string(char *str, const char *data); 00064 00065 uint32_t util_div_round_up(uint32_t dividen, uint32_t divisor); 00066 uint32_t util_div_round_down(uint32_t dividen, uint32_t divisor); 00067 uint32_t util_div_round(uint32_t dividen, uint32_t divisor); 00068 00069 #if !(defined(DAPLINK_NO_ASSERT_FILENAMES) && defined(DAPLINK_BL)) 00070 // With the filename enabled. 00071 #define util_assert(expression) _util_assert((expression), __FILE__, __LINE__) 00072 #else 00073 // Filename disabled to save code size. 00074 #define util_assert(expression) _util_assert((expression), "(file)", __LINE__) 00075 #endif 00076 void _util_assert(bool expression, const char *filename, uint16_t line); 00077 00078 void util_assert_clear(void); 00079 00080 #ifdef __cplusplus 00081 } 00082 #endif 00083 00084 #endif
Generated on Tue Jul 12 2022 15:37:27 by
1.7.2