Skip to main content

Platform Porting

The header file related to cross-platform functionality is uav_platform.h. This document describes the key information and usage methods for the structures and function prototypes in the uav_platform.h file.

Table of Contents

  • Macro Definitions, Enumerations, and Structures
    E_UAVHalUartBaudRate
    T_UAVHalUartHandler
    T_UAVOsalHandler
    T_UAVUartStatus
    T_UAVTime

  • Function Prototypes
    UAV_Platform_RegHalUartHandler
    UAV_Platform_RegOsalHandler
    UAV_Platform_GetOsalHandler

Macro Definitions

/**
* @brief Platform handle of thread task operation.
*/
typedef void *T_UAVTaskHandle;

/**
* @brief Platform handle of mutex operation.
*/
typedef void *T_UAVMutexHandle;

/**
* @brief Platform handle of semaphore operation.
*/
typedef void *T_UAVSemaHandle;

/**
* @brief Platform handle of timer operation.
*/
typedef void *T_UAVTimerHandle;

Enumerations

typedef enum E_UAVHalUartBaudRate

Serial port baud rate macro definition.

Note:

  • This macro definition needs to be used to initialize the baudRateIndex parameter in the serial port handle before registering the serial port.
typedef enum 
{
UAV_BAUDRATE_115200=0,
UAV_BAUDRATE_19200,
UAV_BAUDRATE_230400,
UAV_BAUDRATE_460800,
UAV_BAUDRATE_1000000,
UAV_BAUDRATE_2000000,
UAV_BAUDRATE_MAX,
}E_UAVHalUartBaudRate;

Structures

typedef struct T_UAVHalUartHandler

Serial communication interface.

Note:

  • Before registering the communication interface, the user must implement this interface.
  • For RTOS platforms, only serial communication handles are currently supported. Users can register USB and network communication interfaces through the serial interface.
typedef struct
{
E_UAVHalUartBaudRate baudRateIndex;
T_UAVReturnCode (*init)(void);
T_UAVReturnCode (*deInit)(void);
T_UAVReturnCode (*write)(const uint8_t *buf, uint32_t len);
T_UAVReturnCode (*read)(uint8_t *buf, uint32_t len, uint32_t *realLen);
T_UAVReturnCode (*setBaudRate)(E_UAVHalUartBaudRate baudRateIndex);
T_UAVReturnCode (*getStatus)(void);
uint32_t baudRate;
}T_UAVHalUartHandler;
  • Parameters
    baudRateIndex:Serial port baud rate setting.
    init:Serial port initialization.
    deinit:Serial port de-initialization.
    write:Serial port write function.
    read:Serial port read function.
    setBaudRate:Set serial port baud rate.
    getStatus:Get current serial port status.

typedef struct T_UAVOsalHandler

Operating System Interface.

typedef struct {
int (*TaskCreate)(const char *name, void *(*taskFunc)(void *), uint32_t stackSize, void *arg, uint32_t priority,T_UAVTaskHandle *task);
int (*TaskStart)(T_UAVTaskHandle task);
int (*TaskDestroy)(T_UAVTaskHandle task);
int (*TaskSleepMs)(uint32_t time_ms);
int (*MutexCreate)(T_UAVMutexHandle *mutex);
int (*MutexDestroy)(T_UAVMutexHandle mutex);
int (*MutexLock)(T_UAVMutexHandle mutex);
int (*MutexUnlock)(T_UAVMutexHandle mutex);
int (*SemaphoreCreate)(uint32_t initValue, T_UAVSemaHandle *semaphore);
int (*SemaphoreDestroy)(T_UAVSemaHandle semaphore);
int (*SemaphoreWait)(T_UAVSemaHandle semaphore);
int (*SemaphoreTimedWait)(T_UAVSemaHandle semaphore, uint32_t wait_time_ms);
int (*SemaphorePost)(T_UAVSemaHandle semaphore);
int (*GetTimeMs)(uint32_t *ms);
int (*GetTimeUs)(uint64_t *us);
void *(*Malloc)(uint32_t size);
void (*Free)(void *ptr);
int (*MsToTicks)(uint32_t ms);
void (*TaskList)(char *list);
uint32_t (*FreeHeapSize)(void);
} T_UAVOsalHandler;

typedef struct T_UAVUartStatus

typedef struct 
{
bool isConnect;

}T_UAVUartStatus;

typedef struct T_UAVTime

Date and Time

typedef struct {
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
} T_UAVTime;

Function Prototypes

function UAV_Platform_RegHalUartHandler

  • Function: Register communication interface function.
  • product: all

Register the callback function for adapting the payload device communication interface.

Note:

  • Before registering the communication interface callback function, please test that the function can properly write configuration information to the HAL layer interface.
  • Call this interface before using the payload device functions; otherwise, the payload device will not operate properly.
  • On RTOS platforms, only the T_UAVUarHalHandler interface registration is supported, and there are no separate USB or network communication interfaces.
T_UAVReturnCode UAV_Platform_RegHalUartHandler(const T_UAVHalUartHandler *halUartHandler);
  • ParameterhalUartHandler:Pointer to the payload device operating system communication interface function.
  • Return Value Outputs the corresponding return value based on the program execution status. For details, refer to: UAV Error Codes.

function UAV_Platform_RegOsalHandler

  • Function: Register OSAL interface function.
  • product: all
T_UAVReturnCode UAV_Platform_RegOsalHandler(const T_UAVOsalHandler *osalHandler);
  • ParameterosalHandler:Pointer to the platform's OSAL interface handler.
  • Return Value Outputs the corresponding return value based on the program execution status. For details, refer to: UAV Error Codes.

function UAV_Platform_GetOsalHandler

  • Function: Get the OSAL interface handler.
  • product: all
T_UAVOsalHandler *UAV_Platform_GetOsalHandler(void);
  • Parameternone
  • Return ValueT_UAVOsalHandler * :OSAL handler,=0 if retrieval fails.