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.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC546XX/drivers/fsl_mrt.c@175:af195413fb11, 2017-10-11 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Oct 11 12:45:49 2017 +0100
- Revision:
- 175:af195413fb11
- Parent:
- targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54608/drivers/fsl_mrt.c@170:19eb464bc2be
- Child:
- 182:a56a73fd2a6f
This updates the lib to the mbed lib v 153
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Kojto | 170:19eb464bc2be | 1 | /* |
| Kojto | 170:19eb464bc2be | 2 | * Copyright (c) 2016, Freescale Semiconductor, Inc. |
| Kojto | 170:19eb464bc2be | 3 | * Copyright 2016-2017 NXP |
| Kojto | 170:19eb464bc2be | 4 | * |
| Kojto | 170:19eb464bc2be | 5 | * Redistribution and use in source and binary forms, with or without modification, |
| Kojto | 170:19eb464bc2be | 6 | * are permitted provided that the following conditions are met: |
| Kojto | 170:19eb464bc2be | 7 | * |
| Kojto | 170:19eb464bc2be | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
| Kojto | 170:19eb464bc2be | 9 | * of conditions and the following disclaimer. |
| Kojto | 170:19eb464bc2be | 10 | * |
| Kojto | 170:19eb464bc2be | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
| Kojto | 170:19eb464bc2be | 12 | * list of conditions and the following disclaimer in the documentation and/or |
| Kojto | 170:19eb464bc2be | 13 | * other materials provided with the distribution. |
| Kojto | 170:19eb464bc2be | 14 | * |
| Kojto | 170:19eb464bc2be | 15 | * o Neither the name of the copyright holder nor the names of its |
| Kojto | 170:19eb464bc2be | 16 | * contributors may be used to endorse or promote products derived from this |
| Kojto | 170:19eb464bc2be | 17 | * software without specific prior written permission. |
| Kojto | 170:19eb464bc2be | 18 | * |
| Kojto | 170:19eb464bc2be | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| Kojto | 170:19eb464bc2be | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| Kojto | 170:19eb464bc2be | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| Kojto | 170:19eb464bc2be | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| Kojto | 170:19eb464bc2be | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| Kojto | 170:19eb464bc2be | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| Kojto | 170:19eb464bc2be | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| Kojto | 170:19eb464bc2be | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| Kojto | 170:19eb464bc2be | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| Kojto | 170:19eb464bc2be | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| Kojto | 170:19eb464bc2be | 29 | */ |
| Kojto | 170:19eb464bc2be | 30 | |
| Kojto | 170:19eb464bc2be | 31 | #include "fsl_mrt.h" |
| Kojto | 170:19eb464bc2be | 32 | |
| Kojto | 170:19eb464bc2be | 33 | /******************************************************************************* |
| Kojto | 170:19eb464bc2be | 34 | * Prototypes |
| Kojto | 170:19eb464bc2be | 35 | ******************************************************************************/ |
| Kojto | 170:19eb464bc2be | 36 | /*! |
| Kojto | 170:19eb464bc2be | 37 | * @brief Gets the instance from the base address |
| Kojto | 170:19eb464bc2be | 38 | * |
| Kojto | 170:19eb464bc2be | 39 | * @param base Multi-Rate timer peripheral base address |
| Kojto | 170:19eb464bc2be | 40 | * |
| Kojto | 170:19eb464bc2be | 41 | * @return The MRT instance |
| Kojto | 170:19eb464bc2be | 42 | */ |
| Kojto | 170:19eb464bc2be | 43 | static uint32_t MRT_GetInstance(MRT_Type *base); |
| Kojto | 170:19eb464bc2be | 44 | |
| Kojto | 170:19eb464bc2be | 45 | /******************************************************************************* |
| Kojto | 170:19eb464bc2be | 46 | * Variables |
| Kojto | 170:19eb464bc2be | 47 | ******************************************************************************/ |
| Kojto | 170:19eb464bc2be | 48 | /*! @brief Pointers to MRT bases for each instance. */ |
| Kojto | 170:19eb464bc2be | 49 | static MRT_Type *const s_mrtBases[] = MRT_BASE_PTRS; |
| Kojto | 170:19eb464bc2be | 50 | |
| Kojto | 170:19eb464bc2be | 51 | #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) |
| Kojto | 170:19eb464bc2be | 52 | /*! @brief Pointers to MRT clocks for each instance. */ |
| Kojto | 170:19eb464bc2be | 53 | static const clock_ip_name_t s_mrtClocks[] = MRT_CLOCKS; |
| Kojto | 170:19eb464bc2be | 54 | #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ |
| Kojto | 170:19eb464bc2be | 55 | |
| Kojto | 170:19eb464bc2be | 56 | /*! @brief Pointers to MRT resets for each instance. */ |
| Kojto | 170:19eb464bc2be | 57 | static const reset_ip_name_t s_mrtResets[] = MRT_RSTS; |
| Kojto | 170:19eb464bc2be | 58 | |
| Kojto | 170:19eb464bc2be | 59 | /******************************************************************************* |
| Kojto | 170:19eb464bc2be | 60 | * Code |
| Kojto | 170:19eb464bc2be | 61 | ******************************************************************************/ |
| Kojto | 170:19eb464bc2be | 62 | static uint32_t MRT_GetInstance(MRT_Type *base) |
| Kojto | 170:19eb464bc2be | 63 | { |
| Kojto | 170:19eb464bc2be | 64 | uint32_t instance; |
| Kojto | 170:19eb464bc2be | 65 | uint32_t mrtArrayCount = (sizeof(s_mrtBases) / sizeof(s_mrtBases[0])); |
| Kojto | 170:19eb464bc2be | 66 | |
| Kojto | 170:19eb464bc2be | 67 | /* Find the instance index from base address mappings. */ |
| Kojto | 170:19eb464bc2be | 68 | for (instance = 0; instance < mrtArrayCount; instance++) |
| Kojto | 170:19eb464bc2be | 69 | { |
| Kojto | 170:19eb464bc2be | 70 | if (s_mrtBases[instance] == base) |
| Kojto | 170:19eb464bc2be | 71 | { |
| Kojto | 170:19eb464bc2be | 72 | break; |
| Kojto | 170:19eb464bc2be | 73 | } |
| Kojto | 170:19eb464bc2be | 74 | } |
| Kojto | 170:19eb464bc2be | 75 | |
| Kojto | 170:19eb464bc2be | 76 | assert(instance < mrtArrayCount); |
| Kojto | 170:19eb464bc2be | 77 | |
| Kojto | 170:19eb464bc2be | 78 | return instance; |
| Kojto | 170:19eb464bc2be | 79 | } |
| Kojto | 170:19eb464bc2be | 80 | |
| Kojto | 170:19eb464bc2be | 81 | void MRT_Init(MRT_Type *base, const mrt_config_t *config) |
| Kojto | 170:19eb464bc2be | 82 | { |
| Kojto | 170:19eb464bc2be | 83 | assert(config); |
| Kojto | 170:19eb464bc2be | 84 | |
| Kojto | 170:19eb464bc2be | 85 | #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) |
| Kojto | 170:19eb464bc2be | 86 | /* Ungate the MRT clock */ |
| Kojto | 170:19eb464bc2be | 87 | CLOCK_EnableClock(s_mrtClocks[MRT_GetInstance(base)]); |
| Kojto | 170:19eb464bc2be | 88 | #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ |
| Kojto | 170:19eb464bc2be | 89 | |
| Kojto | 170:19eb464bc2be | 90 | /* Reset the module */ |
| Kojto | 170:19eb464bc2be | 91 | RESET_PeripheralReset(s_mrtResets[MRT_GetInstance(base)]); |
| Kojto | 170:19eb464bc2be | 92 | |
| Kojto | 170:19eb464bc2be | 93 | /* Set timer operating mode */ |
| Kojto | 170:19eb464bc2be | 94 | base->MODCFG = MRT_MODCFG_MULTITASK(config->enableMultiTask); |
| Kojto | 170:19eb464bc2be | 95 | } |
| Kojto | 170:19eb464bc2be | 96 | |
| Kojto | 170:19eb464bc2be | 97 | void MRT_Deinit(MRT_Type *base) |
| Kojto | 170:19eb464bc2be | 98 | { |
| Kojto | 170:19eb464bc2be | 99 | /* Stop all the timers */ |
| Kojto | 170:19eb464bc2be | 100 | MRT_StopTimer(base, kMRT_Channel_0); |
| Kojto | 170:19eb464bc2be | 101 | MRT_StopTimer(base, kMRT_Channel_1); |
| Kojto | 170:19eb464bc2be | 102 | MRT_StopTimer(base, kMRT_Channel_2); |
| Kojto | 170:19eb464bc2be | 103 | MRT_StopTimer(base, kMRT_Channel_3); |
| Kojto | 170:19eb464bc2be | 104 | |
| Kojto | 170:19eb464bc2be | 105 | #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) |
| Kojto | 170:19eb464bc2be | 106 | /* Gate the MRT clock*/ |
| Kojto | 170:19eb464bc2be | 107 | CLOCK_DisableClock(s_mrtClocks[MRT_GetInstance(base)]); |
| Kojto | 170:19eb464bc2be | 108 | #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ |
| Kojto | 170:19eb464bc2be | 109 | } |
| Kojto | 170:19eb464bc2be | 110 | |
| Kojto | 170:19eb464bc2be | 111 | void MRT_UpdateTimerPeriod(MRT_Type *base, mrt_chnl_t channel, uint32_t count, bool immediateLoad) |
| Kojto | 170:19eb464bc2be | 112 | { |
| Kojto | 170:19eb464bc2be | 113 | uint32_t newValue = count; |
| Kojto | 170:19eb464bc2be | 114 | if (((base->CHANNEL[channel].CTRL & MRT_CHANNEL_CTRL_MODE_MASK) == kMRT_OneShotMode) || (immediateLoad)) |
| Kojto | 170:19eb464bc2be | 115 | { |
| Kojto | 170:19eb464bc2be | 116 | /* For one-shot interrupt mode, load the new value immediately even if user forgot to enable */ |
| Kojto | 170:19eb464bc2be | 117 | newValue |= MRT_CHANNEL_INTVAL_LOAD_MASK; |
| Kojto | 170:19eb464bc2be | 118 | } |
| Kojto | 170:19eb464bc2be | 119 | |
| Kojto | 170:19eb464bc2be | 120 | /* Update the timer interval value */ |
| Kojto | 170:19eb464bc2be | 121 | base->CHANNEL[channel].INTVAL = newValue; |
| Kojto | 170:19eb464bc2be | 122 | } |


