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