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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Source/] [portable/] [CodeWarrior/] [HCS12/] [port.c] - Blame information for rev 572

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
/*-----------------------------------------------------------
60
 * Implementation of functions defined in portable.h for the HCS12 port.
61
 *----------------------------------------------------------*/
62
 
63
 
64
/*
65
 * Configure a timer to generate the RTOS tick at the frequency specified
66
 * within FreeRTOSConfig.h.
67
 */
68
static void prvSetupTimerInterrupt( void );
69
 
70
/* Interrupt service routines have to be in non-banked memory - as does the
71
scheduler startup function. */
72
#pragma CODE_SEG __NEAR_SEG NON_BANKED
73
 
74
        /* Manual context switch function.  This is the SWI ISR. */
75
        void interrupt vPortYield( void );
76
 
77
        /* Tick context switch function.  This is the timer ISR. */
78
        void interrupt vPortTickInterrupt( void );
79
 
80
        /* Simply called by xPortStartScheduler().  xPortStartScheduler() does not
81
        start the scheduler directly because the header file containing the
82
        xPortStartScheduler() prototype is part of the common kernel code, and
83
        therefore cannot use the CODE_SEG pragma. */
84
        static portBASE_TYPE xBankedStartScheduler( void );
85
 
86
#pragma CODE_SEG DEFAULT
87
 
88
/* Calls to portENTER_CRITICAL() can be nested.  When they are nested the
89
critical section should not be left (i.e. interrupts should not be re-enabled)
90
until the nesting depth reaches 0.  This variable simply tracks the nesting
91
depth.  Each task maintains it's own critical nesting depth variable so
92
uxCriticalNesting is saved and restored from the task stack during a context
93
switch. */
94
volatile unsigned portBASE_TYPE uxCriticalNesting = 0xff;
95
 
96
/*-----------------------------------------------------------*/
97
 
98
/*
99
 * See header file for description.
100
 */
101
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
102
{
103
        /*
104
                Place a few bytes of known values on the bottom of the stack.
105
                This can be uncommented to provide useful stack markers when debugging.
106
 
107
                *pxTopOfStack = ( portSTACK_TYPE ) 0x11;
108
                pxTopOfStack--;
109
                *pxTopOfStack = ( portSTACK_TYPE ) 0x22;
110
                pxTopOfStack--;
111
                *pxTopOfStack = ( portSTACK_TYPE ) 0x33;
112
                pxTopOfStack--;
113
        */
114
 
115
 
116
 
117
        /* Setup the initial stack of the task.  The stack is set exactly as
118
        expected by the portRESTORE_CONTEXT() macro.  In this case the stack as
119
        expected by the HCS12 RTI instruction. */
120
 
121
 
122
        /* The address of the task function is placed in the stack byte at a time. */
123
        *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 1 );
124
        pxTopOfStack--;
125
        *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 0 );
126
        pxTopOfStack--;
127
 
128
        /* Next are all the registers that form part of the task context. */
129
 
130
        /* Y register */
131
        *pxTopOfStack = ( portSTACK_TYPE ) 0xff;
132
        pxTopOfStack--;
133
        *pxTopOfStack = ( portSTACK_TYPE ) 0xee;
134
        pxTopOfStack--;
135
 
136
        /* X register */
137
        *pxTopOfStack = ( portSTACK_TYPE ) 0xdd;
138
        pxTopOfStack--;
139
        *pxTopOfStack = ( portSTACK_TYPE ) 0xcc;
140
        pxTopOfStack--;
141
 
142
        /* A register contains parameter high byte. */
143
        *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 0 );
144
        pxTopOfStack--;
145
 
146
        /* B register contains parameter low byte. */
147
        *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 1 );
148
        pxTopOfStack--;
149
 
150
        /* CCR: Note that when the task starts interrupts will be enabled since
151
        "I" bit of CCR is cleared */
152
        *pxTopOfStack = ( portSTACK_TYPE ) 0x00;
153
        pxTopOfStack--;
154
 
155
        #ifdef BANKED_MODEL
156
                /* The page of the task. */
157
                *pxTopOfStack = ( portSTACK_TYPE ) ( ( int ) pxCode );
158
                pxTopOfStack--;
159
        #endif
160
 
161
        /* Finally the critical nesting depth is initialised with 0 (not within
162
        a critical section). */
163
        *pxTopOfStack = ( portSTACK_TYPE ) 0x00;
164
 
165
        return pxTopOfStack;
166
}
167
/*-----------------------------------------------------------*/
168
 
169
void vPortEndScheduler( void )
170
{
171
        /* It is unlikely that the HCS12 port will get stopped. */
172
}
173
/*-----------------------------------------------------------*/
174
 
175
static void prvSetupTimerInterrupt( void )
176
{
177
        TickTimer_SetFreqHz( configTICK_RATE_HZ );
178
        TickTimer_Enable();
179
}
180
/*-----------------------------------------------------------*/
181
 
182
portBASE_TYPE xPortStartScheduler( void )
183
{
184
        /* xPortStartScheduler() does not start the scheduler directly because
185
        the header file containing the xPortStartScheduler() prototype is part
186
        of the common kernel code, and therefore cannot use the CODE_SEG pragma.
187
        Instead it simply calls the locally defined xBankedStartScheduler() -
188
        which does use the CODE_SEG pragma. */
189
 
190
        return xBankedStartScheduler();
191
}
192
/*-----------------------------------------------------------*/
193
 
194
#pragma CODE_SEG __NEAR_SEG NON_BANKED
195
 
196
static portBASE_TYPE xBankedStartScheduler( void )
197
{
198
        /* Configure the timer that will generate the RTOS tick.  Interrupts are
199
        disabled when this function is called. */
200
        prvSetupTimerInterrupt();
201
 
202
        /* Restore the context of the first task. */
203
        portRESTORE_CONTEXT();
204
 
205
        /* Simulate the end of an interrupt to start the scheduler off. */
206
        __asm( "rti" );
207
 
208
        /* Should not get here! */
209
        return pdFALSE;
210
}
211
/*-----------------------------------------------------------*/
212
 
213
/*
214
 * Context switch functions.  These are both interrupt service routines.
215
 */
216
 
217
/*
218
 * Manual context switch forced by calling portYIELD().  This is the SWI
219
 * handler.
220
 */
221
void interrupt vPortYield( void )
222
{
223
        portSAVE_CONTEXT();
224
        vTaskSwitchContext();
225
        portRESTORE_CONTEXT();
226
}
227
/*-----------------------------------------------------------*/
228
 
229
/*
230
 * RTOS tick interrupt service routine.  If the cooperative scheduler is
231
 * being used then this simply increments the tick count.  If the
232
 * preemptive scheduler is being used a context switch can occur.
233
 */
234
void interrupt vPortTickInterrupt( void )
235
{
236
        #if configUSE_PREEMPTION == 1
237
        {
238
                /* A context switch might happen so save the context. */
239
                portSAVE_CONTEXT();
240
 
241
                /* Increment the tick ... */
242
                vTaskIncrementTick();
243
 
244
                /* ... then see if the new tick value has necessitated a
245
                context switch. */
246
                vTaskSwitchContext();
247
 
248
                TFLG1 = 1;
249
 
250
                /* Restore the context of a task - which may be a different task
251
                to that interrupted. */
252
                portRESTORE_CONTEXT();
253
        }
254
        #else
255
        {
256
                vTaskIncrementTick();
257
                TFLG1 = 1;
258
        }
259
        #endif
260
}
261
 
262
#pragma CODE_SEG DEFAULT
263
 
264
 

powered by: WebSVN 2.1.0

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