Skip to content

BLE: replace malloc with cordio buffer allocation #8269

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

Merged
merged 8 commits into from
Oct 6, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "CordioPalGenericAccessService.h"
#include "ble/generic/GenericGap.h"
#include "ble/generic/GenericSecurityManager.h"
#include "ble/pal/SimpleEventQueue.h"
#include "SimpleEventQueue.h"

namespace ble {
namespace vendor {
Expand Down Expand Up @@ -152,7 +152,7 @@ class BLE : public ::BLEInstanceBase {
} initialization_status;

::BLE::InstanceID_t instanceID;
mutable pal::SimpleEventQueue _event_queue;
mutable SimpleEventQueue _event_queue;

class SigningEventMonitorProxy : public pal::SigningEventMonitor {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
#include "ble/BLE.h"

namespace ble {
namespace pal {
namespace vendor {
namespace cordio {

/**
* Simple implementation of the pal::EventQueue.
*/
struct SimpleEventQueue : EventQueue {
struct SimpleEventQueue : pal::EventQueue {

typedef mbed::Callback<void()> event_t;

Expand All @@ -51,7 +52,7 @@ struct SimpleEventQueue : EventQueue {
*
* @param ble_id Id of the BLE instance using that event queue.
*/
void initialize(BLEInstanceBase* ble_base, BLE::InstanceID_t ble_id)
void initialize(BLEInstanceBase* ble_base, ::BLE::InstanceID_t ble_id)
{
_ble_base = ble_base;
_ble_instance_id = ble_id;
Expand All @@ -73,8 +74,12 @@ struct SimpleEventQueue : EventQueue {
if (_ble_base == NULL) {
return false;
}

EventNode* next = new (std::nothrow) EventNode(event);
void* event_buf = WsfBufAlloc(sizeof(EventNode));
MBED_ASSERT(event_buf != NULL);
if (event_buf == NULL) {
return false;
}
EventNode* next = new(event_buf) EventNode(event);
if (next == NULL) {
return false;
}
Expand Down Expand Up @@ -102,7 +107,8 @@ struct SimpleEventQueue : EventQueue {
{
while (_events) {
EventNode* next = _events->next;
delete _events;
_events->~EventNode();
WsfBufFree(_events);
_events = next;
}
}
Expand All @@ -115,7 +121,8 @@ struct SimpleEventQueue : EventQueue {
while (_events) {
EventNode* next = _events->next;
_events->event();
delete _events;
_events->~EventNode();
WsfBufFree(_events);
_events = next;
}
}
Expand All @@ -133,11 +140,12 @@ struct SimpleEventQueue : EventQueue {
}

BLEInstanceBase* _ble_base;
BLE::InstanceID_t _ble_instance_id;
::BLE::InstanceID_t _ble_instance_id;
EventNode* _events;
};

} // namespace pal
} // namespace cordio
} // namespace vendor
} // namespace ble

#endif /* BLE_PAL_SIMPLE_EVENT_QUEUE_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
#include "ble/BLEInstanceBase.h"
#include "ble/generic/GenericGattClient.h"
#include "ble/generic/GenericSecurityManager.h"
#include "ble/pal/SimpleEventQueue.h"
#include "nRF5xPalSecurityManager.h"


#include "nRF5xGap.h"
#include "nRF5xGattServer.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "ble/BLEInstanceBase.h"
#include "ble/generic/GenericGattClient.h"
#include "ble/generic/GenericSecurityManager.h"
#include "ble/pal/SimpleEventQueue.h"
#include "nRF5xPalSecurityManager.h"

#include "nRF5xGap.h"
Expand Down