FreeRTOS task not executed after 1.5-2 hours

afynfpbz
Posts: 2
Joined: Tue Oct 02, 2018 12:03 am

FreeRTOS task not executed after 1.5-2 hours

Postby afynfpbz » Tue Oct 02, 2018 12:11 am

After 1-2 hours uptime FreeRTOS task not executed.
I can't understand why. Can anybody help me?

app_main : 1) pin for input from IR receiver 2) built-in LED 3) debug output each 5 sec to UART 4) xTaskCreate

Code: Select all

void app_main()
{
    gpio_config_t io_conf;
    io_conf.intr_type = GPIO_INTR_ANYEDGE;
    io_conf.mode = GPIO_MODE_INPUT;
    io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
    io_conf.pull_down_en = 0;
    io_conf.pull_up_en = 1;
    gpio_config(&io_conf);

    setvbuf(stdout, NULL, _IONBF, 0);

    HW_HS0038B_event_queue = xQueueCreate(200,sizeof(HW_HS0038B_event));
    xTaskCreate(HW_HS0038B_task, "HW_HS0038B", 4096, NULL, 10, NULL);

    gpio_install_isr_service(0);
    gpio_isr_handler_add(GPIO_INPUT_IO_0, HW_HS0038B_ISR_handler, (void*)GPIO_INPUT_IO_0 );

    io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
    io_conf.mode = GPIO_MODE_OUTPUT;
    io_conf.pin_bit_mask = (1ULL<<2);
    io_conf.pull_down_en = 0;
    io_conf.pull_up_en = 0;
    gpio_config(&io_conf);

    int cnt = 0;
    while(1) {
        int64_t ts = esp_timer_get_time();
        ts /= 1000;
        printf("%" PRId64 "\n", ts);
        vTaskDelay(5000 / portTICK_RATE_MS);
    }
ISR:

Code: Select all

typedef struct {
    uint64_t t;
    int level;
} HW_HS0038B_event;
static uint32_t HW_HS0038B_prev_ts;
static xQueueHandle HW_HS0038B_event_queue = NULL;
static int debugH = 0;
static void IRAM_ATTR HW_HS0038B_ISR_handler(void* arg) // gpio_num = (uint32_t)arg;
{
    int64_t ts = esp_timer_get_time();
    HW_HS0038B_event e;
    e.t = ts - HW_HS0038B_prev_ts;
    HW_HS0038B_prev_ts = ts;
    e.level = gpio_get_level( (uint32_t)arg );
    gpio_set_level(2,(debugH++)%2);
    xQueueSendFromISR(HW_HS0038B_event_queue, &e, NULL);
}
Then I press button on IR led is blinking - gpio_set_level(2,(debugH++)%2);

Code: Select all

static uint64_t HW_HS0038B_cmd;
static int HW_HS0038B_pos;
static void HW_HS0038B_task(void* arg)
{
    HW_HS0038B_event e;
    while(true) {
        if ( pdPASS != xQueueReceive(HW_HS0038B_event_queue, &e, portMAX_DELAY) )
            continue;
        if ( e.t >= 2000 ) {
            HW_HS0038B_cmd = HW_HS0038B_pos = 0;
            continue;
        }
        if ( e.t < 1000 )
            HW_HS0038B_cmd |= (1<<HW_HS0038B_pos);

        printf("%d 0x%" PRIx64 "\n", HW_HS0038B_pos, HW_HS0038B_cmd);

        HW_HS0038B_pos++;
    }
}
But this task don't work after 1-2 hours.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: FreeRTOS task not executed after 1.5-2 hours

Postby ESP_Angus » Tue Oct 02, 2018 1:42 am

When you say "But this task don't work after 1-2 hours.", does the ISR keep processing (ie does the LED keep updating)?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: FreeRTOS task not executed after 1.5-2 hours

Postby ESP_Angus » Tue Oct 02, 2018 1:45 am

Oh, I see the bug. I think you'll see it too, shortly. Here are the relevant parts of the code:

Code: Select all

static uint32_t HW_HS0038B_prev_ts;

Code: Select all

   int64_t ts = esp_timer_get_time();
   ...
    e.t = ts - HW_HS0038B_prev_ts;
    HW_HS0038B_prev_ts = ts;

Code: Select all

    while(true) {
        if ( pdPASS != xQueueReceive(HW_HS0038B_event_queue, &e, portMAX_DELAY) )
            continue;
        if ( e.t >= 2000 ) {
            HW_HS0038B_cmd = HW_HS0038B_pos = 0;
            continue;
        }
A hint: 2^32 microseconds is 71 minutes.

afynfpbz
Posts: 2
Joined: Tue Oct 02, 2018 12:03 am

Re: FreeRTOS task not executed after 1.5-2 hours

Postby afynfpbz » Tue Oct 02, 2018 8:57 am

>> When you say "But this task don't work after 1-2 hours.", does the ISR keep processing (ie does the LED keep updating)?
Yes. UART and ISR still running.

>> Oh, I see the bug. I think you'll see it too, shortly. Here are the relevant parts of the code...
Thank you very much, I change type.
e.t will be more 2000 long time...
I must be more attentive, because other tasks still executing more week.

Reload application, wait now.

Who is online

Users browsing this forum: No registered users and 81 guests