http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/a280628a/hw/mcu/atmel/samd21xx/src/sam0/drivers/dma/dma_crc.h ---------------------------------------------------------------------- diff --git a/hw/mcu/atmel/samd21xx/src/sam0/drivers/dma/dma_crc.h b/hw/mcu/atmel/samd21xx/src/sam0/drivers/dma/dma_crc.h deleted file mode 100755 index 3d8c27c..0000000 --- a/hw/mcu/atmel/samd21xx/src/sam0/drivers/dma/dma_crc.h +++ /dev/null @@ -1,230 +0,0 @@ -/** - * \file - * - * \brief SAM DMA cyclic redundancy check (CRC) Driver - * - * Copyright (C) 2014-2015 Atmel Corporation. All rights reserved. - * - * \asf_license_start - * - * \page License - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The name of Atmel may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * 4. This software may only be redistributed and used in connection with an - * Atmel microcontroller product. - * - * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE - * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * \asf_license_stop - * - */ -/* - * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> - */ -#ifndef DMA_CRC_H_INCLUDED -#define DMA_CRC_H_INCLUDED - -#include <compiler.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/** DMA channel n offset. */ -#define DMA_CRC_CHANNEL_N_OFFSET 0x20 - -/** CRC Polynomial Type. */ -enum crc_polynomial_type { - /** CRC16 (CRC-CCITT). */ - CRC_TYPE_16, - /** CRC32 (IEEE 802.3). */ - CRC_TYPE_32, -}; - -/** CRC Beat Type. */ -enum crc_beat_size { - /** Byte bus access. */ - CRC_BEAT_SIZE_BYTE, - /** Half-word bus access. */ - CRC_BEAT_SIZE_HWORD, - /** Word bus access. */ - CRC_BEAT_SIZE_WORD, -}; - -/** Configurations for CRC calculation. */ -struct dma_crc_config { - /** CRC polynomial type. */ - enum crc_polynomial_type type; - /** CRC beat size. */ - enum crc_beat_size size; -}; - -/** - * \brief Get DMA CRC default configurations. - * - * The default configuration is as follows: - * \li Polynomial type is set to CRC-16(CRC-CCITT) - * \li CRC Beat size: BYTE - * - * \param[in] config default configurations - */ -static inline void dma_crc_get_config_defaults(struct dma_crc_config *config) -{ - Assert(config); - - config->type = CRC_TYPE_16; - config->size = CRC_BEAT_SIZE_BYTE; -} - -/** - * \brief Enable DMA CRC module with an DMA channel. - * - * This function enables a CRC calculation with an allocated DMA channel. This channel ID - * can be gotten from a successful \ref dma_allocate. - * - * \param[in] channel_id DMA channel expected with CRC calculation - * \param[in] config CRC calculation configurations - * - * \return Status of the DMC CRC. - * \retval STATUS_OK Get the DMA CRC module - * \retval STATUS_BUSY DMA CRC module is already taken and not ready yet - */ -static inline enum status_code dma_crc_channel_enable(uint32_t channel_id, - struct dma_crc_config *config) -{ - if (DMAC->CRCSTATUS.reg & DMAC_CRCSTATUS_CRCBUSY) { - return STATUS_BUSY; - } - - DMAC->CRCCTRL.reg = DMAC_CRCCTRL_CRCBEATSIZE(config->size) | - DMAC_CRCCTRL_CRCPOLY(config->type) | - DMAC_CRCCTRL_CRCSRC(channel_id+DMA_CRC_CHANNEL_N_OFFSET); - - DMAC->CTRL.reg |= DMAC_CTRL_CRCENABLE; - - return STATUS_OK; -} - -/** - * \brief Disable DMA CRC module. - * - */ -static inline void dma_crc_disable(void) -{ - DMAC->CTRL.reg &= ~DMAC_CTRL_CRCENABLE; - DMAC->CRCCTRL.reg = 0; -} - -/** - * \brief Get DMA CRC checksum value. - * - * \return Calculated CRC checksum. - */ -static inline uint32_t dma_crc_get_checksum(void) -{ - if (DMAC->CRCCTRL.bit.CRCSRC == DMAC_CRCCTRL_CRCSRC_IO_Val) { - DMAC->CRCSTATUS.reg = DMAC_CRCSTATUS_CRCBUSY; - } - - return DMAC->CRCCHKSUM.reg; -} - -/** - * \brief Enable DMA CRC module with I/O. - * - * This function enables a CRC calculation with I/O mode. - * - * \param[in] config CRC calculation configurations. - * - * \return Status of the DMC CRC. - * \retval STATUS_OK Get the DMA CRC module - * \retval STATUS_BUSY DMA CRC module is already taken and not ready yet - */ -static inline enum status_code dma_crc_io_enable( - struct dma_crc_config *config) -{ - if (DMAC->CRCSTATUS.reg & DMAC_CRCSTATUS_CRCBUSY) { - return STATUS_BUSY; - } - - if (DMAC->CTRL.reg & DMAC_CTRL_CRCENABLE) { - return STATUS_BUSY; - } - - DMAC->CRCCTRL.reg = DMAC_CRCCTRL_CRCBEATSIZE(config->size) | - DMAC_CRCCTRL_CRCPOLY(config->type) | - DMAC_CRCCTRL_CRCSRC_IO; - - if (config->type == CRC_TYPE_32) { - DMAC->CRCCHKSUM.reg = 0xFFFFFFFF; - } - - DMAC->CTRL.reg |= DMAC_CTRL_CRCENABLE; - - return STATUS_OK; -} - -/** - * \brief Calculate CRC with I/O. - * - * This function calculate the CRC of the input data buffer. - * - * \param[in] buffer CRC Pointer to calculation buffer - * \param[in] total_beat_size Total beat size to be calculated - * - * \return Calculated CRC checksum value. - */ -static inline void dma_crc_io_calculation(void *buffer, - uint32_t total_beat_size) -{ - uint32_t counter = total_beat_size; - uint8_t *buffer_8; - uint16_t *buffer_16; - uint32_t *buffer_32; - - for (counter=0; counter<total_beat_size; counter++) { - if (DMAC->CRCCTRL.bit.CRCBEATSIZE == CRC_BEAT_SIZE_BYTE) { - buffer_8 = buffer; - DMAC->CRCDATAIN.reg = buffer_8[counter]; - } else if (DMAC->CRCCTRL.bit.CRCBEATSIZE == CRC_BEAT_SIZE_HWORD) { - buffer_16 = buffer; - DMAC->CRCDATAIN.reg = buffer_16[counter]; - } else if (DMAC->CRCCTRL.bit.CRCBEATSIZE == CRC_BEAT_SIZE_WORD) { - buffer_32 = buffer; - DMAC->CRCDATAIN.reg = buffer_32[counter]; - } - /* Wait several cycle to make sure CRC complete */ - nop(); - nop(); - nop(); - nop(); - } -} - -#ifdef __cplusplus -} -#endif - -#endif /* DMA_CRC_H_INCLUDED */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/a280628a/hw/mcu/atmel/samd21xx/src/sam0/drivers/dma/module_config/conf_dma.h ---------------------------------------------------------------------- diff --git a/hw/mcu/atmel/samd21xx/src/sam0/drivers/dma/module_config/conf_dma.h b/hw/mcu/atmel/samd21xx/src/sam0/drivers/dma/module_config/conf_dma.h deleted file mode 100755 index fff0a2c..0000000 --- a/hw/mcu/atmel/samd21xx/src/sam0/drivers/dma/module_config/conf_dma.h +++ /dev/null @@ -1,51 +0,0 @@ -/** - * \file - * - * \brief SAM Direct Memory Access Driver Configuration Header - * - * Copyright (C) 2013-2015 Atmel Corporation. All rights reserved. - * - * \asf_license_start - * - * \page License - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The name of Atmel may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * 4. This software may only be redistributed and used in connection with an - * Atmel microcontroller product. - * - * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE - * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * \asf_license_stop - * - */ -/* - * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> - */ -#ifndef CONF_DMA_H_INCLUDED -#define CONF_DMA_H_INCLUDED - -# define CONF_MAX_USED_CHANNEL_NUM 5 - -#endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/a280628a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events.h ---------------------------------------------------------------------- diff --git a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events.h b/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events.h deleted file mode 100755 index 805bb50..0000000 --- a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events.h +++ /dev/null @@ -1,728 +0,0 @@ -/** - * \file - * - * \brief SAM Event System Driver - * - * Copyright (C) 2012-2015 Atmel Corporation. All rights reserved. - * - * \asf_license_start - * - * \page License - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The name of Atmel may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * 4. This software may only be redistributed and used in connection with an - * Atmel microcontroller product. - * - * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE - * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * \asf_license_stop - * - */ -/* - * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> - */ -#ifndef EVENTS_H_INCLUDED -#define EVENTS_H_INCLUDED - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * \defgroup asfdoc_sam0_events_group SAM Event System (EVENTS) Driver - * - * This driver for Atmel® | SMART ARM®-based microcontrollers provides - * an interface for the configuration and management of the device's peripheral - * event resources and users within the device, including enabling and disabling - * of peripheral source selection and synchronization of clock domains between - * various modules. The following API modes is covered by this manual: - * - Polled API - * \if EVENTS_INTERRUPT_HOOK_MODE - * - Interrupt hook API - * \endif - * - * The following peripheral is used by this module: - * - EVSYS (Event System Management) - * - * The following devices can use this module: - * - Atmel | SMART SAM D20/D21 - * - Atmel | SMART SAM R21 - * - Atmel | SMART SAM D09/D10/D11 - * - Atmel | SMART SAM L21/L22 - * - Atmel | SMART SAM DA1 - * - Atmel | SMART SAM C20/C21 - * - * The outline of this documentation is as follows: - * - \ref asfdoc_sam0_events_prerequisites - * - \ref asfdoc_sam0_events_module_overview - * - \ref asfdoc_sam0_events_special_considerations - * - \ref asfdoc_sam0_events_extra_info - * - \ref asfdoc_sam0_events_examples - * - \ref asfdoc_sam0_events_api_overview - * - * - * \section asfdoc_sam0_events_prerequisites Prerequisites - * - * There are no prerequisites for this module. - * - * - * \section asfdoc_sam0_events_module_overview Module Overview - * - * Peripherals within the SAM devices are capable of generating two types of - * actions in response to given stimulus; set a register flag for later - * intervention by the CPU (using interrupt or polling methods), or generate - * event signals, which can be internally routed directly to other - * peripherals within the device. The use of events allows for direct actions - * to be performed in one peripheral in response to a stimulus in another - * without CPU intervention. This can lower the overall power consumption of the - * system if the CPU is able to remain in sleep modes for longer periods (SleepWalking), and - * lowers the latency of the system response. - * - * The event system is comprised of a number of freely configurable Event - * resources, plus a number of fixed Event Users. Each Event resource can be - * configured to select the input peripheral that will generate the events - * signal, as well as the synchronization path and edge detection mode. - * The fixed-function Event Users, connected to peripherals within the device, - * can then subscribe to an Event resource in a one-to-many relationship in order - * to receive events as they are generated. An overview of the event system - * chain is shown in - * \ref asfdoc_sam0_events_module_overview_fig "the figure below". - * - * \anchor asfdoc_sam0_events_module_overview_fig - * \dot - * digraph overview { - * rankdir=LR; - * node [label="Source\nPeripheral\n(Generator)" shape=ellipse style=filled fillcolor=lightgray] src_peripheral; - * node [label="Event\nResource A" shape=square style=""] event_gen0; - * node [label="Event\nUser X" shape=square style=""] event_user0; - * node [label="Event\nUser Y" shape=square style=""] event_user1; - * node [label="Destination\nPeripheral\n(User)" shape=ellipse style=filled fillcolor=lightgray] dst_peripheral0; - * node [label="Destination\nPeripheral\n(User)" shape=ellipse style=filled fillcolor=lightgray] dst_peripheral1; - * - * src_peripheral -> event_gen0; - * event_gen0 -> event_user0; - * event_gen0 -> event_user1; - * event_user0 -> dst_peripheral0; - * event_user1 -> dst_peripheral1; - * } - * \enddot - * - * There are many different events that can be routed in the device, which can - * then trigger many different actions. For example, an Analog Comparator module - * could be configured to generate an event when the input signal rises above - * the compare threshold, which then triggers a Timer Counter module to capture - * the current count value for later use. - * - * \subsection asfdoc_sam0_events_module_overview_event_channels Event Channels - * The Event module in each device consists of several channels, which can be - * freely linked to an event generator (i.e. a peripheral within the device - * that is capable of generating events). Each channel can be individually - * configured to select the generator peripheral, signal path, and edge detection - * applied to the input event signal, before being passed to any event user(s). - * - * Event channels can support multiple users within the device in a standardized - * manner; when an Event User is linked to an Event Channel, the channel will - * automatically handshake with all attached users to ensure that all modules - * correctly receive and acknowledge the event. - * - * \subsection asfdoc_sam0_events_module_overview_event_users Event Users - * Event Users are able to subscribe to an Event Channel, once it has been - * configured. Each Event User consists of a fixed connection to one of the - * peripherals within the device (for example, an ADC module, or Timer module) - * and is capable of being connected to a single Event Channel. - * - * \subsection asfdoc_sam0_events_module_overview_edge_detection Edge Detection - * For asynchronous events, edge detection on the event input is not possible, - * and the event signal must be passed directly between the event generator and - * event user. For synchronous and re-synchronous events, the input signal from - * the event generator must pass through an edge detection unit, so that only - * the rising, falling, or both edges of the event signal triggers an action in - * the event user. - * - * \subsection asfdoc_sam0_events_module_overview_path_selection Path Selection - * The event system in the SAM devices supports three signal path types from - * the event generator to event users: asynchronous, synchronous, and - * re-synchronous events. - * - * \subsubsection asfdoc_sam0_events_module_overview_path_selection_async Asynchronous Paths - * Asynchronous event paths allow for an asynchronous connection between the - * event generator and event user(s), when the source and destination - * peripherals share the same \ref asfdoc_sam0_system_clock_group "Generic Clock" - * channel. In this mode the event is propagated between the source and - * destination directly to reduce the event latency, thus no edge detection is - * possible. The asynchronous event chain is shown in - * \ref asfdoc_sam0_events_module_async_path_fig "the figure below". - * - * \anchor asfdoc_sam0_events_module_async_path_fig - * \dot - * digraph overview { - * rankdir=LR; - * node [label="Source\nPeripheral" shape=ellipse style=filled fillcolor=lightgray] src_peripheral; - * node [label="<f0> EVSYS | <f1> Event\nChannel/User" fillcolor=white style="dashed" shape=record] events_chan; - * node [label="Destination\nPeripheral" shape=ellipse style=filled fillcolor=lightgray] dst_peripheral; - * - * src_peripheral -> events_chan; - * events_chan -> dst_peripheral; - * - * } - * \enddot - * \note Identically shaped borders in the diagram indicate a shared generic clock channel. - * - * \subsubsection asfdoc_sam0_events_module_overview_path_selection_sync Synchronous Paths - * The Synchronous event path should be used when edge detection or interrupts - * from the event channel are required, and the source event generator and the - * event channel shares the same Generic Clock channel. The synchronous event - * chain is shown in - * \ref asfdoc_sam0_events_module_sync_path_fig "the figure below". - * - * Not all peripherals support Synchronous event paths; refer to the device datasheet. - * - * \anchor asfdoc_sam0_events_module_sync_path_fig - * \dot - * digraph overview { - * rankdir=LR; - * node [label="Source\nPeripheral" shape=ellipse style="filled, dashed" fillcolor=lightgray] src_peripheral; - * node [label="<f0> EVSYS | <f1> Event\nChannel/User" fillcolor=white shape=record style="dashed"] events_chan; - * node [label="Destination\nPeripheral" shape=ellipse style="filled, solid" fillcolor=lightgray] dst_peripheral; - * - * src_peripheral -> events_chan; - * events_chan -> dst_peripheral; - * - * } - * \enddot - * \note Identically shaped borders in the diagram indicate a shared generic clock channel. - * - * \subsubsection asfdoc_sam0_events_module_overview_path_selection_resync Re-synchronous Paths - * Re-synchronous event paths are a special form of synchronous events, where - * when edge detection or interrupts from the event channel are required, but - * the event generator and the event channel use different Generic Clock - * channels. The re-synchronous path allows the Event System to synchronize the - * incoming event signal from the Event Generator to the clock of the Event - * System module to avoid missed events, at the cost of a higher latency due to - * the re-synchronization process. The re-synchronous event chain is shown in - * \ref asfdoc_sam0_events_module_resync_path_fig "the figure below". - * - * Not all peripherals support re-synchronous event paths; refer to the device datasheet. - * \anchor asfdoc_sam0_events_module_resync_path_fig - * \dot - * digraph overview { - * rankdir=LR; - * node [label="Source\nPeripheral" shape=ellipse style="filled, dotted" fillcolor=lightgray] src_peripheral; - * node [label="<f0> EVSYS | <f1> Event\nChannel/User" fillcolor=white shape=record style="dashed"] events_chan; - * node [label="Destination\nPeripheral" shape=ellipse style=filled fillcolor=lightgray] dst_peripheral; - * - * src_peripheral -> events_chan; - * events_chan -> dst_peripheral; - * - * } - * \enddot - * \note Identically shaped borders in the diagram indicate a shared generic clock channel. - * - * \subsection asfdoc_sam0_events_module_overview_physical Physical Connection - * - * \ref asfdoc_sam0_events_module_int_connections_fig "The diagram below" - * shows how this module is interconnected within the device. - * - * \anchor asfdoc_sam0_events_module_int_connections_fig - * \dot - * digraph overview { - * rankdir=LR; - * node [label="Source\nPeripherals" shape=ellipse style=filled fillcolor=lightgray] src_peripheral; - * - * subgraph driver { - * node [label="<f0> EVSYS | <f1> Event Channels" fillcolor=white shape=record] events_chan; - * node [label="<f0> EVSYS | <f1> Event Users" fillcolor=white shape=record] events_user; - * } - * - * node [label="Destination\nPeripherals" shape=ellipse style=filled fillcolor=lightgray] dst_peripheral; - * - * src_peripheral -> events_chan:f1 [label="Source\nMUXs"]; - * events_chan:f1 -> events_user:f1 [label="Channel\nMUXs"]; - * events_user:f1 -> dst_peripheral; - * } - * \enddot - * - * \subsection asfdoc_sam0_events_module_overview_config Configuring Events - * For SAM devices, several steps are required to properly configure an - * event chain, so that hardware peripherals can respond to events generated by - * each other, listed below. - * - * \subsubsection asfdoc_sam0_events_module_overview_config_src Source Peripheral - * -# The source peripheral (that will generate events) must be configured and - * enabled. - * -# The source peripheral (that will generate events) must have an output - * event enabled. - - * \subsubsection asfdoc_sam0_events_module_overview_config_evsys Event System - * -# An event system channel must be allocated and configured with the - * correct source peripheral selected as the channel's event generator. - * -# The event system user must be configured and enabled, and attached to - # event channel previously allocated. - - * \subsubsection asfdoc_sam0_events_module_overview_config_dst Destination Peripheral - * -# The destination peripheral (that will receive events) must be configured - * and enabled. - * -# The destination peripheral (that will receive events) must have an input - * event enabled. - * - * - * \section asfdoc_sam0_events_special_considerations Special Considerations - * - * There are no special considerations for this module. - * - * - * \section asfdoc_sam0_events_extra_info Extra Information - * - * For extra information, see \ref asfdoc_sam0_events_extra. This includes: - * - \ref asfdoc_sam0_events_extra_acronyms - * - \ref asfdoc_sam0_events_extra_dependencies - * - \ref asfdoc_sam0_events_extra_errata - * - \ref asfdoc_sam0_events_extra_history - * - * - * \section asfdoc_sam0_events_examples Examples - * - * For a list of examples related to this driver, see - * \ref asfdoc_sam0_events_exqsg. - * - * - * \section asfdoc_sam0_events_api_overview API Overview - * @{ - */ - -#include <compiler.h> -#include "events_common.h" - -/** - * \brief Edge detect enum. - * - * Event channel edge detect setting. - * - */ -enum events_edge_detect { - /** No event output */ - EVENTS_EDGE_DETECT_NONE, - /** Event on rising edge */ - EVENTS_EDGE_DETECT_RISING, - /** Event on falling edge */ - EVENTS_EDGE_DETECT_FALLING, - /** Event on both edges */ - EVENTS_EDGE_DETECT_BOTH, -}; - -/** - * \brief Path selection enum. - * - * Event channel path selection. - * - */ -enum events_path_selection { - /** Select the synchronous path for this event channel */ - EVENTS_PATH_SYNCHRONOUS, - /** Select the resynchronizer path for this event channel */ - EVENTS_PATH_RESYNCHRONIZED, - /** Select the asynchronous path for this event channel */ - EVENTS_PATH_ASYNCHRONOUS, -}; - -/** - * \brief Events configuration struct. - * - * This event configuration struct is used to configure each of the channels. - * - */ -struct events_config { - /** Select edge detection mode */ - enum events_edge_detect edge_detect; - /** Select events channel path */ - enum events_path_selection path; - /** Set event generator for the channel */ - uint8_t generator; - /** Clock source for the event channel */ - uint8_t clock_source; -#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) - /** Run in standby mode for the channel */ - bool run_in_standby; - /** Run On Demand */ - bool on_demand; -#endif -}; - -/** - * \brief No event generator definition. - * - * Use this to disable any peripheral event input to a channel. This can be useful - * if you only want to use a channel for software generated events. - * - */ - -///@cond INTERNAL -/** - * \internal - * Status bit offsets in the status register/interrupt register. - * - * @{ - */ -#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) -# define _EVENTS_START_OFFSET_BUSY_BITS 16 -# define _EVENTS_START_OFFSET_USER_READY_BIT 0 -# define _EVENTS_START_OFFSET_DETECTION_BIT 16 -# define _EVENTS_START_OFFSET_OVERRUN_BIT 0 -#else /* SAM D/R */ -# define _EVENTS_START_OFFSET_BUSY_BITS 8 -# define _EVENTS_START_OFFSET_USER_READY_BIT 0 -# define _EVENTS_START_OFFSET_DETECTION_BIT 8 -# define _EVENTS_START_OFFSET_OVERRUN_BIT 0 -#endif -/** @} */ -///@endcond - -/** -* Definition for no generator selection. -*/ -#define EVSYS_ID_GEN_NONE 0 - -/** - * \brief Event channel resource. - * - * Event resource structure. - * - * \note The fields in this structure should not be altered by the user application; - * they are reserved for driver internals only. - */ -struct events_resource { -#if !defined(__DOXYGEN__) - /** Channel allocated for the event resource */ - uint8_t channel; - /** Channel setting in CHANNEL register */ - uint32_t channel_reg; -#endif -}; - -#if EVENTS_INTERRUPT_HOOKS_MODE == true -typedef void (*events_interrupt_hook)(struct events_resource *resource); - -/** - * \brief Event hook. - * - * Event hook structure. - * - */ -struct events_hook { - /** Event resource */ - struct events_resource *resource; - /** Event hook function */ - events_interrupt_hook hook_func; - /** Next event hook */ - struct events_hook *next; -}; -#endif - -/** - * \brief Initializes an event configurations struct to defaults. - * - * Initailizes an event configuration struct to predefined safe default settings. - * - * \param[in] config Pointer to an instance of \ref struct events_config - * - */ -void events_get_config_defaults(struct events_config *config); - -/** - * \brief Allocate an event channel and set configuration. - * - * Allocates an event channel from the event channel pool and sets - * the channel configuration. - * - * \param[out] resource Pointer to a \ref events_resource struct instance - * \param[in] config Pointer to a \ref events_config struct - * - * \return Status of the configuration procedure. - * \retval STATUS_OK Allocation and configuration went successful - * \retval STATUS_ERR_NOT_FOUND No free event channel found - * - */ -enum status_code events_allocate(struct events_resource *resource, struct events_config *config); - -/** - * \brief Attach user to the event channel. - * - * Attach a user peripheral to the event channel to receive events. - * - * \param[in] resource Pointer to an \ref events_resource struct instance - * \param[in] user_id A number identifying the user peripheral found in the device header file - * - * \return Status of the user attach procedure. - * \retval STATUS_OK No errors detected when attaching the event user - */ -enum status_code events_attach_user(struct events_resource *resource, uint8_t user_id); - -/** - * \brief Detach a user peripheral from the event channel. - * - * Deattach a user peripheral from the event channels so it does not receive any more events. - * - * \param[in] resource Pointer to an \ref event_resource struct instance - * \param[in] user_id A number identifying the user peripheral found in the device header file - * - * \return Status of the user detach procedure. - * \retval STATUS_OK No errors detected when detaching the event user - */ -enum status_code events_detach_user(struct events_resource *resource, uint8_t user_id); - -/** - * \brief Check if a channel is busy. - * - * Check if a channel is busy, a channel stays busy until all users connected to the channel - * has handled an event. - * - * \param[in] resource Pointer to a \ref events_resource struct instance - * - * \return Status of the channels busy state. - * \retval true One or more users connected to the channel has not handled the last event - * \retval false All users are ready handle new events - */ -bool events_is_busy(struct events_resource *resource); - -/** - * \brief Trigger software event. - * - * Trigger an event by software. - * - * \note Software event works on either a synchronous path or resynchronized path, and - * edge detection must be configured to rising-edge detection. - * - * \param[in] resource Pointer to an \ref events_resource struct - * - * \return Status of the event software procedure. - * \retval STATUS_OK No error was detected when software tigger signal was issued - * \retval STATUS_ERR_UNSUPPORTED_DEV If the channel path is asynchronous and/or the - * edge detection is not set to RISING - */ -enum status_code events_trigger(struct events_resource *resource); - -/** - * \brief Check if all users connected to the channel is ready. - * - * Check if all users connected to the channel is ready to handle incoming events. - * - * \param[in] resource Pointer to an \ref events_resource struct - * - * \return The ready status of users connected to an event channel. - * \retval true All users connect to event channel is ready to handle incoming events - * \retval false One or more users connect to event channel is not ready to handle incoming events - */ -bool events_is_users_ready(struct events_resource *resource); - -/** - * \brief Check if an event is detected on the event channel. - * - * Check if an event has been detected on the channel. - * - * \note This function will clear the event detected interrupt flag. - * - * \param[in] resource Pointer to an \ref events_resource struct - * - * \return Status of the event detection interrupt flag. - * \retval true Event has been detected - * \retval false Event has not been detected - */ -bool events_is_detected(struct events_resource *resource); - -/** - * \brief Check if there has been an overrun situation on this channel. - * - * \note This function will clear the event overrun detected interrupt flag. - * - * \param[in] resource Pointer to an \ref events_resource struct - * - * \return Status of the event overrun interrupt flag. - * \retval true Event overrun has been detected - * \retval false Event overrun has not been detected - */ -bool events_is_overrun(struct events_resource *resource); - -/** - * \brief Release allocated channel back the the resource pool. - * - * Release an allocated channel back to the resource pool to make it available for other purposes. - * - * \param[in] resource Pointer to an \ref events_resource struct - * - * \return Status of channel release procedure. - * \retval STATUS_OK No error was detected when channel was released - * \retval STATUS_BUSY One or more event users have not processed the last event - * \retval STATUS_ERR_NOT_INITIALIZED Channel not allocated, and can therefore not be released - */ -enum status_code events_release(struct events_resource *resource); - -/** - * \brief Get number of free channels. - * - * Get number of allocatable channels in the events system resource pool. - * - * \return The number of free channels in the event system. - * - */ -uint8_t events_get_free_channels(void); - - -///@cond INTERNAL -/** - * \internal - * Function to find bit position in the CHSTATUS and INTFLAG register, - * and return bit mask of this position. - * - * @{ - */ -uint32_t _events_find_bit_position(uint8_t channel, uint8_t start_offset); -/** @} */ -///@endcond - - -/** @} */ - -/** - * \page asfdoc_sam0_events_extra Extra Information for EVENTS Driver - * - * \section asfdoc_sam0_events_extra_acronyms Acronyms - * Below is a table listing the acronyms used in this module, along with their - * intended meanings. - * - * <table> - * <tr> - * <th>Acronym</th> - * <th>Description</th> - * </tr> - * <tr> - * <td>CPU</td> - * <td>Central Processing Unit</td> - * </tr> - * <tr> - * <td>MUX</td> - * <td>Multiplexer</td> - * </tr> - * </table> - * - * - * \section asfdoc_sam0_events_extra_dependencies Dependencies - * This driver has the following dependencies: - * - * - \ref asfdoc_sam0_system_clock_group "System Clock Driver" - * - * - * \section asfdoc_sam0_events_extra_errata Errata - * There are no errata related to this driver. - * - * - * \section asfdoc_sam0_events_extra_history Module History - * An overview of the module history is presented in the table below, with - * details on the enhancements and fixes made to the module since its first - * release. The current version of this corresponds to the newest version in - * the table. - * - * <table> - * <tr> - * <th>Changelog</th> - * </tr> - * <tr> - * <td>Fix a bug in internal function _events_find_bit_position()</td> - * </tr> - * <tr> - * <td>Rewrite of events driver</td> - * </tr> - * <tr> - * <td>Initial Release</td> - * </tr> - * </table> - */ - - /** - * \page asfdoc_sam0_events_exqsg Examples for EVENTS Driver - * - * This is a list of the available Quick Start guides (QSGs) and example - * applications for \ref asfdoc_sam0_events_group. QSGs are simple examples with - * step-by-step instructions to configure and use this driver in a selection of - * use cases. Note that a QSG can be compiled as a standalone application or be - * added to the user application. - * - * - \subpage asfdoc_sam0_events_basic_use_case - * \if EVENTS_INTERRUPT_HOOK_MODE - * - \subpage asfdoc_sam0_events_interrupt_hook_use_case - * \endif - * - * \page asfdoc_sam0_events_document_revision_history Document Revision History - * - * <table> - * <tr> - * <th>Doc. Rev.</td> - * <th>Date</td> - * <th>Comments</td> - * </tr> - * <tr> - * <td>42108G</td> - * <td>08/2015</td> - * <td>Added support for SAM L22</td> - * </tr> - * <tr> - * <td>42108F</td> - * <td>08/2015</td> - * <td>Added support for SAM L21, SAM DA1 and SAM C20/C21</td> - * </tr> - * <tr> - * <td>42108E</td> - * <td>12/2014</td> - * <td>Added support for interrupt hook mode. - * Added support for SAM R21 and SAM D10/D11.</td> - * </tr> - * <tr> - * <td>42108D</td> - * <td>01/2014</td> - * <td>Update to support SAM D21 and corrected documentation typos</td> - * </tr> - * <tr> - * <td>42108C</td> - * <td>11/2013</td> - * <td>Fixed incorrect documentation for the event signal paths. Added - * configuration steps overview to the documentation.</td> - * </tr> - * <tr> - * <td>42108B</td> - * <td>06/2013</td> - * <td>Corrected documentation typos</td> - * </tr> - * <tr> - * <td>42108A</td> - * <td>06/2013</td> - * <td>Initial release</td> - * </tr> - * </table> - */ - -#ifdef __cplusplus -} -#endif - -#endif /* EVENTS_H_INCLUDED */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/a280628a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_common.h ---------------------------------------------------------------------- diff --git a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_common.h b/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_common.h deleted file mode 100755 index b40db7c..0000000 --- a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_common.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * \file - * - * \brief SAM Event System Controller Driver - * - * Copyright (C) 2014-2015 Atmel Corporation. All rights reserved. - * - * \asf_license_start - * - * \page License - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The name of Atmel may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * 4. This software may only be redistributed and used in connection with an - * Atmel microcontroller product. - * - * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE - * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * \asf_license_stop - * - */ -/* - * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> - */ -#ifndef _EVENTS_COMMON_H_INCLUDED_ -#define _EVENTS_COMMON_H_INCLUDED_ - -/** - * \internal Internal module structure to manage necessary globals - * - * - */ -struct _events_module { - /* Allocated channels bitmask where 1 means allocated */ - volatile uint32_t allocated_channels; - /* Free channels */ - uint8_t free_channels; - -#if EVENTS_INTERRUPT_HOOKS_MODE == true - /* Buffer to store a copy of the current interrupt flags */ - volatile uint32_t interrupt_flag_buffer; - /* Buffer to store acknowledged interrupt sources */ - volatile uint32_t interrupt_flag_ack_buffer; - - /* Interrup hook linked list start pointer */ - struct events_hook *hook_list; -#endif -}; - -#endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/a280628a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_hooks.c ---------------------------------------------------------------------- diff --git a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_hooks.c b/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_hooks.c deleted file mode 100755 index e10f555..0000000 --- a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_hooks.c +++ /dev/null @@ -1,235 +0,0 @@ -/* - * \file - * - * \brief SAM Event System Controller Driver - * - * Copyright (C) 2014-2015 Atmel Corporation. All rights reserved. - * - * \asf_license_start - * - * \page License - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The name of Atmel may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * 4. This software may only be redistributed and used in connection with an - * Atmel microcontroller product. - * - * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE - * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * \asf_license_stop - * - */ -/* - * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> - */ -#include "events.h" -#include "events_hooks.h" -#include "system_interrupt.h" - -#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) -# define _EVENTS_INTFLAGS_DETECT 0x0fff0000 -# define _EVENTS_INTFLAGS_OVERRUN 0x00000fff -#else -# define _EVENTS_INTFLAGS_DETECT 0x0f00ff00 -# define _EVENTS_INTFLAGS_OVERRUN 0x000f00ff -#endif -#define _EVENTS_INTFLAGS_MASK (_EVENTS_INTFLAGS_DETECT | _EVENTS_INTFLAGS_OVERRUN) - -extern struct _events_module _events_inst; - -enum status_code events_create_hook(struct events_hook *hook, events_interrupt_hook func) -{ - /* Initialize the hook struct members */ - hook->next = NULL; - hook->resource = NULL; - hook->hook_func = func; - - return STATUS_OK; -} - -enum status_code events_add_hook(struct events_resource *resource, struct events_hook *hook) -{ - struct events_hook *tmp_hook = NULL; - - /* Associate the hook with the resource */ - hook->resource = resource; - - /* Check if this is the first hook in the list */ - if (_events_inst.hook_list == NULL) { - _events_inst.hook_list = hook; - } else { - tmp_hook = _events_inst.hook_list; - - /* Find the first free place in the list */ - while (tmp_hook->next != NULL) { - tmp_hook = tmp_hook->next; - } - - /* Put the hook into the next free place in the list */ - tmp_hook->next = hook; - } - - /* Check if interrupts from the EVSYS module is enabled in the interrupt controller */ - if (!system_interrupt_is_enabled(SYSTEM_INTERRUPT_MODULE_EVSYS)) { - system_interrupt_enable(SYSTEM_INTERRUPT_MODULE_EVSYS); - } - - return STATUS_OK; -} - -enum status_code events_del_hook(struct events_resource *resource, struct events_hook *hook) -{ - struct events_hook *tmp_hook = _events_inst.hook_list; - struct events_hook *last_hook = NULL; - - if (tmp_hook != NULL) { - /* Check if the first hook in the list is the one we are looking for */ - if (tmp_hook != hook) { - /* Don't double check the first hook */ - tmp_hook = tmp_hook->next; - - /* Check if the current hook is the one we are looking for */ - while (tmp_hook != hook) { - - /* If the current hook pointer is NULL the hook is not found in the list */ - if(tmp_hook == NULL) { - return STATUS_ERR_NOT_FOUND; - } - - last_hook = tmp_hook; - tmp_hook = tmp_hook->next; - - } - /* Remove the current hook from the list */ - last_hook->next = tmp_hook->next; - } else { - _events_inst.hook_list = tmp_hook->next; - } - } else { - /* No hooks where found in the list */ - return STATUS_ERR_NO_MEMORY; - } - - return STATUS_OK; -} - -enum status_code events_enable_interrupt_source(struct events_resource *resource, enum events_interrupt_source source) -{ - Assert((source == EVENTS_INTERRUPT_DETECT) || (source == EVENTS_INTERRUPT_OVERRUN)); - - if (source == EVENTS_INTERRUPT_DETECT) { - EVSYS->INTENSET.reg = _events_find_bit_position(resource->channel, - _EVENTS_START_OFFSET_DETECTION_BIT); - } else if (source == EVENTS_INTERRUPT_OVERRUN) { - EVSYS->INTENSET.reg = _events_find_bit_position(resource->channel, - _EVENTS_START_OFFSET_OVERRUN_BIT); - } else { - return STATUS_ERR_INVALID_ARG; - } - - return STATUS_OK; -} - -enum status_code events_disable_interrupt_source(struct events_resource *resource, enum events_interrupt_source source) -{ - Assert((source == EVENTS_INTERRUPT_DETECT) || (source == EVENTS_INTERRUPT_OVERRUN)); - - if (source == EVENTS_INTERRUPT_DETECT) { - EVSYS->INTENCLR.reg = _events_find_bit_position(resource->channel, - _EVENTS_START_OFFSET_DETECTION_BIT); - } else if (source == EVENTS_INTERRUPT_OVERRUN) { - EVSYS->INTENCLR.reg = _events_find_bit_position(resource->channel, - _EVENTS_START_OFFSET_OVERRUN_BIT); - } else { - return STATUS_ERR_INVALID_ARG; - } - - return STATUS_OK; -} - - -bool events_is_interrupt_set(struct events_resource *resource, enum events_interrupt_source source) -{ - Assert((source == EVENTS_INTERRUPT_DETECT) || (source == EVENTS_INTERRUPT_OVERRUN)); - - uint32_t bitpos; - - if (source == EVENTS_INTERRUPT_DETECT) { - bitpos = _events_find_bit_position(resource->channel, - _EVENTS_START_OFFSET_DETECTION_BIT); - } else if (source == EVENTS_INTERRUPT_OVERRUN) { - bitpos = _events_find_bit_position(resource->channel, - _EVENTS_START_OFFSET_OVERRUN_BIT); - } else { - return false; - } - - return (bool)(_events_inst.interrupt_flag_buffer & bitpos); -} - -enum status_code events_ack_interrupt(struct events_resource *resource, enum events_interrupt_source source) -{ - Assert((source == EVENTS_INTERRUPT_DETECT) || (source == EVENTS_INTERRUPT_OVERRUN)); - - uint32_t bitpos; - - if (source == EVENTS_INTERRUPT_DETECT) { - bitpos = _events_find_bit_position(resource->channel, - _EVENTS_START_OFFSET_DETECTION_BIT); - } else if (source == EVENTS_INTERRUPT_OVERRUN) { - bitpos = _events_find_bit_position(resource->channel, - _EVENTS_START_OFFSET_OVERRUN_BIT); - } else { - return STATUS_ERR_INVALID_ARG; - } - - _events_inst.interrupt_flag_ack_buffer |= bitpos; - - return STATUS_OK; -} - -void EVSYS_Handler(void) -{ - struct events_hook *current_hook = _events_inst.hook_list; - uint32_t flag; - - /* Synch the interrupt flag buffer with the hardware register */ - flag = EVSYS->INTFLAG.reg; - _events_inst.interrupt_flag_buffer |= flag; - /* Clear all hardware interrupt flags */ - EVSYS->INTFLAG.reg = _EVENTS_INTFLAGS_MASK; - - /* Traverse the linked list */ - while (current_hook != NULL) { - current_hook->hook_func(current_hook->resource); - current_hook = current_hook->next; - } - - /* Clear acknowledged interrupt sources from the interrupt flag buffer */ - flag = _events_inst.interrupt_flag_ack_buffer; - _events_inst.interrupt_flag_buffer &= ~flag; -} - - - http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/a280628a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_hooks.h ---------------------------------------------------------------------- diff --git a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_hooks.h b/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_hooks.h deleted file mode 100755 index 5edfef5..0000000 --- a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_hooks.h +++ /dev/null @@ -1,182 +0,0 @@ -/** - * \file - * - * \brief SAM Event System Driver - * - * Copyright (C) 2014-2015 Atmel Corporation. All rights reserved. - * - * \asf_license_start - * - * \page License - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The name of Atmel may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * 4. This software may only be redistributed and used in connection with an - * Atmel microcontroller product. - * - * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE - * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * \asf_license_stop - * - */ -/* - * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> - */ - -#include "events.h" - -#ifndef _EVENTS_HOOKS_H_INCLUDED_ -#define _EVENTS_HOOKS_H_INCLUDED_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * \addtogroup asfdoc_sam0_events_group - * @{ - * - */ - -/** - * \brief Interrupt source enumerator. - * - * Interrupt source selector definitions. - * - */ -enum events_interrupt_source { - /** Overrun in event channel detected interrupt */ - EVENTS_INTERRUPT_OVERRUN, - /** Event signal propagation in event channel detected interrupt */ - EVENTS_INTERRUPT_DETECT, -}; - -/** - * \brief Initializes an interrupt hook for insertion in the event interrupt hook queue. - * - * Initializes a hook structure so it is ready for insertion in the interrupt hook queue. - * - * \param[out] hook Pointer to an \ref events_hook struct instance - * \param[in] hook_func Pointer to a function containing the interrupt hook code - * - * \return Status of the hook creation procedure. - * \retval STATUS_OK Creation and initialization of interrupt hook went successful - * - */ -enum status_code events_create_hook(struct events_hook *hook, events_interrupt_hook hook_func); - -/** - * \brief Insert hook into the event drivers interrupt hook queue. - * - * Inserts a hook into the event drivers interrupt hook queue. - * - * \param[in] resource Pointer to an \ref events_resource struct instance - * \param[in] hook Pointer to an \ref events_hook struct instance - * - * \return Status of the insertion procedure. - * \retval STATUS_OK Insertion of hook went successful - * - */ -enum status_code events_add_hook(struct events_resource *resource, struct events_hook *hook); - -/** - * \brief Remove hook from the event drivers interrupt hook queue. - * - * Removes a hook from the event drivers interrupt hook queue. - * - * \param[in] resource Pointer to an \ref events_resource struct instance - * \param[in] hook Pointer to an \ref events_hook struct instance - * - * \return Status of the removal procedure. - * \retval STATUS_OK Removal of hook went successful - * \retval STATUS_ERR_NO_MEMORY There are no hooks instances in the event driver interrupt hook list - * \retval STATUS_ERR_NOT_FOUND Interrupt hook not found in the event drivers interrupt hook list - * - */ -enum status_code events_del_hook(struct events_resource *resource, struct events_hook *hook); - -/** - * \brief Enable interrupt source. - * - * Enable an interrupt source so can trigger execution of an interrupt hook. - * - * \param[in] resource Pointer to an \ref events_resource struct instance - * \param[in] source One of the members in the \ref events_interrupt_source enumerator - * - * \return Status of the interrupt source enable procedure. - * \retval STATUS_OK Enabling of the interrupt source went successful - * \retval STATUS_ERR_INVALID_ARG Interrupt source does not exist - * - */ -enum status_code events_enable_interrupt_source(struct events_resource *resource, enum events_interrupt_source source); - -/** - * \brief Disable interrupt source. - * - * Disable an interrupt source so can trigger execution of an interrupt hook. - * - * \param[in] resource Pointer to an \ref events_resource struct instance - * \param[in] source One of the members in the \ref events_interrupt_source enumerator - * - * \return Status of the interrupt source enable procedure. - * \retval STATUS_OK Enabling of the interrupt source went successful - * \retval STATUS_ERR_INVALID_ARG Interrupt source does not exist - * - */ -enum status_code events_disable_interrupt_source(struct events_resource *resource, enum events_interrupt_source source); - -/** - * \brief Check if interrupt source is set. - * - * Check if an interrupt source is set and should be processed. - * - * \param[in] resource Pointer to an \ref events_resource struct instance - * \param[in] source One of the members in the \ref events_interrupt_source enumerator - * - * \return Status of the interrupt source. - * \retval true Interrupt source is set - * \retval false Interrupt source is not set - * - */ -bool events_is_interrupt_set(struct events_resource *resource, enum events_interrupt_source source); - -/** - * \brief Acknowledge an interrupt source. - * - * Acknowledge an interrupt source so the interrupt state is cleared in hardware. - * - * \param[in] resource Pointer to an \ref events_resource struct instance - * \param[in] source One of the members in the \ref events_interrupt_source enumerator - * - * \return Status of the interrupt source. - * \retval STATUS_OK Interrupt source was acknowledged successfully - * - */ -enum status_code events_ack_interrupt(struct events_resource *resource, enum events_interrupt_source source); - -#ifdef __cplusplus -} -#endif - -#endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/a280628a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_sam_d_r/events.c ---------------------------------------------------------------------- diff --git a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_sam_d_r/events.c b/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_sam_d_r/events.c deleted file mode 100755 index b2180b9..0000000 --- a/hw/mcu/atmel/samd21xx/src/sam0/drivers/events/events_sam_d_r/events.c +++ /dev/null @@ -1,328 +0,0 @@ -/* - * \file - * - * \brief SAM Event System Controller Driver - * - * Copyright (C) 2013-2015 Atmel Corporation. All rights reserved. - * - * \asf_license_start - * - * \page License - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The name of Atmel may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * 4. This software may only be redistributed and used in connection with an - * Atmel microcontroller product. - * - * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE - * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * \asf_license_stop - * - */ -/* - * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> - */ - -#include <events.h> -#include <system.h> -#include <system_interrupt.h> -#include <status_codes.h> - -#define EVENTS_INVALID_CHANNEL 0xff - -struct _events_module _events_inst = { - .allocated_channels = 0, - .free_channels = EVSYS_CHANNELS, - -#if EVENTS_INTERRUPT_HOOKS_MODE == true - .interrupt_flag_buffer = 0, - .interrupt_flag_ack_buffer = 0, - - .hook_list = NULL, -#endif -}; - -/** - * \internal - * - */ -uint32_t _events_find_bit_position(uint8_t channel, uint8_t start_offset) -{ - uint32_t pos; - - if (channel < _EVENTS_START_OFFSET_BUSY_BITS) { - pos = 0x01UL << (start_offset + channel); - } else { - pos = 0x01UL << (start_offset + channel + _EVENTS_START_OFFSET_BUSY_BITS); - } - - return pos; -} - -static uint8_t _events_find_first_free_channel_and_allocate(void) -{ - uint8_t count; - uint32_t tmp; - bool allocated = false; - - system_interrupt_enter_critical_section(); - - tmp = _events_inst.allocated_channels; - - for(count = 0; count < EVSYS_CHANNELS; ++count) { - - if(!(tmp & 0x00000001)) { - /* If free channel found, set as allocated and return number */ - - _events_inst.allocated_channels |= 1 << count; - _events_inst.free_channels--; - allocated = true; - - break; - - } - - tmp = tmp >> 1; - } - - system_interrupt_leave_critical_section(); - - if(!allocated) { - return EVENTS_INVALID_CHANNEL; - } else { - return count; - } -} - -static void _events_release_channel(uint8_t channel) -{ - system_interrupt_enter_critical_section(); - - _events_inst.allocated_channels &= ~(1 << channel); - _events_inst.free_channels++; - - system_interrupt_leave_critical_section(); -} - - -/* This function is called by the system_init function, but should not be a public API call */ -#if defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wmissing-prototypes" -#endif -void _system_events_init(void) -{ - /* Enable EVSYS register interface */ - system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBC, PM_APBCMASK_EVSYS); - - /* Make sure the EVSYS module is properly reset */ - EVSYS->CTRL.reg = EVSYS_CTRL_SWRST; - - while (EVSYS->CTRL.reg & EVSYS_CTRL_SWRST) { - } -} -#if defined(__GNUC__) -# pragma GCC diagnostic pop -#endif - -void events_get_config_defaults(struct events_config *config) -{ - /* Check that config is something other than NULL */ - Assert(config); - - config->edge_detect = EVENTS_EDGE_DETECT_RISING; - config->path = EVENTS_PATH_SYNCHRONOUS; - config->generator = EVSYS_ID_GEN_NONE; - config->clock_source = GCLK_GENERATOR_0; -} - -enum status_code events_allocate( - struct events_resource *resource, - struct events_config *config) -{ - uint8_t new_channel; - - Assert(resource); - - new_channel = _events_find_first_free_channel_and_allocate(); - - if(new_channel == EVENTS_INVALID_CHANNEL) { - return STATUS_ERR_NOT_FOUND; - } - - resource->channel = new_channel; - - if (config->path != EVENTS_PATH_ASYNCHRONOUS) { - /* Set up a GLCK channel to use with the specific channel */ - struct system_gclk_chan_config gclk_chan_conf; - - system_gclk_chan_get_config_defaults(&gclk_chan_conf); - gclk_chan_conf.source_generator = - (enum gclk_generator)config->clock_source; - system_gclk_chan_set_config(EVSYS_GCLK_ID_0 + new_channel, &gclk_chan_conf); - system_gclk_chan_enable(EVSYS_GCLK_ID_0 + new_channel); - } - - /* Save channel setting and configure it after user multiplexer */ - resource->channel_reg = EVSYS_CHANNEL_CHANNEL(new_channel) | - EVSYS_CHANNEL_EVGEN(config->generator) | - EVSYS_CHANNEL_PATH(config->path) | - EVSYS_CHANNEL_EDGSEL(config->edge_detect); - - - return STATUS_OK; -} - - -enum status_code events_release(struct events_resource *resource) -{ - enum status_code err = STATUS_OK; - - Assert(resource); - - /* Check if channel is busy */ - if(events_is_busy(resource)) { - return STATUS_BUSY; - } - - if (!(_events_inst.allocated_channels & (1<<resource->channel))) { - err = STATUS_ERR_NOT_INITIALIZED; - } else { - _events_release_channel(resource->channel); - } - - return err; -} - -enum status_code events_trigger(struct events_resource *resource) -{ - - Assert(resource); - - system_interrupt_enter_critical_section(); - - /* Because of indirect access the channel must be set first */ - ((uint8_t*)&EVSYS->CHANNEL)[0] = EVSYS_CHANNEL_CHANNEL(resource->channel); - - /* Assert if event path is asynchronous */ - if (EVSYS->CHANNEL.reg & EVSYS_CHANNEL_PATH(EVENTS_PATH_ASYNCHRONOUS)) { - return STATUS_ERR_UNSUPPORTED_DEV; - } - - /* Assert if event edge detection is not set to RISING */ - if (!(EVSYS->CHANNEL.reg & EVSYS_CHANNEL_EDGSEL(EVENTS_EDGE_DETECT_RISING))) { - return STATUS_ERR_UNSUPPORTED_DEV; - } - - - /* The GCLKREQ bit has to be set while triggering the software event */ - EVSYS->CTRL.reg = EVSYS_CTRL_GCLKREQ; - - ((uint16_t*)&EVSYS->CHANNEL)[0] = EVSYS_CHANNEL_CHANNEL(resource->channel) | - EVSYS_CHANNEL_SWEVT; - - EVSYS->CTRL.reg &= ~EVSYS_CTRL_GCLKREQ; - - system_interrupt_leave_critical_section(); - - return STATUS_OK; -} - -bool events_is_busy(struct events_resource *resource) -{ - Assert(resource); - - return EVSYS->CHSTATUS.reg & (_events_find_bit_position(resource->channel, - _EVENTS_START_OFFSET_BUSY_BITS)); -} - -bool events_is_users_ready(struct events_resource *resource) -{ - Assert(resource); - - return EVSYS->CHSTATUS.reg & (_events_find_bit_position(resource->channel, - _EVENTS_START_OFFSET_USER_READY_BIT)); -} - -bool events_is_detected(struct events_resource *resource) -{ - Assert(resource); - - uint32_t flag = _events_find_bit_position(resource->channel, - _EVENTS_START_OFFSET_DETECTION_BIT); - - /* Clear flag when read */ - if (EVSYS->INTFLAG.reg & flag) { - EVSYS->INTFLAG.reg = flag; - return true; - } - - return false; -} - -bool events_is_overrun(struct events_resource *resource) -{ - Assert(resource); - - uint32_t flag = _events_find_bit_position(resource->channel, - _EVENTS_START_OFFSET_OVERRUN_BIT); - - /* Clear flag when read */ - if (EVSYS->INTFLAG.reg & flag) { - EVSYS->INTFLAG.reg = flag; - return true; - } - - return false; -} - -enum status_code events_attach_user(struct events_resource *resource, uint8_t user_id) -{ - Assert(resource); - - /* First configure user multiplexer: channel number is n + 1 */ - EVSYS->USER.reg = EVSYS_USER_CHANNEL(resource->channel + 1) | - EVSYS_USER_USER(user_id); - - /* Then configure the channel */ - EVSYS->CHANNEL.reg = resource->channel_reg; - - return STATUS_OK; -} - -enum status_code events_detach_user(struct events_resource *resource, uint8_t user_id) -{ - - Assert(resource); - - /* Write 0 to the channel bit field to select no input */ - EVSYS->USER.reg = EVSYS_USER_USER(user_id); - - return STATUS_OK; -} - -uint8_t events_get_free_channels() -{ - return _events_inst.free_channels; -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/a280628a/hw/mcu/atmel/samd21xx/src/sam0/drivers/extint/extint.h ---------------------------------------------------------------------- diff --git a/hw/mcu/atmel/samd21xx/src/sam0/drivers/extint/extint.h b/hw/mcu/atmel/samd21xx/src/sam0/drivers/extint/extint.h deleted file mode 100755 index be1ab10..0000000 --- a/hw/mcu/atmel/samd21xx/src/sam0/drivers/extint/extint.h +++ /dev/null @@ -1,707 +0,0 @@ -/** - * \file - * - * \brief SAM External Interrupt Driver - * - * Copyright (C) 2012-2015 Atmel Corporation. All rights reserved. - * - * \asf_license_start - * - * \page License - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The name of Atmel may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * 4. This software may only be redistributed and used in connection with an - * Atmel microcontroller product. - * - * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE - * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * \asf_license_stop - * - */ -/* - * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> - */ -#ifndef EXTINT_H_INCLUDED -#define EXTINT_H_INCLUDED - -/** - * \defgroup asfdoc_sam0_extint_group SAM External Interrupt (EXTINT) Driver - * - * This driver for Atmel® | SMART ARM®-based microcontrollers provides - * an interface for the configuration and management of external interrupts - * generated by the physical device pins, including edge detection. - * The following driver API modes are covered by this - * manual: - * - * - Polled APIs - * \if EXTINT_CALLBACK_MODE - * - Callback APIs - * \endif - * - * The following peripheral is used by this module: - * - EIC (External Interrupt Controller) - * - * The following devices can use this module: - * - Atmel | SMART SAM D20/D21 - * - Atmel | SMART SAM R21 - * - Atmel | SMART SAM D09/D10/D11 - * - Atmel | SMART SAM L21/L22 - * - Atmel | SMART SAM DA1 - * - Atmel | SMART SAM C20/C21 - * - * The outline of this documentation is as follows: - * - \ref asfdoc_sam0_extint_prerequisites - * - \ref asfdoc_sam0_extint_module_overview - * - \ref asfdoc_sam0_extint_special_considerations - * - \ref asfdoc_sam0_extint_extra_info - * - \ref asfdoc_sam0_extint_examples - * - \ref asfdoc_sam0_extint_api_overview - * - * - * \section asfdoc_sam0_extint_prerequisites Prerequisites - * - * There are no prerequisites for this module. - * - * - * \section asfdoc_sam0_extint_module_overview Module Overview - * - * The External Interrupt (EXTINT) module provides a method of asynchronously - * detecting rising edge, falling edge, or specific level detection on individual - * I/O pins of a device. This detection can then be used to trigger a software - * interrupt or event, or polled for later use if required. External interrupts - * can also optionally be used to automatically wake up the device from sleep - * mode, allowing the device to conserve power while still being able to react - * to an external stimulus in a timely manner. - * - * \subsection asfdoc_sam0_extint_logical_channels Logical Channels - * The External Interrupt module contains a number of logical channels, each of - * which is capable of being individually configured for a given pin routing, - * detection mode, and filtering/wake up characteristics. - * - * Each individual logical external interrupt channel may be routed to a single - * physical device I/O pin in order to detect a particular edge or level of the - * incoming signal. - * - * \subsection asfdoc_sam0_extint_module_overview_nmi_chanel NMI Channels - * - * One or more Non Maskable Interrupt (NMI) channels are provided within each - * physical External Interrupt Controller module, allowing a single physical pin - * of the device to fire a single NMI interrupt in response to a particular - * edge or level stimulus. An NMI cannot, as the name suggests, be disabled in - * firmware and will take precedence over any in-progress interrupt sources. - * - * NMIs can be used to implement critical device features such as forced - * software reset or other functionality where the action should be executed in - * preference to all other running code with a minimum amount of latency. - * - * \subsection asfdoc_sam0_extint_module_overview_filtering Input Filtering and Detection - * - * To reduce the possibility of noise or other transient signals causing - * unwanted device wake-ups, interrupts, and/or events via an external interrupt - * channel. A hardware signal filter can be enabled on individual channels. This - * filter provides a Majority-of-Three voter filter on the incoming signal, so - * that the input state is considered to be the majority vote of three - * subsequent samples of the pin input buffer. The possible sampled input and - * resulting filtered output when the filter is enabled is shown in - * \ref asfdoc_sam0_extint_filter_table "the table below". - * - * \anchor asfdoc_sam0_extint_filter_table - * <table> - * <caption>Sampled Input and Resulting Filtered Output</caption> - * <tr> - * <th>Input Sample 1</th> - * <th>Input Sample 2</th> - * <th>Input Sample 3</th> - * <th>Filtered Output</th> - * </tr> - * <tr> - * <td>0</td> <td>0</td> <td>0</td> <td>0</td> - * </tr> - * <tr> - * <td>0</td> <td>0</td> <td>1</td> <td>0</td> - * </tr> - * <tr> - * <td>0</td> <td>1</td> <td>0</td> <td>0</td> - * </tr> - * <tr> - * <td>0</td> <td>1</td> <td>1</td> <td>1</td> - * </tr> - * <tr> - * <td>1</td> <td>0</td> <td>0</td> <td>0</td> - * </tr> - * <tr> - * <td>1</td> <td>0</td> <td>1</td> <td>1</td> - * </tr> - * <tr> - * <td>1</td> <td>1</td> <td>0</td> <td>1</td> - * </tr> - * <tr> - * <td>1</td> <td>1</td> <td>1</td> <td>1</td> - * </tr> - * </table> - * - * \subsection asfdoc_sam0_extint_module_overview_events Events and Interrupts - * - * Channel detection states may be polled inside the application for synchronous - * detection, or events and interrupts may be used for asynchronous behavior. - * Each channel can be configured to give an asynchronous hardware event (which - * may in turn trigger actions in other hardware modules) or an asynchronous - * software interrupt. - * - * \note The connection of events between modules requires the use of the - * \ref asfdoc_sam0_events_group "SAM Event System Driver (EVENTS)" - * to route output event of one module to the input event of another. - * For more information on event routing, refer to the event driver - * documentation. - * - * \subsection asfdoc_sam0_extint_module_overview_physical Physical Connection - * - * \ref asfdoc_sam0_extint_int_connections "The diagram below" shows how this - * module is interconnected within the device. - * - * \anchor asfdoc_sam0_extint_int_connections - * \dot - * digraph overview { - * node [label="Port Pad" shape=square] pad; - * - * subgraph driver { - * node [label="Peripheral MUX" shape=trapezium] pinmux; - * node [label="EIC Module" shape=ellipse] eic; - * node [label="Other Peripheral Modules" shape=ellipse style=filled fillcolor=lightgray] peripherals; - * } - * - * pinmux -> eic; - * pad -> pinmux; - * pinmux -> peripherals; - * } - * \enddot - * - * \section asfdoc_sam0_extint_special_considerations Special Considerations - * - * Not all devices support disabling of the NMI channel(s) detection mode - see - * your device datasheet. - * - * - * \section asfdoc_sam0_extint_extra_info Extra Information - * - * For extra information, see \ref asfdoc_sam0_extint_extra. This includes: - * - \ref asfdoc_sam0_extint_extra_acronyms - * - \ref asfdoc_sam0_extint_extra_dependencies - * - \ref asfdoc_sam0_extint_extra_errata - * - \ref asfdoc_sam0_extint_extra_history - * - * - * \section asfdoc_sam0_extint_examples Examples - * - * For a list of examples related to this driver, see - * \ref asfdoc_sam0_extint_exqsg. - * - * - * \section asfdoc_sam0_extint_api_overview API Overview - * @{ - */ - -#include <compiler.h> -#include <pinmux.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * \brief External interrupt edge detection configuration enum. - * - * Enum for the possible signal edge detection modes of the External - * Interrupt Controller module. - */ -enum extint_detect { - /** No edge detection. Not allowed as a NMI detection mode on some - * devices. */ - EXTINT_DETECT_NONE = 0, - /** Detect rising signal edges */ - EXTINT_DETECT_RISING = 1, - /** Detect falling signal edges */ - EXTINT_DETECT_FALLING = 2, - /** Detect both signal edges */ - EXTINT_DETECT_BOTH = 3, - /** Detect high signal levels */ - EXTINT_DETECT_HIGH = 4, - /** Detect low signal levels */ - EXTINT_DETECT_LOW = 5, -}; - -/** - * \brief External interrupt internal pull configuration enum. - * - * Enum for the possible pin internal pull configurations. - * - * \note Disabling the internal pull resistor is not recommended if the driver - * is used in interrupt (callback) mode, due the possibility of floating - * inputs generating continuous interrupts. - */ -enum extint_pull { - /** Internal pull-up resistor is enabled on the pin */ - EXTINT_PULL_UP = SYSTEM_PINMUX_PIN_PULL_UP, - /** Internal pull-down resistor is enabled on the pin */ - EXTINT_PULL_DOWN = SYSTEM_PINMUX_PIN_PULL_DOWN, - /** Internal pull resistor is disconnected from the pin */ - EXTINT_PULL_NONE = SYSTEM_PINMUX_PIN_PULL_NONE, -}; - -/** The EIC is clocked by GCLK_EIC. */ -#define EXTINT_CLK_GCLK 0 -/** The EIC is clocked by CLK_ULP32K. */ -#define EXTINT_CLK_ULP32K 1 - -/** - * \brief External Interrupt Controller channel configuration structure. - * - * Configuration structure for the edge detection mode of an external - * interrupt channel. - */ -struct extint_chan_conf { - /** GPIO pin the NMI should be connected to */ - uint32_t gpio_pin; - /** MUX position the GPIO pin should be configured to */ - uint32_t gpio_pin_mux; - /** Internal pull to enable on the input pin */ - enum extint_pull gpio_pin_pull; -#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) - /** Enable asynchronous edge detection. */ - bool enable_async_edge_detection; -#else - /** Wake up the device if the channel interrupt fires during sleep mode */ - bool wake_if_sleeping; -#endif - /** Filter the raw input signal to prevent noise from triggering an - * interrupt accidentally, using a three sample majority filter */ - bool filter_input_signal; - /** Edge detection mode to use */ - enum extint_detect detection_criteria; -}; - -/** - * \brief External Interrupt event enable/disable structure. - * - * Event flags for the \ref extint_enable_events() and - * \ref extint_disable_events(). - */ -struct extint_events { - /** If \c true, an event will be generated when an external interrupt - * channel detection state changes */ - bool generate_event_on_detect[32 * EIC_INST_NUM]; -}; - -/** - * \brief External Interrupt Controller NMI configuration structure. - * - * Configuration structure for the edge detection mode of an external - * interrupt NMI channel. - */ -struct extint_nmi_conf { - /** GPIO pin the NMI should be connected to */ - uint32_t gpio_pin; - /** MUX position the GPIO pin should be configured to */ - uint32_t gpio_pin_mux; - /** Internal pull to enable on the input pin */ - enum extint_pull gpio_pin_pull; - /** Filter the raw input signal to prevent noise from triggering an - * interrupt accidentally, using a three sample majority filter */ - bool filter_input_signal; - /** Edge detection mode to use. Not all devices support all possible - * detection modes for NMIs. - */ - enum extint_detect detection_criteria; -#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) - /** Enable asynchronous edge detection. */ - bool enable_async_edge_detection; -#endif -}; - -#if EXTINT_CALLBACK_MODE == true -/** Type definition for an EXTINT module callback function */ -typedef void (*extint_callback_t)(void); - -#ifndef EIC_NUMBER_OF_INTERRUPTS -# define EIC_NUMBER_OF_INTERRUPTS 16 -#endif -#endif - -#if !defined(__DOXYGEN__) -/** \internal - * Internal EXTINT module device instance structure definition. - */ -struct _extint_module -{ -# if EXTINT_CALLBACK_MODE == true - /** Asynchronous channel callback table, for user-registered handlers */ - extint_callback_t callbacks[EIC_NUMBER_OF_INTERRUPTS]; -# else - /** Dummy value to ensure the struct has at least one member */ - uint8_t _dummy; -# endif -}; - -/** - * \brief Retrieves the base EIC module address from a given channel number. - * - * Retrieves the base address of a EIC hardware module associated with the - * given external interrupt channel. - * - * \param[in] channel External interrupt channel index to convert - * - * \return Base address of the associated EIC module. - */ -static inline Eic * _extint_get_eic_from_channel( - const uint8_t channel) -{ - uint8_t eic_index = (channel / 32); - - if (eic_index < EIC_INST_NUM) { - /* Array of available EICs */ - Eic *const eics[EIC_INST_NUM] = EIC_INSTS; - - return eics[eic_index]; - } else { - Assert(false); - return NULL; - } -} - -/** - * \brief Retrieves the base EIC module address from a given NMI channel number. - * - * Retrieves the base address of a EIC hardware module associated with the - * given non-maskable external interrupt channel. - * - * \param[in] nmi_channel Non-Maskable interrupt channel index to convert - * - * \return Base address of the associated EIC module. - */ -static inline Eic * _extint_get_eic_from_nmi( - const uint8_t nmi_channel) -{ - uint8_t eic_index = nmi_channel; - - if (eic_index < EIC_INST_NUM) { - /* Array of available EICs */ - Eic *const eics[EIC_INST_NUM] = EIC_INSTS; - - return eics[eic_index]; - } else { - Assert(false); - return NULL; - } -} -#endif - -/** \name Event Management - * @{ - */ - -void extint_enable_events( - struct extint_events *const events); - -void extint_disable_events( - struct extint_events *const events); - -/** @} */ - -/** \name Configuration and Initialization (Channel) - * @{ - */ - -void extint_chan_get_config_defaults( - struct extint_chan_conf *const config); - -void extint_chan_set_config( - const uint8_t channel, - const struct extint_chan_conf *const config); - -/** @} */ - -/** \name Configuration and Initialization (NMI) - * @{ - */ - -/** - * \brief Initializes an External Interrupt NMI channel configuration structure to defaults. - * - * Initializes a given External Interrupt NMI channel configuration structure - * to a set of known default values. This function should be called on all new - * instances of these configuration structures before being modified by the - * user application. - * - * The default configuration is as follows: - * \li Input filtering disabled - * \li Detect falling edges of a signal - * \li Asynchronous edge detection is disabled - * - * \param[out] config Configuration structure to initialize to default values - */ -static inline void extint_nmi_get_config_defaults( - struct extint_nmi_conf *const config) -{ - /* Sanity check arguments */ - Assert(config); - - /* Default configuration values */ - config->gpio_pin = 0; - config->gpio_pin_mux = 0; - config->gpio_pin_pull = EXTINT_PULL_UP; - config->filter_input_signal = false; - config->detection_criteria = EXTINT_DETECT_FALLING; -#if (SAML21) || (SAML22) || (SAMC20) || (SAMC21) - config->enable_async_edge_detection = false; -#endif - -} - -enum status_code extint_nmi_set_config( - const uint8_t nmi_channel, - const struct extint_nmi_conf *const config); - -/** @} */ - -/** \name Detection testing and clearing (channel) - * @{ - */ - -/** - * \brief Retrieves the edge detection state of a configured channel. - * - * Reads the current state of a configured channel, and determines - * if the detection criteria of the channel has been met. - * - * \param[in] channel External Interrupt channel index to check - * - * \return Status of the requested channel's edge detection state. - * \retval true If the channel's edge/level detection criteria was met - * \retval false If the channel has not detected its configured criteria - */ -static inline bool extint_chan_is_detected( - const uint8_t channel) -{ - Eic *const eic_module = _extint_get_eic_from_channel(channel); - uint32_t eic_mask = (1UL << (channel % 32)); - - return (eic_module->INTFLAG.reg & eic_mask); -} - -/** - * \brief Clears the edge detection state of a configured channel. - * - * Clears the current state of a configured channel, readying it for - * the next level or edge detection. - * - * \param[in] channel External Interrupt channel index to check - */ -static inline void extint_chan_clear_detected( - const uint8_t channel) -{ - Eic *const eic_module = _extint_get_eic_from_channel(channel); - uint32_t eic_mask = (1UL << (channel % 32)); - - eic_module->INTFLAG.reg = eic_mask; -} - -/** @} */ - -/** \name Detection Testing and Clearing (NMI) - * @{ - */ - -/** - * \brief Retrieves the edge detection state of a configured NMI channel. - * - * Reads the current state of a configured NMI channel, and determines - * if the detection criteria of the NMI channel has been met. - * - * \param[in] nmi_channel External Interrupt NMI channel index to check - * - * \return Status of the requested NMI channel's edge detection state. - * \retval true If the NMI channel's edge/level detection criteria was met - * \retval false If the NMI channel has not detected its configured criteria - */ -static inline bool extint_nmi_is_detected( - const uint8_t nmi_channel) -{ - Eic *const eic_module = _extint_get_eic_from_nmi(nmi_channel); - - return (eic_module->NMIFLAG.reg & EIC_NMIFLAG_NMI); -} - -/** - * \brief Clears the edge detection state of a configured NMI channel. - * - * Clears the current state of a configured NMI channel, readying it for - * the next level or edge detection. - * - * \param[in] nmi_channel External Interrupt NMI channel index to check - */ -static inline void extint_nmi_clear_detected( - const uint8_t nmi_channel) -{ - Eic *const eic_module = _extint_get_eic_from_nmi(nmi_channel); - - eic_module->NMIFLAG.reg = EIC_NMIFLAG_NMI; -} - -/** @} */ - -#ifdef __cplusplus -} -#endif - -/** @} */ - -#if EXTINT_CALLBACK_MODE == true -# include "extint_callback.h" -#endif - -/** - * \page asfdoc_sam0_extint_extra Extra Information for EXTINT Driver - * - * \section asfdoc_sam0_extint_extra_acronyms Acronyms - * The table below presents the acronyms used in this module: - * - * <table> - * <tr> - * <th>Acronym</th> - * <th>Description</th> - * </tr> - * <tr> - * <td>EIC</td> - * <td>External Interrupt Controller</td> - * </tr> - * <tr> - * <td>MUX</td> - * <td>Multiplexer</td> - * </tr> - * <tr> - * <td>NMI</td> - * <td>Non-Maskable Interrupt</td> - * </tr> - * </table> - * - * - * \section asfdoc_sam0_extint_extra_dependencies Dependencies - * This driver has the following dependencies: - * - * - \ref asfdoc_sam0_system_pinmux_group "System Pin Multiplexer Driver" - * - * - * \section asfdoc_sam0_extint_extra_errata Errata - * There are no errata related to this driver. - * - * - * \section asfdoc_sam0_extint_extra_history Module History - * An overview of the module history is presented in the table below, with - * details on the enhancements and fixes made to the module since its first - * release. The current version of this corresponds to the newest version in - * the table. - * - * <table> - * <tr> - * <th>Changelog</th> - * </tr> - * <tr> - * <td> - * \li Driver updated to follow driver type convention - * \li Removed \c %extint_reset(), \c %extint_disable() and - * \c extint_enable() functions. Added internal function - * \c %_system_extint_init(). - * \li Added configuration EXTINT_CLOCK_SOURCE in conf_extint.h - * \li Removed configuration EXTINT_CALLBACKS_MAX in conf_extint.h, and - * added channel parameter in the register functions - * \c %extint_register_callback() and \c %extint_unregister_callback() - * </td> - * </tr> - * <tr> - * <td>Updated interrupt handler to clear interrupt flag before calling - * callback function</td> - * </tr> - * <tr> - * <td>Updated initialization function to also enable the digital interface - * clock to the module if it is disabled</td> - * </tr> - * <tr> - * <td>Initial Release</td> - * </tr> - * </table> - */ - -/** - * \page asfdoc_sam0_extint_exqsg Examples for EXTINT Driver - * - * This is a list of the available Quick Start guides (QSGs) and example - * applications for \ref asfdoc_sam0_extint_group. - * QSGs are simple examples with step-by-step instructions to configure and - * use this driver in a selection of use cases. Note that a QSG can be compiled - * as a standalone application or be added to the user application. - * - * - \subpage asfdoc_sam0_extint_basic_use_case - * \if EXTINT_CALLBACK_MODE - * - \subpage asfdoc_sam0_extint_callback_use_case - * \endif - * - * \page asfdoc_sam0_extint_document_revision_history Document Revision History - * - * <table> - * <tr> - * <th>Doc. Rev.</th> - * <th>Date</th> - * <th>Comments</th> - * </tr> - * <tr> - * <td>42112E</td> - * <td>12/2015</td> - * <td>Added support for SAM L21/L22, SAM C21, SAM D09, and SAM DA1</td> - * </tr> - * <tr> - * <td>42112D</td> - * <td>12/2014</td> - * <td>Added support for SAM R21 and SAM D10/D11</td> - * </tr> - * <tr> - * <td>42112C</td> - * <td>01/2014</td> - * <td>Added support for SAM D21</td> - * </tr> - * <tr> - * <td>42112B</td> - * <td>06/2013</td> - * <td>Added additional documentation on the event system. Corrected - * documentation typos.</td> - * </tr> - * <tr> - * <td>42112A</td> - * <td>06/2013</td> - * <td>Initial release</td> - * </tr> - * </table> - */ - -#endif