1 /** 2 * @file afe.h 3 * @brief Analog Front End (AFE) communications r 4 */ 5 6 /****************************************************************************** 7 * 8 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by 9 * Analog Devices, Inc.), 10 * Copyright (C) 2023-2024 Analog Devices, Inc. 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 * 24 ******************************************************************************/ 25 26 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_AFE_H_ 27 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_AFE_H_ 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 /***** Includes *******/ 34 #include "afe.h" 35 #include "afe_adc_zero_regs.h" 36 #include "afe_adc_one_regs.h" 37 #include "afe_dac_regs.h" 38 #include "afe_hart_regs.h" 39 #include "tmr.h" 40 #include "mxc_sys.h" 41 #include "mxc_assert.h" 42 #include "infoblock.h" 43 44 /***** Definitions *****/ 45 #define AFE_REG_ADDR_BANK_POS 23 46 #define AFE_REG_ADDR_BANK ((uint32_t)(0x03 << AFE_REG_ADDR_BANK_POS)) 47 #define AFE_REG_ADDR_POS 16 48 #define AFE_REG_ADDR ((uint32_t)(0x7F << AFE_REG_ADDR_POS)) 49 #define AFE_REG_ADDR_LEN_POS 0 50 #define AFE_REG_ADDR_LEN ((uint32_t)(0x07 << AFE_REG_ADDR_LEN_POS)) 51 #define AFE_REG_ADDR_READ_BIT 0x80 52 #define AFE_CRC_LEN 1 53 54 #define AFE_ADC0_BANK 0 55 #define AFE_ADC1_BANK 1 56 #define AFE_DAC_BANK 2 57 #define AFE_HART_BANK 3 58 59 /***** Function Prototypes *****/ 60 /** 61 * @brief Setup the AFE for transactions. 62 * @param tmr Pointer to Timer registers to use for internal AFE timing 63 */ 64 int afe_setup(mxc_tmr_regs_t *tmr); 65 66 /** 67 * @brief Puts the AFE into a RESET state to recover from errors, or reduce power consumption 68 * @note Must call afe_load_trims to restore AFE functionality after a reset. 69 */ 70 void afe_reset(void); 71 72 /** 73 * @brief Writes data to AFE register. 74 * 75 * @param target_reg The register to write the data into 76 * @param value The data to write 77 * 78 * @return See \ref MXC_Error_Codes for a list of return codes. 79 */ 80 int afe_write_register(uint32_t target_reg, uint32_t value); 81 82 /** 83 * @brief Writes data to AFE register in the specified bank. 84 * 85 * @param target_reg The register to write the data into 86 * @param reg_bank register bank 87 * @param value The data to write 88 * 89 * @return See \ref MXC_Error_Codes for a list of return codes. 90 */ 91 int afe_bank_write_register(uint32_t target_reg, uint8_t reg_bank, uint32_t value); 92 93 /** 94 * @brief Read data from AFE register. 95 * 96 * @param target_reg The register to read the data from 97 * @param value Buffer to store data in 98 * 99 * @return See \ref MXC_Error_Codes for a list of return codes. 100 */ 101 int afe_read_register(uint32_t target_reg, uint32_t *value); 102 103 /** 104 * @brief Read data from AFE register in the specified bank. 105 * 106 * @param target_reg The register to read the data from 107 * @param reg_bank register bank 108 * @param value Buffer to store data in 109 * 110 * @return See \ref MXC_Error_Codes for a list of return codes. 111 */ 112 int afe_bank_read_register(uint32_t target_reg, uint8_t reg_bank, uint32_t *value); 113 114 /** 115 * @brief Load AFE Trims. 116 * @note Uncomment DUMP_TRIM_DATA in afe.c to print trime data. 117 * @param tmr Pointer to Timer registers to use for internal AFE timing 118 * 119 * @return See \ref MXC_Error_Codes for a list of return codes. 120 */ 121 int afe_load_trims(mxc_tmr_regs_t *tmr); 122 123 /** 124 * @brief Dumps the AFE registers. 125 * 126 * @param reg_bank Register banks to dump. Check definitions in afe.h. 127 */ 128 void afe_dump_registers(uint32_t reg_bank); 129 130 /**@} end of group afe */ 131 132 #ifdef __cplusplus 133 } 134 #endif 135 136 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_AFE_H_ 137