source: rtems/cpukit/rtems/src/dpmem.c @ 5250ff39

4.104.114.84.95
Last change on this file since 5250ff39 was 5250ff39, checked in by Joel Sherrill <joel.sherrill@…>, on 08/23/95 at 21:06:31

Moved _Thread_Information -> _RTEMS_tasks_Information.

Added a table of object information control blocks.

Modified _Thread_Get so it looks up a thread regardless of which
thread management "entity" (manager, internal, etc) actually "owns" it.

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