Program files for Example program for EVAL-AD7768-1

Dependencies:   platform_drivers

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  *   @details This module contains the configurations needed for IIO application
00005 ********************************************************************************
00006  * Copyright (c) 2021 Analog Devices, Inc.
00007  * All rights reserved.
00008  *
00009  * This software is proprietary to Analog Devices, Inc. and its licensors.
00010  * By using this software you agree to the terms of the associated
00011  * Analog Devices Software License Agreement.
00012 *******************************************************************************/
00013 
00014 /******************************************************************************/
00015 /***************************** Include Files **********************************/
00016 /******************************************************************************/
00017 
00018 #include <stdbool.h>
00019 
00020 #include "app_config.h"
00021 #include "adc_data_capture.h"
00022 #include "ad77681_iio.h"
00023 #include "error.h"
00024 #include "uart.h"
00025 #include "irq.h"
00026 #include "gpio.h"
00027 
00028 /******************************************************************************/
00029 /************************ Macros/Constants ************************************/
00030 /******************************************************************************/
00031 
00032 /******************************************************************************/
00033 /*************************** Types Declarations *******************************/
00034 /******************************************************************************/
00035 
00036 /*
00037  * UART init parameters structure
00038  */
00039 struct uart_init_param uart_init_params = {
00040     .device_id = NULL,
00041     .baud_rate = IIO_UART_BAUD_RATE,
00042     .extra = &uart_init_extra_params
00043 };
00044 
00045 /* LED GPIO descriptor */
00046 struct gpio_init_param gpio_init_led_green = {
00047     .number = LED_GREEN,
00048     .extra = NULL
00049 };
00050 
00051 /* External interrupt init parameters */
00052 struct irq_init_param external_int_init_param = {
00053     .irq_ctrl_id = EXTERNAL_INT_ID1,
00054     .extra = &mbed_ext_int_init_param
00055 };
00056 
00057 /* External interrupt callback descriptor */
00058 struct callback_desc external_int_callback_desc = {
00059     data_capture_callback,
00060     NULL,
00061     NULL
00062 };
00063 
00064 /* LED GPIO descriptor */
00065 gpio_desc *led_green_gpio_desc = NULL;
00066 
00067 /* External interrupt descriptor */
00068 struct irq_ctrl_desc *external_int_desc;
00069 
00070 /******************************************************************************/
00071 /************************ Functions Prototypes ********************************/
00072 /******************************************************************************/
00073 
00074 /******************************************************************************/
00075 /************************ Functions Definitions *******************************/
00076 /******************************************************************************/
00077 
00078 /**
00079  * @brief   Initialize the GPIOs
00080  * @return  SUCCESS in case of success, FAILURE otherwise
00081  * @details This function initialize the GPIOs used by application
00082  */
00083 static int32_t init_gpio(void)
00084 {
00085     /* Initialize the LED GREEN GPIO */
00086     if (gpio_get_optional(&led_green_gpio_desc, &gpio_init_led_green) != SUCCESS) {
00087         return FAILURE;
00088     }
00089 
00090     if (led_green_gpio_desc) {
00091         if (gpio_direction_output(led_green_gpio_desc, GPIO_HIGH) != SUCCESS) {
00092             return FAILURE;
00093         }
00094     }
00095 
00096     return SUCCESS;
00097 }
00098 
00099 /**
00100  * @brief   Initialize the IRQ contoller
00101  * @return  SUCCESS in case of success, FAILURE otherwise
00102  * @details This function initialize the interrupts for system peripherals
00103  */
00104 static int32_t init_interrupt(void)
00105 {
00106     /* Init interrupt controller for external interrupt */
00107     if (irq_ctrl_init(&external_int_desc, &external_int_init_param) == FAILURE) {
00108         return FAILURE;
00109     }
00110 
00111     /* Register a callback function for external interrupt */
00112     if (irq_register_callback(external_int_desc,
00113                   EXTERNAL_INT_ID1,
00114                   &external_int_callback_desc) == FAILURE) {
00115         return FAILURE;
00116     }
00117 
00118     return SUCCESS;
00119 }
00120 
00121 /**
00122  * @brief   Initialize the system peripherals
00123  * @return  SUCCESS in case of success, FAILURE otherwise
00124  */
00125 int32_t init_system(void)
00126 {
00127     if (init_gpio() != SUCCESS) {
00128         return FAILURE;
00129     }
00130 
00131     if (init_interrupt() != SUCCESS) {
00132         return FAILURE;
00133     }
00134 
00135     return SUCCESS;
00136 }