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

NSC veneers for the I/O drivers. More...

#include <stdint.h>
#include "ra8_acmphs.h"
#include "ra8_adc.h"
#include "ra8_crc.h"
#include "ra8_dac_b.h"
#include "ra8_err.h"
#include "ra8_eth.h"
#include "ra8_glcdc.h"
#include "ra8_gpt.h"
#include "ra8_nsc_veneer.h"
#include "ra8_pdm.h"
Include dependency graph for ra8_nsc_io.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_nsc_gpt_init (uint8_t channel, const ra8_gpt_cfg_t *cfg)
 NSC veneer: bring up a GPT channel.
ra8_err_t ra8_nsc_gpt_read (uint8_t channel, uint32_t *out)
 NSC veneer: read the current GPT counter value.
ra8_err_t ra8_nsc_adc_init (void)
 NSC veneer: bring up the ADC.
ra8_err_t ra8_nsc_adc_read_channel (uint8_t channel, uint16_t *out_raw)
 NSC veneer: read one ADC channel sample.
ra8_err_t ra8_nsc_dac_b_init (void)
 NSC veneer: bring up the DAC.
ra8_err_t ra8_nsc_dac_b_write (uint8_t channel, uint16_t value)
 NSC veneer: write a 12-bit value to a DAC channel.
ra8_err_t ra8_nsc_acmphs_init (void)
 NSC veneer: bring up the high-speed analog comparator block.
ra8_err_t ra8_nsc_acmphs_read_output (uint8_t channel, ra8_level_t *out)
 NSC veneer: read a comparator output level.
ra8_err_t ra8_nsc_crc_init (ra8_crc_poly_t poly)
 NSC veneer: bring up the CRC unit with a polynomial.
ra8_err_t ra8_nsc_crc_compute (const uint8_t *data, uint32_t len, uint32_t *out_crc)
 NSC veneer: compute CRC over a buffer.
ra8_err_t ra8_nsc_glcdc_init (const ra8_glcdc_config_t *cfg)
 NSC veneer: bring up the graphics LCD controller.
ra8_err_t ra8_nsc_pdm_init (void)
 NSC veneer: bring up the PDM microphone interface.
ra8_err_t ra8_nsc_eth_init (void)
 NSC veneer: bring up the ethernet switch module.

Detailed Description

NSC veneers for the I/O drivers.

Tag
[Ring 4 / NSC] {World: NSC}

Retrofit veneers for the analog / safety / display / audio / ethernet drivers (ra8_gpt, ra8_adc, ra8_dac_b, ra8_acmphs, ra8_crc, ra8_glcdc, ra8_pdm, ra8_eth). Each veneer is a Non-Secure Callable entry point that validates pointer arguments and forwards to the secure-side Ring-3 driver.

MTU/TPU listed in the original plan are not present on the RA8D2 (see the scope-correction note in the roadmap) so they have no veneers here.

This layer ships init + the most-used primitive per driver. The remaining surface is straightforward to add by following the same pattern; deferred to land alongside the first NS consumer.

Definition in file ra8_nsc_io.h.

Function Documentation

◆ ra8_nsc_acmphs_init()

ra8_err_t ra8_nsc_acmphs_init ( void )
nodiscard

NSC veneer: bring up the high-speed analog comparator block.

Since
0.1.0

Forwards to ra8_acmphs_init.

Returns
ra8_err_t outcome.
Return values
k_ra8_okComparators ready.
k_ra8_err_hw_init_failedHardware refused init.
Precondition
ra8_nsc_periph_init has been called.
TrustZone substrate up.
Postcondition
On success the ACMPHS channels are powered.
On failure no module state was mutated.
TrustZone:
NS->S boundary via cmse_nonsecure_entry. Argument-less call.
Note
Thread-safe: serialised by the secure ACMPHS driver.
Since
0.1.0

Definition at line 230 of file ra8_nsc_io.c.

References ra8_acmphs_init(), and RA8_NSC_VENEER.

◆ ra8_nsc_acmphs_read_output()

ra8_err_t ra8_nsc_acmphs_read_output ( uint8_t channel,
ra8_level_t * out )
nodiscard

NSC veneer: read a comparator output level.

Since
0.1.0

Range-checks out in NS memory and forwards to ra8_acmphs_read_output.

