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 665

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
/*-----------------------------------------------------------
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
static inline void mtspr(unsigned long spr, unsigned long value) {
78
        asm("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
79
}
80
 
81
/* For reading SPR. */
82
static inline unsigned long mfspr(unsigned long spr) {
83
        unsigned long value;
84
        asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
85
        return value;
86
}
87
 
88 664 filepang
inline void vPortDisableInterrupts( void )
89 572 jeremybenn
{
90 664 filepang
        mtspr(SPR_SR, mfspr(SPR_SR) & ~(SPR_SR_TEE|SPR_SR_IEE));        // Tick, interrupt stop
91 665 filepang
        // mtspr(SPR_SR, mfspr(SPR_SR) & ~(SPR_SR_IEE));        // interrupt stop
92
        // mtspr(SPR_SR, mfspr(SPR_SR) & ~(SPR_SR_TEE));        // interrupt stop
93 572 jeremybenn
}
94
 
95 664 filepang
inline void vPortEnableInterrupts( void )
96 572 jeremybenn
{
97 664 filepang
        mtspr(SPR_SR, mfspr(SPR_SR) | (SPR_SR_TEE|SPR_SR_IEE));         // Tick, interrupt start
98 665 filepang
        //mtspr(SPR_SR, mfspr(SPR_SR) | (SPR_SR_IEE));          // interrupt start
99 572 jeremybenn
}
100
 
101
 
102
/*
103
 * Initialise the stack of a task to look exactly as if a call to
104
 * portSAVE_CONTEXT had been called.
105
 *
106
 * See header file for description.
107
 */
108
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
109
{
110 664 filepang
        unsigned portLONG uTaskSR = mfspr(SPR_SR);
111
        uTaskSR |= SPR_SR_SM;                                           // Supervisor mode
112
        uTaskSR |= (SPR_SR_TEE | SPR_SR_IEE);           // Tick interrupt enable, All External interupt enable
113 572 jeremybenn
 
114
        /* Setup the initial stack of the task.  The stack is set exactly as
115
        expected by the portRESTORE_CONTEXT() macro. */
116
        *(--pxTopOfStack) = (portSTACK_TYPE)pxCode;                     // SPR_EPCR_BASE(0)
117
        *(--pxTopOfStack) = (portSTACK_TYPE)uTaskSR;            // SPR_ESR_BASE(0) 
118
 
119
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000031;         // r31
120
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000030;         // r30
121
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000029;         // r29
122
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000028;         // r28
123
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000027;         // r27
124
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000026;         // r26
125
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000025;         // r25
126
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000024;         // r24
127
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000023;         // r23
128
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000022;         // r22
129
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000021;         // r21
130
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000020;         // r20
131
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000019;         // r19
132
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000018;         // r18
133
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000017;         // r17
134
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000016;         // r16
135
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000015;         // r15
136
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000014;         // r14
137
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000013;         // r13
138
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000012;         // r12
139
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000011;         // r11
140
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000010;         // r10
141
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000008;         // r8
142
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000007;         // r7
143
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000006;         // r6
144
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000005;         // r5
145
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000004;         // r4
146
        *(--pxTopOfStack) = (portSTACK_TYPE)pvParameters;       // task argument
147
        *(--pxTopOfStack) = (portSTACK_TYPE)0x00000002;         // r2
148
        *(--pxTopOfStack) = (portSTACK_TYPE)pxCode;                     // PC
149
 
150
        return pxTopOfStack;
151
}
152
 
153
portBASE_TYPE xPortStartScheduler( void )
154
{
155 621 filepang
        if(setjmp((void *)jmpbuf) == 0) {
156
                /* Start the timer that generates the tick ISR.  Interrupts are disabled
157
                here already. */
158
                prvSetupTimerInterrupt();
159 572 jeremybenn
 
160 621 filepang
                /* Start the first task. */
161
                portRESTORE_CONTEXT();
162
 
163
                /* Should not get here! */
164
        } else {
165
                /* Retrun by vPortEndScheduler */
166
        }
167
 
168 572 jeremybenn
        return 0;
169
}
170
 
171
void vPortEndScheduler( void )
172
{
173
        mtspr(SPR_SR, mfspr(SPR_SR) & (~SPR_SR_TEE));   // Tick stop
174 621 filepang
        longjmp((void *)jmpbuf, 1);                                             // return to xPortStartScheduler
175 572 jeremybenn
}
176
 
177
/*
178
 * Setup the tick timer to generate the tick interrupts at the required frequency.
179
 */
180
static void prvSetupTimerInterrupt( void )
181
{
182
        const unsigned portLONG ulTickPeriod = configCPU_CLOCK_HZ / configTICK_RATE_HZ;
183
 
184
        // Disable tick timer exception recognition 
185
        mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE);
186
 
187
        // clears interrupt
188
        mtspr(SPR_TTMR, mfspr(SPR_TTMR) & ~(SPR_TTMR_IP));
189
 
190
        // Set period of one cycle, restartable mode 
191
        mtspr(SPR_TTMR, SPR_TTMR_IE | SPR_TTMR_RT | (ulTickPeriod & SPR_TTMR_PERIOD));
192
 
193
        // Reset counter 
194
        mtspr(SPR_TTCR, 0);
195
 
196
    // set OR1200 to accept exceptions
197
    mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_TEE);
198
}
199
 
200 621 filepang
/*
201
 * naked attribute is ignored or32-elf-gcc 4.5.1-or32-1.0rc1
202
 * use assemble routines in portasm.S
203
 */
204 572 jeremybenn
#if 0
205
void vTickHandler( void )
206
{
207
        // clears interrupt
208
        mtspr(SPR_TTMR, mfspr(SPR_TTMR) & ~(SPR_TTMR_IP));
209
 
210
        /* Increment the RTOS tick count, then look for the highest priority
211
           task that is ready to run. */
212
        vTaskIncrementTick();
213
 
214
        // The cooperative scheduler requires a normal simple Tick ISR to
215
        // simply increment the system tick.
216
#if configUSE_PREEMPTION == 0
217
        // nothing to do here
218
#else
219
        /* Save the context of the current task. */
220
        portSAVE_CONTEXT();
221
 
222
        /* Find the highest priority task that is ready to run. */
223
        vTaskSwitchContext();
224
 
225
        portRESTORE_CONTEXT();
226
#endif
227
}
228
#endif

powered by: WebSVN 2.1.0

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