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