Skip to content

Commit ca7848d

Browse files
Antti Kauppilabulislaw
authored andcommitted
Refactored away onboard_modem_api because it is not needed at all
All targets must implement soft_- and hard_power_on/off() functions which are practically same what onboard_modem_api offered. These were seen as a duplicate features and therefore we removed this. All targets involved have been updated to reflect the changes
1 parent 48cf631 commit ca7848d

File tree

34 files changed

+536
-917
lines changed

34 files changed

+536
-917
lines changed

features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
#include "onboard_modem_api.h"
1918
#include "QUECTEL_UG96.h"
2019
#include "QUECTEL_UG96_CellularContext.h"
2120
#include "AT_CellularNetwork.h"

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/TARGET_RIOT_MICRO_MODULE/ONBOARD_RM1000_AT.cpp

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@
1717
#if MBED_CONF_NSAPI_PRESENT
1818

1919
#include "ONBOARD_RM1000_AT.h"
20-
#include "cellular/onboard_modem_api.h"
2120
#include "UARTSerial.h"
2221

2322
#include "mbed-trace/mbed_trace.h"
2423
#ifndef TRACE_GROUP
2524
#define TRACE_GROUP "RIOTMICRO"
2625
#endif // TRACE_GROUP
2726

27+
#include "gpio_api.h"
28+
#include "PinNames.h"
29+
#include "hal/serial_api.h"
30+
#include "platform/mbed_thread.h"
31+
2832
using namespace mbed;
2933

3034
ONBOARD_RM1000_AT::ONBOARD_RM1000_AT(FileHandle *fh) : RM1000_AT(fh)
@@ -49,18 +53,89 @@ nsapi_error_t ONBOARD_RM1000_AT::soft_power_on()
4953
{
5054
tr_debug("Calling ONBOARD_RM1000_AT::soft_power_on");
5155

52-
::onboard_modem_init();
56+
onboard_modem_init();
5357
return NSAPI_ERROR_OK;
5458
}
5559

5660
nsapi_error_t ONBOARD_RM1000_AT::soft_power_off()
5761
{
5862
tr_debug("Calling ONBOARD_RM1000_AT::soft_power_off");
5963

60-
::onboard_modem_deinit();
64+
onboard_modem_deinit();
6165
return NSAPI_ERROR_OK;
6266
}
6367

68+
void ONBOARD_RM1000_AT::onboard_modem_init()
69+
{
70+
char promptEnd;
71+
72+
tr_debug("onboard_modem_init");
73+
74+
gpio_t gpio;
75+
76+
gpio_init_out_ex(&gpio, MDMCHEN, 0);
77+
gpio_init_out_ex(&gpio, MDMREMAP, 0);
78+
// Take us out of reset
79+
gpio_init_out_ex(&gpio, MDMRST, 0);
80+
thread_sleep_for(100);
81+
gpio_write(&gpio, 1);
82+
83+
/* Initialize UART1 pins to allow collecting logs from a PC */
84+
gpio_init_in_ex(&gpio, MDM_UART1_TXD, PullNone);
85+
gpio_init_in_ex(&gpio, MDM_UART1_RXD, PullNone);
86+
87+
serial_t bootrom_uart;
88+
serial_init(&bootrom_uart, MDM_UART0_TXD, MDM_UART0_RXD);
89+
serial_baud(&bootrom_uart, 115200);
90+
91+
tr_debug("%s: MODEM RESET", __func__);
92+
93+
serial_getc(&bootrom_uart);
94+
tr_debug("%s: MODEM first activity after reset", __func__);
95+
/* Wait for some dots */
96+
for (int i = 0; i < 3; i++) {
97+
do {
98+
promptEnd = serial_getc(&bootrom_uart);
99+
} while ('.' != promptEnd);
100+
}
101+
serial_putc(&bootrom_uart, ' ');
102+
/* Wait for bootrom prompt */
103+
for (int i = 0; i < 2; i++) {
104+
do {
105+
promptEnd = serial_getc(&bootrom_uart);
106+
} while ('>' != promptEnd);
107+
}
108+
serial_putc(&bootrom_uart, '6');
109+
serial_free(&bootrom_uart);
110+
111+
/* Wait for stack prompt */
112+
tr_debug("%s: Wait for stack prompt", __func__);
113+
thread_sleep_for(100);
114+
serial_t cli_uart;
115+
serial_init(&cli_uart, MDM_UART3_TXD, MDM_UART3_RXD);
116+
serial_baud(&cli_uart, 230400); /* TODO make baud rate configurable */
117+
118+
do {
119+
promptEnd = serial_getc(&cli_uart);
120+
} while ('>' != promptEnd);
121+
122+
serial_free(&cli_uart);
123+
124+
tr_debug("%s: MODEM CLI prompt reached", __func__);
125+
126+
tr_debug("Reset RM1000 completed");
127+
}
128+
129+
void ONBOARD_RM1000_AT::onboard_modem_deinit()
130+
{
131+
tr_debug("onboard_modem_deinit");
132+
133+
gpio_t gpio;
134+
135+
// Back into reset
136+
gpio_init_out_ex(&gpio, MDMRST, 0);
137+
}
138+
64139
CellularDevice *CellularDevice::get_target_default_instance()
65140
{
66141
tr_debug("Calling CellularDevice::get_target_default_instance from ONBOARD_RM1000_AT");

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/TARGET_RIOT_MICRO_MODULE/ONBOARD_RM1000_AT.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class ONBOARD_RM1000_AT : public RM1000_AT
3131
virtual nsapi_error_t hard_power_off();
3232
virtual nsapi_error_t soft_power_on();
3333
virtual nsapi_error_t soft_power_off();
34+
35+
private:
36+
void onboard_modem_init();
37+
38+
void onboard_modem_deinit();
3439
};
3540

