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

ADC_B VREF-channel sample-and-log demo for EK-RA8D2. More...

#include <stdint.h>
#include "ra8_adc.h"
#include "ra8_attributes.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_boot_entry.h"
#include "ra8_cgc.h"
#include "ra8_err.h"
#include "ra8_isr.h"
#include "ra8_time.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  adc_b_demo_const_t : uint32_t {
  k_adc_b_demo_baud = 115200U ,
  k_adc_b_demo_period_ms = 500U ,
  k_adc_b_demo_vref_mv = 3300U ,
  k_adc_b_demo_full_scale = 4095U
}
 Demo tunables. More...
enum  adc_b_demo_chan_t : uint8_t { k_adc_b_demo_channel = 0U }
 ADC channel selection. More...
enum  adc_b_demo_fmt_t : uint8_t {
  k_adc_b_demo_dec_digits = 5U ,
  k_adc_b_demo_line_max = 32U ,
  k_adc_b_demo_radix = 10U ,
  k_adc_b_demo_cr = '\r' ,
  k_adc_b_demo_lf = '\n'
}
 Formatting constants. More...

Functions

static uint32_t internal_u16_to_dec (uint8_t *buf, uint16_t val)
 Write the decimal digits of a 16-bit value into a byte buffer.
static void internal_panic_halt (void)
 Park the core after an unrecoverable ADC demo failure.
static void internal_setup_or_halt (void)
 Initialize clocks, SysTick, SCI8, and LED1.
static ra8_err_t internal_arm (void)
 Configure ADC_B in 12-bit software-trigger mode.
void main (void)
 Sample ADC_B and report raw and converted values continuously.

Variables

static const uint8_t s_adc_b_demo_log_prefix [] = "adc: raw="
static const uint8_t s_adc_b_demo_mv_sep [] = " mv="
static const uint8_t s_adc_b_demo_pass_msg [] = "adc: read PASS\r\n"
 Verdict line emitted only after a successful channel read.

Detailed Description

ADC_B VREF-channel sample-and-log demo for EK-RA8D2.

Tag
[Ring 6 / APP] {World: S}

Configures the ADC_B in 12-bit, software-trigger mode, samples the internal VREF channel (k_adc_b_demo_channel) once per loop, and logs the raw count plus the converted millivolt value over SCI8.

Bring-up sequence:

  1. CGC + SysTick + UART (SCI8 on PD_02 / PD_03).
  2. ra8_adc_init_configured with software trigger + 12-bit res.
  3. Loop: ra8_adc_read_channel -> format -> ra8_board_uart_console_write. After each successful read it also emits the fixed verdict line "adc: read PASS\r\n" that the HIL scrape keys on.

Bare EK-RA8D2; no expansion board.

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ adc_b_demo_chan_t

enum adc_b_demo_chan_t : uint8_t

ADC channel selection.

Enumerator
k_adc_b_demo_channel 

AN000 – safe default.

Definition at line 55 of file main.c.

◆ adc_b_demo_const_t

enum adc_b_demo_const_t : uint32_t

Demo tunables.

Enumerator
k_adc_b_demo_baud 

ADC b demo baud.

k_adc_b_demo_period_ms 

ADC b demo period ms.

k_adc_b_demo_vref_mv 

EK-RA8D2 VREFH = 3.3V.

k_adc_b_demo_full_scale 

12-bit max code.

Definition at line 47 of file main.c.

◆ adc_b_demo_fmt_t

enum adc_b_demo_fmt_t : uint8_t

Formatting constants.

Enumerator
k_adc_b_demo_dec_digits 

Max decimal digits for uint16_t (65535).

k_adc_b_demo_line_max 

"adc: raw=XXXXX mv=XXXXX\r\n" fits here.

k_adc_b_demo_radix 

ADC b demo radix.

k_adc_b_demo_cr 

ADC b demo cr.

k_adc_b_demo_lf 

ADC b demo lf.

Definition at line 60 of file main.c.

Function Documentation

◆ internal_arm()

ra8_err_t internal_arm ( void )
staticnodiscard

Configure ADC_B in 12-bit software-trigger mode.

Supplies the fixed resolution, trigger, alignment, and single-scan policy to the configured ADC initialization API.

MC/DC:
Decision: ra8_adc_init_configured != ok. One atomic condition x 2 vectors – golden (this) + null cfg reject (test_app_adc_b_demo.c).
Returns
ADC configuration status from the HAL.
Return values
k_ra8_okADC_B accepted the fixed demo configuration.
(other)ADC_B initialization failed or rejected the configuration.
Precondition
internal_setup_or_halt completed clock initialization.
No other context owns ADC_B configuration.
Postcondition
On success, software-triggered channel reads are available.
On failure, the error is returned unchanged to the caller.
Note
Not thread-safe with concurrent ADC configuration.
Since
0.1.0

