You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2016/10/10 20:41:47 UTC
[1/2] incubator-mynewt-core git commit: MYNEWT-431: Move cputime from
HAL into os.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop fda3dd6f3 -> ac2d49e31
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/net/nimble/transport/uart/src/ble_hci_uart.c
----------------------------------------------------------------------
diff --git a/net/nimble/transport/uart/src/ble_hci_uart.c b/net/nimble/transport/uart/src/ble_hci_uart.c
index 8ec1431..9ea54be 100755
--- a/net/nimble/transport/uart/src/ble_hci_uart.c
+++ b/net/nimble/transport/uart/src/ble_hci_uart.c
@@ -21,12 +21,13 @@
#include <string.h>
#include <stdio.h>
#include <errno.h>
+#include <stdint.h>
+#include "os/os_cputime.h"
#include "syscfg/syscfg.h"
#include "bsp/bsp.h"
#include "os/os.h"
#include "util/mem.h"
#include "hal/hal_gpio.h"
-#include "hal/hal_cputime.h"
#include "hal/hal_uart.h"
/* BLE */
[2/2] incubator-mynewt-core git commit: MYNEWT-431: Move cputime from
HAL into os.
Posted by we...@apache.org.
MYNEWT-431: Move cputime from HAL into os.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ac2d49e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ac2d49e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ac2d49e3
Branch: refs/heads/develop
Commit: ac2d49e31c49ddfe0b107862b4504364f32736df
Parents: fda3dd6
Author: William San Filippo <wi...@runtime.io>
Authored: Mon Oct 10 13:37:56 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Mon Oct 10 13:38:49 2016 -0700
----------------------------------------------------------------------
apps/bleprph/src/main.c | 1 -
apps/bletest/src/main.c | 1 -
apps/bletiny/src/main.c | 1 -
apps/bleuart/src/main.c | 1 -
hw/bsp/arduino_primo_nrf52/src/os_bsp.c | 6 +-
hw/bsp/arduino_primo_nrf52/syscfg.yml | 4 +
hw/bsp/bmd300eval/src/os_bsp.c | 6 +-
hw/bsp/bmd300eval/syscfg.yml | 4 +
hw/bsp/nrf51-arduino_101/src/os_bsp.c | 5 +-
hw/bsp/nrf51-arduino_101/syscfg.yml | 6 +-
hw/bsp/nrf51-blenano/src/os_bsp.c | 5 +-
hw/bsp/nrf51-blenano/syscfg.yml | 6 +-
hw/bsp/nrf51dk-16kbram/src/os_bsp.c | 5 +-
hw/bsp/nrf51dk-16kbram/syscfg.yml | 6 +-
hw/bsp/nrf51dk/src/os_bsp.c | 5 +-
hw/bsp/nrf51dk/syscfg.yml | 6 +-
hw/bsp/nrf52dk/src/os_bsp.c | 6 +-
hw/bsp/nrf52dk/syscfg.yml | 6 +-
hw/drivers/nimble/nrf51/src/ble_phy.c | 6 +-
hw/drivers/nimble/nrf52/src/ble_phy.c | 6 +-
hw/drivers/uart/uart_bitbang/src/uart_bitbang.c | 36 +--
hw/mcu/nordic/nrf51xxx/src/hal_cputime.c | 295 -------------------
hw/mcu/nordic/nrf52xxx/src/hal_cputime.c | 288 ------------------
kernel/os/include/os/os_cputime.h | 205 +++++++++++++
kernel/os/src/os_cputime.c | 270 +++++++++++++++++
kernel/os/syscfg.yml | 3 +
.../controller/include/controller/ble_ll.h | 4 +-
.../controller/include/controller/ble_ll_conn.h | 4 +-
.../controller/include/controller/ble_ll_scan.h | 4 +-
net/nimble/controller/src/ble_ll.c | 12 +-
net/nimble/controller/src/ble_ll_adv.c | 26 +-
net/nimble/controller/src/ble_ll_conn.c | 46 +--
net/nimble/controller/src/ble_ll_ctrl.c | 4 +-
net/nimble/controller/src/ble_ll_scan.c | 24 +-
net/nimble/controller/src/ble_ll_sched.c | 62 ++--
net/nimble/controller/src/ble_ll_whitelist.c | 1 -
net/nimble/transport/uart/src/ble_hci_uart.c | 3 +-
37 files changed, 651 insertions(+), 728 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index b096868..321b7cb 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -26,7 +26,6 @@
#include "os/os.h"
#include "bsp/bsp.h"
#include "hal/hal_gpio.h"
-#include "hal/hal_cputime.h"
#include "console/console.h"
#include "imgmgr/imgmgr.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index 34f57b1..f626c2b 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -24,7 +24,6 @@
#include "bsp/bsp.h"
#include "hal/hal_bsp.h"
#include "hal/hal_gpio.h"
-#include "hal/hal_cputime.h"
#include "hal/hal_flash.h"
#include "console/console.h"
#include "shell/shell.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index e6788c7..4491137 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -29,7 +29,6 @@
#include "os/os.h"
#include "bsp/bsp.h"
#include "hal/hal_gpio.h"
-#include "hal/hal_cputime.h"
#include "console/console.h"
#include "shell/shell.h"
#include "bletiny.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/apps/bleuart/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleuart/src/main.c b/apps/bleuart/src/main.c
index f6d75f0..932f1fc 100755
--- a/apps/bleuart/src/main.c
+++ b/apps/bleuart/src/main.c
@@ -26,7 +26,6 @@
#include "os/os.h"
#include "bsp/bsp.h"
#include "hal/hal_gpio.h"
-#include "hal/hal_cputime.h"
#include <imgmgr/imgmgr.h>
/* BLE */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/bsp/arduino_primo_nrf52/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/arduino_primo_nrf52/src/os_bsp.c b/hw/bsp/arduino_primo_nrf52/src/os_bsp.c
index 1cd0f1e..f12523d 100644
--- a/hw/bsp/arduino_primo_nrf52/src/os_bsp.c
+++ b/hw/bsp/arduino_primo_nrf52/src/os_bsp.c
@@ -18,11 +18,11 @@
*/
#include <assert.h>
-
+#include <stdint.h>
+#include "os/os_cputime.h"
#include "syscfg/syscfg.h"
#include "flash_map/flash_map.h"
#include "hal/hal_bsp.h"
-#include "hal/hal_cputime.h"
#include "hal/hal_flash.h"
#include "hal/hal_spi.h"
#include "hal/hal_watchdog.h"
@@ -92,7 +92,7 @@ bsp_init(void)
#endif
/* Set cputime to count at 1 usec increments */
- rc = cputime_init(MYNEWT_VAL(CLOCK_FREQ));
+ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ));
assert(rc == 0);
#if MYNEWT_VAL(SPI_MASTER)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/bsp/arduino_primo_nrf52/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/arduino_primo_nrf52/syscfg.yml b/hw/bsp/arduino_primo_nrf52/syscfg.yml
index e6faa8d..8f2c137 100644
--- a/hw/bsp/arduino_primo_nrf52/syscfg.yml
+++ b/hw/bsp/arduino_primo_nrf52/syscfg.yml
@@ -9,6 +9,10 @@ syscfg.defs:
description: 'TBD'
value: 1000000
+ OS_CPUTIME_TIMER_NUM:
+ description: 'Timer to use for cputime'
+ value: 0
+
XTAL_32768:
description: 'TBD'
value: 1
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/bsp/bmd300eval/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/src/os_bsp.c b/hw/bsp/bmd300eval/src/os_bsp.c
index a72baff..f94def3 100644
--- a/hw/bsp/bmd300eval/src/os_bsp.c
+++ b/hw/bsp/bmd300eval/src/os_bsp.c
@@ -18,11 +18,11 @@
*/
#include <assert.h>
-
+#include <stdint.h>
+#include "os/os_cputime.h"
#include "syscfg/syscfg.h"
#include "flash_map/flash_map.h"
#include "hal/hal_bsp.h"
-#include "hal/hal_cputime.h"
#include "hal/hal_flash.h"
#include "hal/hal_spi.h"
#include "mcu/nrf52_hal.h"
@@ -89,7 +89,7 @@ bsp_init(void)
#endif
/* Set cputime to count at 1 usec increments */
- rc = cputime_init(MYNEWT_VAL(CLOCK_FREQ));
+ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ));
assert(rc == 0);
#if MYNEWT_VAL(SPI_MASTER)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/bsp/bmd300eval/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/syscfg.yml b/hw/bsp/bmd300eval/syscfg.yml
index 5fa72b4..0014c75 100644
--- a/hw/bsp/bmd300eval/syscfg.yml
+++ b/hw/bsp/bmd300eval/syscfg.yml
@@ -9,6 +9,10 @@ syscfg.defs:
description: 'TBD'
value: 1000000
+ OS_CPUTIME_TIMER_NUM:
+ description: 'Timer to use for cputime'
+ value: 0
+
XTAL_32768:
description: 'TBD'
value: 1
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/bsp/nrf51-arduino_101/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-arduino_101/src/os_bsp.c b/hw/bsp/nrf51-arduino_101/src/os_bsp.c
index 7effdd2..905e0b7 100644
--- a/hw/bsp/nrf51-arduino_101/src/os_bsp.c
+++ b/hw/bsp/nrf51-arduino_101/src/os_bsp.c
@@ -17,6 +17,8 @@
* under the License.
*/
#include <assert.h>
+#include <stdint.h>
+#include "os/os_cputime.h"
#include "syscfg/syscfg.h"
#include "flash_map/flash_map.h"
#include "hal/hal_flash.h"
@@ -28,7 +30,6 @@
#include "os/os_dev.h"
#include "uart/uart.h"
#include "uart_hal/uart_hal.h"
-#include "hal/hal_cputime.h"
#define BSP_LOWEST_PRIO ((1 << __NVIC_PRIO_BITS) - 1)
@@ -55,7 +56,7 @@ bsp_init(void)
#endif
/* Set cputime to count at 1 usec increments */
- rc = cputime_init(MYNEWT_VAL(CLOCK_FREQ));
+ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ));
assert(rc == 0);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/bsp/nrf51-arduino_101/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-arduino_101/syscfg.yml b/hw/bsp/nrf51-arduino_101/syscfg.yml
index 9e86176..30cc04e 100644
--- a/hw/bsp/nrf51-arduino_101/syscfg.yml
+++ b/hw/bsp/nrf51-arduino_101/syscfg.yml
@@ -9,6 +9,10 @@ syscfg.defs:
description: 'TBD'
value: 1000000
+ OS_CPUTIME_TIMER_NUM:
+ description: 'Timer to use for cputime'
+ value: 0
+
XTAL_32768:
description: 'TBD'
value: 1
@@ -48,7 +52,7 @@ syscfg.defs:
TIMER_0:
description: 'NRF51 Timer 0'
- value: 0
+ value: 1
TIMER_0_INTERRUPT_PRIORITY:
description: 'TBD'
value: '((1 << __NVIC_PRIO_BITS) - 1)'
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/bsp/nrf51-blenano/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/src/os_bsp.c b/hw/bsp/nrf51-blenano/src/os_bsp.c
index 15d5d37..cc5cc24 100644
--- a/hw/bsp/nrf51-blenano/src/os_bsp.c
+++ b/hw/bsp/nrf51-blenano/src/os_bsp.c
@@ -17,12 +17,13 @@
* under the License.
*/
#include <assert.h>
+#include <stdint.h>
+#include "os/os_cputime.h"
#include "syscfg/syscfg.h"
#include "flash_map/flash_map.h"
#include "hal/hal_flash.h"
#include "hal/hal_bsp.h"
#include "hal/hal_spi.h"
-#include "hal/hal_cputime.h"
#include "mcu/nrf51_hal.h"
#if MYNEWT_VAL(SPI_MASTER)
#include "nrf_drv_spi.h"
@@ -68,7 +69,7 @@ bsp_init(void)
#endif
/* Set cputime to count at 1 usec increments */
- rc = cputime_init(MYNEWT_VAL(CLOCK_FREQ));
+ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ));
assert(rc == 0);
#if MYNEWT_VAL(SPI_MASTER)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/bsp/nrf51-blenano/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/syscfg.yml b/hw/bsp/nrf51-blenano/syscfg.yml
index 71528ef..8467d21 100644
--- a/hw/bsp/nrf51-blenano/syscfg.yml
+++ b/hw/bsp/nrf51-blenano/syscfg.yml
@@ -9,6 +9,10 @@ syscfg.defs:
description: 'TBD'
value: 1000000
+ OS_CPUTIME_TIMER_NUM:
+ description: 'Timer to use for cputime'
+ value: 0
+
XTAL_32768:
description: 'TBD'
value: 1
@@ -45,7 +49,7 @@ syscfg.defs:
TIMER_0:
description: 'NRF51 Timer 0'
- value: 0
+ value: 1
TIMER_0_INTERRUPT_PRIORITY:
description: 'TBD'
value: '((1 << __NVIC_PRIO_BITS) - 1)'
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/src/os_bsp.c b/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
index a1e56e4..2637d14 100644
--- a/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
+++ b/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
@@ -17,13 +17,14 @@
* under the License.
*/
#include <assert.h>
+#include <stdint.h>
+#include "os/os_cputime.h"
#include "syscfg/syscfg.h"
#include "bsp.h"
#include "flash_map/flash_map.h"
#include "hal/hal_flash.h"
#include "hal/hal_bsp.h"
#include "hal/hal_spi.h"
-#include "hal/hal_cputime.h"
#include "mcu/nrf51_hal.h"
#if MYNEWT_VAL(SPI_MASTER)
#include "nrf_drv_spi.h"
@@ -69,7 +70,7 @@ bsp_init(void)
#endif
/* Set cputime to count at 1 usec increments */
- rc = cputime_init(MYNEWT_VAL(CLOCK_FREQ));
+ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ));
assert(rc == 0);
#if MYNEWT_VAL(SPI_MASTER)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/bsp/nrf51dk-16kbram/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/syscfg.yml b/hw/bsp/nrf51dk-16kbram/syscfg.yml
index 7090137..3a04798 100644
--- a/hw/bsp/nrf51dk-16kbram/syscfg.yml
+++ b/hw/bsp/nrf51dk-16kbram/syscfg.yml
@@ -9,6 +9,10 @@ syscfg.defs:
description: 'TBD'
value: 1000000
+ OS_CPUTIME_TIMER_NUM:
+ description: 'Timer to use for cputime'
+ value: 0
+
XTAL_32768:
description: 'TBD'
value: 1
@@ -45,7 +49,7 @@ syscfg.defs:
TIMER_0:
description: 'NRF51 Timer 0'
- value: 0
+ value: 1
TIMER_0_INTERRUPT_PRIORITY:
description: 'TBD'
value: '((1 << __NVIC_PRIO_BITS) - 1)'
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/bsp/nrf51dk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/src/os_bsp.c b/hw/bsp/nrf51dk/src/os_bsp.c
index a1e56e4..2434abf 100644
--- a/hw/bsp/nrf51dk/src/os_bsp.c
+++ b/hw/bsp/nrf51dk/src/os_bsp.c
@@ -17,13 +17,14 @@
* under the License.
*/
#include <assert.h>
+#include <stdint.h>
#include "syscfg/syscfg.h"
+#include "os/os_cputime.h"
#include "bsp.h"
#include "flash_map/flash_map.h"
#include "hal/hal_flash.h"
#include "hal/hal_bsp.h"
#include "hal/hal_spi.h"
-#include "hal/hal_cputime.h"
#include "mcu/nrf51_hal.h"
#if MYNEWT_VAL(SPI_MASTER)
#include "nrf_drv_spi.h"
@@ -69,7 +70,7 @@ bsp_init(void)
#endif
/* Set cputime to count at 1 usec increments */
- rc = cputime_init(MYNEWT_VAL(CLOCK_FREQ));
+ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ));
assert(rc == 0);
#if MYNEWT_VAL(SPI_MASTER)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/bsp/nrf51dk/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/syscfg.yml b/hw/bsp/nrf51dk/syscfg.yml
index 4ae23a1..9ad1ffc 100644
--- a/hw/bsp/nrf51dk/syscfg.yml
+++ b/hw/bsp/nrf51dk/syscfg.yml
@@ -9,6 +9,10 @@ syscfg.defs:
description: 'TBD'
value: 1000000
+ OS_CPUTIME_TIMER_NUM:
+ description: 'Timer to use for cputime'
+ value: 0
+
XTAL_32768:
description: 'TBD'
value: 1
@@ -45,7 +49,7 @@ syscfg.defs:
TIMER_0:
description: 'NRF51 Timer 0'
- value: 0
+ value: 1
TIMER_0_INTERRUPT_PRIORITY:
description: 'TBD'
value: '((1 << __NVIC_PRIO_BITS) - 1)'
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/bsp/nrf52dk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/src/os_bsp.c b/hw/bsp/nrf52dk/src/os_bsp.c
index 44afde9..2fabff4 100644
--- a/hw/bsp/nrf52dk/src/os_bsp.c
+++ b/hw/bsp/nrf52dk/src/os_bsp.c
@@ -18,12 +18,12 @@
*/
#include <assert.h>
-
+#include <stdint.h>
+#include "os/os_cputime.h"
#include "syscfg/syscfg.h"
#include "sysflash/sysflash.h"
#include "flash_map/flash_map.h"
#include "hal/hal_bsp.h"
-#include "hal/hal_cputime.h"
#include "hal/hal_flash.h"
#include "hal/hal_spi.h"
#include "hal/hal_watchdog.h"
@@ -90,7 +90,7 @@ bsp_init(void)
#endif
/* Set cputime to count at 1 usec increments */
- rc = cputime_init(MYNEWT_VAL(CLOCK_FREQ));
+ rc = os_cputime_init(MYNEWT_VAL(CLOCK_FREQ));
assert(rc == 0);
#if MYNEWT_VAL(SPI_MASTER)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/bsp/nrf52dk/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/syscfg.yml b/hw/bsp/nrf52dk/syscfg.yml
index 1454549..0fb2ad8 100644
--- a/hw/bsp/nrf52dk/syscfg.yml
+++ b/hw/bsp/nrf52dk/syscfg.yml
@@ -9,6 +9,10 @@ syscfg.defs:
description: 'TBD'
value: 1000000
+ OS_CPUTIME_TIMER_NUM:
+ description: 'Timer to use for cputime'
+ value: 0
+
XTAL_32768:
description: 'TBD'
value: 1
@@ -54,7 +58,7 @@ syscfg.defs:
TIMER_0:
description: 'NRF52 Timer 0'
- value: 0
+ value: 1
TIMER_0_INTERRUPT_PRIORITY:
description: 'TBD'
value: '((1 << __NVIC_PRIO_BITS) - 1)'
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/drivers/nimble/nrf51/src/ble_phy.c
----------------------------------------------------------------------
diff --git a/hw/drivers/nimble/nrf51/src/ble_phy.c b/hw/drivers/nimble/nrf51/src/ble_phy.c
index b8d2f6b..45507ea 100644
--- a/hw/drivers/nimble/nrf51/src/ble_phy.c
+++ b/hw/drivers/nimble/nrf51/src/ble_phy.c
@@ -427,7 +427,7 @@ ble_phy_tx_end_isr(void)
}
wfr_time = txstart - BLE_TX_LEN_USECS_M(NRF_RX_START_OFFSET);
wfr_time += BLE_TX_DUR_USECS_M(txlen);
- wfr_time += cputime_usecs_to_ticks(BLE_LL_WFR_USECS);
+ wfr_time += os_cputime_usecs_to_ticks(BLE_LL_WFR_USECS);
ble_ll_wfr_enable(wfr_time);
} else {
/* Disable automatic TXEN */
@@ -825,7 +825,7 @@ ble_phy_tx_set_start_time(uint32_t cputime)
NRF_TIMER0->CC[0] = cputime;
NRF_PPI->CHENSET = PPI_CHEN_CH20_Msk;
NRF_PPI->CHENCLR = PPI_CHEN_CH21_Msk;
- if ((int32_t)(cputime_get32() - cputime) >= 0) {
+ if ((int32_t)(os_cputime_get32() - cputime) >= 0) {
STATS_INC(ble_phy_stats, tx_late);
ble_phy_disable();
rc = BLE_PHY_ERR_TX_LATE;
@@ -856,7 +856,7 @@ ble_phy_rx_set_start_time(uint32_t cputime)
NRF_TIMER0->CC[0] = cputime;
NRF_PPI->CHENCLR = PPI_CHEN_CH20_Msk;
NRF_PPI->CHENSET = PPI_CHEN_CH21_Msk;
- if ((int32_t)(cputime_get32() - cputime) >= 0) {
+ if ((int32_t)(os_cputime_get32() - cputime) >= 0) {
STATS_INC(ble_phy_stats, rx_late);
NRF_PPI->CHENCLR = PPI_CHEN_CH21_Msk;
NRF_RADIO->TASKS_RXEN = 1;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/drivers/nimble/nrf52/src/ble_phy.c
----------------------------------------------------------------------
diff --git a/hw/drivers/nimble/nrf52/src/ble_phy.c b/hw/drivers/nimble/nrf52/src/ble_phy.c
index 6498a06..7707b2d 100644
--- a/hw/drivers/nimble/nrf52/src/ble_phy.c
+++ b/hw/drivers/nimble/nrf52/src/ble_phy.c
@@ -418,7 +418,7 @@ ble_phy_tx_end_isr(void)
}
wfr_time = txstart - BLE_TX_LEN_USECS_M(NRF_RX_START_OFFSET);
wfr_time += BLE_TX_DUR_USECS_M(txlen);
- wfr_time += cputime_usecs_to_ticks(BLE_LL_WFR_USECS);
+ wfr_time += os_cputime_usecs_to_ticks(BLE_LL_WFR_USECS);
ble_ll_wfr_enable(wfr_time);
} else {
/* Disable automatic TXEN */
@@ -806,7 +806,7 @@ ble_phy_tx_set_start_time(uint32_t cputime)
NRF_TIMER0->CC[0] = cputime;
NRF_PPI->CHENSET = PPI_CHEN_CH20_Msk;
NRF_PPI->CHENCLR = PPI_CHEN_CH21_Msk;
- if ((int32_t)(cputime_get32() - cputime) >= 0) {
+ if ((int32_t)(os_cputime_get32() - cputime) >= 0) {
STATS_INC(ble_phy_stats, tx_late);
ble_phy_disable();
rc = BLE_PHY_ERR_TX_LATE;
@@ -837,7 +837,7 @@ ble_phy_rx_set_start_time(uint32_t cputime)
NRF_TIMER0->CC[0] = cputime;
NRF_PPI->CHENCLR = PPI_CHEN_CH20_Msk;
NRF_PPI->CHENSET = PPI_CHEN_CH21_Msk;
- if ((int32_t)(cputime_get32() - cputime) >= 0) {
+ if ((int32_t)(os_cputime_get32() - cputime) >= 0) {
STATS_INC(ble_phy_stats, rx_late);
NRF_PPI->CHENCLR = PPI_CHEN_CH21_Msk;
NRF_RADIO->TASKS_RXEN = 1;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/drivers/uart/uart_bitbang/src/uart_bitbang.c
----------------------------------------------------------------------
diff --git a/hw/drivers/uart/uart_bitbang/src/uart_bitbang.c b/hw/drivers/uart/uart_bitbang/src/uart_bitbang.c
index c20682e..175989d 100644
--- a/hw/drivers/uart/uart_bitbang/src/uart_bitbang.c
+++ b/hw/drivers/uart/uart_bitbang/src/uart_bitbang.c
@@ -23,11 +23,11 @@
#include <hal/hal_gpio.h>
#include <hal/hal_uart.h>
-#include <hal/hal_cputime.h>
+#include <hal/hal_timer.h>
#include <os/os.h>
#include <os/os_dev.h>
-
+#include <os/os_cputime.h>
#include <uart/uart.h>
#include "uart_bitbang/uart_bitbang.h"
@@ -41,7 +41,7 @@ struct uart_bitbang {
int ub_bittime; /* number of cputimer ticks per bit */
struct {
int pin; /* RX pin */
- struct cpu_timer timer;
+ struct hal_timer timer;
uint32_t start; /* cputime when byte rx started */
uint8_t byte; /* receiving this byte */
uint8_t bits; /* how many bits we've seen */
@@ -49,7 +49,7 @@ struct uart_bitbang {
} ub_rx;
struct {
int pin; /* TX pin */
- struct cpu_timer timer;
+ struct hal_timer timer;
uint32_t start; /* cputime when byte tx started */
uint8_t byte; /* byte being transmitted */
uint8_t bits; /* how many bits have been sent */
@@ -93,7 +93,7 @@ uart_bitbang_tx_timer(void *arg)
* Start bit
*/
hal_gpio_write(ub->ub_tx.pin, 0);
- ub->ub_tx.start = cputime_get32();
+ ub->ub_tx.start = os_cputime_get32();
next = ub->ub_tx.start + ub->ub_bittime;
ub->ub_txing = 1;
ub->ub_tx.bits = 0;
@@ -110,7 +110,7 @@ uart_bitbang_tx_timer(void *arg)
next = ub->ub_tx.start + (ub->ub_bittime * 10);
}
}
- cputime_timer_start(&ub->ub_tx.timer, next);
+ os_cputime_timer_start(&ub->ub_tx.timer, next);
}
static void
@@ -139,7 +139,7 @@ uart_bitbang_rx_timer(void *arg)
}
} else {
ub->ub_rx.bits++;
- cputime_timer_start(&ub->ub_rx.timer,
+ os_cputime_timer_start(&ub->ub_rx.timer,
ub->ub_rx.start + (ub->ub_bittime * (ub->ub_rx.bits + 1)) +
(ub->ub_bittime >> 1));
}
@@ -155,7 +155,7 @@ uart_bitbang_isr(void *arg)
struct uart_bitbang *ub = (struct uart_bitbang *)arg;
uint32_t time;
- time = cputime_get32();
+ time = os_cputime_get32();
if (ub->ub_rx.start - time < (9 * ub->ub_bittime)) {
++ub->ub_rx.false_irq;
return;
@@ -168,8 +168,8 @@ uart_bitbang_isr(void *arg)
* We try to sample in the middle of a bit. First sample is taken
* 1.5 bittimes after beginning of start bit.
*/
- cputime_timer_start(&ub->ub_rx.timer, time +
- ub->ub_bittime + (ub->ub_bittime >> 1));
+ os_cputime_timer_start(&ub->ub_rx.timer, time +
+ ub->ub_bittime + (ub->ub_bittime >> 1));
hal_gpio_irq_disable(ub->ub_rx.pin);
}
@@ -186,18 +186,18 @@ uart_bitbang_blocking_tx(struct uart_dev *dev, uint8_t data)
return;
}
hal_gpio_write(ub->ub_tx.pin, 0);
- start = cputime_get32();
+ start = os_cputime_get32();
next = start + ub->ub_bittime;
- while (cputime_get32() < next);
+ while (os_cputime_get32() < next);
for (i = 0; i < 8; i++) {
hal_gpio_write(ub->ub_tx.pin, data & 0x01);
data = data >> 1;
next = start + (ub->ub_bittime * i + 1);
- while (cputime_get32() < next);
+ while (os_cputime_get32() < next);
}
next = start + (ub->ub_bittime * 10);
hal_gpio_write(ub->ub_tx.pin, 1);
- while (cputime_get32() < next);
+ while (os_cputime_get32() < next);
}
static void
@@ -257,8 +257,8 @@ uart_bitbang_config(struct uart_bitbang *ub, int32_t baudrate, uint8_t databits,
}
ub->ub_bittime = ub->ub_cputimer_freq / baudrate;
- cputime_timer_init(&ub->ub_rx.timer, uart_bitbang_rx_timer, ub);
- cputime_timer_init(&ub->ub_tx.timer, uart_bitbang_tx_timer, ub);
+ os_cputime_timer_init(&ub->ub_rx.timer, uart_bitbang_rx_timer, ub);
+ os_cputime_timer_init(&ub->ub_tx.timer, uart_bitbang_tx_timer, ub);
if (hal_gpio_init_out(ub->ub_tx.pin, 1)) {
return -1;
@@ -310,8 +310,8 @@ uart_bitbang_close(struct os_dev *odev)
ub->ub_open = 0;
ub->ub_txing = 0;
ub->ub_rx_stall = 0;
- cputime_timer_stop(&ub->ub_tx.timer);
- cputime_timer_stop(&ub->ub_rx.timer);
+ os_cputime_timer_stop(&ub->ub_tx.timer);
+ os_cputime_timer_stop(&ub->ub_rx.timer);
OS_EXIT_CRITICAL(sr);
return OS_OK;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/mcu/nordic/nrf51xxx/src/hal_cputime.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_cputime.c b/hw/mcu/nordic/nrf51xxx/src/hal_cputime.c
deleted file mode 100644
index 2925697..0000000
--- a/hw/mcu/nordic/nrf51xxx/src/hal_cputime.c
+++ /dev/null
@@ -1,295 +0,0 @@
-/**
- * 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 <string.h>
-#include <stdint.h>
-#include <assert.h>
-#include "bsp/cmsis_nvic.h"
-#include "hal/hal_cputime.h"
-#include "nrf51.h"
-#include "nrf51_bitfields.h"
-#include "mcu/nrf51_hal.h"
-
-/* Maximum timer frequency */
-#define NRF51_MAX_TIMER_FREQ (16000000)
-
-#undef HAL_CPUTIME_USE_OVERFLOW
-
-/* The RF peripheral uses CC registers 0 and 1 for RF events. */
-#define CPUTIMER NRF_TIMER0
-#define CPUTIMER_IRQ (TIMER0_IRQn)
-#define CPUTIMER_CC_CNTR (2)
-#ifdef HAL_CPUTIME_USE_OVERFLOW
-#define CPUTIMER_CC_OVERFLOW (2)
-#endif
-#define CPUTIMER_CC_INT (3)
-
-/* Interrupt mask for interrupt enable/clear */
-#define CPUTIMER_INT_MASK(x) ((1 << (uint32_t)(x)) << 16)
-
-/* XXX:
- * - Must determine how to set priority of cpu timer interrupt
- * - Determine if we should use a mutex as opposed to disabling interrupts
- * - Should I use macro for compare channel?
- * - Sync to OSTIME.
- */
-
-void
-cputime_disable_ocmp(void)
-{
- CPUTIMER->INTENCLR = CPUTIMER_INT_MASK(CPUTIMER_CC_INT);
-}
-
-/**
- * cputime set ocmp
- *
- * Set the OCMP used by the cputime module to the desired cputime.
- *
- * NOTE: Must be called with interrupts disabled.
- *
- * @param timer Pointer to timer.
- */
-void
-cputime_set_ocmp(struct cpu_timer *timer)
-{
- /* Disable ocmp interrupt and set new value */
- cputime_disable_ocmp();
-
- /* Set output compare register to timer expiration */
- CPUTIMER->CC[CPUTIMER_CC_INT] = timer->cputime;
-
- /* Clear interrupt flag*/
- CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_INT] = 0;
-
- /* Enable the output compare interrupt */
- CPUTIMER->INTENSET = CPUTIMER_INT_MASK(CPUTIMER_CC_INT);
-
- /* Force interrupt to occur as we may have missed it */
- if ((int32_t)(cputime_get32() - timer->cputime) >= 0) {
- NVIC_SetPendingIRQ(CPUTIMER_IRQ);
- }
-}
-
-/**
- * cputime isr
- *
- * This is the global timer interrupt routine.
- *
- */
-static void
-cputime_isr(void)
-{
- uint32_t compare;
-#ifdef HAL_CPUTIME_USE_OVERFLOW
- uint32_t overflow;
-#endif
-
- /* Check interrupt source. If set, clear them */
- compare = CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_INT];
- if (compare) {
- CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_INT] = 0;
- }
-
-#ifdef HAL_CPUTIME_USE_OVERFLOW
- overflow = CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_OVERFLOW];
- if (overflow) {
- CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_OVERFLOW] = 0;
- ++g_cputime.uif_ints;
- ++g_cputime.cputime_high;
- }
-#endif
-
- /* Count # of interrupts */
- ++g_cputime.timer_isrs;
-
- /*
- * NOTE: we dont check the 'compare' variable here due to how the timer
- * is implemented on this chip. There is no way to force an output
- * compare, so if we are late setting the output compare (i.e. the timer
- * counter is already passed the output compare value), we use the NVIC
- * to set a pending interrupt. This means that there will be no compare
- * flag set, so all we do is check to see if the compare interrupt is
- * enabled.
- */
- if (CPUTIMER->INTENCLR & CPUTIMER_INT_MASK(CPUTIMER_CC_INT)) {
- ++g_cputime.ocmp_ints;
- cputime_chk_expiration();
-
- /* XXX: Recommended by nordic to make sure interrupts are cleared */
- compare = CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_INT];
- }
-}
-
-/**
- * cputime init
- *
- * Initialize the cputime module. This must be called after os_init is called
- * and before any other timer API are used. This should be called only once
- * and should be called before the hardware timer is used.
- *
- * @param clock_freq The desired cputime frequency, in hertz (Hz).
- *
- * @return int 0 on success; -1 on error.
- */
-int
-cputime_hw_init(uint32_t clock_freq)
-{
- uint32_t ctx;
- uint32_t max_freq;
- uint32_t pre_scaler;
-
-#if defined(HAL_CPUTIME_1MHZ)
- if (clock_freq != 1000000) {
- return -1;
- }
-#endif
-
- /* Clock frequency must be at least 1 MHz */
- if (clock_freq < 1000000U) {
- return -1;
- }
-
- /* Check if clock frequency exceeds max. range */
- max_freq = NRF51_MAX_TIMER_FREQ;
- if (clock_freq > max_freq) {
- return -1;
- }
-
- /* Is this exact frequency obtainable? */
- pre_scaler = max_freq / clock_freq;
- if ((pre_scaler * clock_freq) != max_freq) {
- return -1;
- }
-
- /*
- * Pre-scaler is 4 bits and is a 2^n, so the only possible values that
- * work are 1, 2, 4, 8 and 16, which gives a valid pre-scaler of 0, 1, 2,
- * 3 or 4.
- */
- switch (pre_scaler) {
- case 1:
- pre_scaler = 0;
- break;
- case 2:
- pre_scaler = 1;
- break;
- case 4:
- pre_scaler = 2;
- break;
- case 8:
- pre_scaler = 3;
- break;
- case 16:
- pre_scaler = 4;
- break;
- default:
- pre_scaler = 0xFFFFFFFF;
- break;
- }
-
- if (pre_scaler == 0xFFFFFFFF) {
- return -1;
- }
-
- /* disable interrupts */
- __HAL_DISABLE_INTERRUPTS(ctx);
-
- /* Set the clock frequency */
- g_cputime.ticks_per_usec = clock_freq / 1000000U;
-
- /* XXX: no way to halt the timer in debug mode that I can see */
-
- /* Stop the timer first */
- CPUTIMER->TASKS_STOP = 1;
-
- /* Put the timer in timer mode using 32 bits. */
- CPUTIMER->MODE = TIMER_MODE_MODE_Timer;
- CPUTIMER->BITMODE = TIMER_BITMODE_BITMODE_32Bit;
-
- /* Set the pre-scaler*/
- CPUTIMER->PRESCALER = pre_scaler;
-
- /* Start the timer */
- CPUTIMER->TASKS_START = 1;
-
- /* Use an output compare to generate an overflow */
-#ifdef HAL_CPUTIME_USE_OVERFLOW
- CPUTIMER->CC[CPUTIMER_CC_OVERFLOW] = 0;
- CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_OVERFLOW] = 0;
- CPUTIMER->INTENSET = CPUTIMER_INT_MASK(CPUTIMER_CC_OVERFLOW);
-#endif
-
- /* Set isr in vector table and enable interrupt */
- NVIC_SetVector(CPUTIMER_IRQ, (uint32_t)cputime_isr);
- NVIC_EnableIRQ(CPUTIMER_IRQ);
-
- __HAL_ENABLE_INTERRUPTS(ctx);
-
- return 0;
-}
-
-/**
- * cputime get64
- *
- * Returns cputime as a 64-bit number.
- *
- * @return uint64_t The 64-bit representation of cputime.
- */
-#ifdef HAL_CPUTIME_USE_OVERFLOW
-uint64_t
-cputime_get64(void)
-{
- uint32_t ctx;
- uint32_t high;
- uint32_t low;
- uint64_t cpu_time;
-
- __HAL_DISABLE_INTERRUPTS(ctx);
- high = g_cputime.cputime_high;
- low = cputime_get32();
- if (CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_OVERFLOW]) {
- ++high;
- low = cputime_get32();
- }
- __HAL_ENABLE_INTERRUPTS(ctx);
-
- cpu_time = ((uint64_t)high << 32) | low;
-
- return cpu_time;
-}
-#endif
-
-/**
- * cputime get32
- *
- * Returns the low 32 bits of cputime.
- *
- * @return uint32_t The lower 32 bits of cputime
- */
-uint32_t
-cputime_get32(void)
-{
- uint32_t cpu_time;
-
- /* Force a capture of the timer into 'cntr' capture channel; read it */
- CPUTIMER->TASKS_CAPTURE[CPUTIMER_CC_CNTR] = 1;
- cpu_time = CPUTIMER->CC[CPUTIMER_CC_CNTR];
-
- return cpu_time;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/hw/mcu/nordic/nrf52xxx/src/hal_cputime.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_cputime.c b/hw/mcu/nordic/nrf52xxx/src/hal_cputime.c
deleted file mode 100644
index 5beba20..0000000
--- a/hw/mcu/nordic/nrf52xxx/src/hal_cputime.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/**
- * 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 <string.h>
-#include <stdint.h>
-#include <assert.h>
-#include "bsp/cmsis_nvic.h"
-#include "hal/hal_cputime.h"
-#include "nrf52.h"
-#include "nrf52_bitfields.h"
-#include "mcu/nrf52_hal.h"
-
-/* Maximum timer frequency */
-#define NRF52_MAX_TIMER_FREQ (16000000)
-
-#undef HAL_CPUTIME_USE_OVERFLOW
-
-/* The RF peripheral uses CC registers 0 and 1 for RF events. */
-#define CPUTIMER NRF_TIMER0
-#define CPUTIMER_IRQ (TIMER0_IRQn)
-#define CPUTIMER_CC_CNTR (2)
-#ifdef HAL_CPUTIME_USE_OVERFLOW
-#define CPUTIMER_CC_OVERFLOW (2)
-#endif
-#define CPUTIMER_CC_INT (3)
-
-/* Interrupt mask for interrupt enable/clear */
-#define CPUTIMER_INT_MASK(x) ((1 << (uint32_t)(x)) << 16)
-
-/* Disable output compare used for cputimer */
-void
-cputime_disable_ocmp(void)
-{
- CPUTIMER->INTENCLR = CPUTIMER_INT_MASK(CPUTIMER_CC_INT);
-}
-
-/**
- * cputime set ocmp
- *
- * Set the OCMP used by the cputime module to the desired cputime.
- *
- * NOTE: Must be called with interrupts disabled.
- *
- * @param timer Pointer to timer.
- */
-void
-cputime_set_ocmp(struct cpu_timer *timer)
-{
- /* Disable ocmp interrupt and set new value */
- CPUTIMER->INTENCLR = CPUTIMER_INT_MASK(CPUTIMER_CC_INT);
-
- /* Set output compare register to timer expiration */
- CPUTIMER->CC[CPUTIMER_CC_INT] = timer->cputime;
-
- /* Clear interrupt flag*/
- CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_INT] = 0;
-
- /* Enable the output compare interrupt */
- CPUTIMER->INTENSET = CPUTIMER_INT_MASK(CPUTIMER_CC_INT);
-
- /* Force interrupt to occur as we may have missed it */
- if ((int32_t)(cputime_get32() - timer->cputime) >= 0) {
- NVIC_SetPendingIRQ(CPUTIMER_IRQ);
- }
-}
-
-/**
- * cputime isr
- *
- * This is the global timer interrupt routine.
- *
- */
-static void
-cputime_isr(void)
-{
- uint32_t compare;
-#ifdef HAL_CPUTIME_USE_OVERFLOW
- uint32_t overflow;
-#endif
-
- /* Check interrupt source. If set, clear them */
- compare = CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_INT];
- if (compare) {
- CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_INT] = 0;
- }
-
-#ifdef HAL_CPUTIME_USE_OVERFLOW
- overflow = CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_OVERFLOW];
- if (overflow) {
- CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_OVERFLOW] = 0;
- ++g_cputime.uif_ints;
- ++g_cputime.cputime_high;
- }
-#endif
-
- /* Count # of interrupts */
- ++g_cputime.timer_isrs;
-
- /*
- * NOTE: we dont check the 'compare' variable here due to how the timer
- * is implemented on this chip. There is no way to force an output
- * compare, so if we are late setting the output compare (i.e. the timer
- * counter is already passed the output compare value), we use the NVIC
- * to set a pending interrupt. This means that there will be no compare
- * flag set, so all we do is check to see if the compare interrupt is
- * enabled.
- */
- if (CPUTIMER->INTENCLR & CPUTIMER_INT_MASK(CPUTIMER_CC_INT)) {
- ++g_cputime.ocmp_ints;
- cputime_chk_expiration();
-
- /* XXX: Recommended by nordic to make sure interrupts are cleared */
- compare = CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_INT];
- }
-}
-
-/**
- * cputime hw init
- *
- * Initialize the cputime hw. This should be called only once and should be
- * called before the hardware timer is used.
- *
- * @param clock_freq The desired cputime frequency, in hertz (Hz).
- *
- * @return int 0 on success; -1 on error.
- */
-int
-cputime_hw_init(uint32_t clock_freq)
-{
- uint32_t ctx;
- uint32_t max_freq;
- uint32_t pre_scaler;
-
-#if defined(HAL_CPUTIME_1MHZ)
- if (clock_freq != 1000000) {
- return -1;
- }
-#endif
-
- /* Clock frequency must be at least 1 MHz */
- if (clock_freq < 1000000U) {
- return -1;
- }
-
- /* Check if clock frequency exceeds max. range */
- max_freq = NRF52_MAX_TIMER_FREQ;
- if (clock_freq > max_freq) {
- return -1;
- }
-
- /* Is this exact frequency obtainable? */
- pre_scaler = max_freq / clock_freq;
- if ((pre_scaler * clock_freq) != max_freq) {
- return -1;
- }
-
- /*
- * Pre-scaler is 4 bits and is a 2^n, so the only possible values that
- * work are 1, 2, 4, 8 and 16, which gives a valid pre-scaler of 0, 1, 2,
- * 3 or 4.
- */
- switch (pre_scaler) {
- case 1:
- pre_scaler = 0;
- break;
- case 2:
- pre_scaler = 1;
- break;
- case 4:
- pre_scaler = 2;
- break;
- case 8:
- pre_scaler = 3;
- break;
- case 16:
- pre_scaler = 4;
- break;
- default:
- pre_scaler = 0xFFFFFFFF;
- break;
- }
-
- if (pre_scaler == 0xFFFFFFFF) {
- return -1;
- }
-
- /* disable interrupts */
- __HAL_DISABLE_INTERRUPTS(ctx);
-
- /* Set the clock frequency */
- g_cputime.ticks_per_usec = clock_freq / 1000000U;
-
- /* XXX: no way to halt the timer in debug mode that I can see */
-
- /* Stop the timer first */
- CPUTIMER->TASKS_STOP = 1;
-
- /* Put the timer in timer mode using 32 bits. */
- CPUTIMER->MODE = TIMER_MODE_MODE_Timer;
- CPUTIMER->BITMODE = TIMER_BITMODE_BITMODE_32Bit;
-
- /* Set the pre-scaler*/
- CPUTIMER->PRESCALER = pre_scaler;
-
- /* Start the timer */
- CPUTIMER->TASKS_START = 1;
-
- /* Use an output compare to generate an overflow */
-#ifdef HAL_CPUTIME_USE_OVERFLOW
- CPUTIMER->CC[CPUTIMER_CC_OVERFLOW] = 0;
- CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_OVERFLOW] = 0;
- CPUTIMER->INTENSET = CPUTIMER_INT_MASK(CPUTIMER_CC_OVERFLOW);
-#endif
-
- /* Set isr in vector table and enable interrupt */
- NVIC_SetVector(CPUTIMER_IRQ, (uint32_t)cputime_isr);
- NVIC_EnableIRQ(CPUTIMER_IRQ);
-
- __HAL_ENABLE_INTERRUPTS(ctx);
-
- return 0;
-}
-
-/**
- * cputime get64
- *
- * Returns cputime as a 64-bit number.
- *
- * @return uint64_t The 64-bit representation of cputime.
- */
-#ifdef HAL_CPUTIME_USE_OVERFLOW
-uint64_t
-cputime_get64(void)
-{
- uint32_t ctx;
- uint32_t high;
- uint32_t low;
- uint64_t cpu_time;
-
- __HAL_DISABLE_INTERRUPTS(ctx);
- high = g_cputime.cputime_high;
- low = cputime_get32();
- if (CPUTIMER->EVENTS_COMPARE[CPUTIMER_CC_OVERFLOW]) {
- ++high;
- low = cputime_get32();
- }
- __HAL_ENABLE_INTERRUPTS(ctx);
-
- cpu_time = ((uint64_t)high << 32) | low;
-
- return cpu_time;
-}
-#endif
-
-/**
- * cputime get32
- *
- * Returns the low 32 bits of cputime.
- *
- * @return uint32_t The lower 32 bits of cputime
- */
-uint32_t
-cputime_get32(void)
-{
- uint32_t cpu_time;
-
- /* Force a capture of the timer into 'cntr' capture channel; read it */
- CPUTIMER->TASKS_CAPTURE[CPUTIMER_CC_CNTR] = 1;
- cpu_time = CPUTIMER->CC[CPUTIMER_CC_CNTR];
-
- return cpu_time;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/kernel/os/include/os/os_cputime.h
----------------------------------------------------------------------
diff --git a/kernel/os/include/os/os_cputime.h b/kernel/os/include/os/os_cputime.h
new file mode 100644
index 0000000..89fb6ad
--- /dev/null
+++ b/kernel/os/include/os/os_cputime.h
@@ -0,0 +1,205 @@
+/**
+ * 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.
+ */
+
+#ifndef H_OS_CPUTIME_
+#define H_OS_CPUTIME_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "syscfg/syscfg.h"
+#include "os/queue.h"
+#include "hal/hal_timer.h"
+
+/*
+ * NOTE: these definitions allow one to override the cputime frequency used.
+ * The reason these definitions exist is to make the code more efficient/smaller
+ * when CPUTIME counts at 1 MHz.
+ *
+ * For those who want a different cputime frequency, you can set the config
+ * definition for OS_CPUTIME_FREQ to the desired frequency in your project,
+ * target or bsp.
+ */
+#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 0)
+#error "cputime frequency cannot be 0!"
+#endif
+
+#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 1000000)
+#define OS_CPUTIME_FREQ_1MHZ
+#endif
+
+/* CPUTIME data. */
+struct os_cputime_data
+{
+ uint32_t ticks_per_usec; /* number of ticks per usec */
+};
+extern struct os_cputime_data g_cputime;
+
+/* Helpful macros to compare cputimes */
+#define CPUTIME_LT(__t1, __t2) ((int32_t) ((__t1) - (__t2)) < 0)
+#define CPUTIME_GT(__t1, __t2) ((int32_t) ((__t1) - (__t2)) > 0)
+#define CPUTIME_GEQ(__t1, __t2) ((int32_t) ((__t1) - (__t2)) >= 0)
+#define CPUTIME_LEQ(__t1, __t2) ((int32_t) ((__t1) - (__t2)) <= 0)
+
+/**
+ * os cputime init
+ *
+ * Initialize the cputime module. This must be called after os_init is called
+ * and before any other timer API are used. This should be called only once
+ * and should be called before the hardware timer is used.
+ *
+ * @param clock_freq The desired cputime frequency, in hertz (Hz).
+ *
+ * @return int 0 on success; -1 on error.
+ */
+int os_cputime_init(uint32_t clock_freq);
+
+/**
+ * os cputime get32
+ *
+ * Returns the low 32 bits of cputime.
+ *
+ * @return uint32_t The lower 32 bits of cputime
+ */
+uint32_t os_cputime_get32(void);
+
+/**
+ * os cputime nsecs to ticks
+ *
+ * Converts the given number of nanoseconds into cputime ticks.
+ *
+ * @param usecs The number of nanoseconds to convert to ticks
+ *
+ * @return uint32_t The number of ticks corresponding to 'nsecs'
+ */
+uint32_t os_cputime_nsecs_to_ticks(uint32_t nsecs);
+
+/**
+ * os cputime ticks to nsecs
+ *
+ * Convert the given number of ticks into nanoseconds.
+ *
+ * @param ticks The number of ticks to convert to nanoseconds.
+ *
+ * @return uint32_t The number of nanoseconds corresponding to 'ticks'
+ */
+uint32_t os_cputime_ticks_to_nsecs(uint32_t ticks);
+
+#if defined(OS_CPUTIME_FREQ_1MHZ)
+#define os_cputime_usecs_to_ticks(x) (x)
+#define os_cputime_ticks_to_usecs(x) (x)
+#else
+/**
+ * os cputime usecs to ticks
+ *
+ * Converts the given number of microseconds into cputime ticks.
+ *
+ * @param usecs The number of microseconds to convert to ticks
+ *
+ * @return uint32_t The number of ticks corresponding to 'usecs'
+ */
+uint32_t os_cputime_usecs_to_ticks(uint32_t usecs);
+
+/**
+ * os cputime ticks to usecs
+ *
+ * Convert the given number of ticks into microseconds.
+ *
+ * @param ticks The number of ticks to convert to microseconds.
+ *
+ * @return uint32_t The number of microseconds corresponding to 'ticks'
+ */
+uint32_t os_cputime_ticks_to_usecs(uint32_t ticks);
+#endif
+
+/**
+ * os cputime delay ticks
+ *
+ * Wait until the number of ticks has elapsed. This is a blocking delay.
+ *
+ * @param ticks The number of ticks to wait.
+ */
+void os_cputime_delay_ticks(uint32_t ticks);
+
+/**
+ * os cputime delay nsecs
+ *
+ * Wait until 'nsecs' nanoseconds has elapsed. This is a blocking delay.
+ *
+ * @param nsecs The number of nanoseconds to wait.
+ */
+void os_cputime_delay_nsecs(uint32_t nsecs);
+
+/**
+ * os cputime delay usecs
+ *
+ * Wait until 'usecs' microseconds has elapsed. This is a blocking delay.
+ *
+ * @param usecs The number of usecs to wait.
+ */
+void os_cputime_delay_usecs(uint32_t usecs);
+
+/**
+ * os cputime timer init
+ *
+ * @param timer The timer to initialize. Cannot be NULL.
+ * @param fp The timer callback function. Cannot be NULL.
+ * @param arg Pointer to data object to pass to timer.
+ */
+void os_cputime_timer_init(struct hal_timer *timer, hal_timer_cb fp, void *arg);
+
+/**
+ * os cputime timer start
+ *
+ * Start a cputimer that will expire at 'cputime'. If cputime has already
+ * passed, the timer callback will still be called (at interrupt context).
+ *
+ * @param timer Pointer to timer to start. Cannot be NULL.
+ * @param cputime The cputime at which the timer should expire.
+ */
+void os_cputime_timer_start(struct hal_timer *timer, uint32_t cputime);
+
+/**
+ * os cputimer timer relative
+ *
+ * Sets a cpu timer that will expire 'usecs' microseconds from the current
+ * cputime.
+ *
+ * @param timer Pointer to timer. Cannot be NULL.
+ * @param usecs The number of usecs from now at which the timer will expire.
+ */
+void os_cputime_timer_relative(struct hal_timer *timer, uint32_t usecs);
+
+/**
+ * os cputime timer stop
+ *
+ * Stops a cputimer from running. The timer is removed from the timer queue
+ * and interrupts are disabled if no timers are left on the queue. Can be
+ * called even if timer is not running.
+ *
+ * @param timer Pointer to cputimer to stop. Cannot be NULL.
+ */
+void os_cputime_timer_stop(struct hal_timer *timer);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_OS_CPUTIME_ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/kernel/os/src/os_cputime.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_cputime.c b/kernel/os/src/os_cputime.c
new file mode 100644
index 0000000..ad846d7
--- /dev/null
+++ b/kernel/os/src/os_cputime.c
@@ -0,0 +1,270 @@
+/**
+ * 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 <string.h>
+#include <stdint.h>
+#include <assert.h>
+#include "os/os.h"
+#include "os/os_cputime.h"
+
+#if defined(MYNEWT_VAL_OS_CPUTIME_TIMER_NUM)
+
+struct os_cputime_data g_cputime;
+
+/**
+ * os cputime init
+ *
+ * Initialize the cputime module. This must be called after os_init is called
+ * and before any other timer API are used. This should be called only once
+ * and should be called before the hardware timer is used.
+ *
+ * @param clock_freq The desired cputime frequency, in hertz (Hz).
+ *
+ * @return int 0 on success; -1 on error.
+ */
+int
+os_cputime_init(uint32_t clock_freq)
+{
+ int rc;
+
+ /* Set the ticks per microsecond. */
+ g_cputime.ticks_per_usec = clock_freq / 1000000U;
+ rc = hal_timer_init(MYNEWT_VAL(OS_CPUTIME_TIMER_NUM), clock_freq);
+ return rc;
+}
+
+/**
+ * os cputime nsecs to ticks
+ *
+ * Converts the given number of nanoseconds into cputime ticks.
+ *
+ * @param usecs The number of nanoseconds to convert to ticks
+ *
+ * @return uint32_t The number of ticks corresponding to 'nsecs'
+ */
+uint32_t
+os_cputime_nsecs_to_ticks(uint32_t nsecs)
+{
+ uint32_t ticks;
+
+#if defined(OS_CPUTIME_FREQ_1MHZ)
+ ticks = (nsecs + 999) / 1000;
+#else
+ ticks = ((nsecs * g_cputime.ticks_per_usec) + 999) / 1000;
+#endif
+ return ticks;
+}
+
+/**
+ * os cputime ticks to nsecs
+ *
+ * Convert the given number of ticks into nanoseconds.
+ *
+ * @param ticks The number of ticks to convert to nanoseconds.
+ *
+ * @return uint32_t The number of nanoseconds corresponding to 'ticks'
+ */
+uint32_t
+os_cputime_ticks_to_nsecs(uint32_t ticks)
+{
+ uint32_t nsecs;
+
+#if defined(OS_CPUTIME_FREQ_1MHZ)
+ nsecs = ticks * 1000;
+#else
+ nsecs = ((ticks * 1000) + (g_cputime.ticks_per_usec - 1)) /
+ g_cputime.ticks_per_usec;
+#endif
+
+ return nsecs;
+}
+
+#if !defined(OS_CPUTIME_FREQ_1MHZ)
+/**
+ * os cputime usecs to ticks
+ *
+ * Converts the given number of microseconds into cputime ticks.
+ *
+ * @param usecs The number of microseconds to convert to ticks
+ *
+ * @return uint32_t The number of ticks corresponding to 'usecs'
+ */
+uint32_t
+os_cputime_usecs_to_ticks(uint32_t usecs)
+{
+ uint32_t ticks;
+
+ ticks = (usecs * g_cputime.ticks_per_usec);
+ return ticks;
+}
+
+/**
+ * cputime ticks to usecs
+ *
+ * Convert the given number of ticks into microseconds.
+ *
+ * @param ticks The number of ticks to convert to microseconds.
+ *
+ * @return uint32_t The number of microseconds corresponding to 'ticks'
+ */
+uint32_t
+os_cputime_ticks_to_usecs(uint32_t ticks)
+{
+ uint32_t us;
+
+ us = (ticks + (g_cputime.ticks_per_usec - 1)) / g_cputime.ticks_per_usec;
+ return us;
+}
+#endif
+
+/**
+ * os cputime delay ticks
+ *
+ * Wait until the number of ticks has elapsed. This is a blocking delay.
+ *
+ * @param ticks The number of ticks to wait.
+ */
+void
+os_cputime_delay_ticks(uint32_t ticks)
+{
+ uint32_t until;
+
+ until = os_cputime_get32() + ticks;
+ while ((int32_t)(os_cputime_get32() - until) < 0) {
+ /* Loop here till finished */
+ }
+}
+
+/**
+ * os cputime delay nsecs
+ *
+ * Wait until 'nsecs' nanoseconds has elapsed. This is a blocking delay.
+ *
+ * @param nsecs The number of nanoseconds to wait.
+ */
+void
+os_cputime_delay_nsecs(uint32_t nsecs)
+{
+ uint32_t ticks;
+
+ ticks = os_cputime_nsecs_to_ticks(nsecs);
+ os_cputime_delay_ticks(ticks);
+}
+
+/**
+ * os cputime delay usecs
+ *
+ * Wait until 'usecs' microseconds has elapsed. This is a blocking delay.
+ *
+ * @param usecs The number of usecs to wait.
+ */
+void
+os_cputime_delay_usecs(uint32_t usecs)
+{
+ uint32_t ticks;
+
+ ticks = os_cputime_usecs_to_ticks(usecs);
+ os_cputime_delay_ticks(ticks);
+}
+
+/**
+ * os cputime timer init
+ *
+ *
+ * @param timer The timer to initialize. Cannot be NULL.
+ * @param fp The timer callback function. Cannot be NULL.
+ * @param arg Pointer to data object to pass to timer.
+ */
+void
+os_cputime_timer_init(struct hal_timer *timer, hal_timer_cb fp, void *arg)
+{
+ assert(timer != NULL);
+ assert(fp != NULL);
+
+ hal_timer_set_cb(MYNEWT_VAL(OS_CPUTIME_TIMER_NUM), timer, fp, arg);
+}
+
+/**
+ * os cputime timer start
+ *
+ * Start a cputimer that will expire at 'cputime'. If cputime has already
+ * passed, the timer callback will still be called (at interrupt context).
+ * Cannot be called when the timer has already started.
+ *
+ * @param timer Pointer to timer to start. Cannot be NULL.
+ * @param cputime The cputime at which the timer should expire.
+ */
+void
+os_cputime_timer_start(struct hal_timer *timer, uint32_t cputime)
+{
+ hal_timer_start_at(timer, cputime);
+}
+
+/**
+ * os cputimer timer relative
+ *
+ * Sets a cpu timer that will expire 'usecs' microseconds from the current
+ * cputime.
+ *
+ * @param timer Pointer to timer. Cannot be NULL.
+ * @param usecs The number of usecs from now at which the timer will expire.
+ */
+void
+os_cputime_timer_relative(struct hal_timer *timer, uint32_t usecs)
+{
+ uint32_t cputime;
+
+ assert(timer != NULL);
+
+ cputime = os_cputime_get32() + os_cputime_usecs_to_ticks(usecs);
+ hal_timer_start(timer, cputime);
+}
+
+/**
+ * os cputime timer stop
+ *
+ * Stops a cputimer from running. The timer is removed from the timer queue
+ * and interrupts are disabled if no timers are left on the queue. Can be
+ * called even if timer is not running.
+ *
+ * @param timer Pointer to cputimer to stop. Cannot be NULL.
+ */
+void
+os_cputime_timer_stop(struct hal_timer *timer)
+{
+ hal_timer_stop(timer);
+}
+
+/**
+ * os cputime get32
+ *
+ * Returns current value of cputime.
+ *
+ * @return uint32_t cputime
+ */
+uint32_t
+os_cputime_get32(void)
+{
+ uint32_t cpu_time;
+
+ cpu_time = hal_timer_read(MYNEWT_VAL(OS_CPUTIME_TIMER_NUM));
+ return cpu_time;
+}
+
+#endif /* if defined(MYNEWT_VAL_OS_CPUTIME_TIMER_NUM) */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/kernel/os/syscfg.yml
----------------------------------------------------------------------
diff --git a/kernel/os/syscfg.yml b/kernel/os/syscfg.yml
index 9e903e7..6c613b5 100644
--- a/kernel/os/syscfg.yml
+++ b/kernel/os/syscfg.yml
@@ -9,6 +9,9 @@ syscfg.defs:
OS_COREDUMP:
description: 'TBD'
value: 0
+ OS_CPUTIME_FREQ:
+ description: 'Frequency of os cputime'
+ value: 1000000
SANITY_INTERVAL:
description: 'The interval (in milliseconds) at which the sanity checks should run, should be at least 200ms prior to watchdog'
value: 59500
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/net/nimble/controller/include/controller/ble_ll.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h
index a4df677..8ba11c3 100644
--- a/net/nimble/controller/include/controller/ble_ll.h
+++ b/net/nimble/controller/include/controller/ble_ll.h
@@ -21,8 +21,8 @@
#define H_BLE_LL_
#include "stats/stats.h"
-#include "hal/hal_cputime.h"
#include "os/os_eventq.h"
+#include "os/os_cputime.h"
#include "nimble/nimble_opt.h"
#ifdef __cplusplus
@@ -71,7 +71,7 @@ struct ble_ll_obj
struct os_eventq ll_evq;
/* Wait for response timer */
- struct cpu_timer ll_wfr_timer;
+ struct hal_timer ll_wfr_timer;
/* Packet receive queue (and event). Holds received packets from PHY */
struct os_event ll_rx_pkt_ev;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/net/nimble/controller/include/controller/ble_ll_conn.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_conn.h b/net/nimble/controller/include/controller/ble_ll_conn.h
index c14bd99..acb7116 100644
--- a/net/nimble/controller/include/controller/ble_ll_conn.h
+++ b/net/nimble/controller/include/controller/ble_ll_conn.h
@@ -25,7 +25,7 @@
#include "nimble/hci_common.h"
#include "controller/ble_ll_sched.h"
#include "controller/ble_ll_ctrl.h"
-#include "hal/hal_cputime.h"
+#include "hal/hal_timer.h"
#ifdef __cplusplus
extern "C" {
@@ -212,7 +212,7 @@ struct ble_ll_conn_sm
uint8_t peer_addr[BLE_DEV_ADDR_LEN];
/* connection supervisor timer */
- struct cpu_timer conn_spvn_timer;
+ struct hal_timer conn_spvn_timer;
/* connection supervision timeout event */
struct os_event conn_spvn_ev;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/net/nimble/controller/include/controller/ble_ll_scan.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_scan.h b/net/nimble/controller/include/controller/ble_ll_scan.h
index 7d86102..3d17e13 100644
--- a/net/nimble/controller/include/controller/ble_ll_scan.h
+++ b/net/nimble/controller/include/controller/ble_ll_scan.h
@@ -21,7 +21,7 @@
#define H_BLE_LL_SCAN_
#include "controller/ble_ll_sched.h"
-#include "hal/hal_cputime.h"
+#include "hal/hal_timer.h"
#ifdef __cplusplus
extern "C" {
@@ -74,7 +74,7 @@ struct ble_ll_scan_sm
uint32_t scan_win_start_time;
struct os_mbuf *scan_req_pdu;
struct os_event scan_sched_ev;
- struct cpu_timer scan_timer;
+ struct hal_timer scan_timer;
};
/* Scan types */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/net/nimble/controller/src/ble_ll.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll.c b/net/nimble/controller/src/ble_ll.c
index 0105df2..5df83c6 100644
--- a/net/nimble/controller/src/ble_ll.c
+++ b/net/nimble/controller/src/ble_ll.c
@@ -23,6 +23,7 @@
#include "sysinit/sysinit.h"
#include "syscfg/syscfg.h"
#include "os/os.h"
+#include "os/os_cputime.h"
#include "stats/stats.h"
#include "bsp/bsp.h"
#include "nimble/ble.h"
@@ -39,7 +40,6 @@
#include "controller/ble_ll_whitelist.h"
#include "controller/ble_ll_resolv.h"
#include "ble_ll_conn_priv.h"
-#include "hal/hal_cputime.h"
/* XXX:
*
@@ -220,7 +220,7 @@ ble_ll_log(uint8_t id, uint8_t arg8, uint16_t arg16, uint32_t arg32)
OS_ENTER_CRITICAL(sr);
le = &g_ble_ll_log[g_ble_ll_log_index];
- le->cputime = cputime_get32();
+ le->cputime = os_cputime_get32();
le->log_id = id;
le->log_a8 = arg8;
le->log_a16 = arg16;
@@ -535,7 +535,7 @@ ble_ll_wfr_timer_exp(void *arg)
void
ble_ll_wfr_enable(uint32_t cputime)
{
- cputime_timer_start(&g_ble_ll_data.ll_wfr_timer, cputime);
+ os_cputime_timer_start(&g_ble_ll_data.ll_wfr_timer, cputime);
}
/**
@@ -544,7 +544,7 @@ ble_ll_wfr_enable(uint32_t cputime)
void
ble_ll_wfr_disable(void)
{
- cputime_timer_stop(&g_ble_ll_data.ll_wfr_timer);
+ os_cputime_timer_stop(&g_ble_ll_data.ll_wfr_timer);
}
/**
@@ -1255,8 +1255,8 @@ ble_ll_init(void)
NULL);
/* Initialize wait for response timer */
- cputime_timer_init(&g_ble_ll_data.ll_wfr_timer, ble_ll_wfr_timer_exp,
- NULL);
+ os_cputime_timer_init(&g_ble_ll_data.ll_wfr_timer, ble_ll_wfr_timer_exp,
+ NULL);
ble_ll_hci_os_event_buf = malloc(
OS_MEMPOOL_BYTES(16, sizeof (struct os_event)));
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/net/nimble/controller/src/ble_ll_adv.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_adv.c b/net/nimble/controller/src/ble_ll_adv.c
index 95c302f..9ea636c 100644
--- a/net/nimble/controller/src/ble_ll_adv.c
+++ b/net/nimble/controller/src/ble_ll_adv.c
@@ -21,6 +21,7 @@
#include <assert.h>
#include "syscfg/syscfg.h"
#include "os/os.h"
+#include "os/os_cputime.h"
#include "bsp/bsp.h"
#include "ble/xcvr.h"
#include "nimble/ble.h"
@@ -36,7 +37,6 @@
#include "controller/ble_ll_whitelist.h"
#include "controller/ble_ll_resolv.h"
#include "ble_ll_conn_priv.h"
-#include "hal/hal_cputime.h"
#include "hal/hal_gpio.h"
/* XXX: TODO
@@ -491,13 +491,13 @@ ble_ll_adv_set_sched(struct ble_ll_adv_sm *advsm, int sched_new)
* time of the event since the pdu does not start at the scheduled start.
*/
max_usecs += XCVR_TX_SCHED_DELAY_USECS;
- sch->start_time = cputime_get32();
- sch->end_time = sch->start_time + cputime_usecs_to_ticks(max_usecs);
+ sch->start_time = os_cputime_get32();
+ sch->end_time = sch->start_time + os_cputime_usecs_to_ticks(max_usecs);
} else {
sch->start_time = advsm->adv_pdu_start_time -
- cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
+ os_cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
sch->end_time = advsm->adv_pdu_start_time +
- cputime_usecs_to_ticks(max_usecs);
+ os_cputime_usecs_to_ticks(max_usecs);
}
}
@@ -785,7 +785,7 @@ ble_ll_adv_scheduled(uint32_t sch_start)
/* The event start time is when we start transmission of the adv PDU */
advsm->adv_event_start_time = sch_start +
- cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
+ os_cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
advsm->adv_pdu_start_time = advsm->adv_event_start_time;
@@ -795,7 +795,7 @@ ble_ll_adv_scheduled(uint32_t sch_start)
* duty cycle advertising.
*/
advsm->adv_dir_hd_end_time = advsm->adv_event_start_time +
- cputime_usecs_to_ticks(BLE_LL_ADV_STATE_HD_MAX * 1000);
+ os_cputime_usecs_to_ticks(BLE_LL_ADV_STATE_HD_MAX * 1000);
}
/**
@@ -1300,7 +1300,7 @@ ble_ll_adv_event_done(void *arg)
if (advsm->adv_type != BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD) {
itvl += rand() % (BLE_LL_ADV_DELAY_MS_MAX * 1000);
}
- advsm->adv_event_start_time += cputime_usecs_to_ticks(itvl);
+ advsm->adv_event_start_time += os_cputime_usecs_to_ticks(itvl);
advsm->adv_pdu_start_time = advsm->adv_event_start_time;
/*
@@ -1308,9 +1308,9 @@ ble_ll_adv_event_done(void *arg)
* just keep advancing until we the time is in the future
*/
start_time = advsm->adv_pdu_start_time -
- cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
+ os_cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
- delta_t = (int32_t)(start_time - cputime_get32());
+ delta_t = (int32_t)(start_time - os_cputime_get32());
if (delta_t < 0) {
/* Calculate start time of next advertising event */
while (delta_t < 0) {
@@ -1318,7 +1318,7 @@ ble_ll_adv_event_done(void *arg)
if (advsm->adv_type != BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD) {
itvl += rand() % (BLE_LL_ADV_DELAY_MS_MAX * 1000);
}
- itvl = cputime_usecs_to_ticks(itvl);
+ itvl = os_cputime_usecs_to_ticks(itvl);
advsm->adv_event_start_time += itvl;
advsm->adv_pdu_start_time = advsm->adv_event_start_time;
delta_t += (int32_t)itvl;
@@ -1340,8 +1340,8 @@ ble_ll_adv_event_done(void *arg)
* We will transmit right away. Set next pdu start time to now
* plus a xcvr start delay just so we dont count late adv starts
*/
- advsm->adv_pdu_start_time = cputime_get32() +
- cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
+ advsm->adv_pdu_start_time = os_cputime_get32() +
+ os_cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
}
/*
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/net/nimble/controller/src/ble_ll_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn.c b/net/nimble/controller/src/ble_ll_conn.c
index 4a553d0..7c2208f 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -23,6 +23,7 @@
#include "syscfg/syscfg.h"
#include "bsp/bsp.h"
#include "os/os.h"
+#include "os/os_cputime.h"
#include "nimble/ble.h"
#include "nimble/nimble_opt.h"
#include "nimble/hci_common.h"
@@ -39,7 +40,6 @@
#include "controller/ble_phy.h"
#include "controller/ble_hw.h"
#include "ble_ll_conn_priv.h"
-#include "hal/hal_cputime.h"
#include "hal/hal_gpio.h"
#if (BLETEST_THROUGHPUT_TEST == 1)
@@ -289,7 +289,7 @@ ble_ll_conn_get_ce_end_time(void)
if (g_ble_ll_conn_cur_sm) {
ce_end_time = g_ble_ll_conn_cur_sm->ce_end_time;
} else {
- ce_end_time = cputime_get32();
+ ce_end_time = os_cputime_get32();
}
return ce_end_time;
}
@@ -394,7 +394,7 @@ ble_ll_conn_calc_window_widening(struct ble_ll_conn_sm *connsm)
time_since_last_anchor = (int32_t)(connsm->anchor_point -
connsm->last_anchor_point);
if (time_since_last_anchor > 0) {
- delta_msec = cputime_ticks_to_usecs(time_since_last_anchor) / 1000;
+ delta_msec = os_cputime_ticks_to_usecs(time_since_last_anchor) / 1000;
total_sca_ppm = g_ble_sca_ppm_tbl[connsm->master_sca] +
MYNEWT_VAL(BLE_LL_OUR_SCA);
window_widening = (total_sca_ppm * delta_msec) / 1000;
@@ -702,7 +702,7 @@ ble_ll_conn_get_next_sched_time(struct ble_ll_conn_sm *connsm)
/* Calculate time at which next connection event will start */
itvl = connsm->conn_itvl * BLE_LL_CONN_ITVL_USECS;
- ce_end = connsm->anchor_point + cputime_usecs_to_ticks(itvl);
+ ce_end = connsm->anchor_point + os_cputime_usecs_to_ticks(itvl);
if (ble_ll_sched_next_time(&next_sched_time)) {
if (CPUTIME_LT(next_sched_time, ce_end)) {
@@ -935,8 +935,8 @@ ble_ll_conn_tx_data_pdu(struct ble_ll_conn_sm *connsm)
ticks += (BLE_LL_IFS + connsm->eff_max_rx_time);
}
- ticks = cputime_usecs_to_ticks(ticks);
- if ((cputime_get32() + ticks) < next_event_time) {
+ ticks = os_cputime_usecs_to_ticks(ticks);
+ if ((os_cputime_get32() + ticks) < next_event_time) {
md = 1;
}
}
@@ -1209,7 +1209,7 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch)
*/
usecs = connsm->slave_cur_tx_win_usecs + BLE_LL_WFR_USECS +
connsm->slave_cur_window_widening;
- wfr_time = connsm->anchor_point + cputime_usecs_to_ticks(usecs);
+ wfr_time = connsm->anchor_point + os_cputime_usecs_to_ticks(usecs);
ble_ll_wfr_enable(wfr_time);
/* Set next wakeup time to connection event end time */
@@ -1224,7 +1224,7 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch)
}
/* Set time that we last serviced the schedule */
- connsm->last_scheduled = cputime_get32();
+ connsm->last_scheduled = os_cputime_get32();
return rc;
}
@@ -1279,7 +1279,7 @@ ble_ll_conn_can_send_next_pdu(struct ble_ll_conn_sm *connsm, uint32_t begtime)
ticks = BLE_TX_DUR_USECS_M(0);
}
ticks += (BLE_LL_IFS * 2) + connsm->eff_max_rx_time;
- ticks = cputime_usecs_to_ticks(ticks);
+ ticks = os_cputime_usecs_to_ticks(ticks);
if ((begtime + ticks) >= next_sched_time) {
rc = 0;
}
@@ -1448,7 +1448,7 @@ ble_ll_conn_sm_new(struct ble_ll_conn_sm *connsm)
connsm->conn_param_req.handle = 0;
/* Initialize connection supervision timer */
- cputime_timer_init(&connsm->conn_spvn_timer, ble_ll_conn_spvn_timer_cb,
+ os_cputime_timer_init(&connsm->conn_spvn_timer, ble_ll_conn_spvn_timer_cb,
connsm);
/* Calculate the next data channel */
@@ -1579,7 +1579,7 @@ ble_ll_conn_end(struct ble_ll_conn_sm *connsm, uint8_t ble_err)
ble_ll_sched_rmv_elem(&connsm->conn_sch);
/* Stop supervision timer */
- cputime_timer_stop(&connsm->conn_spvn_timer);
+ os_cputime_timer_stop(&connsm->conn_spvn_timer);
/* Stop any control procedures that might be running */
os_callout_stop(&connsm->ctrl_proc_rsp_timer.cf_c);
@@ -1674,7 +1674,7 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
connsm->event_cntr += latency;
/* Set next connection event start time */
- connsm->anchor_point += cputime_usecs_to_ticks(itvl);
+ connsm->anchor_point += os_cputime_usecs_to_ticks(itvl);
/*
* If a connection update has been scheduled and the event counter
@@ -1704,14 +1704,14 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
connsm->tx_win_size * BLE_LL_CONN_TX_WIN_USECS;
connsm->tx_win_off = upd->winoffset;
connsm->anchor_point +=
- cputime_usecs_to_ticks(upd->winoffset * BLE_LL_CONN_ITVL_USECS);
+ os_cputime_usecs_to_ticks(upd->winoffset * BLE_LL_CONN_ITVL_USECS);
/* Reset the connection supervision timeout */
- cputime_timer_stop(&connsm->conn_spvn_timer);
+ os_cputime_timer_stop(&connsm->conn_spvn_timer);
tmo = connsm->supervision_tmo;
tmo = tmo * BLE_HCI_CONN_SPVN_TMO_UNITS * 1000;
- tmo = cputime_usecs_to_ticks(tmo);
- cputime_timer_start(&connsm->conn_spvn_timer, connsm->anchor_point+tmo);
+ tmo = os_cputime_usecs_to_ticks(tmo);
+ os_cputime_timer_start(&connsm->conn_spvn_timer, connsm->anchor_point+tmo);
/* Reset update scheduled flag */
connsm->csmflags.cfbit.conn_update_sched = 0;
@@ -1780,7 +1780,7 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
/* We adjust end time for connection to end of time slot */
itvl -= XCVR_TX_SCHED_DELAY_USECS;
}
- connsm->ce_end_time = connsm->anchor_point + cputime_usecs_to_ticks(itvl);
+ connsm->ce_end_time = connsm->anchor_point + os_cputime_usecs_to_ticks(itvl);
return 0;
}
@@ -1812,13 +1812,13 @@ ble_ll_conn_created(struct ble_ll_conn_sm *connsm, uint32_t endtime)
/* Set supervision timeout */
usecs = connsm->conn_itvl * BLE_LL_CONN_ITVL_USECS * 6;
- cputime_timer_relative(&connsm->conn_spvn_timer, usecs);
+ os_cputime_timer_relative(&connsm->conn_spvn_timer, usecs);
/* Clear packet received flag */
connsm->csmflags.cfbit.pkt_rxd = 0;
/* Consider time created the last scheduled time */
- connsm->last_scheduled = cputime_get32();
+ connsm->last_scheduled = os_cputime_get32();
/*
* Set first connection event time. If slave the endtime is the receive end
@@ -1831,11 +1831,11 @@ ble_ll_conn_created(struct ble_ll_conn_sm *connsm, uint32_t endtime)
connsm->slave_cur_tx_win_usecs =
connsm->tx_win_size * BLE_LL_CONN_TX_WIN_USECS;
usecs = 1250 + (connsm->tx_win_off * BLE_LL_CONN_TX_WIN_USECS);
- connsm->anchor_point = endtime + cputime_usecs_to_ticks(usecs);
+ connsm->anchor_point = endtime + os_cputime_usecs_to_ticks(usecs);
usecs = connsm->slave_cur_tx_win_usecs +
(MYNEWT_VAL(BLE_LL_CONN_INIT_SLOTS) * BLE_LL_SCHED_USECS_PER_SLOT);
connsm->ce_end_time = connsm->anchor_point +
- cputime_usecs_to_ticks(usecs);
+ os_cputime_usecs_to_ticks(usecs);
connsm->slave_cur_window_widening = 0;
/* Start the scheduler for the first connection event */
@@ -2529,9 +2529,9 @@ ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr)
connsm = ble_ll_conn_find_active_conn(hdr->rxinfo.handle);
if (connsm) {
/* Reset the connection supervision timeout */
- cputime_timer_stop(&connsm->conn_spvn_timer);
+ os_cputime_timer_stop(&connsm->conn_spvn_timer);
tmo = connsm->supervision_tmo * BLE_HCI_CONN_SPVN_TMO_UNITS * 1000;
- cputime_timer_relative(&connsm->conn_spvn_timer, tmo);
+ os_cputime_timer_relative(&connsm->conn_spvn_timer, tmo);
/* Check state machine */
ble_ll_conn_chk_csm_flags(connsm);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/net/nimble/controller/src/ble_ll_ctrl.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_ctrl.c b/net/nimble/controller/src/ble_ll_ctrl.c
index 1d98ed3..3edd40e 100644
--- a/net/nimble/controller/src/ble_ll_ctrl.c
+++ b/net/nimble/controller/src/ble_ll_ctrl.c
@@ -1397,8 +1397,8 @@ ble_ll_ctrl_terminate_start(struct ble_ll_conn_sm *connsm)
/* Set terminate "timeout" */
usecs = connsm->supervision_tmo * BLE_HCI_CONN_SPVN_TMO_UNITS * 1000;
- connsm->terminate_timeout = cputime_get32() +
- cputime_usecs_to_ticks(usecs);
+ connsm->terminate_timeout = os_cputime_get32() +
+ os_cputime_usecs_to_ticks(usecs);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/net/nimble/controller/src/ble_ll_scan.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_scan.c b/net/nimble/controller/src/ble_ll_scan.c
index 2d58282..4284814 100644
--- a/net/nimble/controller/src/ble_ll_scan.c
+++ b/net/nimble/controller/src/ble_ll_scan.c
@@ -23,6 +23,7 @@
#include "syscfg/syscfg.h"
#include "bsp/bsp.h"
#include "os/os.h"
+#include "os/os_cputime.h"
#include "nimble/ble.h"
#include "nimble/nimble_opt.h"
#include "nimble/hci_common.h"
@@ -36,7 +37,6 @@
#include "controller/ble_ll_hci.h"
#include "controller/ble_ll_whitelist.h"
#include "controller/ble_ll_resolv.h"
-#include "hal/hal_cputime.h"
#include "hal/hal_gpio.h"
/*
@@ -631,7 +631,7 @@ ble_ll_scan_window_chk(struct ble_ll_scan_sm *scansm, uint32_t cputime)
uint32_t itvl;
uint32_t win_start;
- itvl = cputime_usecs_to_ticks(scansm->scan_itvl * BLE_HCI_SCAN_ITVL);
+ itvl = os_cputime_usecs_to_ticks(scansm->scan_itvl * BLE_HCI_SCAN_ITVL);
chan = scansm->scan_chan;
win_start = scansm->scan_win_start_time;
while ((int32_t)(cputime - win_start) >= itvl) {
@@ -644,7 +644,7 @@ ble_ll_scan_window_chk(struct ble_ll_scan_sm *scansm, uint32_t cputime)
rc = 0;
if (scansm->scan_window != scansm->scan_itvl) {
- itvl = cputime_usecs_to_ticks(scansm->scan_window * BLE_HCI_SCAN_ITVL);
+ itvl = os_cputime_usecs_to_ticks(scansm->scan_window * BLE_HCI_SCAN_ITVL);
if ((cputime - win_start) >= itvl) {
rc = 1;
}
@@ -670,7 +670,7 @@ ble_ll_scan_sm_stop(int chk_disable)
/* Stop the scanning timer */
scansm = &g_ble_ll_scan_sm;
- cputime_timer_stop(&scansm->scan_timer);
+ os_cputime_timer_stop(&scansm->scan_timer);
/* Disable scanning state machine */
scansm->scan_enabled = 0;
@@ -729,7 +729,7 @@ ble_ll_scan_sm_start(struct ble_ll_scan_sm *scansm)
/* XXX: align to current or next slot???. */
/* Schedule start time now */
- scansm->scan_win_start_time = cputime_get32();
+ scansm->scan_win_start_time = os_cputime_get32();
/* Post scanning event to start off the scanning process */
ble_ll_event_send(&scansm->scan_sched_ev);
@@ -765,14 +765,14 @@ ble_ll_scan_event_proc(void *arg)
*/
scansm = (struct ble_ll_scan_sm *)arg;
if (!scansm->scan_enabled) {
- cputime_timer_stop(&scansm->scan_timer);
+ os_cputime_timer_stop(&scansm->scan_timer);
return;
}
/* Make sure the scan window start time and channel are up to date. */
- now = cputime_get32();
+ now = os_cputime_get32();
- scan_itvl = cputime_usecs_to_ticks(scansm->scan_itvl * BLE_HCI_SCAN_ITVL);
+ scan_itvl = os_cputime_usecs_to_ticks(scansm->scan_itvl * BLE_HCI_SCAN_ITVL);
chan = scansm->scan_chan;
win_start = scansm->scan_win_start_time;
while ((int32_t)(now - win_start) >= scan_itvl) {
@@ -791,7 +791,7 @@ ble_ll_scan_event_proc(void *arg)
rxstate = 1;
next_event_time = win_start + scan_itvl;
if (scansm->scan_window != scansm->scan_itvl) {
- win = cputime_usecs_to_ticks(scansm->scan_window * BLE_HCI_SCAN_ITVL);
+ win = os_cputime_usecs_to_ticks(scansm->scan_window * BLE_HCI_SCAN_ITVL);
if (dt >= win) {
rxstate = 0;
} else {
@@ -827,7 +827,7 @@ ble_ll_scan_event_proc(void *arg)
}
OS_EXIT_CRITICAL(sr);
- cputime_timer_start(&scansm->scan_timer, next_event_time);
+ os_cputime_timer_start(&scansm->scan_timer, next_event_time);
}
/**
@@ -1047,7 +1047,7 @@ ble_ll_scan_chk_resume(void)
if (scansm->scan_enabled) {
OS_ENTER_CRITICAL(sr);
if (ble_ll_state_get() == BLE_LL_STATE_STANDBY) {
- ble_ll_scan_window_chk(scansm, cputime_get32());
+ ble_ll_scan_window_chk(scansm, os_cputime_get32());
}
OS_EXIT_CRITICAL(sr);
}
@@ -1481,7 +1481,7 @@ ble_ll_scan_init(void)
scansm->scan_window = BLE_HCI_SCAN_WINDOW_DEF;
/* Initialize connection supervision timer */
- cputime_timer_init(&scansm->scan_timer, ble_ll_scan_timer_cb, scansm);
+ os_cputime_timer_init(&scansm->scan_timer, ble_ll_scan_timer_cb, scansm);
/* Get a scan request mbuf (packet header) and attach to state machine */
scansm->scan_req_pdu = os_msys_get_pkthdr(BLE_MBUF_PAYLOAD_SIZE,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/net/nimble/controller/src/ble_ll_sched.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_sched.c b/net/nimble/controller/src/ble_ll_sched.c
index 90cb510..4edaf60 100644
--- a/net/nimble/controller/src/ble_ll_sched.c
+++ b/net/nimble/controller/src/ble_ll_sched.c
@@ -20,6 +20,7 @@
#include <assert.h>
#include <string.h>
#include "os/os.h"
+#include "os/os_cputime.h"
#include "ble/xcvr.h"
#include "controller/ble_phy.h"
#include "controller/ble_ll.h"
@@ -27,10 +28,9 @@
#include "controller/ble_ll_adv.h"
#include "controller/ble_ll_scan.h"
#include "ble_ll_conn_priv.h"
-#include "hal/hal_cputime.h"
/* XXX: this is temporary. Not sure what I want to do here */
-struct cpu_timer g_ble_ll_sched_timer;
+struct hal_timer g_ble_ll_sched_timer;
#if (BLE_LL_SCHED_DEBUG == 1)
int32_t g_ble_ll_sched_max_late;
@@ -157,11 +157,11 @@ ble_ll_sched_conn_reschedule(struct ble_ll_conn_sm *connsm)
} else {
usecs = XCVR_TX_SCHED_DELAY_USECS;
}
- sch->start_time = connsm->anchor_point - cputime_usecs_to_ticks(usecs);
+ sch->start_time = connsm->anchor_point - os_cputime_usecs_to_ticks(usecs);
sch->end_time = connsm->ce_end_time;
/* Better be past current time or we just leave */
- if ((int32_t)(sch->start_time - cputime_get32()) < 0) {
+ if ((int32_t)(sch->start_time - os_cputime_get32()) < 0) {
return -1;
}
@@ -174,7 +174,7 @@ ble_ll_sched_conn_reschedule(struct ble_ll_conn_sm *connsm)
}
/* Stop timer since we will add an element */
- cputime_timer_stop(&g_ble_ll_sched_timer);
+ os_cputime_timer_stop(&g_ble_ll_sched_timer);
start_overlap = NULL;
end_overlap = NULL;
@@ -235,7 +235,7 @@ ble_ll_sched_conn_reschedule(struct ble_ll_conn_sm *connsm)
OS_EXIT_CRITICAL(sr);
/* Restart timer */
- cputime_timer_start(&g_ble_ll_sched_timer, sch->start_time);
+ os_cputime_timer_start(&g_ble_ll_sched_timer, sch->start_time);
return rc;
}
@@ -269,13 +269,13 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm, uint32_t adv_rxend,
* advertisement, so we need to add an IFS plus the time it takes to send
* the connection request
*/
- dur = cputime_usecs_to_ticks(req_slots * BLE_LL_SCHED_USECS_PER_SLOT);
+ dur = os_cputime_usecs_to_ticks(req_slots * BLE_LL_SCHED_USECS_PER_SLOT);
earliest_start = adv_rxend +
- cputime_usecs_to_ticks(BLE_LL_IFS + BLE_LL_CONN_REQ_DURATION +
- BLE_LL_CONN_INITIAL_OFFSET);
+ os_cputime_usecs_to_ticks(BLE_LL_IFS + BLE_LL_CONN_REQ_DURATION +
+ BLE_LL_CONN_INITIAL_OFFSET);
earliest_end = earliest_start + dur;
- itvl_t = cputime_usecs_to_ticks(connsm->conn_itvl * BLE_LL_CONN_ITVL_USECS);
+ itvl_t = os_cputime_usecs_to_ticks(connsm->conn_itvl * BLE_LL_CONN_ITVL_USECS);
/* We have to find a place for this schedule */
OS_ENTER_CRITICAL(sr);
@@ -288,9 +288,9 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm, uint32_t adv_rxend,
* earliest start so we can end the connection reasonably.
*/
if (ble_ll_state_get() == BLE_LL_STATE_CONNECTION) {
- tps = cputime_usecs_to_ticks(BLE_LL_SCHED_USECS_PER_SLOT);
+ tps = os_cputime_usecs_to_ticks(BLE_LL_SCHED_USECS_PER_SLOT);
ce_end_time = ble_ll_conn_get_ce_end_time();
- while ((int32_t)(ce_end_time - cputime_get32()) < 0) {
+ while ((int32_t)(ce_end_time - os_cputime_get32()) < 0) {
ce_end_time += tps;
}
@@ -308,7 +308,7 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm, uint32_t adv_rxend,
rc = 0;
connsm->tx_win_off = 0;
} else {
- cputime_timer_stop(&g_ble_ll_sched_timer);
+ os_cputime_timer_stop(&g_ble_ll_sched_timer);
TAILQ_FOREACH(entry, &g_ble_ll_sched_q, link) {
/* Set these because overlap function needs them to be set */
sch->start_time = earliest_start;
@@ -342,7 +342,7 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm, uint32_t adv_rxend,
/* calculate number of connection intervals before start */
sch->enqueued = 1;
connsm->tx_win_off = (earliest_start - initial_start) /
- cputime_usecs_to_ticks(BLE_LL_CONN_ITVL_USECS);
+ os_cputime_usecs_to_ticks(BLE_LL_CONN_ITVL_USECS);
}
}
@@ -350,7 +350,7 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm, uint32_t adv_rxend,
sch->start_time = earliest_start;
sch->end_time = earliest_end;
connsm->anchor_point = earliest_start +
- cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
+ os_cputime_usecs_to_ticks(XCVR_TX_SCHED_DELAY_USECS);
connsm->ce_end_time = earliest_end;
}
@@ -359,7 +359,7 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm, uint32_t adv_rxend,
OS_EXIT_CRITICAL(sr);
- cputime_timer_start(&g_ble_ll_sched_timer, sch->start_time);
+ os_cputime_timer_start(&g_ble_ll_sched_timer, sch->start_time);
return rc;
}
@@ -379,8 +379,8 @@ ble_ll_sched_slave_new(struct ble_ll_conn_sm *connsm)
/* Set schedule start and end times */
sch->start_time = connsm->anchor_point -
- cputime_usecs_to_ticks(XCVR_RX_SCHED_DELAY_USECS +
- connsm->slave_cur_window_widening);
+ os_cputime_usecs_to_ticks(XCVR_RX_SCHED_DELAY_USECS +
+ connsm->slave_cur_window_widening);
sch->end_time = connsm->ce_end_time;
/* We have to find a place for this schedule */
@@ -397,7 +397,7 @@ ble_ll_sched_slave_new(struct ble_ll_conn_sm *connsm)
/* Nothing in schedule. Schedule as soon as possible */
rc = 0;
} else {
- cputime_timer_stop(&g_ble_ll_sched_timer);
+ os_cputime_timer_stop(&g_ble_ll_sched_timer);
while (1) {
next_sch = entry->link.tqe_next;
/* Insert if event ends before next starts */
@@ -433,7 +433,7 @@ ble_ll_sched_slave_new(struct ble_ll_conn_sm *connsm)
OS_EXIT_CRITICAL(sr);
- cputime_timer_start(&g_ble_ll_sched_timer, sch->start_time);
+ os_cputime_timer_start(&g_ble_ll_sched_timer, sch->start_time);
return rc;
}
@@ -459,7 +459,7 @@ ble_ll_sched_adv_new(struct ble_ll_sched_item *sch)
* earliest start so we can end the connection reasonably.
*/
if (ble_ll_state_get() == BLE_LL_STATE_CONNECTION) {
- ticks = (int32_t)cputime_usecs_to_ticks(BLE_LL_SCHED_MAX_TXRX_SLOT);
+ ticks = (int32_t)os_cputime_usecs_to_ticks(BLE_LL_SCHED_MAX_TXRX_SLOT);
ce_end_time = ble_ll_conn_get_ce_end_time();
if ((int32_t)(ce_end_time - sch->start_time) < ticks) {
ce_end_time += ticks;
@@ -473,7 +473,7 @@ ble_ll_sched_adv_new(struct ble_ll_sched_item *sch)
rc = 0;
adv_start = sch->start_time;
} else {
- cputime_timer_stop(&g_ble_ll_sched_timer);
+ os_cputime_timer_stop(&g_ble_ll_sched_timer);
TAILQ_FOREACH(entry, &g_ble_ll_sched_q, link) {
/* We can insert if before entry in list */
if ((int32_t)(sch->end_time - entry->start_time) < 0) {
@@ -514,7 +514,7 @@ ble_ll_sched_adv_new(struct ble_ll_sched_item *sch)
* that we actually go back to scanning. I need to make sure
we re-enable the receive. Put an event in the log! */
- cputime_timer_start(&g_ble_ll_sched_timer, sch->start_time);
+ os_cputime_timer_start(&g_ble_ll_sched_timer, sch->start_time);
return rc;
}
@@ -538,7 +538,7 @@ ble_ll_sched_adv_reschedule(struct ble_ll_sched_item *sch)
entry = ble_ll_sched_insert_if_empty(sch);
if (entry) {
- cputime_timer_stop(&g_ble_ll_sched_timer);
+ os_cputime_timer_stop(&g_ble_ll_sched_timer);
while (1) {
/* Insert before if adv event is before this event */
next_sch = entry->link.tqe_next;
@@ -574,7 +574,7 @@ ble_ll_sched_adv_reschedule(struct ble_ll_sched_item *sch)
OS_EXIT_CRITICAL(sr);
- cputime_timer_start(&g_ble_ll_sched_timer, sch->start_time);
+ os_cputime_timer_start(&g_ble_ll_sched_timer, sch->start_time);
return rc;
}
@@ -600,7 +600,7 @@ ble_ll_sched_rmv_elem(struct ble_ll_sched_item *sch)
if (sch->enqueued) {
first = TAILQ_FIRST(&g_ble_ll_sched_q);
if (first == sch) {
- cputime_timer_stop(&g_ble_ll_sched_timer);
+ os_cputime_timer_stop(&g_ble_ll_sched_timer);
}
TAILQ_REMOVE(&g_ble_ll_sched_q, sch, link);
@@ -609,7 +609,7 @@ ble_ll_sched_rmv_elem(struct ble_ll_sched_item *sch)
if (first == sch) {
first = TAILQ_FIRST(&g_ble_ll_sched_q);
if (first) {
- cputime_timer_start(&g_ble_ll_sched_timer, first->start_time);
+ os_cputime_timer_start(&g_ble_ll_sched_timer, first->start_time);
}
}
}
@@ -674,7 +674,7 @@ ble_ll_sched_run(void *arg)
/* Look through schedule queue */
while ((sch = TAILQ_FIRST(&g_ble_ll_sched_q)) != NULL) {
/* Make sure we have passed the start time of the first event */
- dt = (int32_t)(cputime_get32() - sch->start_time);
+ dt = (int32_t)(os_cputime_get32() - sch->start_time);
if (dt >= 0) {
#if (BLE_LL_SCHED_DEBUG == 1)
if (dt > g_ble_ll_sched_max_late) {
@@ -686,7 +686,7 @@ ble_ll_sched_run(void *arg)
sch->enqueued = 0;
ble_ll_sched_execute_item(sch);
} else {
- cputime_timer_start(&g_ble_ll_sched_timer, sch->start_time);
+ os_cputime_timer_start(&g_ble_ll_sched_timer, sch->start_time);
break;
}
}
@@ -729,7 +729,7 @@ ble_ll_sched_next_time(uint32_t *next_event_time)
void
ble_ll_sched_stop(void)
{
- cputime_timer_stop(&g_ble_ll_sched_timer);
+ os_cputime_timer_stop(&g_ble_ll_sched_timer);
}
/**
@@ -742,6 +742,6 @@ int
ble_ll_sched_init(void)
{
/* Initialize cputimer for the scheduler */
- cputime_timer_init(&g_ble_ll_sched_timer, ble_ll_sched_run, NULL);
+ os_cputime_timer_init(&g_ble_ll_sched_timer, ble_ll_sched_run, NULL);
return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac2d49e3/net/nimble/controller/src/ble_ll_whitelist.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_whitelist.c b/net/nimble/controller/src/ble_ll_whitelist.c
index b92b157..6221ad0 100644
--- a/net/nimble/controller/src/ble_ll_whitelist.c
+++ b/net/nimble/controller/src/ble_ll_whitelist.c
@@ -29,7 +29,6 @@
#include "controller/ble_ll_adv.h"
#include "controller/ble_ll_scan.h"
#include "controller/ble_hw.h"
-#include "hal/hal_cputime.h"
#if (MYNEWT_VAL(BLE_LL_WHITELIST_SIZE) < BLE_HW_WHITE_LIST_SIZE)
#define BLE_LL_WHITELIST_SIZE MYNEWT_VAL(BLE_LL_WHITELIST_SIZE)