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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ucos-ii/] [2.91/] [ucos-port/] [os_cpu_c.c] - Blame information for rev 541

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 471 julius
/*
2
  ----------------------------------------------------------------------
3
  CHiPES Embedded RTR   Systems Copyright (c) Tim Oliver 2002-2004
4
  ----------------------------------------------------------------------
5
  File   :      os_cpu_c.c
6
  Author : Tim Oliver
7
  Email  : timtimoliver@yahoo.co.uk
8
  ---------------------------[Description]------------------------------
9
 
10
  uC/OS-II
11
  The Real-Time Kernel
12
 
13
  (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
14
  All Rights Reserved
15
 
16
  OpenCores OpenRISC
17
 
18
  Inline NOP ORP simulator functions :
19
  void exit (int i) - simulator exit point
20
  void report(unsigned long value) - simulator report messaging
21
 
22
  Internal Routines :
23
  void mtspr(unsigned long spr, unsigned long vakye) -  Move To SPR
24
  unsigned long mfspr(unsigned long spr) -  Move From SPR
25
  OS_CPU_SR OSDisableInterrupts (void)
26
  void OSEnableInterrupts(OS_CPU_SR cpu_sr)
27
  void OSInitTick(void)
28
  void putc (char c) - standard output patch to UART
29
  int getc () - standard input patch to UART
30
  int testc () - check for character received by UART
31
  int ctrlc () - check for control-C received by UART
32
  For OS Routines see descriptions below
33
 
34
*/
35
 
36
/*
37
  This program is free software; you can redistribute it and/or modify
38
  it under the terms of the GNU General Public License as published by
39
  the Free Software Foundation; either version 2 of the License, or
40
  (at your option) any later version.
41
 
42
  This program is distributed in the hope that it will be useful,
43
  but WITHOUT ANY WARRANTY; without even the implied warranty of
44
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
45
  GNU General Public License for more details.
46
 
47
  You should have received a copy of the GNU General Public License
48
  along with this program; if not, write to the Free Software
49
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
50
*/
51
 
52
#define  OS_CPU_GLOBALS
53
#include "includes.h"
54
 
55
/* return value by making a syscall */
56
void exit (int i)
57
{
58
  asm("l.add r3,r0,%0": : "r" (i));
59
  asm("l.nop %0": :"K" (NOP_EXIT));
60
  while (1);
61
}
62
 
63
/* print long */
64
void report(unsigned long value)
65
{
66
  asm("l.addi\tr3,%0,0": :"r" (value));
67
  asm("l.nop %0": :"K" (NOP_REPORT));
68
}
69
 
