Mahesh Phalke / Mbed OS EVAL-AD7606

Dependencies:   platform_drivers

Committer:
mahphalke
Date:
Thu Jul 15 13:21:42 2021 +0530
Revision:
6:75e922b3859a
Child:
7:94f36455773c
Updated the project directory structure to remove the duplicate drivers repositories and replaced with common no-os driver repository

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mahphalke 6:75e922b3859a 1 /***************************************************************************//**
mahphalke 6:75e922b3859a 2 * @file app_config.c
mahphalke 6:75e922b3859a 3 * @brief Application configurations module (platform-agnostic)
mahphalke 6:75e922b3859a 4 * @details This module performs the system configurations
mahphalke 6:75e922b3859a 5 ********************************************************************************
mahphalke 6:75e922b3859a 6 * Copyright (c) 2020-2021 Analog Devices, Inc.
mahphalke 6:75e922b3859a 7 * All rights reserved.
mahphalke 6:75e922b3859a 8 *
mahphalke 6:75e922b3859a 9 * This software is proprietary to Analog Devices, Inc. and its licensors.
mahphalke 6:75e922b3859a 10 * By using this software you agree to the terms of the associated
mahphalke 6:75e922b3859a 11 * Analog Devices Software License Agreement.
mahphalke 6:75e922b3859a 12 *******************************************************************************/
mahphalke 6:75e922b3859a 13
mahphalke 6:75e922b3859a 14 /******************************************************************************/
mahphalke 6:75e922b3859a 15 /***************************** Include Files **********************************/
mahphalke 6:75e922b3859a 16 /******************************************************************************/
mahphalke 6:75e922b3859a 17
mahphalke 6:75e922b3859a 18 #include <stdbool.h>
mahphalke 6:75e922b3859a 19
mahphalke 6:75e922b3859a 20 #include "app_config.h"
mahphalke 6:75e922b3859a 21 #include "ad7606_data_capture.h"
mahphalke 6:75e922b3859a 22 #include "error.h"
mahphalke 6:75e922b3859a 23 #include "uart.h"
mahphalke 6:75e922b3859a 24 #include "gpio.h"
mahphalke 6:75e922b3859a 25 #include "irq.h"
mahphalke 6:75e922b3859a 26 #include "pwm.h"
mahphalke 6:75e922b3859a 27
mahphalke 6:75e922b3859a 28 /******************************************************************************/
mahphalke 6:75e922b3859a 29 /************************ Macros/Constants ************************************/
mahphalke 6:75e922b3859a 30 /******************************************************************************/
mahphalke 6:75e922b3859a 31
mahphalke 6:75e922b3859a 32 /******************************************************************************/
mahphalke 6:75e922b3859a 33 /******************** Variables and User Defined Data Types *******************/
mahphalke 6:75e922b3859a 34 /******************************************************************************/
mahphalke 6:75e922b3859a 35
mahphalke 6:75e922b3859a 36 /* UART init parameters */
mahphalke 6:75e922b3859a 37 struct uart_init_param uart_init_params = {
mahphalke 6:75e922b3859a 38 .device_id = NULL,
mahphalke 6:75e922b3859a 39 .baud_rate = IIO_UART_BAUD_RATE,
mahphalke 6:75e922b3859a 40 .extra = &uart_extra_init_params
mahphalke 6:75e922b3859a 41 };
mahphalke 6:75e922b3859a 42
mahphalke 6:75e922b3859a 43 /* LED GPO init parameters */
mahphalke 6:75e922b3859a 44 static struct gpio_init_param led_gpio_init_params = {
mahphalke 6:75e922b3859a 45 .number = LED_GPO,
mahphalke 6:75e922b3859a 46 .extra = NULL
mahphalke 6:75e922b3859a 47 };
mahphalke 6:75e922b3859a 48
mahphalke 6:75e922b3859a 49 /* External interrupt init parameters */
mahphalke 6:75e922b3859a 50 static struct irq_init_param ext_int_init_params = {
mahphalke 6:75e922b3859a 51 .irq_ctrl_id = EXTERNAL_INT_ID1,
mahphalke 6:75e922b3859a 52 .extra = &ext_int_extra_init_params
mahphalke 6:75e922b3859a 53 };
mahphalke 6:75e922b3859a 54
mahphalke 6:75e922b3859a 55 /* External interrupt callback descriptor */
mahphalke 6:75e922b3859a 56 static struct callback_desc ext_int_callback_desc = {
mahphalke 6:75e922b3859a 57 do_conversion_callback,
mahphalke 6:75e922b3859a 58 NULL,
mahphalke 6:75e922b3859a 59 NULL
mahphalke 6:75e922b3859a 60 };
mahphalke 6:75e922b3859a 61
mahphalke 6:75e922b3859a 62 /* PWM init parameters */
mahphalke 6:75e922b3859a 63 static struct pwm_init_param pwm_init_params = {
mahphalke 6:75e922b3859a 64 .id = PWM_TRIGGER, // GPIO used for PWM
mahphalke 6:75e922b3859a 65 .period_ns = CONV_TRIGGER_PERIOD_NSEC, // PWM period in nsec
mahphalke 6:75e922b3859a 66 .duty_cycle_ns = CONV_TRIGGER_DUTY_CYCLE_NSEC // PWM duty cycle in nsec
mahphalke 6:75e922b3859a 67 };
mahphalke 6:75e922b3859a 68
mahphalke 6:75e922b3859a 69 /* LED GPO descriptor */
mahphalke 6:75e922b3859a 70 gpio_desc *led_gpio_desc;
mahphalke 6:75e922b3859a 71
mahphalke 6:75e922b3859a 72 /* External interrupt descriptor */
mahphalke 6:75e922b3859a 73 struct irq_ctrl_desc *ext_int_desc;
mahphalke 6:75e922b3859a 74
mahphalke 6:75e922b3859a 75 /* PWM descriptor */
mahphalke 6:75e922b3859a 76 struct pwm_desc *pwm_desc;
mahphalke 6:75e922b3859a 77
mahphalke 6:75e922b3859a 78 /******************************************************************************/
mahphalke 6:75e922b3859a 79 /************************** Functions Declarations ****************************/
mahphalke 6:75e922b3859a 80 /******************************************************************************/
mahphalke 6:75e922b3859a 81
mahphalke 6:75e922b3859a 82 /******************************************************************************/
mahphalke 6:75e922b3859a 83 /************************** Functions Definitions *****************************/
mahphalke 6:75e922b3859a 84 /******************************************************************************/
mahphalke 6:75e922b3859a 85
mahphalke 6:75e922b3859a 86 /**
mahphalke 6:75e922b3859a 87 * @brief Initialize the GPIOs
mahphalke 6:75e922b3859a 88 * @return SUCCESS in case of success, FAILURE otherwise
mahphalke 6:75e922b3859a 89 * @details This function initialize the GPIOs used by application
mahphalke 6:75e922b3859a 90 */
mahphalke 6:75e922b3859a 91 static int32_t init_gpio(void)
mahphalke 6:75e922b3859a 92 {
mahphalke 6:75e922b3859a 93 do {
mahphalke 6:75e922b3859a 94 /* Initialize the LED GPO */
mahphalke 6:75e922b3859a 95 if (gpio_get_optional(&led_gpio_desc, &led_gpio_init_params) != SUCCESS) {
mahphalke 6:75e922b3859a 96 break;
mahphalke 6:75e922b3859a 97 }
mahphalke 6:75e922b3859a 98
mahphalke 6:75e922b3859a 99 if (gpio_direction_output(led_gpio_desc, GPIO_HIGH) != SUCCESS) {
mahphalke 6:75e922b3859a 100 break;
mahphalke 6:75e922b3859a 101 }
mahphalke 6:75e922b3859a 102
mahphalke 6:75e922b3859a 103 return SUCCESS;
mahphalke 6:75e922b3859a 104 } while (0);
mahphalke 6:75e922b3859a 105
mahphalke 6:75e922b3859a 106 return FAILURE;
mahphalke 6:75e922b3859a 107 }
mahphalke 6:75e922b3859a 108
mahphalke 6:75e922b3859a 109
mahphalke 6:75e922b3859a 110 /**
mahphalke 6:75e922b3859a 111 * @brief Initialize the IRQ contoller
mahphalke 6:75e922b3859a 112 * @return SUCCESS in case of success, FAILURE otherwise
mahphalke 6:75e922b3859a 113 * @details This function initialize the interrupts for system peripherals
mahphalke 6:75e922b3859a 114 */
mahphalke 6:75e922b3859a 115 static int32_t init_interrupt(void)
mahphalke 6:75e922b3859a 116 {
mahphalke 6:75e922b3859a 117 do {
mahphalke 6:75e922b3859a 118 /* Init interrupt controller for external interrupt */
mahphalke 6:75e922b3859a 119 if (irq_ctrl_init(&ext_int_desc, &ext_int_init_params) != SUCCESS) {
mahphalke 6:75e922b3859a 120 break;
mahphalke 6:75e922b3859a 121 }
mahphalke 6:75e922b3859a 122
mahphalke 6:75e922b3859a 123 /* Register a callback function for external interrupt */
mahphalke 6:75e922b3859a 124 if (irq_register_callback(ext_int_desc,
mahphalke 6:75e922b3859a 125 EXTERNAL_INT_ID1,
mahphalke 6:75e922b3859a 126 &ext_int_callback_desc) != SUCCESS) {
mahphalke 6:75e922b3859a 127 break;
mahphalke 6:75e922b3859a 128 }
mahphalke 6:75e922b3859a 129
mahphalke 6:75e922b3859a 130 return SUCCESS;
mahphalke 6:75e922b3859a 131 } while (0);
mahphalke 6:75e922b3859a 132
mahphalke 6:75e922b3859a 133 return FAILURE;
mahphalke 6:75e922b3859a 134 }
mahphalke 6:75e922b3859a 135
mahphalke 6:75e922b3859a 136
mahphalke 6:75e922b3859a 137 /**
mahphalke 6:75e922b3859a 138 * @brief Initialize the PWM contoller
mahphalke 6:75e922b3859a 139 * @return SUCCESS in case of success, FAILURE otherwise
mahphalke 6:75e922b3859a 140 */
mahphalke 6:75e922b3859a 141 static int32_t init_pwm(void)
mahphalke 6:75e922b3859a 142 {
mahphalke 6:75e922b3859a 143 do {
mahphalke 6:75e922b3859a 144 /* Initialize the PWM interface to generate PWM signal
mahphalke 6:75e922b3859a 145 * on conversion trigger event pin */
mahphalke 6:75e922b3859a 146 if (pwm_init(&pwm_desc, &pwm_init_params) != SUCCESS) {
mahphalke 6:75e922b3859a 147 break;
mahphalke 6:75e922b3859a 148 }
mahphalke 6:75e922b3859a 149
mahphalke 6:75e922b3859a 150 if (pwm_enable(pwm_desc) != SUCCESS) {
mahphalke 6:75e922b3859a 151 break;
mahphalke 6:75e922b3859a 152 }
mahphalke 6:75e922b3859a 153
mahphalke 6:75e922b3859a 154 return SUCCESS;
mahphalke 6:75e922b3859a 155 } while (0);
mahphalke 6:75e922b3859a 156
mahphalke 6:75e922b3859a 157 return FAILURE;
mahphalke 6:75e922b3859a 158 }
mahphalke 6:75e922b3859a 159
mahphalke 6:75e922b3859a 160
mahphalke 6:75e922b3859a 161 /**
mahphalke 6:75e922b3859a 162 * @brief Initialize the system peripherals
mahphalke 6:75e922b3859a 163 * @return SUCCESS in case of success, FAILURE otherwise
mahphalke 6:75e922b3859a 164 */
mahphalke 6:75e922b3859a 165 int32_t init_system(void)
mahphalke 6:75e922b3859a 166 {
mahphalke 6:75e922b3859a 167 if (init_gpio() != SUCCESS) {
mahphalke 6:75e922b3859a 168 return FAILURE;
mahphalke 6:75e922b3859a 169 }
mahphalke 6:75e922b3859a 170
mahphalke 6:75e922b3859a 171 if (init_interrupt() != SUCCESS) {
mahphalke 6:75e922b3859a 172 return FAILURE;
mahphalke 6:75e922b3859a 173 }
mahphalke 6:75e922b3859a 174
mahphalke 6:75e922b3859a 175 if (init_pwm() != SUCCESS) {
mahphalke 6:75e922b3859a 176 return FAILURE;
mahphalke 6:75e922b3859a 177 }
mahphalke 6:75e922b3859a 178
mahphalke 6:75e922b3859a 179 return SUCCESS;
mahphalke 6:75e922b3859a 180 }