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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [arch/] [current/] [include/] [hal_io.h] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_HAL_IO_H
2
#define CYGONCE_HAL_IO_H
3
 
4
//=============================================================================
5
//
6
//      hal_io.h
7
//
8
//      HAL device IO register support.
9
//
10
//=============================================================================
11
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
12
// -------------------------------------------                              
13
// This file is part of eCos, the Embedded Configurable Operating System.   
14
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
15
//
16
// eCos is free software; you can redistribute it and/or modify it under    
17
// the terms of the GNU General Public License as published by the Free     
18
// Software Foundation; either version 2 or (at your option) any later      
19
// version.                                                                 
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT      
22
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
24
// for more details.                                                        
25
//
26
// You should have received a copy of the GNU General Public License        
27
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
28
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
29
//
30
// As a special exception, if other files instantiate templates or use      
31
// macros or inline functions from this file, or you compile this file      
32
// and link it with other works to produce a work based on this file,       
33
// this file does not by itself cause the resulting work to be covered by   
34
// the GNU General Public License. However the source code for this file    
35
// must still be made available in accordance with section (3) of the GNU   
36
// General Public License v2.                                               
37
//
38
// This exception does not invalidate any other reasons why a work based    
39
// on this file might be covered by the GNU General Public License.         
40
// -------------------------------------------                              
41
// ####ECOSGPLCOPYRIGHTEND####                                              
42
//=============================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):    nickg, gthomas
46
// Contributors: Fabrice Gautier
47
// Date:         1998-09-11
48
// Purpose:      Define IO register support
49
// Description:  The macros defined here provide the HAL APIs for handling
50
//               device IO control registers.
51
//              
52
// Usage:
53
//               #include <cyg/hal/hal_io.h>
54
//               ...
55
//              
56
//
57
//####DESCRIPTIONEND####
58
//
59
//=============================================================================
60
 
61
#include <pkgconf/system.h>
62
#include <cyg/infra/cyg_type.h>
63
 
64
#include <cyg/hal/basetype.h>
65
 
66
//-----------------------------------------------------------------------------
67
// Include plf_io.h for platforms. Either via var_io.h or directly.
68
#ifdef CYGBLD_HAL_ARM_VAR_IO_H
69
#include <cyg/hal/var_io.h>
70
#else
71
#include <cyg/hal/plf_io.h>
72
#endif
73
 
74
 
75
//-----------------------------------------------------------------------------
76
// IO Register address.
77
// This type is for recording the address of an IO register.
78
 
79
typedef volatile CYG_ADDRWORD HAL_IO_REGISTER;
80
 
81
//-----------------------------------------------------------------------------
82
// HAL IO macros.
83
#ifndef HAL_IO_MACROS_DEFINED
84
 
85
//-----------------------------------------------------------------------------
86
// BYTE Register access.
87
// Individual and vectorized access to 8 bit registers.
88
 
89
// Little-endian version or big-endian version that doesn't need address munging
90
#if (CYG_BYTEORDER == CYG_LSBFIRST) || defined(HAL_IO_MACROS_NO_ADDRESS_MUNGING)
91
 
92
#define HAL_READ_UINT8( _register_, _value_ ) \
93
        ((_value_) = *((volatile CYG_BYTE *)(_register_)))
94
 
95
#define HAL_WRITE_UINT8( _register_, _value_ ) \
96
        (*((volatile CYG_BYTE *)(_register_)) = (_value_))
97
 
98
#define HAL_READ_UINT8_VECTOR( _register_, _buf_, _count_, _step_ )     \
99
    CYG_MACRO_START                                                     \
100
    cyg_count32 _i_,_j_;                                                \
101
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
102
        (_buf_)[_i_] = ((volatile CYG_BYTE *)(_register_))[_j_];        \
103
    CYG_MACRO_END
104
 
105
#define HAL_WRITE_UINT8_VECTOR( _register_, _buf_, _count_, _step_ )    \
106
    CYG_MACRO_START                                                     \
107
    cyg_count32 _i_,_j_;                                                \
108
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
109
        ((volatile CYG_BYTE *)(_register_))[_j_] = (_buf_)[_i_];        \
110
    CYG_MACRO_END
111
 
112
#define HAL_READ_UINT8_STRING( _register_, _buf_, _count_ )             \
113
    CYG_MACRO_START                                                     \
114
    cyg_count32 _i_;                                                    \
115
    for( _i_ = 0; _i_ < (_count_); _i_++)                               \
116
        (_buf_)[_i_] = ((volatile CYG_BYTE *)(_register_))[_i_];        \
117
    CYG_MACRO_END
118
 
119
#define HAL_WRITE_UINT8_STRING( _register_, _buf_, _count_ )            \
120
    CYG_MACRO_START                                                     \
121
    cyg_count32 _i_;                                                    \
122
    for( _i_ = 0; _i_ < (_count_); _i_++)                               \
123
        ((volatile CYG_BYTE *)(_register_)) = (_buf_)[_i_];             \
