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    import ti.catalog.msp430.peripherals.adc.ADC10 as ADC10;
    34    import ti.catalog.msp430.peripherals.comparator.IComparator as Comparator;
    35    import ti.catalog.msp430.peripherals.clock.BCSplus as BCSplus;
    36    
    37    /*!
    38     *  ======== GPIO for MSP430F21x2 ========
    39     *  MSP430 General Purpose Input Output Ports
    40     */
    41    metaonly module GPIO_MSP430F21x2 inherits IGPIO {
    42        /*!
    43         *  ======== create ========
    44         *  Create an instance of this peripheral. Use a customized
    45         *  init function so that we can get access to the ADC10,
    46         *  Comparator_A, and BCS+ instances.
    47         */
    48        create(ADC10.Instance adc10, Comparator.Instance comparator,
    49            BCSplus.Instance clock);
    50    
    51    instance:
    52        /*! @_nodoc */
    53        config ADC10.Instance adc10;
    54    
    55        /*! @_nodoc */
    56        config Comparator.Instance comparator;
    57    
    58        /*! @_nodoc */
    59        config BCSplus.Instance clock;
    60    
    61        /*! Define an array to describe all device pins. The 1st dimension
    62         *  denotes the port, the second the pin on that port. On an
    63         *  MSP430F21x2 device, there are 3 x 8 = 24 pins total.
    64         */
    65    
    66        /* TODO: This here should really be a module-wide feature, rather than an instance feature,
    67         * however due to limitations in XDCtools 3.21.0.0 the data is located here */
    68        /* TODO: For this device the config variable definition has been moved into the
    69         * corresponding XS file due to its size. This needs a more consistent solution. */
    70        config DevicePin_t devicePins[3][8];
    71    
    72        /*! Implementation of Device Pin Functional Configuration */
    73        override config DevicePinFunctionSetting_t devicePinSetting[3][8];
    74    
    75        /*! Determine if each Register needs to be forced set or not */
    76        readonly config ForceSetDefaultRegister_t forceSetDefaultRegister[] =
    77        [
    78            { register : "P1OUT" , regForceSet : true  },
    79            { register : "P1SEL" , regForceSet : false },
    80            { register : "P1SEL2", regForceSet : false },
    81            { register : "P1DIR" , regForceSet : true  },
    82            { register : "P1REN" , regForceSet : false },
    83            { register : "P1IES" , regForceSet : true },
    84            { register : "P1IFG" , regForceSet : true },
    85            { register : "P1IE"  , regForceSet : false },
    86            { register : "P2OUT" , regForceSet : true  },
    87            { register : "P2SEL" , regForceSet : false },
    88            { register : "P2SEL2", regForceSet : false },
    89            { register : "P2DIR" , regForceSet : true  },
    90            { register : "P2REN" , regForceSet : false },
    91            { register : "P2IES" , regForceSet : true },
    92            { register : "P2IFG" , regForceSet : true },
    93            { register : "P2IE"  , regForceSet : false },
    94            { register : "P3OUT" , regForceSet : true  },
    95            { register : "P3SEL" , regForceSet : false },
    96            { register : "P3DIR" , regForceSet : true  },
    97            { register : "P3REN" , regForceSet : false },
    98        ];
    99    
   100        /*
   101         *  GPIO Digital I/O Registers
   102         *
   103         *  One GIPO instance defines the configuration of an entire,
   104         *  8-bit wide digital I/O port.
   105         */
   106    
   107        /*! Port 1 Output Register */
   108        config GpioBits8PxOut_t P1OUT = {
   109            Bit0        : BIT0_OFF,
   110            Bit1        : BIT1_OFF,
   111            Bit2        : BIT2_OFF,
   112            Bit3        : BIT3_OFF,
   113            Bit4        : BIT4_OFF,
   114            Bit5        : BIT5_OFF,
   115            Bit6        : BIT6_OFF,
   116            Bit7        : BIT7_OFF
   117        };
   118    
   119        /*! Port 1 Port Select Register */
   120        config GpioBits8PxSel_t P1SEL = {
   121            Bit0        : BIT0_OFF,
   122            Bit1        : BIT1_OFF,
   123            Bit2        : BIT2_OFF,
   124            Bit3        : BIT3_OFF,
   125            Bit4        : BIT4_OFF,
   126            Bit5        : BIT5_OFF,
   127            Bit6        : BIT6_OFF,
   128            Bit7        : BIT7_OFF
   129        };
   130    
   131        /*! Port 1 Port Select 2 Register */
   132        config GpioBits8PxSel_t P1SEL2 = {
   133            Bit0        : BIT0_OFF,
   134            Bit1        : BIT1_OFF,
   135            Bit2        : BIT2_OFF,
   136            Bit3        : BIT3_OFF,
   137            Bit4        : BIT4_OFF,
   138            Bit5        : BIT5_OFF,
   139            Bit6        : BIT6_OFF,
   140            Bit7        : BIT7_OFF
   141        };
   142    
   143        /*! Port 1 Direction Register */
   144        config GpioBits8PxDir_t P1DIR = {
   145            Bit0        : BIT0_OFF,
   146            Bit1        : BIT1_OFF,
   147            Bit2        : BIT2_OFF,
   148            Bit3        : BIT3_OFF,
   149            Bit4        : BIT4_OFF,
   150            Bit5        : BIT5_OFF,
   151            Bit6        : BIT6_OFF,
   152            Bit7        : BIT7_OFF
   153        };
   154    
   155        /*! Port 1 Resistor Enable Register */
   156        config GpioBits8PxRen_t P1REN = {
   157            Bit0        : BIT0_OFF,
   158            Bit1        : BIT1_OFF,
   159            Bit2        : BIT2_OFF,
   160            Bit3        : BIT3_OFF,
   161            Bit4        : BIT4_OFF,
   162            Bit5        : BIT5_OFF,
   163            Bit6        : BIT6_OFF,
   164            Bit7        : BIT7_OFF
   165        };
   166    
   167        /*! Port 2 Output Register */
   168        config GpioBits8PxOut_t P2OUT = {
   169            Bit0        : BIT0_OFF,
   170            Bit1        : BIT1_OFF,
   171            Bit2        : BIT2_OFF,
   172            Bit3        : BIT3_OFF,
   173            Bit4        : BIT4_OFF,
   174            Bit5        : BIT5_OFF,
   175            Bit6        : BIT6_OFF,
   176            Bit7        : BIT7_OFF
   177        };
   178    
   179        /*! Port 2 Port Select Register */
   180        config GpioBits8PxSel_t P2SEL = {
   181            Bit0        : BIT0_OFF,
   182            Bit1        : BIT1_OFF,
   183            Bit2        : BIT2_OFF,
   184            Bit3        : BIT3_OFF,
   185            Bit4        : BIT4_OFF,
   186            Bit5        : BIT5_OFF,
   187            Bit6        : BIT6,         /* POR default for all 2xx devices */
   188            Bit7        : BIT7          /* POR default for all 2xx devices */
   189        };
   190    
   191        /*! Port 2 Port Select 2 Register */
   192        config GpioBits8PxSel2_t P2SEL2 = {
   193            Bit0        : BIT0_OFF,
   194            Bit1        : BIT1_OFF,
   195            Bit2        : BIT2_OFF,
   196            Bit3        : BIT3_OFF,
   197            Bit4        : BIT4_OFF,
   198            Bit5        : BIT5_OFF,
   199            Bit6        : BIT6_OFF,
   200            Bit7        : BIT7_OFF
   201        };
   202    
   203        /*! Port 2 Direction Register */
   204        config GpioBits8PxDir_t P2DIR = {
   205            Bit0        : BIT0_OFF,
   206            Bit1        : BIT1_OFF,
   207            Bit2        : BIT2_OFF,
   208            Bit3        : BIT3_OFF,
   209            Bit4        : BIT4_OFF,
   210            Bit5        : BIT5_OFF,
   211            Bit6        : BIT6_OFF,
   212            Bit7        : BIT7_OFF
   213        };
   214    
   215        /*! Port 2 Resistor Enable Register */
   216        config GpioBits8PxRen_t P2REN = {
   217            Bit0        : BIT0_OFF,
   218            Bit1        : BIT1_OFF,
   219            Bit2        : BIT2_OFF,
   220            Bit3        : BIT3_OFF,
   221            Bit4        : BIT4_OFF,
   222            Bit5        : BIT5_OFF,
   223            Bit6        : BIT6_OFF,
   224            Bit7        : BIT7_OFF
   225        };
   226    
   227        /*! Port 3 Output Register */
   228        config GpioBits8PxOut_t P3OUT = {
   229            Bit0        : BIT0_OFF,
   230            Bit1        : BIT1_OFF,
   231            Bit2        : BIT2_OFF,
   232            Bit3        : BIT3_OFF,
   233            Bit4        : BIT4_OFF,
   234            Bit5        : BIT5_OFF,
   235            Bit6        : BIT6_OFF,
   236            Bit7        : BIT7_OFF
   237        };
   238    
   239        /*! Port 3 Port Select Register */
   240        config GpioBits8PxSel_t P3SEL = {
   241            Bit0        : BIT0_OFF,
   242            Bit1        : BIT1_OFF,
   243            Bit2        : BIT2_OFF,
   244            Bit3        : BIT3_OFF,
   245            Bit4        : BIT4_OFF,
   246            Bit5        : BIT5_OFF,
   247            Bit6        : BIT6_OFF,
   248            Bit7        : BIT7_OFF
   249        };
   250    
   251        /*! Port 3 Direction Register */
   252        config GpioBits8PxDir_t P3DIR = {
   253            Bit0        : BIT0_OFF,
   254            Bit1        : BIT1_OFF,
   255            Bit2        : BIT2_OFF,
   256            Bit3        : BIT3_OFF,
   257            Bit4        : BIT4_OFF,
   258            Bit5        : BIT5_OFF,
   259            Bit6        : BIT6_OFF,
   260            Bit7        : BIT7_OFF
   261        };
   262    
   263        /*! Port 3 Resistor Enable Register */
   264        config GpioBits8PxRen_t P3REN = {
   265            Bit0        : BIT0_OFF,
   266            Bit1        : BIT1_OFF,
   267            Bit2        : BIT2_OFF,
   268            Bit3        : BIT3_OFF,
   269            Bit4        : BIT4_OFF,
   270            Bit5        : BIT5_OFF,
   271            Bit6        : BIT6_OFF,
   272            Bit7        : BIT7_OFF
   273        };
   274    }