Exemplo n.º 1
0
_mqx_uint _io_sai_int_install
(
    /* [IN] The initialization structure for the device */
    SAI_INIT_STRUCT_CPTR init_ptr
)
{ /* Body */
    IO_SAI_DEVICE_STRUCT_PTR io_dev_ptr = NULL;    

    io_dev_ptr = (IO_SAI_DEVICE_STRUCT_PTR) _mem_alloc_system_zero(sizeof (IO_SAI_DEVICE_STRUCT));
    
    if (io_dev_ptr == NULL)
    {
        return MQX_OUT_OF_MEMORY;
    }

    io_dev_ptr->DEV_INIT            = init_ptr->INIT;
    io_dev_ptr->DEV_DEINIT          = init_ptr->DEINIT;
    io_dev_ptr->DEV_READ            = init_ptr->RX;
    io_dev_ptr->DEV_WRITE           = init_ptr->TX;
    io_dev_ptr->DEV_IOCTL           = init_ptr->IOCTL;
    io_dev_ptr->DEV_INIT_DATA_PTR   = init_ptr->INIT_DATA_PTR;
    
    _lwsem_create(&io_dev_ptr->LWSEM, 1);
    
    return (_io_dev_install_ext(
        init_ptr->ID_PTR,
        _io_sai_int_open,
        _io_sai_int_close,
        _io_sai_int_read,
        _io_sai_int_write,
        _io_sai_int_ioctl,
        _io_sai_int_uninstall,
        (pointer)io_dev_ptr));

} /* Endbody */
Exemplo n.º 2
0
_mqx_uint _io_dev_install
   (
      /* [IN] A string that identifies the device for fopen */
      char_ptr             identifier,
  
      /* [IN] The I/O open function */
      _mqx_int (_CODE_PTR_ io_open)(MQX_FILE_PTR, char _PTR_, char _PTR_),

      /* [IN] The I/O close function */
      _mqx_int (_CODE_PTR_ io_close)(MQX_FILE_PTR),

      /* [IN] The I/O read function */
      _mqx_int (_CODE_PTR_ io_read)(MQX_FILE_PTR, char _PTR_, _mqx_int),

      /* [IN] The I/O write function */
      _mqx_int (_CODE_PTR_ io_write)(MQX_FILE_PTR, char _PTR_, _mqx_int),

      /* [IN] The I/O ioctl function */
      _mqx_int (_CODE_PTR_ io_ioctl)(MQX_FILE_PTR, _mqx_uint, pointer),

      /* [IN] The I/O initialization data */
      pointer              io_init_data_ptr
   )
{ /* Body */

   return (_io_dev_install_ext(identifier, io_open, io_close, io_read, io_write,
      io_ioctl, (_mqx_int (_CODE_PTR_)(IO_DEVICE_STRUCT_PTR))NULL, 
      io_init_data_ptr));

} /* Endbody */
Exemplo n.º 3
0
_mqx_uint _io_dev_install
   (
      /* [IN] A string that identifies the device for fopen */
      char_ptr      identifier,
  
      /* [IN] The I/O open function */
      IO_OPEN_FPTR  io_open,

      /* [IN] The I/O close function */
      IO_CLOSE_FPTR io_close,

      /* [IN] The I/O read function */
      IO_READ_FPTR  io_read,

      /* [IN] The I/O write function */
      IO_WRITE_FPTR io_write,

      /* [IN] The I/O ioctl function */
      IO_IOCTL_FPTR io_ioctl,

      /* [IN] The I/O initialization data */
      pointer       io_init_data_ptr
   )
{ /* Body */

   return (_io_dev_install_ext(identifier, io_open, io_close, io_read, io_write,
      io_ioctl, (IO_UNINSTALL_FPTR)NULL, io_init_data_ptr));

} /* Endbody */
Exemplo n.º 4
0
/*FUNCTION****************************************************************
* 
* Function Name    : _io_spi_int_install
* Returned Value   : MQX error code
* Comments         :
*    Install the interrupt SPI device.
*
*END**********************************************************************/
_mqx_uint _io_spi_int_install
   (
      /* [IN] A string that identifies the device for fopen */
      char_ptr              identifier,
  
      /* [IN] The I/O init function */
      _mqx_uint (_CODE_PTR_ init)(pointer,char _PTR_),

      /* [IN] The enable interrupts function */
      _mqx_uint (_CODE_PTR_ enable_ints)(pointer),
      
      /* [IN] The I/O de-init function */
      _mqx_uint (_CODE_PTR_ deinit)(pointer, pointer),
      
      /* [IN] The input function */
      _mqx_int  (_CODE_PTR_ recv)(pointer, char _PTR_, _mqx_int),
     
      /* [IN] The output function */
      _mqx_int  (_CODE_PTR_ xmit)(pointer, char _PTR_, _mqx_int),

      /* [IN] The I/O ioctl function */
      _mqx_int  (_CODE_PTR_ ioctl)(pointer, _mqx_uint, _mqx_uint_ptr, _mqx_uint),

      /* [IN] The I/O init data pointer */
      pointer               init_data_ptr
      
   )
{ /* Body */
   IO_SPI_INT_DEVICE_STRUCT_PTR int_dev_ptr;

   int_dev_ptr = (IO_SPI_INT_DEVICE_STRUCT_PTR)_mem_alloc_system_zero((_mem_size)sizeof(IO_SPI_INT_DEVICE_STRUCT));
   if (int_dev_ptr == NULL) 
   {
      return(MQX_OUT_OF_MEMORY);
   }
   _mem_set_type(int_dev_ptr,MEM_TYPE_IO_SPI_INT_DEVICE_STRUCT);       

   int_dev_ptr->DEV_INIT          = init;
   int_dev_ptr->DEV_DEINIT        = deinit;
   int_dev_ptr->DEV_ENABLE_INTS   = enable_ints;
   int_dev_ptr->DEV_READ          = recv;
   int_dev_ptr->DEV_WRITE         = xmit;
   int_dev_ptr->DEV_IOCTL         = ioctl;
   int_dev_ptr->DEV_INIT_DATA_PTR = init_data_ptr;
   
   return (_io_dev_install_ext(identifier,
      _io_spi_int_open, _io_spi_int_close,
      (_mqx_int (_CODE_PTR_)(MQX_FILE_PTR, char_ptr,  _mqx_int))_io_spi_int_read, 
      (_mqx_int (_CODE_PTR_)(MQX_FILE_PTR, char_ptr,  _mqx_int))_io_spi_int_write, 
      (_mqx_int (_CODE_PTR_)(MQX_FILE_PTR, _mqx_uint, pointer))_io_spi_int_ioctl, _io_spi_int_uninstall,
      (pointer)int_dev_ptr));
} /* Endbody */
Exemplo n.º 5
0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : _io_flashx_install
* Returned Value   : _mqx_uint a task error code or MQX_OK
* Comments         :
*    Install a flash driver.
*
*END*----------------------------------------------------------------------*/
_mqx_uint _io_flashx_install
(
      /* [IN] A string that identifies the device for fopen */
      char_ptr                      identifier,

      /* [IN] BSP specific settings for installing device */
      FLASHX_INIT_STRUCT const _PTR_  init_ptr

)
{ /* Body */
   IO_FLASHX_STRUCT_PTR           dev_ptr;
  
   dev_ptr = (IO_FLASHX_STRUCT_PTR)_mem_alloc_system_zero((_mem_size)sizeof(IO_FLASHX_STRUCT));

#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if (dev_ptr == NULL) {
      return MQX_OUT_OF_MEMORY;
   } /* Endif */
