|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
12-Bit D/A Converter (DAC_B) driver implementation More...
#include "ra8_dac_b.h"#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_dac_b_regs.h"#include "ra8_err.h"#include "ra8_log.h"#include "ra8_mstp.h"Go to the source code of this file.
Data Structures | |
| struct | ra8_dac_b_state_t |
| Driver-wide runtime state. More... | |
Enumerations | |
| enum | ra8_dac_b_channel_t : uint8_t { k_ra8_dac_b_channel_0 = 0U , k_ra8_dac_b_channel_1 = 1U } |
| Named channel indices. More... | |
Functions | |
| static uint16_t | internal_ra8_dac_b_clamp (uint16_t value) |
| Clamp a raw value to 12-bit range. | |
| static void | internal_disable_channel (uint8_t channel) |
| Stop a channel and put DACR0 in the FSP "open" baseline. | |
| static void | internal_start_channel (uint8_t channel) |
| Set DACEN=1 on a channel (FSP R_DAC_B_Start equivalent). | |
| static void | internal_stop_channel (uint8_t channel) |
| Clear DACEN on a channel (FSP R_DAC_B_Stop equivalent). | |
| ra8_err_t | ra8_dac_b_init (void) |
| Legacy init – zero every DAC_B register + enable MSTP. | |
| ra8_err_t | ra8_dac_b_write (uint8_t channel, uint16_t value) |
| Programme a DAC channel with a 12-bit code. | |
| static void | internal_apply_cfg (uint8_t channel, const ra8_dac_b_cfg_t *cfg) |
| Apply cfg to one DAC_B instance (FSP R_DAC_B_Open body). | |
| ra8_err_t | ra8_dac_b_init_configured (const ra8_dac_b_cfg_t *cfg) |
| Initialise DAC_B with a full config descriptor. | |
| ra8_err_t | ra8_dac_b_deinit (void) |
| Tear down the DAC_B peripheral. | |
| ra8_err_t | ra8_dac_b_set_vref (ra8_dac_b_vref_t vref) |
| Change the DAC voltage reference at runtime. | |
| ra8_err_t | ra8_dac_b_set_output_enable (uint8_t channel, bool enable) |
| Toggle output-enable for one channel at runtime. | |
| ra8_err_t | ra8_dac_b_get_status (uint8_t *out_mask) |
| Read the DACR output-enable / DAE mask. | |
| ra8_err_t | ra8_dac_b_clear_status (void) |
| Clear DAE + DAOE bits (disable DAC outputs). | |
| ra8_err_t | ra8_dac_b_attach_handler (ra8_dac_b_update_fn_t fn, void *ctx) |
| Attach a DAC-update callback. | |
| ra8_err_t | ra8_dac_b_enter_stop (void) |
| Put DAC_B into MSTP-gated stop. | |
| ra8_err_t | ra8_dac_b_exit_stop (void) |
| Exit MSTP-gated stop. | |
| void | ra8_dac_b_dispatch_update (uint8_t channel) |
| Dispatch a DAC-update event – fire the registered callback. | |
Variables | |
| static const char * | s_tag = "DAC_B" |
| static ra8_dac_b_state_t | s_dac_b_state |
12-Bit D/A Converter (DAC_B) driver implementation
Driver for the RA8D2 DAC_B peripheral. DAC_B is the RA8 successor to the pre-RA8 DAC12 block: each DAC "channel" is a separate IP instance with its own DADR + DACR0/1/2 set. DAC_B0 and DAC_B1 live at 0x40233000 and 0x40233100 (stride 0x100). The driver hides this by keeping a 2-channel public API, with channel 0 routed to DAC_B0 and channel 1 routed to DAC_B1.
Cross-verified against FSP r_dac_b.c (R_DAC_B_Open / Write / Start / Stop / Close paths). The bit layout used here mirrors FSP R_DAC_B0_DACR{0,1,2}_*_Msk exactly. See HUM Ch 54 "12-Bit D/A Converter (DAC12)" p 3490..3496.
Definition in file ra8_dac_b.c.
| enum ra8_dac_b_channel_t : uint8_t |
Named channel indices.
| Enumerator | |
|---|---|
| k_ra8_dac_b_channel_0 | RA8 DAC b channel 0. |
| k_ra8_dac_b_channel_1 | RA8 DAC b channel 1. |
Definition at line 42 of file ra8_dac_b.c.
|
static |
Apply cfg to one DAC_B instance (FSP R_DAC_B_Open body).
See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.
| [in] | channel | See header declaration for direction and constraints. |
| [in] | cfg | See header declaration for direction and constraints. |
Definition at line 213 of file ra8_dac_b.c.
References r_dac_b_regs_t::DACR0, r_dac_b_regs_t::DACR1, r_dac_b_regs_t::DACR2, r_dac_b_regs_t::DADR, ra8_dac_b_cfg_t::data_format, ra8_dac_b_cfg_t::internal_output_enabled, k_ra8_dacr0_mask_daoutdis, k_ra8_dacr1_bit_dpsel, k_ra8_dacr2_bit_ofssel, ra8_dac_b(), RA8_INTERNAL, and ra8_dac_b_cfg_t::vref.
Referenced by ra8_dac_b_init_configured().
|
static |
Stop a channel and put DACR0 in the FSP "open" baseline.
Mirrors p_ctrl->p_reg->DACR0 &= ~(DACEN | DAOUTDIS | DAE) from FSP R_DAC_B_Open. Because we always come in here from a fresh power-on (MSTP just released), an unconditional zero is equivalent and avoids a read-modify-write hazard on a just-clocked register block.
Citation: HUM Ch 54 "12-Bit D/A Converter (DAC12)" p 3490.
| [in] | channel | See header declaration for direction and constraints. |
Definition at line 92 of file ra8_dac_b.c.
References r_dac_b_regs_t::DACR0, r_dac_b_regs_t::DADR, ra8_dac_b(), and RA8_INTERNAL.
Referenced by ra8_dac_b_enter_stop(), and ra8_dac_b_init().
|
inlinestatic |
Clamp a raw value to 12-bit range.
See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.
| [in] | value | See header declaration for direction and constraints. |
| k_ra8_ok | Success path. |
| k_ra8_err_invalid_arg | Caller violated a precondition. |
Definition at line 64 of file ra8_dac_b.c.
References k_ra8_dac_b_max_value, and RA8_INTERNAL.
Referenced by ra8_dac_b_write().
|
static |
Set DACEN=1 on a channel (FSP R_DAC_B_Start equivalent).
Pure read-modify-write of bit 0 of DACR0; preserves DAE and DAOUTDIS so callers can configure those in DACR0 before starting conversion.
| [in] | channel | See header declaration for direction and constraints. |
Definition at line 119 of file ra8_dac_b.c.
References r_dac_b_regs_t::DACR0, k_ra8_dacr0_mask_dacen, ra8_dac_b(), and RA8_INTERNAL.
Referenced by ra8_dac_b_init_configured().
|
static |
Clear DACEN on a channel (FSP R_DAC_B_Stop equivalent).
See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.
| [in] | channel | See header declaration for direction and constraints. |
Definition at line 143 of file ra8_dac_b.c.
References r_dac_b_regs_t::DACR0, k_ra8_dacr0_mask_dacen, ra8_dac_b(), and RA8_INTERNAL.
Referenced by ra8_dac_b_clear_status().
|
nodiscard |
Attach a DAC-update callback.
| [in] | fn | Callback fired on ISR dispatch. |
| [in] | ctx | Context forwarded to the callback. |
Definition at line 337 of file ra8_dac_b.c.
References k_ra8_ok, and s_dac_b_state.
|
nodiscard |
Clear DAE + DAOE bits (disable DAC outputs).
Definition at line 330 of file ra8_dac_b.c.
References internal_stop_channel(), k_ra8_dac_b_channel_0, k_ra8_dac_b_channel_1, and k_ra8_ok.
|
nodiscard |
Tear down the DAC_B peripheral.
Definition at line 260 of file ra8_dac_b.c.
References r_dac_b_regs_t::DACR0, r_dac_b_regs_t::DADR, k_ra8_dac_b_channel_0, k_ra8_dac_b_channel_1, k_ra8_dacr0_mask_daoutdis, k_ra8_mstp_dac12_0, k_ra8_mstp_dac12_1, ra8_dac_b(), ra8_mstp_disable(), and s_dac_b_state.
| void ra8_dac_b_dispatch_update | ( | uint8_t | channel | ) |
Dispatch a DAC-update event – fire the registered callback.
| [in] | channel | Channel that completed an update. |
See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.
Definition at line 362 of file ra8_dac_b.c.
References k_ra8_dac_b_channel_count, and s_dac_b_state.
|
nodiscard |
Put DAC_B into MSTP-gated stop.
Definition at line 344 of file ra8_dac_b.c.
References internal_disable_channel(), k_ra8_dac_b_channel_0, k_ra8_dac_b_channel_1, k_ra8_mstp_dac12_0, k_ra8_mstp_dac12_1, and ra8_mstp_disable().
|
nodiscard |
Exit MSTP-gated stop.
Definition at line 352 of file ra8_dac_b.c.
References k_ra8_mstp_dac12_0, k_ra8_mstp_dac12_1, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, and s_tag.
|
nodiscard |
Read the DACR output-enable / DAE mask.
| [out] | out_mask | DACR value masked to the control bits. |
Definition at line 310 of file ra8_dac_b.c.
References r_dac_b_regs_t::DACR0, k_ra8_dac_b_channel_0, k_ra8_dac_b_channel_1, k_ra8_dacr0_mask_dacen, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_dac_b(), and s_tag.
|
nodiscard |
Legacy init – zero every DAC_B register + enable MSTP.
Definition at line 153 of file ra8_dac_b.c.
References internal_disable_channel(), k_ra8_dac_b_channel_0, k_ra8_dac_b_channel_1, k_ra8_mstp_dac12_0, k_ra8_mstp_dac12_1, k_ra8_ok, ra8_log_info, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, and s_tag.
Referenced by ra8_nsc_dac_b_init().
|
nodiscard |
Initialise DAC_B with a full config descriptor.
| [in] | cfg | Non-NULL configuration descriptor. |
Definition at line 234 of file ra8_dac_b.c.
References ra8_dac_b_cfg_t::enable_channel0, ra8_dac_b_cfg_t::enable_channel1, internal_apply_cfg(), internal_start_channel(), k_ra8_dac_b_channel_0, k_ra8_dac_b_channel_1, k_ra8_mstp_dac12_0, k_ra8_mstp_dac12_1, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_log_info, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, and s_tag.
Referenced by internal_dac_b_demo_arm(), and internal_dac_demo_setup_or_halt().
|
nodiscard |
Toggle output-enable for one channel at runtime.
| [in] | channel | 0 or 1. |
| [in] | enable | True -> drive the pin; false -> Hi-Z. |
Definition at line 293 of file ra8_dac_b.c.
References r_dac_b_regs_t::DACR0, k_ra8_dacr0_mask_dacen, k_ra8_err_invalid_arg, k_ra8_ok, and ra8_dac_b().
Referenced by main().
|
nodiscard |
Change the DAC voltage reference at runtime.
| [in] | vref | New reference source. |
Definition at line 281 of file ra8_dac_b.c.
References r_dac_b_regs_t::DACR2, k_ra8_dac_b_channel_0, k_ra8_dac_b_channel_1, k_ra8_dacr2_bit_ofssel, k_ra8_dacr2_mask_ofssel, k_ra8_ok, and ra8_dac_b().
|
nodiscard |
Programme a DAC channel with a 12-bit code.
| [in] | channel | 0 or 1. |
| [in] | value | Raw 12-bit code (clamped to 0..4095). |
Definition at line 172 of file ra8_dac_b.c.
References r_dac_b_regs_t::DADR, internal_ra8_dac_b_clamp(), k_ra8_err_invalid_arg, k_ra8_ok, ra8_dac_b(), ra8_log_info_val, and s_tag.
Referenced by internal_dac_demo_one_triangle_period(), main(), and ra8_nsc_dac_b_write().
|
static |
Definition at line 196 of file ra8_dac_b.c.
Referenced by ra8_dac_b_attach_handler(), ra8_dac_b_deinit(), and ra8_dac_b_dispatch_update().
|
static |
Definition at line 36 of file ra8_dac_b.c.