1 /*
2  * Copyright (C) 2017-2018 NXP Semiconductors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /**
18  * \file  phOsal_Posix.h
19  *  \brief OSAL header files related to operating system functionalities.
20  */
21 
22 #ifndef PHOSAL_POSIX_H_
23 #define PHOSAL_POSIX_H_
24 
25 #include <stdint.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #define OSALSTATUS_OK 0
32 #define OSALSTATUS_SUCCESS 0
33 #define OSALSTATUS_INVALID_PARAMS 1
34 #define OSALSTATUS_FAILED 2
35 #define OSALSTATUS_SEM_TIMEOUT 3
36 #define OSALSTATUS_Q_OVERFLOW 4
37 #define OSALSTATUS_Q_UNDERFLOW 5
38 #define OSALSTATUS_NOT_SUPPORTED 6
39 #define OSALSTATUS_NOT_INITIALISED 7
40 #define OSALSTATUS_INSUFFICIENT_RESOURCES 8
41 #define OSALSTATUS_ALREADY_INITIALISED 9
42 
43 typedef int32_t OSALSTATUS; /* Return values */
44 
45 /** \ingroup grp_osal_log
46     Types of logging needed.
47     If LOGLEVEL is set for 3(Data Buffers) all types of logs are enabled*/
48 typedef enum phOsal_eLogLevel {
49   PHOSAL_LOGLEVEL_NONE = 0,
50   PHOSAL_LOGLEVEL_ERROR = 1,
51   PHOSAL_LOGLEVEL_INFO = 2,
52   PHOSAL_LOGLEVEL_DEBUG = 3,
53   PHOSAL_LOGLEVEL_DATA_BUFFERS = 4
54 } phOsal_eLogLevel_t;
55 
56 /**
57  * \internal
58  *
59  * \def PH_OSAL_TRACE_MALLOC
60  *
61  * Trace what is being allocated and de-allocated.
62  *
63  * Set to 1 to trace/log malloc and free. 0 to disable tracing */
64 
65 #if PHFL_LOG_MALLOC_LOGLEVEL == PHFL_LOG_LEVEL_FUNC
66 #define PH_OSAL_TRACE_MALLOC 1
67 #else
68 #define PH_OSAL_TRACE_MALLOC 0
69 #endif
70 
71 /** @} */
72 
73 /** \addtogroup grp_osal_stack
74  * @{ */
75 /**
76  * Maximum time a system object can wait to be occupied.
77  */
78 #define PH_OSAL_MAX_WAITTIME (INFINITE)
79 
80 /**
81  * Message Base number at which thread starts storing message queue details */
82 #define PH_OSAL_MESSAGE_BASE (WM_USER + 0x3FF)
83 
84 /** \internal
85  * Debug mode is enabled to analyze and trace the call stack */
86 #define PH_OSAL_ENABLE_DEBUG 0
87 
88 /** @} */
89 /*
90 ***************************Globals,Structure and Enumeration ******************
91 */
92 
93 /** \addtogroup grp_osal_thread
94  * @{ */
95 
96 /**
97  * Thread Function Pointer Declaration.
98  *
99  * This points to the function to be invoked upon creation of thread.
100  * It is not the immediate thread procedure since the API of this function
101  * depends on the OS.
102  *
103  * This function shall be called within the body of the thread procedure
104  * defined by the underlying, OS-depending OSAL implementation.
105  *
106  */
107 /*typedef void (*pphOsal_ThreadFunction_t)(void*);*/
108 
109 /** @} */
110 
111 /** \addtogroup grp_osal_stack
112  * @{ */
113 
114 /**
115  * Deferred call declaration.
116  * This type of API is called from ClientApplication (main thread) to notify
117  * specific callback.
118  */
119 typedef void (*pphOsal_DeferFuncPointer_t)(void*);
120 
121 /**
122  * Deferred message specific info declaration.
123  * This type information packed as WPARAM  when windows message
124  * is posted to message handler thread.
125  */
126 typedef struct phOsal_DeferedCallInfo {
127   pphOsal_DeferFuncPointer_t pDeferedCall; /**< pointer to Deferred callback */
128   void* pParam; /**< contains timer message specific details*/
129 } phOsal_DeferedCallInfo_t;
130 
131 /** @} */
132 
133 /** \ingroup grp_osal_exp
134  *
135  * Supported exception types
136  *
137  * Enum definition contains supported exception types
138  */
139 typedef enum {
140   phOsal_e_NoMemory,           /**< Memory allocation failed */
141   phOsal_e_PrecondFailed,      /**< precondition wasn't met */
142   phOsal_e_InternalErr,        /**< Unrecoverable error */
143   phOsal_e_UnrecovFirmwareErr, /**< Unrecoverable firmware error */
144   phOsal_e_TMLerror            /**< Unrecoverable TML error */
145 } phOsal_ExceptionType_t;      /**< Variable indicating type of Exception */
146 
147 /** \addtogroup grp_osal_stack
148  * @{ */
149 
150 /**
151  *  information to configure OSAL
152  */
153 typedef struct phOsal_Config {
154   uint8_t* pLogFile;           /**< Log File Name*/
155   uint32_t dwCallbackThreadId; /**< Client ID to which message is posted */
156   void* pContext;
157 } phOsal_Config_t, *pphOsal_Config_t /**< Pointer to #phOsal_Config_t */;
158 
159 typedef enum phOsal_eSlzType {
160   phOsal_eSlzTypeStatic = 0x00,
161   phOsal_eSlzTypeDynamic = 0x01
162 } phOsal_eSlzType_t;
163 
164 typedef enum phOsal_eSlzVersion {
165   phOsal_eSlzVersionMantis = 0x00,
166   phOsal_eSlzVersionVienna_1_0 = 0x00,
167   phOsal_eSlzVersionVienna_2_0 = 0x00,
168   phOsal_eSlzVersionVienna_2_1 = 0x11
169 } phOsal_eSlzVersion_t;
170 
171 /**
172  * OSAL initialization.
173  * This function initializes Timer queue and Critical section variable.
174  * \param[in] pOsalConfig               Osal Configuration file.
175  * \retval #OSALSTATUS_SUCCESS            Initialization of OSAL module was
176  * successful. \retval #OSALSTATUS_INVALID_PARAMS  Client Thread ID passed is
177  * invalid. \retval #OSALSTATUS_ALREADY_INITIALISED   Osal Module is already
178  * Initialized. \retval #OSALSTATUS_FAILED             Initialization of OSAL
179  * module was not successful.
180  *
181  */
182 extern OSALSTATUS phOsal_Init(pphOsal_Config_t pOsalConfig);
183 
184 /**
185  * OSAL initialization.
186  * This function De-Initializes the Objects and Memory occupied during
187  * Initialization. This function also closes the objects if any of it is still
188  * open.
189  *
190  */
191 extern void phOsal_DeInit(void);
192 
193 /** @} */
194 
195 /** \addtogroup grp_osal_rng
196  * @{ */
197 
198 /**
199  * Initializes Random Number Generator seed.
200  * \note This function executes successfully without OSAL module Initialization.
201  */
202 void phOsal_RandInit(void);
203 
204 /**
205  * Gets Random number. \ref phOsal_RandInit function shall be invoked prior,
206  * in order to get non-repeating random numbers.
207  * \note This function executes successfully without OSAL module Initialization.
208  *
209  * \retval Random number generated in the range 0 to 32767
210  *
211  */
212 unsigned short phOsal_RandGetNumber(void);
213 
214 /** @} */
215 
216 /** \addtogroup grp_osal_mm
217  * @{ */
218 
219 /**
220  * Allocates some memory.
221  *
222  * \note This function executes successfully without OSAL module initialization.
223  *
224  * \param[in] dwSize   Size, in uint32_t, to be allocated
225  *
226  * \retval NON-NULL value:  The memory is successfully allocated ;
227  * the return value is a pointer to the allocated memory location
228  * \retval NULL:            The operation is not successful.
229  *
230  */
231 #if defined(PH_OSAL_TRACE_MALLOC) && PH_OSAL_TRACE_MALLOC == 0
232 void* phOsal_GetMemory(uint32_t dwSize);
233 #else
234 #define phOsal_GetMemory(dwSize) phOsal_GetMemorySTR(dwSize, #dwSize)
235 /*
236  * Actual function for #phOsal_GetMemory
237  * \param dwSize Size of memory to be freed
238  * \retval See #phOsal_GetMemory for retval
239  */
240 /* void * phOsal_GetMemoryREAL(uint32_t dwSize); */
241 /* Run #phOsal_GetMemory and also show what is being allocated */
242 void* phOsal_GetMemorySTR(uint32_t dwSize, const int8_t* What);
243 #endif
244 /**
245  * This API allows to free already allocated memory.
246  * \note This function executes successfully without OSAL module Initialization.
247  *
248  * \param[in] pMem  Pointer to the memory block to be deallocated
249  */
250 #if defined(PH_OSAL_TRACE_MALLOC) && PH_OSAL_TRACE_MALLOC == 0
251 void phOsal_FreeMemory(void* pMem);
252 #else
253 #define phOsal_FreeMemory(pMem) phOsal_FreeMemorySTR(pMem, #pMem)
254 /* Actual function for #phOsal_GetMemory */
255 /* void phOsal_FreeMemoryREAL(void * pMem); */
256 /* Run \ref phOsal_FreeMemory and also show what is being freed */
257 void phOsal_FreeMemorySTR(void* pMem, const int8_t* What);
258 #endif
259 
260 /**
261  * This API allows to delay the current thread execution.
262  * \note This function executes successfully without OSAL module Initialization.
263  *
264  * \param[in] dwDelay  Duration in milliseconds for which thread execution to be
265  * halted.
266  */
267 void phOsal_Delay(uint32_t dwDelay);
268 
269 /**
270  * Compares the values stored in the source memory with the
271  * values stored in the destination memory.
272  * \note This function executes successfully without OSAL module Initialization.
273  *
274  * \param[in] pDest     Pointer to the Destination string.
275  * \param[in] pSrc      Pointer to the Source string.
276  * \param[in] dwSize    Number of bytes to be compared.
277  *
278  * \retval Zero value:        The comparison is successful,
279                     Both the memory areas contains identical values.
280  * \retval Non-Zero Value:    The comparison failed, both the memory
281  *                  areas are non-identical.
282  *
283  */
284 int32_t phOsal_MemCompare(const void* pDest, const void* pSrc, uint32_t dwSize);
285 
286 /**
287  * Sets the given value in the memory locations.
288  * \note This function executes successfully without OSAL module Initialization.
289  *
290  * \param[in] pMem      Pointer to the memory block to be set to a value
291  * \param[in] bVal      Value to be set
292  * \param[in] dwSize    Number of bytes to be set.
293  *
294  */
295 #if defined(PH_OSAL_TRACE_MALLOC) && PH_OSAL_TRACE_MALLOC == 0
296 void phOsal_SetMemory(void* pMem, uint8_t bVal, uint32_t dwSize);
297 #else
298 #define phOsal_SetMemory(pMem, bVal, dwSize) \
299   phOsal_SetMemorySTR(pMem, #pMem, bVal, dwSize, #dwSize)
300 
301 void phOsal_SetMemoryREAL(void* pMem, uint8_t bVal, uint32_t dwSize);
302 void phOsal_SetMemorySTR(void* pMem, const int8_t* WhatMem, uint8_t bVal,
303                          uint32_t dwSize, const int8_t* WhatSize);
304 #endif
305 /**
306  * Copies the values stored in the source memory to the
307  * values stored in the destination memory.
308  * \note This function executes successfully without OSAL module Initialization.
309  *
310  * \param[in] pDest     Pointer to the Destination Memory
311  * \param[in] pSrc      Pointer to the Source Memory
312  * \param[in] dwSize    Number of bytes to be copied.
313  *
314  */
315 void phOsal_MemCopy(void* pDest, const void* pSrc, uint32_t dwSize);
316 
317 /** @} */
318 
319 /** \addtogroup grp_osal_exp
320  * @{ */
321 
322 /**
323  * Raises exception on a severe error
324  *
325  * The program jumps out of the current execution flow, i.e. this function
326  * doesn't return. The given exception contains information on what has happened
327  * and how severe the error is. \note This function executes successfully
328  * without OSAL module Initialization.
329  *
330  * \param[in] eExceptiontype  exception Type.
331  * \param[in] wReason     This is an additional reason value that gives a vendor
332  * specific reason code
333  */
334 
335 void phOsal_RaiseException(phOsal_ExceptionType_t eExceptiontype,
336                            unsigned short wReason);
337 
338 /** \addtogroup grp_osal_thread
339  * @{ */
340 
341 /**
342  * Thread Function Pointer Declaration.
343  *
344  * This points to the function to be invoked upon creation of thread.
345  * It is not the immediate thread procedure since the API of this function
346  * depends on the OS.
347  *
348  * This function shall be called within the body of the thread procedure
349  * defined by the underlying, OS-depending OSAL implementation.
350  *
351  */
352 typedef void* (*pphOsal_ThreadFunction_t)(void*);
353 
354 /** \ingroup grp_osal_thread
355  *
356  * @{ */
357 
358 /**
359  * Thread Creation.
360  *
361  * This function creates a thread in the underlying system. To delete the
362  * created thread use the phOsal_Thread_Delete function.
363  *
364  *
365  * \param[in,out] hThread    The Thread handle: The caller has to prepare a void
366  * pointer that need not to be initialized. The value (content) of the pointer
367  * is set by the function.
368  *
369  * \param[in] pThreadFunction Pointer to a function within the
370  *                           implementation that shall be called by the Thread
371  *                           procedure. This represents the Thread main
372  * function. When this function exits the thread exits. \param[in] pParam A
373  * pointer to a user-defined location the thread function receives.
374  *
375  * \retval #OSALSTATUS_SUCCESS                    The operation was successful.
376  * \retval #OSALSTATUS_INSUFFICIENT_RESOURCES     At least one parameter value
377  * is invalid. \retval #PH_OSAL_THREAD_CREATION_ERROR     A new Thread could not
378  * be created due to system error. \retval #OSALSTATUS_NOT_INITIALISED Osal
379  * Module is not Initialized.
380  *
381  */
382 OSALSTATUS phOsal_ThreadCreate(void** hThread,
383                                pphOsal_ThreadFunction_t pThreadFunction,
384                                void* pParam);
385 
386 /**
387  * Get the task identifier of the caller thread.
388  *
389  * \retval 0 OSAL is not Initialized.
390  * \retval NonZero Thread ID of the caller thread
391  */
392 uint32_t phOsal_ThreadGetTaskId(void);
393 
394 /**
395  * Terminates the thread.
396  *
397  * This function Terminates the thread passed as a handle.
398  *
399  * \param[in] hThread The handle of the system object.
400  *
401  * \retval #OSALSTATUS_SUCCESS                The operation was successful.
402  * \retval #OSALSTATUS_INVALID_PARAMS      At least one parameter value is
403  * invalid. \retval #PH_OSAL_THREAD_DELETE_ERROR   Thread could not be deleted
404  * due to system error. \retval #OSALSTATUS_NOT_INITIALISED        Osal Module
405  * is not Initialized.
406  *
407  */
408 OSALSTATUS phOsal_ThreadDelete(void* hThread);
409 #ifdef ENABLE_ADVANCED_FUNCS
410 /**
411  * Suspend the specified thread.
412  *
413  * \param[in] hThread The handle of the system object.
414  *
415  * \retval #OSALSTATUS_SUCCESS                The operation was successful.
416  * \retval #OSALSTATUS_INVALID_PARAMS      At least one parameter value is
417  * invalid. \retval #PH_OSAL_THREAD_SUSPEND_ERROR  If the thread is not able to
418  * be suspended. \retval #OSALSTATUS_NOT_INITIALISED        Osal Module is not
419  * Initialized. Note : there is no direct function for suspend thread in linux.
420  */
421 OSALSTATUS phOsal_ThreadSuspend(void* hThread);
422 
423 /**
424  * Resumes the specified thread.
425  *
426  * \param[in] hThread The handle of the system object.
427  *
428  * \retval #OSALSTATUS_SUCCESS                The operation was successful.
429  * \retval #OSALSTATUS_INVALID_PARAMS      At least one parameter value is
430  * invalid. \retval #PH_OSAL_THREAD_RESUME_ERROR   If the thread is not able to
431  * be resume. \retval #OSALSTATUS_NOT_INITIALISED        Osal Module is not
432  * Initialized. Note : there is no direct function for wakeup thread in linux.
433  */
434 OSALSTATUS phOsal_ThreadWakeUp(void* hThread);
435 #endif
436 /**
437  * Set priority for the specified thread.
438  *
439  * \param[in] hThread       The handle of the system object.
440  * \param[in] sdwPriority   Priority of the thread.
441  *
442  * \retval #OSALSTATUS_SUCCESS                The operation was successful.
443  * \retval #OSALSTATUS_INVALID_PARAMS      At least one parameter value is
444  * invalid. \retval #PH_OSAL_THREAD_SETPRIORITY_ERROR If the priority is not
445  * able to be set. \retval #OSALSTATUS_NOT_INITIALISED        Osal Module is not
446  * Initialized.
447  */
448 OSALSTATUS phOsal_ThreadSetPriority(void* hThread, int32_t sdwPriority);
449 
450 /**
451  * OSAL Message structure
452  *
453  * Contains message specific details such as message type ,message specific data
454  * block details
455  */
456 typedef struct phOsal_Message {
457   uint32_t eMsgType; /**< Type of the message to be posted */
458   void* pMsgData; /**< Pointer to message specific data block (in case any) */
459   unsigned short Size;                  /**< Size of the datablock */
460 } phOsal_Message_t, *pphOsal_Message_t; /**< pointer to \ref phOsal_Message */
461 
462 /**
463  * Create a queue by allocating specified memory.
464  *
465  * \param[in,out] msgQHdl    The handle: The caller has to prepare a void
466  * pointer that needs not to be initialized. The value (content) of the pointer
467  * is set by the function. \param[in] dwQueueLength              Length of the
468  * message Queue required.
469  *
470  * \retval #OSALSTATUS_SUCCESS                The operation was successful.
471  * \retval #OSALSTATUS_INVALID_PARAMS      Any caller provided parameter is
472  * invalid. \retval #OSALSTATUS_NOT_INITIALISED        Osal Module is not
473  * Initialized.
474  *
475  */
476 OSALSTATUS phOsal_MsgQCreate(void** msgQHdl, uint32_t dwQueueLength);
477 
478 /**
479  * This API allows to delete a Message Queue.
480  * \param[in] msgQHdl    Handle of the message queue which needs to be deleted.
481  *
482  * \retval #OSALSTATUS_SUCCESS            The operation was successful.
483  * \retval #OSALSTATUS_NOT_INITIALISED   Osal Module is not Initialized.
484  * \retval #OSALSTATUS_INVALID_PARAMS  At least one parameter value is invalid.
485  */
486 OSALSTATUS phOsal_MsgQDelete(void* msgQHdl);
487 
488 /**
489  * Function used to post a message to a thread's message queue.
490  *
491  * \param[in] dwSourceID             The Thread identifier of the sending
492  * thread. \param[in] msgQHdl    The handle of the MessageQueue. \param[in] pMsg
493  * Pointer to the message structure to be posted to the queue.
494  *
495  * \retval #OSALSTATUS_SUCCESS                The operation was successful.
496  * \retval #OSALSTATUS_NOT_INITIALISED       Osal Module is not Initialized.
497  * \retval #OSALSTATUS_INVALID_PARAMS      Any caller provided parameter is
498  * invalid. \retval #OSALSTATUS_INSUFFICIENT_RESOURCES The operation could not
499  * complete because of lack of resources.
500  */
501 OSALSTATUS phOsal_MsgQPostMsg(void* msgQHdl, uint32_t dwSourceID,
502                               phOsal_Message_t* pMsg);
503 
504 /**
505  * Function used to receive a message from calling thread's message queue.
506  *
507  * \param[out] pSourceID            Pointer where Thread ID of poster thread is
508  * stored. \param[in]  msgQHdl  The handle of the MessageQueue. \param[out] pMsg
509  * The message to be filled with the received data from the message queue.
510  *
511  * \retval #OSALSTATUS_SUCCESS                The operation was successful.
512  * \retval #OSALSTATUS_NOT_INITIALISED       Osal Module is not Initialized.
513  * \retval #OSALSTATUS_INVALID_PARAMS      Any caller provided parameter is
514  * invalid. \retval #OSALSTATUS_INSUFFICIENT_RESOURCES The operation could not
515  * complete because of lack of resources.
516  */
517 OSALSTATUS phOsal_MsgQReceiveMsg(void* msgQHdl, uint32_t* pSourceID,
518                                  phOsal_Message_t* pMsg);
519 
520 /**
521  * Semaphore Creation.
522  * This function creates a semaphore in the underlying system.
523  *
524  * \param[in,out] hSemaphore The handle: The caller has to prepare a void
525  *                           pointer where the handle of semaphore shall be
526  * returned.
527  *
528  * \param[in] bInitialValue   The initial value of the Semaphore.
529  * \param[in] bMaxValue       The maximum value of the Semaphore.
530  *
531  * \retval #NFCSTATUS_SUCCESS                    The operation was successful.
532  * \retval #NFCSTATUS_INVALID_PARAMETER          Parameter passed to the
533  * function is not Correct. \retval #NFCSTATUS_INSUFFICIENT_RESOURCES     All
534  * semaphores are occupied by other threads. \retval
535  * #PH_OSAL_SEMAPHORE_CREATION_ERROR  A new semaphore could not be created due
536  * to system error. \retval #NFCSTATUS_NOT_INITIALISED           Osal Module is
537  * not Initialized.
538  *
539  */
540 OSALSTATUS phOsal_SemaphoreCreate(void** hSemaphore, uint8_t bInitialValue,
541                                   uint8_t bMaxValue);
542 
543 /**
544  * Semaphore-Produce (never waiting).
545  *
546  * Increment the value of the semaphore.
547  * The purpose is to enable a waiting thread ("consumer") to continue
548  * if it has been waiting because of the Semaphore value set to zero.
549  *
550  * \param[in] hSemaphore The handle of the Semaphore.
551  *
552  * \retval #NFCSTATUS_SUCCESS                    The operation was successful.
553  * \retval #NFCSTATUS_INVALID_PARAMETER          Parameter passed to the
554  * function is not Correct. \retval #PH_OSAL_SEMAPHORE_PRODUCE_ERROR   The
555  * semaphore cannot be produced due to a system error or invalid handle .
556  * \retval #NFCSTATUS_NOT_INITIALISED           Osal Module is not Initialized.
557  *
558  */
559 OSALSTATUS phOsal_SemaphorePost(void* hSemaphore);
560 
561 /**
562  * Semaphore Consumption (waiting if value is zero).
563  *
564  * Decrement the value of the semaphore. When the internal value is
565  * non-zero, the function continues. If the value is zero however, the
566  * function blocks till the semaphore is released.
567  *
568  * \param[in] hSemaphore The handle of the Semaphore.
569  *
570  * \retval #NFCSTATUS_SUCCESS                    The operation was successful.
571  * \retval #NFCSTATUS_INVALID_PARAMETER          Parameter passed to the
572  * function is not Correct. \retval #PH_OSAL_SEMAPHORE_CONSUME_ERROR   The
573  * semaphore can not be consumed due to a system error or invalid handle .
574  * \retval #NFCSTATUS_NOT_INITIALISED           Osal Module is not Initialized.
575  *
576  */
577 OSALSTATUS phOsal_SemaphoreWait(void* hSemaphore, uint32_t timeout_ms);
578 /**
579  * Semaphore Deletion.
580  * This function deletes the Semaphore in the underlying OS.
581  *
582  * \param[in] hSemaphore                    The handle of the Semaphore.
583  *
584  * \retval #NFCSTATUS_SUCCESS                    The operation was successful.
585  * \retval #NFCSTATUS_INVALID_PARAMETER          Parameter passed to the
586  * function is not Correct. \retval #PH_OSAL_SEMAPHORE_DELETE_ERROR    The
587  * semaphore can not be deleted due to a system error or invalid handle .
588  * \retval #NFCSTATUS_NOT_INITIALISED           Osal Module is not Initialized.
589  *
590  */
591 OSALSTATUS phOsal_SemaphoreDelete(void* hSemaphore);
592 
593 /**
594  * Mutex Creation.
595  * This function creates a Mutex in the underlying system.
596  *
597  * \param[in,out] hMutex     The handle: The caller has to prepare a void
598  *                           pointer where the handle of mutex shall be
599  * returned.
600  *
601  * \retval #NFCSTATUS_SUCCESS The operation was successful.
602  * \retval #NFCSTATUS_INVALID_PARAMETER          Parameter passed to the
603  * function is not Correct. \retval #NFCSTATUS_INSUFFICIENT_RESOURCES     All
604  * Mutexes are occupied by other threads. \retval #PH_OSAL_MUTEX_CREATION_ERROR
605  * A new mutex could not be created due to system error. \retval
606  * #NFCSTATUS_NOT_INITIALISED           Osal Module is not Initialized.
607  *
608  */
609 OSALSTATUS phOsal_MutexCreate(void** hMutex);
610 
611 /**
612  * Mutex Locking.
613  * This function locks a mutex used for handling critical section of code.
614  * However the function blocks till the Mutex is available to be occupied.
615  *
616  * \param[in] hMutex                    The handle of the Mutex.
617  *
618  * \retval #NFCSTATUS_SUCCESS            The operation was successful.
619  * \retval #NFCSTATUS_INVALID_PARAMETER  Parameter passed to the function is not
620  * Correct. \retval #PH_OSAL_MUTEX_LOCK_ERROR  The mutex cannot be locked due to
621  * a system error or invalid handle. \retval #NFCSTATUS_NOT_INITIALISED   Osal
622  * Module is not Initialized.
623  *
624  */
625 OSALSTATUS phOsal_MutexLock(void* hMutex);
626 
627 /**
628  * Mutex Unlocking.
629  * This function unlocks a mutex after updating critical section of code.
630  *
631  * \param[in] hMutex        The handle of the Mutex.
632  *
633  * \retval #NFCSTATUS_SUCCESS                The operation was successful.
634  * \retval #NFCSTATUS_INVALID_PARAMETER      Parameter passed to the function is
635  * not Correct. \retval #PH_OSAL_MUTEX_UNLOCK_ERROR    The mutex cannot be
636  * locked due to a system error or invalid handle. \retval
637  * #NFCSTATUS_NOT_INITIALISED       Osal Module is not Initialized.
638  *
639  */
640 OSALSTATUS phOsal_MutexUnlock(void* hMutex);
641 
642 /**
643  * Mutex Deletion.
644  * This function deletes a Mutex in the underlying system.
645  *
646  * \param[in] hMutex        The handle of the Mutex.
647  *
648  * \retval #NFCSTATUS_SUCCESS                The operation was successful.
649  * \retval #PH_OSAL_MUTEX_DELETE_ERROR    The mutex cannot be deleted due to a
650  * system error or invalid handle. \retval #NFCSTATUS_NOT_INITIALISED       Osal
651  * Module is not Initialized.
652  *
653  */
654 OSALSTATUS phOsal_MutexDelete(void* hMutex);
655 
656 /**
657  * Logging levels
658  * This function set the type of logs to be enabled
659  *
660  * \param[in] eLogLevel  Type of logs to be enabled(info,errors,debug,data)
661  *
662  */
663 void phOsal_SetLogLevel(phOsal_eLogLevel_t eLogLevel);
664 
665 /**
666  * Log Error
667  * This function prints the error message specified
668  * appropriate log level for error needs to be enabled from phOsal_SetLogLevel
669  *
670  * \param[in] pbMsg defines Error log message to be printed
671  *
672  */
673 void phOsal_LogError(const uint8_t* pbMsg);
674 
675 /**
676  * Log Error
677  * This function prints the error message specified along with 32bit value in
678  * Hex appropriate log level for error needs to be enabled from
679  * phOsal_SetLogLevel
680  *
681  * \param[in] pbMsg defines Error log message to be printed
682  * \param[in] wValue defines value to be printed
683  *
684  */
685 void phOsal_LogErrorU32h(const uint8_t* pbMsg, uint32_t wValue);
686 
687 /**
688  * Log Error
689  * This function prints the error message specified along with 32bit value in
690  * decimal appropriate log level for error needs to be enabled from
691  * phOsal_SetLogLevel
692  *
693  * \param[in] pbMsg defines Error log message to be printed
694  * \param[in] wValue defines value to be printed
695  */
696 void phOsal_LogErrorU32d(const uint8_t* pbMsg, uint32_t wValue);
697 
698 /**
699  * Log Error String
700  * This function prints the error message specified along with string
701  * appropriate log level for error needs to be enabled from phOsal_SetLogLevel
702  *
703  * \param[in] pbMsg defines Error log message to be printed
704  * \param[in] pbString defines pointer to string to be printed
705  */
706 void phOsal_LogErrorString(const uint8_t* pbMsg, const uint8_t* pbString);
707 
708 /**
709  * Log Information
710  * This function prints the information /warning specified
711  * appropriate log level for info needs to be enabled from phOsal_SetLogLevel
712  *
713  * \param[in] pbMsg  defines log message to be printed
714  *
715  */
716 void phOsal_LogInfo(const uint8_t* pbMsg);
717 
718 /**
719  * Log Information
720  * This function prints the information /warning specified along with 32bit
721  * value in Hex appropriate log level for info needs to be enabled from
722  * phOsal_SetLogLevel
723  *
724  * \param[in] pbMsg  defines log message to be printed
725  * \param[in] wValue defines value to be printed
726  *
727  */
728 void phOsal_LogInfoU32h(const uint8_t* pbMsg, uint32_t wValue);
729 
730 /**
731  * Log Information
732  * This function prints the information /warning specified along with 32bit
733  * value in Hex appropriate log level for info needs to be enabled from
734  * phOsal_SetLogLevel
735  *
736  * \param[in] pbMsg   defines log message to be printed
737  * \param[in] wValue1 defines value to be printed
738  * \param[in] wValue2 defines value to be printed
739  *
740  */
741 void phOsal_LogInfoU32hh(const uint8_t* pbMsg, uint32_t wValue1,
742                          uint32_t wValue2);
743 
744 /**
745  * Log Information
746  * This function prints the information /warning specified along with 32bit
747  * value in float appropriate log level for info needs to be enabled from
748  * phOsal_SetLogLevel
749  *
750  * \param[in] pbMsg  defines log message to be printed
751  * \param[in] wValue defines value to be printed
752  *
753  */
754 void phOsal_LogInfo32f(const uint8_t* pbMsg, float wValue);
755 
756 /**
757  * Log Information
758  * This function prints the information /warning specified along with 32bit
759  * value in decimal appropriate log level for info needs to be enabled from
760  * phOsal_SetLogLevel
761  *
762  * \param[in] pbMsg  defines log message to be printed
763  * \param[in] wValue defines value to be printed
764  *
765  */
766 void phOsal_LogInfoU32d(const uint8_t* pbMsg, uint32_t wValue);
767 
768 /**
769  * Log Information
770  * This function prints the information /warning specified along with 32bit
771  * value in decimal appropriate log level for info needs to be enabled from
772  * phOsal_SetLogLevel
773  *
774  * \param[in] pbMsg   defines log message to be printed
775  * \param[in] wValue1 defines value to be printed
776  * \param[in] wValue2 defines value to be printed
777  *
778  */
779 void phOsal_LogInfoU32dd(const uint8_t* pbMsg, uint32_t wValue1,
780                          uint32_t wValue2);
781 
782 /**
783  * Log Information and String
784  * This function prints the information specified along with string
785  * appropriate log level for info needs to be enabled from phOsal_SetLogLevel
786  *
787  * \param[in] pbMsg defines log message to be printed
788  * \param[in] pbString defines pointer to string to be printed
789  */
790 void phOsal_LogInfoString(const uint8_t* pbMsg, const uint8_t* pbString);
791 
792 /**
793  * Log Debug Information
794  * This function prints the Debug log message specified
795  * appropriate log level for debug needs to be enabled from phOsal_SetLogLevel
796  *
797  * \param[in] pbMsg defines log message to be printed
798  *
799  */
800 void phOsal_LogDebug(const uint8_t* pbMsg);
801 
802 /**
803  * Log Debug Information
804  * This function prints the Debug log message specified along with 32bit value
805  * in hex appropriate log level for debug needs to be enabled from
806  * phOsal_SetLogLevel
807  *
808  * \param[in] pbMsg defines log message to be printed
809  * \param[in] wValue defines value to be printed
810  *
811  */
812 void phOsal_LogDebugU32h(const uint8_t* pbMsg, uint32_t wValue);
813 
814 /**
815  * Log Debug Information
816  * This function prints the Debug log message specified along with 32bit value
817  * in decimal appropriate log level for debug needs to be enabled from
818  * phOsal_SetLogLevel
819  *
820  * \param[in] pbMsg defines log message to be printed
821  * \param[in] wValue defines value to be printed
822  *
823  */
824 void phOsal_LogDebugU32d(const uint8_t* pbMsg, uint32_t wValue);
825 
826 /**
827  * Log Debug Information
828  * This function prints the Debug log message specified along with pointer value
829  * in hex appropriate log level for debug needs to be enabled from
830  * phOsal_SetLogLevel
831  *
832  * \param[in] pbMsg defines log message to be printed
833  * \param[in] pValue defines value to be printed
834  *
835  */
836 void phOsal_LogDebugPtrh(const uint8_t* pbMsg, void* pValue);
837 
838 /**
839  * Log Debug Information specified along with the string
840  * This function prints the Debug log message specified along with 32bit value
841  * in decimal appropriate log level for debug needs to be enabled from
842  * phOsal_SetLogLevel
843  *
844  * \param[in] pbMsg defines log message to be printed
845  * \param[in] wValue defines value to be printed
846  *
847  */
848 void phOsal_LogDebugString(const uint8_t* pbMsg, const uint8_t* pbString);
849 
850 /**
851  * Log function entry point
852  * This function prints the function name specified prefixed by Module name
853  * appropriate log level for debug needs to be enabled from phOsal_SetLogLevel
854  *
855  * \param[in] pbModuleName defines log message to be printed
856  * \param[in] pbFuncName defines value to be printed
857  *
858  */
859 void phOsal_LogFunctionEntry(const uint8_t* pbModuleName,
860                              const uint8_t* pbFuncName);
861 
862 /**
863  * Log function exit point
864  * This function prints the function name specified prefixed by Module name
865  * appropriate log level for debug needs to be enabled from phOsal_SetLogLevel
866  *
867  * \param[in] pbMsg defines log message to be printed
868  * \param[in] wValue defines value to be printed
869  *
870  */
871 void phOsal_LogFunctionExit(const uint8_t* pbModuleName,
872                             const uint8_t* pbFuncName);
873 
874 /**
875  * Log Buffer data
876  * This function prints the data in the buffers provided in Hex
877  * appropriate log level for debug needs to be enabled from phOsal_SetLogLevel
878  *
879  * \param[in] pbBuffer              Buffer data  to be logged
880  * \param[in] dwSizeOfBuffer        Size of buffer data.
881  * \param[in] pbMsg                 defines message to be printed before
882  * printing the buffer data.
883  *
884  */
885 void phOsal_LogBuffer(const uint8_t* pbBuffer, uint32_t dwSizeOfBuffer,
886                       const uint8_t* pbMsg);
887 
888 #ifdef __cplusplus
889 }
890 #endif /*  C++ Compilation guard */
891 
892 #endif
893