Index: trunk/kernel/drivers/soclib/soclib_tty.c
===================================================================
--- trunk/kernel/drivers/soclib/soclib_tty.c	(revision 1)
+++ trunk/kernel/drivers/soclib/soclib_tty.c	(revision 4)
@@ -23,5 +23,5 @@
 
 #include <dev_txt.h>
-#include <device.h>
+#include <chdev.h>
 #include <soclib_tty.h>
 #include <remote_spinlock.h>
@@ -29,13 +29,9 @@
 #include <hal_special.h>
 
-/////////////////////////////////////
-void soclib_tty_init( xptr_t dev_xp )
+///////////////////////////////////////
+void soclib_tty_init( chdev_t * chdev )
 {
-    // get TXT device cluster and local pointer
-    cxy_t      dev_cxy = GET_CXY( dev_xp );
-    device_t * dev_ptr = (device_t *)GET_PTR( dev_xp );
-
     // get extended pointer on TTY-SOCLIB peripheral base address
-    xptr_t tty_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) ); 
+    xptr_t tty_xp = chdev->base; 
 
     // get SOCLIB_TTY device cluster and local pointer
@@ -46,8 +42,8 @@
     hal_remote_sw( XPTR( tty_cxy , tty_ptr + TTY_CONFIG_REG ) , 0 );
 
-}  // end soclib_tty_init()
-
-//////////////////////////////////////////////////////////////////
-void __attribute__ ((noinline)) soclib_tty_command( xptr_t th_xp )
+}  // soclib_tty_init()
+
+//////////////////////////////////////////////////////////////
+void __attribute__ ((noinline)) soclib_tty_cmd( xptr_t th_xp )
 {
     // get client thread cluster and local pointer
@@ -56,10 +52,10 @@
 
     // get command type and extended pointer on TXT device
-    uint32_t type   =         hal_remote_lw ( XPTR( th_cxy , &th_ptr->dev.txt.type ) );
-    xptr_t   dev_xp = (xptr_t)hal_remote_lwd( XPTR( th_cxy , &th_ptr->dev.txt.dev_xp ) );
+    uint32_t type   =         hal_remote_lw ( XPTR( th_cxy , &th_ptr->command.txt.type ) );
+    xptr_t   dev_xp = (xptr_t)hal_remote_lwd( XPTR( th_cxy , &th_ptr->command.txt.dev_xp ) );
     
     // get TXT device cluster and local pointer
-    cxy_t      dev_cxy = GET_CXY( dev_xp );
-    device_t * dev_ptr = (device_t *)GET_PTR( dev_xp );
+    cxy_t     dev_cxy = GET_CXY( dev_xp );
+    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
 
     // get extended pointer on SOCLIB_TTY base segment
@@ -70,8 +66,12 @@
     uint32_t * tty_ptr = (uint32_t *)GET_PTR( tty_xp );
 
+    // get TTY channel index and channel base address
+    uint32_t   channel = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->channel ) );
+    uint32_t * base    = tty_ptr + TTY_SPAN * channel;
+
     if( type == TXT_READ )              // descheduling strategy for calling thead
     {
         // unmask RX_IRQ (data transfer will be done by the TTY_RX ISR)
-        xptr_t config_xp = XPTR( tty_cxy , tty_ptr + TTY_CONFIG_REG );
+        xptr_t config_xp = XPTR( tty_cxy , base + TTY_CONFIG_REG );
         uint32_t old = hal_remote_lw( config_xp );
         uint32_t new = old | TTY_CONFIG_RX_ENABLE;
@@ -85,5 +85,5 @@
     {
         // unmask TX_IRQ (data transfer will be done by the TTY_TX ISR)
-        xptr_t config_xp = XPTR( tty_cxy , tty_ptr + TTY_CONFIG_REG );
+        xptr_t config_xp = XPTR( tty_cxy , base + TTY_CONFIG_REG );
         uint32_t old = hal_remote_lw( config_xp );
         uint32_t new = old | TTY_CONFIG_TX_ENABLE;
@@ -101,6 +101,6 @@
 
         // get source buffer extended pointer & bytes count
-        uint32_t count  = hal_remote_lw ( XPTR( th_cxy , &th_ptr->dev.txt.count ) );
-        xptr_t   buf_xp = hal_remote_lwd( XPTR( th_cxy , &th_ptr->dev.txt.buf_xp ) );
+        uint32_t count  = hal_remote_lw ( XPTR( th_cxy , &th_ptr->command.txt.count ) );
+        xptr_t   buf_xp = hal_remote_lwd( XPTR( th_cxy , &th_ptr->command.txt.buf_xp ) );
 
         // loop on characters 
@@ -110,5 +110,5 @@
             {
                 // get TTY_STATUS_REG
-                status = hal_remote_lw( XPTR( tty_cxy , tty_ptr + TTY_STATUS_REG ) );
+                status = hal_remote_lw( XPTR( tty_cxy , base + TTY_STATUS_REG ) );
                 empty  = ( (status & TTY_STATUS_TX_FULL) == 0 );
 
@@ -119,5 +119,5 @@
 
                     // write byte to TTY_WRITE_REG in TTY cluster
-                    hal_remote_sb( XPTR( tty_cxy , tty_ptr + TTY_WRITE_REG ) , byte );
+                    hal_remote_sb( XPTR( tty_cxy , base + TTY_WRITE_REG ) , byte );
                 }
             } 
@@ -125,9 +125,9 @@
         }
     }
