cancel
Showing results for 
Search instead for 
Did you mean: 

How can I block the execution of the my task in RTOS

Trinu
Associate III

Hi,

Here i want to stop the particular task for certain time

when it receives the event from another task it should continue.

here is my code .

the task is not stopping.

can any one help me

/*----------------------------------------------------------------------------
 * CMSIS-RTOS 'main' function template
 *---------------------------------------------------------------------------*/
 
#include "RTE_Components.h"
#include  CMSIS_device_header
#include "cmsis_os2.h"
#include "stm32f2xx_hal.h"
#include "main.h"
#include "stm32f2xx_hal_gpio.h"
#include "stm32f2xx_hal_usart.h"
 //int Init_Thread (void);
 #define FLAG_MASK 0x00000001U
osEventFlagsId_t EventFlagsId_t; 
int val;
 /*----------------------------------------------------------------------------
 * I/O Configuration
 *---------------------------------------------------------------------------*/
  void gpioInitfunction(void)
{
 
	__HAL_RCC_GPIOF_CLK_ENABLE(); // enabling the peripheral clock
	
	// gpio structure initialization
	GPIO_InitTypeDef GPIO_InitStructure;
	
	GPIO_InitStructure.Mode= GPIO_MODE_INPUT ;                       
	GPIO_InitStructure.Pin= GPIO_PIN_0;
	GPIO_InitStructure.Pull= GPIO_PULLUP;
	GPIO_InitStructure.Speed= GPIO_SPEED_FREQ_HIGH;
 
	HAL_GPIO_Init(GPIOF, &GPIO_InitStructure);
	
}
 
 
 
/*----------------------------------------------------------------------------
 * Application main thread
 *---------------------------------------------------------------------------*/
__NO_RETURN static void app_main (void *argument) {
  (void)argument;
	
	
  while(1);
}
 
/*----------------------------------------------------------------------------
 * Application ledBlink thread
 *---------------------------------------------------------------------------*/
__NO_RETURN static void ledBlink (void *argument) {
  (void)argument;
	
 
	
	gpioInitfunction();
 
	val=0;
	
	/* here we are blinking the LED*/
  while(1)
	{
			// here we need to implent the logic for the read the input from the gpio pins
		
			if((HAL_GPIO_ReadPin(GPIOF,GPIO_PIN_0)==SET)&&(val==0))
			{
					val++;
					val++;
				   osEventFlagsSet(EventFlagsId_t,FLAG_MASK);
			}
 
	}
	
}
/*----------------------------------------------------------------------------
 * Application serialDataExcahnge thread
 *---------------------------------------------------------------------------*/
__NO_RETURN static void serialDataExcahnge (void *argument) {
  (void)argument;
	
 
		uint8_t buff[10]="hello";
	uint32_t flags;
	
		/* enabling the peripheral clock */
		__HAL_RCC_GPIOB_CLK_ENABLE();  
		__HAL_RCC_USART3_CLK_ENABLE();  
 
		GPIO_InitTypeDef GPIO_InitStructure;
		
		USART_HandleTypeDef USART_HandleInit;
 
		USART_HandleInit.Instance=USART3;
 
		GPIO_InitStructure.Mode= GPIO_MODE_AF_PP ;
		GPIO_InitStructure.Pin= GPIO_PIN_10|GPIO_PIN_11;
		GPIO_InitStructure.Pull= GPIO_PULLUP;
		GPIO_InitStructure.Speed= GPIO_SPEED_FREQ_HIGH;
		GPIO_InitStructure.Alternate=GPIO_AF7_USART3;
 
		HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
 
		USART_HandleInit.Init.BaudRate=9600;
		USART_HandleInit.Init.CLKLastBit=USART_LASTBIT_ENABLE;
		USART_HandleInit.Init.CLKPhase=USART_PHASE_1EDGE;
		USART_HandleInit.Init.CLKPolarity=USART_POLARITY_LOW;
		USART_HandleInit.Init.Mode=USART_MODE_TX_RX ;
		USART_HandleInit.Init.WordLength=UART_WORDLENGTH_8B;
		USART_HandleInit.Init.Parity=USART_PARITY_NONE;
		USART_HandleInit.Init.StopBits=USART_STOPBITS_1;
	
 
		HAL_USART_Init(&USART_HandleInit);
    HAL_USART_Transmit(&USART_HandleInit,buff,5,100);
	
  while(1)
	{
		
 
		flags = osEventFlagsWait(EventFlagsId_t,FLAG_MASK, osFlagsWaitAny, osWaitForever);
		
		HAL_USART_Transmit(&USART_HandleInit,buff,5,100);
		osDelay(1000);
		
		HAL_USART_Transmit(&USART_HandleInit,buff,5,100);
		osDelay(1000);
		val=0;
	}
}
 
 
int main (void) {
 
  // System Initialization
	osThreadId_t thread_id;
 
	
  SystemCoreClockUpdate();
  // ...
 
  osKernelInitialize();                 // Initialize CMSIS-RTOS
	
	 EventFlagsId_t = osEventFlagsNew (NULL);
	
		osThreadNew(app_main, NULL, NULL);    // Create application main thread
	 thread_id = osThreadNew(ledBlink, NULL, NULL);    // Create application ledBlink thread
	 osThreadNew(serialDataExcahnge, NULL, NULL);    // Create application serialDataExcahnge thread
	//Init_Thread (); 
	
  osKernelStart();                      // Start thread execution
  for (;;) {}
}

1 ACCEPTED SOLUTION

Accepted Solutions
Sebastiaan
Senior

I don't see any freertos thread synchronization mechanisms so I think you're not fully aware of them. I suggest to have a look to the freertos documentation (https://www.freertos.org/features.html) to see which mechanisms you could use to synchronize threads.

You could for example use a messagequeue system, or use semaphores to have the 2 threads communicate.

View solution in original post

2 REPLIES 2
Sebastiaan
Senior

I don't see any freertos thread synchronization mechanisms so I think you're not fully aware of them. I suggest to have a look to the freertos documentation (https://www.freertos.org/features.html) to see which mechanisms you could use to synchronize threads.

You could for example use a messagequeue system, or use semaphores to have the 2 threads communicate.

Trinu
Associate III

Thanks for your help.