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
34
35#include <stdint.h>
36
37#include "ra8_attributes.h"
38#include "ra8_board_ek_ra8d2.h"
39#include "ra8_boot_entry.h"
40#include "ra8_canfd.h"
41#include "ra8_cgc.h"
42#include "ra8_err.h"
43#include "ra8_isr.h"
44#include "ra8_port_constants.h"
45#include "ra8_port_utils.h"
46
47#ifndef RA8_OFF_TARGET
48#include "tx_api.h"
49#endif
50
51/* ---------------------------------------------------------------------------
52 * Tunables (typed enums per the no-magic-number rule).
53 * --------------------------------------------------------------------------- */
54
58typedef enum : uint8_t {
67
68typedef enum : uint16_t {
71
75typedef enum : uint8_t {
78
88
92typedef enum : uint32_t {
96
97/* SysTick handler lives in libs/ra8_core/src/ra8_time.c -- the project's
98 * shared weak SysTick_Handler dispatches to ThreadX (via a weak extern
99 * to `_tx_timer_interrupt`) so no per-app override is needed. */
100
101#ifndef RA8_OFF_TARGET
102[[gnu::aligned(8)]] static uint8_t s_thread_tx_stack[k_canfd_thread_stack_bytes];
103[[gnu::aligned(8)]] static uint8_t s_thread_rx_stack[k_canfd_thread_stack_bytes];
106
121volatile uint32_t g_threadx_canfd_match = 0U;
122
134volatile uint32_t g_threadx_canfd_mismatch = 0U;
135
161{
162 (void)thread_input;
163 uint8_t seq = 0U;
164 while (1) {
165 ra8_canfd_frame_t tx = {
166 .id = (uint32_t)k_canfd_heartbeat_id,
167 .dlc = (uint8_t)k_canfd_heartbeat_dlc,
168 .is_extended = 0U,
169 .is_fd = 0U,
170 .is_brs = 0U,
171 .data = {seq,
179 };
180 if (ra8_canfd_transmit((uint8_t)k_canfd_demo_channel, &tx) == k_ra8_ok) {
183 } else {
185 }
186 seq++;
188 }
189}
190
216{
217 (void)thread_input;
218 while (1) {
219 ra8_canfd_frame_t rx = {};
220 const ra8_err_t err = ra8_canfd_receive((uint8_t)k_canfd_demo_channel, &rx);
221 if (err == k_ra8_ok) {
224 } else if (err != k_ra8_err_no_data) {
226 }
228 }
229}
230
241void tx_application_define(void* first_unused_memory)
242{
243 static CHAR s_thread_tx_name[] = "canfd_tx";
244 static CHAR s_thread_rx_name[] = "canfd_rx";
245
246 (void)first_unused_memory;
247
249 s_thread_tx_name,
251 0U,
258 if (err != TX_SUCCESS) {
259 while (1) {
260 __asm__ volatile("wfi");
261 }
262 }
263
265 s_thread_rx_name,
267 0U,
274 if (err != TX_SUCCESS) {
275 while (1) {
276 __asm__ volatile("wfi");
277 }
278 }
279}
280#endif /* !RA8_OFF_TARGET */
281
290void main(void)
291{
292 /* CGC bring-up FIRST so the ThreadX SysTick reload (programmed in
293 * tx_initialize_low_level.S assuming RA8_BOOT_CLOCK_HZ = 1 GHz)
294 * ticks at the intended 1 ms wallclock cadence. On MOCO (~8.4 MHz)
295 * the tick rate would be 1/119 the expected, making
296 * tx_thread_sleep(...) ~119x slower than the ms value declared in
297 * source. */
298 if (ra8_cgc_init() != k_ra8_ok) {
299 while (1) {
300 __asm__ volatile("wfi");
301 }
302 }
303
305 while (1) {
306 __asm__ volatile("wfi");
307 }
308 }
310 while (1) {
311 __asm__ volatile("wfi");
312 }
313 }
314
316 while (1) {
317 __asm__ volatile("wfi");
318 }
319 }
321 (uint32_t)k_canfd_demo_bitrate,
322 (uint32_t)k_canfd_demo_bitrate) != k_ra8_ok) {
323 while (1) {
324 __asm__ volatile("wfi");
325 }
326 }
327 /* Internal-loopback (HUM Ch 41 "CFDCnCTR" p 2710): TX frames echo
328 * into RX so this single-board demo can validate the round trip
329 * without a second CAN node on the bus. */
331 while (1) {
332 __asm__ volatile("wfi");
333 }
334 }
335
337
338#ifndef RA8_OFF_TARGET
339 tx_kernel_enter();
340#endif
341
342 while (1) {
343 __asm__ volatile("wfi");
344 }
345}
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
@ k_canfd_demo_channel
CANFD demo channel.
Definition main.c:53
@ k_canfd_demo_bitrate
CANFD demo bitrate.
Definition main.c:46
canfd_stack_t
Definition main.c:68
@ k_canfd_thread_stack_bytes
CANFD thread stack bytes.
Definition main.c:69
canfd_link_t
CAN-FD channel + bit-rate constants shared by both threads.
Definition main.c:92
static TX_THREAD s_thread_tx
Definition main.c:104
static uint8_t s_thread_rx_stack[k_canfd_thread_stack_bytes]
Definition main.c:103
canfd_priority_t
Thread priorities.
Definition main.c:75
@ k_canfd_thread_priority
CANFD thread priority.
Definition main.c:76
volatile uint32_t g_threadx_canfd_match
HIL success counter – one increment per successful CAN-FD transmit (TX thread) or per accepted RX fra...
Definition main.c:121
static TX_THREAD s_thread_rx
Definition main.c:105
static void internal_thread_tx_entry(ULONG thread_input)
Heartbeat TX thread: send a CAN-FD frame each period.
Definition main.c:160
static void internal_thread_rx_entry(ULONG thread_input)
RX polling thread: drain the loopback-mirrored frame.
Definition main.c:215
canfd_marker_t
Stack size, in bytes, for each CANFD demo thread.
Definition main.c:58
@ k_canfd_marker_5
CANFD marker 5.
Definition main.c:64
@ k_canfd_marker_1
CANFD marker 1.
Definition main.c:60
@ k_canfd_marker_3
CANFD marker 3.
Definition main.c:62
@ k_canfd_marker_6
CANFD marker 6.
Definition main.c:65
@ k_canfd_marker_4
CANFD marker 4.
Definition main.c:63
@ k_canfd_marker_2
CANFD marker 2.
Definition main.c:61
@ k_canfd_marker_0
CANFD marker 0.
Definition main.c:59
volatile uint32_t g_threadx_canfd_mismatch
HIL failure counter – one increment per TX or RX error.
Definition main.c:134
canfd_period_t
Period and identifier values used by the heartbeat thread.
Definition main.c:82
@ k_canfd_rx_poll_ticks
50 ms RX poll cadence.
Definition main.c:84
@ k_canfd_heartbeat_id
11-bit CAN identifier.
Definition main.c:85
@ k_canfd_heartbeat_dlc
Data length code (bytes).
Definition main.c:86
@ k_canfd_heartbeat_ticks
500 ms in 1 kHz ticks.
Definition main.c:83
static uint8_t s_thread_tx_stack[k_canfd_thread_stack_bytes]
Definition main.c:102
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.
CANFD Lite driver (bit-timing, TX, RX, error state).
ra8_err_t ra8_canfd_transmit(uint8_t channel, const ra8_canfd_frame_t *frame)
Queue a frame into the TX message buffer and trigger transmission.
ra8_err_t ra8_canfd_set_bitrate(uint8_t channel, uint32_t bitrate_bps, uint32_t data_bitrate_bps)
Programme nominal (and optional data) bit-timing registers.
ra8_err_t ra8_canfd_receive(uint8_t channel, ra8_canfd_frame_t *out_frame)
Poll the RX FIFO for the next available frame.
ra8_err_t ra8_canfd_init(uint8_t channel)
Take a CANFD channel out of reset into operation mode.
Definition ra8_canfd.c:510
ra8_err_t ra8_canfd_set_test_mode(uint8_t channel, ra8_ctms_mode_t mode)
Enable a CFDC[0].CTR test mode (basic / listen-only / loopback).
Definition ra8_canfd.c:731
@ k_ra8_ctms_self_test_1
11b: Self-test 1 (internal loopback).
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_err_no_data
No application data available (e.g.
Definition ra8_err.h:202
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Definition ra8_isr.c:439
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.
A single CAN / CAN-FD frame as seen by the driver public API.
Definition ra8_canfd.h:52