Update for V6.

pull/4/head
Richard Barry 16 years ago
parent 7dacae2ae9
commit 98ed4f2a20

@ -394,5 +394,21 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * );
#define configUSE_MALLOC_FAILED_HOOK 0 #define configUSE_MALLOC_FAILED_HOOK 0
#endif #endif
#ifndef portPRIVILEGE_BIT
#define portPRIVILEGE_BIT ( ( unsigned portBASE_TYPE ) 0x00 )
#endif
#ifndef portYIELD_WITHIN_API
#define portYIELD_WITHIN_API portYIELD
#endif
#ifndef pvPortMallocAligned
#define pvPortMallocAligned( xSize, pvBuffer ) pvPortMalloc( xSize ); ( void ) pvBuffer
#endif
#ifndef vPortFreeAligned
#define vPortFreeAligned( pvBlockToFree ) vPortFree( pvBlockToFree )
#endif
#endif /* INC_FREERTOS_H */ #endif /* INC_FREERTOS_H */

@ -301,24 +301,54 @@ to find the path to the correct portmacro.h file. */
#include "portmacro.h" #include "portmacro.h"
#endif #endif
#if portBYTE_ALIGNMENT == 8
#define portBYTE_ALIGNMENT_MASK ( 0x0007 )
#endif
#if portBYTE_ALIGNMENT == 4
#define portBYTE_ALIGNMENT_MASK ( 0x0003 )
#endif
#if portBYTE_ALIGNMENT == 2
#define portBYTE_ALIGNMENT_MASK ( 0x0001 )
#endif
#if portBYTE_ALIGNMENT == 1
#define portBYTE_ALIGNMENT_MASK ( 0x0000 )
#endif
#ifndef portBYTE_ALIGNMENT_MASK
#error "Invalid portBYTE_ALIGNMENT definition"
#endif
#ifndef portNUM_CONFIGURABLE_REGIONS
#define portNUM_CONFIGURABLE_REGIONS 1
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "mpu_wrappers.h"
/* /*
* Setup the stack of a new task so it is ready to be placed under the * Setup the stack of a new task so it is ready to be placed under the
* scheduler control. The registers have to be placed on the stack in * scheduler control. The registers have to be placed on the stack in
* the order that the port expects to find them. * the order that the port expects to find them.
* *
*/ */
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ); #if( portUSING_MPU_WRAPPERS == 1 )
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters, portBASE_TYPE xRunPrivileged );
#else
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters );
#endif
/* /*
* Map to the memory management routines required for the port. * Map to the memory management routines required for the port.
*/ */
void *pvPortMalloc( size_t xSize ); void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION;
void vPortFree( void *pv ); void vPortFree( void *pv ) PRIVILEGED_FUNCTION;
void vPortInitialiseBlocks( void ); void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION;
/* /*
* Setup the hardware ready for the scheduler to take control. This generally * Setup the hardware ready for the scheduler to take control. This generally
@ -333,6 +363,18 @@ portBASE_TYPE xPortStartScheduler( void );
*/ */
void vPortEndScheduler( void ); void vPortEndScheduler( void );
/*
* The structures and methods of manipulating the MPU are contained within the
* port layer.
*
* Fills the xMPUSettings structure with the memory region information
* contained in xRegions.
*/
#if( portUSING_MPU_WRAPPERS == 1 )
struct xMEMORY_REGION;
void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, portSTACK_TYPE *pxBottomOfStack, unsigned portSHORT usStackDepth );
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -24,10 +24,10 @@
*************************************************************************** ***************************************************************************
* * * *
* Looking for a quick start? Then check out the FreeRTOS eBook! * * Looking for a quick start? Then check out the FreeRTOS eBook! *
* See http://www.FreeRTOS.org/Documentation for details * * See http://www.FreeRTOS.org/Documentation for details *
* * * *
*************************************************************************** ***************************************************************************
1 tab == 4 spaces! 1 tab == 4 spaces!
@ -58,8 +58,14 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "mpu_wrappers.h"
typedef void * xQueueHandle; typedef void * xQueueHandle;
/* For internal use only. */ /* For internal use only. */
#define queueSEND_TO_BACK ( 0 ) #define queueSEND_TO_BACK ( 0 )
#define queueSEND_TO_FRONT ( 1 ) #define queueSEND_TO_FRONT ( 1 )
@ -69,9 +75,9 @@ 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
@ -92,30 +98,30 @@ typedef void * xQueueHandle;
<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
@ -127,10 +133,10 @@ xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBA
* queue. h * queue. h
* <pre> * <pre>
portBASE_TYPE xQueueSendToToFront( portBASE_TYPE xQueueSendToToFront(
xQueueHandle xQueue, xQueueHandle xQueue,
const void * pvItemToQueue, const void * pvItemToQueue,
portTickType xTicksToWait portTickType xTicksToWait
); );
* </pre> * </pre>
* *
* This is a macro that calls xQueueGenericSend(). * This is a macro that calls xQueueGenericSend().
@ -159,8 +165,8 @@ xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBA
<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;
@ -170,32 +176,32 @@ xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBA
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( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS ) if( xQueueSendToFront( 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;
xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 ); xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
} }
// ... Rest of task code. // ... Rest of task code.
} }
@ -209,10 +215,10 @@ xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBA
* queue. h * queue. h
* <pre> * <pre>
portBASE_TYPE xQueueSendToBack( portBASE_TYPE xQueueSendToBack(
xQueueHandle xQueue, xQueueHandle xQueue,
const void * pvItemToQueue, const void * pvItemToQueue,
portTickType xTicksToWait portTickType xTicksToWait
); );
* </pre> * </pre>
* *
* This is a macro that calls xQueueGenericSend(). * This is a macro that calls xQueueGenericSend().
@ -241,8 +247,8 @@ xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBA
<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;
@ -252,32 +258,32 @@ xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBA
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( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS ) if( xQueueSendToBack( 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;
xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 ); xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
} }
// ... Rest of task code. // ... Rest of task code.
} }
@ -291,10 +297,10 @@ xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBA
* 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>
* *
* This is a macro that calls xQueueGenericSend(). It is included for * This is a macro that calls xQueueGenericSend(). It is included for
@ -325,8 +331,8 @@ xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBA
<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;
@ -336,32 +342,32 @@ xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBA
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.
} }
@ -413,8 +419,8 @@ xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBA
<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;
@ -424,32 +430,32 @@ xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBA
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( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS ) if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != 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;
xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK ); xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
} }
// ... Rest of task code. // ... Rest of task code.
} }
@ -463,10 +469,10 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
* queue. h * queue. h
* <pre> * <pre>
portBASE_TYPE xQueuePeek( portBASE_TYPE xQueuePeek(
xQueueHandle xQueue, xQueueHandle xQueue,
void *pvBuffer, void *pvBuffer,
portTickType xTicksToWait portTickType xTicksToWait
);</pre> );</pre>
* *
* This is a macro that calls the xQueueGenericReceive() function. * This is a macro that calls the xQueueGenericReceive() function.
* *
@ -488,7 +494,7 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
* *
* @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.
* xQueuePeek() will return immediately if xTicksToWait is 0 and the queue * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
* is empty. * is empty.
@ -500,8 +506,8 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
<pre> <pre>
struct AMessage struct AMessage
{ {
portCHAR ucMessageID; portCHAR ucMessageID;
portCHAR ucData[ 20 ]; portCHAR ucData[ 20 ];
} xMessage; } xMessage;
xQueueHandle xQueue; xQueueHandle xQueue;
@ -511,20 +517,20 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
{ {
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.
} }
@ -534,16 +540,16 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
{ {
struct AMessage *pxRxedMessage; struct AMessage *pxRxedMessage;
if( xQueue != 0 ) if( xQueue != 0 )
{ {
// Peek a message on the created queue. Block for 10 ticks if a // Peek a message on the created queue. Block for 10 ticks if a
// message is not immediately available. // message is not immediately available.
if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) ) if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
{ {
// pcRxedMessage now points to the struct AMessage variable posted // pcRxedMessage now points to the struct AMessage variable posted
// by vATask, but the item still remains on the queue. // by vATask, but the item still remains on the queue.
} }
} }
// ... Rest of task code. // ... Rest of task code.
} }
@ -557,10 +563,10 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
* 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>
* *
* This is a macro that calls the xQueueGenericReceive() function. * This is a macro that calls the xQueueGenericReceive() function.
* *
@ -581,7 +587,7 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
* *
* @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. xQueueReceive() will return immediately if xTicksToWait * of the call. xQueueReceive() will return immediately if xTicksToWait
* is zero and the queue is empty. The time is defined in tick periods so the * is zero and the queue is empty. The time is defined in tick periods so the
* constant portTICK_RATE_MS should be used to convert to real time if this is * constant portTICK_RATE_MS should be used to convert to real time if this is
* required. * required.
@ -593,8 +599,8 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
<pre> <pre>
struct AMessage struct AMessage
{ {
portCHAR ucMessageID; portCHAR ucMessageID;
portCHAR ucData[ 20 ]; portCHAR ucData[ 20 ];
} xMessage; } xMessage;
xQueueHandle xQueue; xQueueHandle xQueue;
@ -604,20 +610,20 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
{ {
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.
} }
@ -627,16 +633,16 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
{ {
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.
} }
@ -651,11 +657,11 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
* queue. h * queue. h
* <pre> * <pre>
portBASE_TYPE xQueueGenericReceive( portBASE_TYPE xQueueGenericReceive(
xQueueHandle xQueue, xQueueHandle xQueue,
void *pvBuffer, void *pvBuffer,
portTickType xTicksToWait portTickType xTicksToWait
portBASE_TYPE xJustPeek portBASE_TYPE xJustPeek
);</pre> );</pre>
* *
* It is preferred that the macro xQueueReceive() be used rather than calling * It is preferred that the macro xQueueReceive() be used rather than calling
* this function directly. * this function directly.
@ -675,7 +681,7 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
* *
* @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.
* xQueueGenericReceive() will return immediately if the queue is empty and * xQueueGenericReceive() will return immediately if the queue is empty and
* xTicksToWait is 0. * xTicksToWait is 0.
@ -692,8 +698,8 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
<pre> <pre>
struct AMessage struct AMessage
{ {
portCHAR ucMessageID; portCHAR ucMessageID;
portCHAR ucData[ 20 ]; portCHAR ucData[ 20 ];
} xMessage; } xMessage;
xQueueHandle xQueue; xQueueHandle xQueue;
@ -703,20 +709,20 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
{ {
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.
} }
@ -726,16 +732,16 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const
{ {
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( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) ) if( xQueueGenericReceive( 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.
} }
@ -778,10 +784,10 @@ void vQueueDelete( xQueueHandle xQueue );
* queue. h * queue. h
* <pre> * <pre>
portBASE_TYPE xQueueSendToFrontFromISR( portBASE_TYPE xQueueSendToFrontFromISR(
xQueueHandle pxQueue, xQueueHandle pxQueue,
const void *pvItemToQueue, const void *pvItemToQueue,
portBASE_TYPE *pxHigherPriorityTaskWoken portBASE_TYPE *pxHigherPriorityTaskWoken
); );
</pre> </pre>
* *
* This is a macro that calls xQueueGenericSendFromISR(). * This is a macro that calls xQueueGenericSendFromISR().
@ -817,25 +823,25 @@ void vQueueDelete( xQueueHandle xQueue );
portCHAR cIn; portCHAR cIn;
portBASE_TYPE xHigherPrioritTaskWoken; portBASE_TYPE xHigherPrioritTaskWoken;
// We have not woken a task at the start of the ISR. // We have not woken a task at the start of the ISR.
xHigherPriorityTaskWoken = pdFALSE; xHigherPriorityTaskWoken = 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. // Post the byte.
xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken ); xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
} 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( xHigherPriorityTaskWoken ) if( xHigherPriorityTaskWoken )
{ {
taskYIELD (); taskYIELD ();
} }
} }
</pre> </pre>
* *
@ -849,10 +855,10 @@ void vQueueDelete( xQueueHandle xQueue );
* queue. h * queue. h
* <pre> * <pre>
portBASE_TYPE xQueueSendToBackFromISR( portBASE_TYPE xQueueSendToBackFromISR(
xQueueHandle pxQueue, xQueueHandle pxQueue,
const void *pvItemToQueue, const void *pvItemToQueue,
portBASE_TYPE *pxHigherPriorityTaskWoken portBASE_TYPE *pxHigherPriorityTaskWoken
); );
</pre> </pre>
* *
* This is a macro that calls xQueueGenericSendFromISR(). * This is a macro that calls xQueueGenericSendFromISR().
@ -888,25 +894,25 @@ void vQueueDelete( xQueueHandle xQueue );
portCHAR cIn; portCHAR cIn;
portBASE_TYPE xHigherPriorityTaskWoken; portBASE_TYPE xHigherPriorityTaskWoken;
// We have not woken a task at the start of the ISR. // We have not woken a task at the start of the ISR.
xHigherPriorityTaskWoken = pdFALSE; xHigherPriorityTaskWoken = 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. // Post the byte.
xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken ); xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
} 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( xHigherPriorityTaskWoken ) if( xHigherPriorityTaskWoken )
{ {
taskYIELD (); taskYIELD ();
} }
} }
</pre> </pre>
* *
@ -919,10 +925,10 @@ 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 *pxHigherPriorityTaskWoken portBASE_TYPE *pxHigherPriorityTaskWoken
); );
</pre> </pre>
* *
* This is a macro that calls xQueueGenericSendFromISR(). It is included * This is a macro that calls xQueueGenericSendFromISR(). It is included
@ -961,26 +967,26 @@ void vQueueDelete( xQueueHandle xQueue );
portCHAR cIn; portCHAR cIn;
portBASE_TYPE xHigherPriorityTaskWoken; portBASE_TYPE xHigherPriorityTaskWoken;
// We have not woken a task at the start of the ISR. // We have not woken a task at the start of the ISR.
xHigherPriorityTaskWoken = pdFALSE; xHigherPriorityTaskWoken = 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. // Post the byte.
xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken ); xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
} 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( xHigherPriorityTaskWoken ) if( xHigherPriorityTaskWoken )
{ {
// Actual macro used here is port specific. // Actual macro used here is port specific.
taskYIELD_FROM_ISR (); taskYIELD_FROM_ISR ();
} }
} }
</pre> </pre>
* *
@ -993,11 +999,11 @@ void vQueueDelete( xQueueHandle xQueue );
* queue. h * queue. h
* <pre> * <pre>
portBASE_TYPE xQueueGenericSendFromISR( portBASE_TYPE xQueueGenericSendFromISR(
xQueueHandle pxQueue, xQueueHandle pxQueue,
const void *pvItemToQueue, const void *pvItemToQueue,
portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE *pxHigherPriorityTaskWoken,
portBASE_TYPE xCopyPosition portBASE_TYPE xCopyPosition
); );
</pre> </pre>
* *
* It is preferred that the macros xQueueSendFromISR(), * It is preferred that the macros xQueueSendFromISR(),
@ -1039,26 +1045,26 @@ void vQueueDelete( xQueueHandle xQueue );
portCHAR cIn; portCHAR cIn;
portBASE_TYPE xHigherPriorityTaskWokenByPost; portBASE_TYPE xHigherPriorityTaskWokenByPost;
// We have not woken a task at the start of the ISR. // We have not woken a task at the start of the ISR.
xHigherPriorityTaskWokenByPost = pdFALSE; xHigherPriorityTaskWokenByPost = 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 each byte. // Post each byte.
xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK ); xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
} while( portINPUT_BYTE( BUFFER_COUNT ) ); } while( portINPUT_BYTE( BUFFER_COUNT ) );
// Now the buffer is empty we can switch context if necessary. Note that the // Now the buffer is empty we can switch context if necessary. Note that the
// name of the yield function required is port specific. // name of the yield function required is port specific.
if( xHigherPriorityTaskWokenByPost ) if( xHigherPriorityTaskWokenByPost )
{ {
taskYIELD_YIELD_FROM_ISR(); taskYIELD_YIELD_FROM_ISR();
} }
} }
</pre> </pre>
* *
@ -1071,10 +1077,10 @@ signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void
* 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
@ -1105,27 +1111,27 @@ signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void
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.
@ -1134,21 +1140,21 @@ signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const 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

Loading…
Cancel
Save