Board support library for C027

Dependents:   IoTWorkshopLCD IoTWorkshopBuzzer IoTWorkshopSensors C027_USSDTest ... more

Fork of C027 by u-blox

/media/uploads/ublox/c027_pinout_new.png

Revision:
16:3ce62caf4518
Parent:
15:37252d7bcd9e
Child:
17:8ca897c3cf41
diff -r 37252d7bcd9e -r 3ce62caf4518 C027.cpp
--- a/C027.cpp	Tue Dec 17 16:25:47 2013 +0000
+++ b/C027.cpp	Tue Apr 08 12:15:07 2014 +0000
@@ -6,51 +6,41 @@
 
 #include "C027.h"
 
+#ifndef TARGET_UBLOX_C027
+// override the mbed_die function
 void mbed_die(void)
 {
     DigitalOut led(LED);
-    led = 0;
-    // Send SOS in Morse Code: // "... --- ...  "
-    const char sos[] = "=.=.=...===.===.===...=.=.=......"; 
-    const int  dot = 100; // length of the dot in milliseconds (typical: 50-100 ms)
-    // lengths of symbols: 
-    // di         =   dot 
-    // dah        = 3 dot 
-    // char space = 3 dot 
-    // word space = 6 dot 
-    for (int i = 0; /* nothing */; i = sos[i+1] ? i+1 : 0)
+    __irq_disable();
+    for (;;)
     {
-        led = (sos[i] == '=');
-        wait_ms(dot);
+        // nothing to do here
+        led = 0;
+        wait_ms(200);
+        led = 1;
+        wait_ms(200);
     }
 }
+#endif
 
 C027::C027() :
-    mdmEn(MDMEN),       mdmRst(MDMRST),         mdmPwrOn(MDMPWRON),   // MDM CTRL
-    mdmLvlOe(MDMLVLOE), mdmILvlOe(MDMILVLOE),   mdmUsbDet(MDMUSBDET), // MDM IF
-    gpsEn(GPSEN),       gpsRst(GPSRST)                                // GPS CTRL
+    // Modem
+    mdmEn(MDMEN, 0),            // LDO off
+    mdmRst(MDMRST, 1),          // not reset
+    mdmPwrOn(MDMPWRON, 1),      // Power On idle
+    mdmLvlOe(MDMLVLOE, 1),      // GPIO/Serial velel shifters off
+    mdmILvlOe(MDMILVLOE, 0),    // I2C Level shifter off
+    mdmUsbDet(MDMUSBDET, 0),    // USB not used 
+    // GPS
+    gpsEn(GPSEN, 0),            // LDO off
+    gpsRst(GPSRST, 1)           // not reset
 {
-    DigitalOut led(LED);
-    DigitalOut mdmRts(MDMRTS);
-    led       = 0;  // LED1:   0=off
-    mdmRts    = 0;  // RTS:    0=ready to send 
-    // we start with the gps disabled
-    gpsEn     = 0;  // LDOEN:  1=on,0=off
-    gpsRst    = 0;  // RESET:  0=reset,1=operating
+    DigitalOut led(LED, 0);         // start with leds off
+    DigitalOut mdmRts(MDMRTS, 0);   // make sure that rts is low
+    
     gpsIsEnabled = false;
-    // we start with the modem disabled
-    mdmLvlOe  = 1;  // LVLEN:  1=disabled (uart/gpio)
-    mdmILvlOe = 0;  // ILVLEN: 0=disabled (i2c)
-    mdmUsbDet = 0;  // USBDET: 0=disabled
-    mdmPwrOn  = 1;  // PWRON:  1=idle, 0=action
-    mdmEn     = 0;  // LDOEN:  1=on, 0=off
-    mdmRst    = 0;  // RESET:  0=reset, 1=operating
     mdmIsEnabled = false;
     mdmUseUsb = false;
-    wait_ms(50); // when USB cable is inserted the interface chip issues 
-    // multiple resets to the target CPU We wait here for a short period to 
-    // prevent those resets from propagating to the modem and other 
-    // components. 
 }
 
 void C027::mdmPower(bool enable)
