t

Fork of mbed-dev by mbed official

Committer:
mbed_official
Date:
Tue Apr 05 18:15:12 2016 +0100
Revision:
107:414e9c822e99
Synchronized with git revision dd3c5f7fa8473776950ec6e15c0e4adedb21cf2f

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

* * Base Commit for SAMG55J19. No errors and no implementations.

* * Added gpio files.

* * Added pinmap files.

* * Base commit for usticker implementation.

* * Added gcc_arm export functionality

* * added files for usticker.
* added template file for samd55j19

* * GPIO IRQ base commit.

* * updated with changes in gpio irq driver.

* * Reverted back unexpected commit in SAM0 gpio driver.

* * updated gpio_irq driver.

* * correction in gpio and gpio_irq drivers.
* added support for some test for gpio.

* * base commit for peripheralpins for usart.
* update in serial apis.

* * updated serial apis.

* * updated serial apis and test.

* * update serial apis for asynch apis.

* * updated peripheral pins for i2c and spi.
* added test support for serial flow control

* * Base commit for low power ticker implementation.

* * base commit for port apis.
* update in lp ticker apis.

* * Added test support for port.

* * base commit for sleep apis.

* * Base commit for spi.

* * updated with corrections in gpio irq.
* usticker file updated with latest source.

* * updated with corrections for unexpected board reset.
* updated gpio irq apis and added test for the same.

* * updated sleep api for deepsleep.

* * updated serial apis.

* Added uc_ticker and SPI api implementations

* Removed unused SPI pin map

* Updated review feedback

* * implemented lpticker with TC module.
* updated files for KnR Coding Statndard.
* updated serial and usticker apis.

* * Base commit for AnalogueIn apis.

* * RTC apis base commit without implementation.

* * Updated with corrections in lpticker implementations.

* * Added implementation for rtc apis.

* * updated with implementations for pwm.
* changed usticker from TC0 to TC1.

* Added I2C support

* * removed setvector usage from usticker and lpticker implementations
* added tests for SAMG55J19

* * Removed unwanted .o and .d files.
* Updated I2C files for KnR Coding Standards.
* Update for reducing compiler warnings in peripheralpins,c
* Updated with PWM free implementation.

* * Removed unwanted headers file inclusion.
* Compiler warning corrections in serial_api.c

* * Updated ADC with 16 bit mode initialization and code refinements.
* Updated PWM with code refinements.

* Updated I2C review feedback and fixed style

* Updated target name for SAMG55

* * Added Test Support for I2C with AT30TSE75X and Added Support for SAMG55J19 in atmelstudio project exporter

* * Added Test Support for I2C with AT30TSE75X and Added Support for SAMG55J19 in atmelstudio project exporter

* Used NVIC_SetVector for interrupt callback

* Removed Target macro define in test

* Updated test cases to have SAMG55 support

* * Updated with corrections in Serial and SPI asynchronous implementations.
* Updated deepsleep api implementation
* Merged LP_Ticker with latest code from mbed 3.0 repository.

