# AVR32\_UC3's use of prvScheduleNextTick()

**URL:** <https://forums.freertos.org/t/avr32-uc3s-use-of-prvschedulenexttick/3468>\
**Category:** Kernel\
**Created:** [June 22, 2010, 10:09am UTC](https://forums.freertos.org/t/avr32-uc3s-use-of-prvschedulenexttick/3468 "2010-06-22T10:09:59Z")\
**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:** [June 22, 2010, 10:09am UTC](https://forums.freertos.org/t/avr32-uc3s-use-of-prvschedulenexttick/3468/1 "2010-06-22T10:09:59Z")

</div>

**[rgrover1](https://sourceforge.net/u/rgrover1/)** wrote on [Tuesday, June 22, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/97d08baa/#04c9):

Hello,

I’m working with AVR32\_UC3 and GCC. I’ve got a FreeRTOS port from Atmel at version 6.0.0; and it seems to work fine for a simple app which blinks LEDs.  
I want to upgrade to 6.0.5; but my led-blinker app fails.  
The problem is caused by the changes in port.c to the mechanism used to generate ticks.  
It has to do with prvScheduleNextTick(); which replaces the previous scheme implemented by prvClearCcInt().

I’ll include the code from the two:

```
	__attribute__ (( __noinline__ )) static void prvClearCcInt(void)
	{
		Set_system_register(AVR32_COMPARE, Get_system_register(AVR32_COMPARE));
	}

```

Vs.

```
	__attribute__ (( __noinline__ )) static void prvScheduleNextTick(void)
	{
		unsigned long lCycles, lCount;
		lCycles = Get_system_register(AVR32_COMPARE);
		lCycles += (configCPU_CLOCK_HZ/configTICK_RATE_HZ);
		// If lCycles ends up to be 0, make it 1 so that the COMPARE and exception
		// generation feature does not get disabled.
		if(0 == lCycles)
		{
			lCycles++;
		}
		lCount = Get_system_register(AVR32_COUNT);
		if( lCycles < lCount )
		{ // We missed a tick, recover for the next.
			lCycles += (configCPU_CLOCK_HZ/configTICK_RATE_HZ);
		}
		Set_system_register(AVR32_COMPARE, lCycles);
	}

```

Reverting port.c in 6.0.5 to use prvClearCcInt() makes everything work like normal.

On the surface, it seems that prvScheduleNextTick() certainly has a minor bug about not taking counter wrap-around into consideration-when the COMPARE register value wraps around due to the increment we might end up generating the next tick TWO ticks later. But I can’t figure out why my app completely fails to work with the new scheme.

Can someone please help? Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 22, 2010, 10:13am UTC](https://forums.freertos.org/t/avr32-uc3s-use-of-prvschedulenexttick/3468/2 "2010-06-22T10:13:57Z")

</div>

**[rgrover1](https://sourceforge.net/u/rgrover1/)** wrote on [Tuesday, June 22, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/97d08baa/#9b03):

And could someone please explain to me how the previous scheme worked (i.e. the one using prvClearCcInt). Does setting the COMPARE register to itself reset the COUNT register?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [June 22, 2010, 10:42am UTC](https://forums.freertos.org/t/avr32-uc3s-use-of-prvschedulenexttick/3468/3 "2010-06-22T10:42:21Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, June 22, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/97d08baa/#9661):

The files in the FreeRTOS download are designed for the original ES version of the AVR32, whereas the files in the AVR32 Atmel Software Framework (available from [atmel.com](http://atmel.com)) are designed for the latest AVR32 chips.&nbsp; The ES versions are now somewhat obsolete, and my advice is to use the files from Software Framework V1.7.0.&nbsp; The AVR32 files have not been updated between V6.0.0 and V6.0.5 so I don’t think you will have any problems there.

There is actually a new AVR32 port being created at the moment to add a bit of extra functionality, and the original files have actually been removed from the FreeRTOS SVN repository already.&nbsp; I can’t promise a completion date yet - but watch this space…

Regards.
