OpenCores
URL https://opencores.org/ocsvn/openfire2/openfire2/trunk

Subversion Repositories openfire2

[/] [openfire2/] [trunk/] [sw/] [freertos/] [queue.h] - Diff between revs 4 and 6

Only display areas with differences | Details | Blame | View Log

Rev 4 Rev 6
/*
/*
        FreeRTOS.org V4.2.0 - Copyright (C) 2003-2007 Richard Barry.
        FreeRTOS.org V4.2.0 - Copyright (C) 2003-2007 Richard Barry.
 
 
        This file is part of the FreeRTOS.org distribution.
        This file is part of the FreeRTOS.org distribution.
 
 
        FreeRTOS.org is free software; you can redistribute it and/or modify
        FreeRTOS.org is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.
        (at your option) any later version.
 
 
        FreeRTOS.org is distributed in the hope that it will be useful,
        FreeRTOS.org is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
        GNU General Public License for more details.
 
 
        You should have received a copy of the GNU General Public License
        You should have received a copy of the GNU General Public License
        along with FreeRTOS.org; if not, write to the Free Software
        along with FreeRTOS.org; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
        A special exception to the GPL can be applied should you wish to distribute
        A special exception to the GPL can be applied should you wish to distribute
        a combined work that includes FreeRTOS.org, without being obliged to provide
        a combined work that includes FreeRTOS.org, without being obliged to provide
        the source code for any proprietary components.  See the licensing section
        the source code for any proprietary components.  See the licensing section
        of http://www.FreeRTOS.org for full details of how and when the exception
        of http://www.FreeRTOS.org for full details of how and when the exception
        can be applied.
        can be applied.
 
 
        ***************************************************************************
        ***************************************************************************
        See http://www.FreeRTOS.org for documentation, latest information, license
        See http://www.FreeRTOS.org for documentation, latest information, license
        and contact details.  Please ensure to read the configuration and relevant
        and contact details.  Please ensure to read the configuration and relevant
        port sections of the online documentation.
        port sections of the online documentation.
        ***************************************************************************
        ***************************************************************************
*/
*/
 
 
#ifndef QUEUE_H
#ifndef QUEUE_H
#define QUEUE_H
#define QUEUE_H
 
 
typedef void * xQueueHandle;
typedef void * xQueueHandle;
 
 
/**
/**
 * queue. h
 * queue. h
 * <pre>
 * <pre>
 xQueueHandle xQueueCreate(
 xQueueHandle xQueueCreate(
                              unsigned portBASE_TYPE uxQueueLength,
                              unsigned portBASE_TYPE uxQueueLength,
                              unsigned portBASE_TYPE uxItemSize
                              unsigned portBASE_TYPE uxItemSize
                          );
                          );
 * </pre>
 * </pre>
 *
 *
 * Creates a new queue instance.  This allocates the storage required by the
 * Creates a new queue instance.  This allocates the storage required by the
 * new queue and returns a handle for the queue.
 * new queue and returns a handle for the queue.
 *
 *
 * @param uxQueueLength The maximum number of items that the queue can contain.
 * @param uxQueueLength The maximum number of items that the queue can contain.
 *
 *
 * @param uxItemSize The number of bytes each item in the queue will require.
 * @param uxItemSize The number of bytes each item in the queue will require.
 * Items are queued by copy, not by reference, so this is the number of bytes
 * Items are queued by copy, not by reference, so this is the number of bytes
 * that will be copied for each posted item.  Each item on the queue must be
 * that will be copied for each posted item.  Each item on the queue must be
 * the same size.
 * the same size.
 *
 *
 * @return If the queue is successfully create then a handle to the newly
 * @return If the queue is successfully create then a handle to the newly
 * created queue is returned.  If the queue cannot be created then 0 is
 * created queue is returned.  If the queue cannot be created then 0 is
 * returned.
 * returned.
 *
 *
 * Example usage:
 * Example usage:
   <pre>
   <pre>
 struct AMessage
 struct AMessage
 {
 {
    portCHAR ucMessageID;
    portCHAR ucMessageID;
    portCHAR ucData[ 20 ];
    portCHAR ucData[ 20 ];
 };
 };
 
 
 void vATask( void *pvParameters )
 void vATask( void *pvParameters )
 {
 {
 xQueueHandle xQueue1, xQueue2;
 xQueueHandle xQueue1, xQueue2;
 
 
    // Create a queue capable of containing 10 unsigned long values.
    // Create a queue capable of containing 10 unsigned long values.
    xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
    xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
    if( xQueue1 == 0 )
    if( xQueue1 == 0 )
    {
    {
        // Queue was not created and must not be used.
        // Queue was not created and must not be used.
    }
    }
 
 
    // Create a queue capable of containing 10 pointers to AMessage structures.
    // Create a queue capable of containing 10 pointers to AMessage structures.
    // These should be passed by pointer as they contain a lot of data.
    // These should be passed by pointer as they contain a lot of data.
    xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
    xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
    if( xQueue2 == 0 )
    if( xQueue2 == 0 )
    {
    {
        // Queue was not created and must not be used.
        // Queue was not created and must not be used.
    }
    }
 
 
    // ... Rest of task code.
    // ... Rest of task code.
 }
 }
 </pre>
 </pre>
 * \defgroup xQueueCreate xQueueCreate
 * \defgroup xQueueCreate xQueueCreate
 * \ingroup QueueManagement
 * \ingroup QueueManagement
 */
 */
xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
 
 
/**
/**
 * queue. h
 * queue. h
 * <pre>
 * <pre>
 portBASE_TYPE xQueueSend(
 portBASE_TYPE xQueueSend(
                             xQueueHandle xQueue,
                             xQueueHandle xQueue,
                             const void * pvItemToQueue,
                             const void * pvItemToQueue,
                             portTickType xTicksToWait
                             portTickType xTicksToWait
                         );
                         );
 * </pre>
 * </pre>
 *
 *
 * Post an item on a queue.  The item is queued by copy, not by reference.
 * Post an item on a queue.  The item is queued by copy, not by reference.
 * This function must not be called from an interrupt service routine.
 * This function must not be called from an interrupt service routine.
 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
 *
 *
 * @param xQueue The handle to the queue on which the item is to be posted.
 * @param xQueue The handle to the queue on which the item is to be posted.
 *
 *
 * @param pvItemToQueue A pointer to the item that is to be placed on the
 * @param pvItemToQueue A pointer to the item that is to be placed on the
 * queue.  The size of the items the queue will hold was defined when the
 * queue.  The size of the items the queue will hold was defined when the
 * queue was created, so this many bytes will be copied from pvItemToQueue
 * queue was created, so this many bytes will be copied from pvItemToQueue
 * into the queue storage area.
 * into the queue storage area.
 *
 *
 * @param xTicksToWait The maximum amount of time the task should block
 * @param xTicksToWait The maximum amount of time the task should block
 * waiting for space to become available on the queue, should it already
 * waiting for space to become available on the queue, should it already
 * be full.  The call will return immediately if this is set to 0.  The
 * be full.  The call will return immediately if this is set to 0.  The
 * time is defined in tick periods so the constant portTICK_RATE_MS
 * time is defined in tick periods so the constant portTICK_RATE_MS
 * should be used to convert to real time if this is required.
 * should be used to convert to real time if this is required.
 *
 *
 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
 *
 *
 * Example usage:
 * Example usage:
   <pre>
   <pre>
 struct AMessage
 struct AMessage
 {
 {
    portCHAR ucMessageID;
    portCHAR ucMessageID;
    portCHAR ucData[ 20 ];
    portCHAR ucData[ 20 ];
 } xMessage;
 } xMessage;
 
 
 unsigned portLONG ulVar = 10UL;
 unsigned portLONG ulVar = 10UL;
 
 
 void vATask( void *pvParameters )
 void vATask( void *pvParameters )
 {
 {
 xQueueHandle xQueue1, xQueue2;
 xQueueHandle xQueue1, xQueue2;
 struct AMessage *pxMessage;
 struct AMessage *pxMessage;
 
 
    // Create a queue capable of containing 10 unsigned long values.
    // Create a queue capable of containing 10 unsigned long values.
    xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
    xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
 
 
    // Create a queue capable of containing 10 pointers to AMessage structures.
    // Create a queue capable of containing 10 pointers to AMessage structures.
    // These should be passed by pointer as they contain a lot of data.
    // These should be passed by pointer as they contain a lot of data.
    xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
    xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
 
 
    // ...
    // ...
 
 
    if( xQueue1 != 0 )
    if( xQueue1 != 0 )
    {
    {
        // Send an unsigned long.  Wait for 10 ticks for space to become
        // Send an unsigned long.  Wait for 10 ticks for space to become
        // available if necessary.
        // available if necessary.
        if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
        if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
        {
        {
            // Failed to post the message, even after 10 ticks.
            // Failed to post the message, even after 10 ticks.
        }
        }
    }
    }
 
 
    if( xQueue2 != 0 )
    if( xQueue2 != 0 )
    {
    {
        // Send a pointer to a struct AMessage object.  Don't block if the
        // Send a pointer to a struct AMessage object.  Don't block if the
        // queue is already full.
        // queue is already full.
        pxMessage = & xMessage;
        pxMessage = & xMessage;
        xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
        xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
    }
    }
 
 
        // ... Rest of task code.
        // ... Rest of task code.
 }
 }
 </pre>
 </pre>
 * \defgroup xQueueSend xQueueSend
 * \defgroup xQueueSend xQueueSend
 * \ingroup QueueManagement
 * \ingroup QueueManagement
 */
 */