@@ -59,20 +49,19 @@
     {
 #ifdef C027_REVA
         // we need the gps ldo for the level shifters of the modem
-        gpsEn     = 1;  // LDOEN(gps): 0=off -> 1=on 
+        if (!gpsIsEnabled)
+            gpsEn = 1;  // LDOEN(gps): 0=off -> 1=on
 #endif
-        mdmPwrOn  = 0;  // PWRON:  0=turn on
-        mdmEn     = 0;  // LDOEN:  0=off
-        mdmRst    = 0;  // RESET:  0=reset
         mdmLvlOe  = 1;  // LVLEN:  1=disabled
         mdmILvlOe = 0;  // ILVLEN: 0=disabled
+        // turn on the mode by enabling power with power on pin low and correct USB detect level
         mdmUsbDet = mdmUseUsb ? 1 : 0;  // USBDET: 0=disabled, 1=enabled
-        wait_ms( 10);   //         wait until supply switched off
-        mdmEn     = 1;  // LDOEN:  0=off -> 1=on
-        wait_ms( 10);   //         wait until supply stable and on
+        mdmPwrOn  = 0;  // PWRON:  0=turn on
+        mdmEn     = 1;  // LDOEN:  1=on
+        wait_ms( 1);    //         wait until supply switched off
+        // mnake sure reset is also off
+        mdmRst    = 1;  // RESET:  0=not reset
         wait_ms(300);   //         power on sequence is triggered by keeping reset 50ms-300ms low
-        mdmRst    = 1;  // RESET:  0=reset -> 1=operating
-        wait_ms(150);   //         LISA-C requires 150ms low to turn on
         mdmPwrOn  = 1;  // PWRON:  0=turn on -> 1=idle
         mdmIsEnabled = true;
         // the interfaces of the modem should be fully ready after a certain period
@@ -80,6 +69,7 @@
         // SARA-G350  3000ms
         // LISA-C200       
         wait_ms(1000);
+        // now we can safely enable the level shifters
         mdmLvlOe  = 0;  // LVLEN:  0=enabled (uart/gpio)
         if (gpsIsEnabled) 
             mdmILvlOe = 1; // ILVLEN: 1=enabled (i2c)
@@ -87,20 +77,20 @@
     else if (mdmIsEnabled && !enable) // disable modem
     {
         mdmIsEnabled = false;
-        // initiate power off sequence by setting PwnOn low for >1s
+        // diable all level shifters
         mdmILvlOe = 0;  // ILVLEN: 0=disabled (i2c)
         mdmLvlOe  = 1;  // LVLEN:  1=disabled (uart/gpio)
         mdmUsbDet = 0;  // USBDET: 0=disabled
+        // initiate power off sequence by setting PwnOn low for >1s
         mdmPwrOn  = 0;  // PWRON:  0=active
         wait_ms(1000);  //         send to sleep
         mdmPwrOn  = 1;  // PWRON:  0=active -> 1=idle
         // now we can savely switch off the ldo
-        mdmRst    = 0;  // RESET:  1=operating -> 0=reset
         mdmEn     = 0;  // LDOEN:  1=on -> 0=off
 #ifdef C027_REVA
         // the gps ldo may no longer be needed level shifters of the modem
         // so we switch it off if the gps is not enabled
-        if (!gpsIsEnabled)
+        if (!gpsIsEnabled) 
             gpsEn = 0;  // LDOEN(gps): 1=on -> 0=off
 #endif
     }
@@ -136,8 +126,8 @@
         // wakeup the device by low pulse: 
         // LISA-U200 50-80us
         // SARA-G350     5ms
-        // LISA-C200   150ms 
-        wait_ms(150);   
+        // LISA-C200   300ms 
+        wait_ms(300);   
         mdmPwrOn = 1;
     }
 }
@@ -160,9 +150,10 @@
 {
     if (!gpsIsEnabled && enable) // enable gps
     {
-        gpsRst   = 0;   // RESET: 0=reset
+        // switch on power supply
         gpsEn    = 1;   // LDOEN: 0=off -> 1=on
         wait_ms(1);     //        wait until stable
+        // make sure we are not in reset
         gpsRst   = 1;   // RESET: 0=reset -> 1=operating
         gpsIsEnabled = true;
         // the gps schould be fully ready after 50ms
@@ -173,11 +164,10 @@
     {
         gpsIsEnabled = false;
         mdmILvlOe = 0;   // ILVLEN: 0=disabled (i2c)
-        gpsRst    = 0;   // RESET: 1=operating -> 0=reset
 #ifdef C027_REVA
         // the gps ldo may have to remain enabled for the level shifters of the modem
-        if (!mdmIsEnabled) 
-            gpsEn = 0;   // LDOEN: 1=on -> 0=off 
+        if (!mdmIsEnabled)  
+            gpsEn  = 0;  // LDOEN: 1=on -> 0=off 
 #else
         gpsEn     = 0;   // LDOEN: 1=on -> 0=off 
 #endif