You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/10/08 19:47:47 UTC

[GitHub] andrzej-kaczmarek commented on a change in pull request #163: [WIP] Add support for Nordic RAAL

andrzej-kaczmarek commented on a change in pull request #163: [WIP] Add support for Nordic RAAL
URL: https://github.com/apache/mynewt-nimble/pull/163#discussion_r223477904
 
 

 ##########
 File path: nimble/controller/src/ble_ll_nrf_raal.c
 ##########
 @@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include "syscfg/syscfg.h"
+#include "hal/hal_timer.h"
+#include "controller/ble_ll.h"
+#include "controller/ble_ll_sched.h"
+
+#if MYNEWT_VAL(BLE_LL_NRF_RAAL_ENABLE)
+
+/*
+ * Number of ticks to add at the end of scheduled item to reconfigure radio
+ * after exiting from "external" slot.
+ */
+#define NRF_RAAL_SLOT_END_MARGIN_TICKS      (2)
+
+/* Scheduler item for granted slot */
+static struct ble_ll_sched_item g_ble_ll_nrf_raal_slot_sched;
+
+static struct hal_timer g_ble_ll_nrf_raal_slot_end_tmr;
+
+static int g_ble_ll_nrf_raal_continuous;
+
+/* XXX need locking? */
+static int g_ble_ll_nrf_raal_critical;
+
+#define BLE_LL_NRF_RAAL_PENDING_SLOT_ENTER      (0x01)
+#define BLE_LL_NRF_RAAL_PENDING_SLOT_EXIT       (0x02)
+
+static int g_ble_ll_nrf_raal_pending;
+
+extern void MYNEWT_VAL(BLE_LL_NRF_RAAL_ISR_HANDLER_NAME)(void);
+extern void nrf_raal_timeslot_started(void);
+extern void nrf_raal_timeslot_ended(void);
+
+static inline bool
+ble_ll_nrf_raal_slot_granted(void)
+{
+    return ble_ll_sched_get_current_type() == BLE_LL_SCHED_TYPE_NRF_RAAL;
+}
+
+static void
+ble_ll_nrf_raal_slot_schedule(void)
+{
+    struct ble_ll_sched_item *sch;
+    int rc;
+
+    sch = &g_ble_ll_nrf_raal_slot_sched;
+
+    if (!g_ble_ll_nrf_raal_continuous || sch->enqueued) {
+        return;
+    }
+
+    sch->start_time = os_cputime_get32();
+    sch->end_time = sch->start_time +
+                    ble_ll_usecs_to_ticks_round_up(MYNEWT_VAL(BLE_LL_NRF_RAAL_SLOT_LENGTH)) +
+                    NRF_RAAL_SLOT_END_MARGIN_TICKS;
+
+    rc = ble_ll_sched_nrf_raal(&g_ble_ll_nrf_raal_slot_sched);
+    assert(rc == 0);
+}
+
+static void
+ble_ll_nrf_raal_slot_enter(void)
+{
+    if (!g_ble_ll_nrf_raal_critical) {
+        nrf_raal_timeslot_started();
+        return;
+    }
+
+    /*
+     * No need to make enter pending if there was exit pending since we are
+     * still in slot (so basically we are still in slot).
+     */
+    if (g_ble_ll_nrf_raal_pending & BLE_LL_NRF_RAAL_PENDING_SLOT_EXIT) {
+        /*
+         * XXX is this legal? it means client was not notified that it was out
+         * of slot for some time... not yet sure what this means.
+         */
+        g_ble_ll_nrf_raal_pending = 0;
+    } else {
+        g_ble_ll_nrf_raal_pending |= BLE_LL_NRF_RAAL_PENDING_SLOT_ENTER;
+    }
+}
+
+static void
+ble_ll_nrf_raal_slot_exit(void)
+{
+    if (!g_ble_ll_nrf_raal_critical) {
+        nrf_raal_timeslot_ended();
+        return;
+    }
+
+    /*
+     * No need to make exit pending if there was enter pending since we are
+     * outside slot (so basically slot was missed).
+     */
+    if (g_ble_ll_nrf_raal_pending & BLE_LL_NRF_RAAL_PENDING_SLOT_ENTER) {
+        g_ble_ll_nrf_raal_pending = 0;
+    } else {
+        g_ble_ll_nrf_raal_pending |= BLE_LL_NRF_RAAL_PENDING_SLOT_EXIT;
+    }
+}
+
+static void
+ble_ll_nrf_raal_slot_end_tmr_cb(void *arg)
+{
+    ble_ll_nrf_raal_slot_exit();
+    ble_phy_nrf_raal_slot_exit();
+    /* XXX fixme :) */
 
 Review comment:
   I was not sure what to do with rfclk here (i.e. if we can just disable it) so left it as fixme to figure out this later

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services