Fork to support REVB hardware.

Dependents:   C027_BootTest_revb C027_EthernetSniffTest C027_M3_SerialEcho C027_HelloWorld_revb ... more

Fork of C027 by u-blox

Committer:
dixter1
Date:
Sun Dec 15 21:17:22 2013 +0000
Revision:
22:2ab87e985526
Parent:
21:db7c445289f5
Comment Updates

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
dixter1 20:2ae219d82c0e 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
dixter1 16:6475e8463afc 42 mdmLvlOe = 1; // LVLEN: 1=disabled (uart/gpio)
dixter1 16:6475e8463afc 43 mdmILvlOe = 1; // ILVLEN: 0=disabled (i2c)
dixter1 15:971186932592 44 mdmUsbDet = 1; // USBDET: 0=disabled
dixter1 20:2ae219d82c0e 45
dixter1 20:2ae219d82c0e 46
mazgch 8:a356376db984 47 mdmPwrOn = 1; // PWRON: 1=idle, 0=action
mazgch 8:a356376db984 48 mdmEn = 0; // LDOEN: 1=on, 0=off
dixter1 15:971186932592 49 mdmRst = 1; // RESET: 0=reset, 1=operating
mazgch 6:e11bf54dd344 50 mdmIsEnabled = false;
dixter1 20:2ae219d82c0e 51 mdmUseUsb = false;
dixter1 20:2ae219d82c0e 52
dixter1 19:82c9967207f1 53 // The USB insertion and removal, and the Reset Button
dixter1 19:82c9967207f1 54 // can cause multiple resets to the device. Wait for
dixter1 19:82c9967207f1 55 // a period of time for this to settle before proceeding
dixter1 19:82c9967207f1 56 // with turning on various components on the board.
dixter1 20:2ae219d82c0e 57 wait_ms(3000);
mazgch 6:e11bf54dd344 58 }
mazgch 6:e11bf54dd344 59
dixter1 22:2ab87e985526 60
dixter1 22:2ab87e985526 61 // this is a test function designed to turn on all hardware that
dixter1 22:2ab87e985526 62 // might leak current into the LISA chip, while disabling the
dixter1 22:2ab87e985526 63 // LISA chip itself. This is intended to be as harsh as possible,
dixter1 22:2ab87e985526 64 // and is most relevant to REV B hardware.
dixter1 16:6475e8463afc 65 void C027::LeakageTest( void )
dixter1 16:6475e8463afc 66 {
dixter1 16:6475e8463afc 67 mdmEn = 0; //disable
dixter1 16:6475e8463afc 68 gpsEn = 1; //enable
dixter1 16:6475e8463afc 69 mdmLvlOe = 0; //enable
dixter1 16:6475e8463afc 70 mdmILvlOe = 1; //enable
dixter1 16:6475e8463afc 71 mdmPwrOn = 1; //hi (no meaning this context)
dixter1 16:6475e8463afc 72 }
dixter1 16:6475e8463afc 73
dixter1 20:2ae219d82c0e 74 void C027::mdmPower(bool enable, bool use_mdmuart)
mazgch 6:e11bf54dd344 75 {
mazgch 7:e3eab86f1de9 76 if (!mdmIsEnabled && enable) // enable modem
mazgch 6:e11bf54dd344 77 {
dixter1 20:2ae219d82c0e 78 mdmUsbDet = ( use_mdmuart? 0:1 ); // USBDET: 0=enable uart, 1=USB Only
dixter1 20:2ae219d82c0e 79 wait_ms(10);
mazgch 8:a356376db984 80 mdmEn = 1; // LDOEN: 0=off -> 1=on
dixter1 22:2ab87e985526 81 wait_ms(50); //
dixter1 15:971186932592 82 mdmPwrOn = 0; // PWRON: 0=turn on -> 1=idle
dixter1 22:2ab87e985526 83 wait_ms(300); // power on is triggered by asserting PwrOn
mazgch 14:e30f90b5447e 84 mdmPwrOn = 1; // PWRON: 0=turn on -> 1=idle
mazgch 7:e3eab86f1de9 85 mdmIsEnabled = true;
dixter1 16:6475e8463afc 86 wait_ms(1000);
dixter1 16:6475e8463afc 87 mdmLvlOe = 0; // LVLEN: 0=enabled;
mazgch 7:e3eab86f1de9 88 }
mazgch 7:e3eab86f1de9 89 else if (mdmIsEnabled && !enable) // disable modem
mazgch 7:e3eab86f1de9 90 {
mazgch 7:e3eab86f1de9 91 mdmIsEnabled = false;
mazgch 7:e3eab86f1de9 92 // initiate power off sequence by setting PwnOn low for >1s
mazgch 13:fb30e9923a7b 93 mdmILvlOe = 0; // ILVLEN: 0=disabled (i2c)
mazgch 13:fb30e9923a7b 94 mdmLvlOe = 1; // LVLEN: 1=disabled (uart/gpio)
mazgch 8:a356376db984 95 mdmUsbDet = 0; // USBDET: 0=disabled
mazgch 8:a356376db984 96 mdmPwrOn = 0; // PWRON: 0=active
mazgch 8:a356376db984 97 wait_ms(1000); // send to sleep
mazgch 8:a356376db984 98 mdmPwrOn = 1; // PWRON: 0=active -> 1=idle
mazgch 7:e3eab86f1de9 99 // now we can savely switch off the ldo
mazgch 8:a356376db984 100 mdmRst = 0; // RESET: 1=operating -> 0=reset
mazgch 8:a356376db984 101 mdmEn = 0; // LDOEN: 1=on -> 0=off
dixter1 21:db7c445289f5 102 gpsEn = 0; // LDOEN(gps): 1=on -> 0=off
mazgch 6:e11bf54dd344 103 }
mazgch 13:fb30e9923a7b 104
mazgch 6:e11bf54dd344 105 }
mazgch 6:e11bf54dd344 106
mazgch 14:e30f90b5447e 107 void C027::mdmUsbEnable(bool enable)
mazgch 14:e30f90b5447e 108 {
mazgch 14:e30f90b5447e 109 mdmUseUsb = enable;
mazgch 14:e30f90b5447e 110 if (mdmIsEnabled)
mazgch 14:e30f90b5447e 111 mdmUsbDet = mdmUseUsb ? 1 : 0;
mazgch 14:e30f90b5447e 112 }
mazgch 14:e30f90b5447e 113
mazgch 6:e11bf54dd344 114 void C027::mdmReset(void)
mazgch 6:e11bf54dd344 115 {
mazgch 8:a356376db984 116 if (mdmIsEnabled)
mazgch 8:a356376db984 117 {
mazgch 8:a356376db984 118 mdmRst = 0; // RESET: 0=reset
mazgch 8:a356376db984 119 // power on sequence is triggered by reset low
mazgch 8:a356376db984 120 // LISA-U200 50ms
mazgch 8:a356376db984 121 // SARA-G350 50ms
mazgch 8:a356376db984 122 // LISA-C200 300ms
mazgch 8:a356376db984 123 wait_ms(300);
mazgch 8:a356376db984 124 mdmRst = 1; // RESET: 0=reset -> 1=operating
mazgch 8:a356376db984 125 }
mazgch 8:a356376db984 126 }
mazgch 8:a356376db984 127
mazgch 8:a356376db984 128 void C027::mdmWakeup(void)
mazgch 8:a356376db984 129 {
mazgch 6:e11bf54dd344 130 if (mdmIsEnabled)
mazgch 6:e11bf54dd344 131 {
mazgch 8:a356376db984 132 mdmPwrOn = 0;
mazgch 8:a356376db984 133 // wakeup the device by low pulse:
mazgch 8:a356376db984 134 // LISA-U200 50-80us
mazgch 8:a356376db984 135 // SARA-G350 5ms
mazgch 8:a356376db984 136 // LISA-C200 150ms
mazgch 8:a356376db984 137 wait_ms(150);
mazgch 8:a356376db984 138 mdmPwrOn = 1;
mazgch 6:e11bf54dd344 139 }
mazgch 8:a356376db984 140 }
mazgch 8:a356376db984 141
dixter1 15:971186932592 142 // delete this function?
dixter1 15:971186932592 143 // pwr_on signal has no function once modem is powered on.
mazgch 8:a356376db984 144 void C027::mdmSleep(void)
mazgch 8:a356376db984 145 {
mazgch 8:a356376db984 146 if (mdmIsEnabled)
mazgch 8:a356376db984 147 {
mazgch 8:a356376db984 148 mdmPwrOn = 0;
mazgch 8:a356376db984 149 // going to sleep is triggerd by low pulse:
mazgch 8:a356376db984 150 // LISA-U200 1000ms
mazgch 8:a356376db984 151 // SARA-G350 n/a
mazgch 8:a356376db984 152 // LISA-C200 n/a
mazgch 8:a356376db984 153 wait_ms(1000);
mazgch 8:a356376db984 154 mdmPwrOn = 1;
mazgch 8:a356376db984 155 }
mazgch 7:e3eab86f1de9 156 }
mazgch 7:e3eab86f1de9 157
dixter1 21:db7c445289f5 158 // enable: enable the gps power
dixter1 21:db7c445289f5 159 // lisa_gps: connect GPS to the LISA chip
dixter1 21:db7c445289f5 160 void C027::gpsPower(bool enable, bool lisa_gps )
mazgch 7:e3eab86f1de9 161 {
mazgch 7:e3eab86f1de9 162 if (!gpsIsEnabled && enable) // enable gps
mazgch 7:e3eab86f1de9 163 {
mazgch 7:e3eab86f1de9 164 gpsRst = 0; // RESET: 0=reset
mazgch 7:e3eab86f1de9 165 gpsEn = 1; // LDOEN: 0=off -> 1=on
mazgch 7:e3eab86f1de9 166 wait_ms(1); // wait until stable
mazgch 7:e3eab86f1de9 167 gpsRst = 1; // RESET: 0=reset -> 1=operating
mazgch 7:e3eab86f1de9 168 gpsIsEnabled = true;
mazgch 7:e3eab86f1de9 169 // the gps schould be fully ready after 50ms
dixter1 21:db7c445289f5 170 if (mdmIsEnabled && lisa_gps )
dixter1 21:db7c445289f5 171 {
dixter1 21:db7c445289f5 172 mdmILvlOe = 0; // ILVLEN: 0=enabled (i2c)
dixter1 21:db7c445289f5 173 }
dixter1 21:db7c445289f5 174 else
dixter1 21:db7c445289f5 175 {
dixter1 21:db7c445289f5 176 mdmILvlOe = 1; // ILVLEN: 0=enabled (i2c)
dixter1 21:db7c445289f5 177 }
mazgch 7:e3eab86f1de9 178 }
mazgch 7:e3eab86f1de9 179 else if (gpsIsEnabled && !enable) // diasble gps
mazgch 7:e3eab86f1de9 180 {
mazgch 7:e3eab86f1de9 181 gpsIsEnabled = false;
mazgch 13:fb30e9923a7b 182 mdmILvlOe = 0; // ILVLEN: 0=disabled (i2c)
mazgch 13:fb30e9923a7b 183 gpsRst = 0; // RESET: 1=operating -> 0=reset
mazgch 13:fb30e9923a7b 184 gpsEn = 0; // LDOEN: 1=on -> 0=off
mazgch 7:e3eab86f1de9 185 }
mazgch 6:e11bf54dd344 186 }
mazgch 6:e11bf54dd344 187
mazgch 6:e11bf54dd344 188 void C027::gpsReset(void)
mazgch 6:e11bf54dd344 189 {
mazgch 6:e11bf54dd344 190 if (gpsIsEnabled)
mazgch 6:e11bf54dd344 191 {
mazgch 6:e11bf54dd344 192 gpsRst = 0; // RESET: 0=reset,1=operating
mazgch 6:e11bf54dd344 193 wait_ms(1);
mazgch 6:e11bf54dd344 194 gpsRst = 1; // RESET: 1=operating,0=reset
mazgch 6:e11bf54dd344 195 }
mazgch 6:e11bf54dd344 196 }