2 FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
66 /* Scheduler includes. */
\r
67 #include "FreeRTOS.h"
\r
70 /*-----------------------------------------------------------
\r
71 * Implementation of functions defined in portable.h for the MSP430 port.
\r
72 *----------------------------------------------------------*/
\r
74 /* Constants required for hardware setup. The tick ISR runs off the ACLK,
\r
76 #define portACLK_FREQUENCY_HZ ( ( TickType_t ) 32768 )
\r
77 #define portINITIAL_CRITICAL_NESTING ( ( uint16_t ) 10 )
\r
78 #define portFLAGS_INT_ENABLED ( ( StackType_t ) 0x08 )
\r
80 /* We require the address of the pxCurrentTCB variable, but don't want to know
\r
81 any details of its type. */
\r
83 extern volatile TCB_t * volatile pxCurrentTCB;
\r
85 /* Each task maintains a count of the critical section nesting depth. Each
\r
86 time a critical section is entered the count is incremented. Each time a
\r
87 critical section is exited the count is decremented - with interrupts only
\r
88 being re-enabled if the count is zero.
\r
90 usCriticalNesting will get set to zero when the scheduler starts, but must
\r
91 not be initialised to zero as this will cause problems during the startup
\r
93 volatile uint16_t usCriticalNesting = portINITIAL_CRITICAL_NESTING;
\r
94 /*-----------------------------------------------------------*/
\r
98 * Sets up the periodic ISR used for the RTOS tick. This uses timer 0, but
\r
99 * could have alternatively used the watchdog timer or timer 1.
\r
101 void vPortSetupTimerInterrupt( void );
\r
102 /*-----------------------------------------------------------*/
\r
105 * Initialise the stack of a task to look exactly as if a call to
\r
106 * portSAVE_CONTEXT had been called.
\r
108 * See the header file portable.h.
\r
110 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
113 Place a few bytes of known values on the bottom of the stack.
\r
114 This is just useful for debugging and can be included if required.
\r
116 *pxTopOfStack = ( StackType_t ) 0x1111;
\r
118 *pxTopOfStack = ( StackType_t ) 0x2222;
\r
120 *pxTopOfStack = ( StackType_t ) 0x3333;
\r
124 /* The msp430 automatically pushes the PC then SR onto the stack before
\r
125 executing an ISR. We want the stack to look just as if this has happened
\r
126 so place a pointer to the start of the task on the stack first - followed
\r
127 by the flags we want the task to use when it starts up. */
\r
128 *pxTopOfStack = ( StackType_t ) pxCode;
\r
130 *pxTopOfStack = portFLAGS_INT_ENABLED;
\r
133 /* Next the general purpose registers. */
\r
134 *pxTopOfStack = ( StackType_t ) 0x4444;
\r
136 *pxTopOfStack = ( StackType_t ) 0x5555;
\r
138 *pxTopOfStack = ( StackType_t ) 0x6666;
\r
140 *pxTopOfStack = ( StackType_t ) 0x7777;
\r
142 *pxTopOfStack = ( StackType_t ) 0x8888;
\r
144 *pxTopOfStack = ( StackType_t ) 0x9999;
\r
146 *pxTopOfStack = ( StackType_t ) 0xaaaa;
\r
148 *pxTopOfStack = ( StackType_t ) 0xbbbb;
\r
151 /* When the task starts is will expect to find the function parameter in
\r
153 *pxTopOfStack = ( StackType_t ) pvParameters;
\r
156 *pxTopOfStack = ( StackType_t ) 0xdddd;
\r
158 *pxTopOfStack = ( StackType_t ) 0xeeee;
\r
160 *pxTopOfStack = ( StackType_t ) 0xffff;
\r
163 /* A variable is used to keep track of the critical section nesting.
\r
164 This variable has to be stored as part of the task context and is
\r
165 initially set to zero. */
\r
166 *pxTopOfStack = ( StackType_t ) portNO_CRITICAL_SECTION_NESTING;
\r
168 /* Return a pointer to the top of the stack we have generated so this can
\r
169 be stored in the task control block for the task. */
\r
170 return pxTopOfStack;
\r
172 /*-----------------------------------------------------------*/
\r
174 void vPortEndScheduler( void )
\r
176 /* It is unlikely that the MSP430 port will get stopped. If required simply
\r
177 disable the tick interrupt here. */
\r
179 /*-----------------------------------------------------------*/
\r
182 * Hardware initialisation to generate the RTOS tick. This uses timer 0
\r
183 * but could alternatively use the watchdog timer or timer 1.
\r
185 void vPortSetupTimerInterrupt( void )
\r
187 /* Ensure the timer is stopped. */
\r
190 /* Run the timer of the ACLK. */
\r
193 /* Clear everything to start with. */
\r
196 /* Set the compare match value according to the tick rate we want. */
\r
197 TACCR0 = portACLK_FREQUENCY_HZ / configTICK_RATE_HZ;
\r
199 /* Enable the interrupts. */
\r
202 /* Start up clean. */
\r
208 /*-----------------------------------------------------------*/
\r