#endif

    dev_ptr->SECTOR_ERASE   = init_ptr->DEVICE_IF->SECTOR_ERASE;
    dev_ptr->SECTOR_PROGRAM = init_ptr->DEVICE_IF->SECTOR_PROGRAM;
    dev_ptr->CHIP_ERASE     = init_ptr->DEVICE_IF->CHIP_ERASE;
    dev_ptr->READ           = init_ptr->DEVICE_IF->READ;
    dev_ptr->INIT           = init_ptr->DEVICE_IF->INIT;
    dev_ptr->DEINIT         = init_ptr->DEVICE_IF->DEINIT;
    dev_ptr->WRITE_PROTECT  = init_ptr->DEVICE_IF->WRITE_PROTECT;
    dev_ptr->IOCTL          = init_ptr->DEVICE_IF->IOCTL;

    dev_ptr->BASE_ADDR      = init_ptr->BASE_ADDR;
    dev_ptr->HW_BLOCK       = (FLASHX_BLOCK_INFO_STRUCT_PTR) init_ptr->HW_BLOCK;
    dev_ptr->FILE_BLOCK     = (FLASHX_FILE_BLOCK_PTR) init_ptr->FILE_BLOCK;
    dev_ptr->WIDTH          = init_ptr->WIDTH;
    dev_ptr->DEVICES        = init_ptr->DEVICES;
    dev_ptr->WRITE_VERIFY   = init_ptr->WRITE_VERIFY;

    dev_ptr->DEVICE_SPECIFIC_INIT = init_ptr->DEVICE_SPECIFIC_INIT;

   _lwsem_create(&dev_ptr->HW_ACCESS, 1);
    
    return (_io_dev_install_ext(
        identifier,
        _io_flashx_open,
        _io_flashx_close,
        _io_flashx_read,
        _io_flashx_write,
        _io_flashx_ioctl,
        _io_flashx_uninstall,
        (pointer)dev_ptr));

} /* Endbody */
Exemplo n.º 6
0
_mqx_uint _io_usb_dcd_polled_install
   (
      /* [IN] A string that identifies the device for fopen */
      char_ptr               identifier,
  
      /* [IN] The I/O init function */
      _mqx_uint (_CODE_PTR_ init)(pointer, pointer _PTR_, char_ptr),
      
      /* [IN] The I/O de-init function */
      _mqx_uint (_CODE_PTR_ deinit)(pointer, pointer),
      
      /* [IN] The input function */
      _mqx_int  (_CODE_PTR_ recv)(pointer, char_ptr, _mqx_int),
     
      /* [IN] The output function */
      _mqx_int  (_CODE_PTR_ xmit)(pointer, char_ptr, _mqx_int),

      /* [IN] The I/O ioctl function */
      _mqx_int  (_CODE_PTR_ ioctl)(pointer, _mqx_uint, _mqx_uint_ptr),

      /* [IN] The I/O init data pointer */
      pointer               init_data_ptr
      
   )

