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