Skip to content

Commit 2fcafb9

Browse files
committed
LPC1768 WDT implementation
1 parent b82cfcc commit 2fcafb9

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2006-2018 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+
17+
18+
#ifdef DEVICE_WATCHDOG
19+
20+
#include "watchdog_api.h"
21+
#include "reset_reason_api.h"
22+
#include "device.h"
23+
#include "mbed_error.h"
24+
#include <stdbool.h>
25+
26+
27+
28+
watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
29+
{
30+
LPC_WDT->WDCLKSEL = 0x1; //CLK src to PCLK
31+
uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4
32+
LPC_WDT->WDTC = ((float)config->timeout_ms )* clk/1000;
33+
LPC_WDT->WDMOD = 0x3; // Enable and Reset
34+
hal_watchdog_kick();
35+
36+
return WATCHDOG_STATUS_OK;
37+
}
38+
39+
void hal_watchdog_kick(void)
40+
{
41+
LPC_WDT->WDFEED = 0xAA;
42+
LPC_WDT->WDFEED = 0x55;
43+
}
44+
watchdog_status_t hal_watchdog_stop(void)
45+
{
46+
return WATCHDOG_STATUS_NOT_SUPPORTED;
47+
}
48+
49+
uint32_t hal_watchdog_get_reload_value(void)
50+
{
51+
uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4
52+
53+
return (float)LPC_WDT->WDTC/clk*1000;
54+
}
55+
56+
watchdog_features_t hal_watchdog_get_platform_features(void)
57+
{
58+
uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4
59+
watchdog_features_t features;
60+
features.max_timeout = ((float)INT32_MAX/clk)*1000;
61+
features.update_config = true;
62+
features.disable_watchdog = false;
63+
64+
return features;
65+
}
66+
67+
#endif // DEVICE_WATCHDOG

targets/targets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,8 @@
624624
"STDIO_MESSAGES",
625625
"FLASH",
626626
"MPU",
627-
"USBDEVICE"
627+
"USBDEVICE",
628+
"WATCHDOG"
628629
],
629630
"release_versions": ["2", "5"],
630631
"device_name": "LPC1768",

0 commit comments

Comments
 (0)