Index: /trunk/modules/sdmmc/caba/source/include/sdmmc.h
===================================================================
--- /trunk/modules/sdmmc/caba/source/include/sdmmc.h	(revision 555)
+++ /trunk/modules/sdmmc/caba/source/include/sdmmc.h	(revision 556)
@@ -55,22 +55,22 @@
 
     // Registers
-    sc_signal<int>            	      r_spi_fsm;   	 // SPI state register
-    sc_signal<uint8_t>		      r_spi_shiftreg;	// data shift in/out
-    sc_signal<uint8_t>		      r_spi_bitcount;
-    sc_signal<bool>		      r_spi_clk;
+    int               spi_fsm;   	 // SPI state register
+    int		      spi_shiftreg;	// data shift in/out
+    int		      spi_bitcount;
+    int		      spi_clk;
 
-    sc_signal<uint8_t>		      r_command;
-    sc_signal<uint32_t>		      r_args;
-    sc_signal<uint8_t>		      r_cmdcrc;
-    int                               m_fd;           	 // File descriptor
-    uint64_t                          m_device_size;  	 // Total number of blocks
-    const uint32_t                    m_latency;      	 // device latency
+    uint8_t	      command;
+    uint32_t	      args;
+    uint8_t	      cmdcrc;
+    int               m_fd;           	 // File descriptor
+    uint64_t          m_device_size;  	 // Total number of blocks
+    const uint32_t    m_latency;      	 // device latency
 
-    uint8_t			      m_databuf[1 /* reponse */ + 1 /* data tocken */ + 512 /* data block */ + 2 /* CRC */ ];
-    uint32_t			      m_datalen_snd; // data size to be sent to host
-    uint32_t                          m_datalen_rcv; // data size expected from host
-    uint32_t			      m_data_idx;
-    bool			      m_acmd; // next command will be acmd
-    int				      m_sdstate; // sdcard internal state
+    uint8_t	      m_databuf[1 /* reponse */ + 1 /* data tocken */ + 512 /* data block */ + 2 /* CRC */ ];
+    uint32_t	      m_datalen_snd; // data size to be sent to host
+    uint32_t          m_datalen_rcv; // data size expected from host
+    uint32_t	      m_data_idx;
+    bool	      m_acmd; // next command will be acmd
+    int		      m_sdstate; // sdcard internal state
 
     // sd states
