Commit graph

656 commits

Author SHA1 Message Date
Johan Hedberg 224468f35b Bluetooth: drivers: h4: Fix uart_fifo_fill return value handling
The return value of uart_fifo_fill could potentially be negative, so
make sure the code doesn't do anything bad in that case.

Fixes #39823

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2021-11-10 14:17:50 +01:00
Johan Hedberg cc2d5f8a45 Bluetooth: drivers: h4: Fix uart_fifo_read return value handling
Make sure negative error returns from uart_fifo_read() are correctly
handled.

In the same go, the logic of reading packet headers (ACL/event/ISO) is
refactored into its own helper function. This also fixes having an
appropriate name for the variable that tracks how many header bytes have
already been read (it was called "to_read" and now it's called
"bytes_read").

Fixes #39805

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2021-11-10 14:17:50 +01:00
Torsten Rasmussen 9a2be89557 kconfig: bluetooth: experimental settings now uses select EXPERIMENTAL
With the introduction of `EXPERIMENTAL` and `WARN_EXPERIMENTAL` in
Zephyr all subsys/bluetooth and drivers/bluetooth/hci settings having
`[EXPERIMENTAL]` in their prompt has has been updated to include
`select EXPERIMENTAL` so that developers can enable warnings when
experimental features are enabled.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-10-22 13:59:21 +02:00
Torsten Rasmussen 6ebe0b8425 drivers: create BT_DRIVERS Kconfig entry
Fixes: #38403

Changing Bluetooth drivers from being a menu into a menuconfig.
This aligns the Bluetooth driver configuration with other driver
configurations as well as provides a setting which identifies if
Bluetooth drivers has been enable.

This further helps to avoid empty Zephyr libraries for bluetooth
samples.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-09-28 12:13:23 +02:00
Johann Fischer 9ad610d1a7 bluetooth: remove Kconfig options CONFIG_BT_*_ON_DEV_NAME
Follow up on commit bfd45e5b8c
("drivers: remove Kconfig option CONFIG_UART_CONSOLE_ON_DEV_NAME")
Remove Kconfig options
CONFIG_BT_UART_ON_DEV_NAME and CONFIG_BT_MONITOR_ON_DEV_NAME
since all UART drivers are converted to devicetree and we can just use
DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_uart)) and
DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_mon_uart)).

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-25 18:05:17 -04:00
Alexandre Bourdiol 29d1e90a8d drivers: bluetooth: hci: ipm_stm32wb: macro renamed CFG_BLE_OPTIONS
Adapt to stm32hal stm32wb cube update v1.12.0

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2021-08-24 22:14:20 -04:00
Daniel Leung 378ad046c8 drivers: bluetooth: build as static library
Instead of putting object files inside libzephyr.a,
simply build a separate static library as most other
driver types are doing this already.

Note that the include to subsys/bluetooth has been
moved from under drivers/bluetooth to subsys/bluetooth,
as it is actually the subsystem's job to make sure
the include directories are correct.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-17 06:06:03 -04:00
Martin Jäger ecef16aa86 bluetooth: hci: esp32: Fix DBG logging
The log level was always set to debug. Defining BT_DBG_ENABLED same
as for other bluetooth files allows to switch off debug log messages.

Signed-off-by: Martin Jäger <martin@libre.solar>
2021-08-16 11:44:10 +02:00
Felipe Neves 2474c9b3f3 soc: riscv: esp32c3: added initial support for ble
subsystem by linking esp32 vhci adapter to the
espressif ble controller adapter

Signed-off-by: Felipe Neves <felipe.neves@espressif.com>
2021-08-07 19:59:27 -04:00
Francois Ramu 2790d2ac4c drivers: bluetooth: hci driver for stm32wb includes clock control
The definition of the STM32_LSE_CLOCK is given by the
drivers/clock_control/stm32_clock_control.h
to the hci/ipm_stm32wb driver

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2021-06-18 07:59:48 -05:00
Casper Bonde afe469eac7 Bluetooth: ISO: Speed up BT ISO data processing
For the native posix build the sleep calls used in tasks will stall
the zephyr instance which sets an upper limit on the data processing
interval to once every 20-30 millisecond.
This change reduces the duration of the sleep calls and increases the
TICKS_PER_SECOND to allow for shorter sleeps. This is needed to
support the data rates needed for LE Audio streaming. The rate is
tuned to support up to bidirectional 5ms ISO-intervals.
This change also increases the ISO buffer count from 1 to 5 to
allow for some buffering in the controller, which is needed for
gapless playback and/or use of burst number larger than 1.

Signed-off-by: Casper Bonde <casper_bonde@bose.com>
2021-05-27 13:16:40 +02:00
Alexandre Bourdiol c3d35d89a3 drivers: bluetooth: hci: increase spi_rx_stack
Thread analyze:
 BT SPI RX : STACK: unused 216 usage 296 / 512 (57 %)

Fixes #34601

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2021-05-13 22:07:45 -04:00
Joakim Andersson 597080204e drivers: Bluetooth: Update H5 driver to new delayable work API.
Update the Bluetooth H5 driver to use the new delayable work API.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-05 19:44:09 -04:00
Sylvio Alves a3c35c93ff driver: esp32: add bluetooth support
Add support to BLE and BR/EDR feature.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2021-04-30 16:51:30 -04:00
Erwan Gouriou 2691541ad2 drivers/clock_controller: stm32: Prepare for dts based configuration
To allow transition to device tree based clock configuration on
stm32 targets, rework clock_control driver to use intermediate
STM32_ macros initially defined as the equivalent Kconfig macros
for now.
Propagate the change in all code using these macros.

The reason to introduce these new macros instead of configuring
Kconfig flags using dt kconfigfunctions is that we'll need
to be able to inform users that Kconfig flags are deprecated
once the whole family conversion is done, to encourage
out of tree users to adopt this new configuration scheme.

Note: For now STM32H7 series and code is excluded.
This is the same for some series specific code such as
PLL mul/div for L0/L1 and XTRE prescaler on F1 series.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-04-27 11:53:37 +02:00
Pete Skeggs ecfda097d1 bluetooth: hci: h4: Add thread name
Add a name to the h4 rx thread.

It's useful to put a name on each thread for debugging, e.g., with the
shell's kernel threads command.

Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
2021-03-04 13:17:02 +01:00
Hubert Miś 5548917e69 bluetooth: hci: rpmsg: Use RPMsg Service
This patch modifies Bluetooth HCI RPMsg drivers and samples to use
RPMsg Service instead of configuring OpenAMP directly in the driver
or the sample.

Co-authored-by: Piotr Szkotak <piotr.szkotak@nordicsemi.no>
Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2021-01-19 22:07:09 +01:00
Emil Gydesen 69d8b0a0b4 drivers: bluetooth: hci: Add support for ISO packets in rpmsg
This adds supports for ISO packets so then can be transmitted and
received with rpmsg driver.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-01-15 11:39:09 -05:00
Lingao Meng 8b54f08a69 drivers: bluetooth: Add discard mechanism to avoid waiting timeout
The Bluetooth receiving thread may not be able to process broadcast
packets because the system API(bt_hci_cmd_send_sync) is in block state.
If HCI driver is still waiting buffer for adv report, an assertion will
be triggered.

Fixes: #30955

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-01-07 14:44:13 +02:00
Rubin Gerritsen 75de21b3d6 drivers: bluetooth: Add timeout to rpmsg init
Previously, when opening the Bluetooth driver on the app core of
nRF53, the application could hang forever. This would happen if
the network core was not flashed or flashed with the wrong firmware.

This commit improves the user experience timing out if the net core
is not replying. 3 seconds is considered to be more than enough to boot
the network core.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-12-08 12:41:21 +02:00
Erwan Gouriou 6c7380183e drivers/bluetooth: ipm_stm32: Wake up C2 at init
When C2 is powered on, flash erase/write operation requires C1
to share a flash mutex with C2. This can only be done if IPM
communication is set up (SHCI).
Instead of configuring C2 (BLE controller) at on ble open,
do it at driver start up.
This allows flash operations before ble_open.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-11-19 12:35:01 +01:00
Vinayak Kariappa Chettimada cb1cf54406 drivers: Bluetooth: rpmsg: Fix typo in BT_QUIRK_NO_AUTO_DLE use
Use CONFIG_BT_QUIRK_NO_AUTO_DLE as quirk option's
conditional compilation check.

