source: rtems/c/src/exec/rtems/src/dpmem.c @ 80e2c29e

4.104.114.84.95
Last change on this file since 80e2c29e was 9863dbf, checked in by Joel Sherrill <joel.sherrill@…>, on 08/18/95 at 21:42:58

+ Added object type field to object id.

+ Added name pointer to Object_Control.

+ Modified Object Open and Close to address name field.

+ Removed name as separate element from Thread and Proxy Control.

+ Added parameter "object class" to calls to Initialize Information

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