This is the mail archive of the ecos-discuss@sourceware.cygnus.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Getting serial buffer status: patch attached



>   In order to avoid re-designing the application completely, I
>   need to provide non-blocking serial I/O.
> 
>   Additionally, one of the requirements for the application is
>   that it be able to find out how much space is available in
>   the tx buffer [there's a lot of existing stuff that depends
>   on this ability, and not having it would require ton's of
>   application code to be scrapped.]

I've attached a patch that adds a config key and corresponding
codeto get the current rx/tx buffer info for a serial device.
This only returns status on the buffer implimented in the
mid-level serial driver, and doesn't take into account any FIFO
that the UART may have.

(It also fixes the typo in the 230400 baud rate constant.)

The diff was done against the CVS snapshot of 16 Feb or so.

-- 
Grant Edwards
grante@visi.com
--- ../ecos/packages/io/common/current/include/config_keys.h	Wed Feb  2 13:57:22 2000
+++ ./packages/io/common/current/include/config_keys.h	Fri Feb 25 15:38:11 2000
@@ -52,6 +52,7 @@
 #define CYG_IO_GET_CONFIG_SERIAL_OUTPUT_FLUSH    0x0103
 #define CYG_IO_GET_CONFIG_SERIAL_INPUT_FLUSH     0x0104
 #define CYG_IO_GET_CONFIG_SERIAL_ABORT           0x0105
+#define CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO     0x0111
 #define CYG_IO_SET_CONFIG_SERIAL_INFO            0x0181
 
 // Get/Set configuration 'key' values for tty-like driver
--- ../ecos/packages/io/serial/current/src/common/serial.c	Wed Feb  2 13:57:24 2000
+++ ./packages/io/serial/current/src/common/serial.c	Fri Feb 25 15:59:37 2000
@@ -297,6 +297,39 @@
         cyg_drv_dsr_unlock();
         cyg_drv_mutex_unlock(&cbuf->lock);
         break;
+      
+     case CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO:
+      // return rx/tx buffer sizes and counts
+        {
+          cyg_serial_buf_info_t *p;
+          if (*len < sizeof(cyg_serial_buf_info_t))
+            return -EINVAL;
+          
+          *len = sizeof(cyg_serial_buf_info_t);
+          p = (cyg_serial_buf_info_t *)xbuf;
+
+          p->rx_bufsize = chan->in_cbuf.len;
+          if (p->rx_bufsize)
+            {
+              p->rx_count = chan->in_cbuf.put - chan->in_cbuf.get;
+              if (p->rx_count < 0) 
+                p->rx_count += p->rx_bufsize;
+            }
+          else
+            p->rx_count = 0;
+          
+          p->tx_bufsize = chan->out_cbuf.len;
+          if (p->tx_bufsize)
+            {
+              p->tx_count = chan->out_cbuf.put - chan->out_cbuf.get;
+              if (p->tx_count < 0) 
+                p->tx_count += p->tx_bufsize;
+            }
+          else
+            p->tx_count = 0;
+        }
+      break;
+      
     default:
         res = -EINVAL;
     }
--- ../ecos/packages/io/serial/current/include/serialio.h	Wed Feb  2 13:57:23 2000
+++ ./packages/io/serial/current/include/serialio.h	Fri Feb 25 15:47:54 2000
@@ -75,10 +75,10 @@
     CYGNUM_SERIAL_BAUD_38400,
     CYGNUM_SERIAL_BAUD_57600,
     CYGNUM_SERIAL_BAUD_115200,
-    CYGNUM_SERIAL_BAUD_234000
+    CYGNUM_SERIAL_BAUD_230400
 } cyg_serial_baud_rate_t;
 #define CYGNUM_SERIAL_BAUD_MIN CYGNUM_SERIAL_BAUD_50 
-#define CYGNUM_SERIAL_BAUD_MAX CYGNUM_SERIAL_BAUD_234000
+#define CYGNUM_SERIAL_BAUD_MAX CYGNUM_SERIAL_BAUD_230400
 
 // Note: two levels of macro are required to get proper expansion.
 #define _CYG_SERIAL_BAUD_RATE(n) CYGNUM_SERIAL_BAUD_##n
@@ -119,6 +119,13 @@
 #define CYG_SERIAL_INFO_INIT(_baud,_stop,_parity,_word_length,_flags) \
   { _baud, _stop, _parity, _word_length, _flags}
 
+typedef struct {  
+  cyg_int32 rx_bufsize;
+  cyg_int32 rx_count;
+  cyg_int32 tx_bufsize;
+  cyg_int32 tx_count;
+} cyg_serial_buf_info_t;
+  
 // Control flags
 #define CYG_SERIAL_FLAGS_RTSCTS    0x0001
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]