|
| 1 | +/* |
| 2 | + * Copyright (c) 2020 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +#include <hal/nrf_clock.h> |
| 8 | +#if defined(NRF_UARTE0) || defined(NRF_UARTE1) |
| 9 | + #include <hal/nrf_uarte.h> |
| 10 | +#endif |
| 11 | +#if defined(NRF_RTC0) || defined(NRF_RTC1) || defined(NRF_RTC2) |
| 12 | + #include <hal/nrf_rtc.h> |
| 13 | +#endif |
| 14 | +#if defined(NRF_PPI) |
| 15 | + #include <hal/nrf_ppi.h> |
| 16 | +#endif |
| 17 | +#if defined(NRF_DPPIC) |
| 18 | + #include <hal/nrf_dppi.h> |
| 19 | +#endif |
| 20 | + |
| 21 | +#include <string.h> |
| 22 | + |
| 23 | +#define NRF_UARTE_SUBSCRIBE_CONF_OFFS offsetof(NRF_UARTE_Type, SUBSCRIBE_STARTRX) |
| 24 | +#define NRF_UARTE_SUBSCRIBE_CONF_SIZE (offsetof(NRF_UARTE_Type, EVENTS_CTS) -\ |
| 25 | + NRF_UARTE_SUBSCRIBE_CONF_OFFS) |
| 26 | + |
| 27 | +#define NRF_UARTE_PUBLISH_CONF_OFFS offsetof(NRF_UARTE_Type, PUBLISH_CTS) |
| 28 | +#define NRF_UARTE_PUBLISH_CONF_SIZE (offsetof(NRF_UARTE_Type, SHORTS) -\ |
| 29 | + NRF_UARTE_PUBLISH_CONF_OFFS) |
| 30 | + |
| 31 | +#if defined(NRF_RTC0) || defined(NRF_RTC1) || defined(NRF_RTC2) |
| 32 | +static inline void nrf_cleanup_rtc(NRF_RTC_Type * rtc_reg) |
| 33 | +{ |
| 34 | + nrf_rtc_task_trigger(rtc_reg, NRF_RTC_TASK_STOP); |
| 35 | + nrf_rtc_event_disable(rtc_reg, 0xFFFFFFFF); |
| 36 | + nrf_rtc_int_disable(rtc_reg, 0xFFFFFFFF); |
| 37 | +} |
| 38 | +#endif |
| 39 | + |
| 40 | +static void nrf_cleanup_clock(void) |
| 41 | +{ |
| 42 | + nrf_clock_int_disable(NRF_CLOCK, 0xFFFFFFFF); |
| 43 | +} |
| 44 | + |
| 45 | +void nrf_cleanup_peripheral(void) |
| 46 | +{ |
| 47 | +#if defined(NRF_RTC0) |
| 48 | + nrf_cleanup_rtc(NRF_RTC0); |
| 49 | +#endif |
| 50 | +#if defined(NRF_RTC1) |
| 51 | + nrf_cleanup_rtc(NRF_RTC1); |
| 52 | +#endif |
| 53 | +#if defined(NRF_RTC2) |
| 54 | + nrf_cleanup_rtc(NRF_RTC2); |
| 55 | +#endif |
| 56 | +#if defined(NRF_UARTE0) |
| 57 | + nrf_uarte_disable(NRF_UARTE0); |
| 58 | + nrf_uarte_int_disable(NRF_UARTE0, 0xFFFFFFFF); |
| 59 | +#if defined(NRF_DPPIC) |
| 60 | + /* Clear all SUBSCRIBE configurations. */ |
| 61 | + memset((uint8_t *)NRF_UARTE0 + NRF_UARTE_SUBSCRIBE_CONF_OFFS, 0, NRF_UARTE_SUBSCRIBE_CONF_SIZE); |
| 62 | + /* Clear all PUBLISH configurations. */ |
| 63 | + memset((uint8_t *)NRF_UARTE0 + NRF_UARTE_PUBLISH_CONF_OFFS, 0, NRF_UARTE_PUBLISH_CONF_SIZE); |
| 64 | +#endif |
| 65 | +#endif |
| 66 | +#if defined(NRF_UARTE1) |
| 67 | + nrf_uarte_disable(NRF_UARTE1); |
| 68 | + nrf_uarte_int_disable(NRF_UARTE1, 0xFFFFFFFF); |
| 69 | +#if defined(NRF_DPPIC) |
| 70 | + /* Clear all SUBSCRIBE configurations. */ |
| 71 | + memset((uint8_t *)NRF_UARTE1 + NRF_UARTE_SUBSCRIBE_CONF_OFFS, 0, NRF_UARTE_SUBSCRIBE_CONF_SIZE); |
| 72 | + /* Clear all PUBLISH configurations. */ |
| 73 | + memset((uint8_t *)NRF_UARTE1 + NRF_UARTE_PUBLISH_CONF_OFFS, 0, NRF_UARTE_PUBLISH_CONF_SIZE); |
| 74 | +#endif |
| 75 | +#endif |
| 76 | +#if defined(NRF_PPI) |
| 77 | + nrf_ppi_channels_disable_all(NRF_PPI); |
| 78 | +#endif |
| 79 | +#if defined(NRF_DPPIC) |
| 80 | + nrf_dppi_channels_disable_all(NRF_DPPIC); |
| 81 | +#endif |
| 82 | + nrf_cleanup_clock(); |
| 83 | +} |
0 commit comments