본문 바로가기

FreeRTOS/FreeRTOS 기본 학습

12 FreeRTOS Tutorial: Direct To Task Notifications part2

https://www.youtube.com/watch?v=cv9VIotr4Ms&list=PLEfMFrwVdbPYzMgeaLiFRb4ogjV8m3lt6&index=13&t=0s

TaskHandle_t myTask1Handle = NULL;
TaskHandle_t myTask2Handle = NULL;
int notificationValue;

void myTask1(void *pvParameters)
{

	TickType_t xDelay = pdMS_TO_TICKS(1000);
	TickType_t myLastUnblock;
	myLastUnblock = xTaskGetTickCount();


		for(;;)
		{
			xTaskNotify(myTask2Handle , 0 , eNoAction); //notification을 보낼 것이다. 그러나 value에 관해서는 아무것도 하지 않을 것(eNoAction)
            //eIncrement로 설정하면 1씩 증가해서 들어옴
			vTaskDelay(1000);

		}
}

void myTask2(void *pvParameters)
{

	TickType_t xDelay = pdMS_TO_TICKS(1000);
	TickType_t myLastUnblock;
	myLastUnblock = xTaskGetTickCount();

	uint32_t ulNotifiedValue;
	char temp[10];
	char* text;
		for(;;)
		{


			if( xTaskNotifyWait(0, 0, &ulNotifiedValue, portMAX_DELAY) == pdTRUE)
			{

				text = "notification received : ";
				HAL_UART_Transmit(&huart2, (uint8_t *)text,strlen(text) , 10);
				sprintf(temp,"%d", ulNotifiedValue);
				HAL_UART_Transmit(&huart2, (uint8_t *)temp,strlen(temp) , 10);
				HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);

			}
			//HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);




		}
}

notification received : 0
                                                     
notification received : 0
                                                     
notification received : 0
                                                     
notification received : 0
                                                     
notification received : 0
                                                     
notification received : 0
       

TaskHandle_t myTask1Handle = NULL;
TaskHandle_t myTask2Handle = NULL;
int notificationValue;

void myTask1(void *pvParameters)
{

	TickType_t xDelay = pdMS_TO_TICKS(1000);
	TickType_t myLastUnblock;
	myLastUnblock = xTaskGetTickCount();


		for(;;)
		{
			xTaskNotify(myTask2Handle , (1<<2) | (1<<0) , eSetBits); 
            //notification을 보낼 것이다. 5로 eSetBits 지정해서 보냄
            
			vTaskDelay(1000);

		}
}

void myTask2(void *pvParameters)
{

	TickType_t xDelay = pdMS_TO_TICKS(1000);
	TickType_t myLastUnblock;
	myLastUnblock = xTaskGetTickCount();

	uint32_t ulNotifiedValue;
	char temp[10];
	char* text;
		for(;;)
		{


			if( xTaskNotifyWait(0, 0, &ulNotifiedValue, portMAX_DELAY) == pdTRUE)
			{

				text = "notification received : ";
				HAL_UART_Transmit(&huart2, (uint8_t *)text,strlen(text) , 10);
				sprintf(temp,"%d", ulNotifiedValue);
				HAL_UART_Transmit(&huart2, (uint8_t *)temp,strlen(temp) , 10);
				HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);

			}
			//HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);




		}
}

notification received : 5
                                                      
notification received : 5 
                                                      
notification received : 5 
                                                      
notification received : 5 
                                                      

void myTask1(void *pvParameters)
{

	TickType_t xDelay = pdMS_TO_TICKS(1000);
	TickType_t myLastUnblock;
	myLastUnblock = xTaskGetTickCount();


		for(;;)
		{
			xTaskNotify(myTask2Handle , (1<<0), eSetBits); //notification을 보낼 것이다. 그러나 value에 관해서는 아무것도 하지 않을 것(eNoAction)
			vTaskDelay(1000);

			xTaskNotify(myTask2Handle , (1<<1), eSetBits); //notification을 보낼 것이다. 그러나 value에 관해서는 아무것도 하지 않을 것(eNoAction)
			vTaskDelay(1000);

			xTaskNotify(myTask2Handle , (1<<2), eSetBits); //notification을 보낼 것이다. 그러나 value에 관해서는 아무것도 하지 않을 것(eNoAction)
			vTaskDelay(1000);

		}
}