signed portBASE_TYPE xQueueSend( xQueueHandle xQueue, const void * pvItemToQueue, portTickType xTicksToWait );
signed portBASE_TYPE xQueueSend( xQueueHandle xQueue, const void * pvItemToQueue, portTickType xTicksToWait );
 
 
/**
/**
 * queue. h
 * queue. h
 * <pre>
 * <pre>
 portBASE_TYPE xQueueReceive(
 portBASE_TYPE xQueueReceive(
                                xQueueHandle xQueue,
                                xQueueHandle xQueue,
                                void *pvBuffer,
                                void *pvBuffer,
                                portTickType xTicksToWait
                                portTickType xTicksToWait
                            );</pre>
                            );</pre>
 *
 *
 * Receive an item from a queue.  The item is received by copy so a buffer of
 * Receive an item from a queue.  The item is received by copy so a buffer of
 * adequate size must be provided.  The number of bytes copied into the buffer
 * adequate size must be provided.  The number of bytes copied into the buffer
 * was defined when the queue was created.
 * was defined when the queue was created.
 *
 *
 * This function must not be used in an interrupt service routine.  See
 * This function must not be used in an interrupt service routine.  See
 * xQueueReceiveFromISR for an alternative that can.
 * xQueueReceiveFromISR for an alternative that can.
 *
 *
 * @param pxQueue The handle to the queue from which the item is to be
 * @param pxQueue The handle to the queue from which the item is to be
 * received.
 * received.
 *
 *
 * @param pvBuffer Pointer to the buffer into which the received item will
 * @param pvBuffer Pointer to the buffer into which the received item will
 * be copied.
 * be copied.
 *
 *
 * @param xTicksToWait The maximum amount of time the task should block
 * @param xTicksToWait The maximum amount of time the task should block
 * waiting for an item to receive should the queue be empty at the time
 * waiting for an item to receive should the queue be empty at the time
 * of the call.    The time is defined in tick periods so the constant
 * of the call.    The time is defined in tick periods so the constant
 * portTICK_RATE_MS should be used to convert to real time if this is required.
 * portTICK_RATE_MS should be used to convert to real time if this is required.
 *
 *
 * @return pdTRUE if an item was successfully received from the queue,
 * @return pdTRUE if an item was successfully received from the queue,
 * otherwise pdFALSE.
 * otherwise pdFALSE.
 *
 *
 * Example usage:
 * Example usage:
   <pre>
   <pre>
 struct AMessage
 struct AMessage
 {
 {
    portCHAR ucMessageID;
    portCHAR ucMessageID;
    portCHAR ucData[ 20 ];
    portCHAR ucData[ 20 ];
 } xMessage;
 } xMessage;
 
 
 xQueueHandle xQueue;
 xQueueHandle xQueue;
 
 
 // Task to create a queue and post a value.
 // Task to create a queue and post a value.
 void vATask( void *pvParameters )
 void vATask( void *pvParameters )
 {
 {
 struct AMessage *pxMessage;
 struct AMessage *pxMessage;
 
 
    // Create a queue capable of containing 10 pointers to AMessage structures.
    // Create a queue capable of containing 10 pointers to AMessage structures.
    // These should be passed by pointer as they contain a lot of data.
    // These should be passed by pointer as they contain a lot of data.
    xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
    xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
    if( xQueue == 0 )
    if( xQueue == 0 )
    {
    {
        // Failed to create the queue.
        // Failed to create the queue.
    }
    }
 
 
    // ...
    // ...
 
 
    // Send a pointer to a struct AMessage object.  Don't block if the
    // Send a pointer to a struct AMessage object.  Don't block if the
    // queue is already full.
    // queue is already full.
    pxMessage = & xMessage;
    pxMessage = & xMessage;
    xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
    xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
 
 
        // ... Rest of task code.
        // ... Rest of task code.
 }
 }
 
 
 // Task to receive from the queue.
 // Task to receive from the queue.
 void vADifferentTask( void *pvParameters )
 void vADifferentTask( void *pvParameters )
 {
 {
 struct AMessage *pxRxedMessage;
 struct AMessage *pxRxedMessage;
 
 
    if( xQueue != 0 )
    if( xQueue != 0 )
    {
    {
        // Receive a message on the created queue.  Block for 10 ticks if a
        // Receive a message on the created queue.  Block for 10 ticks if a
        // message is not immediately available.
        // message is not immediately available.
        if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
        if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
        {
        {
            // pcRxedMessage now points to the struct AMessage variable posted
            // pcRxedMessage now points to the struct AMessage variable posted
            // by vATask.
            // by vATask.
        }
        }
    }
    }
 
 
        // ... Rest of task code.
        // ... Rest of task code.
 }
 }
 </pre>
 </pre>
 * \defgroup xQueueReceive xQueueReceive
 * \defgroup xQueueReceive xQueueReceive
 * \ingroup QueueManagement
 * \ingroup QueueManagement
 */
 */
