Analog Devices / Mbed OS EVAL-AD4110

Dependencies:   tempsensors 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   Application configurations module
00004 ********************************************************************************
00005  * Copyright (c) 2022 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 "app_config.h"
00018 #include "no_os_uart.h"
00019 #include "ad4110_data_capture.h"
00020 
00021 /******************************************************************************/
00022 /************************ Macros/Constants ************************************/
00023 /******************************************************************************/
00024 
00025 /******************************************************************************/
00026 /*************************** Types Declarations *******************************/
00027 /******************************************************************************/
00028 
00029 /* UART init parameters */
00030 struct no_os_uart_init_param uart_init_params = {
00031     .device_id = NULL,
00032     .baud_rate = IIO_UART_BAUD_RATE,
00033     .size = NO_OS_UART_CS_8,
00034     .parity = NO_OS_UART_PAR_NO,
00035     .stop = NO_OS_UART_STOP_1_BIT,
00036     .extra = &uart_extra_init_params
00037 };
00038 
00039 /* GPIO - Chip select Pin init parameters */
00040 static struct no_os_gpio_init_param csb_init_param = {
00041     .number = SPI_CSB,
00042     .platform_ops = &csb_platform_ops
00043 };
00044 
00045 #if (DATA_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
00046 /* External interrupt init parameters */
00047 static struct no_os_irq_init_param ext_int_init_params = {
00048     .irq_ctrl_id = 0,
00049     .extra = &ext_int_extra_init_params,
00050     .platform_ops = &irq_platform_ops,
00051 };
00052 /* External interrupt callback descriptor */
00053 static struct no_os_callback_desc ext_int_callback_desc = {
00054     data_capture_callback,
00055     NULL,
00056     NULL
00057 };
00058 #endif
00059 
00060 /* UART descriptor */
00061 struct no_os_uart_desc *uart_desc;
00062 
00063 /* GPIO descriptor for the chip select pin */
00064 no_os_gpio_desc *csb_gpio;
00065 
00066 /* External interrupt descriptor */
00067 struct no_os_irq_ctrl_desc *external_int_desc;
00068 
00069 /******************************************************************************/
00070 /************************ Functions Prototypes ********************************/
00071 /******************************************************************************/
00072 
00073 /******************************************************************************/
00074 /************************ Functions Definitions *******************************/
00075 /******************************************************************************/
00076 
00077 /**
00078  * @brief Initialize the UART peripheral
00079  * @return 0 in case of success, negative error code otherwise
00080  */
00081 static int32_t init_uart(void)
00082 {
00083     return no_os_uart_init(&uart_desc, &uart_init_params);
00084 }
00085 
00086 
00087 #if (DATA_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
00088 /**
00089  * @brief Initialize the IRQ contoller
00090  * @return 0 in case of success, negative error code otherwise
00091  * @details This function initialize the interrupts for system peripherals
00092  */
00093 int32_t init_interrupt(void)
00094 {
00095     int32_t ret;
00096 
00097     do {
00098         /* Init interrupt controller for external interrupt */
00099         ret = no_os_irq_ctrl_init(&external_int_desc, &ext_int_init_params);
00100         if (ret) {
00101             break;
00102         }
00103 
00104         /* Register a callback function for external interrupt */
00105         ret = no_os_irq_register_callback(external_int_desc,
00106                           IRQ_INT_ID,
00107                           &ext_int_callback_desc);
00108         if (ret) {
00109             break;
00110         }
00111 
00112         return 0;
00113     } while (0);
00114 
00115     return ret;
00116 }
00117 #endif
00118 
00119 
00120 /**
00121  * @brief Initialize the system peripherals
00122  * @return 0 in case of success, Negative error code otherwise
00123  */
00124 int32_t init_system(void)
00125 {
00126     int32_t ret;
00127 
00128     ret = init_uart();
00129     if (ret) {
00130         return ret;
00131     }
00132 
00133 #if defined(USE_SDRAM_CAPTURE_BUFFER)
00134     ret = sdram_init();
00135     if (ret) {
00136         return ret;
00137     }
00138 #endif
00139 
00140 #if (DATA_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
00141     ret = init_interrupt();
00142     if (ret) {
00143         return ret;
00144     }
00145 
00146     ret = no_os_gpio_get(&csb_gpio, &csb_init_param);
00147     if (ret) {
00148         return ret;
00149     }
00150 
00151     ret = no_os_gpio_direction_output(csb_gpio, NO_OS_GPIO_HIGH);
00152     if (ret) {
00153         return ret;
00154     }
00155 #endif
00156 
00157     return 0;
00158 }