ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
48
49#include <stdint.h>
50#include <string.h>
51
52#include "ra8_attributes.h"
53#include "ra8_board_ek_ra8d2.h"
54#include "ra8_boot_entry.h"
55#include "ra8_cgc.h"
56#include "ra8_err.h"
57#include "ra8_isr.h"
58#include "ra8_time.h"
59
60/*
61 * The host unit-test build (RA8_OFF_TARGET) does not link the
62 * ThreadX or NimBLE vendor trees, so `tx_api.h` and our adapter
63 * headers are unreachable when clang-tidy walks this file. Pull
64 * them in only on the cross-compile target.
65 */
66#ifndef RA8_OFF_TARGET
67#include "ble_hci_ra8_ble.h"
68#include "nimble_npl_threadx.h"
69#include "ra8_ble.h"
70#include "tx_api.h"
71#endif
72
81typedef enum : uint32_t {
82 k_demo_baud = 115200U,
84 k_demo_tick_ms = 10000U,
87
102
107typedef enum : uint16_t {
111
113static const char s_demo_local_name[] = "EK-RA8D2";
114
116static const char* s_demo_tag = "ble_nimble";
117
118#ifndef RA8_OFF_TARGET
124static CHAR s_demo_thread_name[] = "nimble_demo";
125#endif /* !RA8_OFF_TARGET */
126
129
144{
145 while (1) {
146 __asm__ volatile("wfi");
147 }
148}
149
166RA8_INTERNAL static void internal_demo_log(const char* s)
167{
168 if (s == nullptr) {
169 return;
170 }
171 uint32_t len = (uint32_t)strlen(s);
172 (void)ra8_board_uart_console_write((const uint8_t*)s, (size_t)len);
173}
174
189{
190 uint32_t cpuclk0_hz = 0U;
191
192 if (ra8_cgc_init() != k_ra8_ok) {
194 }
197 }
198 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
200 }
203 }
206 }
207}
208
209#ifndef RA8_OFF_TARGET
228{
229 const ra8_ble_config_t ble_cfg = {
230 .use_external_osc = 1U,
231 .deep_sleep_enable = 0U,
232 };
233 if (ra8_ble_open(&ble_cfg) != k_ra8_ok) {
234 internal_demo_log("[nimble] ra8_ble_open failed -- no C6 companion?\r\n");
236 }
238 internal_demo_log("[nimble] ble_hci_ra8_ble_init failed\r\n");
240 }
242}
243
269
286{
287 (void)arg;
288
289 internal_demo_log("[nimble] starting NimBLE peripheral\r\n");
291 internal_demo_log("[nimble] advertising as ");
293 internal_demo_log("\r\n");
294
295 while (1) {
296 /* Pump any inbound HCI events / ACL frames through the bridge. */
297 (void)ra8_ble_dispatch();
298 /* Sleep one full tick window before the next battery decrement. */
301 }
302}
303
314void tx_application_define(void* first_unused_memory)
315{
316 (void)first_unused_memory;
320 0U,
322 (ULONG)sizeof(s_demo_stack),
327}
328#endif /* !RA8_OFF_TARGET */
329
340void main(void)
341{
344 internal_demo_log("[nimble] booting ThreadX + NimBLE on ");
346 internal_demo_log("\r\n");
347
348#ifndef RA8_OFF_TARGET
349 /* Hands control over to ThreadX permanently. */
350 tx_kernel_enter();
351#endif
352
353 /* Should never return. */
355}
void main(void)
Secure fallback main entry point.
Definition main.c:37
Apache NimBLE HCI transport adapter against the ra8_ble HCI ring.
ra8_err_t ble_hci_ra8_ble_init(void)
Attach the adapter to the ra8_ble HCI ring.
static TX_THREAD s_demo_thread
Definition main.c:237
static void internal_demo_panic_halt(void)
Halt forever in WFI.
Definition main.c:265
demo_config_t
Compile-time settings for the HTTPS client demo.
Definition main.c:87
@ k_demo_thread_stack
Demo thread stack.
Definition main.c:89
@ k_demo_baud
Demo baud.
Definition main.c:88
static void internal_demo_thread_entry(ULONG thread_input)
ThreadX worker entry: bring NetX up, run TLS session, dump body.
Definition main.c:852
static UCHAR s_demo_stack[k_demo_thread_stack]
Definition main.c:238
void tx_application_define(void *first_unused_memory)
ThreadX system-define hook: build worker thread + byte pool.
Definition main.c:942
static const char * s_demo_tag
Tag used in SCI8 / ra8_log output to identify this app.
Definition main.c:116
static uint8_t s_demo_battery_level
Current battery percentage value (mirrored to GATT cache).
Definition main.c:128
static void internal_demo_tick_battery(void)
Tick the battery shadow value.
Definition main.c:259
static CHAR s_demo_thread_name[]
Persistent mutable name retained by the ThreadX thread control block.
Definition main.c:124
@ k_demo_thread_prio
ThreadX priority + threshold.
Definition main.c:85
@ k_demo_tick_ms
Battery decrement period.
Definition main.c:84
static void internal_demo_ble_or_halt(void)
Bring the BLE controller + NimBLE adapter up.
Definition main.c:227
demo_uuid_t
16-bit UUID handles for the Battery Service.
Definition main.c:107
@ k_demo_uuid_battery_service
Battery Service.
Definition main.c:108
@ k_demo_uuid_battery_level
Battery Level char.
Definition main.c:109
static void internal_demo_clocks_or_halt(void)
Bring CGC + SysTick + SCI8 + GPIO basics up.
Definition main.c:188
static const char s_demo_local_name[]
Local-name string broadcast in adv-data.
Definition main.c:113
demo_battery_t
Battery Level characteristic policy.
Definition main.c:96
@ k_demo_battery_step
Decrement amount per tick.
Definition main.c:99
@ k_demo_battery_min
Minimum percentage (rolls to max).
Definition main.c:98
@ k_demo_battery_init
Initial reading at boot.
Definition main.c:100
@ k_demo_battery_max
Maximum percentage.
Definition main.c:97
static void internal_demo_log(const char *s)
Send a NUL-terminated ASCII line over SCI8 (best-effort).
Definition main.c:166
NimBLE Native Porting Layer mapping onto Eclipse ThreadX.
void nimble_port_init(void)
Bring the NimBLE host port up.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
BLE HCI transport seam (host-side).
ra8_err_t ra8_ble_open(const ra8_ble_config_t *cfg)
Power up the BLE controller and open the HCI mailbox.
Definition ra8_ble.c:197
ra8_err_t ra8_ble_dispatch(void)
Pump the HCI receive path – call from ISR or main loop.
Definition ra8_ble.c:362
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_led_toggle(ra8_board_led_id_t led)
Toggle led's output state.
ra8_err_t ra8_board_led_init(ra8_board_led_id_t led)
Configure led as a digital output, initial level low (off).
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
Definition ra8_cgc.c:132
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
Definition ra8_cgc.h:70
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
size_t strlen(const char *s)
Calculate string length.
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Definition ra8_isr.c:439
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
Definition ra8_time.c:59
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
#define tx_thread_create
#define tx_thread_sleep
#define TX_NO_TIME_SLICE
char CHAR
ThreadX-compatible CHAR (host stub).
#define TX_AUTO_START
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
Opaque thread stand-in for the host build.
Configuration passed to ra8_ble_open.
Definition ra8_ble.h:87