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

Committer:
mazgch
Date:
Tue Dec 17 16:25:47 2013 +0000
Revision:
15:37252d7bcd9e
Parent:
14:e30f90b5447e
Child:
16:3ce62caf4518
add short delay after the startup of the board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mazgch 2:b7bd3660ff64 1 /* Platform source file, for the u-blox C27-C20/U20/G35
mazgch 2:b7bd3660ff64 2 * mbed Internet of Things Starter Kit
mazgch 2:b7bd3660ff64 3 * http://mbed.org/platforms/u-blox-C027/
mazgch 2:b7bd3660ff64 4 *
mazgch 2:b7bd3660ff64 5 */
mazgch 2:b7bd3660ff64 6
mazgch 2:b7bd3660ff64 7 #include "C027.h"
mazgch 2:b7bd3660ff64 8
mazgch 2:b7bd3660ff64 9 void mbed_die(void)
mazgch 2:b7bd3660ff64 10 {
mazgch 8:a356376db984 11 DigitalOut led(LED);
mazgch 11:722101675ce4 12 led = 0;
mazgch 11:722101675ce4 13 // Send SOS in Morse Code: // "... --- ... "
mazgch 11:722101675ce4 14 const char sos[] = "=.=.=...===.===.===...=.=.=......";
mazgch 11:722101675ce4 15 const int dot = 100; // length of the dot in milliseconds (typical: 50-100 ms)
mazgch 11:722101675ce4 16 // lengths of symbols:
mazgch 11:722101675ce4 17 // di = dot
mazgch 11:722101675ce4 18 // dah = 3 dot
mazgch 11:722101675ce4 19 // char space = 3 dot
mazgch 11:722101675ce4 20 // word space = 6 dot
mazgch 11:722101675ce4 21 for (int i = 0; /* nothing */; i = sos[i+1] ? i+1 : 0)
mazgch 2:b7bd3660ff64 22 {
mazgch 11:722101675ce4 23 led = (sos[i] == '=');
mazgch 11:722101675ce4 24 wait_ms(dot);
mazgch 2:b7bd3660ff64 25 }
mazgch 2:b7bd3660ff64 26 }
mazgch 2:b7bd3660ff64 27
mazgch 6:e11bf54dd344 28 C027::C027() :
mazgch 13:fb30e9923a7b 29 mdmEn(MDMEN), mdmRst(MDMRST), mdmPwrOn(MDMPWRON), // MDM CTRL
mazgch 13:fb30e9923a7b 30 mdmLvlOe(MDMLVLOE), mdmILvlOe(MDMILVLOE), mdmUsbDet(MDMUSBDET), // MDM IF
mazgch 13:fb30e9923a7b 31 gpsEn(GPSEN), gpsRst(GPSRST) // GPS CTRL
mazgch 6:e11bf54dd344 32 {
mazgch 14:e30f90b5447e 33 DigitalOut led(LED);
mazgch 13:fb30e9923a7b 34 DigitalOut mdmRts(MDMRTS);
mazgch 14:e30f90b5447e 35 led = 0; // LED1: 0=off
mazgch 14:e30f90b5447e 36 mdmRts = 0; // RTS: 0=ready to send
mazgch 7:e3eab86f1de9 37 // we start with the gps disabled
mazgch 8:a356376db984 38 gpsEn = 0; // LDOEN: 1=on,0=off
mazgch 8:a356376db984 39 gpsRst = 0; // RESET: 0=reset,1=operating
mazgch 6:e11bf54dd344 40 gpsIsEnabled = false;
mazgch 7:e3eab86f1de9 41 // we start with the modem disabled
mazgch 13:fb30e9923a7b 42 mdmLvlOe = 1; // LVLEN: 1=disabled (uart/gpio)
mazgch 13:fb30e9923a7b 43 mdmILvlOe = 0; // ILVLEN: 0=disabled (i2c)
mazgch 8:a356376db984 44 mdmUsbDet = 0; // USBDET: 0=disabled
mazgch 8:a356376db984 45 mdmPwrOn = 1; // PWRON: 1=idle, 0=action
mazgch 8:a356376db984 46 mdmEn = 0; // LDOEN: 1=on, 0=off
mazgch 8:a356376db984 47 mdmRst = 0; // RESET: 0=reset, 1=operating
mazgch 6:e11bf54dd344 48 mdmIsEnabled = false;
mazgch 14:e30f90b5447e 49 mdmUseUsb = false;
mazgch 15:37252d7bcd9e 50 wait_ms(50); // when USB cable is inserted the interface chip issues
mazgch 15:37252d7bcd9e 51 // multiple resets to the target CPU We wait here for a short period to
mazgch 15:37252d7bcd9e 52 // prevent those resets from propagating to the modem and other
mazgch 15:37252d7bcd9e 53 // components.
mazgch 6:e11bf54dd344 54 }
mazgch 6:e11bf54dd344 55
mazgch 6:e11bf54dd344 56 void C027::mdmPower(bool enable)
mazgch 6:e11bf54dd344 57 {
mazgch 7:e3eab86f1de9 58 if (!mdmIsEnabled && enable) // enable modem
mazgch 6:e11bf54dd344 59 {
mazgch 7:e3eab86f1de9 60 #ifdef C027_REVA
mazgch 7:e3eab86f1de9 61 // we need the gps ldo for the level shifters of the modem
mazgch 8:a356376db984 62 gpsEn = 1; // LDOEN(gps): 0=off -> 1=on
mazgch 7:e3eab86f1de9 63 #endif
mazgch 14:e30f90b5447e 64 mdmPwrOn = 0; // PWRON: 0=turn on
mazgch 8:a356376db984 65 mdmEn = 0; // LDOEN: 0=off
mazgch 8:a356376db984 66 mdmRst = 0; // RESET: 0=reset
mazgch 8:a356376db984 67 mdmLvlOe = 1; // LVLEN: 1=disabled
mazgch 13:fb30e9923a7b 68 mdmILvlOe = 0; // ILVLEN: 0=disabled
mazgch 14:e30f90b5447e 69 mdmUsbDet = mdmUseUsb ? 1 : 0; // USBDET: 0=disabled, 1=enabled
mazgch 8:a356376db984 70 wait_ms( 10); // wait until supply switched off
mazgch 8:a356376db984 71 mdmEn = 1; // LDOEN: 0=off -> 1=on
mazgch 8:a356376db984 72 wait_ms( 10); // wait until supply stable and on
mazgch 8:a356376db984 73 wait_ms(300); // power on sequence is triggered by keeping reset 50ms-300ms low
mazgch 8:a356376db984 74 mdmRst = 1; // RESET: 0=reset -> 1=operating
mazgch 14:e30f90b5447e 75 wait_ms(150); // LISA-C requires 150ms low to turn on
mazgch 14:e30f90b5447e 76 mdmPwrOn = 1; // PWRON: 0=turn on -> 1=idle
mazgch 7:e3eab86f1de9 77 mdmIsEnabled = true;
mazgch 10:bc9e2eb5daa8 78 // the interfaces of the modem should be fully ready after a certain period
mazgch 10:bc9e2eb5daa8 79 // LISA-U200 5000ms
mazgch 10:bc9e2eb5daa8 80 // SARA-G350 3000ms
mazgch 10:bc9e2eb5daa8 81 // LISA-C200
mazgch 10:bc9e2eb5daa8 82 wait_ms(1000);
mazgch 13:fb30e9923a7b 83 mdmLvlOe = 0; // LVLEN: 0=enabled (uart/gpio)
mazgch 13:fb30e9923a7b 84 if (gpsIsEnabled)
mazgch 13:fb30e9923a7b 85 mdmILvlOe = 1; // ILVLEN: 1=enabled (i2c)
mazgch 7:e3eab86f1de9 86 }
mazgch 7:e3eab86f1de9 87 else if (mdmIsEnabled && !enable) // disable modem
mazgch 7:e3eab86f1de9 88 {
mazgch 7:e3eab86f1de9 89 mdmIsEnabled = false;
mazgch 7:e3eab86f1de9 90 // initiate power off sequence by setting PwnOn low for >1s
mazgch 13:fb30e9923a7b 91 mdmILvlOe = 0; // ILVLEN: 0=disabled (i2c)
mazgch 13:fb30e9923a7b 92 mdmLvlOe = 1; // LVLEN: 1=disabled (uart/gpio)
mazgch 8:a356376db984 93 mdmUsbDet = 0; // USBDET: 0=disabled
mazgch 8:a356376db984 94 mdmPwrOn = 0; // PWRON: 0=active
mazgch 8:a356376db984 95 wait_ms(1000); // send to sleep
mazgch 8:a356376db984 96 mdmPwrOn = 1; // PWRON: 0=active -> 1=idle
mazgch 7:e3eab86f1de9 97 // now we can savely switch off the ldo
mazgch 8:a356376db984 98 mdmRst = 0; // RESET: 1=operating -> 0=reset
mazgch 8:a356376db984 99 mdmEn = 0; // LDOEN: 1=on -> 0=off
mazgch 7:e3eab86f1de9 100 #ifdef C027_REVA
mazgch 7:e3eab86f1de9 101 // the gps ldo may no longer be needed level shifters of the modem
mazgch 7:e3eab86f1de9 102 // so we switch it off if the gps is not enabled
mazgch 7:e3eab86f1de9 103 if (!gpsIsEnabled)
mazgch 7:e3eab86f1de9 104 gpsEn = 0; // LDOEN(gps): 1=on -> 0=off
mazgch 7:e3eab86f1de9 105 #endif
mazgch 6:e11bf54dd344 106 }
mazgch 13:fb30e9923a7b 107
mazgch 6:e11bf54dd344 108 }
mazgch 6:e11bf54dd344 109
mazgch 14:e30f90b5447e 110 void C027::mdmUsbEnable(bool enable)
mazgch 14:e30f90b5447e 111 {
mazgch 14:e30f90b5447e 112 mdmUseUsb = enable;
mazgch 14:e30f90b5447e 113 if (mdmIsEnabled)
mazgch 14:e30f90b5447e 114 mdmUsbDet = mdmUseUsb ? 1 : 0;
mazgch 14:e30f90b5447e 115 }
mazgch 14:e30f90b5447e 116
mazgch 6:e11bf54dd344 117 void C027::mdmReset(void)
mazgch 6:e11bf54dd344 118 {
mazgch 8:a356376db984 119 if (mdmIsEnabled)
mazgch 8:a356376db984 120 {
mazgch 8:a356376db984 121 mdmRst = 0; // RESET: 0=reset
mazgch 8:a356376db984 122 // power on sequence is triggered by reset low
mazgch 8:a356376db984 123 // LISA-U200 50ms
mazgch 8:a356376db984 124 // SARA-G350 50ms
mazgch 8:a356376db984 125 // LISA-C200 300ms
mazgch 8:a356376db984 126 wait_ms(300);
mazgch 8:a356376db984 127 mdmRst = 1; // RESET: 0=reset -> 1=operating
mazgch 8:a356376db984 128 }
mazgch 8:a356376db984 129 }
mazgch 8:a356376db984 130
mazgch 8:a356376db984 131 void C027::mdmWakeup(void)
mazgch 8:a356376db984 132 {
mazgch 6:e11bf54dd344 133 if (mdmIsEnabled)
mazgch 6:e11bf54dd344 134 {
mazgch 8:a356376db984 135 mdmPwrOn = 0;
mazgch 8:a356376db984 136 // wakeup the device by low pulse:
mazgch 8:a356376db984 137 // LISA-U200 50-80us
mazgch 8:a356376db984 138 // SARA-G350 5ms
mazgch 8:a356376db984 139 // LISA-C200 150ms
mazgch 8:a356376db984 140 wait_ms(150);
mazgch 8:a356376db984 141 mdmPwrOn = 1;
mazgch 6:e11bf54dd344 142 }
mazgch 8:a356376db984 143 }
mazgch 8:a356376db984 144
mazgch 8:a356376db984 145 void C027::mdmSleep(void)
mazgch 8:a356376db984 146 {
mazgch 8:a356376db984 147 if (mdmIsEnabled)
mazgch 8:a356376db984 148 {
mazgch 8:a356376db984 149 mdmPwrOn = 0;
mazgch 8:a356376db984 150 // going to sleep is triggerd by low pulse:
mazgch 8:a356376db984 151 // LISA-U200 1000ms
mazgch 8:a356376db984 152 // SARA-G350 n/a
mazgch 8:a356376db984 153 // LISA-C200 n/a
mazgch 8:a356376db984 154 wait_ms(1000);
mazgch 8:a356376db984 155 mdmPwrOn = 1;
mazgch 8:a356376db984 156 }
mazgch 7:e3eab86f1de9 157 }
mazgch 7:e3eab86f1de9 158
mazgch 7:e3eab86f1de9 159 void C027::gpsPower(bool enable)
mazgch 7:e3eab86f1de9 160 {
mazgch 7:e3eab86f1de9 161 if (!gpsIsEnabled && enable) // enable gps
mazgch 7:e3eab86f1de9 162 {
mazgch 7:e3eab86f1de9 163 gpsRst = 0; // RESET: 0=reset
mazgch 7:e3eab86f1de9 164 gpsEn = 1; // LDOEN: 0=off -> 1=on
mazgch 7:e3eab86f1de9 165 wait_ms(1); // wait until stable
mazgch 7:e3eab86f1de9 166 gpsRst = 1; // RESET: 0=reset -> 1=operating
mazgch 7:e3eab86f1de9 167 gpsIsEnabled = true;
mazgch 7:e3eab86f1de9 168 // the gps schould be fully ready after 50ms
mazgch 13:fb30e9923a7b 169 if (mdmIsEnabled)
mazgch 13:fb30e9923a7b 170 mdmILvlOe = 1; // ILVLEN: 0=enabled (i2c)
mazgch 7:e3eab86f1de9 171 }
mazgch 7:e3eab86f1de9 172 else if (gpsIsEnabled && !enable) // diasble gps
mazgch 7:e3eab86f1de9 173 {
mazgch 7:e3eab86f1de9 174 gpsIsEnabled = false;
mazgch 13:fb30e9923a7b 175 mdmILvlOe = 0; // ILVLEN: 0=disabled (i2c)
mazgch 13:fb30e9923a7b 176 gpsRst = 0; // RESET: 1=operating -> 0=reset
mazgch 7:e3eab86f1de9 177 #ifdef C027_REVA
mazgch 7:e3eab86f1de9 178 // the gps ldo may have to remain enabled for the level shifters of the modem
mazgch 7:e3eab86f1de9 179 if (!mdmIsEnabled)
mazgch 13:fb30e9923a7b 180 gpsEn = 0; // LDOEN: 1=on -> 0=off
mazgch 7:e3eab86f1de9 181 #else
mazgch 13:fb30e9923a7b 182 gpsEn = 0; // LDOEN: 1=on -> 0=off
mazgch 7:e3eab86f1de9 183 #endif
mazgch 7:e3eab86f1de9 184 }
mazgch 6:e11bf54dd344 185 }
mazgch 6:e11bf54dd344 186
mazgch 6:e11bf54dd344 187 void C027::gpsReset(void)
mazgch 6:e11bf54dd344 188 {
mazgch 6:e11bf54dd344 189 if (gpsIsEnabled)
mazgch 6:e11bf54dd344 190 {
mazgch 6:e11bf54dd344 191 gpsRst = 0; // RESET: 0=reset,1=operating
mazgch 6:e11bf54dd344 192 wait_ms(1);
mazgch 6:e11bf54dd344 193 gpsRst = 1; // RESET: 1=operating,0=reset
mazgch 6:e11bf54dd344 194 }
mazgch 6:e11bf54dd344 195 }