Example #1
0
static void task00_class00(uint16_t initCondition)

{
    for(;;)
    {
        ++ _noLoopsTask00_C0;

        /* This tasks cycles with about 200ms but it is nearly always suspended and doesn't
           produce significant CPU load. */
        rtos_delay(80);
        rtos_suspendTaskTillTime(/* deltaTimeTillRelease */ 100);
    }
} /* End of task00_class00 */
Example #2
0
static void task01_class00(uint16_t initCondition)

{
#define TICS_CYCLE  125

    uint16_t u;
    uint32_t ti = millis()
           , tiCycle;
    
    Serial.print("task01_class00: Activated by 0x");
    Serial.println(initCondition, HEX);

    for(u=0; u<3; ++u)
        blink(2);
    
    for(;;)
    {
        Serial.println("task01_class00: rtos_delay...");
        u = rtos_delay(55);
        Serial.print("task01_class00: Released with ");
        Serial.println(u, HEX);
        
        Serial.println("task01_class00: Suspending...");
        u = rtos_suspendTaskTillTime(/* deltaTimeTillRelease */ TICS_CYCLE);
        tiCycle = millis();
        Serial.print("task01_class00: Released with ");
        Serial.println(u, HEX);
        
        /* The system timer tic has a frequency of 490.1961 Hz.
             Caution: The compiler fails to recognize the constant floating point
           expression if there's no explicit, superfluous pair of parenthesis around it.
           With parenthesis it compiles just one product, without it uses several products
           and divisions. */
        Serial.print("Cycle time: ");
        Serial.print((tiCycle-ti) * (100.0/1000.0 / (TICS_CYCLE/490.1961)));
        Serial.println("%");
        
        Serial.print("CPU load: ");
        Serial.print(_cpuLoad/2);
        Serial.println("%");
        
        ti = tiCycle;
    }
    
#undef TICS_CYCLE
} /* End of task01_class00 */
Example #3
0
static void taskC0(uint8_t idxTask)
{
    uint32_t cnt = 0;
    
    while(true)  
    {
        /* Wait until we get the resource. */
        getResource();
    
        /* Being here, we can be sure to have the resource. Use it. */
        Serial.print("This is task "); Serial.print(idxTask);
        
        /* The ownership of the resource needs to be independent of the status of the
           tasks. To prove this we suspend the task deliberately in the middle of some
           output operation and we use the blocking Arduino function delay that long, that
           we have a high probability of running into a round robin task switch before
           delay returned. */
        Serial.print(": "); Serial.print(++cnt);
        Serial.print(" loops. Thi");
        rtos_delay(TIME_IN_MS(12));
        Serial.print("s line of console output is interrupted by seve");
        delay(31/*ms*/);
        Serial.print("ral task de-activations. ");
        Serial.print("Now the resource Serial is released by task ");
        Serial.println(idxTask);
        
        /* In the original test case tc09, demonstrating the implementation of a
           pseudo-mutex, we had written: "Give other tasks a chance to get the resource.
           After the call of release, we must not immediately cycle around, otherwise the
           chance is high, that we get it immediately again since most of the concurrent
           tasks have the same priority. Suspend deliberately (but as short as possible),
           so that other tasks of the same priority class can become active."
             Using a true mutex, this becomes obsolete. The call of releaseResource returns
           the mutex, which is in the same atomic instance passed on to one of the
           concurrent, waiting, suspended other tasks. If that is a task of same priority it
           still holds true, that it won't interrupt the running task, but two statements
           later, in its next loop, this running task will try to aqcuire the resource
           again but the mutex is not available and it'll then be suspended. */
        releaseResource();
        //rtos_delay(0);
    }
} /* End of taskC0 */
Example #4
0
static void taskT0_C1(uint16_t initCondition)
{
#define TASK_TIME_T0_C1_MS  21

    uint32_t cnt = 0;
    
    /* The task inspects the results of the interrupt on a regular base. */
    do
    {
        /* Wait until we get the resource. */
        getResource();
    
        /* Being here, we can be sure to have the resource. Use it. */
        
        /* The ownership of the resource needs to be independent of the status of the
           tasks. To prove this we suspend the task deliberately in the middle of some
           output operation and we use the blocking Arduino function delay that long, that
           we have a high probability of running into a round robin task switch before
           delay returned. */
        Serial.print("This is task T0_C1");
        Serial.print(": "); Serial.print(++cnt);
        Serial.print(" loops. This line of conso");
        rtos_delay(TIME_IN_MS(7));
        Serial.print("le output is interr");
        delay(3/*ms*/);
        Serial.print("upted by several task de-activations");
        Serial.println(". Now the resource is released again");

        /* Give other tasks a chance to get the resource. */
        releaseResource();
        
        /* Here, no other task will already use the acquired resource: All concurrent tasks
           are of lower priority. One of them will have become due but not active yet. The
           while condition will now make this task inactive and the already due other one
           active. */
    }
    while(rtos_suspendTaskTillTime(TIME_IN_MS(TASK_TIME_T0_C1_MS)));

#undef TASK_TIME_T0_C1_MS
} /* End of taskT0_C1 */