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 MSP430F24x ========
    40     *  MSP430 General Purpose Input Output Ports
    41     */
    42    metaonly module GPIO_MSP430F24x 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, and 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         *  MSP430F24x device, there are 6 x 8 = 48 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[6][8];
    75    
    76        /*! Implementation of Device Pin Functional Configuration */
    77        override config DevicePinFunctionSetting_t devicePinSetting[6][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        ];
   113    
   114        /*
   115         *  GPIO Digital I/O Registers
   116         *
   117         *  One GIPO instance defines the configuration of an entire,
   118         *  8-bit wide digital I/O port.
   119         */
   120    
   121        /*! Port 1 Output Register */
   122        config GpioBits8PxOut_t P1OUT = {
   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 1 Port Select Register */
   134        config GpioBits8PxSel_t P1SEL = {
   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 Direction Register */
   146        config GpioBits8PxDir_t P1DIR = {
   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 Resistor Enable Register */
   158        config GpioBits8PxRen_t P1REN = {
   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 Output Register */
   170        config GpioBits8PxOut_t P2OUT = {
   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 Port Select Register */
   182        config GpioBits8PxSel_t P2SEL = {
   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 Direction Register */
   194        config GpioBits8PxDir_t P2DIR = {
   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 Resistor Enable Register */
   206        config GpioBits8PxRen_t P2REN = {
   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 3 Output Register */
   218        config GpioBits8PxOut_t P3OUT = {
   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 Port Select Register */
   230        config GpioBits8PxSel_t P3SEL = {
   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 Direction Register */
   242        config GpioBits8PxDir_t P3DIR = {
   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 Resistor Enable Register */
   254        config GpioBits8PxRen_t P3REN = {
   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 4 Output Register */
   266        config GpioBits8PxOut_t P4OUT = {
   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 Port Select Register */
   278        config GpioBits8PxSel_t P4SEL = {
   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 Direction Register */
   290        config GpioBits8PxDir_t P4DIR = {
   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 Resistor Enable Register */
   302        config GpioBits8PxRen_t P4REN = {
   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 5 Output Register */
   314        config GpioBits8PxOut_t P5OUT = {
   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 Port Select Register */
   326        config GpioBits8PxSel_t P5SEL = {
   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 Direction Register */
   338        config GpioBits8PxDir_t P5DIR = {
   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 Resistor Enable Register */
   350        config GpioBits8PxRen_t P5REN = {
   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 6 Output Register */
   362        config GpioBits8PxOut_t P6OUT = {
   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 Port Select Register */
   374        config GpioBits8PxSel_t P6SEL = {
   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 Direction Register */
   386        config GpioBits8PxDir_t P6DIR = {
   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 Resistor Enable Register */
   398        config GpioBits8PxRen_t P6REN = {
   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    }