C027 support

Fork of C027_Support by u-blox

Revision:
95:8282dbbe1492
Parent:
94:d697fe11f3e5
Child:
98:c786461edd40
diff -r d697fe11f3e5 -r 8282dbbe1492 MDM.h
--- a/MDM.h	Thu Jun 12 12:41:26 2014 +0000
+++ b/MDM.h	Tue Jun 17 07:03:48 2014 +0000
@@ -493,6 +493,16 @@
     static int _parseFormated(Pipe<char>* pipe, int len, const char* fmt);
 
 protected:
+    // for rtos over riding by useing Rtos<MDMxx> 
+    /** override in a rtos system, you us the wait function of a Thread
+        \param ms the number of milliseconds to wait
+    */
+    virtual void wait_ms(int ms)   { if (ms) ::wait_ms(ms); }
+    //! override the lock in a rtos system
+    virtual void lock(void)        { } 
+    //! override the unlock in a rtos system
+    virtual void unlock(void)      { } 
+protected:
     // parsing callbacks for different AT commands and their parameter arguments
     static int _cbString(int type, const char* buf, int len, char* str);
     static int _cbInt(int type, const char* buf, int len, int* val);
@@ -530,7 +540,7 @@
     IP          _ip;  //!< assigned ip address
     // management struture for sockets
     typedef enum { SOCK_FREE, SOCK_CREATED, SOCK_CONNECTED } SockState;
-    typedef struct { SockState state; int pending; int timeout_ms; } SockCtrl;
+    typedef struct { volatile SockState state; volatile int pending; int timeout_ms; } SockCtrl;
     // LISA-C has 6 TCP and 6 UDP sockets starting at index 18
     // LISA-U and SARA-G have 7 sockets starting at index 1
     SockCtrl _sockets[32];
@@ -594,7 +604,6 @@
     virtual int _send(const void* buf, int len);
 };
 
- 
 // -----------------------------------------------------------------------
 
 //#define HAVE_MDMUSB
@@ -612,4 +621,27 @@
 };
 #endif
 
+// -----------------------------------------------------------------------
 
+#ifdef RTOS_H
+/** Use this template to override the lock and wait functions of the 
+    modem driver in a Rtos system. For example declare it the modem 
+    object as MDMRtos<MDMSerial> instead of MDMSerial.
+*/
+template <class T>
+class MDMRtos :  public T
+{
+protected:
+    //! we assume that the modem runs in a thread so we yield when waiting
+    virtual void wait_ms(int ms)   {
+        if (ms) Thread::wait(ms);
+        else    Thread::yield();
+    }
+    //! lock a mutex when accessing the modem
+    virtual void lock(void)     { _mtx.lock(); }  
+    //! unlock the modem when done accessing it
+    virtual void unlock(void)   { _mtx.unlock(); }
+    // the mutex resource
+    Mutex _mtx;
+};
+#endif
\ No newline at end of file