Skip to content

Commit d87c289

Browse files
Teppo Järvelinadbridge
authored andcommitted
Cellular: reduced stack size in cellular state machine thread. Release resource that are not needed in cellular state machine.
1 parent c99709e commit d87c289

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

features/cellular/easy_cellular/CellularConnectionFSM.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace mbed {
3939

4040
CellularConnectionFSM::CellularConnectionFSM() :
4141
_serial(0), _state(STATE_INIT), _next_state(_state), _status_callback(0), _network(0), _power(0), _sim(0),
42-
_queue(8 * EVENTS_EVENT_SIZE), _queue_thread(0), _retry_count(0), _state_retry_count(0), _at_queue(8 * EVENTS_EVENT_SIZE)
42+
_queue(8 * EVENTS_EVENT_SIZE), _queue_thread(0), _retry_count(0), _state_retry_count(0), _at_queue(2 * EVENTS_EVENT_SIZE)
4343
{
4444
memset(_sim_pin, 0, sizeof(_sim_pin));
4545
#if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0
@@ -60,7 +60,7 @@ CellularConnectionFSM::CellularConnectionFSM() :
6060
_retry_timeout_array[8] = 600;
6161
_retry_timeout_array[9] = TIMEOUT_NETWORK_MAX;
6262
_retry_array_length = MAX_RETRY_ARRAY_SIZE;
63-
63+
6464
_cellularDevice = new CELLULAR_DEVICE(_at_queue);
6565
}
6666

@@ -155,22 +155,6 @@ bool CellularConnectionFSM::open_sim()
155155
return state == CellularSIM::SimStateReady;
156156
}
157157

158-
void CellularConnectionFSM::device_ready()
159-
{
160-
CellularInformation *info = _cellularDevice->open_information(_serial);
161-
char device_info_buf[2048]; // may be up to 2048 according to 3GPP
162-
163-
if (info->get_manufacturer(device_info_buf, sizeof(device_info_buf)) == NSAPI_ERROR_OK) {
164-
tr_info("Cellular device manufacturer: %s", device_info_buf);
165-
}
166-
if (info->get_model(device_info_buf, sizeof(device_info_buf)) == NSAPI_ERROR_OK) {
167-
tr_info("Cellular device model: %s", device_info_buf);
168-
}
169-
if (info->get_revision(device_info_buf, sizeof(device_info_buf)) == NSAPI_ERROR_OK) {
170-
tr_info("Cellular device revision: %s", device_info_buf);
171-
}
172-
}
173-
174158
bool CellularConnectionFSM::set_network_registration(char *plmn)
175159
{
176160
if (_network->set_registration(plmn) != NSAPI_ERROR_OK) {
@@ -301,7 +285,9 @@ void CellularConnectionFSM::event()
301285
tr_info("Cellular device ready");
302286
_next_state = STATE_SIM_PIN;
303287
_retry_count = 0;
304-
device_ready();
288+
_cellularDevice->close_power();
289+
_power = NULL;
290+
305291
} else {
306292
tr_info("Waiting for cellular device (retry %d/%d, timeout %d ms)", _retry_count, RETRY_COUNT_DEFAULT,
307293
TIMEOUT_POWER_ON);
@@ -320,6 +306,8 @@ void CellularConnectionFSM::event()
320306
_next_state = STATE_REGISTERING_NETWORK;
321307
_retry_count = 0;
322308
_state_retry_count = 0;
309+
_cellularDevice->close_sim();
310+
_sim = NULL;
323311
tr_info("Check for network registration");
324312
} else {
325313
if (_retry_count++ <= RETRY_COUNT_DEFAULT) {
@@ -498,7 +486,7 @@ nsapi_error_t CellularConnectionFSM::start_dispatch()
498486

499487
MBED_ASSERT(!_queue_thread);
500488

501-
_queue_thread = new rtos::Thread;
489+
_queue_thread = new rtos::Thread(osPriorityNormal, 2048);
502490
if (!_queue_thread) {
503491
stop();
504492
return NSAPI_ERROR_NO_MEMORY;
@@ -517,6 +505,10 @@ void CellularConnectionFSM::stop()
517505
tr_info("CellularConnectionUtil::stop");
518506
_cellularDevice->close_power();
519507
_cellularDevice->close_network();
508+
_cellularDevice->close_sim();
509+
_power = NULL;
510+
_network = NULL;
511+
_sim = NULL;
520512
if (_queue_thread) {
521513
_queue_thread->terminate();
522514
_queue_thread = NULL;

features/cellular/easy_cellular/CellularConnectionFSM.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class CellularConnectionFSM
107107
*/
108108
CellularDevice* get_device();
109109

110-
/** Get cellular sim interface
110+
/** Get cellular sim interface. After SIM is open and ready (move from state STATE_SIM_PIN) SIM interface is closed to save resources.
111+
* After SIM interface is closed this method will return NULL and any instances got via this method before this are invalid.
111112
* @return sim interface, NULL on failure
112113
*/
113114
CellularSIM* get_sim();
@@ -144,7 +145,6 @@ class CellularConnectionFSM
144145
NetworkStack *get_stack();
145146

146147
private:
147-
void device_ready();
148148
void report_failure(const char* msg);
149149
void event();
150150

0 commit comments

Comments
 (0)