3
3
/// Macro to create interfaces to CLINT peripherals in PACs.
4
4
/// The resulting struct will be named `CLINT`, and will provide safe access to the CLINT registers.
5
5
///
6
- /// This macro expects 4 different argument types:
6
+ /// This macro expects 5 different argument types:
7
7
///
8
8
/// - Base address (**MANDATORY**): base address of the CLINT peripheral of the target.
9
9
/// - Frequency (**OPTIONAL**): clock frequency (in Hz) of the `MTIME` register. It enables the `delay` method of the `CLINT` struct.
10
+ /// - Async flag (**OPTIONAL**): It enables the `async_delay` method of the `CLINT struct`.
11
+ /// You must activate the `embedded-hal-async` feature to use this flag.
10
12
/// - Per-HART mtimecmp registers (**OPTIONAL**): a list of `mtimecmp` registers for easing access to per-HART mtimecmp regs.
11
13
/// - Per-HART msip registers (**OPTIONAL**): a list of `msip` registers for easing access to per-HART msip regs.
12
14
///
17
19
/// ## Base address only
18
20
///
19
21
/// ```
20
- /// use riscv_peripheral::clint_codegen;
21
- ///
22
- /// clint_codegen!(base 0x0200_0000, freq 32_768,); // do not forget the ending comma!
22
+ /// riscv_peripheral::clint_codegen!(base 0x0200_0000, freq 32_768,); // do not forget the ending comma!
23
23
///
24
- /// let mswi = CLINT::mswi(); // MSWI peripheral
24
+ /// let mswi = CLINT::mswi(); // MSWI peripheral
25
25
/// let mtimer = CLINT::mtimer(); // MTIMER peripheral
26
- /// let delay = CLINT::delay(); // For the `embedded_hal::delay::DelayNs` trait
26
+ /// let delay = CLINT::delay(); // For the `embedded_hal::delay::DelayNs` trait
27
27
/// ```
28
28
///
29
29
/// ## Base address and per-HART mtimecmp registers
30
30
///
31
31
/// ```
32
- /// use riscv_peripheral::clint_codegen;
33
32
/// use riscv_pac::result::{Error, Result};
34
33
///
35
34
/// /// HART IDs for the target CLINT peripheral
36
35
/// #[derive(Clone, Copy, Debug, Eq, PartialEq)]
37
- /// #[repr(u16)]
38
36
/// pub enum HartId { H0 = 0, H1 = 1, H2 = 2 }
39
37
///
40
38
/// // Implement `HartIdNumber` for `HartId`
41
39
/// unsafe impl riscv_peripheral::aclint::HartIdNumber for HartId {
42
40
/// const MAX_HART_ID_NUMBER: u16 = 2;
43
41
/// fn number(self) -> u16 { self as _ }
44
42
/// fn from_number(number: u16) -> Result<Self> {
45
- /// if number > Self::MAX_HART_ID_NUMBER {
46
- /// Err(Error::InvalidVariant(number as usize))
47
- /// } else {
48
- /// // SAFETY: valid context number
49
- /// Ok(unsafe { core::mem::transmute (number) })
43
+ /// match number {
44
+ /// 0 => Ok(HartId::H0),
45
+ /// 1 => Ok(HartId::H1),
46
+ /// 2 => Ok(HartId::H2),
47
+ /// _ => Err(Error::InvalidVariant (number as _)),
50
48
/// }
51
49
/// }
52
50
/// }
53
51
///
54
- /// clint_codegen!(
52
+ /// riscv_peripheral:: clint_codegen!(
55
53
/// base 0x0200_0000,
56
54
/// mtimecmps [mtimecmp0 = (HartId::H0, "`H0`"), mtimecmp1 = (HartId::H1, "`H1`"), mtimecmp2 = (HartId::H2, "`H2`")],
57
55
/// msips [msip0=(HartId::H0,"`H0`"), msip1=(HartId::H1,"`H1`"), msip2=(HartId::H2,"`H2`")], // do not forget the ending comma!
@@ -206,7 +204,7 @@ macro_rules! clint_codegen {
206
204
///
207
205
/// # Note
208
206
///
209
- /// You must export the `riscv_peripheral::hal:: delay::DelayNs` trait in order to use delay methods.
207
+ /// You must export the [`embedded_hal:: delay::DelayNs`] trait in order to use delay methods.
210
208
#[ inline]
211
209
pub const fn delay( ) -> $crate:: hal:: aclint:: Delay {
212
210
$crate:: hal:: aclint:: Delay :: new( Self :: mtime( ) , Self :: freq( ) )
@@ -220,7 +218,7 @@ macro_rules! clint_codegen {
220
218
///
221
219
/// # Note
222
220
///
223
- /// You must export the `riscv_peripheral::hal_async:: delay::DelayNs` trait in order to use delay methods.
221
+ /// You must export the [`embedded_hal_async:: delay::DelayNs`] trait in order to use delay methods.
224
222
///
225
223
/// This implementation relies on the machine-level timer interrupts to wake futures.
226
224
/// Therefore, it needs to schedule the machine-level timer interrupts via the `MTIMECMP` register assigned to the current HART.
@@ -264,6 +262,27 @@ macro_rules! clint_codegen {
264
262
}
265
263
266
264
/// Macro to create interfaces to PLIC peripherals in PACs.
265
+ /// The resulting struct will be named `PLIC`, and will provide safe access to the PLIC registers.
266
+ ///
267
+ /// This macro expects 2 different argument types:
268
+ ///
269
+ /// - Base address (**MANDATORY**): base address of the PLIC peripheral of the target.
270
+ /// - Per-HART contexts (**OPTIONAL**): a list of `ctx` contexts for easing access to per-HART PLIC contexts.
271
+ ///
272
+ /// Check the examples below for more details about the usage and syntax of this macro.
273
+ ///
274
+ /// # Example
275
+ ///
276
+ /// ## Base address only
277
+ ///
278
+ /// ```
279
+ /// use riscv_peripheral::clint_codegen;
280
+ ///
281
+ /// riscv_peripheral::plic_codegen!(base 0x0C00_0000,); // do not forget the ending comma!
282
+ ///
283
+ /// let priorities = PLIC::priorities(); // Priorities registers
284
+ /// let pendings = PLIC::pendings(); // Pendings registers
285
+ /// ```
267
286
#[ macro_export]
268
287
macro_rules! plic_codegen {
269
288
( ) => {
0 commit comments