Platform Porting
This is the header file for "psdk_platform.c", defining the structure and (exported) function prototypes.
Catalog
Function
PsdkPlatform_RegHalUartHandler
PsdkPlatform_RegOsalHandler
PsdkOsal_TaskCreate
PsdkOsal_TaskDestroy
PsdkOsal_TaskSleepMs
PsdkOsal_MutexCreate
PsdkOsal_MutexDestroy
PsdkOsal_MutexLock
PsdkOsal_MutexUnlock
PsdkOsal_SemaphoreCreate
PsdkOsal_SemaphoreDestroy
PsdkOsal_SemaphoreWait
PsdkOsal_SemaphoreTimedWait
PsdkOsal_SemaphorePost
PsdkOsal_GetTimeMs
PsdkOsal_Malloc
PsdkOsal_Free
Define
- Platform handle of thread task operation
typedef void *T_PsdkTaskHandle;
- Platform handle of mutex operation.
typedef void *T_PsdkMutexHandle;
- Platform handle of semaphore operation.
typedef void *T_PsdkSemHandle;
Structure
typedef struct T_PsdkHalUartHandler
Please construct the callback function of the Hal:
- Initialize the config information of the Uart which connected to the payload
- Write data to payload
- Read data from payload
typedef struct {
@brief Prototype of the callback function used to init the user uart that connected to the payload.
@note Users need to implement the initialization interface of their serial device and register it. For the related parameter settings of the serial port, please refer to the document.
@return Execution result
T_PsdkReturnCode (*UartInit)(void);
@brief Prototype of callback function used to write data by the user uart that connected to the payload.
@note Users need to implement the sending interface of their serial device and register it. Please use the relevant tools to test the interface before registering.
@param buf: pointer to memory space used to store the data that needs send by uart.
@param len: the length of data that needs send by uart.
@return Execution result.
T_PsdkReturnCode (*UartWriteData)(const uint8_t *buf, uint16_t len);
@brief Prototype of callback function used to read data from the user uart that connected to the payload.
@note Users need to implement the read interface of their serial device and register it. Please use the relevant tools to test the interface before registering.
@param buf: pointer to memory space used to store the data that read from uart.
@param len: the length of data that need read from uart.
@param realLen: pointer to memory space used to store the real size of reading data from uart.
@return Execution result.
T_PsdkReturnCode (*UartReadData)(uint8_t *buf, uint16_t len, uint16_t *realLen);
} T_PsdkHalUartHandler;
typedef struct T_PsdkOsalHandler
Please construct the callback function of the Osal:
- Declare task container
- Destroy the created task
- Control task sleep within the specified time, unit: ms
- Declare a mutex container
- Destroy the mutex
- Lock the created mutex
- Unlock and release the locked mutex
- Declare semaphore container
- Destroy semaphore
- Waiting for semaphore creating
- Timeout waiting for semaphore creating
- Release the created semaphore
- Get the millisecond time of the operating system of the payload, unit: ms
- Allocate specified memory space
- Free up allocated memory space
typedef struct {
@brief Prototype of callback function used to declare the task container, initialize the task, and create task ID.
@note This interface is mainly used to create the task. Users need to adapt according to their platform and system.
Also needs test the implemented interface before registration to ensure that the registration can be used normally.
For details of the parameters, please refer to the following API interface #PsdkOsal_TaskCreate.
@param task: pointer to memory space used to store the created task handle.
@param taskFunc: pointer to the created task function.
@param name: pointer to task name string, end with '\0'. If user does not specifically name for task, fill in NULL.
@param stackSize: the value of task stack size, unit: byte.
@param arg: pointer to the user-defined data.
@return Execution result.
T_PsdkReturnCode
(*TaskCreate)(T_PsdkTaskHandle *task, void *(*taskFunc)(void *), const char *name, uint32_t stackSize, void *arg);
@brief Prototype of callback function used to destroy the created task.
@note This interface is mainly used to destroy the created task. Users need to adapt according to their platform
and system. Also needs test the implemented interface before registration to ensure that the registration can be used
normally. For details of the parameters, please refer to the following API interface #PsdkOsal_TaskDestroy.
@param task: task handle.
@return Execution result.
T_PsdkReturnCode (*TaskDestroy)(T_PsdkTaskHandle task);
@brief Prototype of callback function used to let task into a sleep state in a set time, uint:ms.
@note This interface is mainly used to let task sleep. Users need to adapt according to their platform and system.
Also needs test the implemented interface before registration to ensure that the registration can be used normally.
For details of the parameters, please refer to the following API interface #PsdkOsal_TaskSleepMs.
@param timeMs: the value of time ms for task sleeping.
@return Execution result.
T_PsdkReturnCode (*TaskSleepMs)(uint32_t timeMs);
@brief Prototype of callback function used to declare the mutex container, initialize the mutex, and create mutex ID.
@note This interface is mainly used to create a mutex. Users need to adapt according to their platform and system.
Also needs test the implemented interface before registration to ensure that the registration can be used normally.
For details of the parameters, please refer to the following API interface #PsdkOsal_MutexCreate.
@param mutex: pointer to memory space used to store the created mutex ID.
@return Execution result.
T_PsdkReturnCode (*MutexCreate)(T_PsdkMutexHandle *mutex);
@brief Prototype of callback function used to destroy the created mutex.
@note This interface is mainly used to destroy the created mutex. Users need to adapt according to their platform
and system. Also need test the implemented interface before registration to ensure that the registration can be used
normally. For details of the parameters, please refer to the following API interface #PsdkOsal_MutexDestroy.
@param mutex: pointer to memory space used to store the created mutex ID.
@return Execution result.
T_PsdkReturnCode (*MutexDestroy)(T_PsdkMutexHandle mutex);
@brief Prototype of callback function used to acquire and lock the mutex when peripheral access is required.
@note This interface is mainly used to lock the created mutex. Users need to adapt according to their platform
and system. Also needs test the implemented interface before registration to ensure that the registration can be
used normally. For details of the parameters, please refer to the following API interface #PsdkOsal_MutexLock.
@param mutex: pointer to memory space used to store the created mutex ID.
@return Execution result.
T_PsdkReturnCode (*MutexLock)(T_PsdkMutexHandle mutex);
@brief Prototype of callback function used to unlock and release the mutex when done with the peripheral access.
@note This interface is mainly used to unlock the created mutex. Users need to adapt according to their platform
and system. Also needs test the implemented interface before registration to ensure that the registration can be used
normally. For details of the parameters, please refer to the following API interface #PsdkOsal_MutexUnlock.
@param mutex: pointer to memory space used to store the created mutex ID.
@return Execution result.
T_PsdkReturnCode (*MutexUnlock)(T_PsdkMutexHandle mutex);
@brief Prototype of callback function used to declare the semaphore container, initialize the semaphore, and create semaphore ID.
@note This interface is mainly used to create semaphore. Users need to adapt according to their platform and system.
Also needs test the implemented interface before registration to ensure that the registration can be used normally.
For details of the parameters, please refer to the following API interface #PsdkOsal_SemaphoreCreate.
@param semaphore: pointer to memory space used to store the created semaphore ID.
@param initValue: init value of semaphore for the created semaphore.
@return Execution result.
T_PsdkReturnCode (*SemaphoreCreate)(T_PsdkSemHandle *semaphore, uint32_t initValue);
@brief Prototype of callback function used to destroy the created semaphore.
@note This interface is mainly used to destroy the created semaphore. Users need to adapt according to their own
platform and system. Also need test the implemented interface before registration to ensure that the registration
can be used normally. For details of the parameters, please refer to the following API interface #PsdkOsal_SemaphoreDestroy.s
@param semaphore: pointer to memory space used to store the created semaphore ID.
@return Execution result.
T_PsdkReturnCode (*SemaphoreDestroy)(T_PsdkSemHandle semaphore);
@brief Prototype of callback function used to wait the created semaphore forever.
@note This interface is mainly used to wait the created semaphore forever. Users need to adapt according to their
own platform and system. Also need to test the implemented interface before registration to ensure that the registration
can be used normally. For details of the parameters, please refer to the following API interface #PsdkOsal_SemaphoreWait.
@param semaphore: pointer to memory space used to store the created semaphore ID.
@return Execution result.
T_PsdkReturnCode (*SemaphoreWait)(T_PsdkSemHandle semaphore);
@brief Prototype of callback function used to ait the created semaphore and set the value of timeout.
@note This interface is mainly used to wait for the created semaphore. Users need to adapt according to their platform
and system. Also needs test the implemented interface before registration to ensure that the registration can be used
normally. For details of the parameters, please refer to the following API interface #PsdkOsal_SemaphoreTimedWait.
@param semaphore: pointer to memory space used to store the created semaphore ID.
@param waitTimeMs: the value of timeout for waiting created semaphore.
@return Execution result.
T_PsdkReturnCode (*SemaphoreTimedWait)(T_PsdkSemHandle semaphore, uint32_t waitTimeMs);
@brief Prototype of callback function used to post the created semaphore.
@note This interface is mainly used to post the created semaphore. Users need to adapt according to their platform
and system. Also needs test the implemented interface before registration to ensure that the registration can be used
normally. For details of the parameters, please refer to the following API interface #PsdkOsal_SemaphorePost.
@param semaphore: pointer to memory space used to store the created semaphore ID.
@return Execution result.
T_PsdkReturnCode (*SemaphorePost)(T_PsdkSemHandle semaphore);
@brief Prototype of callback function used to get the system millisecond time, uint:ms.
@note This interface is mainly used to get system millisecond time. Users need to adapt according to their own
platform and system. Also need test the implemented interface before registration to ensure that the registration
can be used normally. For details of the parameters, please refer to the following API interface #PsdkOsal_GetTimeMs.
@param factor: pointer to memory space used to store the got time ms.
@return Execution result.
T_PsdkReturnCode (*GetTimeMs)(uint32_t *ms);
@brief Prototype of callback function used to allocate size bytes of memory.
@note This interface is mainly used to allocate size bytes of memory. Users need to adapt according to their own
platform and system. Also need test the implemented interface before registration to ensure that the registration
can be used normally. For details of the parameters, please refer to the following API interface #PsdkOsal_Malloc.
@param size: uint32_t size that needs allocate.
@return a void pointer to the allocated memory, if equal to NULL, please do related processing to avoid null pointer crash.
void *(*Malloc)(uint32_t size);
@brief Prototype of callback function used to release allocated memory.
@note This interface is mainly used to release allocated memory. Users need to adapt according to their platform
and system. Also needs test the implemented interface before registration to ensure that the registration can be used
normally. For details of the parameters, please refer to the following API interface #PsdkOsal_Free.
@param ptr: pointer to the need allocated memory.
void (*Free)(void *ptr);
} T_PsdkOsalHandler;
Function
function PsdkPlatform_RegHalUartHandler
Function:Register the interface of Hal | product:all |
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.
T_PsdkReturnCode PsdkPlatform_RegHalUartHandler(const T_PsdkHalUartHandler *halUartHandler);
halUartHandler:pointer to the handler for hal uart interfaces by your platform.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkPlatform_RegOsalHandler
Function:Register the interface of Osal | product:all |
Register the handler for osal 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.
T_PsdkReturnCode PsdkPlatform_RegOsalHandler(const T_PsdkOsalHandler *osalHandler);
osalHandler: pointer to the handler for network handler interfaces by your platform.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkOsal_TaskCreate
Function:Declare the task container | product:all |
Declare the task container, initialize the task, and create task ID.
T_PsdkReturnCode
PsdkOsal_TaskCreate(T_PsdkTaskHandle *task, void *(*taskFunc)(void *), const char *name, uint32_t stackSize,
void *arg);
task:pointer to the created task ID.
taskFunc:pointer to the created task function.
name:pointer to task name string, end with '\0'. If user do not specify name for task, fill in NULL.
stackSize:value of task stack size, unit: byte.
arg:pointer to the user defined data.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkOsal_TaskDestroy
Function:Destroy the created task. | product:all |
Destroy the created task.
T_PsdkReturnCode PsdkOsal_TaskDestroy(T_PsdkTaskHandle task);
task:pointer to the created task ID.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkOsal_TaskSleepMs
Function:Let task into a sleep state in a set time | product:all |
Let task into a sleep state in a set time, uint:ms.
T_PsdkReturnCode PsdkOsal_TaskSleepMs(uint32_t timeMs);
timeMs:value of time ms for task sleeping.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkOsal_MutexCreate
Function:Declare the mutex container | product:all |
Declare the mutex container, initialize the mutex, and create mutex ID.
T_PsdkReturnCode PsdkOsal_MutexCreate(T_PsdkMutexHandle *mutex);
mutex:pointer to the created mutex ID.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkOsal_MutexDestroy
Function:Destroy the created mutex. | product:all |
Destroy the created mutex.
T_PsdkReturnCode PsdkOsal_MutexDestroy(T_PsdkMutexHandle mutex);
mutex:pointer to the created mutex ID.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkOsal_MutexLock
Function:Acquire and lock the mutex when peripheral access is required. | product:all |
Acquire and lock the mutex when peripheral access is required.
T_PsdkReturnCode PsdkOsal_MutexLock(T_PsdkMutexHandle mutex);
mutex:pointer to the created mutex ID.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkOsal_MutexUnlock
Function:Unlock and release the mutex when done with the peripheral access. | product:all |
Unlock and release the mutex when done with the peripheral access.
T_PsdkReturnCode PsdkOsal_MutexUnlock(T_PsdkMutexHandle mutex);
mutex:pointer to the created mutex ID.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkOsal_SemaphoreCreate
Function:Declare the semaphore container | product:all |
Declare the semaphore container, initialize the semaphore, and create semaphore ID.
T_PsdkReturnCode PsdkOsal_SemaphoreCreate(T_PsdkSemHandle *semaphore, uint32_t initValue);
semaphore:pointer to the created semaphore ID.
initValue:init value of semaphore for the created semaphore.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkOsal_SemaphoreDestroy
Function:Destroy the created semaphore. | product:all |
Destroy the created semaphore.
T_PsdkReturnCode PsdkOsal_SemaphoreDestroy(T_PsdkSemHandle semaphore);
semaphore:pointer to the created semaphore ID.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkOsal_SemaphoreWait
Function:Wait the created semaphore forever. | product:all |
Wait the created semaphore forever.
T_PsdkReturnCode PsdkOsal_SemaphoreWait(T_PsdkSemHandle semaphore);
semaphore:pointer to the created semaphore ID.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkOsal_SemaphoreTimedWait
Function:Wait the created semaphore and set the value of timeout. | product:all |
Wait the created semaphore and set the value of timeout.
T_PsdkReturnCode PsdkOsal_SemaphoreTimedWait(T_PsdkSemHandle semaphore, uint32_t waitTimeMs);
semaphore:pointer to the created semaphore ID.
waitTimeMs:value of timeout for waiting created semaphore.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkOsal_SemaphorePost
Function:Post the created semaphore. | product:all |
Post the created semaphore.
T_PsdkReturnCode PsdkOsal_SemaphorePost(T_PsdkSemHandle semaphore);
semaphore:pointer to the created semaphore ID.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkOsal_GetTimeMs
Function:Get the system millisecond time | product:all |
Get the system millisecond time, uint:ms.
T_PsdkReturnCode PsdkOsal_GetTimeMs(uint32_t *ms);
ms:pointer to the got time ms.
Return
The details for the return code please refer to:PsdkErrorCode
function PsdkOsal_Malloc
Function:Allocate size bytes of memory. | product:all |
Allocate size bytes of memory.
note: Users need to apply for memory according to the actual situation of the platform and application.
void *PsdkOsal_Malloc(uint32_t size);
size:uint32_t size that needs allocate.
Return
A void pointer to the allocated memory, if equal to NULL, please do related processing to avoid null pointer crash.
function PsdkOsal_Free
Function:Release allocated memory. | product:all |
Release allocated memory.
void PsdkOsal_Free(void *ptr);
ptr:pointer to the need allocated memory.