DJI Onboard SDK  4.0
dji_platform.hpp
Go to the documentation of this file.
1 
30 #ifndef OSDK_DJI_PLATFORM_H_
31 #define OSDK_DJI_PLATFORM_H_
32 
33 #include "osdk_platform.h"
34 #include "dji_singleton.hpp"
35 #include "osdk_logger.h"
36 
37 #define DJI_REG_UART_HANDLER(handlerPtr) \
38  DJI::OSDK::Platform::instance() \
39  .registerHalUartHandler(handlerPtr)
40 
41 #ifdef __linux__
42 #define DJI_REG_USB_BULK_HANDLER(handlerPtr) \
43  DJI::OSDK::Platform::instance() \
44  .registerHalUSBBulkHandler(handlerPtr)
45 #endif
46 
47 #define DJI_REG_OSAL_HANDLER(handlerPtr) \
48  DJI::OSDK::Platform::instance() \
49  .registerOsalHandler(handlerPtr)
50 
51 #define DJI_REG_LOGGER_CONSOLE(consolePtr) \
52  DJI::OSDK::Platform::instance() \
53  .registerLoggerConsole(consolePtr)
54 
55 #define DJI_TASK_CREATE(taskPtr, taskFunc, stackSize, arg) \
56  DJI::OSDK::Platform::instance() \
57  .taskCreate(taskPtr, taskFunc, stackSize, arg)
58 
59 #define DJI_TASK_DESTROY(task) \
60  DJI::OSDK::Platform::instance() \
61  .taskDestroy(task)
62 
63 #define DJI_TASK_SLEEP_MS(timeMs) \
64  DJI::OSDK::Platform::instance() \
65  .taskSleepMs(timeMs)
66 
67 #define DJI_MUTEX_CREATE(mutexPtr) \
68  DJI::OSDK::Platform::instance() \
69  .mutexCreate(mutexPtr)
70 
71 #define DJI_MUTEX_DESTROY(mutex) \
72  DJI::OSDK::Platform::instance() \
73  .mutexDestroy(mutex)
74 
75 #define DJI_MUTEX_LOCK(mutex) \
76  DJI::OSDK::Platform::instance() \
77  .mutexLock(mutex)
78 
79 #define DJI_MUTEX_UNLOCK(mutex) \
80  DJI::OSDK::Platform::instance() \
81  .mutexUnlock(mutex)
82 
83 #define DJI_SEM_CREATE(semPtr, initValue) \
84  DJI::OSDK::Platform::instance() \
85  .semaphoreCreate(mutexPtr, initValue)
86 
87 #define DJI_SEM_DESTROY(sem) \
88  DJI::OSDK::Platform::instance() \
89  .semaphoreDestroy(sem)
90 
91 #define DJI_SEM_POST(sem) \
92  DJI::OSDK::Platform::instance() \
93  .semaphorePost(sem)
94 
95 #define DJI_SEM_WAIT(sem) \
96  DJI::OSDK::Platform::instance() \
97  .semaphoreWait(sem)
98 
99 #define DJI_SEM_TIMED_WAIT(sem, waitTime) \
100  DJI::OSDK::Platform::instance() \
101  .semaphoreTimedWait(sem, waitTime)
102 
103 #define DJI_MEM_MALLOC(size) \
104  DJI::OSDK::Platform::instance() \
105  .malloc(size)
106 
107 #define DJI_MEM_FREE(ptr) \
108  DJI::OSDK::Platform::instance() \
109  .free(ptr)
110 
111 #define DJI_GET_TIME_MS(msPtr) \
112  DJI::OSDK::Platform::instance() \
113  .getTimeMs(msPtr)
114 
115 #ifdef OS_DEBUG
116 #define DJI_GET_TIME_US(usPtr) \
117  DJI::OSDK::Platform::instance() \
118  .getTimeUs(usPtr)
119 #endif
120 
121 namespace DJI
122 {
123 namespace OSDK
124 {
125 
126 class Platform : public Singleton<Platform>
127 {
128 public:
129  Platform();
130  ~Platform();
131 
132  bool isOsalReady();
133 
134  bool isHalUartReady();
135 
136  bool isLoggerReady();
137 
138  bool registerHalUartHandler(const T_OsdkHalUartHandler *halUartHandler);
139 
140 #ifdef __linux__
141  bool registerHalUSBBulkHandler(const T_OsdkHalUSBBulkHandler *halUSBBulkHandler);
142 #endif
143 
144  bool registerOsalHandler(const T_OsdkOsalHandler *osalHandler);
145 
146  bool registerLoggerConsole(T_OsdkLoggerConsole *console);
147 
148  bool taskCreate(T_OsdkTaskHandle *task, void *(*taskFunc)(void *), uint32_t stackSize, void *arg);
149 
150  bool taskDestroy(T_OsdkTaskHandle task);
151 
152  bool taskSleepMs(uint32_t timeMs);
153 
154  bool mutexCreate(T_OsdkMutexHandle *mutex);
155 
156  bool mutexDestroy(T_OsdkMutexHandle mutex);
157 
158  bool mutexLock(T_OsdkMutexHandle mutex);
159 
160  bool mutexUnlock(T_OsdkMutexHandle mutex);
161 
162  bool semaphoreCreate(T_OsdkSemHandle *semaphore, uint32_t initValue);
163 
164  bool semaphoreDestroy(T_OsdkSemHandle semaphore);
165 
166  bool semaphorePost(T_OsdkSemHandle semaphore);
167 
168  bool semaphoreWait(T_OsdkSemHandle semaphore);
169 
170  bool semaphoreTimedWait(T_OsdkSemHandle semaphore, uint32_t waitTime);
171 
172  bool getTimeMs(uint32_t *ms);
173 
174 #ifdef OS_DEBUG
175  bool getTimeUs(uint64_t *us);
176 #endif
177 
178  void* malloc(uint32_t size);
179 
180  void free(void *ptr);
181 
182 private:
183  bool osalRegFlag;
184  bool halUartRegFlag;
185  bool loggerConsoleRegFlag;
186 
187 };
188 }
189 }
190 
191 //temporary implement for dji_log
192 class Mutex
193 {
194 public:
195  Mutex();
196  ~Mutex();
197 
198  bool lock();
199 
200  bool unlock();
201 
202 private:
203  T_OsdkMutexHandle mutex;
204 };
205 
206 
207 #endif
This is the header file for define OSDK platform interfaces.
This is the header file for "osdk_logger.c", defining the structure and (exported) function prototype...
void * T_OsdkTaskHandle
Platform handle of thread task operation.
Definition: osdk_platform.h:51
Singleton Template Class implementation for use with the DJI OSDK.
void * T_OsdkMutexHandle
Platform handle of mutex operation.
Definition: osdk_platform.h:55
void * T_OsdkSemHandle
Platform handle of semaphore operation.
Definition: osdk_platform.h:59
handle array of characters
Definition: commondatarangehandler.h:14