ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_sdramc.h File Reference

External SDRAM controller driver (framework). More...

#include <stdint.h>
#include "ra8_err.h"
Include dependency graph for ra8_sdramc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ra8_err_t ra8_sdramc_init (void)
 Initialise the external SDRAM at k_ra8_sdram_base_addr.
ra8_err_t ra8_sdramc_deinit (void)
 Tear down the SDRAM controller (disable refresh, clear SDICR).
ra8_err_t ra8_sdramc_set_refresh_interval (uint16_t sdrfcr)
 Change the SDRAM auto-refresh interval at runtime.
ra8_err_t ra8_sdramc_get_status (uint8_t *out_enabled)
 Read the refresh-enable bit as a status mask.
ra8_err_t ra8_sdramc_enter_stop (void)
 Disable auto-refresh for deep-sleep entry.
ra8_err_t ra8_sdramc_exit_stop (void)
 Re-enable auto-refresh after wake-up.
ra8_err_t ra8_sdramc_enter_self_refresh (void)
 Put the external SDRAM into JEDEC self-refresh mode.
ra8_err_t ra8_sdramc_exit_self_refresh (void)
 Exit SDRAM self-refresh and resume normal auto-refresh operation.

Detailed Description

External SDRAM controller driver (framework).

Declares the fixed-sequence external SDRAM controller initialization and readiness interface.

Definition in file ra8_sdramc.h.

Function Documentation

◆ ra8_sdramc_deinit()

ra8_err_t ra8_sdramc_deinit ( void )
nodiscard

Tear down the SDRAM controller (disable refresh, clear SDICR).

Since
0.1.0

Definition at line 321 of file ra8_sdramc.c.

References k_ra8_ok, ra8_sdramc(), r_sdramc_regs_t::SDCCR, and r_sdramc_regs_t::SDRFEN.

◆ ra8_sdramc_enter_self_refresh()

ra8_err_t ra8_sdramc_enter_self_refresh ( void )
nodiscard

Put the external SDRAM into JEDEC self-refresh mode.

Self-refresh is the low-power retention state in which the SDRAM device drives its own internal refresh cycles from its own oscillator while the external bus is idle. This is the required state before the MCU enters Software Standby so the SDRAM contents (working set at 0x68000000) survive sleep.

Entry sequence (HUM Ch 15.3.14, Table 15.8):

  1. Confirm all SDSR status bits are clear.
  2. Disable auto-refresh (SDRFEN = 0).
  3. Assert SDSELF.SFEN = 1; the hardware issues a final auto-refresh then switches the device to self-refresh mode.
  4. Poll SDSR.SRFST until it clears, confirming the SDRAM has accepted the self-refresh command. The poll is bounded by k_ra8_sdramc_spin_max iterations (NASA P10 Rule 2).
Returns
ra8_err_t Error code.
Return values
k_ra8_okSDRAM is now in self-refresh.
k_ra8_err_invalid_stateSDSR status bits were non-zero on entry, or SDSELF.SFEN was already 1.
k_ra8_err_hw_timeoutSDSR.SRFST did not clear within k_ra8_sdramc_spin_max polls.
Precondition
SDSR.SRFST, INIST, and MRSST are all 0 (no operation in progress).
SDSELF.SFEN is 0 (not already in self-refresh).
Postcondition
On k_ra8_ok, SDSELF.SFEN is 1 (self-refresh active).
On k_ra8_ok, SDSR.SRFST is 0 (transition complete).
Note
Not thread-safe. Must be called from a context that guarantees exclusive access to the SDRAMC register block.
SDRAM contents remain valid throughout self-refresh. No DMA or CPU access to the SDRAM window (0x68000000) may occur while in self-refresh.
See also
ra8_sdramc_exit_self_refresh() Paired exit function.
ra8_sdramc_enter_stop() Deeper stop (loses refresh entirely).
Since
0.1.0
HUM:
Ch 15.3.14 "SDSELF : SDRAM Self-Refresh Control Register" p 606. Ch 15.3.22 "SDSR : SDRAM Status Register" p 613. Ch 15.3.16 "SDRFEN : SDRAM Auto-Refresh Control Register" p 608.
NASA Power of 10 Compliance:
  • Rule 2: SDSR poll loop bounded by k_ra8_sdramc_spin_max.
  • Rule 5: 2 precondition checks (SDSR idle, SFEN clear).

Definition at line 360 of file ra8_sdramc.c.

References internal_sdramc_wait(), k_ra8_err_invalid_state, k_ra8_ok, k_ra8_sdself_sfen, k_ra8_sdsr_all, k_ra8_sdsr_srfst, ra8_log_error, ra8_log_info, ra8_sdramc(), s_tag, r_sdramc_regs_t::SDRFEN, r_sdramc_regs_t::SDSELF, and r_sdramc_regs_t::SDSR.

