]> git.sur5r.net Git - freertos/commitdiff
Add MSP430X CCS4 port layer.
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sat, 1 Jan 2011 17:23:00 +0000 (17:23 +0000)
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sat, 1 Jan 2011 17:23:00 +0000 (17:23 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1204 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

Source/portable/CCS4/MSP430X/port.c [new file with mode: 0644]
Source/portable/CCS4/MSP430X/portext.asm [new file with mode: 0644]
Source/portable/CCS4/MSP430X/portmacro.h [new file with mode: 0644]

diff --git a/Source/portable/CCS4/MSP430X/port.c b/Source/portable/CCS4/MSP430X/port.c
new file mode 100644 (file)
index 0000000..fa5e930
--- /dev/null
@@ -0,0 +1,188 @@
+/*\r
+    FreeRTOS V6.1.0 - Copyright (C) 2010 Real Time Engineers Ltd.\r
+\r
+    ***************************************************************************\r
+    *                                                                         *\r
+    * If you are:                                                             *\r
+    *                                                                         *\r
+    *    + New to FreeRTOS,                                                   *\r
+    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
+    *    + Looking for basic training,                                        *\r
+    *    + Wanting to improve your FreeRTOS skills and productivity           *\r
+    *                                                                         *\r
+    * then take a look at the FreeRTOS books - available as PDF or paperback  *\r
+    *                                                                         *\r
+    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
+    *                  http://www.FreeRTOS.org/Documentation                  *\r
+    *                                                                         *\r
+    * A pdf reference manual is also available.  Both are usually delivered   *\r
+    * to your inbox within 20 minutes to two hours when purchased between 8am *\r
+    * and 8pm GMT (although please allow up to 24 hours in case of            *\r
+    * exceptional circumstances).  Thank you for your support!                *\r
+    *                                                                         *\r
+    ***************************************************************************\r
+\r
+    This file is part of the FreeRTOS distribution.\r
+\r
+    FreeRTOS is free software; you can redistribute it and/or modify it under\r
+    the terms of the GNU General Public License (version 2) as published by the\r
+    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+    ***NOTE*** The exception to the GPL is included to allow you to distribute\r
+    a combined work that includes FreeRTOS without being obliged to provide the\r
+    source code for proprietary components outside of the FreeRTOS kernel.\r
+    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
+    more details. You should have received a copy of the GNU General Public\r
+    License and the FreeRTOS license exception along with FreeRTOS; if not it\r
+    can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
+    by writing to Richard Barry, contact details for whom are available on the\r
+    FreeRTOS WEB site.\r
+\r
+    1 tab == 4 spaces!\r
+\r
+    http://www.FreeRTOS.org - Documentation, latest information, license and\r
+    contact details.\r
+\r
+    http://www.SafeRTOS.com - A version that is certified for use in safety\r
+    critical systems.\r
+\r
+    http://www.OpenRTOS.com - Commercial support, development, porting,\r
+    licensing and training services.\r
+*/\r
+\r
+/* Scheduler includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+\r
+/*-----------------------------------------------------------\r
+ * Implementation of functions defined in portable.h for the MSP430X port.\r
+ *----------------------------------------------------------*/\r
+\r
+/* Constants required for hardware setup.  The tick ISR runs off the ACLK,\r
+not the MCLK. */\r
+#define portACLK_FREQUENCY_HZ                  ( ( portTickType ) 32768 )\r
+#define portINITIAL_CRITICAL_NESTING   ( ( unsigned short ) 10 )\r
+#define portFLAGS_INT_ENABLED                  ( ( portSTACK_TYPE ) 0x08 )\r
+\r
+/* We require the address of the pxCurrentTCB variable, but don't want to know\r
+any details of its type. */\r
+typedef void tskTCB;\r
+extern volatile tskTCB * volatile pxCurrentTCB;\r
+\r
+/* Each task maintains a count of the critical section nesting depth.  Each\r
+time a critical section is entered the count is incremented.  Each time a\r
+critical section is exited the count is decremented - with interrupts only\r
+being re-enabled if the count is zero.\r
+\r
+usCriticalNesting will get set to zero when the scheduler starts, but must\r
+not be initialised to zero as this will cause problems during the startup\r
+sequence. */\r
+volatile unsigned short usCriticalNesting = portINITIAL_CRITICAL_NESTING;\r
+/*-----------------------------------------------------------*/\r
+\r
+\r
+/*\r
+ * Sets up the periodic ISR used for the RTOS tick.  This uses timer 0, but\r
+ * could have alternatively used the watchdog timer or timer 1.\r
+ */\r
+void vPortSetupTimerInterrupt( void );\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * Initialise the stack of a task to look exactly as if a call to\r
+ * portSAVE_CONTEXT had been called.\r
+ *\r
+ * See the header file portable.h.\r
+ */\r
+portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
+{\r
+unsigned short *pusTopOfStack;\r
+\r
+       /*\r
+               Place a few bytes of known values on the bottom of the stack.\r
+               This is just useful for debugging and can be included if required.\r
+\r
+               *pxTopOfStack = ( portSTACK_TYPE ) 0x1111;\r
+               pxTopOfStack--;\r
+               *pxTopOfStack = ( portSTACK_TYPE ) 0x2222;\r
+               pxTopOfStack--;\r
+               *pxTopOfStack = ( portSTACK_TYPE ) 0x3333;\r
+               pxTopOfStack--;\r
+       */\r
+\r
+       *pxTopOfStack = ( portSTACK_TYPE ) pxCode;\r
+       pusTopOfStack = ( unsigned short * ) pxTopOfStack;\r
+       pusTopOfStack--;\r
+       *pusTopOfStack = portFLAGS_INT_ENABLED;\r
+       pusTopOfStack -= 2;\r
+       pxTopOfStack = ( portSTACK_TYPE * ) pusTopOfStack;\r
+\r
+       /* Next the general purpose registers. */\r
+       *pxTopOfStack = ( portSTACK_TYPE ) 0xffffff;\r
+       pxTopOfStack--;\r
+       *pxTopOfStack = ( portSTACK_TYPE ) 0xeeeeee;\r
+       pxTopOfStack--;\r
+       *pxTopOfStack = ( portSTACK_TYPE ) 0xdddddd;\r
+       pxTopOfStack--;\r
+       *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;\r
+       pxTopOfStack--;\r
+       *pxTopOfStack = ( portSTACK_TYPE ) 0xbbbbbb;\r
+       pxTopOfStack--;\r
+       *pxTopOfStack = ( portSTACK_TYPE ) 0xaaaaaa;\r
+       pxTopOfStack--;\r
+       *pxTopOfStack = ( portSTACK_TYPE ) 0x999999;\r
+       pxTopOfStack--;\r
+       *pxTopOfStack = ( portSTACK_TYPE ) 0x888888;\r
+       pxTopOfStack--; \r
+       *pxTopOfStack = ( portSTACK_TYPE ) 0x555555;\r
+       pxTopOfStack--;\r
+       *pxTopOfStack = ( portSTACK_TYPE ) 0x666666;\r
+       pxTopOfStack--;\r
+       *pxTopOfStack = ( portSTACK_TYPE ) 0x555555;\r
+       pxTopOfStack--;\r
+       *pxTopOfStack = ( portSTACK_TYPE ) 0x444444;\r
+       pxTopOfStack--;\r
+\r
+       /* A variable is used to keep track of the critical section nesting.\r
+       This variable has to be stored as part of the task context and is\r
+       initially set to zero. */\r
+       *pxTopOfStack = ( portSTACK_TYPE ) portNO_CRITICAL_SECTION_NESTING;     \r
+\r
+       /* Return a pointer to the top of the stack we have generated so this can\r
+       be stored in the task control block for the task. */\r
+       return pxTopOfStack;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vPortEndScheduler( void )\r
+{\r
+       /* It is unlikely that the MSP430 port will get stopped.  If required simply\r
+       disable the tick interrupt here. */\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * Hardware initialisation to generate the RTOS tick.\r
+ */\r
+void vPortSetupTimerInterrupt( void )\r
+{\r
+       vApplicationSetupTimerInterrupt();\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+#pragma vector=configTICK_INTERRUPT_VECTOR\r
+interrupt void vTickISREntry( void )\r
+{\r
+extern void vPortTickISR( void );\r
+\r
+       #if configUSE_PREEMPTION == 1\r
+               extern void vPortPreemptiveTickISR( void );\r
+               vPortPreemptiveTickISR();\r
+       #else\r
+               extern void vPortCooperativeTickISR( void );\r
+               vPortCooperativeTickISR();\r
+       #endif\r
+}\r
+\r
+       \r
diff --git a/Source/portable/CCS4/MSP430X/portext.asm b/Source/portable/CCS4/MSP430X/portext.asm
new file mode 100644 (file)
index 0000000..97c69b6
--- /dev/null
@@ -0,0 +1,173 @@
+;\r
+;    FreeRTOS V6.1.0 - Copyright (C) 2010 Real Time Engineers Ltd.\r
+;\r
+;    ***************************************************************************\r
+;    *                                                                         *\r
+;    * If you are:                                                             *\r
+;    *                                                                         *\r
+;    *    + New to FreeRTOS,                                                   *\r
+;    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
+;    *    + Looking for basic training,                                        *\r
+;    *    + Wanting to improve your FreeRTOS skills and productivity           *\r
+;    *                                                                         *\r
+;    * then take a look at the FreeRTOS books - available as PDF or paperback  *\r
+;    *                                                                         *\r
+;    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
+;    *                  http://www.FreeRTOS.org/Documentation                  *\r
+;    *                                                                         *\r
+;    * A pdf reference manual is also available.  Both are usually delivered   *\r
+;    * to your inbox within 20 minutes to two hours when purchased between 8am *\r
+;    * and 8pm GMT (although please allow up to 24 hours in case of            *\r
+;    * exceptional circumstances).  Thank you for your support!                *\r
+;    *                                                                         *\r
+;    ***************************************************************************\r
+;\r
+;    This file is part of the FreeRTOS distribution.\r
+;\r
+;    FreeRTOS is free software; you can redistribute it and/or modify it under\r
+;    the terms of the GNU General Public License (version 2) as published by the\r
+;    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+;    ***NOTE*** The exception to the GPL is included to allow you to distribute\r
+;    a combined work that includes FreeRTOS without being obliged to provide the\r
+;    source code for proprietary components outside of the FreeRTOS kernel.\r
+;    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
+;    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+;    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
+;    more details. You should have received a copy of the GNU General Public\r
+;    License and the FreeRTOS license exception along with FreeRTOS; if not it\r
+;    can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
+;    by writing to Richard Barry, contact details for whom are available on the\r
+;    FreeRTOS WEB site.\r
+;\r
+;    1 tab == 4 spaces!\r
+;\r
+;    http://www.FreeRTOS.org - Documentation, latest information, license and\r
+;    contact details.\r
+;\r
+;    http://www.SafeRTOS.com - A version that is certified for use in safety\r
+;    critical systems.\r
+;\r
+;    http://www.OpenRTOS.com - Commercial support, development, porting,\r
+;    licensing and training services.\r
+\r
+; * The definition of the "register test" tasks, as described at the top of\r
+; * main.c\r
+\r
+       .global vTaskIncrementTick\r
+       .global vTaskSwitchContext\r
+       .global vPortSetupTimerInterrupt\r
+       .global pxCurrentTCB\r
+       .global usCriticalNesting\r
+\r
+       .def vPortPreemptiveTickISR\r
+       .def vPortCooperativeTickISR\r
+       .def vPortYield\r
+       .def xPortStartScheduler\r
+\r
+;-----------------------------------------------------------\r
+\r
+portSAVE_CONTEXT .macro\r
+\r
+       ;Save the remaining registers.\r
+       pushm.a #12, r15\r
+       movx.w  &usCriticalNesting, r14\r
+       pushx.a r14\r
+       movx.a  &pxCurrentTCB, r12\r
+       movx.a  sp, 0( r12 )\r
+       .endm\r
+;-----------------------------------------------------------\r
+               \r
+portRESTORE_CONTEXT .macro\r
+\r
+       movx.a  &pxCurrentTCB, r12\r
+       movx.a  @r12, sp\r
+       popx.a  r15\r
+       movx.w  r15, &usCriticalNesting\r
+       popm.a  #12, r15\r
+               \r
+       ;The last thing on the stack will be the status register.\r
+    ;Ensure the power down bits are clear ready for the next\r
+    ;time this power down register is popped from the stack.\r
+       bic.w   #0xf0, 0( sp )\r
+               \r
+       pop.w   sr\r
+       reta\r
+       .endm\r
+;-----------------------------------------------------------\r
+\r
+;*\r
+;* The RTOS tick ISR.\r
+;*\r
+;* If the cooperative scheduler is in use this simply increments the tick\r
+;* count.\r
+;*\r
+;* If the preemptive scheduler is in use a context switch can also occur.\r
+;*/\r
+       \r
+       .text\r
+       \r
+vPortPreemptiveTickISR:\r
+       \r
+       ; The sr is not saved in portSAVE_CONTEXT() because vPortYield() needs\r
+       ;to save it manually before it gets modified (interrupts get disabled).\r
+       push.w sr\r
+       portSAVE_CONTEXT\r
+                               \r
+       calla   #vTaskIncrementTick\r
+       calla   #vTaskSwitchContext\r
+               \r
+       portRESTORE_CONTEXT\r
+;-----------------------------------------------------------\r
+\r
+vPortCooperativeTickISR:\r
+       \r
+       ; The sr is not saved in portSAVE_CONTEXT() because vPortYield() needs\r
+       ;to save it manually before it gets modified (interrupts get disabled).\r
+       push.w sr\r
+       portSAVE_CONTEXT\r
+                               \r
+       calla   #vTaskIncrementTick\r
+       calla   #vTaskSwitchContext\r
+               \r
+       portRESTORE_CONTEXT\r
+;-----------------------------------------------------------\r
+\r
+;*\r
+;* Manual context switch called by the portYIELD() macro.\r
+;*/\r
+vPortYield:\r
+\r
+       ; The sr needs saving before it is modified.\r
+       push.w  sr\r
+       \r
+       ; Now the SR is stacked we can disable interrupts.\r
+       dint    \r
+       nop\r
+                               \r
+       ; Save the context of the current task.\r
+       portSAVE_CONTEXT                        \r
+\r
+       ; Select the next task to run.\r
+       calla   #vTaskSwitchContext             \r
+\r
+       ; Restore the context of the new task.\r
+       portRESTORE_CONTEXT\r
+;-----------------------------------------------------------\r
+\r
+\r
+;*\r
+;* Start off the scheduler by initialising the RTOS tick timer, then restoring\r
+;* the context of the first task.\r
+;*\r
+xPortStartScheduler:\r
+\r
+       ; Setup the hardware to generate the tick.  Interrupts are disabled\r
+       ; when this function is called.\r
+       calla   #vPortSetupTimerInterrupt\r
+\r
+       ; Restore the context of the first task that is going to run.\r
+       portRESTORE_CONTEXT\r
+;-----------------------------------------------------------\r
+               \r
+       .end\r
+               \r
diff --git a/Source/portable/CCS4/MSP430X/portmacro.h b/Source/portable/CCS4/MSP430X/portmacro.h
new file mode 100644 (file)
index 0000000..3929bff
--- /dev/null
@@ -0,0 +1,154 @@
+/*\r
+    FreeRTOS V6.1.0 - Copyright (C) 2010 Real Time Engineers Ltd.\r
+\r
+    ***************************************************************************\r
+    *                                                                         *\r
+    * If you are:                                                             *\r
+    *                                                                         *\r
+    *    + New to FreeRTOS,                                                   *\r
+    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
+    *    + Looking for basic training,                                        *\r
+    *    + Wanting to improve your FreeRTOS skills and productivity           *\r
+    *                                                                         *\r
+    * then take a look at the FreeRTOS books - available as PDF or paperback  *\r
+    *                                                                         *\r
+    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
+    *                  http://www.FreeRTOS.org/Documentation                  *\r
+    *                                                                         *\r
+    * A pdf reference manual is also available.  Both are usually delivered   *\r
+    * to your inbox within 20 minutes to two hours when purchased between 8am *\r
+    * and 8pm GMT (although please allow up to 24 hours in case of            *\r
+    * exceptional circumstances).  Thank you for your support!                *\r
+    *                                                                         *\r
+    ***************************************************************************\r
+\r
+    This file is part of the FreeRTOS distribution.\r
+\r
+    FreeRTOS is free software; you can redistribute it and/or modify it under\r
+    the terms of the GNU General Public License (version 2) as published by the\r
+    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+    ***NOTE*** The exception to the GPL is included to allow you to distribute\r
+    a combined work that includes FreeRTOS without being obliged to provide the\r
+    source code for proprietary components outside of the FreeRTOS kernel.\r
+    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
+    more details. You should have received a copy of the GNU General Public\r
+    License and the FreeRTOS license exception along with FreeRTOS; if not it\r
+    can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
+    by writing to Richard Barry, contact details for whom are available on the\r
+    FreeRTOS WEB site.\r
+\r
+    1 tab == 4 spaces!\r
+\r
+    http://www.FreeRTOS.org - Documentation, latest information, license and\r
+    contact details.\r
+\r
+    http://www.SafeRTOS.com - A version that is certified for use in safety\r
+    critical systems.\r
+\r
+    http://www.OpenRTOS.com - Commercial support, development, porting,\r
+    licensing and training services.\r
+*/\r
+\r
+#ifndef PORTMACRO_H\r
+#define PORTMACRO_H\r
+\r
+/*-----------------------------------------------------------\r
+ * Port specific definitions.\r
+ *\r
+ * The settings in this file configure FreeRTOS correctly for the\r
+ * given hardware and compiler.\r
+ *\r
+ * These settings should not be altered.\r
+ *-----------------------------------------------------------\r
+ */\r
+\r
+/* Hardware includes. */\r
+#include "msp430.h"\r
+\r
+/* Type definitions. */\r
+#define portCHAR               char\r
+#define portFLOAT              float\r
+#define portDOUBLE             double\r
+#define portLONG               long\r
+#define portSHORT              int\r
+#define portSTACK_TYPE unsigned portLONG\r
+#define portBASE_TYPE  portSHORT\r
+\r
+#if( configUSE_16_BIT_TICKS == 1 )\r
+       typedef unsigned portSHORT portTickType;\r
+       #define portMAX_DELAY ( portTickType ) 0xffff\r
+#else\r
+       typedef unsigned portLONG portTickType;\r
+       #define portMAX_DELAY ( portTickType ) 0xffffffff\r
+#endif\r
+\r
+/*-----------------------------------------------------------*/        \r
+\r
+/* Interrupt control macros. */\r
+#define portDISABLE_INTERRUPTS()       _disable_interrupt()\r
+#define portENABLE_INTERRUPTS()                _enable_interrupt()\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Critical section control macros. */\r
+#define portNO_CRITICAL_SECTION_NESTING                ( ( unsigned portSHORT ) 0 )\r
+\r
+#define portENTER_CRITICAL()                                                                                                   \\r
+{                                                                                                                                                              \\r
+extern volatile unsigned short usCriticalNesting;                                                              \\r
+                                                                                                                                                               \\r
+       portDISABLE_INTERRUPTS();                                                                                                       \\r
+                                                                                                                                                               \\r
+       /* Now interrupts are disabled usCriticalNesting can be accessed */                     \\r
+       /* directly.  Increment ulCriticalNesting to keep a count of how many */        \\r
+       /* times portENTER_CRITICAL() has been called. */                                                       \\r
+       usCriticalNesting++;                                                                                                            \\r
+}\r
+\r
+#define portEXIT_CRITICAL()                                                                                                            \\r
+{                                                                                                                                                              \\r
+extern volatile unsigned short usCriticalNesting;                                                      \\r
+                                                                                                                                                               \\r
+       if( usCriticalNesting > portNO_CRITICAL_SECTION_NESTING )                                       \\r
+       {                                                                                                                                                       \\r
+               /* Decrement the nesting count as we are leaving a critical section. */ \\r
+               usCriticalNesting--;                                                                                                    \\r
+                                                                                                                                                               \\r
+               /* If the nesting level has reached zero then interrupts should be */   \\r
+               /* re-enabled. */                                                                                                               \\r
+               if( usCriticalNesting == portNO_CRITICAL_SECTION_NESTING )                              \\r
+               {                                                                                                                                               \\r
+                       portENABLE_INTERRUPTS();                                                                                        \\r
+               }                                                                                                                                               \\r
+       }                                                                                                                                                       \\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Task utilities. */\r
+\r
+/*\r
+ * Manual context switch called by portYIELD or taskYIELD.\r
+ */\r
+extern void vPortYield( void );\r
+#define portYIELD() vPortYield()\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Hardware specifics. */\r
+#define portBYTE_ALIGNMENT                     4\r
+#define portSTACK_GROWTH                       ( -1 )\r
+#define portTICK_RATE_MS                       ( ( portTickType ) 1000 / configTICK_RATE_HZ )  \r
+#define portNOP()      \r
+/*-----------------------------------------------------------*/\r
+\r
+/* Task function macros as described on the FreeRTOS.org WEB site. */\r
+#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
+#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
+\r
+extern void vTaskSwitchContext( void );\r
+#define portYIELD_FROM_ISR( x ) if( x ) vPortYield()\r
+       \r
+void vApplicationSetupTimerInterrupt( void );\r
+\r
+#endif /* PORTMACRO_H */\r
+\r