https://www.youtube.com/watch?v=Ht7QRfUvWsI&list=PLEfMFrwVdbPYzMgeaLiFRb4ogjV8m3lt6&index=12&t=0s
/* USER CODE BEGIN 0 */
TaskHandle_t myTask1Handle = NULL;
TaskHandle_t myTask2Handle = NULL;
void myTask1(void *pvParameters)
{
TickType_t xDelay = pdMS_TO_TICKS(1000);
TickType_t myLastUnblock;
myLastUnblock = xTaskGetTickCount();
for(;;)
{
xTaskNotifyGive(myTask2Handle);
vTaskDelay(1000);
}
}
void myTask2(void *pvParameters)
{
TickType_t xDelay = pdMS_TO_TICKS(1000);
TickType_t myLastUnblock;
myLastUnblock = xTaskGetTickCount();
char temp[10];
int notificationValue;
for(;;)
{
//HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);
notificationValue = ulTaskNotifyTake(pdTRUE, (TickType_t) portMAX_DELAY);
//pdTrue 는 1로 정의되어 있다. 첫번째 파라미터는 0 or 1 binary 로 받는다. 0으로 설정하면 받은 value를 감소 시킨다는 의미. 1은 value를 reset 시킨다는 의미
//하지만 notificationValue는 감소되거나 reset 되기 전의 값을 return 받는다. 즉 1을 return 받는다.
if(notificationValue > 0){
sprintf(temp, "%d", notificationValue);
char* text = "notification received : ";
HAL_UART_Transmit(&huart2, (uint8_t *)text,strlen(text) , 10);
HAL_UART_Transmit(&huart2, (uint8_t *)temp, strlen(temp) , 10);
HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);
}
}
}
결과 :
notification received: 1
notification received: 1
notification received: 1
notification received: 1
notification received: 1
void myTask1(void *pvParameters)
{
TickType_t xDelay = pdMS_TO_TICKS(1000);
TickType_t myLastUnblock;
myLastUnblock = xTaskGetTickCount();
for(;;)
{
xTaskNotifyGive(myTask2Handle);
xTaskNotifyGive(myTask2Handle);
xTaskNotifyGive(myTask2Handle);
xTaskNotifyGive(myTask2Handle);
vTaskDelay(5000);
}
}
void myTask2(void *pvParameters)
{
TickType_t xDelay = pdMS_TO_TICKS(1000);
TickType_t myLastUnblock;
myLastUnblock = xTaskGetTickCount();
char temp[10];
for(;;)
{
//HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);
notificationValue = ulTaskNotifyTake(pdTRUE, (TickType_t) portMAX_DELAY);
//4번 보냈으므로 값은 4가 되고 다시 0으로 reset 되어진다. 그러므로 5초간 다시 기다리게된다.
if(notificationValue > 0){
sprintf(temp, "%d", notificationValue);
char* text = "notification received : ";
HAL_UART_Transmit(&huart2, (uint8_t *)text,strlen(text) , 10);
HAL_UART_Transmit(&huart2, (uint8_t *)temp, strlen(temp) , 10);
HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);
}
}
}
결과 :
notification received: 4
notification received: 4
notification received: 4
notification received: 4
notification received: 4
void myTask1(void *pvParameters)
{
TickType_t xDelay = pdMS_TO_TICKS(1000);
TickType_t myLastUnblock;
myLastUnblock = xTaskGetTickCount();
for(;;)
{
xTaskNotifyGive(myTask2Handle);
xTaskNotifyGive(myTask2Handle);
xTaskNotifyGive(myTask2Handle);
xTaskNotifyGive(myTask2Handle);
vTaskDelay(5000);
}
}
void myTask2(void *pvParameters)
{
TickType_t xDelay = pdMS_TO_TICKS(1000);
TickType_t myLastUnblock;
myLastUnblock = xTaskGetTickCount();
char temp[10];
for(;;)
{
//HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);
notificationValue = ulTaskNotifyTake(pdFALSE, (TickType_t) portMAX_DELAY);
//4가 1씩 감소하므로 4 3 2 1 순으로 출력
if(notificationValue > 0){
sprintf(temp, "%d", notificationValue);
char* text = "notification received : ";
HAL_UART_Transmit(&huart2, (uint8_t *)text,strlen(text) , 10);
HAL_UART_Transmit(&huart2, (uint8_t *)temp, strlen(temp) , 10);
HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);
}
}
}
결과 :
notification received: 4
notification received: 3
notification received: 2
notification received: 1
notification received: 4
'FreeRTOS > FreeRTOS 기본 학습' 카테고리의 다른 글
14 FreeRTOS Tutorial: Mutex (0) | 2019.07.08 |
---|---|
12 FreeRTOS Tutorial: Direct To Task Notifications part2 (0) | 2019.06.27 |
10 FreeRTOS Tutorial: Queues part2 (0) | 2019.06.26 |
09 FreeRTOS Tutorial: Queues part1 (0) | 2019.06.21 |
08 FreeRTOS Tutorial: Task Utilities part2 (0) | 2019.06.21 |