cancel
Showing results for 
Search instead for 
Did you mean: 

vTaskResume,vTaskSuspend

rajesh23
Associate II
Posted on August 16, 2016 at 11:45

     

 hi, i am using STM32F746G-Disco in that i have receiving a 16 byte of data from other device,which can be get at interrupt . problem: i have created two threads for GUI and Uart Thread, in that uart thread i have i amcontinuously polling for uart data has receivedcompletely.  Is there is anypossibility for resume task from whenever complete packet received from interrupt given below.  i have tried below code it was hangs some where can any one help me this issue regards rajesh    i have two threads 1. GUI and uart thread   /*

uart thread that resumes from interrupt when data buffer fills in uart RX.

*/

static

void

UartThread(

void

const

* argument )

{

static

uint8_t taskState = FALSE;

if

(taskState == TRUE)

{

taskState = FALSE;

while

(1)

{

HAL_Delay(100);

BSP_LED_Toggle(LED_GREEN);

}

}

else

{

if

(HAL_UART_Receive_IT(&UartHandle, (uint8_t *) aRxBuffer, 16) != HAL_OK)

{

}

else

{

vTaskSuspend(NULL);

taskState = TRUE;

}

}

}

/****

uart rx call back function

*****/

void

HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

if

(huart->RxXferCount == 0x00)

{

vTaskResume(uartTaskhandle);

}

else

{

#st32f46g

3 REPLIES 3
Self.Glenn
Associate III
Posted on August 17, 2016 at 01:13

Hi,

A couple of things.

1) you should declare taskState  with the volatile keyword so that the compiler doesn't optimise it away, leaving you with taskState always equal to 'false' 

2)Is vTaskSuspend() interrupt safe? The documentation doesn't say it is, which means you should assume that it is not.

What you should do is either use a semaphore, or a queue. FreeRTOS has ISR safe Queue/Sem functions.  The ISR posts to the Sem or Queue when it has data. The task will be blocked waiting on the Queue/Sem.  It will unblock when data arrives and you can process it.

If your data arriving via the USART is small in size, you could copy it into the Queue and process it safely in  UartThread().

Glenn

jpeacock23
Associate II
Posted on August 17, 2016 at 19:48

Suspend and resume only control whether a task is available for scheduling.  It doesn't actually cause the task to execute.  You should use an event to block the task when it's idle and unblock when it needs to complete the interrupt.  A semaphore or direct notification in later versions should work for an interrupt completion.

  Jack Peacock

Osto
Senior
Posted on August 19, 2016 at 16:07

Hi,

In my opinion you are using the wrong way for data transfer. There are 2 ways to solve the problem.

1.) Use message queue. you define a queue with size of max transfer length and in  callback you put the data into message queue and in the task you read so long from queue until you get a message then use the data from queue for doing your job.

2.) Use binary semaphore. You define a baniary semaphore which is given by callback and taken by task which do the job. The job task hangs so long until the semaphore is given.

Its not a good way to use suspend task for waiting for an event.

Regards

Osto