|
| 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 |
0 commit comments