Greg Steiert / pegasus_dev

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Nov 11 20:59:50 2016 +0000
Revision:
0:5c4d7b2438d3
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1 /*******************************************************************************
switches 0:5c4d7b2438d3 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
switches 0:5c4d7b2438d3 3 *
switches 0:5c4d7b2438d3 4 * Permission is hereby granted, free of charge, to any person obtaining a
switches 0:5c4d7b2438d3 5 * copy of this software and associated documentation files (the "Software"),
switches 0:5c4d7b2438d3 6 * to deal in the Software without restriction, including without limitation
switches 0:5c4d7b2438d3 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
switches 0:5c4d7b2438d3 8 * and/or sell copies of the Software, and to permit persons to whom the
switches 0:5c4d7b2438d3 9 * Software is furnished to do so, subject to the following conditions:
switches 0:5c4d7b2438d3 10 *
switches 0:5c4d7b2438d3 11 * The above copyright notice and this permission notice shall be included
switches 0:5c4d7b2438d3 12 * in all copies or substantial portions of the Software.
switches 0:5c4d7b2438d3 13 *
switches 0:5c4d7b2438d3 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
switches 0:5c4d7b2438d3 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
switches 0:5c4d7b2438d3 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
switches 0:5c4d7b2438d3 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
switches 0:5c4d7b2438d3 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
switches 0:5c4d7b2438d3 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
switches 0:5c4d7b2438d3 20 * OTHER DEALINGS IN THE SOFTWARE.
switches 0:5c4d7b2438d3 21 *
switches 0:5c4d7b2438d3 22 * Except as contained in this notice, the name of Maxim Integrated
switches 0:5c4d7b2438d3 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
switches 0:5c4d7b2438d3 24 * Products, Inc. Branding Policy.
switches 0:5c4d7b2438d3 25 *
switches 0:5c4d7b2438d3 26 * The mere transfer of this software does not imply any licenses
switches 0:5c4d7b2438d3 27 * of trade secrets, proprietary technology, copyrights, patents,
switches 0:5c4d7b2438d3 28 * trademarks, maskwork rights, or any other form of intellectual
switches 0:5c4d7b2438d3 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
switches 0:5c4d7b2438d3 30 * ownership rights.
switches 0:5c4d7b2438d3 31 *
switches 0:5c4d7b2438d3 32 * $Date: 2016-03-21 14:44:55 -0500 (Mon, 21 Mar 2016) $
switches 0:5c4d7b2438d3 33 * $Revision: 22017 $
switches 0:5c4d7b2438d3 34 *
switches 0:5c4d7b2438d3 35 ******************************************************************************/
switches 0:5c4d7b2438d3 36
switches 0:5c4d7b2438d3 37 /**
switches 0:5c4d7b2438d3 38 * @file pt.h
switches 0:5c4d7b2438d3 39 * @addtogroup pt Pulse Train
switches 0:5c4d7b2438d3 40 * @brief This is the high level API for the pulse train module
switches 0:5c4d7b2438d3 41 * @{
switches 0:5c4d7b2438d3 42 *
switches 0:5c4d7b2438d3 43 */
switches 0:5c4d7b2438d3 44
switches 0:5c4d7b2438d3 45 #ifndef _PT_H
switches 0:5c4d7b2438d3 46 #define _PT_H
switches 0:5c4d7b2438d3 47
switches 0:5c4d7b2438d3 48 #include "mxc_config.h"
switches 0:5c4d7b2438d3 49 #include "pt_regs.h"
switches 0:5c4d7b2438d3 50 #include "mxc_assert.h"
switches 0:5c4d7b2438d3 51 #include "mxc_sys.h"
switches 0:5c4d7b2438d3 52
switches 0:5c4d7b2438d3 53 #ifdef __cplusplus
switches 0:5c4d7b2438d3 54 extern "C" {
switches 0:5c4d7b2438d3 55 #endif
switches 0:5c4d7b2438d3 56
switches 0:5c4d7b2438d3 57 /// @struct pt_pt_cfg_t
switches 0:5c4d7b2438d3 58 /// Pulse train mode configuration structure. @note Do not use for square wave
switches 0:5c4d7b2438d3 59 typedef struct {
switches 0:5c4d7b2438d3 60 uint32_t bps; ///< pulse train bit rate
switches 0:5c4d7b2438d3 61 uint32_t pattern; ///< Output pattern to shift out, starts at LSB
switches 0:5c4d7b2438d3 62 uint8_t ptLength; ///< Number of bits in pulse train, 0 = 32bits, 1 = non valid , 2 = 2 bits, ...
switches 0:5c4d7b2438d3 63 uint16_t loop; ///< Number of times to repeat the train, 0 = continuous
switches 0:5c4d7b2438d3 64 uint16_t loopDelay; ///< Delay between loops specified in bits Example: loopDelay = 4, delays time = time it takes to shift out 4 bits
switches 0:5c4d7b2438d3 65 } pt_pt_cfg_t;
switches 0:5c4d7b2438d3 66
switches 0:5c4d7b2438d3 67 /**
switches 0:5c4d7b2438d3 68 * @brief This function initializes pulse train modules to a known stopped state
switches 0:5c4d7b2438d3 69 * and sets the global PT clock scale
switches 0:5c4d7b2438d3 70 * @param clk_scale scale the system clock for the global PT clock
switches 0:5c4d7b2438d3 71 */
switches 0:5c4d7b2438d3 72 void PT_Init(sys_pt_clk_scale clk_scale);
switches 0:5c4d7b2438d3 73
switches 0:5c4d7b2438d3 74 /**
switches 0:5c4d7b2438d3 75 * @brief Configures the pulse train in the specified mode.
switches 0:5c4d7b2438d3 76 * @details The parameters in config structure must be set before calling this function.
switches 0:5c4d7b2438d3 77 * This function should be used for configuring pulse train mode only.
switches 0:5c4d7b2438d3 78 * @note The pulse train cannot be running when this function is called
switches 0:5c4d7b2438d3 79 *
switches 0:5c4d7b2438d3 80 * @param pt pulse train to operate on
switches 0:5c4d7b2438d3 81 * @param cfg pointer to pulse train configuration
switches 0:5c4d7b2438d3 82 * @param sysCfg pointer to pulse train system GPIO configuration
switches 0:5c4d7b2438d3 83 *
switches 0:5c4d7b2438d3 84 * @returns E_NO_ERROR if everything is successful, error if unsuccessful.
switches 0:5c4d7b2438d3 85 */
switches 0:5c4d7b2438d3 86 int PT_PTConfig(mxc_pt_regs_t *pt, pt_pt_cfg_t *cfg, const sys_cfg_pt_t *sysCfg);
switches 0:5c4d7b2438d3 87
switches 0:5c4d7b2438d3 88 /**
switches 0:5c4d7b2438d3 89 * @brief Configures the pulse train in the square wave mode.
switches 0:5c4d7b2438d3 90 * @details This function should be used for configuring square wave mode only.
switches 0:5c4d7b2438d3 91 * @note The pulse train cannot be running when this function is called
switches 0:5c4d7b2438d3 92 *
switches 0:5c4d7b2438d3 93 * @param pt pulse train to operate on
switches 0:5c4d7b2438d3 94 * @param freq square wave output frequency in Hz
switches 0:5c4d7b2438d3 95 * @param sysCfg pointer to pulse train system GPIO configuration
switches 0:5c4d7b2438d3 96 *
switches 0:5c4d7b2438d3 97 * @returns E_NO_ERROR if everything is successful, error if unsuccessful.
switches 0:5c4d7b2438d3 98 */
switches 0:5c4d7b2438d3 99 int PT_SqrWaveConfig(mxc_pt_regs_t *pt, uint32_t freq, const sys_cfg_pt_t *sysCfg);
switches 0:5c4d7b2438d3 100
switches 0:5c4d7b2438d3 101 /**
switches 0:5c4d7b2438d3 102 * @brief Starts the pulse train specified
switches 0:5c4d7b2438d3 103 *
switches 0:5c4d7b2438d3 104 * @param pt pulse train to operate on
switches 0:5c4d7b2438d3 105 */
switches 0:5c4d7b2438d3 106 __STATIC_INLINE void PT_Start(mxc_pt_regs_t *pt)
switches 0:5c4d7b2438d3 107 {
switches 0:5c4d7b2438d3 108 int ptIndex = MXC_PT_GET_IDX(pt);
switches 0:5c4d7b2438d3 109
switches 0:5c4d7b2438d3 110 MXC_PTG->enable |= (1 << ptIndex);
switches 0:5c4d7b2438d3 111
switches 0:5c4d7b2438d3 112 //wait for PT to start
switches 0:5c4d7b2438d3 113 while( (MXC_PTG->enable & (1 << ptIndex)) == 0 );
switches 0:5c4d7b2438d3 114 }
switches 0:5c4d7b2438d3 115
switches 0:5c4d7b2438d3 116 /**
switches 0:5c4d7b2438d3 117 * @brief Start multiple pulse train modules together.
switches 0:5c4d7b2438d3 118 *
switches 0:5c4d7b2438d3 119 * @param pts set the bits of pulse trains to start
switches 0:5c4d7b2438d3 120 * Bit0-\>pt0, Bit1-\>pt1... etc.
switches 0:5c4d7b2438d3 121 */
switches 0:5c4d7b2438d3 122 __STATIC_INLINE void PT_StartMulti(uint32_t pts)
switches 0:5c4d7b2438d3 123 {
switches 0:5c4d7b2438d3 124 MXC_PTG->enable |= pts;
switches 0:5c4d7b2438d3 125
switches 0:5c4d7b2438d3 126 //wait for PTs to start
switches 0:5c4d7b2438d3 127 while( (MXC_PTG->enable & pts) != pts );
switches 0:5c4d7b2438d3 128 }
switches 0:5c4d7b2438d3 129
switches 0:5c4d7b2438d3 130 /**
switches 0:5c4d7b2438d3 131 * @brief Stops a pulse train
switches 0:5c4d7b2438d3 132 *
switches 0:5c4d7b2438d3 133 * @param pt pulse train to operate on
switches 0:5c4d7b2438d3 134 */
switches 0:5c4d7b2438d3 135 __STATIC_INLINE void PT_Stop(mxc_pt_regs_t *pt)
switches 0:5c4d7b2438d3 136 {
switches 0:5c4d7b2438d3 137 int ptIndex = MXC_PT_GET_IDX(pt);
switches 0:5c4d7b2438d3 138
switches 0:5c4d7b2438d3 139 MXC_PTG->enable &= ~(1 << ptIndex);
switches 0:5c4d7b2438d3 140 }
switches 0:5c4d7b2438d3 141
switches 0:5c4d7b2438d3 142 /**
switches 0:5c4d7b2438d3 143 * @brief Stop multiple pulse trains together
switches 0:5c4d7b2438d3 144 *
switches 0:5c4d7b2438d3 145 * @param pts set the bits of pulse trains to stop
switches 0:5c4d7b2438d3 146 * Bit0-\>pt0, Bit1-\>pt1... etc.
switches 0:5c4d7b2438d3 147 */
switches 0:5c4d7b2438d3 148 __STATIC_INLINE void PT_StopMulti(uint32_t pts)
switches 0:5c4d7b2438d3 149 {
switches 0:5c4d7b2438d3 150 MXC_PTG->enable &= ~(pts);
switches 0:5c4d7b2438d3 151 }
switches 0:5c4d7b2438d3 152
switches 0:5c4d7b2438d3 153 /**
switches 0:5c4d7b2438d3 154 * @brief Determines if the pulse train is running
switches 0:5c4d7b2438d3 155 *
switches 0:5c4d7b2438d3 156 * @param pt pulse train to operate on
switches 0:5c4d7b2438d3 157 *
switches 0:5c4d7b2438d3 158 * @return 0 = pulse train is off, non-zero = pulse train is on
switches 0:5c4d7b2438d3 159 */
switches 0:5c4d7b2438d3 160 __STATIC_INLINE uint32_t PT_IsActive(mxc_pt_regs_t *pt)
switches 0:5c4d7b2438d3 161 {
switches 0:5c4d7b2438d3 162 int ptIndex = MXC_PT_GET_IDX(pt);
switches 0:5c4d7b2438d3 163
switches 0:5c4d7b2438d3 164 return (!!(MXC_PTG->enable & (1 << ptIndex)));
switches 0:5c4d7b2438d3 165 }
switches 0:5c4d7b2438d3 166
switches 0:5c4d7b2438d3 167 /**
switches 0:5c4d7b2438d3 168 * @brief Determines if the pulse trains selected are running
switches 0:5c4d7b2438d3 169 *
switches 0:5c4d7b2438d3 170 * @param pts set the bits of pulse trains to check
switches 0:5c4d7b2438d3 171 * Bit0-\>pt0, Bit1-\>pt1... etc.
switches 0:5c4d7b2438d3 172 *
switches 0:5c4d7b2438d3 173 * @return 0 = all pulse trains are off, non-zero = at least one pulse train is on
switches 0:5c4d7b2438d3 174 */
switches 0:5c4d7b2438d3 175 __STATIC_INLINE uint32_t PT_IsActiveMulti(uint32_t pts)
switches 0:5c4d7b2438d3 176 {
switches 0:5c4d7b2438d3 177 return (MXC_PTG->enable & pts);
switches 0:5c4d7b2438d3 178 }
switches 0:5c4d7b2438d3 179
switches 0:5c4d7b2438d3 180 /**
switches 0:5c4d7b2438d3 181 * @brief Sets the pattern of the pulse train
switches 0:5c4d7b2438d3 182 *
switches 0:5c4d7b2438d3 183 * @param pt Pointer to pulse train to operate on
switches 0:5c4d7b2438d3 184 * @param pattern output pattern
switches 0:5c4d7b2438d3 185 *
switches 0:5c4d7b2438d3 186 */
switches 0:5c4d7b2438d3 187 __STATIC_INLINE void PT_SetPattern(mxc_pt_regs_t *pt, uint32_t pattern)
switches 0:5c4d7b2438d3 188 {
switches 0:5c4d7b2438d3 189 pt->train = pattern;
switches 0:5c4d7b2438d3 190 }
switches 0:5c4d7b2438d3 191
switches 0:5c4d7b2438d3 192 /**
switches 0:5c4d7b2438d3 193 * @brief Enable pulse train interrupt
switches 0:5c4d7b2438d3 194 *
switches 0:5c4d7b2438d3 195 * @param pts Pointer to pulse train to operate on
switches 0:5c4d7b2438d3 196 */
switches 0:5c4d7b2438d3 197 __STATIC_INLINE void PT_EnableINT(mxc_pt_regs_t *pt)
switches 0:5c4d7b2438d3 198 {
switches 0:5c4d7b2438d3 199 int ptIndex = MXC_PT_GET_IDX(pt);
switches 0:5c4d7b2438d3 200
switches 0:5c4d7b2438d3 201 MXC_PTG->inten |= (1 << ptIndex);
switches 0:5c4d7b2438d3 202 }
switches 0:5c4d7b2438d3 203
switches 0:5c4d7b2438d3 204 /**
switches 0:5c4d7b2438d3 205 * @brief Enable interrupts for the pulse trains selected
switches 0:5c4d7b2438d3 206 *
switches 0:5c4d7b2438d3 207 * @param pts set the bits of pulse trains to enable
switches 0:5c4d7b2438d3 208 * Bit0-\>pt0, Bit1-\>pt1... etc.
switches 0:5c4d7b2438d3 209 */
switches 0:5c4d7b2438d3 210 __STATIC_INLINE void PT_EnableINTMulti(uint32_t pts)
switches 0:5c4d7b2438d3 211 {
switches 0:5c4d7b2438d3 212 MXC_PTG->inten |= pts;
switches 0:5c4d7b2438d3 213 }
switches 0:5c4d7b2438d3 214
switches 0:5c4d7b2438d3 215 /**
switches 0:5c4d7b2438d3 216 * @brief Disable pulse train interrupt
switches 0:5c4d7b2438d3 217 *
switches 0:5c4d7b2438d3 218 * @param pts pulse train to operate on
switches 0:5c4d7b2438d3 219 */
switches 0:5c4d7b2438d3 220 __STATIC_INLINE void PT_DisableINT(mxc_pt_regs_t *pt)
switches 0:5c4d7b2438d3 221 {
switches 0:5c4d7b2438d3 222 int ptIndex = MXC_PT_GET_IDX(pt);
switches 0:5c4d7b2438d3 223
switches 0:5c4d7b2438d3 224 MXC_PTG->inten &= ~(1 << ptIndex);
switches 0:5c4d7b2438d3 225 }
switches 0:5c4d7b2438d3 226
switches 0:5c4d7b2438d3 227 /**
switches 0:5c4d7b2438d3 228 * @brief Disable interrupts for the pulse trains selected
switches 0:5c4d7b2438d3 229 *
switches 0:5c4d7b2438d3 230 * @param pts set the bits of pulse trains to enable
switches 0:5c4d7b2438d3 231 * Bit0-\>pt0, Bit1-\>pt1... etc.
switches 0:5c4d7b2438d3 232 */
switches 0:5c4d7b2438d3 233 __STATIC_INLINE void PT_DisableINTMulti(uint32_t pts)
switches 0:5c4d7b2438d3 234 {
switches 0:5c4d7b2438d3 235 MXC_PTG->inten &= ~pts;
switches 0:5c4d7b2438d3 236 }
switches 0:5c4d7b2438d3 237 /**
switches 0:5c4d7b2438d3 238 * @brief Gets the pulse trains's interrupt flags
switches 0:5c4d7b2438d3 239 *
switches 0:5c4d7b2438d3 240 * @return The Pulse Train Flags, bits that are 1 are set.
switches 0:5c4d7b2438d3 241 */
switches 0:5c4d7b2438d3 242 __STATIC_INLINE uint32_t PT_GetFlags(void)
switches 0:5c4d7b2438d3 243 {
switches 0:5c4d7b2438d3 244 return MXC_PTG->intfl;
switches 0:5c4d7b2438d3 245 }
switches 0:5c4d7b2438d3 246
switches 0:5c4d7b2438d3 247 /**
switches 0:5c4d7b2438d3 248 * @brief Clears the pulse train's interrupt flag
switches 0:5c4d7b2438d3 249 *
switches 0:5c4d7b2438d3 250 * @param mask bits to clear
switches 0:5c4d7b2438d3 251 *
switches 0:5c4d7b2438d3 252 */
switches 0:5c4d7b2438d3 253 __STATIC_INLINE void PT_ClearFlags(uint32_t mask)
switches 0:5c4d7b2438d3 254 {
switches 0:5c4d7b2438d3 255 MXC_PTG->intfl = mask;
switches 0:5c4d7b2438d3 256 }
switches 0:5c4d7b2438d3 257
switches 0:5c4d7b2438d3 258 /**
switches 0:5c4d7b2438d3 259 * @brief Setup and enables a pulse train to restart after another pulse train has exited its loop.
switches 0:5c4d7b2438d3 260 * Each pulse train can have up to two restart triggers.
switches 0:5c4d7b2438d3 261 *
switches 0:5c4d7b2438d3 262 * @param ptToRestart pulse train to restart after \a ptStop ends
switches 0:5c4d7b2438d3 263 * @param ptStop pulse train that stops and triggers \a ptToRestart to begin
switches 0:5c4d7b2438d3 264 * @param restartIndex selects which restart trigger to set (0 or 1)
switches 0:5c4d7b2438d3 265 */
switches 0:5c4d7b2438d3 266 __STATIC_INLINE void PT_SetRestart(mxc_pt_regs_t *ptToRestart, mxc_pt_regs_t *ptStop, uint8_t restartIndex)
switches 0:5c4d7b2438d3 267 {
switches 0:5c4d7b2438d3 268 int ptStopIndex = MXC_PT_GET_IDX(ptStop);
switches 0:5c4d7b2438d3 269
switches 0:5c4d7b2438d3 270 MXC_ASSERT(ptStopIndex >= 0);
switches 0:5c4d7b2438d3 271
switches 0:5c4d7b2438d3 272 if(restartIndex) {
switches 0:5c4d7b2438d3 273 ptToRestart->restart |= (ptStopIndex << MXC_F_PT_RESTART_PT_Y_SELECT_POS) |
switches 0:5c4d7b2438d3 274 MXC_F_PT_RESTART_ON_PT_Y_LOOP_EXIT;
switches 0:5c4d7b2438d3 275 } else {
switches 0:5c4d7b2438d3 276 ptToRestart->restart |= (ptStopIndex << MXC_F_PT_RESTART_PT_X_SELECT_POS) |
switches 0:5c4d7b2438d3 277 MXC_F_PT_RESTART_ON_PT_X_LOOP_EXIT;
switches 0:5c4d7b2438d3 278 }
switches 0:5c4d7b2438d3 279 }
switches 0:5c4d7b2438d3 280
switches 0:5c4d7b2438d3 281 /**
switches 0:5c4d7b2438d3 282 * @brief Disable the restart for the specified pulse train
switches 0:5c4d7b2438d3 283 *
switches 0:5c4d7b2438d3 284 * @param ptToRestart pulse train to disable the restart
switches 0:5c4d7b2438d3 285 * @param restartIndex selects which restart trigger to disable (0 or 1)
switches 0:5c4d7b2438d3 286 */
switches 0:5c4d7b2438d3 287 __STATIC_INLINE void PT_RestartDisable(mxc_pt_regs_t *ptToRestart, uint8_t restartIndex)
switches 0:5c4d7b2438d3 288 {
switches 0:5c4d7b2438d3 289 if(restartIndex)
switches 0:5c4d7b2438d3 290 ptToRestart->restart &= ~MXC_F_PT_RESTART_ON_PT_Y_LOOP_EXIT;
switches 0:5c4d7b2438d3 291 else
switches 0:5c4d7b2438d3 292 ptToRestart->restart &= ~MXC_F_PT_RESTART_ON_PT_X_LOOP_EXIT;
switches 0:5c4d7b2438d3 293 }
switches 0:5c4d7b2438d3 294
switches 0:5c4d7b2438d3 295 /**
switches 0:5c4d7b2438d3 296 * @brief Resynchronize individual pulse trains together.
switches 0:5c4d7b2438d3 297 * Resync will stop those resync_pts; others will be still running
switches 0:5c4d7b2438d3 298 *
switches 0:5c4d7b2438d3 299 * @param resyncPts pulse train modules that need to be re-synced by bit number.
switches 0:5c4d7b2438d3 300 * Bit0-\>pt0, Bit1-\>pt1... etc.
switches 0:5c4d7b2438d3 301 */
switches 0:5c4d7b2438d3 302 __STATIC_INLINE void PT_Resync(uint32_t resyncPts)
switches 0:5c4d7b2438d3 303 {
switches 0:5c4d7b2438d3 304 MXC_PTG->resync = resyncPts;
switches 0:5c4d7b2438d3 305 while(MXC_PTG->resync);
switches 0:5c4d7b2438d3 306 }
switches 0:5c4d7b2438d3 307
switches 0:5c4d7b2438d3 308 /**@}*/
switches 0:5c4d7b2438d3 309 #ifdef __cplusplus
switches 0:5c4d7b2438d3 310 }
switches 0:5c4d7b2438d3 311 #endif
switches 0:5c4d7b2438d3 312
switches 0:5c4d7b2438d3 313 #endif /* _PT_H_ */