Skip to content

Commit

Permalink
Fix: Build enable trace facility (FreeRTOS#890)
Browse files Browse the repository at this point in the history
* Fix IAR GCC build for Qemu MPS2

* Add removed file

* Add timer function for runtime stats

* Add lexicon entry
  • Loading branch information
alfred2g authored Dec 6, 2022
1 parent e85b49a commit 101c263
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/core-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ jobs:
- name: Qemu MPS2 MPU build Cortex M3
run: cd workspace/FreeRTOS/Demo/CORTEX_MPU_M3_MPS2_QEMU_GCC && make
- name: Qemu MPS2 IAR build Cortex M3
run: cd workspace/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC/build/gcc && sed -i '/configUSE_STATS_FORMATTING_FUNCTIONS/c\#define configUSE_STATS_FORMATTING_FUNCTIONS 0' ../../FreeRTOSConfig.h && make
run: cd workspace/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC/build/gcc && make
10 changes: 9 additions & 1 deletion FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
* See http://www.freertos.org/a00110.html
*----------------------------------------------------------*/

#define configUSE_TRACE_FACILITY 1
#define configGENERATE_RUN_TIME_STATS 1

void vConfigureTimerForRunTimeStats( void );
unsigned long ulGetRunTimeCounterValue( void );

#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats( )
#define portGET_RUN_TIME_COUNTER_VALUE() ulGetRunTimeCounterValue()

#define configUSE_TICKLESS_IDLE 0
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
Expand All @@ -48,7 +57,6 @@
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 80 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 60 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 0
#define configUSE_MUTEXES 1
Expand Down
38 changes: 38 additions & 0 deletions FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#include "FreeRTOS.h"
#include "task.h"

#include "CMSDK_CM3.h"

/* Standard includes. */
#include <stdio.h>
#include <string.h>
Expand All @@ -75,6 +77,11 @@ required UART registers. */
#define UART0_BAUDDIV ( * ( ( ( volatile uint32_t * )( UART0_ADDRESS + 16UL ) ) ) )
#define TX_BUFFER_MASK ( 1UL )

#define TIMER_POSTSCALER ( 8UL )

/* Time at start of day (in ns). */
static volatile unsigned long ulRunTimeOverflowCount = 0U;

/*
* 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.
Expand Down Expand Up @@ -307,6 +314,37 @@ void *malloc( size_t size )
for( ;; );

}
/*-----------------------------------------------------------*/

void vConfigureTimerForRunTimeStats( void )
{
/* PCLK / SystemCoreClock is 25MHz, Timer clock is always PCLK */

CMSDK_TIMER0->CTRL &= ~( CMSDK_TIMER_CTRL_EN_Msk );

CMSDK_TIMER0->RELOAD = 0xFFFFFFFF;

/* Enable overflow interrupt and start the timer */
CMSDK_TIMER0->CTRL |= CMSDK_TIMER_CTRL_IRQEN_Msk;
CMSDK_TIMER0->CTRL |= CMSDK_TIMER_CTRL_EN_Msk;

}
/*-----------------------------------------------------------*/

unsigned long ulGetRunTimeCounterValue( void )
{
unsigned long ulTimerValue = CMSDK_TIMER0->RELOAD - CMSDK_TIMER0->VALUE;

/*
* 32 bits will overflow after ~ ( 2**32 / 25000000 ) == 171 seconds,
* So we remove the lower 8 bits and borrow 8 bits from the overflow counter.
*/

ulTimerValue = ( ulTimerValue >> TIMER_POSTSCALER );

/* Add remaining 8 bits from ulRunTimeOverflowCount */
ulTimerValue |= ( ulRunTimeOverflowCount << ( 32UL - TIMER_POSTSCALER ) );

return ulTimerValue;
}

1 change: 1 addition & 0 deletions lexicon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2923,6 +2923,7 @@ ulreportid
ulrestartoffset
ulreturned
ulrlar
ulruntimeoverflowcount
ulsecondnotificationvalueconst
ulsecondnotifiedconst
ulsecondnotifiedvalueconst
Expand Down

0 comments on commit 101c263

Please sign in to comment.