Board support library for C027
Dependents: IoTWorkshopLCD IoTWorkshopBuzzer IoTWorkshopSensors C027_USSDTest ... more
Fork of C027 by
C027.cpp@12:31fb5ff9fef5, 2013-11-10 (annotated)
- Committer:
- mazgch
- Date:
- Sun Nov 10 18:46:43 2013 +0000
- Revision:
- 12:31fb5ff9fef5
- Parent:
- 11:722101675ce4
- Child:
- 13:fb30e9923a7b
do not use A0 on rev a
Who changed what in which revision?
User | Revision | Line number | New 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 | 10:bc9e2eb5daa8 | 29 | mdmEn(MDMEN), mdmRst(MDMRST), mdmPwrOn(MDMPWRON), // MDM CTRL |
mazgch | 8:a356376db984 | 30 | mdmRts(MDMRTS), mdmLvlOe(MDMLVLOE), mdmUsbDet(MDMUSBDET), // MDM IF |
mazgch | 8:a356376db984 | 31 | gpsEn(GPSEN), gpsRst(GPSRST) // GPS CTRL |
mazgch | 6:e11bf54dd344 | 32 | { |
mazgch | 7:e3eab86f1de9 | 33 | // we start with the gps disabled |
mazgch | 8:a356376db984 | 34 | gpsEn = 0; // LDOEN: 1=on,0=off |
mazgch | 8:a356376db984 | 35 | gpsRst = 0; // RESET: 0=reset,1=operating |
mazgch | 6:e11bf54dd344 | 36 | gpsIsEnabled = false; |
mazgch | 7:e3eab86f1de9 | 37 | // we start with the modem disabled |
mazgch | 8:a356376db984 | 38 | mdmLvlOe = 1; // LVLEN: 1=disabled |
mazgch | 8:a356376db984 | 39 | mdmUsbDet = 0; // USBDET: 0=disabled |
mazgch | 8:a356376db984 | 40 | mdmPwrOn = 1; // PWRON: 1=idle, 0=action |
mazgch | 8:a356376db984 | 41 | mdmRts = 0; // RTS. 0=ready to send |
mazgch | 8:a356376db984 | 42 | mdmEn = 0; // LDOEN: 1=on, 0=off |
mazgch | 8:a356376db984 | 43 | mdmRst = 0; // RESET: 0=reset, 1=operating |
mazgch | 6:e11bf54dd344 | 44 | mdmIsEnabled = false; |
mazgch | 6:e11bf54dd344 | 45 | } |
mazgch | 6:e11bf54dd344 | 46 | |
mazgch | 6:e11bf54dd344 | 47 | void C027::mdmPower(bool enable) |
mazgch | 6:e11bf54dd344 | 48 | { |
mazgch | 7:e3eab86f1de9 | 49 | if (!mdmIsEnabled && enable) // enable modem |
mazgch | 6:e11bf54dd344 | 50 | { |
mazgch | 7:e3eab86f1de9 | 51 | #ifdef C027_REVA |
mazgch | 7:e3eab86f1de9 | 52 | // we need the gps ldo for the level shifters of the modem |
mazgch | 8:a356376db984 | 53 | gpsEn = 1; // LDOEN(gps): 0=off -> 1=on |
mazgch | 7:e3eab86f1de9 | 54 | #endif |
mazgch | 8:a356376db984 | 55 | mdmPwrOn = 1; // PWRON: 1=idle |
mazgch | 8:a356376db984 | 56 | mdmEn = 0; // LDOEN: 0=off |
mazgch | 8:a356376db984 | 57 | mdmRst = 0; // RESET: 0=reset |
mazgch | 8:a356376db984 | 58 | mdmLvlOe = 1; // LVLEN: 1=disabled |
mazgch | 8:a356376db984 | 59 | mdmUsbDet = 0; // USBDET: 0=disabled |
mazgch | 8:a356376db984 | 60 | wait_ms( 10); // wait until supply switched off |
mazgch | 8:a356376db984 | 61 | mdmEn = 1; // LDOEN: 0=off -> 1=on |
mazgch | 8:a356376db984 | 62 | wait_ms( 10); // wait until supply stable and on |
mazgch | 8:a356376db984 | 63 | wait_ms(300); // power on sequence is triggered by keeping reset 50ms-300ms low |
mazgch | 8:a356376db984 | 64 | mdmRst = 1; // RESET: 0=reset -> 1=operating |
mazgch | 8:a356376db984 | 65 | mdmLvlOe = 0; // LVLEN: 0=enabled |
mazgch | 8:a356376db984 | 66 | mdmUsbDet = 1; // USBDET: 1=enabled |
mazgch | 7:e3eab86f1de9 | 67 | mdmIsEnabled = true; |
mazgch | 10:bc9e2eb5daa8 | 68 | // the interfaces of the modem should be fully ready after a certain period |
mazgch | 10:bc9e2eb5daa8 | 69 | // LISA-U200 5000ms |
mazgch | 10:bc9e2eb5daa8 | 70 | // SARA-G350 3000ms |
mazgch | 10:bc9e2eb5daa8 | 71 | // LISA-C200 |
mazgch | 10:bc9e2eb5daa8 | 72 | wait_ms(1000); |
mazgch | 7:e3eab86f1de9 | 73 | } |
mazgch | 7:e3eab86f1de9 | 74 | else if (mdmIsEnabled && !enable) // disable modem |
mazgch | 7:e3eab86f1de9 | 75 | { |
mazgch | 7:e3eab86f1de9 | 76 | mdmIsEnabled = false; |
mazgch | 7:e3eab86f1de9 | 77 | // initiate power off sequence by setting PwnOn low for >1s |
mazgch | 8:a356376db984 | 78 | mdmLvlOe = 1; // LVLEN: 1=disabled |
mazgch | 8:a356376db984 | 79 | mdmUsbDet = 0; // USBDET: 0=disabled |
mazgch | 8:a356376db984 | 80 | mdmPwrOn = 0; // PWRON: 0=active |
mazgch | 8:a356376db984 | 81 | wait_ms(1000); // send to sleep |
mazgch | 8:a356376db984 | 82 | mdmPwrOn = 1; // PWRON: 0=active -> 1=idle |
mazgch | 7:e3eab86f1de9 | 83 | // now we can savely switch off the ldo |
mazgch | 8:a356376db984 | 84 | mdmRst = 0; // RESET: 1=operating -> 0=reset |
mazgch | 8:a356376db984 | 85 | mdmEn = 0; // LDOEN: 1=on -> 0=off |
mazgch | 7:e3eab86f1de9 | 86 | #ifdef C027_REVA |
mazgch | 7:e3eab86f1de9 | 87 | // the gps ldo may no longer be needed level shifters of the modem |
mazgch | 7:e3eab86f1de9 | 88 | // so we switch it off if the gps is not enabled |
mazgch | 7:e3eab86f1de9 | 89 | if (!gpsIsEnabled) |
mazgch | 7:e3eab86f1de9 | 90 | gpsEn = 0; // LDOEN(gps): 1=on -> 0=off |
mazgch | 7:e3eab86f1de9 | 91 | #endif |
mazgch | 6:e11bf54dd344 | 92 | } |
mazgch | 6:e11bf54dd344 | 93 | } |
mazgch | 6:e11bf54dd344 | 94 | |
mazgch | 6:e11bf54dd344 | 95 | void C027::mdmReset(void) |
mazgch | 6:e11bf54dd344 | 96 | { |
mazgch | 8:a356376db984 | 97 | if (mdmIsEnabled) |
mazgch | 8:a356376db984 | 98 | { |
mazgch | 8:a356376db984 | 99 | mdmRst = 0; // RESET: 0=reset |
mazgch | 8:a356376db984 | 100 | // power on sequence is triggered by reset low |
mazgch | 8:a356376db984 | 101 | // LISA-U200 50ms |
mazgch | 8:a356376db984 | 102 | // SARA-G350 50ms |
mazgch | 8:a356376db984 | 103 | // LISA-C200 300ms |
mazgch | 8:a356376db984 | 104 | wait_ms(300); |
mazgch | 8:a356376db984 | 105 | mdmRst = 1; // RESET: 0=reset -> 1=operating |
mazgch | 8:a356376db984 | 106 | } |
mazgch | 8:a356376db984 | 107 | } |
mazgch | 8:a356376db984 | 108 | |
mazgch | 8:a356376db984 | 109 | void C027::mdmWakeup(void) |
mazgch | 8:a356376db984 | 110 | { |
mazgch | 6:e11bf54dd344 | 111 | if (mdmIsEnabled) |
mazgch | 6:e11bf54dd344 | 112 | { |
mazgch | 8:a356376db984 | 113 | mdmPwrOn = 0; |
mazgch | 8:a356376db984 | 114 | // wakeup the device by low pulse: |
mazgch | 8:a356376db984 | 115 | // LISA-U200 50-80us |
mazgch | 8:a356376db984 | 116 | // SARA-G350 5ms |
mazgch | 8:a356376db984 | 117 | // LISA-C200 150ms |
mazgch | 8:a356376db984 | 118 | wait_ms(150); |
mazgch | 8:a356376db984 | 119 | mdmPwrOn = 1; |
mazgch | 6:e11bf54dd344 | 120 | } |
mazgch | 8:a356376db984 | 121 | } |
mazgch | 8:a356376db984 | 122 | |
mazgch | 8:a356376db984 | 123 | void C027::mdmSleep(void) |
mazgch | 8:a356376db984 | 124 | { |
mazgch | 8:a356376db984 | 125 | if (mdmIsEnabled) |
mazgch | 8:a356376db984 | 126 | { |
mazgch | 8:a356376db984 | 127 | mdmPwrOn = 0; |
mazgch | 8:a356376db984 | 128 | // going to sleep is triggerd by low pulse: |
mazgch | 8:a356376db984 | 129 | // LISA-U200 1000ms |
mazgch | 8:a356376db984 | 130 | // SARA-G350 n/a |
mazgch | 8:a356376db984 | 131 | // LISA-C200 n/a |
mazgch | 8:a356376db984 | 132 | wait_ms(1000); |
mazgch | 8:a356376db984 | 133 | mdmPwrOn = 1; |
mazgch | 8:a356376db984 | 134 | } |
mazgch | 7:e3eab86f1de9 | 135 | } |
mazgch | 7:e3eab86f1de9 | 136 | |
mazgch | 7:e3eab86f1de9 | 137 | void C027::gpsPower(bool enable) |
mazgch | 7:e3eab86f1de9 | 138 | { |
mazgch | 7:e3eab86f1de9 | 139 | if (!gpsIsEnabled && enable) // enable gps |
mazgch | 7:e3eab86f1de9 | 140 | { |
mazgch | 7:e3eab86f1de9 | 141 | gpsRst = 0; // RESET: 0=reset |
mazgch | 7:e3eab86f1de9 | 142 | gpsEn = 1; // LDOEN: 0=off -> 1=on |
mazgch | 7:e3eab86f1de9 | 143 | wait_ms(1); // wait until stable |
mazgch | 7:e3eab86f1de9 | 144 | gpsRst = 1; // RESET: 0=reset -> 1=operating |
mazgch | 7:e3eab86f1de9 | 145 | gpsIsEnabled = true; |
mazgch | 7:e3eab86f1de9 | 146 | // the gps schould be fully ready after 50ms |
mazgch | 7:e3eab86f1de9 | 147 | } |
mazgch | 7:e3eab86f1de9 | 148 | else if (gpsIsEnabled && !enable) // diasble gps |
mazgch | 7:e3eab86f1de9 | 149 | { |
mazgch | 7:e3eab86f1de9 | 150 | gpsIsEnabled = false; |
mazgch | 7:e3eab86f1de9 | 151 | gpsRst = 0; // RESET: 1=operating -> 0=reset |
mazgch | 7:e3eab86f1de9 | 152 | #ifdef C027_REVA |
mazgch | 7:e3eab86f1de9 | 153 | // the gps ldo may have to remain enabled for the level shifters of the modem |
mazgch | 7:e3eab86f1de9 | 154 | if (!mdmIsEnabled) |
mazgch | 7:e3eab86f1de9 | 155 | gpsEn = 0; // LDOEN: 1=on -> 0=off |
mazgch | 7:e3eab86f1de9 | 156 | #else |
mazgch | 7:e3eab86f1de9 | 157 | gpsEn = 0; // LDOEN: 1=on -> 0=off |
mazgch | 7:e3eab86f1de9 | 158 | #endif |
mazgch | 7:e3eab86f1de9 | 159 | } |
mazgch | 6:e11bf54dd344 | 160 | } |
mazgch | 6:e11bf54dd344 | 161 | |
mazgch | 6:e11bf54dd344 | 162 | void C027::gpsReset(void) |
mazgch | 6:e11bf54dd344 | 163 | { |
mazgch | 6:e11bf54dd344 | 164 | if (gpsIsEnabled) |
mazgch | 6:e11bf54dd344 | 165 | { |
mazgch | 6:e11bf54dd344 | 166 | gpsRst = 0; // RESET: 0=reset,1=operating |
mazgch | 6:e11bf54dd344 | 167 | wait_ms(1); |
mazgch | 6:e11bf54dd344 | 168 | gpsRst = 1; // RESET: 1=operating,0=reset |
mazgch | 6:e11bf54dd344 | 169 | } |
mazgch | 6:e11bf54dd344 | 170 | } |