Update for latest nightly.

This commit is contained in:
whitequark 2018-08-28 19:57:17 +00:00
parent 8164b75dfa
commit 89104a551c
11 changed files with 138 additions and 271 deletions

View File

@ -1,8 +1,7 @@
[target.thumbv7em-none-eabihf]
runner = "arm-none-eabi-gdb"
rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "linker=arm-none-eabi-ld",
"-Z", "linker-flavor=ld",
]
[build]

199
firmware/Cargo.lock generated
View File

@ -1,75 +1,64 @@
[[package]]
name = "aligned"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bare-metal"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "build_const"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "byteorder"
version = "1.2.1"
name = "bare-metal"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "chrono"
version = "0.4.0"
name = "bitflags"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "build_const"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "byteorder"
version = "1.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cortex-m"
version = "0.3.1"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aligned 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bare-metal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"aligned 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bare-metal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cortex-m-rt"
version = "0.3.13"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cortex-m 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "crc"
version = "1.7.0"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"build_const 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ionpak-firmware"
version = "1.0.0"
dependencies = [
"cortex-m 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cortex-m-rt 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
"crc 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cortex-m 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"cortex-m-rt 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libm 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp?rev=cd893e6)",
"tm4c129x 0.5.0 (git+https://github.com/m-labs/dslite2svd?rev=d527f3f)",
"tm4c129x 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -83,8 +72,8 @@ dependencies = [
]
[[package]]
name = "libc"
version = "0.2.40"
name = "libm"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -92,56 +81,11 @@ name = "managed"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "num"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
"num-iter 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-integer"
version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-iter"
version = "0.1.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "r0"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_syscall"
version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc_version"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "same-file"
version = "0.1.3"
@ -151,47 +95,24 @@ dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "smoltcp"
version = "0.4.0"
source = "git+https://github.com/m-labs/smoltcp?rev=cd893e6#cd893e6ab60f094d684b37be7bc013bf79f0459d"
dependencies = [
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "time"
version = "0.1.39"
name = "tm4c129x"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tm4c129x"
version = "0.5.0"
source = "git+https://github.com/m-labs/dslite2svd?rev=d527f3f#d527f3febb73eb63db94ff84a580a4ea71d3a23b"
dependencies = [
"bare-metal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cortex-m 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cortex-m-rt 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
"bare-metal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"cortex-m 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"cortex-m-rt 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -223,61 +144,29 @@ name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum aligned 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d1a92995cea48691c7c93e12597cca4d692bb3130d0a291c7141b9793c7829e7"
"checksum bare-metal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aacbba24771a81cfe18f5aedd5bf3208ca8324ecdd9344ddb61f8d2a051a4574"
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
"checksum build_const 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e90dc84f5e62d2ebe7676b83c22d33b6db8bd27340fb6ffbff0a364efa0cb9c9"
"checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23"
"checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9"
"checksum cortex-m 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4d553ca1f23403c81e6d3d28a64ef6e8eadd7f395195aacda65cbc0dc987738e"
"checksum cortex-m-rt 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "53c69efde430b7033dff0257ab2d899be0c66d1d60091aa6ff1eea8db0f74e44"
"checksum crc 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd5d02c0aac6bd68393ed69e00bbc2457f3e89075c6349db7189618dc4ddc1d7"
"checksum aligned 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d39da9b88ae1a81c03c9c082b8db83f1d0e93914126041962af61034ab44c4a5"
"checksum bare-metal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1bdcf9294ed648c7cd29b11db06ea244005aeef50ae8f605b1a3af2940bf8f92"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39"
"checksum byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "90492c5858dd7d2e78691cfb89f90d273a2800fc11d98f60786e5d87e2f83781"
"checksum cortex-m 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9ba6ba839428cb647fea7d4c607825f98c48a4ccd52c0199a19cfc6ef8258cb4"
"checksum cortex-m-rt 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "71738be48d61e40c8a638294efbf6ded5bef29def972ccb07984bf7630cc0bd4"
"checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b"
"checksum libm 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "03c0bb6d5ce1b5cc6fd0578ec1cbc18c9d88b5b591a5c7c1d6c6175e266a0819"
"checksum managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43e2737ecabe4ae36a68061398bf27d2bfd0763f4c3c837a398478459494c4b7"
"checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e"
"checksum num-integer 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f8d26da319fb45674985c78f1d1caf99aa4941f785d384a2ae36d0740bc3e2fe"
"checksum num-iter 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "4b226df12c5a59b63569dd57fafb926d91b385dfce33d8074a412411b689d593"
"checksum num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dee092fcdf725aee04dd7da1d21debff559237d49ef1cb3e69bcb8ece44c7364"
"checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f"
"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd"
"checksum rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a54aa04a10c68c1c4eacb4337fd883b435997ede17a9385784b990777686b09a"
"checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp?rev=cd893e6)" = "<none>"
"checksum time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a15375f1df02096fb3317256ce2cee6a1f42fc84ea5ad5fc8c421cfe40c73098"
"checksum tm4c129x 0.5.0 (git+https://github.com/m-labs/dslite2svd?rev=d527f3f)" = "<none>"
"checksum tm4c129x 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "909a3b55eff7680417067cd499774eb674a20141f28553a234732660b8133e62"
"checksum vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45c297f0afb6928cd08ab1ff9d95e99392595ea25ae1b5ecf822ff8764e57a0d"
"checksum volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286"
"checksum walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "bb08f9e670fab86099470b97cd2b252d6527f0b3cc1401acdb595ffc9dd288ff"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@ -7,14 +7,11 @@ authors = ["whitequark <whitequark@whitequark.org>"]
walkdir = "1.0"
[dependencies]
cortex-m = "0.3"
cortex-m-rt = "0.3"
libm = "0.1.2"
cortex-m = { version = "0.5", features = ["const-fn"] }
cortex-m-rt = "0.5"
crc = { version = "1.7", default-features = false }
[dependencies.tm4c129x]
git = "https://github.com/m-labs/dslite2svd"
rev = "d527f3f"
features = ["rt"]
tm4c129x = { version = "0.7", features = ["rt"] }
[dependencies.smoltcp]
git = "https://github.com/m-labs/smoltcp"

View File

@ -1,6 +0,0 @@
[dependencies.core]
[dependencies.compiler_builtins]
features = ["mem"]
git = "https://github.com/rust-lang-nursery/compiler-builtins"
stage = 1

View File

@ -56,7 +56,6 @@ fn linker_script() {
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=memory.x");
}

View File

@ -48,8 +48,8 @@ pub const FBI_R225: f32 = 22000.0;
pub fn set_led(state: bool) {
cortex_m::interrupt::free(|cs| {
let gpio_k = tm4c129x::GPIO_PORTK.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let gpio_k = unsafe { &*tm4c129x::GPIO_PORTK::ptr() };
if state {
gpio_k.data.modify(|r, w| w.data().bits(r.data().bits() | LED2))
} else {
@ -59,30 +59,30 @@ pub fn set_led(state: bool) {
}
pub fn get_button() -> bool {
let gpio_dat = cortex_m::interrupt::free(|cs| {
let gpio_l = tm4c129x::GPIO_PORTL.borrow(cs);
let gpio_dat = cortex_m::interrupt::free(|_cs| {
let gpio_l = unsafe { &*tm4c129x::GPIO_PORTL::ptr() };
gpio_l.data.read().bits() as u8
});
gpio_dat & BTNN == 0
}
pub fn set_hv_pwm(duty: u16) {
cortex_m::interrupt::free(|cs| {
let pwm0 = tm4c129x::PWM0.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let pwm0 = unsafe { &*tm4c129x::PWM0::ptr() };
pwm0._0_cmpa.write(|w| w.compa().bits(duty));
});
}
pub fn set_fv_pwm(duty: u16) {
cortex_m::interrupt::free(|cs| {
let pwm0 = tm4c129x::PWM0.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let pwm0 = unsafe { &*tm4c129x::PWM0::ptr() };
pwm0._1_cmpa.write(|w| w.compa().bits(duty));
});
}
pub fn set_fbv_pwm(duty: u16) {
cortex_m::interrupt::free(|cs| {
let pwm0 = tm4c129x::PWM0.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let pwm0 = unsafe { &*tm4c129x::PWM0::ptr() };
pwm0._2_cmpa.write(|w| w.compa().bits(duty));
});
}
@ -95,8 +95,8 @@ pub enum EmissionRange {
}
pub fn set_emission_range(range: EmissionRange) {
cortex_m::interrupt::free(|cs| {
let gpio_p = tm4c129x::GPIO_PORTP.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let gpio_p = unsafe { &*tm4c129x::GPIO_PORTP::ptr() };
gpio_p.data.modify(|r, w| {
let value = r.data().bits() & 0b100111;
match range {
@ -116,8 +116,8 @@ pub enum ElectrometerRange {
}
pub fn set_electrometer_range(range: ElectrometerRange) {
cortex_m::interrupt::free(|cs| {
let gpio_p = tm4c129x::GPIO_PORTP.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let gpio_p = unsafe { &*tm4c129x::GPIO_PORTP::ptr() };
gpio_p.data.modify(|r, w| {
let value = r.data().bits() & 0b111100;
match range {
@ -130,23 +130,23 @@ pub fn set_electrometer_range(range: ElectrometerRange) {
}
pub fn reset_error() {
cortex_m::interrupt::free(|cs| {
let gpio_q = tm4c129x::GPIO_PORTQ.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let gpio_q = unsafe { &*tm4c129x::GPIO_PORTQ::ptr() };
gpio_q.data.modify(|r, w| w.data().bits(r.data().bits() & !ERR_RESN));
gpio_q.data.modify(|r, w| w.data().bits(r.data().bits() | ERR_RESN));
});
}
pub fn error_latched() -> bool {
cortex_m::interrupt::free(|cs| {
let gpio_l = tm4c129x::GPIO_PORTL.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let gpio_l = unsafe { &*tm4c129x::GPIO_PORTL::ptr() };
gpio_l.data.read().bits() as u8 & ERR_LATCHN == 0
})
}
pub fn process_errors() {
let gpio_dat = cortex_m::interrupt::free(|cs| {
let gpio_l = tm4c129x::GPIO_PORTL.borrow(cs);
let gpio_dat = cortex_m::interrupt::free(|_cs| {
let gpio_l = unsafe { &*tm4c129x::GPIO_PORTL::ptr() };
gpio_l.data.read().bits() as u8
});
if gpio_dat & FV_ERRN == 0 {
@ -167,8 +167,8 @@ pub fn process_errors() {
}
pub fn init() {
cortex_m::interrupt::free(|cs| {
let sysctl = tm4c129x::SYSCTL.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let sysctl = unsafe { &*tm4c129x::SYSCTL::ptr() };
// Set up main oscillator
sysctl.moscctl.write(|w| w.noxtal().bit(false));
@ -210,7 +210,7 @@ pub fn init() {
while !sysctl.prgpio.read().r14().bit() {}
// Set up UART0
let gpio_a = tm4c129x::GPIO_PORTA_AHB.borrow(cs);
let gpio_a = unsafe { &*tm4c129x::GPIO_PORTA_AHB::ptr() };
gpio_a.dir.write(|w| w.dir().bits(0b11));
gpio_a.den.write(|w| w.den().bits(0b11));
gpio_a.afsel.write(|w| w.afsel().bits(0b11));
@ -219,7 +219,7 @@ pub fn init() {
sysctl.rcgcuart.modify(|_, w| w.r0().bit(true));
while !sysctl.pruart.read().r0().bit() {}
let uart_0 = tm4c129x::UART0.borrow(cs);
let uart_0 = unsafe { &*tm4c129x::UART0::ptr() };
uart_0.cc.write(|w| w.cs().sysclk());
uart_0.ibrd.write(|w| w.divint().bits((UART_DIV / 64) as u16));
uart_0.fbrd.write(|w| w.divfrac().bits((UART_DIV % 64) as u8));
@ -227,7 +227,7 @@ pub fn init() {
uart_0.ctl.write(|w| w.rxe().bit(true).txe().bit(true).uarten().bit(true));
// Set up LEDs
let gpio_k = tm4c129x::GPIO_PORTK.borrow(cs);
let gpio_k = unsafe { &*tm4c129x::GPIO_PORTK::ptr() };
gpio_k.dir.write(|w| w.dir().bits(LED1|LED2));
gpio_k.den.write(|w| w.den().bits(LED1|LED2));
// Switch LED1 to LAN mode
@ -235,15 +235,15 @@ pub fn init() {
gpio_k.pctl.modify(|_, w| unsafe { w.pmc4().bits(5) }); // EN0LED0
// Set up gain and emission range control pins
let gpio_p = tm4c129x::GPIO_PORTP.borrow(cs);
let gpio_p = unsafe { &*tm4c129x::GPIO_PORTP::ptr() };
gpio_p.dir.write(|w| w.dir().bits(0b111111));
gpio_p.den.write(|w| w.den().bits(0b111111));
set_emission_range(EmissionRange::Med);
set_electrometer_range(ElectrometerRange::Med);
// Set up error and pushbutton pins
let gpio_l = tm4c129x::GPIO_PORTL.borrow(cs);
let gpio_q = tm4c129x::GPIO_PORTQ.borrow(cs);
let gpio_l = unsafe { &*tm4c129x::GPIO_PORTL::ptr() };
let gpio_q = unsafe { &*tm4c129x::GPIO_PORTQ::ptr() };
gpio_l.pur.write(|w| w.pue().bits(FV_ERRN|FBV_ERRN|FBI_ERRN|AV_ERRN|AI_ERRN|BTNN));
gpio_l.den.write(|w| w.den().bits(FV_ERRN|FBV_ERRN|FBI_ERRN|AV_ERRN|AI_ERRN|ERR_LATCHN|BTNN));
gpio_q.dir.write(|w| w.dir().bits(ERR_RESN));
@ -251,13 +251,13 @@ pub fn init() {
reset_error(); // error latch is an undefined state upon power-up; reset it
// Set up PWMs
let gpio_f = tm4c129x::GPIO_PORTF_AHB.borrow(cs);
let gpio_f = unsafe { &*tm4c129x::GPIO_PORTF_AHB::ptr() };
gpio_f.dir.write(|w| w.dir().bits(HV_PWM|FV_PWM));
gpio_f.den.write(|w| w.den().bits(HV_PWM|FV_PWM));
gpio_f.afsel.write(|w| w.afsel().bits(HV_PWM|FV_PWM));
gpio_f.pctl.write(|w| unsafe { w.pmc0().bits(6).pmc2().bits(6) });
let gpio_g = tm4c129x::GPIO_PORTG_AHB.borrow(cs);
let gpio_g = unsafe { &*tm4c129x::GPIO_PORTG_AHB::ptr() };
gpio_g.dir.write(|w| w.dir().bits(FBV_PWM));
gpio_g.den.write(|w| w.den().bits(FBV_PWM));
gpio_g.afsel.write(|w| w.afsel().bits(FBV_PWM));
@ -266,7 +266,7 @@ pub fn init() {
sysctl.rcgcpwm.modify(|_, w| w.r0().bit(true));
while !sysctl.prpwm.read().r0().bit() {}
let pwm0 = tm4c129x::PWM0.borrow(cs);
let pwm0 = unsafe { &*tm4c129x::PWM0::ptr() };
// HV_PWM
pwm0._0_gena.write(|w| w.actload().zero().actcmpad().one());
pwm0._0_load.write(|w| w.load().bits(PWM_LOAD));
@ -292,11 +292,11 @@ pub fn init() {
}
pub fn start_adc() {
cortex_m::interrupt::free(|cs| {
let sysctl = tm4c129x::SYSCTL.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let sysctl = unsafe { &*tm4c129x::SYSCTL::ptr() };
let gpio_d = tm4c129x::GPIO_PORTD_AHB.borrow(cs);
let gpio_e = tm4c129x::GPIO_PORTE_AHB.borrow(cs);
let gpio_d = unsafe { &*tm4c129x::GPIO_PORTD_AHB::ptr() };
let gpio_e = unsafe { &*tm4c129x::GPIO_PORTE_AHB::ptr() };
gpio_d.afsel.write(|w| w.afsel().bits(FBV_ADC|AV_ADC));
gpio_d.amsel.write(|w| w.amsel().bits(FBV_ADC|AV_ADC));
gpio_e.afsel.write(|w| w.afsel().bits(FD_ADC|FV_ADC|FBI_ADC|IC_ADC));
@ -305,7 +305,7 @@ pub fn start_adc() {
sysctl.rcgcadc.modify(|_, w| w.r0().bit(true));
while !sysctl.pradc.read().r0().bit() {}
let adc0 = tm4c129x::ADC0.borrow(cs);
let adc0 = unsafe { &*tm4c129x::ADC0::ptr() };
// VCO 480 / 15 = 32MHz ADC clock
adc0.cc.write(|w| w.cs().syspll().clkdiv().bits(15-1));
adc0.im.write(|w| w.mask0().bit(true));
@ -331,27 +331,17 @@ pub fn start_adc() {
adc0.ctl.write(|w| w.vref().bit(true));
adc0.actss.write(|w| w.asen0().bit(true));
let nvic = tm4c129x::NVIC.borrow(cs);
nvic.enable(tm4c129x::Interrupt::ADC0SS0);
let mut cp = unsafe { tm4c129x::CorePeripherals::steal() };
cp.NVIC.enable(tm4c129x::Interrupt::ADC0SS0);
});
}
pub fn get_mac_address() -> [u8; 6] {
let (userreg0, userreg1) = cortex_m::interrupt::free(|cs| {
let flashctl = tm4c129x::FLASH_CTRL.borrow(cs);
let (userreg0, userreg1) = cortex_m::interrupt::free(|_cs| {
let flashctl = unsafe { &*tm4c129x::FLASH_CTRL::ptr() };
(flashctl.userreg0.read().bits(),
flashctl.userreg1.read().bits())
});
[userreg0 as u8, (userreg0 >> 8) as u8, (userreg0 >> 16) as u8,
userreg1 as u8, (userreg1 >> 8) as u8, (userreg1 >> 16) as u8]
}
pub fn delay(d: u32) {
for _ in 0..d {
unsafe {
asm!("
NOP
");
}
}
}

View File

@ -1,38 +1,36 @@
use cortex_m;
use cortex_m::{self, asm::delay};
use tm4c129x;
use board;
pub const BLOCK_COUNT: u16 = 96;
pub const BLOCK_LEN: usize = 64;
fn wait_done() {
while cortex_m::interrupt::free(|cs| {
let eeprom = tm4c129x::EEPROM.borrow(cs);
while cortex_m::interrupt::free(|_cs| {
let eeprom = unsafe { &*tm4c129x::EEPROM::ptr() };
eeprom.eedone.read().working().bit()
}) {};
}
pub fn init() {
cortex_m::interrupt::free(|cs| {
let sysctl = tm4c129x::SYSCTL.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let sysctl = unsafe { &*tm4c129x::SYSCTL::ptr() };
sysctl.rcgceeprom.modify(|_, w| w.r0().bit(true)); // Bring up EEPROM
board::delay(16);
delay(16);
sysctl.sreeprom.modify(|_, w| w.r0().bit(true)); // Activate EEPROM reset
board::delay(16);
delay(16);
sysctl.sreeprom.modify(|_, w| w.r0().bit(false)); // Dectivate EEPROM reset
board::delay(16);
delay(16);
while !sysctl.preeprom.read().r0().bit() {} // Wait for the EEPROM to come out of reset
board::delay(16);
delay(16);
});
wait_done();
}
pub fn read_block(buffer: &mut [u8; BLOCK_LEN], block: u16) {
assert!(block < BLOCK_COUNT);
cortex_m::interrupt::free(|cs| {
let eeprom = tm4c129x::EEPROM.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let eeprom = unsafe { &*tm4c129x::EEPROM::ptr() };
eeprom.eeblock.write(|w| unsafe { w.block().bits(block) });
eeprom.eeoffset.write(|w| unsafe { w.offset().bits(0) });
for i in 0..BLOCK_LEN/4 {
@ -47,19 +45,19 @@ pub fn read_block(buffer: &mut [u8; BLOCK_LEN], block: u16) {
pub fn write_block(buffer: &[u8; BLOCK_LEN], block: u16) {
assert!(block < BLOCK_COUNT);
cortex_m::interrupt::free(|cs| {
let eeprom = tm4c129x::EEPROM.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let eeprom = unsafe { &*tm4c129x::EEPROM::ptr() };
eeprom.eeblock.write(|w| unsafe { w.block().bits(block) });
eeprom.eeoffset.write(|w| unsafe { w.offset().bits(0) });
});
for i in 0..BLOCK_LEN/4 {
let word = buffer[4*i] as u32 | (buffer[4*i+1] as u32) << 8 |
(buffer[4*i+2] as u32) << 16 | (buffer[4*i+3] as u32) << 24;
cortex_m::interrupt::free(|cs| {
let eeprom = tm4c129x::EEPROM.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let eeprom = unsafe { &*tm4c129x::EEPROM::ptr() };
eeprom.eerdwrinc.write(|w| unsafe { w.bits(word) });
});
board::delay(16);
delay(16);
wait_done();
}
}

View File

@ -1,13 +1,11 @@
use core::{slice, cmp};
use cortex_m;
use cortex_m::{self, asm::delay};
use tm4c129x;
use smoltcp::Result;
use smoltcp::time::Instant;
use smoltcp::wire::EthernetAddress;
use smoltcp::phy;
use board;
const EPHY_BMCR: u8 = 0x00; // Ethernet PHY Basic Mode Control
#[allow(dead_code)]
const EPHY_BMSR: u8 = 0x01; // Ethernet PHY Basic Mode Status
@ -43,8 +41,8 @@ const ETH_RX_BUFFER_COUNT: usize = 3;
const ETH_RX_BUFFER_SIZE: usize = 1536;
fn phy_read(reg_addr: u8) -> u16 {
cortex_m::interrupt::free(|cs| {
let emac0 = tm4c129x::EMAC0.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let emac0 = unsafe { &*tm4c129x::EMAC0::ptr() };
// Make sure the MII is idle
while emac0.miiaddr.read().miib().bit() {};
@ -66,8 +64,8 @@ fn phy_read(reg_addr: u8) -> u16 {
}
fn phy_write(reg_addr: u8, reg_data: u16) {
cortex_m::interrupt::free(|cs| {
let emac0 = tm4c129x::EMAC0.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let emac0 = unsafe { &*tm4c129x::EMAC0::ptr() };
// Make sure the MII is idle
while emac0.miiaddr.read().miib().bit() {};
@ -236,8 +234,8 @@ impl TxRing {
self.desc_buf[self.cur_desc + 0] =
EMAC_TDES0_OWN | EMAC_TDES0_LS | EMAC_TDES0_FS | EMAC_TDES0_TCH;
cortex_m::interrupt::free(|cs| {
let emac0 = tm4c129x::EMAC0.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let emac0 = unsafe { &*tm4c129x::EMAC0::ptr() };
// Clear TU flag to resume processing
emac0.dmaris.write(|w| w.tu().bit(true));
// Instruct the DMA to poll the transmit descriptor list
@ -270,27 +268,27 @@ impl Device {
self.rx.init();
self.tx.init();
cortex_m::interrupt::free(|cs| {
let sysctl = tm4c129x::SYSCTL.borrow(cs);
let emac0 = tm4c129x::EMAC0.borrow(cs);
cortex_m::interrupt::free(|_cs| {
let sysctl = &*tm4c129x::SYSCTL::ptr();
let emac0 = &*tm4c129x::EMAC0::ptr();
sysctl.rcgcemac.modify(|_, w| w.r0().bit(true)); // Bring up MAC
sysctl.sremac.modify(|_, w| w.r0().bit(true)); // Activate MAC reset
board::delay(16);
delay(16);
sysctl.sremac.modify(|_, w| w.r0().bit(false)); // Dectivate MAC reset
sysctl.rcgcephy.modify(|_, w| w.r0().bit(true)); // Bring up PHY
sysctl.srephy.modify(|_, w| w.r0().bit(true)); // Activate PHY reset
board::delay(16);
delay(16);
sysctl.srephy.modify(|_, w| w.r0().bit(false)); // Dectivate PHY reset
while !sysctl.premac.read().r0().bit() {} // Wait for the MAC to come out of reset
while !sysctl.prephy.read().r0().bit() {} // Wait for the PHY to come out of reset
board::delay(10000);
delay(10000);
emac0.dmabusmod.modify(|_, w| w.swr().bit(true)); // Reset MAC DMA
while emac0.dmabusmod.read().swr().bit() {} // Wait for the MAC DMA to come out of reset
board::delay(1000);
delay(1000);
emac0.miiaddr.write(|w| w.cr()._100_150()); // Set the MII CSR clock speed.
@ -371,10 +369,10 @@ impl Device {
emac0.flowctl.write(|w| w.bits(0)); // Disable flow control ???
emac0.txdladdr.write(|w| unsafe {
emac0.txdladdr.write(|w| /*unsafe*/ {
w.bits((&mut self.tx.desc_buf[0] as *mut u32) as u32)
});
emac0.rxdladdr.write(|w| unsafe {
emac0.rxdladdr.write(|w| /*unsafe*/ {
w.bits((&mut self.rx.desc_buf[0] as *mut u32) as u32)
});

View File

@ -1,4 +1,4 @@
use core::num::Float;
use libm::F32Ext;
use board;
use pid;

View File

@ -1,4 +1,4 @@
use core::num::Float;
use libm::F32Ext;
use board;
use pid;

View File

@ -1,7 +1,10 @@
#![feature(used, const_fn, core_float, asm, lang_items, conservative_impl_trait)]
#![feature(const_fn, panic_handler)]
#![no_std]
#![no_main]
extern crate libm;
extern crate cortex_m;
#[macro_use]
extern crate cortex_m_rt;
#[macro_use(interrupt)]
extern crate tm4c129x;
@ -30,10 +33,10 @@ macro_rules! println {
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
}
#[lang = "panic_fmt"]
#[no_mangle]
pub extern fn rust_begin_panic(msg: fmt::Arguments, file: &'static str, line: u32, col: u32) -> ! {
println!("panic at {}:{}:{}: {}", file, line, col, msg);
#[no_mangle] // https://github.com/rust-lang/rust/issues/{38281,51647}
#[panic_handler]
pub fn panic_fmt(info: &core::panic::PanicInfo) -> ! {
println!("{}", info);
loop {}
}
@ -72,12 +75,10 @@ pub struct UART0;
impl fmt::Write for UART0 {
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
let uart_0 = unsafe { &*tm4c129x::UART0::ptr() };
for c in s.bytes() {
unsafe {
let uart_0 = tm4c129x::UART0.get();
while (*uart_0).fr.read().txff().bit() {}
(*uart_0).dr.write(|w| w.data().bits(c))
}
while uart_0.fr.read().txff().bit() {}
uart_0.dr.write(|w| w.data().bits(c))
}
Ok(())
}
@ -103,7 +104,9 @@ macro_rules! create_socket {
)
}
fn main() {
entry!(main);
fn main() -> ! {
board::init();
let button_pressed = board::get_button();
@ -283,7 +286,7 @@ fn main() {
interrupt!(ADC0SS0, adc0_ss0);
fn adc0_ss0() {
cortex_m::interrupt::free(|cs| {
let adc0 = tm4c129x::ADC0.borrow(cs);
let adc0 = unsafe { &*tm4c129x::ADC0::ptr() };
if adc0.ostat.read().ov0().bit() {
panic!("ADC FIFO overflowed")
}