RTOS 1.5 Bug wifi_set_event_handler_cb

curiousmuch
Posts: 8
Joined: Thu May 04, 2017 3:48 am

RTOS 1.5 Bug wifi_set_event_handler_cb

Postby curiousmuch » Thu May 04, 2017 3:58 am

Hello,

The wifi_set_event_handler_cb() will not set the callback function if a task with a priority of 6 is started in the user_init(). I have yet to try a higher task priorities yet. The documentation lists that users can set task priority to be from 1-9?

Can Espressif please specify what are the priorities for system tasks or provide a fix.

Thanks guys!

curiousmuch
Posts: 8
Joined: Thu May 04, 2017 3:48 am

Re: RTOS 1.5 Bug wifi_set_event_handler_cb

Postby curiousmuch » Sat May 06, 2017 2:54 pm

Hello?

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: RTOS 1.5 Bug wifi_set_event_handler_cb

Postby ESP_Faye » Tue May 09, 2017 9:47 am

Hi,

Sorry that we cannot duplicate your problem, could you provide your test code which can duplicate the problem?

Thanks for your interest in ESP8266!

curiousmuch
Posts: 8
Joined: Thu May 04, 2017 3:48 am

Re: RTOS 1.5 Bug wifi_set_event_handler_cb

Postby curiousmuch » Fri May 12, 2017 4:08 am

ESP_Faye wrote:Hi,

Sorry that we cannot duplicate your problem, could you provide your test code which can duplicate the problem?

Thanks for your interest in ESP8266!


Absolutely! I'll post code soon along with binaries. Thank you for the response!

curiousmuch
Posts: 8
Joined: Thu May 04, 2017 3:48 am

Re: RTOS 1.5 Bug wifi_set_event_handler_cb

Postby curiousmuch » Fri May 12, 2017 4:26 am

Attached is a user_main.c which demos my issue. If the wifi_controller task is given a priority of 1 the wifi handler will be set. If the task is given a priority of 6, the wifi handler will not be set and a default handler will be used. (See os_printf("Inside Custom Event Handler\n");
)

I'm sorry I cannot attach binaries. There forum doesn't appear to support it.

Code: Select all

/*
 * ESPRSSIF MIT License
 *
 * Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
 *
 * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
 * it is free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
 * to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#include "esp_common.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"

void wifi_handle_event_cb(System_Event_t *evt);


/******************************************************************************
 * FunctionName : user_rf_cal_sector_set
 * Description  : SDK just reversed 4 sectors, used for rf init data and paramters.
 *                We add this function to force users to set rf cal sector, since
 *                we don't know which sector is free in user's application.
 *                sector map for last several sectors : ABCCC
 *                A : rf cal
 *                B : rf init data
 *                C : sdk parameters
 * Parameters   : none
 * Returns      : rf cal sector
*******************************************************************************/
uint32 user_rf_cal_sector_set(void)
{
    flash_size_map size_map = system_get_flash_size_map();
    uint32 rf_cal_sec = 0;

    switch (size_map) {
        case FLASH_SIZE_4M_MAP_256_256:
            rf_cal_sec = 128 - 5;
            break;

        case FLASH_SIZE_8M_MAP_512_512:
            rf_cal_sec = 256 - 5;
            break;

        case FLASH_SIZE_16M_MAP_512_512:
        case FLASH_SIZE_16M_MAP_1024_1024:
            rf_cal_sec = 512 - 5;
            break;

        case FLASH_SIZE_32M_MAP_512_512:
        case FLASH_SIZE_32M_MAP_1024_1024:
            rf_cal_sec = 1024 - 5;
            break;

        default:
            rf_cal_sec = 0;
            break;
    }

    return rf_cal_sec;
}

/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
#include "uart.h"
#include "gpio.h"

