Understand Zephyr Task states

Hi,

I am moving from FreeRTOS to Zephyr. So I jused some of your simple example for trying to understand basics. I edited it little bit.

I have some default task from example called main. In the main is while loop and in this loop is checked variable startTX. When button is pushed the ISR function sets the variable startTX = true, then in the infinite loop some data are trasnmitted (depends on startTX state). Unfortunetelly this works only when I add k_sleep(10) or  LOG_INF("Main completed"); at the end of while.

My question is why the infinite while in the main is not infinite? It looks like the while runs only once and at the end of loop, the Zephyr goes to some idle state and main task is not running. I have only one task main. Time slicing is defult off.

Here is my loop:

while (1) {

        if (startTx){
            LOG_INF("Start TX");
            if (ready) {
                gpio_pin_set_dt(&led,1);
                ready = false;
                startTx = false;
                esb_flush_tx();

                err = esb_write_payload(&tx_payload);
                if (err) {
                    LOG_ERR("Payload write failed, err %d", err);
                }
                tx_payload.data[1]++;
                LOG_INF("Packet sent");
            }
        }
       
        //k_sleep(K_MSEC(10));
        LOG_INF("Main completed");
    }
Parents
  • Hi,

    The snippet you have here is just an eternal loop that calls some functions, and skips parts of it depending on the value of the two variables startTx and ready. There is no task related functionality here (except for the commented out call to k_sleep()), so this task and this main loop will run at all times. Could it be that you just don't set ready to true somewhere?

  • Hi,

    understand, problem is that this main loop works only when I add k_sleep or LOG(..) at the end, when I comment it, so nothing in the main loop is working - only once. 

    I am just a novice in Nordic world, need more time to get oriented. BTW is there any fast way how to disable all logging in my project? LOG_DBG, LOG_ERR,  LOG_INF?

    When I edit CONFIG_ESB=y to  CONFIG_ESB=n in prj.conf, so erros during building appears.

    Thank you.

Reply
  • Hi,

    understand, problem is that this main loop works only when I add k_sleep or LOG(..) at the end, when I comment it, so nothing in the main loop is working - only once. 

    I am just a novice in Nordic world, need more time to get oriented. BTW is there any fast way how to disable all logging in my project? LOG_DBG, LOG_ERR,  LOG_INF?

    When I edit CONFIG_ESB=y to  CONFIG_ESB=n in prj.conf, so erros during building appears.

    Thank you.

Children
  • witc said:
    understand, problem is that this main loop works only when I add k_sleep or LOG(..) at the end, when I comment it, so nothing in the main loop is working - only once. 

    Have you attempted to debug? If you step in the code, what do you see?

    witc said:
    BTW is there any fast way how to disable all logging in my project? LOG_DBG, LOG_ERR,  LOG_INF?

    You can disable logging using this in your prj.conf:

    CONFIG_LOG=n
    CONFIG_SERIAL=n

    witc said:
    When I edit CONFIG_ESB=y to  CONFIG_ESB=n in prj.conf, so erros during building appears.

    That should normally not be a problem, but if your application use some ESB functionality, it would be different and you will get expected build errors (I have only seen your main loop so I do not know what else is there).

Related