FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [November 2010 Threads] Starting 'N' Tasks with a counting sem...Posted by steveb on November 25, 2010 Hello All.
(Using PIC32 Starter Kit)
I'm trying to implement a sync/task start mechanism using counting semaphores. The purpose is to ensure all task Q's/Semaphores and H/W is configured before any task begins communicating with another task.
I have 5 tasks, each creating a Q or semaphore and corresponding H/W configuration. Each task calls semGive on a counting (taskReady) semaphore then immediately blocks on another counting (taskStart) semaphore. I have a 6th 'supervisor' task that blocks on the taskReady semaphore and loops (semTake) around this semaphore until all tasks have reported ready. Once all tasks have given the taskReady semaphore, the 'supervisor' task then gives the taskStart semaphore 5 times to allow each task to continue.
The problem I'm facing is only the following two tasks that are created after the supervisor task (from within main()) ever start i.e. supervisor is created 1st followed by task A, task B etc.... These tasks, A and B call semGive(taskReady) and the supervisor task unblocks twice (semTake(taskReady). A breakpoint in the third created task (or any of the other tasks) never hits?
My understanding is that each task should start in accordance with the scheduler rules i.e based on the task pri or maybe the task creation order. After the supervisor task is unblocked twice for task A/B's semGive(taskReady), it becomes blocked again (permantently). I would expect one of the other tasks to run and call its semGive(taskReady)?
Any suggestions/advice would be greatly appreciated.
Regards, Steve
RE: Starting 'N' Tasks with a counting sem...Posted by Dave on November 25, 2010 It sounds like a very complex scheme and suspect the problem lies in its complexity somewhere.
Why not initialize the hardware before starting the scheduler? If you want to modularize the drivers you can still have the driver encapsulate an initialization function that is called before the task is started.
Alternatively you could have the tasks suspend themselves when they are ready and then the main task can simply check that all the tasks are suspended before starting the real work.
RE: Starting 'N' Tasks with a counting sem...Posted by Richard Damon on November 25, 2010 One though, have you checked that the tasks were successfully created? If you run out of heap, then the tasks won't all be created.
RE: Starting 'N' Tasks with a counting sem...Posted by steveb on November 25, 2010 Thx chaps for the prompt feedback!
It seems I should not have been lazy and checked if each task was created correctly. Turns out more memory is required. Good call Richard.
Dave - thx for your suggestion as well.
Cheers, Steve
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|