#include #include #include "FreeRTOS.h" #include "task.h" #include "event_groups.h" #define TASK1_20MS1_BIT (1UL<<0UL) #define TASK1_50MS1_BIT (1UL<<1UL) #define TASK1_100MS1_BIT (1UL<<2UL) EventGroupHandle_t xEventGroup; void vTaskInit(void); void vTimerInit(void); void vEv_20ms1_Task(void *pvParameters); void vEv_50ms1_Task(void *pvParameters); void vEv_100ms1_Task(void *pvParameters); void prvTimerAl_OsTask_10ms_BSW_AlarmCallback( TimerHandle_t xExpiredTimer ); unsigned char ms_20_rem_10tc=0; unsigned char ms_50_rem_10tc=0; unsigned char ms_100_rem_10tc=0; unsigned char ms10_BSW_tc=0; static TimerHandle_t xTimerMain_10ms1 = NULL; uint32_t Counter20ms1_Timer; uint32_t Counter50ms1_Timer; uint32_t Counter100ms1_Timer; uint32_t Counter20ms1_Task; uint32_t Counter50ms1_Task; uint32_t Counter100ms1_Task; /****************************** Functions ******************************/ void vTaskInit(void) { /*if only Priority changed executes normally*/ xTaskCreate(vEv_20ms1_Task,"TASK1", 1024, NULL, 27, NULL); xTaskCreate(vEv_50ms1_Task,"TASK2", 1024, NULL, 26, NULL); xTaskCreate(vEv_100ms1_Task, "TASK3", 1024, NULL, 25, NULL); } void vTimerInit(void) { xTimerMain_10ms1 = xTimerCreate( "Al_OsTask_10ms", /* Test name for the timer. */ pdMS_TO_TICKS( 10 ), /* Period of the timer. */ pdTRUE, /* The timer will auto-reload itself. */ ( void * ) 0, /* The timer's ID is used to count the number of times it expires - initialise this to 0. */ prvTimerAl_OsTask_10ms_BSW_AlarmCallback ); /* The function called when the timer expires. */ configASSERT( xTimerMain_10ms1 ); xTimerStart( xTimerMain_10ms1, pdMS_TO_TICKS( 0 ) ); } void prvTimerAl_OsTask_10ms_BSW_AlarmCallback( TimerHandle_t xExpiredTimer ) { ms10_BSW_tc++; if(ms10_BSW_tc > 10) { ms10_BSW_tc = 1; } ms_20_rem_10tc = ms10_BSW_tc % 2; ms_50_rem_10tc = ms10_BSW_tc % 5; ms_100_rem_10tc = ms10_BSW_tc % 10; if(ms_20_rem_10tc == 1) { Counter20ms1_Timer++; xEventGroupSetBits(xEventGroup, TASK1_20MS1_BIT); //gioSetBit(gioPORTB, 2, gioGetBit(gioPORTB, 2) ^ 1); } if(ms_50_rem_10tc == 2) { Counter50ms1_Timer++; xEventGroupSetBits(xEventGroup, TASK1_50MS1_BIT); //gioSetBit(gioPORTB, 2, gioGetBit(gioPORTB, 2) ^ 1); } if(ms_100_rem_10tc == 3) { Counter100ms1_Timer++; xEventGroupSetBits(xEventGroup, TASK1_100MS1_BIT); //gioSetBit(gioPORTB, 2, gioGetBit(gioPORTB, 2) ^ 1); } } void vEv_20ms1_Task(void *pvParameters) { EventBits_t xEventGroupValue; const EventBits_t xBitsToWaitFor = TASK1_20MS1_BIT; while(1) { xEventGroupValue = xEventGroupWaitBits( /*Event group to read*/ xEventGroup, xBitsToWaitFor, pdTRUE, pdFALSE, // Event flag will be cleared pdMS_TO_TICKS(20)); // shoud be less than task period, otherwise this will overcome task period if((xEventGroupValue & TASK1_20MS1_BIT)!=0) { Counter20ms1_Task++; } } } void vEv_50ms1_Task(void *pvParameters) { EventBits_t xEventGroupValue; const EventBits_t xBitsToWaitFor = TASK1_50MS1_BIT; while(1) { xEventGroupValue = xEventGroupWaitBits( /*Event group to read*/ xEventGroup, xBitsToWaitFor, pdTRUE, pdFALSE, // Event flag will be cleared pdMS_TO_TICKS(50)); // shoud be less than task period, otherwise this will overcome task period if((xEventGroupValue & TASK1_50MS1_BIT)!=0) { Counter50ms1_Task++; } } } void vEv_100ms1_Task(void *pvParameters) { EventBits_t xEventGroupValue; const EventBits_t xBitsToWaitFor = TASK1_100MS1_BIT; // const TickType_t xDelay100ms = pdMS_TO_TICKS( 100UL ); while(1) { xEventGroupValue = xEventGroupWaitBits( /*Event group to read*/ xEventGroup, xBitsToWaitFor, pdTRUE, pdFALSE, // Event flag will be cleared pdMS_TO_TICKS(100)); // shoud be less than task period, otherwise this will overcome task period if((xEventGroupValue & TASK1_100MS1_BIT)!=0) { Counter100ms1_Task++; } } } void app_main( void ) { vTaskInit(); /* Create and start the software timer. */ vTimerInit(); /* Create the Group Events */ xEventGroup = xEventGroupCreate(); /* Start Scheduler */ vTaskStartScheduler(); }