Search code examples
operating-systembluetooth-lowenergybuffer

How does an OS handle a peripheral data buffer?


A quick question:

I am working with BLE and trying to understand how a data buffer works at an OS level (basic knowledge of OS). E.g. A device (wearable) sends data to a mobile phone.

My understanding from research:

  1. A connection is established and the mobile tells the device driver (BLE module) what memory address (buffer) to send the data too.
  2. The data is then sent to the address where the CPU can access when needed.

I am trying to understand how that allocation works. More specifically, how goes the phone ensure that no packets are lost in reading from incoming BLE.


Solution

  • What you ask about is called flow control.

    At the BLE Link Layer (which is used for the transfer over the air), there is an acknowledge mechanism which makes sure the next paket may not be sent before the previous packet has been acknowledged by the remote device. That way packets can never get lost between other packets.

    Inside the device and the Bluetooth stack, there is also flow control across the different layers, where every layer makes sure that the buffers don't fill up at the next layer. For example at the HCI layer, there is a number of buffers that can be filled with packets. When full, the sending layer cannot send anything right now. When the remote device acknowledges a packet, this is notified over HCI so a new packet can be sent.