signed portBASE_TYPE xQueueReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait );
signed portBASE_TYPE xQueueReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait );
 
 
/**
/**
 * queue. h
 * queue. h
 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( xQueueHandle xQueue );</pre>
 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( xQueueHandle xQueue );</pre>
 *
 *
 * Return the number of messages stored in a queue.
 * Return the number of messages stored in a queue.
 *
 *
 * @param xQueue A handle to the queue being queried.
 * @param xQueue A handle to the queue being queried.
 *
 *
 * @return The number of messages available in the queue.
 * @return The number of messages available in the queue.
 *
 *
 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
 * \ingroup QueueManagement
 * \ingroup QueueManagement
 */
 */
unsigned portBASE_TYPE uxQueueMessagesWaiting( xQueueHandle xQueue );
unsigned portBASE_TYPE uxQueueMessagesWaiting( xQueueHandle xQueue );
 
 
/**
/**
 * queue. h
 * queue. h
 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
 *
 *
 * Delete a queue - freeing all the memory allocated for storing of items
 * Delete a queue - freeing all the memory allocated for storing of items
 * placed on the queue.
 * placed on the queue.
 *
 *
 * @param xQueue A handle to the queue to be deleted.
 * @param xQueue A handle to the queue to be deleted.
 *
 *
 * \page vQueueDelete vQueueDelete
 * \page vQueueDelete vQueueDelete
 * \ingroup QueueManagement
 * \ingroup QueueManagement
 */
 */
