|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
NimBLE-based Battery Service peripheral on top of ThreadX (RA8D2). More...
#include <stdint.h>#include <string.h>#include "ra8_attributes.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_isr.h"#include "ra8_time.h"#include "ble_hci_ra8_ble.h"#include "nimble_npl_threadx.h"#include "ra8_ble.h"#include "tx_api.h"Go to the source code of this file.
Enumerations | |
| enum | demo_config_t : uint32_t { k_demo_baud = 115200U , k_demo_thread_stack = 8192U , k_demo_tick_ms = 10000U , k_demo_thread_prio = 8U } |
| Numeric configuration constants. More... | |
| enum | demo_battery_t : uint8_t { k_demo_battery_max = 100U , k_demo_battery_min = 0U , k_demo_battery_step = 1U , k_demo_battery_init = 50U } |
| Battery Level characteristic policy. More... | |
| enum | demo_uuid_t : uint16_t { k_demo_uuid_battery_service = 0x180FU , k_demo_uuid_battery_level = 0x2A19U } |
| 16-bit UUID handles for the Battery Service. More... | |
Functions | |
| static void | internal_demo_panic_halt (void) |
| Park the CPU forever in WFI on fatal init failure. | |
| static void | internal_demo_log (const char *s) |
| Send a NUL-terminated ASCII line over SCI8 (best-effort). | |
| static void | internal_demo_clocks_or_halt (void) |
| Bring CGC + SysTick + SCI8 + GPIO basics up. | |
| static void | internal_demo_ble_or_halt (void) |
| Bring the BLE controller + NimBLE adapter up. | |
| static void | internal_demo_tick_battery (void) |
| Tick the battery shadow value. | |
| static void | internal_demo_thread_entry (ULONG arg) |
| Worker thread: bring NimBLE up and run the battery loop. | |
| void | tx_application_define (void *first_unused_memory) |
| ThreadX system-define hook: build the worker thread. | |
| void | main (void) |
| Application entry. | |
Variables | |
| static const char | s_demo_local_name [] = "EK-RA8D2" |
| Local-name string broadcast in adv-data. | |
| static const char * | s_demo_tag = "ble_nimble" |
| Tag used in SCI8 / ra8_log output to identify this app. | |
| static TX_THREAD | s_demo_thread |
| Worker thread control block (statically allocated). | |
| static UCHAR | s_demo_stack [k_demo_thread_stack] |
| Worker thread stack. | |
| static CHAR | s_demo_thread_name [] = "nimble_demo" |
| Persistent mutable name retained by the ThreadX thread control block. | |
| static uint8_t | s_demo_battery_level = k_demo_battery_init |
| Current battery percentage value (mirrored to GATT cache). | |
NimBLE-based Battery Service peripheral on top of ThreadX (RA8D2).
NimBLE replacement for the hand-rolled examples/ble_peripheral demo. The bring-up path is:
Bluetooth profile pointers (Bluetooth Core 5.3):
Definition in file main.c.
| enum demo_battery_t : uint8_t |
Battery Level characteristic policy.
Battery Level is a percentage in the range 0..100 (Bluetooth Core 5.3 Service Specifications – Battery Service 1.0 sec 3.1).
| Enumerator | |
|---|---|
| k_demo_battery_max | Maximum percentage. |
| k_demo_battery_min | Minimum percentage (rolls to max). |
| k_demo_battery_step | Decrement amount per tick. |
| k_demo_battery_init | Initial reading at boot. |
| enum demo_config_t : uint32_t |
Numeric configuration constants.
Matches examples/ble_peripheral so the verification flow is unchanged. SCI8 lives on PD_02 / PD_03 (J-Link OB CDC bridge).
| Enumerator | |
|---|---|
| k_demo_baud | J-Link OB CDC log baud. |
| k_demo_thread_stack | Worker thread stack bytes. |
| k_demo_tick_ms | Battery decrement period. |
| k_demo_thread_prio | ThreadX priority + threshold. |
| enum demo_uuid_t : uint16_t |
|
static |
Bring the BLE controller + NimBLE adapter up.
Definition at line 227 of file main.c.
References ble_hci_ra8_ble_init(), internal_demo_log(), internal_demo_panic_halt(), k_ra8_ok, nimble_port_init(), ra8_ble_open(), and RA8_INTERNAL.
Referenced by internal_demo_thread_entry().
|
static |
Bring CGC + SysTick + SCI8 + GPIO basics up.
Panic-halts on fail.
Initializes clocks, obtains CPUCLK0, starts the timebase, and opens LED1 and the console in their dependency order.
Definition at line 188 of file main.c.
References internal_demo_panic_halt(), k_demo_baud, k_ra8_board_led1, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_led_init(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, and ra8_time_init().
Referenced by main().
|
static |
Send a NUL-terminated ASCII line over SCI8 (best-effort).
Measures the string and submits exactly its payload bytes to the BSP console without dynamic allocation or a terminator write.
| [in] | s | ASCII string (NUL-terminated). May be nullptr. |
Definition at line 166 of file main.c.
References ra8_board_uart_console_write(), RA8_INTERNAL, and strlen().
Referenced by internal_demo_ble_or_halt(), internal_demo_thread_entry(), internal_demo_tick_battery(), and main().
|
static |
Park the CPU forever in WFI on fatal init failure.
Preserves the failed bring-up state for debugger inspection while preventing further radio, console, or scheduler activity.
Definition at line 143 of file main.c.
References RA8_INTERNAL.
|
static |
Worker thread: bring NimBLE up and run the battery loop.
Starts the controller and host bridge, announces the local name, then dispatches HCI traffic and advances the battery shadow periodically.
| [in] | arg | Unused. |
Definition at line 285 of file main.c.
References internal_demo_ble_or_halt(), internal_demo_log(), internal_demo_tick_battery(), k_demo_tick_ms, ra8_ble_dispatch(), RA8_INTERNAL, s_demo_local_name, and tx_thread_sleep.
|
static |
Tick the battery shadow value.
Wraps from 0 -> 100. Pushes the new value out as a Handle Value Notification through the upstream NimBLE GATT API once the host stack is wired up; for now we only update the shadow + log.
Definition at line 259 of file main.c.
References internal_demo_log(), k_demo_battery_max, k_demo_battery_min, k_demo_battery_step, k_ra8_board_led1, ra8_board_led_toggle(), RA8_INTERNAL, and s_demo_battery_level.
Referenced by internal_demo_thread_entry().
| void main | ( | void | ) |
Application entry.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART, then enters ThreadX.
Definition at line 340 of file main.c.
References internal_demo_clocks_or_halt(), internal_demo_log(), internal_demo_panic_halt(), ra8_isr_globals_enable(), and s_demo_tag.
| void tx_application_define | ( | void * | first_unused_memory | ) |
ThreadX system-define hook: build the worker thread.
| [in] | first_unused_memory | Unused; we statically allocate. |
Definition at line 314 of file main.c.
References internal_demo_thread_entry(), k_demo_thread_prio, s_demo_stack, s_demo_thread, s_demo_thread_name, TX_AUTO_START, TX_NO_TIME_SLICE, and tx_thread_create.
|
static |
Current battery percentage value (mirrored to GATT cache).
Definition at line 128 of file main.c.
Referenced by internal_demo_tick_battery().
|
static |
Local-name string broadcast in adv-data.
Definition at line 113 of file main.c.
Referenced by internal_demo_thread_entry().
|
static |
|
static |
|
static |
|
static |
Persistent mutable name retained by the ThreadX thread control block.
Definition at line 124 of file main.c.
Referenced by tx_application_define().