Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cellular: Remove compile dependency of UARTSerial #10029

Merged
merged 1 commit into from Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions features/cellular/framework/API/CellularContext.h
Expand Up @@ -20,6 +20,7 @@
#include "CellularInterface.h"
#include "CellularDevice.h"
#include "ControlPlane_netif.h"
#include "PinNames.h"

/** @file CellularContext.h
* @brief Cellular PDP context class
Expand Down Expand Up @@ -261,6 +262,7 @@ class CellularContext : public CellularInterface {
*/
virtual void set_file_handle(FileHandle *fh) = 0;

#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
/** Set the UART serial used to communicate with the modem. Can be used to change default file handle.
* File handle set with this method will use data carrier detect to be able to detect disconnection much faster in PPP mode.
*
Expand All @@ -269,6 +271,7 @@ class CellularContext : public CellularInterface {
* @param active_high a boolean set to true if DCD polarity is active low
*/
virtual void set_file_handle(UARTSerial *serial, PinName dcd_pin = NC, bool active_high = false) = 0;
#endif // #if DEVICE_SERIAL

/** Returns the control plane AT command interface
*/
Expand Down
4 changes: 4 additions & 0 deletions features/cellular/framework/API/CellularDevice.h
Expand Up @@ -22,7 +22,9 @@
#include "CellularStateMachine.h"
#include "Callback.h"
#include "ATHandler.h"
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
#include "UARTSerial.h"
#endif // #if DEVICE_SERIAL

/** @file CellularDevice.h
* @brief Class CellularDevice
Expand Down Expand Up @@ -180,6 +182,7 @@ class CellularDevice {
*/
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL, bool cp_req = false, bool nonip_req = false) = 0;

#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
/** Creates a new CellularContext interface. This API should be used if serial is UART and PPP mode used.
* CellularContext created will use data carrier detect to be able to detect disconnection much faster in PPP mode.
* UARTSerial usually is the same which was given for the CellularDevice.
Expand All @@ -196,6 +199,7 @@ class CellularDevice {
*/
virtual CellularContext *create_context(UARTSerial *serial, const char *apn, PinName dcd_pin = NC,
bool active_high = false, bool cp_req = false, bool nonip_req = false) = 0;
#endif // #if DEVICE_SERIAL

/** Deletes the given CellularContext instance
*
Expand Down
6 changes: 6 additions & 0 deletions features/cellular/framework/AT/AT_CellularContext.cpp
Expand Up @@ -20,7 +20,9 @@
#include "AT_CellularStack.h"
#include "CellularLog.h"
#include "CellularUtil.h"
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
#include "UARTSerial.h"
#endif // #if DEVICE_SERIAL
#include "mbed_wait_api.h"

#define NETWORK_TIMEOUT 30 * 60 * 1000 // 30 minutes
Expand Down Expand Up @@ -89,6 +91,7 @@ void AT_CellularContext::set_file_handle(FileHandle *fh)
_at.set_file_handle(_fh);
}

#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
void AT_CellularContext::set_file_handle(UARTSerial *serial, PinName dcd_pin, bool active_high)
{
tr_info("CellularContext serial %p", serial);
Expand All @@ -98,11 +101,14 @@ void AT_CellularContext::set_file_handle(UARTSerial *serial, PinName dcd_pin, bo
_at.set_file_handle(static_cast<FileHandle *>(serial));
enable_hup(false);
}
#endif // #if DEVICE_SERIAL

void AT_CellularContext::enable_hup(bool enable)
{
if (_dcd_pin != NC) {
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
static_cast<UARTSerial *>(_fh)->set_data_carrier_detect(enable ? _dcd_pin : NC, _active_high);
#endif // #if DEVICE_SERIAL
}
}

Expand Down
2 changes: 2 additions & 0 deletions features/cellular/framework/AT/AT_CellularContext.h
Expand Up @@ -58,7 +58,9 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {
virtual nsapi_error_t register_to_network();
virtual nsapi_error_t attach_to_network();
virtual void set_file_handle(FileHandle *fh);
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
virtual void set_file_handle(UARTSerial *serial, PinName dcd_pin = NC, bool active_high = false);
#endif // #if DEVICE_SERIAL
virtual void enable_hup(bool enable);

virtual ControlPlane_netif *get_cp_netif();
Expand Down
4 changes: 4 additions & 0 deletions features/cellular/framework/AT/AT_CellularDevice.cpp
Expand Up @@ -24,7 +24,9 @@
#include "AT_CellularStack.h"
#include "CellularLog.h"
#include "ATHandler.h"
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
#include "UARTSerial.h"
#endif // #if DEVICE_SERIAL
#include "FileHandle.h"

using namespace mbed_cellular_util;
Expand Down Expand Up @@ -193,6 +195,7 @@ CellularContext *AT_CellularDevice::get_context_list() const
return _context_list;
}

#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
CellularContext *AT_CellularDevice::create_context(UARTSerial *serial, const char *const apn, PinName dcd_pin,
bool active_high, bool cp_req, bool nonip_req)
{
Expand All @@ -203,6 +206,7 @@ CellularContext *AT_CellularDevice::create_context(UARTSerial *serial, const cha
}
return ctx;
}
#endif // #if DEVICE_SERIAL

CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *apn, bool cp_req, bool nonip_req)
{
Expand Down
2 changes: 2 additions & 0 deletions features/cellular/framework/AT/AT_CellularDevice.h
Expand Up @@ -53,7 +53,9 @@ class AT_CellularDevice : public CellularDevice {

virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL, bool cp_req = false, bool nonip_req = false);

#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
virtual CellularContext *create_context(UARTSerial *serial, const char *const apn, PinName dcd_pin = NC, bool active_high = false, bool cp_req = false, bool nonip_req = false);
#endif // #if DEVICE_SERIAL

virtual void delete_context(CellularContext *context);

Expand Down
4 changes: 4 additions & 0 deletions features/cellular/framework/device/CellularContext.cpp
Expand Up @@ -31,9 +31,11 @@ MBED_WEAK CellularContext *CellularContext::get_default_instance()
}

static CellularContext *context = dev->create_context(NULL, NULL, MBED_CONF_CELLULAR_CONTROL_PLANE_OPT);
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
#if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
context->set_file_handle(static_cast<UARTSerial *>(&dev->get_file_handle()), MDMDCD, MDM_PIN_POLARITY);
#endif // #if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
#endif // #if DEVICE_SERIAL
return context;
}

Expand All @@ -46,9 +48,11 @@ MBED_WEAK CellularContext *CellularContext::get_default_nonip_instance()
}

static CellularContext *context = dev->create_context(NULL, NULL, MBED_CONF_CELLULAR_CONTROL_PLANE_OPT, true);
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
#if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
context->set_file_handle(static_cast<UARTSerial *>(&dev->get_file_handle()), MDMDCD, MDM_PIN_POLARITY);
#endif // #if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
#endif // #if DEVICE_SERIAL
return context;
}

Expand Down
Expand Up @@ -19,7 +19,6 @@
#include "CellularDevice.h"
#include "CellularLog.h"
#include "Thread.h"
#include "UARTSerial.h"

#ifndef MBED_TRACE_MAX_LEVEL
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_INFO
Expand Down