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 612

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

powered by: WebSVN 2.1.0

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