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

C027.cpp

Committer:
mazgch
Date:
2013-10-25
Revision:
7:e3eab86f1de9
Parent:
6:e11bf54dd344
Child:
8:a356376db984

File content as of revision 7:e3eab86f1de9:

/*  Platform source file, for the u-blox C27-C20/U20/G35 
*   mbed Internet of Things Starter Kit
*   http://mbed.org/platforms/u-blox-C027/
*   
*/

#include "C027.h"

void mbed_die(void)
{
    for (;;)
    {
        // nothing to do here
        
        // we do not have fancy leds that 
        // can be flashed on the C027
    }
}

C027::C027() :
    mdmEn(MDMEN),
#ifndef C027_REVA
                  mdmRst(MDMRST),
#endif                
                                  mdmPwrOn(MDMPWRON), mdmRts(MDMRTS),
    gpsEn(GPSEN), gpsRst(GPSRST)
{
    // we start with the gps disabled
    gpsEn    = 0; // LDOEN: 1=on,0=off
    gpsRst   = 0; // RESET: 0=reset,1=operating
    gpsIsEnabled = false;
    // we start with the modem disabled
    mdmPwrOn = 1; // PWRON: 1=idle,0=action
    mdmRts   = 0; // RTS.   0=ready to send 
    mdmEn    = 0; // LDOEN: 1=on,0=off
#ifndef C027_REVA
    mdmRst   = 0; // RESET: 0=reset,1=operating
#endif
    mdmIsEnabled = false;
}

void C027::mdmPower(bool enable)
{
    if (!mdmIsEnabled && enable) // enable modem
    {
#ifdef C027_REVA
        // we need the gps ldo for the level shifters of the modem
        gpsEn    = 1;   // LDOEN(gps): 0=off -> 1=on 
#endif
        mdmPwrOn = 1;   // PWRON: 1=idle
        mdmEn    = 0;   // LDOEN: 0=off
#ifndef C027_REVA
        mdmRst   = 0;   // RESET: 0=reset
#endif
        wait_ms(1);     //        wait until stable
        mdmEn    = 1;   // LDOEN: 0=off -> 1=on
        wait_ms(50);    //        power on sequence is triggered by keeping reset 50ms low
#ifndef C027_REVA
        mdmRst   = 1;   // RESET: 0=reset -> 1=operating
#endif
        mdmIsEnabled = true;
        // the modem schould be fully ready after 3000ms
    }
    else if (mdmIsEnabled && !enable) // disable modem
    {
        mdmIsEnabled = false;
        // initiate power off sequence by setting PwnOn low for >1s
        mdmPwrOn = 0;   // PWRON: 0=active
        wait_ms(1000);  
        mdmPwrOn = 1;   // PWRON: 0=active -> 1=idle
        // now we can savely switch off the ldo
#ifndef C027_REVA
        mdmRst   = 0;   // RESET: 1=operating -> 0=reset
#endif
        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)
            gpsEn = 0;  // LDOEN(gps): 1=on -> 0=off
#endif
    }
}

void C027::mdmReset(void)
{
#ifndef C027_REVA
    if (mdmIsEnabled)
    {
        // power on sequence is triggered by 50ms reset low
        mdmRst   = 0;    // RESET: 0=reset,1=operating
        wait_ms(50);
        mdmRst   = 1;    // RESET: 1=operating,0=reset
    }
#endif
}

void C027::gpsPower(bool enable)
{
    if (!gpsIsEnabled && enable) // enable gps
    {
        gpsRst   = 0;   // RESET: 0=reset
        gpsEn    = 1;   // LDOEN: 0=off -> 1=on
        wait_ms(1);     //        wait until stable
        gpsRst   = 1;   // RESET: 0=reset -> 1=operating
        gpsIsEnabled = true;
        // the gps schould be fully ready after 50ms
    }
    else if (gpsIsEnabled && !enable) // diasble gps
    {
        gpsIsEnabled = false;
        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 
#else
        gpsEn    = 0;   // LDOEN: 1=on -> 0=off 
#endif
    }
}

void C027::gpsReset(void)
{
    if (gpsIsEnabled)
    {
        gpsRst   = 0;    // RESET: 0=reset,1=operating
        wait_ms(1);
        gpsRst   = 1;    // RESET: 1=operating,0=reset
    }
}