]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained/libchip_samv7/source/pio.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained / libchip_samv7 / source / pio.c
diff --git a/FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained/libchip_samv7/source/pio.c b/FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained/libchip_samv7/source/pio.c
deleted file mode 100644 (file)
index 087aa78..0000000
+++ /dev/null
@@ -1,501 +0,0 @@
-/* ----------------------------------------------------------------------------\r
- *         SAM Software Package License\r
- * ----------------------------------------------------------------------------\r
- * Copyright (c) 2014, Atmel Corporation\r
- *\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions are met:\r
- *\r
- * - Redistributions of source code must retain the above copyright notice,\r
- * this list of conditions and the disclaimer below.\r
- *\r
- * Atmel's name may not be used to endorse or promote products derived from\r
- * this software without specific prior written permission.\r
- *\r
- * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
- * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- * ----------------------------------------------------------------------------\r
- */\r
-\r
-/** \file */\r
-\r
-/*----------------------------------------------------------------------------\r
- *        Headers\r
- *----------------------------------------------------------------------------*/\r
-#include "chip.h"\r
-\r
-/*----------------------------------------------------------------------------\r
- *        Local functions\r
- *----------------------------------------------------------------------------*/\r
-\r
-/**\r
- * \brief Configures one or more pin(s) of a PIO controller as being controlled by\r
- * peripheral A. Optionally, the corresponding internal pull-up(s) can be enabled.\r
- *\r
- * \param pio  Pointer to a PIO controller.\r
- * \param mask  Bitmask of one or more pin(s) to configure.\r
- * \param enablePullUp  Indicates if the pin(s) internal pull-up shall be\r
- *                      configured.\r
- */\r
-static void PIO_SetPeripheralA(\r
-    Pio *pio,\r
-    unsigned int mask,\r
-    unsigned char enablePullUp)\r
-{\r
-    unsigned int abcdsr;\r
-    /* Disable interrupts on the pin(s) */\r
-    pio->PIO_IDR = mask;\r
-\r
-    /* Enable the pull-up(s) if necessary */\r
-    if (enablePullUp) {\r
-        pio->PIO_PUER = mask;\r
-    }\r
-    else {\r
-\r
-        pio->PIO_PUDR = mask;\r
-    }\r
-\r
-    abcdsr = pio->PIO_ABCDSR[0];\r
-    pio->PIO_ABCDSR[0] &= (~mask & abcdsr);\r
-    abcdsr = pio->PIO_ABCDSR[1];\r
-    pio->PIO_ABCDSR[1] &= (~mask & abcdsr);\r
-    pio->PIO_PDR = mask;\r
-}\r
-\r
-/**\r
- * \brief Configures one or more pin(s) of a PIO controller as being controlled by\r
- * peripheral B. Optionally, the corresponding internal pull-up(s) can be enabled.\r
- *\r
- * \param pio  Pointer to a PIO controller.\r
- * \param mask  Bitmask of one or more pin(s) to configure.\r
- * \param enablePullUp  Indicates if the pin(s) internal pull-up shall be\r
- *                      configured.\r
- */\r
-static void PIO_SetPeripheralB(\r
-    Pio *pio,\r
-    unsigned int mask,\r
-    unsigned char enablePullUp)\r
-{\r
-    unsigned int abcdsr;\r
-    /* Disable interrupts on the pin(s) */\r
-    pio->PIO_IDR = mask;\r
-\r
-    /* Enable the pull-up(s) if necessary */\r
-    if (enablePullUp) {\r
-\r
-        pio->PIO_PUER = mask;\r
-    }\r
-    else {\r
-\r
-        pio->PIO_PUDR = mask;\r
-    }\r
-\r
-    abcdsr = pio->PIO_ABCDSR[0];\r
-    pio->PIO_ABCDSR[0] = (mask | abcdsr);\r
-    abcdsr = pio->PIO_ABCDSR[1];\r
-    pio->PIO_ABCDSR[1] &= (~mask & abcdsr);\r
-\r
-    pio->PIO_PDR = mask;\r
-}\r
-\r
-/**\r
- * \brief Configures one or more pin(s) of a PIO controller as being controlled by\r
- * peripheral C. Optionally, the corresponding internal pull-up(s) can be enabled.\r
- *\r
- * \param pio  Pointer to a PIO controller.\r
- * \param mask  Bitmask of one or more pin(s) to configure.\r
- * \param enablePullUp  Indicates if the pin(s) internal pull-up shall be\r
- *                      configured.\r
- */\r
-static void PIO_SetPeripheralC(\r
-    Pio *pio,\r
-    unsigned int mask,\r
-    unsigned char enablePullUp)\r
-{\r
-    unsigned int abcdsr;\r
-    /* Disable interrupts on the pin(s) */\r
-    pio->PIO_IDR = mask;\r
-\r
-    /* Enable the pull-up(s) if necessary */\r
-    if (enablePullUp) {\r
-\r
-        pio->PIO_PUER = mask;\r
-    }\r
-    else {\r
-\r
-        pio->PIO_PUDR = mask;\r
-    }\r
-\r
-    abcdsr = pio->PIO_ABCDSR[0];\r
-    pio->PIO_ABCDSR[0] &= (~mask & abcdsr);\r
-    abcdsr = pio->PIO_ABCDSR[1];\r
-    pio->PIO_ABCDSR[1] = (mask | abcdsr);\r
-\r
-    pio->PIO_PDR = mask;\r
-}\r
-\r
-/**\r
- * \brief Configures one or more pin(s) of a PIO controller as being controlled by\r
- * peripheral D. Optionally, the corresponding internal pull-up(s) can be enabled.\r
- *\r
- * \param pio  Pointer to a PIO controller.\r
- * \param mask  Bitmask of one or more pin(s) to configure.\r
- * \param enablePullUp  Indicates if the pin(s) internal pull-up shall be\r
- *                      configured.\r
- */\r
-static void PIO_SetPeripheralD(\r
-    Pio *pio,\r
-    unsigned int mask,\r
-    unsigned char enablePullUp)\r
-{\r
-    unsigned int abcdsr;\r
-    /* Disable interrupts on the pin(s) */\r
-    pio->PIO_IDR = mask;\r
-\r
-    /* Enable the pull-up(s) if necessary */\r
-    if (enablePullUp) {\r
-\r
-        pio->PIO_PUER = mask;\r
-    }\r
-    else {\r
-\r
-        pio->PIO_PUDR = mask;\r
-    }\r
-\r
-    abcdsr = pio->PIO_ABCDSR[0];\r
-    pio->PIO_ABCDSR[0] = (mask | abcdsr);\r
-    abcdsr = pio->PIO_ABCDSR[1];\r
-    pio->PIO_ABCDSR[1] = (mask | abcdsr);\r
-\r
-    pio->PIO_PDR = mask;\r
-}\r
-\r
-/**\r
- * \brief Configures one or more pin(s) or a PIO controller as inputs. Optionally,\r
- * the corresponding internal pull-up(s) and glitch filter(s) can be enabled.\r
- *\r
- * \param pio  Pointer to a PIO controller.\r
- * \param mask  Bitmask indicating which pin(s) to configure as input(s).\r
- * \param enablePullUp  Indicates if the internal pull-up(s) must be enabled.\r
- * \param enableFilter  Indicates if the glitch filter(s) must be enabled.\r
- */\r
-static void PIO_SetInput(\r
-    Pio *pio,\r
-    unsigned int mask,\r
-    unsigned char attribute)\r
-{\r
-    /* Disable interrupts */\r
-    pio->PIO_IDR = mask;\r
-\r
-    /* Enable pull-up(s) if necessary */\r
-    if (attribute & PIO_PULLUP)\r
-        pio->PIO_PUER = mask;\r
-    else\r
-        pio->PIO_PUDR = mask;\r
-\r
-    /* Enable Input Filter if necessary */\r
-    if (attribute & (PIO_DEGLITCH | PIO_DEBOUNCE))\r
-        pio->PIO_IFER = mask;\r
-    else\r
-        pio->PIO_IFDR = mask;\r
-\r
-    /* Enable de-glitch or de-bounce if necessary */\r
-    if (attribute & PIO_DEGLITCH)\r
-    {\r
-        pio->PIO_IFSCDR = mask;\r
-    }\r
-    else\r
-    {\r
-        if (attribute & PIO_DEBOUNCE)\r
-        {\r
-            pio->PIO_IFSCER = mask;\r
-        }\r
-    }\r
-\r
-    /* Configure pin as input */\r
-    pio->PIO_ODR = mask;\r
-    pio->PIO_PER = mask;\r
-}\r
-\r
-/**\r
- * \brief Configures one or more pin(s) of a PIO controller as outputs, with the\r
- * given default value. Optionally, the multi-drive feature can be enabled\r
- * on the pin(s).\r
- *\r
- * \param pio  Pointer to a PIO controller.\r
- * \param mask  Bitmask indicating which pin(s) to configure.\r
- * \param defaultValue  Default level on the pin(s).\r
- * \param enableMultiDrive  Indicates if the pin(s) shall be configured as\r
- *                          open-drain.\r
- * \param enablePullUp  Indicates if the pin shall have its pull-up activated.\r
- */\r
-static void PIO_SetOutput(\r
-    Pio *pio,\r
-    unsigned int mask,\r
-    unsigned char defaultValue,\r
-    unsigned char enableMultiDrive,\r
-    unsigned char enablePullUp)\r
-{\r
-    /* Disable interrupts */\r
-    pio->PIO_IDR = mask;\r
-\r
-    /* Enable pull-up(s) if necessary */\r
-    if (enablePullUp) {\r
-\r
-        pio->PIO_PUER = mask;\r
-    }\r
-    else {\r
-\r
-        pio->PIO_PUDR = mask;\r
-    }\r
-\r
-    /* Enable multi-drive if necessary */\r
-    if (enableMultiDrive) {\r
-\r
-        pio->PIO_MDER = mask;\r
-    }\r
-    else {\r
-\r
-        pio->PIO_MDDR = mask;\r
-    }\r
-\r
-    /* Set default value */\r
-    if (defaultValue) {\r
-\r
-        pio->PIO_SODR = mask;\r
-    }\r
-    else {\r
-\r
-        pio->PIO_CODR = mask;\r
-    }\r
-\r
-    /* Configure pin(s) as output(s) */\r
-    pio->PIO_OER = mask;\r
-    pio->PIO_PER = mask;\r
-}\r
-\r
-/*----------------------------------------------------------------------------\r
- *         Global functions\r
- *----------------------------------------------------------------------------*/\r
-\r
-/**\r
- * \brief Configures a list of Pin instances, each of which can either hold a single\r
- * pin or a group of pins, depending on the mask value; all pins are configured\r
- * by this function. The size of the array must also be provided and is easily\r
- * computed using PIO_LISTSIZE whenever its length is not known in advance.\r
- *\r
- * \param list  Pointer to a list of Pin instances.\r
- * \param size  Size of the Pin list (calculated using PIO_LISTSIZE).\r
- *\r
- * \return 1 if the pins have been configured properly; otherwise 0.\r
- */\r
-uint8_t PIO_Configure( const Pin *list, uint32_t size )\r
-{\r
-    /* Configure pins */\r
-    while ( size > 0 )\r
-    {\r
-        switch ( list->type )\r
-        {\r
-\r
-            case PIO_PERIPH_A:\r
-                PIO_SetPeripheralA(list->pio,\r
-                                   list->mask,\r
-                                   (list->attribute & PIO_PULLUP) ? 1 : 0);\r
-            break;\r
-\r
-            case PIO_PERIPH_B:\r
-                PIO_SetPeripheralB(list->pio,\r
-                                   list->mask,\r
-                                   (list->attribute & PIO_PULLUP) ? 1 : 0);\r
-            break;\r
-\r
-            case PIO_PERIPH_C:\r
-                PIO_SetPeripheralC(list->pio,\r
-                                   list->mask,\r
-                                   (list->attribute & PIO_PULLUP) ? 1 : 0);\r
-            break;\r
-\r
-            case PIO_PERIPH_D:\r
-                PIO_SetPeripheralD(list->pio,\r
-                                   list->mask,\r
-                                   (list->attribute & PIO_PULLUP) ? 1 : 0);\r
-            break;\r
-            case PIO_INPUT:\r
-#ifndef __FPGA\r
-                PMC_EnablePeripheral(list->id);\r
-#endif\r
-                PIO_SetInput(list->pio,\r
-                             list->mask,\r
-                             list->attribute);\r
-                break;\r
-\r
-            case PIO_OUTPUT_0:\r
-            case PIO_OUTPUT_1:\r
-                PIO_SetOutput(list->pio,\r
-                              list->mask,\r
-                              (list->type == PIO_OUTPUT_1),\r
-                              (list->attribute & PIO_OPENDRAIN) ? 1 : 0,\r
-                              (list->attribute & PIO_PULLUP) ? 1 : 0);\r
-                break;\r
-\r
-            default: return 0;\r
-        }\r
-\r
-        list++;\r
-        size--;\r
-    }\r
-\r
-    return 1;\r
-}\r
-\r
-/**\r
- * \brief Sets a high output level on all the PIOs defined in the given Pin instance.\r
- * This has no immediate effects on PIOs that are not output, but the PIO\r
- * controller will memorize the value they are changed to outputs.\r
- *\r
- * \param pin  Pointer to a Pin instance describing one or more pins.\r
- */\r
-void PIO_Set(const Pin *pin)\r
-{\r
-    pin->pio->PIO_SODR = pin->mask;\r
-}\r
-\r
-/**\r
- * \brief Sets a low output level on all the PIOs defined in the given Pin instance.\r
- * This has no immediate effects on PIOs that are not output, but the PIO\r
- * controller will memorize the value they are changed to outputs.\r
- *\r
- * \param pin  Pointer to a Pin instance describing one or more pins.\r
- */\r
-void PIO_Clear(const Pin *pin)\r
-{\r
-    pin->pio->PIO_CODR = pin->mask;\r
-}\r
-\r
-/**\r
- * \brief Returns 1 if one or more PIO of the given Pin instance currently have\r
- * a high level; otherwise returns 0. This method returns the actual value that\r
- * is being read on the pin. To return the supposed output value of a pin, use\r
- * PIO_GetOutputDataStatus() instead.\r
- *\r
- * \param pin  Pointer to a Pin instance describing one or more pins.\r
- *\r
- * \return 1 if the Pin instance contains at least one PIO that currently has\r
- * a high level; otherwise 0.\r
- */\r
-unsigned char PIO_Get( const Pin *pin )\r
-{\r
-    unsigned int reg ;\r
-\r
-    if ( (pin->type == PIO_OUTPUT_0) || (pin->type == PIO_OUTPUT_1) )\r
-    {\r
-        reg = pin->pio->PIO_ODSR ;\r
-    }\r
-    else\r
-    {\r
-        reg = pin->pio->PIO_PDSR ;\r
-    }\r
-\r
-    if ( (reg & pin->mask) == 0 )\r
-    {\r
-        return 0 ;\r
-    }\r
-    else\r
-    {\r
-        return 1 ;\r
-    }\r
-}\r
-\r
-/**\r
- * \brief Returns 1 if one or more PIO of the given Pin are configured to output a\r
- * high level (even if they are not output).\r
- * To get the actual value of the pin, use PIO_Get() instead.\r
- *\r
- * \param pin  Pointer to a Pin instance describing one or more pins.\r
- *\r
- * \return 1 if the Pin instance contains at least one PIO that is configured\r
- * to output a high level; otherwise 0.\r
- */\r
-unsigned char PIO_GetOutputDataStatus(const Pin *pin)\r
-{\r
-    if ((pin->pio->PIO_ODSR & pin->mask) == 0) {\r
-\r
-        return 0;\r
-    }\r
-    else {\r
-\r
-        return 1;\r
-    }\r
-}\r
-\r
-/*\r
- * \brief Configures Glitch or Debouncing filter for input.\r
- *\r
- * \param pin  Pointer to a Pin instance describing one or more pins.\r
- * \param cuttoff  Cutt off frequency for debounce filter.\r
- */\r
-void PIO_SetDebounceFilter( const Pin *pin, uint32_t cuttoff )\r
-{\r
-    Pio *pio = pin->pio;\r
-\r
-    pio->PIO_IFSCER = pin->mask; /* set Debouncing, 0 bit field no effect */\r
-    pio->PIO_SCDR = ((32678/(2*(cuttoff))) - 1) & 0x3FFF; /* the lowest 14 bits work */\r
-}\r
-\r
-/*\r
- * \brief Enable write protect.\r
- *\r
- * \param pin  Pointer to a Pin instance describing one or more pins.\r
- */\r
-void PIO_EnableWriteProtect( const Pin *pin )\r
-{\r
-   Pio *pio = pin->pio;\r
-\r
-   pio->PIO_WPMR = ( PIO_WPMR_WPKEY_VALID | PIO_WPMR_WPEN_EN );\r
-}\r
-\r
-/*\r
- * \brief Disable write protect.\r
- *\r
- * \param pin  Pointer to a Pin instance describing one or more pins.\r
- */\r
-\r
-void PIO_DisableWriteProtect( const Pin *pin )\r
-{\r
-   Pio *pio = pin->pio;\r
-\r
-   pio->PIO_WPMR = ( PIO_WPMR_WPKEY_VALID | PIO_WPMR_WPEN_DIS );\r
-}\r
-\r
-/*\r
- * \brief Get write protect violation information.\r
- *\r
- * \param pin  Pointer to a Pin instance describing one or more pins.\r
- */\r
-\r
-uint32_t PIO_GetWriteProtectViolationInfo( const Pin * pin )\r
-{\r
-    Pio *pio = pin->pio;\r
-    return (pio->PIO_WPSR);\r
-}\r
-/* \brief Set pin type\r
- * the pin is controlled by the corresponding peripheral (A, B, C, D,E)\r
- * \param pin      Pointer to a Pin instance describing one or more pins.\r
- * \param pinType  PIO_PERIPH_A, PIO_PERIPH_B, ...\r
- */\r
-\r
-void PIO_SetPinType( Pin * pin, uint8_t pinType)\r
-{\r
-    pin->type = pinType;\r
-}\r
-\r