70
/* For writing into SPR. */
71
void mtspr(unsigned long spr, unsigned long value)
72
{
73
  asm("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
74
}
75
 
76
/* For reading SPR. */
77
unsigned long mfspr(unsigned long spr)
78
{
79
  unsigned long value;
80
  asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
81
  return value;
82
}
83
 
84
#if      OS_CRITICAL_METHOD == 3
85
OS_CPU_SR OSDisableInterrupts (void)
86
{
87
  OS_CPU_SR cpu_sr;
88
 
89
  cpu_sr = mfspr(SPR_SR);
90
  mtspr(SPR_SR, cpu_sr & ~(SPR_SR_IEE | SPR_SR_TEE));
91
  return cpu_sr;
92
}
93
 
94
void OSEnableInterrupts(OS_CPU_SR cpu_sr)
95
{
96
  mtspr(SPR_SR, cpu_sr); /* | (SPR_SR_IEE | SPR_SR_TEE)*/
97
}
98
 
99
#endif
100
 
101
void OSInitTick(void)
102
{
103
  /* Enable tick interrupts in supervisor register */
104
  mtspr(SPR_SR, SPR_SR_TEE | mfspr(SPR_SR));
105
  /* Set tick timer to restart on match, and set interrupt enable, and set period depending on clock
106
     frequency and desired tick rate */
107
  mtspr(SPR_TTMR, SPR_TTMR_IE | SPR_TTMR_RT | ((IN_CLK/TICKS_PER_SEC) & SPR_TTMR_PERIOD));
108
}
109
 
110
/* stdio patches */
111
void putc (char c) {
112
  OS_CPU_SR cpu_sr;
113
 
114
  OS_ENTER_CRITICAL()
115
    uart_putc (c);
116
  OS_EXIT_CRITICAL()
117
}
118
 
119
int getc () {
120
 
121
  return uart_getc ();
122
}
123
 
124
 
125
int testc () {
126
 
127
  return uart_testc ();
128
}
129
 
130
int ctrlc ()
131
{
132
  if (testc ()) {
133
    switch (getc ()) {
134
    case 0x03:    /* ^C - Control C */
135
      return 1;
136
    default:
137
      break;
138
    }
139
  }
140
  return 0;
141
}
142
 
143
/*
144
*********************************************************************************************************
145
*                                       OS INITIALIZATION HOOK
146
*                                            (BEGINNING)
147
*
148
* Description: This function is called by OSInit() at the beginning of OSInit().
149
*
150
* Arguments  : none
151
*
152
* Note(s)    : 1) Interrupts should be disabled during this call.
153
*********************************************************************************************************
154
*/
155
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
156
void  OSInitHookBegin (void)
157
{
158
 
159
  uart_init();
160
 
161
#ifdef __TFP_PRINTF__
162
  init_printf(NULL,putc);
163
#endif
164
 
165
  return;
166
 
167
}
168
#endif
169
 
170
/*
171
*********************************************************************************************************
172
*                                       OS INITIALIZATION HOOK
173
*                                               (END)
174
*
175
* Description: This function is called by OSInit() at the end of OSInit().
176
*
177
* Arguments  : none
178
*
179
* Note(s)    : 1) Interrupts should be disabled during this call.
180
*********************************************************************************************************
181
*/
182
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
183
void  OSInitHookEnd (void)
184
{
185
}
186
#endif
187
 
188
/*$PAGE*/
189
/*
190
*********************************************************************************************************
191
*                                          TASK CREATION HOOK
192
*
193
* Description: This function is called when a task is created.
194
*
195
* Arguments  : ptcb   is a pointer to the task control block of the task being created.
196
*
197
* Note(s)    : 1) Interrupts are disabled during this call.
198
*********************************************************************************************************
199
*/
200
#if OS_CPU_HOOKS_EN > 0
201
void  OSTaskCreateHook (OS_TCB *ptcb)
202
{
203
  ptcb = ptcb;                       /* Prevent compiler warning                                     */
204
}
205
#endif
206
 
207
 
208
/*
209
*********************************************************************************************************
210
*                                           TASK DELETION HOOK
211
*
212
* Description: This function is called when a task is deleted.
213
*
214
* Arguments  : ptcb   is a pointer to the task control block of the task being deleted.
215
*
216
* Note(s)    : 1) Interrupts are disabled during this call.
217
*********************************************************************************************************
218
*/
219
#if OS_CPU_HOOKS_EN > 0
220
void  OSTaskDelHook (OS_TCB *ptcb)
221
{
222
  ptcb = ptcb;                       /* Prevent compiler warning                                     */
223
}
224
#endif
225
 
226
/*
227
*********************************************************************************************************
228
*                                             IDLE TASK HOOK
229
*
230
* Description: This function is called by the idle task.  This hook has been added to allow you to do
231
*              such things as STOP the CPU to conserve power.
232
*
233
* Arguments  : none
234
*
235
* Note(s)    : 1) Interrupts are enabled during this call.
236
*********************************************************************************************************
237
*/
238
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION >= 251
239
void  OSTaskIdleHook (void)
240
{
241
  /* printf("\nEntering idle task"); */
242
}
243
#endif
244
 
245
/*
246
*********************************************************************************************************
247
*                                           STATISTIC TASK HOOK
248
*
249
* Description: This function is called every second by uC/OS-II's statistics task.  This allows your
250
*              application to add functionality to the statistics task.
251
*
252
* Arguments  : none
253
*********************************************************************************************************
254
*/
255
 
256
#if OS_CPU_HOOKS_EN > 0
257
void  OSTaskStatHook (void)
258
{
259
}
260
#endif
261
 
262
/*$PAGE*/
263
/*
264
*********************************************************************************************************
265
*                                        INITIALIZE A TASK'S STACK
266
*
267
* Description: This function is called by either OSTaskCreate() or OSTaskCreateExt() to initialize the
268
*              stack frame of the task being created.  This function is highly processor specific.
269
*
270
* Arguments  : task          is a pointer to the task code
271
*
272
*              pdata         is a pointer to a user supplied data area that will be passed to the task
273
*                            when the task first executes.
274
*
275
*              ptos          is a pointer to the top of stack.  It is assumed that 'ptos' points to
276
*                            a 'free' entry on the task stack.  If OS_STK_GROWTH is set to 1 then
277
*                            'ptos' will contain the HIGHEST valid address of the stack.  Similarly, if
278
*                            OS_STK_GROWTH is set to 0, the 'ptos' will contains the LOWEST valid address
279
*                            of the stack.
280
*
281
*              opt           specifies options that can be used to alter the behavior of OSTaskStkInit().
282
*                            (see uCOS_II.H for OS_TASK_OPT_???).
283
*
284
* Returns    : Always returns the location of the new top-of-stack' once the processor registers have
285
*              been placed on the stack in the proper order.
286
*
287
*********************************************************************************************************
288
*/
289
 
290 525 julius
OS_STK  *OSTaskStkInit (void (*task)(void *pd), void *pdata, OS_STK *ptos,
291
                        INT16U opt)
292 471 julius
{
293
  OS_STK *stk;
294
  OS_STK *fp;
295 541 julius
  INT32U  sr;
296 471 julius
 
297
#ifdef DEBUG
298
  printf("\nCreating Stack at %x for task %x", ptos, task);
299
#endif
300
 
301 541 julius
  sr     = mfspr(SPR_SR);
302 471 julius
  opt    = opt;                           /* 'opt' is not used, prevent warning */
303
  stk    = ptos;                          /* Load stack pointer */
304 525 julius
  stk    -=32;                            /* Skip over red zone, 32 words */
305 471 julius
  stk--;
306
 
307
  *stk-- = (OS_STK)(pdata);               /* fp+0 -> parameter 0    */
308
  fp     = stk;
309
  *stk-- = (OS_STK)fp;                    /* sp+4 -> previous fp    */
310
  *stk-- = (INT32U)0;                     /* sp+0 -> return address */
311
 
312
  *stk-- = (INT32U)31;                     /* r31 = 0  */
313
  *stk-- = (INT32U)30;                     /* r30 = 0  */
314
  *stk-- = (INT32U)29;                     /* r29 = 0  */
315
  *stk-- = (INT32U)28;                     /* r28 = 0  */
316
  *stk-- = (INT32U)27;                     /* r27 = 0  */
317
  *stk-- = (INT32U)26;                     /* r26 = 0  */
318
  *stk-- = (INT32U)25;                     /* r25 = 0  */
319
  *stk-- = (INT32U)24;                     /* r24 = 0  */
320
  *stk-- = (INT32U)23;                     /* r23 = 0  */
321
  *stk-- = (INT32U)22;                     /* r22 = 0  */
322
  *stk-- = (INT32U)21;                     /* r21 = 0  */
323
  *stk-- = (INT32U)20;                     /* r20 = 0  */
324
  *stk-- = (INT32U)19;                     /* r19 = 0  */
325
  *stk-- = (INT32U)18;                     /* r18 = 0  */
326
  *stk-- = (INT32U)17;                     /* r17 = 0  */
327
  *stk-- = (INT32U)16;                     /* r16 = 0  */
328
  *stk-- = (INT32U)15;                     /* r15 = 0  */
329
  *stk-- = (INT32U)14;                     /* r14 = 0  */
330
  *stk-- = (INT32U)13;                     /* r13 = 0  */
331
  *stk-- = (INT32U)12;                     /* r12 = 0  */
332
  *stk-- = (INT32U)11;                     /* r11 = 0 return value      */
333
  *stk-- = (INT32U)10;                     /* r10 = 0                   */
334
  *stk-- = (INT32U)9;                     /* r09 = 0 link register     */
335
  *stk-- = (INT32U)8;                     /* r08 = 0 function paramters*/
336
  *stk-- = (INT32U)7;                     /* r07 = 0                   */
337
  *stk-- = (INT32U)6;                     /* r06 = 0                   */
338
  *stk-- = (INT32U)5;                     /* r05 = 0                   */
339
  *stk-- = (INT32U)4;                     /* r04 = 0                   */
340
  *stk-- = (OS_STK)(pdata);               /* r03 = arg0                */
341
  *stk-- = (OS_STK)fp;                    /* r02 = frame pointer       */
342 541 julius
                                          /* supervision register      */
343
  *stk-- = (INT32U)(SPR_SR_IEE | SPR_SR_TEE | SPR_SR_SM |
344
             (sr & (SPR_SR_ICE | SPR_SR_DCE)));
345 471 julius
  *stk   = (OS_STK)(task);                /* program counter           */
346
 
347
  return ((OS_STK *)stk);                 /* sp gets saved in TCB      */
348
}
349
 
350
 
351
/*$PAGE*/
352
/*
353
*********************************************************************************************************
354
*                                           TASK SWITCH HOOK
355
*
356
* Description: This function is called when a task switch is performed.  This allows you to perform other
357
*              operations during a context switch.
358
*
359
* Arguments  : none
360
*
361
* Note(s)    : 1) Interrupts are disabled during this call.
362
*              2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
363
*                 will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
364
*                 task being switched out (i.e. the preempted task).
365
*********************************************************************************************************
366
*/
367
#if OS_CPU_HOOKS_EN > 0
368
void  OSTaskSwHook (void)
369
{
370
  /* printf("\nTask Switching\n"); */
371
}
372
#endif
373
 
374
/*
375
*********************************************************************************************************
376
*                                           OSTCBInit() HOOK
377
*
378
* Description: This function is called by OS_TCBInit() after setting up most of the TCB.
379
*
380
* Arguments  : ptcb    is a pointer to the TCB of the task being created.
381
*
382
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
383
*********************************************************************************************************
384
*/
385
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
386
void  OSTCBInitHook (OS_TCB *ptcb)
387
{
388
  ptcb = ptcb;                                           /* Prevent Compiler warning                 */
389
}
390
#endif
391
 
392
 
393
/*
394
*********************************************************************************************************
395
*                                               TICK HOOK
396
*
397
* Description: This function is called every tick.
398
*
399
* Arguments  : none
400
*
401
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
402
*********************************************************************************************************
403
*/
404
#if OS_CPU_HOOKS_EN > 0
405
void  OSTimeTickHook (void)
406
{
407
}
408
#endif
409
 
410
 
411
void          OSTaskReturnHook        (OS_TCB          *ptcb)
412
{
413
  /* do nothing for now */
414
  return;
415
}

powered by: WebSVN 2.1.0

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