Skip to content

Commit ccbf005

Browse files
author
Hasnain Virk
committed
Introducing hal/modem_api.h
This provides a HAL layer for Modem bearing devices. Provides a standard interface to upper layer drivers. Platform providers will be implementing this API under their specific targets. As a reference, two implementations are provided under TARGET_C027 (UBLOX) and TARGET_MTS_DRAGONFLY_F411RE (MultiTech). targets.json now contains a tag "MODEM" which tells that this target has a modem and the modem_api is protected by a flag DEVICE_MODEM (following the DEVICE_SERIAL fashion ).
1 parent fcbcfaf commit ccbf005

File tree

6 files changed

+223
-2
lines changed

6 files changed

+223
-2
lines changed

hal/modem_api.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
17+
18+
#ifndef MODEM_API_H_
19+
#define MODEM_API_H_
20+
21+
/** modem_api is a standardizing API for Modem type devices under mbed-os.
22+
* It provides a simple hardware abstraction layer on top of the modem drivers
23+
* written for mbed-os.
24+
*
25+
* It is required from the engineers porting any modem type device (e.g., Cellular or Wifi)
26+
* to provide an implementation of this API in their respective target folder as well as
27+
* usage of standard PinNames (in PinNames.h) is highly encouraged. For example,
28+
*
29+
* MDMTXD = P0_15, // Transmit Data
30+
* MDMRXD = P0_16, // Receive Data
31+
* MDMCTS = P0_17, // Clear to Send
32+
* MDMDCD = P0_18, // Data Carrier Detect
33+
* MDMDSR = P0_19, // Data Set Ready
34+
* MDMDTR = P0_20, // Data Terminal Ready (set high or use handshake)
35+
* MDMRI = P0_21, // Ring Indicator
36+
* MDMRTS = P0_22, // Request to Send (set high or use handshake)
37+
*
38+
*/
39+
40+
#ifdef DEVICE_MODEM
41+
42+
typedef enum {
43+
POWER_READY=1,
44+
POWERED_ON,
45+
POWERED_OFF,
46+
LOWEST_POWER_STATE
47+
} modem_state;
48+
49+
/**
50+
* modem_s is defined in objects.h inside the TARGET folder
51+
*/
52+
typedef struct modem_s modem_t;
53+
54+
#ifdef __cplusplus
55+
extern "C" {
56+
#endif
57+
58+
/** Sets the modem up for powering on
59+
* modem_init() will be equivalent to plugging in the device, i.e.,
60+
* attaching power and serial port.
61+
*/
62+
void modem_init(modem_t *obj);
63+
64+
/** Sets the modem in unplugged state
65+
* modem_deinit() will be equivalent to pulling the plug off of the device, i.e.,
66+
* detaching power and serial port.
67+
* This puts the modem in lowest power state.
68+
*/
69+
void modem_deinit(modem_t *obj);
70+
71+
/** Powers up the modem
72+
* modem_power_up() will be equivalent to pressing the soft power button.
73+
* The driver may repeat this if the modem is not responsive to AT commands.
74+
75+
*/
76+
void modem_power_up(modem_t *obj);
77+
78+
/** Powers down the modem
79+
* modem_power_down() will be equivalent to turning off the modem by button press.
80+
*/
81+
void modem_power_down(modem_t *obj);
82+
83+
#ifdef __cplusplus
84+
}
85+
#endif
86+
87+
#endif /* DEVICE_MODEM*/
88+
#endif /* MODEM_API_H_ */
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
17+
#include "modem_api.h"
18+
#include "ublox_low_level_api.h"
19+
#include "gpio_api.h"
20+
#include "platform/mbed_wait_api.h"
21+
#include "PinNames.h"
22+
23+
#if DEVICE_MODEM
24+
static void press_power_button(int time_ms)
25+
{
26+
gpio_t gpio;
27+
28+
gpio_init_out_ex(&gpio, MDMPWRON, 0);
29+
wait_ms(time_ms);
30+
gpio_write(&gpio, 1);
31+
}
32+
33+
void modem_init(modem_t *obj)
34+
{
35+
//currently USB is not supported, so pass 0 to disable USB
36+
//This call does everything except actually pressing the power button
37+
ublox_mdm_powerOn(0);
38+
obj->state = POWER_READY;
39+
}
40+
41+
void modem_deinit(modem_t *obj)
42+
{
43+
ublox_mdm_powerOff();
44+
obj->state = LOWEST_POWER_STATE;
45+
}
46+
void modem_power_up(modem_t *obj)
47+
{
48+
/* keep the power line low for 150 milisecond */
49+
press_power_button(150);
50+
/* give modem a little time to respond */
51+
wait_ms(100);
52+
obj->state = POWERED_ON;
53+
}
54+
55+
void modem_power_down(modem_t *obj)
56+
{
57+
/* keep the power line low for 1 second */
58+
press_power_button(1000);
59+
obj->state = POWERED_OFF;
60+
}
61+
#endif //DEVICE_MODEM

