Documente Academic
Documente Profesional
Documente Cultură
Lucrarea 2
Task-uri și queues în FreeRTOS
vLEDInit(0);
portTickType xLastWakeTime;
const portTickType xFrequency = timpul;
xLastWakeTime=xTaskGetTickCount();
for( ;; )
{
vLEDToggle(0);
vTaskDelayUntil(&xLastWakeTime,xFrequency);
} }
int main(void)
{
1
xTaskCreate( vLEDFlashTask, "LED1", configMINIMAL_STACK_SIZE, (void
*)timp2, mainLED_TASK_PRIORITY, NULL);
//start scheduler
vTaskStartScheduler();
//you should never get here
while (1)
{ }
return 0;
}
vLEDInit(0);
portTickType xLastWakeTime;
const portTickType xFrequency = prm_in->timp; //acces le componentele
//structurii prin pointer
xLastWakeTime=xTaskGetTickCount();
for( ;; )
{
vLEDToggle(0);
vTaskDelayUntil(&xLastWakeTime,xFrequency);
if (a==0) {vTaskDelete(prm_in->task);a=1;} //sterg doar o data
} }
int main(void)
{
2
xTaskCreate( vLEDFlashTask, "LED2", configMINIMAL_STACK_SIZE, (void
*)timp2, mainLED_TASK_PRIORITY, &xTask1Handle);
prm.task=xTask1Handle;
prm.timp=8000U;
xTaskCreate( vLEDFlashTask1, "LED1", configMINIMAL_STACK_SIZE, (void
*)&prm, mainLED_TASK_PRIORITY, NULL );
//start scheduler
vTaskStartScheduler();
//you should never get here
while (1)
{
}
return 0;
}
Exercițiu: să se modifice programul astfel încât task-ul vLEDFlashTask să fie
șters înainte de a se executa, dacă intervalul de timp de așteptare pentru
vLEDFlashTask1 este mai mic de 3s.
vLEDInit(6);
portTickType xLastWakeTime;
const portTickType xFrequency = timpul;
xLastWakeTime=xTaskGetTickCount();
for( ;; )
{
xQueueReceive(xQueue, &in, portMAX_DELAY );
if (in) vLEDToggle(6);
} }
vBtnInit (3);
portTickType xLastWakeTime;
3
const portTickType xFrequency = timpul;
xLastWakeTime=xTaskGetTickCount();
for( ;; )
{
val=uBtnPressed(3,&ant);
xQueueSendToBack( xQueue, &val, 0 );
vTaskDelayUntil(&xLastWakeTime,xFrequency);
}
}
Se declară în fișierul myTasks.cpp variabila globală:
QueueHandle_t xQueue;