Skip to content

Commit 191f029

Browse files
authored
Merge pull request #11226 from chrissnow/LPC1768_WDT
LPC1768 Watchdog & Reset Reason
2 parents 7ee382b + 82f4be0 commit 191f029

File tree

3 files changed

+149
-4
lines changed

3 files changed

+149
-4
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* Copyright (c) 2017-2019 ARM Limited
2+
* SPDX-License-Identifier: Apache-2.0
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+
* @section DESCRIPTION
17+
*
18+
* LPC1768 Reset Reason
19+
*
20+
*/
21+
#include "reset_reason_api.h"
22+
23+
#ifdef DEVICE_RESET_REASON
24+
25+
#include "device.h"
26+
27+
reset_reason_t hal_reset_reason_get(void)
28+
{
29+
if (LPC_SC->RSID & (1<<0)) {
30+
return RESET_REASON_POWER_ON;
31+
}
32+
33+
if (LPC_SC->RSID & (1<<1)) {
34+
return RESET_REASON_PIN_RESET;
35+
}
36+
if (LPC_SC->RSID & (1<<2)) {
37+
return RESET_REASON_WATCHDOG;
38+
}
39+
40+
if (LPC_SC->RSID & (1<<3)) {
41+
return RESET_REASON_BROWN_OUT;
42+
}
43+
if (LPC_SC->RSID & (1<<4)) {
44+
return RESET_REASON_SOFTWARE;
45+
}
46+
47+
if (LPC_SC->RSID & (1<<5)) {
48+
return RESET_REASON_LOCKUP;
49+
}
50+
51+
return RESET_REASON_UNKNOWN;
52+
}
53+
54+
55+
uint32_t hal_reset_reason_get_raw(void)
56+
{
57+
58+
return LPC_SC->RSID;
59+
}
60+
61+
62+
void hal_reset_reason_clear(void)
63+
{
64+
LPC_SC->RSID = 0xff; // Clear flags
65+
}
66+
67+
#endif // DEVICE_RESET_REASON
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* Copyright (c) 2017-2019 ARM Limited
2+
* SPDX-License-Identifier: Apache-2.0
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+
* @section DESCRIPTION
17+
*
18+
* LPC1768 Watchdog
19+
*
20+
*/
21+
#ifdef DEVICE_WATCHDOG
22+
23+
#include "watchdog_api.h"
24+
#include "reset_reason_api.h"
25+
#include "device.h"
26+
#include "mbed_error.h"
27+
#include <stdbool.h>
28+
29+
30+
31+
watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
32+
{
33+
LPC_WDT->WDCLKSEL = 0x1; //CLK src to PCLK
34+
uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4
35+
LPC_WDT->WDTC = ((float)config->timeout_ms )* clk/1000;
36+
LPC_WDT->WDMOD = 0x3; // Enable and Reset
37+
hal_watchdog_kick();
38+
39+
return WATCHDOG_STATUS_OK;
40+
}
41+
42+
void hal_watchdog_kick(void)
43+
{
44+
LPC_WDT->WDFEED = 0xAA;
45+
LPC_WDT->WDFEED = 0x55;
46+
}
47+
watchdog_status_t hal_watchdog_stop(void)
48+
{
49+
return WATCHDOG_STATUS_NOT_SUPPORTED;
50+
}
51+
52+
uint32_t hal_watchdog_get_reload_value(void)
53+
{
54+
uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4
55+
56+
return (float)LPC_WDT->WDTC/clk*1000;
57+
}
58+
59+
watchdog_features_t hal_watchdog_get_platform_features(void)
60+
{
61+
uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4
62+
watchdog_features_t features;
63+
features.max_timeout = ((float)INT32_MAX/clk)*1000;
64+
features.update_config = true;
65+
features.disable_watchdog = false;
66+
67+
return features;
68+
}
69+
70+
#endif // DEVICE_WATCHDOG

targets/targets.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,9 @@
624624
"STDIO_MESSAGES",
625625
"FLASH",
626626
"MPU",
627-
"USBDEVICE"
627+
"USBDEVICE",
628+
"WATCHDOG",
629+
"RESET_REASON"
628630
],
629631
"release_versions": ["2", "5"],
630632
"device_name": "LPC1768",
@@ -673,7 +675,9 @@
673675
"FLASH",
674676
"MPU",
675677
"USBDEVICE",
676-
"USTICKER"
678+
"USTICKER",
679+
"WATCHDOG",
680+
"RESET_REASON"
677681
],
678682
"release_versions": ["2", "5"],
679683
"device_name": "LPC1768",
@@ -723,7 +727,9 @@
723727
"SPISLAVE",
724728
"STDIO_MESSAGES",
725729
"FLASH",
726-
"MPU"
730+
"MPU",
731+
"WATCHDOG",
732+
"RESET_REASON"
727733
],
728734
"release_versions": ["2", "5"],
729735
"device_name": "LPC1768",
@@ -761,7 +767,9 @@
761767
"SPISLAVE",
762768
"STDIO_MESSAGES",
763769
"FLASH",
764-
"MPU"
770+
"MPU",
771+
"WATCHDOG",
772+
"RESET_REASON"
765773
],
766774
"device_name": "LPC1768"
767775
},

0 commit comments

Comments
 (0)