NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

Revision:
4:fd826cad83c0
Parent:
0:632c9925f013
--- a/drv/serial/buf/SerialBuf.h	Fri Jun 18 10:38:57 2010 +0000
+++ b/drv/serial/buf/SerialBuf.h	Fri Jul 09 14:46:47 2010 +0000
@@ -30,11 +30,37 @@
 #include "drv/serial/usb/UsbSerial.h"
 #endif
 
+class SerialCircularBuf
+{
+public:
+  SerialCircularBuf(int len);  
+  ~SerialCircularBuf();
+  
+  int room();
+  int len();
+  
+  void write(char c);
+  char read();
+  
+  void setReadMode(bool readMode); //If true, keeps chars in buf when read, false by default
+  void flushRead(); //Delete chars that have been read & return chars len (only useful with readMode = true)
+  void resetRead(); //Go back to initial read position & return chars len (only useful with readMode = true)
+  
+private:
+  char* m_buf;
+  int m_len;
+  
+  volatile char* m_pReadStart;
+  volatile char* m_pRead;
+  volatile char* m_pWrite;
+  volatile bool m_readMode;
+};
+
 class SerialBuf
 {
 public:
   SerialBuf(int len); //Buffer length
-  ~SerialBuf();
+  virtual ~SerialBuf();
   
   void attach(Serial* pSerial);
   void detach();
@@ -52,36 +78,20 @@
   void setReadMode(bool readMode); //If true, keeps chars in buf when read, false by default
   void flushRead(); //Delete chars that have been read & return chars len (only useful with readMode = true)
   void resetRead(); //Go back to initial read position & return chars len (only useful with readMode = true)
-protected:
-  virtual bool onRead();// = 0; //Called when new bytes are received : WARN: executed in an interrupt context >> only fast & non-blocking code (eg no printf;))
-  //return true if handled, false otherwise
+  
 private:
-  void onSerialInterrupt(); //Callback from m_pSerial
+  void onRxInterrupt(); //Callback from m_pSerial
+  void onTxInterrupt(); //Callback from m_pSerial
+    
+  SerialCircularBuf m_rxBuf;
+  SerialCircularBuf m_txBuf;
 
-  volatile bool m_trmt; //For debugging (Was transmitting?)
-    
   Serial* m_pSerial; //Not owned
-  
-  char get(); //Get a char from buf
-  void put(char c); //Put a char in buf
-  int room(); //Return room available in buf
-  int len(); //Return chars len in buf
-  
-  char* m_buf;
-  int m_bufLen;
-  volatile char* m_pReadStart;
-  volatile char* m_pRead;
 
-  volatile char* m_pReadByInt; //Chars read during interrupt
-  volatile bool m_intCanReadData;
-
-  volatile char* m_pWrite;
-  volatile bool m_readMode;
-  
   #if NET_USB_SERIAL
   //USB Serial Impl
   UsbSerial* m_pUsbSerial; //Not owned
-  Ticker m_usbTick;
+  //Ticker m_usbTick;
   #endif
 };