targets/TARGET_NXP/TARGET_LPC176X/objects.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ struct spi_s {
7171
LPC_SSP_TypeDef *spi;
7272
};
7373

74+
struct modem_s {
75+
uint32_t state;
76+
};
77+
7478
#ifdef __cplusplus
7579
}
7680
#endif
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 "modem_api.h"
17+
#include "gpio_api.h"
18+
#include "platform/mbed_wait_api.h"
19+
#include "PinNames.h"
20+
21+
#if DEVICE_MODEM
22+
static void press_power_button(int time_ms)
23+
{
24+
gpio_t gpio;
25+
26+
gpio_init_out_ex(&gpio, MDMPWRON, 1);
27+
gpio_write(&gpio, 0);
28+
wait_ms(time_ms);
29+
gpio_write(&gpio, 1);
30+
}
31+
32+
void modem_init(modem_t *obj)
33+
{
34+
//does nothing at the moment, TODO: MultiTech to add hardware initialization stuff if needed
35+
obj->state = POWER_READY;
36+
}
37+
38+
void modem_deinit(modem_t *obj)
39+
{
40+
//does nothing at the moment, TODO: MultiTech to add hardware de-initialization stuff if needed
41+
obj->state = LOWEST_POWER_STATE;
42+
}
43+
void modem_power_up(modem_t *obj)
44+
{
45+
/* keep the power line low for 200 milisecond */
46+
press_power_button(200);
47+
/* give modem a little time to respond */
48+
wait_ms(100);
49+
obj->state = POWERED_ON;
50+
}
51+
52+
void modem_power_down(modem_t *obj)
53+
{
54+
gpio_t gpio;
55+
56+
gpio_init_out_ex(&gpio, MDMPWRON, 0);
57+
/* keep the power line low for more than 10 seconds.
58+
* If 3G_ON_OFF pin is kept low for more than a second, a controlled disconnect and shutdown takes
59+
* place, Due to the network disconnect, shut-off can take up to 30 seconds. However, we wait for 10
60+
* seconds only */
61+
wait_ms(10*1000);
62+
obj->state = POWERED_OFF;
63+
}
64+
#endif //DEVICE_MODEM

targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/objects.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ struct analogin_s {
6060
uint8_t channel;
6161
};
6262

63+
struct modem_s {
64+
uint32_t state;
65+
};
66+
6367
#include "common_objects.h"
6468

6569
#ifdef __cplusplus

targets/targets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@
251251
"extra_labels": ["NXP", "LPC176X", "FLASH_CMSIS_ALGO", "UBLOX_MODEM"],
252252
"macros": ["TARGET_LPC1768"],
253253
"inherits": ["LPCTarget"],
254-
"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"],
254+
"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", "MODEM"],
255255
"release_versions": ["2", "5"],
256256
"features": ["LWIP"],
257257
"device_name": "LPC1768"
@@ -1343,7 +1343,7 @@
13431343
"function": "MTSCode.combine_bins_mts_dragonfly",
13441344
"toolchains": ["GCC_ARM", "ARM_STD", "ARM_MICRO"]
13451345
},
1346-
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
1346+
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "MODEM"],
13471347
"release_versions": ["2", "5"],
13481348
"device_name": "STM32F411RE"
13491349
},

0 commit comments

Comments
 (0)