Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


PIC32 - Using a different Timer

Posted by Marcel van Lieshout on 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 :)

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?

RE: PIC32 - Using a different Timer

Posted by Richard on 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. */


RE: PIC32 - Using a different Timer

Posted by Marcel van Lieshout on June 17, 2013
Richard, thank you for your reply :)

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().

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner