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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Source/] [portable/] [GCC/] [OpenRISC/] [port.c] - Blame information for rev 675

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
/*-----------------------------------------------------------
55
 * Implementation of functions defined in portable.h for the OpenRISC port.
56
 *----------------------------------------------------------*/
57
 
58
 
59
/* Scheduler includes. */
60
#include "FreeRTOS.h"
61
#include "task.h"
62
 
63
/* Processor constants. */
64
#include "port_spr_defs.h"
65
 
66 621 filepang
/* Jump buffer */
67
#include <setjmp.h>
68
static jmp_buf jmpbuf;
69
 
70 572 jeremybenn
/* Tick Timer Interrupt handler */
71
void vTickHandler( void );
72
 
73
/* Setup the timer to generate the tick interrupts. */
74
static void prvSetupTimerInterrupt( void );
75
 
76
/* For writing into SPR. */
77 675 filepang
static inline void mtspr(unsigned long spr, unsigned long value)
78
{
79 572 jeremybenn
        asm("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
80
}
81
 
82
/* For reading SPR. */
83 675 filepang
static inline unsigned long mfspr(unsigned long spr)
84
{
85 572 jeremybenn
        unsigned long value;
86
        asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
87
        return value;
88
}
89
 
90 675 filepang
/* forward decleation */
91
inline void vPortDisableInterrupts( void );
92
inline void vPortEnableInterrupts( void );
93 572 jeremybenn
 
94
/*
95
 * Initialise the stack of a task to look exactly as if a call to
96 675 filepang
 * portSAVE_CONTEXT had been called. Context layout is described in
97
 * portmarco.h
98 572 jeremybenn
 *
99
 * See header file for description.
100
 */
101
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
102
{
103 664 filepang
        unsigned portLONG uTaskSR = mfspr(SPR_SR);
104
        uTaskSR |= SPR_SR_SM;                                           // Supervisor mode
105
        uTaskSR |= (SPR_SR_TEE | SPR_SR_IEE);           // Tick interrupt enable, All External interupt enable
106 675 filepang
 
107
        // allocate redzone     
108
        pxTopOfStack -= REDZONE_SIZE/4;
109 572 jeremybenn
 
110
        /* Setup the initial stack of the task.  The stack is set exactly as
111
        expected by the portRESTORE_CONTEXT() macro. */
112
        *(--pxTopOfStack) = (portSTACK_TYPE)pxCode;                     // SPR_EPCR_BASE(0)
113
        *(--pxTopOfStack) = (portSTACK_TYPE)uTaskSR;            // SPR_ESR_BASE(0) 
114
 
115
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000031;         // r31
116
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000030;         // r30
117
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000029;         // r29
118
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000028;         // r28
119
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000027;         // r27
120
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000026;         // r26
121
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000025;         // r25
122
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000024;         // r24
123
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000023;         // r23
124
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000022;         // r22
125
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000021;         // r21
126
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000020;         // r20
127
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000019;         // r19
128
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000018;         // r18
129
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000017;         // r17
130
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000016;         // r16
131
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000015;         // r15
132
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000014;         // r14
133
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000013;         // r13
134
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000012;         // r12
135
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000011;         // r11
136
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000010;         // r10
137
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000008;         // r8
138
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000007;         // r7
139
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000006;         // r6
140
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000005;         // r5
141
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000004;         // r4
142
        *(--pxTopOfStack) = (portSTACK_TYPE)pvParameters;       // task argument
143
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000002;         // r2
144
        *(--pxTopOfStack) = (portSTACK_TYPE)pxCode;                     // PC
145
 
146
        return pxTopOfStack;
147
}
148
 
149
portBASE_TYPE xPortStartScheduler( void )
150
{
151 621 filepang
        if(setjmp((void *)jmpbuf) == 0) {
152
                /* Start the timer that generates the tick ISR.  Interrupts are disabled
153
                here already. */
154
                prvSetupTimerInterrupt();
155 572 jeremybenn
 
156 621 filepang
                /* Start the first task. */
157 675 filepang
                asm volatile (
158
                " .global       pxCurrentTCB    \n\t"
159
                /*   restore stack pointer              */
160
                "   l.movhi     r3, hi(pxCurrentTCB)            \n\t"
161
                "   l.ori       r3, r3, lo(pxCurrentTCB)        \n\t"
162
                "   l.lwz       r3, 0x0(r3)             \n\t"
163
                "   l.lwz       r1, 0x0(r3)             \n\t"
164
                /*   restore context                    */
165
                "   l.lwz       r9,  0x00(r1)   \n\t"
166
                "   l.lwz       r2,  0x04(r1)   \n\t"
167
                "   l.lwz       r6,  0x14(r1)   \n\t"
168
                "   l.lwz       r7,  0x18(r1)   \n\t"
169
                "   l.lwz       r8,  0x1C(r1)   \n\t"
170
                "   l.lwz       r10, 0x20(r1)   \n\t"
171
                "   l.lwz       r11, 0x24(r1)   \n\t"
172
                "   l.lwz       r12, 0x28(r1)   \n\t"
173
                "   l.lwz       r13, 0x2C(r1)   \n\t"
174
                "   l.lwz       r14, 0x30(r1)   \n\t"
175
                "   l.lwz       r15, 0x34(r1)   \n\t"
176
                "   l.lwz       r16, 0x38(r1)   \n\t"
177
                "   l.lwz       r17, 0x3C(r1)   \n\t"
178
                "   l.lwz       r18, 0x40(r1)   \n\t"
179
                "   l.lwz       r19, 0x44(r1)   \n\t"
180
                "   l.lwz       r20, 0x48(r1)   \n\t"
181
                "   l.lwz       r21, 0x4C(r1)   \n\t"
182
                "   l.lwz       r22, 0x50(r1)   \n\t"
183
                "   l.lwz       r23, 0x54(r1)   \n\t"
184
                "   l.lwz       r24, 0x58(r1)   \n\t"
185
                "   l.lwz       r25, 0x5C(r1)   \n\t"
186
                "   l.lwz       r26, 0x60(r1)   \n\t"
187
                "   l.lwz       r27, 0x64(r1)   \n\t"
188
                "   l.lwz       r28, 0x68(r1)   \n\t"
189
                "   l.lwz       r29, 0x6C(r1)   \n\t"
190
                "   l.lwz       r30, 0x70(r1)   \n\t"
191
                "   l.lwz       r31, 0x74(r1)   \n\t"
192
                /*  restore SPR_ESR_BASE(0), SPR_EPCR_BASE(0) */
193
                "   l.lwz       r3,  0x78(r1)   \n\t"
194
                "   l.lwz       r4,  0x7C(r1)   \n\t"
195
                "   l.mtspr     r0,  r3, %1             \n\t"
196
                "   l.mtspr     r0,  r4, %2             \n\t"
197
                /*   restore clobber register     */
198
                "   l.lwz       r3,  0x08(r1)   \n\t"
199
                "   l.lwz       r4,  0x0C(r1)   \n\t"
200
                "   l.lwz       r5,  0x10(r1)   \n\t"
201
                "   l.addi      r1,  r1, %0             \n\t"
202
                "   l.rfe                       \n\t"
203
                "   l.nop                       \n\t"
204
                :
205
                :       "n"(STACKFRAME_SIZE),
206
                        "n"(SPR_ESR_BASE),
207
                        "n"(SPR_EPCR_BASE)
208
                );
209 621 filepang
 
210
                /* Should not get here! */
211
        } else {
212
                /* Retrun by vPortEndScheduler */
213
        }
214
 
215 572 jeremybenn
        return 0;
216
}
217
 
218
void vPortEndScheduler( void )
219
{
220
        mtspr(SPR_SR, mfspr(SPR_SR) & (~SPR_SR_TEE));   // Tick stop
221 621 filepang
        longjmp((void *)jmpbuf, 1);                                             // return to xPortStartScheduler
222 572 jeremybenn
}
223
 
224
/*
225
 * Setup the tick timer to generate the tick interrupts at the required frequency.
226
 */
227
static void prvSetupTimerInterrupt( void )
228
{
229
        const unsigned portLONG ulTickPeriod = configCPU_CLOCK_HZ / configTICK_RATE_HZ;
230
 
231
        // Disable tick timer exception recognition 
232
        mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE);
233
 
234
        // clears interrupt
235
        mtspr(SPR_TTMR, mfspr(SPR_TTMR) & ~(SPR_TTMR_IP));
236
 
237
        // Set period of one cycle, restartable mode 
238
        mtspr(SPR_TTMR, SPR_TTMR_IE | SPR_TTMR_RT | (ulTickPeriod & SPR_TTMR_PERIOD));
239
 
240
        // Reset counter 
241
        mtspr(SPR_TTCR, 0);
242
 
243
    // set OR1200 to accept exceptions
244
    mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_TEE);
