Skip to content

Commit fcbcfaf

Browse files
author
Hasnain Virk
committed
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
1 parent 925f54b commit fcbcfaf

File tree

8 files changed

+166
-117
lines changed

8 files changed

+166
-117
lines changed

targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.c

Lines changed: 0 additions & 85 deletions
This file was deleted.

targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/C027_api.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/PinNames.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ typedef enum {
162162
NC = (int)0xFFFFFFFF
163163
} PinName;
164164

165+
#define ACTIVE_HIGH_POLARITY 1
166+
#define ACTIVE_LOW_POLARITY 0
167+
168+
#define MDMDCD_POLARITY ACTIVE_LOW_POLARITY
169+
165170
typedef enum {
166171
PullUp = 0,
167172
PullDown = 3,

targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/mbed_overrides.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#include "C027_api.h"
16+
#include "ublox_low_level_api.h"
1717

1818
// called before main
1919
void mbed_sdk_init() {
20-
c027_init();
20+
ublox_mdm_init();
2121
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include <stdbool.h>
17+
#include "hal/us_ticker_api.h"
18+
#include "platform/mbed_wait_api.h"
19+
#include "gpio_api.h"
20+
#include "ublox_low_level_api.h"
21+
22+
static bool modemOn;
23+
static bool gpsOn;
24+
25+
void ublox_mdm_init(void)
26+
{
27+
gpio_t gpio;
28+
// start with modem disabled
29+
gpio_init_out_ex(&gpio, MDMEN, 0);
30+
gpio_init_out_ex(&gpio, MDMRST, 1);
31+
gpio_init_out_ex(&gpio, MDMPWRON, 1);
32+
gpio_init_out_ex(&gpio, MDMLVLOE, 1); // LVLEN: 1=disabled
33+
gpio_init_out_ex(&gpio, MDMILVLOE, 0); // ILVLEN: 0=disabled
34+
gpio_init_out_ex(&gpio, MDMUSBDET, 0);
35+
gpio_init_out_ex(&gpio, MDMRTS, 0);
36+
// start with gps disabled
37+
gpio_init_out_ex(&gpio, GPSEN, 0);
38+
gpio_init_out_ex(&gpio, GPSRST, 1);
39+
// led should be off
40+
gpio_init_out_ex(&gpio, LED, 0);
41+
42+
// Can't use wait_ms() as RTOS isn't initialised yet
43+
//wait_ms(50); // when USB cable is inserted the interface chip issues
44+
// Here's the code from the non-RTOS version
45+
uint32_t start = us_ticker_read();
46+
while ((us_ticker_read() - start) < 50000);
47+
}
48+
49+
void ublox_mdm_powerOn(int usb)
50+
{
51+
gpio_t gpio;
52+
// turn on the mode by enabling power with power on pin low and correct USB detect level
53+
gpio_init_out_ex(&gpio, MDMUSBDET, usb ? 1 : 0); // USBDET: 0=disabled, 1=enabled
54+
if (!modemOn) { // enable modem
55+
gpio_init_out_ex(&gpio, MDMEN, 1); // LDOEN: 1=on
56+
wait_ms(1); // wait until supply switched off
57+
// now we can safely enable the level shifters
58+
gpio_init_out_ex(&gpio, MDMLVLOE, 0); // LVLEN: 0=enabled (uart/gpio)
59+
if (gpsOn)
60+
gpio_init_out_ex(&gpio, MDMILVLOE, 1); // ILVLEN: 1=enabled (i2c)
61+
}
62+
}
63+
64+
void ublox_mdm_powerOff(void)
65+
{
66+
gpio_t gpio;
67+
if (modemOn) {
68+
// diable all level shifters
69+
gpio_init_out_ex(&gpio, MDMILVLOE, 0); // ILVLEN: 0=disabled (i2c)
70+
gpio_init_out_ex(&gpio, MDMLVLOE, 1); // LVLEN: 1=disabled (uart/gpio)
71+
gpio_init_out_ex(&gpio,MDMUSBDET, 0); // USBDET: 0=disabled
72+
// now we can savely switch off the ldo
73+
gpio_init_out_ex(&gpio, MDMEN, 0); // LDOEN: 0=off
74+
modemOn = false;
75+
}
76+
}
77+
78+
void ublox_gps_powerOn(void)
79+
{
80+
gpio_t gpio;
81+
if (!gpsOn) {
82+
// switch on power supply
83+
gpio_init_out_ex(&gpio, GPSEN, 1); // LDOEN: 1=on
84+
wait_ms(1); // wait until supply switched off
85+
if (modemOn)
86+
gpio_init_out_ex(&gpio, MDMILVLOE, 1); // ILVLEN: 1=enabled (i2c)
87+
}
88+
}
89+
90+
void ublox_gps_powerOff(void)
91+
{
92+
gpio_t gpio;
93+
if (gpsOn) {
94+
gpio_init_out_ex(&gpio, MDMILVLOE, 0); // ILVLEN: 0=disabled (i2c)
95+
gpio_init_out_ex(&gpio, GPSEN, 0); // LDOEN: 0=off
96+
}
97+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#ifndef UBLOX_LOW_LEVEL_H
17+
#define UBLOX_LOW_LEVEL_H
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
void ublox_mdm_init(void);
24+
25+
void ublox_mdm_powerOn(int usb);
26+
27+
void ublox_mdm_powerOff(void);
28+
29+
void ublox_gps_powerOn(void);
30+
31+
void ublox_gps_powerOff(void);
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
37+
#endif // UBLOX_LOW_LEVEL_H

targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/PinNames.h

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ extern "C" {
3838
#endif
3939

4040
typedef enum {
41+
// Not connected
42+
NC = -1,
43+
4144
PA_0 = 0x00,
4245
PA_1 = 0x01,
4346
PA_2 = 0x02,
@@ -141,10 +144,20 @@ typedef enum {
141144
RADIO_RX = PC_6,
142145
RADIO_RTS = PB_10,
143146
RADIO_CTS = PB_12,
144-
RADIO_DCD = D5,
145-
RADIO_DSR = D8,
146-
RADIO_DTR = D4,
147-
RADIO_RI = D9,
147+
RADIO_DCD = NC,
148+
RADIO_DSR = NC,
149+
RADIO_DTR = NC,
150+
RADIO_RI = NC,
151+
MDMPWRON = PC_13, // 3G_ONOFF DragonFly Design Guide, Page No. 16
152+
MDMTXD = RADIO_TX, // Transmit Data
153+
MDMRXD = RADIO_RX, // Receive Data
154+
MDMRTS = RADIO_RTS, // Request to Send
155+
MDMCTS = RADIO_CTS, // Clear to Send
156+
MDMDCD = RADIO_DCD, // Data Carrier Detect
157+
MDMDSR = RADIO_DSR, // Data Set Ready
158+
MDMDTR = RADIO_DTR, // Data Terminal Ready
159+
MDMRI = RADIO_RI, // Ring Indicator
160+
148161
WAKEUP = D3,
149162

150163
// I2C1 and I2C3 are available on Arduino pins
@@ -175,12 +188,16 @@ typedef enum {
175188
SPI_MISO = SPI3_MISO,
176189
SPI_SCK = SPI3_SCK,
177190
SPI_CS1 = PA_4,
178-
SPI_CS2 = PB_14,
191+
SPI_CS2 = PB_14
179192

180-
// Not connected
181-
NC = (int)0xFFFFFFFF
182193
} PinName;
183194

195+
#define ACTIVE_HIGH_POLARITY 1
196+
#define ACTIVE_LOW_POLARITY 0
197+
198+
#define MDMDCD_POLARITY ACTIVE_HIGH_POLARITY
199+
200+
184201
#ifdef __cplusplus
185202
}
186203
#endif

targets/targets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
"supported_form_factors": ["ARDUINO"],
249249
"core": "Cortex-M3",
250250
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "GCC_CR", "IAR"],
251-
"extra_labels": ["NXP", "LPC176X", "FLASH_CMSIS_ALGO"],
251+
"extra_labels": ["NXP", "LPC176X", "FLASH_CMSIS_ALGO", "UBLOX_MODEM"],
252252
"macros": ["TARGET_LPC1768"],
253253
"inherits": ["LPCTarget"],
254254
"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"],

0 commit comments

Comments
 (0)