• AVR Freaks

Hot!RTOS in PIC32

Page: 12 > Showing page 1 of 2
Author
Shishi
Super Member
  • Total Posts : 370
  • Reward points : 0
  • Joined: 2016/06/15 05:34:10
  • Location: 0
  • Status: offline
2018/12/05 09:32:08 (permalink)
0

RTOS in PIC32

Hello everyone 
i am using pic32MZ2048EFM144 with harmony v2.06. can any body tell me what is the function of
"portTASK_FUNCTION( prvIdleTask, pvParameters )" in task.c of freeRtos.
it has some discription but i did not understand at the end.
e.x 
/* See if any tasks have deleted themselves - if so then the idle task
is responsible for freeing the deleted task's TCB and stack. */
what does mean "if any tasks deleted themselves"?when it occurs?
#1

35 Replies Related Threads

    rjc101
    Super Member
    • Total Posts : 119
    • Reward points : 0
    • Joined: 2016/07/08 14:56:34
    • Location: 0
    • Status: offline
    Re: RTOS in PIC32 2018/12/05 10:30:40 (permalink)
    0
    That is the Idle task, which runs when no other task is able to (by being suspended, blocked, etc.) or no other tasks exist.
    the FreeRTOS website fully documents how it all works, and you can download .pdf manuals too if you want.
     
    https://www.freertos.org/RTOS-idle-task.html 
    #2
    crosland
    Super Member
    • Total Posts : 1936
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: RTOS in PIC32 2018/12/05 11:17:41 (permalink)
    0
    If a task has done its work it can delete itself, rather than just become permanently idle. Something needs to do some housekeeping, e.g., in this case freeing up the memory that was allocated to the task.
    #3
    Shishi
    Super Member
    • Total Posts : 370
    • Reward points : 0
    • Joined: 2016/06/15 05:34:10
    • Location: 0
    • Status: offline
    Re: RTOS in PIC32 2018/12/06 04:31:37 (permalink)
    0
    in system_tasks.c why 1 ms task delay "vTaskDelay(1 / (portTICK_PERIOD_MS));"is needed?it is used for both _SYS_Tasks() and _APP_Tasks() ruotins.
    post edited by Shishi - 2018/12/06 04:56:15
    #4
    friesen
    Super Member
    • Total Posts : 2123
    • Reward points : 0
    • Joined: 2008/05/08 05:23:35
    • Location: Indiana, USA
    • Status: offline
    Re: RTOS in PIC32 2018/12/06 14:41:15 (permalink)
    0
    vTaskDelay yields so that other tasks can run.  Otherwise it will run until the tick happens.  If you would have a tick rate of 5ms for example, this would mean spending 5ms in this task every time, even if you don't need to.

    Erik Friesen
    #5
    Shishi
    Super Member
    • Total Posts : 370
    • Reward points : 0
    • Joined: 2016/06/15 05:34:10
    • Location: 0
    • Status: offline
    Re: RTOS in PIC32 2018/12/08 04:14:09 (permalink)
    0
    is there anybody that knows if any created task not working anymore how can restar them?
    i saw in sys_tasks() ,2 tasks are created and then vTaskStartScheduler() is used.
    if for any reason tasks not work any more is there any possibility to restart them?
    #6
    rjc101
    Super Member
    • Total Posts : 119
    • Reward points : 0
    • Joined: 2016/07/08 14:56:34
    • Location: 0
    • Status: offline
    Re: RTOS in PIC32 2018/12/08 09:13:01 (permalink)
    0
    A task never quits, or it shouldn't, so it's always running until it is either blocked, or deleted.  You can create tasks before or after you start the scheduler, but no task will actually see any CPU time until the scheduler is running.  So it kind of depends on what you mean by "not working".
     
    You may find it better for in-depth FreeRTOS questions to post on their direct support forums if the information is available from the main FreeRTOS website.  The support site is monitored by the author of FreeRTOS.
     
    https://sourceforge.net/p/freertos/discussion/382005/
    https://www.freertos.org
     
    #7
    Shishi
    Super Member
    • Total Posts : 370
    • Reward points : 0
    • Joined: 2016/06/15 05:34:10
    • Location: 0
    • Status: offline
    Re: RTOS in PIC32 2018/12/10 02:32:38 (permalink)
    0
    rjc101
    A task never quits, or it shouldn't, so it's always running until it is either blocked, or deleted.  You can create tasks before or after you start the scheduler, but no task will actually see any CPU time until the scheduler is running.  So it kind of depends on what you mean by "not working".
     
    You may find it better for in-depth FreeRTOS questions to post on their direct support forums if the information is available from the main FreeRTOS website.  The support site is monitored by the author of FreeRTOS.
     
    https://sourceforge.net/p/freertos/discussion/382005/
    https://www.freertos.org
     


    i am quite sure that tasks become stoped and always program is runing in portTASK_FUNCTION( prvIdleTask, pvParameters ). and not exite anymore . it is just happend when i am connecting to wifi modul.(i am using tcp/ip with freertos using wifi moodul and ethernet).
    so we can say or they are deleted or blocked but why?
    i tried to used vTaskEndScheduler() and then create again tasks and vTaskStartScheduler(). i saw that i can create _sys_task but _App_task no, and i think it is because i can not free memory allocated by app_ tasks as explained functionality of vTaskEndScheduler():

    * vTaskEndScheduler () will cause all of the resources allocated by the
    * kernel to be freed - but will not free resources allocated by application
    * tasks.

    how can i do it?
    #8
    rjc101
    Super Member
    • Total Posts : 119
    • Reward points : 0
    • Joined: 2016/07/08 14:56:34
    • Location: 0
    • Status: offline
    Re: RTOS in PIC32 2018/12/10 03:07:13 (permalink)
    0
    The only way to free the memory of a task that isn't used any more is to delete the task (vTaskDelete), stopping the scheduler will stop everything.
    Have a read through the FreeRTOS documentation, the is a bit on task starts here...
     
    https://www.freertos.org/a00015.html
     
    If you have not worked with FreeRTOS (or any other RTOS for that matter) it's worth going through the documentation and not the code to start with, it will make much more sense.  Everything is up on the FreeRTOS website.
     
    One of your tasks may block for a number of reasons, either intentionally or not.  Going into the idle task is perfectly normal, depending on the structure of your code.  You can also run FreeRTOS in preemptive or co-operative mode that can make a difference too.  For more in-depth FreeRTOS questions you're really better to ask on the support forum I mentioned above, the author is very active on there.
     
     
    #9
    Shishi
    Super Member
    • Total Posts : 370
    • Reward points : 0
    • Joined: 2016/06/15 05:34:10
    • Location: 0
    • Status: offline
    Re: RTOS in PIC32 2018/12/10 04:04:33 (permalink)
    0
    rjc101
    The only way to free the memory of a task that isn't used any more is to delete the task (vTaskDelete), stopping the scheduler will stop everything.
    Have a read through the FreeRTOS documentation, the is a bit on task starts here...
     
    https://www.freertos.org/a00015.html
     
    If you have not worked with FreeRTOS (or any other RTOS for that matter) it's worth going through the documentation and not the code to start with, it will make much more sense.  Everything is up on the FreeRTOS website.
     
    One of your tasks may block for a number of reasons, either intentionally or not.  Going into the idle task is perfectly normal, depending on the structure of your code.  You can also run FreeRTOS in preemptive or co-operative mode that can make a difference too.  For more in-depth FreeRTOS questions you're really better to ask on the support forum I mentioned above, the author is very active on there.
     
     


    thanks for your help.
    i also tried to use vTaskDelete but the problem is the same,because it does not free the memory,so i can not recreate the task. as you can see in explanation of the vTaskDelete:

    Memory allocated by the task code is not automatically freed, and should be freed before the task is deleted.

     
    #10
    rjc101
    Super Member
    • Total Posts : 119
    • Reward points : 0
    • Joined: 2016/07/08 14:56:34
    • Location: 0
    • Status: offline
    Re: RTOS in PIC32 2018/12/10 04:11:11 (permalink)
    0
    There should be no need to delete and recreate a task, basically any task sits in a do while(1) loop and never actually quits, it is either doing something, is blocked waiting to do something, or can be suspended until needed.
     
    If you use malloc inside a task, then yes that will all need to be freed before you delete the task, but any memory related to the task creation (it's stack for example) will be cleared once it's been deleted and the idle task runs.
     
    Why do you need to delete and recreate the same task?  What are you looking to achieve?
    #11
    Shishi
    Super Member
    • Total Posts : 370
    • Reward points : 0
    • Joined: 2016/06/15 05:34:10
    • Location: 0
    • Status: offline
    Re: RTOS in PIC32 2018/12/10 04:44:50 (permalink)
    0
    rjc101
    There should be no need to delete and recreate a task, basically any task sits in a do while(1) loop and never actually quits, it is either doing something, is blocked waiting to do something, or can be suspended until needed.
     
    If you use malloc inside a task, then yes that will all need to be freed before you delete the task, but any memory related to the task creation (it's stack for example) will be cleared once it's been deleted and the idle task runs.
     
    Why do you need to delete and recreate the same task?  What are you looking to achieve?


    the problem is i can not find the reason that why both tasks do not run any more i mean both while(1)of them is not runing i thought maybe they becomes deleted or whatelse, i just want to restart them again and do not  know how.
    1.First i have to find why both of them stop runing, and i have this problem only when i am connecting to wifi module.
    2.second i want to know how can i restart them or unblocked them.
    is that wrong?maybe the way that i choosed is not correct.
    any idea???
    #12
    qhb
    Superb Member
    • Total Posts : 9999
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: RTOS in PIC32 2018/12/10 06:20:43 (permalink)
    0
    Are these tasks that you wrote?
    The most likely explanation is bugs in your code.
     

    Nearly there...
    #13
    Shishi
    Super Member
    • Total Posts : 370
    • Reward points : 0
    • Joined: 2016/06/15 05:34:10
    • Location: 0
    • Status: offline
    Re: RTOS in PIC32 2018/12/10 06:22:49 (permalink)
    0
    qhb
    Are these tasks that you wrote?
    The most likely explanation is bugs in your code.
     


    no they are from harmony, Tcpip freeRtos(harmony V2.06).
    #14
    Shishi
    Super Member
    • Total Posts : 370
    • Reward points : 0
    • Joined: 2016/06/15 05:34:10
    • Location: 0
    • Status: offline
    Re: RTOS in PIC32 2018/12/12 03:05:00 (permalink)
    0
    i tried to see what console tells me in the moment of the issue:
    "[hif_handle_isr](HIF) fail to handle interrupt -12 try gain..
    Wi-Fi Assert: failed to handle m2m events
    winc1500_task.c, line 392"
    that is this routin:

    void winc1500_task(void *arg)
    {
    WINC1500_INTF *intf = (WINC1500_INTF *)arg;
    if (intf->ethMode || intf->fwOtaServerUrl)
    winc1500_task_init(intf);
    else
    winc1500_task_init2(intf);
    while (true) {
    int8_t ret;
    ret = m2m_wifi_handle_events(&g_wdrvext_priv.eventWait);
    if (ret != M2M_SUCCESS) {
    WDRV_ASSERT(false, "Failed to handle m2m events");
    break;
    }
    if (g_wdrvext_priv.deinit_in_progress)
    break;
    }
    winc1500_task_deinit();
    g_wdrvext_priv.deinit_in_progress = false;
    while (true) /* Wait for task to be deleted. */ //---------why?????????????
    WDRV_TIME_DELAY(1000);
    }

    what should i do in this case? how can i prevent this or if it is really deleted wifi task what should i do?
    #15
    friesen
    Super Member
    • Total Posts : 2123
    • Reward points : 0
    • Joined: 2008/05/08 05:23:35
    • Location: Indiana, USA
    • Status: offline
    Re: RTOS in PIC32 2018/12/12 05:31:33 (permalink)
    0
    Check your hardware connections to your
    WiFi module. Also, you have to prevent the interrupt from firing until the module actually asks for it. Frankly though, the harmony WiFi driver needs help.

    Erik Friesen
    #16
    Shishi
    Super Member
    • Total Posts : 370
    • Reward points : 0
    • Joined: 2016/06/15 05:34:10
    • Location: 0
    • Status: offline
    Re: RTOS in PIC32 2018/12/12 07:02:01 (permalink)
    0
    friesen
    Check your hardware connections to your
    WiFi module. Also, you have to prevent the interrupt from firing until the module actually asks for it. Frankly though, the harmony WiFi driver needs help.

    can this problem relative to using i/o of Winc1500? because i am using its i/o and i found in one forum that said:"The function, m2m_periph_gpio_set_val() uses the SPI port.  In the middle of a call to the SPI write, the function hif_handle_isr() was also using this SPI port."
    the forum is: https://www.microchip.com/forums/m1046008.aspx
    #17
    friesen
    Super Member
    • Total Posts : 2123
    • Reward points : 0
    • Joined: 2008/05/08 05:23:35
    • Location: Indiana, USA
    • Status: offline
    Re: RTOS in PIC32 2018/12/12 07:26:29 (permalink)
    0
    Yes, you have to have some mutex to prevent that.
     
    if (xSemaphoreTake(HifMutex, 100 / portTICK_PERIOD_MS) == pdTRUE) {
      m2m_wifi_handle_events(NULL);
      (void) xSemaphoreGive(HifMutex);
    }

    Erik Friesen
    #18
    friesen
    Super Member
    • Total Posts : 2123
    • Reward points : 0
    • Joined: 2008/05/08 05:23:35
    • Location: Indiana, USA
    • Status: offline
    Re: RTOS in PIC32 2018/12/12 07:28:33 (permalink)
    0
    Also you need to use the mutex for anything that calls a m2m function.
     

    Erik Friesen
    #19
    Shishi
    Super Member
    • Total Posts : 370
    • Reward points : 0
    • Joined: 2016/06/15 05:34:10
    • Location: 0
    • Status: offline
    Re: RTOS in PIC32 2018/12/12 07:51:07 (permalink)
    0
    friesen
    Yes, you have to have some mutex to prevent that.
     
    if (xSemaphoreTake(HifMutex, 100 / portTICK_PERIOD_MS) == pdTRUE) {
    m2m_wifi_handle_events(NULL);
    (void) xSemaphoreGive(HifMutex);
    }


    sorry but i could not understand where should i use this function?and should i put my m2m_periph_gpio_set_val() in this function?
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5