ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
cpu1_main.c
Go to the documentation of this file.
1
32
33#include <stdint.h>
34
35#include "dualcore_mailbox.h"
36#include "ra8_err.h"
37
39extern uint32_t g_ra8_ls_cpu1_stack_top;
41extern uint32_t g_ra8_ls_cpu1_data_start;
43extern uint32_t g_ra8_ls_cpu1_data_end;
45extern uint32_t g_ra8_ls_cpu1_data_load;
47extern uint32_t g_ra8_ls_cpu1_bss_start;
49extern uint32_t g_ra8_ls_cpu1_bss_end;
50
51[[noreturn]] void cpu1_reset_handler(void);
52
72[[noreturn]] static void cpu1_main(void)
73{
74 volatile dualcore_mailbox_t* mb = dualcore_mailbox();
75 uint32_t last_seen = 0U;
76 uint32_t reply_count = 0U;
77
78 /* Announce we are alive before servicing anything: the M85 polls this
79 * field to confirm the M33 left reset and is executing user code. */
81 __asm volatile("dsb" ::: "memory");
82
83 while (1) {
84 /* Spin until the M85 advances the request sequence. The volatile read
85 * forces a fresh load each iteration. Bound: the M85 drives this. */
86 while (mb->request_seq == last_seen) {
87 __asm volatile("nop");
88 }
89 last_seen = mb->request_seq;
90
91 /* Transform the operand. Reading `request` after observing the seq bump
92 * guarantees we see the payload the M85 wrote before bumping the seq. */
93 const uint32_t operand = mb->request;
94 const uint32_t answer = (operand * (uint32_t)k_dualcore_m33_mul) + (uint32_t)k_dualcore_m33_add;
95
96 mb->reply = answer;
97 reply_count++;
98 mb->m33_replies = reply_count;
99 /* Drain the write buffer so the M85 sees `reply` + `m33_replies` before
100 * it sees the `reply_seq` ack on the next store. */
101 __asm volatile("dsb" ::: "memory");
102 mb->reply_seq = last_seen;
103 }
104}
105
126[[noreturn]] void cpu1_reset_handler(void)
127{
128 uint32_t* dst = &g_ra8_ls_cpu1_data_start;
129 uint32_t* src = &g_ra8_ls_cpu1_data_load;
130 while (dst < &g_ra8_ls_cpu1_data_end) {
131 *dst = *src;
132 dst++;
133 src++;
134 }
135
136 uint32_t* bss = &g_ra8_ls_cpu1_bss_start;
137 while (bss < &g_ra8_ls_cpu1_bss_end) {
138 *bss = 0U;
139 bss++;
140 }
141
142 cpu1_main();
143}
144
162[[noreturn]] static void cpu1_fault_handler(void)
163{
164 while (1) {
165 __asm volatile("nop");
166 }
167}
168
179#ifndef RA8_OFF_TARGET
180/* The vector table is only meaningful in the cross-compiled M33 image. The
181 * host unit-test build compile-checks this TU but never links it as an
182 * executable, so dropping the table there costs no coverage. */
183[[gnu::used, gnu::section(".cpu1_vectors")]] const uintptr_t g_cpu1_vector_table[] = {
184 (uintptr_t)&g_ra8_ls_cpu1_stack_top,
185 (uintptr_t)&cpu1_reset_handler,
186 (uintptr_t)&cpu1_fault_handler,
187 (uintptr_t)&cpu1_fault_handler,
188 (uintptr_t)&cpu1_fault_handler,
189 (uintptr_t)&cpu1_fault_handler,
190 (uintptr_t)&cpu1_fault_handler,
191 (uintptr_t)&cpu1_fault_handler,
192};
193#endif
Shared-SRAM mailbox layout for the M85 <-> M33 dual-core demo.
static volatile dualcore_mailbox_t * dualcore_mailbox(void)
Typed pointer to the fixed-address shared mailbox.
@ k_dualcore_m33_add
Reply = request * mul + add.
@ k_dualcore_m33_mul
Reply = request * mul + add.
@ k_dualcore_m33_signature
M33 stamps this once it boots ("33").
void cpu1_reset_handler(void)
CPU1 reset handler.
Definition cpu1_main.c:266
uint32_t g_ra8_ls_cpu1_data_end
uint32_t g_ra8_ls_cpu1_bss_start
uint32_t g_ra8_ls_cpu1_data_load
uint32_t g_ra8_ls_cpu1_bss_end
const uintptr_t g_cpu1_vector_table[]
Minimal Armv8-M vector table for CPU1.
Definition cpu1_main.c:337
uint32_t g_ra8_ls_cpu1_stack_top
uint32_t g_ra8_ls_cpu1_data_start
Error Code Definitions for ra8-firmware.
Cross-core message block backed by a fixed shared-SRAM address.
volatile uint32_t reply_seq
M33 sets equal to request_seq when done.
volatile uint32_t request_seq
M85 increments after writing request.
volatile uint32_t request
M85 -> M33: the operand to transform.
volatile uint32_t m33_signature
M33 stamps k_dualcore_m33_signature.
volatile uint32_t m33_replies
M33 increments per reply (liveness count).
volatile uint32_t reply
M33 -> M85: request * 3 + 1.