Real time tasks with CooOs

rtosstm32stm32f4

i am using CooOs with 4 tasks.the problem is that only the first task run (indefinetly).What i want to do is to toggle each task 3 seconds then switch to the other.I know that i can do that with timers or systick but i need to handle CooOs.

#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
#include "CoOS.h"

#define STACK_SIZE_TASK 100

/*---------------------------- Variable Define -------------------------------*/
OS_STK taskg_stk[STACK_SIZE_TASK];
OS_STK tasko_stk[STACK_SIZE_TASK];
OS_STK taskr_stk[STACK_SIZE_TASK];
OS_STK taskb_stk[STACK_SIZE_TASK];
void init_sys() {
SystemInit();
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14
        | GPIO_Pin_15;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOD, &GPIO_InitStruct);

 }

void task_g() {
while (1) {
    GPIO_ResetBits(GPIOD, GPIO_Pin_All);
    GPIO_SetBits(GPIOD, GPIO_Pin_12);
}
}
void task_o() {
while (1) {
    GPIO_ResetBits(GPIOD, GPIO_Pin_All);
    GPIO_SetBits(GPIOD, GPIO_Pin_13);
}

}

void task_r() {
while (1) {
    GPIO_ResetBits(GPIOD, GPIO_Pin_All);
    GPIO_SetBits(GPIOD, GPIO_Pin_14);
}
 }
void task_b() {
while (1) {
    GPIO_ResetBits(GPIOD, GPIO_Pin_All);
    GPIO_SetBits(GPIOD, GPIO_Pin_15);
}
}

OS_TID g, o, r, b;

void main(void) {
    init_sys();
    CoInitOS();
//CoCreateTaskEx(task,argv,prio,stk,stkSz,timeSlice,isWaitting)
 g = CoCreateTaskEx(task_g,0,2,(int)taskg_stk,STACK_SIZE_TASK,1,0);
 o = CoCreateTaskEx(task_o,0,1,(int)tasko_stk,STACK_SIZE_TASK,3,1);
 r = CoCreateTaskEx(task_r,0,2,(int)taskr_stk,STACK_SIZE_TASK,3,1);
 b = CoCreateTaskEx(task_b,0,3,(int)taskb_stk,STACK_SIZE_TASK,3,1);
 CoStartOS();
}

Best Answer

This is just one approach that will work.

Start by creating a fifth "manager" task, that runs at a higher priority than the four tasks that will do the work.

From the manager, create the four managed tasks, all at the same priority that must be lower than the manager task's priority, and all initially in the "TASK_WAITING" state.

The manager then goes into a loop:

  1. Awaken worker task 'x'. CoAwakeTask(workerid[x]);
  2. Delay for 3 seconds. CoTickDelay(3000);
  3. Suspend worker task 'x'. CoSuspendTask(workerid[x]);
  4. Increment and if necessary wrap 'x' if (++x >= NUM_WORKER_TASKS) x = 0;
  5. Loop