Regression introduced in commit bd7ee86496 ("drivers:
Bluetooth: rpmsg: Add missing BT_QUIRK_NO_AUTO_DLE").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-11-13 10:13:22 +01:00
Vinayak Kariappa Chettimada bd7ee86496 drivers: Bluetooth: rpmsg: Add missing BT_QUIRK_NO_AUTO_DLE
Add BT_QUIRK_NO_AUTO_DLE quirk option for HCI rpmsg driver
when the Zephyr open source BLE controller is used.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-16 12:02:32 +02:00
Jeremy LOCHE 1740dfc8c2 drivers: bluetooth: hci_spi: fix init priority
Fixes #28275 by adding bluetooth HCI spi driver priority lower
(75 instead of 50) than SPI (70) to avoid device_get_binding
to return NULL because the device was not initialized.

Signed-off-by: Jeremy LOCHE <lochejeremy@gmail.com>
2020-09-10 15:57:54 -05:00
Luiz Augusto von Dentz f93c4dece0 Bluetooth: userchan: Add support for ISO packets
This adds supports for ISO packets so then can be transmitted and
received with userchan driver.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-04 21:03:13 +02:00
Luiz Augusto von Dentz bfe580bbbe Bluetooth: H5: Add support for ISO packets
This adds supports for ISO packets so then can be transmitted and
received with H5 driver.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-04 21:03:13 +02:00
Luiz Augusto von Dentz 720bbe208e Bluetooth: H4: Add support for ISO packets
This adds supports for ISO packets so then can be transmitted and
received with H4 driver.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-09-04 21:03:13 +02:00
Erwan Gouriou ce29baa0ef drivers/bluetooth: ipm_stm32wb.c: Increase RX thread stack size
Stack overflows where seen in heavy logging conditions since printk
modifications that increased "slightly" RAM consumption
(973487fdad).

Increase RX Thread stack size to avoid these overflows.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-09-03 14:22:33 -04:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Joakim Andersson 9ac8dcf5a7 Bluetooth: Call bt_recv from priority higher that TX thread.
A build assert in dummy.c lists the following requirement:
[...] receive thread priority shall be higher than the Bluetooth
Host's Tx and the Controller's receive thread priority.
This is required in order to dispatch Number of Completed Packets
event before any new data arrives on a connection to the Host threads.

The drivers uses a priority that is equal to the Host TX thread,
and since they don't use the CONFIG define that is only available
to the controller then this BUILD_ASSERT will not catch the
requirement.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-09-01 15:15:36 +03:00
Andrew Boie 7d920ba39b drivers: use K_KERNEL_STACK macros
None of these threads run in user mode and we can save some
memory.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-04 12:16:43 -04:00
Jeremy LOCHE 74fa8cef21 drivers: bluetooth: hci_spi: add missing gpio_dt_flags to spi_cs_config
Fixes #27280 by adding the new gpio_dt_flags to the
HCI spi cs config.

Signed-off-by: Jeremy LOCHE <lochejeremy@gmail.com>
2020-08-04 16:18:54 +02:00
Tomasz Bursztyka c6706561b9 drivers: Apply IPM callback signature change where relevant
Of course IPM drivers now provide their device instance. There are 2
drivers using IPM callbacks as well, so they get the imp device instance
pointer now through the callback.

Fixes #26923

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-07-30 09:51:51 +02:00
Tomasz Bursztyka 7d1af02410 uart: Fix uart_irq_callback_set usage
It was already using uart_irq_callback_user_data_set below, now it also
uses uart_irq_callback_user_data_t as callback type, so let's normalize
the callbacks.

Fixes #26923

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-07-30 09:43:12 +02:00
Kamil Piszczek d19e21fb01 drivers: bluetooth: rpmsg: validate heap size configuration
Added a build-time assert to check if heap memory configuration to
make sure that it can accomodate RPMsg queue allocations.

Ref: NCSDK-5479

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2020-07-10 13:13:46 +02:00
Joakim Andersson 4be66bd33d Bluetooth: Fix host RX thread deadlock
Fix host RX thread being deadlocked. The deadlock occurs because the
RX thread is stuck waiting in conn_tx_alloc with K_FOREVER but if the
connection is disconnected only the RX thread can unblock it in the
handling of the disconnect event.

This commit fixes this deadlock by splitting the processing of the
disconnected event into two parts.
The part needed to unblock the RX is to release resources held by
unack'ed TX packets and mark the connection state as not connected
anymore.
The RX thread waiting for free_tx fifo and the TX thread waiting for
the bt_dev.le.pkts semaphore will both check the connected state after
having acquired them and will abort if disconnected.
The rest of the processing will be handled at normal RX thread
priority like normal.

Move the bt_recv_prio handling to the Bluetooth host when the host
has defined its own RX thread (CONFIG_BT_RECV_IS_RX_THREAD=n).
If the HCI driver has the RX thread (CONFIG_BT_RECV_IS_RX_THREAD=y),
then the responsibility to call bt_recv and bt_recv_prio correctly
falls to the HCI driver.
The helper function bt_hci_evt_is_prio() is replaced with
bt_hci_evt_get_flags() so that the HCI driver can do this correctly.
This decision to replace was made so that existing HCI drivers
maintained out-of-tree will fail at compile time with the new system.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>

Bluetooth: host: Move bt_recv_prio to host when RX thread is defined

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 11:15:39 +02:00
Thomas Stenersen 7a8ac5e2e6 Bluetooth: hci: Depend on SOC not BOARD
The CONFIG_BT_RPMSG_NRF53 should depend on the SOC, not the BOARD
definition. Otherwise this will break for custom boards.

Signed-off-by: Thomas Stenersen <thomas.stenersen@nordicsemi.no>
2020-06-16 22:12:00 +02:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Erwan Gouriou 6ea53792f4 modules: stm32: Rename lib Kconfig symbol
Both ST and STM32 modules where using same HAS_STLIB Kconfig
symbol.
Now that each module is createing is own lib, we need to be able
to distinguish libs.

Depends on zephyrproject-rtos/hal_stm32/pull/52

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-05-09 13:08:42 +02:00
Ioannis Glaropoulos 9b09f136f7 bluetooth: hci_rpmsg: check SHM_SIZE against shared mem size using DT
Add a build-time assert to check that the configured SHM_SIZE
does not exceed the memory allocated as shared memory. USe DT
to extract the shared memory size.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-05-07 10:07:00 +02:00
Erwan Gouriou de9fd59669 drivers/bluetooth: stm32wb: Fix loop
The goto instruction was removed when adding the RX thread.
While still working, this clearly break the clean handling of
error cases.
Re-instantiate the goto instruction.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-04-30 13:34:15 +02:00
Erwan Gouriou 73a19d4d20 drivers/bluetooth: stm32 ipm: Fix mutex on shared memory
ipm_busy is meant to be used as mutex on transport layer accesses.
Due to wrong configuration on rx_thread, imp_busy was a no-op.
Fix this.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-04-30 13:34:15 +02:00
Joakim Andersson 405ae6bb65 Bluetooth: drivers: Convert bluetooth drivers to use k_timeout struct
Convert bluetooth drivers to use k_timeout struct

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-30 13:46:48 +03:00
Joakim Andersson e9375a2814 Bluetooth: Remove bluetooth thread stack size analysis
Remove logging of individual threads spread out throughout the
bluetooth subsystem. The stacks can be analysed by enabling the
following options.

CONFIG_THREAD_ANALYZER=y
CONFIG_THREAD_ANALYZER_AUTO=y
CONFIG_THREAD_ANALYZER_RUN_UNLOCKED=y
Optional:
CONFIG_THREAD_NAME=y

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-28 09:11:13 -04:00
Erwan Gouriou 57a74653df drivers/bluetooth: ipm_stm32: Implement a RX thread
Fasten events handling by unloading callback treatment.
A RX thread is created. IPM RX events are dumped in a FIFO
which is processed in the thread context.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-04-27 19:02:14 +02:00
Martí Bolívar 5dd0db3081 drivers: bluetooth: rpmsg_nrf53: use new DT API
Use DT_CHOSEN() to access the chosen node.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-04-18 07:52:05 -05:00
Ioannis Glaropoulos 88bf06bb01 boards: arm: nrf5340_dk_nrf5340: rename target to nrf5340pdk_nrf5340
We rename the nRF53 Dev Kit board target (nrf5340_dk_nrf5340)
to nrf5340pdk_nrf5340. We update all associated references
in the supportive documentation and all nRF5340-related
cofigurations and overlay files in the samples and tests
in the tree.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-04-06 15:21:45 +02:00
Kumar Gala 75e28f6de9 drivers: bluetooth: hci: spi: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-30 14:49:27 -05:00
Ulf Magnusson 378d6b137a kconfig: Replace non-defconfig single-symbol 'if's with 'depends on'
Same deal as in commit eddd98f811 ("kconfig: Replace some single-symbol
'if's with 'depends on'"), for the remaining cases outside defconfig
files. See that commit for an explanation.

Will do the defconfigs separately in case there are any complaints
there.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-02-12 10:32:34 -06:00
Andrew Boie efc5fe07a2 kernel: overhaul unused stack measurement
The existing stack_analyze APIs had some problems:

1. Not properly namespaced
2. Accepted the stack object as a parameter, yet the stack object
   does not contain the necessary information to get the associated
   buffer region, the thread object is needed for this
3. Caused a crash on certain platforms that do not allow inspection
   of unused stack space for the currently running thread
4. No user mode access
5. Separately passed in thread name

We deprecate these functions and add a new API
k_thread_stack_space_get() which addresses all of these issues.

A helper API log_stack_usage() also added which resembles
STACK_ANALYZE() in functionality.

Fixes: #17852

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-02-08 10:02:35 +02:00
Peter Bigot f591f3e0bf drivers: bluetooth: hci: replace deprecated gpio_pin callback API
gpio_pin_en/disable_callback are to be replaced by
gpio_pin_interrupt_configure.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-02-05 12:00:36 +01:00
Peter Bigot ddc3f0699f gpio: replace gpio pin write/read with set/get
This API will be deprecated in favor of the new API that clearly
specifies whether it works on logical or physical levels.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-02-05 12:00:36 +01:00
Erwan Gouriou bfc1a50eb9 drivers: hci: spi: update to new GPIO API
Update bluetooth hcp spi driver to new GPIO API.
Following changes have been done:
- Use new gpio api functions
- Get reset, irq and cs flags from dt defines
- Define reset pin as active low and invert set/unset logic.

Tested on disco_l475_iot1 and 96b_carbon.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-02-05 12:00:36 +01:00
Peter Bigot 5e486b98b1 treewide: use full path to ipm.h header
The build infrastructure should not be adding the drivers subdirectory
to the include path.  Fix the legacy uses that depended on that
addition.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-01-26 17:52:12 +01:00
Carles Cufi 6cf7ac77bf Bluetooth: Always use full path to hci_driver.h
The path to include/drivers should not be in the compiler include path
list, only include/. In order to make this possible, always explictly
refer to hci_driver.h via the drivers/bluetooth/ path and not only
bluetooth/.

Fixes #21974.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-01-16 19:20:39 -05:00
Håkon Øye Amundsen 311b31d9f4 Bluetooth: select BT_RPMSG_NRF53 for non-secure variant of nrf5340
Prior to this you would get compilation error when building
samples for the nrf5340_dk_nrf5340_cpuappns board.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2020-01-10 16:33:00 +01:00
Ulf Magnusson 6ef29c0250 kconfig: Remove some redundant single-item menus and ifs
A single menu within an if like

    if FOO

    menu "blah"

    ...

    endmenu

    endif

can be replaced with

    menu "blah"
            depends on FOO

    ...

    endmenu

Fix up all existing instances.

Also remove redundant extra menus underneath 'menuconfig' symbols.
'menuconfig' already creates a menu.

Also remove the menu in arch/arm/core/aarch32/Kconfig around the
"Floating point ABI" choice. The choice depends on FLOAT, which depends
on CPU_HAS_CPU, so remove the 'depends on CPU_HAS_FPU' too.

Piggyback removing a redundant 'default n' for BME280.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-21 10:26:54 -05:00
ZhongYao Luo 6412c070eb bluetooth: h5: sending priority events through bt_recv_pri
By default all events are processed through bt_recv, which results
in lost events and subsys/bluetooth/hci_core.c:hci_event function
assertions fail to pass

Signed-off-by: ZhongYao Luo <LuoZhongYao@gmail.com>
2019-12-09 17:04:24 +02:00
ZhongYao Luo 994246f7c6 bluetooth: h5: Handling the the zero length ack packet
If H5_HDR_LEN is equal to zero, remaining will grow
negatively, the commit fixes the problem.

Signed-off-by: ZhongYao Luo <LuoZhongYao@gmail.com>
2019-12-09 17:04:24 +02:00
ZhongYao Luo 5758a9e1c6 bluetooth: h5: Fix memory access error
According to the context information, the processing of
net_buf_add_u8 within the get_evt_buf function is
redundant and incorrect.

Signed-off-by: ZhongYao Luo <LuoZhongYao@gmail.com>
2019-12-09 17:04:24 +02:00
Kamil Piszczek 362f2299cd drivers: bluetooth: hci: rpmsg: fix handling of hci events
Fixed handling of HCI events in the HCI driver over RPMsg. Now,
the driver makes use of discardable buffer pool when allocating
memory for certain HCI event types (e.g. Advertising Report Event).
Applications that are flooded with Advertising Reports will run
much better after this change (e.g. Mesh applications).

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-11-28 10:55:32 +02:00
Kamil Piszczek 83107e5ffd drivers: bluetooth: hci: driver based on RPMsg transport
This commit contributes an RPMsg-based transport for BLE HCI.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-11-20 19:29:06 +01:00
Johan Hedberg d67416321e Bluetooth: hci_raw: Add support for specifying buffer headroom
The HCI transport implemented by an application using the HCI raw
interface may have its own buffer headroom requirements. Currently the
available headroom gets completely determined by the selected HCI
driver. E.g. most of the time this is the native controller driver
which doesn't reserve any headroom at all.

To cover for the needs of HCI raw users, add a new Kconfig variable
for the apps to set to whatever they need. Correspondingly, use the
maximum of the HCI driver and HCI raw headroom requirements for the
buffer pool definitions and the headroom initializations.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-11-20 19:29:06 +01:00
Ulf Magnusson bd6e04411e kconfig: Clean up header comments and make them consistent
Use this short header style in all Kconfig files:

    # <description>

    # <copyright>
    # <license>

    ...

Also change all <description>s from

    # Kconfig[.extension] - Foo-related options

to just

    # Foo-related options

It's clear enough that it's about Kconfig.

The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)

    git ls-files '*Kconfig*' | \
        xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-04 17:31:27 -05:00
Marcio Montenegro 5634d70374 drivers: hci: stm32_ipm: add UID BLE address
The STM32WB has a 64 bit Unique Device Number UID.
The UID is used by firmware to derive 48-bit
Device Address EUI-48.

Signed-off-by: Marcio Montenegro <mtuxpe@gmail.com>
2019-11-04 16:40:01 +01:00
Pavlo Hamov 3674d3343f drivers: hci: stm32_ipm: disable proper LSI
LSI1 is used for RTC, LTC2 for RF.
Disable LSI2 instead of LSI1 on BLE with LSE start

Signed-off-by: Pavlo Hamov <pavlo_hamov@jabil.com>
2019-10-18 08:24:42 -05:00
Pavlo Hamov 535bfeb784 drivers: hci: stm32_ipm: Add possibility to work on LSI
Use CLOCK_STM32_LSE as switch for the RF low speed clock source

Signed-off-by: Pavlo Hamov <pavlo_hamov@jabil.com>
2019-10-18 08:24:42 -05:00
Peter Bigot 6e5db350b2 coccinelle: standardize k_sleep calls with integer timeouts
Re-run with updated script to convert integer literal delay arguments to
k_sleep to use the standard timeout macros.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-10-09 08:38:10 -04:00
Pavlo Hamov 82ed1681f0 drivers: ipm_stm32wb: add workaround for conn_complete
Enhanced connection complete message lacks of
the peer address (FF::FF), which leads to pairing/bonding failure.

Fixes: #19509

Signed-off-by: Pavlo Hamov <pavlo_hamov@jabil.com>
2019-10-04 18:47:31 -07:00
Kumar Gala 8ce0cf0126 kconfig: Convert device tree chosen properties to new kconfigfunctions
Convert how we get the various chosen properties like "zephyr,console"
to use the new kconfig functions like dt_chosen_to_label.

Because of how kconfig parses things we define a set of variables of the
form DT_CHOSEN_Z_<PROP> since comma's are parsed as field seperators in
macros.

This conversion allows us to remove code in gen_defines.py for the
following chosen properties:

zephyr,console
zephyr,shell-uart
zephyr,bt-uart
zephyr,uart-pipe
zephyr,bt-mon-uart
zephyr,uart-mcumgr
zephyr,bt-c2h-uart

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-09-13 11:42:34 -05:00
Roger N'Guessan 1c7eecb1ed Bluetooth: drivers: ipm_st32wb: Fix compilation
Issue faced while running bluetooth sample (peripheral, central, ...)

on stm32wb55rg with the latest zephyr version

Signed-off-by: Roger N'Guessan <roger.nguessan@st.com>
2019-07-09 21:35:44 +03:00
Yaël Boutreux 3704e8b8b4 drivers: bluetooth: hci: spi: Handle when the buffer is empty
Check if the buffer size is not empty before spi transceive and buffer's
data processing. This fixes the need to slow down MCUs to 16MHz when
using BlueNRG-MS chips.
Tested samples : Beacon, Central, Peripheral

Signed-off-by: Yaël Boutreux <yael.boutreux@st.com>
Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@st.com>
Signed-off-by: Alexandre Torgue <alexandre.torgue@st.com>
2019-07-04 09:22:18 -04:00
Johan Hedberg 0d9dab300e Bluetooth: Introduce separate pool for discardable events
Introduce a separate buffer pool for events which the HCI driver
considers discardable. Examples of such events could be e.g.
Advertising Reports. The benefit of having such a pool means that the
if there is a heavy inflow of such events it will not cause the
allocation for other critical events to block and may even eliminate
deadlocks in some cases.

Also update all mesh samples not to specify explicit RX buffer counts
anymore. Instead, create appropriate defaults in Kconfig so that we
only need to override this in the app for cases like the bbc:microbit
with limited memory.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-07-01 16:36:15 +03:00
Johan Hedberg fc2fcd10cf Bluetooth: Add dedicated pool for HCI_Num_Completed_Packets HCI event
This event is a priority one, so it's not safe to have it use the RX
buffer pool which may be depleted due to non-priority events (e.g.
advertising events). Since the event is consumed synchronously it's
safe to have a single-buffer pool for it. Also introduce a new
bt_buf_get_evt() API for HCI drivers to simplify the driver-side code,
this effectively also deprecates bt_buf_get_cmd_complete() which now
has no in-tree HCI driver users anymore.

Fixes #16864

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-07-01 16:36:15 +03:00
Anas Nashif efb8df5366 cleanup: include/: move misc/stack.h to debug/stack.h
move misc/stack.h to debug/stack.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5d001f3e41 cleanup: include/: move misc/byteorder.h to sys/byteorder.h
move misc/byteorder.h to sys/byteorder.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif d1b2718687 cleanup: include/: move uart.h to drivers/uart.h
move uart.h to drivers/uart.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif bd70f6f1ed cleanup: include/: move spi.h to drivers/spi.h
move spi.h to drivers/spi.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 6aa9c3a68f cleanup: include/: move gpio.h to drivers/gpio.h
move gpio.h to drivers/gpio.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Kumar Gala a614a026b7 dts: Rename DT_.*_GPIO_* to DT_.*_GPIOS_*
Convert DT_.*_GPIO_{CONTROLLER,PIN,FLAGS} ->
	DT_.*_GPIOS_{CONTROLLER,PIN,FLAGS)

Used the following commands to make these conversions:

git grep -l DT_.*_GPIO_CONTROLLER | xargs sed -i 's/DT_\(.*\)_GPIO_CONTROLLER/DT_\1_GPIOS_CONTROLLER/g'
git grep -l DT_.*_GPIO_PIN | xargs sed -i 's/DT_\(.*\)_GPIO_PIN/DT_\1_GPIOS_PIN/g'
git grep -l DT_.*_GPIO_FLAGS | xargs sed -i 's/DT_\(.*\)_GPIO_FLAGS/DT_\1_GPIOS_FLAGS/g'

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-06-27 13:02:34 -05:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
Erwan Gouriou afb4e4ff0f drivers: spi hci: Add spi dedicated rx thread
Get spi hci driver to define its own rx thread, in order
not to mix with bt own RX thread as driver use bt_recv_prio
that expect to be used in a different thread than BT host one.

Fixes #15714

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-06-17 03:17:08 -04:00
Kumar Gala a2693975d7 dts: Convert from DT_<COMPAT>_<INSTANCE>_<PROP> to DT_INST...
Change code from using now deprecated DT_<COMPAT>_<INSTANCE>_<PROP>
defines to using DT_INST_<INSTANCE>_<COMPAT>_<PROP>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-06-14 08:02:15 -05:00
Anas Nashif 4c32258606 style: add braces around if/while statements
Per guidelines, all statements should have braces around them. We do not
have a CI check for this, so a few went in unnoticed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-06 15:20:21 +02:00
Erwan Gouriou 3d9416bfed drivers/bluetooth/hci: Implement HCI driver for stm32wb
Implement HCI driver for STM32WB. It allows host to controller.
It is based on ST library allowing communication over RAM shared
bewteen chip's C-M4 and C-M0 cores.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-06-03 09:38:19 -04:00
Carles Cufi bca3deb1e7 drivers: Bluetooth: Generalize IC-specific setup hook
In order to generalize the currently specialized nRF51 IC setup hook,
make the following changes:

- Generalize the hook to bt_ic_setup()
- Use a weak NOP version by default
- Move the currently existing one to the board folder

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-04-19 12:21:21 +02:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Patrik Flykt 97b3bd11a7 drivers: Rename reserved function names
Rename reserved function names in drivers/ subdirectory. Update
function macros concatenatenating function names with '##'. As
there is a conflict between the existing gpio_sch_manage_callback()
and _gpio_sch_manage_callback() names, leave the latter unmodified.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Kumar Gala ff70b3444f dts: Convert CONFIG_ to DT_ symbols for chosen props
Replace generating CONFIG_ symbols with DT_ symbols for chosen
properties like 'zephyr,console' or 'zephyr,bt-mon-uart'.  We now use a
kconfigfunctions (dt_str_val) to extract the info from dts into Kconfig.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 11:41:26 -06:00
Andrzej Głąbek c047e8e469 drivers: bluetooth: hci_spi: Use DT instead of Kconfig to get HW params
Convert the HCI SPI driver to get the SPI and GPIO settings from Device
Tree instead of Kconfig. The "zephyr,bt-hci-spi" binding is used as
a common one for this purpose ("st,spbtle-rf" is removed), to take
advantage of the new DT_<COMPAT>_<INSTANCE> generated macros and get
rid of related fixups and aliases.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-02-01 19:12:57 -05:00
Patrik Flykt 8ff96b5a57 drivers: Add 'U' to unsigned variable assignments
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Kumar Gala aa2bdbe322 drivers: Remove board.h include
We either don't need board.h in the driver or we should be include soc.h
instead.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-01 13:21:11 -04:00
Kumar Gala ef1cc3f488 bluetooth: hci: spi: Fix compile warning
drivers/bluetooth/hci/spi.c: In function ‘bt_spi_open’:
drivers/bluetooth/hci/spi.c:475:31: error: passing argument 2 of ‘gpio_init_callback’ from incompatible pointer type [-Werror=incompatible-pointer-types]
  gpio_init_callback(&gpio_cb, bt_spi_isr, BIT(GPIO_IRQ_PIN));
                               ^~~~~~~~~~
In file included from drivers/bluetooth/hci/spi.c:9:0:
include/gpio.h:247:20: note: expected ‘gpio_callback_handler_t {aka void (*)(struct device *, struct gpio_callback *, long unsigned int)}’ but argument is of type ‘void (*)(struct device *, struct gpio_callback *, unsigned int)’
 static inline void gpio_init_callback(struct gpio_callback *callback,
                    ^~~~~~~~~~~~~~~~~~

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-10-29 10:52:00 -04:00
Johan Hedberg 251d99132d Bluetooth: Remove custom stack macros
Now that log processing happens in a separate thread, the
BT_STACK_EXTRA macro is not needed (since there's no significant
overhead), and therefore the BT_STACK macros become unnecessary as
well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Johan Hedberg 343c53e841 Bluetooth: Switch from SYS_LOG to logger-based logging
Initial conversion to use syslog instead of logger.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-10-19 14:50:22 +02:00
Maureen Helm ad32e3b543 drivers: boards: Merge HAS_DTS_SPI_PINS with HAS_DTS_SPI
Every board that uses dts-enabled spi drivers has a board-level dts, so
there is no need to have separate configs HAS_DTS_SPI_PINS and
HAS_DTS_SPI.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2018-10-01 21:15:06 -05:00
Maureen Helm 89ccead382 drivers: boards: Merge HAS_DTS_SPI_DEVICE with HAS_DTS_SPI
Every board that uses dts-enabled spi drivers has a board-level dts, so
there is no need to have separate configs HAS_DTS_SPI_DEVICE and
HAS_DTS_SPI.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2018-10-01 21:15:06 -05:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Alberto Escolar Piedras 304f26c310 Bluetooth: Userchan: Add missing headers
Added 2 missing headers in drivers/bluetooth/hci/userchan.c
(used by read,write and strtol)

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-08-02 19:14:19 +02:00
Ulf Magnusson d1684a83a4 Kconfig: Clean up some symbol definitions
- Remove redundant 'n' defaults. 'n' is the default value for bool
  symbols.

  This makes the auto-generated documentation clearer as well: You get
  "implicitly defaults to n" instead of
  "- n if <propagated dependencies>".

- Shorten

      <type>
      prompt "foo"

  to

      <type> "foo"

  This works for all types, not just bool.

- Various formatting nits.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-01 12:47:17 -04:00
Alberto Escolar Piedras 55f6620c3e native_posix: Refactor cmd line options
For each driver/model with command line options.
Move its code for the board file into the driver/model file.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-07-30 22:13:46 -04:00
Ulf Magnusson 3e0a900a31 drivers: bluetooth: Kconfig: Remove redundant 'default n' properties
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though, and is
inconsistent.

This will make the auto-generated Kconfig documentation have "No
defaults. Implicitly defaults to n." as well, which is clearer than
'default n if ...'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-03 17:11:31 -04:00
Christophe Priouzeau b0c294ce48 bt: hci driver over spi: Configure BlueNRG-MS in controller mode
Configure BlueNRG in controller w/o host.
By disabling 'HCI_reset' via the quirk, we can request to
BluesNRG hardware to be on controller mode just after it is ready.
By the way it's no necessary to manage a 'HCI_reset' when BluesNRG are
initialised (and on controler mode).

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2018-06-29 10:40:25 +02:00
Christophe Priouzeau 7b02e6dc55 bt: hci driver over spi: BlueNRG-MS read until IRQ pin goes low
According to BlueNRG-MS ref manual, SPI master shoul read  from
controller as long as IRQ pin is high.
Introduce a new loop within spi_rx_thread to do so. Since
it is now possible to enter read loop with nothing to read, set
a max attempts limit to be sure to exit the loop.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
2018-06-29 10:40:25 +02:00
Loic Poulain ea5b866763 Bluetooth: hci: spi: Select BT_RECV_IS_RX_THREAD
SPI driver has its own rx thread, select BT_RECV_IS_RX_THREAD.
This fixes build issue because of undefined CONFIG_BT_RX_PRIO.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-06-11 17:28:27 -04:00
Johan Hedberg 7d9896575b Bluetooth: Add HCI User Channel driver for native POSIX port
Introduce a custom HCI driver for the native POSIX port, which opens a
HCI User Channel socket to the Linux kernel to gain access to a local
Bluetooth controller.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-06-11 17:14:43 -04:00
Yannis Damigos 82c0b8cba1 drivers/bluetooth/hci: Name the choice of BT HCI driver bus
Name the choice of BT HCI driver bus in order to config it
in the board's Kconfig.defconfig file.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-15 15:11:12 -05:00
Erwan Gouriou 00376f08ca dts/bindings: Add reset and irq gpios to "st,spbtle-rf" yaml
In order to generate GPIO definition for control pin of BlueNRG module
define reset-gpio and irq-gpio in st,spbtle-rf yaml binding.

Add HAS_DTS_SPI_PINS kconfig symbol to control use of the '#define'

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2018-05-10 14:21:16 -05:00
Tomasz Bursztyka 3219817d4a drivers/bluetooth: Get rid completely of legacy SPI API in SPI HCI
No need to support legacy API there.
The special usage of CS in BlueNRG is centralized it dedicated functions
to avoid all the #ifdefs everywher.
Also managing transaction error.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-04 19:02:35 +02:00
Tomasz Bursztyka 595340ab8a drivers/bluetooth: Switch SPI based HCI driver to new SPI API
Replacing legacy API calls by news ones.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-04-04 19:02:35 +02:00
Yannis Damigos 8faa307d74 dts: add spi device support for SPI bluetooth modules
Provides HAS_DTS_SPI_DEVICE flag to enable dts based
generation for SPI bluetooth modules

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-01-22 18:08:51 -06:00
Carles Cufi 7d764b35f3 cmake: Use path-corrected version of ZEPHYR_BASE
Instead of accessing the environment variable ZEPHYR_BASE every time we
require accessing the source code root, use an intermediate variable
that has OS path separators correctly set to '/' to avoid issues on
Windows.

Note: This removes the ZEPHYR_SOURCE_DIR CMake variable. External
applications using that will need to change to use the new ZEPHYR_BASE
variable.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-01-11 14:59:03 -05:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Tomasz Bursztyka 5f1360e27d drivers/bluetooth/spi: Do not initialize vendor attribute
As commit introducing it will be reverted.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-10 09:42:45 -04:00
Marti Bolivar 272e8ffccd Bluetooth: hci: spi: add support for new SPI API
Add shim routines for the new SPI driver API.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-15 22:58:02 +03:00
Marti Bolivar bd5c2c07b3 Bluetooth: hci: spi: abstract out legacy SPI API
Some targets (e.g. STM32-based boards) only have SPI drivers using the
new API. To support both these and existing, legacy SPI drivers in the
SPI HCI driver, abstract out the SPI API into shim routines.

There are no behavioral differences due to this patch. The next patch
will add support for the new API.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-15 22:58:02 +03:00
Carles Cufi d5c13a7530 Bluetooth: controller: Rename Kconfig prefix
Rename the BT_CONTROLLER prefix used in all of the Kconfig variables
related to the Bluetooth controller to BT_CTLR.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-14 15:44:56 +03:00
Sebastian Bøe c4176c6526 Kconfig: Hide the "Bluetooth Drivers" menu entry when BT_CONTROLLER
It used to be that there was a fairly empty "Bluetooth Drivers" menu
entry in the drivers menu. This entry was present even though there
was no drivers/bluetooth code being compiled in.

With this patch "Bluetooth Drivers" will no longer be present when
BT_CONTROLLER is enabled.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-08-09 19:06:14 +03:00
Sebastian Bøe 2120beebf4 Kconfig: Move BT_WAIT_NOP into subsys/bluetooth/host
The CONFIG_BT_WAIT_NOP define is used only by
zephyr/subsys/bluetooth/host/hci_core.c.

It is also the only config in drivers/bluetooth that is in use when
BT_CONTROLLER is enabled. Moving it into the bluetooth subsystem
allows us to restructure the drivers/kconfig code such that the entire
Bluetooth driver menu option is omitted when the BT_CONTROLLER is
enabled.

Moving it will also mean that all configs in drivers/bluetooth will
now be related to configuring the source code in drivers/bluetooth.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-08-09 19:06:14 +03:00
Johan Hedberg 2975ca0754 Bluetooth: Kconfig: Rename CONFIG_BLUETOOTH_* to CONFIG_BT_*
The API name space for Bluetooth is bt_* and BT_* so it makes sense to
align the Kconfig name space with this. The additional benefit is that
this also makes the names shorter. It is also in line with what Linux
uses for Bluetooth Kconfig entries.

Some Bluetooth-related Networking Kconfig defines are renamed as well
in order to be consistent, such as NET_L2_BLUETOOTH.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-09 11:14:19 +03:00
Sebastian Bøe 197e6e2ba3 Kconfig: Move BLUETOOTH_HCI_RESERVE into subsys/bluetooth/host
There are two kinds of HCI implementations. Bluetooth drivers in
 drivers/bluetooth that implement HCI by using a wired serial
 transport layer to talk to an external controller chip. And a
 bluetooth controller in subsys/bluetooth/controller that directly
 talks to an internal on-chip controller node.

Currently, when the the subsys/bluetooth/controller is used there
still exists exposed to the user a bluetooth driver configuration
menu, even though no external bluetooth driver is in use. This is due
to a dependency on certain configs in driver/bluetooth that are needed
even though no external controller is used.

This patch moves one of these configs, BLUETOOTH_HCI_RESERVE, from
drivers/bluetooth/hci/Kconfig to subsys/bluetooth/host/Kconfig such
that eventually we can omit the entire Bluetooth driver menu option.

This re-organization does not change when the config can be enabled.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-08-08 23:01:05 +03:00
Savinay Dharmappa c1e5cbfd41 devicetree: Generate BLUETOOTH_UART,UART_PIPE etc config from dt
patch uses chosen property zephyr,bt-uart, zephyr,uart-pipe
and zephyr,bt-mon-uart to determine the uart instance to be
used for bluetooth,uart_pipe and bluetooth_monitor and generate
appropriate configs.

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2017-07-19 11:52:35 -04:00
Vinayak Kariappa Chettimada 9a13a0c732 Bluetooth: Add BUILD_ASSERT to check Tx and Rx thread priorities
Added BUILD_ASSERT check for Tx and Rx thread priorities.

The Tx thread priority shall be higher than Rx thread
priority in order to correctly detect transaction violations
in ATT and SMP protocols. The Number of Completed Packets
for a connection shall be processed before any new data is
received and processed for that connection.

The Controller's priority receive thread priority shall be
higher than the Host's Tx and the Controller's Rx thread
priority.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-12 13:50:51 +03:00
Andrew Boie 65a9d2a94a kernel: make K_.*_INITIALIZER private to kernel
Upcoming memory protection features will be placing some additional
constraints on kernel objects:

- They need to reside in memory owned by the kernel and not the
application
- Certain kernel object validation schemes will require some run-time
initialization of all kernel objects before they can be used.

Per Ben these initializer macros were never intended to be public. It is
not forbidden to use them, but doing so requires care: the memory being
initialized must reside in kernel space, and extra runtime
initialization steps may need to be peformed before they are fully
usable as kernel objects. In particular, kernel subsystems or drivers
whose objects are already in kernel memory may still need to use these
macros if they define kernel objects as members of a larger data
structure.

It is intended that application developers instead use the
K_<object>_DEFINE macros, which will automatically put the object in the
right memory and add them to a section which can be iterated over at
boot to complete initiailization.

There was no K_WORK_DEFINE() macro for creating struct k_work objects,
this is now added.

k_poll_event and k_poll_signal are intended to be instatiated from
application memory and have not been changed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-07-10 11:44:56 -07:00
Johan Hedberg ca61452b8e Bluetooth: drivers: Make RX thread priority consistent
The controller and host-side RX threads recently had their priorities
lowered to 8. Make the driver RX threads consistent with this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-07 10:43:58 -07:00
Andy Gross 2920815d23 bluetooth: hci: Kconfig: Fix dependency
This patch changes the BLUETOOTH_SPI to depend on SPI.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2017-06-15 16:14:59 -05:00
Andrew Boie 2d4a36fc1c drivers: use K_THREAD_STACK_DEFINE macros
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-06-09 18:53:28 -04:00
Johan Hedberg 9516d63836 Bluetooth: Remove support for NBLE
NBLE has been deprecated for a few releases now and can be removed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-25 09:03:16 -07:00
Carles Cufi 6c9e563c92 Bluetooth: Move common code to common/
Since more and more code is going to be reused by both the Host and the
Controller, this commit introduces a common/ folder that will contain
everything that is not tied to one of the two components but shared by
them.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-12 12:56:14 +03:00
Andrew Boie 899cf94dbd bluetooth: use k_thread_create()
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-11 20:24:22 -04:00
Carles Cufi 8a7eeeb7f1 Bluetooth: Move HCI driver debug to top-level Kconfig
Since the HCI driver debug option applies to both files in
drivers/bluetooth and subsys/bluetooth, the configuration option itself
now lives in the top-level Kconfig file for consistency.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-10 08:23:25 +03:00
Johan Hedberg 70e09b11ea Bluetooth: Introduce buffer type parameter to bt_buf_get_rx
This is preparation for re-introducing host flow control.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-04 16:38:34 +03:00
Johan Hedberg 97f0241c07 Bluetooth: Fix alignment issues resulting from new integer types
The switch from C99 integer types to u16_t, etc. caused misalignment
in structs and function definitions with multi-line parameter lists.

Change-Id: Ic0e33dc199f834ad7772417bca4c0b2d2f779d15
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-29 11:39:13 -04:00
David B. Kinder 93e4d7258d spell: fix Kconfig help typos: /boards /drivers
Fix misspellings in Kconfig help text

Change-Id: I3ae28a5d23d8e266612114bc0eb8a6e158129dc7
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-21 21:31:30 +00:00
Kumar Gala d0eb235510 Bluetooth: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: I8f57a17f78e674aca5400f005db8975c9f9e150e
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-20 13:25:23 -05:00
Kumar Gala 789081673f Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t.  This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.

We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.

We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.

Jira: ZEP-2051

Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-20 16:07:08 +00:00
David B. Kinder 896cf7a00a spell: fix doxygen comment typos: /drivers
Fix doxygen comment typos used to generate API docs

Change-Id: I6fd5051c99bdcc731740c92001e525349c254d85
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-19 10:45:34 -07:00
Anas Nashif 306e15e0a1 kernel: remove legacy kernel support
Change-Id: Iac1e21677d74f81a93cd29d64cce261676ae78a6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-04-19 15:48:37 +00:00
Johan Hedberg 5517893543 Bluetooth: Make bt_hci_driver instances link-time constants
Declaring these as const lets the linker generate more optimal code.
Some extra care is needed with hci_ecc.c since it was overwriting the
send callback. Now the choice of send() call is done directly in the
bt_send() function

Change-Id: Iac74f5ee9bee097bbb34c11bd13d1d886700f5cc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Prasanna Karthik 6545aa3f52 Bluetooth: nble: Catch and handle non-zero fn_index
Avoid multiple breaks and gracefully catch non-zero values of fn_index

Change-Id: I1cf7b271b8478e63af2da1f40b4caceb63d7ce90
Signed-off-by: Prasanna Karthik <pkarthik@intrinsyc.com>
2017-02-10 12:03:09 +00:00
Jonathan Gelie 048a15bcc8 Bluetooth: GATT: fixing unsubscription
If subcription was found within the subscription list,
we have check if remains identical subscription
from the next node.
Otherwise none unsubscription is realized.

Change-Id: I38132d7c80575801885b8057902f3d4666b08aea
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-08 11:00:06 +00:00
Jonathan Gelie a42e4f694f Bluetooth: GATT: set subscribe value to zero for unsubscription
Subscribe value is set to zero before calling notify callback,
to distinguish a subscription failure from an unsubscription
on disconnection (when flag BT_GATT_SUBSCRIBE_FLAG_VOLATILE is set).

Change-Id: Ia91220492d82041b2c385bf88a15180387e7a483
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-06 17:44:01 +00:00
Jonathan Gelie b3ac77becd Bluetooth: GATT: introduce volatile subscription flag
Some application protocol required non-persistente subscription
across connection even in bonded case.
Flag BT_GATT_SUBSCRIBE_FLAG_VOLATILE specify if subscription
must be remove during disonnection.

Change-Id: I1bc2bbbb4bc86f58905e44a7eb267ca0871f2fdb
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-06 17:43:18 +00:00
Luiz Augusto von Dentz 31016448b4 Bluetooth: GATT: Fix not removing subscriptions safely
The subscriptions callback may free or reuse the subscription so all
instances that where this could happen need to safely fetch the next
element which is why this changes switch to use sys_list_t as it has
SYS_SLIST_FOR_EACH_NODE_SAFE.

Change-Id: I37d51f27116ea0c057b560924a9416676477597b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-06 11:18:57 +00:00
Johan Hedberg 50678b03cb Bluetooth: Reuse HCI command buffers for the command response
Reduce the pressure on the common RX buffer pool by reusing HCI
command buffers also for the Command Status or Command Complete
response to them. This also implies removing the existing Kconfig
variable for the command buffer sizes since the size is also dependent
on maximum Command Complete event sizes. Instead, reuse the RX buffer
size also for HCI Command buffers.

Change-Id: I006b287d64a0c9ca40de741aa9a424a49a927385
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 743379c21f Bluetooth: Kconfig: Merge headroom reserve variables into a single one
A subsequent patch will start reusing HCI command buffers for
receiving the response, so the distinction of received vs sent data
headroom would just make the code unnecessarily complex. Instead, just
merge these two variable into a single one.

Change-Id: I31d846331939f1a2270df7ed0c75112825e16493
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg bbf389aae6 Bluetooth: drivers/h4: Add support for discarding certain events
If we are low on RX buffers and receive an LE Advertising Report or a
BR/EDR Inquiry response we should just discard this. If we don't
discard the event we increase the risk of deadlock where the RX
interrupt is enabled but bt_recv() is doing a synchronous HCI command
sending, i.e. waiting for a cmd_status/cmd_complete (which will never
come since the RX interrupt is disabled).

Change-Id: I6266625c9790d68bcf8e8718c8c36f127946c4c6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Ricardo Salveti a3474a731e Bluetooth: SPI: Disable IRQ pin callback to avoid spurious IRQs
Avoid spurious IRQ when already handling the SPI Slave IRQ.

Change-Id: If8452a668bc9768d462a5fa56b851e99a076e67c
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-01-28 08:43:41 +02:00
Ricardo Salveti 2569e2e8d1 Bluetooth: SPI: retry spi_transceive calls if invalid
spi_transceive can return successfuly even if the data provided by the
slave is invalid, so check if the content is correct and retry until a
valid data is available.

Change-Id: Ia951de391e0b24c5b41eeabfb5c10b056d32b62e
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-01-28 08:43:41 +02:00
Ricardo Salveti f27d8eef39 Bluetooth: SPI: switch to a single SPI transfer when receiving
Change-Id: I27b504032080bddf7ebc88ef4812a0e7eab691c6
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-01-28 08:43:41 +02:00
Ricardo Salveti 8227c72c47 Bluetooth: SPI: fix max SPI buffer length
Drop the BLUETOOTH_SPI_RX_BUFFER_SIZE and BLUETOOTH_SPI_TX_BUFFER_SIZE
config options by fixing the max SPI buffer length to 255, as used by
the X-NUCLEO-IDB04A1 BSP. This simplifies the rx/tx buffer handling, and
avoids a potential spi rx stack overflow depending on the config values
set by the user.

Change-Id: Ifa7fd086016abda4bdcf9638f28b38d001a288c5
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-01-28 08:43:41 +02:00
Ricardo Salveti 4afe063aad Bluetooth: SPI: introduce CONFIG_BLUETOOTH_SPI_BLUENRG
This new option is used to encapsulate the logic specific to devices
implementing the BlueNRG Bluetooth stack (e.g. X-NUCLEO-IDB05A1).

The current BlueNRG specific logic covers the HCI Reset handling and
the manual control of the SPI Chip Select line (normally not needed since
spi_transceive is also responsible for controlling the SPI CS line).

Change-Id: I5db4addf873eee0af2d957e2181c50aac53ab656
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-01-28 08:43:41 +02:00
Ricardo Salveti ef7f2bd54e Bluetooth: SPI: fix Kconfig SPI IRQ PIN description
Change-Id: I4c25062e922cd05ca738222182909c261b55abca
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-01-28 08:43:41 +02:00
Johan Hedberg 4153b6ca1f Bluetooth: Kconfig: Make device name variable generic
Change BREDR_NAME to DEVICE_NAME so it can also be used as the LE
device name.

Change-Id: I9ef55d9dff098372d47d9d5754ad7a7163a65bc0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-28 08:43:41 +02:00
Ricardo Salveti e2b759bc69 Bluetooth: SPI: fix buf handling for HCI ACL packets
Code was assuming that all the HCI messages were events, causing invalid
data length when receiving HCL ACL packets.

Change-Id: I8c1a07f46b6b62a04e242cf29ee1119f59d4bda6
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-01-28 08:43:41 +02:00
Johan Hedberg 916837c22c Bluetooth: SPI: Replace Apache boilerplate with SPDX tag
There was a recent change to the license boilerplate of the entire
source tree, however as this spi.c was just recently added it missed
the change.

Change-Id: Icc95084a4b051266beaf1796c31d9aec9da538d0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-19 08:04:16 +02:00
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
Lee Jones 7890290e81 Bluetooth: Add HCI SPI driver
This driver acts as a pass-through, taking raw HCI data, converting
it to SPI comms and vice versa.  It works in the same way as the
existing H:4 and H:5 drivers, only it uses SPI instead of UART.

In this first release, the only BLE board which has been tested is
the X-NUCLEO-IDB05A1:

  http://www.st.com/en/ecosystems/x-nucleo-idb05a1.html

Although the current supported SPI format works like the one below,
it should be trivial to adapt it to support other chips with a
different format.

SANITY CHECK = 0x02
SPI WRITE    = 0x0A
SPI READ     = 0x0B

Tx Format:

   [HOST] {SPI WRITE}     0x00          0x00  0x00  0x00  {HCI MESSAGE ...}
   [CHIP] {SANITY CHECK}  {FLASH SIZE}  0x00  0x00  0x00  {0xFF * MESSAGE LEN}

Rx Format:

   {IRQ LINE GOES HIGH}

   [HOST] {SPI READ}  0x00          0x00  0x00             0x00  {0xFF * BYTES TO READ}
   [CHIP] 0x02        {FLASH SIZE}  0x00  {BYTES TO READ}  0x00  {HCI MESSAGE ...}

Change-Id: I4a00711c922d9ea02c5e2afb0d16715e413b1ed5
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2017-01-18 12:24:17 +00:00
Johan Hedberg 4ce96e1bc3 Bluetooth: drivers/nble: Remove bogus BT_DBG manipulation
This file doesn't even include <bluetooth/log.h> so any tricks on
BT_DBG are completely pointless (and wrong after the recent update to
the debug logging API).

Change-Id: I1b2b7942a11a4f7229dc35aa2701b3180dc35a28
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 11:04:58 +02:00
Johan Hedberg 645f867444 Bluetooth: Take advantage of IS_ENABLED macro for BT_DBG
The new IS_ENABLED macro allows exposing conditionally enabled code
always to the compiler, even though it may not ultimately end up being
built. This is in particular useful for letting the compiler catch any
logging format string errors. Introduce a new BT_DBG_ENABLED macro
that c-files need to define before including <bluetooth/log.h> in
order to choose whether BT_DBG() logs are enabled or not.

When no Bluetooth logs are enabled the patch also modifies the log
macros to have the format strings checked with the help of the
__printf_like annotation and empty static inline functions.

Change-Id: Ie6bc8e10727b5b306f3ed0f94089a07a22583d9b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 08:28:06 +02:00
Johan Hedberg d64f47d956 Bluetooth: Create separate bt_recv_prio() API
Since callers of bt_recv() have so far anyway been required to know in
which context to call it (based on e.g. bt_hci_evt_is_prio) it's
cleaner to have two separate APIs: bt_recv and bt_recv_prio.

Change-Id: Icd0d9aed9c51ffd2def31432c4ffcc16a9f13ccd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 3341d7d2b5 Bluetooth: h4: Convert TX path to be interrupt based
Use interrupt based transmission instead of polling.

Change-Id: Iebfd67372044d3e6de9bdbdd6f0c9c6d01d46cb9
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 37aa1a1f8b Bluetooth: h4: Use k_fifo instead of k_sem
So far the use of k_sem meant that there was no major benefit of
having more than 2 or 3 RX buffers since there was no queuing
mechanism. Instead of using k_sem, introduce a k_fifo and use that to
queue up incoming buffers. This way the RX buffer count can be
increased with measurable effects on throughput.

Change-Id: I8122b233aeee7c8e145de3fff5f10bcfe348efaa
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 3fb654ecd1 Bluetooth: drivers: Use bt_buf_get_rx() in h5.c
The H:5 HCI driver doesn't need the type-specific bt_buf allocation
helpers.

Change-Id: Iccb9803f32f3143f1cdf972d9229124816a99aa6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 95049fb99b Bluetooth: Convert H:4 HCI driver to RECV_IS_RX_THREAD
Completely redesign the H:4 driver to utilize its own thread and
select the new RECV_IS_RX_THREAD Kconfig option.

Jira: ZEP-1483

Change-Id: I0ca0661b66d564e5edc1b8505706d6bb76632e79
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg 6f429a38d8 Bluetooth: Kconfig Remove HOST_BUFFERS option
This option has not been used so far and will only contribute
unnecessary complexity in subsequent patches that introduce a concept
of combined RX buffers.

Change-Id: I53e0ce5155eebc352b84ba41b30ecb9d9958699f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg 63f71adc5f Bluetooth: Take advantage of new net_buf_add_mem() API
This helps simplify code that was previously combining net_buf_add()
with memcpy().

Change-Id: If44cf9cd651aba5e544e36567869f147468663eb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg f3c632bf44 Bluetooth: Add timeout to event & ACL buffer allocation functions
Not all users are in an ISR context where we can't block, so give the
callers the freedom to choose if they want to block or not.

Jira: ZEP-1481

Change-Id: I19bd7e2df94c4eeb60886a17a78f872bd7bea887
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-24 08:42:15 +02:00
Johan Hedberg 1c9da665c3 Bluetooth: Remove unnecessary runtime kernel object initialization
There are static initializer macros available for most kernel objects
which we should use whenever possible.

Change-Id: I496f4d05d26801eddd21fae53bdd4fcdc3246fe3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-16 10:27:48 +02:00
Johan Hedberg 71c7c01819 net: buf: Remove the need for net_buf_pool_init()
In order to keep the initialization process light-weight, remove
net_buf_pool_init() and instead perform the initialization of the pool
and buffers in a "lazy" manner. This means storing more information
in the pool, and removing any 'const' members from net_buf. Since
there are no more const members in net_buf the buffer array can be
declared with __noinit, which further reduces initialization overhead.

Change-Id: Ia126af101c2727c130651b697dcba99d159a1c76
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 09:58:02 +02:00
Johan Hedberg c3e08c8fea net: buf: Redesigned pool & buffer allocation API
Until now it has been necessary to separately define a k_fifo and
an array of buffers when creating net_buf pools. This has been a bit
of an inconvenience as well as blurred the line of what exactly
constitutes the "pool".

This patch removes the NET_BUF_POOL() macro and replaces it with a
NET_BUF_POOL_DEFINE() macro that internally expands into the buffer
array and new net_buf_pool struct with a given name:

	NET_BUF_POOL_DEFINE(pool_name, ...);

Having a dedicated context struct for the pool has the added benefit
that we can start moving there net_buf members that have the same
value for all buffers from the same pool. The first such member that
gets moved is the destroy callback, thus shrinking net_buf by four
bytes. Another potential candidate is the user_data_size, however
right not that's left out since it would just leave 2 bytes of padding
in net_buf (i.e. not influence its size). Another common value is
buf->size, however that one is also used by net_buf_simple and can
therefore not be moved.

This patch also splits getting buffers from a FIFO and allocating a
new buffer from a pool into two separate APIs: net_buf_get and
net_buf_alloc, thus simplifying the APIs and their usage. There is no
separate 'reserve_head' parameter anymore when allocating, rather the
user is expected to call net_buf_reserve() afterwards if something
else than 0 headroom is desired.

Change-Id: Id91b1e5c2be2deb1274dde47f5edebfe29af383a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-13 21:41:53 +00:00
Kumar Gala 49cd3b1891 drivers: bluetooth: nble: remove unneeded include path additions
We can locally reference the files we need, so don't add a -I we
don't need.

Change-Id: I764aea4177a8995489e0f15f71f7373427b43394
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2016-12-09 08:18:24 +02:00
Johan Hedberg a4b6b2417d Bluetooth: Switch from printf to printk functions
There's now snprintk available that's more light-weight on the stack
than snprintf.

Change-Id: I6b3e4409703ca92fe6b8f4146ff47c490ab826cb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg 9aafa973df Bluetooth: Fix incorrect logging format specifiers
Fix compilation issues that show up if SYS_LOG is mapped to printk
instead of printf. Unlike printf, printk is annotated so that the
compiler catches incorrect format specifiers passed to it.

Change-Id: I4d6f635a0ed61de698727028ea8767dc0ef28bb1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-07 13:15:59 +00:00
Johan Hedberg 2469bd6f87 Bluetooth: Use convenience macros for timeout durations
Using the K_* macros makes it easier to read what exactly the various
timeouts are.

Change-Id: Ia405d3760b8e600af7e33a7221ef6ec717708973
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-18 07:47:50 +02:00
Johan Hedberg 1e20e8dc04 Bluetooth: Fix left-over usage of TICKS_NONE and TICKS_UNLIMITED
Switch left-over usage of TICKS_NONE and TICKS_UNLIMITED to the new
unified kernel counterparts K_NO_WAIT and K_FOREVER.

Change-Id: I2f2a16360e816f9f8791eb216deb3c70b8cc87df
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-12 19:27:34 +02:00
Johan Hedberg 79f020be54 Bluetooth: Flag NBLE as deprecated
The NBLE driver is now deprecated and will be removed in a future
Zephyr version.

Change-Id: I50753f8cf8566ac1e4e73df480c96253c199e6a7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-12 16:18:55 +02:00
Johan Hedberg effbe6743d Bluetooth: drivers/nble: Convert to unified work APIs
Start using the k_work and k_delayed_work APIs.

Change-Id: Iac0525a444c5c4e0f28db08844d7b28e17e905fc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 11:13:47 +02:00
Johan Hedberg 776b3e6871 Bluetooth: drivers/h5: Convert to unified work APIs
Switch to using k_work and k_delayed_work APIs.

Change-Id: I3be18132cc417607adaec0ad711256b94e314c38
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 11:10:00 +02:00
Johan Hedberg 5f5425f20a Bluetooth: drivers: Don't use deprecated NANOKERNEL init level
Don't use the deprecated NANOKERNEL init level. The only requirement
for Bluetooth drivers is for them to be registered before the
application main() runs, so POST_KERNEL should be good enough.

Change-Id: I02a8609bf63e9d608b802576214a2e76211b3965
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:50:47 +02:00
Johan Hedberg c78bfd9a98 Bluetooth: Use k_sleep() instead of deprecated fiber_sleep()
Use the unified kernel API k_sleep() instead of the deprecated
fiber_sleep().

Change-Id: I587d72ca5b53aacc02647b32c3ebceb1d7fe067e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:38:40 +02:00
Johan Hedberg 918a8e6bac Bluetooth: Use k_thread_spawn() instead of deprecated nano_fiber_start()
Switch to using the unified kernel k_thread_spawn() API instead of
nano_fiber_start().

Change-Id: I325cf467ae2a52c6aec8fc166397c323929e3013
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:38:40 +02:00
Johan Hedberg b0f0742b6e Bluetooth: Use k_yield() instead of deprecated fiber_yield()
Use the unified kernel API k_yield() instead of fiber_yield().

Change-Id: I8f52031f52f7ac8783033a51751dc22decdfa59a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:38:40 +02:00
Szymon Janc 2b16287286 Bluetooth: Use proper timeout defines for net_buf_get_timeout
Use defines from k_fifo intead of legacy API.

Change-Id: Ib8cf0d88240ef145da550b8cf83d2580e7140521
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 06:00:28 +00:00
Szymon Janc e2795499d8 Bluetooth: drivers: Use unified k_fifo API for FIFOs
Change-Id: Id2ef6f9a134e6471c59bf3baedccef219d7f12f6
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg b64e0d4c51 Bluetooth: Kconfig: Remove redundant 'default n' declarations
All boolean options default to 'n' without the need to explicitly
state this. It's only the cases where we want 'default y' where we
need to state this.

Change-Id: I47dbda62462ea437a2423b8508ea2cc640a22e41
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg c583a9f43b Bluetooth: Kconfig: Restructure for a more logical hierarchy
Restructure the Bluetooth options more logically.

- Both host and controller are now behind the same high level
  CONFIG_BLUETOOTH.

- Selecting controller support disables other HCI driver selection, so
  the controller isn't in the same list as HCI drivers any more.

- Under the top-level there's a "Custom stack" option, which when
  enabled opens up the option of choosing CONFIG_NBLE.

There are various other cleanups and simplifications in this patch as
well, since splitting these up would have been fairly tricky while
making sure all test cases still build.

Change-Id: I5bb715cb9d20201cb8b72fbd149c8a09a4b2d7d2
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg d7f4fd74a9 Bluetooth: Use depends on SERIAL instead of selects
This suppresses warnings for platforms where SERIAL can't be provided.
All the platforms that these drivers are interesting for already
default to SERIAL=y.

Change-Id: Id692f99e018009b30903db8a2c046a6086be01c2
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-09 08:57:52 +02:00
Szymon Janc b73b77652c Bluetooth: nble: Use unified k_sem API for semaphores
Change-Id: I5bf66ab7c3f863945f2c9f9392d773b348020367
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Benjamin Walsh 8cf56bcac7 unified: dissociate system workqueue from common workqueue module
Making a reference to the common work queue code should not necessarily
drag in the system workqueue, since it is possible to use a workqueue
that is not the system workqueue. This is done by moving the system
workqueue into its own code module.

Moving the system workqueue to its own code module allows removing the
NANO_WORKQUEUE and SYSTEM_WORKQUEUE kconfig options, and compiling the
common workqueue code and system workqueue all the time. They are only
linked in the final image if a reference to them exist, same as the
other kernel modules.

Change-Id: I6f48d2542bda24f4702e7c2e317818dd082b3c11
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-04 22:39:54 +00:00
Johan Hedberg 26d39cd107 Bluetooth: Move controller code to subsys/bluetooth
Move controller code from drivers/controller to
subsys/bluetooth/controller.

Change-Id: I73f675188485aa3267507bad7647796e593a3da0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:05:05 +02:00
Johan Hedberg 6bc645962a Bluetooth: Move Bluetooth host stack to subsys
Move the Bluetooth host stack from net/bluetooth to
subsys/bluetooth/host. This is preparation for having both host and
controller under the same root, i.e. subsys/bluetooth/.

Change-Id: I3bc796f7e331fca0c485f3890d62b9c03e027b96
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:05:05 +02:00
Carles Cufi 20952b75e3 Bluetooth: uart: Fix UART TX stall condition
In 3 of our UART driver implementations the ISR is exclusively
used and enabled for the RX path. The existing logic was
susceptible to a stall situation where a polled out transmission
would be interrupted by a reception and then the ISR code
would loop forever due to the TX event being signalled (although
the interrupt itself was disabled) causing the ISR to keep
looping for an RX interrupt.

Change-Id: Ic379e58b1c974aca3cee37d2d81f12c3726fb160
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-01 21:40:39 +02:00
Johan Hedberg 900fbc20ba boards: x86: Don't default to 'y' with NRF51_PM and WAIT_NOP
These options were only needed for a MyNewt-based nRF51 firmware on
these boards (the MyNewt BLE stack is called Nimble, hence the
prj_nimble.conf sample config files). With a Zephyr-based nRF51
firmware these options are no-longer needed, so it's not appropriate
to have them default to enabled. Instead, if they are needed, require
the app-specific configuration to enable them.

Change-Id: Iefbee4d97590af4e11bcedea05fe61f32a147b83
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-01 19:37:26 +00:00
Szymon Janc 4a345d3196 Bluetooth: drivers: Include zephyr.h instead of nanokernel.h
zephyr.h includes required kernel header depending on selected
configuration.

Change-Id: Ieb5666c96f94708a42f605c09eb710f8d2eee4ec
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-10-28 16:34:17 +02:00