Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
targets/TARGET_Freescale/TARGET_KSDK2_MCUS/TARGET_K66F/drivers/fsl_pdb.c@149:156823d33999, 2016-10-28 (annotated)
- Committer:
- <>
- Date:
- Fri Oct 28 11:17:30 2016 +0100
- Revision:
- 149:156823d33999
- Parent:
- targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/TARGET_K22F/drivers/fsl_pdb.c@121:7f86b4238bec
This updates the lib to the mbed lib v128
NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 121:7f86b4238bec | 1 | /* |
mbed_official | 121:7f86b4238bec | 2 | * Copyright (c) 2015, Freescale Semiconductor, Inc. |
mbed_official | 121:7f86b4238bec | 3 | * All rights reserved. |
mbed_official | 121:7f86b4238bec | 4 | * |
mbed_official | 121:7f86b4238bec | 5 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 121:7f86b4238bec | 6 | * are permitted provided that the following conditions are met: |
mbed_official | 121:7f86b4238bec | 7 | * |
mbed_official | 121:7f86b4238bec | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
mbed_official | 121:7f86b4238bec | 9 | * of conditions and the following disclaimer. |
mbed_official | 121:7f86b4238bec | 10 | * |
mbed_official | 121:7f86b4238bec | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
mbed_official | 121:7f86b4238bec | 12 | * list of conditions and the following disclaimer in the documentation and/or |
mbed_official | 121:7f86b4238bec | 13 | * other materials provided with the distribution. |
mbed_official | 121:7f86b4238bec | 14 | * |
mbed_official | 121:7f86b4238bec | 15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its |
mbed_official | 121:7f86b4238bec | 16 | * contributors may be used to endorse or promote products derived from this |
mbed_official | 121:7f86b4238bec | 17 | * software without specific prior written permission. |
mbed_official | 121:7f86b4238bec | 18 | * |
mbed_official | 121:7f86b4238bec | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
mbed_official | 121:7f86b4238bec | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
mbed_official | 121:7f86b4238bec | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 121:7f86b4238bec | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
mbed_official | 121:7f86b4238bec | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
mbed_official | 121:7f86b4238bec | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
mbed_official | 121:7f86b4238bec | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
mbed_official | 121:7f86b4238bec | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
mbed_official | 121:7f86b4238bec | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
mbed_official | 121:7f86b4238bec | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 121:7f86b4238bec | 29 | */ |
mbed_official | 121:7f86b4238bec | 30 | |
mbed_official | 121:7f86b4238bec | 31 | #include "fsl_pdb.h" |
mbed_official | 121:7f86b4238bec | 32 | |
mbed_official | 121:7f86b4238bec | 33 | /******************************************************************************* |
mbed_official | 121:7f86b4238bec | 34 | * Prototypes |
mbed_official | 121:7f86b4238bec | 35 | ******************************************************************************/ |
mbed_official | 121:7f86b4238bec | 36 | /*! |
mbed_official | 121:7f86b4238bec | 37 | * @brief Get instance number for PDB module. |
mbed_official | 121:7f86b4238bec | 38 | * |
mbed_official | 121:7f86b4238bec | 39 | * @param base PDB peripheral base address |
mbed_official | 121:7f86b4238bec | 40 | */ |
mbed_official | 121:7f86b4238bec | 41 | static uint32_t PDB_GetInstance(PDB_Type *base); |
mbed_official | 121:7f86b4238bec | 42 | |
mbed_official | 121:7f86b4238bec | 43 | /******************************************************************************* |
mbed_official | 121:7f86b4238bec | 44 | * Variables |
mbed_official | 121:7f86b4238bec | 45 | ******************************************************************************/ |
mbed_official | 121:7f86b4238bec | 46 | /*! @brief Pointers to PDB bases for each instance. */ |
mbed_official | 121:7f86b4238bec | 47 | static PDB_Type *const s_pdbBases[] = PDB_BASE_PTRS; |
mbed_official | 121:7f86b4238bec | 48 | /*! @brief Pointers to PDB clocks for each instance. */ |
mbed_official | 121:7f86b4238bec | 49 | const clock_ip_name_t s_pdbClocks[] = PDB_CLOCKS; |
mbed_official | 121:7f86b4238bec | 50 | |
mbed_official | 121:7f86b4238bec | 51 | /******************************************************************************* |
mbed_official | 121:7f86b4238bec | 52 | * Codes |
mbed_official | 121:7f86b4238bec | 53 | ******************************************************************************/ |
mbed_official | 121:7f86b4238bec | 54 | static uint32_t PDB_GetInstance(PDB_Type *base) |
mbed_official | 121:7f86b4238bec | 55 | { |
mbed_official | 121:7f86b4238bec | 56 | uint32_t instance; |
mbed_official | 121:7f86b4238bec | 57 | |
mbed_official | 121:7f86b4238bec | 58 | /* Find the instance index from base address mappings. */ |
mbed_official | 121:7f86b4238bec | 59 | for (instance = 0; instance < FSL_FEATURE_SOC_PDB_COUNT; instance++) |
mbed_official | 121:7f86b4238bec | 60 | { |
mbed_official | 121:7f86b4238bec | 61 | if (s_pdbBases[instance] == base) |
mbed_official | 121:7f86b4238bec | 62 | { |
mbed_official | 121:7f86b4238bec | 63 | break; |
mbed_official | 121:7f86b4238bec | 64 | } |
mbed_official | 121:7f86b4238bec | 65 | } |
mbed_official | 121:7f86b4238bec | 66 | |
mbed_official | 121:7f86b4238bec | 67 | assert(instance < FSL_FEATURE_SOC_PDB_COUNT); |
mbed_official | 121:7f86b4238bec | 68 | |
mbed_official | 121:7f86b4238bec | 69 | return instance; |
mbed_official | 121:7f86b4238bec | 70 | } |
mbed_official | 121:7f86b4238bec | 71 | |
mbed_official | 121:7f86b4238bec | 72 | void PDB_Init(PDB_Type *base, const pdb_config_t *config) |
mbed_official | 121:7f86b4238bec | 73 | { |
mbed_official | 121:7f86b4238bec | 74 | assert(NULL != config); |
mbed_official | 121:7f86b4238bec | 75 | |
mbed_official | 121:7f86b4238bec | 76 | uint32_t tmp32; |
mbed_official | 121:7f86b4238bec | 77 | |
mbed_official | 121:7f86b4238bec | 78 | /* Enable the clock. */ |
mbed_official | 121:7f86b4238bec | 79 | CLOCK_EnableClock(s_pdbClocks[PDB_GetInstance(base)]); |
mbed_official | 121:7f86b4238bec | 80 | |
mbed_official | 121:7f86b4238bec | 81 | /* Configure. */ |
mbed_official | 121:7f86b4238bec | 82 | /* PDBx_SC. */ |
mbed_official | 121:7f86b4238bec | 83 | tmp32 = base->SC & |
mbed_official | 121:7f86b4238bec | 84 | ~(PDB_SC_LDMOD_MASK | PDB_SC_PRESCALER_MASK | PDB_SC_TRGSEL_MASK | PDB_SC_MULT_MASK | PDB_SC_CONT_MASK); |
mbed_official | 121:7f86b4238bec | 85 | |
mbed_official | 121:7f86b4238bec | 86 | tmp32 |= PDB_SC_LDMOD(config->loadValueMode) | PDB_SC_PRESCALER(config->prescalerDivider) | |
mbed_official | 121:7f86b4238bec | 87 | PDB_SC_TRGSEL(config->triggerInputSource) | PDB_SC_MULT(config->dividerMultiplicationFactor); |
mbed_official | 121:7f86b4238bec | 88 | if (config->enableContinuousMode) |
mbed_official | 121:7f86b4238bec | 89 | { |
mbed_official | 121:7f86b4238bec | 90 | tmp32 |= PDB_SC_CONT_MASK; |
mbed_official | 121:7f86b4238bec | 91 | } |
mbed_official | 121:7f86b4238bec | 92 | base->SC = tmp32; |
mbed_official | 121:7f86b4238bec | 93 | |
mbed_official | 121:7f86b4238bec | 94 | PDB_Enable(base, true); /* Enable the PDB module. */ |
mbed_official | 121:7f86b4238bec | 95 | } |
mbed_official | 121:7f86b4238bec | 96 | |
mbed_official | 121:7f86b4238bec | 97 | void PDB_Deinit(PDB_Type *base) |
mbed_official | 121:7f86b4238bec | 98 | { |
mbed_official | 121:7f86b4238bec | 99 | PDB_Enable(base, false); /* Disable the PDB module. */ |
mbed_official | 121:7f86b4238bec | 100 | |
mbed_official | 121:7f86b4238bec | 101 | /* Disable the clock. */ |
mbed_official | 121:7f86b4238bec | 102 | CLOCK_DisableClock(s_pdbClocks[PDB_GetInstance(base)]); |
mbed_official | 121:7f86b4238bec | 103 | } |
mbed_official | 121:7f86b4238bec | 104 | |
mbed_official | 121:7f86b4238bec | 105 | void PDB_GetDefaultConfig(pdb_config_t *config) |
mbed_official | 121:7f86b4238bec | 106 | { |
mbed_official | 121:7f86b4238bec | 107 | assert(NULL != config); |
mbed_official | 121:7f86b4238bec | 108 | |
mbed_official | 121:7f86b4238bec | 109 | config->loadValueMode = kPDB_LoadValueImmediately; |
mbed_official | 121:7f86b4238bec | 110 | config->prescalerDivider = kPDB_PrescalerDivider1; |
mbed_official | 121:7f86b4238bec | 111 | config->dividerMultiplicationFactor = kPDB_DividerMultiplicationFactor1; |
mbed_official | 121:7f86b4238bec | 112 | config->triggerInputSource = kPDB_TriggerSoftware; |
mbed_official | 121:7f86b4238bec | 113 | config->enableContinuousMode = false; |
mbed_official | 121:7f86b4238bec | 114 | } |
mbed_official | 121:7f86b4238bec | 115 | |
mbed_official | 121:7f86b4238bec | 116 | #if defined(FSL_FEATURE_PDB_HAS_DAC) && FSL_FEATURE_PDB_HAS_DAC |
mbed_official | 121:7f86b4238bec | 117 | void PDB_SetDACTriggerConfig(PDB_Type *base, uint32_t channel, pdb_dac_trigger_config_t *config) |
mbed_official | 121:7f86b4238bec | 118 | { |
mbed_official | 121:7f86b4238bec | 119 | assert(channel < PDB_INTC_COUNT); |
mbed_official | 121:7f86b4238bec | 120 | assert(NULL != config); |
mbed_official | 121:7f86b4238bec | 121 | |
mbed_official | 121:7f86b4238bec | 122 | uint32_t tmp32 = 0U; |
mbed_official | 121:7f86b4238bec | 123 | |
mbed_official | 121:7f86b4238bec | 124 | /* PDBx_DACINTC. */ |
mbed_official | 121:7f86b4238bec | 125 | if (config->enableExternalTriggerInput) |
mbed_official | 121:7f86b4238bec | 126 | { |
mbed_official | 121:7f86b4238bec | 127 | tmp32 |= PDB_INTC_EXT_MASK; |
mbed_official | 121:7f86b4238bec | 128 | } |
mbed_official | 121:7f86b4238bec | 129 | if (config->enableIntervalTrigger) |
mbed_official | 121:7f86b4238bec | 130 | { |
mbed_official | 121:7f86b4238bec | 131 | tmp32 |= PDB_INTC_TOE_MASK; |
mbed_official | 121:7f86b4238bec | 132 | } |
mbed_official | 121:7f86b4238bec | 133 | base->DAC[channel].INTC = tmp32; |
mbed_official | 121:7f86b4238bec | 134 | } |
mbed_official | 121:7f86b4238bec | 135 | #endif /* FSL_FEATURE_PDB_HAS_DAC */ |