1    /*
     2     * Copyright (c) 2016, Texas Instruments Incorporated
     3     * All rights reserved.
     4     *
     5     * Redistribution and use in source and binary forms, with or without
     6     * modification, are permitted provided that the following conditions
     7     * are met:
     8     *
     9     * *  Redistributions of source code must retain the above copyright
    10     *    notice, this list of conditions and the following disclaimer.
    11     *
    12     * *  Redistributions in binary form must reproduce the above copyright
    13     *    notice, this list of conditions and the following disclaimer in the
    14     *    documentation and/or other materials provided with the distribution.
    15     *
    16     * *  Neither the name of Texas Instruments Incorporated nor the names of
    17     *    its contributors may be used to endorse or promote products derived
    18     *    from this software without specific prior written permission.
    19     *
    20     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    21     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    22     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    23     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    24     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    25     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    26     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    27     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    28     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    29     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    30     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    31     */
    32    
    33    /*!
    34     *  ======== GPIO for MSP430G2x01 ========
    35     *  MSP430 General Purpose Input Output Ports
    36     */
    37    metaonly module GPIO_MSP430G2x01 inherits IGPIO {
    38        /*!
    39         *  ======== create ========
    40         *  Create an instance of this peripheral.
    41         */
    42        create();
    43    
    44    instance:
    45       /*! Define an array to describe all device pins. The 1st dimension
    46        *  denotes the port, the second the pin on that port. On an
    47        *  MSP430G2x01 device, there are 8 + 2 = 10 pins total.
    48        */
    49    
    50        /* TODO: This here should really be a module-wide feature, rather than an instance feature,
    51         * however due to limitations in XDCtools 3.21.0.0 the data is located here */
    52        /* TODO: For this device the config variable definition has been moved into the
    53         * corresponding XS file due to its size. This needs a more consistent solution. */
    54        config DevicePin_t devicePins[2][8];
    55    
    56        /*! Implementation of Device Pin Functional Configuration */
    57        override config DevicePinFunctionSetting_t devicePinSetting[2][8];
    58    
    59        /*! Determine if each Register needs to be forced set or not */
    60        readonly config ForceSetDefaultRegister_t forceSetDefaultRegister[] =
    61        [
    62            { register : "P1OUT" , regForceSet : true  },
    63            { register : "P1SEL" , regForceSet : false },
    64            { register : "P1DIR" , regForceSet : true  },
    65            { register : "P1REN" , regForceSet : false },
    66            { register : "P1IES" , regForceSet : true },
    67            { register : "P1IFG" , regForceSet : true },
    68            { register : "P1IE"  , regForceSet : false },
    69            { register : "P2OUT" , regForceSet : true  },
    70            { register : "P2SEL" , regForceSet : false },
    71            { register : "P2DIR" , regForceSet : true  },
    72            { register : "P2REN" , regForceSet : false },
    73            { register : "P2IES" , regForceSet : true },
    74            { register : "P2IFG" , regForceSet : true },
    75            { register : "P2IE"  , regForceSet : false }
    76        ];
    77    
    78        /*
    79         *  GPIO Digital I/O Registers
    80         *
    81         *  One GIPO instance defines the configuration of an entire,
    82         *  8-bit wide digital I/O port.
    83         */
    84    
    85        /*! Port 1 Output Register */
    86        config GpioBits8PxOut_t P1OUT = {
    87            Bit0        : BIT0_OFF,
    88            Bit1        : BIT1_OFF,
    89            Bit2        : BIT2_OFF,
    90            Bit3        : BIT3_OFF,
    91            Bit4        : BIT4_OFF,
    92            Bit5        : BIT5_OFF,
    93            Bit6        : BIT6_OFF,
    94            Bit7        : BIT7_OFF
    95        };
    96    
    97        /*! Port 1 Port Select Register */
    98        config GpioBits8PxSel_t P1SEL = {
    99            Bit0        : BIT0_OFF,
   100            Bit1        : BIT1_OFF,
   101            Bit2        : BIT2_OFF,
   102            Bit3        : BIT3_OFF,
   103            Bit4        : BIT4_OFF,
   104            Bit5        : BIT5_OFF,
   105            Bit6        : BIT6_OFF,
   106            Bit7        : BIT7_OFF
   107        };
   108    
   109        /*! Port 1 Direction Register */
   110        config GpioBits8PxDir_t P1DIR = {
   111            Bit0        : BIT0_OFF,
   112            Bit1        : BIT1_OFF,
   113            Bit2        : BIT2_OFF,
   114            Bit3        : BIT3_OFF,
   115            Bit4        : BIT4_OFF,
   116            Bit5        : BIT5_OFF,
   117            Bit6        : BIT6_OFF,
   118            Bit7        : BIT7_OFF
   119        };
   120    
   121        /*! Port 1 Resistor Enable Register */
   122        config GpioBits8PxRen_t P1REN = {
   123            Bit0        : BIT0_OFF,
   124            Bit1        : BIT1_OFF,
   125            Bit2        : BIT2_OFF,
   126            Bit3        : BIT3_OFF,
   127            Bit4        : BIT4_OFF,
   128            Bit5        : BIT5_OFF,
   129            Bit6        : BIT6_OFF,
   130            Bit7        : BIT7_OFF
   131        };
   132    
   133        /*! Port 2 Output Register */
   134        config GpioBits8PxOut_t P2OUT = {
   135            Bit0        : BIT0_OFF,
   136            Bit1        : BIT1_OFF,
   137            Bit2        : BIT2_OFF,
   138            Bit3        : BIT3_OFF,
   139            Bit4        : BIT4_OFF,
   140            Bit5        : BIT5_OFF,
   141            Bit6        : BIT6_OFF,
   142            Bit7        : BIT7_OFF
   143        };
   144    
   145        /*! Port 2 Port Select Register */
   146        config GpioBits8PxSel_t P2SEL = {
   147            Bit0        : BIT0_OFF,
   148            Bit1        : BIT1_OFF,
   149            Bit2        : BIT2_OFF,
   150            Bit3        : BIT3_OFF,
   151            Bit4        : BIT4_OFF,
   152            Bit5        : BIT5_OFF,
   153            Bit6        : BIT6,         /* POR default for all 2xx devices */
   154            Bit7        : BIT7          /* POR default for all 2xx devices */
   155        };
   156    
   157        /*! Port 2 Direction Register */
   158        config GpioBits8PxDir_t P2DIR = {
   159            Bit0        : BIT0_OFF,
   160            Bit1        : BIT1_OFF,
   161            Bit2        : BIT2_OFF,
   162            Bit3        : BIT3_OFF,
   163            Bit4        : BIT4_OFF,
   164            Bit5        : BIT5_OFF,
   165            Bit6        : BIT6_OFF,
   166            Bit7        : BIT7_OFF
   167        };
   168    
   169        /*! Port 2 Resistor Enable Register */
   170        config GpioBits8PxRen_t P2REN = {
   171            Bit0        : BIT0_OFF,
   172            Bit1        : BIT1_OFF,
   173            Bit2        : BIT2_OFF,
   174            Bit3        : BIT3_OFF,
   175            Bit4        : BIT4_OFF,
   176            Bit5        : BIT5_OFF,
   177            Bit6        : BIT6_OFF,
   178            Bit7        : BIT7_OFF
   179        };
   180    }