Definition at line 179 of file main.c.

References k_ra8_adc_res_12bit, k_ra8_adc_trig_software, ra8_adc_init_configured(), and RA8_INTERNAL.

Referenced by main().

◆ internal_panic_halt()

void internal_panic_halt ( void )
static

Park the core after an unrecoverable ADC demo failure.

Repeatedly executes WFI, preserving failure state for a debugger.

Precondition
Called only from boot failure or the terminal foreground path.
The caller does not require recovery without reset.
Postcondition
The core stays in the WFI loop until external intervention.
No more ADC conversions or console writes are requested.
Note
Not thread-safe; this is a terminal single-threaded path.
Since
0.1.0

Definition at line 123 of file main.c.

References RA8_INTERNAL.

Referenced by internal_clocks_or_halt(), internal_clocks_or_halt(), internal_setup_or_halt(), and main().

◆ internal_setup_or_halt()

void internal_setup_or_halt ( void )
static

Initialize clocks, SysTick, SCI8, and LED1.

Brings dependencies up in order and parks on the first HAL error.

Precondition
Reset startup initialized static storage and the vector table.
Called once before global interrupt enable.
Postcondition
On return, delays, console output, and LED1 are ready.
ADC_B remains unconfigured until internal_arm runs.
Note
Not thread-safe; it mutates global board and clock state.
Since
0.1.0

Definition at line 140 of file main.c.

References internal_panic_halt(), k_adc_b_demo_baud, k_ra8_board_led1, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_led_init(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, and ra8_time_init().

◆ internal_u16_to_dec()

uint32_t internal_u16_to_dec ( uint8_t * buf,
uint16_t val )
static

Write the decimal digits of a 16-bit value into a byte buffer.

Handles zero explicitly; otherwise collects least-significant digits in a bounded local array and reverses them into the caller's destination without appending a NUL terminator.

Parameters
[out]bufDestination with room for five decimal digits.
[in]valValue to convert.
Returns
Number of bytes written to buf.
Return values
1Zero or a single-digit value was written.
2..5The exact digit count of a larger value.
Precondition
buf points to at least k_adc_b_demo_dec_digits writable bytes.
The destination does not overlap this function's local storage.
Postcondition
The returned prefix of buf is the base-10 representation of val.
No byte beyond the returned count is modified.
Note
Reentrant when callers provide distinct output buffers.
Since
0.1.0

Definition at line 93 of file main.c.

References k_adc_b_demo_dec_digits, k_adc_b_demo_radix, and RA8_INTERNAL.

Referenced by main().

◆ main()

void main ( void )

Sample ADC_B and report raw and converted values continuously.

The application entry point Reset_Handler hands control to.

Initializes and arms ADC_B, formats each successful channel sample without variadic I/O, emits the verdict, toggles LED1, and delays.

Precondition
Reset startup and SystemInit completed successfully.
The selected ADC channel matches the board analog connection.
Postcondition
Every PASS verdict follows a successful channel read.
Any read or LED failure leads to the terminal panic helper.
Note
Does not return during normal operation.
Since
0.1.0

Definition at line 201 of file main.c.

References internal_arm(), internal_panic_halt(), internal_setup_or_halt(), internal_u16_to_dec(), k_adc_b_demo_channel, k_adc_b_demo_cr, k_adc_b_demo_full_scale, k_adc_b_demo_lf, k_adc_b_demo_line_max, k_adc_b_demo_period_ms, k_adc_b_demo_vref_mv, k_ra8_board_led1, k_ra8_ok, ra8_adc_read_channel(), ra8_board_led_toggle(), ra8_board_uart_console_write(), ra8_delay_ms(), ra8_isr_globals_enable(), s_adc_b_demo_log_prefix, s_adc_b_demo_mv_sep, and s_adc_b_demo_pass_msg.

Variable Documentation

◆ s_adc_b_demo_log_prefix

const uint8_t s_adc_b_demo_log_prefix[] = "adc: raw="
static

Definition at line 68 of file main.c.

Referenced by main().

◆ s_adc_b_demo_mv_sep

const uint8_t s_adc_b_demo_mv_sep[] = " mv="
static

Definition at line 69 of file main.c.

Referenced by main().

◆ s_adc_b_demo_pass_msg

const uint8_t s_adc_b_demo_pass_msg[] = "adc: read PASS\r\n"
static

Verdict line emitted only after a successful channel read.

Definition at line 72 of file main.c.

Referenced by main().