From f8e0d9cf3ebbff6d3a8c7abedefb66bddaf9e6bf Mon Sep 17 00:00:00 2001 From: mazgch Date: Thu, 15 May 2014 17:10:30 +0200 Subject: [PATCH 1/2] added a api to manage the power supplies of peripheral power supplies and level shifters --- .../TARGET_UBLOX_C027/C027_api.c | 90 +++++++++++++++++++ .../TARGET_UBLOX_C027/C027_api.h | 22 +++++ .../TARGET_UBLOX_C027/mbed_overrides.c | 25 +----- 3 files changed, 114 insertions(+), 23 deletions(-) create mode 100644 libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.c create mode 100644 libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.h diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.c new file mode 100644 index 0000000000..71273aea4f --- /dev/null +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.c @@ -0,0 +1,90 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "gpio_api.h" +#include "wait_api.h" +#include "C027_api.h" + +static gpio_t mdmEn, mdmLvlOe, mdmILvlOe, mdmUsbDet; +static gpio_t gpsEn; + +void c027_init(void) +{ + gpio_t led, mdmRts, mdmRst, gpsRst, mdmPwrOn; + // start with modem disabled + gpio_init_out_ex(&mdmEn, MDMEN, 0); + gpio_init_out_ex(&mdmRst, MDMRST, 1); + gpio_init_out_ex(&mdmPwrOn, MDMPWRON, 1); + gpio_init_out_ex(&mdmLvlOe, MDMLVLOE, 1); // LVLEN: 1=disabled + gpio_init_out_ex(&mdmILvlOe, MDMILVLOE, 0); // ILVLEN: 0=disabled + gpio_init_out_ex(&mdmUsbDet, MDMUSBDET, 0); + gpio_init_out_ex(&mdmRts, MDMRTS, 0); + // start with gps disabled + gpio_init_out_ex(&gpsEn, GPSEN, 0); + gpio_init_out_ex(&gpsRst, GPSRST, 1); + // led should be off + gpio_init_out_ex(&led, LED, 0); + + wait_ms(50); // when USB cable is inserted the interface chip issues +} + +void c027_mdm_powerOn(int usb) +{ + // turn on the mode by enabling power with power on pin low and correct USB detect level + gpio_write(&mdmUsbDet, usb ? 1 : 0); // USBDET: 0=disabled, 1=enabled + if (!gpio_read(&mdmEn)) // enable modem + { + gpio_write(&mdmEn, 1); // LDOEN: 1=on + wait_ms(1); // wait until supply switched off + // now we can safely enable the level shifters + gpio_write(&mdmLvlOe, 0); // LVLEN: 0=enabled (uart/gpio) + if (gpio_read(&gpsEn)) + gpio_write(&mdmILvlOe, 1); // ILVLEN: 1=enabled (i2c) + } +} + +void c027_mdm_powerOff(void) +{ + if (gpio_read(&gpsEn)) + { + // diable all level shifters + gpio_write(&mdmILvlOe, 0); // ILVLEN: 0=disabled (i2c) + gpio_write(&mdmLvlOe, 1); // LVLEN: 1=disabled (uart/gpio) + gpio_write(&mdmUsbDet, 0); // USBDET: 0=disabled + // now we can savely switch off the ldo + gpio_write(&mdmEn, 0); // LDOEN: 0=off + } +} + +void c027_gps_powerOn(void) +{ + if (!gpio_read(&gpsEn)) + { + // switch on power supply + gpio_write(&gpsEn, 1); // LDOEN: 1=on + wait_ms(1); // wait until supply switched off + if (gpio_read(&mdmEn)) + gpio_write(&mdmILvlOe, 1); // ILVLEN: 1=enabled (i2c) + } +} + +void c027_gps_powerOff(void) +{ + if (gpio_read(&gpsEn)) + { + gpio_write(&mdmILvlOe, 0); // ILVLEN: 0=disabled (i2c) + gpio_write(&gpsEn, 0); // LDOEN: 0=off + } +} diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.h b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.h new file mode 100644 index 0000000000..46897945cb --- /dev/null +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.h @@ -0,0 +1,22 @@ +#ifndef C027_H +#define C027_H + +#ifdef __cplusplus +extern "C" { +#endif + +void c027_init(void); + +void c027_mdm_powerOn(int usb); + +void c027_mdm_powerOff(void); + +void c027_gps_powerOn(void); + +void c027_gps_powerOff(void); + +#ifdef __cplusplus +} +#endif + +#endif // C027_H diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/mbed_overrides.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/mbed_overrides.c index fba3793380..8dcd95b37a 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/mbed_overrides.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/mbed_overrides.c @@ -13,31 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "gpio_api.h" -#include "wait_api.h" +#include "C027_api.h" // called before main void mbed_sdk_init() { - gpio_t modemEn, modemRst, modemPwrOn, modemLvlOe, modemILvlOe, modemUsbDet; - gpio_t gpsEn, gpsRst, led, modemRts; - - // start with modem disabled - gpio_init_out_ex(&modemEn, MDMEN, 0); - gpio_init_out_ex(&modemRst, MDMRST, 1); - gpio_init_out_ex(&modemPwrOn, MDMPWRON, 1); - gpio_init_out_ex(&modemLvlOe, MDMLVLOE, 1); - gpio_init_out_ex(&modemILvlOe, MDMILVLOE, 0); - gpio_init_out_ex(&modemUsbDet, MDMUSBDET, 0); - gpio_init_out_ex(&modemRts, MDMRTS, 0); - // start with gps disabled - gpio_init_out_ex(&gpsEn, GPSEN, 0); - gpio_init_out_ex(&gpsRst, GPSRST, 1); - // led should be off - gpio_init_out_ex(&led, LED, 0); - - 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. + c027_init(); } From a36ad6c0b637d2dffb9e9304a844b738aa390db4 Mon Sep 17 00:00:00 2001 From: mazgch Date: Thu, 15 May 2014 17:37:15 +0200 Subject: [PATCH 2/2] address coding style concerns of some individuals --- .../TARGET_UBLOX_C027/C027_api.c | 27 +++++++------------ .../TARGET_UBLOX_C027/mbed_overrides.c | 3 +-- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.c index 71273aea4f..5ec3c1b42c 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.c @@ -20,8 +20,7 @@ static gpio_t mdmEn, mdmLvlOe, mdmILvlOe, mdmUsbDet; static gpio_t gpsEn; -void c027_init(void) -{ +void c027_init(void) { gpio_t led, mdmRts, mdmRst, gpsRst, mdmPwrOn; // start with modem disabled gpio_init_out_ex(&mdmEn, MDMEN, 0); @@ -40,12 +39,10 @@ void c027_init(void) wait_ms(50); // when USB cable is inserted the interface chip issues } -void c027_mdm_powerOn(int usb) -{ +void c027_mdm_powerOn(int usb) { // turn on the mode by enabling power with power on pin low and correct USB detect level gpio_write(&mdmUsbDet, usb ? 1 : 0); // USBDET: 0=disabled, 1=enabled - if (!gpio_read(&mdmEn)) // enable modem - { + if (!gpio_read(&mdmEn)) { // enable modem gpio_write(&mdmEn, 1); // LDOEN: 1=on wait_ms(1); // wait until supply switched off // now we can safely enable the level shifters @@ -55,10 +52,8 @@ void c027_mdm_powerOn(int usb) } } -void c027_mdm_powerOff(void) -{ - if (gpio_read(&gpsEn)) - { +void c027_mdm_powerOff(void) { + if (gpio_read(&gpsEn)) { // diable all level shifters gpio_write(&mdmILvlOe, 0); // ILVLEN: 0=disabled (i2c) gpio_write(&mdmLvlOe, 1); // LVLEN: 1=disabled (uart/gpio) @@ -68,10 +63,8 @@ void c027_mdm_powerOff(void) } } -void c027_gps_powerOn(void) -{ - if (!gpio_read(&gpsEn)) - { +void c027_gps_powerOn(void) { + if (!gpio_read(&gpsEn)) { // switch on power supply gpio_write(&gpsEn, 1); // LDOEN: 1=on wait_ms(1); // wait until supply switched off @@ -80,10 +73,8 @@ void c027_gps_powerOn(void) } } -void c027_gps_powerOff(void) -{ - if (gpio_read(&gpsEn)) - { +void c027_gps_powerOff(void) { + if (gpio_read(&gpsEn)) { gpio_write(&mdmILvlOe, 0); // ILVLEN: 0=disabled (i2c) gpio_write(&gpsEn, 0); // LDOEN: 0=off } diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/mbed_overrides.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/mbed_overrides.c index 8dcd95b37a..9d9eac1c19 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/mbed_overrides.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/mbed_overrides.c @@ -16,7 +16,6 @@ #include "C027_api.h" // called before main -void mbed_sdk_init() -{ +void mbed_sdk_init() { c027_init(); }