121 lines
3.2 KiB
C
121 lines
3.2 KiB
C
/* Board */
|
|
#include "board.h"
|
|
#include "clock_config.h"
|
|
#include "peripherals.h"
|
|
#include "pin_mux.h"
|
|
|
|
/* Debug Console */
|
|
#include "fsl_debug_console.h"
|
|
|
|
/* FreeRTOS */
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
|
|
/* Private */
|
|
#include "app_nh_impl.h"
|
|
|
|
#define APP_DEFAULT_WIFI_SSID "Home-Dev_2"
|
|
#define APP_DEFAULT_WIFI_PASS "qwer1234"
|
|
|
|
static void initialization_task(void *params);
|
|
|
|
static void report_mac_addresses(void);
|
|
static void scan_ap(void);
|
|
static void connect_default_wifi(void);
|
|
|
|
int main(void) {
|
|
BOARD_InitBootPins();
|
|
BOARD_BootClockFROHF96M();
|
|
BOARD_InitBootPeripherals();
|
|
|
|
BOARD_InitDebugConsole();
|
|
|
|
PRINTF("Hello world!!\r\n");
|
|
|
|
if (xTaskCreate(initialization_task, "INIT", 2048, NULL, 2, NULL) != pdPASS) {
|
|
PRINTF("Failed to create initialization task...\r\n");
|
|
|
|
goto dead_loop;
|
|
}
|
|
|
|
vTaskStartScheduler();
|
|
|
|
dead_loop:
|
|
/* We should never reach here. */
|
|
for (;;) {
|
|
__WFI();
|
|
}
|
|
}
|
|
|
|
static void initialization_task(void *params) {
|
|
PRINTF("Initialization task running...\r\n");
|
|
|
|
/* Do initialization stuff here, since the scheduler is running now. */
|
|
if (app_nh_impl_init() != 0) {
|
|
PRINTF("Failed to init nano_hosted\r\n");
|
|
}
|
|
|
|
report_mac_addresses();
|
|
scan_ap();
|
|
connect_default_wifi();
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
static void scan_ap_callback(void *handle, nh_ctrl_ap_scan_item_t *item) {
|
|
PRINTF("AP: [%s]\r\nBSSID: %s\tSig: %lddB\tCH: %lu\r\n", item->ssid, item->bssid, item->rssi, item->channel);
|
|
}
|
|
|
|
static void scan_ap(void) {
|
|
PRINTF("Scanning AP...\r\n");
|
|
if (nh_ctrl_api_get_ap_scan_list(&g_nh_ctrl_api, scan_ap_callback) != NH_RET_SUCCESS) {
|
|
PRINTF("Failed to scan AP list.\r\n");
|
|
}
|
|
|
|
PRINTF("AP scan completed.\r\n");
|
|
}
|
|
|
|
static void connect_default_wifi(void) {
|
|
char mac_addr[NH_CTRL_API_MAC_LENGTH + 1];
|
|
|
|
nh_ctrl_ap_conn_result_t result = {
|
|
.mac_addr = mac_addr,
|
|
};
|
|
|
|
nh_ctrl_ap_conn_params_t param = {
|
|
.ssid = APP_DEFAULT_WIFI_SSID,
|
|
.password = APP_DEFAULT_WIFI_PASS,
|
|
.bssid = "",
|
|
.wpa3_supported = false,
|
|
.listen_interval = 0,
|
|
};
|
|
|
|
PRINTF("Connecting to AP: %s\r\n", APP_DEFAULT_WIFI_SSID);
|
|
|
|
if (nh_ctrl_api_connect_ap(&g_nh_ctrl_api, ¶m, &result) != NH_RET_SUCCESS) {
|
|
PRINTF("Failed to connect to AP.\r\n");
|
|
}
|
|
|
|
if (result.status != NH_CTRL_CONNECT_SUCCESS) {
|
|
PRINTF("Connect to AP failed with result: %d\r\n", result.status);
|
|
} else {
|
|
PRINTF("Connected to AP: %s, MAC address: %s\r\n", APP_DEFAULT_WIFI_SSID, result.mac_addr);
|
|
}
|
|
} |