Skip to content

Commit 19105cd

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

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
30+
31+
void hal_reset_reason_get_capabilities(reset_reason_capabilities_t *cap)
32+
{
33+
cap->reasons = 1 << RESET_REASON_UNKNOWN;
34+
cap->reasons |= 1 << RESET_REASON_WATCHDOG;
35+
cap->reasons |= 1 << RESET_REASON_SOFTWARE;
36+
cap->reasons |= 1 << RESET_REASON_WAKE_LOW_POWER;
37+
cap->reasons |= 1 << RESET_REASON_PLATFORM;
38+
cap->reasons |= 1 << RESET_REASON_MULTIPLE;
39+
}
40+
41+
reset_reason_t hal_reset_reason_get(void)
42+
{
43+
cyhal_reset_reason_t hal_reason = cyhal_system_get_reset_reason();
44+
45+
reset_reason_t reason = RESET_REASON_UNKNOWN;
46+
uint8_t count = 0;
47+
if(CYHAL_SYSTEM_RESET_WDT & hal_reason) {reason = RESET_REASON_WATCHDOG; count++;}
48+
if(CYHAL_SYSTEM_RESET_ACTIVE_FAULT & hal_reason) {reason = RESET_REASON_PLATFORM; count++;}
49+
if(CYHAL_SYSTEM_RESET_DEEPSLEEP_FAULT & hal_reason) {reason = RESET_REASON_PLATFORM; count++;}
50+
if(CYHAL_SYSTEM_RESET_SOFT & hal_reason) {reason = RESET_REASON_SOFTWARE; count++;}
51+
if(CYHAL_SYSTEM_RESET_HIB_WAKEUP & hal_reason) {reason = RESET_REASON_WAKE_LOW_POWER; count++;}
52+
if(CYHAL_SYSTEM_RESET_WCO_ERR & hal_reason) {reason = RESET_REASON_PLATFORM; count++;}
53+
if(CYHAL_SYSTEM_RESET_SYS_CLK_ERR & hal_reason) {reason = RESET_REASON_PLATFORM; count++;}
54+
55+
if(count > 1)
56+
reason = RESET_REASON_MULTIPLE;
57+
58+
return reason;
59+
}
60+
61+
uint32_t hal_reset_reason_get_raw(void)
62+
{
63+
return Cy_SysLib_GetResetReason();
64+
}
65+
66+
void hal_reset_reason_clear(void)
67+
{
68+
Cy_SysLib_ClearResetReason();
69+
}
70+
71+
#ifdef __cplusplus
72+
}
73+
#endif
74+
75+
#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)