平台移植
跨平台相关功能的头文件为 uav_platform.h
,本文档描述了 uav_platform.h
文件中结构体和函数原型的关键信息和使用方法
目录
宏定义、枚举与结构体
E_UAVHalUartBaudRate
T_UAVHalUartHandler
T_UAVOsalHandler
T_UAVUartStatus
T_UAVTime函数原型
UAV_Platform_RegHalUartHandler
UAV_Platform_RegOsalHandler
UAV_Platform_GetOsalHandler
宏定义
/**
* @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;
枚举
typedef enum E_UAVHalUartBaudRate
串口波特率宏定义。
说明:
- 需要在注册串口前,用此宏定义初始化串口句柄中的波特率参数
baudRateIndex
。
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;
结构体
typedef struct T_UAVHalUartHandler
串口通讯接口。
说明:
- 在注册通讯接口前,用户需实现此的接口。
- 对于 RTOS 平台,暂时只支持串口通讯句柄, 用户可通过串口接口实现 USB 和网络的通讯接口注册。
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;
- 参数
baudRateIndex:串口波特率设置。
init:串口初始化。
deinit:串口去初始化。
write:串口写函数。
read:串口读函数。
setBaudRate:设置串口波特率。
getStatus:获取串口当前状态。
typedef struct T_UAVOsalHandler
操作系统接口。
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
日期时间。
typedef struct {
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
} T_UAVTime;
函数原型
function UAV_Platform_RegHalUartHandler
- 功能: 注册通讯接口函数。
- product: all。
注册适配负载设备通讯接口的回调函数
说明:
- 在注册通讯接口的回调函数前,请测试该函数能够正常写入 Hal 层接口配置信息。
- 请在使用负载设备的功能前先调用该接口,否则负载设备将无法正常运行。
- RTOS 平台下,暂只支持
T_UAVUarHalHandler
接口注册,没有独立的 USB 和网络的通讯接口。
T_UAVReturnCode UAV_Platform_RegHalUartHandler(const T_UAVHalUartHandler *halUartHandler);
- 参数halUartHandler:指向负载设备操作系统通讯接口函数。
- 返回值 根据程序执行的情况输出对应的返回值,详情请参见:UAV 错误码。
function UAV_Platform_RegOsalHandler
- 功能: 注册 Osal 接口函数。
- product: all。
T_UAVReturnCode UAV_Platform_RegOsalHandler(const T_UAVOsalHandler *osalHandler);
- 参数osalHandler:指向平台的 Osal 接口处理程序的指针。
- 返回值 根据程序执行的情况输出对应的返回值,详情请参见:UAV 错误码。
function UAV_Platform_GetOsalHandler
- 功能: 获取 Osal 接口的处理程序。
- product: all。
T_UAVOsalHandler *UAV_Platform_GetOsalHandler(void);
- 参数none:
- 返回值T_UAVOsalHandler * :Osal句柄,=0 时获取失败。