Update the MSVC simulator demo to demonstrate heap_5 allocator and pdTICKS_TO_MS macro being used.

pull/1/head
Richard Barry 11 years ago
parent d96dc2adb0
commit 4fe2abc792

@ -83,7 +83,7 @@
#define configUSE_TICK_HOOK 1 #define configUSE_TICK_HOOK 1
#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */ #define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 50 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */ #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 50 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 20 * 1024 ) ) #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 21 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 ) #define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 1 #define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0 #define configUSE_16_BIT_TICKS 0

@ -132,7 +132,7 @@
<ClCompile Include="..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-Trace\trcUser.c" /> <ClCompile Include="..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-Trace\trcUser.c" />
<ClCompile Include="..\..\Source\croutine.c" /> <ClCompile Include="..\..\Source\croutine.c" />
<ClCompile Include="..\..\Source\event_groups.c" /> <ClCompile Include="..\..\Source\event_groups.c" />
<ClCompile Include="..\..\Source\portable\MemMang\heap_4.c" /> <ClCompile Include="..\..\Source\portable\MemMang\heap_5.c" />
<ClCompile Include="..\..\Source\timers.c" /> <ClCompile Include="..\..\Source\timers.c" />
<ClCompile Include="..\Common\Minimal\BlockQ.c" /> <ClCompile Include="..\Common\Minimal\BlockQ.c" />
<ClCompile Include="..\Common\Minimal\blocktim.c" /> <ClCompile Include="..\Common\Minimal\blocktim.c" />

@ -100,9 +100,6 @@
<ClCompile Include="Run-time-stats-utils.c"> <ClCompile Include="Run-time-stats-utils.c">
<Filter>Demo App Source</Filter> <Filter>Demo App Source</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\Source\portable\MemMang\heap_4.c">
<Filter>FreeRTOS Source\Source\Portable</Filter>
</ClCompile>
<ClCompile Include="..\..\Source\croutine.c"> <ClCompile Include="..\..\Source\croutine.c">
<Filter>FreeRTOS Source\Source</Filter> <Filter>FreeRTOS Source\Source</Filter>
</ClCompile> </ClCompile>
@ -136,6 +133,9 @@
<ClCompile Include="..\..\Source\event_groups.c"> <ClCompile Include="..\..\Source\event_groups.c">
<Filter>FreeRTOS Source\Source</Filter> <Filter>FreeRTOS Source\Source</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\Source\portable\MemMang\heap_5.c">
<Filter>FreeRTOS Source\Source\Portable</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="FreeRTOSConfig.h"> <ClInclude Include="FreeRTOSConfig.h">
@ -171,9 +171,6 @@
<ClInclude Include="..\..\Source\include\timers.h"> <ClInclude Include="..\..\Source\include\timers.h">
<Filter>FreeRTOS Source\Include</Filter> <Filter>FreeRTOS Source\Include</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Trace_Recorder_Configuration\trcHardwarePort.h">
<Filter>Configuration Files</Filter>
</ClInclude>
<ClInclude Include="Trace_Recorder_Configuration\trcConfig.h"> <ClInclude Include="Trace_Recorder_Configuration\trcConfig.h">
<Filter>Configuration Files</Filter> <Filter>Configuration Files</Filter>
</ClInclude> </ClInclude>

