cancel
Showing results for 
Search instead for 
Did you mean: 

A priority on callback ?

antonius
Senior

Dear Members,

I have two interrupts on my callback,

how can I make a priority for them ?

Thanks

code :

void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart)
{   
	if(huart->Instance==USART2)
		{
			GPS_CallBack();
		}	
	if(huart->Instance==USART1)
		{ 
			SIM900_CallBack();
		    
		}

4 REPLIES 4

They occur under interrupt context.

The NVIC IRQ priority and settings will be controlling.

The callback must execute very quickly and leave, they can't spend a lot of time faffing around or blocking.

Assume you have a single byte time, if you can't do what you need quickly, buffer the data and process it in another task.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
antonius
Senior

Correct me :

void	SIM900_CallBack(void)
{
	printf("SIM900 CallBack Receiving from SIM900 \r\n");
	SIM900.LastTime=HAL_GetTick();
	if(SIM900.rxIndex < sizeof(SIM900.rxBuffer)-2)
	{
		SIM900.rxBuffer[SIM900.rxIndex] = SIM900.rxTmp;
		SIM900.rxIndex++;
		 memcpy((void *)line_buffer_SIM900, SIM900.rxBuffer, SIM900.rxIndex); 
		  HAL_UART_Transmit_IT(&huart3,(uint8_t *)&SIM900.rxBuffer, 1);
	    
	}	
	HAL_UART_Receive_IT(&_SIM900_USART,&SIM900.rxTmp,1);
}

>>Correct me

I'm not interested in correcting everyone's broken code, it's an endless task. What I need is for you to think this stuff through yourself, so you think about the problems you're having and why they are occuring.

Remember the "within a single byte time", you can't be using printf() to send two-dozen characters. While some implementations can buffer, I'm pretty sure the one here isn't that sophisticated.

How does it manage the completion on the buffer? You probably want a much clearer demarcation of what's handled in the interrupt/callback and what's handled in foreground/other tasks. Just using "volatile" doesn't achieve thread safe operations, or contain race conditions.

Specifically you don't what rxIndex to be changed in multiple locations. Don't move to the line buffer until you have it completed. You want a singular action. ie get closure on the data, move the rxIndex/rxBuffer to a length/buffer, the task doing the work on the length/buffer doesn't write to either of those variables, just reads.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Rogers.Gary
Senior II

You want to change which one gets processes first in the callback? What will initiate the change of priority? If it's a DMA callback, and you can "afford" to loose data while processing, you can set the DMA for overwrite. GPS ephemeris data is a constant stream so if you lose the odd byte it may not cause a problem, depending on the application and USART rate from the GPS. You might think about using FreeRTOS, there are various tools such as event flags that can help prioritize and process data.