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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Source/] [portable/] [GCC/] [NiosII/] [port.c] - Blame information for rev 582

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 NIOS2 port.
56
 *----------------------------------------------------------*/
57
 
58
/* Standard Includes. */
59
#include <string.h>
60
#include <errno.h>
61
 
62
/* Altera includes. */
63
#include "sys/alt_irq.h"
64
#include "altera_avalon_timer_regs.h"
65
#include "priv/alt_irq_table.h"
66
 
67
/* Scheduler includes. */
68
#include "FreeRTOS.h"
69
#include "task.h"
70
 
71
/* Interrupts are enabled. */
72
#define portINITIAL_ESTATUS     ( portSTACK_TYPE ) 0x01 
73
 
74
/*-----------------------------------------------------------*/
75
 
76
/*
77
 * Setup the timer to generate the tick interrupts.
78
 */
79
static void prvSetupTimerInterrupt( void );
80
 
81
/*
82
 * Call back for the alarm function.
83
 */
84
void vPortSysTickHandler( void * context, alt_u32 id );
85
 
86
/*-----------------------------------------------------------*/
87
 
88
void prvReadGp( unsigned long *ulValue )
89
{
90
        asm( "stw gp, (r4) " );
91
};
92
/*-----------------------------------------------------------*/
93
 
94
/*
95
 * See header file for description.
96
 */
97
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
98
{
99
portSTACK_TYPE *pxFramePointer = pxTopOfStack - 1;
100
portSTACK_TYPE xGlobalPointer;
101
 
102
    prvReadGp( &xGlobalPointer );
103
 
104
    /* End of stack marker. */
105
    *pxTopOfStack = 0xdeadbeef;
106
    pxTopOfStack--;
107
 
108
    *pxTopOfStack = ( portSTACK_TYPE ) pxFramePointer;
109
    pxTopOfStack--;
110
 
111
    *pxTopOfStack = xGlobalPointer;
112
 
113
    /* Space for R23 to R16. */
114
    pxTopOfStack -= 9;
115
 
116
    *pxTopOfStack = ( portSTACK_TYPE ) pxCode;
117
    pxTopOfStack--;
118
 
119
    *pxTopOfStack = portINITIAL_ESTATUS;
120
 
121
    /* Space for R15 to R5. */
122
    pxTopOfStack -= 12;
123
 
124
    *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;
125
 
126
    /* Space for R3 to R1, muldiv and RA. */
127
    pxTopOfStack -= 5;
128
 
129
    return pxTopOfStack;
130
}
131
/*-----------------------------------------------------------*/
132
 
133
/*
134
 * See header file for description.
135
 */
136
portBASE_TYPE xPortStartScheduler( void )
137
{
138
        /* Start the timer that generates the tick ISR.  Interrupts are disabled
139
        here already. */
140
        prvSetupTimerInterrupt();
141
 
142
        /* Start the first task. */
143
    asm volatile (  " movia r2, restore_sp_from_pxCurrentTCB        \n"
144
                    " jmp r2                                          " );
145
 
146
        /* Should not get here! */
147
        return 0;
148
}
149
/*-----------------------------------------------------------*/
150
 
151
void vPortEndScheduler( void )
152
{
153
        /* It is unlikely that the NIOS2 port will require this function as there
154
        is nothing to return to.  */
155
}
156
/*-----------------------------------------------------------*/
157
 
158
/*
159
 * Setup the systick timer to generate the tick interrupts at the required
160
 * frequency.
161
 */
162
void prvSetupTimerInterrupt( void )
163
{
164
        /* Try to register the interrupt handler. */
165
        if ( -EINVAL == alt_irq_register( SYS_CLK_IRQ, 0x0, vPortSysTickHandler ) )
166
        {
167
                /* Failed to install the Interrupt Handler. */
168
                asm( "break" );
169
        }
170
        else
171
        {
172
                /* Configure SysTick to interrupt at the requested rate. */
173
                IOWR_ALTERA_AVALON_TIMER_CONTROL( SYS_CLK_BASE, ALTERA_AVALON_TIMER_CONTROL_STOP_MSK );
174
                IOWR_ALTERA_AVALON_TIMER_PERIODL( SYS_CLK_BASE, ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) & 0xFFFF );
175
                IOWR_ALTERA_AVALON_TIMER_PERIODH( SYS_CLK_BASE, ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) >> 16 );
176
                IOWR_ALTERA_AVALON_TIMER_CONTROL( SYS_CLK_BASE, ALTERA_AVALON_TIMER_CONTROL_CONT_MSK | ALTERA_AVALON_TIMER_CONTROL_START_MSK | ALTERA_AVALON_TIMER_CONTROL_ITO_MSK );
177
        }
178
 
179
        /* Clear any already pending interrupts generated by the Timer. */
180
        IOWR_ALTERA_AVALON_TIMER_STATUS( SYS_CLK_BASE, ~ALTERA_AVALON_TIMER_STATUS_TO_MSK );
181
}
182
/*-----------------------------------------------------------*/
183
 
184
void vPortSysTickHandler( void * context, alt_u32 id )
185
{
186
        /* Increment the Kernel Tick. */
187
        vTaskIncrementTick();
188
 
189
        /* If using preemption, also force a context switch. */
190
        #if configUSE_PREEMPTION == 1
191
        vTaskSwitchContext();
192
        #endif
193
 
194
        /* Clear the interrupt. */
195
        IOWR_ALTERA_AVALON_TIMER_STATUS( SYS_CLK_BASE, ~ALTERA_AVALON_TIMER_STATUS_TO_MSK );
196
}
197
/*-----------------------------------------------------------*/
198
 
199
/** This function is a re-implementation of the Altera provided function.
200
 * The function is re-implemented to prevent it from enabling an interrupt
201
 * when it is registered. Interrupts should only be enabled after the FreeRTOS.org
202
 * kernel has its scheduler started so that contexts are saved and switched
203
 * correctly.
204
 */
205
int alt_irq_register( alt_u32 id, void* context, void (*handler)(void*, alt_u32) )
206
{
207
        int rc = -EINVAL;
208
        alt_irq_context status;
209
 
210
        if (id < ALT_NIRQ)
211
        {
212
                /*
213
                 * interrupts are disabled while the handler tables are updated to ensure
214
                 * that an interrupt doesn't occur while the tables are in an inconsistent
215
                 * state.
216
                 */
217
 
218
                status = alt_irq_disable_all ();
219
 
220
                alt_irq[id].handler = handler;
221
                alt_irq[id].context = context;
222
 
223
                rc = (handler) ? alt_irq_enable (id): alt_irq_disable (id);
224
 
225
                /* alt_irq_enable_all(status); This line is removed to prevent the interrupt from being immediately enabled. */
226
        }
227
 
228
        return rc;
229
}
230
/*-----------------------------------------------------------*/
231
 

powered by: WebSVN 2.1.0

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