Analog Devices / Mbed OS EVAL-AD717x-AD411x-IIO

Dependencies:   sdp_k1_sdram

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers app_config.c Source File

app_config.c

Go to the documentation of this file.
00001 /***************************************************************************//**
00002  * @file    app_config.c
00003  * @brief   Source file for the application configuration for AD717x IIO Application
00004 ********************************************************************************
00005 * Copyright (c) 2021-22 Analog Devices, Inc.
00006 * All rights reserved.
00007 *
00008 * This software is proprietary to Analog Devices, Inc. and its licensors.
00009 * By using this software you agree to the terms of the associated
00010 * Analog Devices Software License Agreement.
00011 *******************************************************************************/
00012 
00013 /******************************************************************************/
00014 /***************************** Include Files **********************************/
00015 /******************************************************************************/
00016 
00017 #include <stdio.h>
00018 #include "no_os_uart.h"
00019 #include "ad717x.h"
00020 #include "app_config.h"
00021 #include "no_os_gpio.h"
00022 #include "no_os_irq.h"
00023 #include "ad717x_data_capture.h"
00024 #include "no_os_error.h"
00025 
00026 /******************************************************************************/
00027 /********************* Macros and Constants Definition ************************/
00028 /******************************************************************************/
00029 
00030 /******************************************************************************/
00031 /******************** Variables and User Defined Data Types *******************/
00032 /******************************************************************************/
00033 
00034 /* The UART Descriptor */
00035 struct no_os_uart_desc *uart_desc;
00036 
00037 /* GPIO descriptor for the chip select pin */
00038 struct no_os_gpio_desc *csb_gpio;
00039 
00040 /* GPIO descriptor for the RDY pin */
00041 struct no_os_gpio_desc *rdy_gpio;
00042 
00043 /* External interrupt descriptor */
00044 struct no_os_irq_ctrl_desc *external_int_desc;
00045 
00046 /* UART Initialization Parameters */
00047 static struct no_os_uart_init_param uart_init_params = {
00048     .device_id = NULL,
00049     .baud_rate = IIO_UART_BAUD_RATE,
00050     .size = NO_OS_UART_CS_8,
00051     .parity = NO_OS_UART_PAR_NO,
00052     .stop = NO_OS_UART_STOP_1_BIT,
00053     .extra = &uart_extra_init_params
00054 };
00055 
00056 /* GPIO - Chip select Pin init parameters */
00057 static struct no_os_gpio_init_param csb_init_param = {
00058     .number = SPI_CSB,
00059     .platform_ops = &csb_platform_ops,
00060     .extra = NULL
00061 };
00062 
00063 /* GPIO RDY Pin init parameters */
00064 static struct no_os_gpio_init_param rdy_init_param = {
00065     .number = RDY_PIN,
00066     .platform_ops = &rdy_platform_ops,
00067     .extra = NULL
00068 };
00069 
00070 /* External interrupt init parameters */
00071 static struct no_os_irq_init_param ext_int_init_params = {
00072     .irq_ctrl_id = 0,
00073     .platform_ops = &irq_platform_ops,
00074     .extra = &ext_int_extra_init_params
00075 };
00076 
00077 /* External interrupt callback descriptor */
00078 static struct no_os_callback_desc ext_int_callback_desc = {
00079     data_capture_callback,
00080     NULL,
00081     NULL
00082 };
00083 
00084 /******************************************************************************/
00085 /************************** Functions Declaration *****************************/
00086 /******************************************************************************/
00087 
00088 /******************************************************************************/
00089 /************************** Functions Definition ******************************/
00090 /******************************************************************************/
00091 
00092 /**
00093  * @brief   Initialize the UART peripheral
00094  * @return  SUCCESS in case of success, negative error code
00095  */
00096 static int32_t init_uart(void)
00097 {
00098     return no_os_uart_init(&uart_desc, &uart_init_params);
00099 }
00100 
00101 
00102 /**
00103  * @brief Initialize the IRQ contoller
00104  * @return SUCCESS in case of success, negative error code otherwise
00105  * @details This function initialize the interrupts for system peripherals
00106  */
00107 int32_t init_interrupt(void)
00108 {
00109     int32_t ret;
00110 
00111     do {
00112         /* Init interrupt controller for external interrupt */
00113         ret = no_os_irq_ctrl_init(&external_int_desc, &ext_int_init_params);
00114         if (ret) {
00115             break;
00116         }
00117 
00118         /* Register a callback function for external interrupt */
00119         ret = no_os_irq_register_callback(external_int_desc, IRQ_INT_ID,
00120                           &ext_int_callback_desc);
00121         if (ret) {
00122             break;
00123         }
00124         ret = no_os_irq_trigger_level_set(external_int_desc, IRQ_INT_ID,
00125                           NO_OS_IRQ_EDGE_FALLING);
00126         if (ret) {
00127             return ret;
00128         }
00129 
00130         return 0;
00131     } while (0);
00132 
00133     return ret;
00134 }
00135 
00136 
00137 /**
00138  * @brief   Initialize the system peripherals
00139  * @return  SUCCESS in case of success, negative error code otherwise
00140  */
00141 int32_t init_system(void)
00142 {
00143     int32_t ret;
00144 
00145     if (init_uart() != 0) {
00146         return -EINVAL;
00147     }
00148 
00149 #if defined(USE_SDRAM_CAPTURE_BUFFER)
00150     if (sdram_init() != 0) {
00151         return -EINVAL;
00152     }
00153 #endif
00154 
00155 #if (DATA_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
00156     ret = init_interrupt();
00157     if (ret) {
00158         return ret;
00159     }
00160 
00161     ret = no_os_gpio_get(&csb_gpio, &csb_init_param);
00162     if (ret) {
00163         return ret;
00164     }
00165 
00166     ret = no_os_gpio_direction_output(csb_gpio, NO_OS_GPIO_HIGH);
00167     if (ret) {
00168         return ret;
00169     }
00170 
00171     ret = no_os_gpio_get(&rdy_gpio, &rdy_init_param);
00172     if (ret) {
00173         return ret;
00174     }
00175 
00176     ret = no_os_gpio_direction_input(rdy_gpio);
00177     if (ret) {
00178         return ret;
00179     }
00180 #endif
00181     return 0;
00182 }