BNO08x Driver
API reference
Loading...
Searching...
No Matches
Classes | Namespaces | Functions | Variables
bno08x_shtp_uart.hpp File Reference

Portable framing for SHTP over UART (UART-SHTP mode, PS1 = 1, PS0 = 0). More...

#include <cstddef>
#include <cstdint>
Include dependency graph for bno08x_shtp_uart.hpp:

Go to the source code of this file.

Classes

class  bno08x::shtp_uart::FrameDecoder< Capacity >
 Byte-at-a-time decoder for frames received from the hub. More...
 

Namespaces

namespace  bno08x
 
namespace  bno08x::shtp_uart
 

Functions

constexpr std::size_t bno08x::shtp_uart::MaxEncodedSize (std::size_t payloadLen) noexcept
 Largest frame EncodeFrame() can produce for payloadLen bytes (every byte escaped).
 
std::size_t bno08x::shtp_uart::EncodeFrame (const uint8_t *shtp, std::size_t len, uint8_t *out, std::size_t cap) noexcept
 Wrap one SHTP transfer (header included) in a UART-SHTP frame.
 

Variables

constexpr uint32_t bno08x::shtp_uart::BAUD_RATE = 3000000
 UART-SHTP line rate: 3 Mbit/s, 8 data bits, no parity, 1 stop bit (datasheet 1.2.3.1).
 
constexpr uint32_t bno08x::shtp_uart::HOST_BYTE_GAP_US = 100
 Minimum spacing between bytes sent from the host to the hub, in µs (datasheet 1.2.3.1).
 
constexpr uint8_t bno08x::shtp_uart::FLAG = 0x7E
 Frame delimiter.
 
constexpr uint8_t bno08x::shtp_uart::ESCAPE = 0x7D
 Escape: the next byte is XOR ESCAPE_XOR.
 
constexpr uint8_t bno08x::shtp_uart::ESCAPE_XOR = 0x20
 Value XORed into an escaped byte.
 
constexpr uint8_t bno08x::shtp_uart::PROTOCOL_CONTROL = 0x00
 Protocol ID of control frames (BSQ / BSN).
 
constexpr uint8_t bno08x::shtp_uart::PROTOCOL_SHTP = 0x01
 Protocol ID of SHTP transfers.
 
constexpr uint8_t bno08x::shtp_uart::BUFFER_STATUS_QUERY [3] = {FLAG, PROTOCOL_CONTROL, FLAG}
 Buffer Status Query, ready to send.
 

Detailed Description

Portable framing for SHTP over UART (UART-SHTP mode, PS1 = 1, PS0 = 0).

In UART-SHTP mode every SHTP transfer travels inside a frame (datasheet 1000-3927 section 1.2.3.1, which defers to the SHTP reference manual 1000-3535; byte values as in CEVA's reference UART HAL):

Byte(s) Value
0 Flag 0x7E
1 Protocol ID: 0x01 SHTP transfer, 0x00 control
2 .. n-2 Payload; 0x7E / 0x7D sent as 0x7D, byte XOR 0x20
n-1 Flag 0x7E

Before sending a frame the host asks how much the hub can accept with a Buffer Status Query (control frame with no payload: 7E 00 7E); the hub answers with a control frame carrying the free space as a 16-bit little- endian count. The host sends a frame only when it fits, one byte at a time with at least HOST_BYTE_GAP_US between bytes (section 1.2.3.1). Bytes from the hub have no spacing.

This header has no platform dependencies: a UART port encodes with EncodeFrame() and feeds every received byte to FrameDecoder::Push(). The ESP32 reference port is examples/esp32/main/esp32_bno08x_uart_bus.hpp.