Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
Watchdog.cpp
00001 /* 00002 * Copyright (c) 2018-2019 Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #ifdef DEVICE_WATCHDOG 00018 00019 #include "drivers/Watchdog.h" 00020 00021 namespace mbed { 00022 00023 Watchdog::Watchdog() : _running(false) 00024 { 00025 } 00026 00027 Watchdog::~Watchdog() 00028 { 00029 } 00030 00031 bool Watchdog::start(uint32_t timeout) 00032 { 00033 MBED_ASSERT(timeout <= get_max_timeout()); 00034 MBED_ASSERT(timeout > 0); 00035 00036 core_util_critical_section_enter(); 00037 if (_running) { 00038 core_util_critical_section_exit(); 00039 return false; 00040 } 00041 watchdog_config_t config; 00042 config.timeout_ms = timeout; 00043 watchdog_status_t sts = hal_watchdog_init(&config); 00044 if (sts == WATCHDOG_STATUS_OK) { 00045 _running = true; 00046 } 00047 core_util_critical_section_exit(); 00048 return _running; 00049 } 00050 00051 bool Watchdog::start() 00052 { 00053 00054 return start(get_max_timeout()); 00055 } 00056 00057 bool Watchdog::stop() 00058 { 00059 watchdog_status_t sts; 00060 bool msts = true; 00061 core_util_critical_section_enter(); 00062 if (_running) { 00063 sts = hal_watchdog_stop(); 00064 if (sts != WATCHDOG_STATUS_OK) { 00065 msts = false; 00066 } else { 00067 _running = false; 00068 } 00069 00070 } else { 00071 msts = false; 00072 } 00073 core_util_critical_section_exit(); 00074 return msts; 00075 } 00076 00077 void Watchdog::kick() 00078 { 00079 core_util_critical_section_enter(); 00080 hal_watchdog_kick(); 00081 core_util_critical_section_exit(); 00082 } 00083 00084 bool Watchdog::is_running() const 00085 { 00086 return _running; 00087 } 00088 00089 uint32_t Watchdog::get_timeout() const 00090 { 00091 return hal_watchdog_get_reload_value(); 00092 } 00093 00094 uint32_t Watchdog::get_max_timeout() const 00095 { 00096 const watchdog_features_t features = hal_watchdog_get_platform_features(); 00097 return features.max_timeout; 00098 } 00099 00100 } // namespace mbed 00101 00102 00103 #endif // DEVICE_WATCHDOG
Generated on Tue Jul 12 2022 13:55:03 by