Parameters
[in]channelComparator channel index.
[out]outNS destination for the level enum.
Returns
ra8_err_t outcome.
Return values
k_ra8_okLevel stored at *out.
k_ra8_err_null_ptrout was NULL.
k_ra8_err_invalid_argRange outside NS region.
Precondition
ra8_nsc_acmphs_init succeeded.
out lies in NS data region.
Postcondition
On success *out reflects the comparator level.
On failure *out unchanged.
TrustZone:
NS->S boundary via cmse_nonsecure_entry. out is range-checked.
Note
Thread-safe: serialised by the secure ACMPHS driver.
Since
0.1.0

Definition at line 260 of file ra8_nsc_io.c.

References ra8_acmphs_read_output(), RA8_CHECK_NULL_PTR, RA8_NSC_CHECK_NS_RANGE_RW, RA8_NSC_VENEER, and s_tag.

◆ ra8_nsc_adc_init()

ra8_err_t ra8_nsc_adc_init ( void )
nodiscard

NSC veneer: bring up the ADC.

Since
0.1.0

Forwards to ra8_adc_init. No arguments and no pointers cross the boundary.

Returns
ra8_err_t outcome.
Return values
k_ra8_okADC ready.
k_ra8_err_hw_init_failedHardware refused init.
Precondition
ra8_nsc_periph_init has been called.
TrustZone substrate up.
Postcondition
On success the ADC is calibrated and idle.
On failure no module state was mutated.
TrustZone:
NS->S boundary via cmse_nonsecure_entry. Argument-less scalar call – nothing to range-check.
Note
Thread-safe: serialised by the secure ADC driver.
Since
0.1.0

Definition at line 119 of file ra8_nsc_io.c.

References ra8_adc_init(), and RA8_NSC_VENEER.

◆ ra8_nsc_adc_read_channel()

ra8_err_t ra8_nsc_adc_read_channel ( uint8_t channel,
uint16_t * out_raw )
nodiscard

NSC veneer: read one ADC channel sample.

Since
0.1.0

Range-checks out_raw in NS memory and forwards to ra8_adc_read_channel.

Parameters
[in]channelADC channel index.
[out]out_rawNS destination for the 16-bit raw sample.
Returns
ra8_err_t outcome.
Return values
k_ra8_okSample stored at *out_raw.
k_ra8_err_null_ptrout_raw was NULL.
k_ra8_err_invalid_argRange outside NS region.
Precondition
ra8_nsc_adc_init succeeded.
out_raw lies in NS data region.
Postcondition
On success *out_raw holds the latest sample.
On failure *out_raw unchanged.
TrustZone:
NS->S boundary via cmse_nonsecure_entry. out_raw is range-checked.
Note
Thread-safe: serialised by the secure ADC driver.
Since
0.1.0

Definition at line 150 of file ra8_nsc_io.c.

References ra8_adc_read_channel(), RA8_CHECK_NULL_PTR, RA8_NSC_CHECK_NS_RANGE_RW, RA8_NSC_VENEER, and s_tag.

◆ ra8_nsc_crc_compute()

ra8_err_t ra8_nsc_crc_compute ( const uint8_t * data,
uint32_t len,
uint32_t * out_crc )
nodiscard

NSC veneer: compute CRC over a buffer.

Since
0.1.0

Range-checks data (read) and out_crc (write) in NS memory then forwards to ra8_crc_compute.

Parameters
[in]dataNS source buffer.
[in]lenByte count.
[out]out_crcNS destination for the 32-bit CRC value.
Returns
ra8_err_t outcome.
Return values
k_ra8_okCRC stored at *out_crc.
k_ra8_err_null_ptrA pointer argument was NULL.
k_ra8_err_invalid_argRange outside NS region.
Precondition
ra8_nsc_crc_init succeeded.
Both pointers lie in NS data region.
Postcondition
On success *out_crc holds the CRC of [data,data+len).
On failure *out_crc unchanged.
TrustZone:
NS->S boundary via cmse_nonsecure_entry. Both pointers are cmse_check_address_range-validated so the secure driver only reads/writes NS memory.
Note
Thread-safe: serialised by the secure CRC driver.
Since
0.1.0

Definition at line 322 of file ra8_nsc_io.c.

