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.comparator.IComparator as Comparator;
    34    import ti.catalog.msp430.peripherals.svs.ISVS as SVS;
    35    import ti.catalog.msp430.peripherals.clock.BCSplus as BCSplus;
    36    
    37    /*!
    38     *  ======== GPIO for MSP430F24x1 ========
    39     *  MSP430 General Purpose Input Output Ports
    40     */
    41    metaonly module GPIO_MSP430F24x1 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
    46         *  Comparator_A, SVS, and BCS+ instances.
    47         */
    48        create(Comparator.Instance comparator, SVS.Instance svs, BCSplus.Instance clock);
    49    
    50    instance:
    51        /*! @_nodoc */
    52        config Comparator.Instance comparator;
    53    
    54        /*! @_nodoc */
    55        config SVS.Instance svs;
    56    
    57        /*! @_nodoc */
    58        config BCSplus.Instance clock;
    59    
    60        /*! Define an array to describe all device pins. The 1st dimension
    61         *  denotes the port, the second the pin on that port. On an
    62         *  MSP430F24x1 device, there are 6 x 8 = 48 pins total.
    63         */
    64    
    65        /* TODO: This here should really be a module-wide feature, rather than an instance feature,
    66         * however due to limitations in XDCtools 3.21.0.0 the data is located here */
    67        /* TODO: For this device the config variable definition has been moved into the
    68         * corresponding XS file due to its size. This needs a more consistent solution. */
    69        config DevicePin_t devicePins[6][8];
    70    
    71        /*! Implementation of Device Pin Functional Configuration */
    72        override config DevicePinFunctionSetting_t devicePinSetting[6][8];
    73    
    74        /*! Determine if each Register needs to be forced set or not */
    75        readonly config ForceSetDefaultRegister_t forceSetDefaultRegister[] =
    76        [
    77            { register : "P1OUT" , regForceSet : true  },
    78            { register : "P1SEL" , regForceSet : false },
    79            { register : "P1DIR" , regForceSet : true  },
    80            { register : "P1REN" , regForceSet : false },
    81            { register : "P1IES" , regForceSet : true },
    82            { register : "P1IFG" , regForceSet : true },
    83            { register : "P1IE"  , regForceSet : false },
    84            { register : "P2OUT" , regForceSet : true  },
    85            { register : "P2SEL" , regForceSet : false },
    86            { register : "P2DIR" , regForceSet : true  },
    87            { register : "P2REN" , regForceSet : false },
    88            { register : "P2IES" , regForceSet : true },
    89            { register : "P2IFG" , regForceSet : true },
    90            { register : "P2IE"  , regForceSet : false },
    91            { register : "P3OUT" , regForceSet : true  },
    92            { register : "P3SEL" , regForceSet : false },
    93            { register : "P3DIR" , regForceSet : true  },
    94            { register : "P3REN" , regForceSet : false },
    95            { register : "P4OUT" , regForceSet : true  },
    96            { register : "P4SEL" , regForceSet : false },
    97            { register : "P4DIR" , regForceSet : true  },
    98            { register : "P4REN" , regForceSet : false },
    99            { register : "P5OUT" , regForceSet : true  },
   100            { register : "P5SEL" , regForceSet : false },
   101            { register : "P5DIR" , regForceSet : true  },
   102            { register : "P5REN" , regForceSet : false },
   103            { register : "P6OUT" , regForceSet : true  },
   104            { register : "P6SEL" , regForceSet : false },
   105            { register : "P6DIR" , regForceSet : true  },
   106            { register : "P6REN" , regForceSet : false }
   107        ];
   108    
   109        /*
   110         *  GPIO Digital I/O Registers
   111         *
   112         *  One GIPO instance defines the configuration of an entire,
   113         *  8-bit wide digital I/O port.
   114         */
   115    
   116        /*! Port 1 Output Register */
   117        config GpioBits8PxOut_t P1OUT = {
   118            Bit0        : BIT0_OFF,
   119            Bit1        : BIT1_OFF,
   120            Bit2        : BIT2_OFF,
   121            Bit3        : BIT3_OFF,
   122            Bit4        : BIT4_OFF,
   123            Bit5        : BIT5_OFF,
   124            Bit6        : BIT6_OFF,
   125            Bit7        : BIT7_OFF
   126        };
   127    
   128        /*! Port 1 Port Select Register */
   129        config GpioBits8PxSel_t P1SEL = {
   130            Bit0        : BIT0_OFF,
   131            Bit1        : BIT1_OFF,
   132            Bit2        : BIT2_OFF,
   133            Bit3        : BIT3_OFF,
   134            Bit4        : BIT4_OFF,
   135            Bit5        : BIT5_OFF,
   136            Bit6        : BIT6_OFF,
   137            Bit7        : BIT7_OFF
   138        };
   139    
   140        /*! Port 1 Direction Register */
   141        config GpioBits8PxDir_t P1DIR = {
   142            Bit0        : BIT0_OFF,
   143            Bit1        : BIT1_OFF,
   144            Bit2        : BIT2_OFF,
   145            Bit3        : BIT3_OFF,
   146            Bit4        : BIT4_OFF,
   147            Bit5        : BIT5_OFF,
   148            Bit6        : BIT6_OFF,
   149            Bit7        : BIT7_OFF
   150        };
   151    
   152        /*! Port 1 Resistor Enable Register */
   153        config GpioBits8PxRen_t P1REN = {
   154            Bit0        : BIT0_OFF,
   155            Bit1        : BIT1_OFF,
   156            Bit2        : BIT2_OFF,
   157            Bit3        : BIT3_OFF,
   158            Bit4        : BIT4_OFF,
   159            Bit5        : BIT5_OFF,
   160            Bit6        : BIT6_OFF,
   161            Bit7        : BIT7_OFF
   162        };
   163    
   164        /*! Port 2 Output Register */
   165        config GpioBits8PxOut_t P2OUT = {
   166            Bit0        : BIT0_OFF,
   167            Bit1        : BIT1_OFF,
   168            Bit2        : BIT2_OFF,
   169            Bit3        : BIT3_OFF,
   170            Bit4        : BIT4_OFF,
   171            Bit5        : BIT5_OFF,
   172            Bit6        : BIT6_OFF,
   173            Bit7        : BIT7_OFF
   174        };
   175    
   176        /*! Port 2 Port Select Register */
   177        config GpioBits8PxSel_t P2SEL = {
   178            Bit0        : BIT0_OFF,
   179            Bit1        : BIT1_OFF,
   180            Bit2        : BIT2_OFF,
   181            Bit3        : BIT3_OFF,
   182            Bit4        : BIT4_OFF,
   183            Bit5        : BIT5_OFF,
   184            Bit6        : BIT6_OFF,
   185            Bit7        : BIT7_OFF
   186        };
   187    
   188        /*! Port 2 Direction Register */
   189        config GpioBits8PxDir_t P2DIR = {
   190            Bit0        : BIT0_OFF,
   191            Bit1        : BIT1_OFF,
   192            Bit2        : BIT2_OFF,
   193            Bit3        : BIT3_OFF,
   194            Bit4        : BIT4_OFF,
   195            Bit5        : BIT5_OFF,
   196            Bit6        : BIT6_OFF,
   197            Bit7        : BIT7_OFF
   198        };
   199    
   200        /*! Port 2 Resistor Enable Register */
   201        config GpioBits8PxRen_t P2REN = {
   202            Bit0        : BIT0_OFF,
   203            Bit1        : BIT1_OFF,
   204            Bit2        : BIT2_OFF,
   205            Bit3        : BIT3_OFF,
   206            Bit4        : BIT4_OFF,
   207            Bit5        : BIT5_OFF,
   208            Bit6        : BIT6_OFF,
   209            Bit7        : BIT7_OFF
   210        };
   211    
   212        /*! Port 3 Output Register */
   213        config GpioBits8PxOut_t P3OUT = {
   214            Bit0        : BIT0_OFF,
   215            Bit1        : BIT1_OFF,
   216            Bit2        : BIT2_OFF,
   217            Bit3        : BIT3_OFF,
   218            Bit4        : BIT4_OFF,
   219            Bit5        : BIT5_OFF,
   220            Bit6        : BIT6_OFF,
   221            Bit7        : BIT7_OFF
   222        };
   223    
   224        /*! Port 3 Port Select Register */
   225        config GpioBits8PxSel_t P3SEL = {
   226            Bit0        : BIT0_OFF,
   227            Bit1        : BIT1_OFF,
   228            Bit2        : BIT2_OFF,
   229            Bit3        : BIT3_OFF,
   230            Bit4        : BIT4_OFF,
   231            Bit5        : BIT5_OFF,
   232            Bit6        : BIT6_OFF,
   233            Bit7        : BIT7_OFF
   234        };
   235    
   236        /*! Port 3 Direction Register */
   237        config GpioBits8PxDir_t P3DIR = {
   238            Bit0        : BIT0_OFF,
   239            Bit1        : BIT1_OFF,
   240            Bit2        : BIT2_OFF,
   241            Bit3        : BIT3_OFF,
   242            Bit4        : BIT4_OFF,
   243            Bit5        : BIT5_OFF,
   244            Bit6        : BIT6_OFF,
   245            Bit7        : BIT7_OFF
   246        };
   247    
   248        /*! Port 3 Resistor Enable Register */
   249        config GpioBits8PxRen_t P3REN = {
   250            Bit0        : BIT0_OFF,
   251            Bit1        : BIT1_OFF,
   252            Bit2        : BIT2_OFF,
   253            Bit3        : BIT3_OFF,
   254            Bit4        : BIT4_OFF,
   255            Bit5        : BIT5_OFF,
   256            Bit6        : BIT6_OFF,
   257            Bit7        : BIT7_OFF
   258        };
   259    
   260        /*! Port 4 Output Register */
   261        config GpioBits8PxOut_t P4OUT = {
   262            Bit0        : BIT0_OFF,
   263            Bit1        : BIT1_OFF,
   264            Bit2        : BIT2_OFF,
   265            Bit3        : BIT3_OFF,
   266            Bit4        : BIT4_OFF,
   267            Bit5        : BIT5_OFF,
   268            Bit6        : BIT6_OFF,
   269            Bit7        : BIT7_OFF
   270        };
   271    
   272        /*! Port 4 Port Select Register */
   273        config GpioBits8PxSel_t P4SEL = {
   274            Bit0        : BIT0_OFF,
   275            Bit1        : BIT1_OFF,
   276            Bit2        : BIT2_OFF,
   277            Bit3        : BIT3_OFF,
   278            Bit4        : BIT4_OFF,
   279            Bit5        : BIT5_OFF,
   280            Bit6        : BIT6_OFF,
   281            Bit7        : BIT7_OFF
   282        };
   283    
   284        /*! Port 4 Direction Register */
   285        config GpioBits8PxDir_t P4DIR = {
   286            Bit0        : BIT0_OFF,
   287            Bit1        : BIT1_OFF,
   288            Bit2        : BIT2_OFF,
   289            Bit3        : BIT3_OFF,
   290            Bit4        : BIT4_OFF,
   291            Bit5        : BIT5_OFF,
   292            Bit6        : BIT6_OFF,
   293            Bit7        : BIT7_OFF
   294        };
   295    
   296        /*! Port 4 Resistor Enable Register */
   297        config GpioBits8PxRen_t P4REN = {
   298            Bit0        : BIT0_OFF,
   299            Bit1        : BIT1_OFF,
   300            Bit2        : BIT2_OFF,
   301            Bit3        : BIT3_OFF,
   302            Bit4        : BIT4_OFF,
   303            Bit5        : BIT5_OFF,
   304            Bit6        : BIT6_OFF,
   305            Bit7        : BIT7_OFF
   306        };
   307    
   308            /*! Port 5 Output Register */
   309        config GpioBits8PxOut_t P5OUT = {
   310            Bit0        : BIT0_OFF,
   311            Bit1        : BIT1_OFF,
   312            Bit2        : BIT2_OFF,
   313            Bit3        : BIT3_OFF,
   314            Bit4        : BIT4_OFF,
   315            Bit5        : BIT5_OFF,
   316            Bit6        : BIT6_OFF,
   317            Bit7        : BIT7_OFF
   318        };
   319    
   320        /*! Port 5 Port Select Register */
   321        config GpioBits8PxSel_t P5SEL = {
   322            Bit0        : BIT0_OFF,
   323            Bit1        : BIT1_OFF,
   324            Bit2        : BIT2_OFF,
   325            Bit3        : BIT3_OFF,
   326            Bit4        : BIT4_OFF,
   327            Bit5        : BIT5_OFF,
   328            Bit6        : BIT6_OFF,
   329            Bit7        : BIT7_OFF
   330        };
   331    
   332        /*! Port 5 Direction Register */
   333        config GpioBits8PxDir_t P5DIR = {
   334            Bit0        : BIT0_OFF,
   335            Bit1        : BIT1_OFF,
   336            Bit2        : BIT2_OFF,
   337            Bit3        : BIT3_OFF,
   338            Bit4        : BIT4_OFF,
   339            Bit5        : BIT5_OFF,
   340            Bit6        : BIT6_OFF,
   341            Bit7        : BIT7_OFF
   342        };
   343    
   344        /*! Port 5 Resistor Enable Register */
   345        config GpioBits8PxRen_t P5REN = {
   346            Bit0        : BIT0_OFF,
   347            Bit1        : BIT1_OFF,
   348            Bit2        : BIT2_OFF,
   349            Bit3        : BIT3_OFF,
   350            Bit4        : BIT4_OFF,
   351            Bit5        : BIT5_OFF,
   352            Bit6        : BIT6_OFF,
   353            Bit7        : BIT7_OFF
   354        };
   355    
   356        /*! Port 6 Output Register */
   357        config GpioBits8PxOut_t P6OUT = {
   358            Bit0        : BIT0_OFF,
   359            Bit1        : BIT1_OFF,
   360            Bit2        : BIT2_OFF,
   361            Bit3        : BIT3_OFF,
   362            Bit4        : BIT4_OFF,
   363            Bit5        : BIT5_OFF,
   364            Bit6        : BIT6_OFF,
   365            Bit7        : BIT7_OFF
   366        };
   367    
   368        /*! Port 6 Port Select Register */
   369        config GpioBits8PxSel_t P6SEL = {
   370            Bit0        : BIT0_OFF,
   371            Bit1        : BIT1_OFF,
   372            Bit2        : BIT2_OFF,
   373            Bit3        : BIT3_OFF,
   374            Bit4        : BIT4_OFF,
   375            Bit5        : BIT5_OFF,
   376            Bit6        : BIT6_OFF,
   377            Bit7        : BIT7_OFF
   378        };
   379    
   380        /*! Port 6 Direction Register */
   381        config GpioBits8PxDir_t P6DIR = {
   382            Bit0        : BIT0_OFF,
   383            Bit1        : BIT1_OFF,
   384            Bit2        : BIT2_OFF,
   385            Bit3        : BIT3_OFF,
   386            Bit4        : BIT4_OFF,
   387            Bit5        : BIT5_OFF,
   388            Bit6        : BIT6_OFF,
   389            Bit7        : BIT7_OFF
   390        };
   391    
   392        /*! Port 6 Resistor Enable Register */
   393        config GpioBits8PxRen_t P6REN = {
   394            Bit0        : BIT0_OFF,
   395            Bit1        : BIT1_OFF,
   396            Bit2        : BIT2_OFF,
   397            Bit3        : BIT3_OFF,
   398            Bit4        : BIT4_OFF,
   399            Bit5        : BIT5_OFF,
   400            Bit6        : BIT6_OFF,
   401            Bit7        : BIT7_OFF
   402        };
   403    }