{ /* Body */
   IO_USB_DCD_POLLED_DEVICE_STRUCT_PTR pol_io_dev_ptr;

   pol_io_dev_ptr = (IO_USB_DCD_POLLED_DEVICE_STRUCT_PTR)_mem_alloc_system_zero ((_mem_size)sizeof (IO_USB_DCD_POLLED_DEVICE_STRUCT));
   if (pol_io_dev_ptr == NULL) 
   {
      return MQX_OUT_OF_MEMORY;
   }
   _mem_set_type (pol_io_dev_ptr, MEM_TYPE_IO_USB_DCD_POLLED_DEVICE_STRUCT);            

   pol_io_dev_ptr->DEV_INIT          = init;
   pol_io_dev_ptr->DEV_DEINIT        = deinit;
   pol_io_dev_ptr->DEV_READ          = recv;
   pol_io_dev_ptr->DEV_WRITE         = xmit;
   pol_io_dev_ptr->DEV_IOCTL         = ioctl;
   pol_io_dev_ptr->DEV_INIT_DATA_PTR = init_data_ptr;
   
   return (_io_dev_install_ext (identifier,
      _io_usb_dcd_polled_open,  _io_usb_dcd_polled_close,
      _io_usb_dcd_polled_read,  _io_usb_dcd_polled_write,
      _io_usb_dcd_polled_ioctl, _io_usb_dcd_polled_uninstall,
      (pointer)pol_io_dev_ptr));

} /* Endbody */
Exemplo n.º 7
0
_mqx_uint _io_nandflash_install
   (
      /* [IN] The initialization structure for the device */
      NANDFLASH_INIT_STRUCT _PTR_  init_ptr
   )
{ /* Body */
   IO_NANDFLASH_STRUCT_PTR     dev_ptr;
  
   dev_ptr = (IO_NANDFLASH_STRUCT_PTR)_mem_alloc_system_zero(
      (_mem_size)sizeof(IO_NANDFLASH_STRUCT));

#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if (dev_ptr == NULL) {
      return MQX_OUT_OF_MEMORY;
   } /* Endif */
