Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken match statement when compiling for thumbv6-none-eabi (ARM cortex-m0) #42248

Closed
alevy opened this Issue May 26, 2017 · 16 comments

Comments

Projects
None yet
7 participants
@alevy
Copy link
Contributor

alevy commented May 26, 2017

After upgrading Tock to use a recent nightly, compilation for the NRF51-DK (a Cortex-M0 based board) results in unexpected assembly for a particular match statement.

The match statement looks like this:

impl kernel::Platform for Platform {
    fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
        where F: FnOnce(Option<&kernel::Driver>) -> R
    {
        match driver_num {
            0 => f(Some(self.console)),
            1 => f(Some(self.gpio)),
            3 => f(Some(self.timer)),
            8 => f(Some(self.led)),
            9 => f(Some(self.button)),
            14 => f(Some(self.rng)),
            17 => f(Some(self.aes)),
            36 => f(Some(self.temp)),
            _ => f(None),
        }
    }
}

The LLVM IR that (seems to) corresponds is:

bb49.i.i.i.i:                                     ; preds = %_ZN6kernel7process7Process18incr_syscall_count17h073864aec83cd68fE.exit
  %1192 = load volatile i32, i32* %1028, align 4
  switch i32 %1192, label %bb12.i.i.i1127 [
    i32 0, label %bb1.i.i.i.i.i
    i32 1, label %bb2.i.i.i.i.i
    i32 3, label %bb3.i.i.i.i.i
    i32 8, label %bb4.i57.i.i.i.i
    i32 9, label %bb5.i58.i.i.i.i
    i32 14, label %bb6.i.i.i.i.i
    i32 17, label %bb7.i.i.i.i.i
    i32 36, label %bb8.i.i.i.i.i
  ]

which is a fairly straight forward translation.

In general, the template for the expected output in assembly is something like:

