summaryrefslogblamecommitdiffstats
path: root/cpukit/rtems/src/dpmemcreate.c
blob: eba3a523c42d771265cdecc7442322f48dd525a9 (plain) (tree)
1
2
3
4
5
6
7
8
   
        
  




                                                                  


   
                            
                                                    


                                                           
                                         

   
                    


                   
                                  


                                
                               
                          
 



                                    
                       
                  

 
                                       
 
                                     

                              


                                 



                                                  


                                            
                                






                                           
                          

                                     
        
    
                              

                          










                                                                      
/**
 * @file
 *
 * @ingroup RTEMSImplClassicDPMem
 *
 * @brief This source file contains the implementation of
 *   rtems_port_create() and the Dual-Ported Memory Manager system
 *   initialization.
 */

/*
 *  COPYRIGHT (c) 1989-2014.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <rtems/rtems/dpmemimpl.h>
#include <rtems/rtems/status.h>
#include <rtems/rtems/support.h>
#include <rtems/score/address.h>
#include <rtems/score/thread.h>
#include <rtems/sysinit.h>

rtems_status_code rtems_port_create(
  rtems_name    name,
  void         *internal_start,
  void         *external_start,
  uint32_t      length,
  rtems_id     *id
)
{
  Dual_ported_memory_Control *the_port;

  if ( !rtems_is_name_valid( name ) )
    return RTEMS_INVALID_NAME;

  if ( !id )
    return RTEMS_INVALID_ADDRESS;

  if ( !_Addresses_Is_aligned( internal_start ) ||
       !_Addresses_Is_aligned( external_start ) )
    return RTEMS_INVALID_ADDRESS;

  the_port = _Dual_ported_memory_Allocate();

  if ( !the_port ) {
    _Objects_Allocator_unlock();
    return RTEMS_TOO_MANY;
  }

  the_port->internal_base = internal_start;
  the_port->external_base = external_start;
  the_port->length        = length - 1;

  *id = _Objects_Open_u32(
    &_Dual_ported_memory_Information,
    &the_port->Object,
    name
  );
  _Objects_Allocator_unlock();
  return RTEMS_SUCCESSFUL;
}

static void _Dual_ported_memory_Manager_initialization( void )
{
  _Objects_Initialize_information( &_Dual_ported_memory_Information );
}

RTEMS_SYSINIT_ITEM(
  _Dual_ported_memory_Manager_initialization,
  RTEMS_SYSINIT_CLASSIC_DUAL_PORTED_MEMORY,
  RTEMS_SYSINIT_ORDER_MIDDLE
);