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_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 */
boolean _io_serial_int_addc ( /* [IN] the interrupt I/O context information */ IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr, /* [IN] the character to add to the input queue */ char c ) { /* Body */ CHARQ_STRUCT_PTR in_queue; _mqx_uint ioctl_val; if (int_io_dev_ptr->FLAGS & IO_SERIAL_XON_XOFF) { if (int_io_dev_ptr->HAVE_STOPPED_OUTPUT) { if (c == CNTL_Q) { int_io_dev_ptr->HAVE_STOPPED_OUTPUT = FALSE; return TRUE; } /* Endif */ } else { if (c == CNTL_S) { int_io_dev_ptr->HAVE_STOPPED_OUTPUT = TRUE; return TRUE; } /* Endif */ } /* Endif */ } /* Endif */ in_queue = int_io_dev_ptr->IN_QUEUE; if (_CHARQ_NOT_FULL(in_queue)) { _CHARQ_ENQUEUE(in_queue,c); if (int_io_dev_ptr->FLAGS & (IO_SERIAL_XON_XOFF | IO_SERIAL_HW_FLOW_CONTROL)) { if (_CHARQ_SIZE(in_queue) > int_io_dev_ptr->INPUT_HIGH_WATER_MARK) { if (!int_io_dev_ptr->HAVE_STOPPED_INPUT) { if (int_io_dev_ptr->FLAGS & IO_SERIAL_XON_XOFF) { int_io_dev_ptr->MUST_STOP_INPUT = TRUE; } else { if (int_io_dev_ptr->DEV_IOCTL != NULL) { ioctl_val = IO_SERIAL_RTS; (*int_io_dev_ptr->DEV_IOCTL)(int_io_dev_ptr->DEV_INFO_PTR, IO_IOCTL_SERIAL_CLEAR_HW_SIGNAL, &ioctl_val); } int_io_dev_ptr->HAVE_STOPPED_INPUT = TRUE; } /* Endif */ } /* Endif */ } else if (_CHARQ_SIZE(in_queue) < int_io_dev_ptr->INPUT_LOW_WATER_MARK) { if (int_io_dev_ptr->HAVE_STOPPED_INPUT) { if (int_io_dev_ptr->FLAGS & IO_SERIAL_XON_XOFF) { int_io_dev_ptr->MUST_START_INPUT = TRUE; } else { if (int_io_dev_ptr->DEV_IOCTL != NULL) { 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); } int_io_dev_ptr->HAVE_STOPPED_INPUT = FALSE; } /* Endif */ } /* Endif */ } /* Endif */ } /* Endif */ } else { /* indicate that tossed the character */ return FALSE; } /* Endif */ if (_QUEUE_GET_SIZE(int_io_dev_ptr->IN_WAITING_TASKS)) { _taskq_resume(int_io_dev_ptr->IN_WAITING_TASKS, TRUE); } /* Endif */ return TRUE; } /* Endbody */