drivers/nble: Use flags for state tracking

Using atomic flags instead of bool allows adding new states easily
without aditional memory footprint.

Change-Id: I0289a49af8353dc832a33e16ebdd6651c3913fe3
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
This commit is contained in:
Szymon Janc 2016-05-31 10:32:55 +02:00 committed by Johan Hedberg
parent 47d104530c
commit d2fa54d4a6
6 changed files with 12 additions and 4 deletions

View file

@ -419,7 +419,7 @@ static void notify_disconnected(struct bt_conn *conn)
* FIXME: When disconnected NBLE stops advertising, this should
* be fixed in the NBLE firmware, use this hack for now
*/
if (nble.keep_adv) {
if (atomic_test_bit(&nble.flags, NBLE_FLAG_KEEP_ADVERTISING)) {
BT_WARN("Re-enable advertising on disconnect");
nble_gap_start_adv_req();
}

View file

@ -217,7 +217,7 @@ void on_nble_gap_start_adv_rsp(const struct nble_common_rsp *rsp)
return;
}
nble.keep_adv = true;
atomic_set_bit(&nble.flags, NBLE_FLAG_KEEP_ADVERTISING);
BT_DBG("status %u", rsp->status);
}
@ -238,7 +238,7 @@ void on_nble_gap_stop_advertise_rsp(const struct nble_common_rsp *rsp)
return;
}
nble.keep_adv = false;
atomic_clear_bit(&nble.flags, NBLE_FLAG_KEEP_ADVERTISING);
BT_DBG("status %d", rsp->status);
}

View file

@ -583,11 +583,15 @@ void ble_gap_set_rssi_report(struct ble_rssi_report_params *par,
struct bt_conn *conn,
rssi_report_resp_t resp_cb, rssi_report_t evt_cb);
enum {
NBLE_FLAG_KEEP_ADVERTISING,
};
struct nble {
/* Local Bluetooth LE Device Address */
bt_addr_le_t addr;
const struct bt_conn_auth_cb *auth;
bool keep_adv;
atomic_t flags;
};
extern struct nble nble;

View file

@ -16,6 +16,7 @@
#include <stdlib.h>
#include <string.h>
#include <atomic.h>
#include <bluetooth/gatt.h>
/* for bt_security_t */

View file

@ -15,6 +15,7 @@
*/
#include <string.h>
#include <atomic.h>
#include <bluetooth/gatt.h>
#include <bluetooth/conn.h>

View file

@ -14,6 +14,8 @@
* limitations under the License.
*/
#include <atomic.h>
#include <bluetooth/gatt.h>
#include <bluetooth/conn.h>
#include <bluetooth/log.h>