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