source: rtems/cpukit/rtems/src/dpmem.c @ 98e4ebf

4.104.114.84.95
Last change on this file since 98e4ebf was 98e4ebf, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 8, 1997 at 3:45:54 PM

Fixed typo in the pointer to the license terms.

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 *  Dual Port Memory Manager
3 *
4 *  COPYRIGHT (c) 1989-1997.
5 *  On-Line Applications Research Corporation (OAR).
6 *  Copyright assigned to U.S. Government, 1994.
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#include <rtems/system.h>
16#include <rtems/rtems/status.h>
17#include <rtems/rtems/support.h>
18#include <rtems/score/address.h>
19#include <rtems/rtems/dpmem.h>
20#include <rtems/score/object.h>
21#include <rtems/score/thread.h>
22#include <rtems/rtems/dpmem.h>
23
24/*PAGE
25 *
26 *  _Dual_ported_memory_Manager_initialization
27 *
28 *  This routine initializes all dual-ported memory manager related
29 *  data structures.
30 *
31 *  Input parameters:
32 *    maximum_ports - number of ports to initialize
33 *
34 *  Output parameters:  NONE
35 */
36
37void _Dual_ported_memory_Manager_initialization(
38  unsigned32 maximum_ports
39)
40{
41  _Objects_Initialize_information(
42    &_Dual_ported_memory_Information,
43    OBJECTS_RTEMS_PORTS,
44    FALSE,
45    maximum_ports,
46    sizeof( Dual_ported_memory_Control ),
47    FALSE,
48    RTEMS_MAXIMUM_NAME_LENGTH,
49    FALSE
50  );
51}
52
53/*PAGE
54 *
55 *  rtems_port_create
56 *
57 *  This directive creates a port into a dual-ported memory area.
58 *
59 *  Input parameters:
60 *    name           - user defined port name
61 *    internal_start - internal start address of port
62 *    external_start - external start address of port
63 *    length         - physical length in bytes
64 *    id             - address of port id to set
65 *
66 *  Output parameters:
67 *    id       - port id
68 *    RTEMS_SUCCESSFUL - if successful
69 *    error code - if unsuccessful
70 */
71
72rtems_status_code rtems_port_create(
73  rtems_name    name,
74  void         *internal_start,
75  void         *external_start,
76  unsigned32    length,
77  Objects_Id   *id
78)
79{
80  register Dual_ported_memory_Control *the_port;
81
82  if ( !rtems_is_name_valid( name) )
83    return RTEMS_INVALID_NAME;
84
85  if ( !_Addresses_Is_aligned( internal_start ) ||
86       !_Addresses_Is_aligned( external_start ) )
87    return RTEMS_INVALID_ADDRESS;
88
89  _Thread_Disable_dispatch();             /* to prevent deletion */
90
91  the_port = _Dual_ported_memory_Allocate();
92
93  if ( !the_port ) {
94    _Thread_Enable_dispatch();
95    return RTEMS_TOO_MANY;
96  }
97
98  the_port->internal_base = internal_start;
99  the_port->external_base = external_start;
100  the_port->length        = length - 1;
101
102  _Objects_Open( 
103    &_Dual_ported_memory_Information,
104    &the_port->Object,
105    &name
106  );
107
108  *id = the_port->Object.id;
109  _Thread_Enable_dispatch();
110  return RTEMS_SUCCESSFUL;
111}
112
113/*PAGE
114 *
115 *  rtems_port_ident
116 *
117 *  This directive returns the system ID associated with
118 *  the port name.
119 *
120 *  Input parameters:
121 *    name - user defined port name
122 *    id   - pointer to port id
123 *
124 *  Output parameters:
125 *    *id      - port id
126 *    RTEMS_SUCCESSFUL - if successful
127 *    error code - if unsuccessful
128 */
129
130rtems_status_code rtems_port_ident(
131  rtems_name    name,
132  Objects_Id   *id
133)
134{
135  Objects_Name_to_id_errors  status;
136
137  status = _Objects_Name_to_id(
138    &_Dual_ported_memory_Information,
139    &name,
140    OBJECTS_SEARCH_ALL_NODES,
141    id
142  );
143
144  return _Status_Object_name_errors_to_status[ status ];
145}
146
147/*PAGE
148 *
149 *  rtems_port_delete
150 *
151 *  This directive allows a thread to delete a dual-ported memory area
152 *  specified by the dual-ported memory identifier.
153 *
154 *  Input parameters:
155 *    id - dual-ported memory area id
156 *
157 *  Output parameters:
158 *    RTEMS_SUCCESSFUL - if successful
159 *    error code        - if unsuccessful
160 */
161
162rtems_status_code rtems_port_delete(
163  Objects_Id id
164)
165{
166  register Dual_ported_memory_Control *the_port;
167  Objects_Locations                    location;
168
169  the_port = _Dual_ported_memory_Get( id, &location );
170  switch ( location ) {
171    case OBJECTS_ERROR:
172      return RTEMS_INVALID_ID;
173    case OBJECTS_REMOTE:        /* this error cannot be returned */
174      return RTEMS_INTERNAL_ERROR;
175    case OBJECTS_LOCAL:
176      _Objects_Close( &_Dual_ported_memory_Information, &the_port->Object );
177      _Dual_ported_memory_Free( the_port );
178      _Thread_Enable_dispatch();
179      return RTEMS_SUCCESSFUL;
180  }
181
182  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
183}
184
185/*PAGE
186 *
187 *  rtems_port_internal_to_external
188 *
189 *  This directive converts an internal dual-ported memory address to an
190 *  external dual-ported memory address.  If the given internal address
191 *  is an invalid dual-ported address, then the external address is set
192 *  to the given internal address.
193 *
194 *  Input parameters:
195 *    id       - id of dual-ported memory object
196 *    internal - internal address to set
197 *    external - pointer to external address
198 *
199 *  Output parameters:
200 *    external          - external address
201 *    RTEMS_SUCCESSFUL - always succeeds
202 */
203
204rtems_status_code rtems_port_internal_to_external(
205  Objects_Id   id,
206  void        *internal,
207  void       **external
208)
209{
210  register Dual_ported_memory_Control *the_port;
211  Objects_Locations                    location;
212  unsigned32                           ending;
213
214  the_port = _Dual_ported_memory_Get( id, &location );
215  switch ( location ) {
216    case OBJECTS_ERROR:
217      return RTEMS_INVALID_ID;
218    case OBJECTS_REMOTE:        /* this error cannot be returned */
219      return RTEMS_INTERNAL_ERROR;
220    case OBJECTS_LOCAL:
221      ending = _Addresses_Subtract( internal, the_port->internal_base );
222      if ( ending > the_port->length )
223        *external = internal;
224      else
225        *external = _Addresses_Add_offset( the_port->external_base,
226                                           ending );
227      _Thread_Enable_dispatch();
228      return RTEMS_SUCCESSFUL;
229  }
230
231  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
232}
233
234/*PAGE
235 *
236 *  rtems_port_external_to_internal
237 *
238 *  This directive converts an external dual-ported memory address to an
239 *  internal dual-ported memory address.  If the given external address
240 *  is an invalid dual-ported address, then the internal address is set
241 *  to the given external address.
242 *
243 *  Input parameters:
244 *    id       - id of dp memory object
245 *    external - external address
246 *    internal - pointer of internal address to set
247 *
248 *  Output parameters:
249 *    internal          - internal address
250 *    RTEMS_SUCCESSFUL - always succeeds
251 */
252
253rtems_status_code rtems_port_external_to_internal(
254  Objects_Id   id,
255  void        *external,
256  void       **internal
257)
258{
259  register Dual_ported_memory_Control *the_port;
260  Objects_Locations                    location;
261  unsigned32                           ending;
262
263  the_port = _Dual_ported_memory_Get( id, &location );
264  switch ( location ) {
265    case OBJECTS_ERROR:
266      return RTEMS_INVALID_ID;
267    case OBJECTS_REMOTE:        /* this error cannot be returned */
268      return RTEMS_INTERNAL_ERROR;
269    case OBJECTS_LOCAL:
270      ending = _Addresses_Subtract( external, the_port->external_base );
271      if ( ending > the_port->length )
272        *internal = external;
273      else
274        *internal = _Addresses_Add_offset( the_port->internal_base,
275                                           ending );
276      _Thread_Enable_dispatch();
277      return RTEMS_SUCCESSFUL;
278  }
279
280  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
281}
Note: See TracBrowser for help on using the repository browser.