mbed-os5 only for TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Committer:
kenjiArai
Date:
Tue Dec 31 06:02:27 2019 +0000
Revision:
1:9db0e321a9f4
Parent:
drivers/Watchdog.cpp@0:5b88d5760320
updated based on mbed-os5.15.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 0:5b88d5760320 1 /*
kenjiArai 0:5b88d5760320 2 * Copyright (c) 2018-2019 Arm Limited and affiliates.
kenjiArai 0:5b88d5760320 3 * SPDX-License-Identifier: Apache-2.0
kenjiArai 0:5b88d5760320 4 *
kenjiArai 0:5b88d5760320 5 * Licensed under the Apache License, Version 2.0 (the "License");
kenjiArai 0:5b88d5760320 6 * you may not use this file except in compliance with the License.
kenjiArai 0:5b88d5760320 7 * You may obtain a copy of the License at
kenjiArai 0:5b88d5760320 8 *
kenjiArai 0:5b88d5760320 9 * http://www.apache.org/licenses/LICENSE-2.0
kenjiArai 0:5b88d5760320 10 *
kenjiArai 0:5b88d5760320 11 * Unless required by applicable law or agreed to in writing, software
kenjiArai 0:5b88d5760320 12 * distributed under the License is distributed on an "AS IS" BASIS,
kenjiArai 0:5b88d5760320 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kenjiArai 0:5b88d5760320 14 * See the License for the specific language governing permissions and
kenjiArai 0:5b88d5760320 15 * limitations under the License.
kenjiArai 0:5b88d5760320 16 */
kenjiArai 0:5b88d5760320 17 #ifdef DEVICE_WATCHDOG
kenjiArai 0:5b88d5760320 18
kenjiArai 0:5b88d5760320 19 #include "drivers/Watchdog.h"
kenjiArai 0:5b88d5760320 20
kenjiArai 0:5b88d5760320 21 namespace mbed {
kenjiArai 0:5b88d5760320 22
kenjiArai 0:5b88d5760320 23 Watchdog::Watchdog() : _running(false)
kenjiArai 0:5b88d5760320 24 {
kenjiArai 0:5b88d5760320 25 }
kenjiArai 0:5b88d5760320 26
kenjiArai 0:5b88d5760320 27 Watchdog::~Watchdog()
kenjiArai 0:5b88d5760320 28 {
kenjiArai 0:5b88d5760320 29 }
kenjiArai 0:5b88d5760320 30
kenjiArai 0:5b88d5760320 31 bool Watchdog::start(uint32_t timeout)
kenjiArai 0:5b88d5760320 32 {
kenjiArai 0:5b88d5760320 33 MBED_ASSERT(timeout <= get_max_timeout());
kenjiArai 0:5b88d5760320 34 MBED_ASSERT(timeout > 0);
kenjiArai 0:5b88d5760320 35
kenjiArai 0:5b88d5760320 36 core_util_critical_section_enter();
kenjiArai 0:5b88d5760320 37 if (_running) {
kenjiArai 0:5b88d5760320 38 core_util_critical_section_exit();
kenjiArai 0:5b88d5760320 39 return false;
kenjiArai 0:5b88d5760320 40 }
kenjiArai 0:5b88d5760320 41 watchdog_config_t config;
kenjiArai 0:5b88d5760320 42 config.timeout_ms = timeout;
kenjiArai 0:5b88d5760320 43 watchdog_status_t sts = hal_watchdog_init(&config);
kenjiArai 0:5b88d5760320 44 if (sts == WATCHDOG_STATUS_OK) {
kenjiArai 0:5b88d5760320 45 _running = true;
kenjiArai 0:5b88d5760320 46 }
kenjiArai 0:5b88d5760320 47 core_util_critical_section_exit();
kenjiArai 0:5b88d5760320 48 return _running;
kenjiArai 0:5b88d5760320 49 }
kenjiArai 0:5b88d5760320 50
kenjiArai 0:5b88d5760320 51 bool Watchdog::start()
kenjiArai 0:5b88d5760320 52 {
kenjiArai 0:5b88d5760320 53
kenjiArai 0:5b88d5760320 54 return start(get_max_timeout());
kenjiArai 0:5b88d5760320 55 }
kenjiArai 0:5b88d5760320 56
kenjiArai 0:5b88d5760320 57 bool Watchdog::stop()
kenjiArai 0:5b88d5760320 58 {
kenjiArai 0:5b88d5760320 59 watchdog_status_t sts;
kenjiArai 0:5b88d5760320 60 bool msts = true;
kenjiArai 0:5b88d5760320 61 core_util_critical_section_enter();
kenjiArai 0:5b88d5760320 62 if (_running) {
kenjiArai 0:5b88d5760320 63 sts = hal_watchdog_stop();
kenjiArai 0:5b88d5760320 64 if (sts != WATCHDOG_STATUS_OK) {
kenjiArai 0:5b88d5760320 65 msts = false;
kenjiArai 0:5b88d5760320 66 } else {
kenjiArai 0:5b88d5760320 67 _running = false;
kenjiArai 0:5b88d5760320 68 }
kenjiArai 0:5b88d5760320 69
kenjiArai 0:5b88d5760320 70 } else {
kenjiArai 0:5b88d5760320 71 msts = false;
kenjiArai 0:5b88d5760320 72 }
kenjiArai 0:5b88d5760320 73 core_util_critical_section_exit();
kenjiArai 0:5b88d5760320 74 return msts;
kenjiArai 0:5b88d5760320 75 }
kenjiArai 0:5b88d5760320 76
kenjiArai 0:5b88d5760320 77 void Watchdog::kick()
kenjiArai 0:5b88d5760320 78 {
kenjiArai 0:5b88d5760320 79 core_util_critical_section_enter();
kenjiArai 0:5b88d5760320 80 hal_watchdog_kick();
kenjiArai 0:5b88d5760320 81 core_util_critical_section_exit();
kenjiArai 0:5b88d5760320 82 }
kenjiArai 0:5b88d5760320 83
kenjiArai 0:5b88d5760320 84 bool Watchdog::is_running() const
kenjiArai 0:5b88d5760320 85 {
kenjiArai 0:5b88d5760320 86 return _running;
kenjiArai 0:5b88d5760320 87 }
kenjiArai 0:5b88d5760320 88
kenjiArai 0:5b88d5760320 89 uint32_t Watchdog::get_timeout() const
kenjiArai 0:5b88d5760320 90 {
kenjiArai 0:5b88d5760320 91 return hal_watchdog_get_reload_value();
kenjiArai 0:5b88d5760320 92 }
kenjiArai 0:5b88d5760320 93
kenjiArai 0:5b88d5760320 94 uint32_t Watchdog::get_max_timeout() const
kenjiArai 0:5b88d5760320 95 {
kenjiArai 0:5b88d5760320 96 const watchdog_features_t features = hal_watchdog_get_platform_features();
kenjiArai 0:5b88d5760320 97 return features.max_timeout;
kenjiArai 0:5b88d5760320 98 }
kenjiArai 0:5b88d5760320 99
kenjiArai 0:5b88d5760320 100 } // namespace mbed
kenjiArai 0:5b88d5760320 101
kenjiArai 0:5b88d5760320 102
kenjiArai 0:5b88d5760320 103 #endif // DEVICE_WATCHDOG