准备驱动移植适配Rust
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_module.h
|
||||
* @brief : Board support package module management header file
|
||||
* @brief : 板级支持包模块管理头文件
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
@ -13,7 +13,7 @@
|
||||
#include "hal.h"
|
||||
|
||||
/**
|
||||
* @brief BSP module type definitions
|
||||
* @brief BSP 模块类型定义
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_MODULE_TYPE_LED = 0,
|
||||
@ -31,7 +31,7 @@ typedef enum {
|
||||
} bsp_module_type_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module state definitions
|
||||
* @brief BSP 模块状态定义
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_MODULE_STATE_UNINIT = 0,
|
||||
@ -42,7 +42,7 @@ typedef enum {
|
||||
} bsp_module_state_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module priority definitions
|
||||
* @brief BSP 模块优先级定义
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_MODULE_PRIORITY_HIGHEST = 0,
|
||||
@ -53,36 +53,36 @@ typedef enum {
|
||||
} bsp_module_priority_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module configuration structure
|
||||
* @brief BSP 模块配置结构体
|
||||
*/
|
||||
typedef struct bsp_module_config {
|
||||
bsp_module_type_t type; /*!< Module type */
|
||||
const char* name; /*!< Module name */
|
||||
bsp_module_priority_t priority; /*!< Module priority */
|
||||
uint32_t version; /*!< Module version */
|
||||
uint8_t instance; /*!< Module instance */
|
||||
uint8_t enable; /*!< Module enable flag */
|
||||
void* config_data; /*!< Module configuration data */
|
||||
size_t config_size; /*!< Module configuration size */
|
||||
uint32_t dependencies; /*!< Module dependencies bitmask */
|
||||
bsp_module_type_t type; /*!< 模块类型 */
|
||||
const char* name; /*!< 模块名称 */
|
||||
bsp_module_priority_t priority; /*!< 模块优先级 */
|
||||
uint32_t version; /*!< 模块版本 */
|
||||
uint8_t instance; /*!< 模块实例 */
|
||||
uint8_t enable; /*!< 模块使能标志 */
|
||||
void* config_data; /*!< 模块配置数据 */
|
||||
size_t config_size; /*!< 模块配置大小 */
|
||||
uint32_t dependencies; /*!< 模块依赖位掩码 */
|
||||
} bsp_module_config_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module operations structure
|
||||
* @brief BSP 模块操作结构体
|
||||
*/
|
||||
typedef struct {
|
||||
hal_ret_t (*init)(void* config); /*!< Module initialization function */
|
||||
hal_ret_t (*deinit)(void); /*!< Module deinitialization function */
|
||||
hal_ret_t (*configure)(void* config); /*!< Module configuration function */
|
||||
hal_ret_t (*start)(void); /*!< Module start function */
|
||||
hal_ret_t (*stop)(void); /*!< Module stop function */
|
||||
hal_ret_t (*reset)(void); /*!< Module reset function */
|
||||
bsp_module_state_t (*get_state)(void); /*!< Module get state function */
|
||||
hal_ret_t (*control)(uint32_t cmd, void* param); /*!< Module control function */
|
||||
hal_ret_t (*init)(void* config); /*!< 模块初始化函数 */
|
||||
hal_ret_t (*deinit)(void); /*!< 模块反初始化函数 */
|
||||
hal_ret_t (*configure)(void* config); /*!< 模块配置函数 */
|
||||
hal_ret_t (*start)(void); /*!< 模块启动函数 */
|
||||
hal_ret_t (*stop)(void); /*!< 模块停止函数 */
|
||||
hal_ret_t (*reset)(void); /*!< 模块复位函数 */
|
||||
bsp_module_state_t (*get_state)(void); /*!< 模块获取状态函数 */
|
||||
hal_ret_t (*control)(uint32_t cmd, void* param); /*!< 模块控制函数 */
|
||||
} bsp_module_ops_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module version structure
|
||||
* @brief BSP 模块版本结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t major;
|
||||
@ -91,42 +91,42 @@ typedef struct {
|
||||
} bsp_module_version_t;
|
||||
|
||||
/**
|
||||
* @brief Forward declaration of bsp_module_t
|
||||
* @brief bsp_module_t 的前向声明
|
||||
*/
|
||||
typedef struct bsp_module bsp_module_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module event callback type
|
||||
* @brief BSP 模块事件回调类型
|
||||
*/
|
||||
typedef hal_ret_t (*bsp_module_event_callback_t)(const bsp_module_t* sender, uint32_t event, void* data);
|
||||
|
||||
/**
|
||||
* @brief BSP module structure
|
||||
* @brief BSP 模块结构体
|
||||
*/
|
||||
typedef struct bsp_module {
|
||||
bsp_module_config_t config; /*!< Module configuration */
|
||||
bsp_module_ops_t ops; /*!< Module operations */
|
||||
bsp_module_state_t state; /*!< Module state */
|
||||
bsp_module_version_t version; /*!< Module version */
|
||||
struct bsp_module* next; /*!< Pointer to next module in the list */
|
||||
struct bsp_module* prev; /*!< Pointer to previous module in the list */
|
||||
void* private_data; /*!< Module private data */
|
||||
bsp_module_event_callback_t event_callback; /*!< Event callback */
|
||||
bsp_module_config_t config; /*!< 模块配置 */
|
||||
bsp_module_ops_t ops; /*!< 模块操作 */
|
||||
bsp_module_state_t state; /*!< 模块状态 */
|
||||
bsp_module_version_t version; /*!< 模块版本 */
|
||||
struct bsp_module* next; /*!< 链表中下一个模块的指针 */
|
||||
struct bsp_module* prev; /*!< 链表中上一个模块的指针 */
|
||||
void* private_data; /*!< 模块私有数据 */
|
||||
bsp_module_event_callback_t event_callback; /*!< 事件回调 */
|
||||
} bsp_module_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module event definitions
|
||||
* @brief BSP 模块事件定义
|
||||
*/
|
||||
#define BSP_MODULE_EVENT_INIT (1 << 0) /*!< Module initialized */
|
||||
#define BSP_MODULE_EVENT_DEINIT (1 << 1) /*!< Module deinitialized */
|
||||
#define BSP_MODULE_EVENT_START (1 << 2) /*!< Module started */
|
||||
#define BSP_MODULE_EVENT_STOP (1 << 3) /*!< Module stopped */
|
||||
#define BSP_MODULE_EVENT_ERROR (1 << 4) /*!< Module error */
|
||||
#define BSP_MODULE_EVENT_CONFIG (1 << 5) /*!< Module configured */
|
||||
#define BSP_MODULE_EVENT_CUSTOM (1 << 8) /*!< Custom module event base */
|
||||
#define BSP_MODULE_EVENT_INIT (1 << 0) /*!< 模块已初始化 */
|
||||
#define BSP_MODULE_EVENT_DEINIT (1 << 1) /*!< 模块已反初始化 */
|
||||
#define BSP_MODULE_EVENT_START (1 << 2) /*!< 模块已启动 */
|
||||
#define BSP_MODULE_EVENT_STOP (1 << 3) /*!< 模块已停止 */
|
||||
#define BSP_MODULE_EVENT_ERROR (1 << 4) /*!< 模块错误 */
|
||||
#define BSP_MODULE_EVENT_CONFIG (1 << 5) /*!< 模块已配置 */
|
||||
#define BSP_MODULE_EVENT_CUSTOM (1 << 8) /*!< 自定义模块事件基础 */
|
||||
|
||||
/**
|
||||
* @brief BSP module auto-registration macros
|
||||
* @brief BSP 模块自动注册宏
|
||||
*/
|
||||
#define BSP_MODULE_REGISTER(module) \
|
||||
static const bsp_module_config_t __bsp_module_##module##_config = { \
|
||||
@ -173,228 +173,228 @@ typedef struct bsp_module {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief BSP module manager structure
|
||||
* @brief BSP 模块管理器结构体
|
||||
*/
|
||||
typedef struct {
|
||||
bsp_module_t* modules[BSP_MODULE_TYPE_MAX]; /*!< Modules by type */
|
||||
bsp_module_t* module_list; /*!< Linked list of all modules */
|
||||
uint32_t module_count; /*!< Total number of modules */
|
||||
bsp_module_t* modules[BSP_MODULE_TYPE_MAX]; /*!< 按类型存储的模块 */
|
||||
bsp_module_t* module_list; /*!< 所有模块的链表 */
|
||||
uint32_t module_count; /*!< 模块总数 */
|
||||
} bsp_module_manager_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize BSP module manager
|
||||
* @retval HAL status code
|
||||
* @brief 初始化 BSP 模块管理器
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_manager_init(void);
|
||||
|
||||
/**
|
||||
* @brief Register a BSP module
|
||||
* @param module: Pointer to module structure
|
||||
* @retval HAL status code
|
||||
* @brief 注册一个 BSP 模块
|
||||
* @param module: 指向模块结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_register(bsp_module_t* module);
|
||||
|
||||
/**
|
||||
* @brief Unregister a BSP module
|
||||
* @param module: Pointer to module structure
|
||||
* @retval HAL status code
|
||||
* @brief 注销一个 BSP 模块
|
||||
* @param module: 指向模块结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_unregister(bsp_module_t* module);
|
||||
|
||||
/**
|
||||
* @brief Initialize all registered BSP modules
|
||||
* @retval HAL status code
|
||||
* @brief 初始化所有注册的 BSP 模块
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_init_all(void);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize all registered BSP modules
|
||||
* @retval HAL status code
|
||||
* @brief 反初始化所有注册的 BSP 模块
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_deinit_all(void);
|
||||
|
||||
/**
|
||||
* @brief Start all registered BSP modules
|
||||
* @retval HAL status code
|
||||
* @brief 启动所有注册的 BSP 模块
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_start_all(void);
|
||||
|
||||
/**
|
||||
* @brief Stop all registered BSP modules
|
||||
* @retval HAL status code
|
||||
* @brief 停止所有注册的 BSP 模块
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_stop_all(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @retval HAL status code
|
||||
* @brief 初始化指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_init(bsp_module_type_t type, uint8_t instance);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @retval HAL status code
|
||||
* @brief 反初始化指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_deinit(bsp_module_type_t type, uint8_t instance);
|
||||
|
||||
/**
|
||||
* @brief Configure a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param config: Module configuration data
|
||||
* @param size: Module configuration size
|
||||
* @retval HAL status code
|
||||
* @brief 配置指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param config: 模块配置数据
|
||||
* @param size: 模块配置大小
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_configure(bsp_module_type_t type, uint8_t instance, void* config, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Start a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @retval HAL status code
|
||||
* @brief 启动指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_start(bsp_module_type_t type, uint8_t instance);
|
||||
|
||||
/**
|
||||
* @brief Stop a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @retval HAL status code
|
||||
* @brief 停止指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_stop(bsp_module_type_t type, uint8_t instance);
|
||||
|
||||
/**
|
||||
* @brief Reset a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @retval HAL status code
|
||||
* @brief 复位指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_reset(bsp_module_type_t type, uint8_t instance);
|
||||
|
||||
/**
|
||||
* @brief Get state of a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param state: Pointer to store module state
|
||||
* @retval HAL status code
|
||||
* @brief 获取指定 BSP 模块的状态
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param state: 存储模块状态的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_get_state(bsp_module_type_t type, uint8_t instance, bsp_module_state_t* state);
|
||||
|
||||
/**
|
||||
* @brief Control a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param cmd: Control command
|
||||
* @param param: Control parameter
|
||||
* @retval HAL status code
|
||||
* @brief 控制指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param cmd: 控制命令
|
||||
* @param param: 控制参数
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_control(bsp_module_type_t type, uint8_t instance, uint32_t cmd, void* param);
|
||||
|
||||
/**
|
||||
* @brief Get a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @retval Pointer to module structure, or NULL if not found
|
||||
* @brief 获取指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @retval 指向模块结构体的指针,未找到返回 NULL
|
||||
*/
|
||||
bsp_module_t* bsp_module_get(bsp_module_type_t type, uint8_t instance);
|
||||
|
||||
/**
|
||||
* @brief Get all modules of a specific type
|
||||
* @param type: Module type
|
||||
* @retval Pointer to module list, or NULL if no modules found
|
||||
* @brief 获取指定类型的所有模块
|
||||
* @param type: 模块类型
|
||||
* @retval 指向模块列表的指针,未找到模块返回 NULL
|
||||
*/
|
||||
bsp_module_t* bsp_module_get_by_type(bsp_module_type_t type);
|
||||
|
||||
/**
|
||||
* @brief Get module by name
|
||||
* @param name: Module name
|
||||
* @retval Pointer to module structure, or NULL if not found
|
||||
* @brief 通过名称获取模块
|
||||
* @param name: 模块名称
|
||||
* @retval 指向模块结构体的指针,未找到返回 NULL
|
||||
*/
|
||||
bsp_module_t* bsp_module_get_by_name(const char* name);
|
||||
|
||||
/**
|
||||
* @brief Get total number of registered modules
|
||||
* @retval Number of registered modules
|
||||
* @brief 获取注册模块的总数
|
||||
* @retval 注册模块的数量
|
||||
*/
|
||||
uint32_t bsp_module_get_count(void);
|
||||
|
||||
/**
|
||||
* @brief Check if all dependencies of a module are satisfied
|
||||
* @param module: Pointer to module structure
|
||||
* @retval HAL status code
|
||||
* @brief 检查模块的所有依赖是否满足
|
||||
* @param module: 指向模块结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_check_dependencies(const bsp_module_t* module);
|
||||
|
||||
/**
|
||||
* @brief Get module manager instance
|
||||
* @retval Pointer to module manager structure
|
||||
* @brief 获取模块管理器实例
|
||||
* @retval 指向模块管理器结构体的指针
|
||||
*/
|
||||
bsp_module_manager_t* bsp_module_get_manager(void);
|
||||
|
||||
/**
|
||||
* @brief Register a module event callback
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param callback: Event callback function
|
||||
* @retval HAL status code
|
||||
* @brief 注册模块事件回调
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param callback: 事件回调函数
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_register_event_callback(bsp_module_type_t type, uint8_t instance, bsp_module_event_callback_t callback);
|
||||
|
||||
/**
|
||||
* @brief Trigger a module event
|
||||
* @param module: Pointer to module structure
|
||||
* @param event: Event to trigger
|
||||
* @param data: Event data
|
||||
* @retval HAL status code
|
||||
* @brief 触发模块事件
|
||||
* @param module: 指向模块结构体的指针
|
||||
* @param event: 要触发的事件
|
||||
* @param data: 事件数据
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_trigger_event(const bsp_module_t* module, uint32_t event, void* data);
|
||||
|
||||
/**
|
||||
* @brief Find modules by priority range
|
||||
* @param min_priority: Minimum priority
|
||||
* @param max_priority: Maximum priority
|
||||
* @param count: Pointer to store number of modules found
|
||||
* @retval Pointer to array of module pointers, or NULL if no modules found
|
||||
* @brief 按优先级范围查找模块
|
||||
* @param min_priority: 最低优先级
|
||||
* @param max_priority: 最高优先级
|
||||
* @param count: 存储找到的模块数量的指针
|
||||
* @retval 指向模块指针数组的指针,未找到模块返回 NULL
|
||||
*/
|
||||
bsp_module_t** bsp_module_find_by_priority_range(bsp_module_priority_t min_priority, bsp_module_priority_t max_priority, uint32_t* count);
|
||||
|
||||
/**
|
||||
* @brief Set module enable/disable state
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param enable: Enable flag
|
||||
* @retval HAL status code
|
||||
* @brief 设置模块使能/禁用状态
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param enable: 使能标志
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_set_enable(bsp_module_type_t type, uint8_t instance, uint8_t enable);
|
||||
|
||||
/**
|
||||
* @brief Check if module is enabled
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param enable: Pointer to store enable state
|
||||
* @retval HAL status code
|
||||
* @brief 检查模块是否启用
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param enable: 存储使能状态的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_is_enabled(bsp_module_type_t type, uint8_t instance, uint8_t* enable);
|
||||
|
||||
/**
|
||||
* @brief Set module priority
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param priority: New priority
|
||||
* @retval HAL status code
|
||||
* @brief 设置模块优先级
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param priority: 新优先级
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_set_priority(bsp_module_type_t type, uint8_t instance, bsp_module_priority_t priority);
|
||||
|
||||
/**
|
||||
* @brief Get module priority
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @param priority: Pointer to store priority
|
||||
* @retval HAL return code
|
||||
* @brief 获取模块优先级
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @param priority: 存储优先级的指针
|
||||
* @retval HAL 返回码
|
||||
*/
|
||||
hal_ret_t bsp_module_get_priority(bsp_module_type_t type, uint8_t instance, bsp_module_priority_t* priority);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user