1 /* 2 * Copyright (c) 2012-2014 Wind River Systems, Inc. 3 * Copyright (c) 2020 Arm Limited 4 * Copyright (c) 2021-2023 Nordic Semiconductor ASA 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #ifndef H_IO_ 20 #define H_IO_ 21 22 #include <stddef.h> 23 24 #ifdef CONFIG_SOC_FAMILY_NORDIC_NRF 25 #include <helpers/nrfx_reset_reason.h> 26 #endif 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 /* 33 * Initialises the configured LED. 34 */ 35 void io_led_init(void); 36 37 /* 38 * Sets value of the configured LED. 39 */ 40 void io_led_set(int value); 41 42 /* 43 * Checks if GPIO is set in the required way to remain in serial recovery mode 44 * 45 * @retval false for normal boot, true for serial recovery boot 46 */ 47 bool io_detect_pin(void); 48 49 /* 50 * Checks if board was reset using reset pin and if device should stay in 51 * serial recovery mode 52 * 53 * @retval false for normal boot, true for serial recovery boot 54 */ 55 bool io_detect_pin_reset(void); 56 57 /* 58 * Checks board boot mode via retention subsystem and if device should stay in 59 * serial recovery mode 60 * 61 * @retval false for normal boot, true for serial recovery boot 62 */ 63 bool io_detect_boot_mode(void); 64 65 #ifdef CONFIG_SOC_FAMILY_NORDIC_NRF io_boot_skip_serial_recovery()66static inline bool io_boot_skip_serial_recovery() 67 { 68 uint32_t rr = nrfx_reset_reason_get(); 69 70 return !(rr == 0 || (rr & NRFX_RESET_REASON_RESETPIN_MASK)); 71 } 72 #else io_boot_skip_serial_recovery()73static inline bool io_boot_skip_serial_recovery() 74 { 75 return false; 76 } 77 #endif 78 79 #ifdef __cplusplus 80 } 81 #endif 82 83 #endif 84