├── .github ├── CONTRIBUTING.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .gitmodules ├── .travis.yml ├── .vscode ├── launch.json └── settings.json ├── CHANGELOG.md ├── COPYRIGHT ├── LICENSE-APACHE ├── LICENSE-MIT ├── Makefile ├── README.md ├── arch ├── README.md ├── cortex-m │ ├── Cargo.toml │ └── src │ │ ├── lib.rs │ │ ├── nvic.rs │ │ ├── scb.rs │ │ ├── support.rs │ │ ├── syscall.rs │ │ └── systick.rs ├── cortex-m0 │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── cortex-m3 │ ├── Cargo.toml │ └── src │ │ ├── lib.rs │ │ └── mpu.rs ├── cortex-m4 │ ├── Cargo.toml │ └── src │ │ ├── lib.rs │ │ └── mpu.rs └── rv32i │ ├── Cargo.toml │ ├── README.md │ └── src │ ├── clic.rs │ ├── csr │ ├── mcause.rs │ ├── mcycle.rs │ ├── mepc.rs │ ├── mie.rs │ ├── minstret.rs │ ├── mip.rs │ ├── mod.rs │ ├── mscratch.rs │ ├── mstatus.rs │ ├── mtval.rs │ ├── mtvec.rs │ ├── pmpaddr.rs │ ├── pmpconfig.rs │ ├── stvec.rs │ └── utvec.rs │ ├── lib.rs │ ├── machine_timer.rs │ ├── pmp.rs │ ├── support.rs │ └── syscall.rs ├── boards ├── Makefile.common ├── README.md ├── acd52832 │ ├── Cargo.toml │ ├── Makefile │ ├── README.md │ ├── build.rs │ ├── layout.ld │ └── src │ │ ├── io.rs │ │ └── main.rs ├── arty-e21 │ ├── Cargo.toml │ ├── Makefile │ ├── README.md │ ├── build.rs │ ├── core │ │ ├── README.md │ │ ├── sifive_coreip_E21_AHB_rtl_eval_v19_05p1_release_arty_a7_100t.mcs │ │ └── sifive_coreip_E21_FPGA_Evaluation_v19_02_rc0.mcs │ ├── layout.ld │ ├── openocd │ │ ├── arty-openocd-digilent.cfg │ │ ├── bscan_spi_xc7a100t.bit │ │ └── bscan_spi_xc7a35t.bit │ └── src │ │ ├── io.rs │ │ ├── main.rs │ │ └── timer_test.rs ├── components │ ├── Cargo.toml │ └── src │ │ ├── alarm.rs │ │ ├── button.rs │ │ ├── console.rs │ │ ├── crc.rs │ │ ├── debug_writer.rs │ │ ├── gpio.rs │ │ ├── isl29035.rs │ │ ├── led.rs │ │ ├── lib.rs │ │ ├── lldb.rs │ │ ├── nrf51822.rs │ │ ├── process_console.rs │ │ ├── rng.rs │ │ ├── si7021.rs │ │ └── spi.rs ├── hail │ ├── Cargo.toml │ ├── Makefile │ ├── README.md │ ├── bootloader │ │ ├── README.md │ │ └── bootloader.bin │ ├── build.rs │ ├── chip_layout.ld │ ├── connect.cfg │ ├── debug.gdb │ ├── jlink │ │ ├── gdb_session.sh │ │ ├── hail.gdb │ │ └── jlink_gdbserver.sh │ ├── layout.ld │ ├── media │ │ ├── hail-lab11llc_pinout_and_guide.png │ │ ├── hail_breadboard_1000x859.jpg │ │ ├── hail_reva_noheaders_1000x536.jpg │ │ └── hail_reva_noheaders_labeled.png │ └── src │ │ ├── io.rs │ │ ├── main.rs │ │ └── test_take_map_cell.rs ├── hifive1 │ ├── Cargo.toml │ ├── Makefile │ ├── README.md │ ├── build.rs │ ├── layout.ld │ └── src │ │ ├── io.rs │ │ └── main.rs ├── imix │ ├── Cargo.toml │ ├── Makefile │ ├── README.md │ ├── bootloader │ │ ├── README.md │ │ └── bootloader.bin │ ├── build.rs │ ├── chip_layout.ld │ ├── connect.cfg │ ├── debug.gdb │ ├── layout.ld │ └── src │ │ ├── aes_ccm_test.rs │ │ ├── aes_test.rs │ │ ├── i2c_dummy.rs │ │ ├── icmp_lowpan_test.rs │ │ ├── imix_components │ │ ├── adc.rs │ │ ├── analog_comparator.rs │ │ ├── fxos8700.rs │ │ ├── mod.rs │ │ ├── nonvolatile_storage.rs │ │ ├── radio.rs │ │ ├── rf233.rs │ │ ├── test │ │ │ ├── mock_udp.rs │ │ │ ├── mock_udp2.rs │ │ │ └── mod.rs │ │ ├── udp_driver.rs │ │ ├── udp_mux.rs │ │ └── usb.rs │ │ ├── io.rs │ │ ├── ipv6_lowpan_test.rs │ │ ├── main.rs │ │ ├── power.rs │ │ ├── rng_test.rs │ │ ├── spi_dummy.rs │ │ ├── spi_slave_dummy.rs │ │ ├── udp_lowpan_test.rs │ │ └── virtual_uart_rx_test.rs ├── kernel_layout.ld ├── launchxl │ ├── Cargo.toml │ ├── Makefile │ ├── README.md │ ├── build.rs │ ├── chip_layout.ld │ ├── flash-ccfg.jlink │ ├── flash-ccfg.openocd │ ├── flash-kernel.jlink │ ├── flash-kernel.openocd │ ├── jtag │ │ ├── cc2652r1f.ccxml │ │ ├── gdbinit │ │ └── openocd.cfg │ ├── layout.ld │ ├── shell.nix │ └── src │ │ ├── cc1312r.rs │ │ ├── cc1352p.rs │ │ ├── ccfg.rs │ │ ├── i2c_tests.rs │ │ ├── io.rs │ │ ├── main.rs │ │ └── uart_echo.rs ├── nordic │ ├── nrf52840_dongle │ │ ├── Cargo.toml │ │ ├── Makefile │ │ ├── README.md │ │ ├── build.rs │ │ ├── jtag │ │ │ ├── gdbinit_pca10040.jlink │ │ │ └── jdbserver_pca10040.sh │ │ ├── layout.ld │ │ └── src │ │ │ ├── io.rs │ │ │ └── main.rs │ ├── nrf52840dk │ │ ├── Cargo.toml │ │ ├── Makefile │ │ ├── README.md │ │ ├── build.rs │ │ ├── jtag │ │ │ ├── gdbinit_pca10040.jlink │ │ │ └── jdbserver_pca10040.sh │ │ ├── layout.ld │ │ └── src │ │ │ ├── io.rs │ │ │ └── main.rs │ ├── nrf52dk │ │ ├── Cargo.toml │ │ ├── Makefile │ │ ├── README.md │ │ ├── build.rs │ │ ├── chip_layout.ld │ │ ├── jtag │ │ │ ├── flash-full.jlink │ │ │ ├── flash-kernel.jlink │ │ │ ├── gdbinit_pca10040.jlink │ │ │ └── jdbserver_pca10040.sh │ │ ├── layout.ld │ │ └── src │ │ │ ├── io.rs │ │ │ ├── main.rs │ │ │ └── tests │ │ │ ├── aes.rs │ │ │ ├── mod.rs │ │ │ └── uart.rs │ └── nrf52dk_base │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ ├── lib.rs │ │ └── nrf52_components │ │ ├── ble.rs │ │ ├── ieee802154.rs │ │ └── mod.rs ├── nucleo_f429zi │ ├── Cargo.toml │ ├── Makefile │ ├── README.md │ ├── build.rs │ ├── chip_layout.ld │ ├── layout.ld │ ├── openocd.cfg │ └── src │ │ ├── io.rs │ │ └── main.rs ├── nucleo_f446re │ ├── Cargo.toml │ ├── Makefile │ ├── README.md │ ├── build.rs │ ├── chip_layout.ld │ ├── layout.ld │ ├── openocd.cfg │ └── src │ │ ├── io.rs │ │ ├── main.rs │ │ └── virtual_uart_rx_test.rs └── opentitan │ ├── Cargo.toml │ ├── Makefile │ ├── README.md │ ├── build.rs │ ├── layout.ld │ └── src │ ├── io.rs │ └── main.rs ├── bors.toml ├── capsules ├── Cargo.toml ├── README.md ├── examples │ └── traitobj_list.rs └── src │ ├── adc.rs │ ├── aes_ccm.rs │ ├── alarm.rs │ ├── ambient_light.rs │ ├── analog_comparator.rs │ ├── analog_sensor.rs │ ├── app_flash_driver.rs │ ├── ble_advertising_driver.rs │ ├── button.rs │ ├── buzzer_driver.rs │ ├── console.rs │ ├── crc.rs │ ├── dac.rs │ ├── debug_process_restart.rs │ ├── driver.rs │ ├── fm25cl.rs │ ├── fxos8700cq.rs │ ├── gpio.rs │ ├── gpio_async.rs │ ├── humidity.rs │ ├── i2c_master.rs │ ├── i2c_master_slave_driver.rs │ ├── ieee802154 │ ├── device.rs │ ├── driver.rs │ ├── framer.rs │ ├── mac.rs │ ├── mod.rs │ ├── virtual_mac.rs │ └── xmac.rs │ ├── isl29035.rs │ ├── led.rs │ ├── lib.rs │ ├── low_level_debug │ ├── README.md │ ├── fmt.rs │ └── mod.rs │ ├── lps25hb.rs │ ├── ltc294x.rs │ ├── max17205.rs │ ├── mcp230xx.rs │ ├── mx25r6435f.rs │ ├── net │ ├── frag_utils.rs │ ├── icmpv6 │ │ ├── icmpv6.rs │ │ ├── icmpv6_send.rs │ │ └── mod.rs │ ├── ieee802154.rs │ ├── ip.rs │ ├── ipv6 │ │ ├── ip_utils.rs │ │ ├── ipv6.rs │ │ ├── ipv6_recv.rs │ │ ├── ipv6_send.rs │ │ └── mod.rs │ ├── mod.rs │ ├── sixlowpan │ │ ├── mod.rs │ │ ├── sixlowpan_compression.rs │ │ └── sixlowpan_state.rs │ ├── stream.rs │ ├── tcp.rs │ ├── thread │ │ ├── mod.rs │ │ └── tlv.rs │ ├── udp │ │ ├── driver.rs │ │ ├── mod.rs │ │ ├── udp.rs │ │ ├── udp_port_table.rs │ │ ├── udp_recv.rs │ │ └── udp_send.rs │ └── util.rs │ ├── ninedof.rs │ ├── nonvolatile_storage_driver.rs │ ├── nonvolatile_to_pages.rs │ ├── nrf51822_serialization.rs │ ├── pca9544a.rs │ ├── process_console.rs │ ├── rf233.rs │ ├── rf233_const.rs │ ├── rng.rs │ ├── sdcard.rs │ ├── segger_rtt.rs │ ├── si7021.rs │ ├── spi.rs │ ├── temperature.rs │ ├── test │ ├── aes.rs │ ├── aes_ccm.rs │ ├── alarm.rs │ ├── mod.rs │ ├── rng.rs │ ├── udp.rs │ └── virtual_uart.rs │ ├── tmp006.rs │ ├── tsl2561.rs │ ├── usb │ ├── descriptors.rs │ ├── mod.rs │ ├── usb_user.rs │ ├── usbc_client.rs │ └── usbc_client_ctrl.rs │ ├── virtual_alarm.rs │ ├── virtual_flash.rs │ ├── virtual_i2c.rs │ ├── virtual_pwm.rs │ ├── virtual_spi.rs │ └── virtual_uart.rs ├── chips ├── README.md ├── arty_e21 │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── chip.rs │ │ ├── gpio.rs │ │ ├── interrupts.rs │ │ ├── lib.rs │ │ ├── timer.rs │ │ └── uart.rs ├── cc26x2 │ ├── Cargo.toml │ └── src │ │ ├── aon.rs │ │ ├── ccfg.rs │ │ ├── chip.rs │ │ ├── crt1.rs │ │ ├── event.rs │ │ ├── gpio.rs │ │ ├── gpt.rs │ │ ├── i2c.rs │ │ ├── ioc.rs │ │ ├── lib.rs │ │ ├── memory_map.rs │ │ ├── peripheral_interrupts.rs │ │ ├── prcm.rs │ │ ├── pwm.rs │ │ ├── rom.rs │ │ ├── rtc.rs │ │ ├── trng.rs │ │ └── uart.rs ├── e310x │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── chip.rs │ │ ├── gpio.rs │ │ ├── interrupts.rs │ │ ├── lib.rs │ │ ├── plic.rs │ │ ├── prci.rs │ │ ├── pwm.rs │ │ ├── rtc.rs │ │ ├── timer.rs │ │ ├── uart.rs │ │ └── watchdog.rs ├── ibex │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── chip.rs │ │ ├── gpio.rs │ │ ├── interrupts.rs │ │ ├── lib.rs │ │ ├── plic.rs │ │ ├── timer.rs │ │ └── uart.rs ├── lowrisc │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── gpio.rs │ │ ├── lib.rs │ │ └── uart.rs ├── nrf52 │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── acomp.rs │ │ ├── adc.rs │ │ ├── ble_radio.rs │ │ ├── chip.rs │ │ ├── clock.rs │ │ ├── crt1.rs │ │ ├── deferred_call_tasks.rs │ │ ├── ficr.rs │ │ ├── i2c.rs │ │ ├── ieee802154_radio.rs │ │ ├── interrupt_service.rs │ │ ├── lib.rs │ │ ├── nvmc.rs │ │ ├── power.rs │ │ ├── ppi.rs │ │ ├── pwm.rs │ │ ├── spi.rs │ │ ├── uart.rs │ │ ├── uicr.rs │ │ └── usbd.rs ├── nrf52832 │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── chip.rs │ │ ├── gpio.rs │ │ ├── interrupt_service.rs │ │ └── lib.rs ├── nrf52840 │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── chip.rs │ │ ├── gpio.rs │ │ ├── interrupt_service.rs │ │ ├── lib.rs │ │ └── peripheral_interrupts.rs ├── nrf5x │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── aes.rs │ │ ├── constants.rs │ │ ├── gpio.rs │ │ ├── lib.rs │ │ ├── peripheral_interrupts.rs │ │ ├── pinmux.rs │ │ ├── rtc.rs │ │ ├── temperature.rs │ │ ├── timer.rs │ │ └── trng.rs ├── sam4l │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── acifc.rs │ │ ├── adc.rs │ │ ├── aes.rs │ │ ├── ast.rs │ │ ├── bpm.rs │ │ ├── bscif.rs │ │ ├── chip.rs │ │ ├── crccu.rs │ │ ├── dac.rs │ │ ├── deferred_call_tasks.rs │ │ ├── dma.rs │ │ ├── eic.rs │ │ ├── flashcalw.rs │ │ ├── gloc.rs │ │ ├── gpio.rs │ │ ├── i2c.rs │ │ ├── lib.rs │ │ ├── nvic.rs │ │ ├── pm.rs │ │ ├── scif.rs │ │ ├── serial_num.rs │ │ ├── spi.rs │ │ ├── trng.rs │ │ ├── usart.rs │ │ ├── usbc │ │ ├── debug.rs │ │ └── mod.rs │ │ └── wdt.rs ├── sifive │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── gpio.rs │ │ ├── lib.rs │ │ ├── prci.rs │ │ ├── pwm.rs │ │ ├── rtc.rs │ │ ├── uart.rs │ │ └── watchdog.rs └── stm32f4xx │ ├── Cargo.toml │ ├── README.md │ └── src │ ├── chip.rs │ ├── dbg.rs │ ├── deferred_call_tasks.rs │ ├── dma1.rs │ ├── exti.rs │ ├── gpio.rs │ ├── lib.rs │ ├── nvic.rs │ ├── rcc.rs │ ├── spi.rs │ ├── syscfg.rs │ ├── tim2.rs │ └── usart.rs ├── doc ├── .gitignore ├── BluetoothLEStack.md ├── CodeReview.md ├── Compilation.md ├── Configuration.md ├── CoreTeam.md ├── Design.md ├── Getting_Started.md ├── Lifetimes.md ├── Memory_Isolation.md ├── Memory_Layout.md ├── Mutable_References.md ├── Networking_Stack.md ├── OutOfTree.md ├── Overview.md ├── Porting.md ├── README.md ├── Soundness.md ├── Startup.md ├── Style.md ├── Syscalls.md ├── TockBinaryFormat.md ├── Userland.md ├── architecture.png ├── courses │ ├── 2017-11-SenSys │ │ └── README.md │ ├── 2018-11-SenSys │ │ ├── README.md │ │ ├── application.md │ │ ├── client.md │ │ ├── environment.md │ │ ├── exercises │ │ │ └── app │ │ │ │ ├── .gitignore │ │ │ │ ├── Makefile │ │ │ │ ├── main.c │ │ │ │ └── solutions │ │ │ │ ├── ble-ess.c │ │ │ │ ├── repeat-hello.c │ │ │ │ └── sensors.c │ │ ├── freeform.md │ │ ├── img │ │ │ └── architecture.png │ │ ├── manual_installation.md │ │ └── presentation │ │ │ ├── Makefile │ │ │ ├── architecture.pdf │ │ │ ├── execution.pdf │ │ │ ├── imix.png │ │ │ └── slides.md │ ├── README.md │ ├── rustconf │ │ ├── README.md │ │ ├── application.md │ │ ├── architecture.png │ │ ├── capsule.md │ │ ├── console.png │ │ ├── console.svg │ │ ├── environment.md │ │ ├── goals.txt │ │ ├── presentation │ │ │ ├── architecture.pdf │ │ │ ├── execution.pdf │ │ │ ├── hail.png │ │ │ ├── ipc.pdf │ │ │ ├── ipc.svg │ │ │ ├── presentation.pdf │ │ │ ├── process_layout.png │ │ │ ├── rng.pdf │ │ │ ├── rng.svg │ │ │ ├── slides.md │ │ │ └── snakeoil.jpg │ │ ├── rustconf.png │ │ └── rustconf.svg │ └── sosp │ │ └── README.md ├── debugging │ ├── VSCode_Debugging.md │ └── figures │ │ ├── vsc_breakpoint.png │ │ ├── vsc_debug_view.png │ │ └── vsc_running.png ├── process_memory_layout.png ├── processram.png ├── reference │ ├── README.md │ ├── trd-radio.md │ ├── trd-time.md │ ├── trd1-trds.md │ ├── trd102-adc.md │ └── trd103-gpio.md ├── syscalls │ ├── 00000_alarm.md │ ├── 00001_console.md │ ├── 00002_leds.md │ ├── 00003_buttons.md │ ├── 00004_gpio.md │ ├── 00005_adc.md │ ├── 00007_analog_comparator.md │ ├── 00008_low_level_debug.md │ ├── 30002_udp.md │ ├── 60000_ambient_temperature.md │ ├── 60001_humidity.md │ ├── 60002_luminance.md │ ├── README.md │ └── memop.md ├── tock-stack.png └── wg │ ├── README.md │ ├── opentitan-notes │ └── 2020-02-07.txt │ └── opentitan.md ├── kernel ├── Cargo.toml ├── README.md └── src │ ├── callback.rs │ ├── capabilities.rs │ ├── common │ ├── deferred_call.rs │ ├── dynamic_deferred_call.rs │ ├── leasable_buffer.rs │ ├── list.rs │ ├── math.rs │ ├── mod.rs │ ├── peripherals.rs │ ├── queue.rs │ ├── ring_buffer.rs │ ├── static_ref.rs │ └── utils.rs │ ├── component.rs │ ├── config.rs │ ├── debug.rs │ ├── driver.rs │ ├── grant.rs │ ├── hil │ ├── adc.rs │ ├── analog_comparator.rs │ ├── ble_advertising.rs │ ├── crc.rs │ ├── dac.rs │ ├── eic.rs │ ├── entropy.rs │ ├── flash.rs │ ├── gpio.rs │ ├── gpio_async.rs │ ├── i2c.rs │ ├── led.rs │ ├── mod.rs │ ├── ninedof.rs │ ├── nonvolatile_storage.rs │ ├── pwm.rs │ ├── radio.rs │ ├── rng.rs │ ├── sensors.rs │ ├── spi.rs │ ├── symmetric_encryption.rs │ ├── time.rs │ ├── uart.rs │ ├── usb.rs │ └── watchdog.rs │ ├── introspection.rs │ ├── ipc.rs │ ├── lib.rs │ ├── mem.rs │ ├── memop.rs │ ├── platform │ ├── mod.rs │ ├── mpu.rs │ └── systick.rs │ ├── process.rs │ ├── returncode.rs │ ├── sched.rs │ ├── syscall.rs │ └── tbfheader.rs ├── libraries ├── README.md ├── enum_primitive │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── cast.rs │ │ └── lib.rs ├── riscv-csr │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── csr.rs │ │ └── lib.rs ├── tock-cells │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── lib.rs │ │ ├── map_cell.rs │ │ ├── numeric_cell_ext.rs │ │ ├── optional_cell.rs │ │ ├── take_cell.rs │ │ └── volatile_cell.rs ├── tock-register-interface │ ├── CHANGELOG.md │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── lib.rs │ │ ├── macros.rs │ │ └── registers.rs └── tock-rt0 │ ├── Cargo.toml │ ├── README.md │ └── src │ └── lib.rs ├── rust-toolchain ├── shell.nix ├── tools ├── .gitignore ├── alert_codes │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── build-all-docs.sh ├── check-all-links.sh ├── check_capsule_readme.py ├── check_wildcard_imports.sh ├── list_archs.sh ├── list_boards.sh ├── list_chips.sh ├── list_tools.sh ├── netlify-build.sh ├── run_cargo_fix.sh ├── run_cargo_fmt.sh ├── run_cargo_generate-lockfile.sh ├── run_clippy.sh ├── semver.sh ├── svd2regs.nix ├── svd2regs.py ├── toc.sh ├── update_chip_support.py ├── update_rust_version.sh └── usb │ ├── bulk-echo-fast │ ├── build.sh │ ├── main.c │ └── test.sh │ ├── bulk-echo │ ├── Cargo.toml │ ├── src │ │ └── main.rs │ └── test.sh │ ├── bulk-test │ ├── Cargo.toml │ └── src │ │ └── main.rs │ └── control-test │ ├── Cargo.toml │ └── src │ └── main.rs └── vagrant ├── .gitignore ├── README.md └── Vagrantfile /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Pull Request Overview 2 | 3 | This pull request adds/changes/fixes... 4 | 5 | 6 | ### Testing Strategy 7 | 8 | This pull request was tested by... 9 | 10 | 11 | ### TODO or Help Wanted 12 | 13 | This pull request still needs... 14 | 15 | 16 | ### Documentation Updated 17 | 18 | - [ ] Updated the relevant files in `/docs`, or no updates are required. 19 | 20 | ### Formatting 21 | 22 | - [ ] Ran `make formatall`. 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | build/* 3 | *.rlib 4 | *.sdb 5 | *.bin 6 | *.elf 7 | *.o 8 | *.ll 9 | .gdbinit 10 | .gdb_history 11 | 12 | ## OS X 13 | .DS_Store 14 | .AppleDouble 15 | .LSOverride 16 | 17 | # Icon must end with two \r 18 | Icon 19 | 20 | # Thumbnails 21 | ._* 22 | 23 | # Files that might appear on external disk 24 | .Spotlight-V100 25 | .Trashes 26 | 27 | # Directories potentially created on remote AFP share 28 | .AppleDB 29 | .AppleDesktop 30 | Network Trash Folder 31 | Temporary Items 32 | .apdisk 33 | 34 | ## Log Files 35 | *.log 36 | 37 | # Files generated by rustfmt 38 | *.bk 39 | 40 | # rustdoc folder 41 | doc/rustdoc 42 | 43 | # Backup and swap files 44 | *~ 45 | [._]*.s[a-v][a-z] 46 | [._]*.sw[a-p] 47 | [._]s[a-v][a-z] 48 | [._]sw[a-p] 49 | 50 | /.idea 51 | 52 | # Cargo.lock files have a lot of noisy churn during development. Instead they 53 | # are manually included for releases. 54 | Cargo.lock 55 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/.gitmodules -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: rust 3 | 4 | addons: 5 | apt: 6 | packages: libusb-1.0-0-dev 7 | 8 | 9 | # bors default configuration: 10 | #branches: 11 | # only: 12 | # # This is where pull requests from "bors r+" are built. 13 | # - staging 14 | # # This is where pull requests from "bors try" are built. 15 | # - trying 16 | # # Uncomment this to enable building pull requests. 17 | # - master 18 | # 19 | # Instead, I think we just want to disable to bors temp branch 20 | branches: 21 | except: 22 | - staging.tmp 23 | - trying.tmp 24 | 25 | 26 | cache: 27 | cargo: true 28 | 29 | os: 30 | - linux 31 | 32 | # If you change this, you must also change Getting_Started.md, Makefile.common, 33 | # .vscode/settings.json, and tools/netlify-build.sh. 34 | rust: 35 | - nightly-2020-01-16 36 | 37 | before_script: 38 | - npm install -g markdown-toc 39 | 40 | script: 41 | - export PATH=$HOME/.cargo/bin:$PATH 42 | - make ci-travis 43 | 44 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "nRF52-DK", 6 | "type": "gdb", 7 | "request": "attach", 8 | "executable": "${workspaceRoot}/boards/nrf52dk/target/thumbv7em-none-eabi/release/nrf52dk", 9 | "target": "localhost:2331", 10 | "remote": true, 11 | "cwd": "${workspaceRoot}", 12 | "gdbpath": "arm-none-eabi-gdb", 13 | "autorun": [ 14 | "monitor reset", 15 | "monitor speed auto", 16 | "b reset_handler" 17 | ] 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "rust-client.channel": "nightly-2020-01-16", 4 | } 5 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | Tock Operating System 2 | Copyright 2016 The Tock OS Developers 3 | 4 | Licensed under the Apache License, Version 2.0 5 | or the MIT 7 | license , 8 | at your option. All files in this project may not be copied, 9 | modified, or distributed except according to those terms. 10 | 11 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 The Tock Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /arch/README.md: -------------------------------------------------------------------------------- 1 | Architecture Specific Modules 2 | ============================= 3 | 4 | This folder contains code that is generic for all microcontrollers 5 | based on a specific underlying hardware architecture (e.g. a Cortex-M4 core). 6 | -------------------------------------------------------------------------------- /arch/cortex-m/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cortexm" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | kernel = { path = "../../kernel" } 9 | -------------------------------------------------------------------------------- /arch/cortex-m/src/scb.rs: -------------------------------------------------------------------------------- 1 | //! ARM System Control Block 2 | //! 3 | //! 4 | 5 | use kernel::common::cells::VolatileCell; 6 | use kernel::common::StaticRef; 7 | 8 | #[repr(C)] 9 | struct ScbRegisters { 10 | cpuid: VolatileCell, 11 | icsr: VolatileCell, 12 | vtor: VolatileCell, 13 | aircr: VolatileCell, 14 | scr: VolatileCell, 15 | ccr: VolatileCell, 16 | shp: [VolatileCell; 3], 17 | shcsr: VolatileCell, 18 | cfsr: VolatileCell, 19 | hfsr: VolatileCell, 20 | dfsr: VolatileCell, 21 | mmfar: VolatileCell, 22 | bfar: VolatileCell, 23 | afsr: VolatileCell, 24 | pfr: [VolatileCell; 2], 25 | dfr: VolatileCell, 26 | adr: VolatileCell, 27 | mmfr: [VolatileCell; 4], 28 | isar: [VolatileCell; 5], 29 | _reserved0: [u32; 5], 30 | cpacr: VolatileCell, 31 | } 32 | 33 | const SCB: StaticRef = unsafe { StaticRef::new(0xE000ED00 as *const ScbRegisters) }; 34 | 35 | /// Allow the core to go into deep sleep on WFI. 36 | /// 37 | /// The specific definition of "deep sleep" is chip specific. 38 | pub unsafe fn set_sleepdeep() { 39 | let scr = SCB.scr.get(); 40 | SCB.scr.set(scr | 1 << 2); 41 | } 42 | 43 | /// Do not allow the core to go into deep sleep on WFI. 44 | /// 45 | /// The specific definition of "deep sleep" is chip specific. 46 | pub unsafe fn unset_sleepdeep() { 47 | let scr = SCB.scr.get(); 48 | SCB.scr.set(scr & !(1 << 2)); 49 | } 50 | 51 | /// Software reset using the ARM System Control Block 52 | pub unsafe fn reset() { 53 | let aircr = SCB.aircr.get(); 54 | let reset = (0x5FA << 16) | (aircr & (0x7 << 8)) | (1 << 2); 55 | SCB.aircr.set(reset); 56 | } 57 | -------------------------------------------------------------------------------- /arch/cortex-m/src/support.rs: -------------------------------------------------------------------------------- 1 | use core::ops::FnOnce; 2 | 3 | #[cfg(all(target_arch = "arm", target_os = "none"))] 4 | #[inline(always)] 5 | /// NOP instruction 6 | pub fn nop() { 7 | unsafe { 8 | asm!("nop" :::: "volatile"); 9 | } 10 | } 11 | 12 | #[cfg(all(target_arch = "arm", target_os = "none"))] 13 | #[inline(always)] 14 | /// WFI instruction 15 | pub unsafe fn wfi() { 16 | asm!("wfi" :::: "volatile"); 17 | } 18 | 19 | #[cfg(all(target_arch = "arm", target_os = "none"))] 20 | pub unsafe fn atomic(f: F) -> R 21 | where 22 | F: FnOnce() -> R, 23 | { 24 | // Set PRIMASK 25 | asm!("cpsid i" :::: "volatile"); 26 | 27 | let res = f(); 28 | 29 | // Unset PRIMASK 30 | asm!("cpsie i" :::: "volatile"); 31 | return res; 32 | } 33 | 34 | #[cfg(all(target_arch = "arm", target_os = "none"))] 35 | #[lang = "eh_personality"] 36 | pub extern "C" fn eh_personality() {} 37 | 38 | // Mock implementations for tests on Travis-CI. 39 | #[cfg(not(any(target_arch = "arm", target_os = "none")))] 40 | /// NOP instruction (mock) 41 | pub fn nop() { 42 | unimplemented!() 43 | } 44 | 45 | #[cfg(not(any(target_arch = "arm", target_os = "none")))] 46 | /// WFI instruction (mock) 47 | pub unsafe fn wfi() { 48 | unimplemented!() 49 | } 50 | 51 | #[cfg(not(any(target_arch = "arm", target_os = "none")))] 52 | pub unsafe fn atomic(_f: F) -> R 53 | where 54 | F: FnOnce() -> R, 55 | { 56 | unimplemented!() 57 | } 58 | -------------------------------------------------------------------------------- /arch/cortex-m0/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cortexm0" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | kernel = { path = "../../kernel" } 9 | cortexm = { path = "../cortex-m" } 10 | -------------------------------------------------------------------------------- /arch/cortex-m3/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cortexm3" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | kernel = { path = "../../kernel" } 9 | cortexm = { path = "../cortex-m" } 10 | -------------------------------------------------------------------------------- /arch/cortex-m4/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cortexm4" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | kernel = { path = "../../kernel" } 9 | cortexm = { path = "../cortex-m" } 10 | -------------------------------------------------------------------------------- /arch/cortex-m4/src/mpu.rs: -------------------------------------------------------------------------------- 1 | ../../cortex-m3/src/mpu.rs -------------------------------------------------------------------------------- /arch/rv32i/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rv32i" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | kernel = { path = "../../kernel" } 9 | tock_rt0 = { path = "../../libraries/tock-rt0" } 10 | tock-registers = { path = "../../libraries/tock-register-interface" } 11 | riscv-csr = { path = "../../libraries/riscv-csr" } 12 | 13 | -------------------------------------------------------------------------------- /arch/rv32i/README.md: -------------------------------------------------------------------------------- 1 | RISC-V 32 Bit Integer Architecture (rv32i) 2 | ========================================== 3 | 4 | This crate contains startup code and other base support for 32 bit RISC-V 5 | chips. 6 | 7 | 8 | ISA Documentation 9 | ----------------- 10 | 11 | - [Specifications](https://github.com/riscv/riscv-isa-manual/releases) 12 | -------------------------------------------------------------------------------- /arch/rv32i/src/csr/mcycle.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::registers::register_bitfields; 2 | 3 | // myclce is the lower 32 bits of the number of elapsed cycles 4 | register_bitfields![u32, 5 | pub mcycle [ 6 | mcycle OFFSET(0) NUMBITS(32) [] 7 | ] 8 | ]; 9 | 10 | // myclceh is the higher 32 bits of the number of elapsed cycles 11 | register_bitfields![u32, 12 | pub mcycleh [ 13 | mcycleh OFFSET(0) NUMBITS(32) [] 14 | ] 15 | ]; 16 | -------------------------------------------------------------------------------- /arch/rv32i/src/csr/mepc.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::registers::register_bitfields; 2 | 3 | // mepc contains address of instruction where trap occurred 4 | register_bitfields![u32, 5 | pub mepc [ 6 | trap_addr OFFSET(0) NUMBITS(32) [] 7 | ] 8 | ]; 9 | -------------------------------------------------------------------------------- /arch/rv32i/src/csr/mie.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::registers::register_bitfields; 2 | 3 | // mtvec contains the address(es) of the trap handler 4 | register_bitfields![u32, 5 | pub mie [ 6 | usoft OFFSET(0) NUMBITS(1) [], 7 | ssoft OFFSET(1) NUMBITS(1) [], 8 | msoft OFFSET(3) NUMBITS(1) [], 9 | utimer OFFSET(4) NUMBITS(1) [], 10 | stimer OFFSET(5) NUMBITS(1) [], 11 | mtimer OFFSET(7) NUMBITS(1) [], 12 | uext OFFSET(8) NUMBITS(1) [], 13 | sext OFFSET(9) NUMBITS(1) [], 14 | mext OFFSET(11) NUMBITS(1) [] 15 | ] 16 | ]; 17 | -------------------------------------------------------------------------------- /arch/rv32i/src/csr/minstret.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::registers::register_bitfields; 2 | 3 | // minstret is the lower 32 bits of the number of elasped instructions 4 | register_bitfields![u32, 5 | pub minstret [ 6 | minstret OFFSET(0) NUMBITS(32) [] 7 | ] 8 | ]; 9 | 10 | // minstreth is the higher 32 bits of the number of elapsed instructions 11 | register_bitfields![u32, 12 | pub minstreth [ 13 | minstreth OFFSET(0) NUMBITS(32) [] 14 | ] 15 | ]; 16 | -------------------------------------------------------------------------------- /arch/rv32i/src/csr/mip.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::registers::register_bitfields; 2 | 3 | register_bitfields![u32, 4 | pub mip [ 5 | usoft OFFSET(0) NUMBITS(1) [], 6 | ssoft OFFSET(1) NUMBITS(1) [], 7 | msoft OFFSET(3) NUMBITS(1) [], 8 | utimer OFFSET(4) NUMBITS(1) [], 9 | stimer OFFSET(5) NUMBITS(1) [], 10 | mtimer OFFSET(7) NUMBITS(1) [], 11 | uext OFFSET(8) NUMBITS(1) [], 12 | sext OFFSET(9) NUMBITS(1) [], 13 | mext OFFSET(11) NUMBITS(1) [] 14 | ] 15 | ]; 16 | -------------------------------------------------------------------------------- /arch/rv32i/src/csr/mscratch.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::registers::register_bitfields; 2 | 3 | register_bitfields![u32, 4 | pub mscratch [ 5 | scratch OFFSET(0) NUMBITS(32) [] 6 | ] 7 | ]; 8 | -------------------------------------------------------------------------------- /arch/rv32i/src/csr/mstatus.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::registers::register_bitfields; 2 | 3 | register_bitfields![u32, 4 | pub mstatus [ 5 | uie OFFSET(0) NUMBITS(1) [], 6 | sie OFFSET(1) NUMBITS(1) [], 7 | mie OFFSET(3) NUMBITS(1) [], 8 | upie OFFSET(4) NUMBITS(1) [], 9 | spie OFFSET(5) NUMBITS(1) [], 10 | mpie OFFSET(7) NUMBITS(1) [], 11 | spp OFFSET(8) NUMBITS(1) [], 12 | mpp OFFSET(11) NUMBITS(2) [ 13 | USER = 0, 14 | SUPERVISOR = 1, 15 | RESERVED = 2, 16 | MACHINE = 3 17 | ] 18 | ] 19 | ]; 20 | -------------------------------------------------------------------------------- /arch/rv32i/src/csr/mtval.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::registers::register_bitfields; 2 | 3 | // mtval contains the address of an exception 4 | register_bitfields![u32, 5 | pub mtval [ 6 | exception_addr OFFSET(0) NUMBITS(32) [] 7 | ] 8 | ]; 9 | -------------------------------------------------------------------------------- /arch/rv32i/src/csr/mtvec.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::registers::{register_bitfields, LocalRegisterCopy}; 2 | 3 | // mtvec contains the address(es) of the trap handler 4 | register_bitfields![u32, 5 | pub mtvec [ 6 | trap_addr OFFSET(2) NUMBITS(30) [], 7 | mode OFFSET(0) NUMBITS(2) [ 8 | Direct = 0, 9 | Vectored = 1 10 | ] 11 | ] 12 | ]; 13 | 14 | trait MtvecHelpers { 15 | fn get_trap_address(&self) -> u32; 16 | } 17 | 18 | impl MtvecHelpers for LocalRegisterCopy { 19 | fn get_trap_address(&self) -> u32 { 20 | self.read(mtvec::trap_addr) << 2 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /arch/rv32i/src/csr/pmpaddr.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::registers::register_bitfields; 2 | 3 | register_bitfields![u32, 4 | pub pmpaddr [ 5 | addr OFFSET(0) NUMBITS(32) [] 6 | ] 7 | ]; 8 | -------------------------------------------------------------------------------- /arch/rv32i/src/csr/pmpconfig.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::registers::register_bitfields; 2 | 3 | // pmpcfg 4 | 5 | register_bitfields![u32, 6 | pub pmpcfg [ 7 | r0 OFFSET(0) NUMBITS(1) [], 8 | w0 OFFSET(1) NUMBITS(1) [], 9 | x0 OFFSET(2) NUMBITS(1) [], 10 | a0 OFFSET(3) NUMBITS(2) [ 11 | OFF = 0, 12 | TOR = 1, 13 | NA4 = 2, 14 | NAPOT = 3 15 | ], 16 | l0 OFFSET(7) NUMBITS(1) [], 17 | 18 | r1 OFFSET(8) NUMBITS(1) [], 19 | w1 OFFSET(9) NUMBITS(1) [], 20 | x1 OFFSET(10) NUMBITS(1) [], 21 | a1 OFFSET(11) NUMBITS(2) [ 22 | OFF = 0, 23 | TOR = 1, 24 | NA4 = 2, 25 | NAPOT = 3 26 | ], 27 | l1 OFFSET(15) NUMBITS(1) [], 28 | 29 | r2 OFFSET(16) NUMBITS(1) [], 30 | w2 OFFSET(17) NUMBITS(1) [], 31 | x2 OFFSET(18) NUMBITS(1) [], 32 | a2 OFFSET(19) NUMBITS(2) [ 33 | OFF = 0, 34 | TOR = 1, 35 | NA4 = 2, 36 | NAPOT = 3 37 | ], 38 | l2 OFFSET(23) NUMBITS(1) [], 39 | 40 | r3 OFFSET(24) NUMBITS(1) [], 41 | w3 OFFSET(25) NUMBITS(1) [], 42 | x3 OFFSET(26) NUMBITS(1) [], 43 | a3 OFFSET(27) NUMBITS(2) [ 44 | OFF = 0, 45 | TOR = 1, 46 | NA4 = 2, 47 | NAPOT = 3 48 | ], 49 | l3 OFFSET(31) NUMBITS(1) [] 50 | ] 51 | ]; 52 | -------------------------------------------------------------------------------- /arch/rv32i/src/csr/stvec.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::registers::{register_bitfields, LocalRegisterCopy}; 2 | 3 | // stvec contains the address(es) of the trap handler 4 | register_bitfields![u32, 5 | pub stvec [ 6 | trap_addr OFFSET(2) NUMBITS(30) [], 7 | mode OFFSET(0) NUMBITS(2) [ 8 | Direct = 0, 9 | Vectored = 1 10 | ] 11 | ] 12 | ]; 13 | 14 | trait StvecHelpers { 15 | fn get_trap_address(&self) -> u32; 16 | } 17 | 18 | impl StvecHelpers for LocalRegisterCopy { 19 | fn get_trap_address(&self) -> u32 { 20 | self.read(stvec::trap_addr) << 2 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /arch/rv32i/src/csr/utvec.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::registers::{register_bitfields, LocalRegisterCopy}; 2 | 3 | // utvec contains the address(es) of the trap handler 4 | register_bitfields![u32, 5 | pub utvec [ 6 | trap_addr OFFSET(2) NUMBITS(30) [], 7 | mode OFFSET(0) NUMBITS(2) [ 8 | Direct = 0, 9 | Vectored = 1 10 | ] 11 | ] 12 | ]; 13 | 14 | trait UtvecHelpers { 15 | fn get_trap_address(&self) -> u32; 16 | } 17 | 18 | impl UtvecHelpers for LocalRegisterCopy { 19 | fn get_trap_address(&self) -> u32 { 20 | self.read(utvec::trap_addr) << 2 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /arch/rv32i/src/support.rs: -------------------------------------------------------------------------------- 1 | //! Core low-level operations. 2 | 3 | use crate::csr::{mstatus::mstatus, CSR}; 4 | use core::ops::FnOnce; 5 | 6 | #[cfg(all(target_arch = "riscv32", target_os = "none"))] 7 | #[inline(always)] 8 | /// NOP instruction 9 | pub fn nop() { 10 | unsafe { 11 | asm!("nop" :::: "volatile"); 12 | } 13 | } 14 | 15 | #[cfg(all(target_arch = "riscv32", target_os = "none"))] 16 | #[inline(always)] 17 | /// WFI instruction 18 | pub unsafe fn wfi() { 19 | asm!("wfi" :::: "volatile"); 20 | } 21 | 22 | pub unsafe fn atomic(f: F) -> R 23 | where 24 | F: FnOnce() -> R, 25 | { 26 | let original_mstatus = CSR.mstatus.extract(); 27 | if original_mstatus.is_set(mstatus::mie) { 28 | CSR.mstatus 29 | .modify_no_read(original_mstatus, mstatus::mie::CLEAR); 30 | } 31 | let res = f(); 32 | if original_mstatus.is_set(mstatus::mie) { 33 | CSR.mstatus 34 | .modify_no_read(original_mstatus, mstatus::mie::SET); 35 | } 36 | res 37 | } 38 | 39 | #[cfg(all(target_arch = "riscv32", target_os = "none"))] 40 | #[lang = "eh_personality"] 41 | pub extern "C" fn eh_personality() {} 42 | 43 | // Mock implementations for tests on Travis-CI. 44 | #[cfg(not(any(target_arch = "riscv32", target_os = "none")))] 45 | /// NOP instruction (mock) 46 | pub fn nop() { 47 | unimplemented!() 48 | } 49 | 50 | #[cfg(not(any(target_arch = "riscv32", target_os = "none")))] 51 | /// WFI instruction (mock) 52 | pub unsafe fn wfi() { 53 | unimplemented!() 54 | } 55 | -------------------------------------------------------------------------------- /boards/README.md: -------------------------------------------------------------------------------- 1 | Platforms Supported by Tock 2 | =========================== 3 | 4 | The `/boards` directory contains the physical hardware platforms 5 | that Tock supports. 6 | 7 | | Board | Architecture | MCU | Interface | App deployment | 8 | |---------------------------------------------------|-----------------|------------|------------|----------------| 9 | | [Hail](hail/README.md) | ARM Cortex-M4 | SAM4LC8BA | Bootloader | tockloader | 10 | | [Imix](imix/README.md) | ARM Cortex-M4 | SAM4LC8CA | Bootloader | tockloader | 11 | | [Nordic nRF52-DK](nordic/nrf52dk/README.md) | ARM Cortex-M4 | nRF52832 | jLink | tockloader | 12 | | [Nordic nRF52840-DK](nordic/nrf52840dk/README.md) | ARM Cortex-M4 | nRF52840 | jLink | tockloader | 13 | | [ACD52832](acd52832/README.md) | ARM Cortex-M4 | nRF52832 | jLink | tockloader | 14 | | [TI LAUNCHXL-CC26x2](launchxl/README.md) | ARM Cortex-M4 | CC2652R | openocd | tockloader | 15 | | [ST Nucleo F446RE](nucleo_f446re/README.md) | ARM Cortex-M4 | STM32F446 | openocd | custom | 16 | | [ST Nucleo F429ZI](nucleo_f429zi/README.md) | ARM Cortex-M4 | STM32F429 | openocd | custom | 17 | | [SiFive HiFive1](hifive1/README.md) | RISC-V | FE310-G000 | openocd | tockloader | 18 | | [Digilent Arty A-7 100T](arty-e21/README.md) | RISC-V RV32IMAC | SiFive E21 | openocd | tockloader | 19 | | [Nexys Video OpenTitan](opentitan/README.md) | RISC-V RV32IMC | Ibex | custom | custom | 20 | -------------------------------------------------------------------------------- /boards/acd52832/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "acd52832" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | build = "build.rs" 6 | edition = "2018" 7 | 8 | [profile.dev] 9 | panic = "abort" 10 | lto = false 11 | opt-level = "z" 12 | debug = true 13 | 14 | [profile.release] 15 | panic = "abort" 16 | lto = true 17 | opt-level = "z" 18 | debug = true 19 | 20 | [dependencies] 21 | components = { path = "../components" } 22 | cortexm4 = { path = "../../arch/cortex-m4" } 23 | capsules = { path = "../../capsules" } 24 | kernel = { path = "../../kernel" } 25 | nrf52832 = { path = "../../chips/nrf52832" } 26 | nrf52dk_base = { path = "../nordic/nrf52dk_base" } 27 | -------------------------------------------------------------------------------- /boards/acd52832/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building the tock kernel for the nRF development kit 2 | 3 | TOCK_ARCH=cortex-m4 4 | TARGET=thumbv7em-none-eabi 5 | PLATFORM=acd52832 6 | 7 | include ../Makefile.common 8 | 9 | TOCKLOADER=tockloader 10 | 11 | # Where in the SAM4L flash to load the kernel with `tockloader` 12 | KERNEL_ADDRESS=0x00000 13 | 14 | # Upload programs over uart with tockloader 15 | ifdef PORT 16 | TOCKLOADER_GENERAL_FLAGS += --port $(PORT) 17 | endif 18 | 19 | TOCKLOADER_JTAG_FLAGS = --jlink --board nrf52dk 20 | 21 | # Upload the kernel over JTAG 22 | .PHONY: flash 23 | flash: target/$(TARGET)/release/$(PLATFORM).bin 24 | $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) $(TOCKLOADER_JTAG_FLAGS) $< 25 | -------------------------------------------------------------------------------- /boards/acd52832/README.md: -------------------------------------------------------------------------------- 1 | Platform-Specific Instructions: ACD52832 2 | ======================================== 3 | 4 | ![acd52832](http://aconno.de/wp-content/uploads/2016/03/img_modul-08.png) 5 | 6 | The [ACD52832](http://aconno.de/acd52832/) is a development board based on the 7 | nRF52832. It includes: 8 | 9 | - E-ink display 10 | - LEDs 11 | - Buttons 12 | - Buzzer 13 | - Temperature sensor 14 | - IR LED 15 | - Joystick 16 | - Potentiometer 17 | - 2x 60V DC Relays 18 | - 9DOF sensor 19 | - Light sensor 20 | 21 | ## Getting Started 22 | 23 | First, follow the [Tock Getting Started guide](../../doc/Getting_Started.md) 24 | 25 | JTAG is the preferred method to program. The development kit has an 26 | integrated JTAG debugger, you simply need to [install JTAG 27 | software](../../doc/Getting_Started.md#optional-requirements). 28 | 29 | ## Programming the kernel 30 | Once you have all software installed, you should be able to simply run 31 | make flash in this directory to install a fresh kernel. 32 | 33 | ## Programming user-level applications 34 | You can program an application via JTAG using Tockloader: 35 | 36 | ```bash 37 | $ tockloader install --jlink --board nrf52dk 38 | ``` 39 | 40 | ## TODO 41 | 42 | - Implement panic! print in io.rs. 43 | 44 | 45 | -------------------------------------------------------------------------------- /boards/acd52832/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("cargo:rerun-if-changed=layout.ld"); 3 | println!("cargo:rerun-if-changed=../kernel_layout.ld"); 4 | } 5 | -------------------------------------------------------------------------------- /boards/acd52832/layout.ld: -------------------------------------------------------------------------------- 1 | /* Memory Space Definitions, 512K flash, 64K ram */ 2 | MEMORY 3 | { 4 | rom (rx) : ORIGIN = 0x00000000, LENGTH = 128K 5 | prog (rx) : ORIGIN = 0x00030000, LENGTH = 384K 6 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K 7 | } 8 | 9 | MPU_MIN_ALIGN = 8K; 10 | 11 | INCLUDE ../kernel_layout.ld 12 | -------------------------------------------------------------------------------- /boards/acd52832/src/io.rs: -------------------------------------------------------------------------------- 1 | use core::panic::PanicInfo; 2 | 3 | use kernel::debug; 4 | use kernel::hil::led; 5 | use nrf52832::gpio::Pin; 6 | 7 | /// Panic. 8 | #[cfg(not(test))] 9 | #[no_mangle] 10 | #[panic_handler] 11 | pub unsafe extern "C" fn panic_fmt(_pi: &PanicInfo) -> ! { 12 | const LED1_PIN: Pin = Pin::P0_22; 13 | let led = &mut led::LedLow::new(&mut nrf52832::gpio::PORT[LED1_PIN]); 14 | debug::panic_blink_forever(&mut [led]) 15 | } 16 | -------------------------------------------------------------------------------- /boards/arty-e21/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "arty-e21" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | build = "build.rs" 6 | edition = "2018" 7 | 8 | [profile.dev] 9 | panic = "abort" 10 | lto = false 11 | opt-level = "z" 12 | debug = true 13 | 14 | [profile.release] 15 | panic = "abort" 16 | lto = true 17 | opt-level = "z" 18 | debug = true 19 | 20 | [dependencies] 21 | components = { path = "../components" } 22 | rv32i = { path = "../../arch/rv32i" } 23 | capsules = { path = "../../capsules" } 24 | kernel = { path = "../../kernel" } 25 | arty_e21 = { path = "../../chips/arty_e21" } 26 | sifive = { path = "../../chips/sifive" } 27 | -------------------------------------------------------------------------------- /boards/arty-e21/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building the tock kernel for the HiFive1 platform 2 | 3 | TARGET=riscv32imac-unknown-none-elf 4 | PLATFORM=arty-e21 5 | 6 | include ../Makefile.common 7 | 8 | TOCKLOADER=tockloader 9 | KERNEL_ADDRESS=0x400000 10 | 11 | TOCKLOADER_OPENOCD_FLAGS = --openocd --board arty 12 | 13 | .PHONY: flash-tockloader 14 | flash-tockloader: target/$(TARGET)/release/$(PLATFORM).bin 15 | $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) $(TOCKLOADER_OPENOCD_FLAGS) $< 16 | 17 | flash: target/$(TARGET)/release/$(PLATFORM).bin 18 | openocd -f openocd/arty-openocd-digilent.cfg \ 19 | -c "init; jtagspi_init 0 openocd/bscan_spi_xc7a100t.bit; jtagspi_program $< 0x400000; shutdown" 20 | 21 | flash-e21: core/sifive_coreip_E21_AHB_rtl_eval_v19_05p1_release_arty_a7_100t.mcs 22 | openocd -f openocd/arty-openocd-digilent.cfg \ 23 | -c "init; jtagspi_init 0 openocd/bscan_spi_xc7a100t.bit; jtagspi_program $< 0x0; shutdown" 24 | 25 | -------------------------------------------------------------------------------- /boards/arty-e21/README.md: -------------------------------------------------------------------------------- 1 | SiFive E21 Core on ARTY FPGA Board 2 | ================= 3 | 4 | - SiFive E21 Core IP v19p05 5 | - Digilent Arty Artix-7 100T Development Board 6 | 7 | 8 | Required Tools 9 | -------------- 10 | 11 | - OpenOCD 12 | 13 | 14 | Setup 15 | ----- 16 | 17 | The first step is to flash the SiFive E21 core on to the FPGA. To do this, 18 | connect the ARTY board over USB and run: 19 | 20 | ``` 21 | $ make flash-e21 22 | ``` 23 | 24 | It may display that many memory locations are incorrect. This didn't seem 25 | to matter when I tried this. 26 | 27 | After that has finished, press the `PROG` red button on the top left of the 28 | board. After a few seconds, one of the RGB LEDs should start pulsing colors. 29 | It also prints over the serial connection. To see that, run: 30 | 31 | ``` 32 | $ tockloader listen 33 | ``` 34 | 35 | and select the option with the larger number. 36 | 37 | 38 | Programming 39 | ----------- 40 | 41 | To load a new kernel on to the board, run: 42 | 43 | ``` 44 | $ make flash 45 | ``` 46 | 47 | -------------------------------------------------------------------------------- /boards/arty-e21/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("cargo:rerun-if-changed=layout.ld"); 3 | println!("cargo:rerun-if-changed=../kernel_layout.ld"); 4 | } 5 | -------------------------------------------------------------------------------- /boards/arty-e21/core/README.md: -------------------------------------------------------------------------------- 1 | RISC-V Cores 2 | ============ 3 | 4 | This folder contains FPGA bitstreams for RISC-V cores. 5 | -------------------------------------------------------------------------------- /boards/arty-e21/layout.ld: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | rom (rx) : ORIGIN = 0x40400000, LENGTH = 0x00030000 4 | prog (rx) : ORIGIN = 0x40430000, LENGTH = 1M 5 | ram (rwx) : ORIGIN = 0x80000000, LENGTH = 64K 6 | } 7 | 8 | MPU_MIN_ALIGN = 8K; 9 | 10 | INCLUDE ../kernel_layout.ld 11 | -------------------------------------------------------------------------------- /boards/arty-e21/openocd/arty-openocd-digilent.cfg: -------------------------------------------------------------------------------- 1 | # 2 | # Digilent Arty with Xilinx Artix-7 FPGA 3 | # 4 | # http://store.digilentinc.com/arty-artix-7-fpga-development-board-for-makers-and-hobbyists/ 5 | # 6 | 7 | # iManufacturer 1 Digilent 8 | # iProduct 2 Digilent USB Device 9 | # iSerial 3 210319A28C7F 10 | 11 | interface ftdi 12 | #ftdi_device_desc "Digilent USB Device" 13 | ftdi_vid_pid 0x0403 0x6010 14 | # channel 1 does not have any functionality 15 | ftdi_channel 0 16 | # just TCK TDI TDO TMS, no reset 17 | ftdi_layout_init 0x0088 0x008b 18 | reset_config none 19 | adapter_khz 10000 20 | 21 | source [find cpld/xilinx-xc7.cfg] 22 | source [find cpld/jtagspi.cfg] 23 | -------------------------------------------------------------------------------- /boards/arty-e21/openocd/bscan_spi_xc7a100t.bit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/boards/arty-e21/openocd/bscan_spi_xc7a100t.bit -------------------------------------------------------------------------------- /boards/arty-e21/openocd/bscan_spi_xc7a35t.bit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/boards/arty-e21/openocd/bscan_spi_xc7a35t.bit -------------------------------------------------------------------------------- /boards/arty-e21/src/io.rs: -------------------------------------------------------------------------------- 1 | use arty_e21; 2 | use core::fmt::Write; 3 | use core::panic::PanicInfo; 4 | use core::str; 5 | use kernel::debug; 6 | use kernel::debug::IoWrite; 7 | use kernel::hil::gpio; 8 | use kernel::hil::led; 9 | use rv32i; 10 | 11 | use crate::CHIP; 12 | use crate::PROCESSES; 13 | 14 | struct Writer; 15 | 16 | static mut WRITER: Writer = Writer {}; 17 | 18 | impl Write for Writer { 19 | fn write_str(&mut self, s: &str) -> ::core::fmt::Result { 20 | debug!("{}", s); 21 | Ok(()) 22 | } 23 | } 24 | 25 | impl IoWrite for Writer { 26 | fn write(&mut self, buf: &[u8]) { 27 | let _ = self.write_str(unsafe { str::from_utf8_unchecked(buf) }); 28 | } 29 | } 30 | 31 | /// Panic handler. 32 | #[cfg(not(test))] 33 | #[no_mangle] 34 | #[panic_handler] 35 | pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! { 36 | // turn off the non panic leds, just in case 37 | let led_green = &arty_e21::gpio::PORT[19]; 38 | gpio::Pin::make_output(led_green); 39 | gpio::Pin::set(led_green); 40 | 41 | let led_blue = &arty_e21::gpio::PORT[21]; 42 | gpio::Pin::make_output(led_blue); 43 | gpio::Pin::set(led_blue); 44 | 45 | let led_red = &mut led::LedLow::new(&mut arty_e21::gpio::PORT[22]); 46 | let writer = &mut WRITER; 47 | debug::panic( 48 | &mut [led_red], 49 | writer, 50 | pi, 51 | &rv32i::support::nop, 52 | &PROCESSES, 53 | &CHIP, 54 | ) 55 | } 56 | -------------------------------------------------------------------------------- /boards/arty-e21/src/timer_test.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | use kernel::debug; 4 | use kernel::hil::time::{self, Alarm}; 5 | 6 | pub struct TimerTest<'a, A: Alarm<'a>> { 7 | alarm: &'a A, 8 | } 9 | 10 | impl> TimerTest<'a, A> { 11 | pub const fn new(alarm: &'a A) -> TimerTest<'a, A> { 12 | TimerTest { alarm: alarm } 13 | } 14 | 15 | pub fn start(&self) { 16 | debug!("starting"); 17 | let start = self.alarm.now(); 18 | let exp = start + 99999; 19 | self.alarm.set_alarm(exp); 20 | } 21 | } 22 | 23 | impl> time::AlarmClient for TimerTest<'a, A> { 24 | fn fired(&self) { 25 | debug!("timer!!"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /boards/components/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "components" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | capsules = { path = "../../capsules" } 9 | kernel = { path = "../../kernel" } 10 | -------------------------------------------------------------------------------- /boards/components/src/led.rs: -------------------------------------------------------------------------------- 1 | //! Components for collections of LEDs. 2 | //! 3 | //! Usage 4 | //! ----- 5 | //! ```rust 6 | //! let led = components::led::LedsComponent::new().finalize(components::led_component_helper!( 7 | //! (&nrf52840::gpio::PORT[LED_RED_PIN], capsules::led::ActivationMode::ActiveLow), 8 | //! (&nrf52840::gpio::PORT[LED_GREEN_PIN], capsules::led::ActivationMode::ActiveLow), 9 | //! (&nrf52840::gpio::PORT[LED_BLUE_PIN], capsules::led::ActivationMode::ActiveLow) 10 | //! )); 11 | //! ``` 12 | 13 | use capsules; 14 | use kernel::component::Component; 15 | use kernel::static_init; 16 | 17 | #[macro_export] 18 | macro_rules! led_component_helper { 19 | ($($P:expr),+ ) => {{ 20 | use kernel::count_expressions; 21 | use kernel::static_init; 22 | const NUM_LEDS: usize = count_expressions!($($P),+); 23 | 24 | static_init!( 25 | [( 26 | &'static dyn kernel::hil::gpio::Pin, 27 | capsules::led::ActivationMode 28 | ); NUM_LEDS], 29 | [ 30 | $($P,)* 31 | ] 32 | ) 33 | };}; 34 | } 35 | 36 | pub struct LedsComponent {} 37 | 38 | impl LedsComponent { 39 | pub fn new() -> LedsComponent { 40 | LedsComponent {} 41 | } 42 | } 43 | 44 | impl Component for LedsComponent { 45 | type StaticInput = &'static [( 46 | &'static dyn kernel::hil::gpio::Pin, 47 | capsules::led::ActivationMode, 48 | )]; 49 | type Output = &'static capsules::led::LED<'static>; 50 | 51 | unsafe fn finalize(&mut self, pins: Self::StaticInput) -> Self::Output { 52 | static_init!(capsules::led::LED<'static>, capsules::led::LED::new(pins)) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /boards/components/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | #![feature(in_band_lifetimes)] 3 | 4 | #[macro_use] 5 | pub mod gpio; 6 | #[macro_use] 7 | pub mod led; 8 | #[macro_use] 9 | pub mod button; 10 | 11 | pub mod alarm; 12 | pub mod console; 13 | pub mod crc; 14 | pub mod debug_writer; 15 | pub mod isl29035; 16 | pub mod lldb; 17 | pub mod nrf51822; 18 | pub mod process_console; 19 | pub mod rng; 20 | pub mod si7021; 21 | pub mod spi; 22 | -------------------------------------------------------------------------------- /boards/hail/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hail" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | build = "build.rs" 6 | edition = "2018" 7 | 8 | [profile.dev] 9 | panic = "abort" 10 | lto = false 11 | opt-level = "z" 12 | debug = true 13 | 14 | [profile.release] 15 | panic = "abort" 16 | lto = true 17 | opt-level = "z" 18 | debug = true 19 | 20 | [dependencies] 21 | components = { path = "../components" } 22 | cortexm4 = { path = "../../arch/cortex-m4" } 23 | capsules = { path = "../../capsules" } 24 | kernel = { path = "../../kernel" } 25 | sam4l = { path = "../../chips/sam4l" } 26 | -------------------------------------------------------------------------------- /boards/hail/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building the tock kernel for the Hail platform 2 | 3 | TARGET=thumbv7em-none-eabi 4 | PLATFORM=hail 5 | 6 | include ../Makefile.common 7 | 8 | TOCKLOADER=tockloader 9 | 10 | # Where in the SAM4L flash to load the kernel with `tockloader` 11 | KERNEL_ADDRESS=0x10000 12 | 13 | # Upload programs over uart with tockloader 14 | ifdef PORT 15 | TOCKLOADER_GENERAL_FLAGS += --port $(PORT) 16 | endif 17 | 18 | TOCKLOADER_JTAG_FLAGS = --jtag --board hail --arch cortex-m4 --jtag-device ATSAM4LC8C 19 | 20 | .PHONY: program 21 | program: target/$(TARGET)/release/$(PLATFORM).bin 22 | $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) $< 23 | 24 | # upload kernel over JTAG 25 | .PHONY: flash 26 | flash: target/$(TARGET)/release/$(PLATFORM).bin 27 | $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) $(TOCKLOADER_JTAG_FLAGS) $< 28 | 29 | .PHONY: flash-debug 30 | flash-debug: target/$(TARGET)/debug/$(PLATFORM).bin 31 | $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) $(TOCKLOADER_JTAG_FLAGS) $< 32 | 33 | # Command to flash the bootloader. Flashes the bootloader onto the SAM4L. 34 | .PHONY: flash-bootloader 35 | flash-bootloader: bootloader/bootloader.bin 36 | $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address 0 $(TOCKLOADER_JTAG_FLAGS) $< 37 | -------------------------------------------------------------------------------- /boards/hail/bootloader/README.md: -------------------------------------------------------------------------------- 1 | Hail Bootloader 2 | =============== 3 | 4 | Based on the storm bootloader, the source and more information can be found on 5 | [github](https://github.com/tock/tock-bootloader). 6 | 7 | -------------------------------------------------------------------------------- /boards/hail/bootloader/bootloader.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/boards/hail/bootloader/bootloader.bin -------------------------------------------------------------------------------- /boards/hail/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("cargo:rerun-if-changed=layout.ld"); 3 | println!("cargo:rerun-if-changed=chip_layout.ld"); 4 | println!("cargo:rerun-if-changed=../kernel_layout.ld"); 5 | } 6 | -------------------------------------------------------------------------------- /boards/hail/chip_layout.ld: -------------------------------------------------------------------------------- 1 | /* Memory Spaces Definitions, 448K flash, 64K ram */ 2 | /* Bootloader is at address 0x00000000 */ 3 | MEMORY 4 | { 5 | rom (rx) : ORIGIN = 0x00010000, LENGTH = 0x00020000 6 | prog (rx) : ORIGIN = 0x00030000, LENGTH = 0x00040000 7 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000 8 | } 9 | 10 | MPU_MIN_ALIGN = 8K; 11 | -------------------------------------------------------------------------------- /boards/hail/connect.cfg: -------------------------------------------------------------------------------- 1 | 2 | interface jlink 3 | transport select swd 4 | source [find target/at91sam4lXX.cfg] 5 | -------------------------------------------------------------------------------- /boards/hail/debug.gdb: -------------------------------------------------------------------------------- 1 | 2 | target remote :3333 3 | monitor reset 4 | monitor reset 5 | load 6 | monitor reset 7 | -------------------------------------------------------------------------------- /boards/hail/jlink/gdb_session.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | arm-none-eabi-gdb -x hail.gdb 3 | -------------------------------------------------------------------------------- /boards/hail/jlink/hail.gdb: -------------------------------------------------------------------------------- 1 | target remote localhost:2331 2 | monitor speed 30 3 | file ../target/thumbv7em-none-eabi/release/hail 4 | monitor reset 5 | # 6 | # CPU core initialization (to be done by user) 7 | # 8 | # Set the processor mode 9 | # monitor reg cpsr = 0xd3 10 | # Set auto JTAG speed 11 | monitor speed auto 12 | # Setup GDB FOR FASTER DOWNLOADS 13 | set remote memory-write-packet-size 1024 14 | set remote memory-write-packet-size fixed 15 | # tui enable 16 | # layout split 17 | # layout service_pending_interrupts 18 | b reset_handler 19 | -------------------------------------------------------------------------------- /boards/hail/jlink/jlink_gdbserver.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | JLinkGDBServer -device ATSAM4LC8C -speed 1200 -if swd -AutoConnect 1 -port 2331 3 | -------------------------------------------------------------------------------- /boards/hail/layout.ld: -------------------------------------------------------------------------------- 1 | INCLUDE ./chip_layout.ld 2 | INCLUDE ../kernel_layout.ld 3 | -------------------------------------------------------------------------------- /boards/hail/media/hail-lab11llc_pinout_and_guide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/boards/hail/media/hail-lab11llc_pinout_and_guide.png -------------------------------------------------------------------------------- /boards/hail/media/hail_breadboard_1000x859.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/boards/hail/media/hail_breadboard_1000x859.jpg -------------------------------------------------------------------------------- /boards/hail/media/hail_reva_noheaders_1000x536.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/boards/hail/media/hail_reva_noheaders_1000x536.jpg -------------------------------------------------------------------------------- /boards/hail/media/hail_reva_noheaders_labeled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/boards/hail/media/hail_reva_noheaders_labeled.png -------------------------------------------------------------------------------- /boards/hail/src/test_take_map_cell.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::cells::MapCell; 2 | use kernel::debug; 3 | 4 | pub unsafe fn test_take_map_cell() { 5 | static FOO: u32 = 1234; 6 | 7 | static mut MC_REF: MapCell<&'static u32> = MapCell::new(&FOO); 8 | test_map_cell(&MC_REF); 9 | 10 | static mut MC1: MapCell<[[u8; 256]; 1]> = MapCell::new([[125; 256]; 1]); 11 | test_map_cell(&MC1); 12 | 13 | static mut MC2: MapCell<[[u8; 256]; 2]> = MapCell::new([[125; 256]; 2]); 14 | test_map_cell(&MC2); 15 | 16 | static mut MC3: MapCell<[[u8; 256]; 3]> = MapCell::new([[125; 256]; 3]); 17 | test_map_cell(&MC3); 18 | 19 | static mut MC4: MapCell<[[u8; 256]; 4]> = MapCell::new([[125; 256]; 4]); 20 | test_map_cell(&MC4); 21 | 22 | static mut MC5: MapCell<[[u8; 256]; 5]> = MapCell::new([[125; 256]; 5]); 23 | test_map_cell(&MC5); 24 | 25 | static mut MC6: MapCell<[[u8; 256]; 6]> = MapCell::new([[125; 256]; 6]); 26 | test_map_cell(&MC6); 27 | 28 | static mut MC7: MapCell<[[u8; 256]; 7]> = MapCell::new([[125; 256]; 7]); 29 | test_map_cell(&MC7); 30 | } 31 | 32 | #[inline(never)] 33 | #[allow(unused_unsafe)] 34 | unsafe fn test_map_cell<'a, A>(tc: &MapCell) { 35 | let dwt_ctl: *mut u32 = 0xE0001000 as *mut u32; 36 | let dwt_cycles: *mut u32 = 0xE0001004 as *mut u32; 37 | let demcr: *mut u32 = 0xE000EDFC as *mut u32; 38 | 39 | ::core::ptr::write_volatile(demcr, 0x01000000); 40 | ::core::ptr::write_volatile(dwt_cycles, 0); 41 | ::core::ptr::write_volatile(dwt_ctl, ::core::ptr::read_volatile(dwt_ctl) | 1); 42 | tc.map(|_| ()); 43 | let end = ::core::ptr::read_volatile(dwt_cycles); 44 | debug!("time: {}, size: {}", end, ::core::mem::size_of_val(tc)); 45 | } 46 | -------------------------------------------------------------------------------- /boards/hifive1/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hifive1" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | build = "build.rs" 6 | edition = "2018" 7 | 8 | [profile.dev] 9 | panic = "abort" 10 | lto = false 11 | opt-level = "z" 12 | debug = true 13 | 14 | [profile.release] 15 | panic = "abort" 16 | lto = true 17 | opt-level = "z" 18 | debug = true 19 | 20 | [dependencies] 21 | components = { path = "../components" } 22 | rv32i = { path = "../../arch/rv32i" } 23 | capsules = { path = "../../capsules" } 24 | kernel = { path = "../../kernel" } 25 | e310x = { path = "../../chips/e310x" } 26 | sifive = { path = "../../chips/sifive" } 27 | -------------------------------------------------------------------------------- /boards/hifive1/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building the tock kernel for the HiFive1 platform 2 | 3 | TARGET=riscv32imac-unknown-none-elf 4 | PLATFORM=hifive1 5 | 6 | include ../Makefile.common 7 | 8 | flash: target/$(TARGET)/release/$(PLATFORM).elf 9 | openocd \ 10 | -c "source [find board/sifive-hifive1.cfg]; flash protect 0 64 last off; program $<; resume 0x20400000; exit" 11 | -------------------------------------------------------------------------------- /boards/hifive1/README.md: -------------------------------------------------------------------------------- 1 | SiFive HiFive1 RISC-V Board 2 | ================= 3 | 4 | - https://www.sifive.com/boards/hifive1 5 | 6 | Arduino-compatible dev board for RISC-V. This is the first release of this 7 | board ("Rev A01"). 8 | 9 | Programming 10 | ----------- 11 | 12 | Running `make flash` should load the kernel onto the board. You will need a 13 | relatively new (i.e. from git) version of OpenOCD. 14 | 15 | The kernel also assumes there is the default HiFive1 software bootloader running 16 | on the chip. 17 | 18 | Running in QEMU 19 | --------------- 20 | 21 | The HiFive1 application can be run in the QEMU emulation platform, allowing quick and easy testing. 22 | 23 | QEMU can be started with Tock using the following arguments: 24 | ``` 25 | qemu-system-riscv32 -M sifive_e -kernel boards/hifive1/target/riscv32imac-unknown-none-elf/release/hifive1.elf -nographic 26 | ``` 27 | 28 | QEMU can be started with Tock and a userspace app using the following arguments: 29 | ``` 30 | qemu-system-riscv32 -M sifive_e -kernel boards/hifive1/target/riscv32imac-unknown-none-elf/release/hifive1.elf -device loader,file=./examples/hello.tbf,addr=0x20430000 -nographic 31 | ``` 32 | -------------------------------------------------------------------------------- /boards/hifive1/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("cargo:rerun-if-changed=layout.ld"); 3 | println!("cargo:rerun-if-changed=../kernel_layout.ld"); 4 | } 5 | -------------------------------------------------------------------------------- /boards/hifive1/layout.ld: -------------------------------------------------------------------------------- 1 | /* The HiFive1a board has 512 MB of flash. The first 0x400000 is reserved for 2 | * the default bootloader provided by SiFive. We also reserve room for apps to 3 | * make all of the linker files work, but don't really support them on this 4 | * chip. 5 | */ 6 | 7 | MEMORY 8 | { 9 | rom (rx) : ORIGIN = 0x20400000, LENGTH = 0x30000 10 | prog (rx) : ORIGIN = 0x20430000, LENGTH = 512M-0x430000 11 | ram (rwx) : ORIGIN = 0x80000000, LENGTH = 16K 12 | } 13 | 14 | MPU_MIN_ALIGN = 1K; 15 | 16 | INCLUDE ../kernel_layout.ld 17 | -------------------------------------------------------------------------------- /boards/hifive1/src/io.rs: -------------------------------------------------------------------------------- 1 | use core::fmt::Write; 2 | use core::panic::PanicInfo; 3 | use core::str; 4 | use e310x; 5 | use kernel::debug; 6 | use kernel::debug::IoWrite; 7 | use kernel::hil::gpio; 8 | use kernel::hil::led; 9 | use rv32i; 10 | 11 | use crate::CHIP; 12 | use crate::PROCESSES; 13 | 14 | struct Writer {} 15 | 16 | static mut WRITER: Writer = Writer {}; 17 | 18 | impl Write for Writer { 19 | fn write_str(&mut self, s: &str) -> ::core::fmt::Result { 20 | self.write(s.as_bytes()); 21 | Ok(()) 22 | } 23 | } 24 | 25 | impl IoWrite for Writer { 26 | fn write(&mut self, buf: &[u8]) { 27 | unsafe { 28 | e310x::uart::UART0.transmit_sync(buf); 29 | } 30 | } 31 | } 32 | 33 | /// Panic handler. 34 | #[cfg(not(test))] 35 | #[no_mangle] 36 | #[panic_handler] 37 | pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! { 38 | // turn off the non panic leds, just in case 39 | let led_green = &e310x::gpio::PORT[19]; 40 | gpio::Pin::make_output(led_green); 41 | gpio::Pin::set(led_green); 42 | 43 | let led_blue = &e310x::gpio::PORT[21]; 44 | gpio::Pin::make_output(led_blue); 45 | gpio::Pin::set(led_blue); 46 | 47 | let led_red = &mut led::LedLow::new(&mut e310x::gpio::PORT[22]); 48 | let writer = &mut WRITER; 49 | 50 | debug::panic( 51 | &mut [led_red], 52 | writer, 53 | pi, 54 | &rv32i::support::nop, 55 | &PROCESSES, 56 | &CHIP, 57 | ) 58 | } 59 | -------------------------------------------------------------------------------- /boards/imix/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "imix" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | build = "build.rs" 6 | edition = "2018" 7 | 8 | [profile.dev] 9 | panic = "abort" 10 | lto = false 11 | opt-level = "z" 12 | debug = true 13 | 14 | [profile.release] 15 | panic = "abort" 16 | lto = true 17 | opt-level = "z" 18 | debug = true 19 | 20 | [dependencies] 21 | components = { path = "../components" } 22 | cortexm4 = { path = "../../arch/cortex-m4" } 23 | capsules = { path = "../../capsules" } 24 | kernel = { path = "../../kernel" } 25 | sam4l = { path = "../../chips/sam4l" } 26 | -------------------------------------------------------------------------------- /boards/imix/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building the tock kernel for the Imix platform 2 | 3 | TARGET=thumbv7em-none-eabi 4 | PLATFORM=imix 5 | 6 | include ../Makefile.common 7 | 8 | TOCKLOADER=tockloader 9 | 10 | # Where in the SAM4L flash to load the kernel with `tockloader` 11 | KERNEL_ADDRESS=0x10000 12 | 13 | # Upload programs over uart with tockloader 14 | ifdef PORT 15 | TOCKLOADER_GENERAL_FLAGS += --port $(PORT) 16 | endif 17 | 18 | TOCKLOADER_JTAG_FLAGS = --jtag --board imix --arch cortex-m4 --jtag-device ATSAM4LC8C 19 | 20 | .PHONY: program 21 | program: target/$(TARGET)/release/$(PLATFORM).bin 22 | $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) $< 23 | 24 | # upload kernel over JTAG 25 | .PHONY: flash 26 | flash: target/$(TARGET)/release/$(PLATFORM).bin 27 | $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) $(TOCKLOADER_JTAG_FLAGS) $< 28 | 29 | .PHONY: flash-debug 30 | flash-debug: target/$(TARGET)/debug/$(PLATFORM).bin 31 | $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) $(TOCKLOADER_JTAG_FLAGS) $< 32 | 33 | # Command to flash the bootloader. Flashes the bootloader onto the SAM4L. 34 | .PHONY: flash-bootloader 35 | flash-bootloader: bootloader/bootloader.bin 36 | $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address 0 $(TOCKLOADER_JTAG_FLAGS) $< 37 | -------------------------------------------------------------------------------- /boards/imix/bootloader/README.md: -------------------------------------------------------------------------------- 1 | Imix Bootloader 2 | =============== 3 | 4 | Based on the storm bootloader, the source and more information can be found on 5 | [github](https://github.com/tock/tock-bootloader). 6 | 7 | -------------------------------------------------------------------------------- /boards/imix/bootloader/bootloader.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/boards/imix/bootloader/bootloader.bin -------------------------------------------------------------------------------- /boards/imix/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("cargo:rerun-if-changed=layout.ld"); 3 | println!("cargo:rerun-if-changed=../kernel_layout.ld"); 4 | } 5 | -------------------------------------------------------------------------------- /boards/imix/chip_layout.ld: -------------------------------------------------------------------------------- 1 | /* Memory Spaces Definitions, 448K flash, 64K ram */ 2 | /* Use bootloader starting at 0x0000 */ 3 | MEMORY 4 | { 5 | rom (rx) : ORIGIN = 0x00010000, LENGTH = 0x00030000 6 | prog (rx) : ORIGIN = 0x00040000, LENGTH = 0x00040000 7 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000 8 | } 9 | 10 | MPU_MIN_ALIGN = 8K; 11 | -------------------------------------------------------------------------------- /boards/imix/connect.cfg: -------------------------------------------------------------------------------- 1 | interface jlink 2 | transport select swd 3 | source [find target/at91sam4lXX.cfg] 4 | -------------------------------------------------------------------------------- /boards/imix/debug.gdb: -------------------------------------------------------------------------------- 1 | 2 | target remote :3333 3 | monitor reset 4 | monitor reset 5 | load 6 | monitor reset 7 | -------------------------------------------------------------------------------- /boards/imix/layout.ld: -------------------------------------------------------------------------------- 1 | INCLUDE ./chip_layout.ld 2 | INCLUDE ../kernel_layout.ld 3 | -------------------------------------------------------------------------------- /boards/imix/src/aes_ccm_test.rs: -------------------------------------------------------------------------------- 1 | //! To run this test, include the code 2 | //! ``` 3 | //! aes_ccm_test::run(); 4 | //! ``` 5 | //! In the boot sequence. If it runs correctly, you should see the following 6 | //! output: 7 | //! 8 | //! aes_ccm_test passed: (current_test=0, encrypting=true, tag_is_valid=true) 9 | //! aes_ccm_test passed: (current_test=0, encrypting=false, tag_is_valid=true) 10 | //! aes_ccm_test passed: (current_test=1, encrypting=true, tag_is_valid=true) 11 | //! aes_ccm_test passed: (current_test=1, encrypting=false, tag_is_valid=true) 12 | //! aes_ccm_test passed: (current_test=2, encrypting=true, tag_is_valid=true) 13 | //! aes_ccm_test passed: (current_test=2, encrypting=false, tag_is_valid=true) 14 | 15 | use capsules::aes_ccm; 16 | use capsules::test::aes_ccm::Test; 17 | use kernel::hil::symmetric_encryption::{AES128, AES128CCM, AES128_BLOCK_SIZE}; 18 | use kernel::static_init; 19 | use sam4l::aes::{Aes, AES}; 20 | 21 | pub unsafe fn run() { 22 | let ccm = static_init_ccm(); 23 | AES.set_client(ccm); 24 | 25 | let t = static_init_test(ccm); 26 | ccm.set_client(t); 27 | 28 | t.run(); 29 | } 30 | 31 | unsafe fn static_init_ccm() -> &'static mut aes_ccm::AES128CCM<'static, Aes<'static>> { 32 | const CRYPT_SIZE: usize = 7 * AES128_BLOCK_SIZE; 33 | let crypt_buf = static_init!([u8; CRYPT_SIZE], [0x00; CRYPT_SIZE]); 34 | static_init!( 35 | aes_ccm::AES128CCM<'static, Aes<'static>>, 36 | aes_ccm::AES128CCM::new(&AES, crypt_buf) 37 | ) 38 | } 39 | 40 | type AESCCM = aes_ccm::AES128CCM<'static, Aes<'static>>; 41 | 42 | unsafe fn static_init_test(aes_ccm: &'static AESCCM) -> &'static mut Test<'static, AESCCM> { 43 | let data = static_init!([u8; 4 * AES128_BLOCK_SIZE], [0x00; 4 * AES128_BLOCK_SIZE]); 44 | static_init!(Test<'static, AESCCM>, Test::new(aes_ccm, data)) 45 | } 46 | -------------------------------------------------------------------------------- /boards/imix/src/imix_components/analog_comparator.rs: -------------------------------------------------------------------------------- 1 | //! Component for the Analog Comparator on the imix board. 2 | //! 3 | //! This provides one Component, AcComponent, which implements 4 | //! a userspace syscall interface to the SAM4L ACIFC. It provides 5 | //! 4 AC channels, AC0-AC3. 6 | //! 7 | //! Usage 8 | //! ----- 9 | //! ```rust 10 | //! let ac = AcComponent::new().finalize(()); 11 | //! ``` 12 | 13 | // Author: Danilo Verhaert 14 | // Last modified: August 7th, 2018 15 | 16 | #![allow(dead_code)] // Components are intended to be conditionally included 17 | 18 | use capsules::analog_comparator; 19 | use kernel::component::Component; 20 | use kernel::static_init; 21 | 22 | pub struct AcComponent {} 23 | 24 | impl AcComponent { 25 | pub fn new() -> AcComponent { 26 | AcComponent {} 27 | } 28 | } 29 | 30 | impl Component for AcComponent { 31 | type StaticInput = (); 32 | type Output = 33 | &'static analog_comparator::AnalogComparator<'static, sam4l::acifc::Acifc<'static>>; 34 | 35 | unsafe fn finalize(&mut self, _s: Self::StaticInput) -> Self::Output { 36 | let ac_channels = static_init!( 37 | [&'static sam4l::acifc::AcChannel; 4], 38 | [ 39 | &sam4l::acifc::CHANNEL_AC0, 40 | &sam4l::acifc::CHANNEL_AC1, 41 | &sam4l::acifc::CHANNEL_AC2, 42 | &sam4l::acifc::CHANNEL_AC3, 43 | ] 44 | ); 45 | let analog_comparator = static_init!( 46 | analog_comparator::AnalogComparator<'static, sam4l::acifc::Acifc>, 47 | analog_comparator::AnalogComparator::new(&mut sam4l::acifc::ACIFC, ac_channels) 48 | ); 49 | sam4l::acifc::ACIFC.set_client(analog_comparator); 50 | 51 | analog_comparator 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /boards/imix/src/imix_components/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod adc; 2 | pub mod analog_comparator; 3 | pub mod fxos8700; 4 | pub mod nonvolatile_storage; 5 | pub mod radio; 6 | pub mod rf233; 7 | pub mod test; 8 | pub mod udp_driver; 9 | pub mod udp_mux; 10 | pub mod usb; 11 | 12 | pub use self::adc::AdcComponent; 13 | pub use self::analog_comparator::AcComponent; 14 | pub use self::fxos8700::NineDofComponent; 15 | pub use self::nonvolatile_storage::NonvolatileStorageComponent; 16 | pub use self::radio::RadioComponent; 17 | pub use self::rf233::RF233Component; 18 | pub use self::udp_driver::UDPDriverComponent; 19 | pub use self::udp_mux::UDPMuxComponent; 20 | pub use self::usb::UsbComponent; 21 | -------------------------------------------------------------------------------- /boards/imix/src/imix_components/test/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod mock_udp; 2 | pub mod mock_udp2; 3 | 4 | pub use self::mock_udp::MockUDPComponent; 5 | pub use self::mock_udp2::MockUDPComponent2; 6 | -------------------------------------------------------------------------------- /boards/imix/src/rng_test.rs: -------------------------------------------------------------------------------- 1 | //! This tests an underlying 32-bit entropy generator and the library 2 | //! transformations between 8-bit and 32-bit entropy. To run this test, 3 | //! add this line to the imix boot sequence: 4 | //! ``` 5 | //! rng_test::run_entropy32(); 6 | //! ``` 7 | //! This test takes a 32-bit entropy generator, puts its output into a 8 | //! 32-8 conversion to be an 8-bit generator, puts that output into an 9 | //! 8-to-32 conversion to be a 32-bit generator again, and makes this final 10 | //! 32-bit entropy source be the tested RNG. This therefore tests not only 11 | //! the underlying entropy source but also the conversion library. 12 | //! 13 | //! The expected output is a series of random numbers that should be 14 | //! different on each invocation. Rigorous entropy tests are outside 15 | //! the scope of this test. 16 | 17 | use capsules::rng; 18 | use capsules::test::rng::TestRng; 19 | use kernel::hil::entropy::{Entropy32, Entropy8}; 20 | use kernel::hil::rng::Rng; 21 | use kernel::static_init; 22 | use sam4l::trng::TRNG; 23 | 24 | pub unsafe fn run_entropy32() { 25 | let t = static_init_test_entropy32(); 26 | t.run(); 27 | } 28 | 29 | unsafe fn static_init_test_entropy32() -> &'static TestRng<'static> { 30 | let e1 = static_init!(rng::Entropy32To8<'static>, rng::Entropy32To8::new(&TRNG)); 31 | TRNG.set_client(e1); 32 | let e2 = static_init!(rng::Entropy8To32<'static>, rng::Entropy8To32::new(e1)); 33 | e1.set_client(e2); 34 | let er = static_init!( 35 | rng::Entropy32ToRandom<'static>, 36 | rng::Entropy32ToRandom::new(e2) 37 | ); 38 | e2.set_client(er); 39 | let test = static_init!(TestRng<'static>, TestRng::new(er)); 40 | er.set_client(test); 41 | test 42 | } 43 | -------------------------------------------------------------------------------- /boards/launchxl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "launchxl" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | build = "build.rs" 6 | edition = "2018" 7 | 8 | [profile.dev] 9 | panic = "abort" 10 | lto = false 11 | opt-level = "z" 12 | debug = true 13 | 14 | [profile.release] 15 | panic = "abort" 16 | lto = true 17 | opt-level = "z" 18 | debug = true 19 | 20 | [[bin]] 21 | name = "launchxl" 22 | path = "src/main.rs" 23 | 24 | [[bin]] 25 | name = "launchxlccfg" 26 | path = "src/ccfg.rs" 27 | 28 | [dependencies] 29 | components = { path = "../components" } 30 | cortexm4 = { path = "../../arch/cortex-m4" } 31 | capsules = { path = "../../capsules" } 32 | kernel = { path = "../../kernel" } 33 | cc26x2 = { path = "../../chips/cc26x2" } 34 | enum_primitive = { path = "../../libraries/enum_primitive" } 35 | -------------------------------------------------------------------------------- /boards/launchxl/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building the tock kernel for the launchxl development kit 2 | 3 | TOCK_ARCH=cortex-m4 4 | TOCK_BOARD=launchxl 5 | TARGET=thumbv7em-none-eabi 6 | PLATFORM=launchxl 7 | OPENOCD ?= openocd 8 | JLINK_EXE ?= JLinkExe 9 | JLINK_DEVICE ?= cc1312r1f3 10 | JLINK_ARGUMENTS ?= -device $(JLINK_DEVICE) -if jtag -speed 4000 -AutoConnect 1 -jtagconf -1,-1 11 | 12 | include ../Makefile.common 13 | 14 | flash: target/$(TARGET)/release/launchxl.bin 15 | $(OPENOCD) -f flash-kernel.openocd 16 | 17 | flash-ccfg: target/$(TARGET)/release/launchxlccfg.bin 18 | $(OPENOCD) -f flash-ccfg.openocd 19 | 20 | flash-jlink: target/$(TARGET)/release/launchxl.bin 21 | $(JLINK_EXE) $(JLINK_ARGUMENTS) -CommanderScript flash-kernel.jlink 22 | 23 | flash-ccfg-jlink: target/$(TARGET)/release/launchxlccfg.bin 24 | $(JLINK_EXE) $(JLINK_ARGUMENTS) -CommanderScript flash-ccfg.jlink 25 | -------------------------------------------------------------------------------- /boards/launchxl/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("cargo:rerun-if-changed=layout.ld"); 3 | println!("cargo:rerun-if-changed=chip_layout.ld"); 4 | println!("cargo:rerun-if-changed=../kernel_layout.ld"); 5 | } 6 | -------------------------------------------------------------------------------- /boards/launchxl/chip_layout.ld: -------------------------------------------------------------------------------- 1 | /* Memory Space Definitions, 360K flash, 80K ram */ 2 | MEMORY 3 | { 4 | rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x00030000 5 | prog (rx) : ORIGIN = 0x00030000, LENGTH = 0x00010000 6 | ccfg (rx) : ORIGIN = 0x00057FA8, LENGTH = 0x00000058 7 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 80K 8 | } 9 | 10 | MPU_MIN_ALIGN = 4K; 11 | -------------------------------------------------------------------------------- /boards/launchxl/flash-ccfg.jlink: -------------------------------------------------------------------------------- 1 | h 2 | r 3 | loadbin target/thumbv7em-none-eabi/release/launchxlccfg.bin, 0x57FA8 4 | r 5 | h 6 | g 7 | q 8 | -------------------------------------------------------------------------------- /boards/launchxl/flash-ccfg.openocd: -------------------------------------------------------------------------------- 1 | source [find board/ti_cc26x2_launchpad.cfg] 2 | 3 | init; 4 | halt; 5 | 6 | flash protect 0 0 last off; 7 | flash write_image erase target/thumbv7em-none-eabi/release/launchxlccfg.bin 0x57FA8 bin; 8 | verify_image_checksum target/thumbv7em-none-eabi/release/launchxlccfg.bin 0x57FA8 bin; 9 | soft_reset_halt 10 | resume; 11 | exit; 12 | -------------------------------------------------------------------------------- /boards/launchxl/flash-kernel.jlink: -------------------------------------------------------------------------------- 1 | h 2 | r 3 | loadbin target/thumbv7em-none-eabi/release/launchxl.bin, 0x0 4 | r 5 | h 6 | g 7 | q 8 | -------------------------------------------------------------------------------- /boards/launchxl/flash-kernel.openocd: -------------------------------------------------------------------------------- 1 | source [find board/ti_cc26x2_launchpad.cfg] 2 | 3 | init; 4 | halt; 5 | 6 | flash protect 0 0 last off; 7 | flash write_image erase target/thumbv7em-none-eabi/release/launchxl.bin 0 bin; 8 | verify_image_checksum target/thumbv7em-none-eabi/release/launchxl.bin 0 bin; 9 | soft_reset_halt 10 | resume; 11 | exit; 12 | -------------------------------------------------------------------------------- /boards/launchxl/jtag/gdbinit: -------------------------------------------------------------------------------- 1 | # GDB Init for openocd 2 | 3 | set remotetimeout 20000 4 | 5 | # Connect to openocd at port 3333 6 | target remote localhost:3333 7 | 8 | file target/thumbv7em-none-eabi/release/launchxl 9 | 10 | #monitor reset halt 11 | 12 | # Setup GDB for faster downloads 13 | #set remote memory-write-packet-size 1024 14 | #set remote memory-write-packet-size fixed 15 | -------------------------------------------------------------------------------- /boards/launchxl/layout.ld: -------------------------------------------------------------------------------- 1 | INCLUDE ./chip_layout.ld 2 | INCLUDE ../kernel_layout.ld 3 | -------------------------------------------------------------------------------- /boards/launchxl/src/cc1352p.rs: -------------------------------------------------------------------------------- 1 | use super::Pinmap; 2 | use enum_primitive::cast::FromPrimitive; 3 | use enum_primitive::enum_from_primitive; 4 | 5 | pub const CHIP_ID: u32 = 0x2282_f000; 6 | 7 | enum_from_primitive! { 8 | pub enum PinFn { 9 | Uart0Rx = 12, 10 | Uart0Tx = 13, 11 | I2c0Scl = 22, 12 | I2c0Sda = 5, 13 | Tdo = 16, 14 | Tdi = 17, 15 | RedLed = 6, 16 | GreenLed = 7, 17 | Button1 = 15, 18 | Button2 = 14, 19 | Gpio0 = 21, 20 | Adc0 = 30, 21 | Adc1 = 29, 22 | Adc2 = 28, 23 | Adc3 = 27, 24 | Adc4 = 26, 25 | Adc5 = 25, 26 | Adc6 = 24, 27 | Adc7 = 23, 28 | Pwm0 = 18, 29 | Pwm1 = 19, 30 | } 31 | } 32 | 33 | pub static PINMAP: Pinmap = Pinmap { 34 | uart0_rx: PinFn::Uart0Rx as usize, 35 | uart0_tx: PinFn::Uart0Tx as usize, 36 | i2c0_scl: PinFn::I2c0Scl as usize, 37 | i2c0_sda: PinFn::I2c0Sda as usize, 38 | red_led: PinFn::RedLed as usize, 39 | green_led: PinFn::GreenLed as usize, 40 | button1: PinFn::Button1 as usize, 41 | button2: PinFn::Button2 as usize, 42 | gpio0: PinFn::Gpio0 as usize, 43 | a0: PinFn::Adc0 as usize, 44 | a1: PinFn::Adc1 as usize, 45 | a2: PinFn::Adc2 as usize, 46 | a3: PinFn::Adc3 as usize, 47 | a4: PinFn::Adc4 as usize, 48 | a5: PinFn::Adc5 as usize, 49 | a6: PinFn::Adc6 as usize, 50 | a7: PinFn::Adc7 as usize, 51 | pwm0: PinFn::Pwm0 as usize, 52 | pwm1: PinFn::Pwm1 as usize, 53 | }; 54 | -------------------------------------------------------------------------------- /boards/launchxl/src/ccfg.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | #![no_main] 3 | //! CCFG - Customer Configuration 4 | //! 5 | //! For details see p. 710 in the cc2650 technical reference manual. 6 | //! 7 | //! Currently setup to use the default settings. 8 | 9 | #[used] 10 | #[link_section = ".init"] 11 | pub static CCFG_CONF: [u32; 22] = [ 12 | 0x01800000, 0xFF820010, 0x0058FFFD, 0xF3FFFF3A, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 13 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00FFFFFF, 0xFFFFFFFF, 0xFFFFFF00, 0xFFC5C5C5, 14 | 0xFFC5C5C5, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 15 | ]; 16 | 17 | #[panic_handler] 18 | #[no_mangle] 19 | pub unsafe extern "C" fn panic_fmt(_pi: &core::panic::PanicInfo) -> ! { 20 | loop {} 21 | } 22 | -------------------------------------------------------------------------------- /boards/launchxl/src/io.rs: -------------------------------------------------------------------------------- 1 | use core::fmt::Write; 2 | use core::panic::PanicInfo; 3 | use cortexm4; 4 | use kernel::debug; 5 | use kernel::debug::IoWrite; 6 | use kernel::hil::led; 7 | use kernel::hil::uart; 8 | 9 | use crate::CHIP; 10 | use crate::PROCESSES; 11 | 12 | struct Writer { 13 | initialized: bool, 14 | } 15 | 16 | static mut WRITER: Writer = Writer { initialized: false }; 17 | 18 | impl Write for Writer { 19 | fn write_str(&mut self, s: &str) -> ::core::fmt::Result { 20 | self.write(s.as_bytes()); 21 | Ok(()) 22 | } 23 | } 24 | 25 | impl IoWrite for Writer { 26 | fn write(&mut self, buf: &[u8]) { 27 | let uart = unsafe { &mut cc26x2::uart::UART0 }; 28 | if !self.initialized { 29 | self.initialized = true; 30 | uart::Configure::configure( 31 | uart, 32 | uart::Parameters { 33 | baud_rate: 115200, 34 | stop_bits: uart::StopBits::One, 35 | parity: uart::Parity::None, 36 | hw_flow_control: false, 37 | width: uart::Width::Eight, 38 | }, 39 | ); 40 | } 41 | for &c in buf { 42 | uart.write(c as u32); 43 | while !uart.tx_fifo_not_full() {} 44 | } 45 | } 46 | } 47 | 48 | #[cfg(not(test))] 49 | #[panic_handler] 50 | #[no_mangle] 51 | pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! { 52 | // 6 = Red led, 7 = Green led 53 | const LED_PIN: usize = 6; 54 | 55 | let led = &mut led::LedLow::new(&mut cc26x2::gpio::PORT[LED_PIN]); 56 | let writer = &mut WRITER; 57 | debug::panic( 58 | &mut [led], 59 | writer, 60 | pi, 61 | &cortexm4::support::nop, 62 | &PROCESSES, 63 | &CHIP, 64 | ) 65 | } 66 | -------------------------------------------------------------------------------- /boards/nordic/nrf52840_dongle/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "nrf52840_dongle" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | build = "build.rs" 6 | edition = "2018" 7 | 8 | [profile.dev] 9 | panic = "abort" 10 | lto = false 11 | opt-level = "z" 12 | debug = true 13 | 14 | [profile.release] 15 | panic = "abort" 16 | lto = true 17 | opt-level = "z" 18 | debug = true 19 | 20 | [dependencies] 21 | components = { path = "../../components" } 22 | cortexm4 = { path = "../../../arch/cortex-m4" } 23 | capsules = { path = "../../../capsules" } 24 | kernel = { path = "../../../kernel" } 25 | nrf52840 = { path = "../../../chips/nrf52840" } 26 | nrf52dk_base = { path = "../nrf52dk_base" } 27 | -------------------------------------------------------------------------------- /boards/nordic/nrf52840_dongle/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building the tock kernel for the nRF development kit 2 | 3 | TOCK_ARCH=cortex-m4 4 | TARGET=thumbv7em-none-eabi 5 | PLATFORM=nrf52840_dongle 6 | 7 | include ../../Makefile.common 8 | 9 | TOCKLOADER=tockloader 10 | 11 | # Where in the nrf52 flash to load the kernel with `tockloader` 12 | KERNEL_ADDRESS=0x00000 13 | 14 | # Upload programs over uart with tockloader 15 | ifdef PORT 16 | TOCKLOADER_GENERAL_FLAGS += --port $(PORT) 17 | endif 18 | 19 | TOCKLOADER_JTAG_FLAGS = --jlink --board nrf52dk 20 | 21 | # Upload the kernel over JTAG 22 | .PHONY: flash 23 | flash: target/$(TARGET)/release/$(PLATFORM).bin 24 | $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) $(TOCKLOADER_JTAG_FLAGS) $< 25 | 26 | # Upload the kernel over serial/bootloader 27 | .PHONY: program 28 | program: target/$(TARGET)/release/$(PLATFORM).hex 29 | $(error Cannot program nRF52 Dongle over USB. Use \`make flash\` and JTAG) 30 | -------------------------------------------------------------------------------- /boards/nordic/nrf52840_dongle/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("cargo:rerun-if-changed=layout.ld"); 3 | println!("cargo:rerun-if-changed=../../kernel_layout.ld"); 4 | } 5 | -------------------------------------------------------------------------------- /boards/nordic/nrf52840_dongle/jtag/gdbinit_pca10040.jlink: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # 4 | # J-LINK GDB SERVER initialization 5 | # 6 | # This connects to a GDB Server listening 7 | # for commands on localhost at tcp port 2331 8 | target remote localhost:2331 9 | monitor speed 30 10 | file ../target/thumbv7em-none-eabi/release/nrf52840_dongle 11 | monitor reset 12 | # 13 | # CPU core initialization (to be done by user) 14 | # 15 | # Set the processor mode 16 | # monitor reg cpsr = 0xd3 17 | # Set auto JTAG speed 18 | monitor speed auto 19 | # Setup GDB FOR FASTER DOWNLOADS 20 | set remote memory-write-packet-size 1024 21 | set remote memory-write-packet-size fixed 22 | # tui enable 23 | # layout split 24 | # layout service_pending_interrupts 25 | b reset_handler 26 | -------------------------------------------------------------------------------- /boards/nordic/nrf52840_dongle/jtag/jdbserver_pca10040.sh: -------------------------------------------------------------------------------- 1 | JLinkGDBServer -device nRF52840_xxAA -speed 1200 -if swd -AutoConnect 1 -port 2331 2 | -------------------------------------------------------------------------------- /boards/nordic/nrf52840_dongle/layout.ld: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | rom (rx) : ORIGIN = 0x00000000, LENGTH = 128K 4 | prog (rx) : ORIGIN = 0x00030000, LENGTH = 832K 5 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 256K 6 | } 7 | 8 | MPU_MIN_ALIGN = 8K; 9 | 10 | INCLUDE ../../kernel_layout.ld 11 | -------------------------------------------------------------------------------- /boards/nordic/nrf52840dk/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "nrf52840dk" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | build = "build.rs" 6 | edition = "2018" 7 | 8 | [profile.dev] 9 | panic = "abort" 10 | lto = false 11 | opt-level = "z" 12 | debug = true 13 | 14 | [profile.release] 15 | panic = "abort" 16 | lto = true 17 | opt-level = "z" 18 | debug = true 19 | 20 | [dependencies] 21 | components = { path = "../../components" } 22 | cortexm4 = { path = "../../../arch/cortex-m4" } 23 | capsules = { path = "../../../capsules" } 24 | kernel = { path = "../../../kernel" } 25 | nrf52840 = { path = "../../../chips/nrf52840" } 26 | nrf52dk_base = { path = "../nrf52dk_base" } 27 | -------------------------------------------------------------------------------- /boards/nordic/nrf52840dk/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building the tock kernel for the nRF development kit 2 | 3 | TOCK_ARCH=cortex-m4 4 | TARGET=thumbv7em-none-eabi 5 | PLATFORM=nrf52840dk 6 | 7 | include ../../Makefile.common 8 | 9 | TOCKLOADER=tockloader 10 | 11 | # Where in the SAM4L flash to load the kernel with `tockloader` 12 | KERNEL_ADDRESS=0x00000 13 | 14 | # Upload programs over uart with tockloader 15 | ifdef PORT 16 | TOCKLOADER_GENERAL_FLAGS += --port $(PORT) 17 | endif 18 | 19 | TOCKLOADER_JTAG_FLAGS = --jlink --board nrf52dk 20 | 21 | # Upload the kernel over JTAG 22 | .PHONY: flash 23 | flash: target/$(TARGET)/release/$(PLATFORM).bin 24 | $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) $(TOCKLOADER_JTAG_FLAGS) $< 25 | 26 | # Upload the kernel over serial/bootloader 27 | .PHONY: program 28 | program: target/$(TARGET)/release/$(PLATFORM).hex 29 | $(error Cannot program nRF52DK over USB. Use \`make flash\` and JTAG) 30 | -------------------------------------------------------------------------------- /boards/nordic/nrf52840dk/README.md: -------------------------------------------------------------------------------- 1 | Platform-Specific Instructions: nRF52840-DK 2 | =================================== 3 | 4 | The [nRF52840 Development 5 | Kit](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK) is a platform 6 | based around the nRF52840, an SoC with an ARM Cortex-M4 and a BLE 7 | radio. The kit is Arduino shield compatible and includes several 8 | buttons. 9 | 10 | ## Getting Started 11 | 12 | First, follow the [Tock Getting Started guide](../../../doc/Getting_Started.md) 13 | 14 | JTAG is the preferred method to program. The development kit has an 15 | integrated JTAG debugger, you simply need to [install JTAG 16 | software](../../../doc/Getting_Started.md#loading-the-kernel-onto-a-board). 17 | 18 | ## Programming the kernel 19 | Once you have all software installed, you should be able to simply run 20 | make flash in this directory to install a fresh kernel. 21 | 22 | ## Programming user-level applications 23 | You can program an application over USB using the integrated JTAG and `tockloader`: 24 | 25 | ```bash 26 | $ cd libtock-c/examples/ 27 | $ make 28 | $ tockloader install --jlink --board nrf52dk 29 | ``` 30 | 31 | The same options (`--jlink --board nrf52dk`) must be passed for other tockloader commands 32 | such as `erase-apps` or `list`. 33 | 34 | Viewing console output on the nrf52840dk is slightly different from other boards. You must use 35 | ```bash 36 | $ tockloader listen 37 | ``` 38 | **followed by a press of the reset button** in order to view console output starting from the boot 39 | sequence. Notably, you should not 40 | pass the `--jlink` option to `tockloader listen`. 41 | 42 | ## Debugging 43 | 44 | See the [nrf52dk README](../nrf52dk/README.md) for information about debugging 45 | the nRF52840dk. 46 | -------------------------------------------------------------------------------- /boards/nordic/nrf52840dk/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("cargo:rerun-if-changed=layout.ld"); 3 | println!("cargo:rerun-if-changed=../../kernel_layout.ld"); 4 | } 5 | -------------------------------------------------------------------------------- /boards/nordic/nrf52840dk/jtag/gdbinit_pca10040.jlink: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # 4 | # J-LINK GDB SERVER initialization 5 | # 6 | # This connects to a GDB Server listening 7 | # for commands on localhost at tcp port 2331 8 | target remote localhost:2331 9 | monitor speed 30 10 | file ../target/thumbv7em-none-eabi/release/nrf52dk 11 | monitor reset 12 | # 13 | # CPU core initialization (to be done by user) 14 | # 15 | # Set the processor mode 16 | # monitor reg cpsr = 0xd3 17 | # Set auto JTAG speed 18 | monitor speed auto 19 | # Setup GDB FOR FASTER DOWNLOADS 20 | set remote memory-write-packet-size 1024 21 | set remote memory-write-packet-size fixed 22 | # tui enable 23 | # layout split 24 | # layout service_pending_interrupts 25 | b reset_handler 26 | -------------------------------------------------------------------------------- /boards/nordic/nrf52840dk/jtag/jdbserver_pca10040.sh: -------------------------------------------------------------------------------- 1 | JLinkGDBServer -device nrf52 -speed 1200 -if swd -AutoConnect 1 -port 2331 2 | -------------------------------------------------------------------------------- /boards/nordic/nrf52840dk/layout.ld: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | rom (rx) : ORIGIN = 0x00000000, LENGTH = 128K 4 | prog (rx) : ORIGIN = 0x00030000, LENGTH = 832K 5 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 256K 6 | } 7 | 8 | MPU_MIN_ALIGN = 8K; 9 | 10 | INCLUDE ../../kernel_layout.ld 11 | -------------------------------------------------------------------------------- /boards/nordic/nrf52dk/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "nrf52dk" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | build = "build.rs" 6 | edition = "2018" 7 | 8 | [profile.dev] 9 | panic = "abort" 10 | lto = false 11 | opt-level = "z" 12 | debug = true 13 | 14 | [profile.release] 15 | panic = "abort" 16 | lto = true 17 | opt-level = "z" 18 | debug = true 19 | 20 | [dependencies] 21 | components = { path = "../../components" } 22 | cortexm4 = { path = "../../../arch/cortex-m4" } 23 | capsules = { path = "../../../capsules" } 24 | kernel = { path = "../../../kernel" } 25 | nrf52832 = { path = "../../../chips/nrf52832" } 26 | nrf52dk_base = { path = "../nrf52dk_base" } 27 | -------------------------------------------------------------------------------- /boards/nordic/nrf52dk/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building the tock kernel for the nRF52 development kit 2 | 3 | TOCK_ARCH=cortex-m4 4 | TARGET=thumbv7em-none-eabi 5 | PLATFORM=nrf52dk 6 | 7 | include ../../Makefile.common 8 | 9 | TOCKLOADER=tockloader 10 | 11 | # Where in the nrf52 flash to load the kernel with `tockloader` 12 | KERNEL_ADDRESS=0x00000 13 | 14 | # Upload programs over uart with tockloader 15 | ifdef PORT 16 | TOCKLOADER_GENERAL_FLAGS += --port $(PORT) 17 | endif 18 | 19 | TOCKLOADER_JTAG_FLAGS = --jlink --board nrf52dk 20 | 21 | # Upload the kernel over JTAG 22 | .PHONY: flash 23 | flash: target/$(TARGET)/release/$(PLATFORM).bin 24 | $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) $(TOCKLOADER_JTAG_FLAGS) $< 25 | 26 | # Upload the kernel over serial/bootloader 27 | .PHONY: program 28 | program: target/$(TARGET)/release/$(PLATFORM).hex 29 | $(error Cannot program nRF52DK over USB. Use \`make flash\` and JTAG) 30 | -------------------------------------------------------------------------------- /boards/nordic/nrf52dk/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("cargo:rerun-if-changed=layout.ld"); 3 | println!("cargo:rerun-if-changed=chip_layout.ld"); 4 | println!("cargo:rerun-if-changed=../../kernel_layout.ld"); 5 | } 6 | -------------------------------------------------------------------------------- /boards/nordic/nrf52dk/chip_layout.ld: -------------------------------------------------------------------------------- 1 | /* Memory Space Definitions, 512K flash, 64K ram */ 2 | MEMORY 3 | { 4 | rom (rx) : ORIGIN = 0x00000000, LENGTH = 192K 5 | prog (rx) : ORIGIN = 0x00030000, LENGTH = 320K 6 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K 7 | } 8 | 9 | MPU_MIN_ALIGN = 8K; 10 | -------------------------------------------------------------------------------- /boards/nordic/nrf52dk/jtag/flash-full.jlink: -------------------------------------------------------------------------------- 1 | eoe 1 2 | r 3 | loadfile target/thumbv7em-none-eabi/release/nrf52dk-blink.hex 4 | r 5 | g 6 | q 7 | 8 | -------------------------------------------------------------------------------- /boards/nordic/nrf52dk/jtag/flash-kernel.jlink: -------------------------------------------------------------------------------- 1 | eoe 1 2 | r 3 | loadfile target/thumbv7em-none-eabi/release/nrf52dk.hex 4 | r 5 | g 6 | q 7 | 8 | -------------------------------------------------------------------------------- /boards/nordic/nrf52dk/jtag/gdbinit_pca10040.jlink: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # 4 | # J-LINK GDB SERVER initialization 5 | # 6 | # This connects to a GDB Server listening 7 | # for commands on localhost at tcp port 2331 8 | target remote localhost:2331 9 | monitor speed 30 10 | file ../target/thumbv7em-none-eabi/release/nrf52dk 11 | monitor reset 12 | # 13 | # CPU core initialization (to be done by user) 14 | # 15 | # Set the processor mode 16 | # monitor reg cpsr = 0xd3 17 | # Set auto JTAG speed 18 | monitor speed auto 19 | # Setup GDB FOR FASTER DOWNLOADS 20 | set remote memory-write-packet-size 1024 21 | set remote memory-write-packet-size fixed 22 | # tui enable 23 | # layout split 24 | # layout service_pending_interrupts 25 | b reset_handler 26 | -------------------------------------------------------------------------------- /boards/nordic/nrf52dk/jtag/jdbserver_pca10040.sh: -------------------------------------------------------------------------------- 1 | JLinkGDBServer -device nrf52 -speed 1200 -if swd -AutoConnect 1 -port 2331 2 | -------------------------------------------------------------------------------- /boards/nordic/nrf52dk/layout.ld: -------------------------------------------------------------------------------- 1 | INCLUDE ./chip_layout.ld 2 | INCLUDE ../../kernel_layout.ld 3 | -------------------------------------------------------------------------------- /boards/nordic/nrf52dk/src/tests/aes.rs: -------------------------------------------------------------------------------- 1 | use capsules::test::aes::TestAes128Ctr; 2 | use kernel::hil::symmetric_encryption::{AES128, AES128_BLOCK_SIZE, AES128_KEY_SIZE}; 3 | use kernel::static_init; 4 | use nrf52832::aes::{AesECB, AESECB}; 5 | 6 | /// To run the tests add the following `main.rs::reset_handler` somewhere after that the AES 7 | /// peripheral has been initialized: 8 | /// 9 | /// ```rustc 10 | /// aes::run(); 11 | /// ``` 12 | /// 13 | pub unsafe fn run() { 14 | let t = static_init_test(); 15 | AESECB.set_client(t); 16 | t.run(); 17 | } 18 | 19 | unsafe fn static_init_test() -> &'static mut TestAes128Ctr<'static, AesECB<'static>> { 20 | let source = static_init!([u8; 4 * AES128_BLOCK_SIZE], [0; 4 * AES128_BLOCK_SIZE]); 21 | let data = static_init!([u8; 6 * AES128_BLOCK_SIZE], [0; 6 * AES128_BLOCK_SIZE]); 22 | let key = static_init!([u8; AES128_KEY_SIZE], [0; AES128_KEY_SIZE]); 23 | let iv = static_init!([u8; AES128_BLOCK_SIZE], [0; AES128_BLOCK_SIZE]); 24 | 25 | static_init!( 26 | TestAes128Ctr<'static, AesECB>, 27 | TestAes128Ctr::new(&AESECB, key, iv, source, data) 28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /boards/nordic/nrf52dk/src/tests/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod aes; 2 | pub mod uart; 3 | -------------------------------------------------------------------------------- /boards/nordic/nrf52dk_base/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "nrf52dk_base" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | components = { path = "../../components" } 9 | cortexm4 = { path = "../../../arch/cortex-m4" } 10 | capsules = { path = "../../../capsules" } 11 | kernel = { path = "../../../kernel" } 12 | nrf52 = { path = "../../../chips/nrf52" } 13 | -------------------------------------------------------------------------------- /boards/nordic/nrf52dk_base/README.md: -------------------------------------------------------------------------------- 1 | Generic nRF52 Board 2 | =================================== 3 | 4 | This crate has general code that is used by both the nRF52dk and nRF52840dk 5 | development boards. 6 | -------------------------------------------------------------------------------- /boards/nordic/nrf52dk_base/src/nrf52_components/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod ble; 2 | pub mod ieee802154; 3 | 4 | pub use self::ble::BLEComponent; 5 | pub use self::ieee802154::Ieee802154Component; 6 | -------------------------------------------------------------------------------- /boards/nucleo_f429zi/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "nucleo_f429zi" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | build = "build.rs" 6 | edition = "2018" 7 | 8 | [profile.dev] 9 | panic = "abort" 10 | lto = false 11 | opt-level = "z" 12 | debug = true 13 | 14 | [profile.release] 15 | panic = "abort" 16 | lto = true 17 | opt-level = "z" 18 | debug = true 19 | 20 | [dependencies] 21 | components = { path = "../components" } 22 | cortexm4 = { path = "../../arch/cortex-m4" } 23 | capsules = { path = "../../capsules" } 24 | kernel = { path = "../../kernel" } 25 | stm32f4xx = { path = "../../chips/stm32f4xx", features = ["stm32f429zi"] } 26 | -------------------------------------------------------------------------------- /boards/nucleo_f429zi/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building the tock kernel for the NUCLEO-429ZI platform 2 | # 3 | TARGET=thumbv7em-none-eabi 4 | PLATFORM=nucleo_f429zi 5 | 6 | include ../Makefile.common 7 | 8 | OPENOCD=openocd 9 | OPENOCD_OPTIONS=-f openocd.cfg 10 | 11 | # OpenOCD requires fullpath 12 | CWD=$(shell pwd) 13 | 14 | # sudo is needed for libusb access to work properly 15 | 16 | .PHONY: flash-debug 17 | flash-debug: target/$(TARGET)/debug/$(PLATFORM).elf 18 | sudo $(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(CWD)/$<; verify_image $(CWD)/$<; reset; shutdown" 19 | 20 | .PHONY: flash 21 | flash: target/$(TARGET)/release/$(PLATFORM).elf 22 | sudo $(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(CWD)/$<; verify_image $(CWD)/$<; reset; shutdown" 23 | 24 | .PHONY: program 25 | program: target/$(TARGET)/debug/$(PLATFORM).elf 26 | $(error See README.md and update this section accordingly) 27 | -------------------------------------------------------------------------------- /boards/nucleo_f429zi/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("cargo:rerun-if-changed=layout.ld"); 3 | println!("cargo:rerun-if-changed=chip_layout.ld"); 4 | println!("cargo:rerun-if-changed=../kernel_layout.ld"); 5 | } 6 | -------------------------------------------------------------------------------- /boards/nucleo_f429zi/chip_layout.ld: -------------------------------------------------------------------------------- 1 | /* Memory layout for the STM32F446RE 2 | * rom = 2MB (LENGTH = 0x02000000) 3 | * kernel = 256KB 4 | * user = 256KB 5 | * ram = 192KB */ 6 | 7 | MEMORY 8 | { 9 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 0x00040000 10 | prog (rx) : ORIGIN = 0x08040000, LENGTH = 0x00040000 11 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00030000 12 | } 13 | 14 | MPU_MIN_ALIGN = 8K; 15 | -------------------------------------------------------------------------------- /boards/nucleo_f429zi/layout.ld: -------------------------------------------------------------------------------- 1 | INCLUDE ./chip_layout.ld 2 | INCLUDE ../kernel_layout.ld 3 | -------------------------------------------------------------------------------- /boards/nucleo_f429zi/openocd.cfg: -------------------------------------------------------------------------------- 1 | #interface 2 | interface hla 3 | hla_layout stlink 4 | hla_device_desc "ST-LINK/V2-1" 5 | hla_vid_pid 0x0483 0x374b 6 | 7 | # The chip has 128KB sram, but we will still use 64KB 8 | set WORKAREASIZE 0x10000 9 | 10 | source [find target/stm32f4x.cfg] 11 | 12 | -------------------------------------------------------------------------------- /boards/nucleo_f446re/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "nucleo_f446re" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | build = "build.rs" 6 | edition = "2018" 7 | 8 | [profile.dev] 9 | panic = "abort" 10 | lto = false 11 | opt-level = "z" 12 | debug = true 13 | 14 | [profile.release] 15 | panic = "abort" 16 | lto = true 17 | opt-level = "z" 18 | debug = true 19 | 20 | [dependencies] 21 | components = { path = "../components" } 22 | cortexm4 = { path = "../../arch/cortex-m4" } 23 | capsules = { path = "../../capsules" } 24 | kernel = { path = "../../kernel" } 25 | stm32f4xx = { path = "../../chips/stm32f4xx", features = ["stm32f446re"] } 26 | -------------------------------------------------------------------------------- /boards/nucleo_f446re/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building the tock kernel for the NUCLEO-446RE platform 2 | # 3 | TARGET=thumbv7em-none-eabi 4 | PLATFORM=nucleo_f446re 5 | 6 | include ../Makefile.common 7 | 8 | OPENOCD=openocd 9 | OPENOCD_OPTIONS=-f openocd.cfg 10 | 11 | # OpenOCD requires fullpath 12 | CWD=$(shell pwd) 13 | 14 | # sudo is needed for libusb access to work properly 15 | 16 | .PHONY: flash-debug 17 | flash-debug: target/$(TARGET)/debug/$(PLATFORM).elf 18 | sudo $(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(CWD)/$<; verify_image $(CWD)/$<; reset; shutdown" 19 | 20 | .PHONY: flash 21 | flash: target/$(TARGET)/release/$(PLATFORM).elf 22 | sudo $(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(CWD)/$<; verify_image $(CWD)/$<; reset; shutdown" 23 | 24 | .PHONY: program 25 | program: target/$(TARGET)/debug/$(PLATFORM).elf 26 | $(error See README.md and update this section accordingly) 27 | -------------------------------------------------------------------------------- /boards/nucleo_f446re/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("cargo:rerun-if-changed=layout.ld"); 3 | println!("cargo:rerun-if-changed=chip_layout.ld"); 4 | println!("cargo:rerun-if-changed=../kernel_layout.ld"); 5 | } 6 | -------------------------------------------------------------------------------- /boards/nucleo_f446re/chip_layout.ld: -------------------------------------------------------------------------------- 1 | /* Memory layout for the STM32F446RE 2 | * rom = 512KB (LENGTH = 0x00080000) 3 | * kernel = 256KB 4 | * user = 256KB 5 | * ram = 128KB */ 6 | 7 | MEMORY 8 | { 9 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 0x00040000 10 | prog (rx) : ORIGIN = 0x08040000, LENGTH = 0x00040000 11 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000 12 | } 13 | 14 | MPU_MIN_ALIGN = 8K; 15 | -------------------------------------------------------------------------------- /boards/nucleo_f446re/layout.ld: -------------------------------------------------------------------------------- 1 | INCLUDE ./chip_layout.ld 2 | INCLUDE ../kernel_layout.ld 3 | -------------------------------------------------------------------------------- /boards/nucleo_f446re/openocd.cfg: -------------------------------------------------------------------------------- 1 | #interface 2 | interface hla 3 | hla_layout stlink 4 | hla_device_desc "ST-LINK/V2-1" 5 | hla_vid_pid 0x0483 0x374b 6 | 7 | # The chip has 128KB sram, but we will still use 64KB 8 | set WORKAREASIZE 0x10000 9 | 10 | source [find target/stm32f4x.cfg] 11 | 12 | -------------------------------------------------------------------------------- /boards/opentitan/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "opentitan" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | build = "build.rs" 6 | edition = "2018" 7 | 8 | [profile.dev] 9 | panic = "abort" 10 | lto = false 11 | opt-level = "z" 12 | debug = true 13 | 14 | [profile.release] 15 | panic = "abort" 16 | lto = true 17 | opt-level = "z" 18 | debug = true 19 | 20 | [dependencies] 21 | components = { path = "../components" } 22 | rv32i = { path = "../../arch/rv32i" } 23 | capsules = { path = "../../capsules" } 24 | kernel = { path = "../../kernel" } 25 | ibex = { path = "../../chips/ibex" } 26 | lowrisc = { path = "../../chips/lowrisc" } 27 | -------------------------------------------------------------------------------- /boards/opentitan/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building the tock kernel for the OpenTitan platform 2 | 3 | TARGET=riscv32imc-unknown-none-elf 4 | PLATFORM=opentitan 5 | 6 | include ../Makefile.common 7 | 8 | flash: target/$(TARGET)/release/$(PLATFORM).bin 9 | $(OPENTITAN_TREE)/sw/host/spiflash/spiflash --input=target/$(TARGET)/release/$(PLATFORM).bin 10 | -------------------------------------------------------------------------------- /boards/opentitan/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("cargo:rerun-if-changed=layout.ld"); 3 | println!("cargo:rerun-if-changed=../kernel_layout.ld"); 4 | } 5 | -------------------------------------------------------------------------------- /boards/opentitan/layout.ld: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | rom (rx) : ORIGIN = 0x20000000, LENGTH = 0x30000 4 | prog (rx) : ORIGIN = 0x20030000, LENGTH = 0x100000-0x30000 5 | ram (!rx) : ORIGIN = 0x10000000, LENGTH = 0x10000 6 | } 7 | 8 | MPU_MIN_ALIGN = 1K; 9 | SECTIONS { 10 | /* 11 | * The flash header needs to match what the boot ROM for OpenTitan is 12 | * expecting. At the moment, it contains only the entry point, but it 13 | * will eventually contain the signature -- and (hopefully?!) some 14 | * versioning information to make it slightly easier to debug when the 15 | * boot ROM and Tock are out of sync with respect to the definition... 16 | */ 17 | .flash_header : { 18 | LONG(_stext) 19 | } > rom 20 | } 21 | 22 | INCLUDE ../kernel_layout.ld 23 | -------------------------------------------------------------------------------- /boards/opentitan/src/io.rs: -------------------------------------------------------------------------------- 1 | use core::fmt::Write; 2 | use core::panic::PanicInfo; 3 | use core::str; 4 | use kernel::debug; 5 | use kernel::debug::IoWrite; 6 | use kernel::hil::gpio; 7 | use kernel::hil::led; 8 | 9 | use crate::CHIP; 10 | use crate::PROCESSES; 11 | 12 | struct Writer {} 13 | 14 | static mut WRITER: Writer = Writer {}; 15 | 16 | impl Write for Writer { 17 | fn write_str(&mut self, s: &str) -> ::core::fmt::Result { 18 | self.write(s.as_bytes()); 19 | Ok(()) 20 | } 21 | } 22 | 23 | impl IoWrite for Writer { 24 | fn write(&mut self, buf: &[u8]) { 25 | unsafe { 26 | ibex::uart::UART0.transmit_sync(buf); 27 | } 28 | } 29 | } 30 | 31 | /// Panic handler. 32 | #[cfg(not(test))] 33 | #[no_mangle] 34 | #[panic_handler] 35 | pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! { 36 | // turn off the non panic leds, just in case 37 | let first_led = &mut led::LedLow::new(&mut ibex::gpio::PORT[7]); 38 | gpio::Pin::make_output(&ibex::gpio::PORT[7]); 39 | 40 | let writer = &mut WRITER; 41 | 42 | debug::panic( 43 | &mut [first_led], 44 | writer, 45 | pi, 46 | &rv32i::support::nop, 47 | &PROCESSES, 48 | &CHIP, 49 | ) 50 | } 51 | -------------------------------------------------------------------------------- /bors.toml: -------------------------------------------------------------------------------- 1 | # List of commit statuses that must pass on the merge commit before it is 2 | # pushed to master. 3 | status = [ 4 | "continuous-integration/travis-ci/push", 5 | ] 6 | 7 | # List of PR labels that may not be attached to a PR when it is r+-ed. 8 | block_labels = [ 9 | "blocked", 10 | ] 11 | 12 | # Number of seconds from when a merge commit is created to when its statuses 13 | # must pass. (Default = 3600). 14 | #timeout_sec = 7200 15 | 16 | # If set to true, and if the PR branch is on the same repository that bors-ng 17 | # itself is on, the branch will be deleted. 18 | delete_merged_branches = true 19 | -------------------------------------------------------------------------------- /capsules/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "capsules" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | kernel = { path = "../kernel" } 9 | enum_primitive = { path = "../libraries/enum_primitive" } 10 | -------------------------------------------------------------------------------- /capsules/src/dac.rs: -------------------------------------------------------------------------------- 1 | //! Provides a DAC interface for userspace. 2 | //! 3 | //! Usage 4 | //! ----- 5 | //! 6 | //! ```rust 7 | //! let dac = static_init!( 8 | //! capsules::dac::Dac<'static>, 9 | //! capsules::dac::Dac::new(&mut sam4l::dac::DAC)); 10 | //! ``` 11 | 12 | /// Syscall driver number. 13 | use crate::driver; 14 | pub const DRIVER_NUM: usize = driver::NUM::Dac as usize; 15 | 16 | use kernel::hil; 17 | use kernel::{AppId, Driver, ReturnCode}; 18 | 19 | pub struct Dac<'a> { 20 | dac: &'a dyn hil::dac::DacChannel, 21 | } 22 | 23 | impl Dac<'a> { 24 | pub fn new(dac: &'a dyn hil::dac::DacChannel) -> Dac<'a> { 25 | Dac { dac: dac } 26 | } 27 | } 28 | 29 | impl Driver for Dac<'a> { 30 | /// Control the DAC. 31 | /// 32 | /// ### `command_num` 33 | /// 34 | /// - `0`: Driver check. 35 | /// - `1`: Initialize and enable the DAC. 36 | /// - `2`: Set the output to `data1`, a scaled output value. 37 | fn command(&self, command_num: usize, data: usize, _: usize, _: AppId) -> ReturnCode { 38 | match command_num { 39 | 0 /* check if present */ => ReturnCode::SUCCESS, 40 | 41 | // enable the dac 42 | 1 => self.dac.initialize(), 43 | 44 | // set the dac output 45 | 2 => self.dac.set_value(data), 46 | 47 | _ => ReturnCode::ENOSUPPORT, 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /capsules/src/debug_process_restart.rs: -------------------------------------------------------------------------------- 1 | //! Debug capsule to cause a button press to make all apps fault. 2 | //! 3 | //! This is useful for debugging that capsules and apps work when they are 4 | //! restarted by the kernel. 5 | //! 6 | //! Usage 7 | //! ----- 8 | //! 9 | //! ```rust 10 | //! struct ProcessMgmtCap; 11 | //! unsafe impl capabilities::ProcessManagementCapability for ProcessMgmtCap {} 12 | //! let debug_process_restart = static_init!( 13 | //! capsules::debug_process_restart::DebugProcessRestart< 14 | //! 'static, 15 | //! sam4l::gpio::GPIOPin, 16 | //! ProcessMgmtCap, 17 | //! >, 18 | //! capsules::debug_process_restart::DebugProcessRestart::new( 19 | //! board_kernel, 20 | //! &sam4l::gpio::PA[16], 21 | //! ProcessMgmtCap 22 | //! ) 23 | //! ); 24 | //! sam4l::gpio::PA[16].set_client(debug_process_restart); 25 | //! ``` 26 | 27 | use kernel::capabilities::ProcessManagementCapability; 28 | use kernel::hil::gpio; 29 | use kernel::Kernel; 30 | 31 | pub struct DebugProcessRestart { 32 | kernel: &'static Kernel, 33 | capability: C, 34 | } 35 | 36 | impl<'a, C: ProcessManagementCapability> DebugProcessRestart { 37 | pub fn new( 38 | kernel: &'static Kernel, 39 | pin: &'a dyn gpio::InterruptPin, 40 | cap: C, 41 | ) -> DebugProcessRestart { 42 | pin.make_input(); 43 | pin.enable_interrupts(gpio::InterruptEdge::RisingEdge); 44 | 45 | DebugProcessRestart { 46 | kernel: kernel, 47 | capability: cap, 48 | } 49 | } 50 | } 51 | 52 | impl<'a, C: ProcessManagementCapability> gpio::Client for DebugProcessRestart { 53 | fn fired(&self) { 54 | self.kernel.hardfault_all_apps(&self.capability); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /capsules/src/ieee802154/mod.rs: -------------------------------------------------------------------------------- 1 | //! Support for IEEE 802.15.4. 2 | 3 | pub mod device; 4 | pub mod framer; 5 | pub mod mac; 6 | pub mod virtual_mac; 7 | pub mod xmac; 8 | 9 | mod driver; 10 | 11 | pub use self::driver::RadioDriver; 12 | pub use self::driver::DRIVER_NUM; 13 | -------------------------------------------------------------------------------- /capsules/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![feature(const_fn, in_band_lifetimes)] 2 | #![forbid(unsafe_code)] 3 | #![no_std] 4 | 5 | pub mod test; 6 | 7 | #[macro_use] 8 | pub mod net; 9 | 10 | pub mod adc; 11 | pub mod aes_ccm; 12 | pub mod alarm; 13 | pub mod ambient_light; 14 | pub mod analog_comparator; 15 | pub mod analog_sensor; 16 | pub mod app_flash_driver; 17 | pub mod ble_advertising_driver; 18 | pub mod button; 19 | pub mod buzzer_driver; 20 | pub mod console; 21 | pub mod crc; 22 | pub mod dac; 23 | pub mod debug_process_restart; 24 | pub mod driver; 25 | pub mod fm25cl; 26 | pub mod fxos8700cq; 27 | pub mod gpio; 28 | pub mod gpio_async; 29 | pub mod humidity; 30 | pub mod i2c_master; 31 | pub mod i2c_master_slave_driver; 32 | pub mod ieee802154; 33 | pub mod isl29035; 34 | pub mod led; 35 | pub mod low_level_debug; 36 | pub mod lps25hb; 37 | pub mod ltc294x; 38 | pub mod max17205; 39 | pub mod mcp230xx; 40 | pub mod mx25r6435f; 41 | pub mod ninedof; 42 | pub mod nonvolatile_storage_driver; 43 | pub mod nonvolatile_to_pages; 44 | pub mod nrf51822_serialization; 45 | pub mod pca9544a; 46 | pub mod process_console; 47 | pub mod rf233; 48 | pub mod rf233_const; 49 | pub mod rng; 50 | pub mod sdcard; 51 | pub mod segger_rtt; 52 | pub mod si7021; 53 | pub mod spi; 54 | pub mod temperature; 55 | pub mod tmp006; 56 | pub mod tsl2561; 57 | pub mod usb; 58 | pub mod virtual_alarm; 59 | pub mod virtual_flash; 60 | pub mod virtual_i2c; 61 | pub mod virtual_pwm; 62 | pub mod virtual_spi; 63 | pub mod virtual_uart; 64 | -------------------------------------------------------------------------------- /capsules/src/low_level_debug/README.md: -------------------------------------------------------------------------------- 1 | Low Level Debug 2 | =============== 3 | 4 | The Low Level Debug capsule provides debugging facilities to userspace for 5 | debugging low-level issues such as miscompilation and incorrect relocation. It 6 | implements the system call API described 7 | [here](../doc/syscalls/00008_low_level_debug.md). 8 | -------------------------------------------------------------------------------- /capsules/src/net/icmpv6/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod icmpv6; 2 | pub mod icmpv6_send; 3 | -------------------------------------------------------------------------------- /capsules/src/net/ipv6/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod ip_utils; 2 | pub mod ipv6; 3 | pub mod ipv6_recv; 4 | pub mod ipv6_send; 5 | -------------------------------------------------------------------------------- /capsules/src/net/mod.rs: -------------------------------------------------------------------------------- 1 | //! Modules for IPv6 over 6LoWPAN stack 2 | 3 | pub mod frag_utils; 4 | pub mod sixlowpan; 5 | pub mod util; 6 | #[macro_use] 7 | pub mod stream; 8 | pub mod icmpv6; 9 | pub mod ieee802154; 10 | pub mod ipv6; 11 | pub mod tcp; 12 | pub mod thread; 13 | pub mod udp; 14 | -------------------------------------------------------------------------------- /capsules/src/net/sixlowpan/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod sixlowpan_compression; 2 | pub mod sixlowpan_state; 3 | -------------------------------------------------------------------------------- /capsules/src/net/tcp.rs: -------------------------------------------------------------------------------- 1 | /* Though TCP has not yet been implemented for the Tock Networking stackm 2 | this file defines the structure of the TCPHeader and TCPPacket structs 3 | so that TCPPacket can be included for clarity as part of the 4 | TransportPacket enum */ 5 | 6 | #[derive(Copy, Clone)] 7 | pub struct TCPHeader { 8 | pub src_port: u16, 9 | pub dst_port: u16, 10 | pub seq_num: u32, 11 | pub ack_num: u32, 12 | pub offset_and_control: u16, 13 | pub window: u16, 14 | pub cksum: u16, 15 | pub urg_ptr: u16, 16 | } 17 | 18 | /* 19 | impl TCPPacket<'a> { 20 | pub fn new(buf: &mut [u8]) -> TCPPacket<'a> { 21 | let header = TCPHeader { 22 | src_port: 0, 23 | dst_port: 0, 24 | seq_num: 0, 25 | ack_num: 0, 26 | offset_and_control: 0, 27 | window: 0, 28 | cksum: 0, 29 | urg_ptr: 0, 30 | }; 31 | TCPPacket { 32 | head: header, 33 | payload: buf, 34 | len: 0, 35 | } 36 | } 37 | } 38 | */ 39 | -------------------------------------------------------------------------------- /capsules/src/net/thread/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod tlv; 2 | -------------------------------------------------------------------------------- /capsules/src/net/udp/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod driver; 2 | pub mod udp; 3 | pub mod udp_port_table; 4 | pub mod udp_recv; 5 | pub mod udp_send; 6 | 7 | pub use self::driver::UDPDriver; 8 | pub use self::driver::DRIVER_NUM; 9 | -------------------------------------------------------------------------------- /capsules/src/test/alarm.rs: -------------------------------------------------------------------------------- 1 | //! Test that an Alarm implementation is working. Depends on a working 2 | //! UART and debug! macro. 3 | //! 4 | //! Author: Philip Levis 5 | //! Last Modified: 1/10/2020 6 | use core::cell::Cell; 7 | use kernel::debug; 8 | use kernel::hil::time::{Alarm, AlarmClient, Frequency}; 9 | 10 | pub struct TestAlarm<'a, A: Alarm<'a>> { 11 | alarm: &'a A, 12 | ms: Cell, 13 | } 14 | 15 | impl> TestAlarm<'a, A> { 16 | pub fn new(alarm: &'a A) -> TestAlarm<'a, A> { 17 | TestAlarm { 18 | alarm: alarm, 19 | ms: Cell::new(0), 20 | } 21 | } 22 | 23 | pub fn run(&self) { 24 | debug!("Starting alarms."); 25 | self.ms.set(10000); 26 | self.set_next_alarm(10000); 27 | } 28 | 29 | fn set_next_alarm(&self, ms: u32) { 30 | self.ms.set(ms); 31 | let now = self.alarm.now(); 32 | let freq: u64 = ::frequency() as u64; 33 | let lticks: u64 = ms as u64 * freq; 34 | let ticks: u32 = (lticks / 1000) as u32; 35 | let t = now.wrapping_add(ticks); 36 | debug!("Setting alarm to {}", t); 37 | self.alarm.set_alarm(t); 38 | } 39 | } 40 | 41 | impl> AlarmClient for TestAlarm<'a, A> { 42 | fn fired(&self) { 43 | // Generate a new interval that's irregular 44 | let new_ms: u32 = 10 + ((self.ms.get() + 137) % 757); 45 | self.set_next_alarm(new_ms); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /capsules/src/test/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod aes; 2 | pub mod aes_ccm; 3 | pub mod alarm; 4 | pub mod rng; 5 | pub mod udp; 6 | pub mod virtual_uart; 7 | -------------------------------------------------------------------------------- /capsules/src/usb/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod descriptors; 2 | pub mod usb_user; 3 | pub mod usbc_client; 4 | pub mod usbc_client_ctrl; 5 | -------------------------------------------------------------------------------- /chips/arty_e21/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "arty_e21" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | sifive = { path = "../sifive" } 9 | rv32i = { path = "../../arch/rv32i" } 10 | kernel = { path = "../../kernel" } 11 | 12 | -------------------------------------------------------------------------------- /chips/arty_e21/README.md: -------------------------------------------------------------------------------- 1 | SiFive E21 Core 2 | ======================= 3 | 4 | The E21 core runs on the Arty FPGA boards. 5 | 6 | -------------------------------------------------------------------------------- /chips/arty_e21/src/interrupts.rs: -------------------------------------------------------------------------------- 1 | //! Named interrupts for the E21 Arty core. 2 | 3 | #![allow(dead_code)] 4 | 5 | pub const MTIP: u32 = 7; // Machine Timer 6 | 7 | pub const GPIO0: u32 = 18; 8 | pub const GPIO1: u32 = 19; 9 | pub const GPIO2: u32 = 20; 10 | pub const GPIO3: u32 = 21; 11 | pub const GPIO4: u32 = 22; 12 | pub const GPIO5: u32 = 23; 13 | pub const GPIO6: u32 = 24; 14 | pub const GPIO7: u32 = 25; 15 | pub const GPIO8: u32 = 26; 16 | pub const GPIO9: u32 = 27; 17 | pub const GPIO10: u32 = 28; 18 | pub const GPIO11: u32 = 29; 19 | pub const GPIO12: u32 = 30; 20 | pub const GPIO13: u32 = 31; 21 | pub const GPIO14: u32 = 32; 22 | pub const GPIO15: u32 = 33; 23 | pub const UART0: u32 = 16; 24 | -------------------------------------------------------------------------------- /chips/arty_e21/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Drivers and chip support for the E21 soft core. 2 | 3 | #![feature(asm, concat_idents, const_fn)] 4 | #![feature(exclusive_range_pattern)] 5 | #![no_std] 6 | #![crate_name = "arty_e21"] 7 | #![crate_type = "rlib"] 8 | 9 | mod interrupts; 10 | 11 | pub mod chip; 12 | pub mod gpio; 13 | pub mod timer; 14 | pub mod uart; 15 | -------------------------------------------------------------------------------- /chips/arty_e21/src/timer.rs: -------------------------------------------------------------------------------- 1 | //! Machine Timer instantiation. 2 | 3 | use kernel::common::StaticRef; 4 | use rv32i::machine_timer::{MachineTimer, MachineTimerRegisters}; 5 | 6 | pub static mut MACHINETIMER: MachineTimer = MachineTimer::new(MTIME_BASE); 7 | 8 | const MTIME_BASE: StaticRef = 9 | unsafe { StaticRef::new(0x0200_0000 as *const MachineTimerRegisters) }; 10 | -------------------------------------------------------------------------------- /chips/arty_e21/src/uart.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::StaticRef; 2 | use sifive::uart::{Uart, UartRegisters}; 3 | 4 | pub static mut UART0: Uart = Uart::new(UART0_BASE, 32_000_000); 5 | 6 | const UART0_BASE: StaticRef = 7 | unsafe { StaticRef::new(0x2000_0000 as *const UartRegisters) }; 8 | -------------------------------------------------------------------------------- /chips/cc26x2/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cc26x2" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | cortexm4 = { path = "../../arch/cortex-m4" } 9 | tock_rt0 = { path = "../../libraries/tock-rt0" } 10 | kernel = { path = "../../kernel" } 11 | enum_primitive = { path = "../../libraries/enum_primitive" } 12 | -------------------------------------------------------------------------------- /chips/cc26x2/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![feature(const_fn, untagged_unions)] 2 | #![feature(in_band_lifetimes)] 3 | #![no_std] 4 | #![crate_name = "cc26x2"] 5 | #![crate_type = "rlib"] 6 | 7 | pub mod aon; 8 | pub mod ccfg; 9 | pub mod chip; 10 | pub mod crt1; 11 | pub mod event; 12 | pub mod gpio; 13 | pub mod gpt; 14 | pub mod i2c; 15 | pub mod ioc; 16 | pub mod memory_map; 17 | pub mod peripheral_interrupts; 18 | pub mod prcm; 19 | pub mod pwm; 20 | pub mod rom; 21 | pub mod rtc; 22 | pub mod trng; 23 | pub mod uart; 24 | 25 | pub use crate::crt1::init; 26 | -------------------------------------------------------------------------------- /chips/cc26x2/src/peripheral_interrupts.rs: -------------------------------------------------------------------------------- 1 | use enum_primitive::cast::FromPrimitive; 2 | use enum_primitive::enum_from_primitive; 3 | 4 | enum_from_primitive! { 5 | #[derive(Debug, PartialEq)] 6 | pub enum NvicIrq { 7 | Gpio = 0, 8 | I2c0 = 1, 9 | RfCorePe1 = 2, 10 | //UNASSIGNED 3 11 | AonRtc = 4, 12 | Uart0 = 5, 13 | Ssi0 = 7, 14 | Ssi1 = 8, 15 | RfCorePe2 = 9, 16 | RfCoreHw = 10, 17 | RfCmdAck = 11, 18 | I2s = 12, 19 | //UNASSIGNED 13 20 | Watchdog = 14, 21 | Gpt0a = 15, 22 | Gpt0b = 16, 23 | Gpt1a = 17, 24 | Gpt1b = 18, 25 | Gpt2a = 19, 26 | Gpt2b = 20, 27 | Gpt3a = 21, 28 | Gpt3b = 22, 29 | Crypto = 23, 30 | DmaSu = 24, 31 | DmaError = 25, 32 | Flash = 26, 33 | SwEvent0 = 27, 34 | AuxCombined = 28, 35 | AonProg = 29, 36 | DynamicProg = 30, 37 | AuxCompA = 31, 38 | AuxAdc = 32, 39 | Trng = 33, 40 | Uart1 = 36 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /chips/e310x/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "e310x" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | sifive = { path = "../sifive" } 9 | rv32i = { path = "../../arch/rv32i" } 10 | kernel = { path = "../../kernel" } 11 | 12 | -------------------------------------------------------------------------------- /chips/e310x/README.md: -------------------------------------------------------------------------------- 1 | HiFive Freedom E310 MCU 2 | ======================= 3 | 4 | - https://www.sifive.com/chip-designer#fe310 5 | 6 | The E310 is a core developed by SiFive based on the RISC-V architecture. 7 | -------------------------------------------------------------------------------- /chips/e310x/src/interrupts.rs: -------------------------------------------------------------------------------- 1 | //! Named interrupts for the E310X chip. 2 | 3 | #![allow(dead_code)] 4 | 5 | pub const WATCHDOG: u32 = 1; 6 | pub const RTC: u32 = 2; 7 | pub const UART0: u32 = 3; 8 | pub const UART1: u32 = 4; 9 | pub const QSPI0: u32 = 5; 10 | pub const QSPI1: u32 = 6; 11 | pub const QSPI2: u32 = 7; 12 | pub const GPIO0: u32 = 8; 13 | pub const GPIO1: u32 = 9; 14 | pub const GPIO2: u32 = 10; 15 | pub const GPIO3: u32 = 11; 16 | pub const GPIO4: u32 = 12; 17 | pub const GPIO5: u32 = 13; 18 | pub const GPIO6: u32 = 14; 19 | pub const GPIO7: u32 = 15; 20 | pub const GPIO8: u32 = 16; 21 | pub const GPIO9: u32 = 17; 22 | pub const GPIO10: u32 = 18; 23 | pub const GPIO11: u32 = 19; 24 | pub const GPIO12: u32 = 20; 25 | pub const GPIO13: u32 = 21; 26 | pub const GPIO14: u32 = 22; 27 | pub const GPIO15: u32 = 23; 28 | pub const GPIO16: u32 = 24; 29 | pub const GPIO17: u32 = 25; 30 | pub const GPIO18: u32 = 26; 31 | pub const GPIO19: u32 = 27; 32 | pub const GPIO20: u32 = 28; 33 | pub const GPIO21: u32 = 29; 34 | pub const GPIO22: u32 = 30; 35 | pub const GPIO23: u32 = 31; 36 | pub const GPIO24: u32 = 32; 37 | pub const GPIO25: u32 = 33; 38 | pub const GPIO26: u32 = 34; 39 | pub const GPIO27: u32 = 35; 40 | pub const GPIO28: u32 = 36; 41 | pub const GPIO29: u32 = 37; 42 | pub const GPIO30: u32 = 38; 43 | pub const GPIO31: u32 = 39; 44 | pub const PWM0CMP0: u32 = 40; 45 | pub const PWM0CMP1: u32 = 41; 46 | pub const PWM0CMP2: u32 = 42; 47 | pub const PWM0CMP3: u32 = 43; 48 | pub const PWM1CMP0: u32 = 44; 49 | pub const PWM1CMP1: u32 = 45; 50 | pub const PWM1CMP2: u32 = 46; 51 | pub const PWM1CMP3: u32 = 47; 52 | pub const PWM2CMP0: u32 = 48; 53 | pub const PWM2CMP1: u32 = 49; 54 | pub const PWM2CMP2: u32 = 50; 55 | pub const PWM2CMP3: u32 = 51; 56 | -------------------------------------------------------------------------------- /chips/e310x/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Chip support for the E310 from SiFive. 2 | 3 | #![feature(asm, concat_idents, const_fn)] 4 | #![feature(exclusive_range_pattern)] 5 | #![no_std] 6 | #![crate_name = "e310x"] 7 | #![crate_type = "rlib"] 8 | 9 | mod interrupts; 10 | 11 | pub mod chip; 12 | pub mod gpio; 13 | pub mod plic; 14 | pub mod prci; 15 | pub mod pwm; 16 | pub mod rtc; 17 | pub mod timer; 18 | pub mod uart; 19 | pub mod watchdog; 20 | -------------------------------------------------------------------------------- /chips/e310x/src/prci.rs: -------------------------------------------------------------------------------- 1 | //! Power Reset Clock Interrupt controller instantiation. 2 | 3 | use kernel::common::StaticRef; 4 | use sifive::prci::{Prci, PrciRegisters}; 5 | 6 | pub static mut PRCI: Prci = Prci::new(PRCI_BASE); 7 | 8 | const PRCI_BASE: StaticRef = 9 | unsafe { StaticRef::new(0x1000_8000 as *const PrciRegisters) }; 10 | -------------------------------------------------------------------------------- /chips/e310x/src/pwm.rs: -------------------------------------------------------------------------------- 1 | //! PWM instantiation. 2 | 3 | use kernel::common::StaticRef; 4 | use sifive::pwm::{Pwm, PwmRegisters}; 5 | 6 | pub static mut PWM0: Pwm = Pwm::new(PWM0_BASE); 7 | pub static mut PWM1: Pwm = Pwm::new(PWM1_BASE); 8 | pub static mut PWM2: Pwm = Pwm::new(PWM2_BASE); 9 | 10 | const PWM0_BASE: StaticRef = 11 | unsafe { StaticRef::new(0x10015000 as *const PwmRegisters) }; 12 | const PWM1_BASE: StaticRef = 13 | unsafe { StaticRef::new(0x10025000 as *const PwmRegisters) }; 14 | const PWM2_BASE: StaticRef = 15 | unsafe { StaticRef::new(0x10035000 as *const PwmRegisters) }; 16 | -------------------------------------------------------------------------------- /chips/e310x/src/rtc.rs: -------------------------------------------------------------------------------- 1 | //! RTC instantiation. 2 | 3 | use kernel::common::StaticRef; 4 | use sifive::rtc::{Rtc, RtcRegisters}; 5 | 6 | pub static mut RTC: Rtc = Rtc::new(RTC_BASE); 7 | 8 | const RTC_BASE: StaticRef = 9 | unsafe { StaticRef::new(0x1000_0040 as *const RtcRegisters) }; 10 | -------------------------------------------------------------------------------- /chips/e310x/src/timer.rs: -------------------------------------------------------------------------------- 1 | //! Machine Timer instantiation. 2 | 3 | use kernel::common::StaticRef; 4 | use rv32i::machine_timer::{MachineTimer, MachineTimerRegisters}; 5 | 6 | pub static mut MACHINETIMER: MachineTimer = MachineTimer::new(MTIME_BASE); 7 | 8 | const MTIME_BASE: StaticRef = 9 | unsafe { StaticRef::new(0x0200_0000 as *const MachineTimerRegisters) }; 10 | -------------------------------------------------------------------------------- /chips/e310x/src/uart.rs: -------------------------------------------------------------------------------- 1 | //! UART instantiation. 2 | 3 | use kernel::common::StaticRef; 4 | use sifive::uart::{Uart, UartRegisters}; 5 | 6 | pub static mut UART0: Uart = Uart::new(UART0_BASE, 18_000_000); 7 | 8 | const UART0_BASE: StaticRef = 9 | unsafe { StaticRef::new(0x1001_3000 as *const UartRegisters) }; 10 | -------------------------------------------------------------------------------- /chips/e310x/src/watchdog.rs: -------------------------------------------------------------------------------- 1 | //! Watchdog instantiation. 2 | 3 | use kernel::common::StaticRef; 4 | 5 | use sifive::watchdog::{Watchdog, WatchdogRegisters}; 6 | 7 | pub static mut WATCHDOG: Watchdog = Watchdog::new(WATCHDOG_BASE); 8 | 9 | const WATCHDOG_BASE: StaticRef = 10 | unsafe { StaticRef::new(0x1000_0000 as *const WatchdogRegisters) }; 11 | -------------------------------------------------------------------------------- /chips/ibex/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ibex" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | lowrisc = { path = "../lowrisc" } 9 | rv32i = { path = "../../arch/rv32i" } 10 | kernel = { path = "../../kernel" } 11 | 12 | -------------------------------------------------------------------------------- /chips/ibex/README.md: -------------------------------------------------------------------------------- 1 | lowRISC Ibex Core 2 | ======================= 3 | 4 | The [Ibex core](https://github.com/lowRISC/ibex) core runs on OpenTitan. 5 | 6 | -------------------------------------------------------------------------------- /chips/ibex/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Drivers and chip support for the Ibex soft core. 2 | 3 | #![feature(asm, concat_idents, const_fn, naked_functions)] 4 | #![feature(in_band_lifetimes)] 5 | #![no_std] 6 | #![crate_name = "ibex"] 7 | #![crate_type = "rlib"] 8 | 9 | mod interrupts; 10 | 11 | pub mod chip; 12 | pub mod gpio; 13 | pub mod plic; 14 | pub mod timer; 15 | pub mod uart; 16 | -------------------------------------------------------------------------------- /chips/ibex/src/uart.rs: -------------------------------------------------------------------------------- 1 | use kernel::common::StaticRef; 2 | use lowrisc::uart::{Uart, UartRegisters}; 3 | 4 | use crate::chip; 5 | 6 | pub static mut UART0: Uart = Uart::new(UART0_BASE, chip::CHIP_FREQ); 7 | 8 | const UART0_BASE: StaticRef = 9 | unsafe { StaticRef::new(0x4000_0000 as *const UartRegisters) }; 10 | -------------------------------------------------------------------------------- /chips/lowrisc/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "lowrisc" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | rv32i = { path = "../../arch/rv32i" } 9 | kernel = { path = "../../kernel" } 10 | tock_rt0 = { path = "../../libraries/tock-rt0" } 11 | -------------------------------------------------------------------------------- /chips/lowrisc/README.md: -------------------------------------------------------------------------------- 1 | LoWRISC Peripherals 2 | ======================= 3 | 4 | This crate contains various peripherals shared between various LowRISC 5 | cores. 6 | 7 | -------------------------------------------------------------------------------- /chips/lowrisc/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Implementations for generic LowRISC peripherals. 2 | 3 | #![feature(asm, concat_idents, const_fn, core_intrinsics)] 4 | #![feature(in_band_lifetimes)] 5 | #![feature(exclusive_range_pattern)] 6 | #![no_std] 7 | #![crate_name = "lowrisc"] 8 | #![crate_type = "rlib"] 9 | 10 | pub mod gpio; 11 | pub mod uart; 12 | -------------------------------------------------------------------------------- /chips/nrf52/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "nrf52" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | cortexm4 = { path = "../../arch/cortex-m4" } 9 | kernel = { path = "../../kernel" } 10 | tock_rt0 = { path = "../../libraries/tock-rt0" } 11 | enum_primitive = { path = "../../libraries/enum_primitive" } 12 | 13 | [dependencies.nrf5x] 14 | path = "../nrf5x" 15 | features = ["nrf52"] 16 | -------------------------------------------------------------------------------- /chips/nrf52/README.md: -------------------------------------------------------------------------------- 1 | # Nordic Semiconductor nRF52 Series SoC 2 | 3 | Builds upon the `nRF52` crate and includes hardware setup that is specific to the nRF52 series. 4 | Boards that include an nRF52x chip should depend on a more specific crate (such as `nrf52832` or 5 | `nrf52840`) instead of this one. 6 | 7 | ## Links 8 | 9 | * [General information](https://www.nordicsemi.com/eng/Products/Bluetooth-low-energy/nRF52-DK) 10 | * [Datasheet](http://infocenter.nordicsemi.com/pdf/nRF52832_PS_v1.0.pdf) 11 | -------------------------------------------------------------------------------- /chips/nrf52/src/deferred_call_tasks.rs: -------------------------------------------------------------------------------- 1 | //! Definition of Deferred Call tasks. 2 | //! 3 | //! Deferred calls also peripheral drivers to register pseudo interrupts. 4 | //! These are the definitions of which deferred calls this chip needs. 5 | 6 | use core::convert::Into; 7 | use core::convert::TryFrom; 8 | 9 | /// A type of task to defer a call for 10 | #[derive(Copy, Clone)] 11 | pub enum DeferredCallTask { 12 | Nvmc = 0, 13 | } 14 | 15 | impl TryFrom for DeferredCallTask { 16 | type Error = (); 17 | 18 | fn try_from(value: usize) -> Result { 19 | match value { 20 | 0 => Ok(DeferredCallTask::Nvmc), 21 | _ => Err(()), 22 | } 23 | } 24 | } 25 | 26 | impl Into for DeferredCallTask { 27 | fn into(self) -> usize { 28 | self as usize 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /chips/nrf52/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![feature(asm, const_fn, core_intrinsics)] 2 | #![no_std] 3 | #![crate_name = "nrf52"] 4 | #![crate_type = "rlib"] 5 | 6 | pub mod acomp; 7 | pub mod adc; 8 | pub mod ble_radio; 9 | pub mod chip; 10 | pub mod clock; 11 | pub mod crt1; 12 | mod deferred_call_tasks; 13 | pub mod ficr; 14 | pub mod i2c; 15 | pub mod ieee802154_radio; 16 | pub mod interrupt_service; 17 | pub mod nvmc; 18 | pub mod power; 19 | pub mod ppi; 20 | pub mod pwm; 21 | pub mod spi; 22 | pub mod uart; 23 | pub mod uicr; 24 | pub mod usbd; 25 | 26 | pub use crate::crt1::init; 27 | pub use nrf5x::{ 28 | aes, constants, gpio, peripheral_interrupts, pinmux, rtc, temperature, timer, trng, 29 | }; 30 | -------------------------------------------------------------------------------- /chips/nrf52832/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "nrf52832" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | cortexm4 = { path = "../../arch/cortex-m4" } 9 | kernel = { path = "../../kernel" } 10 | nrf52 = { path = "../nrf52" } 11 | tock_rt0 = { path = "../../libraries/tock-rt0" } 12 | -------------------------------------------------------------------------------- /chips/nrf52832/README.md: -------------------------------------------------------------------------------- 1 | # Nordic Semiconductor nRF52832 Series SoC 2 | 3 | Builds upon the `nRF52` crate and includes hardware setup that is specific to this version of 4 | the nRF52 series. Boards that include an nRF52832 MCU should use this crate as a dependency 5 | and not the `nrf52` crate. 6 | -------------------------------------------------------------------------------- /chips/nrf52832/src/chip.rs: -------------------------------------------------------------------------------- 1 | use crate::interrupt_service::Nrf52832InterruptService; 2 | use nrf52::chip::NRF52; 3 | 4 | pub type Chip = NRF52; 5 | 6 | pub unsafe fn new() -> Chip { 7 | NRF52::new(Nrf52832InterruptService::new()) 8 | } 9 | -------------------------------------------------------------------------------- /chips/nrf52832/src/gpio.rs: -------------------------------------------------------------------------------- 1 | pub use nrf52::gpio::{GPIOPin, Pin, Port}; 2 | 3 | static mut PINS: [GPIOPin; 32] = [ 4 | GPIOPin::new(Pin::P0_00), 5 | GPIOPin::new(Pin::P0_01), 6 | GPIOPin::new(Pin::P0_02), 7 | GPIOPin::new(Pin::P0_03), 8 | GPIOPin::new(Pin::P0_04), 9 | GPIOPin::new(Pin::P0_05), 10 | GPIOPin::new(Pin::P0_06), 11 | GPIOPin::new(Pin::P0_07), 12 | GPIOPin::new(Pin::P0_08), 13 | GPIOPin::new(Pin::P0_09), 14 | GPIOPin::new(Pin::P0_10), 15 | GPIOPin::new(Pin::P0_11), 16 | GPIOPin::new(Pin::P0_12), 17 | GPIOPin::new(Pin::P0_13), 18 | GPIOPin::new(Pin::P0_14), 19 | GPIOPin::new(Pin::P0_15), 20 | GPIOPin::new(Pin::P0_16), 21 | GPIOPin::new(Pin::P0_17), 22 | GPIOPin::new(Pin::P0_18), 23 | GPIOPin::new(Pin::P0_19), 24 | GPIOPin::new(Pin::P0_20), 25 | GPIOPin::new(Pin::P0_21), 26 | GPIOPin::new(Pin::P0_22), 27 | GPIOPin::new(Pin::P0_23), 28 | GPIOPin::new(Pin::P0_24), 29 | GPIOPin::new(Pin::P0_25), 30 | GPIOPin::new(Pin::P0_26), 31 | GPIOPin::new(Pin::P0_27), 32 | GPIOPin::new(Pin::P0_28), 33 | GPIOPin::new(Pin::P0_29), 34 | GPIOPin::new(Pin::P0_30), 35 | GPIOPin::new(Pin::P0_31), 36 | ]; 37 | 38 | pub static mut PORT: Port = Port { 39 | pins: unsafe { &mut PINS }, 40 | }; 41 | -------------------------------------------------------------------------------- /chips/nrf52832/src/interrupt_service.rs: -------------------------------------------------------------------------------- 1 | use crate::gpio; 2 | use nrf52::interrupt_service::InterruptService; 3 | 4 | pub struct Nrf52832InterruptService { 5 | nrf52: nrf52::interrupt_service::Nrf52InterruptService, 6 | } 7 | 8 | impl Nrf52832InterruptService { 9 | pub unsafe fn new() -> Nrf52832InterruptService { 10 | Nrf52832InterruptService { 11 | nrf52: nrf52::interrupt_service::Nrf52InterruptService::new(&gpio::PORT), 12 | } 13 | } 14 | } 15 | 16 | impl InterruptService for Nrf52832InterruptService { 17 | unsafe fn service_interrupt(&self, interrupt: u32) -> bool { 18 | // Add 52832-specific interrupts here. 19 | self.nrf52.service_interrupt(interrupt) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chips/nrf52832/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | pub use nrf52::{ 4 | adc, aes, ble_radio, clock, constants, crt1, ficr, i2c, ieee802154_radio, init, nvmc, 5 | peripheral_interrupts, pinmux, ppi, pwm, rtc, spi, temperature, timer, trng, uart, uicr, 6 | }; 7 | pub mod chip; 8 | pub mod gpio; 9 | pub mod interrupt_service; 10 | -------------------------------------------------------------------------------- /chips/nrf52840/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "nrf52840" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | cortexm4 = { path = "../../arch/cortex-m4" } 9 | kernel = { path = "../../kernel" } 10 | nrf52 = { path = "../nrf52" } 11 | tock_rt0 = { path = "../../libraries/tock-rt0" } 12 | -------------------------------------------------------------------------------- /chips/nrf52840/README.md: -------------------------------------------------------------------------------- 1 | # Nordic Semiconductor nRF52840 Series SoC 2 | 3 | Builds upon the `nRF52` crate and includes hardware setup that is specific to this version of 4 | the nRF52 series. Boards that include an nRF52840 MCU should use this crate as a dependency 5 | and not the `nrf52` crate. 6 | -------------------------------------------------------------------------------- /chips/nrf52840/src/chip.rs: -------------------------------------------------------------------------------- 1 | use crate::interrupt_service::Nrf52840InterruptService; 2 | use nrf52::chip::NRF52; 3 | 4 | pub type Chip = NRF52; 5 | 6 | pub unsafe fn new() -> Chip { 7 | NRF52::new(Nrf52840InterruptService::new()) 8 | } 9 | -------------------------------------------------------------------------------- /chips/nrf52840/src/gpio.rs: -------------------------------------------------------------------------------- 1 | pub use nrf52::gpio::{GPIOPin, Pin, Port}; 2 | 3 | static mut PINS: [GPIOPin; 48] = [ 4 | GPIOPin::new(Pin::P0_00), 5 | GPIOPin::new(Pin::P0_01), 6 | GPIOPin::new(Pin::P0_02), 7 | GPIOPin::new(Pin::P0_03), 8 | GPIOPin::new(Pin::P0_04), 9 | GPIOPin::new(Pin::P0_05), 10 | GPIOPin::new(Pin::P0_06), 11 | GPIOPin::new(Pin::P0_07), 12 | GPIOPin::new(Pin::P0_08), 13 | GPIOPin::new(Pin::P0_09), 14 | GPIOPin::new(Pin::P0_10), 15 | GPIOPin::new(Pin::P0_11), 16 | GPIOPin::new(Pin::P0_12), 17 | GPIOPin::new(Pin::P0_13), 18 | GPIOPin::new(Pin::P0_14), 19 | GPIOPin::new(Pin::P0_15), 20 | GPIOPin::new(Pin::P0_16), 21 | GPIOPin::new(Pin::P0_17), 22 | GPIOPin::new(Pin::P0_18), 23 | GPIOPin::new(Pin::P0_19), 24 | GPIOPin::new(Pin::P0_20), 25 | GPIOPin::new(Pin::P0_21), 26 | GPIOPin::new(Pin::P0_22), 27 | GPIOPin::new(Pin::P0_23), 28 | GPIOPin::new(Pin::P0_24), 29 | GPIOPin::new(Pin::P0_25), 30 | GPIOPin::new(Pin::P0_26), 31 | GPIOPin::new(Pin::P0_27), 32 | GPIOPin::new(Pin::P0_28), 33 | GPIOPin::new(Pin::P0_29), 34 | GPIOPin::new(Pin::P0_30), 35 | GPIOPin::new(Pin::P0_31), 36 | GPIOPin::new(Pin::P1_00), 37 | GPIOPin::new(Pin::P1_01), 38 | GPIOPin::new(Pin::P1_02), 39 | GPIOPin::new(Pin::P1_03), 40 | GPIOPin::new(Pin::P1_04), 41 | GPIOPin::new(Pin::P1_05), 42 | GPIOPin::new(Pin::P1_06), 43 | GPIOPin::new(Pin::P1_07), 44 | GPIOPin::new(Pin::P1_08), 45 | GPIOPin::new(Pin::P1_09), 46 | GPIOPin::new(Pin::P1_10), 47 | GPIOPin::new(Pin::P1_11), 48 | GPIOPin::new(Pin::P1_12), 49 | GPIOPin::new(Pin::P1_13), 50 | GPIOPin::new(Pin::P1_14), 51 | GPIOPin::new(Pin::P1_15), 52 | ]; 53 | 54 | pub static mut PORT: Port = Port { 55 | pins: unsafe { &mut PINS }, 56 | }; 57 | -------------------------------------------------------------------------------- /chips/nrf52840/src/interrupt_service.rs: -------------------------------------------------------------------------------- 1 | use crate::gpio; 2 | use crate::peripheral_interrupts; 3 | use nrf52::interrupt_service::InterruptService; 4 | 5 | pub struct Nrf52840InterruptService { 6 | nrf52: nrf52::interrupt_service::Nrf52InterruptService, 7 | } 8 | 9 | impl Nrf52840InterruptService { 10 | pub unsafe fn new() -> Nrf52840InterruptService { 11 | Nrf52840InterruptService { 12 | nrf52: nrf52::interrupt_service::Nrf52InterruptService::new(&gpio::PORT), 13 | } 14 | } 15 | } 16 | 17 | impl InterruptService for Nrf52840InterruptService { 18 | unsafe fn service_interrupt(&self, interrupt: u32) -> bool { 19 | match interrupt { 20 | peripheral_interrupts::USBD => nrf52::usbd::USBD.handle_interrupt(), 21 | _ => return self.nrf52.service_interrupt(interrupt), 22 | } 23 | true 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chips/nrf52840/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | pub use nrf52::{ 4 | acomp, adc, aes, ble_radio, clock, constants, crt1, ficr, i2c, ieee802154_radio, init, nvmc, 5 | pinmux, ppi, pwm, rtc, spi, temperature, timer, trng, uart, uicr, 6 | }; 7 | pub mod chip; 8 | pub mod gpio; 9 | pub mod interrupt_service; 10 | 11 | mod peripheral_interrupts; 12 | -------------------------------------------------------------------------------- /chips/nrf52840/src/peripheral_interrupts.rs: -------------------------------------------------------------------------------- 1 | pub const USBD: u32 = 39; 2 | #[allow(dead_code)] 3 | pub const UART1: u32 = 40; 4 | #[allow(dead_code)] 5 | pub const QSPI: u32 = 41; 6 | #[allow(dead_code)] 7 | pub const CRYPTOCELL: u32 = 42; 8 | #[allow(dead_code)] 9 | pub const PWM3: u32 = 45; 10 | #[allow(dead_code)] 11 | pub const SPIM3: u32 = 47; 12 | -------------------------------------------------------------------------------- /chips/nrf5x/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "nrf5x" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | kernel = { path = "../../kernel" } 9 | enum_primitive = { path = "../../libraries/enum_primitive" } 10 | 11 | [features] 12 | default = [] 13 | 14 | nrf51 = [] 15 | nrf52 = [] 16 | -------------------------------------------------------------------------------- /chips/nrf5x/README.md: -------------------------------------------------------------------------------- 1 | # Nordic Semiconductor nRF5X Series SoC 2 | -------------------------------------------------------------------------------- /chips/nrf5x/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![feature(const_fn, in_band_lifetimes)] 2 | #![no_std] 3 | #![allow(unused_doc_comments)] 4 | 5 | pub mod aes; 6 | pub mod constants; 7 | pub mod gpio; 8 | pub mod peripheral_interrupts; 9 | pub mod pinmux; 10 | pub mod rtc; 11 | pub mod temperature; 12 | pub mod timer; 13 | pub mod trng; 14 | -------------------------------------------------------------------------------- /chips/nrf5x/src/peripheral_interrupts.rs: -------------------------------------------------------------------------------- 1 | pub const POWER_CLOCK: u32 = 0; 2 | pub const RADIO: u32 = 1; 3 | pub const UART0: u32 = 2; 4 | pub const SPI0_TWI0: u32 = 3; 5 | pub const SPI1_TWI1: u32 = 4; 6 | #[cfg(feature = "nrf52")] 7 | pub const NFCT: u32 = 5; 8 | pub const GPIOTE: u32 = 6; 9 | pub const ADC: u32 = 7; 10 | pub const TIMER0: u32 = 8; 11 | pub const TIMER1: u32 = 9; 12 | pub const TIMER2: u32 = 10; 13 | pub const RTC0: u32 = 11; 14 | pub const TEMP: u32 = 12; 15 | pub const RNG: u32 = 13; 16 | pub const ECB: u32 = 14; 17 | pub const CCM_AAR: u32 = 15; 18 | pub const WDT: u32 = 16; 19 | pub const RTC1: u32 = 17; 20 | pub const QDEC: u32 = 18; 21 | pub const COMP: u32 = 19; 22 | pub const LPCOMP: u32 = 19; 23 | pub const SWI0: u32 = 20; 24 | pub const SWI1: u32 = 21; 25 | pub const SWI2: u32 = 22; 26 | pub const SWI3: u32 = 23; 27 | pub const SWI4: u32 = 24; 28 | pub const SWI5: u32 = 25; 29 | #[cfg(feature = "nrf52")] 30 | pub const TIMER3: u32 = 26; 31 | #[cfg(feature = "nrf52")] 32 | pub const TIMER4: u32 = 27; 33 | #[cfg(feature = "nrf52")] 34 | pub const PWM0: u32 = 28; 35 | #[cfg(feature = "nrf52")] 36 | pub const PDM: u32 = 29; 37 | #[cfg(feature = "nrf52")] 38 | pub const MWU: u32 = 32; 39 | #[cfg(feature = "nrf52")] 40 | pub const PWM1: u32 = 33; 41 | #[cfg(feature = "nrf52")] 42 | pub const PWM2: u32 = 34; 43 | #[cfg(feature = "nrf52")] 44 | pub const SPIM2_SPIS2_SPI2: u32 = 35; 45 | #[cfg(feature = "nrf52")] 46 | pub const RTC2: u32 = 36; 47 | #[cfg(feature = "nrf52")] 48 | pub const I2S: u32 = 37; 49 | #[cfg(feature = "nrf52")] 50 | pub const FPU: u32 = 38; 51 | -------------------------------------------------------------------------------- /chips/nrf5x/src/pinmux.rs: -------------------------------------------------------------------------------- 1 | //! An abstraction over the pin multiplexer, nRF5X-family 2 | //! 3 | //! Controller drivers should use the `Pinmux` type (instead of a `u32`) for 4 | //! fields that determine which pins are used by the hardware. The board 5 | //! configuration should create `Pinmux`s and pass them into controller drivers 6 | //! during initialization. 7 | 8 | use kernel::common::cells::VolatileCell; 9 | 10 | // Note: only the nrf52840 has two ports, but we create two ports to avoid 11 | // gating this code by a feature. 12 | const NUM_PORTS: usize = 2; 13 | 14 | const PIN_PER_PORT: usize = 32; 15 | 16 | // Keep track of which pins has a `Pinmux` been created for. 17 | static mut USED_PINS: [VolatileCell; NUM_PORTS] = [VolatileCell::new(0), VolatileCell::new(0)]; 18 | 19 | /// An opaque wrapper around a configurable pin. 20 | #[derive(Copy, Clone)] 21 | pub struct Pinmux(u32); 22 | 23 | impl Pinmux { 24 | /// Creates a new `Pinmux` wrapping the numbered pin. 25 | /// 26 | /// # Panics 27 | /// 28 | /// If a `Pinmux` for this pin has already 29 | /// been created. 30 | /// 31 | pub unsafe fn new(pin: u32) -> Pinmux { 32 | let port: usize = (pin as usize) / PIN_PER_PORT; 33 | let pin_idx: usize = (pin as usize) % PIN_PER_PORT; 34 | let used_pins = USED_PINS[port].get(); 35 | if used_pins & (1 << pin_idx) != 0 { 36 | panic!("Pin {} is already in use!", pin); 37 | } else { 38 | USED_PINS[port].set(used_pins | 1 << pin_idx); 39 | Pinmux(pin) 40 | } 41 | } 42 | } 43 | 44 | impl Into for Pinmux { 45 | fn into(self) -> u32 { 46 | self.0 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /chips/sam4l/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sam4l" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | cortexm4 = { path = "../../arch/cortex-m4" } 9 | tock_rt0 = { path = "../../libraries/tock-rt0" } 10 | kernel = { path = "../../kernel" } 11 | -------------------------------------------------------------------------------- /chips/sam4l/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Atmel SAM4L 3 | 4 | ## Links 5 | 6 | * [General information](http://www.atmel.com/devices/ATSAM4LC8C.aspx) 7 | * [Datasheet](http://www.atmel.com/Images/Atmel-42023-ARM-Microcontroller-ATSAM4L-Low-Power-LCD_Datasheet.pdf) 8 | 9 | -------------------------------------------------------------------------------- /chips/sam4l/src/deferred_call_tasks.rs: -------------------------------------------------------------------------------- 1 | //! Definition of Deferred Call tasks. 2 | //! 3 | //! Deferred calls allow peripheral drivers to register pseudo interrupts. 4 | //! These are the definitions of which deferred calls this chip needs. 5 | 6 | use core::convert::Into; 7 | use core::convert::TryFrom; 8 | 9 | /// A type of task to defer a call for 10 | #[derive(Copy, Clone)] 11 | pub enum Task { 12 | Flashcalw = 0, 13 | } 14 | 15 | impl TryFrom for Task { 16 | type Error = (); 17 | 18 | fn try_from(value: usize) -> Result { 19 | match value { 20 | 0 => Ok(Task::Flashcalw), 21 | _ => Err(()), 22 | } 23 | } 24 | } 25 | 26 | impl Into for Task { 27 | fn into(self) -> usize { 28 | self as usize 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /chips/sam4l/src/serial_num.rs: -------------------------------------------------------------------------------- 1 | //! Provides a struct that enables access to the unique 120 bit serial number stored in read-only 2 | //! flash on the sam4l. 3 | 4 | use kernel::common::StaticRef; 5 | 6 | // The sam4l stores a unique 120 bit serial number readable from address 0x0080020C to 0x0080021A 7 | // This value cannot be written to normally, and instead requires special instructions to overwrite, 8 | // which we do not implement. Because this number is stored in the user page of flash memory, 9 | // it is not cleared by chip erase. 10 | #[repr(C)] 11 | struct sam4lSerialRegister { 12 | serial_num: [u8; 15], 13 | } 14 | 15 | const SERIAL_NUM_ADDRESS: StaticRef = 16 | unsafe { StaticRef::new(0x0080020C as *const sam4lSerialRegister) }; 17 | 18 | /// Struct that can be used to get the unique serial number of the sam4l 19 | pub struct SerialNum { 20 | regs: StaticRef, 21 | } 22 | 23 | impl SerialNum { 24 | /// Returns a struct that can read the serial number of the sam4l 25 | pub fn new() -> SerialNum { 26 | SerialNum { 27 | regs: SERIAL_NUM_ADDRESS, 28 | } 29 | } 30 | 31 | /// Returns the 120-bit serial number of the sam4l in a byte array 32 | pub fn get(&self) -> [u8; 15] { 33 | self.regs.serial_num 34 | } 35 | 36 | /// Helper function for simply returning the lower 64 bits of the serial number 37 | /// as a u64 rather than a byte array 38 | pub fn get_lower_64(&self) -> u64 { 39 | let full_num = self.regs.serial_num; 40 | full_num 41 | .iter() 42 | .rev() 43 | .take(8) 44 | .enumerate() 45 | .fold(0u64, |sum, (i, &val)| sum + ((val as u64) << i * 8)) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /chips/sifive/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sifive" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | rv32i = { path = "../../arch/rv32i" } 9 | kernel = { path = "../../kernel" } 10 | 11 | -------------------------------------------------------------------------------- /chips/sifive/README.md: -------------------------------------------------------------------------------- 1 | SiFive Peripherals 2 | ======================= 3 | 4 | This crate contains various peripherals shared between various SiFive 5 | cores. 6 | 7 | -------------------------------------------------------------------------------- /chips/sifive/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Implementations for generic SiFive MCU peripherals. 2 | 3 | #![feature(asm, concat_idents, const_fn, core_intrinsics)] 4 | #![feature(in_band_lifetimes)] 5 | #![feature(exclusive_range_pattern)] 6 | #![no_std] 7 | #![crate_name = "sifive"] 8 | #![crate_type = "rlib"] 9 | 10 | pub mod gpio; 11 | pub mod prci; 12 | pub mod pwm; 13 | pub mod rtc; 14 | pub mod uart; 15 | pub mod watchdog; 16 | -------------------------------------------------------------------------------- /chips/sifive/src/rtc.rs: -------------------------------------------------------------------------------- 1 | //! Real Time Clock (RTC) driver. 2 | 3 | use kernel::common::registers::{register_bitfields, ReadWrite}; 4 | use kernel::common::StaticRef; 5 | 6 | #[repr(C)] 7 | pub struct RtcRegisters { 8 | /// RTC Configuration Register 9 | rtccfg: ReadWrite, 10 | _reserved1: [u8; 4], 11 | /// RTC Counter Low Register 12 | rtclo: ReadWrite, 13 | /// RTC Counter High Register 14 | rtchi: ReadWrite, 15 | /// RTC Scaled Counter Register 16 | rtcs: ReadWrite, 17 | _reserved2: [u8; 12], 18 | /// RTC Compare Register 19 | rtccmp: ReadWrite, 20 | } 21 | 22 | register_bitfields![u32, 23 | rtccfg [ 24 | cmpip OFFSET(28) NUMBITS(1) [], 25 | enalways OFFSET(12) NUMBITS(1) [], 26 | scale OFFSET(0) NUMBITS(4) [] 27 | ], 28 | rtclo [ 29 | rtclo OFFSET(0) NUMBITS(32) [] 30 | ], 31 | rtchi [ 32 | rtchi OFFSET(0) NUMBITS(16) [] 33 | ], 34 | rtccmp [ 35 | rtccmp OFFSET(0) NUMBITS(32) [] 36 | ] 37 | ]; 38 | 39 | pub struct Rtc { 40 | registers: StaticRef, 41 | } 42 | 43 | impl Rtc { 44 | pub const fn new(base: StaticRef) -> Rtc { 45 | Rtc { registers: base } 46 | } 47 | 48 | /// Disable the RTC so it does not generate interrupts. 49 | pub fn disable(&self) { 50 | let regs = self.registers; 51 | 52 | // Turn the interrupt compare off so we don't get any RTC interrupts. 53 | regs.rtccfg.write(rtccfg::enalways::CLEAR); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /chips/stm32f4xx/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "stm32f4xx" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | cortexm4 = { path = "../../arch/cortex-m4" } 9 | enum_primitive = { path = "../../libraries/enum_primitive" } 10 | kernel = { path = "../../kernel" } 11 | tock_rt0 = { path = "../../libraries/tock-rt0" } 12 | 13 | [features] 14 | stm32f446re = [] 15 | stm32f429zi = [] 16 | -------------------------------------------------------------------------------- /chips/stm32f4xx/README.md: -------------------------------------------------------------------------------- 1 | For STM32F4 series micro controllers 2 | 3 | 4 | ## Links 5 | ### ST STM32F446RE 6 | 7 | * [General information](https://www.st.com/en/microcontrollers/stm32f446re.html) 8 | * [Datasheet](https://www.st.com/resource/en/datasheet/stm32f446re.pdf) 9 | * [Reference Manual](https://www.st.com/resource/en/reference_manual/dm00135183.pdf) 10 | 11 | ### ST STM32F429ZI 12 | 13 | * [General information](https://www.st.com/en/microcontrollers/stm32f429zi.html) 14 | * [Datasheet](https://www.st.com/resource/en/datasheet/stm32f429zi.pdf) 15 | * [Reference Manual](https://www.st.com/resource/en/reference_manual/dm00031020.pdf) -------------------------------------------------------------------------------- /chips/stm32f4xx/src/deferred_call_tasks.rs: -------------------------------------------------------------------------------- 1 | //! Definition of Deferred Call tasks. 2 | //! 3 | //! Deferred calls allow peripheral drivers to register pseudo interrupts. 4 | //! These are the definitions of which deferred calls this chip needs. 5 | 6 | use core::convert::Into; 7 | use core::convert::TryFrom; 8 | 9 | /// A type of task to defer a call for 10 | #[derive(Copy, Clone)] 11 | pub enum Task { 12 | Nop = 0, 13 | } 14 | 15 | impl TryFrom for Task { 16 | type Error = (); 17 | 18 | fn try_from(value: usize) -> Result { 19 | match value { 20 | 0 => Ok(Task::Nop), 21 | _ => Err(()), 22 | } 23 | } 24 | } 25 | 26 | impl Into for Task { 27 | fn into(self) -> usize { 28 | self as usize 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | rustdoc/ 2 | 3 | website.zip 4 | -------------------------------------------------------------------------------- /doc/Configuration.md: -------------------------------------------------------------------------------- 1 | Configuration 2 | ============= 3 | 4 | Because Tock is meant to run on various platforms (spanning multiple 5 | architectures and various available peripherals), and with multiple use cases in 6 | mind (for example, "production" vs. debug build with various levels of debugging 7 | detail), Tock provides various configuration options so that each build can be 8 | adapted to each use case. 9 | 10 | In Tock, configuration follows some principles to avoid pitfalls of "ifdef" 11 | conditional code (which can be tricky to test). This is currently done in two 12 | ways. 13 | 14 | - **Separation of the code into multiple packages.** Each level of abstraction 15 | (core kernel, CPU architecture, chip, board) has its own package, so that 16 | configuring a board is done by depending on the relevant chip and declaring 17 | the relevant drivers for peripherals avaialble on the board. You can see more 18 | details on the [compilation page](Compilation.md). 19 | 20 | - **Custom kernel configuration.** To facilitate fine-grained configuration of 21 | the kernel (for example to enable tracing the syscalls to the debug output), a 22 | `Config` struct is defined in `kernel/src/config.rs`. To change the 23 | configuration, modify the values in the static `const` object defined in this 24 | file. To use the configuration, simply read the values. For example, to use a 25 | boolean configuration, just use an if statement: the fact that the 26 | configuration is `const` should allow the compiler to optimize away dead code 27 | (so that this configuration has zero cost), while still checking syntax and 28 | types. 29 | -------------------------------------------------------------------------------- /doc/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/architecture.png -------------------------------------------------------------------------------- /doc/courses/2017-11-SenSys/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | location: Delft, Netherlands 3 | date: November 5, 2017 4 | --- 5 | 6 | # Tock OS Training @ SenSys 2017 7 | 8 | This course introduces you to Tock, a secure embedded operating system for 9 | sensor networks and the Internet of Things. Tock is the first operating system 10 | to allow multiple untrusted applications to run concurrently on a 11 | microcontroller-based computer. The Tock kernel is written in Rust, a 12 | memory-safe systems language that does not rely on a garbage collector. 13 | Userspace applications are run in single-threaded processes that can be written 14 | in any language. A paper describing Tock's goals, design, and implementation was 15 | published at the SOSP'17 conference and is available 16 | [here](https://www.amitlevy.com/papers/tock-sosp2017.pdf). 17 | 18 | In this course, you will learn the basic Tock system architecture, how to write 19 | a userspace process in C, Tock's system call interface, and fill in code for a 20 | small kernel extension written in Rust. The course assumes experience 21 | programming embedded devices and fluency in C. It assumes no knowledge of Rust, 22 | although knowing Rust will allow you to be more creative in the Rust programming 23 | part of the course. 24 | 25 | This course was primarily designed in November of 2017, but has been updated 26 | through May 2018. It is a useful introduction to Tock but is no longer updated 27 | as Tock evolves in preparation for new courses that will be used in November 28 | 2018. To follow this course, please checkout the commit below to use Tock at a 29 | point where the tutorial is known to be working. 30 | 31 | ```bash 32 | $ git checkout 1203437bff05667bb0636dc9ab69e1daca13c2a2 33 | ``` 34 | -------------------------------------------------------------------------------- /doc/courses/2018-11-SenSys/exercises/app/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /doc/courses/2018-11-SenSys/exercises/app/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for user application 2 | 3 | # Specify this directory relative to the current application. 4 | TOCK_USERLAND_BASE_DIR = ../../../../../userland 5 | 6 | # Which files to compile. 7 | C_SRCS := $(wildcard *.c) 8 | 9 | PACKAGE_NAME = tock-course-app 10 | 11 | # Include userland master makefile. Contains rules and flags for actually 12 | # building the application. 13 | include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk 14 | -------------------------------------------------------------------------------- /doc/courses/2018-11-SenSys/exercises/app/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main (void) { 5 | printf("Hello, World!\n"); 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /doc/courses/2018-11-SenSys/exercises/app/solutions/repeat-hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | int main (void) { 7 | while (true) { 8 | printf("Hello, World!\n"); 9 | delay_ms(500); 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /doc/courses/2018-11-SenSys/exercises/app/solutions/sensors.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main (void) { 11 | while (1) { 12 | int lux; 13 | ambient_light_read_intensity_sync(&lux); 14 | printf("Light: %d lux\n", lux); 15 | 16 | /* Turn on the red LED in low light conditions */ 17 | if (lux < 30) { 18 | led_on(0); 19 | } 20 | else { 21 | led_off(0); 22 | } 23 | 24 | int temp; 25 | temperature_read_sync(&temp); 26 | printf("Temperature: %d degrees C\n", temp/100); 27 | 28 | unsigned humi; 29 | humidity_read_sync(&humi); 30 | printf("Relative humidity: %u%%\n", humi/100); 31 | 32 | printf("\n"); 33 | delay_ms(2000); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /doc/courses/2018-11-SenSys/freeform.md: -------------------------------------------------------------------------------- 1 | # Free-form Experimentation 2 | --- 3 | 4 | ## Course Agenda 5 | 6 | - [Introduction](README.md) 7 | - Part 1: [Getting started with Tock](environment.md) 8 | - Part 2: [Application Basics](application.md) 9 | - Part 3: [Client Delivery](client.md) 10 | - **Part 4: [Free-form Play](freeform.md)** 11 | 12 | --- 13 | 14 | These are seedling ideas, feel free to try one of these or anything else that 15 | strikes your fancy! 16 | 17 | ## Kernel Hacking 18 | 19 | - Understanding board configuration: 20 | - Look into the four-process limitation, where does it come from, can we add more processes, how? 21 | - How are pins mapped and buses configured? Could we do something like tie the LED to be a SPI status indicator? 22 | 23 | - Add a new capsule to the kernel (write it, include it in the crate, 24 | initialize it in a boot sequence). 25 | - Can you send 802.15.4 packets directly from the within the kernel? 26 | 27 | ## Userland Hacking 28 | 29 | - What other sensors and interfaces are available? 30 | - Write a thermal alarm app? 31 | - Write a light-change triggering motion detector app? 32 | - Understand how the timer interface works and virtual timers? 33 | 34 | - Execution model 35 | - What happens when there are multiple concurrent interrupts? 36 | - How do blocking calls and callbacks interplay? 37 | 38 | ## End-to-End Comprehension 39 | 40 | - What happens when your app returns from main? When will it run again (if at all)? 41 | 42 | - Can you diagram what happens when a process makes a blocking system call 43 | (context switch, interrupt setup, wait_for, interrupt handling, kernel 44 | thread, resuming process)? 45 | 46 | -------------------------------------------------------------------------------- /doc/courses/2018-11-SenSys/img/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/2018-11-SenSys/img/architecture.png -------------------------------------------------------------------------------- /doc/courses/2018-11-SenSys/manual_installation.md: -------------------------------------------------------------------------------- 1 | ## Manual Installation 2 | 3 | If you choose to install manually, you will need the following software: 4 | 5 | 1. Command line utilities: curl, make, git 6 | 7 | 1. Python 3 and pip3 8 | 9 | 1. A local clone of the Tock repository 10 | 11 | $ git clone https://github.com/tock/tock.git 12 | 13 | 1. A local clone of the Tock applications repository (for apps written in C) 14 | 15 | $ git clone https://github.com/tock/libtock-c.git 16 | 17 | 1. [rustup](http://rustup.rs/). This tool helps manage installations of the 18 | Rust compiler and related tools. 19 | 20 | $ curl https://sh.rustup.rs -sSf | sh 21 | 22 | 1. [arm-none-eabi toolchain](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads) (version >= 5.2) 23 | 24 | OS-specific installation instructions can be found 25 | [here](https://github.com/tock/tock/blob/master/doc/Getting_Started.md#arm-none-eabi-toolchain) 26 | 27 | 1. [tockloader](https://github.com/tock/tockloader) 28 | 29 | $ pip3 install -U --user tockloader 30 | 31 | > Note: On MacOS, you may need to add `tockloader` to your path. If you 32 | > cannot run it after installation, run the following: 33 | 34 | $ export PATH=$HOME/Library/Python/3.6/bin/:$PATH 35 | 36 | > Similarly, on Linux distributions, this will typically install to 37 | > `$HOME/.local/bin`, and you may need to add that to your `$PATH` if not 38 | > already present: 39 | 40 | $ PATH=$HOME/.local/bin:$PATH 41 | 42 | 43 | ### Testing 44 | 45 | To verify you have everything installed correctly, 46 | [hop back over to the testing directions in the main README](README.md#testing). 47 | -------------------------------------------------------------------------------- /doc/courses/2018-11-SenSys/presentation/Makefile: -------------------------------------------------------------------------------- 1 | all: presentation.pdf 2 | 3 | presentation.pdf: slides.md 4 | pandoc -s --pdf-engine xelatex -t beamer $< -o $@ 5 | -------------------------------------------------------------------------------- /doc/courses/2018-11-SenSys/presentation/architecture.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/2018-11-SenSys/presentation/architecture.pdf -------------------------------------------------------------------------------- /doc/courses/2018-11-SenSys/presentation/execution.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/2018-11-SenSys/presentation/execution.pdf -------------------------------------------------------------------------------- /doc/courses/2018-11-SenSys/presentation/imix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/2018-11-SenSys/presentation/imix.png -------------------------------------------------------------------------------- /doc/courses/README.md: -------------------------------------------------------------------------------- 1 | Tock courses 2 | ================== 3 | 4 | Courses are a great way to start learning Tock. They take you to the entire 5 | process of getting started, writing an application, and adding a capsule to the 6 | kernel. There are currently three different courses available, corresponding to 7 | the three conferences we've given workshops at: 8 | 9 | - **[RustConf](rustconf)** - For the user familiar with Rust. 10 | - **[Sensys](2018-11-SenSys)** - For the user familiar with embedded networked sensor systems. 11 | - **[SOSP](sosp)** - For the user familiar with operating systems. 12 | 13 | -------------------------------------------------------------------------------- /doc/courses/rustconf/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/rustconf/architecture.png -------------------------------------------------------------------------------- /doc/courses/rustconf/console.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/rustconf/console.png -------------------------------------------------------------------------------- /doc/courses/rustconf/goals.txt: -------------------------------------------------------------------------------- 1 | At the end of the RustConf tutorial, attendees should be able to: 2 | 3 | 1) Set up a Hail board, compile Tock, install Tock, compile applications, 4 | and install applications. 5 | 6 | 2) Add a new capsule to the kernel (write it, include it in the crate, 7 | initialize it in a boot sequence). 8 | 9 | 3) Write a system call interface to a capsule. 10 | 11 | 4) Write a new chip driver for a hardware controller. 12 | - Maybe not, but understanding unsafe use here is important. 13 | - If not, maybe _modify_ a controller driver 14 | 15 | 5) Write down/diagram what happens when a process makes a blocking 16 | system call (context switch, interrupt setup, wait_for, interrupt 17 | handling, kernel thread, resuming process). 18 | 19 | -------------------------------------------------------------------------------- /doc/courses/rustconf/presentation/architecture.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/rustconf/presentation/architecture.pdf -------------------------------------------------------------------------------- /doc/courses/rustconf/presentation/execution.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/rustconf/presentation/execution.pdf -------------------------------------------------------------------------------- /doc/courses/rustconf/presentation/hail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/rustconf/presentation/hail.png -------------------------------------------------------------------------------- /doc/courses/rustconf/presentation/ipc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/rustconf/presentation/ipc.pdf -------------------------------------------------------------------------------- /doc/courses/rustconf/presentation/presentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/rustconf/presentation/presentation.pdf -------------------------------------------------------------------------------- /doc/courses/rustconf/presentation/process_layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/rustconf/presentation/process_layout.png -------------------------------------------------------------------------------- /doc/courses/rustconf/presentation/rng.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/rustconf/presentation/rng.pdf -------------------------------------------------------------------------------- /doc/courses/rustconf/presentation/snakeoil.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/rustconf/presentation/snakeoil.jpg -------------------------------------------------------------------------------- /doc/courses/rustconf/rustconf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/courses/rustconf/rustconf.png -------------------------------------------------------------------------------- /doc/courses/sosp/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | location: Shanghai, China 3 | date: October 28th 4 | --- 5 | 6 | # Tock OS Training @ SOSP 2017 7 | 8 | This course introduces you to Tock, a secure embedded operating system for sensor 9 | networks and the Internet of Things. Tock is the first operating system to 10 | allow multiple untrusted applications to run concurrently on a microcontroller-based 11 | computer. The Tock kernel is written in Rust, a memory-safe systems language that 12 | does not rely on a garbage collector. Userspace applications are run in 13 | single-threaded processes that can be written in any language. A paper 14 | describing Tock's goals, design, and implementation will be presented at the 15 | conference on Monday and is available [here](https://www.amitlevy.com/papers/tock-sosp2017.pdf). 16 | 17 | This course is based on TockOS as it was in October, 2017. It serves as a useful 18 | introduction to Tock, but it is not updated as Tock evolves. To view this 19 | tutorial in the context it was originally designed for, please checkout the 20 | correct commit hash: 21 | 22 | ```bash 23 | $ git checkout 3c12437d23b83db896a5a8e218a3dc14468ce2df 24 | ``` 25 | 26 | This commit includes a working version of this tutorial. 27 | -------------------------------------------------------------------------------- /doc/debugging/figures/vsc_breakpoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/debugging/figures/vsc_breakpoint.png -------------------------------------------------------------------------------- /doc/debugging/figures/vsc_debug_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/debugging/figures/vsc_debug_view.png -------------------------------------------------------------------------------- /doc/debugging/figures/vsc_running.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/debugging/figures/vsc_running.png -------------------------------------------------------------------------------- /doc/process_memory_layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/process_memory_layout.png -------------------------------------------------------------------------------- /doc/processram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/processram.png -------------------------------------------------------------------------------- /doc/reference/README.md: -------------------------------------------------------------------------------- 1 | Internal API Reference Documents 2 | ================================ 3 | 4 | These files document internal Tock APIs. 5 | 6 | Tock Reference Documents 7 | ------------------------ 8 | 9 | - **[TRD 1](trd1-trds.md)**: Tock Reference Documents 10 | - **[TRD 102](trd102-adc.md)**: ADC 11 | -------------------------------------------------------------------------------- /doc/syscalls/60000_ambient_temperature.md: -------------------------------------------------------------------------------- 1 | --- 2 | driver number: 0x60000 3 | --- 4 | 5 | # Ambient Temperature 6 | 7 | ## Overview 8 | 9 | The ambient temperature driver allows a process to read the ambient temperature 10 | from a sensor. Temperature is reported in degrees centigrate at a precision of 11 | hundredths of degrees 12 | 13 | ## Command 14 | 15 | * ### Command number: `0` 16 | 17 | **Description**: Does the driver exist? 18 | 19 | **Argument 1**: unused 20 | 21 | **Argument 2**: unused 22 | 23 | **Returns**: SUCCESS if it exists, otherwise ENODEVICE 24 | 25 | * ### Command number: `1` 26 | 27 | **Description**: Initiate a sensor reading. When a reading is ready, a 28 | callback will be delivered if the process has `subscribed`. 29 | 30 | **Argument 1**: unused 31 | 32 | **Argument 2**: unused 33 | 34 | **Returns**: `EBUSY` if a reading is already pending, `ENOMEM` if there 35 | isn't sufficient grant memory available, or `SUCCESS` if the sensor reading 36 | was initiated successfully. 37 | 38 | ## Subscribe 39 | 40 | * ### Subscribe number: `0` 41 | 42 | **Description**: Subscribe to temperature readings. 43 | 44 | **Callback signature**: The callback receives a single argument, the 45 | temperature in hundredths of degrees centigrate. 46 | 47 | **Returns**: SUCCESS if the subscribe was successful or ENOMEM if the 48 | driver failed to allocate memory to store the callback. 49 | 50 | -------------------------------------------------------------------------------- /doc/syscalls/60001_humidity.md: -------------------------------------------------------------------------------- 1 | --- 2 | driver number: 0x60001 3 | --- 4 | 5 | # Humidity 6 | 7 | ## Overview 8 | 9 | The humidity driver allows a process to read the ambient humidity 10 | from a sensor. Humidity is reported in percent at a precision of 11 | hundredths of a percent. 12 | 13 | ## Command 14 | 15 | * ### Command number: `0` 16 | 17 | **Description**: Does the driver exist? 18 | 19 | **Argument 1**: unused 20 | 21 | **Argument 2**: unused 22 | 23 | **Returns**: SUCCESS if it exists, otherwise ENODEVICE 24 | 25 | * ### Command number: `1` 26 | 27 | **Description**: Initiate a sensor reading. When a reading is ready, a 28 | callback will be delivered if the process has `subscribed`. 29 | 30 | **Argument 1**: unused 31 | 32 | **Argument 2**: unused 33 | 34 | **Returns**: `EBUSY` if a reading is already pending, `ENOMEM` if there 35 | isn't sufficient grant memory available, or `SUCCESS` if the sensor reading 36 | was initiated successfully. 37 | 38 | ## Subscribe 39 | 40 | * ### Subscribe number: `0` 41 | 42 | **Description**: Subscribe to humidity readings. 43 | 44 | **Callback signature**: The callback receives a single argument, the 45 | humidity in hundredths of percent. 46 | 47 | **Returns**: SUCCESS if the subscribe was successful or ENOMEM if the 48 | driver failed to allocate memory to store the callback. 49 | 50 | -------------------------------------------------------------------------------- /doc/syscalls/60002_luminance.md: -------------------------------------------------------------------------------- 1 | --- 2 | driver number: 0x60002 3 | --- 4 | 5 | # Luminance 6 | 7 | ## Overview 8 | 9 | The ambient light driver allows a process to read the ambient light 10 | from a sensor. Luminance is reported in lux (lx). 11 | 12 | ## Command 13 | 14 | * ### Command number: `0` 15 | 16 | **Description**: Does the driver exist? 17 | 18 | **Argument 1**: unused 19 | 20 | **Argument 2**: unused 21 | 22 | **Returns**: SUCCESS if it exists, otherwise ENODEVICE 23 | 24 | * ### Command number: `1` 25 | 26 | **Description**: Initiate a sensor reading. When a reading is ready, a 27 | callback will be delivered if the process has `subscribed`. 28 | 29 | **Argument 1**: unused 30 | 31 | **Argument 2**: unused 32 | 33 | **Returns**: `EBUSY` if a reading is already pending, `ENOMEM` if there 34 | isn't sufficient grant memory available, or `SUCCESS` if the sensor reading 35 | was initiated successfully. 36 | 37 | ## Subscribe 38 | 39 | * ### Subscribe number: `0` 40 | 41 | **Description**: Subscribe to luminance readings. 42 | 43 | **Callback signature**: The callback receives a single argument, the 44 | luminance in lux (lx). 45 | 46 | **Returns**: SUCCESS if the subscribe was successful or ENOMEM if the 47 | driver failed to allocate memory to store the callback. 48 | 49 | -------------------------------------------------------------------------------- /doc/tock-stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oxidecomputer/tock/dd89f3f3be69480a9e80e02e025a7aec04d99120/doc/tock-stack.png -------------------------------------------------------------------------------- /doc/wg/README.md: -------------------------------------------------------------------------------- 1 | Tock Working Groups 2 | =================== 3 | 4 | Working groups (wg) are focused groups to organize development around a 5 | particular aspect of Tock. 6 | 7 | Existing Working Groups 8 | ----------------------- 9 | 10 | - [OpenTitan](opentitan.md) 11 | -------------------------------------------------------------------------------- /kernel/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "kernel" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | tock-registers = { path = "../libraries/tock-register-interface" } 9 | tock-cells = { path = "../libraries/tock-cells" } 10 | -------------------------------------------------------------------------------- /kernel/README.md: -------------------------------------------------------------------------------- 1 | Tock Core Kernel 2 | ================ 3 | 4 | The `/kernel` folder contains the core implementation of Tock that 5 | is shared across all platforms. This includes core operations, like 6 | scheduling and managing processes, internal abstractions, like 7 | `Driver` and `MPU`, and the Hardware Interface Layer (HIL) definitions. 8 | -------------------------------------------------------------------------------- /kernel/src/common/mod.rs: -------------------------------------------------------------------------------- 1 | //! Common operations and types in Tock. 2 | //! 3 | //! These are data types and access mechanisms that are used throughout the Tock 4 | //! kernel. Mostly they simplify common operations and enable the other parts of 5 | //! the kernel (chips and capsules) to be intuitive, valid Rust. In some cases 6 | //! they provide safe wrappers around unsafe interface so that other kernel 7 | //! crates do not need to use unsafe code. 8 | 9 | /// Re-export the tock-register-interface library. 10 | pub mod registers { 11 | pub use tock_registers::registers::InMemoryRegister; 12 | pub use tock_registers::registers::RegisterLongName; 13 | pub use tock_registers::registers::{Field, FieldValue, LocalRegisterCopy}; 14 | pub use tock_registers::registers::{ReadOnly, ReadWrite, WriteOnly}; 15 | pub use tock_registers::{register_bitfields, register_structs}; 16 | } 17 | 18 | pub mod deferred_call; 19 | pub mod dynamic_deferred_call; 20 | pub mod leasable_buffer; 21 | pub mod list; 22 | pub mod math; 23 | pub mod peripherals; 24 | pub mod queue; 25 | pub mod ring_buffer; 26 | pub mod utils; 27 | 28 | mod static_ref; 29 | 30 | pub use self::list::{List, ListLink, ListNode}; 31 | pub use self::queue::Queue; 32 | pub use self::ring_buffer::RingBuffer; 33 | pub use self::static_ref::StaticRef; 34 | 35 | /// Create a "fake" module inside of `common` for all of the Tock `Cell` types. 36 | /// 37 | /// To use `TakeCell`, for example, users should use: 38 | /// 39 | /// use kernel::common::cells::TakeCell; 40 | pub mod cells { 41 | pub use tock_cells::map_cell::MapCell; 42 | pub use tock_cells::numeric_cell_ext::NumericCellExt; 43 | pub use tock_cells::optional_cell::OptionalCell; 44 | pub use tock_cells::take_cell::TakeCell; 45 | pub use tock_cells::volatile_cell::VolatileCell; 46 | } 47 | -------------------------------------------------------------------------------- /kernel/src/common/queue.rs: -------------------------------------------------------------------------------- 1 | //! Interface for queue structure. 2 | 3 | pub trait Queue { 4 | /// Returns true if there are any items in the queue, false otherwise. 5 | fn has_elements(&self) -> bool; 6 | 7 | /// Returns true if the queue is full, false otherwise. 8 | fn is_full(&self) -> bool; 9 | 10 | /// Returns how many elements are in the queue. 11 | fn len(&self) -> usize; 12 | 13 | /// Add a new element to the back of the queue. 14 | fn enqueue(&mut self, val: T) -> bool; 15 | 16 | /// Remove the element from the front of the queue. 17 | fn dequeue(&mut self) -> Option; 18 | 19 | /// Remove all elements from the ring buffer. 20 | fn empty(&mut self); 21 | 22 | /// Retains only the elements that satisfy the predicate. 23 | fn retain(&mut self, f: F) 24 | where 25 | F: FnMut(&T) -> bool; 26 | } 27 | -------------------------------------------------------------------------------- /kernel/src/common/static_ref.rs: -------------------------------------------------------------------------------- 1 | //! Wrapper type for safe pointers to static memory. 2 | 3 | use core::ops::Deref; 4 | 5 | /// A pointer to statically allocated mutable data such as memory mapped I/O 6 | /// registers. 7 | /// 8 | /// This is a simple wrapper around a raw pointer that encapsulates an unsafe 9 | /// dereference in a safe manner. It serve the role of creating a `&'static T` 10 | /// given a raw address and acts similarly to `extern` definitions, except 11 | /// `StaticRef` is subject to module and crate boundaries, while `extern` 12 | /// definitions can be imported anywhere. 13 | #[derive(Debug)] 14 | pub struct StaticRef { 15 | ptr: *const T, 16 | } 17 | 18 | impl StaticRef { 19 | /// Create a new `StaticRef` from a raw pointer 20 | /// 21 | /// ## Safety 22 | /// 23 | /// Callers must pass in a reference to statically allocated memory which 24 | /// does not overlap with other values. 25 | pub const unsafe fn new(ptr: *const T) -> StaticRef { 26 | StaticRef { ptr: ptr } 27 | } 28 | } 29 | 30 | impl Clone for StaticRef { 31 | fn clone(&self) -> Self { 32 | StaticRef { ptr: self.ptr } 33 | } 34 | } 35 | 36 | impl Copy for StaticRef {} 37 | 38 | impl Deref for StaticRef { 39 | type Target = T; 40 | fn deref(&self) -> &'static T { 41 | unsafe { &*self.ptr } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /kernel/src/hil/analog_comparator.rs: -------------------------------------------------------------------------------- 1 | //! Interface for direct control of the analog comparators. 2 | 3 | // Author: Danilo Verhaert 4 | // Last modified August 9th, 2018 5 | 6 | use crate::returncode::ReturnCode; 7 | 8 | pub trait AnalogComparator { 9 | /// The chip-dependent type of an analog comparator channel. 10 | type Channel; 11 | 12 | /// Do a single comparison of two inputs, depending on the AC chosen. Output 13 | /// will be True (1) when one is higher than the other, and False (0) 14 | /// otherwise. Specifically, the output is True when Vp > Vn (Vin positive 15 | /// > Vin negative), and False if Vp < Vn. 16 | fn comparison(&self, channel: &Self::Channel) -> bool; 17 | 18 | /// Start interrupt-based comparison for the chosen channel (e.g. channel 1 19 | /// for AC1). This will make it listen and send an interrupt as soon as 20 | /// Vp > Vn. 21 | fn start_comparing(&self, channel: &Self::Channel) -> ReturnCode; 22 | 23 | /// Stop interrupt-based comparison for the chosen channel. 24 | fn stop_comparing(&self, channel: &Self::Channel) -> ReturnCode; 25 | } 26 | 27 | pub trait Client { 28 | /// Fires when handle_interrupt is called, returning the channel on which 29 | /// the interrupt occurred. 30 | fn fired(&self, _: usize); 31 | } 32 | -------------------------------------------------------------------------------- /kernel/src/hil/crc.rs: -------------------------------------------------------------------------------- 1 | //! Interface for CRC computation. 2 | 3 | use crate::returncode::ReturnCode; 4 | 5 | /// CRC algorithms 6 | /// 7 | /// In all cases, input bytes are bit-reversed (i.e., consumed from LSB to MSB.) 8 | /// 9 | /// Algorithms prefixed with `Sam4L` are native to that chip and thus require 10 | /// no software post-processing on platforms using it. 11 | /// 12 | #[derive(Copy, Clone)] 13 | pub enum CrcAlg { 14 | /// Polynomial 0x04C11DB7, output reversed then inverted ("CRC-32") 15 | Crc32, 16 | /// Polynomial 0x1EDC6F41, output reversed then inverted ("CRC-32C" / "Castagnoli") 17 | Crc32C, 18 | 19 | /// Polynomial 0x1021, no output post-processing 20 | Sam4L16, 21 | /// Polynomial 0x04C11DB7, no output post-processing 22 | Sam4L32, 23 | /// Polynomial 0x1EDC6F41, no output post-processing 24 | Sam4L32C, 25 | } 26 | 27 | pub trait CRC { 28 | /// Initiate a CRC calculation 29 | fn compute(&self, data: &[u8], _: CrcAlg) -> ReturnCode; 30 | 31 | /// Disable the CRC unit until compute() is next called 32 | fn disable(&self); 33 | } 34 | 35 | pub trait Client { 36 | /// Receive the successful result of a CRC calculation 37 | fn receive_result(&self, _: u32); 38 | } 39 | -------------------------------------------------------------------------------- /kernel/src/hil/dac.rs: -------------------------------------------------------------------------------- 1 | //! Interface for digital to analog converters. 2 | 3 | use crate::returncode::ReturnCode; 4 | 5 | /// Simple interface for using the DAC. 6 | pub trait DacChannel { 7 | /// Initialize and enable the DAC. 8 | fn initialize(&self) -> ReturnCode; 9 | 10 | /// Set the DAC output value. 11 | fn set_value(&self, value: usize) -> ReturnCode; 12 | } 13 | -------------------------------------------------------------------------------- /kernel/src/hil/eic.rs: -------------------------------------------------------------------------------- 1 | //! Interface for external interrupt controller. 2 | //! 3 | //! The External Interrupt Controller (EIC) allows pins to be configured as 4 | //! external interrupts. Each external interrupt has its own interrupt request 5 | //! and can be individually masked. Each external interrupt can generate an 6 | //! interrupt on rising or falling edge, or high or low level. 7 | //! Every interrupt pin can also be configured to be asynchronous, in order to 8 | //! wake-up the part from sleep modes where the CLK_SYNC clock has been disabled. 9 | //! 10 | //! A basic use case: 11 | //! A user button is configured for falling edge trigger and async mode. 12 | 13 | /// Enum for selecting which edge to trigger interrupts on. 14 | #[derive(Debug)] 15 | pub enum InterruptMode { 16 | RisingEdge, 17 | FallingEdge, 18 | HighLevel, 19 | LowLevel, 20 | } 21 | 22 | /// Interface for EIC. 23 | pub trait ExternalInterruptController { 24 | /// The chip-dependent type of an EIC line. Number of lines available depends on the chip. 25 | type Line; 26 | 27 | /// Enables external interrupt on the given 'line' 28 | /// In asychronous mode, all edge interrupts will be 29 | /// interpreted as level interrupts and the filter is disabled. 30 | fn line_enable(&self, line: &Self::Line, interrupt_mode: InterruptMode); 31 | 32 | /// Disables external interrupt on the given 'line' 33 | fn line_disable(&self, line: &Self::Line); 34 | } 35 | 36 | /// Interface for users of EIC. In order 37 | /// to execute interrupts, the user must implement 38 | /// this `Client` interface. 39 | pub trait Client { 40 | /// Called when an interrupt occurs. 41 | fn fired(&self); 42 | } 43 | -------------------------------------------------------------------------------- /kernel/src/hil/led.rs: -------------------------------------------------------------------------------- 1 | //! Interface for LEDs that abstract away polarity and pin. 2 | //! 3 | //! Author: Philip Levis 4 | //! Date: July 31, 2015 5 | //! 6 | 7 | use crate::hil::gpio; 8 | 9 | pub trait Led { 10 | fn init(&mut self); 11 | fn on(&mut self); 12 | fn off(&mut self); 13 | fn toggle(&mut self); 14 | fn read(&self) -> bool; 15 | } 16 | 17 | /// For LEDs in which on is when GPIO is high. 18 | pub struct LedHigh<'a> { 19 | pub pin: &'a mut dyn gpio::Pin, 20 | } 21 | 22 | /// For LEDs in which on is when GPIO is low. 23 | pub struct LedLow<'a> { 24 | pub pin: &'a mut dyn gpio::Pin, 25 | } 26 | 27 | impl LedHigh<'a> { 28 | pub fn new(p: &'a mut dyn gpio::Pin) -> LedHigh { 29 | LedHigh { pin: p } 30 | } 31 | } 32 | 33 | impl LedLow<'a> { 34 | pub fn new(p: &'a mut dyn gpio::Pin) -> LedLow { 35 | LedLow { pin: p } 36 | } 37 | } 38 | 39 | impl Led for LedHigh<'a> { 40 | fn init(&mut self) { 41 | self.pin.make_output(); 42 | } 43 | 44 | fn on(&mut self) { 45 | self.pin.set(); 46 | } 47 | 48 | fn off(&mut self) { 49 | self.pin.clear(); 50 | } 51 | 52 | fn toggle(&mut self) { 53 | self.pin.toggle(); 54 | } 55 | 56 | fn read(&self) -> bool { 57 | self.pin.read() 58 | } 59 | } 60 | 61 | impl Led for LedLow<'a> { 62 | fn init(&mut self) { 63 | self.pin.make_output(); 64 | } 65 | 66 | fn on(&mut self) { 67 | self.pin.clear(); 68 | } 69 | 70 | fn off(&mut self) { 71 | self.pin.set(); 72 | } 73 | 74 | fn toggle(&mut self) { 75 | self.pin.toggle(); 76 | } 77 | 78 | fn read(&self) -> bool { 79 | !self.pin.read() 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /kernel/src/hil/mod.rs: -------------------------------------------------------------------------------- 1 | //! Public traits for interfaces between Tock components. 2 | 3 | pub mod adc; 4 | pub mod analog_comparator; 5 | pub mod ble_advertising; 6 | pub mod crc; 7 | pub mod dac; 8 | pub mod eic; 9 | pub mod entropy; 10 | pub mod flash; 11 | pub mod gpio; 12 | pub mod gpio_async; 13 | pub mod i2c; 14 | pub mod led; 15 | pub mod nonvolatile_storage; 16 | pub mod pwm; 17 | pub mod radio; 18 | pub mod rng; 19 | pub mod sensors; 20 | pub mod spi; 21 | pub mod symmetric_encryption; 22 | pub mod time; 23 | pub mod uart; 24 | pub mod usb; 25 | pub mod watchdog; 26 | 27 | /// Shared interface for configuring components. 28 | pub trait Controller { 29 | type Config; 30 | 31 | fn configure(&self, _: Self::Config); 32 | } 33 | -------------------------------------------------------------------------------- /kernel/src/hil/nonvolatile_storage.rs: -------------------------------------------------------------------------------- 1 | //! Generic interface for nonvolatile memory. 2 | 3 | use crate::returncode::ReturnCode; 4 | 5 | /// Simple interface for reading and writing nonvolatile memory. It is expected 6 | /// that drivers for nonvolatile memory would implement this trait. 7 | pub trait NonvolatileStorage<'a> { 8 | fn set_client(&self, client: &'a dyn NonvolatileStorageClient<'a>); 9 | 10 | /// Read `length` bytes starting at address `address` in to the provided 11 | /// buffer. The buffer must be at least `length` bytes long. The address 12 | /// must be in the address space of the physical storage. 13 | fn read(&self, buffer: &'a mut [u8], address: usize, length: usize) -> ReturnCode; 14 | 15 | /// Write `length` bytes starting at address `address` from the provided 16 | /// buffer. The buffer must be at least `length` bytes long. This address 17 | /// must be in the address space of the physical storage. 18 | fn write(&self, buffer: &'a mut [u8], address: usize, length: usize) -> ReturnCode; 19 | } 20 | 21 | /// Client interface for nonvolatile storage. 22 | pub trait NonvolatileStorageClient<'a> { 23 | /// `read_done` is called when the implementor is finished reading in to the 24 | /// buffer. The callback returns the buffer and the number of bytes that 25 | /// were actually read. 26 | fn read_done(&self, buffer: &'a mut [u8], length: usize); 27 | 28 | /// `write_done` is called when the implementor is finished writing from the 29 | /// buffer. The callback returns the buffer and the number of bytes that 30 | /// were actually written. 31 | fn write_done(&self, buffer: &'a mut [u8], length: usize); 32 | } 33 | -------------------------------------------------------------------------------- /kernel/src/hil/watchdog.rs: -------------------------------------------------------------------------------- 1 | //! Interface for a watchdog timer. 2 | 3 | pub trait Watchdog { 4 | /// Enable the watchdog timer. Period is the time in milliseconds 5 | /// the watchdog will timeout if not serviced. 6 | fn start(&self, period: usize); 7 | 8 | /// Disable the watchdog timer. 9 | fn stop(&self); 10 | 11 | /// Service the watchdog to let the hardware know the application 12 | /// is still executing. 13 | fn tickle(&self); 14 | } 15 | -------------------------------------------------------------------------------- /kernel/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Core Tock Kernel 2 | //! 3 | //! The kernel crate implements the core features of Tock as well as shared 4 | //! code that many chips, capsules, and boards use. It also holds the Hardware 5 | //! Interface Layer (HIL) definitions. 6 | //! 7 | //! Most `unsafe` code is in this kernel crate. 8 | 9 | #![feature(core_intrinsics, ptr_internals, const_fn)] 10 | #![feature(panic_info_message)] 11 | #![feature(in_band_lifetimes, crate_visibility_modifier)] 12 | #![feature(associated_type_defaults)] 13 | #![warn(unreachable_pub)] 14 | #![no_std] 15 | 16 | pub mod capabilities; 17 | pub mod common; 18 | pub mod component; 19 | pub mod debug; 20 | pub mod hil; 21 | pub mod introspection; 22 | pub mod ipc; 23 | pub mod syscall; 24 | 25 | mod callback; 26 | mod config; 27 | mod driver; 28 | mod grant; 29 | mod mem; 30 | mod memop; 31 | mod platform; 32 | mod process; 33 | mod returncode; 34 | mod sched; 35 | mod tbfheader; 36 | 37 | pub use crate::callback::{AppId, Callback}; 38 | pub use crate::driver::Driver; 39 | pub use crate::grant::Grant; 40 | pub use crate::mem::{AppPtr, AppSlice, Private, Shared}; 41 | pub use crate::platform::systick::SysTick; 42 | pub use crate::platform::{mpu, Chip, Platform}; 43 | pub use crate::platform::{ClockInterface, NoClockControl, NO_CLOCK_CONTROL}; 44 | pub use crate::returncode::ReturnCode; 45 | pub use crate::sched::Kernel; 46 | 47 | // Export only select items from the process module. To remove the name conflict 48 | // this cannot be called `process`, so we use a shortened version. These 49 | // functions and types are used by board files to setup the platform and setup 50 | // processes. 51 | /// Publicly available process-related objects. 52 | pub mod procs { 53 | pub use crate::process::{ 54 | load_processes, Error, FaultResponse, FunctionCall, Process, ProcessType, 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /libraries/README.md: -------------------------------------------------------------------------------- 1 | Tock Libraries 2 | ============== 3 | 4 | This folder contains crates that are effectively libraries developed for and 5 | used by Tock. The libraries are standalone, have become reasonably stable, and 6 | are likely useful outside of Tock. Therefore they have moved to the libraries 7 | folder as separate crates so that external projects can leverage them. 8 | 9 | Someday these libraries could become their own repositories if the need arises. 10 | 11 | 12 | Using in an External Project 13 | ---------------------------- 14 | 15 | To use one of these libraries, simply add them as a dependency in a Cargo.toml 16 | file. For example: 17 | 18 | ```toml 19 | [dependencies] 20 | tock-registers = { git = "https://github.com/tock/tock" } 21 | ``` 22 | 23 | Cargo will handle finding the correct folder inside of the tock repository. 24 | -------------------------------------------------------------------------------- /libraries/enum_primitive/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "enum_primitive" 3 | version = "0.1.0" 4 | -------------------------------------------------------------------------------- /libraries/enum_primitive/README.md: -------------------------------------------------------------------------------- 1 | enum_primitive 2 | ============== 3 | 4 | This library is a lightly modified clone of 5 | [enum_primitive-rs](https://github.com/andersk/enum_primitive-rs), adapted to 6 | support `no_std`. 7 | 8 | For complete documentation please visit 9 | https://andersk.github.io/enum_primitive-rs/enum_primitive/ 10 | 11 | 12 | Status / Why a Copy? 13 | -------------------- 14 | 15 | Due to auditability concerns, Tock currently has a policy against linking in 16 | external code. For a simpler library, the approach taken here was to audit a 17 | snapshot and include it directly. 18 | -------------------------------------------------------------------------------- /libraries/riscv-csr/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "riscv-csr" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | description = "RISC-V CSR interface developed for Tock." 6 | homepage = "https://www.tockos.org/" 7 | repository = "https://github.com/tock/tock/tree/master/libraries/riscv-csr" 8 | readme = "README.md" 9 | keywords = ["tock", "embedded", "riscv", "bare-metal"] 10 | categories = ["data-structures", "embedded", "no-std"] 11 | license = "MIT/Apache-2.0" 12 | edition = "2018" 13 | 14 | [badges] 15 | travis-ci = { repository = "tock/tock", branch = "master" } 16 | 17 | [dependencies] 18 | tock-registers = { path = "../tock-register-interface" } 19 | -------------------------------------------------------------------------------- /libraries/riscv-csr/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! RISC-V CSR Library 2 | //! 3 | //! Uses the Tock Register Interface to control RISC-V CSRs. 4 | 5 | #![feature(asm)] 6 | #![feature(const_fn)] 7 | #![no_std] 8 | 9 | pub mod csr; 10 | -------------------------------------------------------------------------------- /libraries/tock-cells/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tock-cells" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | 6 | -------------------------------------------------------------------------------- /libraries/tock-cells/README.md: -------------------------------------------------------------------------------- 1 | Tock Cells 2 | ================ 3 | 4 | These are the Cell types that Tock uses for interior mutability. 5 | 6 | -------------------------------------------------------------------------------- /libraries/tock-cells/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Tock Cell types. 2 | 3 | #![feature(const_fn, untagged_unions)] 4 | #![no_std] 5 | 6 | pub mod map_cell; 7 | pub mod numeric_cell_ext; 8 | pub mod optional_cell; 9 | pub mod take_cell; 10 | pub mod volatile_cell; 11 | -------------------------------------------------------------------------------- /libraries/tock-cells/src/volatile_cell.rs: -------------------------------------------------------------------------------- 1 | //! Implementation of a type for accessing MCU registers. 2 | 3 | use core::ptr; 4 | 5 | /// `VolatileCell` provides a wrapper around unsafe volatile pointer reads 6 | /// and writes. This is particularly useful for accessing microcontroller 7 | /// registers. 8 | // Source: https://github.com/hackndev/zinc/tree/master/volatile_cell 9 | #[derive(Copy, Clone, Default)] 10 | #[repr(C)] 11 | pub struct VolatileCell { 12 | value: T, 13 | } 14 | 15 | impl VolatileCell { 16 | pub const fn new(value: T) -> Self { 17 | VolatileCell { value } 18 | } 19 | 20 | #[inline] 21 | pub fn get(&self) -> T { 22 | unsafe { ptr::read_volatile(&self.value) } 23 | } 24 | 25 | #[inline] 26 | pub fn set(&self, value: T) { 27 | unsafe { ptr::write_volatile(&self.value as *const T as *mut T, value) } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /libraries/tock-register-interface/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## master 4 | 5 | - #1554: Allow lifetime parameters for `register_structs! { Foo<'a> { ..` 6 | 7 | ## v0.5 8 | 9 | - #1510 10 | - Register visibility granularity: don't automatically make everything 11 | `pub`, rather give creation macro callers visbility control. 12 | 13 | - #1489 14 | - Make `register_structs!` unit test generation opt-out, so that 15 | `custom-test-frameworks` environments can disable them. 16 | 17 | - #1481 18 | - Add `#[derive(Copy, Clone)]` to InMemoryRegister. 19 | 20 | - #1428 21 | - Implement `mask()` for `FieldValue` which seems to have been 22 | skipped at some point. 23 | - Implement `read()` for `FieldValue` so that individual fields 24 | can be extracted from a register `FieldValue` representation. 25 | 26 | - #1461: Update `register_structs` macro to support flexible visibility of each 27 | struct and each field. Also revert to private structs by default. 28 | 29 | ## v0.4.1 30 | 31 | - #1458: Update struct macro to create `pub` structs 32 | 33 | ## v0.4 34 | 35 | - #1368: Remove `new()` and add `InMemoryRegister` 36 | - #1410: Add new macro for generating structs 37 | 38 | ## v0.3 39 | 40 | - #1243: Update to Rust 2018 (nightly) 41 | - #1250: Doc-only: Fix some rustdoc warnings 42 | 43 | ## v0.2 44 | 45 | - #1161: Add `read_as_enum` to `LocalRegisterCopy`; thanks @andre-richter 46 | 47 | ## v0.1 - Initial Release 48 | -------------------------------------------------------------------------------- /libraries/tock-register-interface/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tock-registers" 3 | version = "0.5.0" 4 | authors = ["Tock Project Developers "] 5 | description = "Memory-Mapped I/O and register interface developed for Tock." 6 | homepage = "https://www.tockos.org/" 7 | repository = "https://github.com/tock/tock/tree/master/libraries/tock-register-interface" 8 | readme = "README.md" 9 | keywords = ["tock", "embedded", "registers", "mmio", "bare-metal"] 10 | categories = ["data-structures", "embedded", "no-std"] 11 | license = "MIT/Apache-2.0" 12 | edition = "2018" 13 | 14 | [badges] 15 | travis-ci = { repository = "tock/tock", branch = "master" } 16 | 17 | [features] 18 | no_std_unit_tests = [] 19 | -------------------------------------------------------------------------------- /libraries/tock-register-interface/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Tock Register Interface 2 | //! 3 | //! 4 | 5 | #![feature(const_fn)] 6 | #![no_std] 7 | 8 | pub mod macros; 9 | pub mod registers; 10 | -------------------------------------------------------------------------------- /libraries/tock-rt0/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tock_rt0" 3 | version = "0.1.0" 4 | authors = ["Tock Project Developers "] 5 | 6 | -------------------------------------------------------------------------------- /libraries/tock-rt0/README.md: -------------------------------------------------------------------------------- 1 | tock-rt0 2 | ======== 3 | 4 | Generic helpers to support the setup of initial runtime (`rt0`). 5 | 6 | Currently has support for data segment relocation and zero-initialization of BSS. 7 | 8 | 9 | Stability 10 | --------- 11 | 12 | This is a relatively new library and thus subject to change. It is also, however, 13 | a fairly simple library and thus less likely to see significant change. 14 | -------------------------------------------------------------------------------- /libraries/tock-rt0/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Tock generic initial runtime (`rt0`) helper functions 2 | 3 | #![no_std] 4 | 5 | /// Initializes the static data, by copying it into memory (RAM) from 6 | /// non-volatile memory (Flash). 7 | /// 8 | /// - `start_data_flash`: The address of the start of the data section stored 9 | /// in non-volatile flash memory. 10 | /// - `start_data_ram`: The address in RAM where the data section starts and 11 | /// should be copied to. 12 | /// - `end_data_ram`: The first address after the end of the data section 13 | /// in RAM. 14 | pub unsafe fn init_data( 15 | mut start_data_flash: *mut u32, 16 | mut start_data_ram: *mut u32, 17 | end_data_ram: *mut u32, 18 | ) { 19 | while start_data_ram < end_data_ram { 20 | start_data_ram.write(start_data_flash.read()); 21 | start_data_ram = start_data_ram.offset(1); 22 | start_data_flash = start_data_flash.offset(1); 23 | } 24 | } 25 | 26 | /// Sets non-initialized data in RAM to 0. 27 | /// This is used to clear the BSS section on initial bootup. 28 | pub unsafe fn zero_bss(mut bss: *mut u32, bss_end: *mut u32) { 29 | while bss < bss_end { 30 | // `volatile` to make sure it doesn't get optimized out 31 | bss.write_volatile(0); 32 | bss = bss.offset(1); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rust-toolchain: -------------------------------------------------------------------------------- 1 | nightly-2020-01-16 2 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | # Shell expression for the Nix package manager 2 | # 3 | # This nix expression creates an environment with necessary packages installed: 4 | # 5 | # * `tockloader` 6 | # * rust 7 | # 8 | # To use: 9 | # 10 | # $ nix-shell 11 | # 12 | 13 | { pkgs ? import {} }: 14 | 15 | with builtins; 16 | let 17 | inherit (pkgs) stdenv; 18 | pythonPackages = stdenv.lib.fix' (self: with self; pkgs.python3Packages // 19 | { 20 | 21 | tockloader = buildPythonPackage rec { 22 | pname = "tockloader"; 23 | version = "1.3.1"; 24 | name = "${pname}-${version}"; 25 | 26 | propagatedBuildInputs = [ argcomplete colorama crcmod pyserial pytoml ]; 27 | 28 | src = fetchPypi { 29 | inherit pname version; 30 | sha256 = "1gralnhvl82xr7rkrmxj0c1rxn1y9dlbmkkrklcdjahragbknivn"; 31 | }; 32 | }; 33 | }); 34 | moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz); 35 | nixpkgs = import { overlays = [ moz_overlay ]; }; 36 | rust_date = "2020-01-16"; 37 | rust_channel = "nightly"; 38 | rust_targets = [ "thumbv7em-none-eabi" "thumbv7em-none-eabihf" "thumbv6m-none-eabi" ]; 39 | rust_build = nixpkgs.rustChannelOfTargets rust_channel rust_date rust_targets; 40 | in 41 | with pkgs; 42 | stdenv.mkDerivation { 43 | name = "tock-dev"; 44 | buildInputs = [ 45 | python3Full 46 | pythonPackages.tockloader 47 | rust_build 48 | ]; 49 | LD_LIBRARY_PATH="${stdenv.cc.cc.lib}/lib64:$LD_LIBRARY_PATH"; 50 | } 51 | -------------------------------------------------------------------------------- /tools/.gitignore: -------------------------------------------------------------------------------- 1 | local_cargo/ 2 | *.svd 3 | 4 | -------------------------------------------------------------------------------- /tools/alert_codes/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "alert_codes" 3 | version = "0.1.0" 4 | authors = ["jrvanwhy "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /tools/check_capsule_readme.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | ''' 4 | Check if all of the available capsules are documented in the README. 5 | ''' 6 | 7 | import os 8 | import re 9 | 10 | SKIP = ['/mod.rs', 11 | 'src/lib.rs', 12 | '/test', 13 | 'src/driver.rs', 14 | 'src/rf233_const.rs'] 15 | 16 | 17 | documented_capsules = [] 18 | implemented_capsules = [] 19 | 20 | # Find all documented capsules 21 | with open('capsules/README.md') as f: 22 | for l in f: 23 | items = re.findall(r".*\((src/.*?)\).*", l) 24 | if len(items) > 0: 25 | for item in items: 26 | documented_capsules.append('capsules/{}'.format(item)) 27 | 28 | 29 | # Find all capsule source files. 30 | for subdir, dirs, files in os.walk(os.fsencode('capsules/src/')): 31 | for file in files: 32 | filepath = os.fsdecode(os.path.join(subdir, file)) 33 | 34 | # Get just the part after /src, effectively. 35 | folders = filepath.split('/') 36 | filepath = '/'.join(folders[0:3]) 37 | 38 | # Skip some noise. 39 | for skip in SKIP: 40 | if skip in filepath: 41 | break 42 | else: 43 | implemented_capsules.append(filepath) 44 | 45 | 46 | # Calculate what doesn't seem to be documented. 47 | missing = list(set(implemented_capsules) - set(documented_capsules)) 48 | 49 | 50 | print('The following capsules do not seem to be documented:') 51 | for m in sorted(missing): 52 | print(' - {}'.format(m)) 53 | 54 | -------------------------------------------------------------------------------- /tools/check_wildcard_imports.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Checks for wildcard imports (which are to be avoided at all costs). Must be 4 | # run from root Tock directory. 5 | # 6 | # Author: Pat Pannuto 7 | # Author: Brad Campbell 8 | # 9 | set -e 10 | 11 | # Verify that we're running in the base directory 12 | if [ ! -x tools/check_wildcard_imports.sh ]; then 13 | echo ERROR: $0 must be run from the tock repository root. 14 | echo "" 15 | exit 1 16 | fi 17 | 18 | set +e 19 | let FAIL=0 20 | set -e 21 | 22 | # Clippy doesn't have an option for this, so do it manually (see 23 | # https://github.com/rust-lang/rust-clippy/issues/1228). 24 | # Find folders with Cargo.toml files in them and check them (avoids matching 25 | # this script!) 26 | for f in $(find . | grep Cargo.toml); do 27 | pushd $(dirname $f) > /dev/null 28 | if $(git grep -q 'use .*\*;' -- ':!src/macros.rs'); then 29 | echo 30 | echo "$(tput bold)Wildcard import(s) found in $(dirname $f).$(tput sgr0)" 31 | echo "Tock style rules prohibit this use of wildcard imports." 32 | echo 33 | echo "The following wildcard imports were found:" 34 | git grep 'use .*\*;' 35 | let FAIL=FAIL+1 36 | fi 37 | popd > /dev/null 38 | done 39 | 40 | if [[ $FAIL -ne 0 ]]; then 41 | echo 42 | echo "$(tput bold)Formatting errors.$(tput sgr0)" 43 | echo "See above for details" 44 | fi 45 | exit $FAIL 46 | -------------------------------------------------------------------------------- /tools/list_archs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Find archs based on folders with Cargo.toml 4 | for b in $(find arch -maxdepth 4 -name 'Cargo.toml'); do 5 | b1=${b#arch/} 6 | b2=${b1%/*} 7 | echo $b2 8 | done 9 | -------------------------------------------------------------------------------- /tools/list_boards.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Find boards based on folders with Makefiles 4 | for b in $(find boards -maxdepth 4 | egrep 'Makefile$'); do 5 | b1=${b#boards/} 6 | b2=${b1%/*} 7 | echo $b2 8 | done 9 | -------------------------------------------------------------------------------- /tools/list_chips.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Find chips based on folders with Cargo.toml 4 | for b in $(find chips -maxdepth 4 -name 'Cargo.toml'); do 5 | b1=${b#chips/} 6 | b2=${b1%/*} 7 | echo $b2 8 | done 9 | -------------------------------------------------------------------------------- /tools/list_tools.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Find tools built in rust based on folders with Cargo.toml 4 | for b in $(find tools -maxdepth 4 -name 'Cargo.toml'); do 5 | b1=${b#tools/} 6 | b2=${b1%/*} 7 | echo $b2 8 | done 9 | -------------------------------------------------------------------------------- /tools/netlify-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Script used to install additional requirements to the base Netlify image. 4 | # 5 | # Should not be used or relied on outside of Netlify context. 6 | # 7 | # Author: Pat Pannuto 8 | 9 | 10 | set -e 11 | set -u 12 | set -x 13 | 14 | curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly-2020-01-16 15 | 16 | export PATH="$PATH:$HOME/.cargo/bin" 17 | 18 | tools/build-all-docs.sh 19 | -------------------------------------------------------------------------------- /tools/run_cargo_fix.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Runs cargo fix (which removes lint warnings) on every subdirectory from . 4 | # that has a Cargo.toml file. 5 | # 6 | # Author: Brad Campbell 7 | 8 | FAIL=0 9 | 10 | set -e 11 | 12 | # Verify that we're running in the base directory 13 | if [ ! -x tools/run_cargo_fix.sh ]; then 14 | echo ERROR: $0 must be run from the tock repository root. 15 | echo "" 16 | exit 1 17 | fi 18 | 19 | for f in $(find . | grep Cargo.toml); do 20 | pushd $(dirname $f) > /dev/null 21 | cargo fix --allow-dirty || let FAIL=FAIL+1 22 | popd > /dev/null 23 | done 24 | 25 | -------------------------------------------------------------------------------- /tools/run_cargo_generate-lockfile.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Runs `cargo generate-lockfile` (which generates and/or updates the Cargo.lock 4 | # file for a crate) on every subdirectory from . that has a Cargo.toml file. 5 | # 6 | # Author: Brad Campbell 7 | 8 | set -e 9 | 10 | # Verify that we're running in the base directory 11 | if [ ! -x tools/run_cargo_generate-lockfile.sh ]; then 12 | echo ERROR: $0 must be run from the tock repository root. 13 | echo "" 14 | exit 1 15 | fi 16 | 17 | for f in $(find . | grep Cargo.toml); do 18 | pushd $(dirname $f) > /dev/null 19 | cargo generate-lockfile 20 | popd > /dev/null 21 | done 22 | 23 | echo "Generated or updated all Cargo.lock files." 24 | echo "Because of the .gitignore file this will not show any changed files." 25 | -------------------------------------------------------------------------------- /tools/run_clippy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Install clippy if it is not already preset. 4 | if ! rustup component list | grep 'clippy.*(installed)' -q; then 5 | rustup component add clippy || rustup component add clippy-preview 6 | fi 7 | 8 | # We start by turning most lints off (by -A with most of the categories), then 9 | # specifically turn on lints that make sense. We do keep `clippy::correctness` 10 | # on. 11 | # 12 | # There are some lints we specifically do not want: 13 | # 14 | # - `clippy::if_same_then_else`: There are often good reasons to enumerate 15 | # different states that have the same effect. 16 | 17 | CLIPPY_ARGS=" 18 | -A clippy::complexity 19 | -A clippy::pedantic 20 | -A clippy::nursery 21 | -A clippy::style 22 | -A clippy::perf 23 | -A clippy::cargo 24 | -A clippy::restriction 25 | 26 | -A clippy::if_same_then_else 27 | 28 | -D clippy::needless_return 29 | -D clippy::unnecessary_mut_passed 30 | -D clippy::empty_line_after_outer_attr 31 | -D clippy::default_trait_access 32 | -D clippy::option_map_unwrap_or 33 | -D clippy::option_map_unwrap_or_else 34 | " 35 | 36 | cargo clippy -- $CLIPPY_ARGS 37 | -------------------------------------------------------------------------------- /tools/semver.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Semantic version comparison. This function compares two 4 | # strings of the form X{.Y}* and returns which is larger or 5 | # whether they are equal. This is not a simple text comparison 6 | # because 4.10.1 > 4.1. 7 | # 8 | # Author: Pat Pannuto 9 | # 10 | # Adapted from 11 | # https://stackoverflow.com/questions/4023830/ 12 | 13 | vercomp () { 14 | if [[ $1 == $2 ]] 15 | then 16 | return 0 17 | fi 18 | local IFS=. 19 | local i ver1=($1) ver2=($2) 20 | # fill empty fields in ver1 with zeros 21 | for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) 22 | do 23 | ver1[i]=0 24 | done 25 | for ((i=0; i<${#ver1[@]}; i++)) 26 | do 27 | if [[ -z ${ver2[i]} ]] 28 | then 29 | # fill empty fields in ver2 with zeros 30 | ver2[i]=0 31 | fi 32 | if ((10#${ver1[i]} > 10#${ver2[i]})) 33 | then 34 | return 1 35 | fi 36 | if ((10#${ver1[i]} < 10#${ver2[i]})) 37 | then 38 | return 2 39 | fi 40 | done 41 | return 0 42 | } 43 | 44 | testvercomp () { 45 | vercomp $1 $2 46 | case $? in 47 | 0) op='=';; 48 | 1) op='>';; 49 | 2) op='<';; 50 | esac 51 | if [[ $op != $3 ]] 52 | then 53 | #echo "FAIL: Expected '$3', Actual '$op', Arg1 '$1', Arg2 '$2'" 54 | echo false 55 | else 56 | echo true 57 | fi 58 | } 59 | 60 | testvercomp $1 $3 $2 61 | -------------------------------------------------------------------------------- /tools/svd2regs.nix: -------------------------------------------------------------------------------- 1 | # 2 | # Nix environment to run svd2regs.py 3 | # 4 | # To install the environment 5 | # 6 | # $ nix-env --file svd2regs.nix --install env-svd2regs 7 | # 8 | # To load the environment 9 | # 10 | # $ load-env-svd2regs 11 | # 12 | with import {}; 13 | let 14 | cmsis-svd = python37.pkgs.buildPythonPackage rec { 15 | pname = "cmsis-svd"; 16 | version = "0.4"; 17 | 18 | src = python37.pkgs.fetchPypi { 19 | inherit pname version; 20 | sha256 = "b5f439fc6bbc43c9b56dd822f1f764359d503c685a42f913a1cfc2a3c6c42b2c"; 21 | }; 22 | 23 | buildInputs = [ python37.pkgs.six ]; 24 | 25 | doCheck = false; 26 | 27 | meta = { 28 | homepage = "https://github.com/posborne/cmsis-svd"; 29 | description = "CMSIS SVD data files and parser"; 30 | }; 31 | }; 32 | 33 | pydentifier = python37.pkgs.buildPythonPackage rec { 34 | pname = "pydentifier"; 35 | version = "0.1.3"; 36 | 37 | src = python37.pkgs.fetchPypi { 38 | inherit pname version; 39 | sha256 = "981f9705f71e0307a22030d3908369847b99a40caa5dba99aea9989400eb56a6"; 40 | }; 41 | 42 | doCheck = false; 43 | 44 | meta = { 45 | homepage = "https://github.com/nathforge/pydentifier"; 46 | description = "Generate Python identifiers from English text"; 47 | }; 48 | }; 49 | 50 | svd2regsPythonEnv = python37.withPackages (_: [ cmsis-svd 51 | pydentifier 52 | python37.pkgs.six 53 | python37.pkgs.setuptools ]); 54 | in 55 | myEnvFun { 56 | name = "svd2regs"; 57 | 58 | buildInputs = [ svd2regsPythonEnv ]; 59 | } 60 | -------------------------------------------------------------------------------- /tools/toc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Run `markdown-toc` on all Markdown files with tables of contents 4 | # to see if any of them need an updated TOC. 5 | # 6 | # As a side effect, if you run this locally it will generate 7 | # all needed TOC and update the markdown documents. 8 | # 9 | # Author: Brad Campbell 10 | 11 | let ERROR=0 12 | 13 | # Find all markdown files 14 | for f in $(find * -name "*.md"); do 15 | 16 | # Only use ones that include a table of contents 17 | grep '' $f > /dev/null 18 | let rc=$? 19 | 20 | if [[ $rc == 0 ]]; then 21 | # Try running the TOC tool and see if anything changes 22 | before=`cat $f` 23 | markdown-toc -i $f 24 | after=`cat $f` 25 | 26 | if [[ "$before" != "$after" ]]; then 27 | echo "$f has an outdated table of contents" 28 | ERROR=1 29 | fi 30 | fi 31 | 32 | done 33 | 34 | # Make sure to return with an error if anything changes 35 | # so that Travis will fail. 36 | if [[ $ERROR == 1 ]]; then 37 | exit -1 38 | fi 39 | -------------------------------------------------------------------------------- /tools/update_rust_version.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | # Ask rustup to pick the latest version that will work. 5 | # This requires rustup >= 1.20.0. 6 | echo "Updating rustc to latest compatible version..." 7 | rustup update nightly 8 | 9 | # # Rerun the command so that it prints out the version it installed. We then have 10 | # # to extract that from the output. If there is a better way to do this then we 11 | # # should update this. 12 | # RUSTUP_NIGHTLY_VERSION=`rustup update nightly 2>&1` 13 | # BEST_DATE=`echo $RUSTUP_NIGHTLY_VERSION | sed 's/.* \([0-9]*-[0-9]*-[0-9]*\).*/\1/g'` 14 | 15 | # I just do not know how to get rustup to tell us the version of the toolchain 16 | # it decided on with the format required for `rust-toolchain`. That the dates 17 | # are off-by-one day is annoying. I'm resorting to just asking the user. 18 | 19 | echo "Please enter the version of Rust to use." 20 | echo "It is probably just one day later than whatever was printed out above." 21 | read BEST_DATE 22 | 23 | # Nightly version string 24 | NIGHTLY=nightly-$BEST_DATE 25 | 26 | echo Updating Rust to $NIGHTLY 27 | 28 | # Set the Rust version in rust-toolchain file. 29 | echo $NIGHTLY > rust-toolchain 30 | 31 | # Update all relevant files with the new version string. 32 | sed -i '' "s/nightly-[0-9]*-[0-9]*-[0-9]*/${NIGHTLY}/g" .travis.yml 33 | sed -i '' "s/nightly-[0-9]*-[0-9]*-[0-9]*/${NIGHTLY}/g" .vscode/settings.json 34 | sed -i '' "s/nightly-[0-9]*-[0-9]*-[0-9]*/${NIGHTLY}/g" doc/Getting_Started.md 35 | sed -i '' "s/nightly-[0-9]*-[0-9]*-[0-9]*/${NIGHTLY}/g" rust-toolchain 36 | sed -i '' "s/nightly-[0-9]*-[0-9]*-[0-9]*/${NIGHTLY}/g" tools/netlify-build.sh 37 | sed -i '' "s/[0-9]*-[0-9]*-[0-9]*/${BEST_DATE}/g" shell.nix 38 | -------------------------------------------------------------------------------- /tools/usb/bulk-echo-fast/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | OPTIONS= 4 | # Uncomment the line below to enable logging 5 | # OPTIONS="-DLOGGING" 6 | 7 | $CC $OPTIONS -I/usr/include/libusb-1.0/ main.c -lusb-1.0 8 | -------------------------------------------------------------------------------- /tools/usb/bulk-echo-fast/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | dd if=/dev/urandom of=input.dat bs=1 count=99999 4 | 5 | time ./a.out output.dat 6 | 7 | diff -q input.dat output.dat && echo 'Success!' 8 | -------------------------------------------------------------------------------- /tools/usb/bulk-echo/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bulk-echo" 3 | version = "0.1.0" 4 | authors = ["Daniel B Giffin "] 5 | 6 | [dependencies] 7 | libusb = "0.3" 8 | -------------------------------------------------------------------------------- /tools/usb/bulk-echo/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | bin=target/debug 4 | 5 | dd if=/dev/urandom of=input.dat bs=1 count=99999 6 | 7 | time $bin/bulk-echo output.dat 8 | 9 | diff -q input.dat output.dat && echo 'Success!' 10 | -------------------------------------------------------------------------------- /tools/usb/bulk-test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bulk-test" 3 | version = "0.1.0" 4 | authors = ["Daniel B. Giffin "] 5 | 6 | [dependencies] 7 | libusb = "0.3" 8 | -------------------------------------------------------------------------------- /tools/usb/control-test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "control-test" 3 | version = "0.1.0" 4 | authors = ["Daniel B. Giffin "] 5 | 6 | [dependencies] 7 | libusb = "0.3" 8 | -------------------------------------------------------------------------------- /vagrant/.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | -------------------------------------------------------------------------------- /vagrant/README.md: -------------------------------------------------------------------------------- 1 | Vagrant 2 | ======= 3 | 4 | Vagrant is tool for building and sharing development environments. To get 5 | started first [install Vagrant](https://www.vagrantup.com/downloads.html) if 6 | you have not already. 7 | 8 | 9 | Vagrant Quick Start 10 | ------------------- 11 | 12 | Vagrant is essentially a management layer over a virtual machine. To get started: 13 | 14 | 1. `vagrant up` - (create and) start the virtual machine 15 | 2. `vagrant ssh` - log in to the virtual machine 16 | 3. `cd /tock` - access the repository; this is a shared folder with the tock 17 | repository already checked out on your machine, so you can 18 | use local and familiar editing tools 19 | 4. `make` - build tock 20 | 21 | If you won't be developing Tock for a while, you can stop the Tock VM via 22 | 23 | - `vagrant suspend` - Pauses the VM (more disk space, but faster) 24 | - `vagrant halt` - Shuts down the VM 25 | 26 | In either case, simply `vagrant up` to begin working again. 27 | 28 | 29 | Getting code onto hardware 30 | -------------------------- 31 | 32 | To flash or program boards, you will need to enable USB passthrough using the 33 | virtual machine manager of your choice for the board-specific programmer for 34 | your device. As the `tock/` folder is shared, you may also simply use this 35 | vagrant image for building and the host machine directly to flash images. 36 | --------------------------------------------------------------------------------