1 /*
2  * Copyright 2017, NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef __SRTM_MESSAGE_H__
10 #define __SRTM_MESSAGE_H__
11 
12 #include "srtm_defs.h"
13 
14 /*!
15  * @addtogroup srtm
16  * @{
17  */
18 
19 /*******************************************************************************
20  * Definitions
21  ******************************************************************************/
22 /*! @brief Get SRTM major version */
23 #define SRTM_MESSAGE_MAJOR_VERSION(ver) (((uint16_t)((ver)&0xFF00U)) >> 8U)
24 /*! @brief Get SRTM minor version */
25 #define SRTM_MESSAGE_MINOR_VERSION(ver) ((uint16_t)((ver)&0xFFU))
26 
27 /**
28  * @brief SRTM local procedure callback function
29  */
30 typedef void (*srtm_message_proc_cb_t)(srtm_dispatcher_t dispatcher, void *param1, void *param2);
31 
32 /**
33  * @brief SRTM free function pointer
34  */
35 typedef void (*srtm_message_free_t)(srtm_message_t message, void *param);
36 
37 /*******************************************************************************
38  * API
39  ******************************************************************************/
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /*!
45  * @brief Create SRTM local procedure message.
46  *
47  * @param procedure local procedure callback.
48  * @param param1 user parameter 1 for the procedure callback.
49  * @param param2 user parameter 2 for the procedure callback.
50  * @return SRTM request handle, or NULL on failure.
51  */
52 srtm_procedure_t SRTM_Procedure_Create(srtm_message_proc_cb_t procedure, void *param1, void *param2);
53 
54 /*!
55  * @brief Destroy SRTM local procedure message.
56  *
57  * @param procedure SRTM local procedure handle.
58  */
59 void SRTM_Procedure_Destroy(srtm_procedure_t procedure);
60 
61 /*!
62  * @brief Create SRTM raw data message.
63  *
64  * @param channel corresponding SRTM channel the rawdata is from/to.
65  * @param dataLen the raw data length in bytes.
66  * @return SRTM raw data message handle, or NULL on failure.
67  */
68 srtm_rawdata_t SRTM_RawData_Create(srtm_channel_t channel, uint32_t dataLen);
69 
70 /*!
71  * @brief Destroy SRTM raw data message.
72  *
73  * @param procedure SRTM raw data message handle.
74  */
75 void SRTM_RawData_Destroy(srtm_rawdata_t data);
76 
77 /*!
78  * @brief Get SRTM data address of raw data message.
79  *
80  * @param message SRTM raw data message handle.
81  * @return SRTM raw data address.
82  */
83 void *SRTM_RawData_GetData(srtm_rawdata_t data);
84 
85 /*!
86  * @brief Get SRTM data length in bytes of raw data message.
87  *
88  * @param message SRTM raw data message handle.
89  * @return SRTM raw data length in bytes.
90  */
91 uint32_t SRTM_RawData_GetDataLen(srtm_rawdata_t data);
92 
93 /*!
94  * @brief Create SRTM request message.
95  *
96  * @param channel corresponding SRTM channel the request is from/to.
97  * @param category SRTM application protocol category.
98  * @param version SRTM application protocol version for the category.
99  * @param command SRTM application protocol command for the category.
100  * @param payloadLen SRTM application protocol payload.
101  * @return SRTM request handle, or NULL on failure.
102  */
103 srtm_request_t SRTM_Request_Create(
104     srtm_channel_t channel, uint8_t category, uint16_t version, uint8_t command, uint16_t payloadLen);
105 
106 /*!
107  * @brief Destroy SRTM request message.
108  *
109  * @param request SRTM request handle.
110  */
111 void SRTM_Request_Destroy(srtm_request_t request);
112 
113 /*!
114  * @brief Get request error code.
115  *
116  * Used in asynchronous request with callback response to indicate the request status.
117  *
118  * @param request SRTM request handle.
119  * @return Error code for the request.
120  */
121 srtm_status_t SRTM_Request_GetErrorCode(srtm_request_t request);
122 
123 /*!
124  * @brief Create SRTM response message.
125  *
126  * @param channel corresponding SRTM channel the response is from/to.
127  * @param category SRTM application protocol category.
128  * @param version SRTM application protocol version for the category.
129  * @param command SRTM application protocol command for the category.
130  * @param payloadLen SRTM application protocol payload.
131  * @return SRTM response handle, or NULL on failure.
132  */
133 srtm_response_t SRTM_Response_Create(
134     srtm_channel_t channel, uint8_t category, uint16_t version, uint8_t command, uint16_t payloadLen);
135 
136 /*!
137  * @brief Destroy SRTM response message.
138  *
139  * @param response SRTM response handle.
140  */
141 void SRTM_Response_Destroy(srtm_response_t response);
142 
143 /*!
144  * @brief Create SRTM notification message.
145  *
146  * @param channel corresponding SRTM channel the notification is from/to.
147  * @param category SRTM application protocol category.
148  * @param version SRTM application protocol version for the category.
149  * @param command SRTM application protocol command for the category.
150  * @param payloadLen SRTM application protocol payload length.
151  * @return SRTM notification handle, or NULL on failure.
152  */
153 srtm_notification_t SRTM_Notification_Create(
154     srtm_channel_t channel, uint8_t category, uint16_t version, uint8_t command, uint16_t payloadLen);
155 
156 /*!
157  * @brief Destroy SRTM notification message.
158  *
159  * @param notification SRTM notification handle.
160  */
161 void SRTM_Notification_Destroy(srtm_notification_t notification);
162 
163 /*!
164  * @brief Get SRTM priority of the message.
165  *
166  * @param message SRTM message handle.
167  * @return SRTM priority value.
168  */
169 uint8_t SRTM_Message_GetPriority(srtm_message_t message);
170 
171 /*!
172  * @brief Set SRTM priority of the message.
173  *
174  * @param message SRTM message handle.
175  * @param priority SRTM message priority.
176  */
177 void SRTM_Message_SetPriority(srtm_message_t message, uint8_t priority);
178 
179 /*!
180  * @brief Set SRTM message free function.
181  * This is useful if the application want to reuse messages to avoid heap fragment. For example, user may
182  * create messages and recycle them in a list with this user defined free function.
183  *
184  * @param message SRTM message handle.
185  * @param func SRTM message free function.
186  * @param param SRTM message free parameter.
187  */
188 void SRTM_Message_SetFreeFunc(srtm_message_t message, srtm_message_free_t func, void *param);
189 
190 /*!
191  * @brief Get SRTM category of request/response/notification message.
192  *
193  * @param message SRTM request/response/notification message handle.
194  * @return SRTM category value.
195  */
196 uint8_t SRTM_CommMessage_GetCategory(srtm_message_t message);
197 
198 /*!
199  * @brief Get SRTM version of request/response/notification message.
200  *
201  * @param message SRTM request/response/notification message handle.
202  *
203  * @return SRTM version value. Major version is on MSB byte and minor version is on LSB byte.
204  */
205 uint16_t SRTM_CommMessage_GetVersion(srtm_message_t message);
206 
207 /*!
208  * @brief Get SRTM command of request/response/notification message.
209  *
210  * @param message SRTM request/response/notification message handle.
211  * @return SRTM command value.
212  */
213 uint8_t SRTM_CommMessage_GetCommand(srtm_message_t message);
214 
215 /*!
216  * @brief Get SRTM payload address of request/response/notification message.
217  *
218  * @param message SRTM request/response/notification message handle.
219  * @return SRTM payload address.
220  */
221 uint8_t *SRTM_CommMessage_GetPayload(srtm_message_t message);
222 
223 /*!
224  * @brief Get SRTM payload length of request/response/notification message.
225  *
226  * @param message SRTM request/response/notification message handle.
227  * @return SRTM payload length.
228  */
229 uint32_t SRTM_CommMessage_GetPayloadLen(srtm_message_t message);
230 
231 /*!
232  * @brief Get SRTM message corresponding communication channel.
233  *
234  * @param message SRTM request/response/notification message handle.
235  * @return SRTM communication channel.
236  */
237 srtm_channel_t SRTM_CommMessage_GetChannel(srtm_message_t message);
238 
239 #ifdef __cplusplus
240 }
241 #endif
242 /*! @} */
243 
244 #endif /* __SRTM_MESSAGE_H__ */
245