351 Commits

Author SHA1 Message Date
Emil Fresk
71188c3202
Merge pull request #185 from AfoHT/cargofmt
Cargo format
2020-12-03 20:50:48 +01:00
Henrik Tjäder
e1177dfd5b Run cargo fmt 2020-12-03 19:23:44 +00:00
Emil Fresk
70687d8ace
Merge pull request #182 from almusil/expose_len_for_consumer_producer
Queue: Expose len and capacity for Consumer and Producer
2020-11-30 15:55:04 +01:00
Ales Musil
5823e4785a Queue: Expose len and capacity for Consumer and Producer
It is usefull to know in advance the space that is
occupied by the items in queue.
2020-11-03 11:29:17 +01:00
bors[bot]
9ff3a5fa89
Merge #178
178: Version bump dependency 'as-slice' -> 0.1.4 r=korken89 a=ToddG

This fixes the issue I was having targeting AVR.

See: https://github.com/japaric/heapless/issues/177#issuecomment-697341580

## REPRO

```
(base) ~/temp/break/abc $ cargo build
    Updating crates.io index
   Compiling compiler_builtins v0.1.35
   Compiling core v0.0.0 (/home/todd/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling typenum v1.12.0
   Compiling version_check v0.9.2
   Compiling byteorder v1.3.4
   Compiling heapless v0.5.6 (/home/todd/temp/heapless)
   Compiling generic-array v0.14.4
   Compiling rustc-std-workspace-core v1.99.0 (/home/todd/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling stable_deref_trait v1.2.0
   Compiling hash32 v0.1.1
   Compiling generic-array v0.12.3
   Compiling generic-array v0.13.2
   Compiling as-slice v0.1.4
   Compiling abc v0.1.0 (/home/todd/temp/break/abc)
    Finished dev [unoptimized + debuginfo] target(s) in 26.46s
```

Co-authored-by: Todd Greenwood <pub+github@zwrob.com>
2020-09-23 13:01:31 +00:00
Todd Greenwood
b97a1762b3 Version bump dependency 'as-slice' -> 0.1.4 2020-09-23 05:51:43 -07:00
bors[bot]
bd3c938379
Merge #175
175: Preparing v0.5.6 release r=korken89 a=korken89



Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
v0.5.6
2020-09-22 18:51:06 +00:00
Emil Fresk
77f31428b5 Preparing v0.5.6 release 2020-09-18 15:32:26 +02:00
bors[bot]
7685445020
Merge #170
170: Buffer methods for Vec and as_mut_vec for String r=japaric a=samlich

This adds `set_len` to `Vec`, identical to the `std` version, with the documentation copied from `std`. This is useful for using it as a buffer by writing to the uninitialized portion and then setting the length to include those bytes.

It also adds `as_mut_vec` to `String` (also from `std`), which enables using `String` as a buffer in the same manner.

Co-authored-by: samlich <1349989+samlich@users.noreply.github.com>
2020-07-31 18:31:44 +00:00
samlich
90d652464a
String: add as_mut_vec 2020-07-29 21:29:05 +00:00
samlich
d9955a2599
Vec: add set_len 2020-07-24 12:25:54 +00:00
bors[bot]
4bb5df514f
Merge #161 #162
161: readme: add instructions for tests r=korken89 a=andresv

It took me some time to figure out which features must be used for tests. So this pull request removes some friction.

162: histbuf: replace slow modulo operations r=korken89 a=andresv

STM32G081 Cortex-M0 64MHz
thumbv6m-none-eabi
Rust 1.43.1

