OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Source/] [portable/] [Rowley/] [MSP430F449/] [port.c] - Blame information for rev 662

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 572 jeremybenn
/*
2
    FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
3
 
4
    ***************************************************************************
5
    *                                                                         *
6
    * If you are:                                                             *
7
    *                                                                         *
8
    *    + New to FreeRTOS,                                                   *
9
    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *
10
    *    + Looking for basic training,                                        *
11
    *    + Wanting to improve your FreeRTOS skills and productivity           *
12
    *                                                                         *
13
    * then take a look at the FreeRTOS books - available as PDF or paperback  *
14
    *                                                                         *
15
    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *
16
    *                  http://www.FreeRTOS.org/Documentation                  *
17
    *                                                                         *
18
    * A pdf reference manual is also available.  Both are usually delivered   *
19
    * to your inbox within 20 minutes to two hours when purchased between 8am *
20
    * and 8pm GMT (although please allow up to 24 hours in case of            *
21
    * exceptional circumstances).  Thank you for your support!                *
22
    *                                                                         *
23
    ***************************************************************************
24
 
25
    This file is part of the FreeRTOS distribution.
26
 
27
    FreeRTOS is free software; you can redistribute it and/or modify it under
28
    the terms of the GNU General Public License (version 2) as published by the
29
    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30
    ***NOTE*** The exception to the GPL is included to allow you to distribute
31
    a combined work that includes FreeRTOS without being obliged to provide the
32
    source code for proprietary components outside of the FreeRTOS kernel.
33
    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
34
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
36
    more details. You should have received a copy of the GNU General Public
37
    License and the FreeRTOS license exception along with FreeRTOS; if not it
38
    can be viewed here: http://www.freertos.org/a00114.html and also obtained
39
    by writing to Richard Barry, contact details for whom are available on the
40
    FreeRTOS WEB site.
41
 
42
    1 tab == 4 spaces!
43
 
44
    http://www.FreeRTOS.org - Documentation, latest information, license and
45
    contact details.
46
 
47
    http://www.SafeRTOS.com - A version that is certified for use in safety
48
    critical systems.
49
 
50
    http://www.OpenRTOS.com - Commercial support, development, porting,
51
    licensing and training services.
52
*/
53
 
54
/* Scheduler includes. */
55
#include "FreeRTOS.h"
56
#include "task.h"
57
 
58
/*-----------------------------------------------------------
59
 * Implementation of functions defined in portable.h for the MSP430 port.
60
 *----------------------------------------------------------*/
61
 
62
/* Constants required for hardware setup.  The tick ISR runs off the ACLK,
63
not the MCLK. */
64
#define portACLK_FREQUENCY_HZ                   ( ( portTickType ) 32768 )
65
#define portINITIAL_CRITICAL_NESTING    ( ( unsigned short ) 10 )
66
#define portFLAGS_INT_ENABLED                   ( ( portSTACK_TYPE ) 0x08 )
67
 
68
/* We require the address of the pxCurrentTCB variable, but don't want to know
69
any details of its type. */
70
typedef void tskTCB;
71
extern volatile tskTCB * volatile pxCurrentTCB;
72
 
73
/* Each task maintains a count of the critical section nesting depth.  Each
74
time a critical section is entered the count is incremented.  Each time a
75
critical section is exited the count is decremented - with interrupts only
76
being re-enabled if the count is zero.
77
 
78
usCriticalNesting will get set to zero when the scheduler starts, but must
79
not be initialised to zero as this will cause problems during the startup
80
sequence. */
81
volatile unsigned short usCriticalNesting = portINITIAL_CRITICAL_NESTING;
82
/*-----------------------------------------------------------*/
83
 
84
 
85
/*
86
 * Sets up the periodic ISR used for the RTOS tick.  This uses timer 0, but
87
 * could have alternatively used the watchdog timer or timer 1.
88
 */
89
void prvSetupTimerInterrupt( void );
90
/*-----------------------------------------------------------*/
91
 
92
/*
93
 * Initialise the stack of a task to look exactly as if a call to
94
 * portSAVE_CONTEXT had been called.
95
 *
96
 * See the header file portable.h.
97
 */
