准备驱动移植适配Rust
This commit is contained in:
@ -29,6 +29,7 @@
|
||||
#include "bsp_config.h"
|
||||
#include "bsp_w25qxx.h"
|
||||
#include "bsp_key.h"
|
||||
#include "bsp_eth.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@ -102,8 +103,36 @@ int main(void)
|
||||
delay_init();
|
||||
logging_init();
|
||||
|
||||
/* Get LED configuration from board config */
|
||||
/* Initialize Ethernet (LAN8720) */
|
||||
log_debug("Starting Ethernet initialization...\r\n");
|
||||
const bsp_board_config_t* board_config = bsp_get_board_config();
|
||||
bsp_eth_config_t eth_config = board_config->eth;
|
||||
if (bsp_eth_init(ð_config) == HAL_RET_OK) {
|
||||
log_info("Ethernet initialized successfully\r\n");
|
||||
|
||||
/* Get Ethernet status */
|
||||
bsp_eth_status_t eth_status;
|
||||
if (bsp_eth_get_status(ð_status) == HAL_RET_OK) {
|
||||
log_info("Ethernet PHY ID: 0x%04X 0x%04X\r\n", eth_status.phy_id1, eth_status.phy_id2);
|
||||
log_info("Ethernet link status: %s\r\n", eth_status.link_up ? "UP" : "DOWN");
|
||||
if (eth_status.link_up) {
|
||||
log_info("Ethernet speed: %lu Mbps\r\n", eth_status.speed);
|
||||
log_info("Ethernet duplex: %s\r\n", eth_status.duplex ? "Full" : "Half");
|
||||
}
|
||||
}
|
||||
|
||||
/* Get MAC address */
|
||||
hal_eth_mac_addr_t mac_addr;
|
||||
if (bsp_eth_get_mac_addr(&mac_addr) == HAL_RET_OK) {
|
||||
log_info("Ethernet MAC address: %02X:%02X:%02X:%02X:%02X:%02X\r\n",
|
||||
mac_addr.byte[0], mac_addr.byte[1], mac_addr.byte[2],
|
||||
mac_addr.byte[3], mac_addr.byte[4], mac_addr.byte[5]);
|
||||
}
|
||||
} else {
|
||||
log_error("Ethernet initialization failed\r\n");
|
||||
}
|
||||
|
||||
/* Get LED configuration from board config */
|
||||
led_config_t led_config = {
|
||||
.gpio_port = board_config->leds.leds[0].port,
|
||||
.gpio_pin = board_config->leds.leds[0].pin
|
||||
@ -214,6 +243,28 @@ int main(void)
|
||||
log_debug("LED toggled\r\n");
|
||||
led_toggle_timer = delay_get_tick(); // Reset timer
|
||||
}
|
||||
|
||||
/* Check Ethernet link status periodically */
|
||||
static uint32_t eth_check_timer = 0;
|
||||
#define ETH_CHECK_INTERVAL 5000 /* 5000ms interval for Ethernet status check */
|
||||
if ((delay_get_tick() - eth_check_timer) >= ETH_CHECK_INTERVAL) {
|
||||
uint8_t link_up;
|
||||
if (bsp_eth_check_link(&link_up) == HAL_RET_OK) {
|
||||
static uint8_t last_link_status = 0;
|
||||
if (link_up != last_link_status) {
|
||||
log_info("Ethernet link status changed: %s\r\n", link_up ? "UP" : "DOWN");
|
||||
if (link_up) {
|
||||
bsp_eth_status_t eth_status;
|
||||
if (bsp_eth_get_status(ð_status) == HAL_RET_OK) {
|
||||
log_info("Ethernet speed: %lu Mbps\r\n", eth_status.speed);
|
||||
log_info("Ethernet duplex: %s\r\n", eth_status.duplex ? "Full" : "Half");
|
||||
}
|
||||
}
|
||||
last_link_status = link_up;
|
||||
}
|
||||
}
|
||||
eth_check_timer = delay_get_tick(); // Reset timer
|
||||
}
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
@ -296,6 +347,6 @@ void assert_failed(uint8_t *file, uint32_t line)
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* USER CODE END 6 */
|
||||
/* USER CODE END 6 */jn
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
Reference in New Issue
Block a user