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

ARM RTOS help required urgent

hello friends
i have written the code for ARM RTOS, i have used same priority for all of my 4 task, its working fine

my problem is when i change the priority in the code then all task's are not executing simultaneously....
please any one help

  • I'm saying that when you have tasks with same priority, you can have the RTOS let each task run for a lite while in a round robin order.

    When you have tasks with different priorities, you must make sure that tasks with high priority have some method to decide when they have work to do (and consumes 100% CPU time) and when they can donate CPU time to lower-prioritized threads.

    One way for a high-priority task to donate CPU time is to make use of delay/sleep calls, telling the OS that the thread don't need any CPU time for x time slices.

    Another way is a high-priority task that waits for an event. While the event isn't available, the OS will dedicate the CPU capacity to other tasks. As soon as an interrupt or other thread sets the event, or sends mail or whatever, then the high-prio task will wake up and do the requested action before going to sleep again, waiting for yet another event.

    But in the end, you only have one processor. It can't be at multiple locations at the same time. With "normal" operating systems, the OS will slowly increase the priority of starved tasks until they get a tiny bit of CPU time before they drop back to their low priority again.

    An RTOS is designed for real-time performance. It expects the developer to make the decisions how to prioritize and make sure that different tasks gets performed within their specific timing requirements. You are that developer. Have you set up rules for what your realtime requirements are? Have you verified that all your tasks fulfills their own requirements without breaking requirements for other - same or higher prioritized - tasks? You have a limited CPU budget - how are you spending it?

  • Thank you Per Westermark

    i hope i dont know the concept of the OS first of a;ll
    so
    can any one guide/provide me some sites for knowing the OS concept Properly?

  • "can any one guide/provide me some sites for knowing the OS concept Properly?"

    The following might be a pretty good start:

    http://www.keil.com/download/docs/403.asp

  • please tell me when the event will set in the down code

    os_evt_set (0x00ff,tsk4);

  • os_evt_wait_or (0x0001, 0xffff); // Wait until ISR triggers an event

    when the ISR will trigger that event
    i means when that event will set?

  • Your code must call os_evt_set() or isr_evt_set() when your code have decided that it needs something done by the thread that is listening for that specific event.

    If your program never needs the receiving thread to be woken up and process any event then maybe your code don't even need that thread.

    So if you have a thread buzzer_thread, then that thread can sleep until some other part of the program needs the buzzer to sound. Then the part that wants the buzzer to sound can set the event, getting the buzzer thread to wake up and activate the buzzer.

    Note that threads are used when you need multiple things performed concurrently. If all you need is to set a GPIO pin to start a buzzer and then clear the pin x seconds or milliseconds later, then you would normally not need a buzzer thread - it would be simple to have a main loop set the buzzer and have your time handling (counting OS time slices or maybe timer interrupts or whatever) silence the buzzer after a suitable amount of time.

    In the end, you must decide what is suitable threads. And you must decide if the individual threads needs to perform work continuously (motivating either round-robin execution using same priority, or letting them have a loop with a sleep in), or if some of the threads should only be woken up when specific things happens (such as when the clock becomes 07:00 in the mortning, or when someone presses a button or serial data is received from an UART), or if some of the threads should activate periodically such as once every second.

    We don't know anything about your project, so we can't tell what is suitable tasks, or what is suitable reasons for them to wake up.

  • thank you Per Westermark

    please tell me how about in this code

    void job3 (void) __task
    {

    while (1)
    {

    SPI();
    counter3++;
    if (counter3 == 0)
    {

    os_evt_set (0x00ff,tsk4);
    os_tsk_pass ();
    } }
    }

  • Do you think that "counter3" is used correctly? Are you really waiting for it to overflow? Is it the intention to carry out so many SPI transactions...?

  • yes counter 3 is used correctly
    and code is working fine but i am not understanding os_evt_set (0x00ff,tsk4); ?

  • I'll ask again: are you SURE that you need that variable to overflow before you set that event? if it is an unsigned 16 bit variable, you will have to wait 65536 iterations!

  • Let's try once more:

    and code is working fine but i am not understanding os_evt_set (0x00ff,tsk4); ?

    Why are you not reading the use manual of RTX? Need to be spoon fed? Not by me thank you very much!

  • Don't you believe in indenting your code, and posting it using the proper tags, as clearly specified just above the message input box?

    void job3 (void) __task {
        while (1) {
            SPI();
            counter3++;
            if (counter3 == 0) {
                os_evt_set (0x00ff,tsk4);
                os_tsk_pass ();
            }
        }
    }
    

    The above code is almost totally meaningless.

    Why?

    1) There isn't a single comment telling what it is expected to do, or more specifically why it things it does what it does.

    2) You make 2^8 or 2^16 or 2^32 iterations of your loop - each iteration with a single call to SPI (which does some SPI communication without we knowing anything about if it just polls something or if it does a full transfer or whatever) and a single increment of your counter3 (which really is not a descriptive name of a symbol - counter3 third counter of what?)

    3) First after having done 2^8 or 2^16 or 2^32 (or maybe even 2^64) iterations of your loop, you get an overflow and enter the body of the if statement. It sends a whole bunch of event flags to your tsk4 (yet another totally meaningless name - the goal of the task can't be to be #4, it really must have a purpose of some kind). Why send many event flags? A task may listen for multiple event flags, but you normally send single event flags depending on what event you want to announce. So you can send MY_EVENT_BEEP_BUZZER, MY_EVENT_HAVE_UART_DATA, MY_EVENT_xx and the task can poll or wait for any of the events to happen and then perform the corresponding action before starting to listen for more events.

    4) First when the counter overflow do you call os_tsk_pass() - why? Did you think it would be a good idea to suddenly manually share a bit of the processor CPU time? If the processor is just round-robin-scheduling, then this call doesn't really fill any purpose other than to shorten this specific time slice. if it isn't round-robin-scheduling and this is a high-prio thread - how much CPU time do you think the other threads did get before you entered the if body? How much time do 2^8 or 2^16 or 2^32 or 2^64 calls to SPI() take?

    5) Note also that os_tsk_pass() only shares CPU time with other tasks of same priority. If you have tasks with higher priority ready to run, then this task wouldn't have run so it wouldn't have been able to call os_tsk_pass(). And if you had other tasks with lower priority, they would still be at lower priority and not be allowed to run by your call to os_tsk_pass() - it can only send execution to the next task with same priority as your task3. If there are no other ready task with same priority, then task3 will instantly continue and start to do a new round of 2^8 or 2^16 or 2^32 or 2^64 calls to SPI().

    So I really think you have to sit down and figure out what you want to do. And then read the documentation for the quite few functions available in RTX. It doesn't take long to read the descriptions and figure out what they do. And it doesn't take long to look at the sample code available in the manual and figure out how they are intended to be used. First then will it be meaningful for you to try to write any multithreaded application.


  • The os_evt_set function sets the event flags for the task identified by the function argument.

    i understood up to here
    The function only sets the event flags whose corresponding bit is set to 1 in the event_flags argument.

    please any one describe it properly

  • I already did - didn't you read item 3 in my previous post?

  • Thankyou so much ,
    my questions might irritates you all but i am very sorry for that, because i am a beginner, i read the user manual but bit confusion in that ....

    my code is here

    #include<lpc214x.h>
    #include"adc.h"
    #include"buzzer.h"
    #include"spi.h"
    /* Include type and function declarations for RTX */
    
    #include <RTX_Config.h>
    #include <RTL.h>                      /* RTX kernel functions & defines      */
    
    OS_ID semaphore;
    
    OS_TID tsk1;                          /* assigne identification for task 1   */
    OS_TID tsk2;                          /* assigne identification for task 2   */
    OS_TID tsk3;                          /* assigne identification for task 3   */
    OS_TID tsk4;                          /* assigne identification for task 4   */
    
    short counter1;                       /* counter for task 1                  */
    short counter2;                       /* counter for task 2                  */
    short counter3;                       /* counter for task 3                  */
    short counter4;                       /* counter for task 4                  */
    
    void job1 (void) __task;
    void job2 (void) __task;
    void job3 (void) __task;
    void job4 (void) __task;
    
    /*----------------------------------------------------------------------------
     *   Task 1:  RTX Kernel starts this task with os_sys_init (job1)
     *---------------------------------------------------------------------------*/
    void job1 (void) __task
    {
      os_sem_init (semaphore, 2);
    
      os_tsk_prio_self (3);               /* higher priority to preempt job3  */
      tsk1 = os_tsk_self ();              /* get own task identification number  */
      tsk2 = os_tsk_create (job2,3);      /* start task 2                        */
      tsk3 = os_tsk_create (job3,2);      /* start task 3                        */
      tsk4 = os_tsk_create (job4,2);      /* start task 4                        */
    
      while (1)                                       /* endless loop                        */
      {
            buzzer();                                 /*turn on buzzer whenever we press some key*/
    
        counter1++;                       /* increment counter 1                 */
        os_dly_wait (5);                  /* wait for timeout: 5 ticks           */
      }
    }
    
    /*----------------------------------------------------------------------------
     *   Task 2 'job2':  RTX Kernel starts this task with os_tsk_create (job2,2)
     *---------------------------------------------------------------------------*/
    void job2 (void) __task                           /* higher priority to preempt job3  */
    {
            while (1)                                                 /* endless loop                        */
            {                                                                 /*Display the converted value on the LCD*/
                ADC();
                counter2++;                       /* increment counter 2                 */
                os_dly_wait (10);                 /* wait for timeout: 10 ticks          */
            }
    }
    
    /*----------------------------------------------------------------------------
     *   Task 3 'job3':  RTX Kernel starts this task with os_tsk_create (job3,1)
     *---------------------------------------------------------------------------*/
    void job3 (void) __task
    {
      while (1)                                               /* endless loop                        */
      {
         SPI();                                               /*send some data to LED to blink it in some sequence*/
            counter3++;                       /* increment counter 3                 */
        if (counter3 == 0)                            /* signal overflow of counter 3        */
            {
          os_evt_set (0x00ff,tsk4);       /* to task 4                           */
         os_tsk_pass ();
        }
      }
    }
    
    /*----------------------------------------------------------------------------
     *   Task 4 'job4':  RTX Kernel starts this task with os_tsk_create (job4,1)
     *---------------------------------------------------------------------------*/
    void job4 (void) __task
    {
      while (1)                                               /* endless loop                        */
      {
         SCI();                                                       /*display ADC data on the hyperterminal*/
            os_evt_wait_or (0x0001, 0xffff);  /* wait for signal event               */
        counter4++;                       /* process overflow from counter 3     */
      }
    }
    
    /*----------------------------------------------------------------------------
     *        Main: Initialize and start RTX Kernel
     *---------------------------------------------------------------------------*/
    int main (void)
    {                     /* program execution starts here       */
    
    
      os_sys_init (job1);                 /* initialize and start task 1         */
    }
    
    /*----------------------------------------------------------------------------
     * end of file
     *---------------------------------------------------------------------------*/
    

    but here its not switching properly for other tasks
    please tell me where may be the problem?