test

Committer:
elijahsj
Date:
Mon Nov 09 00:02:47 2020 -0500
Revision:
1:8a094db1347f
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elijahsj 1:8a094db1347f 1 /**
elijahsj 1:8a094db1347f 2 * @file
elijahsj 1:8a094db1347f 3 * @brief Pulse Train Engine Function Implementations.
elijahsj 1:8a094db1347f 4 */
elijahsj 1:8a094db1347f 5 /* *****************************************************************************
elijahsj 1:8a094db1347f 6 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
elijahsj 1:8a094db1347f 7 *
elijahsj 1:8a094db1347f 8 * Permission is hereby granted, free of charge, to any person obtaining a
elijahsj 1:8a094db1347f 9 * copy of this software and associated documentation files (the "Software"),
elijahsj 1:8a094db1347f 10 * to deal in the Software without restriction, including without limitation
elijahsj 1:8a094db1347f 11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
elijahsj 1:8a094db1347f 12 * and/or sell copies of the Software, and to permit persons to whom the
elijahsj 1:8a094db1347f 13 * Software is furnished to do so, subject to the following conditions:
elijahsj 1:8a094db1347f 14 *
elijahsj 1:8a094db1347f 15 * The above copyright notice and this permission notice shall be included
elijahsj 1:8a094db1347f 16 * in all copies or substantial portions of the Software.
elijahsj 1:8a094db1347f 17 *
elijahsj 1:8a094db1347f 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
elijahsj 1:8a094db1347f 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
elijahsj 1:8a094db1347f 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
elijahsj 1:8a094db1347f 21 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
elijahsj 1:8a094db1347f 22 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
elijahsj 1:8a094db1347f 23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
elijahsj 1:8a094db1347f 24 * OTHER DEALINGS IN THE SOFTWARE.
elijahsj 1:8a094db1347f 25 *
elijahsj 1:8a094db1347f 26 * Except as contained in this notice, the name of Maxim Integrated
elijahsj 1:8a094db1347f 27 * Products, Inc. shall not be used except as stated in the Maxim Integrated
elijahsj 1:8a094db1347f 28 * Products, Inc. Branding Policy.
elijahsj 1:8a094db1347f 29 *
elijahsj 1:8a094db1347f 30 * The mere transfer of this software does not imply any licenses
elijahsj 1:8a094db1347f 31 * of trade secrets, proprietary technology, copyrights, patents,
elijahsj 1:8a094db1347f 32 * trademarks, maskwork rights, or any other form of intellectual
elijahsj 1:8a094db1347f 33 * property whatsoever. Maxim Integrated Products, Inc. retains all
elijahsj 1:8a094db1347f 34 * ownership rights.
elijahsj 1:8a094db1347f 35 *
elijahsj 1:8a094db1347f 36 * $Date: 2016-09-08 17:43:36 -0500 (Thu, 08 Sep 2016) $
elijahsj 1:8a094db1347f 37 * $Revision: 24327 $
elijahsj 1:8a094db1347f 38 *
elijahsj 1:8a094db1347f 39 **************************************************************************** */
elijahsj 1:8a094db1347f 40
elijahsj 1:8a094db1347f 41 /* **** Includes **** */
elijahsj 1:8a094db1347f 42 #include <stddef.h>
elijahsj 1:8a094db1347f 43 #include "pt.h"
elijahsj 1:8a094db1347f 44
elijahsj 1:8a094db1347f 45 /**
elijahsj 1:8a094db1347f 46 * @ingroup pulsetrain
elijahsj 1:8a094db1347f 47 * @{
elijahsj 1:8a094db1347f 48 */
elijahsj 1:8a094db1347f 49
elijahsj 1:8a094db1347f 50 /* ************************************************************************* */
elijahsj 1:8a094db1347f 51 void PT_Init(sys_pt_clk_scale clk_scale)
elijahsj 1:8a094db1347f 52 {
elijahsj 1:8a094db1347f 53 //disable all pulse trains
elijahsj 1:8a094db1347f 54 MXC_PTG->enable = 0;
elijahsj 1:8a094db1347f 55
elijahsj 1:8a094db1347f 56 //clear all interrupts
elijahsj 1:8a094db1347f 57 MXC_PTG->intfl = MXC_PTG->intfl;
elijahsj 1:8a094db1347f 58
elijahsj 1:8a094db1347f 59 SYS_PT_Init(clk_scale);
elijahsj 1:8a094db1347f 60 }
elijahsj 1:8a094db1347f 61
elijahsj 1:8a094db1347f 62 /* ************************************************************************* */
elijahsj 1:8a094db1347f 63 int PT_PTConfig(mxc_pt_regs_t *pt, pt_pt_cfg_t *cfg, const sys_cfg_pt_t *sysCfg)
elijahsj 1:8a094db1347f 64 {
elijahsj 1:8a094db1347f 65 int err;
elijahsj 1:8a094db1347f 66 uint32_t ptClock;
elijahsj 1:8a094db1347f 67 uint32_t rate;
elijahsj 1:8a094db1347f 68
elijahsj 1:8a094db1347f 69 //check for valid base pointer
elijahsj 1:8a094db1347f 70 MXC_ASSERT(MXC_PT_GET_IDX(pt) >= 0);
elijahsj 1:8a094db1347f 71
elijahsj 1:8a094db1347f 72 if(cfg == NULL)
elijahsj 1:8a094db1347f 73 return E_NULL_PTR;
elijahsj 1:8a094db1347f 74
elijahsj 1:8a094db1347f 75 if(cfg->bps == 0)
elijahsj 1:8a094db1347f 76 return E_BAD_PARAM;
elijahsj 1:8a094db1347f 77
elijahsj 1:8a094db1347f 78 //disable pulse train
elijahsj 1:8a094db1347f 79 PT_Stop(pt);
elijahsj 1:8a094db1347f 80
elijahsj 1:8a094db1347f 81 //setup system GPIO configuration
elijahsj 1:8a094db1347f 82 if((err = SYS_PT_Config(pt, sysCfg)) != E_NO_ERROR)
elijahsj 1:8a094db1347f 83 return err;
elijahsj 1:8a094db1347f 84
elijahsj 1:8a094db1347f 85 //get PT clock frequency from SYS level
elijahsj 1:8a094db1347f 86 ptClock = SYS_PT_GetFreq();
elijahsj 1:8a094db1347f 87
elijahsj 1:8a094db1347f 88 if(ptClock == 0)
elijahsj 1:8a094db1347f 89 return E_UNINITIALIZED;
elijahsj 1:8a094db1347f 90
elijahsj 1:8a094db1347f 91 if(ptClock < (cfg->bps))
elijahsj 1:8a094db1347f 92 return E_BAD_STATE;
elijahsj 1:8a094db1347f 93
elijahsj 1:8a094db1347f 94 rate = (ptClock / (cfg->bps));
elijahsj 1:8a094db1347f 95
elijahsj 1:8a094db1347f 96 pt->rate_length = ((rate << MXC_F_PT_RATE_LENGTH_RATE_CONTROL_POS)
elijahsj 1:8a094db1347f 97 & MXC_F_PT_RATE_LENGTH_RATE_CONTROL) |
elijahsj 1:8a094db1347f 98 ((cfg->ptLength << MXC_F_PT_RATE_LENGTH_MODE_POS)
elijahsj 1:8a094db1347f 99 & MXC_F_PT_RATE_LENGTH_MODE);
elijahsj 1:8a094db1347f 100
elijahsj 1:8a094db1347f 101 pt->train = cfg->pattern;
elijahsj 1:8a094db1347f 102 pt->loop = ((cfg->loop << MXC_F_PT_LOOP_COUNT_POS) & MXC_F_PT_LOOP_COUNT) |
elijahsj 1:8a094db1347f 103 ((cfg->loopDelay << MXC_F_PT_LOOP_DELAY_POS) & MXC_F_PT_LOOP_DELAY);
elijahsj 1:8a094db1347f 104
elijahsj 1:8a094db1347f 105 return E_NO_ERROR;
elijahsj 1:8a094db1347f 106 }
elijahsj 1:8a094db1347f 107
elijahsj 1:8a094db1347f 108 /* ************************************************************************* */
elijahsj 1:8a094db1347f 109 int PT_SqrWaveConfig(mxc_pt_regs_t *pt, uint32_t freq, const sys_cfg_pt_t *sysCfg)
elijahsj 1:8a094db1347f 110 {
elijahsj 1:8a094db1347f 111 int err;
elijahsj 1:8a094db1347f 112 uint32_t ptClock;
elijahsj 1:8a094db1347f 113 uint32_t rate;
elijahsj 1:8a094db1347f 114
elijahsj 1:8a094db1347f 115 //check for valid base pointer
elijahsj 1:8a094db1347f 116 MXC_ASSERT(MXC_PT_GET_IDX(pt) >= 0);
elijahsj 1:8a094db1347f 117
elijahsj 1:8a094db1347f 118 if(freq == 0)
elijahsj 1:8a094db1347f 119 return E_BAD_PARAM;
elijahsj 1:8a094db1347f 120
elijahsj 1:8a094db1347f 121 //disable pulse train
elijahsj 1:8a094db1347f 122 PT_Stop(pt);
elijahsj 1:8a094db1347f 123
elijahsj 1:8a094db1347f 124 //setup system GPIO configuration
elijahsj 1:8a094db1347f 125 if((err = SYS_PT_Config(pt, sysCfg)) != E_NO_ERROR)
elijahsj 1:8a094db1347f 126 return err;
elijahsj 1:8a094db1347f 127
elijahsj 1:8a094db1347f 128 //get PT clock frequency from SYS level
elijahsj 1:8a094db1347f 129 ptClock = SYS_PT_GetFreq();
elijahsj 1:8a094db1347f 130
elijahsj 1:8a094db1347f 131 if(ptClock == 0)
elijahsj 1:8a094db1347f 132 return E_UNINITIALIZED;
elijahsj 1:8a094db1347f 133
elijahsj 1:8a094db1347f 134 if(ptClock < (2*freq))
elijahsj 1:8a094db1347f 135 return E_BAD_STATE;
elijahsj 1:8a094db1347f 136
elijahsj 1:8a094db1347f 137 rate = (ptClock / (2*freq)) + 1;
elijahsj 1:8a094db1347f 138
elijahsj 1:8a094db1347f 139 pt->rate_length = ((rate << MXC_F_PT_RATE_LENGTH_RATE_CONTROL_POS)
elijahsj 1:8a094db1347f 140 & MXC_F_PT_RATE_LENGTH_RATE_CONTROL) |
elijahsj 1:8a094db1347f 141 (MXC_V_PT_RATE_LENGTH_MODE_SQUARE_WAVE << MXC_F_PT_RATE_LENGTH_MODE_POS);
elijahsj 1:8a094db1347f 142
elijahsj 1:8a094db1347f 143 return E_NO_ERROR;
elijahsj 1:8a094db1347f 144 }
elijahsj 1:8a094db1347f 145 /**@} end of ingroup pulsetrain*/