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

How to start different task in one Programm

Hello new's group.
My MCU is a ADuC7026. It has only two interrupt priorities, FIQ is high priority, IRQ is normal priority.
I want to write a programm to generate some signals which are related to some sensor mesurements. Some of my cumputations are very resource killing. So this computations can only be performed not so often.
So there are different task.
The task with the highest priority has to be performed 200000 times per second. Another task with a middle priority has to be performed 25000 times per second. The next task with a mid-low priority has to be performed 2000 times per second. And one more task is to be performed 100 times per second. And the last task has to be performed 2 times per second with the lowest priority.

I hope i have explained this so someone can understand it. Of course maybe this is not the right Forum, but i use a keil compiler. My question is how can i programm all this different task without a operating system?
Sorry, i'm not very experienced... :-)

Parents
  • I have run multiple periodic threads like this without an RTOS in the past. My approach is hopefully described adequately by the following pseudocode. It is the timer ISR of a timer set to fire at the frequency of the most frequently required thread (200kHz in your example).

    void Timer_ISR(void) {
       static int t = -1;
       ReEnableTimerInterrupt();
       t += 1;
       HighFrequencyFunction();
       if (0 == (t & 0x000f)) {
          MediumFrequencyFunction();
          if (0 == (t & 0x00ff)) {
             LowFrequencyFunction();
          }
       }
    }
    

    The three functions are called at the timer rate, one sixteenth of the timer rate, and one 256th of the timer rate respectively. The structure is hopefully obvious, and it is clear how the frequencies can be altered, and the idea extended.

    The key elements are that each of the functions is called periodically, and the priorities are linked to the call frequencies, in that the HighhFrequencyFunction() can interrupt MediumFrequencyFunction(), and MediumFrequencyFunction() can interrupt LowFrequencyFunction(). Any number of different frequencies (all must be divisions of the maximum, and it is convenient and efficient if they are power of two divisions) can be called with just one timer.

    The details of getting this to work may require quite a deep understanding of how the processor handles interrupts, storing the context on the stack and such like. You also have to be certain that the worst-case execution time of each function does not exceed the period allocated to it, else you will get recursive calls and the stack will rapidly overflow.

    However, having implemented this type of architecture on several processors over the last decade (8051, AVR etc) I am now a convert to the use of an RTOS in all but the most trivial of applications. As soon as you need to communicate between the threads, you will need locking primitives and such like, and then it becomes increasingly difficult to guarantee worst-case execution times, on which the above scheme absolutely depends.

    I also share the concerns of the other respondents as to the wisdom of using a 200kHz timer interrupt for pretty much any purpose.

    Christopher Hicks

Reply
  • I have run multiple periodic threads like this without an RTOS in the past. My approach is hopefully described adequately by the following pseudocode. It is the timer ISR of a timer set to fire at the frequency of the most frequently required thread (200kHz in your example).

    void Timer_ISR(void) {
       static int t = -1;
       ReEnableTimerInterrupt();
       t += 1;
       HighFrequencyFunction();
       if (0 == (t & 0x000f)) {
          MediumFrequencyFunction();
          if (0 == (t & 0x00ff)) {
             LowFrequencyFunction();
          }
       }
    }
    

    The three functions are called at the timer rate, one sixteenth of the timer rate, and one 256th of the timer rate respectively. The structure is hopefully obvious, and it is clear how the frequencies can be altered, and the idea extended.

    The key elements are that each of the functions is called periodically, and the priorities are linked to the call frequencies, in that the HighhFrequencyFunction() can interrupt MediumFrequencyFunction(), and MediumFrequencyFunction() can interrupt LowFrequencyFunction(). Any number of different frequencies (all must be divisions of the maximum, and it is convenient and efficient if they are power of two divisions) can be called with just one timer.

    The details of getting this to work may require quite a deep understanding of how the processor handles interrupts, storing the context on the stack and such like. You also have to be certain that the worst-case execution time of each function does not exceed the period allocated to it, else you will get recursive calls and the stack will rapidly overflow.

    However, having implemented this type of architecture on several processors over the last decade (8051, AVR etc) I am now a convert to the use of an RTOS in all but the most trivial of applications. As soon as you need to communicate between the threads, you will need locking primitives and such like, and then it becomes increasingly difficult to guarantee worst-case execution times, on which the above scheme absolutely depends.

    I also share the concerns of the other respondents as to the wisdom of using a 200kHz timer interrupt for pretty much any purpose.

    Christopher Hicks

Children
No data