Europalab Devices produces a LoRaWAN transmitting client node, specialised for higher research of actuator and sensor assisted IoT networks. https://dev.europalab.com/nlnet/20200000/
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

170 wiersze
5.1KB

  1. /**
  2. * \file
  3. *
  4. * \brief SAM TC - Timer Counter Callback Driver
  5. *
  6. * Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
  7. *
  8. * \asf_license_start
  9. *
  10. * \page License
  11. *
  12. * Subject to your compliance with these terms, you may use Microchip
  13. * software and any derivatives exclusively with Microchip products.
  14. * It is your responsibility to comply with third party license terms applicable
  15. * to your use of third party software (including open source software) that
  16. * may accompany Microchip software.
  17. *
  18. * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
  19. * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
  20. * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
  21. * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
  22. * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
  23. * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
  24. * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
  25. * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
  26. * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
  27. * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  28. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
  29. *
  30. * \asf_license_stop
  31. *
  32. */
  33. /*
  34. * Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
  35. */
  36. #ifndef TC_INTERRUPT_H_INCLUDED
  37. #define TC_INTERRUPT_H_INCLUDED
  38. #include "tc.h"
  39. #include <system_interrupt.h>
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. #if !defined(__DOXYGEN__)
  44. extern void *_tc_instances[TC_INST_NUM];
  45. # define _TC_INTERRUPT_VECT_NUM(n, unused) \
  46. SYSTEM_INTERRUPT_MODULE_TC##n,
  47. /**
  48. * \internal Get the interrupt vector for the given device instance
  49. *
  50. * \param[in] TC module instance number
  51. *
  52. * \return Interrupt vector for of the given TC module instance.
  53. */
  54. static enum system_interrupt_vector _tc_interrupt_get_interrupt_vector(
  55. uint32_t inst_num)
  56. {
  57. static uint8_t tc_interrupt_vectors[TC_INST_NUM] =
  58. {
  59. #if (SAML21E) || (SAML21G) || (SAMR30E) || (SAMR30G)
  60. SYSTEM_INTERRUPT_MODULE_TC0,
  61. SYSTEM_INTERRUPT_MODULE_TC1,
  62. SYSTEM_INTERRUPT_MODULE_TC4
  63. #else
  64. MRECURSION(TC_INST_NUM, _TC_INTERRUPT_VECT_NUM, TC_INST_MAX_ID)
  65. #endif
  66. };
  67. return (enum system_interrupt_vector)tc_interrupt_vectors[inst_num];
  68. }
  69. #endif /* !defined(__DOXYGEN__) */
  70. /**
  71. * \name Callback Management
  72. * {@
  73. */
  74. enum status_code tc_register_callback(
  75. struct tc_module *const module,
  76. tc_callback_t callback_func,
  77. const enum tc_callback callback_type);
  78. enum status_code tc_unregister_callback(
  79. struct tc_module *const module,
  80. const enum tc_callback callback_type);
  81. /**
  82. * \brief Enables callback.
  83. *
  84. * Enables the callback function registered by the \ref
  85. * tc_register_callback. The callback function will be called from the
  86. * interrupt handler when the conditions for the callback type are
  87. * met. This function will also enable the appropriate interrupts.
  88. *
  89. * \param[in] module Pointer to TC software instance struct
  90. * \param[in] callback_type Callback type given by an enum
  91. */
  92. static inline void tc_enable_callback(
  93. struct tc_module *const module,
  94. const enum tc_callback callback_type)
  95. {
  96. /* Sanity check arguments */
  97. Assert(module);
  98. /* Enable interrupts for this TC module */
  99. system_interrupt_enable(_tc_interrupt_get_interrupt_vector(_tc_get_inst_index(module->hw)));
  100. /* Enable callback */
  101. if (callback_type == TC_CALLBACK_CC_CHANNEL0) {
  102. module->enable_callback_mask |= TC_INTFLAG_MC(1);
  103. module->hw->COUNT8.INTENSET.reg = TC_INTFLAG_MC(1);
  104. }
  105. else if (callback_type == TC_CALLBACK_CC_CHANNEL1) {
  106. module->enable_callback_mask |= TC_INTFLAG_MC(2);
  107. module->hw->COUNT8.INTENSET.reg = TC_INTFLAG_MC(2);
  108. }
  109. else {
  110. module->enable_callback_mask |= (1 << callback_type);
  111. module->hw->COUNT8.INTENSET.reg = (1 << callback_type);
  112. }
  113. }
  114. /**
  115. * \brief Disables callback.
  116. *
  117. * Disables the callback function registered by the \ref
  118. * tc_register_callback, and the callback will not be called from the
  119. * interrupt routine. The function will also disable the appropriate
  120. * interrupts.
  121. *
  122. * \param[in] module Pointer to TC software instance struct
  123. * \param[in] callback_type Callback type given by an enum
  124. */
  125. static inline void tc_disable_callback(
  126. struct tc_module *const module,
  127. const enum tc_callback callback_type){
  128. /* Sanity check arguments */
  129. Assert(module);
  130. /* Disable callback */
  131. if (callback_type == TC_CALLBACK_CC_CHANNEL0) {
  132. module->hw->COUNT8.INTENCLR.reg = TC_INTFLAG_MC(1);
  133. module->enable_callback_mask &= ~TC_INTFLAG_MC(1);
  134. }
  135. else if (callback_type == TC_CALLBACK_CC_CHANNEL1) {
  136. module->hw->COUNT8.INTENCLR.reg = TC_INTFLAG_MC(2);
  137. module->enable_callback_mask &= ~TC_INTFLAG_MC(2);
  138. }
  139. else {
  140. module->hw->COUNT8.INTENCLR.reg = (1 << callback_type);
  141. module->enable_callback_mask &= ~(1 << callback_type);
  142. }
  143. }
  144. /**
  145. * @}
  146. */
  147. #ifdef __cplusplus
  148. }
  149. #endif
  150. #endif /* TC_INTERRUPT_H_INCLUDED */