3641
} // namespace mbed

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/TARGET_RIOT_MICRO_MODULE/onboard_modem_api.c

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

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_EP_AGORA/ONBOARD_TELIT_ME910.cpp

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@
1919

2020
#if EP_AGORA_ENABLE_CELL
2121

22-
#include "cellular/onboard_modem_api.h"
22+
#include "gpio_api.h"
23+
#include "platform/mbed_thread.h"
24+
#include "PinNames.h"
25+
2326
#include "UARTSerial.h"
2427
#include "ONBOARD_TELIT_ME910.h"
2528
#include "ThisThread.h"
2629
#include "CellularLog.h"
2730

31+
2832
using namespace mbed;
2933

3034
ONBOARD_TELIT_ME910::ONBOARD_TELIT_ME910(FileHandle *fh) : TELIT_ME910(fh, PIN_NAME_CELL_ON_OFF, true)
@@ -33,27 +37,27 @@ ONBOARD_TELIT_ME910::ONBOARD_TELIT_ME910(FileHandle *fh) : TELIT_ME910(fh, PIN_N
3337

3438
nsapi_error_t ONBOARD_TELIT_ME910::hard_power_on()
3539
{
36-
::onboard_modem_init();
40+
onboard_modem_init();
3741
return NSAPI_ERROR_OK;
3842
}
3943

4044
nsapi_error_t ONBOARD_TELIT_ME910::hard_power_off()
4145
{
42-
::onboard_modem_deinit();
46+
onboard_modem_deinit();
4347
return NSAPI_ERROR_OK;
4448
}
4549

4650
nsapi_error_t ONBOARD_TELIT_ME910::soft_power_on()
4751
{
48-
::onboard_modem_power_up();
52+
onboard_modem_power_up();
4953
// 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.
5054
rtos::ThisThread::sleep_for(200);
5155
return NSAPI_ERROR_OK;
5256
}
5357

5458
nsapi_error_t ONBOARD_TELIT_ME910::soft_power_off()
5559
{
56-
::onboard_modem_power_down();
60+
onboard_modem_power_down();
5761
return NSAPI_ERROR_OK;
5862
}
5963

@@ -122,6 +126,52 @@ nsapi_error_t ONBOARD_TELIT_ME910::init()
122126
return _at->unlock_return_error();
123127
}
124128

129+
void ONBOARD_TELIT_ME910::press_power_button(int time_ms)
130+
{
131+
gpio_t gpio;
132+
133+
gpio_init_out_ex(&gpio, PIN_NAME_CELL_ON_OFF, 1);
134+
gpio_write(&gpio, 0);
135+
thread_sleep_for(time_ms);
136+
gpio_write(&gpio, 1);
137+
}
138+
139+
void ONBOARD_TELIT_ME910::onboard_modem_init()
140+
{
141+
gpio_t gpio;
142+
143+
gpio_init_out_ex(&gpio, PIN_NAME_CELL_POWER_ENABLE, 0);
144+
gpio_write(&gpio, 1);
145+
}
146+
147+
void ONBOARD_TELIT_ME910::onboard_modem_deinit()
148+
{
149+
gpio_t gpio;
150+
151+
gpio_init_out_ex(&gpio, PIN_NAME_CELL_POWER_ENABLE, 1);
152+
gpio_write(&gpio, 0);
153+
}
154+
155+
void ONBOARD_TELIT_ME910::onboard_modem_power_up()
156+
{
157+
/* keep the power line low for 5 seconds */
158+
press_power_button(5000);
159+
/* give modem a little time to respond */
160+
thread_sleep_for(20 * 1000);
161+
}
162+
163+
void ONBOARD_TELIT_ME910::onboard_modem_power_down()
164+
{
165+
gpio_t gpio;
166+
167+
gpio_init_out_ex(&gpio, PIN_NAME_CELL_ON_OFF, 0);
168+
/* keep the power line low for more than 3 seconds.
169+
* If 3G_ON_OFF pin is kept low for more than a second, a controlled disconnect and shutdown takes
170+
* place, Due to the network disconnect, shut-off can take up to 30 seconds. However, we wait for 10
171+
* seconds only */
172+
thread_sleep_for(10 * 1000);
173+
}
174+
125175
CellularDevice *CellularDevice::get_target_default_instance()
126176
{
127177
static UARTSerial serial(MDMTXD, MDMRXD, 115200);

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_EP_AGORA/ONBOARD_TELIT_ME910.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ class ONBOARD_TELIT_ME910 : public TELIT_ME910 {
3131
virtual nsapi_error_t hard_power_off();
3232
virtual nsapi_error_t soft_power_on();
3333
virtual nsapi_error_t soft_power_off();
34+
35+
private:
36+
void press_power_button(int time_ms);
37+
38+
void onboard_modem_init();
39+
40+
void onboard_modem_deinit();
41+
42+
void onboard_modem_power_up();
43+
44+
void onboard_modem_power_down();
3445
};
3546

3647
} // namespace mbed

0 commit comments

Comments
 (0)