245
}
246
 
247 675 filepang
inline void vPortDisableInterrupts( void )
248
{
249
        mtspr(SPR_SR, mfspr(SPR_SR) & ~(SPR_SR_TEE|SPR_SR_IEE));        // Tick, interrupt stop
250
}
251
 
252
inline void vPortEnableInterrupts( void )
253
{
254
        mtspr(SPR_SR, mfspr(SPR_SR) | (SPR_SR_TEE|SPR_SR_IEE));         // Tick, interrupt start
255
}
256
 
257 621 filepang
/*
258
 * naked attribute is ignored or32-elf-gcc 4.5.1-or32-1.0rc1
259
 * use assemble routines in portasm.S
260
 */
261 572 jeremybenn
#if 0
262
void vTickHandler( void )
263
{
264
        // clears interrupt
265
        mtspr(SPR_TTMR, mfspr(SPR_TTMR) & ~(SPR_TTMR_IP));
266
 
267
        /* Increment the RTOS tick count, then look for the highest priority
268
           task that is ready to run. */
269
        vTaskIncrementTick();
270
 
271
        // The cooperative scheduler requires a normal simple Tick ISR to
272
        // simply increment the system tick.
273
#if configUSE_PREEMPTION == 0
274
        // nothing to do here
275
#else
276
        /* Save the context of the current task. */
277
        portSAVE_CONTEXT();
278
 
279
        /* Find the highest priority task that is ready to run. */
280
        vTaskSwitchContext();
281
 
282
        portRESTORE_CONTEXT();
283
#endif
284
}
285
#endif

powered by: WebSVN 2.1.0

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