/* --COPYRIGHT--,TI
   *MSP Source and Object Code Software License Agreement
 *
 *
 **IMPORTANT - PLEASE CAREFULLY READ THE FOLLOWING LICENSE AGREEMENT, WHICH IS LEGALLY BINDING.  AFTER YOU READ IT, YOU WILL BE ASKED WHETHER YOU ACCEPT AND AGREE TO ITS TERMS.  DO NOT CLICK  "I ACCEPT" UNLESS: (1) YOU WILL USE THE LICENSED MATERIALS FOR YOUR OWN BENEFIT AND PERSONALLY ACCEPT, AGREE TO AND INTEND TO BE BOUND BY THESE TERMS; OR (2) YOU ARE AUTHORIZED TO, AND INTEND TO BE BOUND BY, THESE TERMS ON BEHALF OF YOUR COMPANY.
 *
 *
 **Important - Read carefully: This Source and Object Code Software License Agreement ("Agreement") is a legal agreement between you and Texas Instruments Incorporated ("TI").  In this Agreement "you" means you personally if you will exercise the rights granted for your own benefit, but it means your company (or you on behalf of your company) if you will exercise the rights granted for your company's benefit.  The "Licensed Materials" subject to this Agreement include the software programs and any associated electronic documentation (in each case, in whole or in part) that accompany this Agreement, are set forth in the applicable software manifest and you access "on-line", as well as any updates or upgrades to such software programs or documentation, if any, provided to you at TI's sole discretion.  The Licensed Materials are specifically designed and licensed for use solely and exclusively with MSP microcontroller devices manufactured by or for TI ("TI Devices").  By installing, copying or otherwise using the Licensed Materials you agree to abide by the provisions set forth herein.  This Agreement is displayed for you to read prior to using the Licensed Materials.  If you choose not to accept or agree with these provisions, do not download or install the Licensed Materials.
 *
 **Note Regarding Possible Access to Other Licensed Materials:  The Licensed Materials may be bundled with software and associated electronic documentation, if any, licensed under terms other than the terms of this Agreement (in whole or in part, "Other Licensed Materials"), including, for example Open Source Software and/or TI-owned or third party Proprietary Software licensed under such other terms.  "Open Source Software" means any software licensed under terms requiring that (A) other software ("Proprietary Software") incorporated, combined or distributed with such software or developed using such software: (i) be disclosed or distributed in source code form; or (ii) otherwise be licensed on terms inconsistent with the terms of this Agreement, including but not limited to permitting use of the Proprietary Software on or with devices other than TI Devices, or (B) require the owner of Proprietary Software to license any of its patents to users of the Open Source Software and/or Proprietary Software incorporated, combined or distributed with such Open Source Software or developed using such Open Source Software.
 *
 **If by accepting this Agreement, you gain access to Other Licensed Materials, they will be listed in the applicable software manifest.  Your use of the Other Licensed Materials is subject to the applicable other licensing terms acknowledgements and disclaimers as specified in the applicable software manifest and/or identified or included with the Other Licensed Materials in the software bundle.  For clarification, this Agreement does not limit your rights under, or grant you rights that supersede, the terms of any applicable Other Licensed Materials license agreement.  If any of the Other Licensed Materials is Open Source Software that has been provided to you in object code only under terms that obligate TI to provide to you or show you where you can access the source code versions of such Open Source Software, TI will provide to you, or show you where you can access, such source code if you contact TI at Texas Instruments Incorporated, 12500 TI Boulevard, Mail Station 8638, Dallas, Texas 75243, Attention: Contracts Manager, Embedded Processing.  In the event you choose not to accept or agree with the terms in any applicable Other Licensed Materials license agreement, you must terminate this Agreement.
 *
 **1.    License Grant and Use Restrictions.
 *
 **a.    Licensed Materials License Grant.  Subject to the terms of this Agreement, TI hereby grants to you a limited, non-transferable, non-exclusive, non-assignable, non-sublicensable, fully paid-up and royalty-free license to:
 *
 *            i.    Limited Source Code License:  make copies, prepare derivative works, display internally and use internally the Licensed Materials provided to you in source code for the sole purpose of developing object and executable versions of such Licensed Materials, or any derivative thereof, that execute solely and exclusively on TI Devices, for end use in Licensee Products, and maintaining and supporting such Licensed Materials, or any derivative thereof, and Licensee Products.  For purposes of this Agreement, "Licensee Product" means a product that consists of both hardware, including one or more TI Devices, and software components, including only executable versions of the Licensed Materials that execute solely and exclusively on such TI Devices.
 *
 *            ii.    Object Code Evaluation, Testing and Use License:  make copies, display internally, distribute internally and use internally the Licensed Materials in object code for the sole purposes of evaluating and testing the Licensed Materials and designing and developing Licensee Products, and maintaining and supporting the Licensee Products;
 *
 *            iii.    Demonstration License:  demonstrate to third parties the Licensed Materials executing solely and exclusively on TI Devices as they are used in Licensee Products, provided that such Licensed Materials are demonstrated in object or executable versions only and
 *
 *        iv.    Production and Distribution License:  make, use, import, export and otherwise distribute the Licensed Materials as part of a Licensee Product, provided that such Licensee Products include only embedded executable copies of such Licensed Materials that execute solely and exclusively on TI Devices.
 *
 *    b.    Contractors.  The licenses granted to you hereunder shall include your on-site and off-site contractors (either an individual or entity), while such contractors are performing work for or providing services to you, provided that such contractors have executed work-for-hire agreements with you containing applicable terms and conditions consistent with the terms and conditions set forth in this Agreement and provided further that you shall be liable to TI for any breach by your contractors of this Agreement to the same extent as you would be if you had breached the Agreement yourself.
 *
 *    c.    No Other License.  Nothing in this Agreement shall be construed as a license to any intellectual property rights of TI other than those rights embodied in the Licensed Materials provided to you by TI.  EXCEPT AS PROVIDED HEREIN, NO OTHER LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY OTHER TI INTELLECTUAL PROPERTY RIGHTS IS GRANTED HEREIN.
 *
 *    d.    Covenant not to Sue.  During the term of this Agreement, you agree not to assert a claim against TI or its licensees that the Licensed Materials infringe your intellectual property rights.
 *
 *    e.    Restrictions.  You shall maintain the source code versions of the Licensed Materials under password control protection and shall not disclose such source code versions of the Licensed Materials, to any person other than your employees and contractors whose job performance requires access.  You shall not use the Licensed Materials with a processing device other than a TI Device, and you agree that any such unauthorized use of the Licensed Materials is a material breach of this Agreement.  You shall not use the Licensed Materials for the purpose of analyzing or proving infringement of any of your patents by either TI or TI's customers.  Except as expressly provided in this Agreement, you shall not copy, publish, disclose, display, provide, transfer or make available the Licensed Materials to any third party and you shall not sublicense, transfer, or assign the Licensed Materials or your rights under this Agreement to any third party.  You shall not mortgage, pledge or encumber the Licensed Materials in any way.  You may use the Licensed Materials with Open Source Software or with software developed using Open Source Software tools provided you do not incorporate, combine or distribute the Licensed Materials in a manner that subjects the Licensed Materials to any license obligations or any other intellectual property related terms of any license governing such Open Source Software.
 *
 *    f.    Termination.  This Agreement is effective on the date the Licensed Materials are delivered to you together with this Agreement and will remain in full force and effect until terminated.  You may terminate this Agreement at any time by written notice to TI.  Without prejudice to any other rights, if you fail to comply with the terms of this Agreement or you are acquired, TI may terminate your right to use the Licensed Materials upon written notice to you.  Upon termination of this Agreement, you will destroy any and all copies of the Licensed Materials in your possession, custody or control and provide to TI a written statement signed by your authorized representative certifying such destruction. Except for Sections 1(a), 1(b) and 1(d), all provisions of this Agreement shall survive termination of this Agreement.
 *
 **2.    Licensed Materials Ownership.  The Licensed Materials are licensed, not sold to you, and can only be used in accordance with the terms of this Agreement.  Subject to the licenses granted to you pursuant to this Agreement, TI and its licensors own and shall continue to own all right, title and interest in and to the Licensed Materials, including all copies thereof.  You agree that all fixes, modifications and improvements to the Licensed Materials conceived of or made by TI that are based, either in whole or in part, on your feedback, suggestions or recommendations are the exclusive property of TI and all right, title and interest in and to such fixes, modifications or improvements to the Licensed Materials will vest solely in TI.  Moreover, you acknowledge and agree that when your independently developed software or hardware components are combined, in whole or in part, with the Licensed Materials, your right to use the combined work that includes the Licensed Materials remains subject to the terms and conditions of this Agreement.
 *
 **3.    Intellectual Property Rights.
 *
 *    a.    The Licensed Materials contain copyrighted material, trade secrets and other proprietary information of TI and its licensors and are protected by copyright laws, international copyright treaties, and trade secret laws, as well as other intellectual property laws.  To protect TI's and its licensors' rights in the Licensed Materials, you agree, except as specifically permitted by statute by a provision that cannot be waived by contract, not to "unlock", decompile, reverse engineer, disassemble or otherwise translate to a human-perceivable form any portions of the Licensed Materials provided to you in object code format only, nor permit any person or entity to do so.  You shall not remove, alter, cover, or obscure any confidentiality, trade secret, trade mark, patent, copyright or other proprietary notice or other identifying marks or designs from any component of the Licensed Materials and you shall reproduce and include in all copies of the Licensed Materials the copyright notice(s) and proprietary legend(s) of TI and its licensors as they appear in the Licensed Materials.  TI reserves all rights not specifically granted under this Agreement.
 *
 *    b.    Certain Licensed Materials may be based on industry recognized standards or software programs published by industry recognized standards bodies and certain third parties may claim to own patents, copyrights, and other intellectual property rights that cover implementation of those standards.  You acknowledge and agree that this Agreement does not convey a license to any such third party patents, copyrights, and other intellectual property rights and that you are solely responsible for any patent, copyright, or other intellectual property right claim that relates to your use or distribution of the Licensed Materials or your use or distribution of your products that include or incorporate the Licensed Materials.  Moreover, you acknowledge that you are responsible for any fees or royalties that may be payable to any third party based on such third party's interests in the Licensed Materials or any intellectual property rights that cover implementation of any industry recognized standard, any software program published by any industry recognized standards bodies or any other proprietary technology.
 *
 **4.    Confidential Information.  You acknowledge and agree that the Licensed Materials contain trade secrets and other confidential information of TI and its licensors.  You agree to use the Licensed Materials solely within the scope of the licenses set forth herein, to maintain the Licensed Materials in strict confidence, to use at least the same procedures and degree of care that you use to prevent disclosure of your own confidential information of like importance but in no instance less than reasonable care, and to prevent disclosure of the Licensed Materials to any third party, except as may be necessary and required in connection with your rights and obligations hereunder; provided, however, that you may not provide the Licensed Materials to any business organization or group within your company or to customers or contractors that design or manufacture semiconductors unless TI gives written consent.  You agree to obtain executed confidentiality agreements with your employees and contractors having access to the Licensed Materials and to diligently take steps to enforce such agreements in this respect.  TI may disclose your contact information to TI's licensors.
 *
 **5.    Warranties and Limitations.  THE LICENSED MATERIALS ARE PROVIDED "AS IS".  FURTHERMORE, YOU ACKNOWLEDGE AND AGREE THAT THE LICENSED MATERIALS HAVE NOT BEEN TESTED OR CERTIFIED BY ANY GOVERNMENT AGENCY OR INDUSTRY REGULATORY ORGANIZATION OR ANY OTHER THIRD PARTY ORGANIZATION.  YOU AGREE THAT PRIOR TO USING, INCORPORATING OR DISTRIBUTING THE LICENSED MATERIALS IN OR WITH ANY COMMERCIAL PRODUCT THAT YOU WILL THOROUGHLY TEST THE PRODUCT AND THE FUNCTIONALITY OF THE LICENSED MATERIALS IN OR WITH THAT PRODUCT AND BE SOLELY RESPONSIBLE FOR ANY PROBLEMS OR FAILURES.
 *
 **TI AND ITS LICENSORS MAKE NO WARRANTY OR REPRESENTATION, EITHER EXPRESS, IMPLIED OR STATUTORY, REGARDING THE LICENSED MATERIALS, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT OF ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADE SECRETS OR OTHER INTELLECTUAL PROPERTY RIGHTS.  YOU AGREE TO USE YOUR INDEPENDENT JUDGMENT IN DEVELOPING YOUR PRODUCTS.  NOTHING CONTAINED IN THIS AGREEMENT WILL BE CONSTRUED AS A WARRANTY OR REPRESENTATION BY TI TO MAINTAIN PRODUCTION OF ANY TI SEMICONDUCTOR DEVICE OR OTHER HARDWARE OR SOFTWARE WITH WHICH THE LICENSED MATERIALS MAY BE USED.
 *
 **IN NO EVENT SHALL TI OR ITS LICENSORS, BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL DAMAGES, HOWEVER CAUSED, ON ANY THEORY OF LIABILITY, IN CONNECTION WITH OR ARISING OUT OF THIS AGREEMENT OR THE USE OF THE LICENSED MATERIALS REGARDLESS OF WHETHER TI HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.  EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF REMOVAL OR REINSTALLATION, OUTSIDE COMPUTER TIME, LABOR COSTS, LOSS OF DATA, LOSS OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF USE OR INTERRUPTION OF BUSINESS.  IN NO EVENT WILL TI'S OR ITS LICENSORS' AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF YOUR USE OF THE LICENSED MATERIALS EXCEED FIVE HUNDRED U.S. DOLLARS (US$500).
 *
 *    Because some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages or limitation on how long an implied warranty lasts, the above limitations or exclusions may not apply to you.
 *
 **6.    Indemnification Disclaimer.  YOU ACKNOWLEDGE AND AGREE THAT TI SHALL NOT BE LIABLE FOR AND SHALL NOT DEFEND OR INDEMNIFY YOU AGAINST ANY THIRD PARTY INFRINGEMENT CLAIM THAT RELATES TO OR IS BASED ON YOUR MANUFACTURE, USE, OR DISTRIBUTION OF THE LICENSED MATERIALS OR YOUR MANUFACTURE, USE, OFFER FOR SALE, SALE, IMPORTATION OR DISTRIBUTION OF YOUR PRODUCTS THAT INCLUDE OR INCORPORATE THE LICENSED MATERIALS.
 *
 **7.    No Technical Support.  TI and its licensors are under no obligation to install, maintain or support the Licensed Materials.
 *
 **8.    Notices.  All notices to TI hereunder shall be delivered to Texas Instruments Incorporated, 12500 TI Boulevard, Mail Station 8638, Dallas, Texas 75243, Attention: Contracts Manager - Embedded Processing, with a copy to Texas Instruments Incorporated, 13588 N. Central Expressway, Mail Station 3999, Dallas, Texas 75243, Attention: Law Department - Embedded Processing.  All notices shall be deemed served when received by TI.
 *
 **9.    Export Control.  The Licensed Materials are subject to export control under the U.S. Commerce Department's Export Administration Regulations ("EAR").  Unless prior authorization is obtained from the U.S. Commerce Department, neither you nor your subsidiaries shall export, re-export, or release, directly or indirectly (including, without limitation, by permitting the Licensed Materials to be downloaded), any technology, software, or software source code, received from TI, or export, directly or indirectly, any direct product of such technology, software, or software source code, to any person, destination or country to which the export, re-export, or release of the technology, software, or software source code, or direct product is prohibited by the EAR.  You represent and warrant that you (i) are not located in, or under the control of, a national or resident of Cuba, Iran, North Korea, Sudan and Syria or any other country subject to a U.S. goods embargo; (ii) are not on the U.S. Treasury Department's List of Specially Designated Nationals or the U.S. Commerce Department's Denied Persons List or Entity List; and (iii) will not use the Licensed Materials or transfer the Licensed Materials for use in any military, nuclear, chemical or biological weapons, or missile technology end-uses.  Any software export classification made by TI shall not be construed as a representation or warranty regarding the proper export classification for such software or whether an export license or other documentation is required for the exportation of such software.
 *
 **10.    Governing Law and Severability; Waiver.  This Agreement will be governed by and interpreted in accordance with the laws of the State of Texas, without reference to conflict of laws principles.  If for any reason a court of competent jurisdiction finds any provision of the Agreement to be unenforceable, that provision will be enforced to the maximum extent possible to effectuate the intent of the parties, and the remainder of the Agreement shall continue in full force and effect.  This Agreement shall not be governed by the United Nations Convention on Contracts for the International Sale of Goods, or by the Uniform Computer Information Transactions Act (UCITA).  The parties agree that non-exclusive jurisdiction for any dispute arising out of or relating to this Agreement lies within the courts located in the State of Texas.  Notwithstanding the foregoing, any judgment may be enforced in any United States or foreign court, and either party may seek injunctive relief in any United States or foreign court.  Failure by TI to enforce any provision of this Agreement shall not be deemed a waiver of future enforcement of that or any other provision in this Agreement or any other agreement that may be in place between the parties.
 *
 **11.    PRC Provisions.  If you are located in the People's Republic of China ("PRC") or if the Licensed Materials will be sent to the PRC, the following provisions shall apply:
 *
 *    a.    Registration Requirements.  You shall be solely responsible for performing all acts and obtaining all approvals that may be required in connection with this Agreement by the government of the PRC, including but not limited to registering pursuant to, and otherwise complying with, the PRC Measures on the Administration of Software Products, Management Regulations on Technology Import-Export, and Technology Import and Export Contract Registration Management Rules.  Upon receipt of such approvals from the government authorities, you shall forward evidence of all such approvals to TI for its records.  In the event that you fail to obtain any such approval or registration, you shall be solely responsible for any and all losses, damages or costs resulting therefrom, and shall indemnify TI for all such losses, damages or costs.
 *
 **b.    Governing Language.  This Agreement is written and executed in the English language and shall be authoritative and controlling, whether or not translated into a language other than English to comply with law or for reference purposes.  If a translation of this Agreement is required for any purpose, including but not limited to registration of the Agreement pursuant to any governmental laws, regulations or rules, you shall be solely responsible for creating such translation.
 *
 **12.    Contingencies.    TI shall not be in breach of this Agreement and shall not be liable for any non-performance or delay in performance if such non-performance or delay is due to a force majeure event or other circumstances beyond TI's reasonable control.
 *
 **13.        Entire Agreement.  This is the entire agreement between you and TI and this Agreement supersedes any prior agreement between the parties related to the subject matter of this Agreement.  Notwithstanding the foregoing, any signed and effective software license agreement relating to the subject matter hereof and stating expressly that such agreement shall control regardless of any subsequent click-wrap, shrink-wrap or web-wrap, shall supersede the terms of this Agreement.  No amendment or modification of this Agreement will be effective unless in writing and signed by a duly authorized representative of TI.  You hereby warrant and represent that you have obtained all authorizations and other applicable consents required empowering you to enter into this Agreement.
 *
 *
 *
 * --/COPYRIGHT--*/

#ifndef INCLUDE_GASMETERINGLIB_H_
#define INCLUDE_GASMETERINGLIB_H_

//#############################################################################
//
//! \file   gasMeteringLib.h
//!
//! \brief  Contains all MSP430 Gas Metering Library enums, structs, macros,
//!            function and global variables definitions
//!
//
//  Group:          MSP
//  Target Device:  MSP430FR5994
//
//  (C) Copyright 2016, Texas Instruments, Inc.
//#############################################################################
// TI Release: gasLibrary_1_10_00_11
// Release Date: April 26, 2017
//#############################################################################

//*****************************************************************************
// includes
//*****************************************************************************
#include <msp430.h>
#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus

extern "C" {
#endif

//*****************************************************************************
// defines
//*****************************************************************************

//*****************************************************************************
// typedefs
//*****************************************************************************
//! \brief This enum lists all possible APIs return codes
//!
typedef enum _GASMETERING_return_code_ {
    // Reserved errors 0-29 for configuration errors
    GASMETERING_return_code_configuration_error = 0,
    //!< This error is returned if a configuration parameter is out of spec
    // Reserved errors 30-59 for algorithm initialization errors
    GASMETERING_return_code_init_algorithm_error = 30,
    //!< This error is returned if an error occurs during algorithm
    //!< initialization
    // Reserved errors 60-89 for configuration errors
    GASMETERING_return_code_start_measurement_error = 60,
    //!< This error is returned if an error occurred during the firing
    //!< or capturing of ultrasonic signal
    // Reserved errors 90-119 for algorithm errors
    // Reserved errors 120-149 for update configuration errors
    GASMETERING_return_code_update_configuration_error = 120,
    //!< This error is returned if an error occurred during measurement
    //!< configuration update
    GASMETERING_return_code_no_error = 255
//!< This return code is use to indicate that no error was detected during
//!< API execution
} GASMETERING_return_code;

//! \brief Lists supported crystal frequencies for HFXT
//!
typedef enum _GASMETERING_HFXT_freq_ {
    GASMETERING_HFXT_freq_4MHz = 40,
    //!< Configures library for 4MHz HFXT operation
    GASMETERING_HFXT_freq_8MHz = 80
//!< Configures library for 8MHz HFXT operation
} GASMETERING_HFXT_freq;


//! \brief Lists supported crystal frequencies for HFXT
//!
typedef enum _GASMETERING_low_power_mode_ {
    GASMETERING_low_power_mode_active = 0,
    //!< Keeps device in active mode
    GASMETERING_low_power_mode_0 = LPM0_bits,
    //!< Device will go to low power mode 0
    GASMETERING_low_power_mode_1 = LPM1_bits,
        //!< Device will go to low power mode 1
    GASMETERING_low_power_mode_2 = LPM2_bits,
    //!< Device will go to low power mode 2
    GASMETERING_low_power_mode_3 = LPM3_bits,
    //!< Device will go to low power mode 3
} GASMETERING_low_power_mode;

//! \brief Lists supported computation modes for gas metering
//!
typedef enum _GASMETERING_Algorithm_Computation_Mode_ {
    GASMETERING_Algorithm_Computation_Mode_0 = 0,
    //!< Uses computation method 0 for Abs ToF and Delta ToF
    GASMETERING_Algorithm_Computation_Mode_1 = 1,
    //!< Uses computation method 1 for Abs ToF and Delta ToF
    GASMETERING_Algorithm_Computation_Mode_2 = 2,
    //!< Uses computation method 2 for Abs ToF and Delta ToF
    GASMETERING_Algorithm_Computation_Mode_4 = 4,
    //!< Uses computation method 4 for Abs ToF and Delta ToF
    GASMETERING_Algorithm_Computation_Mode_10 = 10,
    //!< Uses computation method 10 for Abs ToF and Delta ToF
    GASMETERING_Algorithm_Computation_Mode_11 = 11,
    //!< Uses computation method 11 for Abs ToF and Delta ToF
    GASMETERING_Algorithm_Computation_Mode_12 = 12,
    //!< Uses computation method 12 for Abs ToF and Delta ToF
    GASMETERING_Algorithm_Computation_Mode_14 = 14
    //!< Uses computation method 14 for Abs ToF and Delta ToF
} GASMETERING_Algorithm_Computation_Mode;

//! \brief Lists supported ADC capture frequencies  by the library
//!
typedef enum _GASMETERING_ADC_Sampling_Freq_ {
    GASMETERING_ADC_sampling_freq_100_KHz = 1,
    //!< Configures library for 100 KSPS operation mode
    GASMETERING_ADC_sampling_freq_200_KHz = 2
//!< Configures library for 200 KSPS operation mode
} GASMETERING_ADC_Sampling_Freq;

//! \brief Lists supported signal sampling frequencies by the library
//!
typedef enum _GASMETERING_Signal_Sampling_frequency_ {
    GASMETERING_Signal_Sampling_frequency_800_KHz = 8,
    //!< Configures library for 800 KHz signal sampling frequency
    GASMETERING_Signal_Sampling_frequency_1000_KHz = 10,
    //!< Configures library for 1 MHz signal sampling frequency
    GASMETERING_Signal_Sampling_frequency_2000_KHz = 20
//!< Configures library for 2 MHz signal sampling frequency
} GASMETERING_Signal_Sampling_frequency;

//! \brief Lists the options for TX line status after transmission
//!
typedef enum _GASMETERING_TX_line_state_after_firing_ {
    GASMETERING_TX_line_state_after_firing_low = 0,
    //!< Configures TX line low after transmission
    GASMETERING_TX_line_state_after_firing_high = 1,
    //!< Configures TX line high after transmission
} GASMETERING_TX_line_state_after_firing;

//! \brief The following structure contains all status flags used by the
//!         library
//!
typedef union _GASMETERING_Status_Flags_ {
    struct {
        bool GASMETERING_Status_Flags_isLPMTimerExpired :1;
        //!< When this flag is set to true it indicates that LPM Timer has 
        //!< expired, when flag is false the timer has not expired.
        bool GASMETERING_Status_Flags_isADCCaptureComplete :1;
        //!< When this flag is set to true it indicates that an UP stream and 
        //!< Down stream ADC capture has been completed.
        bool GASMETERING_Status_Flags_isADCIntrlvComplete :1;
        //!< This flag is use to indicate that the interleaving of ADC using
        //!< LEA module has been completed.
        uint8_t GASMETERING_Status_Flags_reserved :5;
        //!< The following flags are reserved and always set to false.
    } flags;
    uint8_t byte;
} GASMETERING_Status_Flags;

//! \brief This structure allows user to provide System Configuration parameters
//!
typedef struct _GASMETERING_System_Configuration_ {
    GASMETERING_HFXT_freq hFXTFreq;
    bool runDiagnosticFunctions;
    //!< Setting this values to true will run diagnostic functions. The APIs
    //!< will inform the user of any errors via the API return codes.
} GASMETERING_System_Configuration;

//! \brief This structure allows user to provide Gas Meter configuration
//!           parameters
//!
typedef struct _GASMETERING_Meter_Configuration_ {
    float meterConstant;
    //!< This constant is meter dependent and is calculated using the following
    //!< formula (Area x Length) length^3
} GASMETERING_Meter_Configuration;

//! \brief This structure allows the user to configure firing and capture
//!            setting
typedef struct _GASMETERING_Measurement_Configuration_ {
    uint8_t *pTxPattern;
    //!< Pointer to the TX pattern used to excite the ultrasonic
    //!< transducers
    int16_t txPatternSize;
    //!< Specifies the TX pattern size
    int16_t *pBinTxPattern;
    //!< Pointer to the binary representation of the TX pattern used to
    //!< excite the ultrasonic transducers
    int16_t binTxPatternsize;
    //!< Size of binary representation of the TX pattern
    uint16_t gapPlsSrtandADCCap_usec;
    //!< Specifies the gap between pulse start and ADC Capture.
    //!< Minimum value: 150 usec
    //!< Maximum value: 600 usec
    uint8_t numOfPulses;
    //!< Specifies the number of pulses used in the TX pattern
    //!< Minimum value: 20
    //!< Maximum value: 40
    uint16_t gapUPSandDNS_usec;
    //!< Specifies the gap between Up stream abd Down stream in usec
    //!< Minimum value: gapPlsStrtAndADCCap_usec + captureDuration_usec + 25 usec
    //!< Maximum value: 8000
    uint16_t gapDNSandUPS_msec;
    //!< Specifies the gap between Down stream and Up stream in msec
    //!< Minimum value: 8
    //!< Maximum value: 2000
    bool isGainControlEnabled;
    //!< Controls Gain Control line on AFE booster pack
    //!< true: will enable gain control during firing/capture
    //!< false: will disable gain control during firing/capture
    GASMETERING_ADC_Sampling_Freq adcSamplingFreq;
    GASMETERING_Signal_Sampling_frequency signalSampFreq;
    uint16_t captureDuration_usec;
    //!< For GASMETERING_ADC_Signal_Sampling_frequency_800_KHz and
    //!< GASMETERING_ADC_Signal_Sampling_frequency_1000_KHz valid range is
    //!< [100,700].
    //!< For GASMETERING_ADC_Signal_Sampling_frequency_2000_KHz valid range is
    //!< [50,350].
    bool isDummyFiringEnabled;
    //!< Enable this option to increase SNR, enabling this option will perform
    //!< an extra firing and capture which will increase power consumption
    uint16_t gapAMPandSampFirstCapture_usec;
    //!< Specifies the gap between turning on Gain amplifier and starting the
    //!< first ADC Capture
    //!< Minimum value: 1
    //!< Maximum value: (gapAMPandSampFirstCapture_usec + minGapAMPandSampFirstCapture_usec) < gapPlsSrtandADCCap_usec 
    uint16_t gapAMPandRestOfCapture_usec;
    //!< Specifies the gap between turning on Gain amplifier and starting the
    //!< subsequent ADC Capture
    //!< Minimum value: 1
    //!< Maximum value: gapPlsSrtandADCCap_usec
    uint16_t minGapAMPandSampFirstCapture_usec;
    //!< Specifies the minimum Gap between turning on Gain amplifier and starting the
    //!< first ADC Capture
    //!< Minimum value: 1
    //!< Maximum value: 200
    GASMETERING_TX_line_state_after_firing txLineState;
    //!< Specifies state of TX line after transmission
} GASMETERING_Measurement_Configuration;

//! \brief This structure allows to configure the Time of Flight Algorithm
//!
typedef struct _GASMETERING_Algorithms_Configuration_ {
    GASMETERING_Algorithm_Computation_Mode computationMode;
    //!< Selects computation mode
    int16_t deltaToFOfsset_ps;
    //!< The constant value calibrated by Zero flow drift (sec)
    int16_t absToFAddDelay_ns;
    //!< The additional time it takes during firing and capturing the data,
    //!< which is not accounted for anywhere else.
    float negRngDeltaTOF_sec;
    //!< The max negative index to search across correlation value of UPS and DNS for the matching signal.
    //!< Minimum value: 0
    //!< Maximum value: 75e-6
    float posRngDeltaTOF_sec;
    //!< The max positive index to search across correlation value of UPS and DNS for the matching signal.
    //!< Minimum value: 0
    //!< Maximum value: 75e-6
    float negRngAbsTOF_sec;
    //!< The max negative index to search across correlation value of UPS/DNS and TX pulse for the matching signal.
    //!< Minimum value: 0
    //!< Maximum value: 50e-6
    float posRngAbsTOF_sec;
    //!< The max positive index to search across correlation value of UPS/DNS and TX pulse for the matching signal.
    //!< Minimum value: 0
    //!< Maximum value: 50e-6
    float envCrossThreshold;
    //!< The envelope crossing threshold of correlation output for absolute TOF.
    bool isRunAbsToFUpEnabled;
    //!< This flag must be set equal to true, otherwise GASMETERING_runAlgorithm
    //!< will return 0.0
    bool isRunAbsToFDownEnabled;
    //!< This flag must be set equal to true, otherwise GASMETERING_runAlgorithm
    //!< will return 0.0
    bool isRunDeltaToFUpEnabled;
    //!< This flag must be set equal to true, otherwise GASMETERING_runAlgorithm
    //!< will return 0.0
    bool isRunFlowEnabled;
    //!< This flag must be set equal to true, otherwise GASMETERING_runAlgorithm
    //!< will return 0.0
    uint16_t syncThreshold;
    //!< This threshold specificies the number of captures before triggering a
    //!< new setting Flag_searchForCorrIdxDNS and Flag_searchForCorrIdxUPS to
    //!< true

} GASMETERING_Algorithms_Configuration;

//! \brief This structure is use to provide the pointer to Gas Metering HAL
//!        functions
//!
typedef struct _GASMETERING_HAL_functions_ {
    void (*pGASMETERING_HAL_restoreSysClock)(void);
    //!< Function pointer to HAL function to restore system clock after firing
    //!< and capture
    void (*pGASMETERING_HAL_generateLPMDelay)(uint16_t count, uint16_t mode);
    //!< Function pointer to HAL function to generate LPM Delay
    void (*pGASMETERING_HAL_configSysClockForCapture)(void);
    //!< Function pointer to HAL function to prepare System Clock for Firing and
    //!< Capture
    void (*pGASMETERING_HAL_configUPDNSample)(bool isGainControlEnabled);
    //!< Function pointer to HAL function to power on AFE and configure ADC
    //!< for Firing and Capture
    void (*pGASMETERING_HAL_configIterationSample)(uint16_t iterNum,
            bool isCaptureModeUP, uint16_t fracDelay);
    //!< Function pointer to HAL function to  configure firing and capture
    //!< timers and TX/RX Mux
    void (*pGASMETERING_HAL_finishIterationSample)(void);
    //!< Function pointer to HAL function to stop iteration timers and clean
    //!< ADC DMA
    void (*pGASMETERING_HAL_configGPIOAfterFiring)(void);
    //!< Function pointer to HAL function to deassert GPIO after firing/capture
} GASMETERING_HAL_functions;

//! \brief This structure is used by  GASMETERING_runAlgorithms to return the
//!    results for Abs ToF, Delta ToD and Volume Flow Rate calculations
//!
typedef struct _GASMETERING_Algorithms_Results_ {
    double deltaTOF;
    float totalTOF_UPS;
    float totalTOF_DNS;
    float volumeFlowRate;
} GASMETERING_Algorithms_Results;

//! \brief This hanlde is initialized when calling
//!     GASMETERING_configureUltrasonicMeasurement and
//!     GASMETERING_intializeAlgorithm
//!
typedef struct _GASMETERING_Algorithms_handle_ {
    float deltaTOF;
    //!< The computed deltaTOF
    float totalTOF_UPS;
    //!< The computed total time of flight upstream
    float totalTOF_DNS;
    //!< The computed total time of flight downstream
    float volumeFlowRate;
    //!< The computed volume flow rate
    float volumeScaleFactor;
    //!< The volume scale factor (Area x Length) length^3
    float dcOffset;
    //!< The constant value calibrated by Zero flow drift (sec)
    float ADCSamplePeriod_sec;
    //!< The duration between two captured samples (1/Fs)
    float ADCStartCaptureInstant_sec;
    //!< The time elapsed from the start of pulse excitation and start of ADC
    //!< data capture. This relates to the propagation path length.
    float ADCAdditionalCaptureDelay_sec;
    //!< The additional time it takes during firing and capturing the data,
    //!< which is not accounted for anywhere else.
    uint8_t *arrayTXPtr;
    //!< The pointer to the transmit pulses
    int16_t arrayLengthTX;
    //!< The length of transmit pulses
    int16_t *arrayTXbPtr;
    //!< The pointer to the binary transmit pulses
    int16_t arrayLengthTXb;
    //!< The length of binary transmit pulses
    int16_t *arrayUPSPtr;
    //!< The pointer to the upstream data array
    int16_t *arrayDNSPtr;
    //!< The pointer to the downstream data array
    int16_t arrayLengthDNUP;
    //!< The length of data captured for upstream or downstream
    int16_t *pDMALEARAMADCArray;
    //!< Pointer to array in LEA RAM memory which holds DMA ADC samples
    uint16_t dMALEARAMADCArraySize;
    //!< ADC array size size is determined is dependent on ADC sampling
    //!< frequency
    uint16_t aDCSamplePeriod;
    uint16_t fracDelay;
    //!< Decimation factor
    uint16_t upsampleFactor;
    //!< Upsample factor
    float negRngDeltaTOF;
    //!< The max negative index to search across correlation value of UPS
    //!< and DNS for the matching signal.
    float posRngDeltaTOF;
    //!< The max positive index to search across correlation value of UPS and
    //!< DNS for the matching signal.
    float negRngAbsTOF;
    //!< The max negative index to search across correlation value of UPS/DNS
    //!< and TX pulse for the matching signal.
    float posRngAbsTOF;
    //!< The max positive index to search across correlation value of UPS/DNS
    //!< and TX pulse for the matching signal.
    int16_t corrIdxUPS;
    //!< The index location identified as the correlation peak of the
    //!< received upstream.
    int16_t corrIdxDNS;
    //!< The index location identified as the correlation peak of the
    //!< received downstream.
    bool Flag_searchForCorrIdxDNS;
    //!< The flag to check if the peak correlation index has to be searched
    //!< or it has to only be tracked for downstream.
    bool Flag_searchForCorrIdxUPS;
    //!< The flag to check if the peak correlation index has to be searched
    //!< or it has to only be tracked for upstream.
    float envCrossThreshold;
    //!< The envelope crossing threshold of correlation output for
    //!< absolute TOF.
    float fracIdxUPS;
    //!< The fractional index location identified as the envelope 
    //!< threshold crossing of the received upstream.
    float fracIdxDNS;
    //!< The fractional index location identified as the envelope threshold 
    //!< crossing of the received downstream.
    uint16_t burstDelay;
    // Library will configure a 10 usec burst delay
    uint16_t busrtStartDelay;
    // The following parameter is used to generate interleaved signal
    GASMETERING_Algorithm_Computation_Mode computationMode;
    //!< The parameter to switch between different algorithms to compute
    //!< deltaTOF and AbsTOF.
    int16_t   *arrayHFIRPtr;
    //!< The pointer to the hilbert co-efficients array
    //!< [coeffs = floor(HILBERT_FIR_COEFF_ARRAY*(2^HFF_COEFF_POW2SCALE)]
    int16_t   arrayLengthHFIR;
    //!< The length of hilbert co-efficients array
    uint8_t       hFIRCoeffPower2Scale;
    //!< The 2 power index scaling factor by which the hilbert FIR
    //!< co-efficients have been scaled.
    uint8_t       corrValPow2Scale;
    //!< The 2 power index scaling factor by which the correlation ouptut
    //!< between DNS/UPS and TXbinary have been scaled down.
    int32_t       corrPeakSqValue;
    //!< The square of the correlation peak which is computed in absolute TOF.
    int16_t       firstThresCrossIdx;
    //!< The index location identified as the first threhold crossing value.
    float       firstThresCrossing_sec;
    //!< The actual first threhold crossing value in terms of time.
    bool          Flag_searchForFirstIdx;
    //!< The flag to enable search for the first correlation lobe threhold crossing value.
    bool isLEAusedHE;
    //!< The following flag indicate if Hilbert Envelope operation
    //!< used LEA module
    bool isLEAusedFTC;
    //!< The following flag indicated if Absolute Time Of Flight First Threshold
    //!< crossing operation was performed with LEA module
} GASMETERING_handle;

//! \brief This is the Gas Metering configuration structure. All expect a
//!            a pointer to this configuration structure. The Application will
//!         define this structure via the configuration files of the library.
//!
typedef struct _GASMETERING_configuration_ {
    GASMETERING_System_Configuration *pSystemConfig;
    //!< Pointer to GASMETERING_System_Configuration struct
    GASMETERING_Meter_Configuration *pMeterConfiguration;
    //!< Pointer to GASMETERING_Meter_Configuration struct
    GASMETERING_Measurement_Configuration *pMeasurementConfiguration;
    //!< Pointer to GASMETERING_Measurement_Configuration struct
    GASMETERING_Algorithms_Configuration *pAlgorithmConfiguration;
    //!< Pointer to GASMETERING_Algorithms_Configuration struct
    GASMETERING_HAL_functions *pHalFunctions;
    //!< Pointer to GASMETERING_HAL_functions struct
    GASMETERING_handle *pHandle;
    //!< Pointer to GASMETERING_handle struct
} GASMETERING_configuration;
//*****************************************************************************
// globals
//*****************************************************************************
extern volatile GASMETERING_Status_Flags gGASMETERINGFlags;
extern volatile uint16_t gGASMETRINGLEASCIFG_DEBUG;
extern const char GASMETERING_version[];
//*****************************************************************************
// the function prototypes
//*****************************************************************************

//*****************************************************************************
//
//! \addtogroup configuration_api
//! @{
//
//******************************************************************************

//! \brief Configures measurement for first time
//!
//! This function is used to configure the ultrasonic measurement. This
//!    must be called before calling GASMETERING_startUltrasonicMeasurement.
//!    This function will also intialize the GAS Metering handle.
//!
//! \param pLibraryConfig pointer to GAS Metering library configuration
//!                structure
//!
//! \return  GASMETERING_return_code
extern GASMETERING_return_code GASMETERING_configureUltrasonicMeasurement(
        GASMETERING_configuration *pLibraryConfig);

//******************************************************************************
//
// Close the Doxygen group.
//! @}
//
//******************************************************************************

//*****************************************************************************
//
//! \addtogroup measurement_api
//! @{
//
//******************************************************************************
//! \brief    Triggers a firing and capture.
//!
//!    This function is used to trigger a firing/capture of ultrasonic
//!    signals. If an application interrupt occurs during the execution
//!    of this API, the capture of the signal might be corrupted.
//!    Therefore, user must ensure all application level interrupts are
//!    disabled before invoking this API.
//!
//! \param pLibraryConfig pointer to GAS Metering library configuration
//!                structure
//!
//! \return  GASMETERING_return_code
extern GASMETERING_return_code GASMETERING_startUltrasonicMeasurement(
        GASMETERING_configuration *pLibraryConfig);

//! \brief  Updates measurement configuration during run time
//!
//! This function allows user to update library configuration during
//! runtime.
//!
//! \param pLibraryConfig pointer to GAS Metering library configuration
//!                structure
//!
//! \return  GASMETERING_return_code
//
extern GASMETERING_return_code GASMETERING_updateUltrasonicMeasurement(
        GASMETERING_configuration *pLibraryConfig);

//! \brief Generates a low power delay
//!
//!    The following function allows user to generate a low power delay. The
//!    will remain in low power mode 3 until the timer expires. The clock source
//!    for this timer is ACLK/8. ACLK must the sources by a 32768 Hz crystal.
//!    Hence, the effective timer frequency for this timer is 4096 HZ.
//!    Minimum delay is 1/4096Hz = 244 usec and maximum delay is
//!    65536/4098Hz = 15.99 sec
//!
//! \param pLibraryConfig pointer to GAS Metering library configuration
//!                structure
//! \param delayCount Specifies count for low power delay. Valid values
//!                          (0x0001 - 0xFFFF);
//! \param mode Specifies the low power mode to use for the delay
//! \return GASMETERING_return_code
extern GASMETERING_return_code GASMETERING_generateLPMDelay(
        GASMETERING_configuration *pLibraryConfig, uint16_t delayCount,
        GASMETERING_low_power_mode mode);

//******************************************************************************
//
// Close the Doxygen group.
//! @}
//
//******************************************************************************

//*****************************************************************************
//
//! \addtogroup algorithm_api
//! @{
//
//******************************************************************************

//! \brief Initializes algorithm
//!
//! This API must be called before calling GASMETERING_runAlgorithm API.
//! Failure to call this function  might result in unknown behavior.
//!
//! \param pLibraryConfig pointer to GAS Metering library configuration
//!                structure
//! \return  GASMETERING_return_code
extern GASMETERING_return_code GASMETERING_intializeAlgorithm(
        GASMETERING_configuration *pLibraryConfig);

//! \brief Runs ToF algorithm
//!
//! This API allows user to obtain Absolute Time of Flight, Delta
//!    ToF and volume flow rate. The have control on which calculation
//!    are run based on the selection of the following members of
//!    GASMETERING_Algorithms_Configuration structure:
//!    <ul>
//!        <li>isRunAbsToFUpEnabled</li>
//!        <li>isRunAbsToFDownEnabled</li>
//!        <li>isRunDeltaToFUpEnabled</li>
//!        <li>isRunFlowEnabled</li>
//!    </ul>
//!
//! \param pLibraryConfig pointer to GAS Metering library configuration
//!                structure
//! \param pResults  pointer to result structure.
//!
//! \return  GASMETERING_return_code
extern GASMETERING_return_code GASMETERING_runAlgorithm(
        GASMETERING_configuration *pLibraryConfig,
        GASMETERING_Algorithms_Results *pResults);

//******************************************************************************
//
// Close the Doxygen group.
//! @}
//
//******************************************************************************

#endif /* INCLUDE_GASMETERINGLIB_H_ */
