OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [machine/] [or32/] [or1k-support.c] - Blame information for rev 517

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 517 julius
/* or1k-support - OR1K CPU support functions
2
 
3
   Copyright (C) 2011, ORSoC AB
4
 
5
   Contributor Julius Baxter  <julius.baxter@orsoc.se>
6
 
7
   This file is part of Newlib.
8
 
9
   This program is free software; you can redistribute it and/or modify it
10
   under the terms of the GNU General Public License as published by the Free
11
   Software Foundation; either version 3 of the License, or (at your option)
12
   any later version.
13
 
14
   This program is distributed in the hope that it will be useful, but WITHOUT
15
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
17
   more details.
18
 
19
   You should have received a copy of the GNU General Public License along
20
   with this program.  If not, see <http://www.gnu.org/licenses/>.            */
21
 
22
#include "or1k-newlib-support.h"
23
#include "spr-defs.h"
24
 
25
/* Board-specific CPU clk HZ value */
26
extern unsigned long _board_clk_freq;
27
 
28
/* Tick timer variable */
29
volatile unsigned long or1k_timer_ticks;
30
 
31
/* Tick rate storage */
32
unsigned long or1k_timer_period;
33
 
34
 
35
/* --------------------------------------------------------------------------*/
36
/*!Report a 32-bit value
37
 
38
   Uses the built-in simulator functionality.
39
 
40
   @param[in] value  Value to report.                                        */
41
/* --------------------------------------------------------------------------*/
42
void
43
or1k_report (unsigned long int  value)
44
{
45
  __asm__ __volatile__ ("l.addi\tr3,%0,0\n\t"
46
                        "l.nop %1": : "r" (value), "K" (NOP_REPORT));
47
 
48
}       /* report () */
49
 
50
/* --------------------------------------------------------------------------*/
51
/*!Write a SPR
52
 
53
   @todo Surely the SPR should be a short int, since it is only 16-bits. Left
54
         as is for now due to large amount of user code that might need
55
         changing.
56
 
57
   @param[in] spr    The SPR to write
58
   @param[in] value  The value to write to the SPR                           */
59
/* --------------------------------------------------------------------------*/
60
void
61
or1k_mtspr (unsigned long int  spr,
62
       unsigned long int  value)
63
{
64
  __asm__ __volatile__ ("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
65
 
66
}       /* mtspr () */
67
 
68
/* --------------------------------------------------------------------------*/
69
/*!Read a SPR
70
 
71
   @todo Surely the SPR should be a short int, since it is only 16-bits. Left
72
         as is for now due to large amount of user code that might need
73
         changing.
74
 
75
   @param[in] spr    The SPR to write
76
 
77
   @return  The value read from the SPR                                      */
78
/* --------------------------------------------------------------------------*/
79
unsigned long int
80
or1k_mfspr (unsigned long spr)
81
{
82
  unsigned long value;
83
 
84
  __asm__ __volatile__ ("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
85
 
86
  return value;
87
 
88
}       /* mfspr () */
89
 
90
/* --------------------------------------------------------------------------*/
91
/*!Pseudo-random number generator
92
 
93
   This should return pseudo-random numbers, based on a Galois LFSR
94
 
95
   @return The next pseudo-random number                                     */
96
/* --------------------------------------------------------------------------*/
97
unsigned long int
98
or1k_rand ()
99
{
100
  static unsigned long int lfsr = 1;
101
  static int period = 0;
102
  /* taps: 32 31 29 1; characteristic polynomial: x^32 + x^31 + x^29 + x + 1 */
103
  lfsr = (lfsr >> 1) ^ (unsigned long int)((0 - (lfsr & 1u)) & 0xd0000001u);
104
  ++period;
105
  return lfsr;
106
}
107
 
108
 
109
/* --------------------------------------------------------------------------*/
110
/*!Tick timer interrupt handler
111
 
112
   Increment timer ticks counter, reload TTMR
113
                                                                             */
114
/* --------------------------------------------------------------------------*/
115
void
116
or1k_timer_interrupt_handler(void)
117
{
118
  or1k_timer_ticks++;
119
  or1k_mtspr(SPR_TTMR, SPR_TTMR_IE | SPR_TTMR_RT |
120
        (or1k_timer_period & SPR_TTMR_PERIOD));
121
}
122
 
123
/* --------------------------------------------------------------------------*/
124
/*!Enable tick timer
125
 
126
   Install handler, calculate TTMR period, reset tick counter
127
 
128
   @param[in] hz     Rate at which to trigger timer ticks                    */
129
/* --------------------------------------------------------------------------*/
130
void
131
or1k_timer_init(unsigned int hz)
132
{
133
 
134
  /* Set this, for easy access when reloading */
135
  or1k_timer_period = _board_clk_freq/hz;
136
 
137
  /* Reset timer tick counter */
138
  or1k_timer_ticks = 0;
139
 
140
  /* Install handler */
141
  or1k_exception_handler_add(0x5,or1k_timer_interrupt_handler);
142
 
143
}
144
 
145
/* --------------------------------------------------------------------------*/
146
/*!Enable tick timer
147
 
148
   Enable timer interrupt, install handler, load TTMR
149
                                                                             */
150
/* --------------------------------------------------------------------------*/
151
void
152
or1k_timer_enable(void)
153
{
154
  or1k_mtspr(SPR_TTMR, SPR_TTMR_IE | SPR_TTMR_RT |
155
        (or1k_timer_period & SPR_TTMR_PERIOD));
156
  or1k_mtspr(SPR_SR, SPR_SR_TEE | or1k_mfspr(SPR_SR));
157
 
158
}
159
 
160
/* --------------------------------------------------------------------------*/
161
/*!Disable tick timer
162
 
163
   Disable timer interrupt in SR
164
                                                                             */
165
/* --------------------------------------------------------------------------*/
166
void
167
or1k_timer_disable(void)
168
{
169
   or1k_mtspr(SPR_SR, ~SPR_SR_TEE & or1k_mfspr(SPR_SR));
170
}
171
 
172
/* --------------------------------------------------------------------------*/
173
/*!Get tick timer
174
 
175
   Return value of tick timer
176
                                                                             */
177
/* --------------------------------------------------------------------------*/
178
unsigned long
179
or1k_timer_get_ticks(void)
180
{
181
  return or1k_timer_ticks;
182
}
183
 
184
/* --------------------------------------------------------------------------*/
185
/*!Reset tick timer
186
 
187
   Clear value of tick timer
188
                                                                             */
189
/* --------------------------------------------------------------------------*/
190
void
191
or1k_timer_reset_ticks(void)
192
{
193
  or1k_timer_ticks = 0;
194
}
195
 
196
 
197
 

powered by: WebSVN 2.1.0

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