target/ast10x0/peripherals: align PhantomData to *const () across all structs Replace PhantomData<UnsafeCell<()>> (_not_sync) with PhantomData<*const ()> (_not_send_sync) in all peripheral register wrapper structs, and add the field where it was missing entirely. - scu/registers.rs: rename _not_sync -> _not_send_sync, update type - smc/registers.rs: rename _not_sync -> _not_send_sync, update type, remove now-unused UnsafeCell import - i2c/controller.rs: rename _not_sync -> _not_send_sync, update type, remove now-unused UnsafeCell import - sgpiom/register_block.rs: add missing _not_send_sync field and import - uart/mod.rs: add missing _not_send_sync field and import PhantomData<*const ()> is the conventional way to opt out of both Send and Sync regardless of other field types, and makes the intent explicit at the struct definition.
diff --git a/target/ast10x0/peripherals/scu/registers.rs b/target/ast10x0/peripherals/scu/registers.rs index 3444b72..ceb7314 100644 --- a/target/ast10x0/peripherals/scu/registers.rs +++ b/target/ast10x0/peripherals/scu/registers.rs
@@ -4,7 +4,6 @@ //! AST10x0 SCU low-level register access. use ast1060_pac as device; -use core::cell::UnsafeCell; use core::marker::PhantomData; const SCU_UNLOCK_KEY: u32 = 0x1688_A8A8; @@ -12,7 +11,12 @@ /// Safe wrapper around the AST10x0 SCU register block. pub struct ScuRegisters { base: *const device::scu::RegisterBlock, - _not_sync: PhantomData<UnsafeCell<()>>, // Prevent Sync, allow Send. + /// Prevent `Send` and `Sync`. + /// + /// MMIO register blocks must not be transferred across threads or + /// shared by reference due to potential side effects and lack of + /// synchronization guarantees. + _not_send_sync: PhantomData<*const ()>, } impl ScuRegisters { @@ -23,10 +27,7 @@ /// - `base` points to a valid SCU register block. /// - access to the SCU instance is serialized appropriately. const unsafe fn new(base: *const device::scu::RegisterBlock) -> Self { - Self { - base, - _not_sync: PhantomData, - } + Self { base, _not_send_sync: PhantomData } } /// Create a register accessor for the global SCU instance.
diff --git a/target/ast10x0/peripherals/sgpiom/register_block.rs b/target/ast10x0/peripherals/sgpiom/register_block.rs index 35fa4ec..f227c42 100644 --- a/target/ast10x0/peripherals/sgpiom/register_block.rs +++ b/target/ast10x0/peripherals/sgpiom/register_block.rs
@@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use ast1060_pac as device; +use core::marker::PhantomData; use super::types::{ Bank, BankDevice, Direction, Error, InitialLevel, InterruptMode, InterruptTrigger, @@ -10,6 +11,12 @@ pub struct Sgpiom { sgpiom: *const device::sgpiom::RegisterBlock, + /// Prevent `Send` and `Sync`. + /// + /// MMIO register blocks must not be transferred across threads or + /// shared by reference due to potential side effects and lack of + /// synchronization guarantees. + _not_send_sync: PhantomData<*const ()>, } impl Sgpiom { @@ -21,7 +28,7 @@ /// - The pointed register block must remain valid for the lifetime of this `Sgpiom`. /// - Caller must enforce global ownership so concurrent mutable access does not occur. pub const unsafe fn new(sgpiom: *const device::sgpiom::RegisterBlock) -> Self { - Self { sgpiom } + Self { sgpiom, _not_send_sync: PhantomData } } /// Create an instance pointing to the global AST1060 SGPIOM register block.
diff --git a/target/ast10x0/peripherals/uart/mod.rs b/target/ast10x0/peripherals/uart/mod.rs index 7a07df4..ad45b7f 100644 --- a/target/ast10x0/peripherals/uart/mod.rs +++ b/target/ast10x0/peripherals/uart/mod.rs
@@ -3,6 +3,7 @@ use ast1060_pac as device; use bitflags::bitflags; +use core::marker::PhantomData; use embedded_hal_nb::serial as serial_nb; use embedded_io::{Read, Write}; @@ -100,6 +101,12 @@ } pub struct Usart { usart: *const device::uart::RegisterBlock, + /// Prevent `Send` and `Sync`. + /// + /// MMIO register blocks must not be transferred across threads or + /// shared by reference due to potential side effects and lack of + /// synchronization guarantees. + _not_send_sync: PhantomData<*const ()>, } impl embedded_io::ErrorType for Usart { @@ -278,7 +285,7 @@ /// - `usart` must be a valid, non-null pointer to the AST1060 UART register block. /// - The pointed register block must remain valid for the lifetime of this `Usart`. pub const unsafe fn new_uninit(usart: *const device::uart::RegisterBlock) -> Self { - Self { usart } + Self { usart, _not_send_sync: PhantomData } } /// Create a new USART instance from a raw register-block pointer. @@ -293,7 +300,7 @@ /// - Caller must enforce global ownership/coordination so concurrent mutable access /// does not occur through other code paths. pub unsafe fn new(usart: *const device::uart::RegisterBlock) -> Self { - let this = Self { usart }; + let this = Self { usart, _not_send_sync: PhantomData }; unsafe { this.regs().uartfcr().write(|w| {