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
  • 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);
    }
    
    

Reply
  • 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);
    }
    
    

Children
  • 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.