Index: trunk/modules/vci_block_device_tsar/caba/source/src/vci_block_device_tsar.cpp
===================================================================
--- trunk/modules/vci_block_device_tsar/caba/source/src/vci_block_device_tsar.cpp	(revision 392)
+++ trunk/modules/vci_block_device_tsar/caba/source/src/vci_block_device_tsar.cpp	(revision 400)
@@ -199,12 +199,12 @@
     // Each block is split in bursts, and the number of bursts depends
     // on the memory buffer alignment on a burst boundary:
-    // - If buffer aligned, all burst have the same length (m_flits_per burst)
+    // - If buffer aligned, all burst have the same length (m_words_per burst)
     //   and the number of bursts is (m_bursts_per_block).
     // - If buffer not aligned, the number of bursts is (m_bursts_per_block + 1)
-    //   and first and last burst are shorter, because all flits in a burst 
+    //   and first and last burst are shorter, because all words in a burst 
     //   must be contained in a single cache line.
-    //   first burst => nflits = m_flits_per_burst - offset
-    //   last  burst => nflits = offset
-    //   other burst => nflits = m_flits_per_burst
+    //   first burst => nwords = m_words_per_burst - offset
+    //   last  burst => nwords = offset
+    //   other burst => nwords = m_words_per_burst
     //////////////////////////////////////////////////////////////////////////////
 
@@ -218,9 +218,9 @@
             r_block_count   = 0;
             r_burst_count   = 0;
-            r_flit_count    = 0;
+            r_words_count    = 0;
             r_latency_count = m_latency;
 
             // compute r_burst_offset (zero when buffer aligned)
-            r_burst_offset = (uint32_t)((r_buf_address.read()>>2) % m_flits_per_burst);
+            r_burst_offset = (uint32_t)((r_buf_address.read()>>2) % m_words_per_burst);
 
             // start tranfer
@@ -236,6 +236,6 @@
         {
             r_latency_count = m_latency;
-            ::lseek(m_fd, (r_lba + r_block_count)*m_flits_per_block*4, SEEK_SET);
-            if( ::read(m_fd, r_local_buffer, m_flits_per_block*4) < 0 )  
+            ::lseek(m_fd, (r_lba + r_block_count)*m_words_per_block*4, SEEK_SET);
+            if( ::read(m_fd, r_local_buffer, m_words_per_block*4) < 0 )  
             {
                 r_initiator_fsm = M_READ_ERROR;
@@ -244,5 +244,5 @@
             {
                 r_burst_count   = 0;
-                r_flit_count    = 0;
+                r_words_count    = 0;
                 r_initiator_fsm = M_READ_BURST;
             }
@@ -255,19 +255,24 @@
     }
     //////////////////
-    case M_READ_BURST:  // Compute the number of flits in the burst
-    {
+    case M_READ_BURST:  // Compute the number of words and the number of flits in the burst
+                        // The number of flits can be smaller than the number of words 
+                        // in case of 8 bytes flits...
+    {
+        uint32_t nwords;
         uint32_t offset = r_burst_offset.read();
 
         if ( offset )                  // buffer not aligned
         {
-            if ( r_burst_count.read() == 0 ) r_burst_nflits = m_flits_per_burst - offset;
-            else if ( r_burst_count.read() == m_bursts_per_block ) r_burst_nflits = offset;
-            else r_burst_nflits = m_flits_per_burst;
+            if ( r_burst_count.read() == 0 ) nwords = m_words_per_burst - offset;
+            else if ( r_burst_count.read() == m_bursts_per_block ) nwords = offset;
+            else nwords = m_words_per_burst;
         }
         else                           // buffer aligned
         {
-            r_burst_nflits = m_flits_per_burst;
-        }
-        r_initiator_fsm =  M_READ_CMD;
+            nwords = m_words_per_burst;
+        }
+
+        r_burst_nwords  = nwords;
+        r_initiator_fsm = M_READ_CMD;
         break;
     }
@@ -277,17 +282,46 @@
         if ( p_vci_initiator.cmdack.read() )
         {
-            if ( r_flit_count == (r_burst_nflits.read() - 1) ) // last flit in a burst
-            {
-                r_initiator_fsm = M_READ_RSP;
-                r_flit_count = 0;
-            }
-            else                                               // not the last flit
-            {
-                r_flit_count = r_flit_count.read() + 1;
-            }
-
-            // compute next flit address and next local buffer index
-            r_buf_address = r_buf_address.read() + 4;
-            r_index       = r_index.read() + 1;
+            uint32_t nwords = r_burst_nwords.read() - r_words_count.read();
+
+            if ( vci_param::B == 4 )    // one word per flit 
+            {
+                if ( nwords <= 1 )      // last flit
+                {
+                    r_initiator_fsm = M_READ_RSP;
+                    r_words_count = 0;
+                }
+                else                    // not the last flit
+                {
+                    r_words_count = r_words_count.read() + 1;
+                }
+
+                // compute next word address and next local buffer index
+                r_buf_address = r_buf_address.read() + 4;
+                r_index       = r_index.read() + 1;
+            }
+            else                        // 2 words per flit
+            {
+                if ( nwords <= 2 )      // last flit
+                {
+                    r_initiator_fsm = M_READ_RSP;
+                    r_words_count = 0;
+                }
+                else                    // not the last flit
+                {
+                    r_words_count = r_words_count.read() + 2;
+                }
+                    
+                // compute next word address and next local buffer index
+                if ( nwords == 1 )
+                {
+                    r_buf_address = r_buf_address.read() + 4;
+                    r_index       = r_index.read() + 1;
+                }
+                else
+                {
+                    r_buf_address = r_buf_address.read() + 8;
+                    r_index       = r_index.read() + 2;
+                }
+            }
         }
         break;
@@ -335,18 +369,21 @@
     }
     ///////////////////
