From d7b1025de4e9ee55ea4a380d777ae31f1b53eae2 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Sat, 16 Nov 2019 19:15:51 +0100 Subject: [PATCH] common: Add the watchdog module. For now this only lets us disable the COP watchdog. --- SConscript.libcommon | 1 + src/common/lib.rs | 1 + src/common/watchdog.rs | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/common/watchdog.rs diff --git a/SConscript.libcommon b/SConscript.libcommon index 79433bc..e4dd29a 100644 --- a/SConscript.libcommon +++ b/SConscript.libcommon @@ -9,6 +9,7 @@ source_files_rs = [ 'src/common/systick.rs', 'src/common/port.rs', 'src/common/gpio.rs', + 'src/common/watchdog.rs', 'src/common/crc32.rs', 'src/common/buffer.rs', 'src/common/usb_serial.rs', diff --git a/src/common/lib.rs b/src/common/lib.rs index 7828fea..0c179fc 100644 --- a/src/common/lib.rs +++ b/src/common/lib.rs @@ -31,6 +31,7 @@ pub mod clock; pub mod systick; pub mod port; pub mod gpio; +pub mod watchdog; pub mod crc32; pub mod buffer; pub mod usb_serial; diff --git a/src/common/watchdog.rs b/src/common/watchdog.rs new file mode 100644 index 0000000..981e98a --- /dev/null +++ b/src/common/watchdog.rs @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 Tilman Sauerbeck (tilman at code-monkey de) + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +use register; + +type Reg32 = register::Register; + +const SIM_COPC: u32 = 0x40048100; + +const SIM_COPC_COPT_SHIFT: u32 = 2; + +pub fn disable() { + let mut copc = Reg32::new(SIM_COPC); + + copc.modify(|v| v & !(3 << SIM_COPC_COPT_SHIFT)); +} -- 2.30.2