◆ ra8_sdramc_enter_stop()

ra8_err_t ra8_sdramc_enter_stop ( void )
nodiscard

Disable auto-refresh for deep-sleep entry.

Since
0.1.0

Definition at line 346 of file ra8_sdramc.c.

References k_ra8_ok, ra8_sdramc(), and r_sdramc_regs_t::SDRFEN.

◆ ra8_sdramc_exit_self_refresh()

ra8_err_t ra8_sdramc_exit_self_refresh ( void )
nodiscard

Exit SDRAM self-refresh and resume normal auto-refresh operation.

Clears SDSELF.SFEN to end self-refresh. The hardware performs SDRFCR.REFW self-refresh clearing cycles before returning the device to normal auto-refresh mode. Auto-refresh is then explicitly re-enabled via SDRFEN.

Exit sequence (HUM Ch 15.3.14, Table 15.8):

  1. Confirm SDSELF.SFEN is 1 (currently in self-refresh).
  2. Confirm SDSR.SRFST is 0 (no transition in progress).
  3. Clear SDSELF.SFEN = 0; the hardware runs the clearing cycles.
  4. Poll SDSR.SRFST until it clears (recovery complete).
  5. Re-enable auto-refresh (SDRFEN = 1).
Returns
ra8_err_t Error code.
Return values
k_ra8_okSDRAM has returned to auto-refresh.
k_ra8_err_invalid_stateSDSELF.SFEN was 0 (not in self-refresh) or SDSR.SRFST was set on entry.
k_ra8_err_hw_timeoutSDSR.SRFST did not clear within k_ra8_sdramc_spin_max polls.
Precondition
SDSELF.SFEN is 1 (currently in self-refresh).
SDSR.SRFST is 0 (self-refresh entry transition is complete).
Postcondition
On k_ra8_ok, SDSELF.SFEN is 0 (self-refresh inactive).
On k_ra8_ok, SDRFEN.RFEN is 1 (auto-refresh re-enabled).
Note
Not thread-safe. Must be called before resuming any DMA or CPU access to the SDRAM window (0x68000000).
Must be called after the MCU returns from Software Standby before any access to 0x68000000 is safe.
See also
ra8_sdramc_enter_self_refresh() Paired entry function.
Since
0.1.0
HUM:
Ch 15.3.14 "SDSELF : SDRAM Self-Refresh Control Register" p 606. Ch 15.3.22 "SDSR : SDRAM Status Register" p 613. Ch 15.3.16 "SDRFEN : SDRAM Auto-Refresh Control Register" p 608.
NASA Power of 10 Compliance:
  • Rule 2: SDSR poll loop bounded by k_ra8_sdramc_spin_max.
  • Rule 5: 2 precondition checks (SFEN set, SRFST clear).

Definition at line 400 of file ra8_sdramc.c.

References internal_sdramc_wait(), k_ra8_err_invalid_state, k_ra8_ok, k_ra8_sdramc_kick, k_ra8_sdself_sfen, k_ra8_sdsr_srfst, ra8_log_error, ra8_log_info, ra8_sdramc(), s_tag, r_sdramc_regs_t::SDRFEN, r_sdramc_regs_t::SDSELF, and r_sdramc_regs_t::SDSR.

◆ ra8_sdramc_exit_stop()

ra8_err_t ra8_sdramc_exit_stop ( void )
nodiscard

Re-enable auto-refresh after wake-up.

Since
0.1.0

Definition at line 353 of file ra8_sdramc.c.

References k_ra8_ok, k_ra8_sdramc_kick, ra8_sdramc(), and r_sdramc_regs_t::SDRFEN.

◆ ra8_sdramc_get_status()

ra8_err_t ra8_sdramc_get_status ( uint8_t * out_enabled)
nodiscard

Read the refresh-enable bit as a status mask.

Parameters
[out]out_enabledNon-zero when SDRFEN is set.
Since
0.1.0

Definition at line 338 of file ra8_sdramc.c.

References k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_sdramc(), s_tag, and r_sdramc_regs_t::SDRFEN.

◆ ra8_sdramc_init()

◆ ra8_sdramc_set_refresh_interval()

ra8_err_t ra8_sdramc_set_refresh_interval ( uint16_t sdrfcr)
nodiscard

Change the SDRAM auto-refresh interval at runtime.

Parameters
[in]sdrfcrNew SDRFCR value.
Since
0.1.0

Definition at line 331 of file ra8_sdramc.c.

References k_ra8_ok, ra8_sdramc(), and r_sdramc_regs_t::SDRFCR.