ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_eth_coma.c
Go to the documentation of this file.
1
16
17#include "ra8_eth_coma.h"
18
19#include <stdint.h>
20
21#include "ra8_check.h"
22#include "ra8_err.h"
23#include "ra8_ether_regs.h"
24#include "ra8_hw_err.h"
25#include "ra8_log.h"
26#include "ra8_mstp.h"
27#include "ra8_mstp_regs.h"
28
29static const char* s_tag = "ETHCMA";
30
45typedef enum : uint32_t {
49
51static void* s_coma_ctx;
52
54{
55 /* HUM Ch 11.2.8 "MSTPCRC : Module Stop Control Register C" p 446 */
57 /* GCOVR_EXCL_BR_START -- MSTP HW readback */
58 RA8_RETURN_ON_ERROR(mst_err, s_tag, "coma_init: mstp enable");
59 /* GCOVR_EXCL_BR_STOP */
60
61 volatile r_coma_regs_t* reg = ra8_coma();
62 /* HUM Ch 31 "Ethernet Common Agent (COMA)" p 1590 */
63 reg->COMA_CTRL = 0U;
64 reg->COMA_STS = 0U;
65 reg->COMA_IE = 0U;
66 reg->COMA_ICLR = 0U;
67 ra8_log_info(s_tag, "coma_init");
68 return k_ra8_ok;
69}
70
72{
73 volatile r_coma_regs_t* reg = ra8_coma();
74 /* HUM Ch 31 "Ethernet Common Agent (COMA)" p 1590 */
75 reg->COMA_CTRL = 0U;
76 reg->COMA_IE = 0U;
77 s_coma_fn = nullptr;
78 s_coma_ctx = nullptr;
80}
81
83{
84 /* Step 1: pulse RRC.RR (1 then 0) to reset the ESWM IP, then settle. */
85 /* HUM Ch 31 "Ethernet Common Agent (COMA)" p 1590 */
86 *ra8_coma_rrc() = (uint32_t)k_ra8_coma_rrc_rr;
87 *ra8_coma_rrc() = 0U;
88 for (volatile uint32_t i = 0U; i < (uint32_t)k_ra8_eth_coma_delay_iters; ++i) {
89 __asm__ volatile("nop");
90 }
91
92 /* Step 2: enable the switch clock (RCE) alone, then settle. */
93 /* HUM Ch 31 "Ethernet Common Agent (COMA)" p 1590 */
95 for (volatile uint32_t i = 0U; i < (uint32_t)k_ra8_eth_coma_delay_iters; ++i) {
96 __asm__ volatile("nop");
97 }
98
99 /* Step 3: kick the buffer-pool init and wait for BPR. Writing BPIOG = 1
100 * starts the pool reset; BPR self-sets clk_period x 512 later. On the host
101 * build CABPIRM is mmap'd RAM with no hardware to self-set BPR, so the
102 * shared bounded waiter consults the ra8_fake_mmio fault seam -- first-poll
103 * success unless a test arms a timeout on this register. */
104 /* HUM Ch 31.3.2.7 "CABPIRM" p 1599 */
106 /* HUM Ch 31.3.2.7 "CABPIRM" p 1599 */
108 (uint32_t)k_ra8_coma_cabpirm_bpr,
110 if (bpr_err != k_ra8_ok) {
111 ra8_log_error(s_tag, "coma_bringup: CABPIRM.BPR timeout");
112 return bpr_err;
113 }
114
115 /* Step 4: fan out every per-agent clock (RCE | ACE[6:0] = ALL) so
116 * RMAC0/1 + ETHA0/1 + GWCA + MFWD + GPTP all become accessible. */
117 /* HUM Ch 31 "Ethernet Common Agent (COMA)" p 1590 */
119 for (volatile uint32_t i = 0U; i < (uint32_t)k_ra8_eth_coma_delay_iters; ++i) {
120 __asm__ volatile("nop");
121 }
122 ra8_log_info(s_tag, "coma_bringup");
123 return k_ra8_ok;
124}
125
127{
128 RA8_CHECK_NULL_PTR(out_mask, s_tag, "out_mask must not be nullptr");
129 /* HUM Ch 31 "Ethernet Common Agent (COMA)" p 1590 */
130 *out_mask = ra8_coma()->COMA_STS;
131 return k_ra8_ok;
132}
133
135{
136 volatile r_coma_regs_t* reg = ra8_coma();
137 /* HUM Ch 31 "Ethernet Common Agent (COMA)" p 1590 */
138 reg->COMA_ICLR = mask;
139 reg->COMA_STS = reg->COMA_STS & ~mask;
140 return k_ra8_ok;
141}
142
144{
145 s_coma_fn = fn;
146 s_coma_ctx = ctx;
147 return k_ra8_ok;
148}
149
152{
153 volatile r_coma_regs_t* reg = ra8_coma();
154 /* HUM Ch 31 "Ethernet Common Agent (COMA)" p 1590 */
155 const uint32_t mask = reg->COMA_STS;
157 void* const ctx = s_coma_ctx;
158 reg->COMA_ICLR = mask;
159 reg->COMA_STS = 0U;
160 if (fn != nullptr) {
161 fn(ctx, mask);
162 }
163}
164
166{
167 /* HUM Ch 31 "Ethernet Common Agent (COMA)" p 1590 */
168 ra8_coma()->COMA_CTRL = 0U;
170}
171
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
#define RA8_ISR_SAFE
The function is callable from interrupt context.
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
Definition ra8_check.h:184
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
Error Code Definitions for ra8-firmware.
@ 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
ra8_err_t ra8_eth_coma_enter_stop(void)
Put COMA into MSTP-gated stop.
ra8_err_t ra8_eth_coma_exit_stop(void)
Exit MSTP-gated stop.
ra8_err_t ra8_eth_coma_attach_handler(ra8_eth_coma_event_fn_t fn, void *ctx)
Attach the shared event handler.
void ra8_eth_coma_dispatch(void)
Dispatch a COMA event.
ra8_err_t ra8_eth_coma_bringup(void)
Bring the COMA switch out of reset, init the buffer pool, and fan every per-agent clock out.
ra8_err_t ra8_eth_coma_deinit(void)
Tear down COMA.
ra8_err_t ra8_eth_coma_clear_status(uint32_t mask)
Clear COMA_STS bits via COMA_ICLR.
ra8_err_t ra8_eth_coma_get_status(uint32_t *out_mask)
Read COMA_STS.
ra8_eth_coma_delay_t
Busy-wait iteration counts for the COMA bring-up sequence.
@ k_ra8_eth_coma_delay_iters
~1-3 ms busy wait between COMA writes.
@ k_ra8_eth_coma_bpr_poll_max
CABPIRM.BPR poll upper bound.
static ra8_eth_coma_event_fn_t s_coma_fn
static void * s_coma_ctx
ra8_err_t ra8_eth_coma_init(void)
Initialise COMA.
Ethernet Common Agent (COMA) driver.
void(* ra8_eth_coma_event_fn_t)(void *ctx, uint32_t status_mask)
COMA event callback.
Ethernet controller base addresses for the Renesas RA8D2.
static volatile r_coma_regs_t * ra8_coma(void)
Get pointer to the COMA register block.
static volatile uint32_t * ra8_coma_rcec(void)
Get pointer to the 32-bit COMA.RCEC (Clock Enable Configuration).
static volatile uint32_t * ra8_coma_rrc(void)
Get pointer to the 32-bit COMA.RRC (Reset Configuration).
@ k_ra8_coma_cabpirm_bpiog
CABPIRM.BPIOG – buf-pool init kick.
@ k_ra8_coma_rrc_rr
RRC.RR – pulse to reset ESWM IP.
@ k_ra8_coma_cabpirm_bpr
CABPIRM.BPR – buf-pool ready flag.
@ k_ra8_coma_rcec_rce
RCEC.RCE – enable switch clock.
@ k_ra8_coma_rcec_ace_mask
RCEC.ACE[6:0] – agent clock enable.
static volatile uint32_t * ra8_coma_cabpirm(void)
Get pointer to the 32-bit COMA.CABPIRM (Buf-pool Init/Reset/Monitor).
Bounded wait-flag primitives for RA8D2 HAL drivers.
static ra8_err_t ra8_hw_wait_flag_set32(volatile const uint32_t *reg, uint32_t mask, uint32_t budget)
Spin until (*reg & mask) != 0 or budget runs out.
Definition ra8_hw_err.h:309
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info(tag, message)
RA8 log info.
Definition ra8_log.h:364
#define ra8_log_error(tag, message)
RA8 log error.
Definition ra8_log.h:335
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_enable(ra8_mstp_t id)
Reference-counted "ungate this peripheral" request.
Definition ra8_mstp.c:343
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
Definition ra8_mstp.c:382
Module Stop Control (MSTP) register layout for the Renesas RA8D2.
@ k_ra8_mstp_eswm
MSTPC30 ESWM.
Minimal Common Agent (COMA) register window.
volatile uint32_t COMA_ICLR
+0x0C Interrupt Clear.
volatile uint32_t COMA_CTRL
+0x00 Common Agent Control.
volatile uint32_t COMA_IE
+0x08 Interrupt Enable.
volatile uint32_t COMA_STS
+0x04 Status.