xref: /btstack/chipset/sx128x/SMTC_Drivers/utilities.h (revision cb5466b0821ff1cc151be285948f59ccf7756451)
1 /*!
2  * \file      utilities.h
3  *
4  * \brief     Helper functions implementation
5  *
6  * \copyright Revised BSD License, see section \ref LICENSE.
7  *
8  * \code
9  *                ______                              _
10  *               / _____)             _              | |
11  *              ( (____  _____ ____ _| |_ _____  ____| |__
12  *               \____ \| ___ |    (_   _) ___ |/ ___)  _ \
13  *               _____) ) ____| | | || |_| ____( (___| | | |
14  *              (______/|_____)_|_|_| \__)_____)\____)_| |_|
15  *              (C)2013-2017 Semtech
16  *
17  * \endcode
18  *
19  * \author    Miguel Luis ( Semtech )
20  *
21  * \author    Gregory Cristian ( Semtech )
22  */
23 #ifndef __UTILITIES_H__
24 #define __UTILITIES_H__
25 
26 #include <stdint.h>
27 
28 /*!
29  * Generic definition
30  */
31 #ifndef SUCCESS
32 #define SUCCESS                                     1
33 #endif
34 
35 #ifndef FAIL
36 #define FAIL                                        0
37 #endif
38 
39 /*!
40  * \brief Returns the minimum value between a and b
41  *
42  * \param [IN] a 1st value
43  * \param [IN] b 2nd value
44  * \retval minValue Minimum value
45  */
46 #define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
47 
48 /*!
49  * \brief Returns the maximum value between a and b
50  *
51  * \param [IN] a 1st value
52  * \param [IN] b 2nd value
53  * \retval maxValue Maximum value
54  */
55 #define MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
56 
57 /*!
58  * \brief Returns 2 raised to the power of n
59  *
60  * \param [IN] n power value
61  * \retval result of raising 2 to the power n
62  */
63 #define POW2( n ) ( 1 << n )
64 
65 /*!
66  * \brief Initializes the pseudo random generator initial value
67  *
68  * \param [IN] seed Pseudo random generator initial value
69  */
70 void srand1( uint32_t seed );
71 
72 /*!
73  * \brief Computes a random number between min and max
74  *
75  * \param [IN] min range minimum value
76  * \param [IN] max range maximum value
77  * \retval random random value in range min..max
78  */
79 int32_t randr( int32_t min, int32_t max );
80 
81 /*!
82  * \brief Copies size elements of src array to dst array
83  *
84  * \remark STM32 Standard memcpy function only works on pointers that are aligned
85  *
86  * \param [OUT] dst  Destination array
87  * \param [IN]  src  Source array
88  * \param [IN]  size Number of bytes to be copied
89  */
90 void memcpy1( uint8_t *dst, const uint8_t *src, uint16_t size );
91 
92 /*!
93  * \brief Copies size elements of src array to dst array reversing the byte order
94  *
95  * \param [OUT] dst  Destination array
96  * \param [IN]  src  Source array
97  * \param [IN]  size Number of bytes to be copied
98  */
99 void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size );
100 
101 /*!
102  * \brief Set size elements of dst array with value
103  *
104  * \remark STM32 Standard memset function only works on pointers that are aligned
105  *
106  * \param [OUT] dst   Destination array
107  * \param [IN]  value Default value
108  * \param [IN]  size  Number of bytes to be copied
109  */
110 void memset1( uint8_t *dst, uint8_t value, uint16_t size );
111 
112 /*!
113  * \brief Converts a nibble to an hexadecimal character
114  *
115  * \param [IN] a   Nibble to be converted
116  * \retval hexChar Converted hexadecimal character
117  */
118 int8_t Nibble2HexChar( uint8_t a );
119 
120 #endif // __UTILITIES_H__
121