aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDion Dokter <[email protected]>2024-12-25 22:50:19 +0100
committerDion Dokter <[email protected]>2024-12-25 22:50:19 +0100
commit92a489b6a126913129bedc3f8a1407256b3590d7 (patch)
treea0177bc413c52899ac97ce694499db26e92c454b
parentfd2b6c80e39e7e07a5ec40f784bed123e3f69b06 (diff)
Make SharedData repr C
-rw-r--r--embassy-stm32/src/lib.rs39
1 files changed, 37 insertions, 2 deletions
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index 39f3dfd61..3c7f96bb1 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -326,10 +326,11 @@ mod dual_core {
326 /// ``` 326 /// ```
327 /// 327 ///
328 /// This static must be placed in the same position for both cores. How and where this is done is left to the user. 328 /// This static must be placed in the same position for both cores. How and where this is done is left to the user.
329 #[repr(C)]
329 pub struct SharedData { 330 pub struct SharedData {
330 init_flag: AtomicUsize, 331 init_flag: AtomicUsize,
331 clocks: UnsafeCell<MaybeUninit<Clocks>>, 332 clocks: UnsafeCell<MaybeUninit<Clocks>>,
332 config: UnsafeCell<MaybeUninit<Config>>, 333 config: UnsafeCell<MaybeUninit<SharedConfig>>,
333 } 334 }
334 335
335 unsafe impl Sync for SharedData {} 336 unsafe impl Sync for SharedData {}
@@ -352,7 +353,7 @@ mod dual_core {
352 rcc::set_freqs_ptr(shared_data.clocks.get()); 353 rcc::set_freqs_ptr(shared_data.clocks.get());
353 let p = init_hw(config); 354 let p = init_hw(config);
354 355
355 unsafe { *shared_data.config.get() }.write(config); 356 unsafe { *shared_data.config.get() }.write(config.into());
356 357
357 shared_data.init_flag.store(INIT_DONE_FLAG, Ordering::SeqCst); 358 shared_data.init_flag.store(INIT_DONE_FLAG, Ordering::SeqCst);
358 359
@@ -424,6 +425,40 @@ mod dual_core {
424 425
425 Peripherals::take() 426 Peripherals::take()
426 } 427 }
428
429 #[repr(C)]
430 #[derive(Clone, Copy)]
431 struct SharedConfig {
432 #[cfg(bdma)]
433 bdma_interrupt_priority: Priority,
434 #[cfg(dma)]
435 dma_interrupt_priority: Priority,
436 #[cfg(gpdma)]
437 gpdma_interrupt_priority: Priority,
438 }
439
440 impl From<Config> for SharedConfig {
441 fn from(value: Config) -> Self {
442 let Config {
443 #[cfg(bdma)]
444 bdma_interrupt_priority,
445 #[cfg(dma)]
446 dma_interrupt_priority,
447 #[cfg(gpdma)]
448 gpdma_interrupt_priority,
449 ..
450 } = value;
451
452 SharedConfig {
453 #[cfg(bdma)]
454 bdma_interrupt_priority,
455 #[cfg(dma)]
456 dma_interrupt_priority,
457 #[cfg(gpdma)]
458 gpdma_interrupt_priority,
459 }
460 }
461 }
427} 462}
428 463
429#[cfg(feature = "_dual-core")] 464#[cfg(feature = "_dual-core")]