References RA8_CHECK_NULL_PTR, ra8_crc_compute(), RA8_NSC_CHECK_NS_RANGE_R, RA8_NSC_CHECK_NS_RANGE_RW, RA8_NSC_VENEER, and s_tag.

◆ ra8_nsc_crc_init()

ra8_err_t ra8_nsc_crc_init ( ra8_crc_poly_t poly)
nodiscard

NSC veneer: bring up the CRC unit with a polynomial.

Since
0.1.0

Forwards to ra8_crc_init. No pointer arguments.

Parameters
[in]polyPolynomial enum (CRC-8/16/32 selection).
Returns
ra8_err_t outcome.
Return values
k_ra8_okCRC engine programmed.
k_ra8_err_invalid_argUnknown polynomial enum.
Precondition
ra8_nsc_periph_init has been called.
TrustZone substrate up.
Postcondition
On success the CRC engine is in its initial state.
On failure no module state was mutated.
TrustZone:
NS->S boundary via cmse_nonsecure_entry. Scalar enum argument.
Note
Thread-safe: serialised by the secure CRC driver.
Since
0.1.0

Definition at line 289 of file ra8_nsc_io.c.

References ra8_crc_init(), and RA8_NSC_VENEER.

◆ ra8_nsc_dac_b_init()

ra8_err_t ra8_nsc_dac_b_init ( void )
nodiscard

NSC veneer: bring up the DAC.

Since
0.1.0

NSC veneer: bring up the DAC.

Forwards to ra8_dac_b_init.

Returns
ra8_err_t outcome.
Return values
k_ra8_okDAC ready.
k_ra8_err_hw_init_failedHardware refused init.
Precondition
ra8_nsc_periph_init has been called.
TrustZone substrate up.
Postcondition
On success the DAC channels are powered and idle.
On failure no module state was mutated.
TrustZone:
NS->S boundary via cmse_nonsecure_entry. Argument-less scalar call.
Note
Thread-safe: serialised by the secure DAC driver.
Since
0.1.0

Definition at line 177 of file ra8_nsc_io.c.

References ra8_dac_b_init(), and RA8_NSC_VENEER.

◆ ra8_nsc_dac_b_write()

ra8_err_t ra8_nsc_dac_b_write ( uint8_t channel,
uint16_t value )
nodiscard

NSC veneer: write a 12-bit value to a DAC channel.

Since
0.1.0

NSC veneer: write a 12-bit value to a DAC channel.

Forwards to ra8_dac_b_write. No pointer arguments.

Parameters
[in]channelDAC channel index.
[in]value12-bit value (top 4 bits ignored).
Returns
ra8_err_t outcome.
Return values
k_ra8_okValue latched.
k_ra8_err_invalid_argBad channel index.
Precondition
ra8_nsc_dac_b_init succeeded.
TrustZone substrate up.
Postcondition
On success the DAC output is driving the new value.
On failure the DAC output is unchanged.
TrustZone:
NS->S boundary via cmse_nonsecure_entry. Scalar arguments only.
Note
Thread-safe: serialised by the secure DAC driver.
Since
0.1.0

Definition at line 205 of file ra8_nsc_io.c.

References ra8_dac_b_write(), and RA8_NSC_VENEER.

◆ ra8_nsc_eth_init()

ra8_err_t ra8_nsc_eth_init ( void )
nodiscard

NSC veneer: bring up the ethernet switch module.

Since
0.1.0

Forwards to ra8_eth_init.

Returns
ra8_err_t outcome.
Return values
k_ra8_okESWM up.
k_ra8_err_hw_init_failedHardware refused init.
Precondition
ra8_nsc_periph_init has been called.
TrustZone substrate up.
Postcondition
On success the ESWM is in the link-up-pending state.
On failure no module state was mutated.
TrustZone:
NS->S boundary via cmse_nonsecure_entry. Argument-less call.
Note
Thread-safe: no – single-threaded bring-up.
Since
0.1.0

Definition at line 407 of file ra8_nsc_io.c.

References ra8_eth_init(), and RA8_NSC_VENEER.

◆ ra8_nsc_glcdc_init()

ra8_err_t ra8_nsc_glcdc_init ( const ra8_glcdc_config_t * cfg)
nodiscard

