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    /*!
    34     *  ======== Comparator_Aplus ========
    35     *  MSP430F2xx Family Comparator_Aplus Module
    36     */
    37    metaonly module Comparator_Aplus inherits IComparator {
    38    
    39        /*! CACTL1 Register */
    40        struct CACTL1_t {
    41            CAEX_t      CAEX;               /*! Comparator_A+ exchange. This bit exchanges the comparator inputs and
    42                                             *inverts the comparator output. */
    43            CARSEL_t    CARSEL;             /*! Comparator_A+ reference select. This bit selects which terminal the
    44                                             * VCAREF is applied to.
    45                                             * When CAEX = 0:
    46                                             * 0     VCAREF is applied to the + terminal
    47                                             * 1     VCAREF is applied to the - terminal
    48                                             * When CAEX = 1:
    49                                             * 0     VCAREF is applied to the - terminal
    50                                             * 1     VCAREF is applied to the + terminal */
    51    
    52            CAREF_t     CAREF;              /*! Comparator_A+ reference. These bits select the reference voltage VCAREF.
    53                                             * 00 Internal reference off. An external reference can be applied.
    54                                             * 01 0.25*VCC
    55                                             * 10 0.50*VCC
    56                                             * 11 Diode reference is selected */
    57    
    58            CAON_t      CAON;               /*! Comparator_A+ on. This bit turns on the comparator. When the
    59                                             * comparator is off it consumes no current. The reference circuitry is enabled
    60                                             * or disabled independently.
    61                                             * 0     Off
    62                                             * 1     On */
    63    
    64            CAIES_t     CAIES;              /*! Comparator_A interrupt edge select
    65                                             * 0  Rising edge
    66                                             * 1  Falling edge */
    67    
    68            CAIE_t      CAIE;               /*! Comparator_A+ interrupt enable
    69                                             * 0 Disabled
    70                                             * 1 Enabled */
    71    
    72            CAIFG_t     CAIFG;              /*! The Comparator_A+ interrupt flag
    73                                             * 0 No interrupt pending
    74                                             * 1 Interrupt pending */
    75        }
    76    
    77        /*! CACTL1 Register */
    78        struct CACTL2_t {
    79            CASHORT_t   CASHORT;            /*! Input short. This bit shorts the + and - input terminals.
    80                                             * 0 Inputs not shorted.
    81                                             * 1 Inputs shorted. */
    82            P2CA4_t     P2CA4;              /*! Input select. This bit together with P2CA0 selects the + terminal input when
    83                                             * CAEX = 0 and the - terminal input when CAEX = 1 */
    84    
    85            P2CA3_t     P2CA3;              /*! Input select. These bits select the - terminal input when CAEX = 0 and the
    86                                             * + terminal input when CAEX = 1.
    87                                             * 000 No connection
    88                                             * 001 CA1
    89                                             * 010 CA2
    90                                             * 011 CA3
    91                                             * 100 CA4
    92                                             * 101 CA5
    93                                             * 110 CA6
    94                                             * 111 CA7 */
    95            P2CA2_t     P2CA2;              /*! Input select. These bits select the - terminal input when CAEX = 0 and the
    96                                             * + terminal input when CAEX = 1.
    97                                             * 000 No connection
    98                                             * 001 CA1
    99                                             * 010 CA2
   100                                             * 011 CA3
   101                                             * 100 CA4
   102                                             * 101 CA5
   103                                             * 110 CA6
   104                                             * 111 CA7 */
   105           P2CA1_t     P2CA1;              /*! Input select. These bits select the - terminal input when CAEX = 0 and the
   106                                             * + terminal input when CAEX = 1.
   107                                             * 000 No connection
   108                                             * 001 CA1
   109                                             * 010 CA2
   110                                             * 011 CA3
   111                                             * 100 CA4
   112                                             * 101 CA5
   113                                             * 110 CA6
   114                                             * 111 CA7 */
   115            P2CA0_t     P2CA0;              /*! Input select. This bit, together with P2CA4, selects the + terminal input
   116                                             * when CAEX = 0 and the - terminal input when CAEX = 1.
   117                                             * 00 No connection
   118                                             * 01 CA0
   119                                             * 10 CA1
   120                                             * 11 CA2 */
   121            CAF_t       CAF;                /*! Comparator_A+ output filter
   122                                             * 0 Comparator_A+ output is not filtered
   123                                             * 1 Comparator_A+ output is filtered */
   124        }
   125    
   126        /*! CAPD, Register */
   127        struct CAPD_t {
   128            CAPD7_t     CAPD7;              /*! CAPD7 Comparator_A+ port disable
   129                                             * 0 The input buffer is enabled.
   130                                             * 1 The input buffer is disabled.*/
   131    
   132            CAPD6_t     CAPD6;              /*! CAPD6 Comparator_A+ port disable
   133                                             *  0 The input buffer is enabled.
   134                                             *  1 The input buffer is disabled.*/
   135            CAPD5_t     CAPD5;              /*! CAPD5 Comparator_A+ port disable
   136                                             *  0 The input buffer is enabled.
   137                                             *  1 The input buffer is disabled.*/
   138            CAPD4_t     CAPD4;              /*! CAPD4 Comparator_A+ port disable
   139                                             *  0 The input buffer is enabled.
   140                                             *  1 The input buffer is disabled.*/
   141            CAPD3_t     CAPD3;              /*! CAPD3 Comparator_A+ port disable
   142                                             *  0 The input buffer is enabled.
   143                                             *  1 The input buffer is disabled.*/
   144            CAPD2_t     CAPD2;              /*! CAPD2 Comparator_A+ port disable
   145                                             *  0 The input buffer is enabled.
   146                                             *  1 The input buffer is disabled.*/
   147            CAPD1_t     CAPD1;              /*! CAPD1 Comparator_A+ port disable
   148                                             *  0 The input buffer is enabled.
   149                                             *  1 The input buffer is disabled.*/
   150            CAPD0_t     CAPD0;              /*! CAPD0 Comparator_A+ port disable
   151                                             *  0 The input buffer is enabled.
   152                                             *  1 The input buffer is disabled.*/
   153        }
   154    
   155        /*!
   156         *  ======== create ========
   157         *  Create an instance of this peripheral.
   158         */
   159        create();
   160    
   161    instance:
   162       /*! CACTL1 Register */
   163        config CACTL1_t CACTL1 = {
   164            CAEX    :    CAEX_OFF,
   165            CARSEL  :    CARSEL_OFF,
   166            CAREF   :    CAREF_0,
   167            CAON    :    CAON_OFF,
   168            CAIES   :    CAIES_OFF,
   169            CAIE    :    CAIE_OFF,
   170            CAIFG   :    CAIFG_OFF
   171         };
   172    
   173        /*! CACTL2 Register */
   174        config CACTL2_t CACTL2 = {
   175            CASHORT :    CASHORT_OFF,
   176            P2CA4   :     P2CA4_OFF,
   177            P2CA3   :     P2CA3_OFF,
   178            P2CA2   :     P2CA2_OFF,
   179            P2CA1   :     P2CA1_OFF,
   180            P2CA0   :    P2CA0_OFF,
   181            CAF     :    CAF_OFF
   182        };
   183    
   184        /*! CAPD, Register */
   185        config CAPD_t CAPD = {
   186            CAPD7   :    CAPD7_OFF,
   187            CAPD6   :    CAPD6_OFF,
   188            CAPD5   :    CAPD5_OFF,
   189            CAPD4   :    CAPD4_OFF,
   190            CAPD3   :    CAPD3_OFF,
   191            CAPD2   :    CAPD2_OFF,
   192            CAPD1   :    CAPD1_OFF,
   193            CAPD0   :    CAPD0_OFF
   194        };
   195    
   196        /*! Comparator_A+ has 1 interrupt enable */
   197        config regIntVect_t interruptSource[1];
   198    
   199         /*! Determine if each Register needs to be forced set or not */
   200        readonly config ForceSetDefaultRegister_t forceSetDefaultRegister[] =
   201        [
   202            { register : "CACTL1" , regForceSet : false },
   203            { register : "CACTL2" , regForceSet : false },
   204            { register : "CAPD" , regForceSet : false }
   205        ];
   206    }