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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Source/] [portable/] [Paradigm/] [Tern_EE/] [large_untested/] [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
 
55
/*-----------------------------------------------------------
56
 * Implementation of functions defined in portable.h for the Tern EE 186
57
 * port.
58
 *----------------------------------------------------------*/
59
 
60
/* Library includes. */
61
#include <embedded.h>
62
#include <ae.h>
63
 
64
/* Scheduler includes. */
65
#include "FreeRTOS.h"
66
#include "task.h"
67
#include "portasm.h"
68
 
69
/* The timer increments every four clocks, hence the divide by 4. */
70
#define portTIMER_COMPARE ( unsigned short ) ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) / ( unsigned long ) 4 )
71
 
72
/* From the RDC data sheet. */
73
#define portENABLE_TIMER_AND_INTERRUPT ( unsigned short ) 0xe001
74
 
75
/* Interrupt control. */
76
#define portEIO_REGISTER 0xff22
77
#define portCLEAR_INTERRUPT 0x0008
78
 
79
/* Setup the hardware to generate the required tick frequency. */
80
static void prvSetupTimerInterrupt( void );
81
 
82
/* The ISR used depends on whether the preemptive or cooperative scheduler
83
is being used. */
84
#if( configUSE_PREEMPTION == 1 )
85
        /* Tick service routine used by the scheduler when preemptive scheduling is
86
        being used. */
87
        static void __interrupt __far prvPreemptiveTick( void );
88
#else
89
        /* Tick service routine used by the scheduler when cooperative scheduling is
90
        being used. */
91
        static void __interrupt __far prvNonPreemptiveTick( void );
92
#endif
93
 
94
/* Trap routine used by taskYIELD() to manually cause a context switch. */
95
static void __interrupt __far prvYieldProcessor( void );
96
 
97
/* The timer initialisation functions leave interrupts enabled,
98
which is not what we want.  This ISR is installed temporarily in case
99
the timer fires before we get a change to disable interrupts again. */
100
static void __interrupt __far prvDummyISR( void );
101
 
102
/*-----------------------------------------------------------*/
103
/* See header file for description. */
104
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
105
{
106
portSTACK_TYPE DS_Reg = 0;
107
 
108
        /* Place a few bytes of known values on the bottom of the stack.
109
        This is just useful for debugging. */
110
 
111
        *pxTopOfStack = 0x1111;
112
        pxTopOfStack--;
113
        *pxTopOfStack = 0x2222;
114
        pxTopOfStack--;
115
        *pxTopOfStack = 0x3333;
116
        pxTopOfStack--;
117
 
118
        /* We are going to start the scheduler using a return from interrupt
119
        instruction to load the program counter, so first there would be the
120
        function call with parameters preamble. */
121
 
122
        *pxTopOfStack = FP_SEG( pvParameters );
123
        pxTopOfStack--;
124
        *pxTopOfStack = FP_OFF( pvParameters );
125
        pxTopOfStack--;
126
        *pxTopOfStack = FP_SEG( pxCode );
127
        pxTopOfStack--;
128
        *pxTopOfStack = FP_OFF( pxCode );
129
        pxTopOfStack--;
130
 
131
        /* Next the status register and interrupt return address. */
132
        *pxTopOfStack = portINITIAL_SW;
133
        pxTopOfStack--;
134
        *pxTopOfStack = FP_SEG( pxCode );
135
        pxTopOfStack--;
136
        *pxTopOfStack = FP_OFF( pxCode );
137
        pxTopOfStack--;
138
 
139
        /* The remaining registers would be pushed on the stack by our context
140
        switch function.  These are loaded with values simply to make debugging
141
        easier. */
142
        *pxTopOfStack = ( portSTACK_TYPE ) 0xAAAA;      /* AX */
143
        pxTopOfStack--;
144
        *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BX */
145
        pxTopOfStack--;
146
        *pxTopOfStack = ( portSTACK_TYPE ) 0xCCCC;      /* CX */
147
        pxTopOfStack--;
148
        *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DX */
149
        pxTopOfStack--;
150
        *pxTopOfStack = ( portSTACK_TYPE ) 0xEEEE;      /* ES */
151
        pxTopOfStack--;
152
 
153
        /* We need the true data segment. */
154
        __asm{  MOV DS_Reg, DS };
155
 
156
        *pxTopOfStack = DS_Reg;                                         /* DS */
157
        pxTopOfStack--;
158
        *pxTopOfStack = ( portSTACK_TYPE ) 0x0123;      /* SI */
159
        pxTopOfStack--;
160
        *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DI */
161
        pxTopOfStack--;
162
        *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BP */
163
 
164
        return pxTopOfStack;
165
}
166
/*-----------------------------------------------------------*/
167
 
168
portBASE_TYPE xPortStartScheduler( void )
169
{
170
        /* This is called with interrupts already disabled. */
171
 
172
        /* Put our manual switch (yield) function on a known
173
        vector. */
174
        setvect( portSWITCH_INT_NUMBER, prvYieldProcessor );
175
 
176
        /* Setup the tick interrupt. */
177
        prvSetupTimerInterrupt();
178
 
179
        /* Kick off the scheduler by setting up the context of the first task. */
180
        portFIRST_CONTEXT();
181
 
182
        /* Should not get here! */
183
        return pdFALSE;
184
}
185
/*-----------------------------------------------------------*/
186
 
187
static void __interrupt __far prvDummyISR( void )
188
{
189
        /* The timer initialisation functions leave interrupts enabled,
190
        which is not what we want.  This ISR is installed temporarily in case
191
        the timer fires before we get a change to disable interrupts again. */
192
        outport( portEIO_REGISTER, portCLEAR_INTERRUPT );
193
}
194
/*-----------------------------------------------------------*/
195
 
196
/* The ISR used depends on whether the preemptive or cooperative scheduler
197
is being used. */
198
#if( configUSE_PREEMPTION == 1 )
199
        static void __interrupt __far prvPreemptiveTick( void )
200
        {
201
                /* Get the scheduler to update the task states following the tick. */
202
                vTaskIncrementTick();
203
 
204
                /* Switch in the context of the next task to be run. */
205
                portSWITCH_CONTEXT();
206
 
207
                /* Reset interrupt. */
208
                outport( portEIO_REGISTER, portCLEAR_INTERRUPT );
209
        }
210
#else
211
        static void __interrupt __far prvNonPreemptiveTick( void )
212
        {
213
                /* Same as preemptive tick, but the cooperative scheduler is being used
214
                so we don't have to switch in the context of the next task. */
215
                vTaskIncrementTick();
216
                /* Reset interrupt. */
217
                outport( portEIO_REGISTER, portCLEAR_INTERRUPT );
218
        }
219
#endif
220
/*-----------------------------------------------------------*/
221
 
222
static void __interrupt __far prvYieldProcessor( void )
223
{
224
        /* Switch in the context of the next task to be run. */
225
        portSWITCH_CONTEXT();
226
}
227
/*-----------------------------------------------------------*/
228
 
229
void vPortEndScheduler( void )
230
{
231
        /* Not implemented. */
232
}
233
/*-----------------------------------------------------------*/
234
 
235
static void prvSetupTimerInterrupt( void )
236
{
237
const unsigned short usTimerACompare = portTIMER_COMPARE, usTimerAMode = portENABLE_TIMER_AND_INTERRUPT;
238
const unsigned short usT2_IRQ = 0x13;
239
 
240
        /* Configure the timer, the dummy handler is used here as the init
241
        function leaves interrupts enabled. */
242
        t2_init( usTimerAMode, usTimerACompare, prvDummyISR );
243
 
244
        /* Disable interrupts again before installing the real handlers. */
245
        portDISABLE_INTERRUPTS();
246
 
247
        #if( configUSE_PREEMPTION == 1 )
248
                /* Tick service routine used by the scheduler when preemptive scheduling is
249
                being used. */
250
                setvect( usT2_IRQ, prvPreemptiveTick );
251
        #else
252
                /* Tick service routine used by the scheduler when cooperative scheduling is
253
                being used. */
254
                setvect( usT2_IRQ, prvNonPreemptiveTick );
255
        #endif
256
}
257
 
258
 
259
 
260
 
261
 
262
 
263
 

powered by: WebSVN 2.1.0

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