Skip to content

Commit 1608a66

Browse files
committed
Add #[inline] to lots of trivial functions.
1 parent f505673 commit 1608a66

File tree

8 files changed

+75
-0
lines changed

8 files changed

+75
-0
lines changed

src/itm.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ unsafe fn write_words(stim: &mut Stim, bytes: &[u32]) {
2121
struct Port<'p>(&'p mut Stim);
2222

2323
impl<'p> fmt::Write for Port<'p> {
24+
#[inline]
2425
fn write_str(&mut self, s: &str) -> fmt::Result {
2526
write_all(self.0, s.as_bytes());
2627
Ok(())
@@ -126,13 +127,15 @@ pub fn write_aligned(port: &mut Stim, buffer: &Aligned<A4, [u8]>) {
126127
}
127128

128129
/// Writes `fmt::Arguments` to the ITM `port`
130+
#[inline]
129131
pub fn write_fmt(port: &mut Stim, args: fmt::Arguments) {
130132
use core::fmt::Write;
131133

132134
Port(port).write_fmt(args).ok();
133135
}
134136

135137
/// Writes a string to the ITM `port`
138+
#[inline]
136139
pub fn write_str(port: &mut Stim, string: &str) {
137140
write_all(port, string.as_bytes())
138141
}

src/peripheral/cpuid.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl CPUID {
8282
/// * `ind`: select instruction cache or data/unified cache
8383
///
8484
/// `level` is masked to be between 0 and 7.
85+
#[inline]
8586
pub fn select_cache(&mut self, level: u8, ind: CsselrCacheType) {
8687
const CSSELR_IND_POS: u32 = 0;
8788
const CSSELR_IND_MASK: u32 = 1 << CSSELR_IND_POS;
@@ -97,6 +98,7 @@ impl CPUID {
9798
}
9899

99100
/// Returns the number of sets and ways in the selected cache
101+
#[inline]
100102
pub fn cache_num_sets_ways(&mut self, level: u8, ind: CsselrCacheType) -> (u16, u16) {
101103
const CCSIDR_NUMSETS_POS: u32 = 13;
102104
const CCSIDR_NUMSETS_MASK: u32 = 0x7FFF << CCSIDR_NUMSETS_POS;

src/peripheral/dcb.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl DCB {
2525
/// `peripheral::DWT` cycle counter to work properly.
2626
/// As by STM documentation, this flag is not reset on
2727
/// soft-reset, only on power reset.
28+
#[inline]
2829
pub fn enable_trace(&mut self) {
2930
// set bit 24 / TRCENA
3031
unsafe {
@@ -33,6 +34,7 @@ impl DCB {
3334
}
3435

3536
/// Disables TRACE. See `DCB::enable_trace()` for more details
37+
#[inline]
3638
pub fn disable_trace(&mut self) {
3739
// unset bit 24 / TRCENA
3840
unsafe {
@@ -47,6 +49,7 @@ impl DCB {
4749
/// on Cortex-M0 devices. Per the ARM v6-M Architecture Reference Manual, "Access to the DHCSR
4850
/// from software running on the processor is IMPLEMENTATION DEFINED". Indeed, from the
4951
/// [Cortex-M0+ r0p1 Technical Reference Manual](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0484c/BABJHEIG.html), "Note Software cannot access the debug registers."
52+
#[inline]
5053
pub fn is_debugger_attached() -> bool {
5154
unsafe {
5255
// do an 8-bit read of the 32-bit DHCSR register, and get the LSB

src/peripheral/dwt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ pub struct Comparator {
6565
impl DWT {
6666
/// Enables the cycle counter
6767
#[cfg(not(armv6m))]
68+
#[inline]
6869
pub fn enable_cycle_counter(&mut self) {
6970
unsafe { self.ctrl.modify(|r| r | 1) }
7071
}
7172

7273
/// Returns the current clock cycle count
7374
#[cfg(not(armv6m))]
75+
#[inline]
7476
pub fn get_cycle_count() -> u32 {
7577
// NOTE(unsafe) atomic read with no side effects
7678
unsafe { (*Self::ptr()).cyccnt.read() }

src/peripheral/itm.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,25 @@ pub struct Stim {
3535

3636
impl Stim {
3737
/// Writes an `u8` payload into the stimulus port
38+
#[inline]
3839
pub fn write_u8(&mut self, value: u8) {
3940
unsafe { ptr::write_volatile(self.register.get() as *mut u8, value) }
4041
}
4142

4243
/// Writes an `u16` payload into the stimulus port
44+
#[inline]
4345
pub fn write_u16(&mut self, value: u16) {
4446
unsafe { ptr::write_volatile(self.register.get() as *mut u16, value) }
4547
}
4648

4749
/// Writes an `u32` payload into the stimulus port
50+
#[inline]
4851
pub fn write_u32(&mut self, value: u32) {
4952
unsafe { ptr::write_volatile(self.register.get(), value) }
5053
}
5154

5255
/// Returns `true` if the stimulus port is ready to accept more data
56+
#[inline]
5357
pub fn is_fifo_ready(&self) -> bool {
5458
unsafe { ptr::read_volatile(self.register.get()) == 1 }
5559
}

src/peripheral/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ impl Peripherals {
158158
}
159159

160160
/// Unchecked version of `Peripherals::take`
161+
#[inline]
161162
pub unsafe fn steal() -> Self {
162163
CORE_PERIPHERALS = true;
163164

@@ -211,13 +212,15 @@ unsafe impl Send for CBP {}
211212

212213
#[cfg(not(armv6m))]
213214
impl CBP {
215+
#[inline(always)]
214216
pub(crate) unsafe fn new() -> Self {
215217
CBP {
216218
_marker: PhantomData,
217219
}
218220
}
219221

220222
/// Returns a pointer to the register block
223+
#[inline(always)]
221224
pub fn ptr() -> *const self::cbp::RegisterBlock {
222225
0xE000_EF50 as *const _
223226
}
@@ -227,6 +230,7 @@ impl CBP {
227230
impl ops::Deref for CBP {
228231
type Target = self::cbp::RegisterBlock;
229232

233+
#[inline(always)]
230234
fn deref(&self) -> &Self::Target {
231235
unsafe { &*Self::ptr() }
232236
}
@@ -241,6 +245,7 @@ unsafe impl Send for CPUID {}
241245

242246
impl CPUID {
243247
/// Returns a pointer to the register block
248+
#[inline(always)]
244249
pub fn ptr() -> *const self::cpuid::RegisterBlock {
245250
0xE000_ED00 as *const _
246251
}
@@ -249,6 +254,7 @@ impl CPUID {
249254
impl ops::Deref for CPUID {
250255
type Target = self::cpuid::RegisterBlock;
251256

257+
#[inline(always)]
252258
fn deref(&self) -> &Self::Target {
253259
unsafe { &*Self::ptr() }
254260
}
@@ -263,6 +269,7 @@ unsafe impl Send for DCB {}
263269

264270
impl DCB {
265271
/// Returns a pointer to the register block
272+
#[inline(always)]
266273
pub fn ptr() -> *const dcb::RegisterBlock {
267274
0xE000_EDF0 as *const _
268275
}
@@ -271,6 +278,7 @@ impl DCB {
271278
impl ops::Deref for DCB {
272279
type Target = self::dcb::RegisterBlock;
273280

281+
#[inline(always)]
274282
fn deref(&self) -> &Self::Target {
275283
unsafe { &*DCB::ptr() }
276284
}
@@ -285,6 +293,7 @@ unsafe impl Send for DWT {}
285293

286294
impl DWT {
287295
/// Returns a pointer to the register block
296+
#[inline(always)]
288297
pub fn ptr() -> *const dwt::RegisterBlock {
289298
0xE000_1000 as *const _
290299
}
@@ -293,6 +302,7 @@ impl DWT {
293302
impl ops::Deref for DWT {
294303
type Target = self::dwt::RegisterBlock;
295304

305+
#[inline(always)]
296306
fn deref(&self) -> &Self::Target {
297307
unsafe { &*Self::ptr() }
298308
}
@@ -308,6 +318,7 @@ unsafe impl Send for FPB {}
308318
#[cfg(not(armv6m))]
309319
impl FPB {
310320
/// Returns a pointer to the register block
321+
#[inline(always)]
311322
pub fn ptr() -> *const fpb::RegisterBlock {
312323
0xE000_2000 as *const _
313324
}
@@ -317,6 +328,7 @@ impl FPB {
317328
impl ops::Deref for FPB {
318329
type Target = self::fpb::RegisterBlock;
319330

331+
#[inline(always)]
320332
fn deref(&self) -> &Self::Target {
321333
unsafe { &*Self::ptr() }
322334
}
@@ -332,6 +344,7 @@ unsafe impl Send for FPU {}
332344
#[cfg(any(has_fpu, target_arch = "x86_64"))]
333345
impl FPU {
334346
/// Returns a pointer to the register block
347+
#[inline(always)]
335348
pub fn ptr() -> *const fpu::RegisterBlock {
336349
0xE000_EF30 as *const _
337350
}
@@ -341,6 +354,7 @@ impl FPU {
341354
impl ops::Deref for FPU {
342355
type Target = self::fpu::RegisterBlock;
343356

357+
#[inline(always)]
344358
fn deref(&self) -> &Self::Target {
345359
unsafe { &*Self::ptr() }
346360
}
@@ -356,6 +370,7 @@ unsafe impl Send for ITM {}
356370
#[cfg(not(armv6m))]
357371
impl ITM {
358372
/// Returns a pointer to the register block
373+
#[inline(always)]
359374
pub fn ptr() -> *mut itm::RegisterBlock {
360375
0xE000_0000 as *mut _
361376
}
@@ -365,13 +380,15 @@ impl ITM {
365380
impl ops::Deref for ITM {
366381
type Target = self::itm::RegisterBlock;
367382

383+
#[inline(always)]
368384
fn deref(&self) -> &Self::Target {
369385
unsafe { &*Self::ptr() }
370386
}
371387
}
372388

373389
#[cfg(not(armv6m))]
374390
impl ops::DerefMut for ITM {
391+
#[inline(always)]
375392
fn deref_mut(&mut self) -> &mut Self::Target {
376393
unsafe { &mut *Self::ptr() }
377394
}
@@ -386,6 +403,7 @@ unsafe impl Send for MPU {}
386403

387404
impl MPU {
388405
/// Returns a pointer to the register block
406+
#[inline(always)]
389407
pub fn ptr() -> *const mpu::RegisterBlock {
390408
0xE000_ED90 as *const _
391409
}
@@ -394,6 +412,7 @@ impl MPU {
394412
impl ops::Deref for MPU {
395413
type Target = self::mpu::RegisterBlock;
396414

415+
#[inline(always)]
397416
fn deref(&self) -> &Self::Target {
398417
unsafe { &*Self::ptr() }
399418
}
@@ -408,6 +427,7 @@ unsafe impl Send for NVIC {}
408427

409428
impl NVIC {
410429
/// Returns a pointer to the register block
430+
#[inline(always)]
411431
pub fn ptr() -> *const nvic::RegisterBlock {
412432
0xE000_E100 as *const _
413433
}
@@ -416,6 +436,7 @@ impl NVIC {
416436
impl ops::Deref for NVIC {
417437
type Target = self::nvic::RegisterBlock;
418438

439+
#[inline(always)]
419440
fn deref(&self) -> &Self::Target {
420441
unsafe { &*Self::ptr() }
421442
}
@@ -430,6 +451,7 @@ unsafe impl Send for SCB {}
430451

431452
impl SCB {
432453
/// Returns a pointer to the register block
454+
#[inline(always)]
433455
pub fn ptr() -> *const scb::RegisterBlock {
434456
0xE000_ED04 as *const _
435457
}
@@ -438,6 +460,7 @@ impl SCB {
438460
impl ops::Deref for SCB {
439461
type Target = self::scb::RegisterBlock;
440462

463+
#[inline(always)]
441464
fn deref(&self) -> &Self::Target {
442465
unsafe { &*Self::ptr() }
443466
}
@@ -452,6 +475,7 @@ unsafe impl Send for SYST {}
452475

453476
impl SYST {
454477
/// Returns a pointer to the register block
478+
#[inline(always)]
455479
pub fn ptr() -> *const syst::RegisterBlock {
456480
0xE000_E010 as *const _
457481
}
@@ -460,6 +484,7 @@ impl SYST {
460484
impl ops::Deref for SYST {
461485
type Target = self::syst::RegisterBlock;
462486

487+
#[inline(always)]
463488
fn deref(&self) -> &Self::Target {
464489
unsafe { &*Self::ptr() }
465490
}
@@ -475,6 +500,7 @@ unsafe impl Send for TPIU {}
475500
#[cfg(not(armv6m))]
476501
impl TPIU {
477502
/// Returns a pointer to the register block
503+
#[inline(always)]
478504
pub fn ptr() -> *const tpiu::RegisterBlock {
479505
0xE004_0000 as *const _
480506
}
@@ -484,6 +510,7 @@ impl TPIU {
484510
impl ops::Deref for TPIU {
485511
type Target = self::tpiu::RegisterBlock;
486512

513+
#[inline(always)]
487514
fn deref(&self) -> &Self::Target {
488515
unsafe { &*Self::ptr() }
489516
}

0 commit comments

Comments
 (0)