Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: sdp_k1_sdram
app/app_config.c@2:007533849deb, 2022-07-21 (annotated)
- Committer:
- Mahesh Phalke
- Date:
- Thu Jul 21 16:45:24 2022 +0530
- Revision:
- 2:007533849deb
Initial firmware commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mahesh Phalke |
2:007533849deb | 1 | /***************************************************************************//** |
Mahesh Phalke |
2:007533849deb | 2 | * @file app_config.c |
Mahesh Phalke |
2:007533849deb | 3 | * @brief Application configurations module (platform-agnostic) |
Mahesh Phalke |
2:007533849deb | 4 | * @details This module performs the system configurations |
Mahesh Phalke |
2:007533849deb | 5 | ******************************************************************************** |
Mahesh Phalke |
2:007533849deb | 6 | * Copyright (c) 2021-22 Analog Devices, Inc. |
Mahesh Phalke |
2:007533849deb | 7 | * All rights reserved. |
Mahesh Phalke |
2:007533849deb | 8 | * |
Mahesh Phalke |
2:007533849deb | 9 | * This software is proprietary to Analog Devices, Inc. and its licensors. |
Mahesh Phalke |
2:007533849deb | 10 | * By using this software you agree to the terms of the associated |
Mahesh Phalke |
2:007533849deb | 11 | * Analog Devices Software License Agreement. |
Mahesh Phalke |
2:007533849deb | 12 | *******************************************************************************/ |
Mahesh Phalke |
2:007533849deb | 13 | |
Mahesh Phalke |
2:007533849deb | 14 | /******************************************************************************/ |
Mahesh Phalke |
2:007533849deb | 15 | /***************************** Include Files **********************************/ |
Mahesh Phalke |
2:007533849deb | 16 | /******************************************************************************/ |
Mahesh Phalke |
2:007533849deb | 17 | |
Mahesh Phalke |
2:007533849deb | 18 | #include <stdbool.h> |
Mahesh Phalke |
2:007533849deb | 19 | |
Mahesh Phalke |
2:007533849deb | 20 | #include "app_config.h" |
Mahesh Phalke |
2:007533849deb | 21 | #include "ad7689_data_capture.h" |
Mahesh Phalke |
2:007533849deb | 22 | #include "no_os_error.h" |
Mahesh Phalke |
2:007533849deb | 23 | #include "no_os_uart.h" |
Mahesh Phalke |
2:007533849deb | 24 | #include "no_os_gpio.h" |
Mahesh Phalke |
2:007533849deb | 25 | #include "no_os_irq.h" |
Mahesh Phalke |
2:007533849deb | 26 | #include "no_os_pwm.h" |
Mahesh Phalke |
2:007533849deb | 27 | |
Mahesh Phalke |
2:007533849deb | 28 | /******************************************************************************/ |
Mahesh Phalke |
2:007533849deb | 29 | /************************ Macros/Constants ************************************/ |
Mahesh Phalke |
2:007533849deb | 30 | /******************************************************************************/ |
Mahesh Phalke |
2:007533849deb | 31 | |
Mahesh Phalke |
2:007533849deb | 32 | /******************************************************************************/ |
Mahesh Phalke |
2:007533849deb | 33 | /******************** Variables and User Defined Data Types *******************/ |
Mahesh Phalke |
2:007533849deb | 34 | /******************************************************************************/ |
Mahesh Phalke |
2:007533849deb | 35 | |
Mahesh Phalke |
2:007533849deb | 36 | /* UART init parameters */ |
Mahesh Phalke |
2:007533849deb | 37 | static struct no_os_uart_init_param uart_init_params = { |
Mahesh Phalke |
2:007533849deb | 38 | .device_id = NULL, |
Mahesh Phalke |
2:007533849deb | 39 | .baud_rate = IIO_UART_BAUD_RATE, |
Mahesh Phalke |
2:007533849deb | 40 | .size = NO_OS_UART_CS_8, |
Mahesh Phalke |
2:007533849deb | 41 | .parity = NO_OS_UART_PAR_NO, |
Mahesh Phalke |
2:007533849deb | 42 | .stop = NO_OS_UART_STOP_1_BIT, |
Mahesh Phalke |
2:007533849deb | 43 | .extra = &uart_extra_init_params |
Mahesh Phalke |
2:007533849deb | 44 | }; |
Mahesh Phalke |
2:007533849deb | 45 | |
Mahesh Phalke |
2:007533849deb | 46 | /* LED GPO init parameters */ |
Mahesh Phalke |
2:007533849deb | 47 | static struct no_os_gpio_init_param led_gpio_init_params = { |
Mahesh Phalke |
2:007533849deb | 48 | .number = LED_GPO, |
Mahesh Phalke |
2:007533849deb | 49 | .platform_ops = &gpio_ops, |
Mahesh Phalke |
2:007533849deb | 50 | .extra = NULL |
Mahesh Phalke |
2:007533849deb | 51 | }; |
Mahesh Phalke |
2:007533849deb | 52 | |
Mahesh Phalke |
2:007533849deb | 53 | /* External interrupt init parameters */ |
Mahesh Phalke |
2:007533849deb | 54 | static struct no_os_irq_init_param ext_int_init_params = { |
Mahesh Phalke |
2:007533849deb | 55 | .irq_ctrl_id = 0, |
Mahesh Phalke |
2:007533849deb | 56 | .platform_ops = &irq_ops, |
Mahesh Phalke |
2:007533849deb | 57 | .extra = &ext_int_extra_init_params |
Mahesh Phalke |
2:007533849deb | 58 | }; |
Mahesh Phalke |
2:007533849deb | 59 | |
Mahesh Phalke |
2:007533849deb | 60 | /* External interrupt callback descriptor */ |
Mahesh Phalke |
2:007533849deb | 61 | static struct no_os_callback_desc ext_int_callback_desc = { |
Mahesh Phalke |
2:007533849deb | 62 | data_capture_callback, |
Mahesh Phalke |
2:007533849deb | 63 | NULL, |
Mahesh Phalke |
2:007533849deb | 64 | NULL |
Mahesh Phalke |
2:007533849deb | 65 | }; |
Mahesh Phalke |
2:007533849deb | 66 | |
Mahesh Phalke |
2:007533849deb | 67 | /* PWM init parameters */ |
Mahesh Phalke |
2:007533849deb | 68 | static struct no_os_pwm_init_param pwm_init_params = { |
Mahesh Phalke |
2:007533849deb | 69 | .id = 0, |
Mahesh Phalke |
2:007533849deb | 70 | .period_ns = CONV_TRIGGER_PERIOD_NSEC, // PWM period in nsec |
Mahesh Phalke |
2:007533849deb | 71 | .duty_cycle_ns = CONV_TRIGGER_DUTY_CYCLE_NSEC, // PWM duty cycle in nsec |
Mahesh Phalke |
2:007533849deb | 72 | .extra = &pwm_extra_init_params |
Mahesh Phalke |
2:007533849deb | 73 | }; |
Mahesh Phalke |
2:007533849deb | 74 | |
Mahesh Phalke |
2:007533849deb | 75 | /* LED GPO descriptor */ |
Mahesh Phalke |
2:007533849deb | 76 | struct no_os_gpio_desc *led_gpio_desc; |
Mahesh Phalke |
2:007533849deb | 77 | |
Mahesh Phalke |
2:007533849deb | 78 | /* UART descriptor */ |
Mahesh Phalke |
2:007533849deb | 79 | struct no_os_uart_desc *uart_desc; |
Mahesh Phalke |
2:007533849deb | 80 | |
Mahesh Phalke |
2:007533849deb | 81 | /* External interrupt descriptor */ |
Mahesh Phalke |
2:007533849deb | 82 | struct no_os_irq_ctrl_desc *ext_int_desc; |
Mahesh Phalke |
2:007533849deb | 83 | |
Mahesh Phalke |
2:007533849deb | 84 | /* PWM descriptor */ |
Mahesh Phalke |
2:007533849deb | 85 | struct no_os_pwm_desc *pwm_desc; |
Mahesh Phalke |
2:007533849deb | 86 | |
Mahesh Phalke |
2:007533849deb | 87 | /******************************************************************************/ |
Mahesh Phalke |
2:007533849deb | 88 | /************************** Functions Declarations ****************************/ |
Mahesh Phalke |
2:007533849deb | 89 | /******************************************************************************/ |
Mahesh Phalke |
2:007533849deb | 90 | |
Mahesh Phalke |
2:007533849deb | 91 | /******************************************************************************/ |
Mahesh Phalke |
2:007533849deb | 92 | /************************** Functions Definitions *****************************/ |
Mahesh Phalke |
2:007533849deb | 93 | /******************************************************************************/ |
Mahesh Phalke |
2:007533849deb | 94 | |
Mahesh Phalke |
2:007533849deb | 95 | /** |
Mahesh Phalke |
2:007533849deb | 96 | * @brief Initialize the GPIOs |
Mahesh Phalke |
2:007533849deb | 97 | * @return 0 in case of success, negative error code otherwise |
Mahesh Phalke |
2:007533849deb | 98 | */ |
Mahesh Phalke |
2:007533849deb | 99 | static int32_t init_gpio(void) |
Mahesh Phalke |
2:007533849deb | 100 | { |
Mahesh Phalke |
2:007533849deb | 101 | int32_t ret; |
Mahesh Phalke |
2:007533849deb | 102 | |
Mahesh Phalke |
2:007533849deb | 103 | /* Initialize the LED GPO */ |
Mahesh Phalke |
2:007533849deb | 104 | ret = no_os_gpio_get_optional(&led_gpio_desc, &led_gpio_init_params); |
Mahesh Phalke |
2:007533849deb | 105 | if (ret) { |
Mahesh Phalke |
2:007533849deb | 106 | return ret; |
Mahesh Phalke |
2:007533849deb | 107 | } |
Mahesh Phalke |
2:007533849deb | 108 | |
Mahesh Phalke |
2:007533849deb | 109 | ret = no_os_gpio_direction_output(led_gpio_desc, NO_OS_GPIO_HIGH); |
Mahesh Phalke |
2:007533849deb | 110 | if (ret) { |
Mahesh Phalke |
2:007533849deb | 111 | return ret; |
Mahesh Phalke |
2:007533849deb | 112 | } |
Mahesh Phalke |
2:007533849deb | 113 | |
Mahesh Phalke |
2:007533849deb | 114 | return 0; |
Mahesh Phalke |
2:007533849deb | 115 | } |
Mahesh Phalke |
2:007533849deb | 116 | |
Mahesh Phalke |
2:007533849deb | 117 | /** |
Mahesh Phalke |
2:007533849deb | 118 | * @brief Initialize the UART peripheral |
Mahesh Phalke |
2:007533849deb | 119 | * @return 0 in case of success, negative error code otherwise |
Mahesh Phalke |
2:007533849deb | 120 | */ |
Mahesh Phalke |
2:007533849deb | 121 | static int32_t init_uart(void) |
Mahesh Phalke |
2:007533849deb | 122 | { |
Mahesh Phalke |
2:007533849deb | 123 | return no_os_uart_init(&uart_desc, &uart_init_params); |
Mahesh Phalke |
2:007533849deb | 124 | } |
Mahesh Phalke |
2:007533849deb | 125 | |
Mahesh Phalke |
2:007533849deb | 126 | /** |
Mahesh Phalke |
2:007533849deb | 127 | * @brief Initialize the IRQ contoller |
Mahesh Phalke |
2:007533849deb | 128 | * @return 0 in case of success, negative error code otherwise |
Mahesh Phalke |
2:007533849deb | 129 | */ |
Mahesh Phalke |
2:007533849deb | 130 | static int32_t init_interrupt(void) |
Mahesh Phalke |
2:007533849deb | 131 | { |
Mahesh Phalke |
2:007533849deb | 132 | int32_t ret; |
Mahesh Phalke |
2:007533849deb | 133 | |
Mahesh Phalke |
2:007533849deb | 134 | /* Init interrupt controller for external interrupt */ |
Mahesh Phalke |
2:007533849deb | 135 | ret = no_os_irq_ctrl_init(&ext_int_desc, &ext_int_init_params); |
Mahesh Phalke |
2:007533849deb | 136 | if (ret) { |
Mahesh Phalke |
2:007533849deb | 137 | return ret; |
Mahesh Phalke |
2:007533849deb | 138 | } |
Mahesh Phalke |
2:007533849deb | 139 | |
Mahesh Phalke |
2:007533849deb | 140 | /* Register a callback function for external interrupt */ |
Mahesh Phalke |
2:007533849deb | 141 | ret = no_os_irq_register_callback(ext_int_desc, |
Mahesh Phalke |
2:007533849deb | 142 | EXT_INT_ID, |
Mahesh Phalke |
2:007533849deb | 143 | &ext_int_callback_desc); |
Mahesh Phalke |
2:007533849deb | 144 | if (ret) { |
Mahesh Phalke |
2:007533849deb | 145 | return ret; |
Mahesh Phalke |
2:007533849deb | 146 | } |
Mahesh Phalke |
2:007533849deb | 147 | |
Mahesh Phalke |
2:007533849deb | 148 | /* Enable external interrupt */ |
Mahesh Phalke |
2:007533849deb | 149 | ret = no_os_irq_enable(ext_int_desc, EXT_INT_ID); |
Mahesh Phalke |
2:007533849deb | 150 | if (ret) { |
Mahesh Phalke |
2:007533849deb | 151 | return ret; |
Mahesh Phalke |
2:007533849deb | 152 | } |
Mahesh Phalke |
2:007533849deb | 153 | |
Mahesh Phalke |
2:007533849deb | 154 | return 0; |
Mahesh Phalke |
2:007533849deb | 155 | } |
Mahesh Phalke |
2:007533849deb | 156 | |
Mahesh Phalke |
2:007533849deb | 157 | /** |
Mahesh Phalke |
2:007533849deb | 158 | * @brief Initialize the PWM contoller |
Mahesh Phalke |
2:007533849deb | 159 | * @return 0 in case of success, negative error code otherwise |
Mahesh Phalke |
2:007533849deb | 160 | */ |
Mahesh Phalke |
2:007533849deb | 161 | static int32_t init_pwm(void) |
Mahesh Phalke |
2:007533849deb | 162 | { |
Mahesh Phalke |
2:007533849deb | 163 | int32_t ret; |
Mahesh Phalke |
2:007533849deb | 164 | |
Mahesh Phalke |
2:007533849deb | 165 | /* Initialize the PWM interface to generate PWM signal |
Mahesh Phalke |
2:007533849deb | 166 | * on conversion trigger event pin */ |
Mahesh Phalke |
2:007533849deb | 167 | ret = no_os_pwm_init(&pwm_desc, &pwm_init_params); |
Mahesh Phalke |
2:007533849deb | 168 | if (ret) { |
Mahesh Phalke |
2:007533849deb | 169 | return ret; |
Mahesh Phalke |
2:007533849deb | 170 | } |
Mahesh Phalke |
2:007533849deb | 171 | |
Mahesh Phalke |
2:007533849deb | 172 | ret = no_os_pwm_enable(pwm_desc); |
Mahesh Phalke |
2:007533849deb | 173 | if (ret) { |
Mahesh Phalke |
2:007533849deb | 174 | return ret; |
Mahesh Phalke |
2:007533849deb | 175 | } |
Mahesh Phalke |
2:007533849deb | 176 | |
Mahesh Phalke |
2:007533849deb | 177 | return 0; |
Mahesh Phalke |
2:007533849deb | 178 | } |
Mahesh Phalke |
2:007533849deb | 179 | |
Mahesh Phalke |
2:007533849deb | 180 | /** |
Mahesh Phalke |
2:007533849deb | 181 | * @brief Initialize the system peripherals |
Mahesh Phalke |
2:007533849deb | 182 | * @return 0 in case of success, negative error code otherwise |
Mahesh Phalke |
2:007533849deb | 183 | */ |
Mahesh Phalke |
2:007533849deb | 184 | int32_t init_system(void) |
Mahesh Phalke |
2:007533849deb | 185 | { |
Mahesh Phalke |
2:007533849deb | 186 | int32_t ret; |
Mahesh Phalke |
2:007533849deb | 187 | |
Mahesh Phalke |
2:007533849deb | 188 | ret = init_gpio(); |
Mahesh Phalke |
2:007533849deb | 189 | if (ret) { |
Mahesh Phalke |
2:007533849deb | 190 | return ret; |
Mahesh Phalke |
2:007533849deb | 191 | } |
Mahesh Phalke |
2:007533849deb | 192 | |
Mahesh Phalke |
2:007533849deb | 193 | ret = init_uart(); |
Mahesh Phalke |
2:007533849deb | 194 | if (ret) { |
Mahesh Phalke |
2:007533849deb | 195 | return ret; |
Mahesh Phalke |
2:007533849deb | 196 | } |
Mahesh Phalke |
2:007533849deb | 197 | |
Mahesh Phalke |
2:007533849deb | 198 | #if (DATA_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE) |
Mahesh Phalke |
2:007533849deb | 199 | ret = init_interrupt(); |
Mahesh Phalke |
2:007533849deb | 200 | if (ret) { |
Mahesh Phalke |
2:007533849deb | 201 | return ret; |
Mahesh Phalke |
2:007533849deb | 202 | } |
Mahesh Phalke |
2:007533849deb | 203 | |
Mahesh Phalke |
2:007533849deb | 204 | ret = init_pwm(); |
Mahesh Phalke |
2:007533849deb | 205 | if (ret) { |
Mahesh Phalke |
2:007533849deb | 206 | return ret; |
Mahesh Phalke |
2:007533849deb | 207 | } |
Mahesh Phalke |
2:007533849deb | 208 | #endif |
Mahesh Phalke |
2:007533849deb | 209 | |
Mahesh Phalke |
2:007533849deb | 210 | #if defined(USE_SDRAM_CAPTURE_BUFFER) |
Mahesh Phalke |
2:007533849deb | 211 | ret = sdram_init(); |
Mahesh Phalke |
2:007533849deb | 212 | if (ret) { |
Mahesh Phalke |
2:007533849deb | 213 | return ret; |
Mahesh Phalke |
2:007533849deb | 214 | } |
Mahesh Phalke |
2:007533849deb | 215 | #endif |
Mahesh Phalke |
2:007533849deb | 216 | |
Mahesh Phalke |
2:007533849deb | 217 | return 0; |
Mahesh Phalke |
2:007533849deb | 218 | } |