notification received : 1
                                                     
notification received : 3
                                                     
notification received : 7
                                                     
notification received : 7
                                                     
notification received : 7
                                                     
notification received : 7
                                                     
notification received : 7
          

void myTask1(void *pvParameters)
{

	TickType_t xDelay = pdMS_TO_TICKS(1000);
	TickType_t myLastUnblock;
	myLastUnblock = xTaskGetTickCount();


		for(;;)
		{
			xTaskNotify(myTask2Handle , (1<<0), eSetValueWithOverwrite); //1
			vTaskDelay(1000);

			xTaskNotify(myTask2Handle , (1<<1), eSetValueWithOverwrite); //2
			vTaskDelay(1000);

			xTaskNotify(myTask2Handle , (1<<2), eSetValueWithOverwrite); //4
			vTaskDelay(1000);

		}
}

notification received : 1
                                                      
notification received : 2
                                                      
notification received : 4 

 

void myTask1(void *pvParameters)
{

	TickType_t xDelay = pdMS_TO_TICKS(1000);
	TickType_t myLastUnblock;
	myLastUnblock = xTaskGetTickCount();


		for(;;)
		{
			xTaskNotify(myTask2Handle , (1<<0), eSetBits); //1
			vTaskDelay(1000);

			xTaskNotify(myTask2Handle , (1<<1), eSetBits); //2
			vTaskDelay(1000);

			xTaskNotify(myTask2Handle , (1<<2), eSetBits); //4
			vTaskDelay(1000);

		}
}

void myTask2(void *pvParameters)
{

	TickType_t xDelay = pdMS_TO_TICKS(1000);
	TickType_t myLastUnblock;
	myLastUnblock = xTaskGetTickCount();

	uint32_t ulNotifiedValue;
	char temp[10];
	char* text;
		for(;;)
		{


			if( xTaskNotifyWait( (1<<2) | (1<<1) | (1<<0), 0, &ulNotifiedValue, portMAX_DELAY) == pdTRUE)
			{ //첫번째, mask to notification value that i wan to clear , 두번째 clearing on exit to the function(?)
			  // 모든 bit를 초기화하려면 첫번째 parameter를 0xFFFFFFFF 로 두면됨
				text = "notification received : ";
				HAL_UART_Transmit(&huart2, (uint8_t *)text,strlen(text) , 10);
				sprintf(temp,"%d", ulNotifiedValue);
				HAL_UART_Transmit(&huart2, (uint8_t *)temp,strlen(temp) , 10);
				HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);

			}
			//HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);




		}
}

                   
notification received : 1
                                                     
notification received : 2
                                                     
notification received : 4

void myTask1(void *pvParameters)
{

	TickType_t xDelay = pdMS_TO_TICKS(1000);
	TickType_t myLastUnblock;
	myLastUnblock = xTaskGetTickCount();

	uint32_t ulNotifiedValue;
	char* text;
	char temp[10];

	xTaskNotify(myTask2Handle , (1<<0), eSetValueWithoutOverwrite); //1
	vTaskDelay(1000);

	xTaskNotify(myTask2Handle , (1<<1), eSetValueWithoutOverwrite); //2
	vTaskDelay(1000);

	xTaskNotifyAndQuery(myTask2Handle, (1<<2), eSetValueWithoutOverwrite, &ulNotifiedValue);//4
	//it will show me the last value which is going to be
	vTaskDelay(1000);

	text = "the last notification value was : ";
	sprintf(temp,"%d", ulNotifiedValue);
	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);

		for(;;)
		{


		}
}

void myTask2(void *pvParameters)
{

	TickType_t xDelay = pdMS_TO_TICKS(1000);
	TickType_t myLastUnblock;
	myLastUnblock = xTaskGetTickCount();

	uint32_t ulNotifiedValue;
	char temp[10];
	char* text;
		for(;;)
		{


			if( xTaskNotifyWait( 0, 0, &ulNotifiedValue, portMAX_DELAY) == pdTRUE)
			{ //첫번째, mask to notification value that i wan to clear , 두번째 clearing on exit to the function(?)

				text = "notification received : ";
				HAL_UART_Transmit(&huart2, (uint8_t *)text,strlen(text) , 10);
				sprintf(temp,"%d", ulNotifiedValue);
				HAL_UART_Transmit(&huart2, (uint8_t *)temp,strlen(temp) , 10);
				HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);

			}
			//HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);




		}
}

