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: platform_drivers
app_config.c
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 #include "app_config.h" 00020 #include "adc_data_capture.h" 00021 #include "error.h" 00022 #include "gpio.h" 00023 #include "irq.h" 00024 #include "pwm.h" 00025 #include "uart.h" 00026 00027 /******************************************************************************/ 00028 /************************ Macros/Constants ************************************/ 00029 /******************************************************************************/ 00030 00031 /******************************************************************************/ 00032 /*************************** Types Declarations *******************************/ 00033 /******************************************************************************/ 00034 00035 /* External interrupt init parameters */ 00036 static struct irq_init_param ext_int_init_params = { 00037 .irq_ctrl_id = EXTERNAL_INT_ID1, 00038 .extra = &ext_int_extra_init_params 00039 }; 00040 00041 /* External interrupt callback descriptor */ 00042 static struct callback_desc ext_int_callback_desc = { 00043 data_capture_callback, 00044 NULL, 00045 NULL 00046 }; 00047 00048 /* PWM init parameters */ 00049 static struct pwm_init_param pwm_init_params = { 00050 .id = EXT_TRIGGER_PIN, // GPIO used for PWM 00051 .period_ns = CONV_TRIGGER_PERIOD_NSEC, // PWM period in nsec 00052 .duty_cycle_ns = CONV_TRIGGER_DUTY_CYCLE_NSEC // PWM duty cycle in nsec 00053 }; 00054 00055 /* PWM descriptor */ 00056 struct pwm_desc *pwm_desc; 00057 00058 /* UART init parameters structure */ 00059 struct uart_init_param uart_init_params = { 00060 .device_id = NULL, 00061 .baud_rate = IIO_UART_BAUD_RATE, 00062 .extra = &uart_extra_init_params 00063 }; 00064 00065 /* External interrupt descriptor */ 00066 struct irq_ctrl_desc *ext_int_desc; 00067 00068 /******************************************************************************/ 00069 /************************ Functions Prototypes ********************************/ 00070 /******************************************************************************/ 00071 00072 /******************************************************************************/ 00073 /************************ Functions Definitions *******************************/ 00074 /******************************************************************************/ 00075 00076 /** 00077 * @brief Initialize the IRQ contoller 00078 * @return SUCCESS in case of success, negative error code otherwise. 00079 * @details This function initialize the interrupts for system peripherals 00080 */ 00081 static int32_t init_interrupt(void) 00082 { 00083 do { 00084 /* Init interrupt controller for external interrupt */ 00085 if (irq_ctrl_init(&ext_int_desc, &ext_int_init_params) != SUCCESS) { 00086 break; 00087 } 00088 /* Register a callback function for external interrupt */ 00089 if (irq_register_callback(ext_int_desc, 00090 EXTERNAL_INT_ID1, 00091 &ext_int_callback_desc) != SUCCESS) { 00092 break; 00093 } 00094 return SUCCESS; 00095 } while (0); 00096 00097 return FAILURE; 00098 } 00099 00100 /** 00101 * @brief Initializing system peripherals 00102 * @return SUCCESS in case of success, negative error code otherwise. 00103 * @details This function initializes system peripherals for the application 00104 */ 00105 int32_t init_system(void) 00106 { 00107 if (init_interrupt() != SUCCESS) 00108 return FAILURE; 00109 00110 /* Initialize the PWM interface to generate PWM signal 00111 * on conversion trigger event pin */ 00112 if (pwm_init(&pwm_desc, &pwm_init_params) != SUCCESS) { 00113 return FAILURE; 00114 } 00115 00116 return SUCCESS; 00117 }
Generated on Tue Jul 12 2022 15:35:46 by
