Hi All,
I am trying to run two tasks of similar priorities, but with different scheduled periods.
I call them as such before starting the scheduler:
cmdSuccess = xTaskCreate(cmd_processing, "cp", 256, NULL, configMAX_PRIORITIES-1, &Handle_cmdProcTask);
blinkSuccess = xTaskCreate(blink, "blink", 256, NULL, configMAX_PRIORITIES-1, &Handle_BlinkProcTask);
The first task reads in serial data input from the USB every 10 ms. The second makes an led toggle every 1 second.
They each have the following time execution periods,
blink_period = 1000 ms or 1 second
cmd_proc_period = 10 ms
It’s obvious that at 1000 ms both blink_period and cmd_proc_period are scheduled.
When I run the scheduler I see the LED flicker faintly at times at other times the LED is stuck on off or stuck on on. What can be the cause of this. Am I scheduling tasks wrong? I know that I can use vTaskDelay, but I want to schedule based xTaskGetTickCount(). In that way I know that tasks are running on a timeline and are scheduled simultaneously.
Each one then runs based on the following two task functions:
void blink(void* pvParameters){
uint8_t state = 0;
while(1){
xSemaphoreTake(globSem, portMAX_DELAY);
unsigned long time = xTaskGetTickCount()/portTICK_RATE_MS;
xSemaphoreGive(globSem);
if((time % blink_period) == 0){
state ^= 1;
digitalWrite(led, state);
}
taskYIELD();
}
}
void cmd_processing(void* pvParameters){
while(1){
xSemaphoreTake(globSem, portMAX_DELAY);
unsigned long time = xTaskGetTickCount()/portTICK_RATE_MS;
xSemaphoreGive(globSem);
if((time % cmd_proc_period) == 0){
static uint32_t cnt = 0;
static char param[50];
static char cmd[50];
static char c;
static boolean cmdSet = false;
if (SERIAL.available () > 0) {
c = SERIAL.read ();
if (c == '\n') {
arg[cnt] = '\0';
cnt = 0;
cmdSet = false;
detrmine_input((char*)cmd, (void*)arg);
}
else if (c == ' ') {
cmd[cnt] = '\0';
cnt = 0;
cmdSet = true;
}
else {
if (!cmdSet) {
cmd[cnt++] = c;
cmd[cnt] = '\0';
}
else {
arg[cnt++] = c;
arg[cnt] = '\0';
}
}
}
}
taskYIELD();
}
}