PIC32 - Using a different Timer

hermarcel wrote on Sunday, June 16, 2013:


While working on (loosely) integrating Microchip’s TCP/IP and USB stacks into my FreeRTOS application, I want FreeRTOS to use a different Timer (The default Timer1 is used by Microchip stacks).

The port.c conveniently has vApplicationSetupTickTimerInterrupt() declared as “weak”, allowing me to define this function, setting up a different timer, elsewhere. There also is a configuration definition for the interrupt vector (configTICK_INTERRUPT_VECTOR). This is all quite nice :slight_smile:

The last line in function vPortIncrementTick() in port.c, clears the interruptflag in the following way:

/* Clear timer 1 interrupt. */

So, I still need to modify port.c to change timers. Not a big deal at first glance, but it means I am changing a core FreeRTOS file and that implicates there are license consequences.

What can I do?

rtel wrote on Sunday, June 16, 2013:

Just changing the line that clears the interrupt flag is not a problem and so no licensing issue to worry about as far as I’m concerned because you are not modifying or enhancing the behaviour of the kernel.

What is more of an issue is that the implementation was intended to be such that you would not need to do that.  It looks like a bit of an omission from the port layers implementation, and maybe the line that clears the interrupt source also needs to be user definable.

The other alternative would be to implement your own “increment tick” function the the application - basically just a copy of the one from the port layer.  As you have your own handler you can have the handler call your own increment tick function too.

Note that the next version of FreeRTOS will change the increment tick function somewhat as follows:

void vPortIncrementTick( void )
unsigned portBASE_TYPE uxSavedStatus;
	uxSavedStatus = uxPortSetInterruptMaskFromISR();
		if( xTaskIncrementTick() != pdFALSE )
			/* Pend a context switch. */
			_CP0_BIS_CAUSE( portCORE_SW_0 );
	vPortClearInterruptMaskFromISR( uxSavedStatus );
	/* Clear timer 1 interrupt. */


hermarcel wrote on Monday, June 17, 2013:

Richard, thank you for your reply :slight_smile:

Making the “clear interrupt flag” user definable appeals to me the most. It continues to build upon the already present definable timer parameters. And, even more important for me, updating the kernel to a newer release is not obscured by having to maintain an almost duplicate version of vPortIncrementTick().