mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #12193 from kivaisan/move_event_thread_to_cellulardevice
Cellular: Move cellular event queue thread ownership to CellularDevicepull/12207/head
commit
2d3c4022ae
|
@ -35,6 +35,7 @@ set(unittest-test-sources
|
|||
stubs/CellularContext_stub.cpp
|
||||
stubs/ConditionVariable_stub.cpp
|
||||
stubs/Mutex_stub.cpp
|
||||
stubs/mbed_shared_queues_stub.cpp
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
|
|
|
@ -222,13 +222,6 @@ TEST_F(TestCellularStateMachine, test_start_dispatch)
|
|||
ASSERT_EQ(NSAPI_ERROR_OK, err);
|
||||
ut.delete_state_machine();
|
||||
|
||||
Thread_stub::osStatus_value = osErrorNoMemory;
|
||||
stm = ut.create_state_machine(*dev, *dev->get_queue(), *dev->open_network());
|
||||
EXPECT_TRUE(stm);
|
||||
err = ut.start_dispatch();
|
||||
ASSERT_EQ(NSAPI_ERROR_NO_MEMORY, err);
|
||||
ut.delete_state_machine();
|
||||
|
||||
delete dev;
|
||||
dev = NULL;
|
||||
}
|
||||
|
|
|
@ -21,10 +21,15 @@
|
|||
#include "CellularStateMachine.h"
|
||||
#include "Callback.h"
|
||||
#include "ATHandler.h"
|
||||
|
||||
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
|
||||
#include "UARTSerial.h"
|
||||
#endif // #if DEVICE_SERIAL
|
||||
|
||||
#ifdef MBED_CONF_RTOS_PRESENT
|
||||
#include "Thread.h"
|
||||
#endif // MBED_CONF_RTOS_PRESENT
|
||||
|
||||
/** @file CellularDevice.h
|
||||
* @brief Class CellularDevice
|
||||
*
|
||||
|
@ -504,6 +509,10 @@ private: //Member variables
|
|||
char _sim_pin[MAX_PIN_SIZE + 1];
|
||||
char _plmn[MAX_PLMN_SIZE + 1];
|
||||
PlatformMutex _mutex;
|
||||
|
||||
#ifdef MBED_CONF_RTOS_PRESENT
|
||||
rtos::Thread _queue_thread;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "CellularUtil.h"
|
||||
#include "CellularLog.h"
|
||||
#include "events/EventQueue.h"
|
||||
#include "mbed_shared_queues.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
|
@ -33,16 +34,28 @@ MBED_WEAK CellularDevice *CellularDevice::get_target_default_instance()
|
|||
return NULL;
|
||||
}
|
||||
|
||||
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0),
|
||||
CellularDevice::CellularDevice(FileHandle *fh) :
|
||||
_network_ref_count(0),
|
||||
#if MBED_CONF_CELLULAR_USE_SMS
|
||||
_sms_ref_count(0),
|
||||
#endif //MBED_CONF_CELLULAR_USE_SMS
|
||||
_info_ref_count(0), _fh(fh), _queue(10 * EVENTS_EVENT_SIZE), _state_machine(0),
|
||||
_status_cb(0), _nw(0)
|
||||
#ifdef MBED_CONF_RTOS_PRESENT
|
||||
, _queue_thread(osPriorityNormal, 2048, NULL, "cellular_queue")
|
||||
#endif // MBED_CONF_RTOS_PRESENT
|
||||
{
|
||||
MBED_ASSERT(fh);
|
||||
set_sim_pin(NULL);
|
||||
set_plmn(NULL);
|
||||
|
||||
#ifdef MBED_CONF_RTOS_PRESENT
|
||||
if (_queue_thread.start(callback(&_queue, &events::EventQueue::dispatch_forever)) != osOK) {
|
||||
tr_error("Failed to start thread");
|
||||
}
|
||||
#else
|
||||
_queue.chain(mbed_event_queue());
|
||||
#endif
|
||||
}
|
||||
|
||||
CellularDevice::~CellularDevice()
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
#include "CellularStateMachine.h"
|
||||
#include "CellularDevice.h"
|
||||
#include "CellularLog.h"
|
||||
#include "Thread.h"
|
||||
#include "mbed_shared_queues.h"
|
||||
|
||||
#ifndef MBED_TRACE_MAX_LEVEL
|
||||
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_INFO
|
||||
|
@ -51,9 +49,6 @@ const int DEVICE_READY = 0x04;
|
|||
namespace mbed {
|
||||
|
||||
CellularStateMachine::CellularStateMachine(CellularDevice &device, events::EventQueue &queue, CellularNetwork &nw) :
|
||||
#ifdef MBED_CONF_RTOS_PRESENT
|
||||
_queue_thread(0),
|
||||
#endif
|
||||
_cellularDevice(device), _state(STATE_INIT), _next_state(_state), _target_state(_state),
|
||||
_event_status_cb(0), _network(nw), _queue(queue), _sim_pin(0), _retry_count(0),
|
||||
_event_timeout(-1), _event_id(-1), _plmn(0), _command_success(false),
|
||||
|
@ -106,16 +101,6 @@ void CellularStateMachine::reset()
|
|||
void CellularStateMachine::stop()
|
||||
{
|
||||
tr_debug("CellularStateMachine stop");
|
||||
#ifdef MBED_CONF_RTOS_PRESENT
|
||||
if (_queue_thread) {
|
||||
_queue_thread->terminate();
|
||||
delete _queue_thread;
|
||||
_queue_thread = NULL;
|
||||
}
|
||||
#else
|
||||
_queue.chain(NULL);
|
||||
#endif
|
||||
|
||||
reset();
|
||||
_event_id = STM_STOPPED;
|
||||
}
|
||||
|
@ -643,24 +628,11 @@ void CellularStateMachine::event()
|
|||
|
||||
nsapi_error_t CellularStateMachine::start_dispatch()
|
||||
{
|
||||
#ifdef MBED_CONF_RTOS_PRESENT
|
||||
if (!_queue_thread) {
|
||||
_queue_thread = new rtos::Thread(osPriorityNormal, 2048, NULL, "stm_queue");
|
||||
_event_id = STM_STOPPED;
|
||||
if (_event_id != -1) {
|
||||
tr_warn("Canceling ongoing event (%d)", _event_id);
|
||||
_queue.cancel(_event_id);
|
||||
}
|
||||
|
||||
if (_event_id == STM_STOPPED) {
|
||||
if (_queue_thread->start(callback(&_queue, &events::EventQueue::dispatch_forever)) != osOK) {
|
||||
report_failure("Failed to start thread.");
|
||||
stop();
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
_event_id = -1;
|
||||
#else
|
||||
_queue.chain(mbed_event_queue());
|
||||
#endif
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,12 +22,6 @@
|
|||
#include "CellularCommon.h"
|
||||
#include "PlatformMutex.h"
|
||||
|
||||
#ifdef MBED_CONF_RTOS_PRESENT
|
||||
namespace rtos {
|
||||
class Thread;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace mbed {
|
||||
|
||||
class CellularDevice;
|
||||
|
@ -162,11 +156,6 @@ private:
|
|||
void change_timeout(const int &timeout);
|
||||
|
||||
private:
|
||||
|
||||
#ifdef MBED_CONF_RTOS_PRESENT
|
||||
rtos::Thread *_queue_thread;
|
||||
#endif
|
||||
|
||||
CellularDevice &_cellularDevice;
|
||||
CellularState _state;
|
||||
CellularState _next_state;
|
||||
|
|
Loading…
Reference in New Issue