static bool _io_serial_mix_putc_internal ( /* [IN] the interrupt io device information */ IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr, /* [IN] the character to print out */ char c, _mqx_uint flags ) { /* Body */ volatile CHARQ_STRUCT *out_queue; /* Start CR 388 */ #if (PSP_MEMORY_ADDRESSING_CAPABILITY > 8 ) c &= 0xFF; #endif /* End CR 388 */ out_queue = int_io_dev_ptr->OUT_QUEUE; _int_disable(); if(flags & IO_SERIAL_NON_BLOCKING) { if (_CHARQ_FULL(out_queue)) { _int_enable(); return FALSE; } /* Endif */ } else { if(int_io_dev_ptr->HAVE_STOPPED_OUTPUT) { _taskq_suspend(int_io_dev_ptr->OUT_WAITING_TASKS); } /* Endif */ while (_CHARQ_FULL(out_queue)) { /* Lets wait */ _taskq_suspend(int_io_dev_ptr->OUT_WAITING_TASKS); } /* Endif */ } /* Endif */ if (int_io_dev_ptr->HAVE_STOPPED_OUTPUT || (int_io_dev_ptr->OUTPUT_ENABLED && !(int_io_dev_ptr->TX_DEV_PUTC))) { _CHARQ_ENQUEUE(out_queue,c); } else { int_io_dev_ptr->OUTPUT_ENABLED = TRUE; (*int_io_dev_ptr->DEV_PUTC)(int_io_dev_ptr, c); } /* Endif */ _int_enable(); return TRUE; } /* 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_pipe_write ( /* [IN] the handle returned from _fopen */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] where the characters to write out are */ char _PTR_ data_ptr, /* [IN] the number of characters to write */ _mqx_int num ) { /* Body */ volatile IO_PIPE_INFO_STRUCT_PTR io_pipe_info_ptr; uint_32 i = num + 1; uchar c; volatile CHARQ_STRUCT _PTR_ pipe_queue; uint_32 error; io_pipe_info_ptr = fd_ptr->DEV_DATA_PTR; pipe_queue = io_pipe_info_ptr->QUEUE; /* Turn off pipe abort flags */ io_pipe_info_ptr->KM_ABORT_WRITE = FALSE; /* Lock out other reading tasks */ error = _mutex_lock(&io_pipe_info_ptr->WRITE_MUTEX); #if MQX_CHECK_ERRORS if ( error != MQX_EOK ) { return (-1); } /* Endif */ #endif /* Lock out access of a writer task to the pipe data structures */ error = _mutex_lock(&io_pipe_info_ptr->ACCESS_MUTEX); #if MQX_CHECK_ERRORS if ( error != MQX_EOK ) { return (-1); } /* Endif */ #endif /* Start writing characters to the pipe */ while ( --i ) { /* If the pipe is full, wait until the pipe is not full */ while ( _CHARQ_FULL(pipe_queue) ) { error = _mutex_unlock(&io_pipe_info_ptr->ACCESS_MUTEX); #if MQX_CHECK_ERRORS if ( error != MQX_EOK ) { return (-1); } /* Endif */ #endif error = _lwsem_post(&io_pipe_info_ptr->EMPTY_SEM); #if MQX_CHECK_ERRORS if ( error != MQX_OK ) { return (-1); } /* Endif */ #endif error = _lwsem_wait(&io_pipe_info_ptr->FULL_SEM); #if MQX_CHECK_ERRORS if ( error != MQX_OK ) { return (-1); } /* Endif */ #endif if(io_pipe_info_ptr->KM_ABORT_WRITE) { io_pipe_info_ptr->KM_ABORT_WRITE = FALSE; error = _mutex_unlock(&io_pipe_info_ptr->WRITE_MUTEX); #if MQX_CHECK_ERRORS if ( error != MQX_EOK ) { return (-1); } /* Endif */ #endif return num - i; } /* Lock out access of a writer task to the pipe data structures */ error = _mutex_lock(&io_pipe_info_ptr->ACCESS_MUTEX); #if MQX_CHECK_ERRORS if ( error != MQX_EOK ) { return (-1); } /* Endif */ #endif } /* Endwhile */ c = *data_ptr++; /* Write the next char into the pipe */ _CHARQ_ENQUEUE(pipe_queue,c); } /* Endwhile */ error = _lwsem_post(&io_pipe_info_ptr->EMPTY_SEM); #if MQX_CHECK_ERRORS if ( error != MQX_OK ) { return (-1); } /* Endif */ #endif /* Unlock access mutex and write mutex */ error = _mutex_unlock(&io_pipe_info_ptr->ACCESS_MUTEX); #if MQX_CHECK_ERRORS if ( error != MQX_EOK ) { return (-1); } /* Endif */ #endif error = _mutex_unlock(&io_pipe_info_ptr->WRITE_MUTEX); #if MQX_CHECK_ERRORS if ( error != MQX_EOK ) { return (-1); } /* Endif */ #endif return num; } /* Endbody */