1 /** 2 * @file pt.h 3 * @brief Pulse Train data types, definitions and function prototypes. 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 /* Define to prevent redundant inclusion */ 27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32570_PT_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32570_PT_H_ 29 30 /* **** Includes **** */ 31 32 #include <stdio.h> 33 #include "gcr_regs.h" 34 #include "pt_regs.h" 35 #include "ptg_regs.h" 36 #include "mxc_device.h" 37 #include "mxc_errors.h" 38 #include "mxc_assert.h" 39 #include "mxc_sys.h" 40 #include "mcr_regs.h" 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 /** 47 * @defgroup pt Pulse Train Engine 48 * @ingroup periphlibs 49 * @brief This is the high level API for the pulse train engine. 50 * @{ 51 */ 52 53 /** 54 * @brief Structure type for pulse train mode configuration. 55 * @note Do not use for square wave 56 */ 57 typedef struct { 58 unsigned channel; ///< PT Channel to use 59 uint32_t bps; ///< pulse train bit rate 60 uint32_t pattern; ///< Output pattern to shift out, starts at LSB 61 uint8_t ptLength; ///< Number of bits in pulse train, 0 = 32bits, 1 = non valid , 2 = 2 bits, ... 62 uint16_t loop; ///< Number of times to repeat the train, 0 = continuous 63 uint16_t 64 loopDelay; ///< Delay between loops specified in bits Example: loopDelay = 4, delays time = time it takes to shift out 4 bits 65 } mxc_pt_cfg_t; 66 67 /** 68 * @brief Enumeration type for the system clock scale types 69 */ 70 typedef enum { 71 MXC_PT_CLK_DIV1, 72 MXC_PT_CLK_DIV2, 73 MXC_PT_CLK_DIV4, 74 MXC_PT_CLK_DIV8, 75 MXC_PT_CLK_DIV16, 76 MXC_PT_CLK_DIV32, 77 MXC_PT_CLK_DIV64, 78 MXC_PT_CLK_DIV128, 79 } mxc_clk_scale_t; 80 81 /** 82 * @brief This function initializes the pulse trains to a known stopped 83 * state and sets the global PT clock scale. 84 * 85 * @param clk_scale Scale the system clock for the global PT clock. 86 */ 87 void MXC_PT_Init(mxc_clk_scale_t clk_scale); 88 89 /** 90 * @brief Shutdown the pulse train channel/channels. 91 * @details Shutdown pulse train and if all pluse trains are shut down then turn off pulse train clock. 92 * @note Shutdown pulse train channel/channels and delete config. 93 * 94 * @param pts Pulse train channel to operate on. 95 * 96 * @return #E_NO_ERROR if everything is successful, \ref MXC_Error_Codes 97 * "error" if unsuccessful. 98 */ 99 void MXC_PT_Shutdown(uint32_t pts); 100 101 /** 102 * @brief Configures the pulse train in the specified mode. 103 * @details The parameters in the config structure must be set before calling 104 * this function. This function should be used for configuring pulse 105 * train mode only. 106 * @note The pulse train cannot be running when this function is called. 107 * 108 * @param cfg Pointer to pulse train configuration. 109 * 110 * @return #E_NO_ERROR if everything is successful, \ref MXC_Error_Codes 111 * "error" if unsuccessful. 112 */ 113 int MXC_PT_Config(mxc_pt_cfg_t *cfg); 114 115 /** 116 * @brief Configures the pulse train in the square wave mode. 117 * @details This function should be used for configuring square wave mode only. 118 * @note The pulse train cannot be running when this function is called 119 * 120 * @param channel Pulse train channel to operate on 121 * @param freq square wave output frequency in Hz 122 * 123 * @returns #E_NO_ERROR if everything is successful, \ref MXC_Error_Codes "error" if unsuccessful. 124 */ 125 int MXC_PT_SqrWaveConfig(unsigned channel, uint32_t freq); 126 127 /** 128 * @brief Starts the pulse trains specified. 129 * 130 * @param pts Pulse train pts to operate on. 131 */ 132 void MXC_PT_Start(unsigned pts); 133 134 /** 135 * @brief Stops pulse trains. 136 * 137 * @param pts Pulse train pts to stop. 138 */ 139 void MXC_PT_Stop(unsigned pts); 140 141 /** 142 * @brief Determines if the pulse trains selected are running 143 * 144 * @param pts Set the bits of pulse trains to check Bit0-\>pt0, 145 * Bit1-\>pt1... etc. 146 * 147 * @return 0 All pulse trains are off. 148 * @return \>0 At least one pulse train is on. 149 */ 150 uint32_t MXC_PT_IsActive(uint32_t pts); 151 152 /** 153 * @brief Sets the pattern of the pulse train 154 * 155 * @param pts Pulse train pts to operate on. 156 * @param pattern Output pattern. 157 * 158 */ 159 void MXC_PT_SetPattern(unsigned pts, uint32_t pattern); 160 161 /** 162 * @brief Enable interrupts for the pulse trains selected. 163 * 164 * @param pts Bit mask of which pulse trains to enable. Set the bit 165 * position of each pulse train to enable it. Bit0-\>pt0, 166 * Bit1-\>pt1... etc, 1 will enable the interrupt, 0 to leave 167 * a PT channel in its current state. 168 */ 169 void MXC_PT_EnableInt(uint32_t pts); 170 171 /** 172 * @brief Disable interrupts for the pulse trains selected. 173 * 174 * @param pts Bit mask of what pulse trains to disable. Set the bit 175 * position of each pulse train to disable it. Bit0-\>pt0, 176 * Bit1-\>pt1... etc, 1 will disable the interrupt, 0 to leave 177 * a PT channel in its current state. 178 */ 179 void MXC_PT_DisableInt(uint32_t pts); 180 181 /** 182 * @brief Gets the pulse trains's interrupt flags. 183 * 184 * @return The Pulse Train Interrupt Flags, \ref PTG_INTFL Register 185 * for details. 186 */ 187 uint32_t MXC_PT_GetFlags(void); 188 189 /** 190 * @brief Clears the pulse train's interrupt flag. 191 * 192 * @param flags bits to clear, see \ref PTG_INTFL Register for details. 193 */ 194 void MXC_PT_ClearFlags(uint32_t flags); 195 196 /** 197 * @brief Setup and enables a pulse train to restart after another pulse 198 * train has exited its loop. Each pulse train can have up to two 199 * restart triggers. 200 * 201 * @param start Pulse train channel to start. 202 * @param stop Pulse train channel to stop. 203 * @param restartIndex selects which restart trigger to set (0 or 1). 204 */ 205 void MXC_PT_EnableRestart(unsigned start, unsigned stop, uint8_t restartIndex); 206 207 /** 208 * @brief Disable the restart for the specified pulse train 209 * 210 * @param channel Pulse train channel to restart 211 * @param restartIndex selects which restart trigger to disable (0 or 1) 212 */ 213 void MXC_PT_DisableRestart(unsigned channel, uint8_t restartIndex); 214 215 /** 216 * @brief Resynchronize individual pulse trains together. Resync will stop 217 * those resync_pts; others will be still running 218 * 219 * @param pts Pulse train modules that need to be re-synced by bit 220 * number. Bit0-\>pt0, Bit1-\>pt1... etc. 221 */ 222 void MXC_PT_Resync(uint32_t pts); 223 /**@} end of group pt*/ 224 225 #ifdef __cplusplus 226 } 227 #endif 228 229 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32570_PT_H_ 230