From 84d34b6e6258724407bb798d47f279ab93f431c5 Mon Sep 17 00:00:00 2001 From: Yilin Sun Date: Sat, 14 Jan 2023 18:58:32 +0800 Subject: [PATCH] Updated lib. Signed-off-by: Yilin Sun --- include/app_nh_impl.h | 2 ++ lib/esp_nano_hosted | 2 +- src/app_nh_impl.c | 30 +++++++++++++++++++----------- src/main.c | 19 +++++++++++++++++++ 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/include/app_nh_impl.h b/include/app_nh_impl.h index f0de93e..383f73d 100644 --- a/include/app_nh_impl.h +++ b/include/app_nh_impl.h @@ -4,6 +4,8 @@ #include "nh_shared_if.h" #include "nh_ctrl_api.h" +extern nh_ctrl_api_t g_nh_ctrl_api; + int app_nh_impl_init(void); #endif // APP_NH_IMPL_H diff --git a/lib/esp_nano_hosted b/lib/esp_nano_hosted index 59d47eb..9add7e5 160000 --- a/lib/esp_nano_hosted +++ b/lib/esp_nano_hosted @@ -1 +1 @@ -Subproject commit 59d47eb3427e730ccc94c2ec3ce05ce074a29c41 +Subproject commit 9add7e515b450d4cb1ba5e369d59004ff661e6a2 diff --git a/src/app_nh_impl.c b/src/app_nh_impl.c index b37dfc5..8de4bc9 100644 --- a/src/app_nh_impl.c +++ b/src/app_nh_impl.c @@ -31,6 +31,7 @@ static void app_nh_impl_hs_callback(pint_pin_int_t pintr, uint32_t pmatch_status static nh_ret_t app_nh_impl_ops_xfer(void *handle, uint8_t *tx_data, uint8_t *rx_data, uint32_t len); static nh_ret_t app_nh_impl_ops_drdy_read(void *handle, bool *rdy); +static nh_ret_t app_nh_impl_ops_hs_poll(void *handle, uint32_t timeout_ms); static void app_nh_impl_cb_startup(void *handle, nh_event_init_t *init_data); static void app_nh_impl_cb_init(void *handle); @@ -74,6 +75,7 @@ static nh_shared_if_t s_nh_shared_if = { { .xfer = app_nh_impl_ops_xfer, .drdy_read = app_nh_impl_ops_drdy_read, + .hs_poll = app_nh_impl_ops_hs_poll, }, .cb = { @@ -81,7 +83,7 @@ static nh_shared_if_t s_nh_shared_if = { }, }; -static nh_ctrl_api_t s_nh_ctrl_api = { +nh_ctrl_api_t g_nh_ctrl_api = { .osa = &s_nh_osa, .shared_if = &s_nh_shared_if, .cb = @@ -112,11 +114,11 @@ int app_nh_impl_init(void) { return -4; } - if (nh_ctrl_api_init(&s_nh_ctrl_api) != NH_RET_SUCCESS) { + if (nh_ctrl_api_init(&g_nh_ctrl_api) != NH_RET_SUCCESS) { return -5; } - if (xTaskCreate(app_nh_impl_ctrl_task, "NH_CTRL", 512, &s_nh_ctrl_api, 2, NULL) != pdPASS) { + if (xTaskCreate(app_nh_impl_ctrl_task, "NH_CTRL", 512, &g_nh_ctrl_api, 2, NULL) != pdPASS) { return -6; } @@ -126,13 +128,6 @@ int app_nh_impl_init(void) { PRINTF("Did not received ESPInit event in time, bailing out (assumed soft reset).\r\n"); } - uint8_t mac_addr[18] = {0x00}; - if (nh_ctrl_api_get_mac_address(&s_nh_ctrl_api, mac_addr) != NH_RET_SUCCESS) { - PRINTF("Failed to acquire MAC address.\r\n"); - } else { - PRINTF("STA mode MAC address: %s\r\n", mac_addr); - } - return 0; } @@ -208,6 +203,19 @@ static nh_ret_t app_nh_impl_ops_drdy_read(void *handle, bool *rdy) { return NH_RET_SUCCESS; } +static nh_ret_t app_nh_impl_ops_hs_poll(void *handle, uint32_t timeout_ms) { + TickType_t tick_start = xTaskGetTickCount(); + + while (GPIO_PinRead(GPIO, BOARD_INITMIKROEPINS_ESP_HS_PORT, BOARD_INITMIKROEPINS_ESP_HS_PIN) == 0) { + vTaskDelay(pdMS_TO_TICKS(20)); + if (xTaskGetTickCount() - tick_start > pdMS_TO_TICKS(timeout_ms)) { + return NH_RET_TIMEOUT; + } + } + + return NH_RET_SUCCESS; +} + static nh_ret_t app_nh_impl_ops_xfer(void *handle, uint8_t *tx_data, uint8_t *rx_data, uint32_t len) { spi_transfer_t xfer = { .txData = tx_data, @@ -436,7 +444,7 @@ static void app_nh_impl_shared_if_task(void *parameters) { static void app_nh_impl_ctrl_task(void *parameters) { for (;;) { - nh_ctrl_api_task(&s_nh_ctrl_api); + nh_ctrl_api_task(&g_nh_ctrl_api); } vTaskDelete(NULL); diff --git a/src/main.c b/src/main.c index 80f745e..dd59db4 100644 --- a/src/main.c +++ b/src/main.c @@ -16,6 +16,8 @@ static void initialization_task(void *params); +static void report_mac_addresses(void); + int main(void) { BOARD_InitBootPins(); BOARD_BootClockFROHF96M(); @@ -48,7 +50,24 @@ static void initialization_task(void *params) { PRINTF("Failed to init nano_hosted\r\n"); } + report_mac_addresses(); + PRINTF("Initialization completed, INIT task exit.\r\n"); vTaskDelete(NULL); +} + +static void report_mac_addresses(void) { + uint8_t mac_addr[18] = {0x00}; + if (nh_ctrl_api_get_mac_address(&g_nh_ctrl_api, mac_addr, NH_CTRL_WIFI_MODE_STA) != NH_RET_SUCCESS) { + PRINTF("Failed to acquire MAC address.\r\n"); + } else { + PRINTF("STA mode MAC address: %s\r\n", mac_addr); + } + + if (nh_ctrl_api_get_mac_address(&g_nh_ctrl_api, mac_addr, NH_CTRL_WIFI_MODE_AP) != NH_RET_SUCCESS) { + PRINTF("Failed to acquire MAC address.\r\n"); + } else { + PRINTF("AP mode MAC address: %s\r\n", mac_addr); + } } \ No newline at end of file