This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RL-ARM - Determining priority of current task

I would like to briefly increase the priority of a currently running task and then revert the priority level.

The example given at:

www.keil.com/.../rlarm_os_tsk_prio_self.htm

shows how to do this.

void task1 (void) __task {
    .
    .
   os_tsk_prio_self(10);  /* Increase its priority, for the critical section */
    .                     /* This is a critical section */
    .
   os_tsk_prio_self(2);   /* Decrease its priority at end of critical section */
    .
    .
}

Trouble is, I would like to include this boost within a routine used by various tasks. I know at design time what level to boost to, but the level to return to would need to be determined at run time.

   OldPriority = CURRENT_TASK_PRIORITY_LEVEL;
    .
    .
   os_tsk_prio_self(10);
    .
    .
   os_tsk_prio_self(OldPriority);

I've looked for a function to determine the current task priority level, but cannot find one.

Anyone know of a way of doing this?

Parents
  • If the facility to determine the priority level isn't there, then keeping track of priorities independently (as I type this I see your second response!) might be worth considering.

    I, too, find it a bit odd that there are ways in the API to set the priority of a task, but none to query it. The latter would involve messing with the internals of the operating system directly, and I doubt this is worth the trouble.

    A rather convoluted way, but one that does use the API, would be to have a high-priority "dummy" task that does nothing but wait for an event, try to acquire the mutex, and immediately release it.

    And task that wants its priority raised to that of the "dummy" task could then acquire the mutex abd send the signal the high-priority task is waiting for. The "dummy" task then tries to acquire the mutex (which the normal task has), which raises the priority of the normal task to that of the "dummy" task.

    Once the normal task is finished, it releases the mutex and hence gets bumped down to its usual priority. The "dummy" task then acquires the mutex, immediately releases it, and waits for the next event.

    Yep, convoluted, but should do _exactly_ what you're trying to do, without bypassing the API or other hacks.

    Here the pseudocode:

    void high_priority_dummy_task()
    {
       for(;;)
       {
       wait_for_event();
       acquire_mutex();
       release_mutex();
       }
    }
    
    void task_that_wants_its_priority_raised()
    {
       ...
       acquire_mutex();
       send_event();
    
       do_high_priority_stuff();
    
       release_mutex();
       ...
    }
    

Reply
  • If the facility to determine the priority level isn't there, then keeping track of priorities independently (as I type this I see your second response!) might be worth considering.

    I, too, find it a bit odd that there are ways in the API to set the priority of a task, but none to query it. The latter would involve messing with the internals of the operating system directly, and I doubt this is worth the trouble.

    A rather convoluted way, but one that does use the API, would be to have a high-priority "dummy" task that does nothing but wait for an event, try to acquire the mutex, and immediately release it.

    And task that wants its priority raised to that of the "dummy" task could then acquire the mutex abd send the signal the high-priority task is waiting for. The "dummy" task then tries to acquire the mutex (which the normal task has), which raises the priority of the normal task to that of the "dummy" task.

    Once the normal task is finished, it releases the mutex and hence gets bumped down to its usual priority. The "dummy" task then acquires the mutex, immediately releases it, and waits for the next event.

    Yep, convoluted, but should do _exactly_ what you're trying to do, without bypassing the API or other hacks.

    Here the pseudocode:

    void high_priority_dummy_task()
    {
       for(;;)
       {
       wait_for_event();
       acquire_mutex();
       release_mutex();
       }
    }
    
    void task_that_wants_its_priority_raised()
    {
       ...
       acquire_mutex();
       send_event();
    
       do_high_priority_stuff();
    
       release_mutex();
       ...
    }
    

Children