ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_pfs_regs.h
Go to the documentation of this file.
1
48
49#pragma once
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55#include <stdint.h>
56
57#include "ra8_attributes.h"
58#include "ra8_bit_constants.h"
59#include "ra8_port_constants.h"
60
61/* =============================================================================
62 * Base addresses + layout
63 * =============================================================================
64 */
65
66typedef enum : uintptr_t {
67 k_ra8_pfs_base_addr = 0x40400800UL,
68 k_ra8_pmisc_base_addr = 0x40400D00UL,
70
71typedef enum : uint16_t {
77
78/* =============================================================================
79 * Packed PFS entry -- one per pin
80 * =============================================================================
81 *
82 * Each pin has a 32-bit register. We expose it as a volatile uint32_t*
83 * rather than a bitfield union because bitfield writes are
84 * implementation-defined for write-protected registers: GCC may emit
85 * a read-modify-write that hits the protected read path. A plain
86 * 32-bit write is guaranteed to do one store.
87 */
88
108
113typedef enum : uint32_t {
114 k_ra8_pfs_mask_podr = 0x00000001UL,
115 k_ra8_pfs_mask_pdr = 0x00000004UL,
116 k_ra8_pfs_mask_pcr = 0x00000010UL,
117 k_ra8_pfs_mask_ncodr = 0x00000040UL,
118 k_ra8_pfs_mask_dscr = 0x00000C00UL,
119 k_ra8_pfs_mask_eofr = 0x00003000UL,
120 k_ra8_pfs_mask_isel = 0x00004000UL,
121 k_ra8_pfs_mask_asel = 0x00008000UL,
122 k_ra8_pfs_mask_pmr = 0x00010000UL,
123 k_ra8_pfs_mask_psel = 0x1F000000UL,
125
150
160static inline volatile uint32_t* ra8_pfs_pmn(ra8_port_t port, ra8_pin_t pin)
161{
162 if ((uint8_t)port > k_ra8_port_max) {
163 return nullptr;
164 }
165 if ((uint8_t)pin > k_ra8_pin_max) {
166 return nullptr;
167 }
168
169 /* Each pin is 4 bytes; each port is (k_ra8_pin_count * 4) = 64 bytes apart. */
170 const uintptr_t flat_idx = ((uintptr_t)port * (uintptr_t)k_ra8_pin_count) + (uintptr_t)pin;
171 return (volatile uint32_t*)(k_ra8_pfs_base_addr + (flat_idx * sizeof(uint32_t)));
172}
173
174/* =============================================================================
175 * PWPR unlock / lock
176 * =============================================================================
177 */
178
183typedef enum : uint8_t {
187
190static inline volatile uint8_t* ra8_pfs_pwpr(void)
191{
192 return (volatile uint8_t*)((uintptr_t)k_ra8_pmisc_base_addr + (uintptr_t)k_ra8_pmisc_off_pwpr);
193}
194
208static inline volatile uint8_t* ra8_pfs_pwprs(void)
209{
210 return (volatile uint8_t*)((uintptr_t)k_ra8_pmisc_base_addr + (uintptr_t)k_ra8_pmisc_off_pwprs);
211}
212
241static inline void ra8_pfs_pwpr_unlock(void)
242{
243 volatile uint8_t* pwpr = ra8_pfs_pwpr();
244 volatile uint8_t* pwprs = ra8_pfs_pwprs();
245 /* HUM Ch 20.2.6 "PWPR" / 20.2.7 "PWPRS" -- B0WI must be cleared
246 * before PFSWE can be set. Unlock both NS and Secure paths so PFS
247 * writes land regardless of which world the CPU is in. */
248 *pwpr = 0U;
249 *pwpr = (uint8_t)(1U << k_ra8_pwpr_bit_pfswe);
250 *pwprs = 0U;
251 *pwprs = (uint8_t)(1U << k_ra8_pwpr_bit_pfswe);
252}
253
268static inline void ra8_pfs_pwpr_lock(void)
269{
270 volatile uint8_t* pwpr = ra8_pfs_pwpr();
271 volatile uint8_t* pwprs = ra8_pfs_pwprs();
272 *pwpr = 0U;
273 *pwpr = (uint8_t)(1U << k_ra8_pwpr_bit_b0wi);
274 *pwprs = 0U;
275 *pwprs = (uint8_t)(1U << k_ra8_pwpr_bit_b0wi);
276}
277
278#ifdef __cplusplus
279}
280#endif
Annotation-attribute framework macros for ra8-firmware.
#define RA8_HW_REGISTER_ACCESS
Mark an MMIO accessor function (returns volatile register pointer).
Named Bit Positions and Masks for Register Manipulation.
ra8_board_eth_pin_t pin
Pin.
ra8_pfs_mask_t
Full-width masks for PmnPFS fields.
@ k_ra8_pfs_mask_asel
RA8 PFS mask asel.
@ k_ra8_pfs_mask_dscr
bits 11..10.
@ k_ra8_pfs_mask_pmr
RA8 PFS mask pmr.
@ k_ra8_pfs_mask_psel
bits 28..24 (5-bit function select).
@ k_ra8_pfs_mask_isel
RA8 PFS mask isel.
@ k_ra8_pfs_mask_podr
RA8 PFS mask podr.
@ k_ra8_pfs_mask_ncodr
RA8 PFS mask ncodr.
@ k_ra8_pfs_mask_pdr
RA8 PFS mask pdr.
@ k_ra8_pfs_mask_eofr
bits 13..12.
@ k_ra8_pfs_mask_pcr
RA8 PFS mask pcr.
ra8_pwpr_bit_t
Bit positions inside the 8-bit PWPR register.
@ k_ra8_pwpr_bit_pfswe
1 = PFS writes allowed, 0 = PFS writes blocked.
@ k_ra8_pwpr_bit_b0wi
1 = PFSWE write blocked, 0 = PFSWE writable.
static volatile uint8_t * ra8_pfs_pwpr(void)
Get pointer to the PWPR register (non-secure write-protect).
ra8_pfs_bit_t
Bit positions inside the 32-bit PmnPFS register.
@ k_ra8_pfs_bit_asel
Analog input enable.
@ k_ra8_pfs_bit_psel0
Peripheral select bit 0.
@ k_ra8_pfs_bit_isel
IRQ input enable.
@ k_ra8_pfs_bit_pdr
Direction (0=in, 1=out).
@ k_ra8_pfs_bit_eofr1
Event on rising/falling hi.
@ k_ra8_pfs_bit_podr
Output data.
@ k_ra8_pfs_bit_eofr0
Event on rising/falling lo.
@ k_ra8_pfs_bit_pmr
0=GPIO, 1=peripheral.
@ k_ra8_pfs_bit_pcr
Pull-up enable.
@ k_ra8_pfs_bit_dscr0
Drive strength (low bit).
@ k_ra8_pfs_bit_pidr
Input data (read-only).
@ k_ra8_pfs_bit_dscr1
Drive strength (high bit).
@ k_ra8_pfs_bit_ncodr
N-channel open-drain enable.
ra8_pfs_addr_t
@ k_ra8_pfs_base_addr
PFS array base.
@ k_ra8_pmisc_base_addr
PMISC: contains PWPR and PWPRS.
static void ra8_pfs_pwpr_lock(void)
Re-lock PFS writes.
ra8_pfs_dscr_t
PmnPFS.DSCR[1:0] port drive-capability encodings.
@ k_ra8_pfs_dscr_high_speed_high
10b: High-speed high drive.
@ k_ra8_pfs_dscr_middle
01b: Middle drive.
@ k_ra8_pfs_dscr_high
11b: High drive.
@ k_ra8_pfs_dscr_low
00b: Low drive (reset default).
static void ra8_pfs_pwpr_unlock(void)
Unlock PFS writes.
static volatile uint32_t * ra8_pfs_pmn(ra8_port_t port, ra8_pin_t pin)
Get pointer to the PmnPFS register for a single pin.
static volatile uint8_t * ra8_pfs_pwprs(void)
Get pointer to the PWPRS register (Secure write-protect).
ra8_pmisc_off_t
@ k_ra8_pmisc_off_pwprs
PWPRS: Secure PFS Write Protect.
@ k_ra8_pmisc_off_pmsar
PMSAR[0..14]: Port Security Attribution.
@ k_ra8_pmisc_off_pwpr
PWPR: PFS Write Protect (HUM 20.2.5).
@ k_ra8_pmisc_off_pfenet
PFENET: Ethernet Mode Select.
Typed Port / Pin Constants for the RA8D2 IOPORT Module.
ra8_port_t
Port indices for the RA8D2 IOPORT module.
@ k_ra8_port_max
Highest valid port index.
ra8_pin_t
Pin indices within an IOPORT port (0..15).
@ k_ra8_pin_count
Number of pins per port.
@ k_ra8_pin_max
Highest valid pin index.