Skip to content

Commit 7e2c2a9

Browse files
committed
LPC1768 Reset Reason implementation
1 parent 2fcafb9 commit 7e2c2a9

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2006-2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "reset_reason_api.h"
17+
18+
#ifdef DEVICE_RESET_REASON
19+
20+
#include "device.h"
21+
22+
reset_reason_t hal_reset_reason_get(void)
23+
{
24+
if (LPC_SC->RSID & (1<<0)) {
25+
return RESET_REASON_POWER_ON;
26+
}
27+
28+
if (LPC_SC->RSID & (1<<1)) {
29+
return RESET_REASON_PIN_RESET;
30+
}
31+
if (LPC_SC->RSID & (1<<2)) {
32+
return RESET_REASON_WATCHDOG;
33+
}
34+
35+
if (LPC_SC->RSID & (1<<3)) {
36+
return RESET_REASON_BROWN_OUT;
37+
}
38+
if (LPC_SC->RSID & (1<<4)) {
39+
return RESET_REASON_SOFTWARE;
40+
}
41+
42+
if (LPC_SC->RSID & (1<<5)) {
43+
return RESET_REASON_LOCKUP;
44+
}
45+
46+
return RESET_REASON_UNKNOWN;
47+
}
48+
49+
50+
uint32_t hal_reset_reason_get_raw(void)
51+
{
52+
53+
return LPC_SC->RSID;
54+
}
55+
56+
57+
void hal_reset_reason_clear(void)
58+
{
59+
LPC_SC->RSID = 0xff; // Clear flags
60+
}
61+
62+
#endif // DEVICE_RESET_REASON

targets/targets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,8 @@
625625
"FLASH",
626626
"MPU",
627627
"USBDEVICE",
628-
"WATCHDOG"
628+
"WATCHDOG",
629+
"RESET_REASON"
629630
],
630631
"release_versions": ["2", "5"],
631632
"device_name": "LPC1768",

0 commit comments

Comments
 (0)