124
    CYG_MACRO_END
125
 
126
#else // Big-endian version
127
 
128
#define HAL_READ_UINT8( _register_, _value_ ) \
129
        ((_value_) = *((volatile CYG_BYTE *)((CYG_ADDRWORD)(_register_)^3)))
130
 
131
#define HAL_WRITE_UINT8( _register_, _value_ ) \
132
        (*((volatile CYG_BYTE *)((CYG_ADDRWORD)(_register_)^3)) = (_value_))
133
 
134
#define HAL_READ_UINT8_VECTOR( _register_, _buf_, _count_, _step_ )     \
135
    CYG_MACRO_START                                                     \
136
    cyg_count32 _i_,_j_;                                                \
137
    volatile CYG_BYTE* _r_ = ((CYG_ADDRWORD)(_register_)^3);            \
138
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
139
        (_buf_)[_i_] = _r_[_j_];                                        \
140
    CYG_MACRO_END
141
 
142
#define HAL_WRITE_UINT8_VECTOR( _register_, _buf_, _count_, _step_ )    \
143
    CYG_MACRO_START                                                     \
144
    cyg_count32 _i_,_j_;                                                \
145
    volatile CYG_BYTE* _r_ = ((CYG_ADDRWORD)(_register_)^3);            \
146
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
147
        _r_[_j_] = (_buf_)[_i_];                                        \
148
    CYG_MACRO_END
149
 
150
#define HAL_READ_UINT8_STRING( _register_, _buf_, _count_ )             \
151
    CYG_MACRO_START                                                     \
152
    cyg_count32 _i_;                                                    \
153
    volatile CYG_BYTE* _r_ = ((CYG_ADDRWORD)(_register_)^3);            \
