Index: soft/giet_vm/libs/mwmr_channel.c
===================================================================
--- soft/giet_vm/libs/mwmr_channel.c	(revision 200)
+++ soft/giet_vm/libs/mwmr_channel.c	(revision 207)
@@ -62,4 +62,73 @@
             :"$2", "$3", "$4");
 } 
+//////////////////////////////////////////////////////////////////////////////
+//	   nb_mwmr_write()
+// This is a non-blocking function.
+// The nitems parameter is the number of items to be transfered.
+// The requested transfer is therefore (nitems * width) words.
+// It takes the lock for exclusive access before testing the channel state.
+// If there is not enough data in mwmr channel to read nitems,
+// it reads as many items as possible, releases the lock, and returns 
+// the number of read items (it can be 0).
+//////////////////////////////////////////////////////////////////////////////
+unsigned int nb_mwmr_write( mwmr_channel_t* 	mwmr, 
+                            unsigned int*		buffer,
+                            unsigned int 		nitems )
+{
+    unsigned int	x;
+    unsigned int	spaces;		// number of empty slots (in words)
+    unsigned int	nwords;		// requested transfer length (in words)
+    unsigned int    depth;		// channel depth (in words)
+    unsigned int    width;		// channel width (in words)
+    unsigned int    sts;        // channel sts
+    unsigned int    ptw;        // channel ptw
+
+    if(nitems == 0) return 0;
+
+    // get the lock
+    mwmr_lock_acquire( &mwmr->lock );
+
+    // access fifo status
+    depth  = mwmr->depth;
+    width  = mwmr->width;
+    sts    = mwmr->sts;
+    ptw    = mwmr->ptw;
+    spaces = depth - sts;
+    nwords = width * nitems;
+
+    if( spaces >= nwords ) 	// transfer nitems, release lock and return 
+    {
+        for ( x = 0 ; x < nwords ; x++ )  
+        {
+            mwmr->data[ptw] = buffer[x];
+            if ( (ptw + 1) == depth ) ptw = 0;
+            else                      ptw = ptw + 1;
+        }
+        mwmr->sts  = mwmr->sts + nwords;
+        mwmr->ptw  = ptw;
+        mwmr->lock = 0;
+        return nitems;
+    }
+   
+    else if ( spaces < width )	// release lock and return 
+    {
+        mwmr->lock = 0;
+        return 0;
+    }
+    else	// transfer as many items as possible, release lock and return 
+    {
+        nwords = (spaces/width) * width;	// integer number of items
+        for ( x = 0 ; x < nwords ; x++ )  
+        {
+            mwmr->data[ptw] = buffer[x];
+            if ( (ptw + 1) == depth ) ptw = 0;
+            else                      ptw = ptw + 1;
+        }
+        mwmr->sts  = sts + nwords;
+        mwmr->ptw  = ptw;
+        mwmr->lock = 0;
+        return (nwords/width);
+    }
+} // end nb_mwmr_write()
 
 //////////////////////////////////////////////////////////////////////////////
@@ -136,5 +205,73 @@
         for ( x = giet_rand()>>6 ; x > 0 ; x-- ) asm volatile ( "nop" );
     }
-} 
+} // end mwmr_write()
+
+//////////////////////////////////////////////////////////////////////////////
+//	   nb_mwmr_read()
+// This is a non-blocking function.
+// The nitems parameter is the number of items to be transfered.
+// The requested transfer is therefore (nitems * width) words.
+// It takes the lock for exclusive access before testing the channel state.
+// If there is not enough data in mwmr channel to read nitems,
+// it reads as many items as possible, releases the lock, and returns 
+// the number of read items (it can be 0).
+//////////////////////////////////////////////////////////////////////////////
+unsigned int nb_mwmr_read( mwmr_channel_t* 	mwmr, 
+                           unsigned int*		buffer,
+                           unsigned int 		nitems )
+{
+    unsigned int	x;
+    unsigned int	nwords;		// requested transfer length (in words)
+    unsigned int    depth;		// channel depth (in words)
+    unsigned int    width;		// channel width (in words)
+    unsigned int    sts;        // channel sts
+    unsigned int    ptr;        // channel ptr
+
+    if(nitems == 0) return 0;
+
+    // get the lock
+    mwmr_lock_acquire( &mwmr->lock );
+
+    // access fifo status
+    depth  = mwmr->depth;
+    width  = mwmr->width;
+    sts    = mwmr->sts;
+    ptr    = mwmr->ptr;
+    nwords = width * nitems;
+
+    if( sts >= nwords ) 	// transfer nitems, release lock and return 
+    {
+        for ( x = 0 ; x < nwords ; x++ )  
+        {
+            buffer[x] = mwmr->data[ptr];
+            if ( (ptr + 1) == depth ) ptr = 0;
+            else                      ptr = ptr + 1;
+        }
+        mwmr->sts  = mwmr->sts - nwords;
+        mwmr->ptr  = ptr;
+        mwmr->lock = 0;
+        return nitems;
+    }
+   
+    else if ( sts < width )	// release lock and return 
+    {
+        mwmr->lock = 0;
+        return 0;
+    }
+    else	// transfer as many items as possible, release lock and return 
+    {
+        nwords = (sts/width) * width;	// integer number of items
+        for ( x = 0 ; x < nwords ; x++ )  
+        {
+            buffer[x] = mwmr->data[ptr];
+            if ( (ptr + 1) == depth ) ptr = 0;
+            else                      ptr = ptr + 1;
+        }
+        mwmr->sts  = sts - nwords;
+        mwmr->ptr  = ptr;
+        mwmr->lock = 0;
+        return (nwords/width);
+    }
+} // nb_mwmr_read() 
 
 //////////////////////////////////////////////////////////////////////////////
@@ -157,5 +294,5 @@
     unsigned int    width;		// channel width (in words)
     unsigned int    sts;        // channel sts
-    unsigned int    ptr;        // channel ptw
+    unsigned int    ptr;        // channel ptr
 
     if(nitems == 0) return;
@@ -209,4 +346,5 @@
         for ( x = giet_rand()>>6 ; x > 0 ; x-- ) asm volatile ( "nop" );
     }
-} 
-
+} // end mwmr_read() 
+
+
