FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [January 2017 Threads] xQueueResetPosted by jalegre2003 on January 31, 2017 Hello,
Can xQueueReset be used from within an ISR?
If not, which function should be used?
Thanks in advance.
xQueueResetPosted by heinbali01 on January 31, 2017 As you might have guessed, xQueueReset() doesn't end with fromISR and it is not supposed to be called from an ISR.
I wouldn't know a good reason to reset a queue from within an ISR.
All I ever do with a queue from within an interrupt is post a message, give to a semaphore, and always using the fromISR functions.
Can you explain why you would want to reset a queue ?
xQueueResetPosted by rtel on January 31, 2017 Only functions that end if FromISR can be used in an ISR.
If you want to reset a queue from an interrupt then one option would be
to create a function that wraps the xQueueReset() API, and pend the
function from the ISR. Be aware that the queue won't actually get reset
until the ISR has exited though:
http://www.freertos.org/xTimerPendFunctionCallFromISR.html
xQueueResetPosted by jalegre2003 on January 31, 2017 I'm making a kind of simple SPI <--> UART bridge.
Through SPI commands I am able to configure, write, read... the UART ports.
For example, I use a queue to hold the bytes received from the UART side.
In the SPI side, when a RECEIVEUARTCHAR command is received, the SPI ISR takes one character out of that queue and resends it through SPI.
One of the possible commands is CLEAR_BUFFER, which, as expected, should empty/reset that queue.
A xQueueResetFromISR would perfectly do the work.
Any ideas?
Thanks.
xQueueResetPosted by rtel on January 31, 2017 Something like the following should work, but note this is completely
untested, not even compiled.
BaseType_t xQueueResetFromISR( QueueHandle_t xQueue )
{
Queue_t * const pxQueue = ( Queue_t * ) xQueue;
UBaseType_t uxSavedInterruptStatus;
configASSERT( pxQueue );
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
{
pxQueue->pcTail = pxQueue->pcHead + ( pxQueue->uxLength *
pxQueue->uxItemSize );
pxQueue->uxMessagesWaiting = ( UBaseType_t ) 0U;
pxQueue->pcWriteTo = pxQueue->pcHead;
pxQueue->u.pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength
- ( UBaseType_t ) 1U ) * pxQueue->uxItemSize );
pxQueue->cRxLock = queueUNLOCKED;
pxQueue->cTxLock = queueUNLOCKED;
vListInitialise( &( pxQueue->xTasksWaitingToSend ) );
vListInitialise( &( pxQueue->xTasksWaitingToReceive ) );
}
portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
}
xQueueResetPosted by jalegre2003 on February 1, 2017 Thanks a lot!
I've tried that code and it compiles ok. It also seems that it works ok but, anyway, I'm going to use the pending mechanism option because I think it's, for now, a safer option, until Real Time Engineers decide to release (I hope so) such a feature (xQueueResetFromISR).
Again, thanks for the provided solutions.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|