notification received : 1
                                                     
notification received : 2
                                                     
notification received : 4     

the last notification value was : 2        

void myTask1(void *pvParameters)
{

	TickType_t xDelay = pdMS_TO_TICKS(1000);
	TickType_t myLastUnblock;
	myLastUnblock = xTaskGetTickCount();

	uint32_t ulNotifiedValue;
	char* text;
	char temp[10];

	xTaskNotify(myTask2Handle , (1<<0), eSetBits); //1
	xTaskNotify(myTask2Handle , (1<<1), eSetBits); //2

	xTaskNotifyStateClear(myTask2Handle); //notification value를 초기화 하진 않는다.

	xTaskNotify(myTask2Handle , (1<<2), eSetBits); //2

	vTaskDelay(1000);
/*
	text = "the last notification value was : ";
	sprintf(temp,"%d", ulNotifiedValue);
	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);
*/
		for(;;)
		{


		}
}

void myTask2(void *pvParameters)
{

	TickType_t xDelay = pdMS_TO_TICKS(1000);
	TickType_t myLastUnblock;
	myLastUnblock = xTaskGetTickCount();

	uint32_t ulNotifiedValue;
	char temp[10];
	char* text;

	vTaskDelay(1000);

		for(;;)
		{


			if( xTaskNotifyWait( 0, 0, &ulNotifiedValue, portMAX_DELAY) == pdTRUE)
			{ //첫번째, mask to notification value that i wan to clear , 두번째 clearing on exit to the function(?)

				text = "notification received : ";
				HAL_UART_Transmit(&huart2, (uint8_t *)text,strlen(text) , 10);
				sprintf(temp,"%d", ulNotifiedValue);
				HAL_UART_Transmit(&huart2, (uint8_t *)temp,strlen(temp) , 10);
				HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);

			}
			//HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);




		}
}



notification received : 7

 

TaskHandle_t myTask1Handle = NULL;
TaskHandle_t myTask2Handle = NULL;
int notificationValue;

void myTask1(void *pvParameters)
{

	TickType_t xDelay = pdMS_TO_TICKS(1000);
	TickType_t myLastUnblock;
	myLastUnblock = xTaskGetTickCount();

	uint32_t ulNotifiedValue;
	char* text;
	char temp[10];

	
		for(;;)
		{

			xTaskNotify(myTask2Handle , (1<<0), eSetBits); //1
			vTaskDelay(1000);
			xTaskNotify(myTask2Handle , (1<<1), eSetBits); //2
			vTaskDelay(1000);
			xTaskNotify(myTask2Handle , (1<<2), eSetBits); //2
			vTaskDelay(1000);

		}
}

void myTask2(void *pvParameters)
{

	TickType_t xDelay = pdMS_TO_TICKS(1000);
	TickType_t myLastUnblock;
	myLastUnblock = xTaskGetTickCount();

	uint32_t ulNotifiedValue;
	char temp[10];
	char* text;

	vTaskDelay(1000);

		for(;;)
		{


			if( xTaskNotifyWait( 0xFFFFFFFF, 0, &ulNotifiedValue, portMAX_DELAY) == pdTRUE)
			{ //첫번째, mask to notification value that i wan to clear , 두번째 clearing on exit to the function(?)

				if( ulNotifiedValue & (1<<0)  )
				{
					HAL_UART_Transmit(&huart2, (uint8_t *)"red\r\n",strlen("red\r\n") , 10);
				}else if( ulNotifiedValue & (1<<1)  )
				{
					HAL_UART_Transmit(&huart2, (uint8_t *)"green\r\n",strlen("green\r\n") , 10);
				}else if( ulNotifiedValue & (1<<2)  )
				{
					HAL_UART_Transmit(&huart2, (uint8_t *)"blue\r\n",strlen("blue\r\n") , 10);
				}


			}
			//HAL_UART_Transmit(&huart2, (uint8_t *)"\r\n",strlen("\r\n") , 10);




		}
}

red
                                                                           
green
                                                                         
blue
                                                                          
red
                                                                           
green
                                                                         
blue