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 #include "tc_interrupt.h"
mbed_official 579:53297373a894 2
mbed_official 579:53297373a894 3 void *_tc_instances[TC_INST_NUM];
mbed_official 579:53297373a894 4
mbed_official 579:53297373a894 5 void _tc_interrupt_handler(uint8_t instance);
mbed_official 579:53297373a894 6
mbed_official 579:53297373a894 7 /**
mbed_official 579:53297373a894 8 * \brief Registers a callback.
mbed_official 579:53297373a894 9 *
mbed_official 579:53297373a894 10 * Registers a callback function which is implemented by the user.
mbed_official 579:53297373a894 11 *
mbed_official 579:53297373a894 12 * \note The callback must be enabled by \ref tc_enable_callback,
mbed_official 579:53297373a894 13 * in order for the interrupt handler to call it when the conditions for the
mbed_official 579:53297373a894 14 * callback type is met.
mbed_official 579:53297373a894 15 *
mbed_official 579:53297373a894 16 * \param[in] module Pointer to TC software instance struct
mbed_official 579:53297373a894 17 * \param[in] callback_func Pointer to callback function
mbed_official 579:53297373a894 18 * \param[in] callback_type Callback type given by an enum
mbed_official 579:53297373a894 19 */
mbed_official 579:53297373a894 20 enum status_code tc_register_callback(
mbed_official 579:53297373a894 21 struct tc_module *const module,
mbed_official 579:53297373a894 22 tc_callback_t callback_func,
mbed_official 579:53297373a894 23 const enum tc_callback callback_type)
mbed_official 579:53297373a894 24 {
mbed_official 579:53297373a894 25 /* Sanity check arguments */
mbed_official 579:53297373a894 26 Assert(module);
mbed_official 579:53297373a894 27 Assert(callback_func);
mbed_official 579:53297373a894 28
mbed_official 579:53297373a894 29 /* Register callback function */
mbed_official 579:53297373a894 30 module->callback[callback_type] = callback_func;
mbed_official 579:53297373a894 31
mbed_official 579:53297373a894 32 /* Set the bit corresponding to the callback_type */
mbed_official 579:53297373a894 33 if (callback_type == TC_CALLBACK_CC_CHANNEL0) {
mbed_official 579:53297373a894 34 module->register_callback_mask |= TC_INTFLAG_MC(1);
mbed_official 579:53297373a894 35 } else if (callback_type == TC_CALLBACK_CC_CHANNEL1) {
mbed_official 579:53297373a894 36 module->register_callback_mask |= TC_INTFLAG_MC(2);
mbed_official 579:53297373a894 37 } else {
mbed_official 579:53297373a894 38 module->register_callback_mask |= (1 << callback_type);
mbed_official 579:53297373a894 39 }
mbed_official 579:53297373a894 40 return STATUS_OK;
mbed_official 579:53297373a894 41 }
mbed_official 579:53297373a894 42
mbed_official 579:53297373a894 43 /**
mbed_official 579:53297373a894 44 * \brief Unregisters a callback.
mbed_official 579:53297373a894 45 *
mbed_official 579:53297373a894 46 * Unregisters a callback function implemented by the user. The callback should be
mbed_official 579:53297373a894 47 * disabled before it is unregistered.
mbed_official 579:53297373a894 48 *
mbed_official 579:53297373a894 49 * \param[in] module Pointer to TC software instance struct
mbed_official 579:53297373a894 50 * \param[in] callback_type Callback type given by an enum
mbed_official 579:53297373a894 51 */
mbed_official 579:53297373a894 52 enum status_code tc_unregister_callback(
mbed_official 579:53297373a894 53 struct tc_module *const module,
mbed_official 579:53297373a894 54 const enum tc_callback callback_type)
mbed_official 579:53297373a894 55 {
mbed_official 579:53297373a894 56 /* Sanity check arguments */
mbed_official 579:53297373a894 57 Assert(module);
mbed_official 579:53297373a894 58
mbed_official 579:53297373a894 59 /* Unregister callback function */
mbed_official 579:53297373a894 60 module->callback[callback_type] = NULL;
mbed_official 579:53297373a894 61
mbed_official 579:53297373a894 62 /* Clear the bit corresponding to the callback_type */
mbed_official 579:53297373a894 63 if (callback_type == TC_CALLBACK_CC_CHANNEL0) {
mbed_official 579:53297373a894 64 module->register_callback_mask &= ~TC_INTFLAG_MC(1);
mbed_official 579:53297373a894 65 } else if (callback_type == TC_CALLBACK_CC_CHANNEL1) {
mbed_official 579:53297373a894 66 module->register_callback_mask &= ~TC_INTFLAG_MC(2);
mbed_official 579:53297373a894 67 } else {
mbed_official 579:53297373a894 68 module->register_callback_mask &= ~(1 << callback_type);
mbed_official 579:53297373a894 69 }
mbed_official 579:53297373a894 70 return STATUS_OK;
mbed_official 579:53297373a894 71 }
mbed_official 579:53297373a894 72
mbed_official 579:53297373a894 73 /**
mbed_official 579:53297373a894 74 * \internal ISR handler for TC
mbed_official 579:53297373a894 75 *
mbed_official 579:53297373a894 76 * Auto-generate a set of interrupt handlers for each TC in the device.
mbed_official 579:53297373a894 77 */
mbed_official 579:53297373a894 78 #define _TC_INTERRUPT_HANDLER(n, m) \
mbed_official 579:53297373a894 79 void TC##n##_Handler(void) \
mbed_official 579:53297373a894 80 { \
mbed_official 579:53297373a894 81 _tc_interrupt_handler(m); \
mbed_official 579:53297373a894 82 }
mbed_official 579:53297373a894 83
mbed_official 579:53297373a894 84 #if (SAML21E) || (SAML21G)
mbed_official 579:53297373a894 85 _TC_INTERRUPT_HANDLER(0,0)
mbed_official 579:53297373a894 86 _TC_INTERRUPT_HANDLER(1,1)
mbed_official 579:53297373a894 87 _TC_INTERRUPT_HANDLER(4,2)
mbed_official 579:53297373a894 88 #else
mbed_official 579:53297373a894 89 MRECURSION(TC_INST_NUM, _TC_INTERRUPT_HANDLER, TC_INST_MAX_ID)
mbed_official 579:53297373a894 90 #endif
mbed_official 579:53297373a894 91
mbed_official 579:53297373a894 92
mbed_official 579:53297373a894 93 /**
mbed_official 579:53297373a894 94 * \internal Interrupt Handler for TC module
mbed_official 579:53297373a894 95 *
mbed_official 579:53297373a894 96 * Handles interrupts as they occur, it will run the callback functions
mbed_official 579:53297373a894 97 * that are registered and enabled.
mbed_official 579:53297373a894 98 *
mbed_official 579:53297373a894 99 * \param[in] instance ID of the TC instance calling the interrupt
mbed_official 579:53297373a894 100 * handler.
mbed_official 579:53297373a894 101 */
mbed_official 579:53297373a894 102 void _tc_interrupt_handler(
mbed_official 579:53297373a894 103 uint8_t instance)
mbed_official 579:53297373a894 104 {
mbed_official 579:53297373a894 105 /* Temporary variable */
mbed_official 579:53297373a894 106 uint8_t interrupt_and_callback_status_mask;
mbed_official 579:53297373a894 107
mbed_official 579:53297373a894 108 /* Get device instance from the look-up table */
mbed_official 579:53297373a894 109 struct tc_module *module
mbed_official 579:53297373a894 110 = (struct tc_module *)_tc_instances[instance];
mbed_official 579:53297373a894 111
mbed_official 579:53297373a894 112 /* Read and mask interrupt flag register */
mbed_official 579:53297373a894 113 interrupt_and_callback_status_mask = module->hw->COUNT8.INTFLAG.reg &
mbed_official 579:53297373a894 114 module->register_callback_mask &
mbed_official 579:53297373a894 115 module->enable_callback_mask;
mbed_official 579:53297373a894 116
mbed_official 579:53297373a894 117 /* Check if an Overflow interrupt has occurred */
mbed_official 579:53297373a894 118 if (interrupt_and_callback_status_mask & TC_INTFLAG_OVF) {
mbed_official 579:53297373a894 119 /* Invoke registered and enabled callback function */
mbed_official 579:53297373a894 120 (module->callback[TC_CALLBACK_OVERFLOW])(module);
mbed_official 579:53297373a894 121 /* Clear interrupt flag */
mbed_official 579:53297373a894 122 module->hw->COUNT8.INTFLAG.reg = TC_INTFLAG_OVF;
mbed_official 579:53297373a894 123 }
mbed_official 579:53297373a894 124
mbed_official 579:53297373a894 125 /* Check if an Error interrupt has occurred */
mbed_official 579:53297373a894 126 if (interrupt_and_callback_status_mask & TC_INTFLAG_ERR) {
mbed_official 579:53297373a894 127 /* Invoke registered and enabled callback function */
mbed_official 579:53297373a894 128 (module->callback[TC_CALLBACK_ERROR])(module);
mbed_official 579:53297373a894 129 /* Clear interrupt flag */
mbed_official 579:53297373a894 130 module->hw->COUNT8.INTFLAG.reg = TC_INTFLAG_ERR;
mbed_official 579:53297373a894 131 }
mbed_official 579:53297373a894 132
mbed_official 579:53297373a894 133 /* Check if an Match/Capture Channel 0 interrupt has occurred */
mbed_official 579:53297373a894 134 if (interrupt_and_callback_status_mask & TC_INTFLAG_MC(1)) {
mbed_official 579:53297373a894 135 /* Invoke registered and enabled callback function */
mbed_official 579:53297373a894 136 (module->callback[TC_CALLBACK_CC_CHANNEL0])(module);
mbed_official 579:53297373a894 137 /* Clear interrupt flag */
mbed_official 579:53297373a894 138 module->hw->COUNT8.INTFLAG.reg = TC_INTFLAG_MC(1);
mbed_official 579:53297373a894 139 }
mbed_official 579:53297373a894 140
mbed_official 579:53297373a894 141 /* Check if an Match/Capture Channel 1 interrupt has occurred */
mbed_official 579:53297373a894 142 if (interrupt_and_callback_status_mask & TC_INTFLAG_MC(2)) {
mbed_official 579:53297373a894 143 /* Invoke registered and enabled callback function */
mbed_official 579:53297373a894 144 (module->callback[TC_CALLBACK_CC_CHANNEL1])(module);
mbed_official 579:53297373a894 145 /* Clear interrupt flag */
mbed_official 579:53297373a894 146 module->hw->COUNT8.INTFLAG.reg = TC_INTFLAG_MC(2);
mbed_official 579:53297373a894 147 }
mbed_official 579:53297373a894 148 }