#endif

   dev_ptr->INIT                 = init_ptr->INIT;
   dev_ptr->DEINIT               = init_ptr->DEINIT;
   dev_ptr->CHIP_ERASE           = init_ptr->CHIP_ERASE;
   dev_ptr->BLOCK_ERASE          = init_ptr->BLOCK_ERASE;
   dev_ptr->PAGE_READ            = init_ptr->PAGE_READ;
   dev_ptr->PAGE_PROGRAM         = init_ptr->PAGE_PROGRAM;
   dev_ptr->WRITE_PROTECT        = init_ptr->WRITE_PROTECT;
   dev_ptr->IS_BLOCK_BAD         = init_ptr->IS_BLOCK_BAD;
   dev_ptr->MARK_BLOCK_AS_BAD    = init_ptr->MARK_BLOCK_AS_BAD;
   dev_ptr->IOCTL                = init_ptr->IOCTL;
   dev_ptr->NANDFLASH_INFO_PTR   = init_ptr->NANDFLASH_INFO_PTR;
   dev_ptr->VIRTUAL_PAGE_SIZE    = BSP_VIRTUAL_PAGE_SIZE;
   dev_ptr->NUM_VIRTUAL_PAGES    = (init_ptr->NANDFLASH_INFO_PTR->BLOCK_SIZE / BSP_VIRTUAL_PAGE_SIZE) * init_ptr->NANDFLASH_INFO_PTR->NUM_BLOCKS;
   dev_ptr->PHY_PAGE_SIZE_TO_VIRTUAL_PAGE_SIZE_RATIO    
                                 = (init_ptr->NANDFLASH_INFO_PTR->PHY_PAGE_SIZE / BSP_VIRTUAL_PAGE_SIZE);
   dev_ptr->ECC_SIZE             = BSP_ECC_SIZE;
   dev_ptr->WRITE_VERIFY         = init_ptr->WRITE_VERIFY;
   dev_ptr->DEVICE_SPECIFIC_DATA = init_ptr->DEVICE_SPECIFIC_DATA;

   _lwsem_create(&dev_ptr->LWSEM, 1);
    
   return (_io_dev_install_ext(
      init_ptr->ID_PTR,
      _io_nandflash_open,
      _io_nandflash_close,
      _io_nandflash_read,
      _io_nandflash_write,
      _io_nandflash_ioctl,
      _io_nandflash_uninstall, 
      (pointer)dev_ptr)); 
} /* Endbody */
Exemplo n.º 8
0
uint32_t _io_tfs_install
   (
      /*[IN] the name that should be given to tfs (ex: "C:", "TFS1:", etc..) */
      char              *identifier,
      
      /*[IN] pointer to the first entry of the root TFS directory  */  
      const TFS_DIR_ENTRY   *root
   )
{ /* Body */
   uint32_t                      error_code;
   TFS_DRIVE_STRUCT_PTR         drive_ptr;
   
   drive_ptr = _mem_alloc_system_zero( sizeof(TFS_DRIVE_STRUCT) );
   if ( drive_ptr == NULL ) {
      return( TFS_INSUFFICIENT_MEMORY );
   }/* Endif */
   _mem_set_type(drive_ptr,MEM_TYPE_IO_TFS_DRIVE_STRUCT);      
   
   _int_disable();

   error_code = _io_dev_install_ext( identifier, 
      _io_tfs_open,                     
      _io_tfs_close, 
      _io_tfs_read,                      
      _io_tfs_write,                     
      _io_tfs_ioctl,
      _io_tfs_uninstall,
      (void *)drive_ptr);

   if (error_code != IO_OK) {
      _mem_free(drive_ptr);
      drive_ptr = NULL;
      _int_enable();      
      return error_code;
   } /* Endif */

   drive_ptr->IDENTIFIER = identifier;
   drive_ptr->ROOT     = root;
 
   _int_enable();

   return(error_code);

} /* Endbody */
Exemplo n.º 9
0
_mqx_uint _io_pipe_install
   (
      /* [IN] A string that identifies the device for fopen */
      char_ptr            identifier,
      
      /* [IN] The pipe queue size to use */
      uint_32             queue_size,

      /* [IN] Currently not used */
      uint_32             flags

   )
{ /* Body */
   IO_PIPE_INIT_STRUCT_PTR  io_pipe_init_ptr;

   /* Allocate an Pipe installation structure */
   io_pipe_init_ptr = _mem_alloc_system_zero(
      (uint_32)sizeof(IO_PIPE_INIT_STRUCT));

#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if (io_pipe_init_ptr == NULL) {
      return(MQX_OUT_OF_MEMORY);
   } /* Endif */
