Skip to content

Commit 7b5a8d3

Browse files
authored
Merge pull request #12966 from MultiTechSystems/update-df413-onoff
DRAGONFLY_F413RH: Update power on and power off functionality
2 parents ff024d2 + b8554a3 commit 7b5a8d3

File tree

2 files changed

+67
-21
lines changed

2 files changed

+67
-21
lines changed

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F413xH/TARGET_MTS_DRAGONFLY_F413RH/ONBOARD_TELIT_HE910.cpp

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#if MBED_CONF_NSAPI_PRESENT
1818

1919
#include "gpio_api.h"
20-
#include "platform/mbed_wait_api.h"
2120
#include "PinNames.h"
2221

2322
#include "drivers/BufferedSerial.h"
@@ -33,49 +32,93 @@ ONBOARD_TELIT_HE910::ONBOARD_TELIT_HE910(FileHandle *fh) : TELIT_HE910(fh)
3332

3433
nsapi_error_t ONBOARD_TELIT_HE910::hard_power_on()
3534
{
36-
//does nothing at the moment, TODO: MultiTech to add hardware initialization stuff if needed
35+
power_up();
3736
return NSAPI_ERROR_OK;
3837
}
3938

4039
nsapi_error_t ONBOARD_TELIT_HE910::hard_power_off()
4140
{
42-
//does nothing at the moment, TODO: MultiTech to add hardware de-initialization stuff if needed
41+
power_down();
4342
return NSAPI_ERROR_OK;
4443
}
4544

4645
nsapi_error_t ONBOARD_TELIT_HE910::soft_power_on()
4746
{
48-
49-
/* keep the power line low for 200 milisecond */
50-
press_power_button(200);
51-
/* give modem a little time to respond */
52-
rtos::ThisThread::sleep_for(100);
47+
power_down();
48+
power_up();
5349
// From Telit_xE910 Global form factor App note: It is mandatory to avoid sending data to the serial ports during the first 200ms of the module start-up.
5450
rtos::ThisThread::sleep_for(200);
5551
return NSAPI_ERROR_OK;
5652
}
5753

5854
nsapi_error_t ONBOARD_TELIT_HE910::soft_power_off()
5955
{
60-
gpio_t gpio;
61-
62-
gpio_init_out_ex(&gpio, MDMPWRON, 0);
63-
/* keep the power line low for more than 10 seconds.
64-
* If 3G_ON_OFF pin is kept low for more than a second, a controlled disconnect and shutdown takes
65-
* place, Due to the network disconnect, shut-off can take up to 30 seconds. However, we wait for 10
66-
* seconds only */
67-
rtos::ThisThread::sleep_for(10 * 1000);
56+
power_down();
6857
return NSAPI_ERROR_OK;
6958
}
7059

71-
void ONBOARD_TELIT_HE910::press_power_button(int time_ms)
60+
void ONBOARD_TELIT_HE910::press_power_button()
7261
{
7362
gpio_t gpio;
63+
gpio_init_out_ex(&gpio, MDMPWRON, 0);
64+
}
7465

66+
void ONBOARD_TELIT_HE910::release_power_button()
67+
{
68+
gpio_t gpio;
7569
gpio_init_out_ex(&gpio, MDMPWRON, 1);
76-
gpio_write(&gpio, 0);
77-
rtos::ThisThread::sleep_for(time_ms);
78-
gpio_write(&gpio, 1);
70+
}
71+
72+
// 1.8v from the radio should be high before exiting this function. Do nothing if it's already high.
73+
// Releasing MDMPWRON (going high) tells the tiny9 to turn the radio back on, assuming 1.8v was low.
74+
void ONBOARD_TELIT_HE910::power_up()
75+
{
76+
// Set up to read 1.8v from the radio.
77+
gpio_t radioOn;
78+
gpio_init_in(&radioOn, PC_5);
79+
80+
// Do nothing if it's already powered.
81+
if (gpio_read(&radioOn)) {
82+
return;
83+
}
84+
else {
85+
// power it up.
86+
release_power_button();
87+
}
88+
89+
// wait a max of 60s for 1.8v to go high.
90+
volatile int v1_8 = 0;
91+
uint8_t timeout = 60;
92+
do {
93+
rtos::ThisThread::sleep_for(1000);
94+
v1_8 = gpio_read(&radioOn);
95+
} while (!v1_8 && timeout--);
96+
97+
// The radio should be ready for commands after another 2s minimum.
98+
rtos::ThisThread::sleep_for(3000);
99+
}
100+
101+
void ONBOARD_TELIT_HE910::power_down()
102+
{
103+
gpio_t radioOn;
104+
gpio_init_in(&radioOn, PC_5);
105+
106+
// Do nothing if it's already off.
107+
if (!gpio_read(&radioOn)) {
108+
return;
109+
}
110+
else {
111+
// power down.
112+
press_power_button();
113+
}
114+
115+
// wait a max of 60s for 1.8v to go low.
116+
volatile int v1_8 = 1;
117+
uint8_t timeout = 60;
118+
do {
119+
rtos::ThisThread::sleep_for(1000);
120+
v1_8 = gpio_read(&radioOn);
121+
} while (v1_8 && timeout--);
79122
}
80123

81124
CellularDevice *CellularDevice::get_target_default_instance()

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F413xH/TARGET_MTS_DRAGONFLY_F413RH/ONBOARD_TELIT_HE910.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ class ONBOARD_TELIT_HE910 : public TELIT_HE910 {
3131
virtual nsapi_error_t soft_power_off();
3232

3333
private:
34-
void press_power_button(int time_ms);
34+
void press_power_button();
35+
void release_power_button();
36+
void power_up();
37+
void power_down();
3538
};
3639

3740
} // namespace mbed

0 commit comments

Comments
 (0)