# \#define in FreeRTOS.h

**URL:** <https://forums.freertos.org/t/define-in-freertos-h/6428>\
**Category:** Kernel\
**Created:** [February 18, 2017, 2:50am UTC](https://forums.freertos.org/t/define-in-freertos-h/6428 "2017-02-18T02:50:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 18, 2017, 2:50am UTC](https://forums.freertos.org/t/define-in-freertos-h/6428/1 "2017-02-18T02:50:03Z")

</div>

**[eaoiyrioeaf](https://sourceforge.net/u/eaoiyrioeaf/)** wrote on [Saturday, February 18, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/e57fe885/#7a2c):

In the FreeRTOS.h file, there are lots of definition as shown in below:  
#ifndef traceTASK\_INCREMENT\_TICK  
#define traceTASK\_INCREMENT\_TICK( xTickCount )  
#endif

the statement “#define traceTASK\_INCREMENT\_TICK( xTickCount )” seems actually doing nothing, I’m not quite understand it. Could anyone kindly help?

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [February 18, 2017, 3:44am UTC](https://forums.freertos.org/t/define-in-freertos-h/6428/2 "2017-02-18T03:44:44Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Saturday, February 18, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/e57fe885/#6b88):

Look here in task.c :

```auto
BaseType_t xTaskIncrementTick( void )
{
TCB_t * pxTCB;
TickType_t xItemValue;
BaseType_t xSwitchRequired = pdFALSE;

	/* Called by the portable layer each time a tick interrupt occurs.
	Increments the tick then checks to see if the new tick value will cause any
	tasks to be unblocked. */
	traceTASK_INCREMENT_TICK( xTickCount );
	if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )
	...

```

For every tick increment, it calls a macro or a function called `traceTASK_INCREMENT_TICK()`.

**By default** , the macro does nothing:

```auto
#ifndef traceTASK_INCREMENT_TICK
	#define traceTASK_INCREMENT_TICK( xTickCount )
#endif

```

Now if you want to do something during every tick-increment, you can define the macro in a new way. Write that new definition in you `FreeRTOSConfig.h` file, so it will be included **before** `include/FreeRTOS.h`.

```auto
extern void vMyTickIncrement( TickType_t xCount );

#define traceTASK_INCREMENT_TICK( xTickCount ) \
	do \
	{ \
		vMyTickIncrement( xTickCount ); \
	} while( 0 )

```

When you run this, your function will be called for every increment.

So what you see in FreeRTOS is giving a proper default value for every macro.

Be careful: most trace-macro’s are being called from critical situations. The task scheduler is often temporarily disabled, interrupts might have been disabled. When a trace macro is called from the idle task, there are many things you’re not supposed to do, and the task-stack will be very small.

The good thing about trace macro’s: they avoid the necessity to change the FreeRTOS source code. Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 18, 2017, 6:25am UTC](https://forums.freertos.org/t/define-in-freertos-h/6428/3 "2017-02-18T06:25:23Z")

</div>

**[eaoiyrioeaf](https://sourceforge.net/u/eaoiyrioeaf/)** wrote on [Saturday, February 18, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/e57fe885/#6b88/dfa2):

That help me a lot, Thank you so much!
