1 /******************************************************************************* 2 * @file rsi_utils.h 3 ******************************************************************************* 4 * # License 5 * <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b> 6 ******************************************************************************* 7 * 8 * SPDX-License-Identifier: Zlib 9 * 10 * The licensor of this software is Silicon Laboratories Inc. 11 * 12 * This software is provided 'as-is', without any express or implied 13 * warranty. In no event will the authors be held liable for any damages 14 * arising from the use of this software. 15 * 16 * Permission is granted to anyone to use this software for any purpose, 17 * including commercial applications, and to alter it and redistribute it 18 * freely, subject to the following restrictions: 19 * 20 * 1. The origin of this software must not be misrepresented; you must not 21 * claim that you wrote the original software. If you use this software 22 * in a product, an acknowledgment in the product documentation would be 23 * appreciated but is not required. 24 * 2. Altered source versions must be plainly marked as such, and must not be 25 * misrepresented as being the original software. 26 * 3. This notice may not be removed or altered from any source distribution. 27 * 28 ******************************************************************************/ 29 30 #ifndef RSI_UTILS_H 31 #define RSI_UTILS_H 32 33 #include <stdint.h> 34 /****************************************************** 35 * * Macros 36 * ******************************************************/ 37 #ifndef BIT 38 #define BIT(a) ((uint32_t)1U << a) 39 #endif 40 41 //#define RSI_MIN(x, y) ((x) > (y) ? (y) : (x)) //This statement is modified to avoid compilation warning 42 #define RSI_MIN(x, y) ((int32_t)(x) > (int32_t)(y) ? (int32_t)(y) : (int32_t)(x)) 43 44 #ifndef NULL 45 #define NULL 0 46 #endif 47 48 /****************************************************** 49 * * Constants 50 * ******************************************************/ 51 /****************************************************** 52 * * Enumerations 53 * ******************************************************/ 54 /****************************************************** 55 * * Type Definitions 56 * ******************************************************/ 57 /****************************************************** 58 * * Structures 59 * ******************************************************/ 60 /****************************************************** 61 * * Global Variables 62 * ******************************************************/ 63 /****************************************************** 64 * * Function Declarations 65 * ******************************************************/ 66 void rsi_uint32_to_4bytes(uint8_t *dBuf, uint32_t val); 67 void rsi_uint16_to_2bytes(uint8_t *dBuf, uint16_t val); 68 uint16_t rsi_bytes2R_to_uint16(const uint8_t *dBuf); 69 uint32_t rsi_bytes4R_to_uint32(const uint8_t *dBuf); 70 uint8_t *rsi_ascii_dev_address_to_6bytes_rev(uint8_t *hex_addr, int8_t *ascii_mac_address); 71 uint8_t *rsi_6byte_dev_address_to_ascii(uint8_t *ascii_mac_address, const uint8_t *hex_addr); 72 uint8_t convert_lower_case_to_upper_case(uint8_t lwrcase); 73 void string2array(uint8_t *dst, const uint8_t *src, uint32_t length); 74 int32_t rsi_atoi(const int8_t *str); 75 void rsi_ascii_dot_address_to_4bytes(uint8_t *hexAddr, int8_t *asciiDotAddress); 76 void rsi_ascii_mac_address_to_6bytes(uint8_t *hexAddr, int8_t *asciiMacAddress); 77 78 int8_t rsi_ascii_hex2num(int8_t ascii_hex_in); 79 int8_t rsi_char_hex2dec(int8_t *cBuf); 80 int8_t hex_to_ascii(uint8_t hex_num); 81 uint8_t *rsi_itoa(uint32_t val, uint8_t *str); 82 int8_t asciihex_2_num(int8_t ascii_hex_in); 83 int8_t rsi_charhex_2_dec(int8_t *cBuf); 84 uint32_t rsi_ntohl(uint32_t a); 85 #endif 86