RTFM application where data from ADC channels is added to `HistoryBuffers`:
```Rust
// this is shared with DMA
static mut ADC_DATA: [u16; 6] = [0; 6];
...
// this interrupt fires when DMA has finished sequencing all ADC channels
#[task(binds = DMA_CHANNEL1, resources = [pa9, adc_data, hist0, hist1, hist2, hist3, hist4, hist5])]
fn adc_data_ready(ctx: adc_data_ready::Context) {
    let dma = unsafe { &(*stm32::DMA::ptr()) };
    // transfer complete flag clear
    dma.ifcr.write(|w| w.ctcif1().set_bit());

    ctx.resources.pa9.set_high().unwrap();
    
    ctx.resources.hist0.write(ctx.resources.adc_data[0]);
    ctx.resources.hist1.write(ctx.resources.adc_data[1]);
    ctx.resources.hist2.write(ctx.resources.adc_data[2]);
    ctx.resources.hist3.write(ctx.resources.adc_data[3]);
    ctx.resources.hist4.write(ctx.resources.adc_data[4]);
    ctx.resources.hist5.write(ctx.resources.adc_data[5]);
    
    ctx.resources.pa9.set_low().unwrap();
}
```

Time is measured from `PA9` pin using logic analyzer.
```
[profile.release]
opt-level = "s"
codegen-units = 1
debug = true
lto = true
```

- before `27.6 us`
- with fix `4.4 us`


```
[profile.release]
opt-level = 2
codegen-units = 1
debug = true
lto = true
```

- before `25.9 us`
- with fix `2.9 us`

Co-authored-by: Andres Vahter <andres.vahter@gmail.com>
2020-05-12 14:02:34 +00:00
Andres Vahter
c6e4f59640 histbuf: fix style 2020-05-09 21:32:55 +03:00
Andres Vahter
f5a26c04c4 histbuf: replace slow modulo operatins
on cortex m0  `%` is extremely costly
2020-05-09 20:05:19 +03:00
Andres Vahter
cfe596bd3e readme: add instructions for tests 2020-05-09 19:46:06 +03:00
bors[bot]
ab9f2515a7
Merge #154
154: indexmap: expose PowerOfTwo, Bucket and Pos r=japaric a=willem66745

This change allows the create custom structs based on `IndexMap` with size arguments outside
the heapless crate itself.

For example:
```rust
use heapless::consts::*;
use heapless::{ArrayLength, Bucket, FnvIndexMap, Pos, PowerOfTwo};

struct CustomMap<S>
where
    S: ArrayLength<Bucket<u8, u16>> + ArrayLength<Option<Pos>> + PowerOfTwo,
{
    map: FnvIndexMap<u8, u16, S>,
}

impl<S> CustomMap<S>
where
    S: ArrayLength<Bucket<u8, u16>> + ArrayLength<Option<Pos>> + PowerOfTwo,
{
    fn new() -> CustomMap<S> {
        CustomMap {
            map: FnvIndexMap::<_, _, S>::new(),
        }
    }
}

fn main() {
    let mut bla = CustomMap::<U8>::new();

    bla.map.insert(8, 16).unwrap();
}
```

I can imagine that exposing these types is not preferable, but at least it would help for my usecase. Or is there a way where exposing these types is not needed?

Co-authored-by: Willem <willem66745@gmail.com>
2020-05-04 20:34:00 +00:00
bors[bot]
b265330c67
Merge #149
149: Make Producer<..., SingleCore> Send, like Consumer r=japaric a=BryanKadzban

