/* The example of esp-free-rtos
*
* This sample code is in the public domain.
*/
#include <string.h>
#include <espressif/esp_common.h>
#include <esp/uart.h>
#include <FreeRTOS.h>
#include <task.h>
#include "ssid_config.h"
#include <lwip/api.h>
SemaphoreHandle_t xSemaphore;
void Task(void *pvParameters)
{
TickType_t nowTick;
nowTick = xTaskGetTickCount();
printf("[%s:%d]
Start\n",pcTaskGetName(0),nowTick);
xSemaphoreTake(xSemaphore,
portMAX_DELAY);
nowTick = xTaskGetTickCount();
printf("[%s:%d]
Take\n",pcTaskGetName(0),nowTick);
xSemaphoreGive(xSemaphore);
nowTick = xTaskGetTickCount();
printf("[%s:%d]
Give\n",pcTaskGetName(0),nowTick);
while(1) {
vTaskDelay(1);
}
}
void WifiTask(void *pvParameters)
{
TickType_t nowTick;
nowTick = xTaskGetTickCount();
printf("[%s:%d]
start\n",pcTaskGetName(0),nowTick);
struct ip_info info;
while(1) {
if
(sdk_wifi_get_ip_info(STATION_IF, &info)) {
/*
#define
IP2STR(ipaddr) ip4_addr1_16(ipaddr), \
ip4_addr2_16(ipaddr), \
ip4_addr3_16(ipaddr), \
ip4_addr4_16(ipaddr)
ip4_addr2_16(ipaddr), \
ip4_addr3_16(ipaddr), \
ip4_addr4_16(ipaddr)
#define IPSTR
"%d.%d.%d.%d"
*/
nowTick =
xTaskGetTickCount();
printf("[%s:%d]
IP
address="IPSTR"\n",pcTaskGetName(0),nowTick,IP2STR(&info.ip));
if
(ip4_addr1_16(&info.ip) != 0) break;
}
vTaskDelay(100);
}
printf("[%s:%d]
Netmask="IPSTR"\n",pcTaskGetName(0),nowTick,IP2STR(&info.netmask));
printf("[%s:%d]
Gateway="IPSTR"\n",pcTaskGetName(0),nowTick,IP2STR(&info.gw));
// Start other task
xSemaphoreGive(xSemaphore);
vTaskDelete(NULL);
}
void user_init(void)
{
uart_set_baud(0, 115200);
printf("SDK version:%s\n",
sdk_system_get_sdk_version());
printf("pcTaskGetName=%s\n",pcTaskGetName(0));
/* Create Semaphore */
xSemaphore = xSemaphoreCreateBinary();
/* Check everything was created. */
configASSERT( xSemaphore );
struct sdk_station_config config = {
.ssid =
WIFI_SSID,
.password =
WIFI_PASS,
};
// Required to call wifi_set_opmode
before station_set_config.
sdk_wifi_set_opmode(STATION_MODE);
sdk_wifi_station_set_config(&config);
xTaskCreate(WifiTask, "WifiTask", 512,
NULL, 2, NULL);
xTaskCreate(Task, "Task1", 256, NULL,
2, NULL);
xTaskCreate(Task, "Task2", 256, NULL,
2, NULL);
xTaskCreate(Task, "Task3", 256, NULL,
2, NULL);
xTaskCreate(Task, "Task4", 256, NULL,
2, NULL);
}
|