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 669

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

powered by: WebSVN 2.1.0

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