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

4.104.114.84.95
Last change on this file since 98e4ebf5 was 98e4ebf5, checked in by Joel Sherrill <joel.sherrill@…>, on 10/08/97 at 15:45:54

Fixed typo in the pointer to the license terms.

  • Property mode set to 100644
File size: 7.1 KB
RevLine 
[ac7d5ef0]1/*
2 *  Dual Port Memory Manager
3 *
[03f2154e]4 *  COPYRIGHT (c) 1989-1997.
[ac7d5ef0]5 *  On-Line Applications Research Corporation (OAR).
[03f2154e]6 *  Copyright assigned to U.S. Government, 1994.
[ac7d5ef0]7 *
[98e4ebf5]8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
[03f2154e]10 *  http://www.OARcorp.com/rtems/license.html.
[ac7d5ef0]11 *
12 *  $Id$
13 */
14
15#include <rtems/system.h>
[3a4ae6c]16#include <rtems/rtems/status.h>
17#include <rtems/rtems/support.h>
[5e9b32b]18#include <rtems/score/address.h>
[3a4ae6c]19#include <rtems/rtems/dpmem.h>
[5e9b32b]20#include <rtems/score/object.h>
21#include <rtems/score/thread.h>
[3a4ae6c]22#include <rtems/rtems/dpmem.h>
[ac7d5ef0]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(
[3235ad9]42    &_Dual_ported_memory_Information,
43    OBJECTS_RTEMS_PORTS,
44    FALSE,
45    maximum_ports,
46    sizeof( Dual_ported_memory_Control ),
47    FALSE,
[5250ff39]48    RTEMS_MAXIMUM_NAME_LENGTH,
49    FALSE
[ac7d5ef0]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(
[3235ad9]73  rtems_name    name,
[ac7d5ef0]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
[3235ad9]82  if ( !rtems_is_name_valid( name) )
[3a4ae6c]83    return RTEMS_INVALID_NAME;
[ac7d5ef0]84
85  if ( !_Addresses_Is_aligned( internal_start ) ||
86       !_Addresses_Is_aligned( external_start ) )
[3a4ae6c]87    return RTEMS_INVALID_ADDRESS;
[ac7d5ef0]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();
[3a4ae6c]95    return RTEMS_TOO_MANY;
[ac7d5ef0]96  }
97
98  the_port->internal_base = internal_start;
99  the_port->external_base = external_start;
100  the_port->length        = length - 1;
101
[3235ad9]102  _Objects_Open(
103    &_Dual_ported_memory_Information,
104    &the_port->Object,
105    &name
106  );
107
[ac7d5ef0]108  *id = the_port->Object.id;
109  _Thread_Enable_dispatch();
[3a4ae6c]110  return RTEMS_SUCCESSFUL;
[ac7d5ef0]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(
[3235ad9]131  rtems_name    name,
[ac7d5ef0]132  Objects_Id   *id
133)
134{
[3a4ae6c]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
[ac7d5ef0]142  );
[3a4ae6c]143
144  return _Status_Object_name_errors_to_status[ status ];
[ac7d5ef0]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:
[3a4ae6c]172      return RTEMS_INVALID_ID;
[ac7d5ef0]173    case OBJECTS_REMOTE:        /* this error cannot be returned */
[3a4ae6c]174      return RTEMS_INTERNAL_ERROR;
[ac7d5ef0]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();
[3a4ae6c]179      return RTEMS_SUCCESSFUL;
[ac7d5ef0]180  }
181
[3a4ae6c]182  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
[ac7d5ef0]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:
[3a4ae6c]217      return RTEMS_INVALID_ID;
[ac7d5ef0]218    case OBJECTS_REMOTE:        /* this error cannot be returned */
[3a4ae6c]219      return RTEMS_INTERNAL_ERROR;
[ac7d5ef0]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();
[3a4ae6c]228      return RTEMS_SUCCESSFUL;
[ac7d5ef0]229  }
230
[3a4ae6c]231  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
[ac7d5ef0]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:
[3a4ae6c]266      return RTEMS_INVALID_ID;
[ac7d5ef0]267    case OBJECTS_REMOTE:        /* this error cannot be returned */
[3a4ae6c]268      return RTEMS_INTERNAL_ERROR;
[ac7d5ef0]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();
[3a4ae6c]277      return RTEMS_SUCCESSFUL;
[ac7d5ef0]278  }
279
[3a4ae6c]280  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
[ac7d5ef0]281}
Note: See TracBrowser for help on using the repository browser.