Index: /trunk/modules/sdmmc/caba/source/src/sdmmc.cpp
===================================================================
--- /trunk/modules/sdmmc/caba/source/src/sdmmc.cpp	(revision 555)
+++ /trunk/modules/sdmmc/caba/source/src/sdmmc.cpp	(revision 556)
@@ -44,5 +44,5 @@
     if(p_resetn.read() == false) 
     {
-        r_spi_fsm  = S_IDLE;
+        spi_fsm  = S_IDLE;
 	m_acmd	   = false;	 
 	m_sdstate  = SD_IDLE;
@@ -50,75 +50,75 @@
     } 
     if (p_spi_ss.read()) {
-	if (r_spi_fsm != S_IDLE) {
+	if (spi_fsm != S_IDLE) {
 		std::cerr << name() << " deselect but not idle, state "
-		<< std::dec << r_spi_fsm << " last cmd " << (int)r_command
-		<< " args " << std::hex << r_args << std::dec
-		<< " bitcount " << (int)r_spi_bitcount.read()
+		<< std::dec << spi_fsm << " last cmd " << (int)command
+		<< " args " << std::hex << args << std::dec
+		<< " bitcount " << (int)spi_bitcount
 		<< " idx " << m_data_idx << " len_snd " << m_datalen_snd
 		<< " len_rcv " << m_datalen_rcv << std::endl;
 	}
-	r_spi_fsm  = S_IDLE;
+	spi_fsm  = S_IDLE;
+	spi_clk = p_spi_clk;
 	return;
     }
 
-    r_spi_clk = p_spi_clk;
-
-    switch(r_spi_fsm) {
+    switch(spi_fsm) {
     case S_IDLE:
-	if (p_spi_clk.read() == 1 && r_spi_clk.read() == 0) {
+	if (p_spi_clk.read() == 1 && spi_clk == 0) {
 		// rising edge
-		r_command = (r_command << 1) | p_spi_mosi;
-		r_spi_bitcount = 6;
-		r_spi_fsm = S_RECEIVE_CMD;
+		command = (command << 1) | p_spi_mosi;
+		spi_bitcount = 6;
+		spi_fsm = S_RECEIVE_CMD;
 	}
         break;
     case S_RECEIVE_CMD:
-	if (p_spi_clk.read() == 1 && r_spi_clk.read() == 0) {
+	if (p_spi_clk.read() == 1 && spi_clk == 0) {
 		// rising edge
-		r_command = (r_command << 1) | p_spi_mosi;
-		r_spi_bitcount = r_spi_bitcount - 1;
-		if (r_spi_bitcount == 0) {
-			if (((r_command << 1) & 0x80) == 0) {
-				r_spi_fsm = S_RECEIVE_ARGS_START;
+		command = (command << 1) | p_spi_mosi;
+		if (spi_bitcount == 0) {
+			if ((command & 0x80) == 0) {
+				spi_fsm = S_RECEIVE_ARGS_START;
 			} else {
 #ifdef SOCLIB_MODULE_DEBUG0
-				std::cout << name() << " S_RECEIVE_CMD " << std::hex << ((int)((r_command << 1) | p_spi_mosi) & 0xff) << std::endl;
-#endif
-				r_spi_fsm = S_IDLE;
+				std::cout << name() << " S_RECEIVE_CMD " << std::hex << (int)command << std::endl;
+#endif
+				spi_fsm = S_IDLE;
 			}
+		} else {
+		    spi_bitcount = spi_bitcount - 1;
 		}
 	}
 	break;
     case S_RECEIVE_ARGS_START:
-	if (p_spi_clk.read() == 1 && r_spi_clk.read() == 0) {
+	if (p_spi_clk.read() == 1 && spi_clk == 0) {
 		// rising edge
-		r_args = (r_args << 1) | p_spi_mosi;
-		r_spi_bitcount = 30;
-		r_spi_fsm = S_RECEIVE_ARGS;
+		args = (args << 1) | p_spi_mosi;
+		spi_bitcount = 30;
+		spi_fsm = S_RECEIVE_ARGS;
 	}
         break;
     case S_RECEIVE_ARGS:
-	if (p_spi_clk.read() == 1 && r_spi_clk.read() == 0) {
+	if (p_spi_clk.read() == 1 && spi_clk == 0) {
 		// rising edge
-		r_args = (r_args << 1) | p_spi_mosi;
-		r_spi_bitcount = r_spi_bitcount - 1;
-		if (r_spi_bitcount == 0) {
-			r_spi_bitcount = 7;
-			r_spi_fsm = S_RECEIVE_CRC;
+		args = (args << 1) | p_spi_mosi;
+		if (spi_bitcount == 0) {
+			spi_bitcount = 7;
+			spi_fsm = S_RECEIVE_CRC;
+		} else {
+		    spi_bitcount = spi_bitcount - 1;
 		}
 	}
         break;
     case S_RECEIVE_CRC:
-	if (p_spi_clk.read() == 1 && r_spi_clk.read() == 0) {
+	if (p_spi_clk.read() == 1 && spi_clk == 0) {
 		// rising edge
-		uint8_t crc = (r_cmdcrc << 1) | p_spi_mosi;
-		r_cmdcrc = crc;
-		if (r_spi_bitcount == 0) {
-			handle_sdmmc_cmd(r_command.read(), r_args.read());
-			r_spi_bitcount = 0; // SEND_DATA will reset it
-			r_spi_fsm = S_SEND_DATA;
+		cmdcrc = (cmdcrc << 1) | p_spi_mosi;
+		if (spi_bitcount == 0) {
+			handle_sdmmc_cmd(command, args);
+			spi_bitcount = 0; // SEND_DATA will reset it
+			spi_fsm = S_SEND_DATA;
 			m_data_idx = 0;
 		} else {
-			r_spi_bitcount = r_spi_bitcount - 1;
+			spi_bitcount = spi_bitcount - 1;
 		}
 	}
@@ -126,11 +126,11 @@
 	
     case S_SEND_DATA:
-	if (p_spi_clk.read() == 0 && r_spi_clk.read() == 1) {
+	if (p_spi_clk.read() == 0 && spi_clk == 1) {
 		// falling edge
-		if (r_spi_bitcount == 0) {
+		if (spi_bitcount == 0) {
 			if (m_data_idx != m_datalen_snd) {	
-				r_spi_shiftreg = m_databuf[m_data_idx];
-				r_spi_bitcount = 7;
-				r_spi_fsm = S_SEND_DATA;
+				spi_shiftreg = m_databuf[m_data_idx];
+				spi_bitcount = 7;
+				spi_fsm = S_SEND_DATA;
 				m_data_idx++;
 #ifdef SOCLIB_MODULE_DEBUG0
@@ -138,30 +138,29 @@
 #endif
 			} else if (m_datalen_rcv != 0) {
-				r_spi_fsm = S_RECEIVE_DATA_WAIT;
-				r_spi_bitcount = 7;
+				spi_fsm = S_RECEIVE_DATA_WAIT;
+				spi_bitcount = 7;
 				m_data_idx = 0;
 			} else {
-				r_spi_fsm = S_IDLE;
+				spi_fsm = S_IDLE;
 			}
 		} else {
-			r_spi_bitcount = r_spi_bitcount - 1;
-			r_spi_shiftreg = r_spi_shiftreg << 1;
+			spi_bitcount = spi_bitcount - 1;
+			spi_shiftreg = spi_shiftreg << 1;
 		}
 	}
 	break;
     case S_RECEIVE_DATA_WAIT:
-	if (p_spi_clk.read() == 1 && r_spi_clk.read() == 0) {
+	if (p_spi_clk.read() == 1 && spi_clk == 0) {
+	    // rising edge
 	    uint8_t s_data;
-	    // rising edge
 	    s_data = (m_databuf[0] << 1) | p_spi_mosi;
 	    m_databuf[0] = s_data;
-	    r_spi_bitcount = r_spi_bitcount - 1;
-	    if (r_spi_bitcount == 0) {
+	    if (spi_bitcount == 0) {
 #ifdef SOCLIB_MODULE_DEBUG
 	std::cout << name() << " S_RECEIVE_DATA_WAIT " << std::dec << (int)s_data << std::endl;
 #endif
-		    r_spi_bitcount = 7;
+		    spi_bitcount = 7;
 		    if (s_data == 0xfe) { // data start token
-			r_spi_fsm = S_RECEIVE_DATA;
+			spi_fsm = S_RECEIVE_DATA;
 			m_data_idx = 1;
 		    } else {
@@ -169,34 +168,37 @@
 			std::cout << name() << " S_RECEIVE_DATA_WAIT " << std::hex << (int)s_data << std::endl;
 #endif
-			r_spi_fsm = S_RECEIVE_DATA_WAIT;
-		}
+			spi_fsm = S_RECEIVE_DATA_WAIT;
+		}
+	    } else {
+	        spi_bitcount = spi_bitcount - 1;
 	    }
 	}
 	break;
 	case S_RECEIVE_DATA:
-	    if (p_spi_clk.read() == 1 && r_spi_clk.read() == 0) {
+	    if (p_spi_clk.read() == 1 && spi_clk == 0) {
 		// rising edge
 		m_databuf[m_data_idx] = (m_databuf[m_data_idx] << 1) | p_spi_mosi;
-		if (r_spi_bitcount == 0) {
+		if (spi_bitcount == 0) {
 		    m_data_idx++;
 		    if (m_data_idx != m_datalen_rcv) {
-		    	r_spi_fsm = S_RECEIVE_DATA;
-		    	r_spi_bitcount = 7;
+		    	spi_fsm = S_RECEIVE_DATA;
+		    	spi_bitcount = 7;
 		    } else {
-		        handle_sdmmc_write(r_command.read(), r_args.read());
+		        handle_sdmmc_write(command, args);
 		        if (m_datalen_snd > 0) {
-		            r_spi_bitcount = 0; // SEND_DATA will reset it
-		            r_spi_fsm = S_SEND_DATA;
+		            spi_bitcount = 0; // SEND_DATA will reset it
+		            spi_fsm = S_SEND_DATA;
 		            m_data_idx = 0;
 		        } else {
-		            r_spi_fsm = S_IDLE;
+		            spi_fsm = S_IDLE;
 		        }
 		    }
 		} else {
-			r_spi_bitcount = r_spi_bitcount - 1;
+			spi_bitcount = spi_bitcount - 1;
 		}
 	    }
 	    break;
     }
+    spi_clk = p_spi_clk.read();
 }  // end transition
 
@@ -204,10 +206,10 @@
 void SdMMC::genMoore()
 {
-    switch(r_spi_fsm) {
+    switch(spi_fsm) {
     case S_IDLE:
 	p_spi_miso = !p_spi_ss.read();
         break;
     case S_SEND_DATA:
-	p_spi_miso = (r_spi_shiftreg & 0x80) != 0;
+	p_spi_miso = (spi_shiftreg & 0x80) != 0;
 	break;
     default:
@@ -235,5 +237,5 @@
 	if (m_acmd) {
 #ifdef SOCLIB_MODULE_DEBUG0
-	std::cout << name() << " new acmd " << std::dec << (int)cmd << " args " << std::hex << data << " crc " << (int)r_cmdcrc << std::endl;
+	std::cout << name() << " new acmd " << std::dec << (int)cmd << " args " << std::hex << data << " crc " << (int)cmdcrc << std::endl;
 #endif
 	    m_acmd = false;
@@ -267,5 +269,5 @@
 	} else {
 #ifdef SOCLIB_MODULE_DEBUG0
-	std::cout << name() << " new cmd " << std::dec << (int)cmd << " args " << std::hex << data << " crc " << (int)r_cmdcrc << std::endl;
+	std::cout << name() << " new cmd " << std::dec << (int)cmd << " args " << std::hex << data << " crc " << (int)cmdcrc << std::endl;
 #endif
 	    switch (cmd) {
@@ -524,12 +526,12 @@
                 "S_NOP",
 	};
-	if (r_spi_clk != p_spi_clk) {
-	std::cout << name() << " SPI_FSM : " << spi_str[r_spi_fsm] 
+	if (spi_clk != p_spi_clk.read()) {
+	std::cout << name() << " SPI_FSM : " << spi_str[spi_fsm] 
 	    << std::dec
-	    << " clk " << r_spi_clk << "->" << p_spi_clk << " ss " << p_spi_ss
+	    << " clk " << spi_clk << "->" << p_spi_clk << " ss " << p_spi_ss
 	    << " mosi " << p_spi_mosi << " miso " << p_spi_miso
 	    << std::endl;
-	std::cout << "         r_spi_shiftreg: " << std::hex << (int)r_spi_shiftreg
-	    << " r_spi_bitcount: " << (int)r_spi_bitcount
+	std::cout << "         spi_shiftreg: " << std::hex << (int)spi_shiftreg
+	    << " spi_bitcount: " << (int)spi_bitcount
 	    << std::endl;
         }
