Preparing grounds for modem api

* Lays down ground for mbed modem_api
* Standardizes pin names relating to modem device for UBLOX C027 and MTS_DRAGONFLY_F411RE
  devices
* Ublox modem api is changed to use a standard, platform independent name so that same
  api could be used with multiple ubloc modems.
* DCD Polarity macro is added to assist the driver in knowing correct polarity
pull/4119/head
Hasnain Virk 2017-05-01 23:15:34 +03:00
parent 925f54bfce
commit fcbcfafec5
8 changed files with 166 additions and 117 deletions

View File

@ -1,85 +0,0 @@
/* 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 "mbed_wait_api.h"
#include "C027_api.h"
#include "us_ticker_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);
// Can't use wait_ms() as RTOS isn't initialised yet
// so this is the correct way to wait for 50 ms
uint32_t start = us_ticker_read();
while ((us_ticker_read() - start) < 50000);
}
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(&mdmEn)) {
// 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
}
}

View File

@ -1,22 +0,0 @@
#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

View File

@ -162,6 +162,11 @@ typedef enum {
NC = (int)0xFFFFFFFF
} PinName;
#define ACTIVE_HIGH_POLARITY 1
#define ACTIVE_LOW_POLARITY 0
#define MDMDCD_POLARITY ACTIVE_LOW_POLARITY
typedef enum {
PullUp = 0,
PullDown = 3,

View File

@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "C027_api.h"
#include "ublox_low_level_api.h"
// called before main
void mbed_sdk_init() {
c027_init();
ublox_mdm_init();
}

View File

@ -0,0 +1,97 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 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 <stdbool.h>
#include "hal/us_ticker_api.h"
#include "platform/mbed_wait_api.h"
#include "gpio_api.h"
#include "ublox_low_level_api.h"
static bool modemOn;
static bool gpsOn;
void ublox_mdm_init(void)
{
gpio_t gpio;
// start with modem disabled
gpio_init_out_ex(&gpio, MDMEN, 0);
gpio_init_out_ex(&gpio, MDMRST, 1);
gpio_init_out_ex(&gpio, MDMPWRON, 1);
gpio_init_out_ex(&gpio, MDMLVLOE, 1); // LVLEN: 1=disabled
gpio_init_out_ex(&gpio, MDMILVLOE, 0); // ILVLEN: 0=disabled
gpio_init_out_ex(&gpio, MDMUSBDET, 0);
gpio_init_out_ex(&gpio, MDMRTS, 0);
// start with gps disabled
gpio_init_out_ex(&gpio, GPSEN, 0);
gpio_init_out_ex(&gpio, GPSRST, 1);
// led should be off
gpio_init_out_ex(&gpio, LED, 0);
// Can't use wait_ms() as RTOS isn't initialised yet
//wait_ms(50); // when USB cable is inserted the interface chip issues
// Here's the code from the non-RTOS version
uint32_t start = us_ticker_read();
while ((us_ticker_read() - start) < 50000);
}
void ublox_mdm_powerOn(int usb)
{
gpio_t gpio;
// turn on the mode by enabling power with power on pin low and correct USB detect level
gpio_init_out_ex(&gpio, MDMUSBDET, usb ? 1 : 0); // USBDET: 0=disabled, 1=enabled
if (!modemOn) { // enable modem
gpio_init_out_ex(&gpio, MDMEN, 1); // LDOEN: 1=on
wait_ms(1); // wait until supply switched off
// now we can safely enable the level shifters
gpio_init_out_ex(&gpio, MDMLVLOE, 0); // LVLEN: 0=enabled (uart/gpio)
if (gpsOn)
gpio_init_out_ex(&gpio, MDMILVLOE, 1); // ILVLEN: 1=enabled (i2c)
}
}
void ublox_mdm_powerOff(void)
{
gpio_t gpio;
if (modemOn) {
// diable all level shifters
gpio_init_out_ex(&gpio, MDMILVLOE, 0); // ILVLEN: 0=disabled (i2c)
gpio_init_out_ex(&gpio, MDMLVLOE, 1); // LVLEN: 1=disabled (uart/gpio)
gpio_init_out_ex(&gpio,MDMUSBDET, 0); // USBDET: 0=disabled
// now we can savely switch off the ldo
gpio_init_out_ex(&gpio, MDMEN, 0); // LDOEN: 0=off
modemOn = false;
}
}
void ublox_gps_powerOn(void)
{
gpio_t gpio;
if (!gpsOn) {
// switch on power supply
gpio_init_out_ex(&gpio, GPSEN, 1); // LDOEN: 1=on
wait_ms(1); // wait until supply switched off
if (modemOn)
gpio_init_out_ex(&gpio, MDMILVLOE, 1); // ILVLEN: 1=enabled (i2c)
}
}
void ublox_gps_powerOff(void)
{
gpio_t gpio;
if (gpsOn) {
gpio_init_out_ex(&gpio, MDMILVLOE, 0); // ILVLEN: 0=disabled (i2c)
gpio_init_out_ex(&gpio, GPSEN, 0); // LDOEN: 0=off
}
}

View File

@ -0,0 +1,37 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 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.
*/
#ifndef UBLOX_LOW_LEVEL_H
#define UBLOX_LOW_LEVEL_H
#ifdef __cplusplus
extern "C" {
#endif
void ublox_mdm_init(void);
void ublox_mdm_powerOn(int usb);
void ublox_mdm_powerOff(void);
void ublox_gps_powerOn(void);
void ublox_gps_powerOff(void);
#ifdef __cplusplus
}
#endif
#endif // UBLOX_LOW_LEVEL_H

