static _mqx_int _io_serial_mix_open ( /* [IN] the file handle for the device being opened */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the remaining portion of the name of the device */ char *open_name_ptr, /* [IN] the flags to be used during operation: ** echo, translation, xon/xoff */ char *flags ) { /* Body */ IO_DEVICE_STRUCT_PTR io_dev_ptr; IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr; _mqx_uint result = MQX_OK; _mqx_uint ioctl_val; io_dev_ptr = fd_ptr->DEV_PTR; int_io_dev_ptr = (void *)io_dev_ptr->DRIVER_INIT_PTR; if (int_io_dev_ptr->COUNT) { /* Device is already opened */ int_io_dev_ptr->COUNT++; fd_ptr->FLAGS = int_io_dev_ptr->FLAGS; return(result); } /* Endif */ int_io_dev_ptr->IN_WAITING_TASKS = _taskq_create(MQX_TASK_QUEUE_FIFO); int_io_dev_ptr->OUT_WAITING_TASKS = _taskq_create(MQX_TASK_QUEUE_FIFO); int_io_dev_ptr->OUT_QUEUE = (void *)_mem_alloc_system( sizeof(CHARQ_STRUCT) - (4 * sizeof(char)) + int_io_dev_ptr->OQUEUE_SIZE); _mem_set_type(int_io_dev_ptr->OUT_QUEUE,MEM_TYPE_IO_SERIAL_OUT_QUEUE); _CHARQ_INIT(int_io_dev_ptr->OUT_QUEUE, int_io_dev_ptr->OQUEUE_SIZE); int_io_dev_ptr->FLAGS = (_mqx_uint)flags; fd_ptr->FLAGS = (_mqx_uint)flags; result = (*int_io_dev_ptr->DEV_INIT)(int_io_dev_ptr, open_name_ptr); if (result == MQX_OK) { result = (*int_io_dev_ptr->DEV_ENABLE_INTS)(int_io_dev_ptr->DEV_INFO_PTR); } /* Endif */ if (result != MQX_OK) { _mem_free(int_io_dev_ptr->OUT_QUEUE); _taskq_destroy(int_io_dev_ptr->IN_WAITING_TASKS); _taskq_destroy(int_io_dev_ptr->OUT_WAITING_TASKS); } int_io_dev_ptr->COUNT = 1; return(result); } /* Endbody */
_mqx_int _io_pipe_open ( /* [IN] the file handle for the device being opened */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the remaining portion of the name of the device */ char _PTR_ open_name_ptr, /* [IN] the flags to be used during operation: ** echo, translation, xon/xoff */ char _PTR_ flags ) { /* Body */ IO_DEVICE_STRUCT_PTR io_dev_ptr = fd_ptr->DEV_PTR; IO_PIPE_INIT_STRUCT_PTR io_pipe_init_ptr; IO_PIPE_INFO_STRUCT_PTR io_pipe_info_ptr; MUTEX_ATTR_STRUCT mutex_attr; uint_32 result = MQX_OK; /* Allocate a Pipe information structure */ io_pipe_info_ptr = _mem_alloc_system_zero( (uint_32)sizeof(IO_PIPE_INFO_STRUCT)); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (io_pipe_info_ptr == NULL){ return(MQX_OUT_OF_MEMORY); }/* Endif */ #endif fd_ptr->DEV_DATA_PTR = io_pipe_info_ptr; io_pipe_init_ptr = (IO_PIPE_INIT_STRUCT_PTR)io_dev_ptr->DRIVER_INIT_PTR; io_pipe_info_ptr->QUEUE_SIZE = io_pipe_init_ptr->QUEUE_SIZE; /* Initialize mutexes */ result = _mutatr_init(&mutex_attr); #if MQX_CHECK_ERRORS if (result != MQX_EOK) { _mem_free(io_pipe_info_ptr); return (result); } /* Endif */ #endif _mutatr_set_wait_protocol(&mutex_attr, MUTEX_PRIORITY_QUEUEING); _mutatr_set_sched_protocol(&mutex_attr, MUTEX_PRIO_INHERIT); result = _mutex_init(&io_pipe_info_ptr->READ_MUTEX, &mutex_attr); #if MQX_CHECK_ERRORS if (result != MQX_EOK) { _mem_free(io_pipe_info_ptr); return (result); } /* Endif */ #endif result = _mutex_init(&io_pipe_info_ptr->WRITE_MUTEX, &mutex_attr); #if MQX_CHECK_ERRORS if (result != MQX_EOK) { _mem_free(io_pipe_info_ptr); return (result); } /* Endif */ #endif result = _mutex_init(&io_pipe_info_ptr->ACCESS_MUTEX, &mutex_attr); #if MQX_CHECK_ERRORS if (result != MQX_EOK) { _mem_free(io_pipe_info_ptr); return (result); } /* Endif */ #endif /* Initialize semaphores */ result = _lwsem_create(&io_pipe_info_ptr->FULL_SEM, 0); #if MQX_CHECK_ERRORS if (result != MQX_OK) { _mem_free(io_pipe_info_ptr); return (result); } /* Endif */ #endif result = _lwsem_create(&io_pipe_info_ptr->EMPTY_SEM, 0); #if MQX_CHECK_ERRORS if (result != MQX_OK) { _mem_free(io_pipe_info_ptr); return (result); } /* Endif */ #endif /* Allocate queue structure for pipe char queue */ io_pipe_info_ptr->QUEUE = (pointer)_mem_alloc_system( sizeof(CHARQ_STRUCT) - (4 * sizeof(char)) + io_pipe_info_ptr->QUEUE_SIZE); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (io_pipe_info_ptr->QUEUE == NULL){ _mem_free(io_pipe_info_ptr); return(MQX_OUT_OF_MEMORY); }/* Endif */ #endif /* Initialize Pipe queue */ _CHARQ_INIT(io_pipe_info_ptr->QUEUE, io_pipe_init_ptr->QUEUE_SIZE); return(result); } /* Endbody */
_mqx_int _io_pipe_ioctl ( /* [IN] the handle returned from _fopen */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the ioctl command */ uint_32 cmd, /* [IN] the ioctl parameters */ pointer param_ptr ) { /* Body */ IO_PIPE_INFO_STRUCT_PTR io_pipe_info_ptr; uint_32 result = MQX_OK; _mqx_uint_ptr uparam_ptr = param_ptr; io_pipe_info_ptr = fd_ptr->DEV_DATA_PTR; result = _mutex_lock(&io_pipe_info_ptr->ACCESS_MUTEX); #if MQX_CHECK_ERRORS if ( result != MQX_OK ) { return (result); } /* Endif */ #endif switch (cmd) { case PIPE_IOCTL_CHAR_AVAIL: if ( !_CHARQ_EMPTY(io_pipe_info_ptr->QUEUE) ) { *uparam_ptr = (uint_32)TRUE; } else { *uparam_ptr = (uint_32)FALSE; } /* Endif */ break; case PIPE_IOCTL_GET_SIZE: *uparam_ptr = io_pipe_info_ptr->QUEUE_SIZE; break; case PIPE_IOCTL_FULL: if ( _CHARQ_FULL(io_pipe_info_ptr->QUEUE) ) { *uparam_ptr = (uint_32)TRUE; } else { *uparam_ptr = (uint_32)FALSE; } /* Endif */ break; case PIPE_IOCTL_EMPTY: if ( _CHARQ_EMPTY(io_pipe_info_ptr->QUEUE) ) { *uparam_ptr = (uint_32)TRUE; } else { *uparam_ptr = (uint_32)FALSE; } /* Endif */ break; case PIPE_IOCTL_RE_INIT: _CHARQ_INIT(io_pipe_info_ptr->QUEUE, io_pipe_info_ptr->QUEUE_SIZE) io_pipe_info_ptr->KM_ABORT_READ = TRUE; io_pipe_info_ptr->KM_ABORT_WRITE = TRUE; result = _lwsem_post(&io_pipe_info_ptr->EMPTY_SEM); #if MQX_CHECK_ERRORS if ( result != MQX_OK ) { return (-1); } /* Endif */ #endif result = _lwsem_post(&io_pipe_info_ptr->FULL_SEM); #if MQX_CHECK_ERRORS if ( result != MQX_OK ) { return (-1); } /* Endif */ #endif break; case PIPE_IOCTL_NUM_CHARS_FULL: *uparam_ptr = _CHARQ_SIZE(io_pipe_info_ptr->QUEUE); break; case PIPE_IOCTL_NUM_CHARS_FREE: *uparam_ptr = io_pipe_info_ptr->QUEUE_SIZE - _CHARQ_SIZE(io_pipe_info_ptr->QUEUE); break; default: break; } /* Endswitch */ result = _mutex_unlock(&io_pipe_info_ptr->ACCESS_MUTEX); #if MQX_CHECK_ERRORS if ( result != MQX_OK ) { return (result); } /* Endif */ #endif return result; } /* Endbody */
_mqx_int _io_serial_int_open ( /* [IN] the file handle for the device being opened */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the remaining portion of the name of the device */ char _PTR_ open_name_ptr, /* [IN] the flags to be used during operation: ** echo, translation, xon/xoff */ char _PTR_ flags ) { /* Body */ IO_DEVICE_STRUCT_PTR io_dev_ptr; IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr; _mqx_uint result = MQX_OK; _mqx_uint ioctl_val; io_dev_ptr = fd_ptr->DEV_PTR; int_io_dev_ptr = (pointer)io_dev_ptr->DRIVER_INIT_PTR; if (int_io_dev_ptr->COUNT) { /* Device is already opened */ int_io_dev_ptr->COUNT++; fd_ptr->FLAGS = int_io_dev_ptr->FLAGS; return(result); } /* Endif */ int_io_dev_ptr->IN_WAITING_TASKS = _taskq_create(MQX_TASK_QUEUE_FIFO); int_io_dev_ptr->OUT_WAITING_TASKS = _taskq_create(MQX_TASK_QUEUE_FIFO); int_io_dev_ptr->IN_QUEUE = (pointer)_mem_alloc_system( sizeof(CHARQ_STRUCT) - (4 * sizeof(char)) + int_io_dev_ptr->QUEUE_SIZE); int_io_dev_ptr->OUT_QUEUE = (pointer)_mem_alloc_system( sizeof(CHARQ_STRUCT) - (4 * sizeof(char)) + int_io_dev_ptr->QUEUE_SIZE); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if ((int_io_dev_ptr->IN_QUEUE == NULL) || (int_io_dev_ptr->OUT_QUEUE == NULL) || (int_io_dev_ptr->IN_WAITING_TASKS == NULL) || (int_io_dev_ptr->OUT_WAITING_TASKS == NULL)) { if (int_io_dev_ptr->IN_QUEUE != NULL){ _mem_free(int_io_dev_ptr->IN_QUEUE); } /* Endif */ if (int_io_dev_ptr->OUT_QUEUE != NULL){ _mem_free(int_io_dev_ptr->OUT_QUEUE); } /* Endif */ if (int_io_dev_ptr->IN_WAITING_TASKS != NULL) { _taskq_destroy(int_io_dev_ptr->IN_WAITING_TASKS); }/* Endif */ if (int_io_dev_ptr->OUT_WAITING_TASKS != NULL) { _taskq_destroy(int_io_dev_ptr->OUT_WAITING_TASKS); }/* Endif */ return(MQX_OUT_OF_MEMORY); }/* Endif */ #endif _mem_set_type(int_io_dev_ptr->IN_QUEUE,MEM_TYPE_IO_SERIAL_IN_QUEUE); _mem_set_type(int_io_dev_ptr->OUT_QUEUE,MEM_TYPE_IO_SERIAL_OUT_QUEUE); _CHARQ_INIT(int_io_dev_ptr->IN_QUEUE, int_io_dev_ptr->QUEUE_SIZE); _CHARQ_INIT(int_io_dev_ptr->OUT_QUEUE, int_io_dev_ptr->QUEUE_SIZE); int_io_dev_ptr->INPUT_HIGH_WATER_MARK = int_io_dev_ptr->QUEUE_SIZE - int_io_dev_ptr->QUEUE_SIZE/8; int_io_dev_ptr->INPUT_LOW_WATER_MARK = int_io_dev_ptr->QUEUE_SIZE/2; int_io_dev_ptr->FLAGS = (_mqx_uint)flags; fd_ptr->FLAGS = (_mqx_uint)flags; #if MQX_ENABLE_LOW_POWER _lwsem_wait (&(int_io_dev_ptr->LPM_INFO.LOCK)); #endif result = (*int_io_dev_ptr->DEV_INIT)(int_io_dev_ptr, open_name_ptr); #if MQX_ENABLE_LOW_POWER _lwsem_post (&(int_io_dev_ptr->LPM_INFO.LOCK)); #endif if (result == MQX_OK) { #if MQX_ENABLE_LOW_POWER _lwsem_wait (&(int_io_dev_ptr->LPM_INFO.LOCK)); #endif result = (*int_io_dev_ptr->DEV_ENABLE_INTS)(int_io_dev_ptr->DEV_INFO_PTR); #if MQX_ENABLE_LOW_POWER _lwsem_post (&(int_io_dev_ptr->LPM_INFO.LOCK)); #endif if (int_io_dev_ptr->DEV_IOCTL != NULL) { if ((_mqx_uint)flags & IO_SERIAL_HW_FLOW_CONTROL) { ioctl_val = IO_SERIAL_RTS; (*int_io_dev_ptr->DEV_IOCTL)(int_io_dev_ptr->DEV_INFO_PTR, IO_IOCTL_SERIAL_SET_HW_SIGNAL, &ioctl_val); } /* Endif */ ioctl_val = (_mqx_uint)flags; (*int_io_dev_ptr->DEV_IOCTL)(int_io_dev_ptr->DEV_INFO_PTR, IO_IOCTL_SERIAL_SET_FLAGS, &ioctl_val); } if (result == MQX_OK && ((_mqx_uint)flags & IO_SERIAL_NON_BLOCKING) && (_mqx_uint)flags & (IO_SERIAL_TRANSLATION | IO_SERIAL_ECHO | IO_SERIAL_XON_XOFF)) { result = MQX_INVALID_PARAMETER; } /* Endif */ } /* Endif */ if (result != MQX_OK) { _mem_free(int_io_dev_ptr->IN_QUEUE); _mem_free(int_io_dev_ptr->OUT_QUEUE); _taskq_destroy(int_io_dev_ptr->IN_WAITING_TASKS); _taskq_destroy(int_io_dev_ptr->OUT_WAITING_TASKS); } int_io_dev_ptr->COUNT = 1; return(result); } /* Endbody */