void vQueueDelete( xQueueHandle xQueue );
void vQueueDelete( xQueueHandle xQueue );
 
 
/**
/**
 * queue. h
 * queue. h
 * <pre>
 * <pre>
 portBASE_TYPE xQueueSendFromISR(
 portBASE_TYPE xQueueSendFromISR(
                                    xQueueHandle pxQueue,
                                    xQueueHandle pxQueue,
                                    const void *pvItemToQueue,
                                    const void *pvItemToQueue,
                                    portBASE_TYPE xTaskPreviouslyWoken
                                    portBASE_TYPE xTaskPreviouslyWoken
                                );
                                );
 </pre>
 </pre>
 *
 *
 * Post an item on a queue.  It is safe to use this function from within an
 * Post an item on a queue.  It is safe to use this function from within an
 * interrupt service routine.
 * interrupt service routine.
 *
 *
 * Items are queued by copy not reference so it is preferable to only
 * Items are queued by copy not reference so it is preferable to only
 * queue small items, especially when called from an ISR.  In most cases
 * queue small items, especially when called from an ISR.  In most cases
 * it would be preferable to store a pointer to the item being queued.
 * it would be preferable to store a pointer to the item being queued.
 *
 *
 * @param xQueue The handle to the queue on which the item is to be posted.
 * @param xQueue The handle to the queue on which the item is to be posted.
 *
 *
 * @param pvItemToQueue A pointer to the item that is to be placed on the
 * @param pvItemToQueue A pointer to the item that is to be placed on the
 * queue.  The size of the items the queue will hold was defined when the
 * queue.  The size of the items the queue will hold was defined when the
 * queue was created, so this many bytes will be copied from pvItemToQueue
 * queue was created, so this many bytes will be copied from pvItemToQueue
 * into the queue storage area.
 * into the queue storage area.
 *
 *
 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
 * the same queue multiple times from a single interrupt.  The first call
 * the same queue multiple times from a single interrupt.  The first call
 * should always pass in pdFALSE.  Subsequent calls should pass in
 * should always pass in pdFALSE.  Subsequent calls should pass in
 * the value returned from the previous call.  See the file serial .c in the
 * the value returned from the previous call.  See the file serial .c in the
 * PC port for a good example of this mechanism.
 * PC port for a good example of this mechanism.
 *
 *
 * @return pdTRUE if a task was woken by posting onto the queue.  This is
 * @return pdTRUE if a task was woken by posting onto the queue.  This is
 * used by the ISR to determine if a context switch may be required following
 * used by the ISR to determine if a context switch may be required following
 * the ISR.
 * the ISR.
 *
 *
 * Example usage for buffered IO (where the ISR can obtain more than one value
 * Example usage for buffered IO (where the ISR can obtain more than one value
 * per call):
 * per call):
   <pre>
   <pre>
 void vBufferISR( void )
 void vBufferISR( void )
 {
 {
 portCHAR cIn;
 portCHAR cIn;
 portBASE_TYPE xTaskWokenByPost;
 portBASE_TYPE xTaskWokenByPost;
 
 
    // We have not woken a task at the start of the ISR.
    // We have not woken a task at the start of the ISR.
    cTaskWokenByPost = pdFALSE;
    cTaskWokenByPost = pdFALSE;
 
 
    // Loop until the buffer is empty.
    // Loop until the buffer is empty.
    do
    do
    {
    {
        // Obtain a byte from the buffer.
        // Obtain a byte from the buffer.
        cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
        cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
 
 
        // Post the byte.  The first time round the loop cTaskWokenByPost
        // Post the byte.  The first time round the loop cTaskWokenByPost
        // will be pdFALSE.  If the queue send causes a task to wake we do
        // will be pdFALSE.  If the queue send causes a task to wake we do
        // not want the task to run until we have finished the ISR, so
        // not want the task to run until we have finished the ISR, so
        // xQueueSendFromISR does not cause a context switch.  Also we
        // xQueueSendFromISR does not cause a context switch.  Also we
        // don't want subsequent posts to wake any other tasks, so we store
        // don't want subsequent posts to wake any other tasks, so we store
        // the return value back into cTaskWokenByPost so xQueueSendFromISR
        // the return value back into cTaskWokenByPost so xQueueSendFromISR
        // knows not to wake any task the next iteration of the loop.
        // knows not to wake any task the next iteration of the loop.
        xTaskWokenByPost = xQueueSendFromISR( xRxQueue, &cIn, cTaskWokenByPost );
        xTaskWokenByPost = xQueueSendFromISR( xRxQueue, &cIn, cTaskWokenByPost );
 
 
    } while( portINPUT_BYTE( BUFFER_COUNT ) );
    } while( portINPUT_BYTE( BUFFER_COUNT ) );
 
 
    // Now the buffer is empty we can switch context if necessary.
    // Now the buffer is empty we can switch context if necessary.
    if( cTaskWokenByPost )
    if( cTaskWokenByPost )
    {
    {
        taskYIELD ();
        taskYIELD ();
    }
    }
 }
 }
 </pre>
 </pre>
 *
 *
 * \defgroup xQueueSendFromISR xQueueSendFromISR
 * \defgroup xQueueSendFromISR xQueueSendFromISR
 * \ingroup QueueManagement
 * \ingroup QueueManagement
 */
 */