;given r1 is `driver_num`, the variable we're matching against
lsls    r1, r1, #1
add     r1, pc
ldrh    r1, [r1, #4] ; load a half-word from the switch's offset table
lsls    r1, r1, #1 ; this half-word is actually 2x what it should be (idk why, just cause)
add     pc, r1 ; use the result as an offset from the current PC and jump there
                     ; (because we're executing a closure

The match statement seems to end up being broken up (makes sense since the matched values are sparse), with one of the cases (which is called at least when driver_num is 3) looking like this:

add     r1, pc, #16
lsls    r1, r1, #1
ldrh    r1, [r1, r1]
lsls    r1, r1, #1
add     pc, r1

This basically doesn't make any sense... it's grabbing a text segment address, multiplying it by two then loading a half-word from an address that's again multiplied by two (and at this point, completely outside the text segment so it could be anything really). In practice, that returns 0xffff, which after shifting left by one results in 0x1fffe. Finally, adding that to the current PC is way way way outside of the text segment and results in a hardware fault.

Notes

We can "fix" this in a variety of ways:

  • Commenting out the 17 valued branch (commenting out no other branch seems to do the trick)

  • Making the function inline(never)

  • Using opt-level 0 or 1

  • Compiling for better supported architectures by LLVM (e.g. thumbv7m-none-eabi) although those don't run on the same hardware so I can only confirm

Meta

This is using rustc 1.19.0-nightly (5b13bff52 2017-05-23)

Reproducing

Checkout commit d5565a227f8aa40e8c94efa9877a425003d02752 from helena-project/tock and:

$ make TOCK_BOARD=nrf51dk

the resulting binary will be boards/nrf51dk/target/thumbv6-none-eabi/release/nrf51dk, which you can read with objdump:

$ arm-none-eabi-objdump -d boards/nrf51dk/target/thumbv7-none-eabi/release/nrf51dk
@alevy

This comment has been minimized.

Copy link
Contributor Author

alevy commented May 26, 2017

/cc @rkruppe and @nagisa who helped debug this a bit on #rust-internals

alevy added a commit to alevy/tock that referenced this issue May 26, 2017

Downgrade Rust nightly to 2017-04-12
Due to oddly LLVM generated code for thumbv6 the nrf51dk does not work
as compiled with later versions of Rust nightly for now. This is
currently tracked upstream at rust-lang/rust#42248
But for now, this is the latest version I could find for which NRF51dk
apps seem to work (tested with blink, buttons, tests/aes and tests/rng)
@alevy

This comment has been minimized.

Copy link
Contributor Author

alevy commented May 26, 2017

The last nightly where this works as expected is rustc 1.17.0 (56124baa9 2017-04-24), which I believe is the last one before the upgrade to LLVM 4.0, which is at least some evidence that this is an LLVM bug.

@alevy

This comment has been minimized.

Copy link
Contributor Author

alevy commented May 26, 2017

I also compiled to thumb assembly the same LLVM-IR with llc from

  1. an older version of LLVM 3.9 and
  2. a newer version of LLVM from git.

LLVM 3.9 seems to use an entirely different mechanism for compiling switch statements to thumb assembly and recent git-LLVM seems to use the same strategy but doesn't result in the same strange compilation bug as described above.

I'm still figuring out if it's possible to link the result and run it on my hardware, but if I can confirm that (2) works as expected, it seems there may be an existing fix somewhere in the LLVM source tree between the 4.0 that Rust uses and bleeding edge.

@ppannuto

This comment has been minimized.

Copy link

ppannuto commented May 26, 2017

As Tock is moving around this problem with the inline(never) fix, could you add a link to a commit hash that exhibits this issue?

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented May 29, 2017

@ppannuto

LLVM bugs that cause scary miscompilations are not that rare, especially on non-x86 architectures. Normally, we work with the LLVM devs to get them fixed and backport the fixes to our LLVM version.

Can you upload LLVM IR that exhibits the problem?

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented May 29, 2017

This change looks relevant:
llvm-mirror/llvm@a90b36e

It's not on our LLVM. If I had LLVM IR exhibiting the bug I could check whether it fixes the problem.

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented May 29, 2017

Can confirm issue. Let me see whether the LLVM changes fix it.

@alevy

This comment has been minimized.

Copy link
Contributor Author

alevy commented May 29, 2017

@arielb1 you are my hero and savior!

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented May 29, 2017

The bug is actually fixed by llvm-mirror/llvm@f4523b0 rather than the other commit. Now we only have to see what scary codegen bugs the other commits to that file fix.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jun 8, 2017

triage: P-high

@rust-highfive rust-highfive added P-high and removed I-nominated labels Jun 8, 2017

@sanxiyn sanxiyn added the O-ARM label Jun 10, 2017

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jun 15, 2017

Will this be fixed by the llvm upgrade #42410?

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jun 15, 2017

@arielb1 says the upgrade does not include the fix.

arielb1 added a commit to arielb1/rust that referenced this issue Jun 18, 2017

Backport fixes to LLVM 4.0 ARM codegen bugs
So ARM had quite a few codegen bugs on LLVM 4.0 which are fixed on LLVM
trunk. This backports 5 of them:
r297871 - ARM: avoid clobbering register in v6 jump-table expansion.
    - fixes rust-lang#42248
r294949 - [Thumb-1] TBB generation: spot redefinitions of index
r295816 - [ARM] Fix constant islands pass.
r300870 - [Thumb-1] Fix corner cases for compressed jump tables
r302650 - [IfConversion] Add missing check in
IfConversion/canFallThroughTo
    - unblocks rust-lang#39409

arielb1 added a commit to arielb1/rust that referenced this issue Jun 18, 2017

Backport fixes to LLVM 4.0 ARM codegen bugs
So ARM had quite a few codegen bugs on LLVM 4.0 which are fixed on LLVM
trunk. This backports 5 of them:
r297871 - ARM: avoid clobbering register in v6 jump-table expansion.
    - fixes rust-lang#42248
r294949 - [Thumb-1] TBB generation: spot redefinitions of index
r295816 - [ARM] Fix constant islands pass.
r300870 - [Thumb-1] Fix corner cases for compressed jump tables
r302650 - [IfConversion] Add missing check in
IfConversion/canFallThroughTo
    - unblocks rust-lang#39409

arielb1 added a commit to arielb1/rust that referenced this issue Jun 18, 2017

Backport fixes to LLVM 4.0 ARM codegen bugs
So ARM had quite a few codegen bugs on LLVM 4.0 which are fixed on LLVM
trunk. This backports 5 of them:
r297871 - ARM: avoid clobbering register in v6 jump-table expansion.
    - fixes rust-lang#42248
r294949 - [Thumb-1] TBB generation: spot redefinitions of index
r295816 - [ARM] Fix constant islands pass.
r300870 - [Thumb-1] Fix corner cases for compressed jump tables
r302650 - [IfConversion] Add missing check in
IfConversion/canFallThroughTo
    - unblocks rust-lang#39409

bors added a commit that referenced this issue Jun 19, 2017

Auto merge of #42740 - arielb1:bad-arm-2, r=alexcrichton
Backport fixes to LLVM 4.0 ARM codegen bugs

So ARM had quite a few codegen bugs on LLVM 4.0 which are fixed on LLVM
trunk. This backports 5 of them:
r297871 - ARM: avoid clobbering register in v6 jump-table expansion.
    - fixes #42248
r294949 - [Thumb-1] TBB generation: spot redefinitions of index
r295816 - [ARM] Fix constant islands pass.
r300870 - [Thumb-1] Fix corner cases for compressed jump tables
r302650 - [IfConversion] Add missing check in
IfConversion/canFallThroughTo
    - unblocks #39409

r? @alexcrichton
beta-nominating because this fixes regressions introduced by LLVM 4.0.

@bors bors closed this in #42740 Jun 19, 2017

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jun 19, 2017

Can you confirm the generated code works @alevy ? I can't read ARM that well.

@arielb1 arielb1 reopened this Jun 19, 2017

@alevy

This comment has been minimized.

Copy link
Contributor Author

alevy commented Jun 19, 2017

Appears to as far as I can test. I've not been able to reliably get a minimal, repeatable example of the bug, but on code that breaks with previous nightly doesn't break with this one, so seems fixed to me!

alevy added a commit to alevy/tock that referenced this issue Jun 19, 2017

Upgrade Rust nightly
Rust nightly 06-19-17 included LLVM upstream fixes that address an issue
we were running into on Cortex-M0 targets.

rust-lang/rust#42248

@arielb1 arielb1 closed this Jun 19, 2017

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jun 19, 2017

Yay!

alevy added a commit to alevy/tock that referenced this issue Jun 19, 2017

Upgrade Rust nightly
Rust nightly 06-19-17 included LLVM upstream fixes that address an issue
we were running into on Cortex-M0 targets.

rust-lang/rust#42248

alevy added a commit to tock/tock that referenced this issue Jun 21, 2017

Revert removing no-inline from NRF51DK with_driver
Turns out this Rust upstream issue is not resolved (actually an LLVM
issue, but we thought it was just about upgrading the version of LLVM
Rust uses):

rust-lang/rust#42248

It seems as though the assembly _is_ different, but still incorrect
(generating `add pc, r1` instead of `mov r0, r1; br pc` which is why I
wasn't catching it...)
@alevy

This comment has been minimized.

Copy link
Contributor Author

alevy commented Jun 21, 2017

@arielb1 I take it back, I didn't test properly. It looks like the generated code is still incorrect. FWIW, this seems like a difficult thing to fix on the Rust side other than just regularly upgrading LLVM versions, unless we (I?) can identify more clearly why this is happening in the LLVM codegen and where it's been fixed. Sorry @arielb1, I misled you... :/

No no no! False alarm! I hadn't upgraded to the right Rust version when I pushed my changes to Tock upstream! It works! Sorry again!

brson added a commit to brson/rust that referenced this issue Jun 22, 2017

Backport fixes to LLVM 4.0 ARM codegen bugs
So ARM had quite a few codegen bugs on LLVM 4.0 which are fixed on LLVM
trunk. This backports 5 of them:
r297871 - ARM: avoid clobbering register in v6 jump-table expansion.
    - fixes rust-lang#42248
r294949 - [Thumb-1] TBB generation: spot redefinitions of index
r295816 - [ARM] Fix constant islands pass.
r300870 - [Thumb-1] Fix corner cases for compressed jump tables
r302650 - [IfConversion] Add missing check in
IfConversion/canFallThroughTo
    - unblocks rust-lang#39409

bradjc added a commit to tock/tock that referenced this issue Dec 4, 2017

Rust Format
Clean up of unimplemented areas
Slave write/ master read is not implemeneted
Added unimplemeneted and _ variables that are unused
Learned how to use enums with structs

Update SignbusLayers.md
Update SignbusLayers.md

Header size changes
Update SignbusLayers.md

Formatting issues
Create SignbusLayers.md

Describe the layers in signbus and their specific interface.
Getting ready for PR
Cleaned up warnings (unused imports/ vars)
Added unimplemented
Wrote parts of functions for Master read

Rustformat, fix long lines

Rust Format

changed some of the TODOs etc

Rust Format

message received from controller correct!

Merge branch 'signbus' of https://github.com/helena-project/tock into signbus

Rust Format

move InitMessageType to support.rs
api_type and message_type check for received message

controller response check for declaration
need to clean up some of the enums for api_type, mesage_type, and frame_type

Rust Format

added error messages
need to parse message for message type and api type

Rust Format

getting rid of debug statements
how do I use ReturnCode::SuccessWithValue?

make support in mod.rs private
take away unneeded headers in main.rs

Merge branch 'master' of https://github.com/helena-project/tock into signbus

Merge pull request #550 from helena-project/ltc-configure-fix

Add command to configure model in userland driver
Merge branch 'master' of https://github.com/helena-project/tock into signbus

Rust Format

Add command to configure model in userland driver

Signbus Initialization tested and working.

Problems with HMAC and concatenation in port_layer

cleaning up more and added usage at the top of files

removed unnecessary files in signbus folder

cleaned up layers and commented some
need to test isolation and module declaration for signbus init

Merge pull request #548 from niklasad1/nRF52/remove_used_init

nRF52 remove unused chip initialization
Merge pull request #545 from alevy/tbfimprovements

Remove `data_start_pointer` from load_info
remove unused chip initilization

Assign registers more precisely in switch_to_user

Remove data_start_pointer from load_info

data_start_pointer was only being used to set the value of r9 in
`switch_to_user`. However, first, that's dependant on the processes
(i.e. a processes that uses a different PIC strategy will point r9
somewhere else). Second, it was buggy for non-PIC processes (setting r9
to 0 in practice). Finally, we already have this value anyway from the
initial stack poitner in the default PIC strategy.

So, this removes that field, removes setting the r9 value in the kernel,
deferring it to the processes, and uses the initial stack pointer as the
reference for where the GOT starts.

Merge pull request #508 from niklasad1/nRF52/BLE

nRF52DK/BLE
Merge pull request #547 from helena-project/tlv-aligned

TBF header: pad all TLV blocks to 4
TBF header: pad all TLV blocks to 4

To help with avoiding unaligned accesses, all TLV blocks are now aligned
to 4 bytes. The length field still specifies the length of the Value
section, but if that length is not a multiple of 4, there is padding so
that the next header starts on a multiple of 4.

ble works woho

Merge pull request #541 from helena-project/kernel-lst

provide a target to build lst for kernel
Merge pull request #542 from cbiffle/owned_container

container: stop using Owned with enter, each
Merge pull request #543 from alevy/tbfimprovements

Make pic information optional in `elf2tbf` through an argument
elf2tbf: make pic information optional through arg

And add it by default to the C apps in `userland/`

container: stop using Owned with enter, each

This introduces another smart-pointer type, Borrowed, for the case where the
memory is not actually owned but borrowed. I would have preferred to just use
`&mut T`, but capsules are relying on the value including an `app_id`, so this
seemed like the smallest delta.

Fixes #538.

Merge pull request #540 from helena-project/docs-nrf-circles

Remove circular references from NRF documentation
Update README.md
provide a target to build lst for kernel

There's an asymmetry right now between userland and kernel, where
in the kernel `make debug` does a different build and in userland
it makes the lst file. We should rectify that interface at some
point, but in the immediate term, it's useful to have any way to
generate an lst file for the kernel

Merge pull request #416 from daniel-scs/usb

Add driver for SAM4L's USBC and generic USB lib
capsules::usb_user: instantiation documentation

doc: nrf51 - fix gdb elf path
Remove circular references from NRF documentation

The NRF docs pointed you to getting started and getting started pointed you to "board-specific" instructions in these docs.

@niklasad1 could you double-check that I haven't said anything wrong / oversimplified here
usb-related code: prettify

chips/sam4l/Cargo.lock: reverse inadvertent changes

working on test_signbus_init
able to request isolation from hail to controller
now need to send i2c messages to declare module
need to start cleaning up code

nit: add missing period from #531
Merge pull request #531 from helena-project/update-doc

doc: improve main tock docs
Merge pull request #535 from cbiffle/alloc

process: fix containers that impl Drop.
Merge pull request #539 from daniel-scs/drag-imixv1

imixv1: merge back some of the changes to imix
usb syscalls: allocate a free driver number

imixv1: merge back some of the changes to imix

  - use PllExternalOscillatorAt48MHz
  - use kernel::process::load_processes()
  - eliminate size args from static_init! calls

This is useful just because I still develop on imixv1 and don't want to
diverge more than necessary from the new board.

usbc: use scif::ClockSource::CLK_HSB for usb clock

The controller code first checks pm::get_system_frequency() in an
attempt to ensure the system clock is going to work for the USBC.

This approach (but not CLK_CPU for some reason) works with the system
clock set to PllExternalOscillatorAt48MHz, as well as with the old
setting of DfllRc32kAt48MHz.

usbc: use #[repr(align(N))] for endpoint descriptors

This feature is experimental and required features `repr_align` and
`attr_literals` to be added to crate chips/sam4l.

Without this, it appears we have to just cross our fingers and disable
the USBC if unlucky.

capsules::usb: add bounds checks and some docs

tools: add usb/control-test

This rust program uses libusb on a USB host to perform a simple read and
write to a connected device.

As described in the program's documentation, it requires that the device
running Tock has loaded the app examples/tests/usb, which enables the
USB controller on the device and causes it to respond to control
requests.

process: fix containers that impl Drop.

The code was assigning Default::default() into allocated memory, which
implies dropping the value that previously lived there. But the "value"
at this point is uninitialized kernel segment memory, and so dropping it
is not intrinsically safe. (Though it works for most types.)

This change switches to writing the container using core::ptr::write,
which is defined as moving its argument *without* dropping the contents
of the target.

using htons to formart u16 in header
new capsule test_signbus_init to test initialization

Merge branch 'master' of https://github.com/helena-project/tock into signbus

-stitching things together to test module initialization

grammar nit
testing recv..

Merge pull request #534 from niklasad1/nRF51/doc

nRF51/docs_remove_mbed_file_system
removed docs about mbed-file-system and fixed a typo

-io_layer_recv finished, need to test
-bring all functions to app layer
-finish rest of callbacks

usb: improve quality, begin userspace interface

- register handling:
  - macros now use StaticRef<VolatileCell<u32>>,
    and we add kernel::common::static_ref (thanks, Amit!)
  - use absolute paths for supporting symbols
  - move potentially-common stuff into usbc::common for now;
    if another user appears we can promote it
- use VolatileCell explicitly, and from kernel::common (thanks, Brad!)
- file structure:
  - capsules::usb is a protocol library
  - capsules::usb_user provides a (currently trivial) syscall interface
  - capsules::usbc_client implements hil::usb::Client and
    talks to the hardware; usb_user interacts only with usbc_client
- debugging bits: usbc_client promiscuously accepts and logs
  control-writes in vendor requests, and similarly responds with a few
  bytes to control-reads
- the usb controller may be enabled from userspace but is disabled on
  boot, so this code should not effect folks not using it
- usb is now on both imixv1 and imix,
  although the latter platform has not been tested

Merge branch 'master' of github.com:helena-project/tock into usb

New architecture figure

Closes #532

userland: set stack_size so ble app doesn't crash

kernel: process: debug: fix stack size bug

Nits in Getting Started
doc: improve main tock docs

Add `map_or*()` functions.

Mention Xargo.

Generally make docs more consistent and update to latest code.

Fixes #405.

Fixes #403.

Fixes #404.

userland: remove READELF redefine

We can simply use the already defined READELF from the arm toolcahin install

Merge pull request #527 from helena-project/mo-money-mo-money-mo-money-mo-money

Automatic relocation-aware listing generation
Automatic relocation-aware listing generation

This is the complementary half of 2db20bb3b, providing the `make`
rules to actually generate the requested listings.

Verified by checking that `crash_dummy`'s PC is a null pointer ldr

Merge pull request #525 from helena-project/memop-doc

kernel: memop: comments for `make doc`
Merge pull request #457 from helena-project/app-freedom

app flash: allow apps to write their own flash
kernel: memop: comments for `make doc`

Note that APP_STATE_DECLARE can only be used once

userland: add app_state

This userland library uses the app_flash capsule to allow apps to store
configuration state to persistent flash memory within their flash space.

elf2tbf: update to add app_state region to binary

capsules: add app_flash capsule

This capsule enables apps to be able to write their own flash. The
capsule prevents access to the TBF header, however.

kernel: provide functions for app flash range

Adds support to the `AppId` object to get the range of flash that apps
own.

Merge pull request #396 from helena-project/tbf-version2

TBF Header Version 2
imixv1: remove unused `use`s

Upgrade tockloader version to 0.7.1

userland: add app to test getting flash regions

kernel: add memop calls

This adds calls for processes to get information about their writeable
flash regions as well as update the kernel if they move the stack
pointer or app heap pointer.

elf2tbf: Update to TBF header v2

The elf2tbf script generates the header for an app and generates the
binary with the v2 header.

kernel: Update to TBF Header v2

Tock Binary Format header version 2 adds a `flags` field that can be
used to mark properties of a flashed application.

The two supported flags are:

1. Enable/disable. Tells the kernel to run or not run an application at
boot.
2. Sticky. Tells tockloader to not erase the app without --force.

It also allows apps to tell the kernel to not do PIC fixups on its
behalf.

Apps can also now specify flash regions that the app intends to write.

Fixes #379

boards: remove old `use` statements

Merge pull request #511 from helena-project/process-load-thyself

Create a generic and default load_processes() function
Merge pull request #522 from helena-project/doc-target-make

make: generate target file if not exist
Merge pull request #520 from helena-project/mpu-disable

kernel: enable and disable MPU for process
make: generate target file if not exist

For some reason building docs won't generate a target folder if one
doesn't already exist.

nrf5X: update to shared load_processes function

imix: update to shared load_process() function

hail: update to generic load_process function

kernel: allow skips in loading processes

Updates the generic `load_processes()` function to allow the `create()`
function to return no new app, but to indicate that the load function
should skip ahead in flash to keep looking. This is useful if a process
is disabled or there is just padding between processes.

kernel: add default load_process() function

Historically the `load_process()` function has been in the board's
main.rs file. This has lead to some duplicated code. This commit adds a
generic version to process.rs that platforms can use if they wish.

Merge pull request #523 from helena-project/gimme-docs-or-gimme-confusion

tools: script to build all rustdocs in one folder
tools: script to build all rustdocs in one folder

Merge pull request #521 from helena-project/kernel-doc

Kernel: spelling and comments
kernel: add syscall number comments

kernel: enable and disable MPU for process

This will disable the MPU entirely when the kernel runs.

This also means that `enable_mpu()` does not need to be called in
board/main.rs.

Merge pull request #519 from helena-project/hail-panic-leds

hail: turn off other leds during panic
Modify `read_write_bytes` DMA ordering

After fixing all the clock issues, I found that the signpost
`signpost_controller_app` still wasn't working and eventually traced the
problem down to not receiving a DMA read callback in the SPI over USART
implementation. Debugging with GPIO pins showed that the RX DMA transfer
was not started until after several bytes had already been written over
the wire, which seems bad. Combining the maps together and then starting
the RX transfer first solved the issue.

It is entirely unclear to me why this would be an issue now when it has
worked for months...

After further testing though, we have switched back to original SPI DMA ordering

It appears that changing the map stuff was the most important, because
the `signpost_controller_app` still works. Changing the ordering and
starting the read first hear led to an extra byte in the receive buffer
which current drivers and applications did not account for.

More clock enable/disable fixing. Also dma order

For clocks, the order of handling things in the interrupt handler needed
to be modified or else we ended up accessing registers after our clock
was disabled. In attempting to find this bug, many other places where we
could have ended up accessing registers after disabling the clock were
also fixed, so I left those fixes in although they may not all be
strictly necessary in practice.

Remove UART reset during panic!

UART clocks are disabled after `init`, making this unsafe to call here.
Morever, it was always unnecessary since `init` already calls `reset`
internally.

Fix uart clock enable/disabling

hello loop app

SAM4L: manage USART clocks

Only leaves the USART clock enabled when the USART is currently
transmitting or recieving. In order to properly deal with transmission
through the DMA (which may complete while there are still bytes in the
TX buffer), the change adds a check for the TX_EMPTY interrupt.

mpu: spelling

Merge pull request #518 from helena-project/mpu-add-disable

mpu: add disable() function
hail: turn off other leds during panic

This makes the panic! blink more obvious.

-working on receiving messages in io_layer

mpu: add disable() function

Also update comments for the enable() function.

io_layer.rs
-io_layer able to send multiple packets with packet_sent callback!!

support.rs
-Packet struct now contains a sized (I2C_MAX_DATA_LEN) array instead of 'static slice
-Added some error codes received from i2c chip driver

protocol_layer & app_layer
-added traits and clients to io_layer and protocol layer for better interface and connected them

Future
-need to figure out if all port_layer functions should reach up to app_layer
-starting work on slave receiving packets

userland: print more info on complier version error

Merge pull request #516 from helena-project/more-sh-bash-equal

More sh bash equal problems
Merge pull request #514 from helena-project/function-warning

userland: warnings on use of certain functions
userland: format

these slipped through travis with the == vs = problem

make: cannot use '==' for string equality in make

make invokes sh as subshell on linux

Merge pull request #513 from helena-project/slicker-linker

userland: remove unused load_info section from .ld
Merge pull request #515 from helena-project/doc-all-the-things

docs: tell rustdoc to document private fields
-fragmenting is almost working!
-need to change Packet struct to have fixed size

docs: tell rustdoc to document private fields

By default, rustdoc only documents public fields. This is great for
users of crates, and less great for developers of crates. This commit
tells rustdoc to document everything.

userland: format

userland: warnings on use of certain functions

Inspired by a series of signpost bugs, there are some functions that,
while not inherently unsafe, are often dangerous to use and easy to
replace with something safer. The motivating example here being
`snprintf` in favor of `sprintf`. We could add more in the future*,
but for now this is a scaffolding

*Brad was lobbying for strlen, but that's a bit harder, critically
this warning only applies to _emitted_ function calls, so something
like `foo("buf", strlen("buf"))` would not emit a warning, but that's
a bridge for another day)

userland: remove unused load_info section from .ld

userland: remove `putstr` function

This is a legacy method that is supplanted by proper printf/puts

Merge pull request #510 from helena-project/ltc294x-conversion-scaler

Fix LTC294x counter to charge conversion
Merge pull request #509 from helena-project/internal-timer-overflow-bug-fix

Uses Correct Order of Operations to Prevent Internal Timer Overflow
now returning uah instead of mah

removed floating point math

enforces order of operations to prevent overflow

also implicitly casts the division to a float in case
alarm_internal_frequency() returns a non-divisable number.
Cast back to uint32_t before setting the interval

-.gitignore added .swo

-tested gpio set/clear functions in port_layer
-tested gpio enable_interrupt
-starting to implement sending fragmented messages using callbacks in io_layer()

Merge pull request #506 from helena-project/fixclockfortock

Change system clock interface
Change clock setup to include oscillator config

Now the oscillator configuration is included in the enum itself. Also, always
more comments.

More comments about clock settings

-test timer
-most of the gpio functions in port_layer completed
-need to test these functions

Merge pull request #507 from helena-project/cmake

doc: add cmake to getting started
doc: add cmake to getting started
-delay_ms with alarm callback
-need to test

rustformat

Refactored power manager interface

Added a new method of specifying external oscillator and system clock in
order to allow adding slow startup which is necessary for sleep on
signpost.

Tried to make the system clock specification more rigid. It has always
been assumming a 16 MHz external oscillator and allowed you to set a 48
MHz PLL based on it, or use it directly. Now those options are explict.

Also moved functionality into bpm, bscif, scif, and flashcalw as
appropriate while I was in here since a lot of functionality was handled
in PM.

Merge pull request #505 from helena-project/sbrk-return

userland: fix return of _sbrk
-tested packet_serialization
-in the middle of testing i2c_master_write from tock to controller

userland: fix return of _sbrk

_sbrk semantics are to return -1 in case of error or a pointer.

TOCK_ENOMEM is not -1, so newlib treated it as a pointer. A quick readover of
the `malloc_extend_top` implementation in newlib (which is what actually calls
_sbrk [well, _sbrk_r which calls _sbrk]) shows that it checks against -1, then
checks that the new pointer is greater than the old pointer (which a modest
negative number certainly would be), then bumps the internal "top" of allocated
memory to the new pointer and rolls merrily on. This explains the behavior we
were seeing where it seems that allocations never failed, rather the MPU would
eventually trip when we ran off the top of the heap

Merge pull request #502 from helena-project/virtual-flash

Add Virtual Flash
flash: add virtual_flash

Allow multiple users of a single underlying flash interface.

flash: update HIL to split out set_client

-added set_client to port_layer
-working on packet_to_buf in support
-added len arg to i2c_master_write in port_layer

radio.c format

Fix nrf51dk compilation warning

Merge pull request #487 from shaneleonard/imix-submodule-power

Imix submodule power configuration
Merge pull request #501 from ptcrews/mac_header

RF233: correct offsets and lengths so 1 byte of payload isn't dropped
Merge pull request #504 from niklasad1/nRF52/buttons

nRF52/buttons
buttons work and reset button functionlity added

typo fixed

Merge pull request #453 from niklasad1/ble_add_ad_types

BLE advertisement support 31 byte payload and added scanning
Merge pull request #503 from niklasad1/nRF52/typos

nRF52 fixed typos/consistency
fixed typos/consistency

rust fmt

travis fix and scan on channel 37,38 & 39

TOCK_SUCCESS

format

added a very simple trait and modified the userapp a bit

BLE advertisement support 31 byte payload and added scanning

refactor, spelling

format

-simple i2c test with controller and hail working with Branden's port layer interface

Merge branch 'signbus' of https://github.com/helena-project/tock into signbus

-small debug statements
-signbus setup in main.rs for hail

Restructuring and framework for port_layer

power: Address Amit's review comments

- Eliminate unnecessary traits
- Eliminate unnecessary allocations in configure_submodule
- Simplify function parameters (no Option wrapper on list)
- Consistent renaming (module --> submodule, eliminate "Imix")
- Add module-level comment explaining overall purpose

Merge pull request #490 from niklasad1/nRF52832

nRF52-DK
Moved everything to signbus folder in capsules/

Need to redo most of signbus...

Disable i2cslave Perhiperal for Master Transfer (#500)

you can't just disable the clock - it causes the i2c to hang
Fixes length and offset issues with RF233 that cause 1 byte of payload
to be dropped on receive. Also rename some variables to distinguish the
different lengths involved.

Type in Capsules README: Utilty -> Utility

Merge pull request #497 from alevy/bug/virtualtimers

Reimplement virtual timers using a linked list instead of heap
Merge pull request #498 from warner/list-boards-bug

list_boards.sh: hush a bash warning when not using -1
list_boards.sh: hush a bash warning when not using -1

Without this, running "make list-boards" gets me an error like:

 ./tools/list_boards.sh: line 19: [: -eq: unary operator expected

userland format

Fix apps to work with virtual timer interface

Clean up virtual timer interface

Requires users to pass in a a `tock_timer_t` or `alarm_t` instead of the
implementation allocating it. Also unifies the two kinds of timers so
both call `timer_cancel`.

Update libnrfserialization

Make sure to free timer in NRF serialization

Reimplement virtual timers in userland with linked-list

Merge pull request #496 from shaneleonard/bug/495

imix: Correct PC[08] assignment.
imix: Correct PC[08] assignment. Fixes #495

Merge pull request #494 from helena-project/fix-xargo-updates

Have xargo updates use specific version of rustc
Have xargo updates use specific version of rustc

Merge pull request #493 from helena-project/shell-are-the-worst

tools: use = rather than == for string equality in sh
tools: use = rather than == for string equality in sh

Fixes #491.

Merge pull request #492 from helena-project/fix-ltc294x-capsule

Enable I2C in Configure Function
enabled i2c in the configure function

Merge pull request #480 from ptcrews/spi_fixes

Fixes two bugs in the SPI code introduced in 7217345d
Merge pull request #485 from enzuru/ak-xargo-update

Makefile.common updates xargo if it is out-of-date
make: remove unused CHIP variable from V=1

make: only print xargo version on verbose build

buggy mistake

rustfmt

ooops

Update README.md
cleanup and better uart-code

uart works but the payload is limited to 48 bytes atm and no checks for it

uart with faulty register inits

You needed to turn the clocks on

no interrupts :(

interrupt vector numbers seem to consistent with nrf51

─── Threads ──────────────────────────────────────────────────────────────────────────────────────────
[1] id 57005 from 0x00000922 in kernel::container::Container<capsules::timer::TimerData>::enter<capsules::timer::TimerData,closure,(kernel::returncode::ReturnCode, bool)> at /home/niklasad1/Projects/tock/kernel/src/container.rs:183
──────────────────────────────────────────────────────────────────────────────────────────────────────
kernel::container::Container<capsules::timer::TimerData>::enter<capsules::timer::TimerData,closure,(kernel::returncode::ReturnCode, bool)> (self=<optimized out>, appid=..., fun=...) at /home/niklasad1/Projects/tock/kernel/src/container.rs:183
183	                            .map_or(Err(Error::OutOfMemory), move |root_ptr| {

=> Issue with allocating a Container for the Timer..... my guess is
that crt0.s is the issue!!

work

LEDs work, but not timers yet

work

Update gdbinit_pca10028.jlink
progress, debugging symbols for nRF52-DK exist

progress, debugging symbols for nRF52-DK exist

added chips for nRF52

getting started with nRF52

Update README.md

Update chip_layout.ld

getting started with nRF52

added chips for nRF52

getting started with nRF52

Update README.md

Update chip_layout.ld

getting started with nRF52

Merge pull request #489 from helena-project/pm-ps2

sam4l: power scaling before increasing core speed
sam4l: power scaling before increasing core speed

The default RUN0 only supports up to a 36MHz clock, however most
boards request a 48MHz clock source. The bootloader ASF code was
already changing this, but that was really luck that things were
working

power: Rename 'setting' parameter to more accurate 'state'

rustfmt

power: Combine on and off into one 'power' method

-Finished up signbus_app_send() in app_layer
-Need to test this function
-And look into receiving messages and callbacks

rustfmt

Fix incorrect gate pin assignment, enable_output before gate pin set/clear

Initial API for controlling imix submodule power

Merge pull request #481 from helena-project/dont-keep-prompting

style: only check for unstaged changes once
style: really only check for unstaged changes once

Merge pull request #486 from niklasad1/patch-1

nrf51dk/README.md
-Added dead_code, unused_variables, and unused_imports attributes
-Added enums for api_type and frame_type in app_layer

-Small clean ups
-Declared app_layer and protocol_layer objects in main
-Finishing up signbus_send() functions from all layers (app_layer -> protocol_layer -> io_interface -> port)

Update README.md

Minor correction because Xargo enables debugging symbols and a typo fixed.
Makefile.common updates xargo if it is out-of-date

Small error in length calc in header

pull master into signbus

signbus_io_interface.rs
	-Deleted unneccessary traits and consts
	-Cleaned up and commented

signbus_io_interface.rs
	-finished signbus_io_send()
	-finalized I2C network packet structs

Merge pull request #482 from helena-project/ble-serialization-fixes

libnrfserialization: fix packet ordering
Merge pull request #483 from niklasad1/doc_fixes

doc/Getting_Started.md rustc version
update rustc version

libnrfserialization: fix packet ordering

- Remove call to kernel that keeps the serialization state machine
  happy. We can replace it with just a function call to userspace if we
  are smart about when we make the call.

- Add more comments to the capsule.

- Remove some warnings from the libnrfserialization library.

- Add packet queues and enforce ordering of received packets in the
  userspace library. There are two types of RX packets: responses and
  events. All transmitted commands generate a response packet, and the
  serialization library blocks until it gets the response (or an error).
  The first problem this fixes is that if the response packet gets
  concantenated into a single buffer behind an event packet, it would
  never get parsed and the state machine would grind to a halt.

      The second issue is that even if you parse multiple packets in a
      single buffer, enough event packets can delay processing of the
      response packet until after another packet is transmitted.
      However, that packet will block until the response packet to the
      first TX message is received, and it blocks in a while loop, which
      never exits.

      Sometimes packets get corrupted. If this happens to a response
      packet, the state machine keeps waiting for it and everything
      stops.

      To fix these issues, we start by implementing two queues in
      userspace: one for events and one for responses. This allows us to
      unpack buffers of concatenated packets.

      Next we prioritize response packets and wait to process any events
      until we receive the response.

      We also add a timeout in case the response is dropped.

style: only check for unstaged changes once

A bit copy/pasty, but that's fine for a one-off like this IMO

Resolves Problem 1 from #432.

hail: add aes driver

sam4l: add AES driver

userland: aes: small cleanup of test app

hil: symmetric encryption: standardize

Make it more consistent with other HIL interfaces

capsules: symmetric_encryption remove duplication

Fixes two bugs in the SPI code introduced in 7217345d

- real_rate: We corrected the check for whether the division was exact
from `clock % rate` to `clock % real_rate`, but that introduced a new
bug, because then it actually tries to increment it when it is already
at the slowest rate (which ends up setting scbr to the invalid 0). The
solution is to only get a slower baud rate if we are not at the slowest
rate already.
- transfers_in_progress: the hunk that set this to 0 was accidentally
deleted when we squashed/reordered some commits so that our code
introduces SPI slave and then reverts the board initialization code.

Merge pull request #478 from ptcrews/imixv2_build

Correct the binary path in the imix v2.0 Makefile
Correct the binary path in the imix v2.0 Makefile

- Fixes the imixv2 Makefile to point to the right target, otherwise
  it expects the binary to be in `target/sam4l/release` and is not
  able to flash.
- Updates the getting started documentation to reflect the fact that
  flashing imixv2 now requires tockloader.

Added STARTUP time to ADC

Re-added initialization, updated RCSYS expected frequency

Disable ADC before changing clock, make initialization implicit

Merged ADC Continuous interfaces

Merge pull request #477 from alevy/lowpower/button_driver

Only enable interrupts for buttons when necessary
Only enable interrupts for buttons when necessary

Merge pull request #476 from helena-project/more-format-crap

style: treat formatted files as built objects
Merge pull request #475 from helena-project/button-capsule-doc

capsules: button: update comments and doc
style: treat formatted files as built objects

Instead of unconditionally formatting all sources, now create a
%.c[c|pp|xx] -> build/format/%.uncrustify mapping for formatted files.
This allows make to do the right thing on only reformat ("rebuild")
when the source file has actually changed.

Addresses Problem 3 from #432.

Merge branch 'master' into button-capsule-doc
rustfmt

doc: ಠ_ಠ @adkinsjd
Merge pull request #473 from helena-project/yield_for_timeout

Add yield_for_timeout Function
Implementing signbus_io_send in the SignbusIOInterface level
	-need to serialize struct to pass into buffer

Merge pull request #472 from alevy/feature/kernel/lowpower

Adds a `prepare_for_sleep` method to the Chip trait with implementation for SAM4L
fixed name in readme

renamed yield_for_timeout to yield_for_with_timeout

SAM4L: Add comment to the PM's mask_clock macro

SAM4L keep track of GPIO interrupt count for PM

Instead of enabling/disabling the GPIO clock, which would require
enabling it on each operation, we just special case GPIO for power
management and keep track of how many interrupts are enabled through a
shared, atomic variable. This works because we _only_ care about
interrupts for determining whether it's OK to go into various sleep
modes.

Implement `prepare_for_sleep` on the SAM4L

The basic strategy is to look at the power manager's clock mask
register's and compare them against a set of known clock masks that
would let us go into deep sleep without preventing any active
peripherals from working.

fixed style problems

clarified readme

added the alarm cancel if the condition succeeds

test app is working

added yield_for_timeout and a test

Adds a `prepare_for_sleep` method to the Chip HIL

With a default null implementation, and calls it before `WFI` in the
main loop.

Merge pull request #471 from alevy/cortexm4/deepsleep

Adds calls to enable and disable deep sleep on CM4
capsules: button: update comments and doc

Merge pull request #466 from helena-project/ble-uart

userland: add ble-uart app
gpio: configure(None) correct behavior. Fixes #464 (#469)

Adds calls to enable and disable deep sleep on CM4

signbus pull master in

Merge branch 'master' of https://github.com/helena-project/tock into signbus

Added files signbus_app_layer.rs & signbus_protocol_layer.rs
-working on signbus_io_send() in protocol layer
-network structs in protocol layer

Merge pull request #468 from helena-project/strerror

Add human-friendly error code explanations
userland: consistent printf in tmp006 app

userland: add tock_strerror

style: order functions the same in .h and .c

userland: add error checking to tsl2651 test app

userland: update ble-env-sense readme

userland: add ble-uart app

This is an app that demonstrates how to setup a serial over BLE
connection.

Merge pull request #465 from helena-project/nrf-serialization-fix

userland: nrf serialization fix
userland: nrf serialization fix

- Update to newer nrf5x-base which fixes weak reference issues.
- Fix receiving buffer flag to be set before function call. Otherwise
  the state machine grinds to a halt if a callback generates a new
  command.

Merge pull request #461 from helena-project/userland-tock-errors

userland: prepend `TOCK_` to error names
Merge pull request #460 from helena-project/sam4l-helpers-prune

sam4l: remove unused functions in helpers.rs
userland: prepend `TOCK_` to error names

This allows `tock.h` to be compatible with `errno.h`.

Fixes #353

Merge pull request #452 from ptcrews/rf233_fixes

Fix if/if bug and possibly implement packet_get_length/pan in RF233
sam4l: remove unused functions in helpers

Merge pull request #456 from helena-project/handle-pages

capsules: add tool to handle flash pages (needs #430 and #446)
Merge branch 'master' into handle-pages
Merge pull request #446 from helena-project/flash-update

Flash updates, implement Flash trait for SAM4L
Merge pull request #430 from helena-project/nonvolatile

Create a nonvolatile storage interface.
build: allow .cxx extension for c++

Merge pull request #458 from helena-project/check-rustfmt-version

tools: verify rustfmt version before running
tools: verify rustfmt version before running

Fixes #455.

Merge pull request #454 from helena-project/formatall

add `formatall` to root Makefile
build: add root `formatall`

Towards #432

capsules: add tool to handle flash pages

NonvolatileToPages takes a read or write of arbitrary length at an
arbitrary location and maps it to a series of page read and writes so it
works with page based storage.

build: fix missing PHONY's

userspace: add nv storage to libtock

also add a test app

capsules: add nv storage for userspace

Allows the kernel to provide a slice of nonvolatile storage to
userspace.

flash: update HIL, improve SAM4L flash driver

Update the SAM4L flash driver to implement the Flash trait.

Make page size as an associated type of the Flash trait.
This should allow implementers of the trait to require a certain buffer
size for page reads and writes to be enforced at compile time.

Merge pull request #419 from alevy/feature/user/virtalarm

Userland virtual alarm
signbus update from master

Basic interface for port_signpost_tock and signbus_io_interface compiles.
	-implemented signbus_io_init
	-added basic structures
	-empty I2C callbacks to satisfy traits

Added capsules to lib.rs

Edits to boards/hail/src/main.rs
	-static_init objects

Merge pull request #360 from helena-project/pca9544a

Add PCA9544a Capsule
userland: add libtock drivers for pca9544a

capsules: add PCA9544A I2C selector

This chip lets a board multiplex a single I2C address among multiple
chips with that same address.

Pass correct userdata to repeating timer

Fix if/if bug and possibly implement packet_get_length/pan

Merge pull request #450 from helena-project/allow-arch-override

userland: allow runtime override of TOCK_ARCHS
Merge pull request #451 from helena-project/defer-failure

travis: defer userland app failure to get whole list
travis: defer userland app failure to get whole list

Borrowing this from signpost, the idea is to defer the error until all
apps have tried to build, so that you get a complete list of things you
need to fix when Travis fails rather than going in a loop.

userland: allow runtime override of TOCK_ARCHS

This should be a `?=` like everything else, in the interest of allowing
quick command line overrides

Merge pull request #448 from helena-project/crccu-rename

sam4l: rename crccu interrupt
Uncrustify

Port apps to timer/alarm userland lib

Nits in timer capsule

Separate timer and alarm userland interfaces

Address @ppannuto's comments for virtual timers

Address nits in virtual alarm userland

Comment alarm.h

Move multi-timer-blink to multi_timer_test

Fix reference to timer in aes test

Rename alarm_start to alarm_at and move alarm_read

Add event system to libtock for virtual timers

fix bug in timer capsule

Userland alarm: more complex test app

Modify the multi-alarm test app to include delay_ms inside the alarm
callback. This makes sure the main alarm callback is re-entrant and also
seems to trigger a bug where the alarm stalls because a virtual alarm
expires before it is actually set...

Call all expired userland alarms, not just first

If two alarms were expired (e.g. they have the same expiration value),
only the first called. This continues iterating through the alarm heap
until we reach an alarm that hasn't expired.

There are a couple subtelties to doing this, basically resulting from
the fact that we're calling the virtual alarm's callback directly:

  1. We need to re-read the current clock value each time we iterate
  through the heap since the alarm's callback could have taken a long
  time.

  2. The alarm's callback _could_ call `yield`, meaning that we would
  reenter the non-virtualized callback. So we need to take care not to
  overzealously dequeue virtual alarms from the heap before we know _for
  sure_ we're going handle them.

Port userland examples to new alarm API

Move userland timer->alarm and defulat virtualize

Removes uint32 wrapping logic, because wrapping is actually well-defined
for uint32 in C.

Renames "timer" to "alarm" and lifts the virtual alarm interface to the
default. The low level interface is now in "internal/alarm.h"

checkpoint

Implement wrapping alarm logic for userland

Add userland virtual timer blink example

Blinks two leds at different intervals concurrently

Initial stab at virtual timer

Add support for new Timer driver calls in userland

Adds absolute expiration to timer driver

Adds commands for the Timer system call driver to set an alarm for an
absolute time in clock tics and to return the clock frequency. Did some
refactoring of the TimerData struct to make this a bit cleaner.

Merge pull request #449 from helena-project/dfll-name-fix

sam4l: fix DFLL name
Merge pull request #447 from helena-project/debug-constants

debug.rs: Make length a const variable.
sam4l: fix DFLL name

sam4l: rename crccu interrupt

debug.rs: Make length a const variable.

Merge pull request #443 from helena-project/nrf51test

Remove inline(never) upgrade Rust version
Finished most of port_signpost_tock.rs
-still need to implement client callback for i2c_master_write()

Starting signbus_io_interface
-layer above port_signpost_tock

Merge pull request #445 from helena-project/auto-component

build: explicitly check for rust-src component
build: explicitly check for rust-src component

This should fix the build error from #443

Remove inline(never) upgrade Rust version

I was just super wrong. I just didn't upgrade to the right Rust
version...

merge master into signbus

still working on port_signpost layer

Merge pull request #441 from helena-project/dac-bradjc

SAM4L: Add DAC driver
Revert removing no-inline from NRF51DK with_driver

Turns out this Rust upstream issue is not resolved (actually an LLVM
issue, but we thought it was just about upgrading the version of LLVM
Rust uses):

https://github.com/rust-lang/rust/issues/42248

It seems as though the assembly _is_ different, but still incorrect
(generating `add pc, r1` instead of `mov r0, r1; br pc` which is why I
wasn't catching it...)

Merge pull request #361 from helena-project/max17205

Add MAX17205 Driver
userland: add max17205 to libtock

capsules: add max17205 driver

userland: add dac to libtock and test app

Merge pull request #440 from helena-project/move-rustup-component

build: trigger rustup component during install
sam4l: add DAC support

Merge pull request #442 from helena-project/uncrustify-libtock

style: add format for libraries too
style: add format for libraries too

The way this is done right now has the slightly unfortunate effect
that `format_all` will reformat libtock for every application (for
the same reason that it "rebuilds" libtock (only it's already built)
when doing a `build_all`). This isn't a problem per se, it's just a
little slow.

I'll add that ergnomic nit to #432, but I think it's more valuable
to get consistent formatting in while I noodle over that problem

Merge pull request #439 from helena-project/capsule-readme

capsules: doc: update readmes
capsules: doc: update readmes

build: trigger rustup component during install

This command only needs to be run once, placing it with the install of
the new toolchain means we don't have to remember to put it everywhere
that we possibly invoke rust, plus it gets rid of the `info: already
up to date` message that was printing with every build

Fixes #436.

Merge pull request #438 from helena-project/doc-improvements

doc: Updating auto-generated documentation
doc: Updating auto-generated documentation

Improve comments in source files.

make: make `doc` target phony so it runs correctly

Merge pull request #435 from alevy/upgrade

Upgrade Rust nightly
style: remove extraneous blank line

travis: ; -> || exit

popd was returning success even if the script failed. It doesn't matter
that we won't be in the right directory as travis will quit once one
command fails anyway.

n.b. You can't chain the popd with &&, as that won't do what you want either,
you need the explicit exit to maximize robustness
http://mywiki.wooledge.org/BashFAQ/105

make: XARGO is a variable

SPI slave implementation for the SAM4L with DMA (#381)

* SPI slave implementation for the SAM4L. This implementation uses DMA
rather than individual interrupts.

* Added spi_slave_transfer and spi_master_transfer examples; these programs
echo buffers between each other, setting an LED on failure

* Tested two SPI devices (FM25CL and sdcard) to ensure they still work.
Upgrade Rust nightly

Rust nightly 06-19-17 included LLVM upstream fixes that address an issue
we were running into on Cortex-M0 targets.

https://github.com/rust-lang/rust/issues/42248

static_init! cleanup (#431)

* imix: clean up board main.rs

- Remove size in static_init!
- Remove dummy pin

* capsules: clean up old static_init! calls

No longer need the size parameter, remove it from comments and examples.

Changing interface of PortSignpostTock

Still editing port_signpost_tock.rs

Merge pull request #433 from helena-project/fine-just-install-it

style: pin to one version of uncrustify
style: pin to one version of uncrustify

I suppose it's not the most surprising that different versions would
format things differently. Like rustfmt, just pin to a specific version
and install it automatically on demand

Towards #432.

Starting kernel signbus implementation

    -apps/libsignpost/port_signpost_tock.c -> kernel/tock/port_signpost_tock.rs
	-constructing static buffers and structures
	-adding functions to PortSignpostTock

Merge pull request #365 from shaneleonard/imix-v2_0-bootloader-support

imix v2.0+ support, with tock-bootloader
doc: update uncrustify version
style: fix spacing

style: enforce uncrustify version

add imixv1 board

To support existing stock of imix boards.

imix: update readme to specify v2

remove makefile that isn't needed as tockloader support exists.

imix v2.0+: use tockloader/bootloader, not openocd

Due to a hardware fix to the serial port, imix v2.0 and onward will be
compatible with tockloader and the tock-bootloader. This eliminates an
external dependency on openocd.

The tock-bootloader was configured for imix (and a pull request
submitted to that repo). The Makefile, README, and chip_layout were
basically copied from hail.

Tested successfully with a modified imix v1.3 and tockloader. All
tockloader features worked, and apps ran correctly.

imix v2.0+: pins, kernel LED, external oscillator

Several pins are rearranged in imix v1.3 onward; see changelist.md in
imix repository for details.

Use external 16 MHz crystal oscillator instead of internal oscillator,
because it is more accurate and robust to things like hot-air rework.

Add support for the newly added kernel LED, to help disambiguate user
LED messages from kernel faults.

Merge branch 'master' of https://github.com/helena-project/tock into signbus

Update ADC TRD

Updates to TRD documentation for the ADC.

Pulling this apart from the main ADC PR so that we can have back and forth on it, but still get the ADC stuff merged into Tock to start using it.
libtock: aes library syncronous (#425)

Updated AES library to provide synchronous functions and asynchronous wrappers of system calls. Also updated example application to demonstrate functionality.

* made the aes library syncronous and changed the test accordingly

* changed name convention and callbacks are stack allocated

* removed set_key_done from HIL makes no sense to have it async. tried to fix stuff according to brghena comments

* async version of aes128_ctr added

* grammar

style: only inlucde settings we use in config

This should really address the problems from #427

Merge pull request #429 from helena-project/ergonomics-format-unstaged

tools: check for unstaged changes before formatting
doc: note uncrustify version
tools: check for unstaged changes before formatting

Closes #302.

Merge pull request #428 from helena-project/mark-asm

Mark inputs and outputs for extended ASM correctly
Mark inputs and outputs for extended ASM correctly

LTO optimizations breaking things continues to teach me more about
how these are supposed to be written. I believe these are now completely
correct.

A little extra regarding yield:

@brghena and I spent a little while talking this through, but this
should properly express to the complier the semantics of what we're
doing.

Our old approach of

    push {lr}
    svc  0
    pop  {pc}

failed in cases where yield is inlined and the link register isn't
live (i.e. during the `while (1) { yield(); }` loop at the end.

It would've been okay if we'd `pop {lr}` instead of `pop {pc}`'d
because then we would've just pushed and popped a garbage value to
the stack, but the better fix is to just express the clobbers to
the compiler and let it sort what what does and doesn't need to be
saved.

Currently tested working with blink / c_hello / accel_leds

style: comment out v0.64 options

uncrustify isn't forward compatible, so using a config generated
from bleeding edge version causes some issues

Fixes #427

Fix nightly version in docs

Merge pull request #426 from helena-project/c-style-lints

C style lints
add documentation for userland style

style: align assignment blocks where not obnoxious

If I understand these options, if it's within N=8 characters to align
assignments, do so, which from the diff looks like a pretty reasonable
setting

Make everything better, after Amit's review

  - remove static_fmt (only useful for cruddy debugging)
  - replace volatile_slice, copy_slice with [VolatileCell<u8>], etc.
  - manage usb_simple's state value with a Cell instead of a RefCell
  - embed ep0_buf and descriptor_buf in SimpleClient instead of static
  - simplify Reg* types; replace Regs with array of Reg
  - mark Reg* constructors unsafe

add @brghena's comment suggestion

show linter complaints in travis build log

userland: add C/C++ linting

we've been doing this pretty manually and informally up till now

Merge pull request #424 from niklasad1/nrf51/uart_no_more_transmute

nrf51/uart_refactor
replaced transmute's with deferecing instead and made the pointer to memory mapped I/O const

Added coulomb helper function for ltc294x (#421)

* added coulomb helper function for ltc294x

Merge pull request #423 from helena-project/hail-no-size

hail: remove size parameter from static_init
hail: remove size parameter from static_init

Merge pull request #422 from alevy/ergonomics/static_init_no_size

Avoid requiring an explicit size in static_init
Merge pull request #409 from frenicth/nrf51/ble_advertisement

Nrf51/ble advertisement
Avoid requiring an explicit size in static_init

Sacrifices up to a word of memory in order to avoid requiring the caller
to explicitly pass in the size of the type. When we finally get
`size_of` or other intrinsics at compile-time, we'll be able to get rid
of that overhead as well.

For backwards compatibility accepts an optional size argument which is
simply ignored.

libtock

rust fmt format

patch to @brghena review
* removed un-necessary stuff such client callback, e's ...
* added support to configure advertisement address from user-space
* radio file is cleaned up with new constants for the readability and
so on
* most comments should be resolved

The following are added:
* System call number in Syscall.md
* More verbose error checking in demo app
* Replaced #defines with enum for TX_Power

Merge branch 'master' into nrf51/ble_advertisement
Merge pull request #5 from frenicth/nrf51/ble_all_in_chips

This a patch for @alevy comments
Fix of-by-one on bounds check for adc channels

Unsafe stuff removed and some typos fixed

This a patch for @alevy comments
   * removed the BLE HIL
   * moved syscall driver into chips/nrf51/src/ble_advertising_driver.rs
   * the initlization of ble stuff is changed
   * the public functions are instead call directly instead of going
     through HIL
   * some more unsafe are needed in ble_advertising_driver
   * radio is now responsible for advertisements on the different
     channels

Merge pull request #406 from helena-project/mcp23008

Add MCP23008 Capsule
userland: add gpio_async test

userland: add async_gpio to libtock

capsules: add Async GPIO and MCP23008

This adds support for a particular GPIO extender and an interface for
new ones in the future (asynchronous GPIO).

Update ble.h

weird nrf values and probably not platform independent macros!
Update ble.h

Fixed Invalid mapping of power levels
Removed some trailing debug prints, renaming of variables and fixed user app

Merge pull request #417 from daniel-scs/pm-doc

sam4l pm: fix some comments about clock sources
fmt

Changed names in boards/nrf51dk/src/main from radio to ble_radio
Removed capsule from chips (radio)
Added support to set advertisement interval from user space
Added support to clear the payload of an advertisement packet from user space
Fixed how to compute correct number of ticks for delays
Updated/added comments and corrected spelling misstakes

sam4l pm: fix some comments about clock sources

Add driver for SAM4L's USBC and generic USB lib

This is still experimental, and provides just enough support so that
the SAM4L can be enumerated as a device (at least on Linux).

In the boot code for imix, the kernel attaches to the USB bus and
registers handlers to respond to host requests.

This commit includes:

- The beginnings of a generic interface to USB controllers
  in kernel/src/hil
- A driver (implementing the hil-controller interface) for the
  SAM4L's USBC in chips/sam4l
- A library in capsules/src/usb.rs that provides datatypes and
  serialization routines for speaking USB
- A client (implementing the hil-client interface) in
  capsules/src/usb_simple.rs that does all the platform-independent
  logic necessary for enumeration, like responding to host requests for
  various descriptors
- Some unsafe support code in kernel/src/common, most of which
  is not pretty and can probably be removed before mainlining

There is no user-space interface yet.

userland: skip testing directories with leading _'s

libtock: don't allow serialization calls to ignore returns

libtock: don't allow syscalls to ignore returns

libtock: allow nrf serialization to bubble errors

libtock: allow putstr function to return errors

rust fmt format

un-necessary files removed

cleaned up the code before pull request

ram 32 -> 16

refactoring, renaming

merge

Now sending on all frequencies correctly, major refactor, fixed payload to get valid CRC

removed debug prints

set_adv_data() supported for all AD types

The following improvements:
  - added a new BLE library
  - started to add support for all AD types (far away from finished ...)
  - added support to configure TX Power from user space
  - added support to configure advertisement intervall from user space
  - removed all other radio stuff

rebase/merge

rebase/merge

Added the following:
 - local name and data can be zero and use pre-configured local name
 - minor documentation in the capsule
 - buffer bounce checking in the capsule

rust fmt

major refactor, re-wrote the capsule the name and data are only configured before every advertisement, makes to code more clean and so on

sending advertisements with small delay between each channel via the capsule. using this for testing and measuring

added temporary files for measurement, remove later

updated advertisement interval to match how Zephyr OS does it

minor refactor, fixed to unssafe part with an ugly workaround and divided transmit_ble_adv into two functions

Now possible to set local name and data from userland to be used in BLE advertisements

Skeleton added how to send data to userland
* new approasch use slice.len() get buffer length
* added a another allow call
* suggestion how to nest two closured to send both the chips

added minimal code so it at least compiles and a suggestion how to loop through the buffers

Added busy guard to protect radio from several requests

advertisements are now sending one all three channels per cycle and then waits. Need to trim time between advertisements and cycles

refactor, changed name of sending function to be more precise

Refactoring:
	Created name of function that puts buffer from userland into the kernel to read_userland_buffer. Changed the way the for-loop works as well (Alevi suggestion).
Feature:
	Disable transmission of ble advertisement packets.
Status:
	Bug or strange behaviour when using delay_ms in userland, system calls does not work properly.

removed commented code

ble adv in progress, works with virtual timers

fmt

working on virtual timers, removed some panics...

started working on virtual alarm... not virtual though.

cleaned up the code a little bit removed all transmute() for example

new branch for bluetooth low energy. Currently sends advertisements packets

Added the following:
 - local name and data can be zero and use pre-configured local name
 - minor documentation in the capsule
 - buffer bounce checking in the capsule

rust fmt

major refactor, re-wrote the capsule the name and data are only configured before every advertisement, makes to code more clean and so on

sending advertisements with small delay between each channel via the capsule. using this for testing and measuring

added temporary files for measurement, remove later

updated advertisement interval to match how Zephyr OS does it

minor refactor, fixed to unssafe part with an ugly workaround and divided transmit_ble_adv into two functions

Someone didn't take care of the return values correctly

Now possible to set local name and data from userland to be used in BLE advertisements

Skeleton added how to send data to userland
* new approasch use slice.len() get buffer length
* added a another allow call
* suggestion how to nest two closured to send both the chips

added minimal code so it at least compiles and a suggestion how to loop through the buffers

added mostly comments and I suggest how to loop through the buffers without the actual length

Sending data from userland

Just trying out how to set local name from userland… position 11 in
PAYLOAD and forward can be used for localname.

Set channel should not be possible from user land

Added busy guard to protect radio from several requests

updated makefile according to new way of making userland apps

advertisements are now sending one all three channels per cycle and then waits. Need to trim time between advertisements and cycles

user app now sends advertisements for 50 seconds, turns them off for 10 seconds and repeats indefinitely

fixed warnings

refactor, changed name of sending function to be more precise

Refactoring:
	Created name of function that puts buffer from userland into the kernel to read_userland_buffer. Changed the way the for-loop works as well (Alevi suggestion).
Feature:
	Disable transmission of ble advertisement packets.
Status:
	Bug or strange behaviour when using delay_ms in userland, system calls does not work properly.

removed commented code

ble adv in progress, works with virtual timers

fmt

working on virtual timers, removed some panics...

started working on virtual alarm... not virtual though.

cleaned up the code a little bit removed all transmute() for example

new branch for bluetooth low energy. Currently sends advertisements packets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.