mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

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 "sercom_interrupt.h"
mbed_official 579:53297373a894 2
mbed_official 579:53297373a894 3 void *_sercom_instances[SERCOM_INST_NUM];
mbed_official 579:53297373a894 4
mbed_official 579:53297373a894 5 /** Save status of initialized handlers. */
mbed_official 579:53297373a894 6 static bool _handler_table_initialized = false;
mbed_official 579:53297373a894 7
mbed_official 579:53297373a894 8 /** Void pointers for saving device instance structures. */
mbed_official 579:53297373a894 9 static void (*_sercom_interrupt_handlers[SERCOM_INST_NUM])(const uint8_t instance);
mbed_official 579:53297373a894 10
mbed_official 579:53297373a894 11 /**
mbed_official 579:53297373a894 12 * \internal
mbed_official 579:53297373a894 13 * Default interrupt handler.
mbed_official 579:53297373a894 14 *
mbed_official 579:53297373a894 15 * \param[in] instance SERCOM instance used.
mbed_official 579:53297373a894 16 */
mbed_official 579:53297373a894 17 static void _sercom_default_handler(
mbed_official 579:53297373a894 18 const uint8_t instance)
mbed_official 579:53297373a894 19 {
mbed_official 579:53297373a894 20 Assert(false);
mbed_official 579:53297373a894 21 }
mbed_official 579:53297373a894 22
mbed_official 579:53297373a894 23 /**
mbed_official 579:53297373a894 24 * \internal
mbed_official 579:53297373a894 25 * Saves the given callback handler.
mbed_official 579:53297373a894 26 *
mbed_official 579:53297373a894 27 * \param[in] instance Instance index.
mbed_official 579:53297373a894 28 * \param[in] interrupt_handler Pointer to instance callback handler.
mbed_official 579:53297373a894 29 */
mbed_official 579:53297373a894 30 void _sercom_set_handler(
mbed_official 579:53297373a894 31 const uint8_t instance,
mbed_official 579:53297373a894 32 const sercom_handler_t interrupt_handler)
mbed_official 579:53297373a894 33 {
mbed_official 579:53297373a894 34 /* Initialize handlers with default handler and device instances with 0. */
mbed_official 579:53297373a894 35 if (_handler_table_initialized == false) {
mbed_official 579:53297373a894 36 for (uint32_t i = 0; i < SERCOM_INST_NUM; i++) {
mbed_official 579:53297373a894 37 _sercom_interrupt_handlers[i] = &_sercom_default_handler;
mbed_official 579:53297373a894 38 _sercom_instances[i] = NULL;
mbed_official 579:53297373a894 39 }
mbed_official 579:53297373a894 40
mbed_official 579:53297373a894 41 _handler_table_initialized = true;
mbed_official 579:53297373a894 42 }
mbed_official 579:53297373a894 43
mbed_official 579:53297373a894 44 /* Save interrupt handler. */
mbed_official 579:53297373a894 45 _sercom_interrupt_handlers[instance] = interrupt_handler;
mbed_official 579:53297373a894 46 }
mbed_official 579:53297373a894 47
mbed_official 579:53297373a894 48
mbed_official 579:53297373a894 49 /** \internal
mbed_official 579:53297373a894 50 * Converts a given SERCOM index to its interrupt vector index.
mbed_official 579:53297373a894 51 */
mbed_official 579:53297373a894 52 #define _SERCOM_INTERRUPT_VECT_NUM(n, unused) \
mbed_official 579:53297373a894 53 SYSTEM_INTERRUPT_MODULE_SERCOM##n,
mbed_official 579:53297373a894 54
mbed_official 579:53297373a894 55 /** \internal
mbed_official 579:53297373a894 56 * Generates a SERCOM interrupt handler function for a given SERCOM index.
mbed_official 579:53297373a894 57 */
mbed_official 579:53297373a894 58 #define _SERCOM_INTERRUPT_HANDLER(n, unused) \
mbed_official 579:53297373a894 59 void SERCOM##n##_Handler(void) \
mbed_official 579:53297373a894 60 { \
mbed_official 579:53297373a894 61 _sercom_interrupt_handlers[n](n); \
mbed_official 579:53297373a894 62 }
mbed_official 579:53297373a894 63
mbed_official 579:53297373a894 64 /**
mbed_official 579:53297373a894 65 * \internal
mbed_official 579:53297373a894 66 * Returns the system interrupt vector.
mbed_official 579:53297373a894 67 *
mbed_official 579:53297373a894 68 * \param[in] sercom_instance Instance pointer
mbed_official 579:53297373a894 69 *
mbed_official 579:53297373a894 70 * \return Enum of system interrupt vector
mbed_official 579:53297373a894 71 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM0
mbed_official 579:53297373a894 72 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM1
mbed_official 579:53297373a894 73 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM2
mbed_official 579:53297373a894 74 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM3
mbed_official 579:53297373a894 75 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM4
mbed_official 579:53297373a894 76 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM5
mbed_official 579:53297373a894 77 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM6
mbed_official 579:53297373a894 78 * \retval SYSTEM_INTERRUPT_MODULE_SERCOM7
mbed_official 579:53297373a894 79 */
mbed_official 579:53297373a894 80 enum system_interrupt_vector _sercom_get_interrupt_vector(
mbed_official 579:53297373a894 81 Sercom *const sercom_instance)
mbed_official 579:53297373a894 82 {
mbed_official 579:53297373a894 83 const uint8_t sercom_int_vectors[SERCOM_INST_NUM] = {
mbed_official 579:53297373a894 84 MREPEAT(SERCOM_INST_NUM, _SERCOM_INTERRUPT_VECT_NUM, ~)
mbed_official 579:53297373a894 85 };
mbed_official 579:53297373a894 86
mbed_official 579:53297373a894 87 /* Retrieve the index of the SERCOM being requested */
mbed_official 579:53297373a894 88 uint8_t instance_index = _sercom_get_sercom_inst_index(sercom_instance);
mbed_official 579:53297373a894 89
mbed_official 579:53297373a894 90 /* Get the vector number from the lookup table for the requested SERCOM */
mbed_official 579:53297373a894 91 return (enum system_interrupt_vector)sercom_int_vectors[instance_index];
mbed_official 579:53297373a894 92 }
mbed_official 579:53297373a894 93
mbed_official 579:53297373a894 94 /** Auto-generate a set of interrupt handlers for each SERCOM in the device */
mbed_official 579:53297373a894 95 MREPEAT(SERCOM_INST_NUM, _SERCOM_INTERRUPT_HANDLER, ~)