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/sercom/sercom_interrupt.c@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 Serial Peripheral Interface Driver
mbed_official 15:a81a8d6c1dfe 5 *
mbed_official 15:a81a8d6c1dfe 6 * Copyright (C) 2012-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 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
mbed_official 15:a81a8d6c1dfe 45 */
mbed_official 15:a81a8d6c1dfe 46 #include "sercom_interrupt.h"
mbed_official 15:a81a8d6c1dfe 47
mbed_official 15:a81a8d6c1dfe 48 void *_sercom_instances[SERCOM_INST_NUM];
mbed_official 15:a81a8d6c1dfe 49
mbed_official 15:a81a8d6c1dfe 50 /** Save status of initialized handlers. */
mbed_official 15:a81a8d6c1dfe 51 static bool _handler_table_initialized = false;
mbed_official 15:a81a8d6c1dfe 52
mbed_official 15:a81a8d6c1dfe 53 /** Void pointers for saving device instance structures. */
mbed_official 15:a81a8d6c1dfe 54 static void (*_sercom_interrupt_handlers[SERCOM_INST_NUM])(const uint8_t instance);
mbed_official 15:a81a8d6c1dfe 55
mbed_official 15:a81a8d6c1dfe 56 /**
mbed_official 15:a81a8d6c1dfe 57 * \internal
mbed_official 15:a81a8d6c1dfe 58 * Default interrupt handler.
mbed_official 15:a81a8d6c1dfe 59 *
mbed_official 15:a81a8d6c1dfe 60 * \param[in] instance SERCOM instance used.
mbed_official 15:a81a8d6c1dfe 61 */
mbed_official 15:a81a8d6c1dfe 62 static void _sercom_default_handler(
mbed_official 15:a81a8d6c1dfe 63 const uint8_t instance)
mbed_official 15:a81a8d6c1dfe 64 {
mbed_official 15:a81a8d6c1dfe 65 Assert(false);
mbed_official 15:a81a8d6c1dfe 66 }
mbed_official 15:a81a8d6c1dfe 67
mbed_official 15:a81a8d6c1dfe 68 /**
mbed_official 15:a81a8d6c1dfe 69 * \internal
mbed_official 15:a81a8d6c1dfe 70 * Saves the given callback handler.
mbed_official 15:a81a8d6c1dfe 71 *
mbed_official 15:a81a8d6c1dfe 72 * \param[in] instance Instance index.
mbed_official 15:a81a8d6c1dfe 73 * \param[in] interrupt_handler Pointer to instance callback handler.
mbed_official 15:a81a8d6c1dfe 74 */
mbed_official 15:a81a8d6c1dfe 75 void _sercom_set_handler(
mbed_official 15:a81a8d6c1dfe 76 const uint8_t instance,
mbed_official 15:a81a8d6c1dfe 77 const sercom_handler_t interrupt_handler)
mbed_official 15:a81a8d6c1dfe 78 {
mbed_official 15:a81a8d6c1dfe 79 /* Initialize handlers with default handler and device instances with 0. */
mbed_official 15:a81a8d6c1dfe 80 if (_handler_table_initialized == false) {
mbed_official 15:a81a8d6c1dfe 81 for (uint32_t i = 0; i < SERCOM_INST_NUM; i++) {
mbed_official 15:a81a8d6c1dfe 82 _sercom_interrupt_handlers[i] = &_sercom_default_handler;
mbed_official 15:a81a8d6c1dfe 83 _sercom_instances[i] = NULL;
mbed_official 15:a81a8d6c1dfe 84 }
mbed_official 15:a81a8d6c1dfe 85
mbed_official 15:a81a8d6c1dfe 86 _handler_table_initialized = true;
mbed_official 15:a81a8d6c1dfe 87 }
mbed_official 15:a81a8d6c1dfe 88
mbed_official 15:a81a8d6c1dfe 89 /* Save interrupt handler. */
mbed_official 15:a81a8d6c1dfe 90 _sercom_interrupt_handlers[instance] = interrupt_handler;
mbed_official 15:a81a8d6c1dfe 91 }
mbed_official 15:a81a8d6c1dfe 92
mbed_official 15:a81a8d6c1dfe 93
mbed_official 15:a81a8d6c1dfe 94 /** \internal
mbed_official 15:a81a8d6c1dfe 95 * Converts a given SERCOM index to its interrupt vector index.
mbed_official 15:a81a8d6c1dfe 96 */
mbed_official 15:a81a8d6c1dfe 97 #define _SERCOM_INTERRUPT_VECT_NUM(n, unused) \
mbed_official 15:a81a8d6c1dfe 98 SYSTEM_INTERRUPT_MODULE_SERCOM##n,
mbed_official 15:a81a8d6c1dfe 99
mbed_official 15:a81a8d6c1dfe 100 /** \internal
mbed_official 15:a81a8d6c1dfe 101 * Generates a SERCOM interrupt handler function for a given SERCOM index.
mbed_official 15:a81a8d6c1dfe 102 */
mbed_official 15:a81a8d6c1dfe 103 #define _SERCOM_INTERRUPT_HANDLER(n, unused) \
mbed_official 15:a81a8d6c1dfe 104 void SERCOM##n##_Handler(void) \
mbed_official 15:a81a8d6c1dfe 105 { \
mbed_official 15:a81a8d6c1dfe 106 _sercom_interrupt_handlers[n](n); \
mbed_official 15:a81a8d6c1dfe 107 }
mbed_official 15:a81a8d6c1dfe 108
mbed_official 15:a81a8d6c1dfe 109 /**
mbed_official 15:a81a8d6c1dfe 110 * \internal
mbed_official 15:a81a8d6c1dfe 111 * Returns the system interrupt vector.
mbed_official 15:a81a8d6c1dfe 112 *
mbed_official 15:a81a8d6c1dfe 113 * \param[in] sercom_instance Instance pointer
mbed_official 15:a81a8d6c1dfe 114 *
mbed_official 15:a81a8d6c1dfe 115 * \return Enum of system interrupt vector
mbed_official 15:a81a8d6c1dfe 116 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM0
mbed_official 15:a81a8d6c1dfe 117 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM1
mbed_official 15:a81a8d6c1dfe 118 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM2
mbed_official 15:a81a8d6c1dfe 119 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM3
mbed_official 15:a81a8d6c1dfe 120 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM4
mbed_official 15:a81a8d6c1dfe 121 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM5
mbed_official 15:a81a8d6c1dfe 122 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM6
mbed_official 15:a81a8d6c1dfe 123 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM7
mbed_official 15:a81a8d6c1dfe 124 */
mbed_official 15:a81a8d6c1dfe 125 enum system_interrupt_vector _sercom_get_interrupt_vector(
mbed_official 15:a81a8d6c1dfe 126 Sercom *const sercom_instance)
mbed_official 15:a81a8d6c1dfe 127 {
mbed_official 15:a81a8d6c1dfe 128 const uint8_t sercom_int_vectors[SERCOM_INST_NUM] = {
mbed_official 15:a81a8d6c1dfe 129 MREPEAT(SERCOM_INST_NUM, _SERCOM_INTERRUPT_VECT_NUM, ~)
mbed_official 15:a81a8d6c1dfe 130 };
mbed_official 15:a81a8d6c1dfe 131
mbed_official 15:a81a8d6c1dfe 132 /* Retrieve the index of the SERCOM being requested */
mbed_official 15:a81a8d6c1dfe 133 uint8_t instance_index = _sercom_get_sercom_inst_index(sercom_instance);
mbed_official 15:a81a8d6c1dfe 134
mbed_official 15:a81a8d6c1dfe 135 /* Get the vector number from the lookup table for the requested SERCOM */
mbed_official 15:a81a8d6c1dfe 136 return (enum system_interrupt_vector)sercom_int_vectors[instance_index];
mbed_official 15:a81a8d6c1dfe 137 }
mbed_official 15:a81a8d6c1dfe 138
mbed_official 15:a81a8d6c1dfe 139 /** Auto-generate a set of interrupt handlers for each SERCOM in the device */
mbed_official 15:a81a8d6c1dfe 140 MREPEAT(SERCOM_INST_NUM, _SERCOM_INTERRUPT_HANDLER, ~)