View File

@ -38,6 +38,9 @@ extern "C" {
#endif
typedef enum {
// Not connected
NC = -1,
PA_0 = 0x00,
PA_1 = 0x01,
PA_2 = 0x02,
@ -141,10 +144,20 @@ typedef enum {
RADIO_RX = PC_6,
RADIO_RTS = PB_10,
RADIO_CTS = PB_12,
RADIO_DCD = D5,
RADIO_DSR = D8,
RADIO_DTR = D4,
RADIO_RI = D9,
RADIO_DCD = NC,
RADIO_DSR = NC,
RADIO_DTR = NC,
RADIO_RI = NC,
MDMPWRON = PC_13, // 3G_ONOFF DragonFly Design Guide, Page No. 16
MDMTXD = RADIO_TX, // Transmit Data
MDMRXD = RADIO_RX, // Receive Data
MDMRTS = RADIO_RTS, // Request to Send
MDMCTS = RADIO_CTS, // Clear to Send
MDMDCD = RADIO_DCD, // Data Carrier Detect
MDMDSR = RADIO_DSR, // Data Set Ready
MDMDTR = RADIO_DTR, // Data Terminal Ready
MDMRI = RADIO_RI, // Ring Indicator
WAKEUP = D3,
// I2C1 and I2C3 are available on Arduino pins
@ -175,12 +188,16 @@ typedef enum {
SPI_MISO = SPI3_MISO,
SPI_SCK = SPI3_SCK,
SPI_CS1 = PA_4,
SPI_CS2 = PB_14,
SPI_CS2 = PB_14
// Not connected
NC = (int)0xFFFFFFFF
} PinName;
#define ACTIVE_HIGH_POLARITY 1
#define ACTIVE_LOW_POLARITY 0
#define MDMDCD_POLARITY ACTIVE_HIGH_POLARITY
#ifdef __cplusplus
}
#endif

View File

@ -248,7 +248,7 @@
"supported_form_factors": ["ARDUINO"],
"core": "Cortex-M3",
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "GCC_CR", "IAR"],
"extra_labels": ["NXP", "LPC176X", "FLASH_CMSIS_ALGO"],
"extra_labels": ["NXP", "LPC176X", "FLASH_CMSIS_ALGO", "UBLOX_MODEM"],
"macros": ["TARGET_LPC1768"],
"inherits": ["LPCTarget"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "DEBUG_AWARENESS", "ERROR_RED", "ETHERNET", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "FLASH"],