freqm_callback.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief SAM Frequency Meter driver.
  6. *
  7. * This file defines a useful set of functions for the FREQM on SAM devices.
  8. *
  9. * Copyright (c) 2015 Atmel Corporation. All rights reserved.
  10. *
  11. * \asf_license_start
  12. *
  13. * \page License
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are met:
  17. *
  18. * 1. Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. *
  21. * 2. Redistributions in binary form must reproduce the above copyright notice,
  22. * this list of conditions and the following disclaimer in the documentation
  23. * and/or other materials provided with the distribution.
  24. *
  25. * 3. The name of Atmel may not be used to endorse or promote products derived
  26. * from this software without specific prior written permission.
  27. *
  28. * 4. This software may only be redistributed and used in connection with an
  29. * Atmel microcontroller product.
  30. *
  31. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  32. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  33. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  34. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  35. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  40. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGE.
  42. *
  43. * \asf_license_stop
  44. *
  45. */
  46. /*
  47. * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
  48. */
  49. #ifndef FREQM_CALLBACK_H_INCLUDED
  50. #define FREQM_CALLBACK_H_INCLUDED
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54. #include <compiler.h>
  55. #include <system_interrupt.h>
  56. /**
  57. * \addtogroup asfdoc_sam0_freqm_group
  58. *
  59. * @{
  60. */
  61. /** FREQM callback type. */
  62. enum freqm_callback_type {
  63. /** Measurement done callback.*/
  64. FREQM_CALLBACK_MEASURE_DONE = 0,
  65. };
  66. /** \name Callback Configuration and Initialization
  67. * @{
  68. */
  69. enum status_code freqm_register_callback(
  70. struct freqm_module *const module,
  71. freqm_callback_t callback_func,
  72. enum freqm_callback callback_type);
  73. enum status_code freqm_unregister_callback(
  74. struct freqm_module *module,
  75. enum freqm_callback callback_type);
  76. /** @} */
  77. /** \name Callback Enabling and Disabling
  78. * @{
  79. */
  80. /**
  81. * \brief Enable an FREQM callback.
  82. *
  83. * \param[in,out] module Pointer to the software instance struct
  84. * \param[in] type Callback source type
  85. *
  86. * \return Status of the callback enable operation.
  87. * \retval STATUS_OK The callback was enabled successfully
  88. * \retval STATUS_ERR_INVALID_ARG If an invalid callback type was supplied
  89. */
  90. static inline enum status_code freqm_enable_callback(struct freqm_module *const module,
  91. const enum freqm_callback_type type)
  92. {
  93. /* Sanity check arguments */
  94. Assert(module);
  95. if (type == FREQM_CALLBACK_MEASURE_DONE){
  96. module->hw->INTENSET.reg = FREQM_INTENSET_DONE;
  97. } else {
  98. Assert(false);
  99. return STATUS_ERR_INVALID_ARG;
  100. }
  101. system_interrupt_enable(SYSTEM_INTERRUPT_MODULE_FREQM);
  102. return STATUS_OK;
  103. }
  104. /**
  105. * \brief Disable an FREQM callback.
  106. *
  107. * \param[in,out] module Pointer to the software instance struct
  108. * \param[in] type Callback source type
  109. *
  110. * \return Status of the callback enable operation.
  111. * \retval STATUS_OK The callback was enabled successfully
  112. * \retval STATUS_ERR_INVALID_ARG If an invalid callback type was supplied
  113. */
  114. static inline enum status_code freqm_disable_callback(struct freqm_module *const module,
  115. const enum freqm_callback_type type)
  116. {
  117. /* Sanity check arguments */
  118. Assert(module);
  119. if (type == FREQM_CALLBACK_MEASURE_DONE){
  120. module->hw->INTENCLR.reg = FREQM_INTENCLR_DONE;
  121. } else {
  122. Assert(false);
  123. return STATUS_ERR_INVALID_ARG;
  124. }
  125. system_interrupt_disable(SYSTEM_INTERRUPT_MODULE_FREQM);
  126. return STATUS_OK;
  127. }
  128. /** @} */
  129. /** @} */
  130. #ifdef __cplusplus
  131. }
  132. #endif
  133. #endif /* FREQM_CALLBACK_H_INCLUDED */