Ejemplo n.º 1
0
static _mqx_int _io_serial_mix_nextc
   (
      /* [IN] the interrupt I/O context information */
      IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr
   )
{ /* Body */
   unsigned char c;

   if (int_io_dev_ptr->HAVE_STOPPED_OUTPUT
      || (! int_io_dev_ptr->OUTPUT_ENABLED))
   {
      return(-1);
   } /* Endif */

   if (_CHARQ_EMPTY(int_io_dev_ptr->OUT_QUEUE)) {
      /* No output */
      int_io_dev_ptr->OUTPUT_ENABLED = FALSE;
      if (_QUEUE_GET_SIZE(int_io_dev_ptr->OUT_WAITING_TASKS)) {
         _taskq_resume(int_io_dev_ptr->OUT_WAITING_TASKS, TRUE);
      } /* Endif */
      return(-1);
   }/* Endif */

   _CHARQ_DEQUEUE(int_io_dev_ptr->OUT_QUEUE, c);
   return((_mqx_int)c);

} /* Endbody */
Ejemplo n.º 2
0
_mqx_int _io_serial_int_nextc
   (
      /* [IN] the interrupt I/O context information */
      IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr
   )
{ /* Body */
   uchar c;

   if (int_io_dev_ptr->FLAGS & IO_SERIAL_XON_XOFF) {
      if (int_io_dev_ptr->MUST_STOP_INPUT) {
         int_io_dev_ptr->MUST_STOP_INPUT    = FALSE;
         int_io_dev_ptr->HAVE_STOPPED_INPUT = TRUE;
        return((int_32)CNTL_S);
      } else if (int_io_dev_ptr->MUST_START_INPUT) {
         int_io_dev_ptr->MUST_START_INPUT   = FALSE;
         int_io_dev_ptr->HAVE_STOPPED_INPUT = FALSE;
         return((int_32)CNTL_Q);
      } /* Endif */
   } /* Endif */

   if (int_io_dev_ptr->HAVE_STOPPED_OUTPUT
      || (! int_io_dev_ptr->OUTPUT_ENABLED))
   {
      return(-1);
   } /* Endif */

   if (_CHARQ_EMPTY(int_io_dev_ptr->OUT_QUEUE)) {
      /* No output */
      int_io_dev_ptr->OUTPUT_ENABLED = FALSE;
      if (_QUEUE_GET_SIZE(int_io_dev_ptr->OUT_WAITING_TASKS)) {
         _taskq_resume(int_io_dev_ptr->OUT_WAITING_TASKS, TRUE);
      } /* Endif */
      return(-1);
   }/* Endif */

   _CHARQ_DEQUEUE(int_io_dev_ptr->OUT_QUEUE, c);
   return((_mqx_int)c);

} /* Endbody */
Ejemplo n.º 3
0
_mqx_int _io_pipe_read
   (
      /* [IN] the handle returned from _fopen */
      FILE_DEVICE_STRUCT_PTR fd_ptr,

      /* [IN] where the characters are to be stored */
      char             _PTR_ data_ptr,

      /* [IN] the number of characters to input */
      _mqx_int               num
      
   )
{ /* Body */      
   volatile IO_PIPE_INFO_STRUCT_PTR       io_pipe_info_ptr;
   uchar                                  c;
   uint_32                                i = num + 1;
   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_READ = FALSE;
   
   /* Lock out other reading tasks */       
   error = _mutex_lock(&io_pipe_info_ptr->READ_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 reading characters from the pipe*/
   while ( --i ) {

     /* If the pipe is empty, wait until the pipe is not empty */                            
      while (_CHARQ_EMPTY(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->FULL_SEM);
      #if MQX_CHECK_ERRORS
         if ( error != MQX_OK ) {
            return (-1);
         } /* Endif */
      #endif   
         
         error = _lwsem_wait(&io_pipe_info_ptr->EMPTY_SEM);
      #if MQX_CHECK_ERRORS
         if ( error != MQX_OK ) {
            return (-1);
         } /* Endif */
      #endif   
         
       if(io_pipe_info_ptr->KM_ABORT_READ)
       {
		   error = _mutex_unlock(&io_pipe_info_ptr->READ_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 */

      /* Read char from pipe */
      _CHARQ_DEQUEUE(pipe_queue,c);

      /* Copy data to the returned buffer */
      *data_ptr++ = c;
                
   } /* Endwhile */

   error = _lwsem_post(&io_pipe_info_ptr->FULL_SEM);
#if MQX_CHECK_ERRORS
   if ( error != MQX_OK ) {
      return (-1);
   } /* Endif */
#endif   

   /* Unlock access access mutex and read 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->READ_MUTEX);

#if MQX_CHECK_ERRORS
   if ( error != MQX_EOK ) {
      return (-1);
   } /* Endif */
#endif
   
   return num;

} /* Endbody */
Ejemplo n.º 4
0
_mqx_int _io_serial_int_read
   (
      /* [IN] the handle returned from _fopen */
      FILE_DEVICE_STRUCT_PTR fd_ptr,

      /* [IN] where the characters are to be stored */
      char             _PTR_ data_ptr,

      /* [IN] the number of characters to input */
      _mqx_int               num
      
   )
{ /* Body */
   IO_DEVICE_STRUCT_PTR            io_dev_ptr;
   IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr;
   _mqx_int                        ioctl_val;
   uchar                           c = 0;
   _mqx_uint                       flags;
   _mqx_int                        i = num;
   volatile CHARQ_STRUCT _PTR_     in_queue;

   io_dev_ptr     = fd_ptr->DEV_PTR;
   int_io_dev_ptr = (pointer)io_dev_ptr->DRIVER_INIT_PTR;
   flags          = fd_ptr->FLAGS;

   while ( i ) {

      in_queue = int_io_dev_ptr->IN_QUEUE;
      _int_disable();
      if(flags & IO_SERIAL_NON_BLOCKING) {
          if (_CHARQ_SIZE(in_queue) == 0) {
              num -= i;
              _int_enable();
              break;
          } /* Endif */
      } else {
          while (_CHARQ_SIZE(in_queue) == 0) {
             _taskq_suspend(int_io_dev_ptr->IN_WAITING_TASKS);
          } /* Endwhile */  
      } /* Endif */
      _CHARQ_DEQUEUE(in_queue,c);

      if (int_io_dev_ptr->HAVE_STOPPED_INPUT) {
         if (_CHARQ_SIZE(in_queue) < int_io_dev_ptr->INPUT_LOW_WATER_MARK) {
            if (flags & IO_SERIAL_HW_FLOW_CONTROL) {
               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;
            } else {
               if (int_io_dev_ptr->OUTPUT_ENABLED && !int_io_dev_ptr->HAVE_STOPPED_OUTPUT) {
                  int_io_dev_ptr->MUST_START_INPUT = TRUE;
               } else {
                  int_io_dev_ptr->HAVE_STOPPED_INPUT = FALSE;
                  int_io_dev_ptr->OUTPUT_ENABLED = TRUE;
                  (*int_io_dev_ptr->DEV_PUTC)(int_io_dev_ptr, CNTL_Q);
               } /* Endif */
            } /* Endif */
         } /* Endif */
      } /* Endif */
      _int_enable();

      if (flags & IO_SERIAL_TRANSLATION) {
         if (c == '\r') {
            /* Start CR 387 */
            if (flags & IO_SERIAL_ECHO) {
               _io_serial_int_putc_internal(int_io_dev_ptr, (char)c, 0);
            } /* Endif */
            /* End CR 387 */
            c = '\n';
         } else if ((c == '\b') && (flags & IO_SERIAL_ECHO)) {
            _io_serial_int_putc_internal(int_io_dev_ptr, (char)'\b', 0);
            _io_serial_int_putc_internal(int_io_dev_ptr, (char)' ', 0);
         } /* Endif */
      } /* Endif */

      if (flags & IO_SERIAL_ECHO) {
         _io_serial_int_putc_internal(int_io_dev_ptr, (char)c, 0);
      } /* Endif */

      *data_ptr++ = c;
      --i;
      
   } /* Endwhile */

   return num;

} /* Endbody */