98
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
99
{
100
        /*
101
                Place a few bytes of known values on the bottom of the stack.
102
                This is just useful for debugging and can be included if required.
103
 
104
                *pxTopOfStack = ( portSTACK_TYPE ) 0x1111;
105
                pxTopOfStack--;
106
                *pxTopOfStack = ( portSTACK_TYPE ) 0x2222;
107
                pxTopOfStack--;
108
                *pxTopOfStack = ( portSTACK_TYPE ) 0x3333;
109
                pxTopOfStack--;
110
        */
111
 
112
        /* The msp430 automatically pushes the PC then SR onto the stack before
113
        executing an ISR.  We want the stack to look just as if this has happened
114
        so place a pointer to the start of the task on the stack first - followed
115
        by the flags we want the task to use when it starts up. */
116
        *pxTopOfStack = ( portSTACK_TYPE ) pxCode;
117
        pxTopOfStack--;
118
        *pxTopOfStack = portFLAGS_INT_ENABLED;
119
        pxTopOfStack--;
120
 
121
        /* Next the general purpose registers. */
122
        *pxTopOfStack = ( portSTACK_TYPE ) 0x4444;
123
        pxTopOfStack--;
124
        *pxTopOfStack = ( portSTACK_TYPE ) 0x5555;
125
        pxTopOfStack--;
126
        *pxTopOfStack = ( portSTACK_TYPE ) 0x6666;
127
        pxTopOfStack--;
128
        *pxTopOfStack = ( portSTACK_TYPE ) 0x7777;
129
        pxTopOfStack--;
130
        *pxTopOfStack = ( portSTACK_TYPE ) 0x8888;
131
        pxTopOfStack--;
132
        *pxTopOfStack = ( portSTACK_TYPE ) 0x9999;
133
        pxTopOfStack--;
134
        *pxTopOfStack = ( portSTACK_TYPE ) 0xaaaa;
135
        pxTopOfStack--;
136
        *pxTopOfStack = ( portSTACK_TYPE ) 0xbbbb;
137
        pxTopOfStack--;
138
        *pxTopOfStack = ( portSTACK_TYPE ) 0xcccc;
139
        pxTopOfStack--;
140
        *pxTopOfStack = ( portSTACK_TYPE ) 0xdddd;
141
        pxTopOfStack--;
142
        *pxTopOfStack = ( portSTACK_TYPE ) 0xeeee;
143
        pxTopOfStack--;
144
 
145
        /* When the task starts is will expect to find the function parameter in
146
        R15. */
147
        *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;
148
        pxTopOfStack--;
149
 
150
        /* A variable is used to keep track of the critical section nesting.
151
        This variable has to be stored as part of the task context and is
152
        initially set to zero. */
153
        *pxTopOfStack = ( portSTACK_TYPE ) portNO_CRITICAL_SECTION_NESTING;
154
 
155
        /* Return a pointer to the top of the stack we have generated so this can
156
        be stored in the task control block for the task. */
157
        return pxTopOfStack;
158
}
159
/*-----------------------------------------------------------*/
160
 
161
void vPortEndScheduler( void )
162
{
163
        /* It is unlikely that the MSP430 port will get stopped.  If required simply
164
        disable the tick interrupt here. */
165
}
166
/*-----------------------------------------------------------*/
167
 
168
/*
169
 * Hardware initialisation to generate the RTOS tick.  This uses timer 0
170
 * but could alternatively use the watchdog timer or timer 1.
171
 */
172
void prvSetupTimerInterrupt( void )
173
{
174
        /* Ensure the timer is stopped. */
175
        TACTL = 0;
176
 
177
        /* Run the timer of the ACLK. */
178
        TACTL = TASSEL_1;
179
 
180
        /* Clear everything to start with. */
181
        TACTL |= TACLR;
182
 
183
        /* Set the compare match value according to the tick rate we want. */
184
        TACCR0 = portACLK_FREQUENCY_HZ / configTICK_RATE_HZ;
185
 
186
        /* Enable the interrupts. */
187
        TACCTL0 = CCIE;
188
 
189
        /* Start up clean. */
190
        TACTL |= TACLR;
191
 
192
        /* Up mode. */
193
        TACTL |= MC_1;
194
}
195
/*-----------------------------------------------------------*/
196
 
197
 
198
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.