DJI Onboard SDK  4.0
osdk_platform.h
Go to the documentation of this file.
1 
27 /* Define to prevent recursive inclusion -------------------------------------*/
28 #ifndef OSDK_PLATFORM_H
29 #define OSDK_PLATFORM_H
30 
31 /* Includes ------------------------------------------------------------------*/
32 #ifdef __linux__
33 #include <sys/socket.h>
34 #include <netinet/in.h>
35 #include <arpa/inet.h>
36 #endif
37 #include "osdk_typedef.h"
38 
39 #define OSDK_TASK_STACK_SIZE_DEFAULT 1024
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 //#define OS_DEBUG
46 
47 /* Exported constants --------------------------------------------------------*/
51 typedef void *T_OsdkTaskHandle;
55 typedef void *T_OsdkMutexHandle;
59 typedef void *T_OsdkSemHandle;
60 
61 typedef struct {
62  int fd;
63 }T_UartObj;
64 
65 #ifdef __linux__
66 typedef struct {
67  void* handle;
68  uint16_t epIn;
69  uint16_t epOut;
70 }T_UsbBulkObj;
71 #endif
72 
73 typedef struct {
74  union {
75  T_UartObj uartObject;
76 #ifdef __linux__
77  T_UsbBulkObj bulkObject;
78 #endif
79  };
80 }T_HalObj;
81 
82 /* Exported types ------------------------------------------------------------*/
83 typedef struct {
87  E_OsdkStat (*UartInit)(const char *port, const int baudrate, T_HalObj *obj);
88 
92  E_OsdkStat (*UartWriteData)(const T_HalObj *obj, const uint8_t *pBuf, uint32_t bufLen);
93 
97  E_OsdkStat (*UartReadData)(const T_HalObj *obj, uint8_t *pBuf, uint32_t *bufLen);
98 
102  E_OsdkStat (*UartClose)(T_HalObj *obj);
103 } T_OsdkHalUartHandler;
104 
105 #ifdef __linux__
106 typedef struct {
110  E_OsdkStat (*USBBulkInit)(uint16_t pid, uint16_t vid, uint16_t num, uint16_t epIn, uint16_t epOut, T_HalObj *obj);
111 
115  E_OsdkStat (*USBBulkWriteData)(const T_HalObj *obj, const uint8_t *pBuf, uint32_t bufLen);
116 
120  E_OsdkStat (*USBBulkReadData)(const T_HalObj *obj, uint8_t *pBuf, uint32_t *bufLen);
121 
125  E_OsdkStat (*USBBulkClose)(T_HalObj *obj);
126 } T_OsdkHalUSBBulkHandler;
127 #endif
128 
129 typedef struct {
134  E_OsdkStat (*TaskCreate)(T_OsdkTaskHandle *task, void *(*taskFunc)(void *), uint32_t stackSize, void *arg);
135 
140  E_OsdkStat (*TaskDestroy)(T_OsdkTaskHandle task);
141 
146  E_OsdkStat (*TaskSleepMs)(uint32_t timeMs);
147 
152  E_OsdkStat (*MutexCreate)(T_OsdkMutexHandle *mutex);
153 
158  E_OsdkStat (*MutexDestroy)(T_OsdkMutexHandle mutex);
159 
164  E_OsdkStat (*MutexLock)(T_OsdkMutexHandle mutex);
165 
170  E_OsdkStat (*MutexUnlock)(T_OsdkMutexHandle mutex);
171 
176  E_OsdkStat (*SemaphoreCreate)(T_OsdkSemHandle *semaphore, uint32_t initValue);
177 
182  E_OsdkStat (*SemaphoreDestroy)(T_OsdkSemHandle semaphore);
183 
188  E_OsdkStat (*SemaphoreWait)(T_OsdkSemHandle semaphore);
189 
194  E_OsdkStat (*SemaphoreTimedWait)(T_OsdkSemHandle semaphore, uint32_t waitTimeMs);
195 
200  E_OsdkStat (*SemaphorePost)(T_OsdkSemHandle semaphore);
201 
206  E_OsdkStat (*GetTimeMs)(uint32_t *ms);
207 
208 #ifdef OS_DEBUG
209  E_OsdkStat (*GetTimeUs)(uint64_t *us);
210 #endif
211 
216  void *(*Malloc)(uint32_t size);
217 
222  void (*Free)(void *ptr);
223 } T_OsdkOsalHandler;
224 
225 /* Exported functions --------------------------------------------------------*/
236 E_OsdkStat OsdkPlatform_RegHalUartHandler(const T_OsdkHalUartHandler *halUartHandler);
237 
238 #ifdef __linux__
239 
249 E_OsdkStat OsdkPlatform_RegHalUSBBulkHandler(const T_OsdkHalUSBBulkHandler *halUSBBulkHandler);
250 #endif
251 
262 E_OsdkStat OsdkPlatform_RegOsalHandler(const T_OsdkOsalHandler *osalHandler);
263 
272 E_OsdkStat OsdkOsal_TaskCreate(T_OsdkTaskHandle *task, void *(*taskFunc)(void *),
273  uint32_t stackSize, void *arg);
274 
280 E_OsdkStat OsdkOsal_TaskDestroy(T_OsdkTaskHandle task);
281 
287 E_OsdkStat OsdkOsal_TaskSleepMs(uint32_t timeMs);
288 
294 E_OsdkStat OsdkOsal_MutexCreate(T_OsdkMutexHandle *mutex);
295 
301 E_OsdkStat OsdkOsal_MutexDestroy(T_OsdkMutexHandle mutex);
302 
308 E_OsdkStat OsdkOsal_MutexLock(T_OsdkMutexHandle mutex);
309 
315 E_OsdkStat OsdkOsal_MutexUnlock(T_OsdkMutexHandle mutex);
316 
322 E_OsdkStat OsdkOsal_SemaphoreCreate(T_OsdkSemHandle *semaphore, uint32_t initValue);
323 
329 E_OsdkStat OsdkOsal_SemaphoreDestroy(T_OsdkSemHandle semaphore);
330 
336 E_OsdkStat OsdkOsal_SemaphoreWait(T_OsdkSemHandle semaphore);
337 
344 E_OsdkStat OsdkOsal_SemaphoreTimedWait(T_OsdkSemHandle semaphore, uint32_t waitTimeMs);
345 
351 E_OsdkStat OsdkOsal_SemaphorePost(T_OsdkSemHandle semaphore);
352 
358 E_OsdkStat OsdkOsal_GetTimeMs(uint32_t *ms);
359 
365 #ifdef OS_DEBUG
366 E_OsdkStat OsdkOsal_GetTimeUs(uint64_t *us);
367 #endif
368 
376 void *OsdkOsal_Malloc(uint32_t size);
377 
384 void OsdkOsal_Free(void *ptr);
385 
386 #ifdef __cplusplus
387 }
388 #endif
389 
390 #endif // OSDK_PLATFORM_H
391 /************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/
E_OsdkStat OsdkOsal_SemaphoreDestroy(T_OsdkSemHandle semaphore)
Destroy the created semaphore.
E_OsdkStat OsdkOsal_TaskSleepMs(uint32_t timeMs)
Let task into a sleep state in a set time, uint:ms.
E_OsdkStat OsdkPlatform_RegHalUartHandler(const T_OsdkHalUartHandler *halUartHandler)
Register the handler for hal uart interfaces by your platform.
E_OsdkStat OsdkOsal_TaskDestroy(T_OsdkTaskHandle task)
Destroy the created task.
void * T_OsdkTaskHandle
Platform handle of thread task operation.
Definition: osdk_platform.h:51
E_OsdkStat OsdkPlatform_RegOsalHandler(const T_OsdkOsalHandler *osalHandler)
Register the handler for osal interfaces by your platform.
void OsdkOsal_Free(void *ptr)
Release allocated memory.
void * T_OsdkMutexHandle
Platform handle of mutex operation.
Definition: osdk_platform.h:55
E_OsdkStat OsdkOsal_SemaphoreCreate(T_OsdkSemHandle *semaphore, uint32_t initValue)
Declare the semaphore container, initialize the semaphore, and create semaphore ID.
E_OsdkStat OsdkOsal_TaskCreate(T_OsdkTaskHandle *task, void *(*taskFunc)(void *), uint32_t stackSize, void *arg)
Declare the task container, initialize the task, and create task ID.
E_OsdkStat OsdkOsal_MutexCreate(T_OsdkMutexHandle *mutex)
Declare the mutex container, initialize the mutex, and create mutex ID.
E_OsdkStat OsdkOsal_MutexLock(T_OsdkMutexHandle mutex)
Acquire and lock the mutex when peripheral access is required.
E_OsdkStat OsdkOsal_SemaphorePost(T_OsdkSemHandle semaphore)
Post the created semaphore.
void * T_OsdkSemHandle
Platform handle of semaphore operation.
Definition: osdk_platform.h:59
void * OsdkOsal_Malloc(uint32_t size)
Get the system time, uint:us.
E_OsdkStat OsdkOsal_GetTimeMs(uint32_t *ms)
Get the system millisecond time, uint:ms.
E_OsdkStat OsdkOsal_SemaphoreTimedWait(T_OsdkSemHandle semaphore, uint32_t waitTimeMs)
Wait the created semaphore and set the value of timeout.
E_OsdkStat OsdkOsal_SemaphoreWait(T_OsdkSemHandle semaphore)
Wait the created semaphore forever.
E_OsdkStat OsdkOsal_MutexUnlock(T_OsdkMutexHandle mutex)
Unlock and release the mutex, when done with the peripheral access.
E_OsdkStat OsdkOsal_MutexDestroy(T_OsdkMutexHandle mutex)
Destroy the created mutex.