void wifi_handle_event_cb(System_Event_t *evt)
{
    os_printf("Inside Custom Event Handler\n");
    switch (evt->event_id) {
         case EVENT_STAMODE_CONNECTED:
         {
             printf("connect to ssid %s, channel %d\n",
             evt->event_info.connected.ssid,
             evt->event_info.connected.channel);
             break;
         }
         case EVENT_STAMODE_DISCONNECTED:
             printf("disconnect from ssid %s, reason %d\n",
             evt->event_info.disconnected.ssid,
             evt->event_info.disconnected.reason);
             break;
         case EVENT_STAMODE_AUTHMODE_CHANGE:
             printf("mode: %d -> %d\n",
             evt->event_info.auth_change.old_mode,
             evt->event_info.auth_change.new_mode);
             break;
         case EVENT_STAMODE_GOT_IP:
             printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR,
             IP2STR(&evt->event_info.got_ip.ip),
             IP2STR(&evt->event_info.got_ip.mask),
             IP2STR(&evt->event_info.got_ip.gw));
             printf("\n");
             break;
         case EVENT_SOFTAPMODE_STACONNECTED:
             printf("station: " MACSTR "join, AID = %d\n",
             MAC2STR(evt->event_info.sta_connected.mac),
             evt->event_info.sta_connected.aid);
             break;
         case EVENT_SOFTAPMODE_STADISCONNECTED:
             printf("station: " MACSTR "leave, AID = %d\n",
             MAC2STR(evt->event_info.sta_disconnected.mac),
             evt->event_info.sta_disconnected.aid);
             break;
         default:
             break;
 }
}

#define MAX_STATIONS 5
#define DEFAULT_SSID "curiousmuch?"
#define DEFAULT_PASSWORD "MBg4Nqd8"

void wifi_controller(void *pvParameters)
{
    printf("Starting Wi-Fi Controller...\n");

    // setup inital Wi-Fi parameters
    struct station_config * config =   (struct   station_config   *)zalloc(sizeof(struct
        station_config));
    sprintf(config->ssid, DEFAULT_SSID);
    sprintf(config->password, DEFAULT_PASSWORD);

    wifi_set_event_handler_cb(wifi_handle_event_cb);
    wifi_station_ap_number_set(MAX_STATIONS);
    wifi_set_opmode(STATION_MODE);
    wifi_station_set_config(config);
    free(config);
    wifi_station_connect();

    while(1);
        vTaskDelay(100000);
}


#include "uart.h"

void user_init(void)
{
    uart_init_new();  // initial UART (move to main or user config)
    printf("SDK version:%s :)\n\r", system_get_sdk_version());

    // functions which must be called in user_init()
    wifi_station_set_auto_connect(false);
    wifi_station_set_reconnect_policy(false);


    printf("Creating Task(s)\n");
    xTaskCreate(wifi_controller, "wifi_contoller", 500, NULL, 6, NULL);

}

curiousmuch
Posts: 8
Joined: Thu May 04, 2017 3:48 am

Re: RTOS 1.5 Bug wifi_set_event_handler_cb

Postby curiousmuch » Sun May 14, 2017 12:54 am

Please let me know if I can provide additional information.

Her Mary
Posts: 537
Joined: Mon Oct 27, 2014 11:09 am

Re: RTOS 1.5 Bug wifi_set_event_handler_cb

Postby Her Mary » Mon May 15, 2017 5:05 pm

while(1); should not be used, if the task is always in RUNNING state, the other tasks of which priority is lower will not execute.
You need to suspend it or block it. http://www.freertos.org/RTOS-task-states.html
Usually, messages will be used for task.

curiousmuch
Posts: 8
Joined: Thu May 04, 2017 3:48 am

Re: RTOS 1.5 Bug wifi_set_event_handler_cb

Postby curiousmuch » Mon May 15, 2017 9:54 pm

while(1); should not be used, if the task is always in RUNNING state, the other tasks of which priority is lower will not execute.
You need to suspend it or block it. http://www.freertos.org/RTOS-task-states.html
Usually, messages will be used for task.


Opps. I just noticed the extra semi-colon. Thanks! : ) This should have been the following:

Code: Select all

while(1)
   vTaskDelay(1000);


The task should unblock now. Nevertheless, I believe Espressif has the priority for system tasks too low.

System tasks should have the highest priority and if they're not the highest priority Espressif should specify what the priority of the tasks are so developers don't have to spend significant time dicking around creating test cases to determine themselves. I don't understand why they would specify users can create tasks with priorities 1-9, but then create tasks crucial to the SDK operation at priorities lower than 9.

curiousmuch
Posts: 8
Joined: Thu May 04, 2017 3:48 am

Re: RTOS 1.5 Bug wifi_set_event_handler_cb

Postby curiousmuch » Tue May 16, 2017 9:53 am

Hopefully Espressif can provide a list of system task priorities if this isn't deemed as a bug?

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: RTOS 1.5 Bug wifi_set_event_handler_cb

Postby ESP_Faye » Tue May 16, 2017 1:24 pm

Hi,

The documentation has been updated, please refer to the Section 2.2 of 20A-ESP8266__RTOS_SDK__Programming Guide.

Thanks for your reporting!

Who is online

Users browsing this forum: No registered users and 3 guests