Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

How to port xTaskCreatePinnedToCore() into mongoose-os lib function?

aiferaifer China
edited March 26 in Mongoose OS

I want to port some codes into my mongoose-os project.
The codes use xTaskCreatePinnedToCore(), a ESP32 ESP-IDF lib function/FreeRTOS.

BaseType_t xTaskCreatePinnedToCore(
TaskFunction_t pxTaskCode,
const char * pcName,
const uint16_t usStackDepth,
void *pvParameters,
UBaseType_t uxPriority,
TaskHandle_t *pxCreatedTask,
const BasType_t xCoreID)

How to ported xTaskCreatePinnedToCore() into mongoose-os lib function?
Should I use mongoolse_poll()? And How?
Or xTaskCreatePinnedToCore() can work with mongoose_poll()?

«1

Comments

  • SergeySergey Dublin, Ireland

    Mongoose event handling is done in it's own dedicated task. See https://github.com/cesanta/mongoose-os/blob/4439978b7aed8f54fe9fb7282993cfccb0033075/fw/platforms/esp32/src/esp32_main.c#L196-L197

    What task are you going to create?

  • aiferaifer China
    edited May 2017

    This are the codes:

    xTaskCreatePinnedToCore(&http_get_task, "http_get_task", 2048, config, 20, my_task, 0);
    
    static void http_get_task(void *pvParameters)
    {
        my_type_t *a_conf = pvParameters;
    
        /* parse URL */
        url_t *url = url_create(a_conf->url);
    
        // blocks until end of stream
        int result = http_client_get(
                url->host, url->port, url->path,
                callback,
                a_conf->para_config);
    
        if(result != 0) {
            ESP_LOGE(TAG, "http_client_get error");
        } else {
            ESP_LOGI(TAG, "http_client_get completed");
        }
    
        url_free(url);
    
        vTaskDelete(NULL);
    }
    

    http_client_get() does HTTP GET,and receive the response from a server。

  • aiferaifer China
    edited May 2017

    xTaskCreatePinnedToCore() is some different from xTaskCreate used by mongoose-os.

    How can I do http_get_task in mongoose-os?

  • SergeySergey Dublin, Ireland

    What do you want to do?
    Make an HTTP GET request periodically?

  • aiferaifer China
    edited May 2017

    Not periodically.
    In the HTTP GET request,the URL is a large file, such as a audio/video file. It may Takes a bit long time to download, and the RAM/FLASH is not large enough. So xTaskCreatePinnedToCore() is used.
    The response data is stored into a fifo, and be treated at the same time.
    For example, audio stream.

    HTTP GET task --(data in)--> FIFO --(data out)-->data processor task
    parallel processing

  • SergeySergey Dublin, Ireland
    edited May 2017

    Ok. That is triggering a large download, saving a file to some media or piping it to UART.

    I can see no reason why that should be a dedicated task, pinned to a CPU core. This task is a typical IO bound task, could be implemented as a state machine as a Mongoose HTTP reply handler.

  • aiferaifer China

    How to implement a FIFO in FLAHS in mongoose-os? And Semaphore ?
    Is there a example?

  • aiferaifer China

    And, Can I use xTaskCreate/xTaskCreatePinnedToCore() in a ffied C/C++ fcuntion to create a new RTOS task?

  • aiferaifer China

    Another, How to create FIFO in flash by mongoose-os?

  • SergeySergey Dublin, Ireland

    Absolutely you can call xTaskCreate and create tasks as you need.
    FIFO in flash - what do you mean?

  • aiferaifer China
    edited May 2017

    Hi, I try to call xTaskCreate and create a task, but mongoose-os crashed.

    xTaskCreate(&my_task, "mytask", 8000, pl, configMAX_PRIORITIES-2, NULL);
    
    Guru Meditation Error: Core  0 panic'ed (Unhandled debug exception)
    Debug exception reason: Stack canary watchpoint triggered 
    Register dump:
    PC      : 0x40084360  PS      : 0x00060836  A0      : 0x800844be  A1      : 0x3ffe90a0  
    A2      : 0x3ffe8aa4  A3      : 0x00000114  A4      : 0x00000114  A5      : 0xff000000  
    A6      : 0x80ffffff  A7      : 0x00000005  A8      : 0x00000000  A9      : 0x00000000  
    A10     : 0x3ffe6a1c  A11     : 0x3ffb4b34  A12     : 0x00000005  A13     : 0x00000080  
    A14     : 0x0000002a  A15     : 0x3ffe93a0  SAR     : 0x00000017  EXCCAUSE: 0x00000001  
    EXCVADDR: 0x00000000  LBEG    : 0x4000c349  LEND    : 0x4000c36b  LCOUNT  : 0x00000000  
    
    Backtrace: 0x40084360:0x3ffe90a0 0x400844be:0x3ffe9180 0x40086e01:0x3ffe91b0 0x40086e40:0x3ffe91e0 0x40082036:0x3ffe9200 0x4000bee0:0x3ffe9220 0x4011cf74:0x3ffe9240 0x4011cff9:0x3ffe9260 0x40118c5c:0x3ffe9280 0x40110b45:0x3ffe92a0 0x40118de4:0x3ffe9320 0x4010da7c:0x3ffe9340 0x4000bd86:0x3ffe9360 0x40001180:0x3ffe9380 0x40059301:0x3ffe93a0 0x4005937d:0x3ffe93c0 0x40058bc2:0x3ffe93e0 0x4010613c:0x3ffe9410 0x40101f8d:0x3ffe9440 0x401020dc:0x3ffe9750 0x40081ee5:0x3ffe9780 0x4012dd97:0x3ffe97e0 0x4012f2d7:0x3ffe9800 0x4012ad89:0x3ffe9820
    
  • SergeySergey Dublin, Ireland

    did you mean, your code crashed? :)
    jokes aside, please show your my_task .

  • aiferaifer China
    edited May 2017

    :wink:
    What's the limits about Size of the stack for the task and Priority of the task in mongoose-os?
    Or, what's the highest Priority I can asign to my own task?

  • aiferaifer China

    Should I feed the watchdog in time in my own task? by mgos_wdt_feed()?

  • aiferaifer China

    my_task is a test task.

    void my_task(void *pvParameters){
      printf("%s", "hello, my task");
      mgos_wdt_feed();
      vTaskDelete(NULL);
    }
    

    the error message

    Task watchdog got triggered. The following tasks did not feed the watchdog in time:
     - mgos (CPU 0)
    Tasks currently running:
    CPU 0: IDLE
    Aborting.
    abort() was called at PC 0x400d08f9 on core 0
    Guru Meditation Error: Core  0 panic'ed (abort)
    
  • SergeySergey Dublin, Ireland

    What if you put an endless loop like

    for (;;) {
      printf("boo\n");
      sleep(1);
    }
    
  • aiferaifer China

    in my_task code?

  • SergeySergey Dublin, Ireland

    Yeah

  • aiferaifer China
    edited May 2017
    void my_task(void *pvParameters){
      for (;;) {
          printf("boo\n");
          mgos_msleep(1000);
      }
      vTaskDelete(NULL);
    }
    
  • SergeySergey Dublin, Ireland
    edited May 2017
    void my_task(void *pvParameters){
      printf("%s", "hello, my task");
      for (;;) {
          printf("boo\n");
          mgos_msleep(1000);
      }
    }
    

    Does that work for you?

  • aiferaifer China

    No, it doesn't work.

  • aiferaifer China

    printf("boo\n") only be run once.

  • SergeySergey Dublin, Ireland
    edited May 2017
    void my_task(void *pvParameters){
      for (;;) {
          printf("boo\n");
          sleep(1);
      }
    }
    
  • aiferaifer China
    edited May 2017

    where is sleep() in mongoose-os?
    I can't include it.

    undefined reference to sleep

  • SergeySergey Dublin, Ireland

    that should be a ESP32 IDF API.

  • aiferaifer China

    I found it in mongoose.h, not it?

  • aiferaifer China

    xTaskCreatePinnedToCore() can work on core 0, but will crash on core1, why?
    (mongoose-os, ESP32)

    //
    void my_task(void *pvParameters){
      printf("%s", "hello, my task");
      vTaskDelete(NULL);
    }
    
    xTaskCreatePinnedToCore(&my_task, "tskmad", 2048, pa, 5, NULL, 1); // crash, can't go into my_task
    xTaskCreatePinnedToCore(&my_task, "tskmad", 2048, pa, 5, NULL, 0); // work, go into my_task ok
    
    
  • aiferaifer China

    Does mongoose-os work in Single core mode?

    booting information:

    I (1647) cpu_start: Single core mode

    I (47) boot: ESP-IDF v1.0-1182-g07c0049 2nd stage bootloader
    I (47) boot: compile time 03:03:57
    I (80) boot: Enabling RNG early entropy source...
    I (81) boot: SPI Speed      : 40MHz
    I (81) boot: SPI Mode       : DIO
    I (89) boot: SPI Flash Size : 4MB
    I (102) boot: Partition Table:
    I (113) boot: ## Label            Usage          Type ST Offset   Length   Flags
    I (138) boot:  0 nvs              WiFi data        01 02 00009000 00004000 00000000
    I (163) boot:  1 otadata          OTA data         01 00 0000d000 00002000 00000000
    I (189) boot:  2 app_0            OTA app          00 10 00010000 00180000 00000000
    I (215) boot:  3 fs_0             SPIFFS           01 82 00190000 00020000 00000000
    I (240) boot:  4 app_1            OTA app          00 11 001b0000 00180000 00000000
    I (266) boot:  5 fs_1             SPIFFS           01 82 00330000 00020000 00000000
    I (292) boot: End of partition table
    I (305) boot: OTA data 0: seq 0x00000001, st 0x10, CRC 0x157a2b85, valid? 1
    I (328) boot: OTA data 1: seq 0x00000000, st 0x00, CRC 0x00000000, valid? 0
    I (352) boot: Disabling RNG early entropy source...
    I (369) boot: Loading app partition at offset 00010000
    I (1454) boot: segment 0: paddr=0x00010018 vaddr=0x00000000 size=0x0ffe8 ( 65512) 
    I (1455) boot: segment 1: paddr=0x00020008 vaddr=0x3f400010 size=0x18978 (100728) map
    I (1471) boot: segment 2: paddr=0x00038988 vaddr=0x3ffc0000 size=0x0235c (  9052) load
    I (1502) boot: segment 3: paddr=0x0003acec vaddr=0x40080000 size=0x00400 (  1024) load
    I (1525) boot: segment 4: paddr=0x0003b0f4 vaddr=0x40080400 size=0x130b4 ( 78004) load
    I (1588) boot: segment 5: paddr=0x0004e1b0 vaddr=0x400c0000 size=0x00000 (     0) load
    I (1589) boot: segment 6: paddr=0x0004e1b8 vaddr=0x00000000 size=0x01e50 (  7760) 
    I (1609) boot: segment 7: paddr=0x00050010 vaddr=0x400d0018 size=0x8c988 (575880) map
    I (1636) cpu_start: Pro cpu up.
    I (1647) cpu_start: Single core mode
    I (1661) heap_alloc_caps: Initializing. RAM available for dynamic allocation:
    I (1684) heap_alloc_caps: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
    I (1705) heap_alloc_caps: At 3FFB3000 len 00005000 (20 KiB): DRAM
    I (1726) heap_alloc_caps: At 3FFBBB28 len 00002000 (8 KiB): DRAM
    I (1746) heap_alloc_caps: At 3FFD96C0 len 00006940 (26 KiB): DRAM
    I (1767) heap_alloc_caps: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
    I (1788) heap_alloc_caps: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
    I (1810) heap_alloc_caps: At 400934B4 len 0000CB4C (50 KiB): IRAM
    I (1831) cpu_start: Pro cpu start user code
    I (1886) cpu_start: Starting scheduler on PRO CPU.
    
    
  • aiferaifer China
    edited May 2017
    void my_task(void *pvParameters){
    
      for(;;) {
        printf("%s", "hello, my task");
        mgos_msleep(100);
      }
      vTaskDelete(NULL);
    }
    

    I add mgos_msleep in the for loop, and IDLE task can run,but mgos not feed the dog yet:

    Task watchdog got triggered. The following tasks did does not feed the watchdog in time:
     - mgos (CPU 0)
    Tasks currently running:
    CPU 0: IDLE
    Aborting.
    abort() was called at PC 0x400d08f9 on core 0
    Guru Meditation Error: Core  0 panic'ed (abort)
  • SuryaObulareddySuryaObulareddy hyderabad
    edited March 26
    rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)<CR><LF>
    configsip: 0, SPIWP:0xee<CR><LF>
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00<CR><LF>
    mode:DIO, clock div:1<CR><LF>
    load:0x3fff0018,len:4<CR><LF>
    load:0x3fff001c,len:6188<CR><LF>
    load:0x40078000,len:9592<CR><LF>
    load:0x40080400,len:6944<CR><LF>
    entry 0x40080740<CR><LF>
    <ESC>[0;33mW (58) boot: PRO CPU has been reset by WDT.<ESC>[0m<CR><LF>
    <ESC>[0;33mW (58) boot: WDT reset info: PRO CPU PC=0x400803c0<ESC>[0m<CR><LF>
    <ESC>[0;33mW (58) boot: WDT reset info: APP CPU PC=0x8a9e2587<ESC>[0m<CR><LF>
    <ESC>[0;32mI (64) boot: ESP-IDF v3.2-r2 2nd stage bootloader<ESC>[0m<CR><LF>
    <ESC>[0;32mI (69) boot: compile time 12:43:38<ESC>[0m<CR><LF>
    <ESC>[0;32mI (73) boot: Enabling RNG early entropy source...<ESC>[0m<CR><LF>
    <ESC>[0;32mI (79) qio_mode: Enabling default flash chip QIO<ESC>[0m<CR><LF>
    <ESC>[0;32mI (84) boot: SPI Speed      : 80MHz<ESC>[0m<CR><LF>
    <ESC>[0;32mI (88) boot: SPI Mode       : QIO<ESC>[0m<CR><LF>
    <ESC>[0;32mI (92) boot: SPI Flash Size : 4MB<ESC>[0m<CR><LF>
    <ESC>[0;32mI (96) boot: Partition Table:<ESC>[0m<CR><LF>
    <ESC>[0;32mI (100) boot: ## Label            Usage          Type ST Offset   Length   Flags<ESC>[0m<CR><LF>
    <ESC>[0;32mI (108) boot:  0 nvs              WiFi data        01 02 00009000 00004000 00000000<ESC>[0m<CR><LF>
    <ESC>[0;32mI (116) boot:  1 otadata          OTA data         01 00 0000d000 00002000 00000000<ESC>[0m<CR><LF>
    <ESC>[0;32mI (125) boot:  2 app_0            OTA app          00 10 00010000 00180000 00000000<ESC>[0m<CR><LF>
    <ESC>[0;32mI (133) boot:  3 fs_0             SPIFFS           01 82 00190000 00040000 00000000<ESC>[0m<CR><LF>
    <ESC>[0;32mI (141) boot:  4 app_1            OTA app          00 11 001d0000 00180000 00000000<ESC>[0m<CR><LF>
    <ESC>[0;32mI (150) boot:  5 fs_1             SPIFFS           01 82 00350000 00040000 00000000<ESC>[0m<CR><LF>
    <ESC>[0;32mI (158) boot: End of partition table<ESC>[0m<CR><LF>
    <ESC>[0;32mI (162) boot: OTA data 0: seq 0x00000001, st 0x10, CRC 0x157a2b85, valid? 1<ESC>[0m<CR><LF>
    <ESC>[0;32mI (170) boot: OTA data 1: seq 0x00000000, st 0x00, CRC 0x00000000, valid? 0<ESC>[0m<CR><LF>
    <ESC>[0;32mI (177) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x245d0 (148944) map<ESC>[0m<CR><LF>
    <ESC>[0;32mI (225) esp_image: segment 1: paddr=0x000345f8 vaddr=0x3ffb0000 size=0x0253c (  9532) load<ESC>[0m<CR><LF>
    <ESC>[0;32mI (228) esp_image: segment 2: paddr=0x00036b3c vaddr=0x40080000 size=0x00400 (  1024) load<ESC>[0m<CR><LF>
    <ESC>[0;32mI (232) esp_image: segment 3: paddr=0x00036f44 vaddr=0x40080400 size=0x090cc ( 37068) load<ESC>[0m<CR><LF>
    <ESC>[0;32mI (252) esp_image: segment 4: paddr=0x00040018 vaddr=0x400d0018 size=0xa9c60 (695392) map<ESC>[0m<CR><LF>
    <ESC>[0;32mI (434) esp_image: segment 5: paddr=0x000e9c80 vaddr=0x400894cc size=0x07b30 ( 31536) load<ESC>[0m<CR><LF>
    <ESC>[0;32mI (453) boot: Loaded app from partition at offset 0x10000<ESC>[0m<CR><LF>
    <ESC>[0;32mI (454) boot: Disabling RNG early entropy source...<ESC>[0m<CR><LF>
    <ESC>[0;32mI (454) cpu_start: Pro cpu up.<ESC>[0m<CR><LF>
    <ESC>[0;32mI (458) cpu_start: Single core mode<ESC>[0m<CR><LF>
    <ESC>[0;32mI (462) heap_init: Initializing. RAM available for dynamic allocation:<ESC>[0m<CR><LF>
    <ESC>[0;32mI (469) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM<ESC>[0m<CR><LF>
    <ESC>[0;32mI (475) heap_init: At 3FFBA588 len 00025A78 (150 KiB): DRAM<ESC>[0m<CR><LF>
    <ESC>[0;32mI (481) heap_init: At 3FFE0440 len 0001FBC0 (126 KiB): D/IRAM<ESC>[0m<CR><LF>
    <ESC>[0;32mI (488) heap_init: At 40078000 len 00008000 (32 KiB): IRAM<ESC>[0m<CR><LF>
    <ESC>[0;32mI (494) heap_init: At 40090FFC len 0000F004 (60 KiB): IRAM<ESC>[0m<CR><LF>
    <ESC>[0;32mI (500) cpu_start: Pro cpu start user code<ESC>[0m<CR><LF>
    <ESC>[0;32mI (181) cpu_start: Starting scheduler on PRO CPU.<ESC>[0m<CR><LF>
    mgos_hal_freertos.c:177 rtos 1.0 (20190326-164015)<CR><LF>
    mgos_hal_freertos.c:179 Mongoose OS 2.12.1 (20190326-124823/2.12.1-gdd403d6)<CR><LF>
    mgos_hal_freertos.c:182 CPU: 160 MHz, heap: 290172 total, 258440 free<CR><LF>
    mgos_hal_freertos.c:184 Newlib 2.2.0<CR><LF>
    esp32_main.c:116        ESP-IDF v3.2-r2<LF>
    esp32_main.c:119        Boot partition: app_0; flash: 4M<LF>
    mg_lwip_ev_mgr.c:93     Mongoose 6.13, LwIP 2.0.3<LF>
    mg_ssl_if_mbedtls.c:57  mbed TLS 2.13.1-cesanta5<LF>
    mgos_vfs_dev.c:73       fs_0: esp32part ({"label": "fs_0"}), size 262144<LF>
    mgos_vfs_dev.c:73       fs_1: esp32part ({"label": "fs_1"}), size 262144<LF>
    mgos_vfs.c:147          /: SPIFFS @ fs_0, opts {"bs": 4096, "ps": 256, "es": 4096}<LF>
    mgos_vfs.c:319          /: size 233681, used: 2008, free: 231673<LF>
    mgos_sys_config.c:231   Loading conf0.json<LF>
    mgos_sys_config.c:347   MAC: 30AEA49031A8<LF>
    mgos_sys_config.c:355   WDT: 30 seconds<LF>
    mgos_rpc_channel_mq:203 0x3ffc1920 esp32_9031A8/rpc<LF>
    <DC1>mgos_rpc_channel_ua:313 0x3ffc1aa4 UART0<LF>
    mgos_wifi.c:458         WiFi mode: AP<LF>
    esp32_wifi.c:236        cur mode: 0<LF>
    esp32_wifi.c:196        WiFi mode: AP<LF>
    I (666) wifi: wifi driver task: 3ffc31c4, prio:23, stack:3584, core=0<LF>
    I (676) wifi: wifi firmware version: 112656e<LF>
    I (676) wifi: config NVS flash: enabled<LF>
    I (676) wifi: config nano formating: disabled<LF>
    I (686) wifi: Init dynamic tx buffer num: 32<LF>
    I (696) wifi: Init data frame dynamic rx buffer num: 64<LF>
    I (696) wifi: Init management frame dynamic rx buffer num: 64<LF>
    I (706) wifi: Init static rx buffer size: 1600<LF>
    I (706) wifi: Init static rx buffer num: 10<LF>
    I (716) wifi: Init dynamic rx buffer num: 0<LF>
    <ESC>[0;32mI (776) phy: phy_version: 4007, 9c6b43b, Jan 11 2019, 16:45:07, 0, 0<ESC>[0m<CR><LF>
    I (776) wifi: mode : softAP (30:ae:a4:90:31:a9)<LF>
    I (786) wifi: Init max length of beacon: 752/752<LF>
    I (786) wifi: Init max length of beacon: 752/752<LF>
    I (796) wifi: Set ps type: 0<LF>
    <LF>
    esp32_wifi.c:443        WiFi AP: SSID Mongoose_9031A8, channel 6<LF>
    esp32_wifi.c:484        WiFi AP IP: 192.168.4.1/255.255.255.0 gw 192.168.4.1, DHCP range 192.168.4.2 - 192.168.4.100<LF>
    esp32_wifi.c:489        WiFi AP: SSID Mongoose_9031A8, channel 6<LF>
    main.c:61               &&&&&&&&&&&&&&&&&&&&&<LF>
    <LF>
    Free RAM: <CR><LF>
    mgos_init.c:36          Init done, RAM: 289560 total, 223852 free, 223852 min free<LF>
    Guru Meditation Error: Core  0 panic'ed (Unhandled debug exception)<CR><LF>
    Debug exception reason: Stack canary watchpoint triggered (mongoose) <CR><LF>
    Core 0 register dump:<CR><LF>
    PC      : 0x4008d8d3  PS      : 0x00060e36  A0      : 0x40081631  A1      : 0x3ffc8d20  <CR><LF>
    A2      : 0x00000000  A3      : 0x3ffc07d8  A4      : 0x00000025  A5      : 0x00000000  <CR><LF>
    A6      : 0x3ffc0634  A7      : 0x3ffc067c  A8      : 0x4016468c  A9      : 0x3ffc8dc0  <CR><LF>
    A10     : 0x3ffc067c  A11     : 0x3ffc07d8  A12     : 0x00000025  A13     : 0x00000100  <CR><LF>
    A14     : 0x00000001  A15     : 0x00000001  SAR     : 0x00000000  EXCCAUSE: 0x00000001  <CR><LF>
    EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffa  <CR><LF>
    <CR><LF>
    Backtrace: 0x4008d8d3 0x4008162e<CR><LF>
    <CR><LF>
    --- BEGIN CORE DUMP ---<CR><LF>
    {"app": "rtos", "arch": "esp32", "version": "1.0", "build_id": "20190326-164015", "build_image": "docker.io/mgos/esp32-build:3.2-r2",<CR><LF>
    "REGS": {"addr": 1073446480, "data": "<CR><LF>
    

    Facing above problem with rtos using mongoose esp32

Sign In or Register to comment.