mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Jul 17 09:15:10 2015 +0100
Revision:
592:a274ee790e56
Parent:
579:53297373a894
Synchronized with git revision e7144f83a8d75df80c4877936b6ffe552b0be9e6

Full URL: https://github.com/mbedmicro/mbed/commit/e7144f83a8d75df80c4877936b6ffe552b0be9e6/

More API implementation for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 579:53297373a894 1 #ifndef TC_INTERRUPT_H_INCLUDED
mbed_official 579:53297373a894 2 #define TC_INTERRUPT_H_INCLUDED
mbed_official 579:53297373a894 3
mbed_official 579:53297373a894 4 #include "tc.h"
mbed_official 579:53297373a894 5 #include <system_interrupt.h>
mbed_official 579:53297373a894 6
mbed_official 579:53297373a894 7 #ifdef __cplusplus
mbed_official 579:53297373a894 8 extern "C" {
mbed_official 579:53297373a894 9 #endif
mbed_official 579:53297373a894 10
mbed_official 579:53297373a894 11 #if !defined(__DOXYGEN__)
mbed_official 579:53297373a894 12 extern void *_tc_instances[TC_INST_NUM];
mbed_official 579:53297373a894 13
mbed_official 579:53297373a894 14 # define _TC_INTERRUPT_VECT_NUM(n, unused) \
mbed_official 579:53297373a894 15 SYSTEM_INTERRUPT_MODULE_TC##n,
mbed_official 579:53297373a894 16 /**
mbed_official 579:53297373a894 17 * \internal Get the interrupt vector for the given device instance
mbed_official 579:53297373a894 18 *
mbed_official 579:53297373a894 19 * \param[in] TC module instance number.
mbed_official 579:53297373a894 20 *
mbed_official 579:53297373a894 21 * \return Interrupt vector for of the given TC module instance.
mbed_official 579:53297373a894 22 */
mbed_official 579:53297373a894 23 static enum system_interrupt_vector _tc_interrupt_get_interrupt_vector(
mbed_official 579:53297373a894 24 uint32_t inst_num)
mbed_official 579:53297373a894 25 {
mbed_official 579:53297373a894 26 static uint8_t tc_interrupt_vectors[TC_INST_NUM] = {
mbed_official 579:53297373a894 27 #if (SAML21E) || (SAML21G)
mbed_official 579:53297373a894 28 SYSTEM_INTERRUPT_MODULE_TC0,
mbed_official 579:53297373a894 29 SYSTEM_INTERRUPT_MODULE_TC1,
mbed_official 579:53297373a894 30 SYSTEM_INTERRUPT_MODULE_TC4
mbed_official 579:53297373a894 31 #else
mbed_official 579:53297373a894 32 MRECURSION(TC_INST_NUM, _TC_INTERRUPT_VECT_NUM, TC_INST_MAX_ID)
mbed_official 579:53297373a894 33 #endif
mbed_official 579:53297373a894 34 };
mbed_official 579:53297373a894 35
mbed_official 579:53297373a894 36 return (enum system_interrupt_vector)tc_interrupt_vectors[inst_num];
mbed_official 579:53297373a894 37 }
mbed_official 579:53297373a894 38 #endif /* !defined(__DOXYGEN__) */
mbed_official 579:53297373a894 39
mbed_official 579:53297373a894 40 /**
mbed_official 579:53297373a894 41 * \name Callback Management
mbed_official 579:53297373a894 42 * {@
mbed_official 579:53297373a894 43 */
mbed_official 579:53297373a894 44
mbed_official 579:53297373a894 45 enum status_code tc_register_callback(
mbed_official 579:53297373a894 46 struct tc_module *const module,
mbed_official 579:53297373a894 47 tc_callback_t callback_func,
mbed_official 579:53297373a894 48 const enum tc_callback callback_type);
mbed_official 579:53297373a894 49
mbed_official 579:53297373a894 50 enum status_code tc_unregister_callback(
mbed_official 579:53297373a894 51 struct tc_module *const module,
mbed_official 579:53297373a894 52 const enum tc_callback callback_type);
mbed_official 579:53297373a894 53
mbed_official 579:53297373a894 54 /**
mbed_official 579:53297373a894 55 * \brief Enables callback.
mbed_official 579:53297373a894 56 *
mbed_official 579:53297373a894 57 * Enables the callback function registered by the \ref
mbed_official 579:53297373a894 58 * tc_register_callback. The callback function will be called from the
mbed_official 579:53297373a894 59 * interrupt handler when the conditions for the callback type are
mbed_official 579:53297373a894 60 * met. This function will also enable the appropriate interrupts.
mbed_official 579:53297373a894 61 *
mbed_official 579:53297373a894 62 * \param[in] module Pointer to TC software instance struct
mbed_official 579:53297373a894 63 * \param[in] callback_type Callback type given by an enum
mbed_official 579:53297373a894 64 */
mbed_official 579:53297373a894 65 static inline void tc_enable_callback(
mbed_official 579:53297373a894 66 struct tc_module *const module,
mbed_official 579:53297373a894 67 const enum tc_callback callback_type)
mbed_official 579:53297373a894 68 {
mbed_official 579:53297373a894 69 /* Sanity check arguments */
mbed_official 579:53297373a894 70 Assert(module);
mbed_official 579:53297373a894 71
mbed_official 579:53297373a894 72
mbed_official 579:53297373a894 73 /* Enable interrupts for this TC module */
mbed_official 579:53297373a894 74 system_interrupt_enable(_tc_interrupt_get_interrupt_vector(_tc_get_inst_index(module->hw)));
mbed_official 579:53297373a894 75
mbed_official 579:53297373a894 76 /* Enable callback */
mbed_official 579:53297373a894 77 if (callback_type == TC_CALLBACK_CC_CHANNEL0) {
mbed_official 579:53297373a894 78 module->enable_callback_mask |= TC_INTFLAG_MC(1);
mbed_official 579:53297373a894 79 module->hw->COUNT8.INTENSET.reg = TC_INTFLAG_MC(1);
mbed_official 579:53297373a894 80 } else if (callback_type == TC_CALLBACK_CC_CHANNEL1) {
mbed_official 579:53297373a894 81 module->enable_callback_mask |= TC_INTFLAG_MC(2);
mbed_official 579:53297373a894 82 module->hw->COUNT8.INTENSET.reg = TC_INTFLAG_MC(2);
mbed_official 579:53297373a894 83 } else {
mbed_official 579:53297373a894 84 module->enable_callback_mask |= (1 << callback_type);
mbed_official 579:53297373a894 85 module->hw->COUNT8.INTENSET.reg = (1 << callback_type);
mbed_official 579:53297373a894 86 }
mbed_official 579:53297373a894 87 }
mbed_official 579:53297373a894 88
mbed_official 579:53297373a894 89 /**
mbed_official 579:53297373a894 90 * \brief Disables callback.
mbed_official 579:53297373a894 91 *
mbed_official 579:53297373a894 92 * Disables the callback function registered by the \ref
mbed_official 579:53297373a894 93 * tc_register_callback, and the callback will not be called from the
mbed_official 579:53297373a894 94 * interrupt routine. The function will also disable the appropriate
mbed_official 579:53297373a894 95 * interrupts.
mbed_official 579:53297373a894 96 *
mbed_official 579:53297373a894 97 * \param[in] module Pointer to TC software instance struct
mbed_official 579:53297373a894 98 * \param[in] callback_type Callback type given by an enum
mbed_official 579:53297373a894 99 */
mbed_official 579:53297373a894 100 static inline void tc_disable_callback(
mbed_official 579:53297373a894 101 struct tc_module *const module,
mbed_official 579:53297373a894 102 const enum tc_callback callback_type)
mbed_official 579:53297373a894 103 {
mbed_official 579:53297373a894 104 /* Sanity check arguments */
mbed_official 579:53297373a894 105 Assert(module);
mbed_official 579:53297373a894 106
mbed_official 579:53297373a894 107 /* Disable callback */
mbed_official 579:53297373a894 108 if (callback_type == TC_CALLBACK_CC_CHANNEL0) {
mbed_official 579:53297373a894 109 module->hw->COUNT8.INTENCLR.reg = TC_INTFLAG_MC(1);
mbed_official 579:53297373a894 110 module->enable_callback_mask &= ~TC_INTFLAG_MC(1);
mbed_official 579:53297373a894 111 } else if (callback_type == TC_CALLBACK_CC_CHANNEL1) {
mbed_official 579:53297373a894 112 module->hw->COUNT8.INTENCLR.reg = TC_INTFLAG_MC(2);
mbed_official 579:53297373a894 113 module->enable_callback_mask &= ~TC_INTFLAG_MC(2);
mbed_official 579:53297373a894 114 } else {
mbed_official 579:53297373a894 115 module->hw->COUNT8.INTENCLR.reg = (1 << callback_type);
mbed_official 579:53297373a894 116 module->enable_callback_mask &= ~(1 << callback_type);
mbed_official 579:53297373a894 117 }
mbed_official 579:53297373a894 118 }
mbed_official 579:53297373a894 119
mbed_official 579:53297373a894 120 /**
mbed_official 579:53297373a894 121 * @}
mbed_official 579:53297373a894 122 */
mbed_official 579:53297373a894 123
mbed_official 579:53297373a894 124 #ifdef __cplusplus
mbed_official 579:53297373a894 125 }
mbed_official 579:53297373a894 126 #endif
mbed_official 579:53297373a894 127
mbed_official 579:53297373a894 128 #endif /* TC_INTERRUPT_H_INCLUDED */