1 /*
2  * Copyright 2017, NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef __SRTM_DEFS_H__
10 #define __SRTM_DEFS_H__
11 
12 #include "srtm_config.h"
13 #include <assert.h>
14 #include <stdbool.h>
15 #include <stdint.h>
16 
17 /*!
18  * @addtogroup srtm
19  * @{
20  */
21 
22 /*******************************************************************************
23  * Definitions
24  ******************************************************************************/
25 /*! @brief Defines SRTM major version */
26 #define SRTM_VERSION_MAJOR (0x01UL)
27 /*! @brief Defines SRTM minor version */
28 #define SRTM_VERSION_MINOR (0x01UL)
29 /*! @brief Defines SRTM bugfix version */
30 #define SRTM_VERSION_BUGFIX (0x00UL)
31 
32 /*! @brief SRTM version definition */
33 #define SRTM_MAKE_VERSION(major, minor, bugfix) ((((uint32_t)major) << 16) | (((uint32_t)minor) << 8) | (bugfix))
34 
35 /*! Define static api calls as disabled, if no other option is present. */
36 #ifndef SRTM_STATIC_API
37 #define SRTM_STATIC_API 0
38 #endif
39 
40 /* IAR ARM build tools */
41 #if defined(__ICCARM__)
42 
43 #include <intrinsics.h>
44 
45 #ifndef SRTM_PACKED_BEGIN
46 #define SRTM_PACKED_BEGIN __packed
47 #endif
48 
49 #ifndef SRTM_PACKED_END
50 #define SRTM_PACKED_END
51 #endif
52 
53 #ifndef SRTM_ANON_DEC_BEGIN
54 #define SRTM_ANON_DEC_BEGIN _Pragma("language=extended")
55 #endif
56 
57 #ifndef SRTM_ANON_DEC_END
58 #define SRTM_ANON_DEC_END _Pragma("language=default")
59 #endif
60 
61 /* GNUC */
62 #elif defined(__GNUC__)
63 
64 #ifndef SRTM_PACKED_BEGIN
65 #define SRTM_PACKED_BEGIN
66 #endif
67 
68 #ifndef SRTM_PACKED_END
69 #define SRTM_PACKED_END __attribute__((__packed__))
70 #endif
71 
72 /* anonymous unions are enabled by default */
73 #ifndef SRTM_ANON_DEC_BEGIN
74 #define SRTM_ANON_DEC_BEGIN
75 #endif
76 
77 #ifndef SRTM_ANON_DEC_END
78 #define SRTM_ANON_DEC_END
79 #endif
80 
81 /* ARMCC */
82 #elif defined(__CC_ARM) || defined(__ARMCC_VERSION)
83 
84 #ifndef SRTM_PACKED_BEGIN
85 #define SRTM_PACKED_BEGIN _Pragma("pack(1U)")
86 #endif
87 
88 #ifndef SRTM_PACKED_END
89 #define SRTM_PACKED_END _Pragma("pack()")
90 #endif
91 
92 #ifndef SRTM_ANON_DEC_BEGIN
93 #define SRTM_ANON_DEC_BEGIN _Pragma("push") _Pragma("anon_unions")
94 #endif
95 
96 #ifndef SRTM_ANON_DEC_END
97 #define SRTM_ANON_DEC_END _Pragma("pop")
98 #endif
99 
100 #else
101 /* There is no default definition here to avoid wrong structures packing in case of not supported compiler */
102 #error Please implement the structure packing macros for your compiler here!
103 #endif
104 
105 /*! @brief Defines SRTM debug message function. If user want to debug SRTM, he should define
106     SRTM_DEBUG_MESSAGE_FUNC to proper printf function, as well as define
107     SRTM_DEBUG_VERBOSE_LEVEL to intended verbose level. */
108 #ifdef SRTM_DEBUG_MESSAGE_FUNC
109 extern int SRTM_DEBUG_MESSAGE_FUNC(const char *fmt_s, ...);
110 
111 #ifndef SRTM_DEBUG_VERBOSE_LEVEL
112 #define SRTM_DEBUG_VERBOSE_LEVEL SRTM_DEBUG_VERBOSE_WARN
113 #endif
114 
115 #define SRTM_DEBUG_MESSAGE(verbose, ...)                \
116     do                                                  \
117     {                                                   \
118         if ((verbose) <= SRTM_DEBUG_VERBOSE_LEVEL)      \
119         {                                               \
120             (void)SRTM_DEBUG_MESSAGE_FUNC(__VA_ARGS__); \
121         }                                               \
122     } while ((bool)false)
123 #else
124 #define SRTM_DEBUG_MESSAGE(verbose, format, ...)
125 #endif
126 
127 /*! @brief SRTM debug message verbose definition */
128 #define SRTM_DEBUG_VERBOSE_NONE  (0U)
129 #define SRTM_DEBUG_VERBOSE_ERROR (1U)
130 #define SRTM_DEBUG_VERBOSE_WARN  (2U)
131 #define SRTM_DEBUG_VERBOSE_INFO  (3U)
132 #define SRTM_DEBUG_VERBOSE_DEBUG (4U)
133 
134 /**
135  * @brief Timeout definition: infinite wait that never timeout
136  */
137 #define SRTM_WAIT_FOR_EVER (0xFFFFFFFFU)
138 
139 /**
140  * @brief Timeout definition: no wait that return immediately
141  */
142 #define SRTM_NO_WAIT (0x0U)
143 
144 /*! @brief SRTM error code */
145 typedef enum _srtm_status
146 {
147     SRTM_Status_Success = 0x00U, /*!< Success */
148     SRTM_Status_Error,           /*!< Failed */
149 
150     SRTM_Status_InvalidParameter, /*!< Invalid parameter */
151     SRTM_Status_InvalidMessage,   /*!< Invalid message */
152     SRTM_Status_InvalidState,     /*!< Operate in invalid state */
153     SRTM_Status_OutOfMemory,      /*!< Memory allocation failed */
154     SRTM_Status_Timeout,          /*!< Timeout when waiting for an event */
155     SRTM_Status_ListAddFailed,    /*!< Cannot add to list as node already in another list */
156     SRTM_Status_ListRemoveFailed, /*!< Cannot remove from list as node not in list */
157 
158     SRTM_Status_TransferTimeout,  /*!< Transfer timeout */
159     SRTM_Status_TransferNotAvail, /*!< Transfer failed due to peer core not ready */
160     SRTM_Status_TransferFailed,   /*!< Transfer failed due to communication failure */
161 
162     SRTM_Status_ServiceNotFound,    /*!< Cannot find service for a request/notification */
163     SRTM_Status_ServiceVerMismatch, /*!< Service version cannot support the request/notification */
164 } srtm_status_t;
165 
166 /**
167  * @brief SRTM message is a pointer to the SRTM message instance
168  */
169 typedef struct _srtm_message *srtm_message_t;
170 
171 /**
172  * @brief SRTM request is a pointer to the SRTM request message
173  */
174 typedef srtm_message_t srtm_request_t;
175 
176 /**
177  * @brief SRTM response is a pointer to the SRTM response message
178  */
179 typedef srtm_message_t srtm_response_t;
180 
181 /**
182  * @brief SRTM notification is a pointer to the SRTM notification message
183  */
184 typedef srtm_message_t srtm_notification_t;
185 
186 /**
187  * @brief SRTM procedure is a pointer to the SRTM local procedure message
188  */
189 typedef srtm_message_t srtm_procedure_t;
190 
191 /**
192  * @brief SRTM rawdata is a pointer to the SRTM raw data message
193  */
194 typedef srtm_message_t srtm_rawdata_t;
195 
196 /**
197  * @brief SRTM dispatcher is a pointer to the SRTM dispatcher instance
198  */
199 typedef struct _srtm_dispatcher *srtm_dispatcher_t;
200 
201 /**
202  * @brief SRTM peer core handle is a pointer to the SRTM peer core instance
203  */
204 typedef struct _srtm_peercore *srtm_peercore_t;
205 
206 /**
207  * @brief SRTM channel handle is a pointer to the SRTM channel instance
208  */
209 typedef struct _srtm_channel *srtm_channel_t;
210 
211 /**
212  * @brief SRTM service handle is a pointer to the SRTM service instance
213  */
214 typedef struct _srtm_service *srtm_service_t;
215 
216 /**
217  * @brief SRTM version fields
218  */
219 typedef struct _srtm_version
220 {
221     uint8_t major;  /*!< Major */
222     uint8_t minor;  /*!< Minor */
223     uint8_t bugfix; /*!< Bug fix */
224 } srtm_version_t;
225 
226 /*******************************************************************************
227  * API
228  ******************************************************************************/
229 /*!
230  * @brief Get SRTM version.
231  *
232  * @return SRTM version.
233  */
SRTM_GetVersion(void)234 static inline uint32_t SRTM_GetVersion(void)
235 {
236     return SRTM_MAKE_VERSION(SRTM_VERSION_MAJOR, SRTM_VERSION_MINOR, SRTM_VERSION_BUGFIX);
237 }
238 
239 /*! @} */
240 
241 #endif /* __SRTM_DEFS_H__ */
242