From ca62c72a1d0d450a7635bcb2906ffcda597a0a85 Mon Sep 17 00:00:00 2001 From: richardbarry Date: Sun, 24 Feb 2008 11:42:27 +0000 Subject: [PATCH] Add initial PPC405 files - this is a work in progress not a completed port. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@216 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- Source/portable/GCC/PPC405/port.c | 227 +++++++++++++++++++++++++ Source/portable/GCC/PPC405/portasm.s | 104 +++++++++++ Source/portable/GCC/PPC405/portmacro.h | 113 ++++++++++++ 3 files changed, 444 insertions(+) create mode 100644 Source/portable/GCC/PPC405/port.c create mode 100644 Source/portable/GCC/PPC405/portasm.s create mode 100644 Source/portable/GCC/PPC405/portmacro.h diff --git a/Source/portable/GCC/PPC405/port.c b/Source/portable/GCC/PPC405/port.c new file mode 100644 index 000000000..8801d7294 --- /dev/null +++ b/Source/portable/GCC/PPC405/port.c @@ -0,0 +1,227 @@ +/* + FreeRTOS.org V4.7.1 - Copyright (C) 2003-2008 Richard Barry. + + This file is part of the FreeRTOS.org distribution. + + FreeRTOS.org is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FreeRTOS.org is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FreeRTOS.org; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + A special exception to the GPL can be applied should you wish to distribute + a combined work that includes FreeRTOS.org, without being obliged to provide + the source code for any proprietary components. See the licensing section + of http://www.FreeRTOS.org for full details of how and when the exception + can be applied. + + *************************************************************************** + + Please ensure to read the configuration and relevant port sections of the + online documentation. + + +++ http://www.FreeRTOS.org +++ + Documentation, latest information, license and contact details. + + +++ http://www.SafeRTOS.com +++ + A version that is certified for use in safety critical systems. + + +++ http://www.OpenRTOS.com +++ + Commercial support, development, porting, licensing and training services. + + *************************************************************************** +*/ + +/*----------------------------------------------------------- + * Implementation of functions defined in portable.h for the MicroBlaze port. + *----------------------------------------------------------*/ + + +/* Scheduler includes. */ +#include "FreeRTOS.h" +#include "task.h" + +/* Library includes. */ +#include "xexception_l.h" +#include "xtime_l.h" + +/* Standard includes. */ +#include + +/*-----------------------------------------------------------*/ + +#define portCRITICAL_INTERRUPT_ENABLE ( 1UL << 14UL ) +#define portEXTERNAL_INTERRUPT_ENABLE ( 1UL << 16UL ) +#define portMACHINE_CHECK_ENABLE ( 1UL << 19UL ) +#define portINITIAL_MSR ( portCRITICAL_INTERRUPT_ENABLE | portEXTERNAL_INTERRUPT_ENABLE | portMACHINE_CHECK_ENABLE ) + +/* + */ +static void prvSetupTimerInterrupt( void ); +extern void vStartFirstTask( void ); +/*-----------------------------------------------------------*/ + +static void prvTickISR( void ); +extern void vPortYield( void ); + +/* + * Initialise the stack of a task to look exactly as if a call to + * portSAVE_CONTEXT had been made. + * + * See the header file portable.h. + */ +portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) +{ + /* Place a known value at the bottom of the stack for debugging. */ + *pxTopOfStack = 0xDEADBEEF; + *pxTopOfStack--; + + *pxTopOfStack = 0x10000001UL;; /* R0. */ + pxTopOfStack--; + /* SP. */ + *pxTopOfStack = 0x31313131UL; /* R31. */ + pxTopOfStack--; + *pxTopOfStack = 0x30303030UL; /* R30. */ + pxTopOfStack--; + *pxTopOfStack = 0x29292929UL; /* R29. */ + pxTopOfStack--; + *pxTopOfStack = 0x28282828UL; /* R28. */ + pxTopOfStack--; + *pxTopOfStack = 0x27272727UL; /* R27. */ + pxTopOfStack--; + *pxTopOfStack = 0x26262626UL; /* R26. */ + pxTopOfStack--; + *pxTopOfStack = 0x25252525UL; /* R25. */ + pxTopOfStack--; + *pxTopOfStack = 0x24242424UL; /* R24. */ + pxTopOfStack--; + *pxTopOfStack = 0x23232323UL; /* R23. */ + pxTopOfStack--; + *pxTopOfStack = 0x22222222UL; /* R22. */ + pxTopOfStack--; + *pxTopOfStack = 0x21212121UL; /* R21. */ + pxTopOfStack--; + *pxTopOfStack = 0x20202020UL; /* R20. */ + pxTopOfStack--; + *pxTopOfStack = 0x19191919UL; /* R19. */ + pxTopOfStack--; + *pxTopOfStack = 0x18181818UL; /* R18. */ + pxTopOfStack--; + *pxTopOfStack = 0x17171717UL; /* R17. */ + pxTopOfStack--; + *pxTopOfStack = 0x16161616UL; /* R16. */ + pxTopOfStack--; + *pxTopOfStack = 0x15151515UL; /* R15. */ + pxTopOfStack--; + *pxTopOfStack = 0x14141414UL; /* R14. */ + pxTopOfStack--; + *pxTopOfStack = 0x13131313UL; /* R13. */ + pxTopOfStack--; + *pxTopOfStack = 0x12121212UL; /* R12. */ + pxTopOfStack--; + *pxTopOfStack = 0x11111111UL; /* R11. */ + pxTopOfStack--; + *pxTopOfStack = 0x10101010UL; /* R10. */ + pxTopOfStack--; + *pxTopOfStack = 0x09090909UL; /* R9. */ + pxTopOfStack--; + *pxTopOfStack = 0x08080808UL; /* R8. */ + pxTopOfStack--; + *pxTopOfStack = 0x07070707UL; /* R7. */ + pxTopOfStack--; + *pxTopOfStack = 0x06060606UL; /* R6. */ + pxTopOfStack--; + *pxTopOfStack = 0x05050505UL; /* R5. */ + pxTopOfStack--; + *pxTopOfStack = 0x04040404UL; /* R4. */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) pvParameters; + pxTopOfStack--; + *pxTopOfStack = 0x02020202UL; /* R2. */ + pxTopOfStack--; + *pxTopOfStack = 0x00000000; /* CR. */ + pxTopOfStack--; + *pxTopOfStack = 0x00000000; /* XER. */ + pxTopOfStack--; + *pxTopOfStack = 0x00000000; /* LR. */ + pxTopOfStack--; + *pxTopOfStack = 0x00000000; /* CTR. */ + pxTopOfStack--; + *pxTopOfStack = 0x00000000; /* USPRG0. */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* SRR0. */ + pxTopOfStack--; + *pxTopOfStack = portINITIAL_MSR;/* SRR1. */ + pxTopOfStack--; + + return pxTopOfStack; +} +/*-----------------------------------------------------------*/ + +portBASE_TYPE xPortStartScheduler( void ) +{ +extern void *pxCurrentTCB; + + prvSetupTimerInterrupt(); + vStartFirstTask(); + + /* Should not get here as the tasks are now running! */ + return pdFALSE; +} +/*-----------------------------------------------------------*/ + +void vPortEndScheduler( void ) +{ + /* Not implemented. */ +} +/*-----------------------------------------------------------*/ + +/* + * Hardware initialisation to generate the RTOS tick. + */ +static void prvSetupTimerInterrupt( void ) +{ +const unsigned portLONG ulInterval = ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL ); + + XExc_Init(); + XExc_mDisableExceptions( XEXC_NON_CRITICAL ) ; + XExc_RegisterHandler( XEXC_ID_PIT_INT, ( XExceptionHandler ) prvTickISR, ( void * ) 0 ); + XExc_RegisterHandler( XEXC_ID_SYSTEM_CALL, ( XExceptionHandler ) vPortYield, ( void * ) 0 ); + + XTime_PITEnableAutoReload(); + XTime_PITEnableInterrupt(); + XTime_PITSetInterval( ulInterval ); + XTime_PITEnableInterrupt(); + + XExc_mEnableExceptions( XEXC_NON_CRITICAL ) ; +} +/*-----------------------------------------------------------*/ + +static void prvTickISR( void ) +{ +static unsigned portLONG ulTicks = 0; + + ulTicks++; + if( ulTicks >= 1000 ) + { + vParTestToggleLED( 0 ); + ulTicks = 0; + } + XTime_PITClearInterrupt(); + + #if configUSE_PREEMPTION == 1 + #endif +} +/*-----------------------------------------------------------*/ + + + + diff --git a/Source/portable/GCC/PPC405/portasm.s b/Source/portable/GCC/PPC405/portasm.s new file mode 100644 index 000000000..6849a8d98 --- /dev/null +++ b/Source/portable/GCC/PPC405/portasm.s @@ -0,0 +1,104 @@ + .extern pxCurrentTCB + .extern vTaskSwitchContext + + .global vStartFirstTask + .global vPortYield + +.set portCONTEXT_SIZE, 156 +.set portR0_OFFSET, 152 +.set portGPR_OFFSET, 32 +.set portCR_OFFSET, 28 +.set portXER_OFFSET, 24 +.set portLR_OFFSET, 20 +.set portCTR_OFFSET, 16 +.set portUSPRG0_OFFSET, 12 +.set portSRR0_OFFSET, 8 +.set portSRR1_OFFSET, 4 + +.macro portRESTORE_CONTEXT + + # Get the address of the TCB. + xor R0, R0, R0 + addis SP, R0, pxCurrentTCB@ha + lwz SP, pxCurrentTCB@l( SP ) + + # Get the task stack pointer from the TCB. + lwz SP, 0( SP ) + + # Pop the special purpose registers + lwz R0, portSRR1_OFFSET( SP ) + mtspr SRR1, R0 + lwz R0, portSRR0_OFFSET( SP ) + mtspr SRR0, R0 + lwz R0, portUSPRG0_OFFSET( SP ) + mtspr 256, R0 #USPRG0 + lwz R0, portCTR_OFFSET( SP ) + mtspr CTR, R0 + lwz R0, portLR_OFFSET( SP ) + mtspr LR, R0 + lwz R0, portXER_OFFSET( SP ) + mtspr XER, R0 + lwz R0, portCR_OFFSET( SP ) + mtcr R0 + + # Pop GPRs + lmw R2, portGPR_OFFSET( SP ) + + # Finally pop R0 and correct the stack pointer + lwz R0, portR0_OFFSET( SP ) + addi R1, R1, portCONTEXT_SIZE + + # Start the task running + rfi + + .endm + +.macro portSAVE_CONTEXT + + # Make room on the stack. + subi R1, R1, portCONTEXT_SIZE + + # Push R0, then the GPRs + stw R0, portR0_OFFSET( SP ) + stm R2, portGPR_OFFSET( SP ) + + # Push the SFRs + mfcr R0 + stw R0, portCR_OFFSET( SP ) + mfspr R0, XER + stw R0, portXER_OFFSET( SP ) + mfspr R0, LR + stw R0, portLR_OFFSET( SP ) + mfspr R0, CTR + stw R0, portCTR_OFFSET( SP ) + mfspr R0, 256 #USPRG0 + stw R0, portUSPRG0_OFFSET( SP ) + mfspr R0, SRR0 + stw R0, portSRR0_OFFSET( SP ) + mfspr R0, SRR1 + stw R0, portSRR1_OFFSET( SP ) + + # Get the address of the TCB. + xor R0, R0, R0 + addis R2, R0, pxCurrentTCB@ha + lwz R2, pxCurrentTCB@l( R2 ) + + # Store the stack pointer into the TCB + stw SP, 0( R2 ) + + .endm + +vStartFirstTask: + portRESTORE_CONTEXT + rfi + + + +vPortYield: + + portSAVE_CONTEXT + bl vTaskSwitchContext + portRESTORE_CONTEXT + + NOP + NOP diff --git a/Source/portable/GCC/PPC405/portmacro.h b/Source/portable/GCC/PPC405/portmacro.h new file mode 100644 index 000000000..478c1174e --- /dev/null +++ b/Source/portable/GCC/PPC405/portmacro.h @@ -0,0 +1,113 @@ +/* + FreeRTOS.org V4.7.1 - Copyright (C) 2003-2008 Richard Barry. + + This file is part of the FreeRTOS.org distribution. + + FreeRTOS.org is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FreeRTOS.org is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FreeRTOS.org; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + A special exception to the GPL can be applied should you wish to distribute + a combined work that includes FreeRTOS.org, without being obliged to provide + the source code for any proprietary components. See the licensing section + of http://www.FreeRTOS.org for full details of how and when the exception + can be applied. + + *************************************************************************** + + Please ensure to read the configuration and relevant port sections of the + online documentation. + + +++ http://www.FreeRTOS.org +++ + Documentation, latest information, license and contact details. + + +++ http://www.SafeRTOS.com +++ + A version that is certified for use in safety critical systems. + + +++ http://www.OpenRTOS.com +++ + Commercial support, development, porting, licensing and training services. + + *************************************************************************** +*/ + +#ifndef PORTMACRO_H +#define PORTMACRO_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*----------------------------------------------------------- + * Port specific definitions. + * + * The settings in this file configure FreeRTOS correctly for the + * given hardware and compiler. + * + * These settings should not be altered. + *----------------------------------------------------------- + */ + +/* Type definitions. */ +#define portCHAR char +#define portFLOAT float +#define portDOUBLE double +#define portLONG long +#define portSHORT short +#define portSTACK_TYPE unsigned portLONG +#define portBASE_TYPE portLONG + +#if( configUSE_16_BIT_TICKS == 1 ) + typedef unsigned portSHORT portTickType; + #define portMAX_DELAY ( portTickType ) 0xffff +#else + typedef unsigned portLONG portTickType; + #define portMAX_DELAY ( portTickType ) 0xffffffff +#endif +/*-----------------------------------------------------------*/ + +/* Interrupt control macros. */ +#define portDISABLE_INTERRUPTS() +#define portENABLE_INTERRUPTS() +/*-----------------------------------------------------------*/ + +/* Critical section macros. */ +void vPortEnterCritical( void ); +void vPortExitCritical( void ); +#define portENTER_CRITICAL() +#define portEXIT_CRITICAL() + +/*-----------------------------------------------------------*/ + +/* Task utilities. */ +void vPortYield( void ); +#define portYIELD() asm volatile ( "SC" ) +#define portYIELD_FROM_ISR() +/*-----------------------------------------------------------*/ + +/* Hardware specifics. */ +#define portBYTE_ALIGNMENT 8 +#define portSTACK_GROWTH ( -1 ) +#define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) +#define portNOP() asm volatile ( "NOP" ) +/*-----------------------------------------------------------*/ + +/* Task function macros as described on the FreeRTOS.org WEB site. */ +#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) +#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) + +#ifdef __cplusplus +} +#endif + +#endif /* PORTMACRO_H */ + -- 2.39.5