source: rtems/cpukit/rtems/src/dpmem.c @ ea9d7db

4.104.114.84.95
Last change on this file since ea9d7db was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/95 at 17:39:37

Initial revision

  • 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     FALSE,
41     maximum_ports,
42     sizeof( Dual_ported_memory_Control )
43  );
44}
45
46/*PAGE
47 *
48 *  rtems_port_create
49 *
50 *  This directive creates a port into a dual-ported memory area.
51 *
52 *  Input parameters:
53 *    name           - user defined port name
54 *    internal_start - internal start address of port
55 *    external_start - external start address of port
56 *    length         - physical length in bytes
57 *    id             - address of port id to set
58 *
59 *  Output parameters:
60 *    id       - port id
61 *    RTEMS_SUCCESSFUL - if successful
62 *    error code - if unsuccessful
63 */
64
65rtems_status_code rtems_port_create(
66  Objects_Name  name,
67  void         *internal_start,
68  void         *external_start,
69  unsigned32    length,
70  Objects_Id   *id
71)
72{
73  register Dual_ported_memory_Control *the_port;
74
75  if ( !_Objects_Is_name_valid( name) )
76    return ( RTEMS_INVALID_NAME );
77
78  if ( !_Addresses_Is_aligned( internal_start ) ||
79       !_Addresses_Is_aligned( external_start ) )
80    return( RTEMS_INVALID_ADDRESS );
81
82  _Thread_Disable_dispatch();             /* to prevent deletion */
83
84  the_port = _Dual_ported_memory_Allocate();
85
86  if ( !the_port ) {
87    _Thread_Enable_dispatch();
88    return( RTEMS_TOO_MANY );
89  }
90
91  the_port->internal_base = internal_start;
92  the_port->external_base = external_start;
93  the_port->length        = length - 1;
94
95  _Objects_Open( &_Dual_ported_memory_Information,
96                 &the_port->Object, name );
97  *id = the_port->Object.id;
98  _Thread_Enable_dispatch();
99  return( RTEMS_SUCCESSFUL );
100}
101
102/*PAGE
103 *
104 *  rtems_port_ident
105 *
106 *  This directive returns the system ID associated with
107 *  the port name.
108 *
109 *  Input parameters:
110 *    name - user defined port name
111 *    id   - pointer to port id
112 *
113 *  Output parameters:
114 *    *id      - port id
115 *    RTEMS_SUCCESSFUL - if successful
116 *    error code - if unsuccessful
117 */
118
119rtems_status_code rtems_port_ident(
120  Objects_Name  name,
121  Objects_Id   *id
122)
123{
124  return(
125    _Objects_Name_to_id(
126      &_Dual_ported_memory_Information,
127      name,
128      RTEMS_SEARCH_ALL_NODES,
129      id
130    )
131  );
132}
133
134/*PAGE
135 *
136 *  rtems_port_delete
137 *
138 *  This directive allows a thread to delete a dual-ported memory area
139 *  specified by the dual-ported memory identifier.
140 *
141 *  Input parameters:
142 *    id - dual-ported memory area id
143 *
144 *  Output parameters:
145 *    RTEMS_SUCCESSFUL - if successful
146 *    error code        - if unsuccessful
147 */
148
149rtems_status_code rtems_port_delete(
150  Objects_Id id
151)
152{
153  register Dual_ported_memory_Control *the_port;
154  Objects_Locations                    location;
155
156  the_port = _Dual_ported_memory_Get( id, &location );
157  switch ( location ) {
158    case OBJECTS_ERROR:
159      return( RTEMS_INVALID_ID );
160    case OBJECTS_REMOTE:        /* this error cannot be returned */
161      return( RTEMS_INTERNAL_ERROR );
162    case OBJECTS_LOCAL:
163      _Objects_Close( &_Dual_ported_memory_Information, &the_port->Object );
164      _Dual_ported_memory_Free( the_port );
165      _Thread_Enable_dispatch();
166      return( RTEMS_SUCCESSFUL );
167  }
168
169  return( RTEMS_INTERNAL_ERROR );   /* unreached - only to remove warnings */
170}
171
172/*PAGE
173 *
174 *  rtems_port_internal_to_external
175 *
176 *  This directive converts an internal dual-ported memory address to an
177 *  external dual-ported memory address.  If the given internal address
178 *  is an invalid dual-ported address, then the external address is set
179 *  to the given internal address.
180 *
181 *  Input parameters:
182 *    id       - id of dual-ported memory object
183 *    internal - internal address to set
184 *    external - pointer to external address
185 *
186 *  Output parameters:
187 *    external          - external address
188 *    RTEMS_SUCCESSFUL - always succeeds
189 */
190
191rtems_status_code rtems_port_internal_to_external(
192  Objects_Id   id,
193  void        *internal,
194  void       **external
195)
196{
197  register Dual_ported_memory_Control *the_port;
198  Objects_Locations                    location;
199  unsigned32                           ending;
200
201  the_port = _Dual_ported_memory_Get( id, &location );
202  switch ( location ) {
203    case OBJECTS_ERROR:
204      return( RTEMS_INVALID_ID );
205    case OBJECTS_REMOTE:        /* this error cannot be returned */
206      return( RTEMS_INTERNAL_ERROR );
207    case OBJECTS_LOCAL:
208      ending = _Addresses_Subtract( internal, the_port->internal_base );
209      if ( ending > the_port->length )
210        *external = internal;
211      else
212        *external = _Addresses_Add_offset( the_port->external_base,
213                                           ending );
214      _Thread_Enable_dispatch();
215      return( RTEMS_SUCCESSFUL );
216  }
217
218  return( RTEMS_INTERNAL_ERROR );   /* unreached - only to remove warnings */
219}
220
221/*PAGE
222 *
223 *  rtems_port_external_to_internal
224 *
225 *  This directive converts an external dual-ported memory address to an
226 *  internal dual-ported memory address.  If the given external address
227 *  is an invalid dual-ported address, then the internal address is set
228 *  to the given external address.
229 *
230 *  Input parameters:
231 *    id       - id of dp memory object
232 *    external - external address
233 *    internal - pointer of internal address to set
234 *
235 *  Output parameters:
236 *    internal          - internal address
237 *    RTEMS_SUCCESSFUL - always succeeds
238 */
239
240rtems_status_code rtems_port_external_to_internal(
241  Objects_Id   id,
242  void        *external,
243  void       **internal
244)
245{
246  register Dual_ported_memory_Control *the_port;
247  Objects_Locations                    location;
248  unsigned32                           ending;
249
250  the_port = _Dual_ported_memory_Get( id, &location );
251  switch ( location ) {
252    case OBJECTS_ERROR:
253      return( RTEMS_INVALID_ID );
254    case OBJECTS_REMOTE:        /* this error cannot be returned */
255      return( RTEMS_INTERNAL_ERROR );
256    case OBJECTS_LOCAL:
257      ending = _Addresses_Subtract( external, the_port->external_base );
258      if ( ending > the_port->length )
259        *internal = external;
260      else
261        *internal = _Addresses_Add_offset( the_port->internal_base,
262                                           ending );
263      _Thread_Enable_dispatch();
264      return( RTEMS_SUCCESSFUL );
265  }
266
267  return( RTEMS_INTERNAL_ERROR );   /* unreached - only to remove warnings */
268}
Note: See TracBrowser for help on using the repository browser.