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

Parents Reply Children
  • What part of this statement don't you understand:

    Read the user manual. Read the user manual. Read the user manual. Read the user manual. Read the user manual. Read the user manual.

    !

  • Do you have any reasons to believe that you need to change any scheduler options?

    Note that if you do run threads with different priority, then you can't look at the scheduler and magically get it to handle your scheduling problems. Whenever you have multiple priorities, you (Y.O.U.) must write specific code for your specific threads that makes sure that the high-prio threads only runs when they have specific (high-priority) work to do and that whenever that high-priority work is done, you leave the CPU capacities for less prioritized threads.

    Whenever you have multiple priorities, then the scheduler can only switch between ready (runnable) tasks of the highest priority. So your goal is to make sure that the highest prioritized threads are not in the state running or runnable for 100% of the time or your (Y.O.U.R) code will starve the less prioritized threads.

    It doesn't matter if how long time slices you have or if you play with round-robin scheduling or not. Whenever you have multiple priorities involved, YOU must add schedulling code (sleeps or waits (events, mails, ...) into your threads to get them to cooperate. The RTOS does have the primitives you need for that work. It's like LEGO bricks, that you can combine. We can't do it for you - we don't even know what the goals are with your program.

    The Keil samples do show examples of the use of the different OS functions. You can see how threads can sleep. You can see how threads turn over CPU time to threads of same priority. You can see how threads sets events or sends mails. You can see how threads sleeps until they get an event or mail. You can see how threads changes priorities (but don't be too quick to play with dynamic thread priorities).

    The total number of functions available is quite low. So the total time needed to read through the manual pages and the related sample code is not so high. Have you spent such time yet? Do you have any specific questions after having read the documentation - specific sentences or paragraphs you don't understand?

  • Per,

    It is really very nice that you are doing your best to help this guy. But really, the OP does not read our comments (at all!), clearly did not read the manuals (to which we have posted multiple links!) and is generally disoriented - maybe it is a language barrier. Just let him be: he simply refuses to make a minimal effort.

  • Thank you for your active co-operation

    i wrote here code for 2 task
    when the tsk1 is compleed its going for the tsk2..... and its not comming back to the tsk1

    according to the above discution i gave some delay after tsk2 completion

    __task void task1 (void){
      /* Obtain own system task identification number */
      id1 = os_tsk_self();
      os_tsk_prio_self(1);
    
      /* Create task2 and obtain its task identification number */
      id2 = os_tsk_create (task2, 2);
    
      for (;;)
      {
        buzzer();
        os_evt_set(0x0002,id2); //after completion of the buzzer operation going to the tsk2
        /* Signal to task2 that task1 has compelted */
    
    
        /* Wait for completion of task2 activity. */
        /*  0xFFFF makes it wait without timeout. */
        /*  0x0004 represents bit 2. */
        os_evt_wait_or(0x0001, 0xFFFF);
      }
    }
    
    __task void task2 (void) {
      for (;;) {
        /* Wait for completion of task1 activity. */
        /*  0xFFFF makes it wait without timeout. */
        /*  0x0004 represents bit 2. */
        os_evt_wait_or(0x0002, 0xFFFF);
    
    
        ADC();
    
        /* Signal to task1 if task2 has compelted */
        os_evt_set(0x0001, id1);
            os_dly_wait(10);
      }
    }
    
    int main (void) {
      /* Start the RTX kernel, and then create and execute task1. */
      os_sys_init(task1);
    }
    
    

  • Are you intentionally posting broken code, or are you not better than this?

        /*  0x0004 represents bit 2. */
        os_evt_wait_or(0x0001, 0xFFFF);
    


    What does 0x0004 have with 0x0001 to do?

      for (;;)
      {
        buzzer();
        os_evt_set(0x0002,id2); //after completion of the buzzer operation going to the tsk2
        /* Signal to task2 that task1 has compelted */
    
    
        /* Wait for completion of task2 activity. */
        /*  0xFFFF makes it wait without timeout. */
        /*  0x0004 represents bit 2. */
        os_evt_wait_or(0x0001, 0xFFFF);
      }
    }
    


    So every time your unit boots, it should run buzzer first, and then wait for next buzzer event? Is that logical? Does the door bell at your home always sound once whenever the power company turns on the power?

    And you seem to have tried to make task1 and task2 run every other time unconditionally. Isn't that very illogical? So you do one ADC read per activation of the buzzer? Exactly why should buzzer and ADC always run buzzer -> ADC -> buzzer -> ADC? Why not just have a single loop then with one call to buzzer and one call to ADC?

    You do realize that the goal with multiple tasks are to prioritize things - letting high-priority tasks take over to perform the critical work before dropping out and returning the processor to lower-prioritized work? And to have multiple tasks because you want multiple things to happen semi-concurrently and normally at individual speeds.

    A higher priority task can take the ownership of the CPU. So you don't need any task to wait for another task to finish.

    The only really practical reason to implement two tasks that runs in lockstep is when you have a typical producer/consumer situation. The consumer sits and waits until the producer have produced something. The producer signals "data available" and the consumer wakes up, picks up the produced work and performs further processing of it. As soon as the consumer don't have any more data to work on, it goes down to sleep again, waiting for the producer to produce more. But your code is not an example of any producer/consumer. Just an attempt at converting a standard loop:

    for (;;) {
        do_a();
        do_b();
    }
    


    into something very much more complicated. You don't have any concurrency between do_a() and do_b() so, as written, the threads are not adding any functionality to your system.

    What is concurrency then? Concurrency is when you do process ADC values and present on the LCD even when the buzzer is busy buzzing. Concurrency is when you scan a keyboard and process keyboard commands if the buzzer is buzzing or not. Concurrency is about making one task continue doing what it needs to do, while being as little affected as possible by other actions in the system - with the special case that tasks with critical priorities have the ability to jump in and take the processing capacity from tasks with high prio. And tasks with high prio can take the processor from tasks with medium or low prio. So tasks with low prio will only run when all tasks with medium, high or critical priority are sleeping, waiting for more input data or new events.