summaryrefslogtreecommitdiff
path: root/Source/portable/SDCC/PIC18/port.c
diff options
context:
space:
mode:
Diffstat (limited to 'Source/portable/SDCC/PIC18/port.c')
-rw-r--r--Source/portable/SDCC/PIC18/port.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/Source/portable/SDCC/PIC18/port.c b/Source/portable/SDCC/PIC18/port.c
index 86c52bad..7bdf0fef 100644
--- a/Source/portable/SDCC/PIC18/port.c
+++ b/Source/portable/SDCC/PIC18/port.c
@@ -83,9 +83,9 @@ static void prvSetupTimerInterrupt(void);
* When MR0ReloadValue=0 (65536 increments) configTICK_RATE_HZ=76Hz (with respect to values in FreeRTOSConfig.h)
* When MR0ReloadValue=65535 (1 increment) configTICK_RATE_HZ=5MHz (with respect to values in FreeRTOSConfig.h)
* This implies the bellow linear relation between configTICK_RATE_HZ and TMR0ReloadValue
- * , if we accept that 1 is negligible with respect to 65535.
+ * TMR0ReloadValue=65536 - configCPU_CLOCK_HZ/(portTIMER_FOSC_SCALE*configTICK_RATE_HZ)
*/
-portSHORT TMR0ReloadValue=(portSHORT)(65536.0 -(float)(portTIMER_FOSC_SCALE*65536.0*configTICK_RATE_HZ/configCPU_CLOCK_HZ)+65537.0);
+const unsigned portSHORT TMR0ReloadValue=(65536 - configCPU_CLOCK_HZ/(configTICK_RATE_HZ*portTIMER_FOSC_SCALE));
/*
@@ -202,7 +202,7 @@ portBASE_TYPE xPortStartScheduler(void)
/* Restore the context of the first task to run. */
portRESTORE_CONTEXT();
- /* Should not get here. Use the function name to stop compiler warnings. */
+ /* Should not get here. Use the function name to stop compiler warnings. */
( void ) prvLowInterrupt;
return pdTRUE;
@@ -254,7 +254,11 @@ void vPortYield(void) __naked
/* Interrupts must have been enabled for the ISR to fire, so we have to
save the context with interrupts enabled. */
portSAVE_CONTEXT(portGLOBAL_INTERRUPT_FLAG);
+
INTCONbits.TMR0IF=0;
+ /*set TMR0L and TMR0H vlaue*/
+ TMR0H=(unsigned portCHAR)((TMR0ReloadValue&(unsigned portSHORT)0xff00)>>8);
+ TMR0L=(unsigned portCHAR)(TMR0ReloadValue&(unsigned portSHORT)0x00ff);
/* Maintain the tick count. */
vTaskIncrementTick();
@@ -283,15 +287,13 @@ static void prvSetupTimerInterrupt(void)
INTCONbits.TMR0IF=0; /*Timer0 interrupt flag cleared*/
INTCON2bits.T0IP=0; /*TimerO has low priority interrupt*/
- /**/
- TMR0H=0x00; /*Initialize timer0 high byte register*/
- TMR0L=0x00; /*Initialize timer0 low byte register*/
-
+ /*set TMR0L and TMR0H vlaue*/
+ TMR0H=(unsigned portCHAR)((TMR0ReloadValue&(unsigned portSHORT)0xff00)>>8);
+ TMR0L=(unsigned portCHAR)(TMR0ReloadValue&(unsigned portSHORT)0x00ff);
RCONbits.IPEN=1; /* Interrupt priority feature enabled. FIXME: this is
* something like hardware interrupt controller configu-
* ration, so needs to be done somewhere else I think
*/
-
T0CONbits.TMR0ON=1; /*Now enable timer0*/
}