#endif

   /* Set queue size for Pipe */
   io_pipe_init_ptr->QUEUE_SIZE = queue_size;

   /* Copy flags field */
   io_pipe_init_ptr->FLAGS      = flags;

   /* Install device */
   return (_io_dev_install_ext(identifier,
      _io_pipe_open, _io_pipe_close,
      _io_pipe_read, _io_pipe_write,
      _io_pipe_ioctl, _io_pipe_uninstall,
      (pointer)io_pipe_init_ptr)); 

} /* Endbody */
Exemplo n.º 10
0
/*FUNCTION****************************************************************
*
* Function Name    : _io_spi_install
* Returned Value   : MQX error code
* Comments         :
*    Installs SPI device.
*
*END**********************************************************************/
_mqx_int _io_spi_install
    (
        /* [IN] A string that identifies the device for fopen */
        char                       *identifier,

        /* [IN] Pointer to driver initialization data */
        SPI_INIT_STRUCT_CPTR           init_data_ptr
    )
{
    SPI_DRIVER_DATA_STRUCT_PTR driver_data;

    _mqx_int error_code = MQX_OK;

    if ((init_data_ptr->DEVIF->SETPARAM == NULL) || (init_data_ptr->DEVIF->TX_RX == NULL))
    {
        /* Missing mandatory low level driver function */
        return IO_ERROR_DEVICE_INVALID;
    }

    driver_data = (SPI_DRIVER_DATA_STRUCT_PTR)_mem_alloc_system_zero((_mem_size)sizeof(SPI_DRIVER_DATA_STRUCT));
    if (driver_data == NULL)
    {
        return MQX_OUT_OF_MEMORY;
    }
    _mem_set_type(driver_data, MEM_TYPE_IO_SPI_POLLED_DEVICE_STRUCT);

    driver_data->CS_CALLBACK = init_data_ptr->CS_CALLBACK;
    driver_data->CS_USERDATA= init_data_ptr->CS_USERDATA;
    driver_data->PARAMS = init_data_ptr->PARAMS;
    driver_data->DEVIF = init_data_ptr->DEVIF;

    /* initialize low level driver */
    if (driver_data->DEVIF->INIT)
        error_code = driver_data->DEVIF->INIT(init_data_ptr->DEVIF_INIT, &(driver_data->DEVIF_DATA));

    if (error_code != MQX_OK)
    {
        _mem_free(driver_data);
        return error_code;
    }

    _lwsem_create(&driver_data->BUS_LOCK, 1);
/********************************************/
	/*special for em9301 IRQ*/
	_lwsem_create(&driver_data->IRQ_SEM, 0);
	lwgpio_init(&driver_data->SPI_IRQ_PIN, BSP_EM9301_IRQ_PIN, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE);
    lwgpio_set_functionality(&driver_data->SPI_IRQ_PIN, BSP_EM9301_IRQ_MUX_IRQ);
    lwgpio_set_attribute(&driver_data->SPI_IRQ_PIN, LWGPIO_ATTR_PULL_DOWN, LWGPIO_AVAL_ENABLE);
    lwgpio_int_init(&driver_data->SPI_IRQ_PIN, LWGPIO_INT_MODE_RISING);
    _int_install_isr(lwgpio_int_get_vector(&driver_data->SPI_IRQ_PIN), _dspi_em9301_isr, driver_data);
    _bsp_int_init(lwgpio_int_get_vector(&driver_data->SPI_IRQ_PIN), BSP_DSPI_INT_LEVEL, 0, TRUE);
    lwgpio_int_enable(&driver_data->SPI_IRQ_PIN, TRUE);
/********************************************/
    error_code = _io_dev_install_ext(identifier,
        _io_spi_open, _io_spi_close,
        _io_spi_read, _io_spi_write,
        _io_spi_ioctl,
        _io_spi_uninstall,
        (void *)driver_data);

    if (error_code)
    {
        /* deinitialize low level driver */
        if (driver_data->DEVIF->DEINIT)
            driver_data->DEVIF->DEINIT(driver_data->DEVIF_DATA);

        _lwsem_destroy(&driver_data->BUS_LOCK);
        _mem_free(driver_data);
        return error_code;
    }

    return MQX_OK;
}
Exemplo n.º 11
0
uint_32 _io_usb_mfs_install
   (
      /* [IN] A string that identifies the device for fopen */
      char_ptr                      identifier,

      /* [IN] Logical unit number which driver need to install */
      uint_8                        logical_unit,

      /* [IN] Interface Handle */
      CLASS_CALL_STRUCT_PTR         ccs_ptr

   )
{ /* Body */
   IO_USB_MFS_STRUCT_PTR            info_ptr;
   USB_MASS_CLASS_INTF_STRUCT_PTR   intf_ptr = NULL;
   USB_STATUS                       error = USBERR_ERROR;

   /* Pointer validity-checking, clear memory, init header */
   USB_lock();
   if (usb_host_class_intf_validate(ccs_ptr)) {
      intf_ptr = (USB_MASS_CLASS_INTF_STRUCT_PTR) ccs_ptr->class_intf_handle;
      if(intf_ptr != NULL) {
         error = usb_hostdev_validate (intf_ptr->G.dev_handle);
      }
   } /* Endif */

   if (USB_OK != error) { /* Device was already detached or intf_ptr is NULL */
      USB_unlock();
      return MQX_OUT_OF_MEMORY;
   }

   if (USB_OK != _usb_hostdev_get_buffer(intf_ptr->G.dev_handle, sizeof(IO_USB_MFS_STRUCT), (pointer *) &info_ptr)) {
      USB_unlock();
      return MQX_OUT_OF_MEMORY;
   }

   _mem_zero(info_ptr, sizeof(IO_USB_MFS_STRUCT));
   _mem_set_type(info_ptr, MEM_TYPE_USB_MFS_STRUCT);

   USB_unlock();

   /* Fill in the state structure with the info we know */
   info_ptr->LUN         = logical_unit;
   info_ptr->BLENGTH     = USB_MFS_DEFAULT_SECTOR_SIZE;
   info_ptr->ERROR_CODE  = IO_OK;
   info_ptr->BLOCK_MODE  = TRUE;

   info_ptr->COMMAND.CBW_PTR = (CBW_STRUCT_PTR) &info_ptr->CBW;
   info_ptr->COMMAND.CSW_PTR = (CSW_STRUCT_PTR) &info_ptr->CSW;
   info_ptr->COMMAND.CALL_PTR = ccs_ptr;
   info_ptr->COMMAND.LUN = logical_unit;
   info_ptr->COMMAND.CALLBACK = _io_usb_mfs_callback;
   info_ptr->COMMAND_STATUS = MQX_OK;
   _lwsem_create(&info_ptr->LWSEM, 1);
   _lwsem_create(&info_ptr->COMMAND_DONE, 0);

   return (_io_dev_install_ext(identifier,
      (_mqx_int (_CODE_PTR_)(MQX_FILE_PTR, char_ptr,  char_ptr))_io_usb_mfs_open,
      (_mqx_int (_CODE_PTR_)(MQX_FILE_PTR)                     )_io_usb_mfs_close,
      (_mqx_int (_CODE_PTR_)(MQX_FILE_PTR, char_ptr,  int_32)  )_io_usb_mfs_read,
      (_mqx_int (_CODE_PTR_)(MQX_FILE_PTR, char_ptr,  int_32)  )_io_usb_mfs_write,
      (_mqx_int (_CODE_PTR_)(MQX_FILE_PTR, _mqx_uint, pointer) ) _io_usb_mfs_ioctl,
      _io_usb_mfs_uninstall_internal,
      (pointer)info_ptr
      ));

} /* Endbody */
Exemplo n.º 12
0
_mqx_uint _io_asrc_install
   (
      /* [IN] A string that identifies the device for fopen */
      char *               identifier,

      /* [IN] The I/O init function */
      _mqx_uint (_CODE_PTR_ init)(void *, void * *),

      /* The I/O open function */
      _mqx_uint (_CODE_PTR_ open)(void *, void *, char *),

      /* The I/O open function */
      _mqx_uint (_CODE_PTR_ close)(void *, void *),

      /* [IN] The I/O de-init function */
      _mqx_uint (_CODE_PTR_ deinit)(void *),

      /* [IN] The I/O ioctl function */
      _mqx_int  (_CODE_PTR_ ioctl)(void *, void *, _mqx_uint, _mqx_uint_ptr),

      /* [IN] The I/O init data pointer */
      void *               init_data_ptr,

      /* [IN] functions for pcm manager*/
      ASRC_PCMM_FUNCS_STRUCT_PTR   pcmm_funcs_ptr

   )

