进一步迭代优化统一管理
This commit is contained in:
@ -11,39 +11,53 @@
|
||||
#define BSP_BOARD_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "hal.h"
|
||||
#include "hal_gpio.h"
|
||||
#include "hal_uart.h"
|
||||
#include "hal_spi.h"
|
||||
#include "hal_i2c.h"
|
||||
#include "hal_can.h"
|
||||
#include "hal_adc.h"
|
||||
|
||||
/**
|
||||
* @brief BSP configuration version
|
||||
*/
|
||||
#define BSP_CONFIG_VERSION_MAJOR 1
|
||||
#define BSP_CONFIG_VERSION_MINOR 0
|
||||
#define BSP_CONFIG_VERSION_PATCH 0
|
||||
#define BSP_CONFIG_VERSION (BSP_CONFIG_VERSION_MAJOR << 16 | BSP_CONFIG_VERSION_MINOR << 8 | BSP_CONFIG_VERSION_PATCH)
|
||||
|
||||
/**
|
||||
* @brief Board LED configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
hal_gpio_port_t port;
|
||||
hal_gpio_pin_t pin;
|
||||
hal_gpio_mode_t mode;
|
||||
hal_gpio_speed_t speed;
|
||||
hal_gpio_pull_t pull;
|
||||
uint8_t enable; /*!< LED enable flag */
|
||||
hal_gpio_port_t port; /*!< LED GPIO port */
|
||||
hal_gpio_pin_t pin; /*!< LED GPIO pin */
|
||||
hal_gpio_mode_t mode; /*!< LED GPIO mode */
|
||||
hal_gpio_speed_t speed; /*!< LED GPIO speed */
|
||||
hal_gpio_pull_t pull; /*!< LED GPIO pull configuration */
|
||||
} bsp_led_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board button configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
hal_gpio_port_t port;
|
||||
hal_gpio_pin_t pin;
|
||||
hal_gpio_mode_t mode;
|
||||
hal_gpio_speed_t speed;
|
||||
hal_gpio_pull_t pull;
|
||||
uint8_t active_high;
|
||||
hal_gpio_port_t port; /*!< Button GPIO port */
|
||||
hal_gpio_pin_t pin; /*!< Button GPIO pin */
|
||||
hal_gpio_mode_t mode; /*!< Button GPIO mode */
|
||||
hal_gpio_speed_t speed; /*!< Button GPIO speed */
|
||||
hal_gpio_pull_t pull; /*!< Button GPIO pull configuration */
|
||||
uint8_t active_high; /*!< Button active high flag */
|
||||
} bsp_button_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board buttons configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t count;
|
||||
const bsp_button_config_t* buttons;
|
||||
uint8_t enable; /*!< Buttons enable flag */
|
||||
uint8_t count; /*!< Number of buttons */
|
||||
const bsp_button_config_t* buttons; /*!< Pointer to buttons configuration array */
|
||||
} bsp_buttons_config_t;
|
||||
|
||||
/**
|
||||
@ -63,62 +77,226 @@ typedef enum {
|
||||
* @brief Board UART configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
bsp_uart_instance_t instance;
|
||||
uint32_t baudrate;
|
||||
hal_uart_parity_t parity;
|
||||
hal_uart_stopbits_t stopbits;
|
||||
hal_uart_databits_t databits;
|
||||
hal_gpio_port_t tx_port;
|
||||
hal_gpio_pin_t tx_pin;
|
||||
hal_gpio_port_t rx_port;
|
||||
hal_gpio_pin_t rx_pin;
|
||||
uint8_t enable; /*!< UART enable flag */
|
||||
bsp_uart_instance_t instance; /*!< UART instance */
|
||||
uint32_t baudrate; /*!< UART baudrate */
|
||||
hal_uart_parity_t parity; /*!< UART parity */
|
||||
hal_uart_stopbits_t stopbits; /*!< UART stop bits */
|
||||
hal_uart_databits_t databits; /*!< UART data bits */
|
||||
hal_gpio_port_t tx_port; /*!< UART TX port */
|
||||
hal_gpio_pin_t tx_pin; /*!< UART TX pin */
|
||||
hal_gpio_port_t rx_port; /*!< UART RX port */
|
||||
hal_gpio_pin_t rx_pin; /*!< UART RX pin */
|
||||
} bsp_uart_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board SPI configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
hal_spi_instance_t instance;
|
||||
hal_spi_mode_t mode;
|
||||
uint32_t baudrate;
|
||||
hal_spi_polarity_t polarity;
|
||||
hal_spi_phase_t phase;
|
||||
hal_spi_databits_t databits;
|
||||
uint8_t enable; /*!< SPI enable flag */
|
||||
hal_spi_instance_t instance; /*!< SPI instance */
|
||||
hal_spi_mode_t mode; /*!< SPI mode */
|
||||
uint32_t baudrate; /*!< SPI baudrate */
|
||||
hal_spi_polarity_t polarity; /*!< SPI clock polarity */
|
||||
hal_spi_phase_t phase; /*!< SPI clock phase */
|
||||
hal_spi_databits_t databits; /*!< SPI data bits */
|
||||
hal_gpio_port_t sck_port; /*!< SPI SCK port */
|
||||
hal_gpio_pin_t sck_pin; /*!< SPI SCK pin */
|
||||
hal_gpio_port_t miso_port; /*!< SPI MISO port */
|
||||
hal_gpio_pin_t miso_pin; /*!< SPI MISO pin */
|
||||
hal_gpio_port_t mosi_port; /*!< SPI MOSI port */
|
||||
hal_gpio_pin_t mosi_pin; /*!< SPI MOSI pin */
|
||||
} bsp_spi_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board I2C configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< I2C enable flag */
|
||||
hal_i2c_instance_t instance; /*!< I2C instance */
|
||||
hal_i2c_speed_t speed; /*!< I2C speed */
|
||||
hal_i2c_address_mode_t address_mode; /*!< I2C address mode */
|
||||
hal_i2c_dutycycle_t dutycycle; /*!< I2C duty cycle */
|
||||
uint16_t own_address1; /*!< I2C own address 1 */
|
||||
hal_gpio_port_t scl_port; /*!< I2C SCL port */
|
||||
hal_gpio_pin_t scl_pin; /*!< I2C SCL pin */
|
||||
hal_gpio_port_t sda_port; /*!< I2C SDA port */
|
||||
hal_gpio_pin_t sda_pin; /*!< I2C SDA pin */
|
||||
} bsp_i2c_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board CAN configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< CAN enable flag */
|
||||
hal_can_instance_t instance; /*!< CAN instance */
|
||||
hal_can_mode_t mode; /*!< CAN mode */
|
||||
uint32_t prescaler; /*!< CAN prescaler */
|
||||
uint8_t sync_jump_width; /*!< CAN sync jump width */
|
||||
uint8_t time_segment1; /*!< CAN time segment 1 */
|
||||
uint8_t time_segment2; /*!< CAN time segment 2 */
|
||||
hal_gpio_port_t rx_port; /*!< CAN RX port */
|
||||
hal_gpio_pin_t rx_pin; /*!< CAN RX pin */
|
||||
hal_gpio_port_t tx_port; /*!< CAN TX port */
|
||||
hal_gpio_pin_t tx_pin; /*!< CAN TX pin */
|
||||
} bsp_can_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board ADC channel configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< ADC channel enable flag */
|
||||
hal_adc_channel_t channel; /*!< ADC channel */
|
||||
hal_adc_sampletime_t sampletime; /*!< ADC sample time */
|
||||
uint8_t rank; /*!< ADC channel rank */
|
||||
} bsp_adc_channel_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board ADC configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t enable; /*!< ADC enable flag */
|
||||
hal_adc_instance_t instance; /*!< ADC instance */
|
||||
hal_adc_resolution_t resolution; /*!< ADC resolution */
|
||||
uint8_t scan_conversion_mode; /*!< ADC scan conversion mode */
|
||||
uint8_t continuous_conversion_mode; /*!< ADC continuous conversion mode */
|
||||
uint8_t channel_count; /*!< Number of ADC channels */
|
||||
const bsp_adc_channel_config_t* channels; /*!< Pointer to ADC channels configuration array */
|
||||
} bsp_adc_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board W25QXX configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
hal_gpio_port_t cs_port;
|
||||
hal_gpio_pin_t cs_pin;
|
||||
bsp_spi_config_t spi_config;
|
||||
uint8_t enable; /*!< W25QXX enable flag */
|
||||
hal_gpio_port_t cs_port; /*!< W25QXX CS port */
|
||||
hal_gpio_pin_t cs_pin; /*!< W25QXX CS pin */
|
||||
uint8_t spi_instance; /*!< SPI instance used by W25QXX */
|
||||
} bsp_w25qxx_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board peripheral initialization function type
|
||||
*/
|
||||
typedef void (*bsp_periph_init_func_t)(const void* config);
|
||||
typedef hal_ret_t (*bsp_periph_init_func_t)(const void* config);
|
||||
|
||||
/**
|
||||
* @brief Board ID structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t vendor_id; /*!< Board vendor ID */
|
||||
uint16_t product_id; /*!< Board product ID */
|
||||
uint32_t serial_number; /*!< Board serial number */
|
||||
} bsp_board_id_t;
|
||||
|
||||
/**
|
||||
* @brief Board feature flags
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_BOARD_FEATURE_LED = (1 << 0), /*!< Board has LED support */
|
||||
BSP_BOARD_FEATURE_BUTTON = (1 << 1), /*!< Board has button support */
|
||||
BSP_BOARD_FEATURE_UART = (1 << 2), /*!< Board has UART support */
|
||||
BSP_BOARD_FEATURE_SPI = (1 << 3), /*!< Board has SPI support */
|
||||
BSP_BOARD_FEATURE_I2C = (1 << 4), /*!< Board has I2C support */
|
||||
BSP_BOARD_FEATURE_CAN = (1 << 5), /*!< Board has CAN support */
|
||||
BSP_BOARD_FEATURE_ADC = (1 << 6), /*!< Board has ADC support */
|
||||
BSP_BOARD_FEATURE_DAC = (1 << 7), /*!< Board has DAC support */
|
||||
BSP_BOARD_FEATURE_TIMER = (1 << 8), /*!< Board has TIMER support */
|
||||
BSP_BOARD_FEATURE_RTC = (1 << 9), /*!< Board has RTC support */
|
||||
BSP_BOARD_FEATURE_W25QXX = (1 << 10), /*!< Board has W25QXX support */
|
||||
BSP_BOARD_FEATURE_DMA = (1 << 11), /*!< Board has DMA support */
|
||||
BSP_BOARD_FEATURE_ETH = (1 << 12), /*!< Board has ETH support */
|
||||
BSP_BOARD_FEATURE_USB = (1 << 13), /*!< Board has USB support */
|
||||
BSP_BOARD_FEATURE_SDIO = (1 << 14), /*!< Board has SDIO support */
|
||||
BSP_BOARD_FEATURE_FSMC = (1 << 15), /*!< Board has FSMC support */
|
||||
} bsp_board_feature_t;
|
||||
|
||||
/**
|
||||
* @brief Board hardware information structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t clock_speed; /*!< Board clock speed */
|
||||
uint32_t flash_size; /*!< Flash size in bytes */
|
||||
uint32_t ram_size; /*!< RAM size in bytes */
|
||||
uint32_t eeprom_size; /*!< EEPROM size in bytes */
|
||||
uint32_t sram_size; /*!< SRAM size in bytes */
|
||||
uint8_t cpu_core; /*!< CPU core type */
|
||||
uint8_t cpu_bits; /*!< CPU bits (32 or 64) */
|
||||
} bsp_board_hw_info_t;
|
||||
|
||||
/**
|
||||
* @brief Board peripheral configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
/* UART configurations */
|
||||
uint8_t uart_count; /*!< Number of UARTs */
|
||||
const bsp_uart_config_t* uarts; /*!< Pointer to UARTs configuration array */
|
||||
|
||||
/* SPI configurations */
|
||||
uint8_t spi_count; /*!< Number of SPIs */
|
||||
const bsp_spi_config_t* spis; /*!< Pointer to SPIs configuration array */
|
||||
|
||||
/* I2C configurations */
|
||||
uint8_t i2c_count; /*!< Number of I2Cs */
|
||||
const bsp_i2c_config_t* i2cs; /*!< Pointer to I2Cs configuration array */
|
||||
|
||||
/* CAN configurations */
|
||||
uint8_t can_count; /*!< Number of CANs */
|
||||
const bsp_can_config_t* cans; /*!< Pointer to CANs configuration array */
|
||||
|
||||
/* ADC configurations */
|
||||
uint8_t adc_count; /*!< Number of ADCs */
|
||||
const bsp_adc_config_t* adcs; /*!< Pointer to ADCs configuration array */
|
||||
} bsp_board_periph_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board initialization function pointers structure
|
||||
*/
|
||||
typedef struct {
|
||||
bsp_periph_init_func_t led_init; /*!< LED initialization function */
|
||||
bsp_periph_init_func_t button_init; /*!< Button initialization function */
|
||||
bsp_periph_init_func_t uart_init; /*!< UART initialization function */
|
||||
bsp_periph_init_func_t spi_init; /*!< SPI initialization function */
|
||||
bsp_periph_init_func_t i2c_init; /*!< I2C initialization function */
|
||||
bsp_periph_init_func_t can_init; /*!< CAN initialization function */
|
||||
bsp_periph_init_func_t adc_init; /*!< ADC initialization function */
|
||||
bsp_periph_init_func_t w25qxx_init; /*!< W25QXX initialization function */
|
||||
} bsp_board_init_funcs_t;
|
||||
|
||||
/**
|
||||
* @brief Board configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
const char* name;
|
||||
bsp_led_config_t led;
|
||||
bsp_buttons_config_t buttons;
|
||||
bsp_uart_config_t uart;
|
||||
bsp_w25qxx_config_t w25qxx;
|
||||
uint32_t version; /*!< Configuration version */
|
||||
const char* name; /*!< Board name */
|
||||
const char* description; /*!< Board description */
|
||||
bsp_board_id_t id; /*!< Board ID information */
|
||||
|
||||
/* Initialization function pointers */
|
||||
bsp_periph_init_func_t led_init;
|
||||
bsp_periph_init_func_t button_init;
|
||||
bsp_periph_init_func_t uart_init;
|
||||
bsp_periph_init_func_t w25qxx_init;
|
||||
/* Board features */
|
||||
uint32_t features; /*!< Board feature flags */
|
||||
|
||||
/* Hardware information */
|
||||
bsp_board_hw_info_t hw_info; /*!< Hardware information */
|
||||
|
||||
/* Peripheral configurations */
|
||||
bsp_led_config_t led; /*!< LED configuration */
|
||||
bsp_buttons_config_t buttons; /*!< Buttons configuration */
|
||||
bsp_w25qxx_config_t w25qxx; /*!< W25QXX configuration */
|
||||
|
||||
/* Peripheral arrays */
|
||||
bsp_board_periph_config_t periphs; /*!< Peripheral configurations */
|
||||
|
||||
/* Initialization functions */
|
||||
bsp_board_init_funcs_t init_funcs; /*!< Initialization function pointers */
|
||||
|
||||
/* Additional board-specific configuration */
|
||||
uint32_t clock_speed;
|
||||
uint8_t uart_count;
|
||||
void* custom_config; /*!< Custom board configuration pointer */
|
||||
size_t custom_config_size; /*!< Custom board configuration size */
|
||||
|
||||
/* Board revision information */
|
||||
uint8_t major_rev; /*!< Major revision */
|
||||
uint8_t minor_rev; /*!< Minor revision */
|
||||
uint8_t patch_rev; /*!< Patch revision */
|
||||
const char* revision_desc; /*!< Revision description */
|
||||
} bsp_board_config_t;
|
||||
|
||||
/**
|
||||
@ -128,8 +306,9 @@ extern const bsp_board_config_t stm32f407vet6_board_config;
|
||||
|
||||
/**
|
||||
* @brief Board hardware initialization
|
||||
* @retval HAL status code
|
||||
*/
|
||||
void bsp_board_init(void);
|
||||
hal_ret_t bsp_board_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get board name
|
||||
@ -137,4 +316,10 @@ void bsp_board_init(void);
|
||||
*/
|
||||
const char* bsp_board_get_name(void);
|
||||
|
||||
/**
|
||||
* @brief Get board configuration
|
||||
* @retval Pointer to board configuration structure
|
||||
*/
|
||||
const bsp_board_config_t* bsp_board_get_config(void);
|
||||
|
||||
#endif /* BSP_BOARD_H */
|
||||
|
||||
@ -37,16 +37,16 @@ const bsp_board_config_t* bsp_board_get_by_name(const char* name);
|
||||
/**
|
||||
* @brief Set current board configuration by index
|
||||
* @param index: Board configuration index
|
||||
* @retval 0 if successful, -1 if invalid index
|
||||
* @retval HAL status code
|
||||
*/
|
||||
int8_t bsp_board_set_by_index(uint8_t index);
|
||||
hal_ret_t bsp_board_set_by_index(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief Set current board configuration by name
|
||||
* @param name: Board name string
|
||||
* @retval 0 if successful, -1 if not found
|
||||
* @retval HAL status code
|
||||
*/
|
||||
int8_t bsp_board_set_by_name(const char* name);
|
||||
hal_ret_t bsp_board_set_by_name(const char* name);
|
||||
|
||||
/**
|
||||
* @brief Get current board configuration
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_config.h
|
||||
* @brief : Board support package configuration file
|
||||
* @brief : Board support package configuration file header
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
@ -10,42 +10,175 @@
|
||||
#ifndef BSP_CONFIG_H
|
||||
#define BSP_CONFIG_H
|
||||
|
||||
#include "hal_gpio.h"
|
||||
#include "hal_uart.h"
|
||||
#include <stdio.h>
|
||||
#include "bsp_module.h"
|
||||
#include "bsp_board.h"
|
||||
#include "hal.h"
|
||||
|
||||
/**
|
||||
* @brief Board name definition
|
||||
* @brief BSP configuration file format definitions
|
||||
*/
|
||||
#define BOARD_NAME "STM32F407VET6"
|
||||
#define BSP_CONFIG_FILE_VERSION "1.0.0"
|
||||
#define BSP_CONFIG_MAX_LINE_LENGTH 256
|
||||
#define BSP_CONFIG_MAX_SECTION_NAME_LENGTH 32
|
||||
#define BSP_CONFIG_MAX_KEY_NAME_LENGTH 32
|
||||
#define BSP_CONFIG_MAX_VALUE_LENGTH 128
|
||||
|
||||
/**
|
||||
* @brief LED hardware configuration
|
||||
* @brief BSP configuration section type
|
||||
*/
|
||||
#define BSP_LED_PORT HAL_GPIO_PORT_A
|
||||
#define BSP_LED_PIN HAL_GPIO_PIN_6
|
||||
typedef enum {
|
||||
BSP_CONFIG_SECTION_NONE = 0,
|
||||
BSP_CONFIG_SECTION_BOARD,
|
||||
BSP_CONFIG_SECTION_MODULE,
|
||||
BSP_CONFIG_SECTION_PERIPH,
|
||||
BSP_CONFIG_SECTION_MAX
|
||||
} bsp_config_section_t;
|
||||
|
||||
/**
|
||||
* @brief Button hardware configuration
|
||||
* @brief BSP configuration entry
|
||||
*/
|
||||
/* KEY0 - PE4, active low */
|
||||
#define BSP_KEY0_PORT HAL_GPIO_PORT_E
|
||||
#define BSP_KEY0_PIN HAL_GPIO_PIN_4
|
||||
|
||||
/* KEY1 - PE3, active low */
|
||||
#define BSP_KEY1_PORT HAL_GPIO_PORT_E
|
||||
#define BSP_KEY1_PIN HAL_GPIO_PIN_3
|
||||
|
||||
/* WK_UP - PA0, active high */
|
||||
#define BSP_WKUP_PORT HAL_GPIO_PORT_A
|
||||
#define BSP_WKUP_PIN HAL_GPIO_PIN_0
|
||||
typedef struct {
|
||||
const char* section;
|
||||
const char* key;
|
||||
const char* value;
|
||||
} bsp_config_entry_t;
|
||||
|
||||
/**
|
||||
* @brief UART hardware configuration
|
||||
* @brief BSP configuration parser context
|
||||
*/
|
||||
#define BSP_UART_INSTANCE BSP_UART_INSTANCE_1
|
||||
#define BSP_UART_BAUDRATE 115200
|
||||
#define BSP_UART_PARITY HAL_UART_PARITY_NONE
|
||||
#define BSP_UART_STOPBITS HAL_UART_STOPBITS_1
|
||||
#define BSP_UART_DATABITS HAL_UART_DATABITS_8
|
||||
typedef struct {
|
||||
FILE* file;
|
||||
char current_section[BSP_CONFIG_MAX_SECTION_NAME_LENGTH];
|
||||
char buffer[BSP_CONFIG_MAX_LINE_LENGTH];
|
||||
uint32_t line_number;
|
||||
uint8_t initialized;
|
||||
} bsp_config_parser_t;
|
||||
|
||||
/**
|
||||
* @brief BSP configuration file operations
|
||||
*/
|
||||
typedef struct {
|
||||
hal_ret_t (*open)(const char* filename, bsp_config_parser_t* parser);
|
||||
hal_ret_t (*close)(bsp_config_parser_t* parser);
|
||||
hal_ret_t (*read_entry)(bsp_config_parser_t* parser, bsp_config_entry_t* entry);
|
||||
hal_ret_t (*parse_int)(const char* value, int* result);
|
||||
hal_ret_t (*parse_uint)(const char* value, uint32_t* result);
|
||||
hal_ret_t (*parse_bool)(const char* value, uint8_t* result);
|
||||
hal_ret_t (*parse_string)(const char* value, char* result, size_t max_length);
|
||||
} bsp_config_ops_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize BSP configuration system
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_config_init(void);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize BSP configuration system
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_config_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief Load BSP configuration from file
|
||||
* @param filename: Configuration file name
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_config_load(const char* filename);
|
||||
|
||||
/**
|
||||
* @brief Save BSP configuration to file
|
||||
* @param filename: Configuration file name
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_config_save(const char* filename);
|
||||
|
||||
/**
|
||||
* @brief Get configuration value
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Pointer to store value
|
||||
* @param max_length: Maximum length of value buffer
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_config_get_value(const char* section, const char* key, char* value, size_t max_length);
|
||||
|
||||
/**
|
||||
* @brief Set configuration value
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Configuration value
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_config_set_value(const char* section, const char* key, const char* value);
|
||||
|
||||
/**
|
||||
* @brief Get configuration value as integer
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Pointer to store integer value
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_config_get_int(const char* section, const char* key, int* value);
|
||||
|
||||
/**
|
||||
* @brief Set configuration value as integer
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Integer value
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_config_set_int(const char* section, const char* key, int value);
|
||||
|
||||
/**
|
||||
* @brief Get configuration value as unsigned integer
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Pointer to store unsigned integer value
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_config_get_uint(const char* section, const char* key, uint32_t* value);
|
||||
|
||||
/**
|
||||
* @brief Set configuration value as unsigned integer
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Unsigned integer value
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_config_set_uint(const char* section, const char* key, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Get configuration value as boolean
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Pointer to store boolean value
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_config_get_bool(const char* section, const char* key, uint8_t* value);
|
||||
|
||||
/**
|
||||
* @brief Set configuration value as boolean
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Boolean value
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_config_set_bool(const char* section, const char* key, uint8_t value);
|
||||
|
||||
/**
|
||||
* @brief Parse BSP modules from configuration
|
||||
* @param config: Pointer to BSP board configuration structure to fill
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_config_parse_modules(bsp_board_config_t* config);
|
||||
|
||||
/**
|
||||
* @brief Initialize BSP from configuration file
|
||||
* @param filename: Configuration file name
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_init_from_config(const char* filename);
|
||||
|
||||
#endif /* BSP_CONFIG_H */
|
||||
|
||||
@ -14,13 +14,15 @@
|
||||
|
||||
/**
|
||||
* @brief Initialize board support package
|
||||
* @retval HAL status code
|
||||
*/
|
||||
void bsp_init(void);
|
||||
hal_ret_t bsp_init(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize board GPIO
|
||||
* @retval HAL status code
|
||||
*/
|
||||
void bsp_gpio_init(void);
|
||||
hal_ret_t bsp_gpio_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get board name
|
||||
|
||||
401
BSP/Inc/bsp_module.h
Normal file
401
BSP/Inc/bsp_module.h
Normal file
@ -0,0 +1,401 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_module.h
|
||||
* @brief : Board support package module management header file
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef BSP_MODULE_H
|
||||
#define BSP_MODULE_H
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
/**
|
||||
* @brief BSP module type definitions
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_MODULE_TYPE_LED = 0,
|
||||
BSP_MODULE_TYPE_BUTTON,
|
||||
BSP_MODULE_TYPE_UART,
|
||||
BSP_MODULE_TYPE_SPI,
|
||||
BSP_MODULE_TYPE_I2C,
|
||||
BSP_MODULE_TYPE_CAN,
|
||||
BSP_MODULE_TYPE_ADC,
|
||||
BSP_MODULE_TYPE_DAC,
|
||||
BSP_MODULE_TYPE_TIMER,
|
||||
BSP_MODULE_TYPE_RTC,
|
||||
BSP_MODULE_TYPE_W25QXX,
|
||||
BSP_MODULE_TYPE_MAX
|
||||
} bsp_module_type_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module state definitions
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_MODULE_STATE_UNINIT = 0,
|
||||
BSP_MODULE_STATE_INIT,
|
||||
BSP_MODULE_STATE_CONFIGURED,
|
||||
BSP_MODULE_STATE_RUNNING,
|
||||
BSP_MODULE_STATE_ERROR
|
||||
} bsp_module_state_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module priority definitions
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_MODULE_PRIORITY_HIGHEST = 0,
|
||||
BSP_MODULE_PRIORITY_HIGH,
|
||||
BSP_MODULE_PRIORITY_MEDIUM,
|
||||
BSP_MODULE_PRIORITY_LOW,
|
||||
BSP_MODULE_PRIORITY_LOWEST
|
||||
} bsp_module_priority_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module configuration structure
|
||||
*/
|
||||
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_config_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module operations structure
|
||||
*/
|
||||
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 */
|
||||
} bsp_module_ops_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module version structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t major;
|
||||
uint8_t minor;
|
||||
uint8_t patch;
|
||||
} bsp_module_version_t;
|
||||
|
||||
/**
|
||||
* @brief Forward declaration of bsp_module_t
|
||||
*/
|
||||
typedef struct bsp_module bsp_module_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module event callback type
|
||||
*/
|
||||
typedef hal_ret_t (*bsp_module_event_callback_t)(const bsp_module_t* sender, uint32_t event, void* data);
|
||||
|
||||
/**
|
||||
* @brief BSP module structure
|
||||
*/
|
||||
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_t;
|
||||
|
||||
/**
|
||||
* @brief BSP module event definitions
|
||||
*/
|
||||
#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 */
|
||||
|
||||
/**
|
||||
* @brief BSP module auto-registration macros
|
||||
*/
|
||||
#define BSP_MODULE_REGISTER(module) \
|
||||
static const bsp_module_config_t __bsp_module_##module##_config = { \
|
||||
.type = BSP_MODULE_TYPE_##module, \
|
||||
.name = #module, \
|
||||
.priority = BSP_MODULE_PRIORITY_MEDIUM, \
|
||||
.version = 1, \
|
||||
.instance = 0, \
|
||||
.enable = 1, \
|
||||
.config_data = NULL, \
|
||||
.config_size = 0, \
|
||||
.dependencies = 0 \
|
||||
}; \
|
||||
static bsp_module_t __bsp_module_##module = { \
|
||||
.config = __bsp_module_##module##_config, \
|
||||
.state = BSP_MODULE_STATE_UNINIT, \
|
||||
.version = {1, 0, 0}, \
|
||||
.event_callback = NULL \
|
||||
};
|
||||
|
||||
#define BSP_MODULE_REGISTER_FULL(module, type, priority, instance, deps) \
|
||||
static const bsp_module_config_t __bsp_module_##module##_config = { \
|
||||
.type = (type), \
|
||||
.name = #module, \
|
||||
.priority = (priority), \
|
||||
.version = 1, \
|
||||
.instance = (instance), \
|
||||
.enable = 1, \
|
||||
.config_data = NULL, \
|
||||
.config_size = 0, \
|
||||
.dependencies = (deps) \
|
||||
}; \
|
||||
static bsp_module_t __bsp_module_##module = { \
|
||||
.config = __bsp_module_##module##_config, \
|
||||
.state = BSP_MODULE_STATE_UNINIT, \
|
||||
.version = {1, 0, 0}, \
|
||||
.event_callback = NULL \
|
||||
};
|
||||
|
||||
#define BSP_MODULE_REGISTER_AT_STARTUP(module) \
|
||||
BSP_MODULE_REGISTER(module) \
|
||||
__attribute__((constructor)) static void __bsp_register_##module##_at_startup(void) { \
|
||||
bsp_module_register(&__bsp_module_##module); \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief BSP module manager structure
|
||||
*/
|
||||
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_manager_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize BSP module manager
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_module_manager_init(void);
|
||||
|
||||
/**
|
||||
* @brief Register a BSP module
|
||||
* @param module: Pointer to module structure
|
||||
* @retval HAL status code
|
||||
*/
|
||||
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
|
||||
*/
|
||||
hal_ret_t bsp_module_unregister(bsp_module_t* module);
|
||||
|
||||
/**
|
||||
* @brief Initialize all registered BSP modules
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_module_init_all(void);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize all registered BSP modules
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_module_deinit_all(void);
|
||||
|
||||
/**
|
||||
* @brief Start all registered BSP modules
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_module_start_all(void);
|
||||
|
||||
/**
|
||||
* @brief Stop all registered BSP modules
|
||||
* @retval HAL status code
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
bsp_module_t* bsp_module_get_by_name(const char* name);
|
||||
|
||||
/**
|
||||
* @brief Get total number of registered modules
|
||||
* @retval Number of registered modules
|
||||
*/
|
||||
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
|
||||
*/
|
||||
hal_ret_t bsp_module_check_dependencies(const bsp_module_t* module);
|
||||
|
||||
/**
|
||||
* @brief Get module manager instance
|
||||
* @retval Pointer to module manager structure
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
hal_ret_t bsp_module_get_priority(bsp_module_type_t type, uint8_t instance, bsp_module_priority_t* priority);
|
||||
|
||||
#endif /* BSP_MODULE_H */
|
||||
Reference in New Issue
Block a user