nrf_sdh_soc.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * Copyright (c) 2017 - 2019, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #include "sdk_common.h"
  41. #if NRF_MODULE_ENABLED(NRF_SDH_SOC)
  42. #include "nrf_sdh_soc.h"
  43. #include "nrf_sdh.h"
  44. #include "nrf_soc.h"
  45. #include "app_error.h"
  46. #define NRF_LOG_MODULE_NAME nrf_sdh_soc
  47. #if NRF_SDH_SOC_LOG_ENABLED
  48. #define NRF_LOG_LEVEL NRF_SDH_SOC_LOG_LEVEL
  49. #define NRF_LOG_INFO_COLOR NRF_SDH_SOC_INFO_COLOR
  50. #define NRF_LOG_DEBUG_COLOR NRF_SDH_SOC_DEBUG_COLOR
  51. #else
  52. #define NRF_LOG_LEVEL 0
  53. #endif // NRF_SDH_SOC_LOG_ENABLED
  54. #include "nrf_log.h"
  55. NRF_LOG_MODULE_REGISTER();
  56. // Create section set "sdh_soc_observers".
  57. NRF_SECTION_SET_DEF(sdh_soc_observers, nrf_sdh_soc_evt_observer_t, NRF_SDH_SOC_OBSERVER_PRIO_LEVELS);
  58. /**@brief Function for polling SoC events.
  59. *
  60. * @param[in] p_context Context of the observer.
  61. */
  62. static void nrf_sdh_soc_evts_poll(void * p_context)
  63. {
  64. ret_code_t ret_code;
  65. UNUSED_VARIABLE(p_context);
  66. while (true)
  67. {
  68. uint32_t evt_id;
  69. ret_code = sd_evt_get(&evt_id);
  70. if (ret_code != NRF_SUCCESS)
  71. {
  72. break;
  73. }
  74. NRF_LOG_DEBUG("SoC event: 0x%x.", evt_id);
  75. // Forward the event to SoC observers.
  76. nrf_section_iter_t iter;
  77. for (nrf_section_iter_init(&iter, &sdh_soc_observers);
  78. nrf_section_iter_get(&iter) != NULL;
  79. nrf_section_iter_next(&iter))
  80. {
  81. nrf_sdh_soc_evt_observer_t * p_observer;
  82. nrf_sdh_soc_evt_handler_t handler;
  83. p_observer = (nrf_sdh_soc_evt_observer_t *) nrf_section_iter_get(&iter);
  84. handler = p_observer->handler;
  85. handler(evt_id, p_observer->p_context);
  86. }
  87. }
  88. if (ret_code != NRF_ERROR_NOT_FOUND)
  89. {
  90. APP_ERROR_HANDLER(ret_code);
  91. }
  92. }
  93. NRF_SDH_STACK_OBSERVER(m_nrf_sdh_soc_evts_poll, NRF_SDH_SOC_STACK_OBSERVER_PRIO) =
  94. {
  95. .handler = nrf_sdh_soc_evts_poll,
  96. .p_context = NULL,
  97. };
  98. #endif // NRF_MODULE_ENABLED(NRF_SDH_SOC)