17
17
#if MBED_CONF_NSAPI_PRESENT
18
18
19
19
#include " gpio_api.h"
20
- #include " platform/mbed_wait_api.h"
21
20
#include " PinNames.h"
22
21
23
22
#include " drivers/BufferedSerial.h"
@@ -33,49 +32,93 @@ ONBOARD_TELIT_HE910::ONBOARD_TELIT_HE910(FileHandle *fh) : TELIT_HE910(fh)
33
32
34
33
nsapi_error_t ONBOARD_TELIT_HE910::hard_power_on ()
35
34
{
36
- // does nothing at the moment, TODO: MultiTech to add hardware initialization stuff if needed
35
+ power_up ();
37
36
return NSAPI_ERROR_OK;
38
37
}
39
38
40
39
nsapi_error_t ONBOARD_TELIT_HE910::hard_power_off ()
41
40
{
42
- // does nothing at the moment, TODO: MultiTech to add hardware de-initialization stuff if needed
41
+ power_down ();
43
42
return NSAPI_ERROR_OK;
44
43
}
45
44
46
45
nsapi_error_t ONBOARD_TELIT_HE910::soft_power_on ()
47
46
{
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 ();
53
49
// 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.
54
50
rtos::ThisThread::sleep_for (200 );
55
51
return NSAPI_ERROR_OK;
56
52
}
57
53
58
54
nsapi_error_t ONBOARD_TELIT_HE910::soft_power_off ()
59
55
{
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 ();
68
57
return NSAPI_ERROR_OK;
69
58
}
70
59
71
- void ONBOARD_TELIT_HE910::press_power_button (int time_ms )
60
+ void ONBOARD_TELIT_HE910::press_power_button ()
72
61
{
73
62
gpio_t gpio;
63
+ gpio_init_out_ex (&gpio, MDMPWRON, 0 );
64
+ }
74
65
66
+ void ONBOARD_TELIT_HE910::release_power_button ()
67
+ {
68
+ gpio_t gpio;
75
69
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--);
79
122
}
80
123
81
124
CellularDevice *CellularDevice::get_target_default_instance ()
0 commit comments