I assume there's no reason that only multi-core Producers are marked
Send, while Consumers are not (they're pretty symmetrical).

(Context: I'm trying to use an SPSC queue on a single cortex-m0 MCU.
So I can guarantee that a SingleCore queue is safe because there is no
other core it could possibly be shared with.  The RTFM framework adds
an assert_send on the producer, since it's shared between init and an
SPI receiver interrupt.  It also adds an assert_send on the Consumer,
since it's shared between init and the I2C transmit interrupt, but that one
works since Consumer has this extra C type in the impl already.)

Co-authored-by: Bryan Kadzban <github@kadzban.net>
2020-05-04 20:20:59 +00:00
bors[bot]
82064d0e6e
Merge #157
157: Preparing for v0.5.5 r=korken89 a=korken89

Prepared v0.5.5 to release the latest accepted PRs

Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
v0.5.5
2020-05-04 18:59:58 +00:00
Emil Fresk
357360e1e8 Preparing for v0.5.5 2020-05-04 20:59:35 +02:00
bors[bot]
417e26617e
Merge #153
153: x86_64: "practically" thread-safe  Pool r=korken89 a=japaric

### Summary / motivation

this PR makes `Pool` `Sync` on x86_64 with the main goal of being able to test `no_std` code that uses `Pool` (e.g. via the singleton `pool!` macro) on x86_64 (as it's not straight forward to run tests on embedded devices, and even less to CI those tests).

### Details

this PR reduces the chance of Pool running into the ABA problem (which corrupts the underlying lock-free stack) by using 32-bit version tags (search term: IBM ABA-prevention tags). Version tags do not 100% prevent the ABA problem but make it almost impossible to run into it in practice (the bigger the tag, in bits, the less the chance of running into ABA). See module level docs for details and limitations.

As this does not eliminate ABA with 100% certainty perhaps it should live behind a Cargo feature?

It seems to me that hazard pointers may be able to completely get rid of ABA but implementing those, AFAICT, require Thread Local Storage (`#[thread_local]`) which is not supported in `no_std` code.

r? @korken89 

Co-authored-by: Jorge Aparicio <jorge@japaric.io>
2020-05-04 18:51:01 +00:00
Jorge Aparicio
ebedb559c0 1.36.0 compatibility 2020-05-04 20:45:52 +02:00
bors[bot]
a28dac7087
Merge #143
143: Implement core::fmt::Write for heapless::Vec<u8, N> r=korken89 a=ijl

I didn't see a mention of this in issues or previous pull requests, but I expect it's in scope?

Co-authored-by: ijl <ijl@mailbox.org>
Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
2020-05-04 09:19:32 +00:00
Emil Fresk
373abf1d96
Fixing test 2020-05-04 11:18:50 +02:00
Emil Fresk
99ea5f123e
Merge branch 'master' into write 2020-05-04 11:10:52 +02:00
Jorge Aparicio
ea0c189a62 x86: put Sync impl behind a Cargo feature 2020-05-03 17:18:22 +02:00
Jorge Aparicio
af877b4418 fix warnings 2020-05-03 17:18:11 +02:00
Jorge Aparicio
e4c8f1f75b x86_64: "practically" thread-safe Pool 2020-05-03 17:18:11 +02:00
bors[bot]
da154963e2
Merge #155
155: Extend ARMv7-R `Pool` support to the bare-metal `armebv7r-` targets r=japaric a=rjsberry

Extends support for singleton `Pool`s to include the `armebv7r-none-eabi` and `armebv7r-none-eabihf` targets.

Co-authored-by: Richard Berry <rjsberry@pm.me>
2020-05-03 14:11:53 +00:00
bors[bot]
b470e26fd0
Merge #156
156: Add optional ufmt impls r=japaric a=dbrgn

By enabling the `ufmt-impl` feature, `uWrite` impls are provided for `String<N>` and `Vec<u8, N>`.

Co-authored-by: Danilo Bargen <mail@dbrgn.ch>
2020-05-03 14:07:10 +00:00
Danilo Bargen
92d1a399e8 Add optional ufmt impls 2020-05-03 13:29:59 +02:00
bors[bot]
75bcd7e496
Merge #152
152: Implement Vec::starts_with and Vec::ends_with r=korken89 a=dbrgn

Implementation mostly copied from `std`.

The logic should be covered by documentation tests, so no separate unit tests were added.

Co-authored-by: Danilo Bargen <mail@dbrgn.ch>
2020-05-03 06:56:57 +00:00
Richard Berry
8bcf9d8970 Extend ARMv7-R Pool support to the bare-metal armebv7r- targets 2020-04-30 20:13:18 +01:00
Danilo Bargen
5e32bf7244 Implement Vec::starts_with and Vec::ends_with 2020-04-30 13:58:00 +02:00
bors[bot]
253cd89228
Merge #151
151: Implement Vec::from_slice r=korken89 a=dbrgn

Fixes #150.

Co-authored-by: Danilo Bargen <mail@dbrgn.ch>
2020-04-30 10:54:24 +00:00
Danilo Bargen
779564cb9f Implement Vec::from_slice 2020-04-30 11:07:55 +02:00
bors[bot]
4d613da755
Merge #136
136: add the HistoryBuffer type r=korken89 a=birkenfeld

Closes #112

Unfortunately `const` construction won't work since the `Default` or `Clone` bound on `T` can't be used then, so I've not added an internal type to `i.rs`.

Let me know if you think any other traits should be implemented...

Co-authored-by: Georg Brandl <georg@python.org>
2020-04-30 09:01:34 +00:00
Willem
7a369f3e5c indexmap: expose PowerOfTwo, Bucket and Pos
This change allows the create custom structs with size arguments outside
the heapless crate itself.
2020-04-22 10:01:05 +02:00
Bryan Kadzban
de0ef160ea Make Producer<..., SingleCore> Send, like Consumer
I assume there's no reason that only multi-core Producers are marked
Send, while Consumers are not (they're pretty symmetrical).
2020-04-11 21:23:57 -07:00
Emil Fresk
3d20301aec
Merge pull request #148 from japaric/v0.5.4_release
Preparing for v0.5.4
v0.5.4
2020-04-06 22:24:07 +02:00
Emil Fresk
f7f0dcdb44 Preparing for v0.5.4 2020-04-06 20:57:27 +02:00
bors[bot]
4e960b30bc
Merge #147
147: Implement StableDeref for singleton::Box r=korken89 a=thalesfragoso

There was a discussion in the riot channel about what it's needed for a buffer to be DMA safe, where ra_kete came up with this POC:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=339a9a29fb59c080b42b6d77a902acb6

Where it seems that the requirements described in the [Embedonomicon](https://docs.rust-embedded.org/embedonomicon/dma.html#static-bound) doesn't seem to be enough to prevent stack corruption.

If that is really the case and we decide to use `StableDeref` instead, then a implementation for Box is very important to be able to easily use it on DMA APIs and a new point release would be necessary.

CC @korken89 

Co-authored-by: thalesfragoso <thales.fragosoz@gmail.com>
2020-04-06 18:47:40 +00:00
thalesfragoso
bb712eb2b0 Implement StableDeref for singleton::Box 2020-04-06 15:24:37 -03:00
bors[bot]
e3f02b06b2
Merge #145
145: Made Box StableDeref r=japaric a=korken89



Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
2020-03-25 06:00:21 +00:00
Emil Fresk
b45ea9bd18 Made box StableDeref 2020-03-24 13:05:51 +01:00
ijl
64e891330c Implement core::fmt::Write for heapless::Vec<u8, N> 2020-02-11 13:51:25 +00:00
bors[bot]
1d6c207917
Merge #142
142: Extend the ARMv7-A `Pool` support to the bare-metal `armv7a-` targets. r=japaric a=japaric

The built-in rustc targets ended with names that start with `armv7a-` so #140
does not cover them though the intention was to support them; this commit fixes
that

Co-authored-by: Jorge Aparicio <jorge.aparicio@ferrous-systems.com>
v0.5.3
2020-01-27 11:11:01 +00:00
Jorge Aparicio
7de6f7907d Extend the ARMv7-A Pool support to the bare-metal armv7a- targets.
The built-in rustc targets ended with names that start with `armv7a-` so #140
does not cover them though the intention was to support them; this commit fixes
that
2020-01-27 12:08:15 +01:00
Jorge Aparicio
f32038d3bb v0.5.2 v0.5.2 2020-01-15 11:57:49 +01:00
bors[bot]
b6bd3af38d
Merge #140
140: extend singleton pool! support to ARMv7-A r=japaric a=japaric



Co-authored-by: Jorge Aparicio <jorge.aparicio@ferrous-systems.com>
2020-01-15 10:49:57 +00:00
Jorge Aparicio
646c56545d extend singleton pool! support to ARMv7-A 2020-01-15 11:47:55 +01:00