1    /* --COPYRIGHT--,EPL
     2     *  Copyright (c) 2008 Texas Instruments and others.
     3     *  All rights reserved. This program and the accompanying materials
     4     *  are made available under the terms of the Eclipse Public License v1.0
     5     *  which accompanies this distribution, and is available at
     6     *  http://www.eclipse.org/legal/epl-v10.html
     7     * 
     8     *  Contributors:
     9     *      Texas Instruments - initial implementation
    10     * 
    11     * --/COPYRIGHT--*/
    12    /*!
    13     *  ======== GPIO ========
    14     *  MSP430 General Purpose Input Output Ports
    15     */
    16    metaonly interface IGPIO inherits xdc.platform.IPeripheral {
    17    
    18        /*! GPIO Bit 0 Definitions */
    19        enum Bit0_t {
    20            BIT0_OFF = 0x00u,
    21            BIT0 = 0x01u
    22        };
    23        
    24        enum Bit1_t {
    25            BIT1_OFF = 0x00u,
    26            BIT1 = 0x02u
    27        };
    28        
    29        enum Bit2_t {
    30            BIT2_OFF = 0x00u,
    31            BIT2 = 0x04u
    32        };
    33        
    34        enum Bit3_t {
    35            BIT3_OFF = 0x00u,
    36            BIT3 = 0x08u
    37        };
    38        
    39        enum Bit4_t {
    40            BIT4_OFF = 0x00u,
    41            BIT4 = 0x10u
    42        };
    43        
    44        enum Bit5_t {
    45            BIT5_OFF = 0x00u,
    46            BIT5 = 0x20u
    47        };
    48        
    49        enum Bit6_t {
    50            BIT6_OFF = 0x00u,
    51            BIT6 = 0x20u
    52        };
    53        
    54        enum Bit7_t {
    55            BIT7_OFF = 0x00u,
    56            BIT7 = 0x80u
    57        };
    58    
    59        /*!
    60        *  ======== GpioBits8_t ========
    61        *  Generic GPIO 8-bit Register
    62        *
    63        *  @see #GpioBits8_t
    64        */
    65        struct GpioBits8PxIn_t {
    66            Bit0_t    Bit0;     /*! GPIO Input Signal Bit 0 */
    67            Bit1_t    Bit1;     /*! GPIO Input Signal Bit 1 */
    68            Bit2_t    Bit2;     /*! GPIO Input Signal Bit 2 */
    69            Bit3_t    Bit3;     /*! GPIO Input Signal Bit 3 */
    70            Bit4_t    Bit4;     /*! GPIO Input Signal Bit 4 */
    71            Bit5_t    Bit5;     /*! GPIO Input Signal Bit 5 */
    72            Bit6_t    Bit6;     /*! GPIO Input Signal Bit 6 */
    73            Bit7_t    Bit7;     /*! GPIO Input Signal Bit 7 */
    74        }
    75    
    76        /*!
    77        *  ======== GpioBits8PxOut_t ========
    78        *  Generic GPIO 8-bit PxOUT Register
    79        *
    80        *  @see #GpioBits8PxOut_t
    81        */
    82        struct GpioBits8PxOut_t {
    83            Bit0_t    Bit0;     /*! GPIO Output Signal Bit 0 */
    84            Bit1_t    Bit1;     /*! GPIO Output Signal Bit 1 */
    85            Bit2_t    Bit2;     /*! GPIO Output Signal Bit 2 */
    86            Bit3_t    Bit3;     /*! GPIO Output Signal Bit 3 */
    87            Bit4_t    Bit4;     /*! GPIO Output Signal Bit 4 */
    88            Bit5_t    Bit5;     /*! GPIO Output Signal Bit 5 */
    89            Bit6_t    Bit6;     /*! GPIO Output Signal Bit 6 */
    90            Bit7_t    Bit7;     /*! GPIO Output Signal Bit 7 */
    91        }
    92        
    93        /*!
    94        *  ======== GpioBits8PxDir_t ========
    95        *  Generic GPIO 8-bit PxDIR Register
    96        *
    97        *  @see #GpioBits8PxDir_t
    98        */
    99        struct GpioBits8PxDir_t {
   100            Bit0_t    Bit0;     /*! GPIO Select Direction Bit 0
   101                                   *  Bit = 0: The port pin is switched to input direction
   102                                   *  Bit = 1: The port pin is switched to output direction */
   103            Bit1_t    Bit1;     /*! GPIO Select Direction Bit 1
   104                                   *  Bit = 0: The port pin is switched to input direction
   105                                   *  Bit = 1: The port pin is switched to output direction */
   106            Bit2_t    Bit2;     /*! GPIO Select Direction Bit 2
   107                                   *  Bit = 0: The port pin is switched to input direction
   108                                   *  Bit = 1: The port pin is switched to output direction */
   109            Bit3_t    Bit3;     /*! GPIO Select Direction Bit 3
   110                                   *  Bit = 0: The port pin is switched to input direction
   111                                   *  Bit = 1: The port pin is switched to output direction */
   112            Bit4_t    Bit4;     /*! GPIO Select Direction Bit 4
   113                                   *  Bit = 0: The port pin is switched to input direction
   114                                   *  Bit = 1: The port pin is switched to output direction */
   115            Bit5_t    Bit5;     /*! GPIO Select Direction Bit 5
   116                                   *  Bit = 0: The port pin is switched to input direction
   117                                   *  Bit = 1: The port pin is switched to output direction */
   118            Bit6_t    Bit6;     /*! GPIO Select Direction Bit 6
   119                                   *  Bit = 0: The port pin is switched to input direction
   120                                   *  Bit = 1: The port pin is switched to output direction */
   121            Bit7_t    Bit7;     /*! GPIO Select Direction Bit 7
   122                                   *  Bit = 0: The port pin is switched to input direction
   123                                   *  Bit = 1: The port pin is switched to output direction */
   124        }
   125        
   126        /*!
   127        *  ======== GpioBits8PxRen_t ========
   128        *  Generic GPIO 8-bit PxREN Register
   129        *
   130        *  @see #GpioBits8PxRen_t
   131        */
   132        struct GpioBits8PxRen_t {
   133            Bit0_t    Bit0;     /*! GPIO Enables or Disables Pullup/Pulldown Bit 0
   134                                   *  Bit = 0: Pullup/pulldown resistor disabled
   135                                   *  Bit = 1: Pullup/pulldown resistor enabled 
   136                                   *           Set Pullup/down via PxOUT 0 = Down; 1 = Up */
   137            Bit1_t    Bit1;     /*! GPIO Enables or Disables Pullup/Pulldown Bit 1
   138                                   *  Bit = 0: Pullup/pulldown resistor disabled
   139                                   *  Bit = 1: Pullup/pulldown resistor enabled
   140                                   *           Set Pullup/down via PxOUT 0 = Down; 1 = Up */
   141            Bit2_t    Bit2;     /*! GPIO Enables or Disables Pullup/Pulldown Bit 2
   142                                   *  Bit = 0: Pullup/pulldown resistor disabled
   143                                   *  Bit = 1: Pullup/pulldown resistor enabled
   144                                   *           Set Pullup/down via PxOUT 0 = Down; 1 = Up */
   145            Bit3_t    Bit3;     /*! GPIO Enables or Disables Pullup/Pulldown Bit 3
   146                                   *  Bit = 0: Pullup/pulldown resistor disabled
   147                                   *  Bit = 1: Pullup/pulldown resistor enabled
   148                                   *           Set Pullup/down via PxOUT 0 = Down; 1 = Up */
   149            Bit4_t    Bit4;     /*! GPIO Enables or Disables Pullup/Pulldown Bit 4
   150                                   *  Bit = 0: Pullup/pulldown resistor disabled
   151                                   *  Bit = 1: Pullup/pulldown resistor enabled
   152                                   *           Set Pullup/down via PxOUT 0 = Down; 1 = Up */
   153            Bit5_t    Bit5;     /*! GPIO Enables or Disables Pullup/Pulldown Bit 5
   154                                   *  Bit = 0: Pullup/pulldown resistor disabled
   155                                   *  Bit = 1: Pullup/pulldown resistor enabled
   156                                   *           Set Pullup/down via PxOUT 0 = Down; 1 = Up */
   157            Bit6_t    Bit6;     /*! GPIO Enables or Disables Pullup/Pulldown Bit 6
   158                                   *  Bit = 0: Pullup/pulldown resistor disabled
   159                                   *  Bit = 1: Pullup/pulldown resistor enabled
   160                                   *           Set Pullup/down via PxOUT 0 = Down; 1 = Up */
   161            Bit7_t    Bit7;     /*! GPIO Enables or Disables Pullup/Pulldown Bit 7
   162                                   *  Bit = 0: Pullup/pulldown resistor disabled
   163                                   *  Bit = 1: Pullup/pulldown resistor enabled
   164                                   *           Set Pullup/down via PxOUT 0 = Down; 1 = Up */
   165        }
   166        
   167        /*!
   168        *  ======== GpioBits8PxSel_t ========
   169        *  Generic GPIO 8-bit PxSEL Register
   170        *
   171        *  @see #GpioBits8PxSel_t
   172        */
   173        struct GpioBits8PxSel_t {
   174            Bit0_t    Bit0;     /*! GPIO Select Pin Function Bit 0 
   175                                   *See the device-specific data sheet to determine pin functions. */
   176            Bit1_t    Bit1;     /*! GPIO Select Pin Function Bit 1
   177                                   *See the device-specific data sheet to determine pin functions. */
   178            Bit2_t    Bit2;     /*! GPIO Select Pin Function Bit 2
   179                                   *See the device-specific data sheet to determine pin functions. */
   180            Bit3_t    Bit3;     /*! GPIO Select Pin Function Bit 3
   181                                   *See the device-specific data sheet to determine pin functions. */
   182            Bit4_t    Bit4;     /*! GPIO Select Pin Function Bit 4
   183                                   *See the device-specific data sheet to determine pin functions. */
   184            Bit5_t    Bit5;     /*! GPIO Select Pin Function Bit 5
   185                                   *See the device-specific data sheet to determine pin functions. */
   186            Bit6_t    Bit6;     /*! GPIO Select Pin Function Bit 6
   187                                   *See the device-specific data sheet to determine pin functions. */
   188            Bit7_t    Bit7;     /*! GPIO Select Pin Function Bit 7
   189                                   *See the device-specific data sheet to determine pin functions. */
   190        }
   191    
   192        /*!
   193        *  ======== GpioBits8PxSel2_t ========
   194        *  Generic GPIO 8-bit PxSEL2 Register
   195        *
   196        *  @see #GpioBits8PxSel2_t
   197        */
   198        struct GpioBits8PxSel2_t {
   199            Bit0_t    Bit0;     /*! GPIO Select Pin Function Bit 0 
   200                                   *See the device-specific data sheet to determine pin functions. */
   201            Bit1_t    Bit1;     /*! GPIO Select Pin Function Bit 1
   202                                   *See the device-specific data sheet to determine pin functions. */
   203            Bit2_t    Bit2;     /*! GPIO Select Pin Function Bit 2
   204                                   *See the device-specific data sheet to determine pin functions. */
   205            Bit3_t    Bit3;     /*! GPIO Select Pin Function Bit 3
   206                                   *See the device-specific data sheet to determine pin functions. */
   207            Bit4_t    Bit4;     /*! GPIO Select Pin Function Bit 4
   208                                   *See the device-specific data sheet to determine pin functions. */
   209            Bit5_t    Bit5;     /*! GPIO Select Pin Function Bit 5
   210                                   *See the device-specific data sheet to determine pin functions. */
   211            Bit6_t    Bit6;     /*! GPIO Select Pin Function Bit 6
   212                                   *See the device-specific data sheet to determine pin functions. */
   213            Bit7_t    Bit7;     /*! GPIO Select Pin Function Bit 7
   214                                   *See the device-specific data sheet to determine pin functions. */
   215        }
   216    
   217        /*!
   218        *  ======== GpioBits8PxIe_t ========
   219        *  Generic GPIO 8-bit PxIE Register
   220        *
   221        *  @see #GpioBits8PxIe_t
   222        */
   223        struct GpioBits8PxIe_t {
   224            Bit0_t    Bit0;     /*! GPIO Interrupt Enable Bit 0
   225                                   *  Bit = 0: The interrupt is disabled.
   226                                   *  Bit = 1: The interrupt is enabled. */
   227            Bit1_t    Bit1;     /*! GPIO Interrupt Enable Bit 1
   228                                   *  Bit = 0: The interrupt is disabled.
   229                                   *  Bit = 1: The interrupt is enabled. */
   230            Bit2_t    Bit2;     /*! GPIO Interrupt Enable Bit 2
   231                                   *  Bit = 0: The interrupt is disabled.
   232                                   *  Bit = 1: The interrupt is enabled. */
   233            Bit3_t    Bit3;     /*! GPIO Interrupt Enable Bit 3
   234                                   *  Bit = 0: The interrupt is disabled.
   235                                   *  Bit = 1: The interrupt is enabled. */
   236            Bit4_t    Bit4;     /*! GPIO Interrupt Enable Bit 4
   237                                   *  Bit = 0: The interrupt is disabled.
   238                                   *  Bit = 1: The interrupt is enabled. */
   239            Bit5_t    Bit5;     /*! GPIO Interrupt Enable Bit 5
   240                                   *  Bit = 0: The interrupt is disabled.
   241                                   *  Bit = 1: The interrupt is enabled. */
   242            Bit6_t    Bit6;     /*! GPIO Interrupt Enable Bit 6
   243                                   *  Bit = 0: The interrupt is disabled.
   244                                   *  Bit = 1: The interrupt is enabled. */
   245            Bit7_t    Bit7;     /*! GPIO Interrupt Enable Bit 7
   246                                   *  Bit = 0: The interrupt is disabled.
   247                                   *  Bit = 1: The interrupt is enabled. */
   248        }
   249        
   250        /*!
   251        *  ======== GpioBits8PxIes_t ========
   252        *  Generic GPIO 8-bit PxIES Register
   253        *
   254        *  @see #GpioBits8PxIes_t
   255        */
   256        struct GpioBits8PxIes_t {
   257            Bit0_t    Bit0;     /*! GPIO Select Interrupt Edge Bit 0
   258                                   *  Bit = 0: The PxIFGx flag is set with a low-to-high transition
   259                                   *  Bit = 1: The PxIFGx flag is set with a high-to-low transition */
   260            Bit1_t    Bit1;     /*! GPIO Select Interrupt Edge Bit 1
   261                                   *  Bit = 0: The PxIFGx flag is set with a low-to-high transition
   262                                   *  Bit = 1: The PxIFGx flag is set with a high-to-low transition */
   263            Bit2_t    Bit2;     /*! GPIO Select Interrupt Edge Bit 2
   264                                   *  Bit = 0: The PxIFGx flag is set with a low-to-high transition
   265                                   *  Bit = 1: The PxIFGx flag is set with a high-to-low transition */
   266            Bit3_t    Bit3;     /*! GPIO Select Interrupt Edge Bit 3
   267                                   *  Bit = 0: The PxIFGx flag is set with a low-to-high transition
   268                                   *  Bit = 1: The PxIFGx flag is set with a high-to-low transition */
   269            Bit4_t    Bit4;     /*! GPIO Select Interrupt Edge Bit 4
   270                                   *  Bit = 0: The PxIFGx flag is set with a low-to-high transition
   271                                   *  Bit = 1: The PxIFGx flag is set with a high-to-low transition */
   272            Bit5_t    Bit5;     /*! GPIO Select Interrupt Edge Bit 5
   273                                   *  Bit = 0: The PxIFGx flag is set with a low-to-high transition
   274                                   *  Bit = 1: The PxIFGx flag is set with a high-to-low transition */
   275            Bit6_t    Bit6;     /*! GPIO Select Interrupt Edge Bit 6
   276                                   *  Bit = 0: The PxIFGx flag is set with a low-to-high transition
   277                                   *  Bit = 1: The PxIFGx flag is set with a high-to-low transition */
   278            Bit7_t    Bit7;     /*! GPIO Select Interrupt Edge Bit 7
   279                                   *  Bit = 0: The PxIFGx flag is set with a low-to-high transition
   280                                   *  Bit = 1: The PxIFGx flag is set with a high-to-low transition */
   281        }
   282        
   283        /*!
   284        *  ======== GpioBits8PxIfg_t ========
   285        *  Generic GPIO 8-bit PxIFG Register
   286        *
   287        *  @see #GpioBits8PxIfg_t
   288        */
   289        struct GpioBits8PxIfg_t {
   290            Bit0_t    Bit0;     /*! GPIO Interrupt Flag Bit 0
   291                                   *  Bit = 0: No interrupt is pending
   292                                   *  Bit = 1: An interrupt is pending */
   293            Bit1_t    Bit1;     /*! GPIO Interrupt Flag Bit 1
   294                                   *  Bit = 0: No interrupt is pending
   295                                   *  Bit = 1: An interrupt is pending */
   296            Bit2_t    Bit2;     /*! GPIO Interrupt Flag Bit 2
   297                                   *  Bit = 0: No interrupt is pending
   298                                   *  Bit = 1: An interrupt is pending */
   299            Bit3_t    Bit3;     /*! GPIO Interrupt Flag Bit 3
   300                                   *  Bit = 0: No interrupt is pending
   301                                   *  Bit = 1: An interrupt is pending */
   302            Bit4_t    Bit4;     /*! GPIO Interrupt Flag Bit 4
   303                                   *  Bit = 0: No interrupt is pending
   304                                   *  Bit = 1: An interrupt is pending */
   305            Bit5_t    Bit5;     /*! GPIO Interrupt Flag Bit 5
   306                                   *  Bit = 0: No interrupt is pending
   307                                   *  Bit = 1: An interrupt is pending */
   308            Bit6_t    Bit6;     /*! GPIO Interrupt Flag Bit 6
   309                                   *  Bit = 0: No interrupt is pending
   310                                   *  Bit = 1: An interrupt is pending */
   311            Bit7_t    Bit7;     /*! GPIO Interrupt Flag Bit 7
   312                                   *  Bit = 0: No interrupt is pending
   313                                   *  Bit = 1: An interrupt is pending */
   314        }
   315    
   316        /*!
   317        *  ======== DeviceRegisterConfig_t ========
   318        *  Device Register Configuration Descriptor
   319        *
   320        *  Type to describe how a register is configured for a particular
   321        *  use. The type allows setting and clearing of an arbitrary bit
   322        *  pattern inside the specified register.
   323        *
   324        *  @see #DeviceRegisterConfig_t
   325        */
   326        struct DeviceRegisterConfig_t {
   327            String              register;
   328            UInt                bitSetMask;
   329            UInt                bitClearMask;
   330        }
   331    
   332        /*!
   333        *  ======== DevicePinFunction_t ========
   334        *  Device Pin Functional Descriptor
   335        *
   336        *  Type to describe how a device pin is configured for all its
   337        *  different uses that are possible. The function names are consolidated
   338        *  in one String array rather than located together with the function-
   339        *  specific data to allow easier access by Grace widgets. The functionConfig
   340        *  member contains an arbitrary-length array describing all register
   341        *  settings that need to be performed to configure a certain function.
   342        *
   343        *  @see #DevicePinFunction_t
   344        */
   345        struct DevicePinFunction_t {
   346            String                    functionName[];
   347            DeviceRegisterConfig_t    functionConfig[][];
   348        }
   349    
   350        /*!
   351        *  ======== DevicePin_t ========
   352        *  Device Pin Descriptor
   353        *
   354        *  Type to describe a single device pin and all its possible
   355        *  configurations.
   356        *
   357        *  @see #DevicePin_t
   358        */
   359        struct DevicePin_t {
   360            String                    pinName;
   361            DevicePinFunction_t       pinFunction;        
   362        }
   363    
   364        /*!
   365        *  ======== MatchedPortFunction_t ========
   366        *  Port Function Enumeration Type
   367        *
   368        *  This type is used to store a list of applicable pins based on the
   369        *  search criteria when using the function findPinsForFunction().
   370        *
   371        *  @see #MatchedPortFunction_t
   372        */
   373        struct MatchedPortFunction_t {
   374            UInt      port[];
   375            UInt      pin[];
   376            String    pinName[];
   377            UInt      functionIndex[];                                      
   378            String    functionName[];
   379        }
   380    
   381        /*!
   382        *  ======== DevicePinFunctionSetting_t ========
   383        *  Device Pin Functional Setting Descriptor
   384        *
   385        *  Type to store the selected pin configuration and a reference
   386        *  to the object that last modified the configuration.
   387        *
   388        *  @see #DevicePinFunctionSetting_t
   389        */
   390        struct DevicePinFunctionSetting_t {
   391            UInt       functionIndex;                               /*! Device Pin Functional Selection */
   392            Any        owner;                                               /*! Current Device Pin Owner */
   393        }
   394    
   395        /*!
   396        *  ======== ForceSetDefaultRegister_t ========
   397        *  Force Set Default Register
   398        *
   399        *  Type to store if each register needs to be forced initialized
   400        *  even if the register is in default state.
   401        *
   402        *  @see #ForceSetDefaultRegister_t
   403        */
   404        struct ForceSetDefaultRegister_t {
   405            String     register;
   406            Bool       regForceSet;        
   407        }
   408        
   409    instance:
   410        /*! Forward Declaration of Device Pin Functional Configuration */
   411        config DevicePinFunctionSetting_t devicePinSetting[][];
   412    
   413        /*!
   414         *  ======== findPinsForFunction ========
   415         *    Identify all device pins that can be used to serve a certain purpose
   416         *
   417         *  Function to scan through the pin configuration database to identify
   418         *    a list of device pins matching a regular expression.
   419         */    
   420        MatchedPortFunction_t findPinsForFunction(String regExp);
   421    
   422        /*!
   423         *  ======== pinFunctionIsActive ========
   424         *  Check if a pin is enabled for a certain function
   425         *
   426         *    This function is used to check if a certain functionality is enabled
   427         *    on a given device pins (returns 'true' in that case).
   428         */
   429        Bool pinFunctionIsActive(UInt port, UInt pin, String regExp);
   430        
   431        /*!
   432         *  ======== getPinFunctionIndex ========
   433         *  Get a pin's current functional configuration
   434         *
   435         *  This function is used to obtain the current configuration of a given
   436         *    device pin. The returned value can be used as an index to obtain further
   437         *  information from the pin configuration database.
   438         */
   439        UInt getPinFunctionIndex(UInt port, UInt pin);
   440        
   441        /*!
   442         *  ======== getPinOwner ========
   443         *    This function returns the current owner of the specified device pin.
   444         */ 
   445        Any getPinOwner(UInt port, UInt pin);
   446    
   447        /*!
   448         *  ======== setPinFunctionUsingIndex ========
   449         *     Configure a device pin to a specific peripheral function
   450         *
   451         *  This function is used to configure a device pin to a specific peripheral
   452         *    function that is identified by an index. The index corresponds to an
   453         *    associated set of configuration parameters stored in the pin configuration
   454         *    database. The owner parameter can be used to protect a pin from being
   455         *    used by somebody else. A pin configuration can only be changed if the
   456         *    current owner is undefined, or of the current owner matches the
   457         *    owner specified as function parameter.
   458         */
   459        Void setPinFunctionUsingIndex(UInt port, UInt pin, UInt index, Any owner);
   460        
   461        /*!
   462         *  ======== setDefaultPinFunction ========
   463         *     Configure a device pin to its default state
   464         *
   465         *  This function is used to configure a device pin to its default state
   466         *    and is typically used when a peripheral module relinquishes ownership
   467         *    of a pin so that it can be used by other peripheral modules.
   468         */
   469        Void setDefaultPinFunction(UInt port, UInt pin, Any owner);
   470    }