|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
BLE HCI transport seam (host-side). More...
Go to the source code of this file.
Data Structures | |
| struct | ra8_ble_config_t |
| Configuration passed to ra8_ble_open. More... | |
Typedefs | |
| typedef void(* | ra8_ble_event_fn_t) (void *ctx, uint8_t evt_code, const uint8_t *params, uint8_t params_len) |
| Fired when an HCI event packet has been received. | |
| typedef void(* | ra8_ble_acl_fn_t) (void *ctx, uint16_t handle, const uint8_t *payload, uint16_t len) |
| Fired when an HCI ACL data packet has been received. | |
Enumerations | |
| enum | ra8_ble_limits_t : uint16_t { k_ra8_ble_max_cmd_params = 255U , k_ra8_ble_max_evt_params = 255U , k_ra8_ble_max_acl_payload = 251U , k_ra8_ble_addr_bytes = 6U , k_ra8_ble_adv_data_max = 31U } |
| Driver-side packet bounds. More... | |
| enum | ra8_ble_hci_pkt_t : uint8_t { k_ra8_ble_pkt_cmd = 0x01U , k_ra8_ble_pkt_acl_data = 0x02U , k_ra8_ble_pkt_event = 0x04U } |
| H4 HCI packet-type indicator bytes (Bluetooth Core 5.3 Vol 4 Part A 2). More... | |
Functions | |
| ra8_err_t | ra8_ble_open (const ra8_ble_config_t *cfg) |
| Power up the BLE controller and open the HCI mailbox. | |
| ra8_err_t | ra8_ble_close (void) |
| Close the HCI mailbox and put the controller back in reset. | |
| ra8_err_t | ra8_ble_hci_send_command (uint16_t opcode, const uint8_t *params, uint8_t params_len) |
| Emit an HCI command packet. | |
| ra8_err_t | ra8_ble_hci_send_acl_data (uint16_t handle, const uint8_t *payload, uint16_t len) |
| Emit an HCI ACL data packet. | |
| ra8_err_t | ra8_ble_attach_event_handler (ra8_ble_event_fn_t fn, void *ctx) |
| Register a handler for inbound HCI events. | |
| ra8_err_t | ra8_ble_attach_acl_handler (ra8_ble_acl_fn_t fn, void *ctx) |
| Register a handler for inbound HCI ACL data. | |
| ra8_err_t | ra8_ble_dispatch (void) |
| Pump the HCI receive path – call from ISR or main loop. | |
| ra8_err_t | ra8_ble_set_random_address (const uint8_t addr[k_ra8_ble_addr_bytes]) |
| Send LE_Set_Random_Address (opcode 0x2005). | |
| ra8_err_t | ra8_ble_set_advertising_data (const uint8_t *data, uint8_t len) |
| Send LE_Set_Advertising_Data (opcode 0x2008). | |
| ra8_err_t | ra8_ble_set_advertising_enable (uint8_t enable) |
| Send LE_Set_Advertising_Enable (opcode 0x200A). | |
| ra8_err_t | ra8_ble_scan_start (uint8_t active, uint16_t interval, uint16_t window) |
| Send LE_Set_Scan_Parameters then LE_Set_Scan_Enable. | |
BLE HCI transport seam (host-side).
The host-side HCI transport the NimBLE host stack (via port/nimble) sits on. It is deliberately the controller-agnostic seam:
The packet framing matches Bluetooth Core 5.3 Volume 4 Part A 2 ("HCI Transport Layer") with the H4-style packet-indicator byte:
| type | opcode (LE16) | param-len | params... | command (0x01) | type | event-code | param-len | params... | event (0x04) | type | handle (LE16) | data-len (LE16) | payload | ACL (0x02)
Definition in file ra8_ble.h.
| typedef void(* ra8_ble_acl_fn_t) (void *ctx, uint16_t handle, const uint8_t *payload, uint16_t len) |
Fired when an HCI ACL data packet has been received.
| [in] | ctx | User context registered alongside the callback. |
| [in] | handle | ACL connection handle (12-bit, low bits of the LE16). |
| [in] | payload | Pointer into a driver-owned scratch buffer; valid only for the duration of the callback. |
| [in] | len | Number of payload bytes. |
| typedef void(* ra8_ble_event_fn_t) (void *ctx, uint8_t evt_code, const uint8_t *params, uint8_t params_len) |
Fired when an HCI event packet has been received.
| [in] | ctx | User context registered alongside the callback. |
| [in] | evt_code | HCI event code (Bluetooth Core 5.3 Vol 4 Part E 7.7). |
| [in] | params | Pointer into a driver-owned scratch buffer; valid only for the duration of the callback. |
| [in] | params_len | Number of bytes pointed to by params. |
| enum ra8_ble_hci_pkt_t : uint8_t |
H4 HCI packet-type indicator bytes (Bluetooth Core 5.3 Vol 4 Part A 2).
HCI protocol constants – not hardware registers. Public on the HCI seam so both the transport and its tests frame H4 packets with them.
| Enumerator | |
|---|---|
| k_ra8_ble_pkt_cmd | HCI command packet indicator. |
| k_ra8_ble_pkt_acl_data | HCI ACL data packet indicator. |
| k_ra8_ble_pkt_event | HCI event packet indicator. |
| enum ra8_ble_limits_t : uint16_t |
Driver-side packet bounds.
Picked to match HCI maximum sizes in Bluetooth Core 5.3 Vol 4 Part E 5.4 "Exchange of HCI-specific information".
|
nodiscard |
Register a handler for inbound HCI ACL data.
| [in] | fn | Callback. Pass NULL to detach. |
| [in] | ctx | Opaque user context, passed back on each ACL packet. |
Definition at line 281 of file ra8_ble.c.
References k_ra8_ok, and s_state.
Referenced by ble_hci_ra8_ble_deinit(), and ble_hci_ra8_ble_init().
|
nodiscard |
Register a handler for inbound HCI events.
| [in] | fn | Callback. Pass NULL to detach. |
| [in] | ctx | Opaque user context, passed back on each event. |
Definition at line 274 of file ra8_ble.c.
References k_ra8_ok, and s_state.
Referenced by ble_hci_ra8_ble_deinit(), and ble_hci_ra8_ble_init().
|
nodiscard |
Close the HCI mailbox and put the controller back in reset.
Definition at line 211 of file ra8_ble.c.
References k_ra8_err_invalid_arg, k_ra8_ok, ra8_log_info, s_state, and s_tag.
|
nodiscard |
Pump the HCI receive path – call from ISR or main loop.
Drains both the event FIFO and the ACL RX FIFO, dispatching each frame through the registered callbacks. Bounded by a static loop cap so it never blocks indefinitely.
Definition at line 362 of file ra8_ble.c.
References internal_dispatch_acl(), internal_dispatch_event(), internal_rx_byte(), k_ra8_ble_dispatch_budget, k_ra8_ble_pkt_acl_data, k_ra8_ble_pkt_event, k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_ok, and s_state.
Referenced by internal_demo_thread_entry().
|
nodiscard |
Emit an HCI ACL data packet.
Frames [0x02][handle_lo][handle_hi][len_lo][len_hi][payload] and pushes it into the HCI ACL TX FIFO. The handle field carries the 12-bit connection handle plus PB/BC flags as one LE16 word; callers are expected to merge those fields beforehand.
| [in] | handle | Connection handle + PB/BC flags (LE16, 16 bits). |
| [in] | payload | Payload bytes. May be NULL iff len == 0. |
| [in] | len | Payload byte count (0..k_ra8_ble_max_acl_payload). |
Definition at line 246 of file ra8_ble.c.
References internal_tx_byte(), k_ra8_ble_byte_mask, k_ra8_ble_byte_shift, k_ra8_ble_max_acl_payload, k_ra8_ble_pkt_acl_data, k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_err_null_ptr, k_ra8_ok, and s_state.
Referenced by ble_transport_to_ll_acl_impl().
|
nodiscard |
Emit an HCI command packet.
Frames [0x01][opcode_lo][opcode_hi][params_len][params...] and pushes it into the HCI command FIFO. Returns immediately; the matching Command Complete or Command Status event arrives via the event callback.
| [in] | opcode | 16-bit HCI opcode (Bluetooth Core 5.3 Vol 4 Part E 5.4.1). |
| [in] | params | Parameter bytes. May be NULL iff params_len == 0. |
| [in] | params_len | Parameter byte count (0..255). |
Definition at line 226 of file ra8_ble.c.
References internal_tx_byte(), k_ra8_ble_byte_mask, k_ra8_ble_byte_shift, k_ra8_ble_pkt_cmd, k_ra8_err_not_initialized, k_ra8_err_null_ptr, k_ra8_ok, and s_state.
Referenced by ble_transport_to_ll_cmd_impl(), ra8_ble_scan_start(), ra8_ble_set_advertising_data(), ra8_ble_set_advertising_enable(), and ra8_ble_set_random_address().
|
nodiscard |
Power up the BLE controller and open the HCI mailbox.
Steps (mirrors FSP r_ble open + the production patch-load helper):
| [in] | cfg | Driver configuration. Must not be NULL. |
Definition at line 197 of file ra8_ble.c.
References k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_log_info, s_state, and s_tag.
Referenced by internal_demo_ble_or_halt().
|
nodiscard |
Send LE_Set_Scan_Parameters then LE_Set_Scan_Enable.
Bluetooth Core 5.3 Vol 4 Part E 7.8.10 / 7.8.11. Two HCI commands fly back-to-back; the controller answers with two Command Complete events, both delivered through the registered event handler.
| [in] | active | 1 = active scanning (with SCAN_REQ), 0 = passive. |
| [in] | interval | Scan interval in 0.625 ms units (0x0004..0x4000). |
| [in] | window | Scan window in 0.625 ms units (0x0004..0x4000), <= interval. |
Definition at line 426 of file ra8_ble.c.
References k_ra8_ble_byte_mask, k_ra8_ble_byte_shift, k_ra8_ble_op_le_set_scan_enable, k_ra8_ble_op_le_set_scan_params, k_ra8_ble_scan_enable_bytes, k_ra8_ble_scan_filt_basic, k_ra8_ble_scan_max, k_ra8_ble_scan_min, k_ra8_ble_scan_off_filter, k_ra8_ble_scan_off_interval_hi, k_ra8_ble_scan_off_interval_lo, k_ra8_ble_scan_off_own_addr, k_ra8_ble_scan_off_type, k_ra8_ble_scan_off_window_hi, k_ra8_ble_scan_off_window_lo, k_ra8_ble_scan_own_pub, k_ra8_ble_scan_param_bytes, k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_ok, ra8_ble_hci_send_command(), and s_state.
|
nodiscard |
Send LE_Set_Advertising_Data (opcode 0x2008).
| [in] | data | Advertising-data bytes. |
| [in] | len | Byte count (0..k_ra8_ble_adv_data_max). |
Definition at line 400 of file ra8_ble.c.
References internal_byte_copy(), k_ra8_ble_adv_data_max, k_ra8_ble_op_le_set_adv_data, k_ra8_err_invalid_arg, k_ra8_err_null_ptr, and ra8_ble_hci_send_command().
|
nodiscard |
Send LE_Set_Advertising_Enable (opcode 0x200A).
| [in] | enable | 0 = disable advertising, 1 = enable. |
Definition at line 420 of file ra8_ble.c.
References k_ra8_ble_op_le_set_adv_enable, and ra8_ble_hci_send_command().
|
nodiscard |
Send LE_Set_Random_Address (opcode 0x2005).
| [in] | addr | 6-byte random Bluetooth address (LSB first per spec). |
Definition at line 394 of file ra8_ble.c.
References k_ra8_ble_addr_bytes, k_ra8_ble_op_le_set_random_address, ra8_ble_hci_send_command(), RA8_CHECK_NULL_PTR, and s_tag.