Skip to content

Commit ceff920

Browse files
Implemented reset reason api.
1 parent 3d038e5 commit ceff920

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* mbed Microcontroller Library
3+
* Copyright (c) 2017-2018 Future Electronics
4+
* Copyright (c) 2019, Arm Limited and affiliates.
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#include "mbed_assert.h"
21+
#include "mbed_error.h"
22+
#include "cyhal_system.h"
23+
#include "hal/reset_reason_api.h"
24+
25+
#if DEVICE_RESET_REASON
26+
27+
void hal_reset_reason_get_capabilities(reset_reason_capabilities_t *cap)
28+
{
29+
cap->reasons = 1 << RESET_REASON_UNKNOWN;
30+
cap->reasons |= 1 << RESET_REASON_WATCHDOG;
31+
cap->reasons |= 1 << RESET_REASON_SOFTWARE;
32+
cap->reasons |= 1 << RESET_REASON_WAKE_LOW_POWER;
33+
cap->reasons |= 1 << RESET_REASON_PLATFORM;
34+
cap->reasons |= 1 << RESET_REASON_MULTIPLE;
35+
}
36+
37+
reset_reason_t hal_reset_reason_get(void)
38+
{
39+
cyhal_reset_reason_t hal_reason = cyhal_system_get_reset_reason();
40+
41+
reset_reason_t reason = RESET_REASON_UNKNOWN;
42+
uint8_t count = 0;
43+
if(CYHAL_SYSTEM_RESET_WDT & hal_reason) {
44+
reason = RESET_REASON_WATCHDOG;
45+
count++;
46+
}
47+
if(CYHAL_SYSTEM_RESET_ACTIVE_FAULT & hal_reason) {
48+
reason = RESET_REASON_PLATFORM;
49+
count++;
50+
}
51+
if(CYHAL_SYSTEM_RESET_DEEPSLEEP_FAULT & hal_reason) {
52+
reason = RESET_REASON_PLATFORM;
53+
count++;
54+
}
55+
if(CYHAL_SYSTEM_RESET_SOFT & hal_reason) {
56+
reason = RESET_REASON_SOFTWARE;
57+
count++;
58+
}
59+
if(CYHAL_SYSTEM_RESET_HIB_WAKEUP & hal_reason) {
60+
reason = RESET_REASON_WAKE_LOW_POWER;
61+
count++;
62+
}
63+
if(CYHAL_SYSTEM_RESET_WCO_ERR & hal_reason) {
64+
reason = RESET_REASON_PLATFORM;
65+
count++;
66+
}
67+
if(CYHAL_SYSTEM_RESET_SYS_CLK_ERR & hal_reason) {
68+
reason = RESET_REASON_PLATFORM;
69+
count++;
70+
}
71+
72+
if(count > 1)
73+
reason = RESET_REASON_MULTIPLE;
74+
75+
return reason;
76+
}
77+
78+
uint32_t hal_reset_reason_get_raw(void)
79+
{
80+
return Cy_SysLib_GetResetReason();
81+
}
82+
83+
void hal_reset_reason_clear(void)
84+
{
85+
Cy_SysLib_ClearResetReason();
86+
}
87+
88+
#endif // DEVICE_RESET_REASON

targets/targets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13398,6 +13398,7 @@
1339813398
"PORTINOUT",
1339913399
"PWMOUT",
1340013400
"QSPI",
13401+
"RESET_REASON",
1340113402
"RTC",
1340213403
"SERIAL",
1340313404
"SERIAL_FC",

0 commit comments

Comments
 (0)