ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_elc.c
Go to the documentation of this file.
1
18
19#include "ra8_elc.h"
20
21#include <stdint.h>
22
23#include "ra8_attributes.h"
24#include "ra8_check.h"
25#include "ra8_elc_regs.h"
26#include "ra8_err.h"
27#include "ra8_log.h"
28#include "ra8_mstp.h"
29#include "ra8_mstp_regs.h"
30
31static const char* s_tag = "ELC";
32
33/* =============================================================================
34 * Internal register accessors
35 * =============================================================================
36 */
37
46RA8_INTERNAL static inline volatile uint8_t* internal_elcr(void)
47{
48 return (volatile uint8_t*)((uintptr_t)k_ra8_elc_base_addr + (uintptr_t)k_ra8_elc_off_elcr);
49}
50
62RA8_INTERNAL static inline volatile uint16_t* internal_elsr(uint8_t index)
63{
64 return (volatile uint16_t*)((uintptr_t)k_ra8_elc_base_addr + (uintptr_t)k_ra8_elc_off_elsr0 +
65 ((uintptr_t)index * (uintptr_t)k_ra8_elc_elsr_stride));
66}
67
80RA8_INTERNAL static inline volatile uint8_t* internal_elsegr(uint8_t group)
81{
82 return (volatile uint8_t*)((uintptr_t)k_ra8_elc_base_addr + (uintptr_t)k_ra8_elc_off_elsegr0 +
83 ((uintptr_t)group * (uintptr_t)k_ra8_elc_elsegr_stride));
84}
85
86/* =============================================================================
87 * Public API
88 * =============================================================================
89 */
90
92{
93 ra8_log_info(s_tag, "ra8_elc_init");
94
95 /* HUM Ch 11.2.8 "MSTPCRC : Module Stop Control Register C", p 447 */
97 /* GCOVR_EXCL_BR_START -- MSTP HW readback */
98 RA8_RETURN_ON_ERROR(mst_err, s_tag, "elc_init: mstp enable");
99 /* GCOVR_EXCL_BR_STOP */
100
101 /* Clear every ELSR slot before flipping ELCON so stale routes
102 * don't fire spuriously.
103 * HUM Ch 19.2.3 "ELSRn : Event Link Setting Register n", p 820 */
104 for (uint8_t i = 0U; i < k_ra8_elc_elsr_count; ++i) {
105 *internal_elsr(i) = 0U;
106 }
107
108 /* HUM Ch 19.2.2 "ELSEGRn : Event Link Software Event Generation",
109 * p 819 -- writing 0 clears WI/WE/SEG so subsequent
110 * ra8_elc_software_trigger calls start from a clean state. */
111 for (uint8_t g = 0U; g < k_ra8_elc_segr_count; ++g) {
113 }
114
115 /* HUM Ch 19.2.1 "ELCR : Event Link Control Register", p 819 */
116 *internal_elcr() = (uint8_t)(1U << k_ra8_elcr_bit_elcon);
117 return k_ra8_ok;
118}
119
121{
122 /* HUM Ch 19.2.1 "ELCR : Event Link Control Register", p 819 */
123 *internal_elcr() = 0U;
125}
126
127ra8_err_t ra8_elc_link(uint8_t elsr_index, ra8_elc_event_t event)
128{
129 if (elsr_index >= k_ra8_elc_elsr_count) {
131 }
132 /* HUM Ch 19.2.3 "ELSRn : Event Link Setting Register n", p 820 */
133 *internal_elsr(elsr_index) = (uint16_t)event;
134 return k_ra8_ok;
135}
136
137ra8_err_t ra8_elc_unlink(uint8_t elsr_index)
138{
139 if (elsr_index >= k_ra8_elc_elsr_count) {
141 }
142 /* HUM Ch 19.2.3 "ELSRn : Event Link Setting Register n", p 820 */
143 *internal_elsr(elsr_index) = 0U;
144 return k_ra8_ok;
145}
146
148{
149 if (event_index >= k_ra8_elc_segr_count) {
151 }
152 /* HUM Ch 19.2.2 "ELSEGRn : Event Link Software Event Generation
153 * Register n", p 819. ELSEGRn is write-protected by WI/WE; SEG
154 * latches only after the documented three-write sequence. The
155 * same sequence is used by FSP R_ELC_SoftwareEventGenerate
156 * (`ELC_ELSEGRN_STEP1..3`). */
157 volatile uint8_t* elsegr = internal_elsegr(event_index);
161 return k_ra8_ok;
162}
163
165{
166 RA8_CHECK_NULL_PTR(out_enabled, s_tag, "is_enabled out");
167 /* HUM Ch 19.2.1 "ELCR : Event Link Control Register", p 819 */
168 const uint8_t val = *internal_elcr();
169 *out_enabled = ((val & (uint8_t)(1U << k_ra8_elcr_bit_elcon)) != 0U);
170 return k_ra8_ok;
171}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
Annotation-attribute framework macros for ra8-firmware.
#define RA8_HW_REGISTER_ACCESS
Mark an MMIO accessor function (returns volatile register pointer).
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
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
static volatile uint8_t * internal_elcr(void)
Pointer to the 8-bit ELCR register.
Definition ra8_elc.c:46
ra8_err_t ra8_elc_unlink(uint8_t elsr_index)
Clear one ELSR slot so it stops routing any event.
Definition ra8_elc.c:137
ra8_err_t ra8_elc_deinit(void)
Disable the ELC globally (ELCR.ELCON = 0) and stop the module.
Definition ra8_elc.c:120
ra8_err_t ra8_elc_link(uint8_t elsr_index, ra8_elc_event_t event)
Route an ELC event to an ELSR slot so the destination peripheral triggers on it.
Definition ra8_elc.c:127
static volatile uint8_t * internal_elsegr(uint8_t group)
Pointer to the 8-bit ELSEGRn (BY) register at index group.
Definition ra8_elc.c:80
ra8_err_t ra8_elc_is_enabled(bool *out_enabled)
Read ELCR.ELCON to verify the global enable state.
Definition ra8_elc.c:164
ra8_err_t ra8_elc_init(void)
Reset the ELC register block and enable the controller.
Definition ra8_elc.c:91
static volatile uint16_t * internal_elsr(uint8_t index)
Pointer to ELSR slot index.
Definition ra8_elc.c:62
ra8_err_t ra8_elc_software_trigger(uint8_t event_index)
Fire a software event via one of the ELSEGRn registers.
Definition ra8_elc.c:147
Event Link Controller driver.
@ k_ra8_elc_segr_count
ELSEGR0..ELSEGR3 (FSP R_ELC_Type).
Definition ra8_elc.h:63
@ k_ra8_elc_elsr_count
ELSR0..ELSR52 (FSP R_ELC_Type).
Definition ra8_elc.h:62
Event Link Controller (ELC) register layout for the Renesas RA8D2.
@ k_ra8_elcr_bit_elcon
ELCR.ELCON – global enable.
@ k_ra8_elc_elsegr_step_unlock
WI=0, WE=0, SEG=0 – clear write-disable.
@ k_ra8_elc_elsegr_step_trigger
WI=0, WE=1, SEG=1 – fire software event.
@ k_ra8_elc_elsegr_step_arm
WI=0, WE=1, SEG=0 – arm SEG bit for write.
@ k_ra8_elc_elsr_stride
Stride between ELSR slots.
@ k_ra8_elc_off_elsr0
ELSR[0]: first link slot, ELSR0..ELSR52 (16b, stride 4).
@ k_ra8_elc_off_elsegr0
ELSEGR[0]: software event gen 0 (8b, stride 4).
@ k_ra8_elc_off_elcr
ELCR: global enable bit ELCON @ bit 7 (8b).
@ k_ra8_elc_elsegr_stride
Stride between ELSEGR slots.
@ k_ra8_elc_base_addr
RA8 elc base address.
ra8_elc_event_t
Partial list of ELC events (populate as drivers need them).
Error Code Definitions for ra8-firmware.
@ k_ra8_err_out_of_range
Sensor or peripheral output out of valid range.
Definition ra8_err.h:337
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ 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
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info(tag, message)
RA8 log info.
Definition ra8_log.h:364
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_elc
MSTPC14 ELC.