|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
NSC veneers for the communications drivers. More...
#include <stdint.h>#include "ra8_err.h"#include "ra8_i3c.h"#include "ra8_nsc_veneer.h"#include "ra8_sci.h"#include "ra8_spi.h"#include "ra8_usb.h"Go to the source code of this file.
Enumerations | |
| enum | ra8_nsc_spi_pack_const_t : uint32_t { k_ra8_nsc_spi_byte_msk = 0x000000FFU , k_ra8_nsc_spi_bw_shift = 8U } |
| Bit layout for ra8_nsc_spi_ch_bw() packed argument. More... | |
Functions | |
| ra8_err_t | ra8_nsc_sci_init (uint8_t channel, const ra8_sci_cfg_t *cfg) |
| NSC veneer: bring up an SCI channel from NS code. | |
| ra8_err_t | ra8_nsc_sci_putc (uint8_t channel, uint8_t byte) |
| NSC veneer: blocking single-byte SCI write. | |
| ra8_err_t | ra8_nsc_sci_getc (uint8_t channel, uint8_t *out_byte) |
| NSC veneer: blocking single-byte SCI read. | |
| ra8_err_t | ra8_nsc_iic_init (uint8_t channel, const ra8_i3c_cfg_t *cfg) |
| NSC veneer: bring up an IIC channel. | |
| ra8_err_t | ra8_nsc_iic_write (uint8_t channel, uint8_t target_7b, const uint8_t *data, uint32_t len) |
| NSC veneer: blocking I2C write to a 7-bit target. | |
| ra8_err_t | ra8_nsc_iic_read (uint8_t channel, uint8_t target_7b, uint8_t *out_buf, uint32_t len) |
| NSC veneer: blocking I2C read from a 7-bit target. | |
| ra8_err_t | ra8_nsc_spi_init (uint8_t channel, const ra8_spi_cfg_t *cfg) |
| NSC veneer: bring up an SPI controller channel. | |
| ra8_err_t | ra8_nsc_spi_xfer8 (uint8_t channel, uint8_t tx, uint8_t *rx) |
| NSC veneer: full-duplex single-byte SPI exchange. | |
| ra8_err_t | ra8_nsc_spi_write (uint8_t channel, const void *tx, uint32_t len, ra8_spi_bit_width_t bit_width) |
| NSC veneer: multi-frame TX-only polling SPI write. | |
| ra8_err_t | ra8_nsc_spi_read (uint8_t channel, void *rx, uint32_t len, ra8_spi_bit_width_t bit_width) |
| NSC veneer: multi-frame RX-only polling SPI read. | |
| static uint32_t | ra8_nsc_spi_ch_bw (uint8_t channel, ra8_spi_bit_width_t bit_width) |
| Pack channel + bit_width into a single 32-bit argument. | |
| ra8_err_t | ra8_nsc_spi_write_read (uint32_t ch_bw, const void *tx, void *rx, uint32_t len) |
| NSC veneer: multi-frame full-duplex polling SPI exchange. | |
| ra8_err_t | ra8_nsc_usb_init (ra8_usb_speed_t speed) |
| NSC veneer: bring up the USB device controller. | |
| ra8_err_t | ra8_nsc_usb_attach (ra8_usb_speed_t speed, bool attached) |
| NSC veneer: raise / drop USB D+ pull-up. | |
NSC veneers for the communications drivers.
Retrofit veneers for the comms drivers (ra8_sci, ra8_iic, ra8_spi, ra8_usb). Each function here is a Non-Secure Callable entry point that validates pointer arguments via cmse_check_address_range (under TrustZone) and forwards to the matching Ring-3 driver primitive in the secure world.
This layer ships a representative subset – init + the most common transfer primitive per driver. The remaining surface (interrupt callbacks, DMA paths, error introspection) is straightforward to add by following the same pattern; it is deferred to land alongside the first NS-world consumer that actually exercises those paths.
ra8_nsc_sci_init wraps ra8_sci_init ra8_nsc_sci_putc wraps ra8_sci_putc_polling ra8_nsc_sci_getc wraps ra8_sci_getc_polling ra8_nsc_iic_init wraps ra8_i3c_init ra8_nsc_iic_write wraps ra8_i3c_write ra8_nsc_iic_read wraps ra8_i3c_read ra8_nsc_spi_init wraps ra8_spi_init ra8_nsc_spi_xfer8 wraps ra8_spi_xfer8 ra8_nsc_usb_init wraps ra8_usb_device_init ra8_nsc_usb_attach wraps ra8_usb_device_attach
Definition in file ra8_nsc_comms.h.
| enum ra8_nsc_spi_pack_const_t : uint32_t |
Bit layout for ra8_nsc_spi_ch_bw() packed argument.
| Enumerator | |
|---|---|
| k_ra8_nsc_spi_byte_msk | Byte mask within the packed word. |
| k_ra8_nsc_spi_bw_shift | Bit position of bit_width. |
Definition at line 181 of file ra8_nsc_comms.h.
|
nodiscard |
NSC veneer: bring up an IIC channel.
NSC veneer: bring up an IIC channel.
Validates the NS pointer to cfg then forwards to ra8_i3c_init.
| [in] | channel | IIC channel index. |
| [in] | cfg | Caller-supplied configuration in NS memory. |
| k_ra8_ok | Channel programmed. |
| k_ra8_err_null_ptr | cfg was NULL. |
| k_ra8_err_invalid_arg | cfg not in NS region or channel bad. |
Definition at line 167 of file ra8_nsc_comms.c.
References k_ra8_i3c_mode_i2c, ra8_i3c_cfg_t::mode, RA8_CHECK_NULL_PTR, ra8_i3c_init(), RA8_NSC_CHECK_NS_RANGE_R, RA8_NSC_VENEER, and s_tag.
|
nodiscard |
NSC veneer: blocking I2C read from a 7-bit target.
Validates [out_buf, out_buf+len) lies in writable NS memory then forwards to ra8_i3c_read.
| [in] | channel | IIC channel index. |
| [in] | target_7b | 7-bit peripheral address. |
| [out] | out_buf | NS destination buffer. |
| [in] | len | Byte count to read. |
| k_ra8_ok | Bytes received into out_buf. |
| k_ra8_err_null_ptr | out_buf was NULL. |
| k_ra8_err_invalid_arg | Range outside NS region. |
Definition at line 244 of file ra8_nsc_comms.c.
References RA8_CHECK_NULL_PTR, ra8_i3c_read(), RA8_NSC_CHECK_NS_RANGE_RW, RA8_NSC_VENEER, and s_tag.
|
nodiscard |
NSC veneer: blocking I2C write to a 7-bit target.
Validates [data, data+len) lies in NS memory then forwards to ra8_i3c_write.
| [in] | channel | IIC channel index. |
| [in] | target_7b | 7-bit peripheral address. |
| [in] | data | NS source buffer. |
| [in] | len | Byte count. |
| k_ra8_ok | Bytes transmitted (or ACK-checked). |
| k_ra8_err_null_ptr | data was NULL. |
| k_ra8_err_invalid_arg | Range outside NS region or len bogus. |
Definition at line 206 of file ra8_nsc_comms.c.
References RA8_CHECK_NULL_PTR, ra8_i3c_write(), RA8_NSC_CHECK_NS_RANGE_R, RA8_NSC_VENEER, and s_tag.
|
nodiscard |
NSC veneer: blocking single-byte SCI read.
| [in] | channel | SCI channel 0..9. |
| [out] | out_byte | Destination in NS memory. |
Validates out_byte is in the NS region and forwards to ra8_sci_getc_polling.
| [in] | channel | SCI channel index. |
| [out] | out_byte | Destination byte (in NS memory). |
| k_ra8_ok | One byte stored at *out_byte. |
| k_ra8_err_null_ptr | out_byte was NULL. |
| k_ra8_err_invalid_arg | Pointer not in NS region. |
Definition at line 129 of file ra8_nsc_comms.c.
References RA8_CHECK_NULL_PTR, RA8_NSC_CHECK_NS_RANGE_RW, RA8_NSC_VENEER, ra8_sci_getc_polling(), and s_tag.
|
nodiscard |
NSC veneer: bring up an SCI channel from NS code.
| [in] | channel | SCI channel 0..9. |
| [in] | cfg | Configuration descriptor in NS memory. |
NSC veneer: bring up an SCI channel from NS code.
Validates cfg lies inside the NS region (TZ builds) and forwards to the secure ra8_sci_init driver.
| [in] | channel | SCI channel index (0..k_ra8_sci_channel_max-1). |
| [in] | cfg | Caller-supplied configuration in NS memory. |
| k_ra8_ok | Channel programmed and ready. |
| k_ra8_err_null_ptr | cfg was NULL. |
| k_ra8_err_invalid_arg | cfg outside NS range or channel bad. |
Definition at line 65 of file ra8_nsc_comms.c.
References RA8_CHECK_NULL_PTR, RA8_NSC_CHECK_NS_RANGE_R, RA8_NSC_VENEER, ra8_sci_init(), and s_tag.
|
nodiscard |
NSC veneer: blocking single-byte SCI write.
| [in] | channel | SCI channel 0..9. |
| [in] | byte | Byte to send. |
Forwards directly to ra8_sci_putc_polling; no pointer crosses the boundary so no NS-range check is needed.
| [in] | channel | SCI channel index. |
| [in] | byte | Byte to transmit. |
| k_ra8_ok | Byte queued for TX. |
| k_ra8_err_invalid_arg | Bad channel index. |
Definition at line 97 of file ra8_nsc_comms.c.
References RA8_NSC_VENEER, and ra8_sci_putc_polling().
|
inlinestatic |
Pack channel + bit_width into a single 32-bit argument.
ra8_nsc_spi_write_read would naturally have five arguments (channel, tx, rx, len, bit_width) but cmse_nonsecure_entry requires every parameter to fit in a register (AAPCS R0..R3). Five args spill to the stack and the compiler rejects the attribute. We encode channel in bits [7:0] and bit_width in bits [15:8] so the veneer takes four register-sized arguments.
| [in] | channel | SPI channel id. |
| [in] | bit_width | Bus bit width enum value. |
| value | (channel & 0xFF) | (bit_width << 8). |
Definition at line 212 of file ra8_nsc_comms.h.
References k_ra8_nsc_spi_bw_shift, and k_ra8_nsc_spi_byte_msk.
|
nodiscard |
NSC veneer: bring up an SPI controller channel.
NSC veneer: bring up an SPI controller channel.
Validates the NS pointer to cfg then forwards to ra8_spi_init.
| [in] | channel | SPI channel index. |
| [in] | cfg | Caller-supplied configuration in NS memory. |
| k_ra8_ok | Channel programmed. |
| k_ra8_err_null_ptr | cfg was NULL. |
| k_ra8_err_invalid_arg | cfg not in NS region or channel bad. |
Definition at line 285 of file ra8_nsc_comms.c.
References RA8_CHECK_NULL_PTR, RA8_NSC_CHECK_NS_RANGE_R, RA8_NSC_VENEER, ra8_spi_init(), and s_tag.
|
nodiscard |
NSC veneer: multi-frame RX-only polling SPI read.
Computes the byte span, range-checks rx in NS writable memory, then forwards to ra8_spi_read.
| [in] | channel | SPI channel index. |
| [out] | rx | NS destination buffer (may be NULL only if len == 0). |
| [in] | len | Frame count. |
| [in] | bit_width | Frame width (8/16/32). |
| k_ra8_ok | Bytes received into rx. |
| k_ra8_err_null_ptr | rx was NULL with non-zero len. |
| k_ra8_err_invalid_arg | Range outside NS region or bad width. |
Definition at line 485 of file ra8_nsc_comms.c.
References internal_spi_byte_span(), internal_spi_unit_bytes(), k_ra8_err_invalid_arg, RA8_CHECK_NULL_PTR, RA8_NSC_CHECK_NS_RANGE_RW, RA8_NSC_VENEER, ra8_spi_read(), and s_tag.
|
nodiscard |
NSC veneer: multi-frame TX-only polling SPI write.
Computes bytes_per_frame * len, range-checks the source buffer in NS memory, then forwards to ra8_spi_write.
| [in] | channel | SPI channel index. |
| [in] | tx | NS source buffer (may be NULL only if len == 0). |
| [in] | len | Frame count. |
| [in] | bit_width | Frame width (8/16/32). |
| k_ra8_ok | Bytes shifted out. |
| k_ra8_err_null_ptr | tx was NULL with non-zero len. |
| k_ra8_err_invalid_arg | Range outside NS region or bad width. |
Definition at line 437 of file ra8_nsc_comms.c.
References internal_spi_byte_span(), internal_spi_unit_bytes(), k_ra8_err_invalid_arg, RA8_CHECK_NULL_PTR, RA8_NSC_CHECK_NS_RANGE_R, RA8_NSC_VENEER, ra8_spi_write(), and s_tag.
|
nodiscard |
NSC veneer: multi-frame full-duplex polling SPI exchange.
The veneer takes four register-sized arguments; pack channel and bit_width into ch_bw with ra8_nsc_spi_ch_bw().
Definition at line 505 of file ra8_nsc_comms.c.
References internal_spi_byte_span(), internal_spi_unit_bytes(), k_ra8_err_invalid_arg, k_ra8_nsc_spi_bw_shift, k_ra8_nsc_spi_byte_msk, RA8_CHECK_NULL_PTR, RA8_NSC_CHECK_NS_RANGE_R, RA8_NSC_CHECK_NS_RANGE_RW, RA8_NSC_VENEER, ra8_spi_write_read(), and s_tag.
|
nodiscard |
NSC veneer: full-duplex single-byte SPI exchange.
Forwards to ra8_spi_xfer8. rx may be NULL (matches the legacy ra8_spi_xfer8 contract); when non-NULL it is range- checked.
| [in] | channel | SPI channel index. |
| [in] | tx | Byte to transmit. |
| [out] | rx | Optional NS destination for the received byte. |
| k_ra8_ok | Exchange complete. |
| k_ra8_err_invalid_arg | rx non-NULL but outside NS region. |
Definition at line 319 of file ra8_nsc_comms.c.
References RA8_NSC_CHECK_NS_RANGE_RW, RA8_NSC_VENEER, and ra8_spi_xfer8().
|
nodiscard |
NSC veneer: raise / drop USB D+ pull-up.
NSC veneer: raise / drop USB D+ pull-up.
Forwards to ra8_usb_device_attach.
| [in] | speed | Negotiated USB speed enum. |
| [in] | attached | True to assert pull-up, false to release. |
| k_ra8_ok | Pull-up state set. |
| k_ra8_err_invalid_arg | Unknown speed. |
Definition at line 589 of file ra8_nsc_comms.c.
References RA8_NSC_VENEER, and ra8_usb_device_attach().
Referenced by internal_usb_audio_usb_or_halt().
|
nodiscard |
NSC veneer: bring up the USB device controller.
Forwards to ra8_usb_device_init. Scalar-only signature, so no NS-range check is needed.
| [in] | speed | Negotiated USB speed enum. |
| k_ra8_ok | USB controller programmed. |
| k_ra8_err_invalid_arg | Unknown speed. |
Definition at line 561 of file ra8_nsc_comms.c.
References RA8_NSC_VENEER, and ra8_usb_device_init().