mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.c@323:9e901b0a5aa1, 2014-09-13 (annotated)
- Committer:
- shaoziyang
- Date:
- Sat Sep 13 14:25:46 2014 +0000
- Revision:
- 323:9e901b0a5aa1
- Parent:
- 196:fdfa63dee410
test with CLOCK_SETUP = 0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 194:718a82ebba31 | 1 | /* mbed Microcontroller Library |
mbed_official | 194:718a82ebba31 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 194:718a82ebba31 | 3 | * |
mbed_official | 194:718a82ebba31 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 194:718a82ebba31 | 5 | * you may not use this file except in compliance with the License. |
mbed_official | 194:718a82ebba31 | 6 | * You may obtain a copy of the License at |
mbed_official | 194:718a82ebba31 | 7 | * |
mbed_official | 194:718a82ebba31 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 194:718a82ebba31 | 9 | * |
mbed_official | 194:718a82ebba31 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 194:718a82ebba31 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 194:718a82ebba31 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 194:718a82ebba31 | 13 | * See the License for the specific language governing permissions and |
mbed_official | 194:718a82ebba31 | 14 | * limitations under the License. |
mbed_official | 194:718a82ebba31 | 15 | */ |
mbed_official | 194:718a82ebba31 | 16 | #include "gpio_api.h" |
mbed_official | 194:718a82ebba31 | 17 | #include "wait_api.h" |
mbed_official | 194:718a82ebba31 | 18 | #include "C027_api.h" |
mbed_official | 194:718a82ebba31 | 19 | |
mbed_official | 194:718a82ebba31 | 20 | static gpio_t mdmEn, mdmLvlOe, mdmILvlOe, mdmUsbDet; |
mbed_official | 194:718a82ebba31 | 21 | static gpio_t gpsEn; |
mbed_official | 194:718a82ebba31 | 22 | |
mbed_official | 194:718a82ebba31 | 23 | void c027_init(void) { |
mbed_official | 194:718a82ebba31 | 24 | gpio_t led, mdmRts, mdmRst, gpsRst, mdmPwrOn; |
mbed_official | 194:718a82ebba31 | 25 | // start with modem disabled |
mbed_official | 194:718a82ebba31 | 26 | gpio_init_out_ex(&mdmEn, MDMEN, 0); |
mbed_official | 194:718a82ebba31 | 27 | gpio_init_out_ex(&mdmRst, MDMRST, 1); |
mbed_official | 194:718a82ebba31 | 28 | gpio_init_out_ex(&mdmPwrOn, MDMPWRON, 1); |
mbed_official | 194:718a82ebba31 | 29 | gpio_init_out_ex(&mdmLvlOe, MDMLVLOE, 1); // LVLEN: 1=disabled |
mbed_official | 194:718a82ebba31 | 30 | gpio_init_out_ex(&mdmILvlOe, MDMILVLOE, 0); // ILVLEN: 0=disabled |
mbed_official | 194:718a82ebba31 | 31 | gpio_init_out_ex(&mdmUsbDet, MDMUSBDET, 0); |
mbed_official | 194:718a82ebba31 | 32 | gpio_init_out_ex(&mdmRts, MDMRTS, 0); |
mbed_official | 194:718a82ebba31 | 33 | // start with gps disabled |
mbed_official | 194:718a82ebba31 | 34 | gpio_init_out_ex(&gpsEn, GPSEN, 0); |
mbed_official | 194:718a82ebba31 | 35 | gpio_init_out_ex(&gpsRst, GPSRST, 1); |
mbed_official | 194:718a82ebba31 | 36 | // led should be off |
mbed_official | 194:718a82ebba31 | 37 | gpio_init_out_ex(&led, LED, 0); |
mbed_official | 194:718a82ebba31 | 38 | |
mbed_official | 194:718a82ebba31 | 39 | wait_ms(50); // when USB cable is inserted the interface chip issues |
mbed_official | 194:718a82ebba31 | 40 | } |
mbed_official | 194:718a82ebba31 | 41 | |
mbed_official | 194:718a82ebba31 | 42 | void c027_mdm_powerOn(int usb) { |
mbed_official | 194:718a82ebba31 | 43 | // turn on the mode by enabling power with power on pin low and correct USB detect level |
mbed_official | 194:718a82ebba31 | 44 | gpio_write(&mdmUsbDet, usb ? 1 : 0); // USBDET: 0=disabled, 1=enabled |
mbed_official | 194:718a82ebba31 | 45 | if (!gpio_read(&mdmEn)) { // enable modem |
mbed_official | 194:718a82ebba31 | 46 | gpio_write(&mdmEn, 1); // LDOEN: 1=on |
mbed_official | 194:718a82ebba31 | 47 | wait_ms(1); // wait until supply switched off |
mbed_official | 194:718a82ebba31 | 48 | // now we can safely enable the level shifters |
mbed_official | 194:718a82ebba31 | 49 | gpio_write(&mdmLvlOe, 0); // LVLEN: 0=enabled (uart/gpio) |
mbed_official | 194:718a82ebba31 | 50 | if (gpio_read(&gpsEn)) |
mbed_official | 194:718a82ebba31 | 51 | gpio_write(&mdmILvlOe, 1); // ILVLEN: 1=enabled (i2c) |
mbed_official | 194:718a82ebba31 | 52 | } |
mbed_official | 194:718a82ebba31 | 53 | } |
mbed_official | 194:718a82ebba31 | 54 | |
mbed_official | 194:718a82ebba31 | 55 | void c027_mdm_powerOff(void) { |
mbed_official | 196:fdfa63dee410 | 56 | if (gpio_read(&mdmEn)) { |
mbed_official | 194:718a82ebba31 | 57 | // diable all level shifters |
mbed_official | 194:718a82ebba31 | 58 | gpio_write(&mdmILvlOe, 0); // ILVLEN: 0=disabled (i2c) |
mbed_official | 194:718a82ebba31 | 59 | gpio_write(&mdmLvlOe, 1); // LVLEN: 1=disabled (uart/gpio) |
mbed_official | 194:718a82ebba31 | 60 | gpio_write(&mdmUsbDet, 0); // USBDET: 0=disabled |
mbed_official | 194:718a82ebba31 | 61 | // now we can savely switch off the ldo |
mbed_official | 194:718a82ebba31 | 62 | gpio_write(&mdmEn, 0); // LDOEN: 0=off |
mbed_official | 194:718a82ebba31 | 63 | } |
mbed_official | 194:718a82ebba31 | 64 | } |
mbed_official | 194:718a82ebba31 | 65 | |
mbed_official | 194:718a82ebba31 | 66 | void c027_gps_powerOn(void) { |
mbed_official | 194:718a82ebba31 | 67 | if (!gpio_read(&gpsEn)) { |
mbed_official | 194:718a82ebba31 | 68 | // switch on power supply |
mbed_official | 194:718a82ebba31 | 69 | gpio_write(&gpsEn, 1); // LDOEN: 1=on |
mbed_official | 194:718a82ebba31 | 70 | wait_ms(1); // wait until supply switched off |
mbed_official | 194:718a82ebba31 | 71 | if (gpio_read(&mdmEn)) |
mbed_official | 194:718a82ebba31 | 72 | gpio_write(&mdmILvlOe, 1); // ILVLEN: 1=enabled (i2c) |
mbed_official | 194:718a82ebba31 | 73 | } |
mbed_official | 194:718a82ebba31 | 74 | } |
mbed_official | 194:718a82ebba31 | 75 | |
mbed_official | 194:718a82ebba31 | 76 | void c027_gps_powerOff(void) { |
mbed_official | 194:718a82ebba31 | 77 | if (gpio_read(&gpsEn)) { |
mbed_official | 194:718a82ebba31 | 78 | gpio_write(&mdmILvlOe, 0); // ILVLEN: 0=disabled (i2c) |
mbed_official | 194:718a82ebba31 | 79 | gpio_write(&gpsEn, 0); // LDOEN: 0=off |
mbed_official | 194:718a82ebba31 | 80 | } |
mbed_official | 194:718a82ebba31 | 81 | } |