-}  // end soclib_tty_command()
-
-
-////////////////////////////////////////////////////////////////
-void __attribute__ ((noinline)) soclib_tty_isr( device_t * dev )
+}  // soclib_tty_command()
+
+
+/////////////////////////////////////////////////////////////////
+void __attribute__ ((noinline)) soclib_tty_isr( chdev_t * chdev )
 {
     uint32_t   type;         // command type
@@ -138,7 +138,6 @@
     uint32_t   i;
 
-
     // get extended pointer on client thread
-    xptr_t root = XPTR( local_cxy , &dev->wait_root );
+    xptr_t root      = XPTR( local_cxy , &chdev->wait_root );
     xptr_t client_xp = XLIST_FIRST_ELEMENT( root , thread_t , wait_list );
 
@@ -148,21 +147,24 @@
 
     // get command arguments
-    type    = hal_remote_lw ( XPTR( client_cxy , &client_ptr->dev.txt.type   ) );
-    count   = hal_remote_lw ( XPTR( client_cxy , &client_ptr->dev.txt.count  ) );
-    buf_xp  = hal_remote_lwd( XPTR( client_cxy , &client_ptr->dev.txt.buf_xp ) );
+    type    = hal_remote_lw ( XPTR( client_cxy , &client_ptr->command.txt.type   ) );
+    count   = hal_remote_lw ( XPTR( client_cxy , &client_ptr->command.txt.count  ) );
+    buf_xp  = hal_remote_lwd( XPTR( client_cxy , &client_ptr->command.txt.buf_xp ) );
 
     // get SOCLIB_TTY peripheral cluster and local pointer
-    cxy_t      tty_cxy = GET_CXY( dev->base );
-    uint32_t * tty_ptr = (uint32_t *)GET_PTR( dev->base );
+    cxy_t      tty_cxy = GET_CXY( chdev->base );
+    uint32_t * tty_ptr = (uint32_t *)GET_PTR( chdev->base );
+
+    // get channel base address
+    uint32_t * base = tty_ptr + TTY_SPAN * chdev->channel;
 
     if( type == TXT_READ )              // read one single character
     {
         // get TTY_STATUS_REG
-        status = hal_remote_lw( XPTR( tty_cxy , tty_ptr + TTY_STATUS_REG ) );
+        status = hal_remote_lw( XPTR( tty_cxy , base + TTY_STATUS_REG ) );
 
         if( status & TTY_STATUS_RX_FULL )   // TTY_RX full => transfer one byte
         {
             // get a byte from TTY_READ_REG, and acknowledge RX_IRQ
-            byte = (char)hal_remote_lb( XPTR( tty_cxy , tty_ptr + TTY_READ_REG ) );
+            byte = (char)hal_remote_lb( XPTR( tty_cxy , base + TTY_READ_REG ) );
 
             // write it to command buffer
@@ -174,11 +176,11 @@
                 if( (byte == '\b') || (byte == 0x7F) )
 		        {
-			        hal_remote_sb( XPTR( tty_cxy , tty_ptr + TTY_WRITE_REG ) , '\b' );
-			        hal_remote_sb( XPTR( tty_cxy , tty_ptr + TTY_WRITE_REG ) , ' '  );
-			        hal_remote_sb( XPTR( tty_cxy , tty_ptr + TTY_WRITE_REG ) , '\b' );
+			        hal_remote_sb( XPTR( tty_cxy , base + TTY_WRITE_REG ) , '\b' );
+			        hal_remote_sb( XPTR( tty_cxy , base + TTY_WRITE_REG ) , ' '  );
+			        hal_remote_sb( XPTR( tty_cxy , base + TTY_WRITE_REG ) , '\b' );
 		        }
                 else
                 {
-			        hal_remote_sw( XPTR( tty_cxy , tty_ptr + TTY_WRITE_REG ) , byte );
+			        hal_remote_sw( XPTR( tty_cxy , base + TTY_WRITE_REG ) , byte );
 		        }
             }
@@ -195,5 +197,5 @@
         { 
             // get TTY_STATUS_REG
-            status = hal_remote_lw( XPTR( tty_cxy , tty_ptr + TTY_STATUS_REG ) );
+            status = hal_remote_lw( XPTR( tty_cxy , base + TTY_STATUS_REG ) );
 
             if( (status & TTY_STATUS_TX_FULL) == 0 ) // TTY_TX empty => transfer one byte
@@ -203,11 +205,10 @@
 
                 // write byte to TTY_WRITE_REG, and acknowledge TX_IRQ
-                hal_remote_sb( XPTR( tty_cxy , tty_ptr + TTY_STATUS_REG ) , byte );
+                hal_remote_sb( XPTR( tty_cxy , base + TTY_STATUS_REG ) , byte );
             }
             else         // TTY_TX full => update command arguments and exit ISR for retry
             {
-                // update arguments in command for retry
-                hal_remote_sw ( XPTR( client_cxy , &client_ptr->dev.txt.count )  , count - i ); 
-                hal_remote_swd( XPTR( client_cxy , &client_ptr->dev.txt.buf_xp ) , buf_xp + i );
+                hal_remote_sw ( XPTR( client_cxy , &client_ptr->command.txt.count ), count-i ); 
+                hal_remote_swd( XPTR( client_cxy , &client_ptr->command.txt.buf_xp ), buf_xp+i );
                 return;
             }
@@ -218,16 +219,16 @@
 
     // mask both TTY_RX_IRQ and TTY_TX_IRQ
-    hal_remote_sw( XPTR( tty_cxy , tty_ptr + TTY_CONFIG_REG ) , 0 );
+    hal_remote_sw( XPTR( tty_cxy , base + TTY_CONFIG_REG ) , 0 );
 
     // set I/O operation status in command
-    hal_remote_sw( XPTR( client_cxy , &client_ptr->dev.txt.error ) , 0 );
+    hal_remote_sw( XPTR( client_cxy , &client_ptr->command.txt.error ) , 0 );
 
     // unblock server thread
-    thread_unblock( XPTR( local_cxy , &dev->server ) , THREAD_BLOCKED_DEV_ISR );
+    thread_unblock( XPTR( local_cxy , &chdev->server ) , THREAD_BLOCKED_DEV_ISR );
 
     // unblock client thread
     thread_unblock( client_xp , THREAD_BLOCKED_IO );
 
-}  // end soclib_tty_isr()
-
-
+}  // soclib_tty_isr()
+
+