signed portBASE_TYPE xQueueSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xTaskPreviouslyWoken );
signed portBASE_TYPE xQueueSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xTaskPreviouslyWoken );
 
 
/**
/**
 * queue. h
 * queue. h
 * <pre>
 * <pre>
 portBASE_TYPE xQueueReceiveFromISR(
 portBASE_TYPE xQueueReceiveFromISR(
                                       xQueueHandle pxQueue,
                                       xQueueHandle pxQueue,
                                       void *pvBuffer,
                                       void *pvBuffer,
                                       portBASE_TYPE *pxTaskWoken
                                       portBASE_TYPE *pxTaskWoken
                                   );
                                   );
 * </pre>
 * </pre>
 *
 *
 * Receive an item from a queue.  It is safe to use this function from within an
 * Receive an item from a queue.  It is safe to use this function from within an
 * interrupt service routine.
 * interrupt service routine.
 *
 *
 * @param pxQueue The handle to the queue from which the item is to be
 * @param pxQueue The handle to the queue from which the item is to be
 * received.
 * received.
 *
 *
 * @param pvBuffer Pointer to the buffer into which the received item will
 * @param pvBuffer Pointer to the buffer into which the received item will
 * be copied.
 * be copied.
 *
 *
 * @param pxTaskWoken A task may be blocked waiting for space to become
 * @param pxTaskWoken A task may be blocked waiting for space to become
 * available on the queue.  If xQueueReceiveFromISR causes such a task to
 * available on the queue.  If xQueueReceiveFromISR causes such a task to
 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
 * remain unchanged.
 * remain unchanged.
 *
 *
 * @return pdTRUE if an item was successfully received from the queue,
 * @return pdTRUE if an item was successfully received from the queue,
 * otherwise pdFALSE.
 * otherwise pdFALSE.
 *
 *
 * Example usage:
 * Example usage:
   <pre>
   <pre>
 
 
 xQueueHandle xQueue;
 xQueueHandle xQueue;
 
 
 // Function to create a queue and post some values.
 // Function to create a queue and post some values.
 void vAFunction( void *pvParameters )
 void vAFunction( void *pvParameters )
 {
 {
 portCHAR cValueToPost;
 portCHAR cValueToPost;
 const portTickType xBlockTime = ( portTickType )0xff;
 const portTickType xBlockTime = ( portTickType )0xff;
 
 
    // Create a queue capable of containing 10 characters.
    // Create a queue capable of containing 10 characters.
    xQueue = xQueueCreate( 10, sizeof( portCHAR ) );
    xQueue = xQueueCreate( 10, sizeof( portCHAR ) );
    if( xQueue == 0 )
    if( xQueue == 0 )
    {
    {
        // Failed to create the queue.
        // Failed to create the queue.
    }
    }
 
 
    // ...
    // ...
 
 
    // Post some characters that will be used within an ISR.  If the queue
    // Post some characters that will be used within an ISR.  If the queue
    // is full then this task will block for xBlockTime ticks.
    // is full then this task will block for xBlockTime ticks.
    cValueToPost = 'a';
    cValueToPost = 'a';
    xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
    xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
    cValueToPost = 'b';
    cValueToPost = 'b';
    xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
    xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
 
 
    // ... keep posting characters ... this task may block when the queue
    // ... keep posting characters ... this task may block when the queue
    // becomes full.
    // becomes full.
 
 
    cValueToPost = 'c';
    cValueToPost = 'c';
    xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
    xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
 }
 }
 
 
 // ISR that outputs all the characters received on the queue.
 // ISR that outputs all the characters received on the queue.
 void vISR_Routine( void )
 void vISR_Routine( void )
 {
 {
 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
 portCHAR cRxedChar;
 portCHAR cRxedChar;
 
 
    while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
    while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
    {
    {
        // A character was received.  Output the character now.
        // A character was received.  Output the character now.
        vOutputCharacter( cRxedChar );
        vOutputCharacter( cRxedChar );
 
 
        // If removing the character from the queue woke the task that was
        // If removing the character from the queue woke the task that was
        // posting onto the queue cTaskWokenByReceive will have been set to
        // posting onto the queue cTaskWokenByReceive will have been set to
        // pdTRUE.  No matter how many times this loop iterates only one
        // pdTRUE.  No matter how many times this loop iterates only one
        // task will be woken.
        // task will be woken.
    }
    }
 
 
    if( cTaskWokenByPost != ( portCHAR ) pdFALSE;
    if( cTaskWokenByPost != ( portCHAR ) pdFALSE;
    {
    {
        taskYIELD ();
        taskYIELD ();
    }
    }
 }
 }
 </pre>
 </pre>
 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
 * \ingroup QueueManagement
 * \ingroup QueueManagement
 */
 */
signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
 
 
 
 
/*
/*
 * The functions defined above are for passing data to and from tasks.  The
 * The functions defined above are for passing data to and from tasks.  The
 * functions below are the equivalents for passing data to and from
 * functions below are the equivalents for passing data to and from
 * co-rtoutines.
 * co-rtoutines.
 *
 *
 * These functions are called from the co-routine macro implementation and
 * These functions are called from the co-routine macro implementation and
 * should not be called directly from application code.  Instead use the macro
 * should not be called directly from application code.  Instead use the macro
 * wrappers defined within croutine.h.
 * wrappers defined within croutine.h.
 */
 */
signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
 
 
#endif
#endif
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.