1 /******************************************************************************
2 * @file  base_types.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 __BASE_TYPES_H__
31 #define __BASE_TYPES_H__
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /*****************************************************************************/
38 /* Include files                                                             */
39 /*****************************************************************************/
40 #include <stddef.h>
41 #include "stdint.h"
42 #include <stdbool.h>
43 #include <string.h>
44 /*****************************************************************************/
45 /* Global pre-processor symbols/macros                                       */
46 /*****************************************************************************/
47 #ifndef TRUE
48 /** Value is true (boolean_t type) */
49 #define TRUE 1
50 #endif
51 
52 #ifndef FALSE
53 /** Value is false (boolean_t type) */
54 #define FALSE 0
55 #endif
56 
57 #ifndef MIN
58 /** Returns the minimum value out of two values */
59 #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
60 #endif
61 #ifndef MAX
62 /** Returns the maximum value out of two values */
63 #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
64 #endif
65 /** Returns the dimension of an array */
66 #define DIM(X) (sizeof(X) / sizeof(X[0]))
67 
68 #ifndef BIT
69 #define BIT(x) ((uint32_t)1U << (x))
70 #endif
71 typedef enum en { Enable = 1, Disable = 0 } en_t;
72 /******************************************************************************
73  * Global type definitions
74  ******************************************************************************/
75 
76 /** logical datatype (only values are TRUE and FALSE) */
77 typedef uint8_t boolean_t;
78 
79 /** single precision floating point number (4 byte) */
80 typedef float float32_t;
81 
82 /** double precision floating point number (8 byte) */
83 typedef double float64_t;
84 
85 /** ASCCI character for string generation (8 bit) */
86 typedef char char_t;
87 
88 /** function pointer type to void/void function */
89 typedef void (*func_ptr_t)(void);
90 
91 /** function pointer type to void/uint8_t function */
92 typedef void (*func_ptr_arg1_t)(uint8_t);
93 
94 #define RSI_DRIVER_VERSION_MAJOR_MINOR(major, minor) (((major) << 8) | (minor))
95 
96 /**
97 \brief Driver Version
98  */
99 typedef struct _RSI_DRIVER_VERSION {
100   uint16_t api; ///< API version
101   uint16_t drv; ///< Driver version
102 } RSI_DRIVER_VERSION_M4;
103 
104 /* General return codes */
105 #define RSI_DRIVER_OK                0  ///< Operation succeeded
106 #define RSI_DRIVER_ERROR             -1 ///< Unspecified error
107 #define RSI_DRIVER_ERROR_BUSY        -2 ///< Driver is busy
108 #define RSI_DRIVER_ERROR_TIMEOUT     -3 ///< Timeout occurred
109 #define RSI_DRIVER_ERROR_UNSUPPORTED -4 ///< Operation not supported
110 #define RSI_DRIVER_ERROR_PARAMETER   -5 ///< Parameter error
111 #define RSI_DRIVER_ERROR_SPECIFIC    -6 ///< Start of driver specific errors
112 
113 #define SET_BIT(n) BIT(n)  //((uint32_t)1 << n)
114 #define CLR_BIT(n) ~BIT(n) //(~((uint32_t)1 << n))
115 
116 #ifndef STATIC
117 #define STATIC static
118 #endif
119 
120 #ifndef INLINE
121 #ifdef __CC_ARM
122 #define INLINE __inline
123 #else
124 #define INLINE inline
125 #endif
126 #endif
127 
128 #define ENABLE  1
129 #define DISABLE 0
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #endif /* __BASE_TYPES_H__ */
136 
137 /******************************************************************************/
138 /* EOF                                                                        */
139 /******************************************************************************/
140