{ /* Body */
   IO_ASRC_DEVICE_STRUCT_PTR asrc_io_dev_ptr;
   MUTEX_ATTR_STRUCT mutex_attr;

   asrc_io_dev_ptr = (IO_ASRC_DEVICE_STRUCT_PTR)_mem_alloc_system_zero(
        (_mem_size)sizeof (IO_ASRC_DEVICE_STRUCT));
   if (asrc_io_dev_ptr == NULL)
   {
      return MQX_OUT_OF_MEMORY;
   }
   _mem_set_type (asrc_io_dev_ptr, MEM_TYPE_IO_ASRC_DEVICE_STRUCT);

   asrc_io_dev_ptr->DEV_INIT          = init;
   asrc_io_dev_ptr->DEV_OPEN          = open;
   asrc_io_dev_ptr->DEV_CLOSE         = close;
   asrc_io_dev_ptr->DEV_DEINIT        = deinit;
   asrc_io_dev_ptr->DEV_IOCTL         = ioctl;
   asrc_io_dev_ptr->DEV_INIT_DATA_PTR = init_data_ptr;
   asrc_io_dev_ptr->DEV_INFO_PTR      = NULL;
   asrc_io_dev_ptr->COUNT             = 0;

   asrc_io_dev_ptr->PCMM_DRV_FUNCS_PTR = pcmm_funcs_ptr;

   _mutatr_init(&mutex_attr);
   _mutatr_set_sched_protocol(&mutex_attr, MUTEX_PRIO_INHERIT);
   _mutex_init(&asrc_io_dev_ptr->DEV_MUTEX, &mutex_attr);

   if (NULL != pcmm_funcs_ptr) {
     /*register to pcm manager*/

     /*set pcm handle to a valid value*/
     asrc_io_dev_ptr->PCMM_DRV_HANDLE = PCMM_HANDLE_ASRC_VALID;

   }

   return (_io_dev_install_ext (identifier,
      _io_asrc_open,  _io_asrc_close,
      NULL,  NULL,
      _io_asrc_ioctl, _io_asrc_uninstall,
      (void *)asrc_io_dev_ptr));

} /* Endbody */
Exemplo n.º 13
0
_mqx_uint _io_pcb_shm_install
    (
        /* [IN] the name of this device */
        char    *device_name_ptr,

        /* [IN] the initialization record for this device */
        void       *init_ptr
    )
{
    IO_PCB_SHM_INFO_STRUCT_PTR info_ptr;
    uint32_t                    tmp;

    info_ptr = _mem_alloc_system_zero(sizeof(IO_PCB_SHM_INFO_STRUCT));
    if (info_ptr == NULL) {
        return(MQX_OUT_OF_MEMORY);
    }

    info_ptr->INIT = *((IO_PCB_SHM_INIT_STRUCT_PTR)init_ptr);

    /* Initialize the info structure */
    /*
    ** Set the Tx and Rx RINGPTR address base
    **
    */
    info_ptr->TX_RING_PTR = (IO_PCB_SHM_BUFFER_STRUCT_PTR)(
        ((IO_PCB_SHM_INIT_STRUCT_PTR)init_ptr)->TX_BD_ADDR);

    info_ptr->TX_RING_PTR = (IO_PCB_SHM_BUFFER_STRUCT_PTR)
        SHM_DESCR_ALIGN((uint32_t)info_ptr->TX_RING_PTR);
    tmp = (uint32_t)(IO_PCB_SHM_BUFFER_STRUCT_PTR)(((IO_PCB_SHM_INIT_STRUCT_PTR)
        init_ptr)->TX_LIMIT_ADDR);
    tmp -= (uint32_t)(info_ptr->TX_RING_PTR);
    tmp /= sizeof(IO_PCB_SHM_BUFFER_STRUCT);

    info_ptr->TXENTRIES = tmp;
    info_ptr->TX_LENGTH = tmp;
    info_ptr->TXNEXT = 0;
    info_ptr->TXLAST = 0;

    info_ptr->RX_RING_PTR = (IO_PCB_SHM_BUFFER_STRUCT_PTR)(
        ((IO_PCB_SHM_INIT_STRUCT_PTR)init_ptr)->RX_BD_ADDR);

    info_ptr->RX_RING_PTR = (IO_PCB_SHM_BUFFER_STRUCT_PTR)
        SHM_DESCR_ALIGN((uint32_t)info_ptr->RX_RING_PTR);

    tmp = (uint32_t)(IO_PCB_SHM_BUFFER_STRUCT_PTR)(((IO_PCB_SHM_INIT_STRUCT_PTR)
        init_ptr)->RX_LIMIT_ADDR);
    tmp -= (uint32_t)(info_ptr->RX_RING_PTR);
    tmp /= sizeof(IO_PCB_SHM_BUFFER_STRUCT);
    info_ptr->RXENTRIES = tmp;
    info_ptr->RX_LENGTH = tmp;
    info_ptr->RXNEXT = 0;
    info_ptr->RXLAST = 0;

    return (_io_dev_install_ext(device_name_ptr,
        _io_pcb_shm_open,
        _io_pcb_shm_close,
        _io_pcb_shm_read,
        _io_pcb_shm_write,
        _io_pcb_shm_ioctl,
        _io_pcb_shm_uninstall,
        (void *)info_ptr));

}
Exemplo n.º 14
0
/*FUNCTION****************************************************************
*
* Function Name    : _io_spi_install
* Returned Value   : MQX error code
* Comments         :
*    Installs SPI device.
*
*END**********************************************************************/
_mqx_int _io_spi_install
    (
        /* [IN] A string that identifies the device for fopen */
        char                       *identifier,

        /* [IN] Pointer to driver initialization data */
        SPI_INIT_STRUCT_CPTR           init_data_ptr
    )
{
    SPI_DRIVER_DATA_STRUCT_PTR driver_data;

    _mqx_int error_code = MQX_OK;

    if ((init_data_ptr->DEVIF->SETPARAM == NULL) || (init_data_ptr->DEVIF->TX_RX == NULL))
    {
        /* Missing mandatory low level driver function */
        return IO_ERROR_DEVICE_INVALID;
    }

    driver_data = (SPI_DRIVER_DATA_STRUCT_PTR)_mem_alloc_system_zero((_mem_size)sizeof(SPI_DRIVER_DATA_STRUCT));
    if (driver_data == NULL)
    {
        return MQX_OUT_OF_MEMORY;
    }
    _mem_set_type(driver_data, MEM_TYPE_IO_SPI_POLLED_DEVICE_STRUCT);

    driver_data->CS_CALLBACK = init_data_ptr->CS_CALLBACK;
    driver_data->CS_USERDATA= init_data_ptr->CS_USERDATA;
    driver_data->PARAMS = init_data_ptr->PARAMS;
    driver_data->DEVIF = init_data_ptr->DEVIF;

    /* initialize low level driver */
    if (driver_data->DEVIF->INIT)
        error_code = driver_data->DEVIF->INIT(init_data_ptr->DEVIF_INIT, &(driver_data->DEVIF_DATA));

    if (error_code != MQX_OK)
    {
        _mem_free(driver_data);
        return error_code;
    }

    _lwsem_create(&driver_data->BUS_LOCK, 1);

    error_code = _io_dev_install_ext(identifier,
        _io_spi_open, _io_spi_close,
        _io_spi_read, _io_spi_write,
        _io_spi_ioctl,
        _io_spi_uninstall,
        (void *)driver_data);

    if (error_code)
    {
        /* deinitialize low level driver */
        if (driver_data->DEVIF->DEINIT)
            driver_data->DEVIF->DEINIT(driver_data->DEVIF_DATA);

        _lwsem_destroy(&driver_data->BUS_LOCK);
        _mem_free(driver_data);
        return error_code;
    }

    return MQX_OK;
}