@ -107,6 +107,15 @@ comprehensive test and demo application is implemented and described in
main_full.c. */ main_full.c. */
#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
/* This demo uses heap_5.c, and these constants define the sizes of the regions
that make up the total heap. This is only done to provide an example of heap_5
being used as this demo could easily create one large heap region instead of
multiple smaller heap regions - in which case heap_4.c would be the more
appropriate choice. */
#define mainREGION_1_SIZE 2001
#define mainREGION_2_SIZE 18005
#define mainREGION_3_SIZE 1007
/* /*
* main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1. * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
* main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0. * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
@ -114,15 +123,28 @@ main_full.c. */
extern void main_blinky( void ); extern void main_blinky( void );
extern void main_full( void ); extern void main_full( void );
/* Some of the RTOS hook (callback) functions only need special processing when /*
the full demo is being used. The simply blinky demo has no special requirements, * Some of the RTOS hook (callback) functions only need special processing when
so these functions are called from the hook functions defined in this file, but * the full demo is being used. The simply blinky demo has no special
are defined in main_full.c. */ * requirements, so these functions are called from the hook functions defined
* in this file, but are defined in main_full.c.
*/
void vFullDemoTickHookFunction( void ); void vFullDemoTickHookFunction( void );
void vFullDemoIdleFunction( void ); void vFullDemoIdleFunction( void );
/* Prototypes for the standard FreeRTOS callback/hook functions implemented /*
within this file. */ * This demo uses heap_5.c, so start by defining some heap regions. This is
* only done to provide an example as this demo could easily create one large
* heap region instead of multiple smaller heap regions - in which case heap_4.c
* would be the more appropriate choice. No initialisation is required when
* heap_4.c is used.
*/
static void prvInitialiseHeap( void );
/*
* Prototypes for the standard FreeRTOS callback/hook functions implemented
* within this file.
*/
void vApplicationMallocFailedHook( void ); void vApplicationMallocFailedHook( void );
void vApplicationIdleHook( void ); void vApplicationIdleHook( void );
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName ); void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
@ -145,6 +167,13 @@ static portBASE_TYPE xTraceRunning = pdTRUE;
int main( void ) int main( void )
{ {
/* This demo uses heap_5.c, so start by defining some heap regions. This
is only done to provide an example as this demo could easily create one
large heap region instead of multiple smaller heap regions - in which case
heap_4.c would be the more appropriate choice. No initialisation is
required when heap_4.c is used. */
prvInitialiseHeap();
/* Initialise the trace recorder and create the label used to post user /* Initialise the trace recorder and create the label used to post user
events to the trace recording on each tick interrupt. */ events to the trace recording on each tick interrupt. */
vTraceInitTraceData(); vTraceInitTraceData();
@ -311,3 +340,33 @@ FILE* pxOutputFile;
printf( "\r\nFailed to create trace dump file\r\n" ); printf( "\r\nFailed to create trace dump file\r\n" );
} }
} }
/*-----------------------------------------------------------*/
static void prvInitialiseHeap( void )
{
/* This demo uses heap_5.c, so start by defining some heap regions. This is
only done to provide an example as this demo could easily create one large heap
region instead of multiple smaller heap regions - in which case heap_4.c would
be the more appropriate choice. No initialisation is required when heap_4.c is
used. The xHeapRegions structure requires the regions to be defined in order,
so this just creates one big array, then populates the structure with offsets
into the array - with gaps in between and messy alignment just for test
purposes. */
static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
volatile uint32_t ulAdditionalOffset = 19; /* Just to prevent 'condition is always true' warnings in configASSERT(). */
const HeapRegion_t xHeapRegions[] =
{
/* Start address with dummy offsets Size */
{ ucHeap + 1, mainREGION_1_SIZE },
{ ucHeap + 15 + mainREGION_1_SIZE, mainREGION_2_SIZE },
{ ucHeap + 19 + mainREGION_1_SIZE + mainREGION_2_SIZE, mainREGION_3_SIZE },
{ NULL, 0 }
};
/* Sanity check that the sizes and offsets defined actually fit into the
array. */
configASSERT( ( ulAdditionalOffset + mainREGION_1_SIZE + mainREGION_2_SIZE + mainREGION_3_SIZE ) < configTOTAL_HEAP_SIZE );
vPortDefineHeapRegions( xHeapRegions );
}

@ -128,7 +128,7 @@
/* The rate at which data is sent to the queue. The 200ms value is converted /* The rate at which data is sent to the queue. The 200ms value is converted
to ticks using the portTICK_PERIOD_MS constant. */ to ticks using the portTICK_PERIOD_MS constant. */
#define mainQUEUE_SEND_FREQUENCY_MS ( 200 / portTICK_PERIOD_MS ) #define mainQUEUE_SEND_FREQUENCY_MS ( 200 )
/* The number of items the queue can hold. This is 1 as the receive task /* The number of items the queue can hold. This is 1 as the receive task
will remove items as they are added, meaning the send task should always find will remove items as they are added, meaning the send task should always find
@ -190,6 +190,7 @@ static void prvQueueSendTask( void *pvParameters )
{ {
TickType_t xNextWakeTime; TickType_t xNextWakeTime;
const unsigned long ulValueToSend = 100UL; const unsigned long ulValueToSend = 100UL;
const TickType_t xBlockTime = pdMS_TO_TICKS( mainQUEUE_SEND_FREQUENCY_MS );
/* Remove compiler warning in the case that configASSERT() is not /* Remove compiler warning in the case that configASSERT() is not
defined. */ defined. */
@ -207,7 +208,7 @@ const unsigned long ulValueToSend = 100UL;
The block time is specified in ticks, the constant used converts ticks The block time is specified in ticks, the constant used converts ticks
to ms. While in the Blocked state this task will not consume any CPU to ms. While in the Blocked state this task will not consume any CPU
time. */ time. */
vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS ); vTaskDelayUntil( &xNextWakeTime, xBlockTime );
/* Send to the queue - causing the queue receive task to unblock and /* Send to the queue - causing the queue receive task to unblock and
toggle the LED. 0 is used as the block time so the sending operation toggle the LED. 0 is used as the block time so the sending operation

Loading…
Cancel
Save