t

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Oct 28 11:17:30 2016 +0100
Revision:
149:156823d33999
Parent:
targets/hal/TARGET_Atmel/TARGET_SAM_CortexM0P/drivers/tc/tc_interrupt.h@15:a81a8d6c1dfe
This updates the lib to the mbed lib v128

NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 15:a81a8d6c1dfe 1 /**
mbed_official 15:a81a8d6c1dfe 2 * \file
mbed_official 15:a81a8d6c1dfe 3 *
mbed_official 15:a81a8d6c1dfe 4 * \brief SAM TC - Timer Counter Callback Driver
mbed_official 15:a81a8d6c1dfe 5 *
mbed_official 15:a81a8d6c1dfe 6 * Copyright (C) 2013-2015 Atmel Corporation. All rights reserved.
mbed_official 15:a81a8d6c1dfe 7 *
mbed_official 15:a81a8d6c1dfe 8 * \asf_license_start
mbed_official 15:a81a8d6c1dfe 9 *
mbed_official 15:a81a8d6c1dfe 10 * \page License
mbed_official 15:a81a8d6c1dfe 11 *
mbed_official 15:a81a8d6c1dfe 12 * Redistribution and use in source and binary forms, with or without
mbed_official 15:a81a8d6c1dfe 13 * modification, are permitted provided that the following conditions are met:
mbed_official 15:a81a8d6c1dfe 14 *
mbed_official 15:a81a8d6c1dfe 15 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 15:a81a8d6c1dfe 16 * this list of conditions and the following disclaimer.
mbed_official 15:a81a8d6c1dfe 17 *
mbed_official 15:a81a8d6c1dfe 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 15:a81a8d6c1dfe 19 * this list of conditions and the following disclaimer in the documentation
mbed_official 15:a81a8d6c1dfe 20 * and/or other materials provided with the distribution.
mbed_official 15:a81a8d6c1dfe 21 *
mbed_official 15:a81a8d6c1dfe 22 * 3. The name of Atmel may not be used to endorse or promote products derived
mbed_official 15:a81a8d6c1dfe 23 * from this software without specific prior written permission.
mbed_official 15:a81a8d6c1dfe 24 *
mbed_official 15:a81a8d6c1dfe 25 * 4. This software may only be redistributed and used in connection with an
mbed_official 15:a81a8d6c1dfe 26 * Atmel microcontroller product.
mbed_official 15:a81a8d6c1dfe 27 *
mbed_official 15:a81a8d6c1dfe 28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
mbed_official 15:a81a8d6c1dfe 29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed_official 15:a81a8d6c1dfe 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
mbed_official 15:a81a8d6c1dfe 31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
mbed_official 15:a81a8d6c1dfe 32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 15:a81a8d6c1dfe 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
mbed_official 15:a81a8d6c1dfe 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
mbed_official 15:a81a8d6c1dfe 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
mbed_official 15:a81a8d6c1dfe 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 15:a81a8d6c1dfe 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 15:a81a8d6c1dfe 38 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 15:a81a8d6c1dfe 39 *
mbed_official 15:a81a8d6c1dfe 40 * \asf_license_stop
mbed_official 15:a81a8d6c1dfe 41 *
mbed_official 15:a81a8d6c1dfe 42 */
mbed_official 15:a81a8d6c1dfe 43
mbed_official 15:a81a8d6c1dfe 44 /*
mbed_official 15:a81a8d6c1dfe 45 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
mbed_official 15:a81a8d6c1dfe 46 */
mbed_official 15:a81a8d6c1dfe 47
mbed_official 15:a81a8d6c1dfe 48 #ifndef TC_INTERRUPT_H_INCLUDED
mbed_official 15:a81a8d6c1dfe 49 #define TC_INTERRUPT_H_INCLUDED
mbed_official 15:a81a8d6c1dfe 50
mbed_official 15:a81a8d6c1dfe 51 #include "tc.h"
mbed_official 15:a81a8d6c1dfe 52 #include <system_interrupt.h>
mbed_official 15:a81a8d6c1dfe 53
mbed_official 15:a81a8d6c1dfe 54 #ifdef __cplusplus
mbed_official 15:a81a8d6c1dfe 55 extern "C" {
mbed_official 15:a81a8d6c1dfe 56 #endif
mbed_official 15:a81a8d6c1dfe 57
mbed_official 15:a81a8d6c1dfe 58 #if !defined(__DOXYGEN__)
mbed_official 15:a81a8d6c1dfe 59 extern void *_tc_instances[TC_INST_NUM];
mbed_official 15:a81a8d6c1dfe 60
mbed_official 15:a81a8d6c1dfe 61 # define _TC_INTERRUPT_VECT_NUM(n, unused) \
mbed_official 15:a81a8d6c1dfe 62 SYSTEM_INTERRUPT_MODULE_TC##n,
mbed_official 15:a81a8d6c1dfe 63 /**
mbed_official 15:a81a8d6c1dfe 64 * \internal Get the interrupt vector for the given device instance
mbed_official 15:a81a8d6c1dfe 65 *
mbed_official 15:a81a8d6c1dfe 66 * \param[in] TC module instance number.
mbed_official 15:a81a8d6c1dfe 67 *
mbed_official 15:a81a8d6c1dfe 68 * \return Interrupt vector for of the given TC module instance.
mbed_official 15:a81a8d6c1dfe 69 */
mbed_official 15:a81a8d6c1dfe 70 static enum system_interrupt_vector _tc_interrupt_get_interrupt_vector(
mbed_official 15:a81a8d6c1dfe 71 uint32_t inst_num)
mbed_official 15:a81a8d6c1dfe 72 {
mbed_official 15:a81a8d6c1dfe 73 static uint8_t tc_interrupt_vectors[TC_INST_NUM] = {
mbed_official 15:a81a8d6c1dfe 74 #if (SAML21E) || (SAML21G)
mbed_official 15:a81a8d6c1dfe 75 SYSTEM_INTERRUPT_MODULE_TC0,
mbed_official 15:a81a8d6c1dfe 76 SYSTEM_INTERRUPT_MODULE_TC1,
mbed_official 15:a81a8d6c1dfe 77 SYSTEM_INTERRUPT_MODULE_TC4
mbed_official 15:a81a8d6c1dfe 78 #else
mbed_official 15:a81a8d6c1dfe 79 MRECURSION(TC_INST_NUM, _TC_INTERRUPT_VECT_NUM, TC_INST_MAX_ID)
mbed_official 15:a81a8d6c1dfe 80 #endif
mbed_official 15:a81a8d6c1dfe 81 };
mbed_official 15:a81a8d6c1dfe 82
mbed_official 15:a81a8d6c1dfe 83 return (enum system_interrupt_vector)tc_interrupt_vectors[inst_num];
mbed_official 15:a81a8d6c1dfe 84 }
mbed_official 15:a81a8d6c1dfe 85 #endif /* !defined(__DOXYGEN__) */
mbed_official 15:a81a8d6c1dfe 86
mbed_official 15:a81a8d6c1dfe 87 /**
mbed_official 15:a81a8d6c1dfe 88 * \name Callback Management
mbed_official 15:a81a8d6c1dfe 89 * {@
mbed_official 15:a81a8d6c1dfe 90 */
mbed_official 15:a81a8d6c1dfe 91
mbed_official 15:a81a8d6c1dfe 92 enum status_code tc_register_callback(
mbed_official 15:a81a8d6c1dfe 93 struct tc_module *const module,
mbed_official 15:a81a8d6c1dfe 94 tc_callback_t callback_func,
mbed_official 15:a81a8d6c1dfe 95 const enum tc_callback callback_type);
mbed_official 15:a81a8d6c1dfe 96
mbed_official 15:a81a8d6c1dfe 97 enum status_code tc_unregister_callback(
mbed_official 15:a81a8d6c1dfe 98 struct tc_module *const module,
mbed_official 15:a81a8d6c1dfe 99 const enum tc_callback callback_type);
mbed_official 15:a81a8d6c1dfe 100
mbed_official 15:a81a8d6c1dfe 101 /**
mbed_official 15:a81a8d6c1dfe 102 * \brief Enables callback.
mbed_official 15:a81a8d6c1dfe 103 *
mbed_official 15:a81a8d6c1dfe 104 * Enables the callback function registered by the \ref
mbed_official 15:a81a8d6c1dfe 105 * tc_register_callback. The callback function will be called from the
mbed_official 15:a81a8d6c1dfe 106 * interrupt handler when the conditions for the callback type are
mbed_official 15:a81a8d6c1dfe 107 * met. This function will also enable the appropriate interrupts.
mbed_official 15:a81a8d6c1dfe 108 *
mbed_official 15:a81a8d6c1dfe 109 * \param[in] module Pointer to TC software instance struct
mbed_official 15:a81a8d6c1dfe 110 * \param[in] callback_type Callback type given by an enum
mbed_official 15:a81a8d6c1dfe 111 */
mbed_official 15:a81a8d6c1dfe 112 static inline void tc_enable_callback(
mbed_official 15:a81a8d6c1dfe 113 struct tc_module *const module,
mbed_official 15:a81a8d6c1dfe 114 const enum tc_callback callback_type)
mbed_official 15:a81a8d6c1dfe 115 {
mbed_official 15:a81a8d6c1dfe 116 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 117 Assert(module);
mbed_official 15:a81a8d6c1dfe 118
mbed_official 15:a81a8d6c1dfe 119
mbed_official 15:a81a8d6c1dfe 120 /* Enable interrupts for this TC module */
mbed_official 15:a81a8d6c1dfe 121 system_interrupt_enable(_tc_interrupt_get_interrupt_vector(_tc_get_inst_index(module->hw)));
mbed_official 15:a81a8d6c1dfe 122
mbed_official 15:a81a8d6c1dfe 123 /* Enable callback */
mbed_official 15:a81a8d6c1dfe 124 if (callback_type == TC_CALLBACK_CC_CHANNEL0) {
mbed_official 15:a81a8d6c1dfe 125 module->enable_callback_mask |= TC_INTFLAG_MC(1);
mbed_official 15:a81a8d6c1dfe 126 module->hw->COUNT8.INTENSET.reg = TC_INTFLAG_MC(1);
mbed_official 15:a81a8d6c1dfe 127 } else if (callback_type == TC_CALLBACK_CC_CHANNEL1) {
mbed_official 15:a81a8d6c1dfe 128 module->enable_callback_mask |= TC_INTFLAG_MC(2);
mbed_official 15:a81a8d6c1dfe 129 module->hw->COUNT8.INTENSET.reg = TC_INTFLAG_MC(2);
mbed_official 15:a81a8d6c1dfe 130 } else {
mbed_official 15:a81a8d6c1dfe 131 module->enable_callback_mask |= (1 << callback_type);
mbed_official 15:a81a8d6c1dfe 132 module->hw->COUNT8.INTENSET.reg = (1 << callback_type);
mbed_official 15:a81a8d6c1dfe 133 }
mbed_official 15:a81a8d6c1dfe 134 }
mbed_official 15:a81a8d6c1dfe 135
mbed_official 15:a81a8d6c1dfe 136 /**
mbed_official 15:a81a8d6c1dfe 137 * \brief Disables callback.
mbed_official 15:a81a8d6c1dfe 138 *
mbed_official 15:a81a8d6c1dfe 139 * Disables the callback function registered by the \ref
mbed_official 15:a81a8d6c1dfe 140 * tc_register_callback, and the callback will not be called from the
mbed_official 15:a81a8d6c1dfe 141 * interrupt routine. The function will also disable the appropriate
mbed_official 15:a81a8d6c1dfe 142 * interrupts.
mbed_official 15:a81a8d6c1dfe 143 *
mbed_official 15:a81a8d6c1dfe 144 * \param[in] module Pointer to TC software instance struct
mbed_official 15:a81a8d6c1dfe 145 * \param[in] callback_type Callback type given by an enum
mbed_official 15:a81a8d6c1dfe 146 */
mbed_official 15:a81a8d6c1dfe 147 static inline void tc_disable_callback(
mbed_official 15:a81a8d6c1dfe 148 struct tc_module *const module,
mbed_official 15:a81a8d6c1dfe 149 const enum tc_callback callback_type)
mbed_official 15:a81a8d6c1dfe 150 {
mbed_official 15:a81a8d6c1dfe 151 /* Sanity check arguments */
mbed_official 15:a81a8d6c1dfe 152 Assert(module);
mbed_official 15:a81a8d6c1dfe 153
mbed_official 15:a81a8d6c1dfe 154 /* Disable callback */
mbed_official 15:a81a8d6c1dfe 155 if (callback_type == TC_CALLBACK_CC_CHANNEL0) {
mbed_official 15:a81a8d6c1dfe 156 module->hw->COUNT8.INTENCLR.reg = TC_INTFLAG_MC(1);
mbed_official 15:a81a8d6c1dfe 157 module->enable_callback_mask &= ~TC_INTFLAG_MC(1);
mbed_official 15:a81a8d6c1dfe 158 } else if (callback_type == TC_CALLBACK_CC_CHANNEL1) {
mbed_official 15:a81a8d6c1dfe 159 module->hw->COUNT8.INTENCLR.reg = TC_INTFLAG_MC(2);
mbed_official 15:a81a8d6c1dfe 160 module->enable_callback_mask &= ~TC_INTFLAG_MC(2);
mbed_official 15:a81a8d6c1dfe 161 } else {
mbed_official 15:a81a8d6c1dfe 162 module->hw->COUNT8.INTENCLR.reg = (1 << callback_type);
mbed_official 15:a81a8d6c1dfe 163 module->enable_callback_mask &= ~(1 << callback_type);
mbed_official 15:a81a8d6c1dfe 164 }
mbed_official 15:a81a8d6c1dfe 165 }
mbed_official 15:a81a8d6c1dfe 166
mbed_official 15:a81a8d6c1dfe 167 /**
mbed_official 15:a81a8d6c1dfe 168 * @}
mbed_official 15:a81a8d6c1dfe 169 */
mbed_official 15:a81a8d6c1dfe 170
mbed_official 15:a81a8d6c1dfe 171 #ifdef __cplusplus
mbed_official 15:a81a8d6c1dfe 172 }
mbed_official 15:a81a8d6c1dfe 173 #endif
mbed_official 15:a81a8d6c1dfe 174
mbed_official 15:a81a8d6c1dfe 175 #endif /* TC_INTERRUPT_H_INCLUDED */