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
44
45#include <stdint.h>
46
47#include "ra8_attributes.h"
48#include "ra8_board_ek_ra8d2.h"
49#include "ra8_boot_entry.h"
50#include "ra8_cgc.h"
51#include "ra8_err.h"
52#include "ra8_isr.h"
53#include "ra8_port_constants.h"
54#include "ra8_port_utils.h"
55
56/*
57 * The host unit-test build (RA8_OFF_TARGET) does not link the
58 * ThreadX vendor tree, so `tx_api.h` is unreachable when clang-tidy
59 * walks this file. Pull it in only on the cross-compile target.
60 */
61#ifndef RA8_OFF_TARGET
62#include "tx_api.h"
63#endif
64
65/* ---------------------------------------------------------------------------
66 * Timer-thread tunables (typed enums per the project's no-magic-number rule).
67 * --------------------------------------------------------------------------- */
68
78typedef enum : uint16_t {
81
85typedef enum : uint8_t {
88
97typedef enum : uint16_t {
101
102#ifndef RA8_OFF_TARGET
103/* ---------------------------------------------------------------------------
104 * Static thread + stack storage. Only meaningful on the cross build,
105 * where TX_THREAD is defined by the ThreadX vendor headers.
106 * --------------------------------------------------------------------------- */
107
112[[gnu::aligned(8)]] static uint8_t s_thread_a_stack[k_blink_thread_stack_bytes];
113
117[[gnu::aligned(8)]] static uint8_t s_thread_b_stack[k_blink_thread_stack_bytes];
118
123
128
148volatile uint32_t g_threadx_blink_tick = 0U;
149
150/* SysTick handler lives in libs/ra8_core/src/ra8_time.c -- the project's
151 * shared weak SysTick_Handler dispatches to ThreadX (via a weak extern
152 * to `_tx_timer_interrupt`) so no per-app override is needed. Closes
153 * Issue #8. */
154
155/* ---------------------------------------------------------------------------
156 * Thread bodies.
157 * --------------------------------------------------------------------------- */
158
180{
181 (void)thread_input;
182 while (1) {
186 }
187}
188
209{
210 (void)thread_input;
211 while (1) {
214 }
215}
216
217/* ---------------------------------------------------------------------------
218 * tx_application_define -- ThreadX calls this once, just before the first
219 * scheduling decision, with the address of the first byte of unused RAM.
220 * Threads are created here, NOT in main(), because the kernel needs them
221 * registered before tx_kernel_enter dispatches.
222 * --------------------------------------------------------------------------- */
223
244void tx_application_define(void* first_unused_memory)
245{
246 static CHAR s_thread_a_name[] = "blink_a";
247 static CHAR s_thread_b_name[] = "blink_b";
248
249 (void)first_unused_memory;
250
252 s_thread_a_name,
254 0U,
261 if (err != TX_SUCCESS) {
262 while (1) {
263 __asm__ volatile("wfi");
264 }
265 }
266
268 s_thread_b_name,
270 0U,
277 if (err != TX_SUCCESS) {
278 while (1) {
279 __asm__ volatile("wfi");
280 }
281 }
282}
283#endif /* !RA8_OFF_TARGET */
284
285/* ---------------------------------------------------------------------------
286 * main() -- driver init, then drop into the ThreadX scheduler.
287 * --------------------------------------------------------------------------- */
288
301void main(void)
302{
303 /* CGC bring-up FIRST. tx_initialize_low_level.S programs SysTick
304 * with a reload of (1 GHz / 1000 - 1) = 999999 cycles per tick
305 * (chip HUM Ch 11 CGC, plus our port/threadx/src/cortex_m85/
306 * tx_initialize_low_level.S RA8_BOOT_CLOCK_HZ value). If the chip
307 * is still on MOCO (~8.4 MHz) at scheduler-enter time, that
308 * 999999-cycle reload takes ~119 ms wallclock instead of 1 ms --
309 * a 119x slowdown, which makes tx_thread_sleep(500 ticks) sleep
310 * for ~60 s and the LED toggle look frozen in any reasonable
311 * HIL window. Bring up the PLL before tx_kernel_enter so the
312 * scheduler tick rate matches what tx_user.h declared. */
313 if (ra8_cgc_init() != k_ra8_ok) {
314 while (1) {
315 __asm__ volatile("wfi");
316 }
317 }
318
319 /* GPIO init runs with PRIMASK set; ThreadX will re-enable IRQs once
320 * its scheduler is up. */
322 while (1) {
323 __asm__ volatile("wfi");
324 }
325 }
327 while (1) {
328 __asm__ volatile("wfi");
329 }
330 }
331
332 /* Drop into ThreadX. Returns only on internal scheduler error.
333 * The host build has no kernel, so it just falls into the WFI loop. */
334#ifndef RA8_OFF_TARGET
335 tx_kernel_enter();
336#endif
337
338 /* Belt + suspenders. */
339 while (1) {
340 __asm__ volatile("wfi");
341 }
342}
void main(void)
Secure fallback main entry point.
Definition main.c:37
void tx_application_define(void *first_unused_memory)
ThreadX system-define hook: build worker thread + byte pool.
Definition main.c:942
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
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_led2
LED2, GREEN, P303 (jumper E26).
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
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
NVIC + ICU IELSR allocator.
Typed Port / Pin Constants for the RA8D2 IOPORT Module.
High-level GPIO helpers on top of the PORT + PFS register layer.
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
#define TX_SUCCESS
#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.