RTOS - delay_ms hangs

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi  everybody,

Why I can't use delay_ms insite a task?
I have to use de delay because of interval about AT commands, start modem etc

 

static void gsm_task(void *p) {

int x = 0;

(void)p;

while (1) {

if (xSemaphoreTake(disp_mutex, ~0)) {

 

gpio_set_pin_level(START_MODEM, true);

gpio_set_pin_level(PWR_KEY, false);

delay_ms(100);

gpio_set_pin_level(PWR_KEY, true);

delay_ms(10000);

 

x++; // Just for breakpoint

xSemaphoreGive(disp_mutex);

        }

 

        os_sleep(5000);

}

After xSemaphoreGive the RTOS hangs and does not execute tasks anymore.

Any help will be apprecciated.

Best Regards
Thanks

Adriano

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Why do you use delay_ms when you have os_sleep at your disposal?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Anytime you need to "wait" in a RTOS, give control back to the OS and let it do something productive with the time.

In this case use os_sleep(number of ms);

 

Jim

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And just to point out that:

delay_ms(100);

is really probably nothing much more than:

for (uint64_t counter = 0; counter < some_big_number_caculated_to_be_100ms; counter++) {
    asm("nop"):
}

So this "holds execution". (though in a pre-emptive OS something will likely task switch out of this long loop a number of times - that in itself will make the 100ms calculation wrong!)

 

Having said that what OS is this and where does the delay_ms() come from? For all we know maybe it is already implemented as:

void delay_ms(int n) {
    while (n--) {
        os_sleep(1);
    }
}

or something like that? If so then it *should* work as the name suggests I guess? (assuming in my example that os_sleep() really can deliver a 1ms granularity?)

 

EDIT: From the xSemaphoreTake() call it looks very like this is FreeRTOS. If so then I can't see that it has delay_ms() so I guess this is something in your own code? What it does have is:

 

https://www.freertos.org/a00127.html

 

EDIT2: having said that I can't see that it natively has os_sleep() either so are delay_ms() and os_sleep() some kind of wrappers around lower FreeRTOS provide functions? Is this your own implementation or are you using something dreadful like ASF ??

 

EDIT3: clearly more coffee needed here - just spotted that this post is in the ASF forum - so I guess these things are ASF nonsense then?

 

EDIT4: I found an ASF document that mentions both os_sleep() and delay_ms():  https://usermanual.wiki/Document/ASF420API20Reference20Manual.198802149.pdf  it says it is an API reference and yet it only has one mention of each API - each in example code with no explanation of what the functions do. However other digging suggests "delay_ms()"  is nothing to do with FreeRTOS but is an independent cycle waster perhaps.

Last Edited: Thu. Jun 27, 2019 - 01:33 PM