Skip to content

Commit

Permalink
feat(r3): rename *::{build → define}
Browse files Browse the repository at this point in the history
Leaves room for a runtime builder.
  • Loading branch information
yvt committed Dec 3, 2021
1 parent 7ed52b3 commit f4db2da
Show file tree
Hide file tree
Showing 102 changed files with 386 additions and 370 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
System::configure_systick(b);

Objects {
task: Task::build()
task: Task::define()
.start(task_body)
.priority(2)
.active(true)
Expand Down
6 changes: 3 additions & 3 deletions examples/basic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const COTTAGE: Objects = r3_kernel::build!(SystemTraits, configure_app => Object
const fn configure_app(b: &mut r3_kernel::Cfg<'_, SystemTraits>) -> Objects {
b.num_task_priority_levels(4);

let task1 = Task::build()
let task1 = Task::define()
.start(task1_body)
.priority(2)
.active(true)
.finish(b);
let task2 = Task::build().start(task2_body).priority(3).finish(b);
let task2 = Task::define().start(task2_body).priority(3).finish(b);

let mutex1 = Mutex::build().finish(b);
let mutex1 = Mutex::define().finish(b);

Objects {
task1,
Expand Down
6 changes: 3 additions & 3 deletions examples/basic_gr_peach/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
SystemTraits::configure_os_timer(b);

// Initialize the serial port
StartupHook::build()
StartupHook::define()
.start(|_| {
use support_rza1::serial::ScifExt;

Expand All @@ -89,12 +89,12 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
})
.finish(b);

let task1 = Task::build()
let task1 = Task::define()
.start(task1_body)
.priority(2)
.active(true)
.finish(b);
let task2 = Task::build().start(task2_body).priority(3).finish(b);
let task2 = Task::define().start(task2_body).priority(3).finish(b);

Objects { task1, task2 }
}
Expand Down
8 changes: 4 additions & 4 deletions examples/basic_nucleo_f401re/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {

// Initialize RTT (Real-Time Transfer) with a single up channel and set
// it as the print channel for the printing macros
StartupHook::build()
StartupHook::define()
.start(|_| {
rtt_target::rtt_init_print!();
})
.finish(b);

SystemTraits::configure_systick(b);

let task1 = Task::build()
let task1 = Task::define()
.start(task1_body)
.priority(2)
.active(true)
.finish(b);
let task2 = Task::build().start(task2_body).priority(3).finish(b);
let task2 = Task::define().start(task2_body).priority(3).finish(b);

let mutex1 = Mutex::build().finish(b);
let mutex1 = Mutex::define().finish(b);

Objects {
task1,
Expand Down
8 changes: 4 additions & 4 deletions examples/basic_rp_pico/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const COTTAGE: Objects = r3_kernel::build!(SystemTraits, configure_app => Object
const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
b.num_task_priority_levels(4);

StartupHook::build()
StartupHook::define()
.start(|_| {
// Configure peripherals
let p = unsafe { rp2040::Peripherals::steal() };
Expand Down Expand Up @@ -115,14 +115,14 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {

SystemTraits::configure_systick(b);

let task1 = Task::build()
let task1 = Task::define()
.start(task1_body)
.priority(2)
.active(true)
.finish(b);
let task2 = Task::build().start(task2_body).priority(3).finish(b);
let task2 = Task::define().start(task2_body).priority(3).finish(b);

let mutex1 = Mutex::build().finish(b);
let mutex1 = Mutex::define().finish(b);

Objects {
task1,
Expand Down
30 changes: 15 additions & 15 deletions examples/basic_wio_terminal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
b.num_task_priority_levels(4);

// Register a hook to initialize hardware
StartupHook::build()
StartupHook::define()
.start(|_| {
init_hardware();
})
Expand All @@ -119,65 +119,65 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
SystemTraits::configure_systick(b);

// Miscellaneous tasks
let _noisy_task = Task::build()
let _noisy_task = Task::define()
.start(noisy_task_body)
.priority(0)
.active(true)
.finish(b);
let button_reporter_task = Task::build()
let button_reporter_task = Task::define()
.start(button_reporter_task_body)
.priority(2)
.active(true)
.finish(b);
let _blink_task = Task::build()
let _blink_task = Task::define()
.start(blink_task_body)
.priority(1)
.active(true)
.finish(b);

// USB input handler
let usb_in_task = Task::build()
let usb_in_task = Task::define()
.start(usb_in_task_body)
.priority(2)
.active(true)
.finish(b);
let usb_poll_timer = Timer::build()
let usb_poll_timer = Timer::define()
.start(usb_poll_timer_handler)
.delay(r3::time::Duration::from_millis(0))
// Should be < 10ms for USB compliance
.period(r3::time::Duration::from_millis(5))
.finish(b);
let usb_interrupt_lines = [
InterruptLine::build()
InterruptLine::define()
.line(interrupt::USB_OTHER as InterruptNum + port::INTERRUPT_EXTERNAL0)
.priority(1)
.enabled(true)
.finish(b),
InterruptLine::build()
InterruptLine::define()
.line(interrupt::USB_TRCPT0 as InterruptNum + port::INTERRUPT_EXTERNAL0)
.priority(1)
.enabled(true)
.finish(b),
InterruptLine::build()
InterruptLine::define()
.line(interrupt::USB_TRCPT1 as InterruptNum + port::INTERRUPT_EXTERNAL0)
.priority(1)
.enabled(true)
.finish(b),
];

// Graphics-related tasks and objects
let _animation_task = Task::build()
let _animation_task = Task::define()
.start(animation_task_body)
.priority(2)
.active(true)
.finish(b);
let _console_task = Task::build()
let _console_task = Task::define()
.start(console_task_body)
.priority(3)
.active(true)
.finish(b);
let console_pipe = queue::Queue::new(b);
let lcd_mutex = Mutex::build().finish(b);
let lcd_mutex = Mutex::define().finish(b);

Objects {
console_pipe,
Expand Down Expand Up @@ -686,9 +686,9 @@ mod queue {
C: ~const traits::CfgBase<System = System> + ~const traits::CfgMutex,
{
Self {
st: Mutex::build().finish(cfg),
reader_lock: Mutex::build().finish(cfg),
writer_lock: Mutex::build().finish(cfg),
st: Mutex::define().finish(cfg),
reader_lock: Mutex::define().finish(cfg),
writer_lock: Mutex::define().finish(cfg),
}
}

Expand Down
12 changes: 6 additions & 6 deletions examples/smp_rp_pico/src/core0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const COTTAGE: Objects = r3_kernel::build!(SystemTraits, configure_app => Object
const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
b.num_task_priority_levels(4);

StartupHook::build()
StartupHook::define()
.start(|_| {
// Configure peripherals
let p = unsafe { rp2040::Peripherals::steal() };
Expand Down Expand Up @@ -87,26 +87,26 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {

SystemTraits::configure_systick(b);

let task1 = Task::build()
let task1 = Task::define()
.start(task1_body)
.priority(2)
.active(true)
.finish(b);
let task2 = Task::build().start(task2_body).priority(3).finish(b);
let task2 = Task::define().start(task2_body).priority(3).finish(b);

let mutex1 = Mutex::build().finish(b);
let mutex1 = Mutex::define().finish(b);

// Listen for messages from core1
let int_fifo = rp2040::Interrupt::SIO_IRQ_PROC0 as InterruptNum + port::INTERRUPT_EXTERNAL0;
InterruptLine::build()
InterruptLine::define()
.line(int_fifo)
// The priority should be lower than USB interrupts so that USB packets
// can handled by the USB interrupt handler while we are doing
// `write_bytes`
.priority(0x40)
.enabled(true)
.finish(b);
InterruptHandler::build()
InterruptHandler::define()
.line(int_fifo)
.start(|_| {
let p = unsafe { rp2040::Peripherals::steal() };
Expand Down
2 changes: 1 addition & 1 deletion examples/smp_rp_pico/src/core1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {

SystemTraits::configure_systick(b);

let task1 = Task::build()
let task1 = Task::define()
.start(task1_body)
.priority(2)
.active(true)
Expand Down
8 changes: 4 additions & 4 deletions src/r3/src/hunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ unsafe impl<System, T: ?Sized + Sync> Sync for Hunk<System, T> {}
impl<System: raw::KernelBase + cfg::KernelStatic, T: ?Sized> Hunk<System, T> {
/// Construct a `HunkDefiner` to define a hunk in [a configuration
/// function](crate#static-configuration).
pub const fn build() -> HunkDefiner<System, T, DefaultInitTag> {
pub const fn define() -> HunkDefiner<System, T, DefaultInitTag> {
HunkDefiner {
_phantom: PhantomData,
len: 1,
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<System: raw::KernelBase + cfg::KernelStatic, T, InitTag: HunkIniter<T>>
self,
cfg: &mut Cfg<C>,
) -> Hunk<System, T> {
let untyped_hunk = kernel::Hunk::<System>::build()
let untyped_hunk = kernel::Hunk::<System>::define()
.len(mem::size_of::<T>())
.align(max(mem::align_of::<T>(), self.align))
.finish(cfg);
Expand All @@ -163,7 +163,7 @@ impl<System: raw::KernelBase + cfg::KernelStatic, T, InitTag: HunkIniter<T>>
// Insert an initializer
if InitTag::NEEDS_INIT {
unsafe {
StartupHook::build()
StartupHook::define()
.priority(INIT_HOOK_PRIORITY)
.start(|start| {
let untyped_hunk = kernel::Hunk::<System>::from_offset(start).as_ptr();
Expand Down Expand Up @@ -193,7 +193,7 @@ impl<System: raw::KernelBase + cfg::KernelStatic, T, InitTag: HunkIniter<T>>
) -> Hunk<System, [T]> {
assert!(self.align.is_power_of_two(), "`align` is not power of two");

let untyped_hunk = kernel::Hunk::<System>::build()
let untyped_hunk = kernel::Hunk::<System>::define()
.len(mem::size_of::<T>() * self.len)
.align(max(mem::align_of::<T>(), self.align))
.finish(cfg);
Expand Down
2 changes: 1 addition & 1 deletion src/r3/src/kernel/event_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<System: raw::KernelEventGroup> EventGroup<System> {
impl<System: raw::KernelEventGroup> EventGroup<System> {
/// Construct a `EventGroupDefiner` to define an event group in [a
/// configuration function](crate#static-configuration).
pub const fn build() -> EventGroupDefiner<System> {
pub const fn define() -> EventGroupDefiner<System> {
EventGroupDefiner::new()
}

Expand Down
2 changes: 1 addition & 1 deletion src/r3/src/kernel/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct StartupHook<System: raw::KernelBase>(PhantomInvariant<System>);
impl<System: raw::KernelBase> StartupHook<System> {
/// Construct a `StartupHookDefiner` to register a startup hook in
/// [a configuration function](crate#static-configuration).
pub const fn build() -> StartupHookDefiner<System> {
pub const fn define() -> StartupHookDefiner<System> {
StartupHookDefiner::new()
}

Expand Down
2 changes: 1 addition & 1 deletion src/r3/src/kernel/hunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<System: cfg::KernelStatic> Copy for Hunk<System> {}
impl<System: cfg::KernelStatic> Hunk<System> {
/// Construct a `HunkDefiner` to define a hunk in [a
/// configuration function](crate#static-configuration).
pub const fn build() -> HunkDefiner<System> {
pub const fn define() -> HunkDefiner<System> {
HunkDefiner::new()
}

Expand Down
6 changes: 3 additions & 3 deletions src/r3/src/kernel/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<System: raw::KernelInterruptLine> InterruptLine<System> {
impl<System: raw::KernelInterruptLine> InterruptLine<System> {
/// Construct a `InterruptLineDefiner` to define an interrupt line in [a
/// configuration function](crate#static-configuration).
pub const fn build() -> InterruptLineDefiner<System> {
pub const fn define() -> InterruptLineDefiner<System> {
InterruptLineDefiner::new()
}

Expand Down Expand Up @@ -175,7 +175,7 @@ impl<System: raw::KernelInterruptLine> InterruptHandler<System> {

/// Construct a `InterruptHandlerDefiner` to define an interrupt handler in
/// [a configuration function](crate#static-configuration).
pub const fn build() -> InterruptHandlerDefiner<System> {
pub const fn define() -> InterruptHandlerDefiner<System> {
InterruptHandlerDefiner::new()
}
}
Expand Down Expand Up @@ -366,7 +366,7 @@ impl<System: raw::KernelInterruptLine> InterruptHandlerDefiner<System> {
};

// Add a `CfgInterruptLineInfo` at the same time
InterruptLine::build().line(line_num).finish(cfg);
InterruptLine::define().line(line_num).finish(cfg);

let order = cfg.interrupt_handlers.len();
cfg.interrupt_handlers.push(CfgInterruptHandler {
Expand Down
4 changes: 2 additions & 2 deletions src/r3/src/kernel/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub use raw::MutexProtocol;
/// C: ~const traits::CfgMutex,
/// C::System: traits::KernelMutex, // FIXME: Why not implied by `CfgMutex`?
/// {
/// let mutex = Mutex::build()
/// let mutex = Mutex::define()
/// .protocol(MutexProtocol::Ceiling(1))
/// .finish(cfg);
/// Objects { mutex }
Expand Down Expand Up @@ -323,7 +323,7 @@ impl<System: raw::KernelMutex> Mutex<System> {
impl<System: raw::KernelMutex> Mutex<System> {
/// Construct a `MutexDefiner` to define a mutex in [a
/// configuration function](crate#static-configuration).
pub const fn build() -> MutexDefiner<System> {
pub const fn define() -> MutexDefiner<System> {
MutexDefiner::new()
}

Expand Down
2 changes: 1 addition & 1 deletion src/r3/src/kernel/semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<System: raw::KernelSemaphore> Semaphore<System> {
impl<System: raw::KernelSemaphore> Semaphore<System> {
/// Construct a `SemaphoreDefiner` to define a semaphore in [a
/// configuration function](crate#static-configuration).
pub const fn build() -> SemaphoreDefiner<System> {
pub const fn define() -> SemaphoreDefiner<System> {
SemaphoreDefiner::new()
}

Expand Down
2 changes: 1 addition & 1 deletion src/r3/src/kernel/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<System: raw::KernelBase> Task<System> {
impl<System: raw::KernelBase> Task<System> {
/// Construct a `TaskDefiner` to define a mutex in [a configuration
/// function](crate#static-configuration).
pub const fn build() -> TaskDefiner<System> {
pub const fn define() -> TaskDefiner<System> {
TaskDefiner::new()
}

Expand Down
Loading

0 comments on commit f4db2da

Please sign in to comment.