-    case M_WRITE_BURST:  // Compute the number of flits in the burst
-    {
+    case M_WRITE_BURST:  // Compute the number of words in the burst
+    {
+        uint32_t nwords;
         uint32_t offset = r_burst_offset.read();
 
         if ( offset )                  // buffer not aligned
         {
-            if ( r_burst_count.read() == 0 ) r_burst_nflits = m_flits_per_burst - offset;
-            else if ( r_burst_count.read() == m_bursts_per_block ) r_burst_nflits = offset;
-            else r_burst_nflits = m_flits_per_burst;
+            if ( r_burst_count.read() == 0 ) nwords = m_words_per_burst - offset;
+            else if ( r_burst_count.read() == m_bursts_per_block ) nwords = offset;
+            else nwords = m_words_per_burst;
         }
         else                           // buffer aligned
         {
-            r_burst_nflits = m_flits_per_burst;
-        }
+            nwords = m_words_per_burst;
+        }
+
+        r_burst_nwords  = nwords;
         r_initiator_fsm =  M_WRITE_CMD;
         break;
@@ -359,17 +396,26 @@
     }
     /////////////////
-    case M_WRITE_RSP:	// This is actually a multi-flits VCI READ response
-    {
-        bool aligned = (r_burst_offset.read() == 0);
-
+    case M_WRITE_RSP:	// This is actually a multi-words VCI READ response
+    {
         if ( p_vci_initiator.rspval.read() )
         {
-            r_local_buffer[r_index.read()] = (uint32_t)p_vci_initiator.rdata.read();
-            r_index = r_index.read() + 1;
+            bool aligned = (r_burst_offset.read() == 0);
+
+            if ( (vci_param::B == 8) and (r_burst_nwords.read() > 1) )
+            {
+                r_local_buffer[r_index.read()]   = (uint32_t)p_vci_initiator.rdata.read();
+                r_local_buffer[r_index.read()+1] = (uint32_t)(p_vci_initiator.rdata.read()>>32);
+                r_index = r_index.read() + 2;
+            }
+            else
+            {
+                r_local_buffer[r_index.read()]   = (uint32_t)p_vci_initiator.rdata.read();
+                r_index = r_index.read() + 1;
+            }
 
             if ( p_vci_initiator.reop.read() )  // last flit of the burst
             {
-	            r_flit_count  = 0;
-                r_buf_address = r_buf_address.read() + (r_burst_nflits.read()<<2); 
+	            r_words_count  = 0;
+                r_buf_address = r_buf_address.read() + (r_burst_nwords.read()<<2); 
 
 	            if( (p_vci_initiator.rerror.read()&0x1) != 0 ) 
@@ -378,5 +424,5 @@
                 }
                 else if ( (not aligned and (r_burst_count.read() == m_bursts_per_block)) or 
-                          (aligned and (r_burst_count.read() == (m_bursts_per_block-1))) ) // last burst
+                     (aligned and (r_burst_count.read() == (m_bursts_per_block-1))) ) // last burst
                 {
                     r_initiator_fsm  = M_WRITE_BLOCK;
@@ -390,5 +436,5 @@
             else
             {
-	            r_flit_count = r_flit_count.read() + 1;
+	            r_words_count = r_words_count.read() + 1;
             }
         }
@@ -401,6 +447,6 @@
         {
             r_latency_count = m_latency;
-            ::lseek(m_fd, (r_lba + r_block_count)*m_flits_per_block*vci_param::B, SEEK_SET);
-            if( ::write(m_fd, r_local_buffer, m_flits_per_block*vci_param::B) < 0 )
+            ::lseek(m_fd, (r_lba + r_block_count)*m_words_per_block*vci_param::B, SEEK_SET);
+            if( ::write(m_fd, r_local_buffer, m_words_per_block*vci_param::B) < 0 )
             {
                 r_initiator_fsm = M_WRITE_ERROR; 
@@ -413,7 +459,7 @@
             {
                 r_burst_count    = 0;
-		r_index          = 0;
+                r_index          = 0;
                 r_block_count    = r_block_count.read() + 1;
-                r_initiator_fsm = M_WRITE_BURST;
+                r_initiator_fsm  = M_WRITE_BURST;
             }
         } 
@@ -474,5 +520,5 @@
         p_vci_target.cmdack = false;
         p_vci_target.rspval = true;
-        p_vci_target.rdata = (uint32_t)r_nblocks.read();
+        p_vci_target.rdata  = r_nblocks.read();
         p_vci_target.rerror = VCI_READ_OK;
         break;
@@ -480,5 +526,5 @@
         p_vci_target.cmdack = false;
         p_vci_target.rspval = true;
-        p_vci_target.rdata = (uint32_t)r_lba.read();
+        p_vci_target.rdata  = r_lba.read();
         p_vci_target.rerror = VCI_READ_OK;
         break;
@@ -486,5 +532,5 @@
         p_vci_target.cmdack = false;
         p_vci_target.rspval = true;
-        p_vci_target.rdata = (uint32_t)r_irq_enable.read();
+        p_vci_target.rdata  = r_irq_enable.read();
         p_vci_target.rerror = VCI_READ_OK;
         break;
@@ -492,5 +538,5 @@
         p_vci_target.cmdack = false;
         p_vci_target.rspval = true;
-        p_vci_target.rdata = (uint32_t)m_device_size;
+        p_vci_target.rdata  = m_device_size;
         p_vci_target.rerror = VCI_READ_OK;
         break;
@@ -498,5 +544,5 @@
         p_vci_target.cmdack = false;
         p_vci_target.rspval = true;
-        p_vci_target.rdata = (uint32_t)m_flits_per_block*vci_param::B;
+        p_vci_target.rdata  = m_words_per_block*vci_param::B;
         p_vci_target.rerror = VCI_READ_OK;
         break;
@@ -504,5 +550,5 @@
         p_vci_target.cmdack = false;
         p_vci_target.rspval = true;
-        p_vci_target.rdata = 0;
+        p_vci_target.rdata  = 0;
         p_vci_target.rerror = VCI_READ_ERROR;
         break;
@@ -510,5 +556,5 @@
         p_vci_target.cmdack = false;
         p_vci_target.rspval = true;
-        p_vci_target.rdata = 0;
+        p_vci_target.rdata  = 0;
         p_vci_target.rerror = VCI_WRITE_ERROR;
         break;
@@ -516,5 +562,5 @@
         p_vci_target.cmdack = false;
         p_vci_target.rspval = true;
-        p_vci_target.rdata = 0;
+        p_vci_target.rdata  = 0;
         p_vci_target.rerror = VCI_WRITE_OK;
         break;
@@ -531,5 +577,5 @@
 
     switch (r_initiator_fsm) {
-    case M_WRITE_CMD:		// It is actually a single flit VCI read command
+    case M_WRITE_CMD:		// It is actually a single word VCI read command
         p_vci_initiator.rspack  = false;
         p_vci_initiator.cmdval  = true;
@@ -539,8 +585,8 @@
         p_vci_initiator.wdata   = 0;
         p_vci_initiator.be      = (uint32_t)0xF;
-        p_vci_initiator.plen    = (sc_dt::sc_uint<vci_param::K>)(r_burst_nflits.read()<<2);
+        p_vci_initiator.plen    = (sc_dt::sc_uint<vci_param::K>)(r_burst_nwords.read()<<2);
         p_vci_initiator.eop     = true;
         break;
-    case M_READ_CMD:		// It is actually a multi-flits VCI WRITE command 
+    case M_READ_CMD:		// It is actually a multi-words VCI WRITE command 
         p_vci_initiator.rspack  = false;
         p_vci_initiator.cmdval  = true;
@@ -548,8 +594,10 @@
         p_vci_initiator.cmd     = vci_param::CMD_WRITE;
         p_vci_initiator.pktid   = TYPE_WRITE;
-        p_vci_initiator.wdata   = (uint32_t)r_local_buffer[r_index.read()];
         p_vci_initiator.be      = 0xF;
-        p_vci_initiator.plen    = (sc_dt::sc_uint<vci_param::K>)(r_burst_nflits.read()<<2);
-        p_vci_initiator.eop     = ( r_flit_count.read() == (r_burst_nflits.read() - 1) );
+        p_vci_initiator.plen    = (sc_dt::sc_uint<vci_param::K>)(r_burst_nwords.read()<<2);
+        p_vci_initiator.eop     = ( r_words_count.read() == (r_burst_nwords.read() - 1) );
+        if (vci_param::B == 4)  p_vci_initiator.wdata = r_local_buffer[r_index.read()];
+        else                    p_vci_initiator.wdata = (uint64_t)r_local_buffer[r_index.read()] +
+                                   ((uint64_t)r_local_buffer[r_index.read()+1])<<32; 
         break;
     case M_READ_RSP:
@@ -574,17 +622,17 @@
 //////////////////////////////////////////////////////////////////////////////
 tmpl(/**/)::VciBlockDeviceTsar( sc_core::sc_module_name              name, 
-                                  const soclib::common::MappingTable   &mt,
-                                  const soclib::common::IntTab         &srcid,
-                                  const soclib::common::IntTab         &tgtid,
-                                  const std::string                    &filename,
-                                  const uint32_t                       block_size,
-                                  const uint32_t                       burst_size,
-                                  const uint32_t                       latency)
+                                const soclib::common::MappingTable   &mt,
+                                const soclib::common::IntTab         &srcid,
+                                const soclib::common::IntTab         &tgtid,
+                                const std::string                    &filename,
+                                const uint32_t                       block_size,
+                                const uint32_t                       burst_size,
+                                const uint32_t                       latency)
 
 : caba::BaseModule(name),
 	m_segment(mt.getSegment(tgtid)),
 	m_srcid(mt.indexForId(srcid)),
-	m_flits_per_block(block_size/vci_param::B),
-	m_flits_per_burst(burst_size/vci_param::B),
+	m_words_per_block(block_size/4),
+	m_words_per_burst(burst_size/4),
 	m_bursts_per_block(block_size/burst_size),
 	m_latency(latency),
@@ -603,6 +651,5 @@
     sensitive << p_clk.neg();
 
-	if( (block_size != 64 )  && 
-        (block_size != 128)  && 
+    if( (block_size != 128)  && 
         (block_size != 256)  && 
         (block_size != 512)  && 
@@ -615,7 +662,5 @@
 		exit(1);
 	}
-	if( (burst_size != 1 ) && 
-		(burst_size != 2 ) && 
-		(burst_size != 4 ) && 
+    if( (burst_size != 4 ) && 
 		(burst_size != 8 ) && 
 		(burst_size != 16) && 
@@ -624,23 +669,23 @@
 	{
 		std::cout << "Error in component VciBlockDeviceTsar : " << name << std::endl;
-		std::cout << "The burst size must be 1, 2, 4, 8, 16, 32 or 64 bytes" << std::endl;
+		std::cout << "The burst size must be 4, 8, 16, 32 or 64 bytes" << std::endl;
 		exit(1);
 	}
-	if ( m_segment.size() < 32 ) 
+	if ( m_segment.size() < 64 ) 
 	{
 		std::cout << "Error in component VciBlockDeviceTsar : " << name << std::endl;
-		std::cout << "The size of the segment cannot be smaller than 32 bytes" << std::endl;
+		std::cout << "The size of the segment cannot be smaller than 64 bytes" << std::endl;
 		exit(1);
 	}
-	if ( (m_segment.baseAddress() & 0x0000001F) != 0 ) 
+	if ( (m_segment.baseAddress() & 0x0000003F) != 0 ) 
 	{
 		std::cout << "Error in component VciBlockDeviceTsar : " << name << std::endl;
-		std::cout << "The base address of the segment must be multiple of 32 bytes" << std::endl;
+		std::cout << "The base address of the segment must be multiple of 64 bytes" << std::endl;
 		exit(1);
 	}
-	if ( vci_param::B != 4 )
+	if ( (vci_param::B != 4) and (vci_param::B != 8) )
 	{
 		std::cout << "Error in component VciBlockDeviceTsar : " << name << std::endl;
-		std::cout << "The VCI data fields must have 32 bits" << std::endl;
+		std::cout << "The VCI data fields must have 32 bits or 64 bits" << std::endl;
 		exit(1);
 	}
@@ -661,5 +706,5 @@
 	}
 
-	r_local_buffer = new uint32_t[m_flits_per_block];
+	r_local_buffer = new uint32_t[m_words_per_block];
 
 } // end constructor
@@ -711,5 +756,5 @@
 		  << "  block = " << std::dec << r_block_count.read() 
 		  << "  burst = " << r_burst_count.read() 
-		  << "  flit  = " << r_flit_count.read() <<std::endl; 
+		  << "  word  = " << r_words_count.read() <<std::endl; 
 }
 
