Example #1
0
static void prvCheckForValidListAndQueue( void )
{
	/* Check that the list from which active timers are referenced, and the
	queue used to communicate with the timer service, have been
	initialised. */
	taskENTER_CRITICAL();
	{
		if( xTimerQueue == NULL )
		{
			vListInitialise( &xActiveTimerList1 );
			vListInitialise( &xActiveTimerList2 );
			pxCurrentTimerList = &xActiveTimerList1;
			pxOverflowTimerList = &xActiveTimerList2;

			#if( configSUPPORT_STATIC_ALLOCATION == 1 )
			{
				/* The timer queue is allocated statically in case
				configSUPPORT_DYNAMIC_ALLOCATION is 0. */
				static StaticQueue_t xStaticTimerQueue; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */
				static uint8_t ucStaticTimerQueueStorage[ ( size_t ) configTIMER_QUEUE_LENGTH * sizeof( DaemonTaskMessage_t ) ]; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */

				xTimerQueue = xQueueCreateStatic( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, ( UBaseType_t ) sizeof( DaemonTaskMessage_t ), &( ucStaticTimerQueueStorage[ 0 ] ), &xStaticTimerQueue );
			}
			#else
			{
				xTimerQueue = xQueueCreate( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, sizeof( DaemonTaskMessage_t ) );
			}
			#endif

			#if ( configQUEUE_REGISTRY_SIZE > 0 )
			{
				if( xTimerQueue != NULL )
				{
					vQueueAddToRegistry( xTimerQueue, "TmrQ" );
				}
				else
				{
					mtCOVERAGE_TEST_MARKER();
				}
			}
			#endif /* configQUEUE_REGISTRY_SIZE */
		}
		else
		{
			mtCOVERAGE_TEST_MARKER();
		}
	}
	taskEXIT_CRITICAL();
}
Example #2
0
void main_blinky( void )
{
	/* See http://www.FreeRTOS.org/TI_MSP432_Free_RTOS_Demo.html for 
	instructions and notes regarding the difference in power saving that can be 
	achieved between using the generic tickless RTOS implementation (as used by 
	the blinky demo) and a tickless RTOS implementation that is tailored 
	specifically to the MSP432. */

	/* The full demo configures the clocks for maximum frequency, wheras this
	blinky demo uses a slower clock as it also uses low power features. */
	prvConfigureClocks();
	CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);

	/* Create the queue. */
	xQueue = xQueueCreateStatic( mainQUEUE_LENGTH, sizeof(TransportMessages), xRxQueueBuf, &xRxQueueDef);

	if( xQueue != NULL )
	{
		/* Start the two tasks as described in the comments at the top of this
		file. */
		xTaskCreateStatic( prvQueueReceiveTask,					/* The function that implements the task. */
					"Rx", 									/* The text name assigned to the task - for debug only as it is not used by the kernel. */
					configMINIMAL_STACK_SIZE, 				/* The size of the stack to allocate to the task. */
					( void * ) mainQUEUE_RECEIVE_PARAMETER, /* The parameter passed to the task - just to check the functionality. */
					mainQUEUE_RECEIVE_TASK_PRIORITY, 		/* The priority assigned to the task. */
					NULL,									/* The task handle is not required, so NULL is passed. */
					xRxStack,
					&xRxTaskBuffer);

		xTaskCreateStatic( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, ( void * ) mainQUEUE_SEND_PARAMETER, mainQUEUE_SEND_TASK_PRIORITY, NULL,
						   xTxStack, &xTxTaskBuffer);

		/* Start the tasks and timer running. */
		vTaskStartScheduler();
	}

	/* If all is well, the scheduler will now be running, and the following
	line will never be reached.  If the following line does execute, then
	there was insufficient FreeRTOS heap memory available for the idle and/or
	timer tasks	to be created.  See the memory management section on the
	FreeRTOS web site for more details. */
	for( ;; );
}
Example #3
0
wifi_static_queue_t* wifi_create_queue( int queue_len, int item_size)
{
    wifi_static_queue_t *queue = NULL;

    queue = (wifi_static_queue_t*)heap_caps_malloc(sizeof(wifi_static_queue_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
    if (!queue) {
        return NULL;
    }

#if 0 /* TODO: CONFIG_SPIRAM_USE_MALLOC */

    queue->storage = heap_caps_calloc(1, sizeof(StaticQueue_t) + (queue_len*item_size), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
    if (!queue->storage) {
        goto _error;
    }

    queue->handle = xQueueCreateStatic( queue_len, item_size, ((uint8_t*)(queue->storage)) + sizeof(StaticQueue_t), (StaticQueue_t*)(queue->storage));

    if (!queue->handle) {
        goto _error;
    }

    return queue;

_error:
    if (queue) {
        if (queue->storage) {
            free(queue->storage);
        }

        free(queue);
    }

    return NULL;
#else
    queue->handle = xQueueCreate( queue_len, item_size);
    return queue;
#endif
}
static void prvCreateAndDeleteStaticallyAllocatedQueues( void )
{
QueueHandle_t xQueue;

/* StaticQueue_t is a publicly accessible structure that has the same size and
alignment requirements as the real queue structure.  It is provided as a
mechanism for applications to know the size of the queue (which is dependent on
the architecture and configuration file settings) without breaking the strict
data hiding policy by exposing the real queue internals.  This StaticQueue_t
variable is passed into the xQueueCreateStatic() function calls within this
function. */
static StaticQueue_t xStaticQueue;

/* The queue storage area must be large enough to hold the maximum number of
items it is possible for the queue to hold at any one time, which equals the
queue length (in items, not bytes) multiplied by the size of each item.  In this
case the queue will hold staticQUEUE_LENGTH_IN_ITEMS 64-bit items.  See
http://www.freertos.org/Embedded-RTOS-Queues.html */
static uint8_t ucQueueStorageArea[ staticQUEUE_LENGTH_IN_ITEMS * sizeof( uint64_t ) ];

	/* Create the queue.  xQueueCreateStatic() has two more parameters than the
	usual xQueueCreate() function.  The first new parameter is a pointer to the
	pre-allocated queue storage area.  The second new parameter is a pointer to
	the StaticQueue_t structure that will hold the queue state information in
	an anonymous way.  If the two pointers are passed as NULL then the data
	will be allocated dynamically as if xQueueCreate() had been called. */
	xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */
								 sizeof( uint64_t ), /* The size of each item. */
								 ucQueueStorageArea, /* The buffer used to hold items within the queue. */
								 &xStaticQueue );	 /* The static queue structure that will hold the state of the queue. */

	/* The queue handle should equal the static queue structure passed into the
	xQueueCreateStatic() function. */
	configASSERT( xQueue == ( QueueHandle_t ) &xStaticQueue );

	/* Ensure the queue passes a few sanity checks as a valid queue. */
	prvSanityCheckCreatedQueue( xQueue );

	/* Delete the queue again so the buffers can be reused. */
	vQueueDelete( xQueue );

	/* Now do the same using a dynamically allocated queue to ensure the delete
	function is working correctly in both the static and dynamic memory
	allocation cases. */
	#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
	{
		xQueue = xQueueCreate( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */
							   sizeof( uint64_t ) ); 		/* The size of each item. */

		/* The queue handle should equal the static queue structure passed into the
		xQueueCreateStatic() function. */
		configASSERT( xQueue != NULL );

		/* Ensure the queue passes a few sanity checks as a valid queue. */
		prvSanityCheckCreatedQueue( xQueue );

		/* Delete the queue again so the buffers can be reused. */
		vQueueDelete( xQueue );
	}
	#endif
}
Example #5
0
static void prvCreateAndDeleteStaticallyAllocatedQueues( void )
{
QueueHandle_t xQueue;

/* StaticQueue_t is a publicly accessible structure that has the same size and
alignment requirements as the real queue structure.  It is provided as a
mechanism for applications to know the size of the queue (which is dependent on
the architecture and configuration file settings) without breaking the strict
data hiding policy by exposing the real queue internals.  This StaticQueue_t
variable is passed into the xQueueCreateStatic() function calls within this
function. */
static StaticQueue_t xStaticQueue;

/* The queue storage area must be large enough to hold the maximum number of
items it is possible for the queue to hold at any one time, which equals the
queue length (in items, not bytes) multiplied by the size of each item.  In this
case the queue will hold staticQUEUE_LENGTH_IN_ITEMS 64-bit items.  See
http://www.freertos.org/Embedded-RTOS-Queues.html */
static uint8_t ucQueueStorageArea[ staticQUEUE_LENGTH_IN_ITEMS * sizeof( uint64_t ) ];

	/* Create the queue.  xQueueCreateStatic() has two more parameters than the
	usual xQueueCreate() function.  The first new paraemter is a pointer to the
	pre-allocated queue storage area.  The second new parameter is a pointer to
	the StaticQueue_t structure that will hold the queue state information in
	an anonymous way.  If either pointer is passed as NULL then the respective
	data will be allocated dynamically as if xQueueCreate() had been called. */
	xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */
								 sizeof( uint64_t ), /* The size of each item. */
								 ucQueueStorageArea, /* The buffer used to hold items within the queue. */
								 &xStaticQueue );	 /* The static queue structure that will hold the state of the queue. */

	/* The queue handle should equal the static queue structure passed into the
	xQueueCreateStatic() function. */
	configASSERT( xQueue == ( QueueHandle_t ) &xStaticQueue );

	/* Ensure the queue passes a few sanity checks as a valid queue. */
	prvSanityCheckCreatedQueue( xQueue );

	/* Delete the queue again so the buffers can be reused. */
	vQueueDelete( xQueue );


	/* The queue created above had a statically allocated queue storage area and
	queue structure.  Repeat the above with three more times - with different
	combinations of static and dynamic allocation. */

	xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */
								 sizeof( uint64_t ), /* The size of each item. */
								 NULL,				 /* Allocate the buffer used to hold items within the queue dynamically. */
								 &xStaticQueue );	 /* The static queue structure that will hold the state of the queue. */

	configASSERT( xQueue == ( QueueHandle_t ) &xStaticQueue );
	prvSanityCheckCreatedQueue( xQueue );
	vQueueDelete( xQueue );

	/* Ensure lower priority tasks get CPU time. */
	vTaskDelay( prvGetNextDelayTime() );

	/* Just to show the check task that this task is still executing. */
	uxCycleCounter++;

	xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */
								 sizeof( uint64_t ), /* The size of each item. */
								 ucQueueStorageArea, /* The buffer used to hold items within the queue. */
								 NULL );			 /* The queue structure is allocated dynamically. */

	prvSanityCheckCreatedQueue( xQueue );
	vQueueDelete( xQueue );

	xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */
								 sizeof( uint64_t ), /* The size of each item. */
								 NULL,				 /* Allocate the buffer used to hold items within the queue dynamically. */
								 NULL );			 /* The queue structure is allocated dynamically. */

	prvSanityCheckCreatedQueue( xQueue );
	vQueueDelete( xQueue );

	/* Ensure lower priority tasks get CPU time. */
	vTaskDelay( prvGetNextDelayTime() );

	/* Just to show the check task that this task is still executing. */
	uxCycleCounter++;
}
Example #6
0
static void prvTestAbortingQueueSend( void )
{
TickType_t xTimeAtStart;
BaseType_t xReturn;
const UBaseType_t xQueueLength = ( UBaseType_t ) 1;
QueueHandle_t xQueue;
uint8_t ucItemToQueue;

	#if( configSUPPORT_STATIC_ALLOCATION == 1 )
	{
		static StaticQueue_t xQueueBuffer;
		static uint8_t ucQueueStorage[ sizeof( uint8_t ) ];

		/* Create the queue.  Statically allocated memory is used so the
		creation cannot fail. */
		xQueue = xQueueCreateStatic( xQueueLength, sizeof( uint8_t ), ucQueueStorage, &xQueueBuffer );
	}
	#else
	{
		xQueue = xQueueCreate( xQueueLength, sizeof( uint8_t ) );
		configASSERT( xQueue );
	}
	#endif

	/* This function tests aborting when in the blocked state waiting to send,
	so the queue must be full.  There is only one space in the queue. */
	xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
	if( xReturn != pdPASS )
	{
		xErrorOccurred = pdTRUE;
	}

	/* Note the time before the delay so the length of the delay is known. */
	xTimeAtStart = xTaskGetTickCount();

	/* This first delay should just time out. */
	xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
	if( xReturn != pdFALSE )
	{
		xErrorOccurred = pdTRUE;
	}
	prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );

	/* Note the time before the delay so the length of the delay is known. */
	xTimeAtStart = xTaskGetTickCount();

	/* This second delay should be aborted by the primary task half way
	through. */
	xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
	if( xReturn != pdFALSE )
	{
		xErrorOccurred = pdTRUE;
	}
	prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );

	/* Note the time before the delay so the length of the delay is known. */
	xTimeAtStart = xTaskGetTickCount();

	/* This third delay should just time out again. */
	xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
	if( xReturn != pdFALSE )
	{
		xErrorOccurred = pdTRUE;
	}
	prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );

	/* Not really necessary in this case, but for completeness. */
	vQueueDelete( xQueue );
}