/*
 * @file exo_ahw_al_data_acq_dvc_common.c
 *
 * @brief This file has abstracted driver functions for data acquisition device
 *
 * @copyright Copyright 2023 Antaris, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdlib.h>
#include "exo_ahw_al_data_acq_dvc_common.h"
#include "exo_ahw_al_data_acq_dvc_wrapper.h"
#include "exo_ah_iob_csn.h"
#include "exo_ahdlsd.h"
#include "logger.h"
#include "exo_common.h"
#include "err_handler.h"

#ifndef LINUX_TEMP_PORT
/*!
 *  @brief API to get the data from the specified channel number
 */
hal_ret_sts ahw_al_ads7828_get_data(uint32_t ahw_id,ahw_al_ads7828_chnl chnl,ahw_al_ads7828_pd_sel pd_opt,uint16_t* data)
{
    hal_ret_sts sts;
    ahw_al_ads7828_hdle *h_dl = ahal_get_hdle(ahw_id);
    sts = ahiobcsn_check_ste(&h_dl->ahw_gen_info);
    if(HAL_SCS == sts)
    {
    	sts = err_get_fault_status(ERR_GROUP_AHW_SET_1, ahw_id-2);
		if(sts != 0)
		{
			return HAL_AH_DRIVER_ERR;
		}

        ahiobcsn_updt_ahste(&h_dl->ahw_gen_info, AH_BUSY_STATE);
        if(HAL_SCS == ahw_al_common_ads7828_get_data(h_dl,chnl,pd_opt,data))
        {
            ahiobcsn_updt_ahste(&h_dl->ahw_gen_info, AH_FREE_STATE);
            sts = HAL_SCS;
            log_id_with_one_arg(LOG_INFO_L1,LOG_AHW,AHW_AL_ADS_GET_DATA_SCS_INST_ID__eq__u32_,ahw_id);
        }
        else
        {
            err_detected(ERR_GROUP_AHW_SET_1, ahw_id-2);
            sts = HAL_AH_DRIVER_ERR;
            log_id_with_one_arg(LOG_ERROR,LOG_AHW,AHW_AL_ADS_GET_DATA_ERR_INST_ID__eq__u32_,ahw_id);
        }
    }
    else
    {

    }
    return sts;
}
#endif
