2017-11-28 14:00:56 +00:00
|
|
|
/* mbed Microcontroller Library
|
2018-11-19 16:55:27 +00:00
|
|
|
* Copyright (c) 2018 ARM Limited
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2017-11-28 14:00:56 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#ifdef DEVICE_WATCHDOG
|
|
|
|
|
|
|
|
#include "Watchdog.h"
|
|
|
|
|
2019-01-25 11:41:23 +00:00
|
|
|
namespace mbed {
|
|
|
|
|
|
|
|
Watchdog *Watchdog::_first = NULL;
|
2019-01-03 12:33:26 +00:00
|
|
|
|
2019-01-25 11:41:23 +00:00
|
|
|
Watchdog::Watchdog(uint32_t timeout, const char *const str): _name(str)
|
|
|
|
{
|
|
|
|
_current_count = 0;
|
|
|
|
_is_initialized = false;
|
|
|
|
_next = NULL;
|
|
|
|
_max_timeout = timeout;
|
|
|
|
}
|
2019-01-03 12:33:26 +00:00
|
|
|
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
void Watchdog::add_to_list()
|
2017-11-28 14:00:56 +00:00
|
|
|
{
|
2019-01-25 11:41:23 +00:00
|
|
|
this->_next = _first;
|
|
|
|
_first = this;
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
_is_initialized = true;
|
2017-11-28 14:00:56 +00:00
|
|
|
}
|
|
|
|
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
void Watchdog::start()
|
2017-11-28 14:00:56 +00:00
|
|
|
{
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
MBED_ASSERT(!_is_initialized);
|
|
|
|
core_util_critical_section_enter();
|
|
|
|
add_to_list();
|
|
|
|
core_util_critical_section_exit();
|
2017-11-28 14:00:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
void Watchdog::kick()
|
2017-11-28 14:00:56 +00:00
|
|
|
{
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
MBED_ASSERT(_is_initialized);
|
|
|
|
core_util_critical_section_enter();
|
|
|
|
_current_count = 0;
|
|
|
|
core_util_critical_section_exit();
|
|
|
|
}
|
2019-01-03 12:33:26 +00:00
|
|
|
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
void Watchdog::stop()
|
|
|
|
{
|
|
|
|
MBED_ASSERT(_is_initialized);
|
|
|
|
core_util_critical_section_enter();
|
|
|
|
remove_from_list();
|
|
|
|
core_util_critical_section_exit();
|
2017-11-28 14:00:56 +00:00
|
|
|
}
|
|
|
|
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
void Watchdog::remove_from_list()
|
2019-01-03 12:33:26 +00:00
|
|
|
{
|
2019-01-25 11:41:23 +00:00
|
|
|
Watchdog *cur_ptr = _first,
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
*prev_ptr = NULL;
|
2019-01-25 11:41:23 +00:00
|
|
|
while (cur_ptr != NULL) {
|
|
|
|
if (cur_ptr == this) {
|
|
|
|
if (cur_ptr == _first) {
|
|
|
|
prev_ptr = _first;
|
|
|
|
_first = cur_ptr->_next;
|
|
|
|
prev_ptr->_next = NULL;
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
} else {
|
2019-01-25 11:41:23 +00:00
|
|
|
prev_ptr->_next = cur_ptr->_next;
|
|
|
|
cur_ptr->_next = NULL;
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
}
|
|
|
|
_is_initialized = false;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
prev_ptr = cur_ptr;
|
2019-01-25 11:41:23 +00:00
|
|
|
cur_ptr = cur_ptr->_next;
|
2019-01-03 12:33:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-28 14:00:56 +00:00
|
|
|
|
2019-01-25 11:41:23 +00:00
|
|
|
void Watchdog::process(uint32_t elapsed_ms)
|
2017-11-28 14:00:56 +00:00
|
|
|
{
|
2019-01-25 11:41:23 +00:00
|
|
|
Watchdog *cur_ptr = _first;
|
|
|
|
while (cur_ptr != NULL) {
|
|
|
|
if (cur_ptr->_current_count > cur_ptr->_max_timeout) {
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
system_reset();
|
|
|
|
} else {
|
2019-01-25 11:41:23 +00:00
|
|
|
cur_ptr->_current_count += elapsed_ms;
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
}
|
2019-01-25 11:41:23 +00:00
|
|
|
cur_ptr = cur_ptr->_next;
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
}
|
2017-11-28 14:00:56 +00:00
|
|
|
}
|
|
|
|
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
Watchdog::~Watchdog()
|
2017-11-28 14:00:56 +00:00
|
|
|
{
|
2019-01-25 11:41:23 +00:00
|
|
|
if (_is_initialized) {
|
Add SW Watchdog
-SW watchdog has interface name start(),stop(),kick() Sw watchdog internally has static list and shared across multiple instance of SW watchdog
- Sw watchdog initialize timeout value,unique string via constructor whenever threads created sw watchdog object
-Threads make sure pass proper timeout value,Unique string while creating the instance.
-start() called by components(BLE,WIFI etc.,),it adds the entry into static list with few details current count ,etc.,
-kick() called by registered components(BLE,WIFI etc.) to reset current count to zero.
-is_alive - interface API to mbed_watchdog_manager
-implementation optimization
2019-01-17 11:57:56 +00:00
|
|
|
stop();
|
2019-01-25 11:41:23 +00:00
|
|
|
}
|
2017-11-28 14:00:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mbed
|
|
|
|
|
|
|
|
#endif // DEVICE_WATCHDOG
|