IIO firmware for the AD4110

Dependencies:   tempsensors sdp_k1_sdram

Committer:
Janani Sunil
Date:
Mon Aug 01 11:09:48 2022 +0530
Revision:
1:a78dbaa4b05d
Parent:
0:6ca37a8f8ba9
Initial implementation of AD4110 IIO Firmware

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Janani Sunil 0:6ca37a8f8ba9 1 /***************************************************************************//**
Janani Sunil 0:6ca37a8f8ba9 2 * @file app_config.c
Janani Sunil 0:6ca37a8f8ba9 3 * @brief Application configurations module
Janani Sunil 0:6ca37a8f8ba9 4 ********************************************************************************
Janani Sunil 0:6ca37a8f8ba9 5 * Copyright (c) 2022 Analog Devices, Inc.
Janani Sunil 0:6ca37a8f8ba9 6 * All rights reserved.
Janani Sunil 0:6ca37a8f8ba9 7 *
Janani Sunil 0:6ca37a8f8ba9 8 * This software is proprietary to Analog Devices, Inc. and its licensors.
Janani Sunil 0:6ca37a8f8ba9 9 * By using this software you agree to the terms of the associated
Janani Sunil 0:6ca37a8f8ba9 10 * Analog Devices Software License Agreement.
Janani Sunil 0:6ca37a8f8ba9 11 *******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 12
Janani Sunil 0:6ca37a8f8ba9 13 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 14 /***************************** Include Files **********************************/
Janani Sunil 0:6ca37a8f8ba9 15 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 16
Janani Sunil 0:6ca37a8f8ba9 17 #include "app_config.h"
Janani Sunil 0:6ca37a8f8ba9 18 #include "no_os_uart.h"
Janani Sunil 0:6ca37a8f8ba9 19 #include "ad4110_data_capture.h"
Janani Sunil 0:6ca37a8f8ba9 20
Janani Sunil 0:6ca37a8f8ba9 21 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 22 /************************ Macros/Constants ************************************/
Janani Sunil 0:6ca37a8f8ba9 23 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 24
Janani Sunil 0:6ca37a8f8ba9 25 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 26 /*************************** Types Declarations *******************************/
Janani Sunil 0:6ca37a8f8ba9 27 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 28
Janani Sunil 0:6ca37a8f8ba9 29 /* UART init parameters */
Janani Sunil 0:6ca37a8f8ba9 30 struct no_os_uart_init_param uart_init_params = {
Janani Sunil 0:6ca37a8f8ba9 31 .device_id = NULL,
Janani Sunil 0:6ca37a8f8ba9 32 .baud_rate = IIO_UART_BAUD_RATE,
Janani Sunil 0:6ca37a8f8ba9 33 .size = NO_OS_UART_CS_8,
Janani Sunil 0:6ca37a8f8ba9 34 .parity = NO_OS_UART_PAR_NO,
Janani Sunil 0:6ca37a8f8ba9 35 .stop = NO_OS_UART_STOP_1_BIT,
Janani Sunil 0:6ca37a8f8ba9 36 .extra = &uart_extra_init_params
Janani Sunil 0:6ca37a8f8ba9 37 };
Janani Sunil 0:6ca37a8f8ba9 38
Janani Sunil 0:6ca37a8f8ba9 39 /* GPIO - Chip select Pin init parameters */
Janani Sunil 0:6ca37a8f8ba9 40 static struct no_os_gpio_init_param csb_init_param = {
Janani Sunil 0:6ca37a8f8ba9 41 .number = SPI_CSB,
Janani Sunil 0:6ca37a8f8ba9 42 .platform_ops = &csb_platform_ops
Janani Sunil 0:6ca37a8f8ba9 43 };
Janani Sunil 0:6ca37a8f8ba9 44
Janani Sunil 0:6ca37a8f8ba9 45 #if (DATA_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
Janani Sunil 0:6ca37a8f8ba9 46 /* External interrupt init parameters */
Janani Sunil 0:6ca37a8f8ba9 47 static struct no_os_irq_init_param ext_int_init_params = {
Janani Sunil 0:6ca37a8f8ba9 48 .irq_ctrl_id = 0,
Janani Sunil 0:6ca37a8f8ba9 49 .extra = &ext_int_extra_init_params,
Janani Sunil 0:6ca37a8f8ba9 50 .platform_ops = &irq_platform_ops,
Janani Sunil 0:6ca37a8f8ba9 51 };
Janani Sunil 0:6ca37a8f8ba9 52 /* External interrupt callback descriptor */
Janani Sunil 0:6ca37a8f8ba9 53 static struct no_os_callback_desc ext_int_callback_desc = {
Janani Sunil 0:6ca37a8f8ba9 54 data_capture_callback,
Janani Sunil 0:6ca37a8f8ba9 55 NULL,
Janani Sunil 0:6ca37a8f8ba9 56 NULL
Janani Sunil 0:6ca37a8f8ba9 57 };
Janani Sunil 0:6ca37a8f8ba9 58 #endif
Janani Sunil 0:6ca37a8f8ba9 59
Janani Sunil 0:6ca37a8f8ba9 60 /* UART descriptor */
Janani Sunil 0:6ca37a8f8ba9 61 struct no_os_uart_desc *uart_desc;
Janani Sunil 0:6ca37a8f8ba9 62
Janani Sunil 0:6ca37a8f8ba9 63 /* GPIO descriptor for the chip select pin */
Janani Sunil 0:6ca37a8f8ba9 64 no_os_gpio_desc *csb_gpio;
Janani Sunil 0:6ca37a8f8ba9 65
Janani Sunil 0:6ca37a8f8ba9 66 /* External interrupt descriptor */
Janani Sunil 0:6ca37a8f8ba9 67 struct no_os_irq_ctrl_desc *external_int_desc;
Janani Sunil 0:6ca37a8f8ba9 68
Janani Sunil 0:6ca37a8f8ba9 69 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 70 /************************ Functions Prototypes ********************************/
Janani Sunil 0:6ca37a8f8ba9 71 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 72
Janani Sunil 0:6ca37a8f8ba9 73 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 74 /************************ Functions Definitions *******************************/
Janani Sunil 0:6ca37a8f8ba9 75 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 76
Janani Sunil 0:6ca37a8f8ba9 77 /**
Janani Sunil 0:6ca37a8f8ba9 78 * @brief Initialize the UART peripheral
Janani Sunil 0:6ca37a8f8ba9 79 * @return 0 in case of success, negative error code otherwise
Janani Sunil 0:6ca37a8f8ba9 80 */
Janani Sunil 0:6ca37a8f8ba9 81 static int32_t init_uart(void)
Janani Sunil 0:6ca37a8f8ba9 82 {
Janani Sunil 0:6ca37a8f8ba9 83 return no_os_uart_init(&uart_desc, &uart_init_params);
Janani Sunil 0:6ca37a8f8ba9 84 }
Janani Sunil 0:6ca37a8f8ba9 85
Janani Sunil 0:6ca37a8f8ba9 86
Janani Sunil 0:6ca37a8f8ba9 87 #if (DATA_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
Janani Sunil 0:6ca37a8f8ba9 88 /**
Janani Sunil 0:6ca37a8f8ba9 89 * @brief Initialize the IRQ contoller
Janani Sunil 0:6ca37a8f8ba9 90 * @return 0 in case of success, negative error code otherwise
Janani Sunil 0:6ca37a8f8ba9 91 * @details This function initialize the interrupts for system peripherals
Janani Sunil 0:6ca37a8f8ba9 92 */
Janani Sunil 0:6ca37a8f8ba9 93 int32_t init_interrupt(void)
Janani Sunil 0:6ca37a8f8ba9 94 {
Janani Sunil 0:6ca37a8f8ba9 95 int32_t ret;
Janani Sunil 0:6ca37a8f8ba9 96
Janani Sunil 0:6ca37a8f8ba9 97 do {
Janani Sunil 0:6ca37a8f8ba9 98 /* Init interrupt controller for external interrupt */
Janani Sunil 0:6ca37a8f8ba9 99 ret = no_os_irq_ctrl_init(&external_int_desc, &ext_int_init_params);
Janani Sunil 0:6ca37a8f8ba9 100 if (ret) {
Janani Sunil 0:6ca37a8f8ba9 101 break;
Janani Sunil 0:6ca37a8f8ba9 102 }
Janani Sunil 0:6ca37a8f8ba9 103
Janani Sunil 0:6ca37a8f8ba9 104 /* Register a callback function for external interrupt */
Janani Sunil 0:6ca37a8f8ba9 105 ret = no_os_irq_register_callback(external_int_desc,
Janani Sunil 0:6ca37a8f8ba9 106 IRQ_INT_ID,
Janani Sunil 0:6ca37a8f8ba9 107 &ext_int_callback_desc);
Janani Sunil 0:6ca37a8f8ba9 108 if (ret) {
Janani Sunil 0:6ca37a8f8ba9 109 break;
Janani Sunil 0:6ca37a8f8ba9 110 }
Janani Sunil 0:6ca37a8f8ba9 111
Janani Sunil 0:6ca37a8f8ba9 112 return 0;
Janani Sunil 0:6ca37a8f8ba9 113 } while (0);
Janani Sunil 0:6ca37a8f8ba9 114
Janani Sunil 0:6ca37a8f8ba9 115 return ret;
Janani Sunil 0:6ca37a8f8ba9 116 }
Janani Sunil 0:6ca37a8f8ba9 117 #endif
Janani Sunil 0:6ca37a8f8ba9 118
Janani Sunil 0:6ca37a8f8ba9 119
Janani Sunil 0:6ca37a8f8ba9 120 /**
Janani Sunil 0:6ca37a8f8ba9 121 * @brief Initialize the system peripherals
Janani Sunil 0:6ca37a8f8ba9 122 * @return 0 in case of success, Negative error code otherwise
Janani Sunil 0:6ca37a8f8ba9 123 */
Janani Sunil 0:6ca37a8f8ba9 124 int32_t init_system(void)
Janani Sunil 0:6ca37a8f8ba9 125 {
Janani Sunil 0:6ca37a8f8ba9 126 int32_t ret;
Janani Sunil 0:6ca37a8f8ba9 127
Janani Sunil 0:6ca37a8f8ba9 128 ret = init_uart();
Janani Sunil 0:6ca37a8f8ba9 129 if (ret) {
Janani Sunil 0:6ca37a8f8ba9 130 return ret;
Janani Sunil 0:6ca37a8f8ba9 131 }
Janani Sunil 0:6ca37a8f8ba9 132
Janani Sunil 0:6ca37a8f8ba9 133 #if defined(USE_SDRAM_CAPTURE_BUFFER)
Janani Sunil 0:6ca37a8f8ba9 134 ret = sdram_init();
Janani Sunil 0:6ca37a8f8ba9 135 if (ret) {
Janani Sunil 0:6ca37a8f8ba9 136 return ret;
Janani Sunil 0:6ca37a8f8ba9 137 }
Janani Sunil 0:6ca37a8f8ba9 138 #endif
Janani Sunil 0:6ca37a8f8ba9 139
Janani Sunil 0:6ca37a8f8ba9 140 #if (DATA_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
Janani Sunil 0:6ca37a8f8ba9 141 ret = init_interrupt();
Janani Sunil 0:6ca37a8f8ba9 142 if (ret) {
Janani Sunil 0:6ca37a8f8ba9 143 return ret;
Janani Sunil 0:6ca37a8f8ba9 144 }
Janani Sunil 0:6ca37a8f8ba9 145
Janani Sunil 0:6ca37a8f8ba9 146 ret = no_os_gpio_get(&csb_gpio, &csb_init_param);
Janani Sunil 0:6ca37a8f8ba9 147 if (ret) {
Janani Sunil 0:6ca37a8f8ba9 148 return ret;
Janani Sunil 0:6ca37a8f8ba9 149 }
Janani Sunil 0:6ca37a8f8ba9 150
Janani Sunil 0:6ca37a8f8ba9 151 ret = no_os_gpio_direction_output(csb_gpio, NO_OS_GPIO_HIGH);
Janani Sunil 0:6ca37a8f8ba9 152 if (ret) {
Janani Sunil 0:6ca37a8f8ba9 153 return ret;
Janani Sunil 0:6ca37a8f8ba9 154 }
Janani Sunil 0:6ca37a8f8ba9 155 #endif
Janani Sunil 0:6ca37a8f8ba9 156
Janani Sunil 0:6ca37a8f8ba9 157 return 0;
Janani Sunil 0:6ca37a8f8ba9 158 }