From 693e891448b0ab4e2672aeba12b4425c32094ba1 Mon Sep 17 00:00:00 2001 From: Abdoulaye Walsimou Gaye Date: Sun, 19 Apr 2009 19:49:45 +0200 Subject: PIC18_SDCC: fix task stack corruption This patch: * Reduce copyright characters * fix task stack corruption Signed-off-by: Abdoulaye Walsimou Gaye --- Source/portable/SDCC/PIC18/port.c | 44 +++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/Source/portable/SDCC/PIC18/port.c b/Source/portable/SDCC/PIC18/port.c index 27914e90..332e68a9 100644 --- a/Source/portable/SDCC/PIC18/port.c +++ b/Source/portable/SDCC/PIC18/port.c @@ -1,7 +1,7 @@ /** * ####################################################################################### * GAYE Abdoulaye Walsimou, -* Copyright(C) 2009 GAYE Abdoulaye Walsimou, . All rights reserved. +* Copyright (C) 2009 GAYE Abdoulaye Walsimou. All rights reserved. * * This program is free software; you can distribute it and/or modify it * under the terms of the GNU General Public License @@ -85,7 +85,6 @@ const static unsigned portSHORT TMR0ReloadValue=(65536 - configCPU_CLOCK_HZ/(con */ void prvLowInterrupt(void) __naked __interrupt 2; - /*-----------------------------------------------------------*/ /* * See header file for description. @@ -94,17 +93,25 @@ portSTACK_TYPE *pxPortInitialiseStack(portSTACK_TYPE *pxTopOfStack, pdTASK_CODE { unsigned portLONG ulAddress; unsigned portCHAR ucBlock; + portSTACK_TYPE pvParameters_Upper; + portSTACK_TYPE pvParameters_High; + portSTACK_TYPE pvParameters_Low; /*First store the function parameters. This is where the task will expect to find them when it starts running. */ + ulAddress = (unsigned portLONG) pvParameters; - *pxTopOfStack = (portSTACK_TYPE) (ulAddress & (unsigned portLONG)0x00ff); - pxTopOfStack--; + pvParameters_Low = (portSTACK_TYPE)(ulAddress & (unsigned portLONG)0x00ff); ulAddress >>= 8; - *pxTopOfStack = (portSTACK_TYPE) (ulAddress & (unsigned portLONG)0x00ff); - pxTopOfStack--; + pvParameters_High = (portSTACK_TYPE)(ulAddress & (unsigned portLONG)0x00ff); ulAddress >>= 8; - *pxTopOfStack = (portSTACK_TYPE) (ulAddress & (unsigned portLONG)0x00ff); + pvParameters_Upper = (portSTACK_TYPE)(ulAddress & (unsigned portLONG)0x00ff); + + *pxTopOfStack = pvParameters_Upper; + pxTopOfStack--; + *pxTopOfStack = pvParameters_High; + pxTopOfStack--; + *pxTopOfStack = pvParameters_Low; pxTopOfStack--; /*Now we save hardware and compiler registers*/ @@ -154,14 +161,15 @@ portSTACK_TYPE *pxPortInitialiseStack(portSTACK_TYPE *pxTopOfStack, pdTASK_CODE *pxTopOfStack = (portSTACK_TYPE)0xee; /* TBLPTRU. */ pxTopOfStack--; + /* Next the .registers sections. Assuming that it is portCOMPILER_MANAGED_MEMORY_SIZE*/ - for( ucBlock = 0; ucBlock >8); TMR0L=(unsigned portCHAR)(TMR0ReloadValue&(unsigned portSHORT)0x00ff); @@ -272,22 +280,22 @@ void vPortYield(void) __naked */ static void prvSetupTimerInterrupt(void) { - T0CONbits.TMR0ON=0; /*Timer0 off at the begining*/ - T0CONbits.T08BIT=0; /*Timer0 as 16 bits timer*/ - T0CONbits.T0CS=0; /*Timer0 works in timer mode*/ - T0CONbits.T0SE=0; /*Timer0 will increment positive transition*/ - T0CONbits.PSA=1; /*Timer0 prescaler is not assigned*/ + T0CONbits.TMR0ON=0; /*Timer0 off at the begining*/ + T0CONbits.T08BIT=0; /*Timer0 as 16 bits timer*/ + T0CONbits.T0CS=0; /*Timer0 works in timer mode*/ + T0CONbits.T0SE=0; /*Timer0 will increment positive transition*/ + T0CONbits.PSA=1; /*Timer0 prescaler is not assigned*/ INTCONbits.TMR0IE=1; /*Timer0 interrupts are allowed*/ INTCONbits.TMR0IF=0; /*Timer0 interrupt flag cleared*/ /*set TMR0L and TMR0H value*/ - TMR0H=(unsigned portCHAR)((TMR0ReloadValue&(unsigned portSHORT)0xff00)>>8); - TMR0L=(unsigned portCHAR)(TMR0ReloadValue&(unsigned portSHORT)0x00ff); + 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*/ + T0CONbits.TMR0ON=1; /*Now enable timer0*/ } void *pvPortMalloc(size_t xSize) -- cgit v1.2.3