gdu_platform.h
12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/**
********************************************************************
* @file gdu_platform.h
* @brief This is the header file for "gdu_platform.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2021 GDU. All rights reserved.
*
* All information contained herein is, and remains, the property of GDU.
* The intellectual and technical concepts contained herein are proprietary
* to GDU and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of GDU.
*
* If you receive this source code without GDU’s authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify GDU of its removal. GDU reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef GDU_PLATFORM_H
#define GDU_PLATFORM_H
/* Includes ------------------------------------------------------------------*/
#include "gdu_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/**
* @brief Platform handle of uart operation.
*/
typedef void *T_GduUartHandle;
/**
* @brief Platform handle of usb bulk operation.
*/
typedef void *T_GduUsbBulkHandle;
/**
* @brief Platform handle of network operation.
*/
typedef void *T_GduNetworkHandle;
/**
* @brief Platform handle of thread task operation.
*/
typedef void *T_GduTaskHandle;
/**
* @brief Platform handle of mutex operation.
*/
typedef void *T_GduMutexHandle;
/**
* @brief Platform handle of semaphore operation.
*/
typedef void *T_GduSemaHandle;
/**
* @brief Platform handle of file operation.
*/
typedef void *T_GduFileHandle;
/**
* @brief Platform handle of dir operation.
*/
typedef void *T_GduDirHandle;
/**
* @brief Platform handle of socket operation.
*/
typedef void *T_GduSocketHandle;
typedef enum {
GDU_HAL_UART_NUM_0,
GDU_HAL_UART_NUM_1,
} E_GduHalUartNum;
typedef enum {
GDU_SOCKET_MODE_UDP,
GDU_SOCKET_MODE_TCP,
} E_GduSocketMode;
typedef struct {
bool isConnect;
} T_GduUartStatus;
typedef struct {
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
} T_GduTime;
typedef struct {
uint32_t size;
T_GduTime createTime;
T_GduTime modifyTime;
char path[GDU_FILE_PATH_SIZE_MAX];
bool isDir;
} T_GduFileInfo;
typedef struct {
T_GduReturnCode (*UartInit)(E_GduHalUartNum uartNum, uint32_t baudRate, T_GduUartHandle *uartHandle);
T_GduReturnCode (*UartDeInit)(T_GduUartHandle uartHandle);
T_GduReturnCode (*UartWriteData)(T_GduUartHandle uartHandle, const uint8_t *buf, uint32_t len, uint32_t *realLen);
T_GduReturnCode (*UartReadData)(T_GduUartHandle uartHandle, uint8_t *buf, uint32_t len, uint32_t *realLen);
T_GduReturnCode (*UartGetStatus)(E_GduHalUartNum uartNum, T_GduUartStatus *status);
} T_GduHalUartHandler;
typedef struct {
uint16_t interfaceNum;
uint16_t endPointIn;
uint16_t endPointOut;
} T_GduHalUsbBulkChannelInfo;
typedef struct {
bool isUsbHost;
// attention: if 'isUsbHost' equals false, the following parameters is not valid.
uint16_t pid;
uint16_t vid;
T_GduHalUsbBulkChannelInfo channelInfo;
} T_GduHalUsbBulkInfo;
typedef struct {
uint16_t pid;
uint16_t vid;
uint8_t bulkChannelNum;
T_GduHalUsbBulkChannelInfo *channelInfo;
} T_GduHalUsbBulkDeviceInfo;
typedef struct {
T_GduReturnCode (*UsbBulkInit)(T_GduHalUsbBulkInfo usbBulkInfo, T_GduUsbBulkHandle *usbBulkHandle);
T_GduReturnCode (*UsbBulkDeInit)(T_GduUsbBulkHandle usbBulkHandle);
T_GduReturnCode (*UsbBulkWriteData)(T_GduUsbBulkHandle usbBulkHandle, const uint8_t *buf,
uint32_t len, uint32_t *realLen);
T_GduReturnCode (*UsbBulkReadData)(T_GduUsbBulkHandle usbBulkHandle, uint8_t *buf,
uint32_t len, uint32_t *realLen);
T_GduReturnCode (*UsbBulkGetDeviceInfo)(T_GduHalUsbBulkDeviceInfo *deviceInfo);
} T_GduHalUsbBulkHandler;
typedef struct {
T_GduReturnCode (*NetworkInit)(const char *ipAddr, const char *netMask, T_GduNetworkHandle *networkHandle);
T_GduReturnCode (*NetworkDeInit)(T_GduNetworkHandle networkHandle);
} T_GduHalNetworkHandler;
typedef struct {
T_GduReturnCode (*TaskCreate)(const char *name, void *(*taskFunc)(void *),
uint32_t stackSize, void *arg, T_GduTaskHandle *task);
T_GduReturnCode (*TaskDestroy)(T_GduTaskHandle task);
T_GduReturnCode (*TaskSleepMs)(uint32_t timeMs);
T_GduReturnCode (*MutexCreate)(T_GduMutexHandle *mutex);
T_GduReturnCode (*MutexDestroy)(T_GduMutexHandle mutex);
T_GduReturnCode (*MutexLock)(T_GduMutexHandle mutex);
T_GduReturnCode (*MutexUnlock)(T_GduMutexHandle mutex);
T_GduReturnCode (*SemaphoreCreate)(uint32_t initValue, T_GduSemaHandle *semaphore);
T_GduReturnCode (*SemaphoreDestroy)(T_GduSemaHandle semaphore);
T_GduReturnCode (*SemaphoreWait)(T_GduSemaHandle semaphore);
T_GduReturnCode (*SemaphoreTimedWait)(T_GduSemaHandle semaphore, uint32_t waitTimeMs);
T_GduReturnCode (*SemaphorePost)(T_GduSemaHandle semaphore);
T_GduReturnCode (*GetTimeMs)(uint32_t *ms);
T_GduReturnCode (*GetTimeUs)(uint64_t *us);
T_GduReturnCode (*GetIPAddr)(uint8_t *addr);
void *(*Malloc)(uint32_t size);
void (*Free)(void *ptr);
} T_GduOsalHandler;
typedef struct {
T_GduReturnCode (*FileOpen)(const char *fileName, const char *fileMode, T_GduFileHandle *fileObj);
T_GduReturnCode (*FileClose)(T_GduFileHandle fileObj);
T_GduReturnCode (*FileWrite)(T_GduFileHandle fileObj, const uint8_t *buf, uint32_t len, uint32_t *realLen);
T_GduReturnCode (*FileRead)(T_GduFileHandle fileObj, uint8_t *buf, uint32_t len, uint32_t *realLen);
T_GduReturnCode (*FileSeek)(T_GduFileHandle fileObj, uint32_t offset);
T_GduReturnCode (*FileSync)(T_GduFileHandle fileObj);
T_GduReturnCode (*DirOpen)(const char *filePath, T_GduDirHandle *dirObj);
T_GduReturnCode (*DirClose)(T_GduDirHandle dirObj);
T_GduReturnCode (*DirRead)(T_GduDirHandle dirObj, T_GduFileInfo *fileInfo);
T_GduReturnCode (*Mkdir)(const char *filePath);
T_GduReturnCode (*Unlink)(const char *filePath);
T_GduReturnCode (*Rename)(const char *oldFilePath, const char *newFilePath);
T_GduReturnCode (*Stat)(const char *filePath, T_GduFileInfo *fileInfo);
} T_GduFileSystemHandler;
typedef struct {
T_GduReturnCode (*Socket)(E_GduSocketMode mode, T_GduSocketHandle *socketHandle);
T_GduReturnCode (*Close)(T_GduSocketHandle socketHandle);
T_GduReturnCode (*Bind)(T_GduSocketHandle socketHandle, const char *ipAddr, uint32_t port);
T_GduReturnCode (*UdpSendData)(T_GduSocketHandle socketHandle, const char *ipAddr, uint32_t port,
const uint8_t *buf, uint32_t len, uint32_t *realLen);
T_GduReturnCode (*UdpRecvData)(T_GduSocketHandle socketHandle, char *ipAddr, uint32_t *port,
uint8_t *buf, uint32_t len, uint32_t *realLen);
T_GduReturnCode (*TcpListen)(T_GduSocketHandle socketHandle);
T_GduReturnCode (*TcpAccept)(T_GduSocketHandle socketHandle, char *ipAddr, uint32_t *port,
T_GduSocketHandle *outSocketHandle);
T_GduReturnCode (*TcpConnect)(T_GduSocketHandle socketHandle, const char *ipAddr, uint32_t port);
T_GduReturnCode (*TcpSendData)(T_GduSocketHandle socketHandle,
const uint8_t *buf, uint32_t len, uint32_t *realLen);
T_GduReturnCode (*TcpRecvData)(T_GduSocketHandle socketHandle,
uint8_t *buf, uint32_t len, uint32_t *realLen);
} T_GduSocketHandler;
/* Exported functions --------------------------------------------------------*/
/**
* @brief Register the handler for hal uart interfaces by your platform.
* @note It should be noted that the interface in hal is written and tested well. Users need to implement all the
* interfaces. Otherwise, the user interface cannot be successfully registered, and then the user interface is registered
* through the interface. If the registration fails, it needs to be based on the return code. To judge the problem. Make
* sure that the feature is available after a successful registration. The interface needs to be called at the beginning of
* the application for registration, otherwise, the subsequent functions will not work properly.
* @param halUartHandler: pointer to the handler for hal uart interfaces by your platform.
* @return Execution result.
*/
T_GduReturnCode GduPlatform_RegHalUartHandler(const T_GduHalUartHandler *halUartHandler);
/**
* @brief Register the handler for usb bulk interfaces by your platform.
* @param fileSystemHandler: pointer to the handler for usb bulk interfaces by your platform.
* @return Execution result.
*/
T_GduReturnCode GduPlatform_RegHalUsbBulkHandler(const T_GduHalUsbBulkHandler *halUsbBulkHandler);
/**
* @brief Register the handler for hal network interfaces by your platform.
* @note It should be noted that the interface in hal is written and tested well. Users need to implement all the
* interfaces. Otherwise, the user interface cannot be successfully registered, and then the user interface is registered
* through the interface. If the registration fails, it needs to be based on the return code. To judge the problem. Make
* sure that the feature is available after a successful registration.
* @attention The interface needs to be called at the beginning of the application for registration, otherwise, the
* subsequent functions will not work properly.
* @param osalHandler: pointer to the handler for network handler interfaces by your platform.
* @return Execution result.
*/
T_GduReturnCode GduPlatform_RegHalNetworkHandler(const T_GduHalNetworkHandler *halNetworkHandler);
/**
* @brief Register the handler for osal interfaces by your platform.
* @note It should be noted that the interface in osal is written and tested well. Users need to implement all the
* interfaces. Otherwise, the user interface cannot be successfully registered, and then the user interface is registered
* through the interface. If the registration fails, it needs to be based on the return code. To judge the problem. Make
* sure that the feature is available after a successful registration. The interface needs to be called at the beginning of
* the application for registration, otherwise, the subsequent functions will not work properly.
* @param osalHandler: pointer to the handler for osal interfaces by your platform.
* @return Execution result.
*/
T_GduReturnCode GduPlatform_RegOsalHandler(const T_GduOsalHandler *osalHandler);
/**
* @brief Register the handler for file-system interfaces by your platform.
* @param fileSystemHandler: pointer to the handler for file-system interfaces by your platform.
* @return Execution result.
*/
T_GduReturnCode GduPlatform_RegFileSystemHandler(const T_GduFileSystemHandler *fileSystemHandler);
/**
* @brief Register the handler for socket interfaces by your platform.
* @param fileSystemHandler: pointer to the handler for socket interfaces by your platform.
* @return Execution result.
*/
T_GduReturnCode GduPlatform_RegSocketHandler(const T_GduSocketHandler *socketHandler);
/**
* @brief Get the handler of osal interfaces.
* @return Execution result.
*/
T_GduOsalHandler *GduPlatform_GetOsalHandler(void);
/**
* @brief Get the handler of file-system interfaces.
* @return Execution result.
*/
T_GduFileSystemHandler *GduPlatform_GetFileSystemHandler(void);
/**
* @brief Get the handler of socket interfaces.
* @return Execution result.
*/
T_GduSocketHandler *GduPlatform_GetSocketHandler(void);
#ifdef __cplusplus
}
#endif
#endif // GDU_PLATFORM_H
/************************ (C) COPYRIGHT GDU Innovations *******END OF FILE******/