diff --git a/targets/TARGET_NXP/TARGET_LPC176X/reset_reason.c b/targets/TARGET_NXP/TARGET_LPC176X/reset_reason.c new file mode 100644 index 0000000000..bbf08f50f9 --- /dev/null +++ b/targets/TARGET_NXP/TARGET_LPC176X/reset_reason.c @@ -0,0 +1,62 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2017 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "reset_reason_api.h" + +#ifdef DEVICE_RESET_REASON + +#include "device.h" + +reset_reason_t hal_reset_reason_get(void) +{ + if (LPC_SC->RSID & (1<<0)) { + return RESET_REASON_POWER_ON; + } + + if (LPC_SC->RSID & (1<<1)) { + return RESET_REASON_PIN_RESET; + } + if (LPC_SC->RSID & (1<<2)) { + return RESET_REASON_WATCHDOG; + } + + if (LPC_SC->RSID & (1<<3)) { + return RESET_REASON_BROWN_OUT; + } + if (LPC_SC->RSID & (1<<4)) { + return RESET_REASON_SOFTWARE; + } + + if (LPC_SC->RSID & (1<<5)) { + return RESET_REASON_LOCKUP; + } + + return RESET_REASON_UNKNOWN; +} + + +uint32_t hal_reset_reason_get_raw(void) +{ + + return LPC_SC->RSID; +} + + +void hal_reset_reason_clear(void) +{ + LPC_SC->RSID = 0xff; // Clear flags +} + +#endif // DEVICE_RESET_REASON diff --git a/targets/targets.json b/targets/targets.json index dcc4b5f010..ccf0617377 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -625,7 +625,8 @@ "FLASH", "MPU", "USBDEVICE", - "WATCHDOG" + "WATCHDOG", + "RESET_REASON" ], "release_versions": ["2", "5"], "device_name": "LPC1768",