* * updated with corrections in I2C Asynch implementation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 107:414e9c822e99 1 /**
mbed_official 107:414e9c822e99 2 * \file
mbed_official 107:414e9c822e99 3 *
mbed_official 107:414e9c822e99 4 * \brief Parallel Input/Output (PIO) interrupt handler for SAM.
mbed_official 107:414e9c822e99 5 *
mbed_official 107:414e9c822e99 6 * Copyright (c) 2011-2015 Atmel Corporation. All rights reserved.
mbed_official 107:414e9c822e99 7 *
mbed_official 107:414e9c822e99 8 * \asf_license_start
mbed_official 107:414e9c822e99 9 *
mbed_official 107:414e9c822e99 10 * \page License
mbed_official 107:414e9c822e99 11 *
mbed_official 107:414e9c822e99 12 * Redistribution and use in source and binary forms, with or without
mbed_official 107:414e9c822e99 13 * modification, are permitted provided that the following conditions are met:
mbed_official 107:414e9c822e99 14 *
mbed_official 107:414e9c822e99 15 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 107:414e9c822e99 16 * this list of conditions and the following disclaimer.
mbed_official 107:414e9c822e99 17 *
mbed_official 107:414e9c822e99 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 107:414e9c822e99 19 * this list of conditions and the following disclaimer in the documentation
mbed_official 107:414e9c822e99 20 * and/or other materials provided with the distribution.
mbed_official 107:414e9c822e99 21 *
mbed_official 107:414e9c822e99 22 * 3. The name of Atmel may not be used to endorse or promote products derived
mbed_official 107:414e9c822e99 23 * from this software without specific prior written permission.
mbed_official 107:414e9c822e99 24 *
mbed_official 107:414e9c822e99 25 * 4. This software may only be redistributed and used in connection with an
mbed_official 107:414e9c822e99 26 * Atmel microcontroller product.
mbed_official 107:414e9c822e99 27 *
mbed_official 107:414e9c822e99 28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
mbed_official 107:414e9c822e99 29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed_official 107:414e9c822e99 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
mbed_official 107:414e9c822e99 31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
mbed_official 107:414e9c822e99 32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 107:414e9c822e99 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
mbed_official 107:414e9c822e99 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
mbed_official 107:414e9c822e99 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
mbed_official 107:414e9c822e99 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 107:414e9c822e99 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 107:414e9c822e99 38 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 107:414e9c822e99 39 *
mbed_official 107:414e9c822e99 40 * \asf_license_stop
mbed_official 107:414e9c822e99 41 *
mbed_official 107:414e9c822e99 42 */
mbed_official 107:414e9c822e99 43 /*
mbed_official 107:414e9c822e99 44 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
mbed_official 107:414e9c822e99 45 */
mbed_official 107:414e9c822e99 46
mbed_official 107:414e9c822e99 47 #include "pio.h"
mbed_official 107:414e9c822e99 48 #include "pio_handler.h"
mbed_official 107:414e9c822e99 49
mbed_official 107:414e9c822e99 50 /**
mbed_official 107:414e9c822e99 51 * Maximum number of interrupt sources that can be defined. This
mbed_official 107:414e9c822e99 52 * constant can be increased, but the current value is the smallest possible one
mbed_official 107:414e9c822e99 53 * that will be compatible with all existing projects.
mbed_official 107:414e9c822e99 54 */
mbed_official 107:414e9c822e99 55 #define MAX_INTERRUPT_SOURCES 7
mbed_official 107:414e9c822e99 56
mbed_official 107:414e9c822e99 57 /**
mbed_official 107:414e9c822e99 58 * Describes a PIO interrupt source, including the PIO instance triggering the
mbed_official 107:414e9c822e99 59 * interrupt and the associated interrupt handler.
mbed_official 107:414e9c822e99 60 */
mbed_official 107:414e9c822e99 61 struct s_interrupt_source {
mbed_official 107:414e9c822e99 62 uint32_t id;
mbed_official 107:414e9c822e99 63 uint32_t mask;
mbed_official 107:414e9c822e99 64 uint32_t attr;
mbed_official 107:414e9c822e99 65
mbed_official 107:414e9c822e99 66 /* Interrupt handler. */
mbed_official 107:414e9c822e99 67 void (*handler) (const uint32_t, const uint32_t);
mbed_official 107:414e9c822e99 68 };
mbed_official 107:414e9c822e99 69
mbed_official 107:414e9c822e99 70
mbed_official 107:414e9c822e99 71 /* List of interrupt sources. */
mbed_official 107:414e9c822e99 72 static struct s_interrupt_source gs_interrupt_sources[MAX_INTERRUPT_SOURCES];
mbed_official 107:414e9c822e99 73
mbed_official 107:414e9c822e99 74 /* Number of currently defined interrupt sources. */
mbed_official 107:414e9c822e99 75 static uint32_t gs_ul_nb_sources = 0;
mbed_official 107:414e9c822e99 76
mbed_official 107:414e9c822e99 77 #if (SAM3S || SAM4S || SAM4E)
mbed_official 107:414e9c822e99 78 /* PIO Capture handler */
mbed_official 107:414e9c822e99 79 static void (*pio_capture_handler)(Pio *) = NULL;
mbed_official 107:414e9c822e99 80 extern uint32_t pio_capture_enable_flag;
mbed_official 107:414e9c822e99 81 #endif
mbed_official 107:414e9c822e99 82
mbed_official 107:414e9c822e99 83 /**
mbed_official 107:414e9c822e99 84 * \brief Process an interrupt request on the given PIO controller.
mbed_official 107:414e9c822e99 85 *
mbed_official 107:414e9c822e99 86 * \param p_pio PIO controller base address.
mbed_official 107:414e9c822e99 87 * \param ul_id PIO controller ID.
mbed_official 107:414e9c822e99 88 */
mbed_official 107:414e9c822e99 89 void pio_handler_process(Pio *p_pio, uint32_t ul_id)
mbed_official 107:414e9c822e99 90 {
mbed_official 107:414e9c822e99 91 uint32_t status;
mbed_official 107:414e9c822e99 92 uint32_t i;
mbed_official 107:414e9c822e99 93
mbed_official 107:414e9c822e99 94 /* Read PIO controller status */
mbed_official 107:414e9c822e99 95 status = pio_get_interrupt_status(p_pio);
mbed_official 107:414e9c822e99 96 status &= pio_get_interrupt_mask(p_pio);
mbed_official 107:414e9c822e99 97
mbed_official 107:414e9c822e99 98 /* Check pending events */
mbed_official 107:414e9c822e99 99 if (status != 0) {
mbed_official 107:414e9c822e99 100 /* Find triggering source */
mbed_official 107:414e9c822e99 101 i = 0;
mbed_official 107:414e9c822e99 102 while (status != 0) {
mbed_official 107:414e9c822e99 103 /* Source is configured on the same controller */
mbed_official 107:414e9c822e99 104 if (gs_interrupt_sources[i].id == ul_id) {
mbed_official 107:414e9c822e99 105 /* Source has PIOs whose statuses have changed */
mbed_official 107:414e9c822e99 106 if ((status & gs_interrupt_sources[i].mask) != 0) {
mbed_official 107:414e9c822e99 107 gs_interrupt_sources[i].handler(gs_interrupt_sources[i].id,
mbed_official 107:414e9c822e99 108 gs_interrupt_sources[i].mask);
mbed_official 107:414e9c822e99 109 status &= ~(gs_interrupt_sources[i].mask);
mbed_official 107:414e9c822e99 110 }
mbed_official 107:414e9c822e99 111 }
mbed_official 107:414e9c822e99 112 i++;
mbed_official 107:414e9c822e99 113 if (i >= MAX_INTERRUPT_SOURCES) {
mbed_official 107:414e9c822e99 114 break;
mbed_official 107:414e9c822e99 115 }
mbed_official 107:414e9c822e99 116 }
mbed_official 107:414e9c822e99 117 }
mbed_official 107:414e9c822e99 118
mbed_official 107:414e9c822e99 119 /* Check capture events */
mbed_official 107:414e9c822e99 120 #if (SAM3S || SAM4S || SAM4E)
mbed_official 107:414e9c822e99 121 if (pio_capture_enable_flag) {
mbed_official 107:414e9c822e99 122 if (pio_capture_handler) {
mbed_official 107:414e9c822e99 123 pio_capture_handler(p_pio);
mbed_official 107:414e9c822e99 124 }
mbed_official 107:414e9c822e99 125 }
mbed_official 107:414e9c822e99 126 #endif
mbed_official 107:414e9c822e99 127 }
mbed_official 107:414e9c822e99 128
mbed_official 107:414e9c822e99 129 /**
mbed_official 107:414e9c822e99 130 * \brief Set an interrupt handler for the provided pins.
mbed_official 107:414e9c822e99 131 * The provided handler will be called with the triggering pin as its parameter
mbed_official 107:414e9c822e99 132 * as soon as an interrupt is detected.
mbed_official 107:414e9c822e99 133 *
mbed_official 107:414e9c822e99 134 * \param p_pio PIO controller base address.
mbed_official 107:414e9c822e99 135 * \param ul_id PIO ID.
mbed_official 107:414e9c822e99 136 * \param ul_mask Pins (bit mask) to configure.
mbed_official 107:414e9c822e99 137 * \param ul_attr Pins attribute to configure.
mbed_official 107:414e9c822e99 138 * \param p_handler Interrupt handler function pointer.
mbed_official 107:414e9c822e99 139 *
mbed_official 107:414e9c822e99 140 * \return 0 if successful, 1 if the maximum number of sources has been defined.
mbed_official 107:414e9c822e99 141 */
mbed_official 107:414e9c822e99 142 uint32_t pio_handler_set(Pio *p_pio, uint32_t ul_id, uint32_t ul_mask,
mbed_official 107:414e9c822e99 143 uint32_t ul_attr, void (*p_handler) (uint32_t, uint32_t))
mbed_official 107:414e9c822e99 144 {
mbed_official 107:414e9c822e99 145 struct s_interrupt_source *pSource;
mbed_official 107:414e9c822e99 146
mbed_official 107:414e9c822e99 147 if (gs_ul_nb_sources >= MAX_INTERRUPT_SOURCES)
mbed_official 107:414e9c822e99 148 return 1;
mbed_official 107:414e9c822e99 149
mbed_official 107:414e9c822e99 150 /* Define new source */
mbed_official 107:414e9c822e99 151 pSource = &(gs_interrupt_sources[gs_ul_nb_sources]);
mbed_official 107:414e9c822e99 152 pSource->id = ul_id;
mbed_official 107:414e9c822e99 153 pSource->mask = ul_mask;
mbed_official 107:414e9c822e99 154 pSource->attr = ul_attr;
mbed_official 107:414e9c822e99 155 pSource->handler = p_handler;
mbed_official 107:414e9c822e99 156 gs_ul_nb_sources++;
mbed_official 107:414e9c822e99 157
mbed_official 107:414e9c822e99 158 /* Configure interrupt mode */
mbed_official 107:414e9c822e99 159 pio_configure_interrupt(p_pio, ul_mask, ul_attr);
mbed_official 107:414e9c822e99 160
mbed_official 107:414e9c822e99 161 return 0;
mbed_official 107:414e9c822e99 162 }
mbed_official 107:414e9c822e99 163
mbed_official 107:414e9c822e99 164 #if (SAM3S || SAM4S || SAM4E)
mbed_official 107:414e9c822e99 165 /**
mbed_official 107:414e9c822e99 166 * \brief Set a capture interrupt handler for all PIO.
mbed_official 107:414e9c822e99 167 *
mbed_official 107:414e9c822e99 168 * The handler will be called with the triggering PIO as its parameter
mbed_official 107:414e9c822e99 169 * as soon as an interrupt is detected.
mbed_official 107:414e9c822e99 170 *
mbed_official 107:414e9c822e99 171 * \param p_handler Interrupt handler function pointer.
mbed_official 107:414e9c822e99 172 *
mbed_official 107:414e9c822e99 173 */
mbed_official 107:414e9c822e99 174 void pio_capture_handler_set(void (*p_handler)(Pio *))
mbed_official 107:414e9c822e99 175 {
mbed_official 107:414e9c822e99 176 pio_capture_handler = p_handler;
mbed_official 107:414e9c822e99 177 }
mbed_official 107:414e9c822e99 178 #endif
mbed_official 107:414e9c822e99 179
mbed_official 107:414e9c822e99 180 #ifdef ID_PIOA
mbed_official 107:414e9c822e99 181 /**
mbed_official 107:414e9c822e99 182 * \brief Set an interrupt handler for the specified pin.
mbed_official 107:414e9c822e99 183 * The provided handler will be called with the triggering pin as its parameter
mbed_official 107:414e9c822e99 184 * as soon as an interrupt is detected.
mbed_official 107:414e9c822e99 185 *
mbed_official 107:414e9c822e99 186 * \param ul_pin Pin index to configure.
mbed_official 107:414e9c822e99 187 * \param ul_flag Pin flag.
mbed_official 107:414e9c822e99 188 * \param p_handler Interrupt handler function pointer.
mbed_official 107:414e9c822e99 189 *
mbed_official 107:414e9c822e99 190 * \return 0 if successful, 1 if the maximum number of sources has been defined.
mbed_official 107:414e9c822e99 191 */
mbed_official 107:414e9c822e99 192 uint32_t pio_handler_set_pin(uint32_t ul_pin, uint32_t ul_flag,
mbed_official 107:414e9c822e99 193 void (*p_handler) (uint32_t, uint32_t))
mbed_official 107:414e9c822e99 194 {
mbed_official 107:414e9c822e99 195 Pio *p_pio = pio_get_pin_group(ul_pin);
mbed_official 107:414e9c822e99 196 uint32_t group_id = pio_get_pin_group_id(ul_pin);
mbed_official 107:414e9c822e99 197 uint32_t group_mask = pio_get_pin_group_mask(ul_pin);
mbed_official 107:414e9c822e99 198
mbed_official 107:414e9c822e99 199 return pio_handler_set(p_pio, group_id, group_mask, ul_flag, p_handler);
mbed_official 107:414e9c822e99 200 }
mbed_official 107:414e9c822e99 201
mbed_official 107:414e9c822e99 202 /**
mbed_official 107:414e9c822e99 203 * \brief Parallel IO Controller A interrupt handler.
mbed_official 107:414e9c822e99 204 * Redefined PIOA interrupt handler for NVIC interrupt table.
mbed_official 107:414e9c822e99 205 */
mbed_official 107:414e9c822e99 206 void PIOA_Handler(void)
mbed_official 107:414e9c822e99 207 {
mbed_official 107:414e9c822e99 208 pio_handler_process(PIOA, ID_PIOA);
mbed_official 107:414e9c822e99 209 }
mbed_official 107:414e9c822e99 210 #endif
mbed_official 107:414e9c822e99 211
mbed_official 107:414e9c822e99 212 #ifdef ID_PIOB
mbed_official 107:414e9c822e99 213 /**
mbed_official 107:414e9c822e99 214 * \brief Parallel IO Controller B interrupt handler
mbed_official 107:414e9c822e99 215 * Redefined PIOB interrupt handler for NVIC interrupt table.
mbed_official 107:414e9c822e99 216 */
mbed_official 107:414e9c822e99 217 void PIOB_Handler(void)
mbed_official 107:414e9c822e99 218 {
mbed_official 107:414e9c822e99 219 pio_handler_process(PIOB, ID_PIOB);
mbed_official 107:414e9c822e99 220 }
mbed_official 107:414e9c822e99 221 #endif
mbed_official 107:414e9c822e99 222
mbed_official 107:414e9c822e99 223 #ifdef ID_PIOC
mbed_official 107:414e9c822e99 224 /**
mbed_official 107:414e9c822e99 225 * \brief Parallel IO Controller C interrupt handler.
mbed_official 107:414e9c822e99 226 * Redefined PIOC interrupt handler for NVIC interrupt table.
mbed_official 107:414e9c822e99 227 */
mbed_official 107:414e9c822e99 228 void PIOC_Handler(void)
mbed_official 107:414e9c822e99 229 {
mbed_official 107:414e9c822e99 230 pio_handler_process(PIOC, ID_PIOC);
mbed_official 107:414e9c822e99 231 }
mbed_official 107:414e9c822e99 232 #endif
mbed_official 107:414e9c822e99 233
mbed_official 107:414e9c822e99 234 #ifdef ID_PIOD
mbed_official 107:414e9c822e99 235 /**
mbed_official 107:414e9c822e99 236 * \brief Parallel IO Controller D interrupt handler.
mbed_official 107:414e9c822e99 237 * Redefined PIOD interrupt handler for NVIC interrupt table.
mbed_official 107:414e9c822e99 238 */
mbed_official 107:414e9c822e99 239 void PIOD_Handler(void)
mbed_official 107:414e9c822e99 240 {
mbed_official 107:414e9c822e99 241 pio_handler_process(PIOD, ID_PIOD);
mbed_official 107:414e9c822e99 242 }
mbed_official 107:414e9c822e99 243 #endif
mbed_official 107:414e9c822e99 244
mbed_official 107:414e9c822e99 245 #ifdef ID_PIOE
mbed_official 107:414e9c822e99 246 /**
mbed_official 107:414e9c822e99 247 * \brief Parallel IO Controller E interrupt handler.
mbed_official 107:414e9c822e99 248 * Redefined PIOE interrupt handler for NVIC interrupt table.
mbed_official 107:414e9c822e99 249 */
mbed_official 107:414e9c822e99 250 void PIOE_Handler(void)
mbed_official 107:414e9c822e99 251 {
mbed_official 107:414e9c822e99 252 pio_handler_process(PIOE, ID_PIOE);
mbed_official 107:414e9c822e99 253 }
mbed_official 107:414e9c822e99 254 #endif
mbed_official 107:414e9c822e99 255
mbed_official 107:414e9c822e99 256 #ifdef ID_PIOF
mbed_official 107:414e9c822e99 257 /**
mbed_official 107:414e9c822e99 258 * \brief Parallel IO Controller F interrupt handler.
mbed_official 107:414e9c822e99 259 * Redefined PIOF interrupt handler for NVIC interrupt table.
mbed_official 107:414e9c822e99 260 */
mbed_official 107:414e9c822e99 261 void PIOF_Handler(void)
mbed_official 107:414e9c822e99 262 {
mbed_official 107:414e9c822e99 263 pio_handler_process(PIOF, ID_PIOF);
mbed_official 107:414e9c822e99 264 }
mbed_official 107:414e9c822e99 265 #endif
mbed_official 107:414e9c822e99 266
mbed_official 107:414e9c822e99 267 /**
mbed_official 107:414e9c822e99 268 * \brief Initialize PIO interrupt management logic.
mbed_official 107:414e9c822e99 269 *
mbed_official 107:414e9c822e99 270 * \param p_pio PIO controller base address.
mbed_official 107:414e9c822e99 271 * \param ul_irqn NVIC line number.
mbed_official 107:414e9c822e99 272 * \param ul_priority PIO controller interrupts priority.
mbed_official 107:414e9c822e99 273 */
mbed_official 107:414e9c822e99 274 void pio_handler_set_priority(Pio *p_pio, IRQn_Type ul_irqn, uint32_t ul_priority)
mbed_official 107:414e9c822e99 275 {
mbed_official 107:414e9c822e99 276 uint32_t bitmask = 0;
mbed_official 107:414e9c822e99 277
mbed_official 107:414e9c822e99 278 bitmask = pio_get_interrupt_mask(p_pio);
mbed_official 107:414e9c822e99 279 pio_disable_interrupt(p_pio, 0xFFFFFFFF);
mbed_official 107:414e9c822e99 280 pio_get_interrupt_status(p_pio);
mbed_official 107:414e9c822e99 281 NVIC_DisableIRQ(ul_irqn);
mbed_official 107:414e9c822e99 282 NVIC_ClearPendingIRQ(ul_irqn);
mbed_official 107:414e9c822e99 283 NVIC_SetPriority(ul_irqn, ul_priority);
mbed_official 107:414e9c822e99 284 NVIC_EnableIRQ(ul_irqn);
mbed_official 107:414e9c822e99 285 pio_enable_interrupt(p_pio, bitmask);
mbed_official 107:414e9c822e99 286 }