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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Source/] [portable/] [IAR/] [ARM_CM3/] [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
        Change from V4.2.1:
56
 
57
        + Introduced usage of configKERNEL_INTERRUPT_PRIORITY macro to set the
58
          interrupt priority used by the kernel.
59
*/
60
 
61
/*-----------------------------------------------------------
62
 * Implementation of functions defined in portable.h for the ARM CM3 port.
63
 *----------------------------------------------------------*/
64
 
65
/* Scheduler includes. */
66
#include "FreeRTOS.h"
67
#include "task.h"
68
 
69
/* Constants required to manipulate the NVIC. */
70
#define portNVIC_SYSTICK_CTRL           ( ( volatile unsigned long *) 0xe000e010 )
71
#define portNVIC_SYSTICK_LOAD           ( ( volatile unsigned long *) 0xe000e014 )
72
#define portNVIC_INT_CTRL                       ( ( volatile unsigned long *) 0xe000ed04 )
73
#define portNVIC_SYSPRI2                        ( ( volatile unsigned long *) 0xe000ed20 )
74
#define portNVIC_SYSTICK_CLK            0x00000004
75
#define portNVIC_SYSTICK_INT            0x00000002
76
#define portNVIC_SYSTICK_ENABLE         0x00000001
77
#define portNVIC_PENDSVSET                      0x10000000
78
#define portNVIC_PENDSV_PRI                     ( ( ( unsigned long ) configKERNEL_INTERRUPT_PRIORITY ) << 16 )
79
#define portNVIC_SYSTICK_PRI            ( ( ( unsigned long ) configKERNEL_INTERRUPT_PRIORITY ) << 24 )
80
 
81
/* Constants required to set up the initial stack. */
82
#define portINITIAL_XPSR                        ( 0x01000000 )
83
 
84
/* For backward compatibility, ensure configKERNEL_INTERRUPT_PRIORITY is
85
defined.  The value 255 should also ensure backward compatibility.
86
FreeRTOS.org versions prior to V4.3.0 did not include this definition. */
87
#ifndef configKERNEL_INTERRUPT_PRIORITY
88
        #define configKERNEL_INTERRUPT_PRIORITY 0
89
#endif
90
 
91
/* Each task maintains its own interrupt status in the critical nesting
92
variable. */
93
static unsigned portBASE_TYPE uxCriticalNesting = 0xaaaaaaaa;
94
 
95
/*
96
 * Setup the timer to generate the tick interrupts.
97
 */
98
static void prvSetupTimerInterrupt( void );
99
 
100
/*
101
 * Exception handlers.
102
 */
103
void xPortSysTickHandler( void );
104
 
105
/*
106
 * Start first task is a separate function so it can be tested in isolation.
107
 */
108
extern void vPortStartFirstTask( void );
109
 
110
/*-----------------------------------------------------------*/
111
 
112
/*
113
 * See header file for description.
114
 */
115
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
116
{
117
        /* Simulate the stack frame as it would be created by a context switch
118
        interrupt. */
119
        pxTopOfStack--; /* Offset added to account for the way the MCU uses the stack on entry/exit of interrupts. */
120
        *pxTopOfStack = portINITIAL_XPSR;       /* xPSR */
121
        pxTopOfStack--;
122
        *pxTopOfStack = ( portSTACK_TYPE ) pxCode;      /* PC */
123
        pxTopOfStack--;
124
        *pxTopOfStack = 0;       /* LR */
125
        pxTopOfStack -= 5;      /* R12, R3, R2 and R1. */
126
        *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;        /* R0 */
127
        pxTopOfStack -= 8;      /* R11, R10, R9, R8, R7, R6, R5 and R4. */
128
 
129
        return pxTopOfStack;
130
}
131
/*-----------------------------------------------------------*/
132
 
133
/*
134
 * See header file for description.
135
 */
136
portBASE_TYPE xPortStartScheduler( void )
137
{
138
        /* Make PendSV and SysTick the lowest priority interrupts. */
139
        *(portNVIC_SYSPRI2) |= portNVIC_PENDSV_PRI;
140
        *(portNVIC_SYSPRI2) |= portNVIC_SYSTICK_PRI;
141
 
142
        /* Start the timer that generates the tick ISR.  Interrupts are disabled
143
        here already. */
144
        prvSetupTimerInterrupt();
145
 
146
        /* Initialise the critical nesting count ready for the first task. */
147
        uxCriticalNesting = 0;
148
 
149
        /* Start the first task. */
150
        vPortStartFirstTask();
151
 
152
        /* Should not get here! */
153
        return 0;
154
}
155
/*-----------------------------------------------------------*/
156
 
157
void vPortEndScheduler( void )
158
{
159
        /* It is unlikely that the CM3 port will require this function as there
160
        is nothing to return to.  */
161
}
162
/*-----------------------------------------------------------*/
163
 
164
void vPortYieldFromISR( void )
165
{
166
        /* Set a PendSV to request a context switch. */
167
        *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET;
168
}
169
/*-----------------------------------------------------------*/
170
 
171
void vPortEnterCritical( void )
172
{
173
        portDISABLE_INTERRUPTS();
174
        uxCriticalNesting++;
175
}
176
/*-----------------------------------------------------------*/
177
 
178
void vPortExitCritical( void )
179
{
180
        uxCriticalNesting--;
181
        if( uxCriticalNesting == 0 )
182
        {
183
                portENABLE_INTERRUPTS();
184
        }
185
}
186
/*-----------------------------------------------------------*/
187
 
188
void xPortSysTickHandler( void )
189
{
190
unsigned long ulDummy;
191
 
192
        /* If using preemption, also force a context switch. */
193
        #if configUSE_PREEMPTION == 1
194
                *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET;
195
        #endif
196
 
197
        ulDummy = portSET_INTERRUPT_MASK_FROM_ISR();
198
        {
199
                vTaskIncrementTick();
200
        }
201
        portCLEAR_INTERRUPT_MASK_FROM_ISR( ulDummy );
202
}
203
/*-----------------------------------------------------------*/
204
 
205
/*
206
 * Setup the systick timer to generate the tick interrupts at the required
207
 * frequency.
208
 */
209
void prvSetupTimerInterrupt( void )
210
{
211
        /* Configure SysTick to interrupt at the requested rate. */
212
        *(portNVIC_SYSTICK_LOAD) = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
213
        *(portNVIC_SYSTICK_CTRL) = portNVIC_SYSTICK_CLK | portNVIC_SYSTICK_INT | portNVIC_SYSTICK_ENABLE;
214
}
215
/*-----------------------------------------------------------*/
216
 

powered by: WebSVN 2.1.0

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