NSC veneer: bring up the graphics LCD controller.

Since
0.1.0

Range-checks cfg in NS memory and forwards to ra8_glcdc_init.

Parameters
[in]cfgCaller configuration in NS memory.
Returns
ra8_err_t outcome.
Return values
k_ra8_okGLCDC programmed.
k_ra8_err_null_ptrcfg was NULL.
k_ra8_err_invalid_argRange outside NS region or invalid config.
Precondition
ra8_nsc_periph_init has been called.
cfg lies in NS data region.
Postcondition
On success the GLCDC is scanning out the framebuffer.
On failure no module state was mutated.
TrustZone:
NS->S boundary via cmse_nonsecure_entry. cfg is range-checked.
Note
Thread-safe: no – GLCDC bring-up is single-threaded.
Since
0.1.0

Definition at line 355 of file ra8_nsc_io.c.

References RA8_CHECK_NULL_PTR, ra8_glcdc_init(), RA8_NSC_CHECK_NS_RANGE_R, RA8_NSC_VENEER, and s_tag.

◆ ra8_nsc_gpt_init()

ra8_err_t ra8_nsc_gpt_init ( uint8_t channel,
const ra8_gpt_cfg_t * cfg )
nodiscard

NSC veneer: bring up a GPT channel.

Since
0.1.0

Range-checks cfg in NS memory and forwards to ra8_gpt_init.

Parameters
[in]channelGPT channel index.
[in]cfgCaller configuration in NS memory.
Returns
ra8_err_t outcome.
Return values
k_ra8_okChannel programmed.
k_ra8_err_null_ptrcfg was NULL.
k_ra8_err_invalid_argcfg outside NS region or channel bad.
Precondition
TrustZone substrate up.
cfg lies in NS data region.
Postcondition
On success the GPT channel is counting per its mode.
On failure no module state was mutated.
TrustZone:
NS->S boundary via cmse_nonsecure_entry. cfg is range-checked.
Note
Thread-safe: serialised by the secure GPT driver.
Since
0.1.0

Definition at line 58 of file ra8_nsc_io.c.

References RA8_CHECK_NULL_PTR, ra8_gpt_init(), RA8_NSC_CHECK_NS_RANGE_R, RA8_NSC_VENEER, and s_tag.

◆ ra8_nsc_gpt_read()

ra8_err_t ra8_nsc_gpt_read ( uint8_t channel,
uint32_t * out )
nodiscard

NSC veneer: read the current GPT counter value.

Since
0.1.0

Range-checks out in NS writable memory and forwards to ra8_gpt_read.

Parameters
[in]channelGPT channel index.
[out]outNS destination for the counter value.
Returns
ra8_err_t outcome.
Return values
k_ra8_okCounter read into *out.
k_ra8_err_null_ptrout was NULL.
k_ra8_err_invalid_argout outside NS region.
Precondition
ra8_nsc_gpt_init succeeded for channel.
out lies in NS data region.
Postcondition
On success *out reflects the live counter value.
On failure *out unchanged.
TrustZone:
NS->S boundary via cmse_nonsecure_entry. out is range-checked.
Note
Thread-safe: serialised by the secure GPT driver.
Since
0.1.0

Definition at line 90 of file ra8_nsc_io.c.

References RA8_CHECK_NULL_PTR, ra8_gpt_read(), RA8_NSC_CHECK_NS_RANGE_RW, RA8_NSC_VENEER, and s_tag.

◆ ra8_nsc_pdm_init()

ra8_err_t ra8_nsc_pdm_init ( void )
nodiscard

NSC veneer: bring up the PDM microphone interface.

Since
0.1.0

Forwards to ra8_pdm_init.

Returns
ra8_err_t outcome.
Return values
k_ra8_okPDM ready.
k_ra8_err_hw_init_failedHardware refused init.
Precondition
ra8_nsc_periph_init has been called.
TrustZone substrate up.
Postcondition
On success the PDM clock is running.
On failure no module state was mutated.
TrustZone:
NS->S boundary via cmse_nonsecure_entry. Argument-less call.
Note
Thread-safe: serialised by the secure PDM driver.
Since
0.1.0

Definition at line 382 of file ra8_nsc_io.c.

References RA8_NSC_VENEER, and ra8_pdm_init().