mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Apr 03 11:45:06 2014 +0100
Revision:
149:1fb5f62b92bd
Parent:
targets/hal/TARGET_Freescale/TARGET_KSDK_MCUS/TARGET_KSDK_CODE/hal/flextimer/fsl_ftm_hal.c@146:f64d43ff0c18
Child:
324:406fd2029f23
Synchronized with git revision 220c0bb39ceee40016e1e86350c058963d01ed42

Full URL: https://github.com/mbedmicro/mbed/commit/220c0bb39ceee40016e1e86350c058963d01ed42/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 146:f64d43ff0c18 1 /*
mbed_official 146:f64d43ff0c18 2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
mbed_official 146:f64d43ff0c18 3 * All rights reserved.
mbed_official 146:f64d43ff0c18 4 *
mbed_official 146:f64d43ff0c18 5 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 146:f64d43ff0c18 6 * are permitted provided that the following conditions are met:
mbed_official 146:f64d43ff0c18 7 *
mbed_official 146:f64d43ff0c18 8 * o Redistributions of source code must retain the above copyright notice, this list
mbed_official 146:f64d43ff0c18 9 * of conditions and the following disclaimer.
mbed_official 146:f64d43ff0c18 10 *
mbed_official 146:f64d43ff0c18 11 * o Redistributions in binary form must reproduce the above copyright notice, this
mbed_official 146:f64d43ff0c18 12 * list of conditions and the following disclaimer in the documentation and/or
mbed_official 146:f64d43ff0c18 13 * other materials provided with the distribution.
mbed_official 146:f64d43ff0c18 14 *
mbed_official 146:f64d43ff0c18 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
mbed_official 146:f64d43ff0c18 16 * contributors may be used to endorse or promote products derived from this
mbed_official 146:f64d43ff0c18 17 * software without specific prior written permission.
mbed_official 146:f64d43ff0c18 18 *
mbed_official 146:f64d43ff0c18 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
mbed_official 146:f64d43ff0c18 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
mbed_official 146:f64d43ff0c18 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 146:f64d43ff0c18 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
mbed_official 146:f64d43ff0c18 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
mbed_official 146:f64d43ff0c18 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 146:f64d43ff0c18 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
mbed_official 146:f64d43ff0c18 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
mbed_official 146:f64d43ff0c18 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
mbed_official 146:f64d43ff0c18 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 146:f64d43ff0c18 29 */
mbed_official 146:f64d43ff0c18 30 #include "fsl_ftm_hal.h"
mbed_official 146:f64d43ff0c18 31
mbed_official 146:f64d43ff0c18 32 /*******************************************************************************
mbed_official 146:f64d43ff0c18 33 * Definitions
mbed_official 146:f64d43ff0c18 34 ******************************************************************************/
mbed_official 146:f64d43ff0c18 35 /*see fsl_ftm_hal.h for documentation of this function*/
mbed_official 146:f64d43ff0c18 36 void ftm_hal_init(uint8_t instance, ftm_config_t *config)
mbed_official 146:f64d43ff0c18 37 {
mbed_official 146:f64d43ff0c18 38 switch(config->mode)
mbed_official 146:f64d43ff0c18 39 {
mbed_official 146:f64d43ff0c18 40 case kFtmInputCapture:
mbed_official 146:f64d43ff0c18 41 break;
mbed_official 146:f64d43ff0c18 42 case kFtmOutputCompare:
mbed_official 146:f64d43ff0c18 43 break;
mbed_official 146:f64d43ff0c18 44 case kFtmEdgeAlignedPWM:
mbed_official 146:f64d43ff0c18 45 case kFtmCenterAlignedPWM:
mbed_official 146:f64d43ff0c18 46 case kFtmCombinedPWM:
mbed_official 146:f64d43ff0c18 47 ftm_hal_enable_pwm_mode(instance, config);
mbed_official 146:f64d43ff0c18 48 break;
mbed_official 146:f64d43ff0c18 49 case kFtmDualEdgeCapture:
mbed_official 146:f64d43ff0c18 50 break;
mbed_official 146:f64d43ff0c18 51 case kFtmQuadCapture:
mbed_official 146:f64d43ff0c18 52 break;
mbed_official 146:f64d43ff0c18 53 default:
mbed_official 146:f64d43ff0c18 54 assert(0);
mbed_official 146:f64d43ff0c18 55 break;
mbed_official 146:f64d43ff0c18 56 }
mbed_official 146:f64d43ff0c18 57 }
mbed_official 146:f64d43ff0c18 58
mbed_official 146:f64d43ff0c18 59 /*see fsl_ftm_hal.h for documentation of this function*/
mbed_official 146:f64d43ff0c18 60 void ftm_hal_enable_pwm_mode(uint8_t instance, ftm_config_t *config)
mbed_official 146:f64d43ff0c18 61 {
mbed_official 146:f64d43ff0c18 62 ftm_hal_enable_dual_capture(instance, config->channel, false);
mbed_official 146:f64d43ff0c18 63 ftm_hal_set_channel_edge_level(instance, config->channel,config->edge_mode.ftm_pwm_edge_mode? 1:2);
mbed_official 146:f64d43ff0c18 64 switch(config->mode)
mbed_official 146:f64d43ff0c18 65 {
mbed_official 146:f64d43ff0c18 66 case kFtmEdgeAlignedPWM:
mbed_official 146:f64d43ff0c18 67 ftm_hal_enable_dual_channel_combine(instance, config->channel, false);
mbed_official 146:f64d43ff0c18 68 ftm_hal_set_cpwms(instance, 0);
mbed_official 146:f64d43ff0c18 69 ftm_hal_set_channel_MSnBA_mode(instance, config->channel, 2);
mbed_official 146:f64d43ff0c18 70 break;
mbed_official 146:f64d43ff0c18 71 case kFtmCenterAlignedPWM:
mbed_official 146:f64d43ff0c18 72 ftm_hal_enable_dual_channel_combine(instance, config->channel, false);
mbed_official 146:f64d43ff0c18 73 ftm_hal_set_cpwms(instance, 1);
mbed_official 146:f64d43ff0c18 74 break;
mbed_official 146:f64d43ff0c18 75 case kFtmCombinedPWM:
mbed_official 146:f64d43ff0c18 76 ftm_hal_set_cpwms(instance, 0);
mbed_official 146:f64d43ff0c18 77 ftm_hal_enable_dual_channel_combine(instance, config->channel, true);
mbed_official 146:f64d43ff0c18 78 break;
mbed_official 146:f64d43ff0c18 79 default:
mbed_official 146:f64d43ff0c18 80 assert(0);
mbed_official 146:f64d43ff0c18 81 break;
mbed_official 146:f64d43ff0c18 82 }
mbed_official 146:f64d43ff0c18 83 }
mbed_official 146:f64d43ff0c18 84
mbed_official 146:f64d43ff0c18 85 /*see fsl_ftm_hal.h for documentation of this function*/
mbed_official 146:f64d43ff0c18 86 void ftm_hal_disable_pwm_mode(uint8_t instance, ftm_config_t *config)
mbed_official 146:f64d43ff0c18 87 {
mbed_official 146:f64d43ff0c18 88
mbed_official 146:f64d43ff0c18 89 ftm_hal_set_channel_count_value(instance, config->channel, 0);
mbed_official 146:f64d43ff0c18 90 switch(config->mode)
mbed_official 146:f64d43ff0c18 91 {
mbed_official 146:f64d43ff0c18 92 case kFtmEdgeAlignedPWM:
mbed_official 146:f64d43ff0c18 93 ftm_hal_set_channel_MSnBA_mode(instance, config->channel, 1);
mbed_official 146:f64d43ff0c18 94 break;
mbed_official 146:f64d43ff0c18 95 case kFtmCenterAlignedPWM:
mbed_official 146:f64d43ff0c18 96 ftm_hal_set_cpwms(instance, 0);
mbed_official 146:f64d43ff0c18 97 break;
mbed_official 146:f64d43ff0c18 98 case kFtmCombinedPWM:
mbed_official 146:f64d43ff0c18 99 ftm_hal_enable_dual_channel_combine(instance, config->channel, false);
mbed_official 146:f64d43ff0c18 100 break;
mbed_official 146:f64d43ff0c18 101 default:
mbed_official 146:f64d43ff0c18 102 assert(0);
mbed_official 146:f64d43ff0c18 103 break;
mbed_official 146:f64d43ff0c18 104 }
mbed_official 146:f64d43ff0c18 105 }
mbed_official 146:f64d43ff0c18 106 /*see fsl_ftm_hal.h for documentation of this function*/
mbed_official 146:f64d43ff0c18 107 void ftm_hal_reset(uint8_t instance)
mbed_official 146:f64d43ff0c18 108 {
mbed_official 146:f64d43ff0c18 109 uint8_t chan = ((instance == 1) || (instance == 2)) ? 2 : HW_FTM_CHANNEL_COUNT;
mbed_official 146:f64d43ff0c18 110 ftm_hal_set_clock_source(instance,kClock_source_FTM_None);
mbed_official 146:f64d43ff0c18 111 HW_FTM_SC_WR(instance, 0);
mbed_official 146:f64d43ff0c18 112 HW_FTM_CNT_WR(instance, 0);
mbed_official 146:f64d43ff0c18 113 HW_FTM_MOD_WR(instance, 0);
mbed_official 146:f64d43ff0c18 114
mbed_official 146:f64d43ff0c18 115 /*instance 1 and 2 only has two channels,0 and 1*/
mbed_official 146:f64d43ff0c18 116 for(int i = 0; i<chan; i++)
mbed_official 146:f64d43ff0c18 117 {
mbed_official 146:f64d43ff0c18 118 HW_FTM_CnSC_WR(instance, i, 0);
mbed_official 146:f64d43ff0c18 119 HW_FTM_CnV_WR(instance, i, 0);
mbed_official 146:f64d43ff0c18 120 }
mbed_official 146:f64d43ff0c18 121 HW_FTM_CNTIN_WR(instance, 0);
mbed_official 146:f64d43ff0c18 122 HW_FTM_STATUS_WR(instance, 0);
mbed_official 146:f64d43ff0c18 123 HW_FTM_MODE_WR(instance, 0x00000004);
mbed_official 146:f64d43ff0c18 124 HW_FTM_SYNC_WR(instance, 0);
mbed_official 146:f64d43ff0c18 125 HW_FTM_OUTINIT_WR(instance, 0);
mbed_official 146:f64d43ff0c18 126 HW_FTM_OUTMASK_WR(instance, 0);
mbed_official 146:f64d43ff0c18 127 HW_FTM_COMBINE_WR(instance, 0);
mbed_official 146:f64d43ff0c18 128 HW_FTM_DEADTIME_WR(instance, 0);
mbed_official 146:f64d43ff0c18 129 HW_FTM_EXTTRIG_WR(instance, 0);
mbed_official 146:f64d43ff0c18 130 HW_FTM_POL_WR(instance, 0);
mbed_official 146:f64d43ff0c18 131 HW_FTM_FMS_WR(instance, 0);
mbed_official 146:f64d43ff0c18 132 HW_FTM_FILTER_WR(instance, 0);
mbed_official 146:f64d43ff0c18 133 HW_FTM_FLTCTRL_WR(instance, 0);
mbed_official 146:f64d43ff0c18 134 /*HW_FTM_QDCTRL_WR(instance, 0);*/
mbed_official 146:f64d43ff0c18 135 HW_FTM_CONF_WR(instance, 0);
mbed_official 146:f64d43ff0c18 136 HW_FTM_FLTPOL_WR(instance, 0);
mbed_official 146:f64d43ff0c18 137 HW_FTM_SYNCONF_WR(instance, 0);
mbed_official 146:f64d43ff0c18 138 HW_FTM_INVCTRL_WR(instance, 0);
mbed_official 146:f64d43ff0c18 139 HW_FTM_SWOCTRL_WR(instance, 0);
mbed_official 146:f64d43ff0c18 140 HW_FTM_PWMLOAD_WR(instance, 0);
mbed_official 146:f64d43ff0c18 141 }
mbed_official 146:f64d43ff0c18 142 /*see fsl_ftm_hal.h for documentation of this function*/
mbed_official 146:f64d43ff0c18 143 void ftm_hal_set_hardware_trigger(uint8_t instance, uint8_t trigger_num, bool enable)
mbed_official 146:f64d43ff0c18 144 {
mbed_official 146:f64d43ff0c18 145 assert(instance <HW_FTM_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 146 switch(trigger_num)
mbed_official 146:f64d43ff0c18 147 {
mbed_official 146:f64d43ff0c18 148 case 0:
mbed_official 146:f64d43ff0c18 149 BW_FTM_SYNC_TRIG0(instance, enable?1:0);
mbed_official 146:f64d43ff0c18 150 break;
mbed_official 146:f64d43ff0c18 151
mbed_official 146:f64d43ff0c18 152 case 1:
mbed_official 146:f64d43ff0c18 153 BW_FTM_SYNC_TRIG1(instance, enable?1:0);
mbed_official 146:f64d43ff0c18 154 break;
mbed_official 146:f64d43ff0c18 155
mbed_official 146:f64d43ff0c18 156 case 2:
mbed_official 146:f64d43ff0c18 157 BW_FTM_SYNC_TRIG2(instance, enable?1:0);
mbed_official 146:f64d43ff0c18 158 break;
mbed_official 146:f64d43ff0c18 159
mbed_official 146:f64d43ff0c18 160 default:
mbed_official 146:f64d43ff0c18 161 assert(0);
mbed_official 146:f64d43ff0c18 162 break;
mbed_official 146:f64d43ff0c18 163 }
mbed_official 146:f64d43ff0c18 164 }
mbed_official 146:f64d43ff0c18 165
mbed_official 146:f64d43ff0c18 166 /*see fsl_ftm_hal.h for documentation of this function*/
mbed_official 146:f64d43ff0c18 167 void ftm_hal_enable_channel_trigger(uint8_t instance, uint8_t channel, bool val)
mbed_official 146:f64d43ff0c18 168 {
mbed_official 146:f64d43ff0c18 169 uint8_t bit = val? 1:0;
mbed_official 146:f64d43ff0c18 170 uint32_t value = (channel > 1U)? (uint8_t)(bit<<(channel-2U)) : (uint8_t)(bit<<(channel+4U));
mbed_official 146:f64d43ff0c18 171 assert(instance <HW_FTM_INSTANCE_COUNT && channel < (HW_FTM_CHANNEL_COUNT - 2));
mbed_official 146:f64d43ff0c18 172 BW_FTM_EXTTRIG_INITTRIGEN(instance, val);
mbed_official 146:f64d43ff0c18 173 val? HW_FTM_EXTTRIG_SET(instance, value)
mbed_official 146:f64d43ff0c18 174 : HW_FTM_EXTTRIG_CLR(instance, value);
mbed_official 146:f64d43ff0c18 175 }
mbed_official 146:f64d43ff0c18 176
mbed_official 146:f64d43ff0c18 177 /*see fsl_ftm_hal.h for documentation of this function*/
mbed_official 146:f64d43ff0c18 178 void ftm_hal_set_channel_input_capture_filter(uint8_t instance, uint8_t channel, uint8_t val)
mbed_official 146:f64d43ff0c18 179 {
mbed_official 146:f64d43ff0c18 180 assert(instance < HW_FTM_INSTANCE_COUNT && channel < HW_CHAN4);
mbed_official 146:f64d43ff0c18 181 switch(channel)
mbed_official 146:f64d43ff0c18 182 {
mbed_official 146:f64d43ff0c18 183 case 0:
mbed_official 146:f64d43ff0c18 184 BW_FTM_FILTER_CH0FVAL(instance, val);
mbed_official 146:f64d43ff0c18 185 break;
mbed_official 146:f64d43ff0c18 186
mbed_official 146:f64d43ff0c18 187 case 1:
mbed_official 146:f64d43ff0c18 188 BW_FTM_FILTER_CH1FVAL(instance, val);
mbed_official 146:f64d43ff0c18 189 break;
mbed_official 146:f64d43ff0c18 190
mbed_official 146:f64d43ff0c18 191 case 2:
mbed_official 146:f64d43ff0c18 192 BW_FTM_FILTER_CH2FVAL(instance, val);
mbed_official 146:f64d43ff0c18 193 break;
mbed_official 146:f64d43ff0c18 194
mbed_official 146:f64d43ff0c18 195 case 3:
mbed_official 146:f64d43ff0c18 196 BW_FTM_FILTER_CH3FVAL(instance, val);
mbed_official 146:f64d43ff0c18 197 break;
mbed_official 146:f64d43ff0c18 198
mbed_official 146:f64d43ff0c18 199 default:
mbed_official 146:f64d43ff0c18 200 assert(0);
mbed_official 146:f64d43ff0c18 201 break;
mbed_official 146:f64d43ff0c18 202 }
mbed_official 146:f64d43ff0c18 203 }
mbed_official 146:f64d43ff0c18 204
mbed_official 146:f64d43ff0c18 205 /*see fsl_ftm_hal.h for documentation of this function */
mbed_official 146:f64d43ff0c18 206 /*void ftm_hal_set_deadtime(uint8_t instance, uint_32 us)*/