|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
High-Speed Analog Comparator driver implementation. More...
#include "ra8_acmphs.h"#include <stdint.h>#include "ra8_acmphs_regs.h"#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_log.h"#include "ra8_mstp.h"#include "ra8_port_constants.h"Go to the source code of this file.
Enumerations | |
| enum | ra8_acmphs_mstp_limit_t : uint8_t { k_ra8_acmphs_mstp_id_count = 4U } |
| Number of ACMPHS channels that have dedicated MSTPD bits. More... | |
| enum | ra8_acmphs_bits_t : uint8_t { k_ra8_acmphs_ceg_shift = 3U , k_ra8_acmphs_cdfs_shift = 5U , k_ra8_acmphs_cdfs_enabled_value = 1U , k_ra8_acmphs_ctl_mask } |
| CMPCTL field shifts (match FSP R_ACMPHS0_CMPCTL_b). More... | |
Functions | |
| static ra8_err_t | internal_reset_channel (uint8_t ch) |
| Reset one ACMPHS channel's control + selector registers. | |
| ra8_err_t | ra8_acmphs_init (void) |
| Legacy init – reset every channel to its power-on state. | |
| ra8_err_t | ra8_acmphs_channel_enable (uint8_t channel) |
| Enable a single ACMPHS channel. | |
| ra8_err_t | ra8_acmphs_read_output (uint8_t channel, ra8_level_t *out) |
| Read the live output of a channel. | |
| ra8_err_t | ra8_acmphs_channel_init (uint8_t channel, const ra8_acmphs_cfg_t *cfg) |
| Initialise one channel with a full config descriptor. | |
| ra8_err_t | ra8_acmphs_channel_deinit (uint8_t channel) |
| Tear down one channel (disable + clear CMPCTL). | |
| ra8_err_t | ra8_acmphs_set_inputs (uint8_t channel, uint8_t ivpsel, uint8_t ivrefsel) |
| Change the input selection of one channel at runtime. | |
| ra8_err_t | ra8_acmphs_get_status (uint8_t channel, uint8_t *out_mask) |
| Read CMPCTL enable / edge bits. | |
| ra8_err_t | ra8_acmphs_clear_status (uint8_t channel) |
| Clear CMPCTL (disable + edge mode off) for one channel. | |
| ra8_err_t | ra8_acmphs_attach_handler (ra8_acmphs_event_fn_t fn, void *ctx) |
| Attach an ACMPHS event callback (shared across all channels). | |
| ra8_err_t | ra8_acmphs_enter_stop (uint8_t channel) |
| Put one channel into MSTP-gated stop. | |
| ra8_err_t | ra8_acmphs_exit_stop (uint8_t channel) |
| Exit MSTP-gated stop for one channel. | |
| void | ra8_acmphs_dispatch (uint8_t channel) |
| Dispatch an ACMPHS edge event – fire the registered callback. | |
Variables | |
| static const char * | s_tag = "ACMPHS" |
| static const ra8_mstp_t | s_acmphs_mstp_table [k_ra8_acmphs_mstp_id_count] |
| Channel-index -> MSTP id lookup for the first 4 channels. | |
| static ra8_acmphs_event_fn_t | s_acmphs_fn |
| static void * | s_acmphs_ctx |
High-Speed Analog Comparator driver implementation.
driver for the RA8D2 ACMPHS block (6 channels total; channels 0..3 have dedicated MSTPD bits, 4..5 share with ACMPHS0). Exposes per-channel init/deinit/enable, output read, input selection, status get/clear, async dispatch, and power transition. Every register access carries a HUM Ch 56 citation.
Definition in file ra8_acmphs.c.
| enum ra8_acmphs_bits_t : uint8_t |
CMPCTL field shifts (match FSP R_ACMPHS0_CMPCTL_b).
Definition at line 154 of file ra8_acmphs.c.
| enum ra8_acmphs_mstp_limit_t : uint8_t |
Number of ACMPHS channels that have dedicated MSTPD bits.
HUM Ch 11.2.9 p 449 only defines MSTPD25..MSTPD28 covering ACMPHS3..ACMPHS0. Higher-numbered channels on the RA8D2 (k_ra8_acmphs_channel_count = 6) share the same MSTPD28 bit as channel 0; in practice channels 4 and 5 are enabled as a side effect of ACMPHS0 so the driver does not need to request a separate MSTP id for them.
| Enumerator | |
|---|---|
| k_ra8_acmphs_mstp_id_count | RA8 acmphs mstp ID count. |
Definition at line 46 of file ra8_acmphs.c.
|
static |
Reset one ACMPHS channel's control + selector registers.
| [in] | ch | Channel index already validated against k_ra8_acmphs_channel_count. |
See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.
| k_ra8_ok | Success path. |
| k_ra8_err_invalid_arg | Caller violated a precondition. |
Definition at line 81 of file ra8_acmphs.c.
References r_acmphs_regs_t::CMPCTL, r_acmphs_regs_t::CMPSEL0, r_acmphs_regs_t::CMPSEL1, r_acmphs_regs_t::CPIOC, k_ra8_acmphs_mstp_id_count, k_ra8_err_hw_init_failed, k_ra8_ok, ra8_acmphs(), ra8_mstp_enable(), RA8_RETURN_ON_ERROR, s_acmphs_mstp_table, and s_tag.
Referenced by ra8_acmphs_init().
|
nodiscard |
Attach an ACMPHS event callback (shared across all channels).
| [in] | fn | Callback fired on ISR dispatch. |
| [in] | ctx | Context forwarded to the callback. |
Definition at line 255 of file ra8_acmphs.c.
References k_ra8_ok, s_acmphs_ctx, and s_acmphs_fn.
|
nodiscard |
Tear down one channel (disable + clear CMPCTL).
Definition at line 200 of file ra8_acmphs.c.
References r_acmphs_regs_t::CMPCTL, r_acmphs_regs_t::CMPSEL0, r_acmphs_regs_t::CMPSEL1, k_ra8_acmphs_channel_count, k_ra8_acmphs_mstp_id_count, k_ra8_err_invalid_arg, k_ra8_ok, ra8_acmphs(), RA8_CHECK_NULL_PTR, ra8_mstp_disable(), s_acmphs_mstp_table, and s_tag.
|
nodiscard |
Enable a single ACMPHS channel.
| [in] | channel | Channel index (0..5). |
Definition at line 113 of file ra8_acmphs.c.
References r_acmphs_regs_t::CMPCTL, k_ra8_acmphs_channel_count, k_ra8_acmphs_mask_hcen, k_ra8_err_invalid_arg, k_ra8_ok, ra8_acmphs(), RA8_CHECK_NULL_PTR, ra8_log_info_val, and s_tag.
|
nodiscard |
Initialise one channel with a full config descriptor.
| [in] | channel | Channel 0..5. |
| [in] | cfg | Non-NULL configuration descriptor. |
Definition at line 166 of file ra8_acmphs.c.
References r_acmphs_regs_t::CMPCTL, r_acmphs_regs_t::CMPSEL0, r_acmphs_regs_t::CMPSEL1, ra8_acmphs_cfg_t::edge, ra8_acmphs_cfg_t::filter_en, ra8_acmphs_cfg_t::invert_out, ra8_acmphs_cfg_t::ivpsel, ra8_acmphs_cfg_t::ivrefsel, k_ra8_acmphs_cdfs_enabled_value, k_ra8_acmphs_cdfs_shift, k_ra8_acmphs_ceg_shift, k_ra8_acmphs_channel_count, k_ra8_acmphs_mask_cinv, k_ra8_acmphs_mask_hcen, k_ra8_acmphs_mstp_id_count, k_ra8_err_invalid_arg, k_ra8_ok, ra8_acmphs(), RA8_CHECK_NULL_PTR, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, s_acmphs_mstp_table, and s_tag.
Referenced by internal_acmphs_demo_setup().
|
nodiscard |
Clear CMPCTL (disable + edge mode off) for one channel.
Definition at line 243 of file ra8_acmphs.c.
References r_acmphs_regs_t::CMPCTL, k_ra8_acmphs_channel_count, k_ra8_err_invalid_arg, k_ra8_ok, ra8_acmphs(), RA8_CHECK_NULL_PTR, and s_tag.
| void ra8_acmphs_dispatch | ( | uint8_t | channel | ) |
Dispatch an ACMPHS edge event – fire the registered callback.
| [in] | channel | Channel 0..5 that fired the edge. |
See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.
Definition at line 285 of file ra8_acmphs.c.
References k_ra8_acmphs_channel_count, s_acmphs_ctx, and s_acmphs_fn.
|
nodiscard |
Put one channel into MSTP-gated stop.
Definition at line 262 of file ra8_acmphs.c.
References k_ra8_acmphs_channel_count, k_ra8_acmphs_mstp_id_count, k_ra8_err_invalid_arg, k_ra8_ok, ra8_mstp_disable(), and s_acmphs_mstp_table.
|
nodiscard |
Exit MSTP-gated stop for one channel.
Definition at line 273 of file ra8_acmphs.c.
References k_ra8_acmphs_channel_count, k_ra8_acmphs_mstp_id_count, k_ra8_err_invalid_arg, k_ra8_ok, ra8_mstp_enable(), and s_acmphs_mstp_table.
|
nodiscard |
Read CMPCTL enable / edge bits.
| [in] | channel | Channel 0..5. |
| [out] | out_mask | CMPCTL value. |
Definition at line 230 of file ra8_acmphs.c.
References r_acmphs_regs_t::CMPCTL, k_ra8_acmphs_channel_count, k_ra8_acmphs_ctl_mask, k_ra8_err_invalid_arg, k_ra8_ok, ra8_acmphs(), RA8_CHECK_NULL_PTR, and s_tag.
|
nodiscard |
Legacy init – reset every channel to its power-on state.
Definition at line 101 of file ra8_acmphs.c.
References internal_reset_channel(), k_ra8_acmphs_channel_count, k_ra8_ok, ra8_log_info, RA8_RETURN_ON_ERROR, and s_tag.
Referenced by internal_acmphs_demo_setup(), and ra8_nsc_acmphs_init().
|
nodiscard |
Read the live output of a channel.
| [in] | channel | Channel index (0..5). |
| [out] | out | Receives k_ra8_level_high or k_ra8_level_low. |
Definition at line 127 of file ra8_acmphs.c.
References r_acmphs_regs_t::CMPMON, k_ra8_acmphs_channel_count, k_ra8_acmphs_mask_hcmon, k_ra8_err_invalid_arg, k_ra8_level_high, k_ra8_level_low, k_ra8_ok, ra8_acmphs(), RA8_CHECK_NULL_PTR, and s_tag.
Referenced by internal_acmphs_demo_one_iter(), and ra8_nsc_acmphs_read_output().
|
nodiscard |
Change the input selection of one channel at runtime.
| [in] | channel | Channel 0..5. |
| [in] | ivpsel | Plus-input selector. |
| [in] | ivrefsel | Minus-input selector. |
Definition at line 217 of file ra8_acmphs.c.
References r_acmphs_regs_t::CMPSEL0, r_acmphs_regs_t::CMPSEL1, k_ra8_acmphs_channel_count, k_ra8_err_invalid_arg, k_ra8_ok, ra8_acmphs(), RA8_CHECK_NULL_PTR, and s_tag.
|
static |
Definition at line 164 of file ra8_acmphs.c.
Referenced by ra8_acmphs_attach_handler(), and ra8_acmphs_dispatch().
|
static |
Definition at line 163 of file ra8_acmphs.c.
Referenced by ra8_acmphs_attach_handler(), and ra8_acmphs_dispatch().
|
static |
Channel-index -> MSTP id lookup for the first 4 channels.
Definition at line 54 of file ra8_acmphs.c.
Referenced by internal_reset_channel(), ra8_acmphs_channel_deinit(), ra8_acmphs_channel_init(), ra8_acmphs_enter_stop(), and ra8_acmphs_exit_stop().
|
static |
Definition at line 32 of file ra8_acmphs.c.