ZG2100 Network interface source

Revision:
1:3a7c15057192
Parent:
0:b802fc31f1db
--- a/drv/zg2100/zg_com.c	Fri Jul 09 15:37:23 2010 +0000
+++ b/drv/zg2100/zg_com.c	Fri Aug 06 10:23:41 2010 +0000
@@ -37,13 +37,14 @@
 //Locals
 static SPI* m_pSpi;
 static DigitalOut* m_pCs;
-static InterruptIn* m_pInt;
+//static InterruptIn* m_pInt;
+static DigitalIn* m_pInt;
 
 static byte cmd[ZG_CMD_BUF_SIZE] ZG_MEM;
 
 //Functions
 
-void zg_com_init(SPI* pSpi, DigitalOut* pCs, InterruptIn* pInt, DigitalOut* pNrst)
+void zg_com_init(SPI* pSpi, DigitalOut* pCs, /*InterruptIn**/ DigitalIn* pInt, DigitalOut* pNrst)
 {
   m_pSpi = pSpi;
   m_pCs = pCs;
@@ -57,7 +58,7 @@
   wait_ms(100);
   //And release
   pNrst->write(ZG_SPI_RST_OFF);
-  m_pInt->fall(zg_on_int); //Attach on interrupt callback
+ // m_pInt->fall(zg_on_int); //Attach on interrupt callback
 }
 
 
@@ -125,15 +126,15 @@
 {
   cmd[0] = (fifo==ZG_FIFO_DATA)?ZG_CMD_FIFO_RD_DATA:ZG_CMD_FIFO_RD_MGMT;
   memset( &cmd[1], 0, 2 );
-  zg_spi_trf(cmd, 3, false); //false : Command not terminated yet
+  zg_spi_trf(cmd, 3, false, ZG_SPI_TRF); //false : Command not terminated yet
   *pType = cmd[1];
   *pSubtype = cmd[2];
   
-  memset(buf, 0, len);
-  zg_spi_trf(buf, len);  
+  //memset(buf, 0, len);
+  zg_spi_trf(buf, len, true, ZG_SPI_READ);  
   
   cmd[0] = ZG_CMD_FIFO_RD_DONE;
-  zg_spi_trf(cmd, 1);  
+  zg_spi_trf(cmd, 1, true, ZG_SPI_WRITE);  
 }
 
 void zg_fifo_write( byte fifo, byte type, byte subtype, byte* buf, int len, bool start /*= true*/, bool stop /*= true*/ )
@@ -143,52 +144,70 @@
     cmd[0] = (fifo==ZG_FIFO_DATA)?ZG_CMD_FIFO_WR_DATA:ZG_CMD_FIFO_WR_MGMT;
     cmd[1] = type;
     cmd[2] = subtype;
-    zg_spi_trf(cmd, 3, false); //false : Command not terminated yet
+    zg_spi_trf(cmd, 3, false, ZG_SPI_WRITE); //false : Command not terminated yet
   }
   
   /*if(len>0 && buf!=NULL)
   {*/
-    zg_spi_trf(buf, len, stop);
+    zg_spi_trf(buf, len, stop, ZG_SPI_WRITE);
   /*}*/
   
   if(stop)
   {
     cmd[0] = ZG_CMD_FIFO_WR_DONE;
-    zg_spi_trf(cmd, 1);
+    zg_spi_trf(cmd, 1, true, ZG_SPI_WRITE);
   }
 }
 
 
-void zg_spi_trf(byte* buf, int len, bool resetCs /*= true*/)
+void zg_spi_trf(byte* buf, int len, bool resetCs /*= true*/, ZG_SPI_DIR dir /*= ZG_SPI_TRF*/)
 {
   int i;
   m_pCs->write(ZG_SPI_CS_ON);
 
-/*
+#ifdef __DEBUG
   DBG("\r\nDump: >>\r\n");
   for(i=0; i<len; i++)
   {
-    DBG("%02x ", buf[i]);
+    DBGL("%02x ", buf[i]);
   }
-  DBG("\r\n>>\r\n"); 
-*/
+  DBG("\r\n>>\r\n");
+#endif
 
-  for(i=0; i<len; i++)
+  switch(dir)
   {
-    buf[i] = (byte) m_pSpi->write(buf[i]);
+  case ZG_SPI_READ:
+    for(i=0; i<len; i++)
+      buf[i] = (byte) m_pSpi->write(0);
+    break;
+  case ZG_SPI_WRITE:
+    for(i=0; i<len; i++)
+      m_pSpi->write(buf[i]);
+    break;
+  case ZG_SPI_TRF:
+  default:
+    for(i=0; i<len; i++)
+      buf[i] = (byte) m_pSpi->write(buf[i]);
+    break;
   }
 
-/*
+#ifdef __DEBUG
   DBG("\r\nDump: <<\r\n");
   for(i=0; i<len; i++)
   {
-    DBG("%02x ", buf[i]);
+    DBGL("%02x ", buf[i]);
   }
   DBG("\r\n<<\r\n"); 
-*/
+#endif
+
  
   if(resetCs) //If false, allows to split transfer in multiple calls
     m_pCs->write(ZG_SPI_CS_OFF);
 }
 
+bool zg_is_int()
+{
+  return !(m_pInt->read());
+}
+
 #endif