uint_32 _io_apcflash_install ( /* [IN] A string that identifies the device for fopen */ char_ptr identifier ) { /* Body */ IO_PCFLASH_STRUCT_PTR info_ptr; /* Allocate memory for the state structure */ info_ptr = _mem_alloc_system_zero((uint_32)sizeof(IO_PCFLASH_STRUCT)); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (info_ptr == NULL) { return(MQX_OUT_OF_MEMORY); } /* Endif */ #endif _mem_set_type(info_ptr,MEM_TYPE_IO_PCFLASH); /* Fill in the state structure with the info we know */ info_ptr->DRIVE = 0; /* always use ATA device 0 */ info_ptr->SECTOR_SIZE = ATA_SECTOR_SIZE; info_ptr->TEMP_BUFF_PTR = NULL; info_ptr->ERROR_CODE = IO_OK; _lwsem_create(&info_ptr->LWSEM, 1L); return (_io_dev_install(identifier, (_mqx_int (_CODE_PTR_)(MQX_FILE_PTR, char _PTR_, char _PTR_))_io_apcflash_open, (_mqx_int (_CODE_PTR_)(MQX_FILE_PTR)) _io_apcflash_close, (_mqx_int (_CODE_PTR_)(MQX_FILE_PTR, char_ptr, _mqx_int)) _io_apcflash_read, (_mqx_int (_CODE_PTR_)(MQX_FILE_PTR, char_ptr, _mqx_int)) _io_apcflash_write, (_mqx_int (_CODE_PTR_)(MQX_FILE_PTR, _mqx_uint, pointer)) _io_apcflash_ioctl, (pointer)info_ptr)); } /* Endbody */
/*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 */
_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 */
/*FUNCTION**************************************************************** * * Function Name : _dspi_polled_install * Returned Value : MQX error code * Comments : * Install an SPI device. * *END*********************************************************************/ uint_32 _dspi_polled_install ( /* [IN] A string that identifies the device for fopen */ char_ptr identifier, /* [IN] The I/O init data pointer */ DSPI_INIT_STRUCT_CPTR init_data_ptr ) { return _io_spi_polled_install(identifier, (uint_32 (_CODE_PTR_)(pointer, pointer _PTR_, char_ptr))_dspi_polled_init, (uint_32 (_CODE_PTR_)(pointer, pointer))_dspi_polled_deinit, (_mqx_int (_CODE_PTR_)(pointer, char_ptr, int_32))_dspi_polled_rx, (_mqx_int (_CODE_PTR_)(pointer, char_ptr, int_32))_dspi_polled_tx, (_mqx_int (_CODE_PTR_)(pointer, uint_32, _mqx_uint_ptr, uint_32))_dspi_polled_ioctl, (pointer)init_data_ptr); }
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 */
_mqx_int _io_usb_mfs_read_write_sectors_internal ( /* [IN] the file handle for the device */ MQX_FILE_PTR fd_ptr, /* [IN] USB MFS state structure */ IO_USB_MFS_STRUCT_PTR info_ptr, /* [IN] where the newly-read bytes are to be stored */ char_ptr data_ptr, /* [IN] the number of sectors to read */ uint_32 num, /* [IN] Read/write mode */ boolean write ) { /* Body */ _mqx_int (_CODE_PTR_ rw_func_long)(IO_USB_MFS_STRUCT_PTR, uint_32, uint_32, uchar_ptr); _mqx_int (_CODE_PTR_ rw_func)(IO_USB_MFS_STRUCT_PTR, uint_32, uint_16, uchar_ptr); _mqx_int io_result = IO_ERROR; _mqx_uint io_error; if (write) { io_error = IO_ERROR_WRITE_ACCESS; rw_func = _io_usb_mfs_write_sector_internal; rw_func_long = _io_usb_mfs_write_sector_long_internal; } else { io_error = IO_ERROR_READ_ACCESS; rw_func = _io_usb_mfs_read_sector_internal; rw_func_long = _io_usb_mfs_read_sector_long_internal; } /* Endif */ if (fd_ptr->LOCATION >= info_ptr->BCOUNT) { fd_ptr->ERROR = io_error; } else { if ((num + fd_ptr->LOCATION) >= info_ptr->BCOUNT) { fd_ptr->ERROR = (_mqx_uint)io_error; num = (uint_32)(info_ptr->BCOUNT - fd_ptr->LOCATION + 1); } /* Endif */ /* Read all the sectors, one at a time */ if (num > 0xFFFE) { /* Read all the sectors at once */ io_result = rw_func_long(info_ptr, fd_ptr->LOCATION, num, (uchar_ptr)data_ptr); } else { io_result = rw_func(info_ptr, fd_ptr->LOCATION, (uint_16)num, (uchar_ptr)data_ptr); } /* Endif */ if (io_result == IO_ERROR ) { fd_ptr->ERROR = io_error; } else { fd_ptr->LOCATION += num; } /* Endif */ } /* Endif */ return io_result; } /* Endbody */