154
    for( _i_ = 0; _i_ < (_count_); _i_++;                               \
155
        (_buf_)[_i_] = _r_[_i_];                                        \
156
    CYG_MACRO_END
157
 
158
#define HAL_WRITE_UINT8_STRING( _register_, _buf_, _count_ )            \
159
    CYG_MACRO_START                                                     \
160
    cyg_count32 _i_;                                                    \
161
    volatile CYG_BYTE* _r_ = ((CYG_ADDRWORD)(_register_)^3);            \
162
    for( _i_ = 0; _i_ < (_count_); _i_++)                               \
163
        _r_[_i_] = (_buf_)[_i_];                                        \
164
    CYG_MACRO_END
165
 
166
#endif // Big-endian
167
 
168
//-----------------------------------------------------------------------------
169
// 16 bit access.
170
// Individual and vectorized access to 16 bit registers.
171
 
172
// Little-endian version or big-endian version that doesn't need address munging
173
#if (CYG_BYTEORDER == CYG_LSBFIRST) || defined(HAL_IO_MACROS_NO_ADDRESS_MUNGING)
174
 
175
#define HAL_READ_UINT16( _register_, _value_ ) \
176
        ((_value_) = *((volatile CYG_WORD16 *)(_register_)))
177
 
178
#define HAL_WRITE_UINT16( _register_, _value_ ) \
179
        (*((volatile CYG_WORD16 *)(_register_)) = (_value_))
180
 
181
#define HAL_READ_UINT16_VECTOR( _register_, _buf_, _count_, _step_ )    \
182
    CYG_MACRO_START                                                     \
183
    cyg_count32 _i_,_j_;                                                \
184
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
185
        (_buf_)[_i_] = ((volatile CYG_WORD16 *)(_register_))[_j_];      \
186
    CYG_MACRO_END
187
 
188
#define HAL_WRITE_UINT16_VECTOR( _register_, _buf_, _count_, _step_ )   \
189
    CYG_MACRO_START                                                     \
190
    cyg_count32 _i_,_j_;                                                \
191
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
192
        ((volatile CYG_WORD16 *)(_register_))[_j_] = (_buf_)[_i_];      \
193
    CYG_MACRO_END
194
 
195
#define HAL_READ_UINT16_STRING( _register_, _buf_, _count_)             \
196
    CYG_MACRO_START                                                     \
197
    cyg_count32 _i_;                                                    \
198
    for( _i_ = 0; _i_ < (_count_); _i_++)                               \
199
        (_buf_)[_i_] = ((volatile CYG_WORD16 *)(_register_))[_i_];      \
200
    CYG_MACRO_END
201
 
202
#define HAL_WRITE_UINT16_STRING( _register_, _buf_, _count_)            \
203
    CYG_MACRO_START                                                     \
204
    cyg_count32 _i_;                                                    \
205
    for( _i_ = 0; _i_ < (_count_); _i_++)                               \
206
        ((volatile CYG_WORD16 *)(_register_))[_i_] = (_buf_)[_i_];      \
207
    CYG_MACRO_END
208
 
209
 
210
#else // Big-endian version
211
 
212
#define HAL_READ_UINT16( _register_, _value_ ) \
213
        ((_value_) = *((volatile CYG_WORD16 *)((CYG_ADDRWORD)(_register_)^3)))
214
 
215
#define HAL_WRITE_UINT16( _register_, _value_ ) \
216
        (*((volatile CYG_WORD16 *)((CYG_ADDRWORD)(_register_)^3)) = (_value_))
217
 
218
#define HAL_READ_UINT16_VECTOR( _register_, _buf_, _count_, _step_ )    \
219
    CYG_MACRO_START                                                     \
220
    cyg_count32 _i_,_j_;                                                \
221
    volatile CYG_WORD16* _r_ = ((CYG_ADDRWORD)(_register_)^3);          \
222
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
223
        (_buf_)[_i_] = _r_[_j_];                                        \
224
    CYG_MACRO_END
225
 
226
#define HAL_WRITE_UINT16_VECTOR( _register_, _buf_, _count_, _step_ )   \
227
    CYG_MACRO_START                                                     \
228
    cyg_count32 _i_,_j_;                                                \
229
    volatile CYG_WORD16* _r_ = ((CYG_ADDRWORD)(_register_)^3);          \
230
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
231
        _r_[_j_] = (_buf_)[_i_];                                        \
232
    CYG_MACRO_END
233
 
234
#define HAL_READ_UINT16_STRING( _register_, _buf_, _count_)             \
235
    CYG_MACRO_START                                                     \
236
    cyg_count32 _i_;                                                    \
237
    volatile CYG_WORD16* _r_ = ((CYG_ADDRWORD)(_register_)^3);          \
238
    for( _i_ = 0 = 0; _i_ < (_count_); _i_++)                           \
239
        (_buf_)[_i_] = _r_[_i_];                                        \
240
    CYG_MACRO_END
241
 
242
#define HAL_WRITE_UINT16_STRING( _register_, _buf_, _count_)            \
243
    CYG_MACRO_START                                                     \
244
    cyg_count32 _i_;                                                    \
245
    volatile CYG_WORD16* _r_ = ((CYG_ADDRWORD)(_register_)^3);          \
246
    for( _i_ = 0 = 0; _i_ < (_count_); _i_++)                           \
247
        _r_[_i_] = (_buf_)[_i_];                                        \
248
    CYG_MACRO_END
249
 
250
 
251
#endif // Big-endian
252
 
253
//-----------------------------------------------------------------------------
254
// 32 bit access.
255
// Individual and vectorized access to 32 bit registers.
256
 
257
// Note: same macros for little- and big-endian systems.
258
 
259
#define HAL_READ_UINT32( _register_, _value_ ) \
260
        ((_value_) = *((volatile CYG_WORD32 *)(_register_)))
261
 
262
#define HAL_WRITE_UINT32( _register_, _value_ ) \
263
        (*((volatile CYG_WORD32 *)(_register_)) = (_value_))
264
 
265
#define HAL_READ_UINT32_VECTOR( _register_, _buf_, _count_, _step_ )    \
266
    CYG_MACRO_START                                                     \
267
    cyg_count32 _i_,_j_;                                                \
268
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
269
        (_buf_)[_i_] = ((volatile CYG_WORD32 *)(_register_))[_j_];      \
270
    CYG_MACRO_END
271
 
272
#define HAL_WRITE_UINT32_VECTOR( _register_, _buf_, _count_, _step_ )   \
273
    CYG_MACRO_START                                                     \
274
    cyg_count32 _i_,_j_;                                                \
275
    for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
276
        ((volatile CYG_WORD32 *)(_register_))[_j_] = (_buf_)[_i_];      \
277
    CYG_MACRO_END
278
 
279
#define HAL_READ_UINT32_STRING( _register_, _buf_, _count_)             \
280
    CYG_MACRO_START                                                     \
281
    cyg_count32 _i_;                                                    \
282
    for( _i_ = 0; _i_ < (_count_); _i_++)                               \
283
        (_buf_)[_i_] = ((volatile CYG_WORD32 *)(_register_))[_i_];      \
284
    CYG_MACRO_END
285
 
286
#define HAL_WRITE_UINT32_STRING( _register_, _buf_, _count_)            \
287
    CYG_MACRO_START                                                     \
288
    cyg_count32 _i_;                                                    \
289
    for( _i_ = 0; _i_ < (_count_); _i_++)                               \
290
        ((volatile CYG_WORD32 *)(_register_))[_i_] = (_buf_)[_i_];      \
291
    CYG_MACRO_END
292
 
293
 
294
#define HAL_IO_MACROS_DEFINED
295
 
296
#endif // !HAL_IO_MACROS_DEFINED
297
 
298
// Enforce a flow "barrier" to prevent optimizing compiler from reordering 
299
// operations.
300
#define HAL_IO_BARRIER()
301
 
302
//-----------------------------------------------------------------------------
303
#endif // ifndef CYGONCE_HAL_IO_H
304
// End of hal_io.h

powered by: WebSVN 2.1.0

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