|
0
|
1 #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 //####COPYRIGHTBEGIN#### |
|
|
12 // |
|
|
13 // ------------------------------------------- |
|
|
14 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
15 // Version 1.0 (the "License"); you may not use this file except in |
|
|
16 // compliance with the License. You may obtain a copy of the License at |
|
|
17 // http://sourceware.cygnus.com/ecos |
|
|
18 // |
|
|
19 // Software distributed under the License is distributed on an "AS IS" |
|
|
20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
21 // License for the specific language governing rights and limitations under |
|
|
22 // the License. |
|
|
23 // |
|
|
24 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
25 // September 30, 1998. |
|
|
26 // |
|
|
27 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
28 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
29 // ------------------------------------------- |
|
|
30 // |
|
|
31 //####COPYRIGHTEND#### |
|
|
32 //============================================================================= |
|
|
33 //#####DESCRIPTIONBEGIN#### |
|
|
34 // |
|
|
35 // Author(s): nickg |
|
|
36 // Contributors: nickg |
|
|
37 // Date: 1998-02-17 |
|
|
38 // Purpose: Define IO register support |
|
|
39 // Description: The macros defined here provide the HAL APIs for handling |
|
|
40 // device IO control registers. |
|
|
41 // |
|
|
42 // Usage: |
|
|
43 // #include <cyg/hal/hal_io.h> |
|
|
44 // ... |
|
|
45 // |
|
|
46 // |
|
|
47 //####DESCRIPTIONEND#### |
|
|
48 // |
|
|
49 //============================================================================= |
|
|
50 |
|
|
51 #include <cyg/infra/cyg_type.h> |
|
|
52 |
|
|
53 //----------------------------------------------------------------------------- |
|
|
54 // Enforce in-order IO for all HAL reads/writes using this macro. |
|
|
55 #define HAL_IO_BARRIER() \ |
|
2
|
56 asm volatile ( "eieio" : : : "memory" ) |
|
0
|
57 |
|
|
58 //----------------------------------------------------------------------------- |
|
|
59 // IO Register address. |
|
|
60 // This type is for recording the address of an IO register. |
|
|
61 |
|
|
62 typedef volatile CYG_ADDRWORD HAL_IO_REGISTER; |
|
|
63 |
|
|
64 //----------------------------------------------------------------------------- |
|
|
65 // BYTE Register access. |
|
|
66 // Individual and vectorized access to 8 bit registers. |
|
|
67 |
|
2
|
68 #define HAL_READ_UINT8( _register_, _value_ ) \ |
|
|
69 CYG_MACRO_START \ |
|
|
70 ((_value_) = *((volatile CYG_BYTE *)(_register_))); \ |
|
|
71 HAL_IO_BARRIER (); \ |
|
|
72 CYG_MACRO_END |
|
0
|
73 |
|
2
|
74 #define HAL_WRITE_UINT8( _register_, _value_ ) \ |
|
|
75 CYG_MACRO_START \ |
|
|
76 (*((volatile CYG_BYTE *)(_register_)) = (_value_)); \ |
|
|
77 HAL_IO_BARRIER (); \ |
|
|
78 CYG_MACRO_END |
|
0
|
79 |
|
|
80 #define HAL_READ_UINT8_VECTOR( _register_, _buf_, _count_, _step_ ) \ |
|
|
81 CYG_MACRO_START \ |
|
|
82 cyg_count32 _i_,_j_; \ |
|
|
83 for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) { \ |
|
|
84 (_buf_)[_i_] = ((volatile CYG_BYTE *)(_register_))[_j_]; \ |
|
|
85 HAL_IO_BARRIER (); \ |
|
|
86 } \ |
|
|
87 CYG_MACRO_END |
|
|
88 |
|
|
89 #define HAL_WRITE_UINT8_VECTOR( _register_, _buf_, _count_, _step_ ) \ |
|
|
90 CYG_MACRO_START \ |
|
|
91 cyg_count32 _i_,_j_; \ |
|
|
92 for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) { \ |
|
|
93 ((volatile CYG_BYTE *)(_register_))[_j_] = (_buf_)[_i_]; \ |
|
|
94 HAL_IO_BARRIER (); \ |
|
|
95 } \ |
|
|
96 CYG_MACRO_END |
|
|
97 |
|
|
98 |
|
|
99 //----------------------------------------------------------------------------- |
|
|
100 // 16 bit access. |
|
|
101 // Individual and vectorized access to 16 bit registers. |
|
|
102 |
|
|
103 #define HAL_READ_UINT16( _register_, _value_ ) \ |
|
2
|
104 CYG_MACRO_START \ |
|
|
105 ((_value_) = *((volatile CYG_WORD16 *)(_register_))); \ |
|
|
106 HAL_IO_BARRIER (); \ |
|
|
107 CYG_MACRO_END |
|
0
|
108 |
|
|
109 #define HAL_WRITE_UINT16( _register_, _value_ ) \ |
|
2
|
110 CYG_MACRO_START \ |
|
|
111 (*((volatile CYG_WORD16 *)(_register_)) = (_value_)); \ |
|
|
112 HAL_IO_BARRIER (); \ |
|
|
113 CYG_MACRO_END |
|
0
|
114 |
|
|
115 #define HAL_READ_UINT16_VECTOR( _register_, _buf_, _count_, _step_ ) \ |
|
|
116 CYG_MACRO_START \ |
|
|
117 cyg_count32 _i_,_j_; \ |
|
|
118 for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) { \ |
|
|
119 (_buf_)[_i_] = ((volatile CYG_WORD16 *)(_register_))[_j_]; \ |
|
|
120 HAL_IO_BARRIER (); \ |
|
|
121 } \ |
|
|
122 CYG_MACRO_END |
|
|
123 |
|
|
124 #define HAL_WRITE_UINT16_VECTOR( _register_, _buf_, _count_, _step_ ) \ |
|
|
125 CYG_MACRO_START \ |
|
|
126 cyg_count32 _i_,_j_; \ |
|
|
127 for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) { \ |
|
|
128 ((volatile CYG_WORD16 *)(_register_))[_j_] = (_buf_)[_i_]; \ |
|
|
129 HAL_IO_BARRIER (); \ |
|
|
130 } \ |
|
|
131 CYG_MACRO_END |
|
|
132 |
|
|
133 //----------------------------------------------------------------------------- |
|
|
134 // 32 bit access. |
|
|
135 // Individual and vectorized access to 32 bit registers. |
|
|
136 |
|
|
137 #define HAL_READ_UINT32( _register_, _value_ ) \ |
|
2
|
138 CYG_MACRO_START \ |
|
|
139 ((_value_) = *((volatile CYG_WORD32 *)(_register_))); \ |
|
|
140 HAL_IO_BARRIER (); \ |
|
|
141 CYG_MACRO_END |
|
0
|
142 |
|
|
143 #define HAL_WRITE_UINT32( _register_, _value_ ) \ |
|
2
|
144 CYG_MACRO_START \ |
|
|
145 (*((volatile CYG_WORD32 *)(_register_)) = (_value_)); \ |
|
|
146 HAL_IO_BARRIER (); \ |
|
|
147 CYG_MACRO_END |
|
0
|
148 |
|
|
149 #define HAL_READ_UINT32_VECTOR( _register_, _buf_, _count_, _step_ ) \ |
|
|
150 CYG_MACRO_START \ |
|
|
151 cyg_count32 _i_,_j_; \ |
|
|
152 for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) { \ |
|
|
153 (_buf_)[_i_] = ((volatile CYG_WORD32 *)(_register_))[_j_]; \ |
|
|
154 HAL_IO_BARRIER (); \ |
|
|
155 } \ |
|
|
156 CYG_MACRO_END |
|
|
157 |
|
|
158 #define HAL_WRITE_UINT32_VECTOR( _register_, _buf_, _count_, _step_ ) \ |
|
|
159 CYG_MACRO_START \ |
|
|
160 cyg_count32 _i_,_j_; \ |
|
|
161 for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_)) { \ |
|
|
162 ((volatile CYG_WORD32 *)(_register_))[_j_] = (_buf_)[_i_]; \ |
|
|
163 HAL_IO_BARRIER (); \ |
|
|
164 } \ |
|
|
165 CYG_MACRO_END |
|
|
166 |
|
|
167 //----------------------------------------------------------------------------- |
|
|
168 #endif // ifndef CYGONCE_HAL_IO_H |
|
|
169 // End of hal_io.h |