From 6c677380905d7a398680a669fdd8f92d4c7afea6 Mon Sep 17 00:00:00 2001 From: richardbarry Date: Tue, 16 Oct 2012 09:48:45 +0000 Subject: [PATCH] Make the timer used for the PIC32 port layer user configurable. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1797 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- FreeRTOS/Source/portable/MPLAB/PIC32MX/port.c | 20 ++++++++++++++----- .../Source/portable/MPLAB/PIC32MX/port_asm.S | 8 ++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/FreeRTOS/Source/portable/MPLAB/PIC32MX/port.c b/FreeRTOS/Source/portable/MPLAB/PIC32MX/port.c index 7c22b4933..538c9bee8 100644 --- a/FreeRTOS/Source/portable/MPLAB/PIC32MX/port.c +++ b/FreeRTOS/Source/portable/MPLAB/PIC32MX/port.c @@ -83,6 +83,10 @@ the first task is being restored. */ #define portINITIAL_SR ( portIE_BIT | portEXL_BIT ) +#ifndef configTICK_INTERRUPT_VECTOR + #define configTICK_INTERRUPT_VECTOR _TIMER_1_VECTOR +#endif + /* Records the interrupt nesting depth. This starts at one as it will be decremented to 0 when the first task starts. */ volatile unsigned portBASE_TYPE uxInterruptNesting = 0x01; @@ -101,9 +105,9 @@ const portSTACK_TYPE * const xISRStackTop = &( xISRStack[ configISR_STACK_SIZE - * Place the prototype here to ensure the interrupt vector is correctly installed. * Note that because the interrupt is written in assembly, the IPL setting in the * following line of code has no effect. The interrupt priority is set by the - * call to ConfigIntTimer1() in prvSetupTimerInterrupt(). + * call to ConfigIntTimer1() in vApplicationSetupTickTimerInterrupt(). */ -extern void __attribute__( (interrupt(ipl1), vector(_TIMER_1_VECTOR))) vT1InterruptHandler( void ); +extern void __attribute__( (interrupt(ipl1), vector( configTICK_INTERRUPT_VECTOR ))) vPortTickInterruptHandler( void ); /* * The software interrupt handler that performs the yield. Note that, because @@ -152,9 +156,15 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE /*-----------------------------------------------------------*/ /* - * Setup a timer for a regular tick. + * Setup a timer for a regular tick. This function uses peripheral timer 1. + * The function is declared weak so an application writer can use a different + * timer by redefining this implementation. If a different timer is used then + * configTICK_INTERRUPT_VECTOR must also be defined in FreeRTOSConfig.h to + * ensure the RTOS provided tick interrupt handler is installed on the correct + * vector number. When Timer 1 is used the vector number is defined as + * _TIMER_1_VECTOR. */ -void prvSetupTimerInterrupt( void ) +__attribute__(( weak )) void vApplicationSetupTickTimerInterrupt( void ) { const unsigned long ulCompareMatch = ( (configPERIPHERAL_CLOCK_HZ / portTIMER_PRESCALE) / configTICK_RATE_HZ ) - 1; @@ -182,7 +192,7 @@ extern void *pxCurrentTCB; /* Setup the timer to generate the tick. Interrupts will have been disabled by the time we get here. */ - prvSetupTimerInterrupt(); + vApplicationSetupTickTimerInterrupt(); /* Kick off the highest priority task that has been created so far. Its stack location is loaded into uxSavedTaskStackPointer. */ diff --git a/FreeRTOS/Source/portable/MPLAB/PIC32MX/port_asm.S b/FreeRTOS/Source/portable/MPLAB/PIC32MX/port_asm.S index 8d4a4eab8..722a5c3bb 100644 --- a/FreeRTOS/Source/portable/MPLAB/PIC32MX/port_asm.S +++ b/FreeRTOS/Source/portable/MPLAB/PIC32MX/port_asm.S @@ -79,16 +79,16 @@ .global vPortStartFirstTask .global vPortYieldISR - .global vT1InterruptHandler + .global vPortTickInterruptHandler /******************************************************************/ .set noreorder .set noat - .ent vT1InterruptHandler + .ent vPortTickInterruptHandler -vT1InterruptHandler: +vPortTickInterruptHandler: portSAVE_CONTEXT @@ -97,7 +97,7 @@ vT1InterruptHandler: portRESTORE_CONTEXT - .end vT1InterruptHandler + .end vPortTickInterruptHandler /******************************************************************/ -- 2.39.5