IIO Application Library

Dependents:  

Committer:
mahphalke
Date:
Mon Oct 05 12:28:13 2020 +0530
Revision:
1:182a6f54cab0
IIO application library- Initial Revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mahphalke 1:182a6f54cab0 1 /***************************************************************************//**
mahphalke 1:182a6f54cab0 2 * @file iio_app.c
mahphalke 1:182a6f54cab0 3 * @brief Implementation of iio_app.
mahphalke 1:182a6f54cab0 4 * This application instantiates iio_axi_adc and iio_axi_dac devices, for
mahphalke 1:182a6f54cab0 5 * reading/writing and parameterization.
mahphalke 1:182a6f54cab0 6 * @author Cristian Pop (cristian.pop@analog.com)
mahphalke 1:182a6f54cab0 7 ********************************************************************************
mahphalke 1:182a6f54cab0 8 * Copyright 2019, 2020(c) Analog Devices, Inc.
mahphalke 1:182a6f54cab0 9 *
mahphalke 1:182a6f54cab0 10 * All rights reserved.
mahphalke 1:182a6f54cab0 11 *
mahphalke 1:182a6f54cab0 12 * Redistribution and use in source and binary forms, with or without
mahphalke 1:182a6f54cab0 13 * modification, are permitted provided that the following conditions are met:
mahphalke 1:182a6f54cab0 14 * - Redistributions of source code must retain the above copyright
mahphalke 1:182a6f54cab0 15 * notice, this list of conditions and the following disclaimer.
mahphalke 1:182a6f54cab0 16 * - Redistributions in binary form must reproduce the above copyright
mahphalke 1:182a6f54cab0 17 * notice, this list of conditions and the following disclaimer in
mahphalke 1:182a6f54cab0 18 * the documentation and/or other materials provided with the
mahphalke 1:182a6f54cab0 19 * distribution.
mahphalke 1:182a6f54cab0 20 * - Neither the name of Analog Devices, Inc. nor the names of its
mahphalke 1:182a6f54cab0 21 * contributors may be used to endorse or promote products derived
mahphalke 1:182a6f54cab0 22 * from this software without specific prior written permission.
mahphalke 1:182a6f54cab0 23 * - The use of this software may or may not infringe the patent rights
mahphalke 1:182a6f54cab0 24 * of one or more patent holders. This license does not release you
mahphalke 1:182a6f54cab0 25 * from the requirement that you obtain separate licenses from these
mahphalke 1:182a6f54cab0 26 * patent holders to use this software.
mahphalke 1:182a6f54cab0 27 * - Use of the software either in source or binary form, must be run
mahphalke 1:182a6f54cab0 28 * on or directly connected to an Analog Devices Inc. component.
mahphalke 1:182a6f54cab0 29 *
mahphalke 1:182a6f54cab0 30 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
mahphalke 1:182a6f54cab0 31 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
mahphalke 1:182a6f54cab0 32 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
mahphalke 1:182a6f54cab0 33 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
mahphalke 1:182a6f54cab0 34 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
mahphalke 1:182a6f54cab0 35 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
mahphalke 1:182a6f54cab0 36 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mahphalke 1:182a6f54cab0 37 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mahphalke 1:182a6f54cab0 38 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mahphalke 1:182a6f54cab0 39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mahphalke 1:182a6f54cab0 40 *******************************************************************************/
mahphalke 1:182a6f54cab0 41
mahphalke 1:182a6f54cab0 42 /******************************************************************************/
mahphalke 1:182a6f54cab0 43 /***************************** Include Files **********************************/
mahphalke 1:182a6f54cab0 44 /******************************************************************************/
mahphalke 1:182a6f54cab0 45
mahphalke 1:182a6f54cab0 46 #include "error.h"
mahphalke 1:182a6f54cab0 47 #include "iio.h"
mahphalke 1:182a6f54cab0 48 #include "iio_app.h"
mahphalke 1:182a6f54cab0 49
mahphalke 1:182a6f54cab0 50 /**
mahphalke 1:182a6f54cab0 51 * @brief Application parameterization.
mahphalke 1:182a6f54cab0 52 * @param desc - Application descriptor.
mahphalke 1:182a6f54cab0 53 * @param param - Application initial configuration structure.
mahphalke 1:182a6f54cab0 54 * @return SUCCESS in case of success, FAILURE otherwise.
mahphalke 1:182a6f54cab0 55 */
mahphalke 1:182a6f54cab0 56 int32_t iio_app_init(struct iio_app_desc **desc,
mahphalke 1:182a6f54cab0 57 struct iio_app_init_param *param)
mahphalke 1:182a6f54cab0 58 {
mahphalke 1:182a6f54cab0 59 struct tinyiiod *iiod;
mahphalke 1:182a6f54cab0 60 int32_t status;
mahphalke 1:182a6f54cab0 61
mahphalke 1:182a6f54cab0 62 if (!param)
mahphalke 1:182a6f54cab0 63 return FAILURE;
mahphalke 1:182a6f54cab0 64
mahphalke 1:182a6f54cab0 65 status = iio_init(&iiod, param->iio_server_ops);
mahphalke 1:182a6f54cab0 66 if(status < 0)
mahphalke 1:182a6f54cab0 67 return status;
mahphalke 1:182a6f54cab0 68
mahphalke 1:182a6f54cab0 69 *desc = calloc(1, sizeof(struct iio_app_desc));
mahphalke 1:182a6f54cab0 70 if (!(*desc))
mahphalke 1:182a6f54cab0 71 return FAILURE;
mahphalke 1:182a6f54cab0 72
mahphalke 1:182a6f54cab0 73 (*desc)->iiod = iiod;
mahphalke 1:182a6f54cab0 74
mahphalke 1:182a6f54cab0 75 return SUCCESS;
mahphalke 1:182a6f54cab0 76 }
mahphalke 1:182a6f54cab0 77
mahphalke 1:182a6f54cab0 78 /**
mahphalke 1:182a6f54cab0 79 * @brief Release resources.
mahphalke 1:182a6f54cab0 80 * @param desc - Application descriptor.
mahphalke 1:182a6f54cab0 81 * @return SUCCESS in case of success, FAILURE otherwise.
mahphalke 1:182a6f54cab0 82 */
mahphalke 1:182a6f54cab0 83 int32_t iio_app_remove(struct iio_app_desc *desc)
mahphalke 1:182a6f54cab0 84 {
mahphalke 1:182a6f54cab0 85 int32_t status;
mahphalke 1:182a6f54cab0 86
mahphalke 1:182a6f54cab0 87 if (!desc)
mahphalke 1:182a6f54cab0 88 return FAILURE;
mahphalke 1:182a6f54cab0 89
mahphalke 1:182a6f54cab0 90 status = iio_remove(desc->iiod);
mahphalke 1:182a6f54cab0 91 if(status < 0)
mahphalke 1:182a6f54cab0 92 return status;
mahphalke 1:182a6f54cab0 93
mahphalke 1:182a6f54cab0 94 free(desc);
mahphalke 1:182a6f54cab0 95
mahphalke 1:182a6f54cab0 96 return SUCCESS;
mahphalke 1:182a6f54cab0 97 }
mahphalke 1:182a6f54cab0 98
mahphalke 1:182a6f54cab0 99 /**
mahphalke 1:182a6f54cab0 100 * @brief iio application, reads commands and executes them.
mahphalke 1:182a6f54cab0 101 * @param desc - Application descriptor.
mahphalke 1:182a6f54cab0 102 * @return: SUCCESS in case of success, FAILURE otherwise.
mahphalke 1:182a6f54cab0 103 */
mahphalke 1:182a6f54cab0 104 int32_t iio_app(struct iio_app_desc *desc)
mahphalke 1:182a6f54cab0 105 {
mahphalke 1:182a6f54cab0 106 int32_t status;
mahphalke 1:182a6f54cab0 107
mahphalke 1:182a6f54cab0 108 status = tinyiiod_read_command(desc->iiod);
mahphalke 1:182a6f54cab0 109 if(status < 0)
mahphalke 1:182a6f54cab0 110 return status;
mahphalke 1:182a6f54cab0 111 }