Add KSDK and readme.
This commit is contained in:
8782
devices/MK22F51212/MK22F51212.h
Normal file
8782
devices/MK22F51212/MK22F51212.h
Normal file
File diff suppressed because it is too large
Load Diff
99924
devices/MK22F51212/MK22F51212.svd
Normal file
99924
devices/MK22F51212/MK22F51212.svd
Normal file
File diff suppressed because it is too large
Load Diff
2144
devices/MK22F51212/MK22F51212_features.h
Normal file
2144
devices/MK22F51212/MK22F51212_features.h
Normal file
File diff suppressed because it is too large
Load Diff
129
devices/MK22F51212/arm/MK22FN512xxx12_flash.scf
Normal file
129
devices/MK22F51212/arm/MK22FN512xxx12_flash.scf
Normal file
@@ -0,0 +1,129 @@
|
||||
#! armcc -E
|
||||
/*
|
||||
** ###################################################################
|
||||
** Processors: MK22FN512CAP12
|
||||
** MK22FN512VDC12
|
||||
** MK22FN512VFX12
|
||||
** MK22FN512VLH12
|
||||
** MK22FN512VLL12
|
||||
** MK22FN512VMP12
|
||||
**
|
||||
** Compiler: Keil ARM C/C++ Compiler
|
||||
** Reference manual: K22P121M120SF7RM, Rev. 1, March 24, 2014
|
||||
** Version: rev. 2.9, 2016-03-21
|
||||
** Build: b160321
|
||||
**
|
||||
** Abstract:
|
||||
** Linker file for the Keil ARM C/C++ Compiler
|
||||
**
|
||||
** Copyright (c) 2016 Freescale Semiconductor, Inc.
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without modification,
|
||||
** are permitted provided that the following conditions are met:
|
||||
**
|
||||
** o Redistributions of source code must retain the above copyright notice, this list
|
||||
** of conditions and the following disclaimer.
|
||||
**
|
||||
** o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
** list of conditions and the following disclaimer in the documentation and/or
|
||||
** other materials provided with the distribution.
|
||||
**
|
||||
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
** contributors may be used to endorse or promote products derived from this
|
||||
** software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**
|
||||
** http: www.freescale.com
|
||||
** mail: support@freescale.com
|
||||
**
|
||||
** ###################################################################
|
||||
*/
|
||||
|
||||
#if (defined(__ram_vector_table__))
|
||||
#define __ram_vector_table_size__ 0x00000400
|
||||
#else
|
||||
#define __ram_vector_table_size__ 0x00000000
|
||||
#endif
|
||||
|
||||
#define m_interrupts_start 0x00000000
|
||||
#define m_interrupts_size 0x00000400
|
||||
|
||||
#define m_flash_config_start 0x00000400
|
||||
#define m_flash_config_size 0x00000010
|
||||
|
||||
#define m_text_start 0x00000410
|
||||
#define m_text_size 0x0007FBF0
|
||||
|
||||
#define m_interrupts_ram_start 0x1FFF0000
|
||||
#define m_interrupts_ram_size __ram_vector_table_size__
|
||||
|
||||
#define m_data_start (m_interrupts_ram_start + m_interrupts_ram_size)
|
||||
#define m_data_size (0x00010000 - m_interrupts_ram_size)
|
||||
|
||||
#define m_data_2_start 0x20000000
|
||||
#define m_data_2_size 0x00010000
|
||||
|
||||
/* Sizes */
|
||||
#if (defined(__stack_size__))
|
||||
#define Stack_Size __stack_size__
|
||||
#else
|
||||
#define Stack_Size 0x0400
|
||||
#endif
|
||||
|
||||
#if (defined(__heap_size__))
|
||||
#define Heap_Size __heap_size__
|
||||
#else
|
||||
#define Heap_Size 0x0400
|
||||
#endif
|
||||
|
||||
LR_m_text m_text_start m_text_size { ; load region size_region
|
||||
ER_m_text m_text_start m_text_size { ; load address = execution address
|
||||
* (InRoot$$Sections)
|
||||
.ANY (+RO)
|
||||
}
|
||||
RW_m_data m_data_start m_data_size { ; RW data
|
||||
.ANY (+RW +ZI)
|
||||
}
|
||||
RW_m_data_2 m_data_2_start m_data_2_size-Stack_Size-Heap_Size { ; RW data
|
||||
.ANY (+RW +ZI)
|
||||
}
|
||||
ARM_LIB_HEAP ((ImageLimit(RW_m_data_2) == m_data_2_start) ? ImageLimit(RW_m_data) : +0) EMPTY Heap_Size { ; Heap region growing up
|
||||
}
|
||||
ARM_LIB_STACK m_data_2_start+m_data_2_size EMPTY -Stack_Size { ; Stack region growing down
|
||||
}
|
||||
}
|
||||
|
||||
LR_m_interrupts m_interrupts_start m_interrupts_size {
|
||||
#if (!defined(__ram_vector_table__))
|
||||
VECTOR_RAM m_interrupts_start EMPTY 0 {
|
||||
}
|
||||
#endif
|
||||
VECTOR_ROM m_interrupts_start m_interrupts_size { ; load address = execution address
|
||||
* (RESET,+FIRST)
|
||||
}
|
||||
}
|
||||
|
||||
LR_m_flash_config m_flash_config_start m_flash_config_size {
|
||||
ER_m_flash_config m_flash_config_start m_flash_config_size { ; load address = execution address
|
||||
* (FlashConfig)
|
||||
}
|
||||
}
|
||||
|
||||
#if (defined(__ram_vector_table__))
|
||||
LR_m_interrupts_ram m_interrupts_ram_start m_interrupts_ram_size {
|
||||
VECTOR_RAM m_interrupts_ram_start EMPTY m_interrupts_ram_size {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
100
devices/MK22F51212/arm/MK22FN512xxx12_ram.scf
Normal file
100
devices/MK22F51212/arm/MK22FN512xxx12_ram.scf
Normal file
@@ -0,0 +1,100 @@
|
||||
#! armcc -E
|
||||
/*
|
||||
** ###################################################################
|
||||
** Processors: MK22FN512CAP12
|
||||
** MK22FN512VDC12
|
||||
** MK22FN512VFX12
|
||||
** MK22FN512VLH12
|
||||
** MK22FN512VLL12
|
||||
** MK22FN512VMP12
|
||||
**
|
||||
** Compiler: Keil ARM C/C++ Compiler
|
||||
** Reference manual: K22P121M120SF7RM, Rev. 1, March 24, 2014
|
||||
** Version: rev. 2.9, 2016-03-21
|
||||
** Build: b160321
|
||||
**
|
||||
** Abstract:
|
||||
** Linker file for the Keil ARM C/C++ Compiler
|
||||
**
|
||||
** Copyright (c) 2016 Freescale Semiconductor, Inc.
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without modification,
|
||||
** are permitted provided that the following conditions are met:
|
||||
**
|
||||
** o Redistributions of source code must retain the above copyright notice, this list
|
||||
** of conditions and the following disclaimer.
|
||||
**
|
||||
** o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
** list of conditions and the following disclaimer in the documentation and/or
|
||||
** other materials provided with the distribution.
|
||||
**
|
||||
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
** contributors may be used to endorse or promote products derived from this
|
||||
** software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**
|
||||
** http: www.freescale.com
|
||||
** mail: support@freescale.com
|
||||
**
|
||||
** ###################################################################
|
||||
*/
|
||||
|
||||
#define m_interrupts_start 0x1FFF0000
|
||||
#define m_interrupts_size 0x00000400
|
||||
|
||||
#define m_text_start 0x1FFF0400
|
||||
#define m_text_size 0x0000FC00
|
||||
|
||||
#define m_data_start 0x20000000
|
||||
#define m_data_size 0x00010000
|
||||
|
||||
/* Sizes */
|
||||
#if (defined(__stack_size__))
|
||||
#define Stack_Size __stack_size__
|
||||
#else
|
||||
#define Stack_Size 0x0400
|
||||
#endif
|
||||
|
||||
#if (defined(__heap_size__))
|
||||
#define Heap_Size __heap_size__
|
||||
#else
|
||||
#define Heap_Size 0x0400
|
||||
#endif
|
||||
|
||||
LR_m_text m_text_start m_text_size { ; load region size_region
|
||||
ER_m_text m_text_start m_text_size { ; load address = execution address
|
||||
* (InRoot$$Sections)
|
||||
.ANY (+RO)
|
||||
}
|
||||
RW_m_data m_data_start m_data_size-Stack_Size-Heap_Size { ; RW data
|
||||
.ANY (+RW +ZI)
|
||||
}
|
||||
ARM_LIB_HEAP +0 EMPTY Heap_Size { ; Heap region growing up
|
||||
}
|
||||
ARM_LIB_STACK m_data_start+m_data_size EMPTY -Stack_Size { ; Stack region growing down
|
||||
}
|
||||
}
|
||||
|
||||
LR_m_interrupts m_interrupts_start m_interrupts_size {
|
||||
VECTOR_ROM m_interrupts_start m_interrupts_size { ; load address = execution address
|
||||
* (RESET,+FIRST)
|
||||
}
|
||||
}
|
||||
|
||||
LR_m_interrupts_ram m_interrupts_start m_interrupts_size {
|
||||
VECTOR_RAM m_interrupts_start m_interrupts_size { ; load address = execution address
|
||||
.ANY (.m_interrupts_ram)
|
||||
}
|
||||
}
|
||||
|
||||
907
devices/MK22F51212/arm/startup_MK22F51212.s
Normal file
907
devices/MK22F51212/arm/startup_MK22F51212.s
Normal file
File diff suppressed because it is too large
Load Diff
363
devices/MK22F51212/drivers/fsl_adc16.c
Normal file
363
devices/MK22F51212/drivers/fsl_adc16.c
Normal file
@@ -0,0 +1,363 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_adc16.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
/*!
|
||||
* @brief Get instance number for ADC16 module.
|
||||
*
|
||||
* @param base ADC16 peripheral base address
|
||||
*/
|
||||
static uint32_t ADC16_GetInstance(ADC_Type *base);
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
/*! @brief Pointers to ADC16 bases for each instance. */
|
||||
static ADC_Type *const s_adc16Bases[] = ADC_BASE_PTRS;
|
||||
|
||||
/*! @brief Pointers to ADC16 clocks for each instance. */
|
||||
const clock_ip_name_t s_adc16Clocks[] = ADC16_CLOCKS;
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
static uint32_t ADC16_GetInstance(ADC_Type *base)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
/* Find the instance index from base address mappings. */
|
||||
for (instance = 0; instance < FSL_FEATURE_SOC_ADC16_COUNT; instance++)
|
||||
{
|
||||
if (s_adc16Bases[instance] == base)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(instance < FSL_FEATURE_SOC_ADC16_COUNT);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ADC16_Init(ADC_Type *base, const adc16_config_t *config)
|
||||
{
|
||||
assert(NULL != config);
|
||||
|
||||
uint32_t tmp32;
|
||||
|
||||
/* Enable the clock. */
|
||||
CLOCK_EnableClock(s_adc16Clocks[ADC16_GetInstance(base)]);
|
||||
|
||||
/* ADCx_CFG1. */
|
||||
tmp32 = ADC_CFG1_ADICLK(config->clockSource) | ADC_CFG1_MODE(config->resolution);
|
||||
if (kADC16_LongSampleDisabled != config->longSampleMode)
|
||||
{
|
||||
tmp32 |= ADC_CFG1_ADLSMP_MASK;
|
||||
}
|
||||
tmp32 |= ADC_CFG1_ADIV(config->clockDivider);
|
||||
if (config->enableLowPower)
|
||||
{
|
||||
tmp32 |= ADC_CFG1_ADLPC_MASK;
|
||||
}
|
||||
base->CFG1 = tmp32;
|
||||
|
||||
/* ADCx_CFG2. */
|
||||
tmp32 = base->CFG2 & ~(ADC_CFG2_ADACKEN_MASK | ADC_CFG2_ADHSC_MASK | ADC_CFG2_ADLSTS_MASK);
|
||||
if (kADC16_LongSampleDisabled != config->longSampleMode)
|
||||
{
|
||||
tmp32 |= ADC_CFG2_ADLSTS(config->longSampleMode);
|
||||
}
|
||||
if (config->enableHighSpeed)
|
||||
{
|
||||
tmp32 |= ADC_CFG2_ADHSC_MASK;
|
||||
}
|
||||
if (config->enableAsynchronousClock)
|
||||
{
|
||||
tmp32 |= ADC_CFG2_ADACKEN_MASK;
|
||||
}
|
||||
base->CFG2 = tmp32;
|
||||
|
||||
/* ADCx_SC2. */
|
||||
tmp32 = base->SC2 & ~(ADC_SC2_REFSEL_MASK);
|
||||
tmp32 |= ADC_SC2_REFSEL(config->referenceVoltageSource);
|
||||
base->SC2 = tmp32;
|
||||
|
||||
/* ADCx_SC3. */
|
||||
if (config->enableContinuousConversion)
|
||||
{
|
||||
base->SC3 |= ADC_SC3_ADCO_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->SC3 &= ~ADC_SC3_ADCO_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
void ADC16_Deinit(ADC_Type *base)
|
||||
{
|
||||
/* Disable the clock. */
|
||||
CLOCK_DisableClock(s_adc16Clocks[ADC16_GetInstance(base)]);
|
||||
}
|
||||
|
||||
void ADC16_GetDefaultConfig(adc16_config_t *config)
|
||||
{
|
||||
assert(NULL != config);
|
||||
|
||||
config->referenceVoltageSource = kADC16_ReferenceVoltageSourceVref;
|
||||
config->clockSource = kADC16_ClockSourceAsynchronousClock;
|
||||
config->enableAsynchronousClock = true;
|
||||
config->clockDivider = kADC16_ClockDivider8;
|
||||
config->resolution = kADC16_ResolutionSE12Bit;
|
||||
config->longSampleMode = kADC16_LongSampleDisabled;
|
||||
config->enableHighSpeed = false;
|
||||
config->enableLowPower = false;
|
||||
config->enableContinuousConversion = false;
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && FSL_FEATURE_ADC16_HAS_CALIBRATION
|
||||
status_t ADC16_DoAutoCalibration(ADC_Type *base)
|
||||
{
|
||||
bool bHWTrigger = false;
|
||||
uint32_t tmp32;
|
||||
status_t status = kStatus_Success;
|
||||
|
||||
/* The calibration would be failed when in hardwar mode.
|
||||
* Remember the hardware trigger state here and restore it later if the hardware trigger is enabled.*/
|
||||
if (0U != (ADC_SC2_ADTRG_MASK & base->SC2))
|
||||
{
|
||||
bHWTrigger = true;
|
||||
base->SC2 &= ~ADC_SC2_ADTRG_MASK;
|
||||
}
|
||||
|
||||
/* Clear the CALF and launch the calibration. */
|
||||
base->SC3 |= ADC_SC3_CAL_MASK | ADC_SC3_CALF_MASK;
|
||||
while (0U == (kADC16_ChannelConversionDoneFlag & ADC16_GetChannelStatusFlags(base, 0U)))
|
||||
{
|
||||
/* Check the CALF when the calibration is active. */
|
||||
if (0U != (kADC16_CalibrationFailedFlag & ADC16_GetStatusFlags(base)))
|
||||
{
|
||||
status = kStatus_Fail;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Restore the hardware trigger setting if it was enabled before. */
|
||||
if (bHWTrigger)
|
||||
{
|
||||
base->SC2 |= ADC_SC2_ADTRG_MASK;
|
||||
}
|
||||
/* Check the CALF at the end of calibration. */
|
||||
if (0U != (kADC16_CalibrationFailedFlag & ADC16_GetStatusFlags(base)))
|
||||
{
|
||||
status = kStatus_Fail;
|
||||
}
|
||||
if (kStatus_Success != status) /* Check if the calibration process is succeed. */
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Calculate the calibration values. */
|
||||
tmp32 = base->CLP0 + base->CLP1 + base->CLP2 + base->CLP3 + base->CLP4 + base->CLPS;
|
||||
tmp32 = 0x8000U | (tmp32 >> 1U);
|
||||
base->PG = tmp32;
|
||||
|
||||
#if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE
|
||||
tmp32 = base->CLM0 + base->CLM1 + base->CLM2 + base->CLM3 + base->CLM4 + base->CLMS;
|
||||
tmp32 = 0x8000U | (tmp32 >> 1U);
|
||||
base->MG = tmp32;
|
||||
#endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
#endif /* FSL_FEATURE_ADC16_HAS_CALIBRATION */
|
||||
|
||||
#if defined(FSL_FEATURE_ADC16_HAS_MUX_SELECT) && FSL_FEATURE_ADC16_HAS_MUX_SELECT
|
||||
void ADC16_SetChannelMuxMode(ADC_Type *base, adc16_channel_mux_mode_t mode)
|
||||
{
|
||||
if (kADC16_ChannelMuxA == mode)
|
||||
{
|
||||
base->CFG2 &= ~ADC_CFG2_MUXSEL_MASK;
|
||||
}
|
||||
else /* kADC16_ChannelMuxB. */
|
||||
{
|
||||
base->CFG2 |= ADC_CFG2_MUXSEL_MASK;
|
||||
}
|
||||
}
|
||||
#endif /* FSL_FEATURE_ADC16_HAS_MUX_SELECT */
|
||||
|
||||
void ADC16_SetHardwareCompareConfig(ADC_Type *base, const adc16_hardware_compare_config_t *config)
|
||||
{
|
||||
uint32_t tmp32 = base->SC2 & ~(ADC_SC2_ACFE_MASK | ADC_SC2_ACFGT_MASK | ADC_SC2_ACREN_MASK);
|
||||
|
||||
if (!config) /* Pass "NULL" to disable the feature. */
|
||||
{
|
||||
base->SC2 = tmp32;
|
||||
return;
|
||||
}
|
||||
/* Enable the feature. */
|
||||
tmp32 |= ADC_SC2_ACFE_MASK;
|
||||
|
||||
/* Select the hardware compare working mode. */
|
||||
switch (config->hardwareCompareMode)
|
||||
{
|
||||
case kADC16_HardwareCompareMode0:
|
||||
break;
|
||||
case kADC16_HardwareCompareMode1:
|
||||
tmp32 |= ADC_SC2_ACFGT_MASK;
|
||||
break;
|
||||
case kADC16_HardwareCompareMode2:
|
||||
tmp32 |= ADC_SC2_ACREN_MASK;
|
||||
break;
|
||||
case kADC16_HardwareCompareMode3:
|
||||
tmp32 |= ADC_SC2_ACFGT_MASK | ADC_SC2_ACREN_MASK;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
base->SC2 = tmp32;
|
||||
|
||||
/* Load the compare values. */
|
||||
base->CV1 = ADC_CV1_CV(config->value1);
|
||||
base->CV2 = ADC_CV2_CV(config->value2);
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_ADC16_HAS_HW_AVERAGE) && FSL_FEATURE_ADC16_HAS_HW_AVERAGE
|
||||
void ADC16_SetHardwareAverage(ADC_Type *base, adc16_hardware_average_mode_t mode)
|
||||
{
|
||||
uint32_t tmp32 = base->SC3 & ~(ADC_SC3_AVGE_MASK | ADC_SC3_AVGS_MASK);
|
||||
|
||||
if (kADC16_HardwareAverageDisabled != mode)
|
||||
{
|
||||
tmp32 |= ADC_SC3_AVGE_MASK | ADC_SC3_AVGS(mode);
|
||||
}
|
||||
base->SC3 = tmp32;
|
||||
}
|
||||
#endif /* FSL_FEATURE_ADC16_HAS_HW_AVERAGE */
|
||||
|
||||
#if defined(FSL_FEATURE_ADC16_HAS_PGA) && FSL_FEATURE_ADC16_HAS_PGA
|
||||
void ADC16_SetPGAConfig(ADC_Type *base, const adc16_pga_config_t *config)
|
||||
{
|
||||
uint32_t tmp32;
|
||||
|
||||
if (!config) /* Passing "NULL" is to disable the feature. */
|
||||
{
|
||||
base->PGA = 0U;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Enable the PGA and set the gain value. */
|
||||
tmp32 = ADC_PGA_PGAEN_MASK | ADC_PGA_PGAG(config->pgaGain);
|
||||
|
||||
/* Configure the misc features for PGA. */
|
||||
if (config->enableRunInNormalMode)
|
||||
{
|
||||
tmp32 |= ADC_PGA_PGALPb_MASK;
|
||||
}
|
||||
#if defined(FSL_FEATURE_ADC16_HAS_PGA_CHOPPING) && FSL_FEATURE_ADC16_HAS_PGA_CHOPPING
|
||||
if (config->disablePgaChopping)
|
||||
{
|
||||
tmp32 |= ADC_PGA_PGACHPb_MASK;
|
||||
}
|
||||
#endif /* FSL_FEATURE_ADC16_HAS_PGA_CHOPPING */
|
||||
#if defined(FSL_FEATURE_ADC16_HAS_PGA_OFFSET_MEASUREMENT) && FSL_FEATURE_ADC16_HAS_PGA_OFFSET_MEASUREMENT
|
||||
if (config->enableRunInOffsetMeasurement)
|
||||
{
|
||||
tmp32 |= ADC_PGA_PGAOFSM_MASK;
|
||||
}
|
||||
#endif /* FSL_FEATURE_ADC16_HAS_PGA_OFFSET_MEASUREMENT */
|
||||
base->PGA = tmp32;
|
||||
}
|
||||
#endif /* FSL_FEATURE_ADC16_HAS_PGA */
|
||||
|
||||
uint32_t ADC16_GetStatusFlags(ADC_Type *base)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
|
||||
if (0U != (base->SC2 & ADC_SC2_ADACT_MASK))
|
||||
{
|
||||
ret |= kADC16_ActiveFlag;
|
||||
}
|
||||
#if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && FSL_FEATURE_ADC16_HAS_CALIBRATION
|
||||
if (0U != (base->SC3 & ADC_SC3_CALF_MASK))
|
||||
{
|
||||
ret |= kADC16_CalibrationFailedFlag;
|
||||
}
|
||||
#endif /* FSL_FEATURE_ADC16_HAS_CALIBRATION */
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ADC16_ClearStatusFlags(ADC_Type *base, uint32_t mask)
|
||||
{
|
||||
#if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && FSL_FEATURE_ADC16_HAS_CALIBRATION
|
||||
if (0U != (mask & kADC16_CalibrationFailedFlag))
|
||||
{
|
||||
base->SC3 |= ADC_SC3_CALF_MASK;
|
||||
}
|
||||
#endif /* FSL_FEATURE_ADC16_HAS_CALIBRATION */
|
||||
}
|
||||
|
||||
void ADC16_SetChannelConfig(ADC_Type *base, uint32_t channelGroup, const adc16_channel_config_t *config)
|
||||
{
|
||||
assert(channelGroup < ADC_SC1_COUNT);
|
||||
assert(NULL != config);
|
||||
|
||||
uint32_t sc1 = ADC_SC1_ADCH(config->channelNumber); /* Set the channel number. */
|
||||
|
||||
#if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE
|
||||
/* Enable the differential conversion. */
|
||||
if (config->enableDifferentialConversion)
|
||||
{
|
||||
sc1 |= ADC_SC1_DIFF_MASK;
|
||||
}
|
||||
#endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */
|
||||
/* Enable the interrupt when the conversion is done. */
|
||||
if (config->enableInterruptOnConversionCompleted)
|
||||
{
|
||||
sc1 |= ADC_SC1_AIEN_MASK;
|
||||
}
|
||||
base->SC1[channelGroup] = sc1;
|
||||
}
|
||||
|
||||
uint32_t ADC16_GetChannelStatusFlags(ADC_Type *base, uint32_t channelGroup)
|
||||
{
|
||||
assert(channelGroup < ADC_SC1_COUNT);
|
||||
|
||||
uint32_t ret = 0U;
|
||||
|
||||
if (0U != (base->SC1[channelGroup] & ADC_SC1_COCO_MASK))
|
||||
{
|
||||
ret |= kADC16_ChannelConversionDoneFlag;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
527
devices/MK22F51212/drivers/fsl_adc16.h
Normal file
527
devices/MK22F51212/drivers/fsl_adc16.h
Normal file
File diff suppressed because it is too large
Load Diff
1782
devices/MK22F51212/drivers/fsl_clock.c
Normal file
1782
devices/MK22F51212/drivers/fsl_clock.c
Normal file
File diff suppressed because it is too large
Load Diff
1453
devices/MK22F51212/drivers/fsl_clock.h
Normal file
1453
devices/MK22F51212/drivers/fsl_clock.h
Normal file
File diff suppressed because it is too large
Load Diff
279
devices/MK22F51212/drivers/fsl_cmp.c
Normal file
279
devices/MK22F51212/drivers/fsl_cmp.c
Normal file
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_cmp.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
/*!
|
||||
* @brief Get instance number for CMP module.
|
||||
*
|
||||
* @param base CMP peripheral base address
|
||||
*/
|
||||
static uint32_t CMP_GetInstance(CMP_Type *base);
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
/*! @brief Pointers to CMP bases for each instance. */
|
||||
static CMP_Type *const s_cmpBases[] = CMP_BASE_PTRS;
|
||||
/*! @brief Pointers to CMP clocks for each instance. */
|
||||
const clock_ip_name_t s_cmpClocks[] = CMP_CLOCKS;
|
||||
|
||||
/*******************************************************************************
|
||||
* Codes
|
||||
******************************************************************************/
|
||||
static uint32_t CMP_GetInstance(CMP_Type *base)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
/* Find the instance index from base address mappings. */
|
||||
for (instance = 0; instance < FSL_FEATURE_SOC_CMP_COUNT; instance++)
|
||||
{
|
||||
if (s_cmpBases[instance] == base)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(instance < FSL_FEATURE_SOC_CMP_COUNT);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void CMP_Init(CMP_Type *base, const cmp_config_t *config)
|
||||
{
|
||||
assert(NULL != config);
|
||||
|
||||
uint8_t tmp8;
|
||||
|
||||
/* Enable the clock. */
|
||||
CLOCK_EnableClock(s_cmpClocks[CMP_GetInstance(base)]);
|
||||
|
||||
/* Configure. */
|
||||
CMP_Enable(base, false); /* Disable the CMP module during configuring. */
|
||||
/* CMPx_CR1. */
|
||||
tmp8 = base->CR1 & ~(CMP_CR1_PMODE_MASK | CMP_CR1_INV_MASK | CMP_CR1_COS_MASK | CMP_CR1_OPE_MASK);
|
||||
if (config->enableHighSpeed)
|
||||
{
|
||||
tmp8 |= CMP_CR1_PMODE_MASK;
|
||||
}
|
||||
if (config->enableInvertOutput)
|
||||
{
|
||||
tmp8 |= CMP_CR1_INV_MASK;
|
||||
}
|
||||
if (config->useUnfilteredOutput)
|
||||
{
|
||||
tmp8 |= CMP_CR1_COS_MASK;
|
||||
}
|
||||
if (config->enablePinOut)
|
||||
{
|
||||
tmp8 |= CMP_CR1_OPE_MASK;
|
||||
}
|
||||
#if defined(FSL_FEATURE_CMP_HAS_TRIGGER_MODE) && FSL_FEATURE_CMP_HAS_TRIGGER_MODE
|
||||
if (config->enableTriggerMode)
|
||||
{
|
||||
tmp8 |= CMP_CR1_TRIGM_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp8 &= ~CMP_CR1_TRIGM_MASK;
|
||||
}
|
||||
#endif /* FSL_FEATURE_CMP_HAS_TRIGGER_MODE */
|
||||
base->CR1 = tmp8;
|
||||
|
||||
/* CMPx_CR0. */
|
||||
tmp8 = base->CR0 & ~CMP_CR0_HYSTCTR_MASK;
|
||||
tmp8 |= CMP_CR0_HYSTCTR(config->hysteresisMode);
|
||||
base->CR0 = tmp8;
|
||||
|
||||
CMP_Enable(base, config->enableCmp); /* Enable the CMP module after configured or not. */
|
||||
}
|
||||
|
||||
void CMP_Deinit(CMP_Type *base)
|
||||
{
|
||||
/* Disable the CMP module. */
|
||||
CMP_Enable(base, false);
|
||||
|
||||
/* Disable the clock. */
|
||||
CLOCK_DisableClock(s_cmpClocks[CMP_GetInstance(base)]);
|
||||
}
|
||||
|
||||
void CMP_GetDefaultConfig(cmp_config_t *config)
|
||||
{
|
||||
assert(NULL != config);
|
||||
|
||||
config->enableCmp = true; /* Enable the CMP module after initialization. */
|
||||
config->hysteresisMode = kCMP_HysteresisLevel0;
|
||||
config->enableHighSpeed = false;
|
||||
config->enableInvertOutput = false;
|
||||
config->useUnfilteredOutput = false;
|
||||
config->enablePinOut = false;
|
||||
#if defined(FSL_FEATURE_CMP_HAS_TRIGGER_MODE) && FSL_FEATURE_CMP_HAS_TRIGGER_MODE
|
||||
config->enableTriggerMode = false;
|
||||
#endif /* FSL_FEATURE_CMP_HAS_TRIGGER_MODE */
|
||||
}
|
||||
|
||||
void CMP_SetInputChannels(CMP_Type *base, uint8_t positiveChannel, uint8_t negativeChannel)
|
||||
{
|
||||
uint8_t tmp8 = base->MUXCR;
|
||||
|
||||
tmp8 &= ~(CMP_MUXCR_PSEL_MASK | CMP_MUXCR_MSEL_MASK);
|
||||
tmp8 |= CMP_MUXCR_PSEL(positiveChannel) | CMP_MUXCR_MSEL(negativeChannel);
|
||||
base->MUXCR = tmp8;
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_CMP_HAS_DMA) && FSL_FEATURE_CMP_HAS_DMA
|
||||
void CMP_EnableDMA(CMP_Type *base, bool enable)
|
||||
{
|
||||
uint8_t tmp8 = base->SCR & ~(CMP_SCR_CFR_MASK | CMP_SCR_CFF_MASK); /* To avoid change the w1c bits. */
|
||||
|
||||
if (enable)
|
||||
{
|
||||
tmp8 |= CMP_SCR_DMAEN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp8 &= ~CMP_SCR_DMAEN_MASK;
|
||||
}
|
||||
base->SCR = tmp8;
|
||||
}
|
||||
#endif /* FSL_FEATURE_CMP_HAS_DMA */
|
||||
|
||||
void CMP_SetFilterConfig(CMP_Type *base, const cmp_filter_config_t *config)
|
||||
{
|
||||
assert(NULL != config);
|
||||
|
||||
uint8_t tmp8;
|
||||
|
||||
#if defined(FSL_FEATURE_CMP_HAS_EXTERNAL_SAMPLE_SUPPORT) && FSL_FEATURE_CMP_HAS_EXTERNAL_SAMPLE_SUPPORT
|
||||
/* Choose the clock source for sampling. */
|
||||
if (config->enableSample)
|
||||
{
|
||||
base->CR1 |= CMP_CR1_SE_MASK; /* Choose the external SAMPLE clock. */
|
||||
}
|
||||
else
|
||||
{
|
||||
base->CR1 &= ~CMP_CR1_SE_MASK; /* Choose the internal divided bus clock. */
|
||||
}
|
||||
#endif /* FSL_FEATURE_CMP_HAS_EXTERNAL_SAMPLE_SUPPORT */
|
||||
/* Set the filter count. */
|
||||
tmp8 = base->CR0 & ~CMP_CR0_FILTER_CNT_MASK;
|
||||
tmp8 |= CMP_CR0_FILTER_CNT(config->filterCount);
|
||||
base->CR0 = tmp8;
|
||||
/* Set the filter period. It is used as the divider to bus clock. */
|
||||
base->FPR = CMP_FPR_FILT_PER(config->filterPeriod);
|
||||
}
|
||||
|
||||
void CMP_SetDACConfig(CMP_Type *base, const cmp_dac_config_t *config)
|
||||
{
|
||||
uint8_t tmp8 = 0U;
|
||||
|
||||
if (NULL == config)
|
||||
{
|
||||
/* Passing "NULL" as input parameter means no available configuration. So the DAC feature is disabled.*/
|
||||
base->DACCR = 0U;
|
||||
return;
|
||||
}
|
||||
/* CMPx_DACCR. */
|
||||
tmp8 |= CMP_DACCR_DACEN_MASK; /* Enable the internal DAC. */
|
||||
if (kCMP_VrefSourceVin2 == config->referenceVoltageSource)
|
||||
{
|
||||
tmp8 |= CMP_DACCR_VRSEL_MASK;
|
||||
}
|
||||
tmp8 |= CMP_DACCR_VOSEL(config->DACValue);
|
||||
|
||||
base->DACCR = tmp8;
|
||||
}
|
||||
|
||||
void CMP_EnableInterrupts(CMP_Type *base, uint32_t mask)
|
||||
{
|
||||
uint8_t tmp8 = base->SCR & ~(CMP_SCR_CFR_MASK | CMP_SCR_CFF_MASK); /* To avoid change the w1c bits. */
|
||||
|
||||
if (0U != (kCMP_OutputRisingInterruptEnable & mask))
|
||||
{
|
||||
tmp8 |= CMP_SCR_IER_MASK;
|
||||
}
|
||||
if (0U != (kCMP_OutputFallingInterruptEnable & mask))
|
||||
{
|
||||
tmp8 |= CMP_SCR_IEF_MASK;
|
||||
}
|
||||
base->SCR = tmp8;
|
||||
}
|
||||
|
||||
void CMP_DisableInterrupts(CMP_Type *base, uint32_t mask)
|
||||
{
|
||||
uint8_t tmp8 = base->SCR & ~(CMP_SCR_CFR_MASK | CMP_SCR_CFF_MASK); /* To avoid change the w1c bits. */
|
||||
|
||||
if (0U != (kCMP_OutputRisingInterruptEnable & mask))
|
||||
{
|
||||
tmp8 &= ~CMP_SCR_IER_MASK;
|
||||
}
|
||||
if (0U != (kCMP_OutputFallingInterruptEnable & mask))
|
||||
{
|
||||
tmp8 &= ~CMP_SCR_IEF_MASK;
|
||||
}
|
||||
base->SCR = tmp8;
|
||||
}
|
||||
|
||||
uint32_t CMP_GetStatusFlags(CMP_Type *base)
|
||||
{
|
||||
uint32_t ret32 = 0U;
|
||||
|
||||
if (0U != (CMP_SCR_CFR_MASK & base->SCR))
|
||||
{
|
||||
ret32 |= kCMP_OutputRisingEventFlag;
|
||||
}
|
||||
if (0U != (CMP_SCR_CFF_MASK & base->SCR))
|
||||
{
|
||||
ret32 |= kCMP_OutputFallingEventFlag;
|
||||
}
|
||||
if (0U != (CMP_SCR_COUT_MASK & base->SCR))
|
||||
{
|
||||
ret32 |= kCMP_OutputAssertEventFlag;
|
||||
}
|
||||
return ret32;
|
||||
}
|
||||
|
||||
void CMP_ClearStatusFlags(CMP_Type *base, uint32_t mask)
|
||||
{
|
||||
uint8_t tmp8 = base->SCR & ~(CMP_SCR_CFR_MASK | CMP_SCR_CFF_MASK); /* To avoid change the w1c bits. */
|
||||
|
||||
if (0U != (kCMP_OutputRisingEventFlag & mask))
|
||||
{
|
||||
tmp8 |= CMP_SCR_CFR_MASK;
|
||||
}
|
||||
if (0U != (kCMP_OutputFallingEventFlag & mask))
|
||||
{
|
||||
tmp8 |= CMP_SCR_CFF_MASK;
|
||||
}
|
||||
base->SCR = tmp8;
|
||||
}
|
||||
346
devices/MK22F51212/drivers/fsl_cmp.h
Normal file
346
devices/MK22F51212/drivers/fsl_cmp.h
Normal file
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FSL_CMP_H_
|
||||
#define _FSL_CMP_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup cmp
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief CMP driver version 2.0.0. */
|
||||
#define FSL_CMP_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
|
||||
/*@}*/
|
||||
|
||||
/*!
|
||||
* @brief Interrupt enable/disable mask.
|
||||
*/
|
||||
enum _cmp_interrupt_enable
|
||||
{
|
||||
kCMP_OutputRisingInterruptEnable = CMP_SCR_IER_MASK, /*!< Comparator interrupt enable rising. */
|
||||
kCMP_OutputFallingInterruptEnable = CMP_SCR_IEF_MASK, /*!< Comparator interrupt enable falling. */
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Status flags' mask.
|
||||
*/
|
||||
enum _cmp_status_flags
|
||||
{
|
||||
kCMP_OutputRisingEventFlag = CMP_SCR_CFR_MASK, /*!< Rising-edge on compare output has occurred. */
|
||||
kCMP_OutputFallingEventFlag = CMP_SCR_CFF_MASK, /*!< Falling-edge on compare output has occurred. */
|
||||
kCMP_OutputAssertEventFlag = CMP_SCR_COUT_MASK, /*!< Return the current value of the analog comparator output. */
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief CMP Hysteresis mode.
|
||||
*/
|
||||
typedef enum _cmp_hysteresis_mode
|
||||
{
|
||||
kCMP_HysteresisLevel0 = 0U, /*!< Hysteresis level 0. */
|
||||
kCMP_HysteresisLevel1 = 1U, /*!< Hysteresis level 1. */
|
||||
kCMP_HysteresisLevel2 = 2U, /*!< Hysteresis level 2. */
|
||||
kCMP_HysteresisLevel3 = 3U, /*!< Hysteresis level 3. */
|
||||
} cmp_hysteresis_mode_t;
|
||||
|
||||
/*!
|
||||
* @brief CMP Voltage Reference source.
|
||||
*/
|
||||
typedef enum _cmp_reference_voltage_source
|
||||
{
|
||||
kCMP_VrefSourceVin1 = 0U, /*!< Vin1 is selected as resistor ladder network supply reference Vin. */
|
||||
kCMP_VrefSourceVin2 = 1U, /*!< Vin2 is selected as resistor ladder network supply reference Vin. */
|
||||
} cmp_reference_voltage_source_t;
|
||||
|
||||
/*!
|
||||
* @brief Configure the comparator.
|
||||
*/
|
||||
typedef struct _cmp_config
|
||||
{
|
||||
bool enableCmp; /*!< Enable the CMP module. */
|
||||
cmp_hysteresis_mode_t hysteresisMode; /*!< CMP Hysteresis mode. */
|
||||
bool enableHighSpeed; /*!< Enable High Speed (HS) comparison mode. */
|
||||
bool enableInvertOutput; /*!< Enable inverted comparator output. */
|
||||
bool useUnfilteredOutput; /*!< Set compare output(COUT) to equal COUTA(true) or COUT(false). */
|
||||
bool enablePinOut; /*!< The comparator output is available on the associated pin. */
|
||||
#if defined(FSL_FEATURE_CMP_HAS_TRIGGER_MODE) && FSL_FEATURE_CMP_HAS_TRIGGER_MODE
|
||||
bool enableTriggerMode; /*!< Enable the trigger mode. */
|
||||
#endif /* FSL_FEATURE_CMP_HAS_TRIGGER_MODE */
|
||||
} cmp_config_t;
|
||||
|
||||
/*!
|
||||
* @brief Configure the filter.
|
||||
*/
|
||||
typedef struct _cmp_filter_config
|
||||
{
|
||||
#if defined(FSL_FEATURE_CMP_HAS_EXTERNAL_SAMPLE_SUPPORT) && FSL_FEATURE_CMP_HAS_EXTERNAL_SAMPLE_SUPPORT
|
||||
bool enableSample; /*!< Using external SAMPLE as sampling clock input, or using divided bus clock. */
|
||||
#endif /* FSL_FEATURE_CMP_HAS_EXTERNAL_SAMPLE_SUPPORT */
|
||||
uint8_t filterCount; /*!< Filter Sample Count. Available range is 1-7, 0 would cause the filter disabled.*/
|
||||
uint8_t filterPeriod; /*!< Filter Sample Period. The divider to bus clock. Available range is 0-255. */
|
||||
} cmp_filter_config_t;
|
||||
|
||||
/*!
|
||||
* @brief Configure the internal DAC.
|
||||
*/
|
||||
typedef struct _cmp_dac_config
|
||||
{
|
||||
cmp_reference_voltage_source_t referenceVoltageSource; /*!< Supply voltage reference source. */
|
||||
uint8_t DACValue; /*!< Value for DAC Output Voltage. Available range is 0-63.*/
|
||||
} cmp_dac_config_t;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @name Initialization
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes the CMP.
|
||||
*
|
||||
* This function initializes the CMP module. The operations included are:
|
||||
* - Enabling the clock for CMP module.
|
||||
* - Configuring the comparator.
|
||||
* - Enabling the CMP module.
|
||||
* Note: For some devices, multiple CMP instance share the same clock gate. In this case, to enable the clock for
|
||||
* any instance enables all the CMPs. Check the chip reference manual for the clock assignment of the CMP.
|
||||
*
|
||||
* @param base CMP peripheral base address.
|
||||
* @param config Pointer to configuration structure.
|
||||
*/
|
||||
void CMP_Init(CMP_Type *base, const cmp_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief De-initializes the CMP module.
|
||||
*
|
||||
* This function de-initializes the CMP module. The operations included are:
|
||||
* - Disabling the CMP module.
|
||||
* - Disabling the clock for CMP module.
|
||||
*
|
||||
* This function disables the clock for the CMP.
|
||||
* Note: For some devices, multiple CMP instance shares the same clock gate. In this case, before disabling the
|
||||
* clock for the CMP, ensure that all the CMP instances are not used.
|
||||
*
|
||||
* @param base CMP peripheral base address.
|
||||
*/
|
||||
void CMP_Deinit(CMP_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Enables/disables the CMP module.
|
||||
*
|
||||
* @param base CMP peripheral base address.
|
||||
* @param enable Enable the module or not.
|
||||
*/
|
||||
static inline void CMP_Enable(CMP_Type *base, bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
base->CR1 |= CMP_CR1_EN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->CR1 &= ~CMP_CR1_EN_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Initializes the CMP user configuration structure.
|
||||
*
|
||||
* This function initializes the user configure structure to these default values:
|
||||
* @code
|
||||
* config->enableCmp = true;
|
||||
* config->hysteresisMode = kCMP_HysteresisLevel0;
|
||||
* config->enableHighSpeed = false;
|
||||
* config->enableInvertOutput = false;
|
||||
* config->useUnfilteredOutput = false;
|
||||
* config->enablePinOut = false;
|
||||
* config->enableTriggerMode = false;
|
||||
* @endcode
|
||||
* @param config Pointer to the configuration structure.
|
||||
*/
|
||||
void CMP_GetDefaultConfig(cmp_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Sets the input channels for the comparator.
|
||||
*
|
||||
* This function sets the input channels for the comparator.
|
||||
* Note that two input channels cannot be set as same in the application. When the user selects the same input
|
||||
* from the analog mux to the positive and negative port, the comparator is disabled automatically.
|
||||
*
|
||||
* @param base CMP peripheral base address.
|
||||
* @param positiveChannel Positive side input channel number. Available range is 0-7.
|
||||
* @param negativeChannel Negative side input channel number. Available range is 0-7.
|
||||
*/
|
||||
void CMP_SetInputChannels(CMP_Type *base, uint8_t positiveChannel, uint8_t negativeChannel);
|
||||
|
||||
/* @} */
|
||||
|
||||
/*!
|
||||
* @name Advanced Features
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(FSL_FEATURE_CMP_HAS_DMA) && FSL_FEATURE_CMP_HAS_DMA
|
||||
/*!
|
||||
* @brief Enables/disables the DMA request for rising/falling events.
|
||||
*
|
||||
* This function enables/disables the DMA request for rising/falling events. Either event triggers the generation of
|
||||
* the DMA
|
||||
* request from CMP if the DMA feature is enabled. Both events are ignored for generating the DMA request from the CMP
|
||||
* if the
|
||||
* DMA is disabled.
|
||||
*
|
||||
* @param base CMP peripheral base address.
|
||||
* @param enable Enable the feature or not.
|
||||
*/
|
||||
void CMP_EnableDMA(CMP_Type *base, bool enable);
|
||||
#endif /* FSL_FEATURE_CMP_HAS_DMA */
|
||||
|
||||
#if defined(FSL_FEATURE_CMP_HAS_WINDOW_MODE) && FSL_FEATURE_CMP_HAS_WINDOW_MODE
|
||||
/*!
|
||||
* @brief Enables/disables the window mode.
|
||||
*
|
||||
* @param base CMP peripheral base address.
|
||||
* @param enable Enable the feature or not.
|
||||
*/
|
||||
static inline void CMP_EnableWindowMode(CMP_Type *base, bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
base->CR1 |= CMP_CR1_WE_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->CR1 &= ~CMP_CR1_WE_MASK;
|
||||
}
|
||||
}
|
||||
#endif /* FSL_FEATURE_CMP_HAS_WINDOW_MODE */
|
||||
|
||||
#if defined(FSL_FEATURE_CMP_HAS_PASS_THROUGH_MODE) && FSL_FEATURE_CMP_HAS_PASS_THROUGH_MODE
|
||||
/*!
|
||||
* @brief Enables/disables the pass through mode.
|
||||
*
|
||||
* @param base CMP peripheral base address.
|
||||
* @param enable Enable the feature or not.
|
||||
*/
|
||||
static inline void CMP_EnablePassThroughMode(CMP_Type *base, bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
base->MUXCR |= CMP_MUXCR_PSTM_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->MUXCR &= ~CMP_MUXCR_PSTM_MASK;
|
||||
}
|
||||
}
|
||||
#endif /* FSL_FEATURE_CMP_HAS_PASS_THROUGH_MODE */
|
||||
|
||||
/*!
|
||||
* @brief Configures the filter.
|
||||
*
|
||||
* @param base CMP peripheral base address.
|
||||
* @param config Pointer to configuration structure.
|
||||
*/
|
||||
void CMP_SetFilterConfig(CMP_Type *base, const cmp_filter_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Configures the internal DAC.
|
||||
*
|
||||
* @param base CMP peripheral base address.
|
||||
* @param config Pointer to configuration structure. "NULL" is for disabling the feature.
|
||||
*/
|
||||
void CMP_SetDACConfig(CMP_Type *base, const cmp_dac_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Enables the interrupts.
|
||||
*
|
||||
* @param base CMP peripheral base address.
|
||||
* @param mask Mask value for interrupts. See "_cmp_interrupt_enable".
|
||||
*/
|
||||
void CMP_EnableInterrupts(CMP_Type *base, uint32_t mask);
|
||||
|
||||
/*!
|
||||
* @brief Disables the interrupts.
|
||||
*
|
||||
* @param base CMP peripheral base address.
|
||||
* @param mask Mask value for interrupts. See "_cmp_interrupt_enable".
|
||||
*/
|
||||
void CMP_DisableInterrupts(CMP_Type *base, uint32_t mask);
|
||||
|
||||
/* @} */
|
||||
|
||||
/*!
|
||||
* @name Results
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Gets the status flags.
|
||||
*
|
||||
* @param base CMP peripheral base address.
|
||||
*
|
||||
* @return Mask value for the asserted flags. See "_cmp_status_flags".
|
||||
*/
|
||||
uint32_t CMP_GetStatusFlags(CMP_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Clears the status flags.
|
||||
*
|
||||
* @param base CMP peripheral base address.
|
||||
* @param mask Mask value for the flags. See "_cmp_status_flags".
|
||||
*/
|
||||
void CMP_ClearStatusFlags(CMP_Type *base, uint32_t mask);
|
||||
|
||||
/* @} */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
#endif /* _FSL_CMP_H_ */
|
||||
95
devices/MK22F51212/drivers/fsl_common.c
Normal file
95
devices/MK22F51212/drivers/fsl_common.c
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_common.h"
|
||||
#include "fsl_debug_console.h"
|
||||
|
||||
#ifndef NDEBUG
|
||||
#if (defined(__CC_ARM)) || (defined(__ICCARM__))
|
||||
void __aeabi_assert(const char *failedExpr, const char *file, int line)
|
||||
{
|
||||
PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" \n", failedExpr, file, line);
|
||||
for (;;)
|
||||
{
|
||||
__asm("bkpt #0");
|
||||
}
|
||||
}
|
||||
#elif(defined(__GNUC__))
|
||||
void __assert_func(const char *file, int line, const char *func, const char *failedExpr)
|
||||
{
|
||||
PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" function name \"%s\" \n", failedExpr, file, line, func);
|
||||
for (;;)
|
||||
{
|
||||
__asm("bkpt #0");
|
||||
}
|
||||
}
|
||||
#endif /* (defined(__CC_ARM)) || (defined (__ICCARM__)) */
|
||||
#endif /* NDEBUG */
|
||||
|
||||
void InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler)
|
||||
{
|
||||
/* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */
|
||||
#if defined(__CC_ARM)
|
||||
extern uint32_t Image$$VECTOR_ROM$$Base[];
|
||||
extern uint32_t Image$$VECTOR_RAM$$Base[];
|
||||
extern uint32_t Image$$RW_m_data$$Base[];
|
||||
|
||||
#define __VECTOR_TABLE Image$$VECTOR_ROM$$Base
|
||||
#define __VECTOR_RAM Image$$VECTOR_RAM$$Base
|
||||
#define __RAM_VECTOR_TABLE_SIZE (((uint32_t)Image$$RW_m_data$$Base - (uint32_t)Image$$VECTOR_RAM$$Base))
|
||||
#elif defined(__ICCARM__)
|
||||
extern uint32_t __RAM_VECTOR_TABLE_SIZE[];
|
||||
extern uint32_t __VECTOR_TABLE[];
|
||||
extern uint32_t __VECTOR_RAM[];
|
||||
#elif defined(__GNUC__)
|
||||
extern uint32_t __VECTOR_TABLE[];
|
||||
extern uint32_t __VECTOR_RAM[];
|
||||
extern uint32_t __RAM_VECTOR_TABLE_SIZE_BYTES[];
|
||||
uint32_t __RAM_VECTOR_TABLE_SIZE = (uint32_t)(__RAM_VECTOR_TABLE_SIZE_BYTES);
|
||||
#endif /* defined(__CC_ARM) */
|
||||
uint32_t n;
|
||||
|
||||
__disable_irq();
|
||||
if (SCB->VTOR != (uint32_t)__VECTOR_RAM)
|
||||
{
|
||||
/* Copy the vector table from ROM to RAM */
|
||||
for (n = 0; n < ((uint32_t)__RAM_VECTOR_TABLE_SIZE) / sizeof(uint32_t); n++)
|
||||
{
|
||||
__VECTOR_RAM[n] = __VECTOR_TABLE[n];
|
||||
}
|
||||
/* Point the VTOR to the position of vector table */
|
||||
SCB->VTOR = (uint32_t)__VECTOR_RAM;
|
||||
}
|
||||
|
||||
/* make sure the __VECTOR_RAM is noncachable */
|
||||
__VECTOR_RAM[irq + 16] = irqHandler;
|
||||
|
||||
__enable_irq();
|
||||
}
|
||||
255
devices/MK22F51212/drivers/fsl_common.h
Normal file
255
devices/MK22F51212/drivers/fsl_common.h
Normal file
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FSL_COMMON_H_
|
||||
#define _FSL_COMMON_H_
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "fsl_device_registers.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup ksdk_common
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief Construct a status code value from a group and code number. */
|
||||
#define MAKE_STATUS(group, code) ((((group)*100) + (code)))
|
||||
|
||||
/*! @brief Construct the version number for drivers. */
|
||||
#define MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
|
||||
|
||||
/* Debug console type definition. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_NONE 0U /*!< No debug console. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_UART 1U /*!< Debug console base on UART. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_LPUART 2U /*!< Debug console base on LPUART. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_LPSCI 3U /*!< Debug console base on LPSCI. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_USBCDC 4U /*!< Debug console base on USBCDC. */
|
||||
|
||||
/*! @brief Status group numbers. */
|
||||
enum _status_groups
|
||||
{
|
||||
kStatusGroup_Generic = 0, /*!< Group number for generic status codes. */
|
||||
kStatusGroup_FLASH = 1, /*!< Group number for FLASH status codes. */
|
||||
kStatusGroup_LPSPI = 4, /*!< Group number for LPSPI status codes. */
|
||||
kStatusGroup_FLEXIO_SPI = 5, /*!< Group number for FLEXIO SPI status codes. */
|
||||
kStatusGroup_DSPI = 6, /*!< Group number for DSPI status codes. */
|
||||
kStatusGroup_FLEXIO_UART = 7, /*!< Group number for FLEXIO UART status codes. */
|
||||
kStatusGroup_FLEXIO_I2C = 8, /*!< Group number for FLEXIO I2C status codes. */
|
||||
kStatusGroup_LPI2C = 9, /*!< Group number for LPI2C status codes. */
|
||||
kStatusGroup_UART = 10, /*!< Group number for UART status codes. */
|
||||
kStatusGroup_I2C = 11, /*!< Group number for UART status codes. */
|
||||
kStatusGroup_LPSCI = 12, /*!< Group number for LPSCI status codes. */
|
||||
kStatusGroup_LPUART = 13, /*!< Group number for LPUART status codes. */
|
||||
kStatusGroup_SPI = 14, /*!< Group number for SPI status code.*/
|
||||
kStatusGroup_XRDC = 15, /*!< Group number for XRDC status code.*/
|
||||
kStatusGroup_SEMA42 = 16, /*!< Group number for SEMA42 status code.*/
|
||||
kStatusGroup_SDHC = 17, /*!< Group number for SDHC status code */
|
||||
kStatusGroup_SDMMC = 18, /*!< Group number for SDMMC status code */
|
||||
kStatusGroup_SAI = 19, /*!< Group number for SAI status code */
|
||||
kStatusGroup_MCG = 20, /*!< Group number for MCG status codes. */
|
||||
kStatusGroup_SCG = 21, /*!< Group number for SCG status codes. */
|
||||
kStatusGroup_SDSPI = 22, /*!< Group number for SDSPI status codes. */
|
||||
kStatusGroup_FLEXIO_I2S = 23, /*!< Group number for FLEXIO I2S status codes */
|
||||
kStatusGroup_SDRAMC = 35, /*!< Group number for SDRAMC status codes. */
|
||||
kStatusGroup_POWER = 39, /*!< Group number for POWER status codes. */
|
||||
kStatusGroup_ENET = 40, /*!< Group number for ENET status codes. */
|
||||
kStatusGroup_PHY = 41, /*!< Group number for PHY status codes. */
|
||||
kStatusGroup_TRGMUX = 42, /*!< Group number for TRGMUX status codes. */
|
||||
kStatusGroup_SMARTCARD = 43, /*!< Group number for SMARTCARD status codes. */
|
||||
kStatusGroup_LMEM = 44, /*!< Group number for LMEM status codes. */
|
||||
kStatusGroup_QSPI = 45, /*!< Group number for QSPI status codes. */
|
||||
kStatusGroup_DMA = 50, /*!< Group number for DMA status codes. */
|
||||
kStatusGroup_EDMA = 51, /*!< Group number for EDMA status codes. */
|
||||
kStatusGroup_DMAMGR = 52, /*!< Group number for DMAMGR status codes. */
|
||||
kStatusGroup_FLEXCAN = 53, /*!< Group number for FlexCAN status codes. */
|
||||
kStatusGroup_LTC = 54, /*!< Group number for LTC status codes. */
|
||||
kStatusGroup_FLEXIO_CAMERA = 55, /*!< Group number for FLEXIO CAMERA status codes. */
|
||||
kStatusGroup_NOTIFIER = 98, /*!< Group number for NOTIFIER status codes. */
|
||||
kStatusGroup_DebugConsole = 99, /*!< Group number for debug console status codes. */
|
||||
kStatusGroup_ApplicationRangeStart = 100, /*!< Starting number for application groups. */
|
||||
};
|
||||
|
||||
/*! @brief Generic status return codes. */
|
||||
enum _generic_status
|
||||
{
|
||||
kStatus_Success = MAKE_STATUS(kStatusGroup_Generic, 0),
|
||||
kStatus_Fail = MAKE_STATUS(kStatusGroup_Generic, 1),
|
||||
kStatus_ReadOnly = MAKE_STATUS(kStatusGroup_Generic, 2),
|
||||
kStatus_OutOfRange = MAKE_STATUS(kStatusGroup_Generic, 3),
|
||||
kStatus_InvalidArgument = MAKE_STATUS(kStatusGroup_Generic, 4),
|
||||
kStatus_Timeout = MAKE_STATUS(kStatusGroup_Generic, 5),
|
||||
kStatus_NoTransferInProgress = MAKE_STATUS(kStatusGroup_Generic, 6),
|
||||
};
|
||||
|
||||
/*! @brief Type used for all status and error return values. */
|
||||
typedef int32_t status_t;
|
||||
|
||||
/*
|
||||
* The fsl_clock.h is included here because it needs MAKE_VERSION/MAKE_STATUS/status_t
|
||||
* defined in previous of this file.
|
||||
*/
|
||||
#include "fsl_clock.h"
|
||||
|
||||
/*! @name Min/max macros */
|
||||
/* @{ */
|
||||
#if !defined(MIN)
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#if !defined(MAX)
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
/* @} */
|
||||
|
||||
/*! @brief Computes the number of elements in an array. */
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
/*! @name UINT16_MAX/UINT32_MAX value */
|
||||
/* @{ */
|
||||
#if !defined(UINT16_MAX)
|
||||
#define UINT16_MAX ((uint16_t)-1)
|
||||
#endif
|
||||
|
||||
#if !defined(UINT32_MAX)
|
||||
#define UINT32_MAX ((uint32_t)-1)
|
||||
#endif
|
||||
/* @} */
|
||||
|
||||
/*! @name Timer utilities */
|
||||
/* @{ */
|
||||
/*! Macro to convert a microsecond period to raw count value */
|
||||
#define USEC_TO_COUNT(us, clockFreqInHz) (uint64_t)((uint64_t)us * clockFreqInHz / 1000000U)
|
||||
/*! Macro to convert a raw count value to microsecond */
|
||||
#define COUNT_TO_USEC(count, clockFreqInHz) (uint64_t)((uint64_t)count * 1000000U / clockFreqInHz)
|
||||
|
||||
/*! Macro to convert a millisecond period to raw count value */
|
||||
#define MSEC_TO_COUNT(ms, clockFreqInHz) (uint64_t)((uint64_t)ms * clockFreqInHz / 1000U)
|
||||
/*! Macro to convert a raw count value to millisecond */
|
||||
#define COUNT_TO_MSEC(count, clockFreqInHz) (uint64_t)((uint64_t)count * 1000U / clockFreqInHz)
|
||||
/* @} */
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Enable specific interrupt.
|
||||
*
|
||||
* Enable the interrupt not routed from intmux.
|
||||
*
|
||||
* @param interrupt The IRQ number.
|
||||
*/
|
||||
static inline void EnableIRQ(IRQn_Type interrupt)
|
||||
{
|
||||
#if defined(FSL_FEATURE_SOC_INTMUX_COUNT) && (FSL_FEATURE_SOC_INTMUX_COUNT > 0)
|
||||
if (interrupt < FSL_FEATURE_INTMUX_IRQ_START_INDEX)
|
||||
#endif
|
||||
{
|
||||
NVIC_EnableIRQ(interrupt);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disable specific interrupt.
|
||||
*
|
||||
* Disable the interrupt not routed from intmux.
|
||||
*
|
||||
* @param interrupt The IRQ number.
|
||||
*/
|
||||
static inline void DisableIRQ(IRQn_Type interrupt)
|
||||
{
|
||||
#if defined(FSL_FEATURE_SOC_INTMUX_COUNT) && (FSL_FEATURE_SOC_INTMUX_COUNT > 0)
|
||||
if (interrupt < FSL_FEATURE_INTMUX_IRQ_START_INDEX)
|
||||
#endif
|
||||
{
|
||||
NVIC_DisableIRQ(interrupt);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disable the global IRQ
|
||||
*
|
||||
* Disable the global interrupt and return the current primask register. User is required to provided the primask
|
||||
* register for the EnableGlobalIRQ().
|
||||
*
|
||||
* @return Current primask value.
|
||||
*/
|
||||
static inline uint32_t DisableGlobalIRQ(void)
|
||||
{
|
||||
uint32_t regPrimask = __get_PRIMASK();
|
||||
|
||||
__disable_irq();
|
||||
|
||||
return regPrimask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Enaable the global IRQ
|
||||
*
|
||||
* Set the primask register with the provided primask value but not just enable the primask. The idea is for the
|
||||
* convinience of integration of RTOS. some RTOS get its own management mechanism of primask. User is required to
|
||||
* use the EnableGlobalIRQ() and DisableGlobalIRQ() in pair.
|
||||
*
|
||||
* @param primask value of primask register to be restored. The primask value is supposed to be provided by the
|
||||
* DisableGlobalIRQ().
|
||||
*/
|
||||
static inline void EnableGlobalIRQ(uint32_t primask)
|
||||
{
|
||||
__set_PRIMASK(primask);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief install IRQ handler
|
||||
*
|
||||
* @param irq IRQ number
|
||||
* @param irqHandler IRQ handler address
|
||||
*/
|
||||
void InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @} */
|
||||
|
||||
#endif /* _FSL_COMMON_H_ */
|
||||
270
devices/MK22F51212/drivers/fsl_crc.c
Normal file
270
devices/MK22F51212/drivers/fsl_crc.c
Normal file
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "fsl_crc.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(CRC_DRIVER_USE_CRC16_CCIT_FALSE_AS_DEFAULT) && CRC_DRIVER_USE_CRC16_CCIT_FALSE_AS_DEFAULT
|
||||
/* @brief Default user configuration structure for CRC-16-CCITT */
|
||||
#define CRC_DRIVER_DEFAULT_POLYNOMIAL 0x1021U
|
||||
/*< CRC-16-CCIT polynomial x**16 + x**12 + x**5 + x**0 */
|
||||
#define CRC_DRIVER_DEFAULT_SEED 0xFFFFU
|
||||
/*< Default initial checksum */
|
||||
#define CRC_DRIVER_DEFAULT_REFLECT_IN false
|
||||
/*< Default is no transpose */
|
||||
#define CRC_DRIVER_DEFAULT_REFLECT_OUT false
|
||||
/*< Default is transpose bytes */
|
||||
#define CRC_DRIVER_DEFAULT_COMPLEMENT_CHECKSUM false
|
||||
/*< Default is without complement of CRC data register read data */
|
||||
#define CRC_DRIVER_DEFAULT_CRC_BITS kCrcBits16
|
||||
/*< Default is 16-bit CRC protocol */
|
||||
#define CRC_DRIVER_DEFAULT_CRC_RESULT kCrcFinalChecksum
|
||||
/*< Default is resutl type is final checksum */
|
||||
#endif /* CRC_DRIVER_USE_CRC16_CCIT_FALSE_AS_DEFAULT */
|
||||
|
||||
/*! @brief CRC type of transpose of read write data */
|
||||
typedef enum _crc_transpose_type
|
||||
{
|
||||
kCrcTransposeNone = 0U, /*! No transpose */
|
||||
kCrcTransposeBits = 1U, /*! Tranpose bits in bytes */
|
||||
kCrcTransposeBitsAndBytes = 2U, /*! Transpose bytes and bits in bytes */
|
||||
kCrcTransposeBytes = 3U, /*! Transpose bytes */
|
||||
} crc_transpose_type_t;
|
||||
|
||||
/*!
|
||||
* @brief CRC module configuration.
|
||||
*
|
||||
* This structure holds the configuration for the CRC module.
|
||||
*/
|
||||
typedef struct _crc_module_config
|
||||
{
|
||||
uint32_t polynomial; /*!< CRC Polynomial, MSBit first.@n
|
||||
Example polynomial: 0x1021 = 1_0000_0010_0001 = x^12+x^5+1 */
|
||||
uint32_t seed; /*!< Starting checksum value */
|
||||
crc_transpose_type_t readTranspose; /*!< Type of transpose when reading CRC result. */
|
||||
crc_transpose_type_t writeTranspose; /*!< Type of transpose when writing CRC input data. */
|
||||
bool complementChecksum; /*!< True if the result shall be complement of the actual checksum. */
|
||||
crc_bits_t crcBits; /*!< Selects 16- or 32- bit CRC protocol. */
|
||||
} crc_module_config_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Returns transpose type for CRC protocol reflect in parameter.
|
||||
*
|
||||
* This functions helps to set writeTranspose member of crc_config_t structure. Reflect in is CRC protocol parameter.
|
||||
*
|
||||
* @param enable True or false for the selected CRC protocol Reflect In (refin) parameter.
|
||||
*/
|
||||
static inline crc_transpose_type_t crc_GetTransposeTypeFromReflectIn(bool enable)
|
||||
{
|
||||
return ((enable) ? kCrcTransposeBitsAndBytes : kCrcTransposeBytes);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Returns transpose type for CRC protocol reflect out parameter.
|
||||
*
|
||||
* This functions helps to set readTranspose member of crc_config_t structure. Reflect out is CRC protocol parameter.
|
||||
*
|
||||
* @param enable True or false for the selected CRC protocol Reflect Out (refout) parameter.
|
||||
*/
|
||||
static inline crc_transpose_type_t crc_GetTransposeTypeFromReflectOut(bool enable)
|
||||
{
|
||||
return ((enable) ? kCrcTransposeBitsAndBytes : kCrcTransposeNone);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Starts checksum computation.
|
||||
*
|
||||
* Configures the CRC module for the specified CRC protocol. @n
|
||||
* Starts the checksum computation by writing the seed value
|
||||
*
|
||||
* @param base CRC peripheral address.
|
||||
* @param config Pointer to protocol configuration structure.
|
||||
*/
|
||||
static void crc_ConfigureAndStart(CRC_Type *base, const crc_module_config_t *config)
|
||||
{
|
||||
uint32_t crcControl;
|
||||
|
||||
/* pre-compute value for CRC control registger based on user configuraton without WAS field */
|
||||
crcControl = 0 | CRC_CTRL_TOT(config->writeTranspose) | CRC_CTRL_TOTR(config->readTranspose) |
|
||||
CRC_CTRL_FXOR(config->complementChecksum) | CRC_CTRL_TCRC(config->crcBits);
|
||||
|
||||
/* make sure the control register is clear - WAS is deasserted, and protocol is set */
|
||||
base->CTRL = crcControl;
|
||||
|
||||
/* write polynomial register */
|
||||
base->GPOLY = config->polynomial;
|
||||
|
||||
/* write pre-computed control register value along with WAS to start checksum computation */
|
||||
base->CTRL = crcControl | CRC_CTRL_WAS(true);
|
||||
|
||||
/* write seed (initial checksum) */
|
||||
base->DATA = config->seed;
|
||||
|
||||
/* deassert WAS by writing pre-computed CRC control register value */
|
||||
base->CTRL = crcControl;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Starts final checksum computation.
|
||||
*
|
||||
* Configures the CRC module for the specified CRC protocol. @n
|
||||
* Starts final checksum computation by writing the seed value.
|
||||
* @note CRC_Get16bitResult() or CRC_Get32bitResult() return final checksum
|
||||
* (output reflection and xor functions are applied).
|
||||
*
|
||||
* @param base CRC peripheral address.
|
||||
* @param protocolConfig Pointer to protocol configuration structure.
|
||||
*/
|
||||
static void crc_SetProtocolConfig(CRC_Type *base, const crc_config_t *protocolConfig)
|
||||
{
|
||||
crc_module_config_t moduleConfig;
|
||||
/* convert protocol to CRC peripheral module configuration, prepare for final checksum */
|
||||
moduleConfig.polynomial = protocolConfig->polynomial;
|
||||
moduleConfig.seed = protocolConfig->seed;
|
||||
moduleConfig.readTranspose = crc_GetTransposeTypeFromReflectOut(protocolConfig->reflectOut);
|
||||
moduleConfig.writeTranspose = crc_GetTransposeTypeFromReflectIn(protocolConfig->reflectIn);
|
||||
moduleConfig.complementChecksum = protocolConfig->complementChecksum;
|
||||
moduleConfig.crcBits = protocolConfig->crcBits;
|
||||
|
||||
crc_ConfigureAndStart(base, &moduleConfig);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Starts intermediate checksum computation.
|
||||
*
|
||||
* Configures the CRC module for the specified CRC protocol. @n
|
||||
* Starts intermediate checksum computation by writing the seed value.
|
||||
* @note CRC_Get16bitResult() or CRC_Get32bitResult() return intermediate checksum (raw data register value).
|
||||
*
|
||||
* @param base CRC peripheral address.
|
||||
* @param protocolConfig Pointer to protocol configuration structure.
|
||||
*/
|
||||
static void crc_SetRawProtocolConfig(CRC_Type *base, const crc_config_t *protocolConfig)
|
||||
{
|
||||
crc_module_config_t moduleConfig;
|
||||
/* convert protocol to CRC peripheral module configuration, prepare for intermediate checksum */
|
||||
moduleConfig.polynomial = protocolConfig->polynomial;
|
||||
moduleConfig.seed = protocolConfig->seed;
|
||||
moduleConfig.readTranspose =
|
||||
kCrcTransposeNone; /* intermediate checksum does no transpose of data register read value */
|
||||
moduleConfig.writeTranspose = crc_GetTransposeTypeFromReflectIn(protocolConfig->reflectIn);
|
||||
moduleConfig.complementChecksum = false; /* intermediate checksum does no xor of data register read value */
|
||||
moduleConfig.crcBits = protocolConfig->crcBits;
|
||||
|
||||
crc_ConfigureAndStart(base, &moduleConfig);
|
||||
}
|
||||
|
||||
void CRC_Init(CRC_Type *base, const crc_config_t *config)
|
||||
{
|
||||
/* ungate clock */
|
||||
CLOCK_EnableClock(kCLOCK_Crc0);
|
||||
/* configure CRC module and write the seed */
|
||||
if (config->crcResult == kCrcFinalChecksum)
|
||||
{
|
||||
crc_SetProtocolConfig(base, config);
|
||||
}
|
||||
else
|
||||
{
|
||||
crc_SetRawProtocolConfig(base, config);
|
||||
}
|
||||
}
|
||||
|
||||
void CRC_GetDefaultConfig(crc_config_t *config)
|
||||
{
|
||||
static const crc_config_t crc16ccit = {
|
||||
CRC_DRIVER_DEFAULT_POLYNOMIAL, CRC_DRIVER_DEFAULT_SEED,
|
||||
CRC_DRIVER_DEFAULT_REFLECT_IN, CRC_DRIVER_DEFAULT_REFLECT_OUT,
|
||||
CRC_DRIVER_DEFAULT_COMPLEMENT_CHECKSUM, CRC_DRIVER_DEFAULT_CRC_BITS,
|
||||
CRC_DRIVER_DEFAULT_CRC_RESULT,
|
||||
};
|
||||
|
||||
*config = crc16ccit;
|
||||
}
|
||||
|
||||
void CRC_WriteData(CRC_Type *base, const uint8_t *data, size_t dataSize)
|
||||
{
|
||||
const uint32_t *data32;
|
||||
|
||||
/* 8-bit reads and writes till source address is aligned 4 bytes */
|
||||
while ((dataSize) && ((uint32_t)data & 3U))
|
||||
{
|
||||
base->ACCESS8BIT.DATALL = *data;
|
||||
data++;
|
||||
dataSize--;
|
||||
}
|
||||
|
||||
/* use 32-bit reads and writes as long as possible */
|
||||
data32 = (const uint32_t *)data;
|
||||
while (dataSize >= sizeof(uint32_t))
|
||||
{
|
||||
base->DATA = *data32;
|
||||
data32++;
|
||||
dataSize -= sizeof(uint32_t);
|
||||
}
|
||||
|
||||
data = (const uint8_t *)data32;
|
||||
|
||||
/* 8-bit reads and writes till end of data buffer */
|
||||
while (dataSize)
|
||||
{
|
||||
base->ACCESS8BIT.DATALL = *data;
|
||||
data++;
|
||||
dataSize--;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t CRC_Get16bitResult(CRC_Type *base)
|
||||
{
|
||||
uint32_t retval;
|
||||
uint32_t totr; /* type of transpose read bitfield */
|
||||
|
||||
retval = base->DATA;
|
||||
totr = (base->CTRL & CRC_CTRL_TOTR_MASK) >> CRC_CTRL_TOTR_SHIFT;
|
||||
|
||||
/* check transpose type to get 16-bit out of 32-bit register */
|
||||
if (totr >= 2U)
|
||||
{
|
||||
/* transpose of bytes for read is set, the result CRC is in CRC_DATA[HU:HL] */
|
||||
retval &= 0xFFFF0000U;
|
||||
retval = retval >> 16U;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* no transpose of bytes for read, the result CRC is in CRC_DATA[LU:LL] */
|
||||
retval &= 0x0000FFFFU;
|
||||
}
|
||||
return (uint16_t)retval;
|
||||
}
|
||||
195
devices/MK22F51212/drivers/fsl_crc.h
Normal file
195
devices/MK22F51212/drivers/fsl_crc.h
Normal file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FSL_CRC_H_
|
||||
#define _FSL_CRC_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup crc_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief CRC driver version. Version 2.0.0. */
|
||||
#define FSL_CRC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
|
||||
/*@}*/
|
||||
|
||||
/*! @internal @brief Has data register with name CRC. */
|
||||
#if defined(FSL_FEATURE_CRC_HAS_CRC_REG) && FSL_FEATURE_CRC_HAS_CRC_REG
|
||||
#define DATA CRC
|
||||
#define DATALL CRCLL
|
||||
#endif
|
||||
|
||||
#ifndef CRC_DRIVER_CUSTOM_DEFAULTS
|
||||
/*! @brief Default configuration structure filled by CRC_GetDefaultConfig(). Use CRC16-CCIT-FALSE as defeault. */
|
||||
#define CRC_DRIVER_USE_CRC16_CCIT_FALSE_AS_DEFAULT 1
|
||||
#endif
|
||||
|
||||
/*! @brief CRC bit width */
|
||||
typedef enum _crc_bits
|
||||
{
|
||||
kCrcBits16 = 0U, /*!< Generate 16-bit CRC code */
|
||||
kCrcBits32 = 1U /*!< Generate 32-bit CRC code */
|
||||
} crc_bits_t;
|
||||
|
||||
/*! @brief CRC result type */
|
||||
typedef enum _crc_result
|
||||
{
|
||||
kCrcFinalChecksum = 0U, /*!< CRC data register read value is the final checksum.
|
||||
Reflect out and final xor protocol features are applied. */
|
||||
kCrcIntermediateChecksum = 1U /*!< CRC data register read value is intermediate checksum (raw value).
|
||||
Reflect out and final xor protocol feature are not applied.
|
||||
Intermediate checksum can be used as a seed for CRC_Init()
|
||||
to continue adding data to this checksum. */
|
||||
} crc_result_t;
|
||||
|
||||
/*!
|
||||
* @brief CRC protocol configuration.
|
||||
*
|
||||
* This structure holds the configuration for the CRC protocol.
|
||||
*
|
||||
*/
|
||||
typedef struct _crc_config
|
||||
{
|
||||
uint32_t polynomial; /*!< CRC Polynomial, MSBit first.
|
||||
Example polynomial: 0x1021 = 1_0000_0010_0001 = x^12+x^5+1 */
|
||||
uint32_t seed; /*!< Starting checksum value */
|
||||
bool reflectIn; /*!< Reflect bits on input. */
|
||||
bool reflectOut; /*!< Reflect bits on output. */
|
||||
bool complementChecksum; /*!< True if the result shall be complement of the actual checksum. */
|
||||
crc_bits_t crcBits; /*!< Selects 16- or 32- bit CRC protocol. */
|
||||
crc_result_t crcResult; /*!< Selects final or intermediate checksum return from CRC_Get16bitResult() or
|
||||
CRC_Get32bitResult() */
|
||||
} crc_config_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Enables and configures the CRC peripheral module.
|
||||
*
|
||||
* This functions enables the clock gate in the Kinetis SIM module for the CRC peripheral.
|
||||
* It also configures the CRC module and starts checksum computation by writing the seed.
|
||||
*
|
||||
* @param base CRC peripheral address.
|
||||
* @param config CRC module configuration structure
|
||||
*/
|
||||
void CRC_Init(CRC_Type *base, const crc_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Disables the CRC peripheral module.
|
||||
*
|
||||
* This functions disables the clock gate in the Kinetis SIM module for the CRC peripheral.
|
||||
*
|
||||
* @param base CRC peripheral address.
|
||||
*/
|
||||
static inline void CRC_Deinit(CRC_Type *base)
|
||||
{
|
||||
/* gate clock */
|
||||
CLOCK_DisableClock(kCLOCK_Crc0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Loads default values to CRC protocol configuration structure.
|
||||
*
|
||||
* Loads default values to CRC protocol configuration structure. The default values are:
|
||||
* @code
|
||||
* config->polynomial = 0x1021;
|
||||
* config->seed = 0xFFFF;
|
||||
* config->reflectIn = false;
|
||||
* config->reflectOut = false;
|
||||
* config->complementChecksum = false;
|
||||
* config->crcBits = kCrcBits16;
|
||||
* config->crcResult = kCrcFinalChecksum;
|
||||
* @endcode
|
||||
*
|
||||
* @param config CRC protocol configuration structure
|
||||
*/
|
||||
void CRC_GetDefaultConfig(crc_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Writes data to the CRC module.
|
||||
*
|
||||
* Writes input data buffer bytes to CRC data register.
|
||||
* The configured type of transpose is applied.
|
||||
*
|
||||
* @param base CRC peripheral address.
|
||||
* @param data Input data stream, MSByte in data[0].
|
||||
* @param dataSize Size in bytes of the input data buffer.
|
||||
*/
|
||||
void CRC_WriteData(CRC_Type *base, const uint8_t *data, size_t dataSize);
|
||||
|
||||
/*!
|
||||
* @brief Reads 32-bit checksum from the CRC module.
|
||||
*
|
||||
* Reads CRC data register (intermediate or final checksum).
|
||||
* The configured type of transpose and complement are applied.
|
||||
*
|
||||
* @param base CRC peripheral address.
|
||||
* @return intermediate or final 32-bit checksum, after configured transpose and complement operations.
|
||||
*/
|
||||
static inline uint32_t CRC_Get32bitResult(CRC_Type *base)
|
||||
{
|
||||
return base->DATA;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reads 16-bit checksum from the CRC module.
|
||||
*
|
||||
* Reads CRC data register (intermediate or final checksum).
|
||||
* The configured type of transpose and complement are applied.
|
||||
*
|
||||
* @param base CRC peripheral address.
|
||||
* @return intermediate or final 16-bit checksum, after configured transpose and complement operations.
|
||||
*/
|
||||
uint16_t CRC_Get16bitResult(CRC_Type *base);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
*@}
|
||||
*/
|
||||
|
||||
#endif /* _FSL_CRC_H_ */
|
||||
213
devices/MK22F51212/drivers/fsl_dac.c
Normal file
213
devices/MK22F51212/drivers/fsl_dac.c
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_dac.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
/*!
|
||||
* @brief Get instance number for DAC module.
|
||||
*
|
||||
* @param base DAC peripheral base address
|
||||
*/
|
||||
static uint32_t DAC_GetInstance(DAC_Type *base);
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
/*! @brief Pointers to DAC bases for each instance. */
|
||||
static DAC_Type *const s_dacBases[] = DAC_BASE_PTRS;
|
||||
/*! @brief Pointers to DAC clocks for each instance. */
|
||||
const clock_ip_name_t s_dacClocks[] = DAC_CLOCKS;
|
||||
|
||||
/*******************************************************************************
|
||||
* Codes
|
||||
******************************************************************************/
|
||||
static uint32_t DAC_GetInstance(DAC_Type *base)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
/* Find the instance index from base address mappings. */
|
||||
for (instance = 0; instance < FSL_FEATURE_SOC_DAC_COUNT; instance++)
|
||||
{
|
||||
if (s_dacBases[instance] == base)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(instance < FSL_FEATURE_SOC_DAC_COUNT);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void DAC_Init(DAC_Type *base, const dac_config_t *config)
|
||||
{
|
||||
assert(NULL != config);
|
||||
|
||||
uint8_t tmp8;
|
||||
|
||||
/* Enable the clock. */
|
||||
CLOCK_EnableClock(s_dacClocks[DAC_GetInstance(base)]);
|
||||
|
||||
/* Configure. */
|
||||
/* DACx_C0. */
|
||||
tmp8 = base->C0 & ~(DAC_C0_DACRFS_MASK | DAC_C0_LPEN_MASK);
|
||||
if (kDAC_ReferenceVoltageSourceVref2 == config->referenceVoltageSource)
|
||||
{
|
||||
tmp8 |= DAC_C0_DACRFS_MASK;
|
||||
}
|
||||
if (config->enableLowPowerMode)
|
||||
{
|
||||
tmp8 |= DAC_C0_LPEN_MASK;
|
||||
}
|
||||
base->C0 = tmp8;
|
||||
|
||||
DAC_Enable(base, true);
|
||||
}
|
||||
|
||||
void DAC_Deinit(DAC_Type *base)
|
||||
{
|
||||
DAC_Enable(base, false);
|
||||
|
||||
/* Disable the clock. */
|
||||
CLOCK_DisableClock(s_dacClocks[DAC_GetInstance(base)]);
|
||||
}
|
||||
|
||||
void DAC_GetDefaultConfig(dac_config_t *config)
|
||||
{
|
||||
assert(NULL != config);
|
||||
|
||||
config->referenceVoltageSource = kDAC_ReferenceVoltageSourceVref2;
|
||||
config->enableLowPowerMode = false;
|
||||
}
|
||||
|
||||
void DAC_SetBufferConfig(DAC_Type *base, const dac_buffer_config_t *config)
|
||||
{
|
||||
assert(NULL != config);
|
||||
|
||||
uint8_t tmp8;
|
||||
|
||||
/* DACx_C0. */
|
||||
tmp8 = base->C0 & ~(DAC_C0_DACTRGSEL_MASK);
|
||||
if (kDAC_BufferTriggerBySoftwareMode == config->triggerMode)
|
||||
{
|
||||
tmp8 |= DAC_C0_DACTRGSEL_MASK;
|
||||
}
|
||||
base->C0 = tmp8;
|
||||
|
||||
/* DACx_C1. */
|
||||
tmp8 = base->C1 &
|
||||
~(
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION) && FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION
|
||||
DAC_C1_DACBFWM_MASK |
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION */
|
||||
DAC_C1_DACBFMD_MASK);
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION) && FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION
|
||||
tmp8 |= DAC_C1_DACBFWM(config->watermark);
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION */
|
||||
tmp8 |= DAC_C1_DACBFMD(config->workMode);
|
||||
base->C1 = tmp8;
|
||||
|
||||
/* DACx_C2. */
|
||||
tmp8 = base->C2 & ~DAC_C2_DACBFUP_MASK;
|
||||
tmp8 |= DAC_C2_DACBFUP(config->upperLimit);
|
||||
base->C2 = tmp8;
|
||||
}
|
||||
|
||||
void DAC_GetDefaultBufferConfig(dac_buffer_config_t *config)
|
||||
{
|
||||
assert(NULL != config);
|
||||
|
||||
config->triggerMode = kDAC_BufferTriggerBySoftwareMode;
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION) && FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION
|
||||
config->watermark = kDAC_BufferWatermark1Word;
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION */
|
||||
config->workMode = kDAC_BufferWorkAsNormalMode;
|
||||
config->upperLimit = DAC_DATL_COUNT - 1U;
|
||||
}
|
||||
|
||||
void DAC_SetBufferValue(DAC_Type *base, uint8_t index, uint16_t value)
|
||||
{
|
||||
assert(index < DAC_DATL_COUNT);
|
||||
|
||||
base->DAT[index].DATL = (uint8_t)(0xFFU & value); /* Low 8-bit. */
|
||||
base->DAT[index].DATH = (uint8_t)((0xF00U & value) >> 8); /* High 4-bit. */
|
||||
}
|
||||
|
||||
void DAC_SetBufferReadPointer(DAC_Type *base, uint8_t index)
|
||||
{
|
||||
assert(index < DAC_DATL_COUNT);
|
||||
|
||||
uint8_t tmp8 = base->C2 & ~DAC_C2_DACBFRP_MASK;
|
||||
|
||||
tmp8 |= DAC_C2_DACBFRP(index);
|
||||
base->C2 = tmp8;
|
||||
}
|
||||
|
||||
void DAC_EnableBufferInterrupts(DAC_Type *base, uint32_t mask)
|
||||
{
|
||||
mask &= (
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION) && FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
|
||||
DAC_C0_DACBWIEN_MASK |
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION */
|
||||
DAC_C0_DACBTIEN_MASK | DAC_C0_DACBBIEN_MASK);
|
||||
base->C0 |= ((uint8_t)mask); /* Write 1 to enable. */
|
||||
}
|
||||
|
||||
void DAC_DisableBufferInterrupts(DAC_Type *base, uint32_t mask)
|
||||
{
|
||||
mask &= (
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION) && FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
|
||||
DAC_C0_DACBWIEN_MASK |
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION */
|
||||
DAC_C0_DACBTIEN_MASK | DAC_C0_DACBBIEN_MASK);
|
||||
base->C0 &= (uint8_t)(~((uint8_t)mask)); /* Write 0 to disable. */
|
||||
}
|
||||
|
||||
uint32_t DAC_GetBufferStatusFlags(DAC_Type *base)
|
||||
{
|
||||
return (uint32_t)(base->SR & (
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION) && FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
|
||||
DAC_SR_DACBFWMF_MASK |
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION */
|
||||
DAC_SR_DACBFRPTF_MASK | DAC_SR_DACBFRPBF_MASK));
|
||||
}
|
||||
|
||||
void DAC_ClearBufferStatusFlags(DAC_Type *base, uint32_t mask)
|
||||
{
|
||||
mask &= (
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION) && FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
|
||||
DAC_SR_DACBFWMF_MASK |
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION */
|
||||
DAC_SR_DACBFRPTF_MASK | DAC_SR_DACBFRPBF_MASK);
|
||||
base->SR &= (uint8_t)(~((uint8_t)mask)); /* Write 0 to clear flags. */
|
||||
}
|
||||
379
devices/MK22F51212/drivers/fsl_dac.h
Normal file
379
devices/MK22F51212/drivers/fsl_dac.h
Normal file
@@ -0,0 +1,379 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FSL_DAC_H_
|
||||
#define _FSL_DAC_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup dac
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief DAC driver version 2.0.0. */
|
||||
#define FSL_DAC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
|
||||
/*@}*/
|
||||
|
||||
/*!
|
||||
* @brief DAC buffer flags.
|
||||
*/
|
||||
enum _dac_buffer_status_flags
|
||||
{
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION) && FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
|
||||
kDAC_BufferWatermarkFlag = DAC_SR_DACBFWMF_MASK, /*!< DAC Buffer Watermark Flag. */
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION */
|
||||
kDAC_BufferReadPointerTopPositionFlag = DAC_SR_DACBFRPTF_MASK, /*!< DAC Buffer Read Pointer Top Position Flag. */
|
||||
kDAC_BufferReadPointerBottomPositionFlag = DAC_SR_DACBFRPBF_MASK, /*!< DAC Buffer Read Pointer Bottom Position
|
||||
Flag. */
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief DAC buffer interrupts.
|
||||
*/
|
||||
enum _dac_buffer_interrupt_enable
|
||||
{
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION) && FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
|
||||
kDAC_BufferWatermarkInterruptEnable = DAC_C0_DACBWIEN_MASK, /*!< DAC Buffer Watermark Interrupt Enable. */
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION */
|
||||
kDAC_BufferReadPointerTopInterruptEnable = DAC_C0_DACBTIEN_MASK, /*!< DAC Buffer Read Pointer Top Flag Interrupt
|
||||
Enable. */
|
||||
kDAC_BufferReadPointerBottomInterruptEnable = DAC_C0_DACBBIEN_MASK, /*!< DAC Buffer Read Pointer Bottom Flag
|
||||
Interrupt Enable */
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief DAC reference voltage source.
|
||||
*/
|
||||
typedef enum _dac_reference_voltage_source
|
||||
{
|
||||
kDAC_ReferenceVoltageSourceVref1 = 0U, /*!< The DAC selects DACREF_1 as the reference voltage. */
|
||||
kDAC_ReferenceVoltageSourceVref2 = 1U, /*!< The DAC selects DACREF_2 as the reference voltage. */
|
||||
} dac_reference_voltage_source_t;
|
||||
|
||||
/*!
|
||||
* @brief DAC buffer trigger mode.
|
||||
*/
|
||||
typedef enum _dac_buffer_trigger_mode
|
||||
{
|
||||
kDAC_BufferTriggerByHardwareMode = 0U, /*!< The DAC hardware trigger is selected. */
|
||||
kDAC_BufferTriggerBySoftwareMode = 1U, /*!< The DAC software trigger is selected. */
|
||||
} dac_buffer_trigger_mode_t;
|
||||
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION) && FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION
|
||||
/*!
|
||||
* @brief DAC buffer watermark.
|
||||
*/
|
||||
typedef enum _dac_buffer_watermark
|
||||
{
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_1_WORD) && FSL_FEATURE_DAC_HAS_WATERMARK_1_WORD
|
||||
kDAC_BufferWatermark1Word = 0U, /*!< 1 word away from the upper limit. */
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_1_WORD */
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_2_WORD) && FSL_FEATURE_DAC_HAS_WATERMARK_2_WORD
|
||||
kDAC_BufferWatermark2Word = 1U, /*!< 2 words away from the upper limit. */
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_2_WORD */
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_3_WORD) && FSL_FEATURE_DAC_HAS_WATERMARK_3_WORD
|
||||
kDAC_BufferWatermark3Word = 2U, /*!< 3 words away from the upper limit. */
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_3_WORD */
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_4_WORD) && FSL_FEATURE_DAC_HAS_WATERMARK_4_WORD
|
||||
kDAC_BufferWatermark4Word = 3U, /*!< 4 words away from the upper limit. */
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_4_WORD */
|
||||
} dac_buffer_watermark_t;
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION */
|
||||
|
||||
/*!
|
||||
* @brief DAC buffer work mode.
|
||||
*/
|
||||
typedef enum _dac_buffer_work_mode
|
||||
{
|
||||
kDAC_BufferWorkAsNormalMode = 0U, /*!< Normal mode. */
|
||||
#if defined(FSL_FEATURE_DAC_HAS_BUFFER_SWING_MODE) && FSL_FEATURE_DAC_HAS_BUFFER_SWING_MODE
|
||||
kDAC_BufferWorkAsSwingMode, /*!< Swing mode. */
|
||||
#endif /* FSL_FEATURE_DAC_HAS_BUFFER_SWING_MODE */
|
||||
kDAC_BufferWorkAsOneTimeScanMode, /*!< One-Time Scan mode. */
|
||||
#if defined(FSL_FEATURE_DAC_HAS_BUFFER_FIFO_MODE) && FSL_FEATURE_DAC_HAS_BUFFER_FIFO_MODE
|
||||
kDAC_BufferWorkAsFIFOMode, /*!< FIFO mode. */
|
||||
#endif /* FSL_FEATURE_DAC_HAS_BUFFER_FIFO_MODE */
|
||||
} dac_buffer_work_mode_t;
|
||||
|
||||
/*!
|
||||
* @brief DAC module configuration.
|
||||
*/
|
||||
typedef struct _dac_config
|
||||
{
|
||||
dac_reference_voltage_source_t referenceVoltageSource; /*!< Select the DAC reference voltage source. */
|
||||
bool enableLowPowerMode; /*!< Enable the low power mode. */
|
||||
} dac_config_t;
|
||||
|
||||
/*!
|
||||
* @brief DAC buffer configuration.
|
||||
*/
|
||||
typedef struct _dac_buffer_config
|
||||
{
|
||||
dac_buffer_trigger_mode_t triggerMode; /*!< Select the buffer's trigger mode. */
|
||||
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION) && FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION
|
||||
dac_buffer_watermark_t watermark; /*!< Select the buffer's watermark. */
|
||||
#endif /* FSL_FEATURE_DAC_HAS_WATERMARK_SELECTION */
|
||||
dac_buffer_work_mode_t workMode; /*!< Select the buffer's work mode. */
|
||||
uint8_t upperLimit; /*!< Set the upper limit for buffer index.
|
||||
Normally, 0-15 is available for buffer with 16 item. */
|
||||
} dac_buffer_config_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @name Initialization
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes the DAC module.
|
||||
*
|
||||
* This function initializes the DAC module, including:
|
||||
* - Enabling the clock for DAC module.
|
||||
* - Configuring the DAC converter with a user configuration.
|
||||
* - Enabling the DAC module.
|
||||
*
|
||||
* @param base DAC peripheral base address.
|
||||
* @param config Pointer to the configuration structure. See "dac_config_t".
|
||||
*/
|
||||
void DAC_Init(DAC_Type *base, const dac_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief De-initializes the DAC module.
|
||||
*
|
||||
* This function de-initializes the DAC module, including:
|
||||
* - Disabling the DAC module.
|
||||
* - Disabling the clock for the DAC module.
|
||||
*
|
||||
* @param base DAC peripheral base address.
|
||||
*/
|
||||
void DAC_Deinit(DAC_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Initializes the DAC user configuration structure.
|
||||
*
|
||||
* This function initializes the user configuration structure to a default value. The default values are:
|
||||
* @code
|
||||
* config->referenceVoltageSource = kDAC_ReferenceVoltageSourceVref2;
|
||||
* config->enableLowPowerMode = false;
|
||||
* @endcode
|
||||
* @param config Pointer to the configuration structure. See "dac_config_t".
|
||||
*/
|
||||
void DAC_GetDefaultConfig(dac_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Enables the DAC module.
|
||||
*
|
||||
* @param base DAC peripheral base address.
|
||||
* @param enable Enables the feature or not.
|
||||
*/
|
||||
static inline void DAC_Enable(DAC_Type *base, bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
base->C0 |= DAC_C0_DACEN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->C0 &= ~DAC_C0_DACEN_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
/* @} */
|
||||
|
||||
/*!
|
||||
* @name Buffer
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Enables the DAC buffer.
|
||||
*
|
||||
* @param base DAC peripheral base address.
|
||||
* @param enable Enables the feature or not.
|
||||
*/
|
||||
static inline void DAC_EnableBuffer(DAC_Type *base, bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
base->C1 |= DAC_C1_DACBFEN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->C1 &= ~DAC_C1_DACBFEN_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Configures the CMP buffer.
|
||||
*
|
||||
* @param base DAC peripheral base address.
|
||||
* @param config Pointer to the configuration structure. See "dac_buffer_config_t".
|
||||
*/
|
||||
void DAC_SetBufferConfig(DAC_Type *base, const dac_buffer_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Initializes the DAC buffer configuration structure.
|
||||
*
|
||||
* This function initializes the DAC buffer configuration structure to a default value. The default values are:
|
||||
* @code
|
||||
* config->triggerMode = kDAC_BufferTriggerBySoftwareMode;
|
||||
* config->watermark = kDAC_BufferWatermark1Word;
|
||||
* config->workMode = kDAC_BufferWorkAsNormalMode;
|
||||
* config->upperLimit = DAC_DATL_COUNT - 1U;
|
||||
* @endcode
|
||||
* @param config Pointer to the configuration structure. See "dac_buffer_config_t".
|
||||
*/
|
||||
void DAC_GetDefaultBufferConfig(dac_buffer_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Enables the DMA for DAC buffer.
|
||||
*
|
||||
* @param base DAC peripheral base address.
|
||||
* @param enable Enables the feature or not.
|
||||
*/
|
||||
static inline void DAC_EnableBufferDMA(DAC_Type *base, bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
base->C1 |= DAC_C1_DMAEN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->C1 &= ~DAC_C1_DMAEN_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets the value for items in the buffer.
|
||||
*
|
||||
* @param base DAC peripheral base address.
|
||||
* @param index Setting index for items in the buffer. The available index should not exceed the size of the DAC buffer.
|
||||
* @param value Setting value for items in the buffer. 12-bits are available.
|
||||
*/
|
||||
void DAC_SetBufferValue(DAC_Type *base, uint8_t index, uint16_t value);
|
||||
|
||||
/*!
|
||||
* @brief Triggers the buffer by software and updates the read pointer of the DAC buffer.
|
||||
*
|
||||
* This function triggers the function by software. The read pointer of the DAC buffer is updated with one step
|
||||
* after this function is called. Changing the read pointer depends on the buffer's work mode.
|
||||
*
|
||||
* @param base DAC peripheral base address.
|
||||
*/
|
||||
static inline void DAC_DoSoftwareTriggerBuffer(DAC_Type *base)
|
||||
{
|
||||
base->C0 |= DAC_C0_DACSWTRG_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets the current read pointer of the DAC buffer.
|
||||
*
|
||||
* This function gets the current read pointer of the DAC buffer.
|
||||
* The current output value depends on the item indexed by the read pointer. It is updated
|
||||
* by software trigger or hardware trigger.
|
||||
*
|
||||
* @param base DAC peripheral base address.
|
||||
*
|
||||
* @return Current read pointer of DAC buffer.
|
||||
*/
|
||||
static inline uint8_t DAC_GetBufferReadPointer(DAC_Type *base)
|
||||
{
|
||||
return ((base->C2 & DAC_C2_DACBFRP_MASK) >> DAC_C2_DACBFRP_SHIFT);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets the current read pointer of the DAC buffer.
|
||||
*
|
||||
* This function sets the current read pointer of the DAC buffer.
|
||||
* The current output value depends on the item indexed by the read pointer. It is updated by
|
||||
* software trigger or hardware trigger. After the read pointer changes, the DAC output value also changes.
|
||||
*
|
||||
* @param base DAC peripheral base address.
|
||||
* @param index Setting index value for the pointer.
|
||||
*/
|
||||
void DAC_SetBufferReadPointer(DAC_Type *base, uint8_t index);
|
||||
|
||||
/*!
|
||||
* @brief Enables interrupts for the DAC buffer.
|
||||
*
|
||||
* @param base DAC peripheral base address.
|
||||
* @param mask Mask value for interrupts. See "_dac_buffer_interrupt_enable".
|
||||
*/
|
||||
void DAC_EnableBufferInterrupts(DAC_Type *base, uint32_t mask);
|
||||
|
||||
/*!
|
||||
* @brief Disables interrupts for the DAC buffer.
|
||||
*
|
||||
* @param base DAC peripheral base address.
|
||||
* @param mask Mask value for interrupts. See "_dac_buffer_interrupt_enable".
|
||||
*/
|
||||
void DAC_DisableBufferInterrupts(DAC_Type *base, uint32_t mask);
|
||||
|
||||
/*!
|
||||
* @brief Gets the flags of events for the DAC buffer.
|
||||
*
|
||||
* @param base DAC peripheral base address.
|
||||
*
|
||||
* @return Mask value for the asserted flags. See "_dac_buffer_status_flags".
|
||||
*/
|
||||
uint32_t DAC_GetBufferStatusFlags(DAC_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Clears the flags of events for the DAC buffer.
|
||||
*
|
||||
* @param base DAC peripheral base address.
|
||||
* @param mask Mask value for flags. See "_dac_buffer_status_flags_t".
|
||||
*/
|
||||
void DAC_ClearBufferStatusFlags(DAC_Type *base, uint32_t mask);
|
||||
|
||||
/* @} */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
#endif /* _FSL_DAC_H_ */
|
||||
87
devices/MK22F51212/drivers/fsl_dmamux.c
Normal file
87
devices/MK22F51212/drivers/fsl_dmamux.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_dmamux.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Get instance number for DMAMUX.
|
||||
*
|
||||
* @param base DMAMUX peripheral base address.
|
||||
*/
|
||||
static uint32_t DMAMUX_GetInstance(DMAMUX_Type *base);
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief Array to map DMAMUX instance number to base pointer. */
|
||||
static DMAMUX_Type *const s_dmamuxBases[] = DMAMUX_BASE_PTRS;
|
||||
|
||||
/*! @brief Array to map DMAMUX instance number to clock name. */
|
||||
static const clock_ip_name_t s_dmamuxClockName[] = DMAMUX_CLOCKS;
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
static uint32_t DMAMUX_GetInstance(DMAMUX_Type *base)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
/* Find the instance index from base address mappings. */
|
||||
for (instance = 0; instance < FSL_FEATURE_SOC_DMAMUX_COUNT; instance++)
|
||||
{
|
||||
if (s_dmamuxBases[instance] == base)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(instance < FSL_FEATURE_SOC_DMAMUX_COUNT);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void DMAMUX_Init(DMAMUX_Type *base)
|
||||
{
|
||||
CLOCK_EnableClock(s_dmamuxClockName[DMAMUX_GetInstance(base)]);
|
||||
}
|
||||
|
||||
void DMAMUX_Deinit(DMAMUX_Type *base)
|
||||
{
|
||||
CLOCK_DisableClock(s_dmamuxClockName[DMAMUX_GetInstance(base)]);
|
||||
}
|
||||
176
devices/MK22F51212/drivers/fsl_dmamux.h
Normal file
176
devices/MK22F51212/drivers/fsl_dmamux.h
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FSL_DMAMUX_H_
|
||||
#define _FSL_DMAMUX_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup dmamux
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief DMAMUX driver version 2.0.0. */
|
||||
#define FSL_DMAMUX_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
|
||||
/*@}*/
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*!
|
||||
* @name DMAMUX Initialize and De-initialize
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes DMAMUX peripheral.
|
||||
*
|
||||
* This function ungate the DMAMUX clock.
|
||||
*
|
||||
* @param base DMAMUX peripheral base address.
|
||||
*
|
||||
*/
|
||||
void DMAMUX_Init(DMAMUX_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Deinitializes DMAMUX peripheral.
|
||||
*
|
||||
* This function gate the DMAMUX clock.
|
||||
*
|
||||
* @param base DMAMUX peripheral base address.
|
||||
*/
|
||||
void DMAMUX_Deinit(DMAMUX_Type *base);
|
||||
|
||||
/* @} */
|
||||
/*!
|
||||
* @name DMAMUX Channel Operation
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Enable DMAMUX channel.
|
||||
*
|
||||
* This function enable DMAMUX channel to work.
|
||||
*
|
||||
* @param base DMAMUX peripheral base address.
|
||||
* @param channel DMAMUX channel number.
|
||||
*/
|
||||
static inline void DMAMUX_EnableChannel(DMAMUX_Type *base, uint32_t channel)
|
||||
{
|
||||
assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
|
||||
|
||||
base->CHCFG[channel] |= DMAMUX_CHCFG_ENBL_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disable DMAMUX channel.
|
||||
*
|
||||
* This function disable DMAMUX channel.
|
||||
*
|
||||
* @note User must disable DMAMUX channel before configure it.
|
||||
* @param base DMAMUX peripheral base address.
|
||||
* @param channel DMAMUX channel number.
|
||||
*/
|
||||
static inline void DMAMUX_DisableChannel(DMAMUX_Type *base, uint32_t channel)
|
||||
{
|
||||
assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
|
||||
|
||||
base->CHCFG[channel] &= ~DMAMUX_CHCFG_ENBL_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Configure DMAMUX channel source.
|
||||
*
|
||||
* @param base DMAMUX peripheral base address.
|
||||
* @param channel DMAMUX channel number.
|
||||
* @param source Channel source which is used to trigger DMA transfer.
|
||||
*/
|
||||
static inline void DMAMUX_SetSource(DMAMUX_Type *base, uint32_t channel, uint8_t source)
|
||||
{
|
||||
assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
|
||||
|
||||
base->CHCFG[channel] = ((base->CHCFG[channel] & ~DMAMUX_CHCFG_SOURCE_MASK) | DMAMUX_CHCFG_SOURCE(source));
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_DMAMUX_HAS_TRIG) && FSL_FEATURE_DMAMUX_HAS_TRIG > 0U
|
||||
/*!
|
||||
* @brief Enable DMAMUX period trigger.
|
||||
*
|
||||
* This function enable DMAMUX period trigger feature.
|
||||
*
|
||||
* @param base DMAMUX peripheral base address.
|
||||
* @param channel DMAMUX channel number.
|
||||
*/
|
||||
static inline void DMAMUX_EnablePeriodTrigger(DMAMUX_Type *base, uint32_t channel)
|
||||
{
|
||||
assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
|
||||
|
||||
base->CHCFG[channel] |= DMAMUX_CHCFG_TRIG_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disable DMAMUX period trigger.
|
||||
*
|
||||
* This function disable DMAMUX period trigger.
|
||||
*
|
||||
* @param base DMAMUX peripheral base address.
|
||||
* @param channel DMAMUX channel number.
|
||||
*/
|
||||
static inline void DMAMUX_DisablePeriodTrigger(DMAMUX_Type *base, uint32_t channel)
|
||||
{
|
||||
assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
|
||||
|
||||
base->CHCFG[channel] &= ~DMAMUX_CHCFG_TRIG_MASK;
|
||||
}
|
||||
#endif /* FSL_FEATURE_DMAMUX_HAS_TRIG */
|
||||
|
||||
/* @} */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* @} */
|
||||
|
||||
#endif /* _FSL_DMAMUX_H_ */
|
||||
1659
devices/MK22F51212/drivers/fsl_dspi.c
Normal file
1659
devices/MK22F51212/drivers/fsl_dspi.c
Normal file
File diff suppressed because it is too large
Load Diff
1185
devices/MK22F51212/drivers/fsl_dspi.h
Normal file
1185
devices/MK22F51212/drivers/fsl_dspi.h
Normal file
File diff suppressed because it is too large
Load Diff
1262
devices/MK22F51212/drivers/fsl_dspi_edma.c
Normal file
1262
devices/MK22F51212/drivers/fsl_dspi_edma.c
Normal file
File diff suppressed because it is too large
Load Diff
283
devices/MK22F51212/drivers/fsl_dspi_edma.h
Normal file
283
devices/MK22F51212/drivers/fsl_dspi_edma.h
Normal file
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_DSPI_EDMA_H_
|
||||
#define _FSL_DSPI_EDMA_H_
|
||||
|
||||
#include "fsl_dspi.h"
|
||||
#include "fsl_edma.h"
|
||||
/*!
|
||||
* @addtogroup dspi_edma_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Definitions
|
||||
**********************************************************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Forward declaration of the DSPI eDMA master handle typedefs.
|
||||
*/
|
||||
typedef struct _dspi_master_edma_handle dspi_master_edma_handle_t;
|
||||
|
||||
/*!
|
||||
* @brief Forward declaration of the DSPI eDMA slave handle typedefs.
|
||||
*/
|
||||
typedef struct _dspi_slave_edma_handle dspi_slave_edma_handle_t;
|
||||
|
||||
/*!
|
||||
* @brief Completion callback function pointer type.
|
||||
*
|
||||
* @param base DSPI peripheral base address.
|
||||
* @param handle Pointer to the handle for the DSPI master.
|
||||
* @param status Success or error code describing whether the transfer completed.
|
||||
* @param userData Arbitrary pointer-dataSized value passed from the application.
|
||||
*/
|
||||
typedef void (*dspi_master_edma_transfer_callback_t)(SPI_Type *base,
|
||||
dspi_master_edma_handle_t *handle,
|
||||
status_t status,
|
||||
void *userData);
|
||||
/*!
|
||||
* @brief Completion callback function pointer type.
|
||||
*
|
||||
* @param base DSPI peripheral base address.
|
||||
* @param handle Pointer to the handle for the DSPI slave.
|
||||
* @param status Success or error code describing whether the transfer completed.
|
||||
* @param userData Arbitrary pointer-dataSized value passed from the application.
|
||||
*/
|
||||
typedef void (*dspi_slave_edma_transfer_callback_t)(SPI_Type *base,
|
||||
dspi_slave_edma_handle_t *handle,
|
||||
status_t status,
|
||||
void *userData);
|
||||
|
||||
/*! @brief DSPI master eDMA transfer handle structure used for transactional API. */
|
||||
struct _dspi_master_edma_handle
|
||||
{
|
||||
uint32_t bitsPerFrame; /*!< Desired number of bits per frame. */
|
||||
volatile uint32_t command; /*!< Desired data command. */
|
||||
volatile uint32_t lastCommand; /*!< Desired last data command. */
|
||||
|
||||
uint8_t fifoSize; /*!< FIFO dataSize. */
|
||||
|
||||
volatile bool isPcsActiveAfterTransfer; /*!< Is PCS signal keep active after the last frame transfer.*/
|
||||
volatile bool isThereExtraByte; /*!< Is there extra byte.*/
|
||||
|
||||
uint8_t *volatile txData; /*!< Send buffer. */
|
||||
uint8_t *volatile rxData; /*!< Receive buffer. */
|
||||
volatile size_t remainingSendByteCount; /*!< Number of bytes remaining to send.*/
|
||||
volatile size_t remainingReceiveByteCount; /*!< Number of bytes remaining to receive.*/
|
||||
size_t totalByteCount; /*!< Number of transfer bytes*/
|
||||
|
||||
uint32_t rxBuffIfNull; /*!< Used if there is not rxData for DMA purpose.*/
|
||||
uint32_t txBuffIfNull; /*!< Used if there is not txData for DMA purpose.*/
|
||||
|
||||
volatile uint8_t state; /*!< DSPI transfer state , _dspi_transfer_state.*/
|
||||
|
||||
dspi_master_edma_transfer_callback_t callback; /*!< Completion callback. */
|
||||
void *userData; /*!< Callback user data. */
|
||||
|
||||
edma_handle_t *edmaRxRegToRxDataHandle; /*!<edma_handle_t handle point used for RxReg to RxData buff*/
|
||||
edma_handle_t *edmaTxDataToIntermediaryHandle; /*!<edma_handle_t handle point used for TxData to Intermediary*/
|
||||
edma_handle_t *edmaIntermediaryToTxRegHandle; /*!<edma_handle_t handle point used for Intermediary to TxReg*/
|
||||
|
||||
edma_tcd_t dspiSoftwareTCD[2]; /*!<SoftwareTCD , internal used*/
|
||||
};
|
||||
|
||||
/*! @brief DSPI slave eDMA transfer handle structure used for transactional API.*/
|
||||
struct _dspi_slave_edma_handle
|
||||
{
|
||||
uint32_t bitsPerFrame; /*!< Desired number of bits per frame. */
|
||||
volatile bool isThereExtraByte; /*!< Is there extra byte.*/
|
||||
|
||||
uint8_t *volatile txData; /*!< Send buffer. */
|
||||
uint8_t *volatile rxData; /*!< Receive buffer. */
|
||||
volatile size_t remainingSendByteCount; /*!< Number of bytes remaining to send.*/
|
||||
volatile size_t remainingReceiveByteCount; /*!< Number of bytes remaining to receive.*/
|
||||
size_t totalByteCount; /*!< Number of transfer bytes*/
|
||||
|
||||
uint32_t rxBuffIfNull; /*!< Used if there is not rxData for DMA purpose.*/
|
||||
uint32_t txBuffIfNull; /*!< Used if there is not txData for DMA purpose.*/
|
||||
uint32_t txLastData; /*!< Used if there is an extra byte when 16bits per frame for DMA purpose.*/
|
||||
|
||||
volatile uint8_t state; /*!< DSPI transfer state.*/
|
||||
|
||||
uint32_t errorCount; /*!< Error count for slave transfer.*/
|
||||
|
||||
dspi_slave_edma_transfer_callback_t callback; /*!< Completion callback. */
|
||||
void *userData; /*!< Callback user data. */
|
||||
|
||||
edma_handle_t *edmaRxRegToRxDataHandle; /*!<edma_handle_t handle point used for RxReg to RxData buff*/
|
||||
edma_handle_t *edmaTxDataToTxRegHandle; /*!<edma_handle_t handle point used for TxData to TxReg*/
|
||||
|
||||
edma_tcd_t dspiSoftwareTCD[2]; /*!<SoftwareTCD , internal used*/
|
||||
};
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* API
|
||||
**********************************************************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /*_cplusplus*/
|
||||
|
||||
/*Transactional APIs*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes the DSPI master eDMA handle.
|
||||
*
|
||||
* This function initializes the DSPI eDMA handle which can be used for other DSPI transactional APIs. Usually, for a
|
||||
* specified DSPI instance, user need only call this API once to get the initialized handle.
|
||||
*
|
||||
* Note that DSPI eDMA has separated (RX and TX as two sources) or shared (RX and TX are the same source) DMA request source.
|
||||
* (1)For the separated DMA request source, enable and set the RX DMAMUX source for edmaRxRegToRxDataHandle and
|
||||
* TX DMAMUX source for edmaIntermediaryToTxRegHandle.
|
||||
* (2)For the shared DMA request source, enable and set the RX/RX DMAMUX source for the edmaRxRegToRxDataHandle.
|
||||
*
|
||||
* @param base DSPI peripheral base address.
|
||||
* @param handle DSPI handle pointer to dspi_master_edma_handle_t.
|
||||
* @param callback DSPI callback.
|
||||
* @param userData callback function parameter.
|
||||
* @param edmaRxRegToRxDataHandle edmaRxRegToRxDataHandle pointer to edma_handle_t.
|
||||
* @param edmaTxDataToIntermediaryHandle edmaTxDataToIntermediaryHandle pointer to edma_handle_t.
|
||||
* @param edmaIntermediaryToTxRegHandle edmaIntermediaryToTxRegHandle pointer to edma_handle_t.
|
||||
*/
|
||||
void DSPI_MasterTransferCreateHandleEDMA(SPI_Type *base,
|
||||
dspi_master_edma_handle_t *handle,
|
||||
dspi_master_edma_transfer_callback_t callback,
|
||||
void *userData,
|
||||
edma_handle_t *edmaRxRegToRxDataHandle,
|
||||
edma_handle_t *edmaTxDataToIntermediaryHandle,
|
||||
edma_handle_t *edmaIntermediaryToTxRegHandle);
|
||||
|
||||
/*!
|
||||
* @brief DSPI master transfer data using eDMA.
|
||||
*
|
||||
* This function transfer data using eDMA. This is non-blocking function, which returns right away. When all data
|
||||
* have been transfer, the callback function is called.
|
||||
*
|
||||
* @param base DSPI peripheral base address.
|
||||
* @param handle pointer to dspi_master_edma_handle_t structure which stores the transfer state.
|
||||
* @param transfer pointer to dspi_transfer_t structure.
|
||||
* @return status of status_t.
|
||||
*/
|
||||
status_t DSPI_MasterTransferEDMA(SPI_Type *base, dspi_master_edma_handle_t *handle, dspi_transfer_t *transfer);
|
||||
|
||||
/*!
|
||||
* @brief DSPI master aborts a transfer which using eDMA.
|
||||
*
|
||||
* This function aborts a transfer which using eDMA.
|
||||
*
|
||||
* @param base DSPI peripheral base address.
|
||||
* @param handle pointer to dspi_master_edma_handle_t structure which stores the transfer state.
|
||||
*/
|
||||
void DSPI_MasterTransferAbortEDMA(SPI_Type *base, dspi_master_edma_handle_t *handle);
|
||||
|
||||
/*!
|
||||
* @brief Gets the master eDMA transfer count.
|
||||
*
|
||||
* This function get the master eDMA transfer count.
|
||||
*
|
||||
* @param base DSPI peripheral base address.
|
||||
* @param handle pointer to dspi_master_edma_handle_t structure which stores the transfer state.
|
||||
* @param count Number of bytes transferred so far by the non-blocking transaction.
|
||||
* @return status of status_t.
|
||||
*/
|
||||
status_t DSPI_MasterTransferGetCountEDMA(SPI_Type *base, dspi_master_edma_handle_t *handle, size_t *count);
|
||||
|
||||
/*!
|
||||
* @brief Initializes the DSPI slave eDMA handle.
|
||||
*
|
||||
* This function initializes the DSPI eDMA handle which can be used for other DSPI transactional APIs. Usually, for a
|
||||
* specified DSPI instance, call this API once to get the initialized handle.
|
||||
*
|
||||
* Note that DSPI eDMA has separated (RN and TX in 2 sources) or shared (RX and TX are the same source) DMA request source.
|
||||
* (1)For the separated DMA request source, enable and set the RX DMAMUX source for edmaRxRegToRxDataHandle and
|
||||
* TX DMAMUX source for edmaTxDataToTxRegHandle.
|
||||
* (2)For the shared DMA request source, enable and set the RX/RX DMAMUX source for the edmaRxRegToRxDataHandle.
|
||||
*
|
||||
* @param base DSPI peripheral base address.
|
||||
* @param handle DSPI handle pointer to dspi_slave_edma_handle_t.
|
||||
* @param callback DSPI callback.
|
||||
* @param userData callback function parameter.
|
||||
* @param edmaRxRegToRxDataHandle edmaRxRegToRxDataHandle pointer to edma_handle_t.
|
||||
* @param edmaTxDataToTxRegHandle edmaTxDataToTxRegHandle pointer to edma_handle_t.
|
||||
*/
|
||||
void DSPI_SlaveTransferCreateHandleEDMA(SPI_Type *base,
|
||||
dspi_slave_edma_handle_t *handle,
|
||||
dspi_slave_edma_transfer_callback_t callback,
|
||||
void *userData,
|
||||
edma_handle_t *edmaRxRegToRxDataHandle,
|
||||
edma_handle_t *edmaTxDataToTxRegHandle);
|
||||
|
||||
/*!
|
||||
* @brief DSPI slave transfer data using eDMA.
|
||||
*
|
||||
* This function transfer data using eDMA. This is non-blocking function, which returns right away. When all data
|
||||
* have been transfer, the callback function is called.
|
||||
* Note that slave EDMA transfer cannot support the situation that transfer_size is 1 when the bitsPerFrame is greater
|
||||
* than 8 .
|
||||
|
||||
* @param base DSPI peripheral base address.
|
||||
* @param handle pointer to dspi_slave_edma_handle_t structure which stores the transfer state.
|
||||
* @param transfer pointer to dspi_transfer_t structure.
|
||||
* @return status of status_t.
|
||||
*/
|
||||
status_t DSPI_SlaveTransferEDMA(SPI_Type *base, dspi_slave_edma_handle_t *handle, dspi_transfer_t *transfer);
|
||||
|
||||
/*!
|
||||
* @brief DSPI slave aborts a transfer which using eDMA.
|
||||
*
|
||||
* This function aborts a transfer which using eDMA.
|
||||
*
|
||||
* @param base DSPI peripheral base address.
|
||||
* @param handle pointer to dspi_slave_edma_handle_t structure which stores the transfer state.
|
||||
*/
|
||||
void DSPI_SlaveTransferAbortEDMA(SPI_Type *base, dspi_slave_edma_handle_t *handle);
|
||||
|
||||
/*!
|
||||
* @brief Gets the slave eDMA transfer count.
|
||||
*
|
||||
* This function gets the slave eDMA transfer count.
|
||||
*
|
||||
* @param base DSPI peripheral base address.
|
||||
* @param handle pointer to dspi_slave_edma_handle_t structure which stores the transfer state.
|
||||
* @param count Number of bytes transferred so far by the non-blocking transaction.
|
||||
* @return status of status_t.
|
||||
*/
|
||||
status_t DSPI_SlaveTransferGetCountEDMA(SPI_Type *base, dspi_slave_edma_handle_t *handle, size_t *count);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /*_cplusplus*/
|
||||
/*!
|
||||
*@}
|
||||
*/
|
||||
|
||||
#endif /*_FSL_DSPI_EDMA_H_*/
|
||||
1313
devices/MK22F51212/drivers/fsl_edma.c
Normal file
1313
devices/MK22F51212/drivers/fsl_edma.c
Normal file
File diff suppressed because it is too large
Load Diff
879
devices/MK22F51212/drivers/fsl_edma.h
Normal file
879
devices/MK22F51212/drivers/fsl_edma.h
Normal file
File diff suppressed because it is too large
Load Diff
92
devices/MK22F51212/drivers/fsl_ewm.c
Normal file
92
devices/MK22F51212/drivers/fsl_ewm.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_ewm.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
void EWM_Init(EWM_Type *base, const ewm_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
uint32_t value = 0U;
|
||||
|
||||
CLOCK_EnableClock(kCLOCK_Ewm0);
|
||||
value = EWM_CTRL_EWMEN(config->enableEwm) | EWM_CTRL_ASSIN(config->setInputAssertLogic) |
|
||||
EWM_CTRL_INEN(config->enableEwmInput) | EWM_CTRL_INTEN(config->enableInterrupt);
|
||||
#if defined(FSL_FEATURE_EWM_HAS_PRESCALER) && FSL_FEATURE_EWM_HAS_PRESCALER
|
||||
base->CLKPRESCALER = config->prescaler;
|
||||
#endif /* FSL_FEATURE_EWM_HAS_PRESCALER */
|
||||
|
||||
#if defined(FSL_FEATURE_EWM_HAS_CLOCK_SELECT) && FSL_FEATURE_EWM_HAS_CLOCK_SELECT
|
||||
base->CLKCTRL = config->clockSource;
|
||||
#endif /* FSL_FEATURE_EWM_HAS_CLOCK_SELECT*/
|
||||
|
||||
base->CMPL = config->compareLowValue;
|
||||
base->CMPH = config->compareHighValue;
|
||||
base->CTRL = value;
|
||||
}
|
||||
|
||||
void EWM_Deinit(EWM_Type *base)
|
||||
{
|
||||
EWM_DisableInterrupts(base, kEWM_InterruptEnable);
|
||||
CLOCK_DisableClock(kCLOCK_Ewm0);
|
||||
}
|
||||
|
||||
void EWM_GetDefaultConfig(ewm_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
config->enableEwm = true;
|
||||
config->enableEwmInput = false;
|
||||
config->setInputAssertLogic = false;
|
||||
config->enableInterrupt = false;
|
||||
#if defined(FSL_FEATURE_EWM_HAS_CLOCK_SELECT) && FSL_FEATURE_EWM_HAS_CLOCK_SELECT
|
||||
config->clockSource = kEWM_LpoClockSource0;
|
||||
#endif /* FSL_FEATURE_EWM_HAS_CLOCK_SELECT*/
|
||||
#if defined(FSL_FEATURE_EWM_HAS_PRESCALER) && FSL_FEATURE_EWM_HAS_PRESCALER
|
||||
config->prescaler = 0U;
|
||||
#endif /* FSL_FEATURE_EWM_HAS_PRESCALER */
|
||||
config->compareLowValue = 0U;
|
||||
config->compareHighValue = 0xFEU;
|
||||
}
|
||||
|
||||
void EWM_Refresh(EWM_Type *base)
|
||||
{
|
||||
uint32_t primaskValue = 0U;
|
||||
|
||||
/* Disable the global interrupt to protect refresh sequence */
|
||||
primaskValue = DisableGlobalIRQ();
|
||||
base->SERV = (uint8_t)0xB4U;
|
||||
base->SERV = (uint8_t)0x2CU;
|
||||
EnableGlobalIRQ(primaskValue);
|
||||
}
|
||||
242
devices/MK22F51212/drivers/fsl_ewm.h
Normal file
242
devices/MK22F51212/drivers/fsl_ewm.h
Normal file
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_EWM_H_
|
||||
#define _FSL_EWM_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup ewm_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
*******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief EWM driver version 2.0.1. */
|
||||
#define FSL_EWM_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
|
||||
/*@}*/
|
||||
|
||||
/*! @brief Describes ewm clock source. */
|
||||
#if defined(FSL_FEATURE_EWM_HAS_CLOCK_SELECT) && FSL_FEATURE_EWM_HAS_CLOCK_SELECT
|
||||
typedef enum _ewm_lpo_clock_source
|
||||
{
|
||||
kEWM_LpoClockSource0 = 0U, /*!< ewm clock sourced from lpo_clk[0]*/
|
||||
kEWM_LpoClockSource1 = 1U, /*!< ewm clock sourced from lpo_clk[1]*/
|
||||
kEWM_LpoClockSource2 = 2U, /*!< ewm clock sourced from lpo_clk[2]*/
|
||||
kEWM_LpoClockSource3 = 3U, /*!< ewm clock sourced from lpo_clk[3]*/
|
||||
} ewm_lpo_clock_source_t;
|
||||
#endif /* FSL_FEATURE_EWM_HAS_CLOCK_SELECT */
|
||||
|
||||
/*!
|
||||
* @brief Data structure for EWM configuration.
|
||||
*
|
||||
* This structure is used to configure the EWM.
|
||||
*/
|
||||
typedef struct _ewm_config
|
||||
{
|
||||
bool enableEwm; /*!< Enable EWM module */
|
||||
bool enableEwmInput; /*!< Enable EWM_in input */
|
||||
bool setInputAssertLogic; /*!< EWM_in signal assertion state */
|
||||
bool enableInterrupt; /*!< Enable EWM interrupt */
|
||||
#if defined(FSL_FEATURE_EWM_HAS_CLOCK_SELECT) && FSL_FEATURE_EWM_HAS_CLOCK_SELECT
|
||||
ewm_lpo_clock_source_t clockSource; /*!< Clock source select */
|
||||
#endif /* FSL_FEATURE_EWM_HAS_CLOCK_SELECT */
|
||||
#if defined(FSL_FEATURE_EWM_HAS_PRESCALER) && FSL_FEATURE_EWM_HAS_PRESCALER
|
||||
uint8_t prescaler; /*!< Clock prescaler value */
|
||||
#endif /* FSL_FEATURE_EWM_HAS_PRESCALER */
|
||||
uint8_t compareLowValue; /*!< Compare low register value */
|
||||
uint8_t compareHighValue; /*!< Compare high register value */
|
||||
} ewm_config_t;
|
||||
|
||||
/*!
|
||||
* @brief EWM interrupt configuration structure, default settings all disabled.
|
||||
*
|
||||
* This structure contains the settings for all of the EWM interrupt configurations.
|
||||
*/
|
||||
enum _ewm_interrupt_enable_t
|
||||
{
|
||||
kEWM_InterruptEnable = EWM_CTRL_INTEN_MASK, /*!< Enable EWM to generate an interrupt*/
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief EWM status flags.
|
||||
*
|
||||
* This structure contains the constants for the EWM status flags for use in the EWM functions.
|
||||
*/
|
||||
enum _ewm_status_flags_t
|
||||
{
|
||||
kEWM_RunningFlag = EWM_CTRL_EWMEN_MASK, /*!< Running flag, set when ewm is enabled*/
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
*******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*!
|
||||
* @name EWM Initialization and De-initialization
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes the EWM peripheral.
|
||||
*
|
||||
* This function is used to initialize the EWM. After calling, the EWM
|
||||
* runs immediately according to the configuration.
|
||||
* Note that except for interrupt enable control bit, other control bits and registers are write once after a
|
||||
* CPU reset. Modifying them more than once generates a bus transfer error.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* ewm_config_t config;
|
||||
* EWM_GetDefaultConfig(&config);
|
||||
* config.compareHighValue = 0xAAU;
|
||||
* EWM_Init(ewm_base,&config);
|
||||
* @endcode
|
||||
*
|
||||
* @param base EWM peripheral base address
|
||||
* @param config The configuration of EWM
|
||||
*/
|
||||
void EWM_Init(EWM_Type *base, const ewm_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Deinitializes the EWM peripheral.
|
||||
*
|
||||
* This function is used to shut down the EWM.
|
||||
*
|
||||
* @param base EWM peripheral base address
|
||||
*/
|
||||
void EWM_Deinit(EWM_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Initializes the EWM configuration structure.
|
||||
*
|
||||
* This function initializes the EWM configure structure to default values. The default
|
||||
* values are:
|
||||
* @code
|
||||
* ewmConfig->enableEwm = true;
|
||||
* ewmConfig->enableEwmInput = false;
|
||||
* ewmConfig->setInputAssertLogic = false;
|
||||
* ewmConfig->enableInterrupt = false;
|
||||
* ewmConfig->ewm_lpo_clock_source_t = kEWM_LpoClockSource0;
|
||||
* ewmConfig->prescaler = 0;
|
||||
* ewmConfig->compareLowValue = 0;
|
||||
* ewmConfig->compareHighValue = 0xFEU;
|
||||
* @endcode
|
||||
*
|
||||
* @param config Pointer to EWM configuration structure.
|
||||
* @see ewm_config_t
|
||||
*/
|
||||
void EWM_GetDefaultConfig(ewm_config_t *config);
|
||||
|
||||
/* @} */
|
||||
|
||||
/*!
|
||||
* @name EWM functional Operation
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Enables the EWM interrupt.
|
||||
*
|
||||
* This function enables the EWM interrupt.
|
||||
*
|
||||
* @param base EWM peripheral base address
|
||||
* @param mask The interrupts to enable
|
||||
* The parameter can be combination of the following source if defined:
|
||||
* @arg kEWM_InterruptEnable
|
||||
*/
|
||||
static inline void EWM_EnableInterrupts(EWM_Type *base, uint32_t mask)
|
||||
{
|
||||
base->CTRL |= mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disables the EWM interrupt.
|
||||
*
|
||||
* This function enables the EWM interrupt.
|
||||
*
|
||||
* @param base EWM peripheral base address
|
||||
* @param mask The interrupts to disable
|
||||
* The parameter can be combination of the following source if defined:
|
||||
* @arg kEWM_InterruptEnable
|
||||
*/
|
||||
static inline void EWM_DisableInterrupts(EWM_Type *base, uint32_t mask)
|
||||
{
|
||||
base->CTRL &= ~mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets EWM all status flags.
|
||||
*
|
||||
* This function gets all status flags.
|
||||
*
|
||||
* Example for getting Running Flag:
|
||||
* @code
|
||||
* uint32_t status;
|
||||
* status = EWM_GetStatusFlags(ewm_base) & kEWM_RunningFlag;
|
||||
* @endcode
|
||||
* @param base EWM peripheral base address
|
||||
* @return State of the status flag: asserted (true) or not-asserted (false).@see _ewm_status_flags_t
|
||||
* - true: related status flag has been set.
|
||||
* - false: related status flag is not set.
|
||||
*/
|
||||
static inline uint32_t EWM_GetStatusFlags(EWM_Type *base)
|
||||
{
|
||||
return (base->CTRL & EWM_CTRL_EWMEN_MASK);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Service EWM.
|
||||
*
|
||||
* This function reset EWM counter to zero.
|
||||
*
|
||||
* @param base EWM peripheral base address
|
||||
*/
|
||||
void EWM_Refresh(EWM_Type *base);
|
||||
|
||||
/*@}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_EWM_H_ */
|
||||
2610
devices/MK22F51212/drivers/fsl_flash.c
Normal file
2610
devices/MK22F51212/drivers/fsl_flash.c
Normal file
File diff suppressed because it is too large
Load Diff
1177
devices/MK22F51212/drivers/fsl_flash.h
Normal file
1177
devices/MK22F51212/drivers/fsl_flash.h
Normal file
File diff suppressed because it is too large
Load Diff
196
devices/MK22F51212/drivers/fsl_flexbus.c
Normal file
196
devices/MK22F51212/drivers/fsl_flexbus.c
Normal file
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_flexbus.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Gets the instance from the base address
|
||||
*
|
||||
* @param base FLEXBUS peripheral base address
|
||||
*
|
||||
* @return The FLEXBUS instance
|
||||
*/
|
||||
static uint32_t FLEXBUS_GetInstance(FB_Type *base);
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief Pointers to FLEXBUS bases for each instance. */
|
||||
static FB_Type *const s_flexbusBases[] = FB_BASE_PTRS;
|
||||
|
||||
/*! @brief Pointers to FLEXBUS clocks for each instance. */
|
||||
static const clock_ip_name_t s_flexbusClocks[] = FLEXBUS_CLOCKS;
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
static uint32_t FLEXBUS_GetInstance(FB_Type *base)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
/* Find the instance index from base address mappings. */
|
||||
for (instance = 0; instance < FSL_FEATURE_SOC_FB_COUNT; instance++)
|
||||
{
|
||||
if (s_flexbusBases[instance] == base)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(instance < FSL_FEATURE_SOC_FB_COUNT);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void FLEXBUS_Init(FB_Type *base, const flexbus_config_t *config)
|
||||
{
|
||||
assert(config != NULL);
|
||||
assert(config->chip < FB_CSAR_COUNT);
|
||||
assert(config->waitStates <= 0x3FU);
|
||||
|
||||
uint32_t chip = 0;
|
||||
uint32_t reg_value = 0;
|
||||
|
||||
/* Ungate clock for FLEXBUS */
|
||||
CLOCK_EnableClock(s_flexbusClocks[FLEXBUS_GetInstance(base)]);
|
||||
|
||||
/* Reset all the register to default state */
|
||||
for (chip = 0; chip < FB_CSAR_COUNT; chip++)
|
||||
{
|
||||
/* Reset CSMR register, all chips not valid (disabled) */
|
||||
base->CS[chip].CSMR = 0x0000U;
|
||||
/* Set default base address */
|
||||
base->CS[chip].CSAR &= (~FB_CSAR_BA_MASK);
|
||||
/* Reset FB_CSCRx register */
|
||||
base->CS[chip].CSCR = 0x0000U;
|
||||
}
|
||||
/* Set FB_CSPMCR register */
|
||||
/* FlexBus signal group 1 multiplex control */
|
||||
reg_value |= kFLEXBUS_MultiplexGroup1_FB_ALE << FB_CSPMCR_GROUP1_SHIFT;
|
||||
/* FlexBus signal group 2 multiplex control */
|
||||
reg_value |= kFLEXBUS_MultiplexGroup2_FB_CS4 << FB_CSPMCR_GROUP2_SHIFT;
|
||||
/* FlexBus signal group 3 multiplex control */
|
||||
reg_value |= kFLEXBUS_MultiplexGroup3_FB_CS5 << FB_CSPMCR_GROUP3_SHIFT;
|
||||
/* FlexBus signal group 4 multiplex control */
|
||||
reg_value |= kFLEXBUS_MultiplexGroup4_FB_TBST << FB_CSPMCR_GROUP4_SHIFT;
|
||||
/* FlexBus signal group 5 multiplex control */
|
||||
reg_value |= kFLEXBUS_MultiplexGroup5_FB_TA << FB_CSPMCR_GROUP5_SHIFT;
|
||||
/* Write to CSPMCR register */
|
||||
base->CSPMCR = reg_value;
|
||||
|
||||
/* Update chip value */
|
||||
chip = config->chip;
|
||||
|
||||
/* Base address */
|
||||
reg_value = config->chipBaseAddress;
|
||||
/* Write to CSAR register */
|
||||
base->CS[chip].CSAR = reg_value;
|
||||
/* Chip-select validation */
|
||||
reg_value = 0x1U << FB_CSMR_V_SHIFT;
|
||||
/* Write protect */
|
||||
reg_value |= (uint32_t)(config->writeProtect) << FB_CSMR_WP_SHIFT;
|
||||
/* Base address mask */
|
||||
reg_value |= config->chipBaseAddressMask << FB_CSMR_BAM_SHIFT;
|
||||
/* Write to CSMR register */
|
||||
base->CS[chip].CSMR = reg_value;
|
||||
/* Burst write */
|
||||
reg_value = (uint32_t)(config->burstWrite) << FB_CSCR_BSTW_SHIFT;
|
||||
/* Burst read */
|
||||
reg_value |= (uint32_t)(config->burstRead) << FB_CSCR_BSTR_SHIFT;
|
||||
/* Byte-enable mode */
|
||||
reg_value |= (uint32_t)(config->byteEnableMode) << FB_CSCR_BEM_SHIFT;
|
||||
/* Port size */
|
||||
reg_value |= (uint32_t)config->portSize << FB_CSCR_PS_SHIFT;
|
||||
/* The internal transfer acknowledge for accesses */
|
||||
reg_value |= (uint32_t)(config->autoAcknowledge) << FB_CSCR_AA_SHIFT;
|
||||
/* Byte-Lane shift */
|
||||
reg_value |= (uint32_t)config->byteLaneShift << FB_CSCR_BLS_SHIFT;
|
||||
/* The number of wait states */
|
||||
reg_value |= (uint32_t)config->waitStates << FB_CSCR_WS_SHIFT;
|
||||
/* Write address hold or deselect */
|
||||
reg_value |= (uint32_t)config->writeAddressHold << FB_CSCR_WRAH_SHIFT;
|
||||
/* Read address hold or deselect */
|
||||
reg_value |= (uint32_t)config->readAddressHold << FB_CSCR_RDAH_SHIFT;
|
||||
/* Address setup */
|
||||
reg_value |= (uint32_t)config->addressSetup << FB_CSCR_ASET_SHIFT;
|
||||
/* Extended transfer start/extended address latch */
|
||||
reg_value |= (uint32_t)(config->extendTransferAddress) << FB_CSCR_EXTS_SHIFT;
|
||||
/* Secondary wait state */
|
||||
reg_value |= (uint32_t)(config->secondaryWaitStates) << FB_CSCR_SWSEN_SHIFT;
|
||||
/* Write to CSCR register */
|
||||
base->CS[chip].CSCR = reg_value;
|
||||
/* FlexBus signal group 1 multiplex control */
|
||||
reg_value = (uint32_t)config->group1MultiplexControl << FB_CSPMCR_GROUP1_SHIFT;
|
||||
/* FlexBus signal group 2 multiplex control */
|
||||
reg_value |= (uint32_t)config->group2MultiplexControl << FB_CSPMCR_GROUP2_SHIFT;
|
||||
/* FlexBus signal group 3 multiplex control */
|
||||
reg_value |= (uint32_t)config->group3MultiplexControl << FB_CSPMCR_GROUP3_SHIFT;
|
||||
/* FlexBus signal group 4 multiplex control */
|
||||
reg_value |= (uint32_t)config->group4MultiplexControl << FB_CSPMCR_GROUP4_SHIFT;
|
||||
/* FlexBus signal group 5 multiplex control */
|
||||
reg_value |= (uint32_t)config->group5MultiplexControl << FB_CSPMCR_GROUP5_SHIFT;
|
||||
/* Write to CSPMCR register */
|
||||
base->CSPMCR = reg_value;
|
||||
}
|
||||
|
||||
void FLEXBUS_Deinit(FB_Type *base)
|
||||
{
|
||||
/* Gate clock for FLEXBUS */
|
||||
CLOCK_EnableClock(s_flexbusClocks[FLEXBUS_GetInstance(base)]);
|
||||
}
|
||||
|
||||
void FLEXBUS_GetDefaultConfig(flexbus_config_t *config)
|
||||
{
|
||||
config->chip = 0; /* Chip 0 FlexBus for validation */
|
||||
config->writeProtect = 0; /* Write accesses are allowed */
|
||||
config->burstWrite = 0; /* Burst-Write disable */
|
||||
config->burstRead = 0; /* Burst-Read disable */
|
||||
config->byteEnableMode = 0; /* Byte-Enable mode is asserted for data write only */
|
||||
config->autoAcknowledge = true; /* Auto-Acknowledge enable */
|
||||
config->extendTransferAddress = 0; /* Extend transfer start/extend address latch disable */
|
||||
config->secondaryWaitStates = 0; /* Secondary wait state disable */
|
||||
config->byteLaneShift = kFLEXBUS_NotShifted; /* Byte-Lane shift disable */
|
||||
config->writeAddressHold = kFLEXBUS_Hold1Cycle; /* Write address hold 1 cycles */
|
||||
config->readAddressHold = kFLEXBUS_Hold1Or0Cycles; /* Read address hold 0 cycles */
|
||||
config->addressSetup =
|
||||
kFLEXBUS_FirstRisingEdge; /* Assert ~FB_CSn on the first rising clock edge after the address is asserted */
|
||||
config->portSize = kFLEXBUS_1Byte; /* 1 byte port size of transfer */
|
||||
config->group1MultiplexControl = kFLEXBUS_MultiplexGroup1_FB_ALE; /* FB_ALE */
|
||||
config->group2MultiplexControl = kFLEXBUS_MultiplexGroup2_FB_CS4; /* FB_CS4 */
|
||||
config->group3MultiplexControl = kFLEXBUS_MultiplexGroup3_FB_CS5; /* FB_CS5 */
|
||||
config->group4MultiplexControl = kFLEXBUS_MultiplexGroup4_FB_TBST; /* FB_TBST */
|
||||
config->group5MultiplexControl = kFLEXBUS_MultiplexGroup5_FB_TA; /* FB_TA */
|
||||
}
|
||||
266
devices/MK22F51212/drivers/fsl_flexbus.h
Normal file
266
devices/MK22F51212/drivers/fsl_flexbus.h
Normal file
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FSL_FLEXBUS_H_
|
||||
#define _FSL_FLEXBUS_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup flexbus
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
#define FSL_FLEXBUS_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0. */
|
||||
/*@}*/
|
||||
|
||||
/*!
|
||||
* @brief Defines port size for FlexBus peripheral.
|
||||
*/
|
||||
typedef enum _flexbus_port_size
|
||||
{
|
||||
kFLEXBUS_4Bytes = 0x00U, /*!< 32-bit port size */
|
||||
kFLEXBUS_1Byte = 0x01U, /*!< 8-bit port size */
|
||||
kFLEXBUS_2Bytes = 0x02U /*!< 16-bit port size */
|
||||
} flexbus_port_size_t;
|
||||
|
||||
/*!
|
||||
* @brief Defines number of cycles to hold address and attributes for FlexBus peripheral.
|
||||
*/
|
||||
typedef enum _flexbus_write_address_hold
|
||||
{
|
||||
kFLEXBUS_Hold1Cycle = 0x00U, /*!< Hold address and attributes one cycles after FB_CSn negates on writes */
|
||||
kFLEXBUS_Hold2Cycles = 0x01U, /*!< Hold address and attributes two cycles after FB_CSn negates on writes */
|
||||
kFLEXBUS_Hold3Cycles = 0x02U, /*!< Hold address and attributes three cycles after FB_CSn negates on writes */
|
||||
kFLEXBUS_Hold4Cycles = 0x03U /*!< Hold address and attributes four cycles after FB_CSn negates on writes */
|
||||
} flexbus_write_address_hold_t;
|
||||
|
||||
/*!
|
||||
* @brief Defines number of cycles to hold address and attributes for FlexBus peripheral.
|
||||
*/
|
||||
typedef enum _flexbus_read_address_hold
|
||||
{
|
||||
kFLEXBUS_Hold1Or0Cycles = 0x00U, /*!< Hold address and attributes 1 or 0 cycles on reads */
|
||||
kFLEXBUS_Hold2Or1Cycles = 0x01U, /*!< Hold address and attributes 2 or 1 cycles on reads */
|
||||
kFLEXBUS_Hold3Or2Cycle = 0x02U, /*!< Hold address and attributes 3 or 2 cycles on reads */
|
||||
kFLEXBUS_Hold4Or3Cycle = 0x03U /*!< Hold address and attributes 4 or 3 cycles on reads */
|
||||
} flexbus_read_address_hold_t;
|
||||
|
||||
/*!
|
||||
* @brief Address setup for FlexBus peripheral.
|
||||
*/
|
||||
typedef enum _flexbus_address_setup
|
||||
{
|
||||
kFLEXBUS_FirstRisingEdge = 0x00U, /*!< Assert FB_CSn on first rising clock edge after address is asserted */
|
||||
kFLEXBUS_SecondRisingEdge = 0x01U, /*!< Assert FB_CSn on second rising clock edge after address is asserted */
|
||||
kFLEXBUS_ThirdRisingEdge = 0x02U, /*!< Assert FB_CSn on third rising clock edge after address is asserted */
|
||||
kFLEXBUS_FourthRisingEdge = 0x03U, /*!< Assert FB_CSn on fourth rising clock edge after address is asserted */
|
||||
} flexbus_address_setup_t;
|
||||
|
||||
/*!
|
||||
* @brief Defines byte-lane shift for FlexBus peripheral.
|
||||
*/
|
||||
typedef enum _flexbus_bytelane_shift
|
||||
{
|
||||
kFLEXBUS_NotShifted = 0x00U, /*!< Not shifted. Data is left-justified on FB_AD */
|
||||
kFLEXBUS_Shifted = 0x01U, /*!< Shifted. Data is right justified on FB_AD */
|
||||
} flexbus_bytelane_shift_t;
|
||||
|
||||
/*!
|
||||
* @brief Defines multiplex group1 valid signals.
|
||||
*/
|
||||
typedef enum _flexbus_multiplex_group1_signal
|
||||
{
|
||||
kFLEXBUS_MultiplexGroup1_FB_ALE = 0x00U, /*!< FB_ALE */
|
||||
kFLEXBUS_MultiplexGroup1_FB_CS1 = 0x01U, /*!< FB_CS1 */
|
||||
kFLEXBUS_MultiplexGroup1_FB_TS = 0x02U, /*!< FB_TS */
|
||||
} flexbus_multiplex_group1_t;
|
||||
|
||||
/*!
|
||||
* @brief Defines multiplex group2 valid signals.
|
||||
*/
|
||||
typedef enum _flexbus_multiplex_group2_signal
|
||||
{
|
||||
kFLEXBUS_MultiplexGroup2_FB_CS4 = 0x00U, /*!< FB_CS4 */
|
||||
kFLEXBUS_MultiplexGroup2_FB_TSIZ0 = 0x01U, /*!< FB_TSIZ0 */
|
||||
kFLEXBUS_MultiplexGroup2_FB_BE_31_24 = 0x02U, /*!< FB_BE_31_24 */
|
||||
} flexbus_multiplex_group2_t;
|
||||
|
||||
/*!
|
||||
* @brief Defines multiplex group3 valid signals.
|
||||
*/
|
||||
typedef enum _flexbus_multiplex_group3_signal
|
||||
{
|
||||
kFLEXBUS_MultiplexGroup3_FB_CS5 = 0x00U, /*!< FB_CS5 */
|
||||
kFLEXBUS_MultiplexGroup3_FB_TSIZ1 = 0x01U, /*!< FB_TSIZ1 */
|
||||
kFLEXBUS_MultiplexGroup3_FB_BE_23_16 = 0x02U, /*!< FB_BE_23_16 */
|
||||
} flexbus_multiplex_group3_t;
|
||||
|
||||
/*!
|
||||
* @brief Defines multiplex group4 valid signals.
|
||||
*/
|
||||
typedef enum _flexbus_multiplex_group4_signal
|
||||
{
|
||||
kFLEXBUS_MultiplexGroup4_FB_TBST = 0x00U, /*!< FB_TBST */
|
||||
kFLEXBUS_MultiplexGroup4_FB_CS2 = 0x01U, /*!< FB_CS2 */
|
||||
kFLEXBUS_MultiplexGroup4_FB_BE_15_8 = 0x02U, /*!< FB_BE_15_8 */
|
||||
} flexbus_multiplex_group4_t;
|
||||
|
||||
/*!
|
||||
* @brief Defines multiplex group5 valid signals.
|
||||
*/
|
||||
typedef enum _flexbus_multiplex_group5_signal
|
||||
{
|
||||
kFLEXBUS_MultiplexGroup5_FB_TA = 0x00U, /*!< FB_TA */
|
||||
kFLEXBUS_MultiplexGroup5_FB_CS3 = 0x01U, /*!< FB_CS3 */
|
||||
kFLEXBUS_MultiplexGroup5_FB_BE_7_0 = 0x02U, /*!< FB_BE_7_0 */
|
||||
} flexbus_multiplex_group5_t;
|
||||
|
||||
/*!
|
||||
* @brief Configuration structure that the user needs to set.
|
||||
*/
|
||||
typedef struct _flexbus_config
|
||||
{
|
||||
uint8_t chip; /*!< Chip FlexBus for validation */
|
||||
uint8_t waitStates; /*!< Value of wait states */
|
||||
uint32_t chipBaseAddress; /*!< Chip base address for using FlexBus */
|
||||
uint32_t chipBaseAddressMask; /*!< Chip base address mask */
|
||||
bool writeProtect; /*!< Write protected */
|
||||
bool burstWrite; /*!< Burst-Write enable */
|
||||
bool burstRead; /*!< Burst-Read enable */
|
||||
bool byteEnableMode; /*!< Byte-enable mode support */
|
||||
bool autoAcknowledge; /*!< Auto acknowledge setting */
|
||||
bool extendTransferAddress; /*!< Extend transfer start/extend address latch enable */
|
||||
bool secondaryWaitStates; /*!< Secondary wait states number */
|
||||
flexbus_port_size_t portSize; /*!< Port size of transfer */
|
||||
flexbus_bytelane_shift_t byteLaneShift; /*!< Byte-lane shift enable */
|
||||
flexbus_write_address_hold_t writeAddressHold; /*!< Write address hold or deselect option */
|
||||
flexbus_read_address_hold_t readAddressHold; /*!< Read address hold or deselect option */
|
||||
flexbus_address_setup_t addressSetup; /*!< Address setup setting */
|
||||
flexbus_multiplex_group1_t group1MultiplexControl; /*!< FlexBus Signal Group 1 Multiplex control */
|
||||
flexbus_multiplex_group2_t group2MultiplexControl; /*!< FlexBus Signal Group 2 Multiplex control */
|
||||
flexbus_multiplex_group3_t group3MultiplexControl; /*!< FlexBus Signal Group 3 Multiplex control */
|
||||
flexbus_multiplex_group4_t group4MultiplexControl; /*!< FlexBus Signal Group 4 Multiplex control */
|
||||
flexbus_multiplex_group5_t group5MultiplexControl; /*!< FlexBus Signal Group 5 Multiplex control */
|
||||
} flexbus_config_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*!
|
||||
* @name FlexBus functional operation
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes and configures the FlexBus module.
|
||||
*
|
||||
* This function enables the clock gate for FlexBus module.
|
||||
* Only chip 0 is validated and set to known values. Other chips are disabled.
|
||||
* NOTE: In this function, certain parameters, depending on external memories, must
|
||||
* be set before using FLEXBUS_Init() function.
|
||||
* This example shows how to set up the uart_state_t and the
|
||||
* flexbus_config_t parameters and how to call the FLEXBUS_Init function by passing
|
||||
* in these parameters:
|
||||
@code
|
||||
flexbus_config_t flexbusConfig;
|
||||
FLEXBUS_GetDefaultConfig(&flexbusConfig);
|
||||
flexbusConfig.waitStates = 2U;
|
||||
flexbusConfig.chipBaseAddress = 0x60000000U;
|
||||
flexbusConfig.chipBaseAddressMask = 7U;
|
||||
FLEXBUS_Init(FB, &flexbusConfig);
|
||||
@endcode
|
||||
*
|
||||
* @param base FlexBus peripheral address.
|
||||
* @param config Pointer to the configure structure
|
||||
*/
|
||||
void FLEXBUS_Init(FB_Type *base, const flexbus_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief De-initializes a FlexBus instance.
|
||||
*
|
||||
* This function disables the clock gate of the FlexBus module clock.
|
||||
*
|
||||
* @param base FlexBus peripheral address.
|
||||
*/
|
||||
void FLEXBUS_Deinit(FB_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Initializes the FlexBus configuration structure.
|
||||
*
|
||||
* This function initializes the FlexBus configuration structure to default value. The default
|
||||
* values are:
|
||||
@code
|
||||
fbConfig->chip = 0;
|
||||
fbConfig->writeProtect = 0;
|
||||
fbConfig->burstWrite = 0;
|
||||
fbConfig->burstRead = 0;
|
||||
fbConfig->byteEnableMode = 0;
|
||||
fbConfig->autoAcknowledge = true;
|
||||
fbConfig->extendTransferAddress = 0;
|
||||
fbConfig->secondaryWaitStates = 0;
|
||||
fbConfig->byteLaneShift = kFLEXBUS_NotShifted;
|
||||
fbConfig->writeAddressHold = kFLEXBUS_Hold1Cycle;
|
||||
fbConfig->readAddressHold = kFLEXBUS_Hold1Or0Cycles;
|
||||
fbConfig->addressSetup = kFLEXBUS_FirstRisingEdge;
|
||||
fbConfig->portSize = kFLEXBUS_1Byte;
|
||||
fbConfig->group1MultiplexControl = kFLEXBUS_MultiplexGroup1_FB_ALE;
|
||||
fbConfig->group2MultiplexControl = kFLEXBUS_MultiplexGroup2_FB_CS4 ;
|
||||
fbConfig->group3MultiplexControl = kFLEXBUS_MultiplexGroup3_FB_CS5;
|
||||
fbConfig->group4MultiplexControl = kFLEXBUS_MultiplexGroup4_FB_TBST;
|
||||
fbConfig->group5MultiplexControl = kFLEXBUS_MultiplexGroup5_FB_TA;
|
||||
@endcode
|
||||
* @param config Pointer to the initialization structure.
|
||||
* @see FLEXBUS_Init
|
||||
*/
|
||||
void FLEXBUS_GetDefaultConfig(flexbus_config_t *config);
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_FLEXBUS_H_ */
|
||||
876
devices/MK22F51212/drivers/fsl_ftm.c
Normal file
876
devices/MK22F51212/drivers/fsl_ftm.c
Normal file
File diff suppressed because it is too large
Load Diff
862
devices/MK22F51212/drivers/fsl_ftm.h
Normal file
862
devices/MK22F51212/drivers/fsl_ftm.h
Normal file
File diff suppressed because it is too large
Load Diff
179
devices/MK22F51212/drivers/fsl_gpio.c
Normal file
179
devices/MK22F51212/drivers/fsl_gpio.c
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_gpio.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
static PORT_Type *const s_portBases[] = PORT_BASE_PTRS;
|
||||
static GPIO_Type *const s_gpioBases[] = GPIO_BASE_PTRS;
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Gets the GPIO instance according to the GPIO base
|
||||
*
|
||||
* @param base GPIO peripheral base pointer(PTA, PTB, PTC, etc.)
|
||||
* @retval GPIO instance
|
||||
*/
|
||||
static uint32_t GPIO_GetInstance(GPIO_Type *base);
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
static uint32_t GPIO_GetInstance(GPIO_Type *base)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
/* Find the instance index from base address mappings. */
|
||||
for (instance = 0; instance < FSL_FEATURE_SOC_GPIO_COUNT; instance++)
|
||||
{
|
||||
if (s_gpioBases[instance] == base)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(instance < FSL_FEATURE_SOC_GPIO_COUNT);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void GPIO_PinInit(GPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
if (config->pinDirection == kGPIO_DigitalInput)
|
||||
{
|
||||
base->PDDR &= ~(1U << pin);
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIO_WritePinOutput(base, pin, config->outputLogic);
|
||||
base->PDDR |= (1U << pin);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t GPIO_GetPinsInterruptFlags(GPIO_Type *base)
|
||||
{
|
||||
uint8_t instance;
|
||||
PORT_Type *portBase;
|
||||
instance = GPIO_GetInstance(base);
|
||||
portBase = s_portBases[instance];
|
||||
return portBase->ISFR;
|
||||
}
|
||||
|
||||
void GPIO_ClearPinsInterruptFlags(GPIO_Type *base, uint32_t mask)
|
||||
{
|
||||
uint8_t instance;
|
||||
PORT_Type *portBase;
|
||||
instance = GPIO_GetInstance(base);
|
||||
portBase = s_portBases[instance];
|
||||
portBase->ISFR = mask;
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_SOC_FGPIO_COUNT) && FSL_FEATURE_SOC_FGPIO_COUNT
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
static FGPIO_Type *const s_fgpioBases[] = FGPIO_BASE_PTRS;
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
/*!
|
||||
* @brief Gets the FGPIO instance according to the GPIO base
|
||||
*
|
||||
* @param base FGPIO peripheral base pointer(PTA, PTB, PTC, etc.)
|
||||
* @retval FGPIO instance
|
||||
*/
|
||||
static uint32_t FGPIO_GetInstance(FGPIO_Type *base);
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
static uint32_t FGPIO_GetInstance(FGPIO_Type *base)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
/* Find the instance index from base address mappings. */
|
||||
for (instance = 0; instance < FSL_FEATURE_SOC_FGPIO_COUNT; instance++)
|
||||
{
|
||||
if (s_fgpioBases[instance] == base)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(instance < FSL_FEATURE_SOC_FGPIO_COUNT);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void FGPIO_PinInit(FGPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
if (config->pinDirection == kGPIO_DigitalInput)
|
||||
{
|
||||
base->PDDR &= ~(1U << pin);
|
||||
}
|
||||
else
|
||||
{
|
||||
FGPIO_WritePinOutput(base, pin, config->outputLogic);
|
||||
base->PDDR |= (1U << pin);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t FGPIO_GetPinsInterruptFlags(FGPIO_Type *base)
|
||||
{
|
||||
uint8_t instance;
|
||||
instance = FGPIO_GetInstance(base);
|
||||
PORT_Type *portBase;
|
||||
portBase = s_portBases[instance];
|
||||
return portBase->ISFR;
|
||||
}
|
||||
|
||||
void FGPIO_ClearPinsInterruptFlags(FGPIO_Type *base, uint32_t mask)
|
||||
{
|
||||
uint8_t instance;
|
||||
instance = FGPIO_GetInstance(base);
|
||||
PORT_Type *portBase;
|
||||
portBase = s_portBases[instance];
|
||||
portBase->ISFR = mask;
|
||||
}
|
||||
|
||||
#endif /* FSL_FEATURE_SOC_FGPIO_COUNT */
|
||||
390
devices/MK22F51212/drivers/fsl_gpio.h
Normal file
390
devices/MK22F51212/drivers/fsl_gpio.h
Normal file
@@ -0,0 +1,390 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SDRVL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FSL_GPIO_H_
|
||||
#define _FSL_GPIO_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup gpio
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief GPIO driver version 2.1.0. */
|
||||
#define FSL_GPIO_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
|
||||
/*@}*/
|
||||
|
||||
/*! @brief GPIO direction definition*/
|
||||
typedef enum _gpio_pin_direction
|
||||
{
|
||||
kGPIO_DigitalInput = 0U, /*!< Set current pin as digital input*/
|
||||
kGPIO_DigitalOutput = 1U, /*!< Set current pin as digital output*/
|
||||
} gpio_pin_direction_t;
|
||||
|
||||
/*!
|
||||
* @brief The GPIO pin configuration structure.
|
||||
*
|
||||
* Every pin can only be configured as either output pin or input pin at a time.
|
||||
* If configured as a input pin, then leave the outputConfig unused
|
||||
* Note : In some cases, the corresponding port property should be configured in advance
|
||||
* with the PORT_SetPinConfig()
|
||||
*/
|
||||
typedef struct _gpio_pin_config
|
||||
{
|
||||
gpio_pin_direction_t pinDirection; /*!< gpio direction, input or output */
|
||||
/* Output configurations, please ignore if configured as a input one */
|
||||
uint8_t outputLogic; /*!< Set default output logic, no use in input */
|
||||
} gpio_pin_config_t;
|
||||
|
||||
/*! @} */
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @addtogroup gpio_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @name GPIO Configuration */
|
||||
/*@{*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes a GPIO pin used by the board.
|
||||
*
|
||||
* To initialize the GPIO, define a pin configuration, either input or output, in the user file.
|
||||
* Then, call the GPIO_PinInit() function.
|
||||
*
|
||||
* This is an example to define an input pin or output pin configuration:
|
||||
* @code
|
||||
* // Define a digital input pin configuration,
|
||||
* gpio_pin_config_t config =
|
||||
* {
|
||||
* kGPIO_DigitalInput,
|
||||
* 0,
|
||||
* }
|
||||
* //Define a digital output pin configuration,
|
||||
* gpio_pin_config_t config =
|
||||
* {
|
||||
* kGPIO_DigitalOutput,
|
||||
* 0,
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @param base GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @param pin GPIO port pin number
|
||||
* @param config GPIO pin configuration pointer
|
||||
*/
|
||||
void GPIO_PinInit(GPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config);
|
||||
|
||||
/*@}*/
|
||||
|
||||
/*! @name GPIO Output Operations */
|
||||
/*@{*/
|
||||
|
||||
/*!
|
||||
* @brief Sets the output level of the multiple GPIO pins to the logic 1 or 0.
|
||||
*
|
||||
* @param base GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @param pin GPIO pin's number
|
||||
* @param output GPIO pin output logic level.
|
||||
* - 0: corresponding pin output low logic level.
|
||||
* - 1: corresponding pin output high logic level.
|
||||
*/
|
||||
static inline void GPIO_WritePinOutput(GPIO_Type *base, uint32_t pin, uint8_t output)
|
||||
{
|
||||
if (output == 0U)
|
||||
{
|
||||
base->PCOR = 1 << pin;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->PSOR = 1 << pin;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets the output level of the multiple GPIO pins to the logic 1.
|
||||
*
|
||||
* @param base GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @param mask GPIO pins' numbers macro
|
||||
*/
|
||||
static inline void GPIO_SetPinsOutput(GPIO_Type *base, uint32_t mask)
|
||||
{
|
||||
base->PSOR = mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets the output level of the multiple GPIO pins to the logic 0.
|
||||
*
|
||||
* @param base GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @param mask GPIO pins' numbers macro
|
||||
*/
|
||||
static inline void GPIO_ClearPinsOutput(GPIO_Type *base, uint32_t mask)
|
||||
{
|
||||
base->PCOR = mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reverses current output logic of the multiple GPIO pins.
|
||||
*
|
||||
* @param base GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @param mask GPIO pins' numbers macro
|
||||
*/
|
||||
static inline void GPIO_TogglePinsOutput(GPIO_Type *base, uint32_t mask)
|
||||
{
|
||||
base->PTOR = mask;
|
||||
}
|
||||
/*@}*/
|
||||
|
||||
/*! @name GPIO Input Operations */
|
||||
/*@{*/
|
||||
|
||||
/*!
|
||||
* @brief Reads the current input value of the whole GPIO port.
|
||||
*
|
||||
* @param base GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @param pin GPIO pin's number
|
||||
* @retval GPIO port input value
|
||||
* - 0: corresponding pin input low logic level.
|
||||
* - 1: corresponding pin input high logic level.
|
||||
*/
|
||||
static inline uint32_t GPIO_ReadPinInput(GPIO_Type *base, uint32_t pin)
|
||||
{
|
||||
return (((base->PDIR) >> pin) & 0x01U);
|
||||
}
|
||||
/*@}*/
|
||||
|
||||
/*! @name GPIO Interrupt */
|
||||
/*@{*/
|
||||
|
||||
/*!
|
||||
* @brief Reads whole GPIO port interrupt status flag.
|
||||
*
|
||||
* If a pin is configured to generate the DMA request, the corresponding flag
|
||||
* is cleared automatically at the completion of the requested DMA transfer.
|
||||
* Otherwise, the flag remains set until a logic one is written to that flag.
|
||||
* If configured for a level sensitive interrupt that remains asserted, the flag
|
||||
* is set again immediately.
|
||||
*
|
||||
* @param base GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @retval Current GPIO port interrupt status flag, for example, 0x00010001 means the
|
||||
* pin 0 and 17 have the interrupt.
|
||||
*/
|
||||
uint32_t GPIO_GetPinsInterruptFlags(GPIO_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Clears multiple GPIO pins' interrupt status flag.
|
||||
*
|
||||
* @param base GPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @param mask GPIO pins' numbers macro
|
||||
*/
|
||||
void GPIO_ClearPinsInterruptFlags(GPIO_Type *base, uint32_t mask);
|
||||
|
||||
/*@}*/
|
||||
/*! @} */
|
||||
|
||||
/*!
|
||||
* @addtogroup fgpio_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*
|
||||
* Introduce the FGPIO feature.
|
||||
*
|
||||
* The FGPIO features are only support on some of Kinetis chips. The FGPIO registers are aliased to the IOPORT
|
||||
* interface. Accesses via the IOPORT interface occur in parallel with any instruction fetches and will therefore
|
||||
* complete in a single cycle. This aliased Fast GPIO memory map is called FGPIO.
|
||||
*/
|
||||
|
||||
#if defined(FSL_FEATURE_SOC_FGPIO_COUNT) && FSL_FEATURE_SOC_FGPIO_COUNT
|
||||
|
||||
/*! @name FGPIO Configuration */
|
||||
/*@{*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes a FGPIO pin used by the board.
|
||||
*
|
||||
* To initialize the FGPIO driver, define a pin configuration, either input or output, in the user file.
|
||||
* Then, call the FGPIO_PinInit() function.
|
||||
*
|
||||
* This is an example to define an input pin or output pin configuration:
|
||||
* @code
|
||||
* // Define a digital input pin configuration,
|
||||
* gpio_pin_config_t config =
|
||||
* {
|
||||
* kGPIO_DigitalInput,
|
||||
* 0,
|
||||
* }
|
||||
* //Define a digital output pin configuration,
|
||||
* gpio_pin_config_t config =
|
||||
* {
|
||||
* kGPIO_DigitalOutput,
|
||||
* 0,
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @param base FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @param pin FGPIO port pin number
|
||||
* @param config FGPIO pin configuration pointer
|
||||
*/
|
||||
void FGPIO_PinInit(FGPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config);
|
||||
|
||||
/*@}*/
|
||||
|
||||
/*! @name FGPIO Output Operations */
|
||||
/*@{*/
|
||||
|
||||
/*!
|
||||
* @brief Sets the output level of the multiple FGPIO pins to the logic 1 or 0.
|
||||
*
|
||||
* @param base FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @param pin FGPIO pin's number
|
||||
* @param output FGPIOpin output logic level.
|
||||
* - 0: corresponding pin output low logic level.
|
||||
* - 1: corresponding pin output high logic level.
|
||||
*/
|
||||
static inline void FGPIO_WritePinOutput(FGPIO_Type *base, uint32_t pin, uint8_t output)
|
||||
{
|
||||
if (output == 0U)
|
||||
{
|
||||
base->PCOR = 1 << pin;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->PSOR = 1 << pin;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets the output level of the multiple FGPIO pins to the logic 1.
|
||||
*
|
||||
* @param base FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @param mask FGPIO pins' numbers macro
|
||||
*/
|
||||
static inline void FGPIO_SetPinsOutput(FGPIO_Type *base, uint32_t mask)
|
||||
{
|
||||
base->PSOR = mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets the output level of the multiple FGPIO pins to the logic 0.
|
||||
*
|
||||
* @param base FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @param mask FGPIO pins' numbers macro
|
||||
*/
|
||||
static inline void FGPIO_ClearPinsOutput(FGPIO_Type *base, uint32_t mask)
|
||||
{
|
||||
base->PCOR = mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reverses current output logic of the multiple FGPIO pins.
|
||||
*
|
||||
* @param base FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @param mask FGPIO pins' numbers macro
|
||||
*/
|
||||
static inline void FGPIO_TogglePinsOutput(FGPIO_Type *base, uint32_t mask)
|
||||
{
|
||||
base->PTOR = mask;
|
||||
}
|
||||
/*@}*/
|
||||
|
||||
/*! @name FGPIO Input Operations */
|
||||
/*@{*/
|
||||
|
||||
/*!
|
||||
* @brief Reads the current input value of the whole FGPIO port.
|
||||
*
|
||||
* @param base FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @param pin FGPIO pin's number
|
||||
* @retval FGPIO port input value
|
||||
* - 0: corresponding pin input low logic level.
|
||||
* - 1: corresponding pin input high logic level.
|
||||
*/
|
||||
static inline uint32_t FGPIO_ReadPinInput(FGPIO_Type *base, uint32_t pin)
|
||||
{
|
||||
return (((base->PDIR) >> pin) & 0x01U);
|
||||
}
|
||||
/*@}*/
|
||||
|
||||
/*! @name FGPIO Interrupt */
|
||||
/*@{*/
|
||||
|
||||
/*!
|
||||
* @brief Reads the whole FGPIO port interrupt status flag.
|
||||
*
|
||||
* If a pin is configured to generate the DMA request, the corresponding flag
|
||||
* is cleared automatically at the completion of the requested DMA transfer.
|
||||
* Otherwise, the flag remains set until a logic one is written to that flag.
|
||||
* If configured for a level sensitive interrupt that remains asserted, the flag
|
||||
* is set again immediately.
|
||||
*
|
||||
* @param base FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @retval Current FGPIO port interrupt status flags, for example, 0x00010001 means the
|
||||
* pin 0 and 17 have the interrupt.
|
||||
*/
|
||||
uint32_t FGPIO_GetPinsInterruptFlags(FGPIO_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Clears the multiple FGPIO pins' interrupt status flag.
|
||||
*
|
||||
* @param base FGPIO peripheral base pointer(GPIOA, GPIOB, GPIOC, and so on.)
|
||||
* @param mask FGPIO pins' numbers macro
|
||||
*/
|
||||
void FGPIO_ClearPinsInterruptFlags(FGPIO_Type *base, uint32_t mask);
|
||||
|
||||
/*@}*/
|
||||
|
||||
#endif /* FSL_FEATURE_SOC_FGPIO_COUNT */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* _FSL_GPIO_H_*/
|
||||
1536
devices/MK22F51212/drivers/fsl_i2c.c
Normal file
1536
devices/MK22F51212/drivers/fsl_i2c.c
Normal file
File diff suppressed because it is too large
Load Diff
781
devices/MK22F51212/drivers/fsl_i2c.h
Normal file
781
devices/MK22F51212/drivers/fsl_i2c.h
Normal file
File diff suppressed because it is too large
Load Diff
526
devices/MK22F51212/drivers/fsl_i2c_edma.c
Normal file
526
devices/MK22F51212/drivers/fsl_i2c_edma.c
Normal file
File diff suppressed because it is too large
Load Diff
133
devices/MK22F51212/drivers/fsl_i2c_edma.h
Normal file
133
devices/MK22F51212/drivers/fsl_i2c_edma.h
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_I2C_DMA_H_
|
||||
#define _FSL_I2C_DMA_H_
|
||||
|
||||
#include "fsl_i2c.h"
|
||||
#include "fsl_dmamux.h"
|
||||
#include "fsl_edma.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup i2c_edma_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief I2C master edma handle typedef. */
|
||||
typedef struct _i2c_master_edma_handle i2c_master_edma_handle_t;
|
||||
|
||||
/*! @brief I2C master edma transfer callback typedef. */
|
||||
typedef void (*i2c_master_edma_transfer_callback_t)(I2C_Type *base,
|
||||
i2c_master_edma_handle_t *handle,
|
||||
status_t status,
|
||||
void *userData);
|
||||
|
||||
/*! @brief I2C master edma transfer structure. */
|
||||
struct _i2c_master_edma_handle
|
||||
{
|
||||
i2c_master_transfer_t transfer; /*!< I2C master transfer struct. */
|
||||
size_t transferSize; /*!< Total bytes to be transferred. */
|
||||
uint8_t state; /*!< I2C master transfer status. */
|
||||
edma_handle_t *dmaHandle; /*!< The eDMA handler used. */
|
||||
i2c_master_edma_transfer_callback_t
|
||||
completionCallback; /*!< Callback function called after edma transfer finished. */
|
||||
void *userData; /*!< Callback parameter passed to callback function. */
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /*_cplusplus. */
|
||||
|
||||
/*!
|
||||
* @name I2C Block EDMA Transfer Operation
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Init the I2C handle which is used in transcational functions.
|
||||
*
|
||||
* @param base I2C peripheral base address.
|
||||
* @param handle pointer to i2c_master_edma_handle_t structure.
|
||||
* @param callback pointer to user callback function.
|
||||
* @param userData user param passed to the callback function.
|
||||
* @param edmaHandle EDMA handle pointer.
|
||||
*/
|
||||
void I2C_MasterCreateEDMAHandle(I2C_Type *base,
|
||||
i2c_master_edma_handle_t *handle,
|
||||
i2c_master_edma_transfer_callback_t callback,
|
||||
void *userData,
|
||||
edma_handle_t *edmaHandle);
|
||||
|
||||
/*!
|
||||
* @brief Performs a master edma non-blocking transfer on the I2C bus.
|
||||
*
|
||||
* @param base I2C peripheral base address.
|
||||
* @param handle pointer to i2c_master_edma_handle_t structure.
|
||||
* @param xfer pointer to transfer structure of i2c_master_transfer_t.
|
||||
* @retval kStatus_Success Sucessully complete the data transmission.
|
||||
* @retval kStatus_I2C_Busy Previous transmission still not finished.
|
||||
* @retval kStatus_I2C_Timeout Transfer error, wait signal timeout.
|
||||
* @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
|
||||
* @retval kStataus_I2C_Nak Transfer error, receive Nak during transfer.
|
||||
*/
|
||||
status_t I2C_MasterTransferEDMA(I2C_Type *base, i2c_master_edma_handle_t *handle, i2c_master_transfer_t *xfer);
|
||||
|
||||
/*!
|
||||
* @brief Get master transfer status during a edma non-blocking transfer.
|
||||
*
|
||||
* @param base I2C peripheral base address.
|
||||
* @param handle pointer to i2c_master_edma_handle_t structure.
|
||||
* @param count Number of bytes transferred so far by the non-blocking transaction.
|
||||
*/
|
||||
status_t I2C_MasterTransferGetCountEDMA(I2C_Type *base, i2c_master_edma_handle_t *handle, size_t *count);
|
||||
|
||||
/*!
|
||||
* @brief Abort a master edma non-blocking transfer in a early time.
|
||||
*
|
||||
* @param base I2C peripheral base address.
|
||||
* @param handle pointer to i2c_master_edma_handle_t structure.
|
||||
*/
|
||||
void I2C_MasterTransferAbortEDMA(I2C_Type *base, i2c_master_edma_handle_t *handle);
|
||||
|
||||
/* @} */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /*_cplusplus. */
|
||||
/*@}*/
|
||||
#endif /*_FSL_I2C_DMA_H_*/
|
||||
404
devices/MK22F51212/drivers/fsl_llwu.c
Normal file
404
devices/MK22F51212/drivers/fsl_llwu.c
Normal file
@@ -0,0 +1,404 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_llwu.h"
|
||||
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN)
|
||||
void LLWU_SetExternalWakeupPinMode(LLWU_Type *base, uint32_t pinIndex, llwu_external_pin_mode_t pinMode)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_LLWU_REG_BITWIDTH) && (FSL_FEATURE_LLWU_REG_BITWIDTH == 32))
|
||||
volatile uint32_t *regBase;
|
||||
uint32_t regOffset;
|
||||
uint32_t reg;
|
||||
|
||||
switch (pinIndex >> 4U)
|
||||
{
|
||||
case 0U:
|
||||
regBase = &base->PE1;
|
||||
break;
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 16))
|
||||
case 1U:
|
||||
regBase = &base->PE2;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
regBase = NULL;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
volatile uint8_t *regBase;
|
||||
uint8_t regOffset;
|
||||
uint8_t reg;
|
||||
switch (pinIndex >> 2U)
|
||||
{
|
||||
case 0U:
|
||||
regBase = &base->PE1;
|
||||
break;
|
||||
case 1U:
|
||||
regBase = &base->PE2;
|
||||
break;
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 8))
|
||||
case 2U:
|
||||
regBase = &base->PE3;
|
||||
break;
|
||||
#endif
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 12))
|
||||
case 3U:
|
||||
regBase = &base->PE4;
|
||||
break;
|
||||
#endif
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 16))
|
||||
case 4U:
|
||||
regBase = &base->PE5;
|
||||
break;
|
||||
#endif
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 20))
|
||||
case 5U:
|
||||
regBase = &base->PE6;
|
||||
break;
|
||||
#endif
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 24))
|
||||
case 6U:
|
||||
regBase = &base->PE7;
|
||||
break;
|
||||
#endif
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 28))
|
||||
case 7U:
|
||||
regBase = &base->PE8;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
regBase = NULL;
|
||||
break;
|
||||
}
|
||||
#endif /* FSL_FEATURE_LLWU_REG_BITWIDTH == 32 */
|
||||
|
||||
if (regBase)
|
||||
{
|
||||
reg = *regBase;
|
||||
#if (defined(FSL_FEATURE_LLWU_REG_BITWIDTH) && (FSL_FEATURE_LLWU_REG_BITWIDTH == 32))
|
||||
regOffset = ((pinIndex & 0x0FU) << 1U);
|
||||
#else
|
||||
regOffset = ((pinIndex & 0x03U) << 1U);
|
||||
#endif
|
||||
reg &= ~(0x3U << regOffset);
|
||||
reg |= ((uint32_t)pinMode << regOffset);
|
||||
*regBase = reg;
|
||||
}
|
||||
}
|
||||
|
||||
bool LLWU_GetExternalWakeupPinFlag(LLWU_Type *base, uint32_t pinIndex)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_LLWU_REG_BITWIDTH) && (FSL_FEATURE_LLWU_REG_BITWIDTH == 32))
|
||||
return (bool)(base->PF & (1U << pinIndex));
|
||||
#else
|
||||
volatile uint8_t *regBase;
|
||||
|
||||
switch (pinIndex >> 3U)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PF) && FSL_FEATURE_LLWU_HAS_PF)
|
||||
case 0U:
|
||||
regBase = &base->PF1;
|
||||
break;
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 8))
|
||||
case 1U:
|
||||
regBase = &base->PF2;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 16))
|
||||
case 2U:
|
||||
regBase = &base->PF3;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 24))
|
||||
case 3U:
|
||||
regBase = &base->PF4;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
#else
|
||||
case 0U:
|
||||
regBase = &base->F1;
|
||||
break;
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 8))
|
||||
case 1U:
|
||||
regBase = &base->F2;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 16))
|
||||
case 2U:
|
||||
regBase = &base->F3;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 24))
|
||||
case 3U:
|
||||
regBase = &base->F4;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PF */
|
||||
default:
|
||||
regBase = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (regBase)
|
||||
{
|
||||
return (bool)(*regBase & (1U << pinIndex % 8));
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif /* FSL_FEATURE_LLWU_REG_BITWIDTH */
|
||||
}
|
||||
|
||||
void LLWU_ClearExternalWakeupPinFlag(LLWU_Type *base, uint32_t pinIndex)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_LLWU_REG_BITWIDTH) && (FSL_FEATURE_LLWU_REG_BITWIDTH == 32))
|
||||
base->PF = (1U << pinIndex);
|
||||
#else
|
||||
volatile uint8_t *regBase;
|
||||
switch (pinIndex >> 3U)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PF) && FSL_FEATURE_LLWU_HAS_PF)
|
||||
case 0U:
|
||||
regBase = &base->PF1;
|
||||
break;
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 8))
|
||||
case 1U:
|
||||
regBase = &base->PF2;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 16))
|
||||
case 2U:
|
||||
regBase = &base->PF3;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 24))
|
||||
case 3U:
|
||||
regBase = &base->PF4;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
#else
|
||||
case 0U:
|
||||
regBase = &base->F1;
|
||||
break;
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 8))
|
||||
case 1U:
|
||||
regBase = &base->F2;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 16))
|
||||
case 2U:
|
||||
regBase = &base->F3;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 24))
|
||||
case 3U:
|
||||
regBase = &base->F4;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PF */
|
||||
default:
|
||||
regBase = NULL;
|
||||
break;
|
||||
}
|
||||
if (regBase)
|
||||
{
|
||||
*regBase = (1U << pinIndex % 8U);
|
||||
}
|
||||
#endif /* FSL_FEATURE_LLWU_REG_BITWIDTH */
|
||||
}
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && FSL_FEATURE_LLWU_HAS_PIN_FILTER)
|
||||
void LLWU_SetPinFilterMode(LLWU_Type *base, uint32_t filterIndex, llwu_external_pin_filter_mode_t filterMode)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_LLWU_REG_BITWIDTH) && (FSL_FEATURE_LLWU_REG_BITWIDTH == 32))
|
||||
uint32_t reg;
|
||||
|
||||
reg = base->FILT;
|
||||
reg &= ~((LLWU_FILT_FILTSEL1_MASK | LLWU_FILT_FILTE1_MASK) << (filterIndex * 8U - 1U));
|
||||
reg |= (((filterMode.pinIndex << LLWU_FILT_FILTSEL1_SHIFT) | (filterMode.filterMode << LLWU_FILT_FILTE1_SHIFT)
|
||||
/* Clear the Filter Detect Flag */
|
||||
| LLWU_FILT_FILTF1_MASK)
|
||||
<< (filterIndex * 8U - 1U));
|
||||
base->FILT = reg;
|
||||
#else
|
||||
volatile uint8_t *regBase;
|
||||
uint8_t reg;
|
||||
|
||||
switch (filterIndex)
|
||||
{
|
||||
case 1:
|
||||
regBase = &base->FILT1;
|
||||
break;
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && (FSL_FEATURE_LLWU_HAS_PIN_FILTER > 1))
|
||||
case 2:
|
||||
regBase = &base->FILT2;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && (FSL_FEATURE_LLWU_HAS_PIN_FILTER > 2))
|
||||
case 3:
|
||||
regBase = &base->FILT3;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && (FSL_FEATURE_LLWU_HAS_PIN_FILTER > 3))
|
||||
case 4:
|
||||
regBase = &base->FILT4;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
|
||||
default:
|
||||
regBase = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (regBase)
|
||||
{
|
||||
reg = *regBase;
|
||||
reg &= ~(LLWU_FILT1_FILTSEL_MASK | LLWU_FILT1_FILTE_MASK);
|
||||
reg |= ((uint32_t)filterMode.pinIndex << LLWU_FILT1_FILTSEL_SHIFT);
|
||||
reg |= ((uint32_t)filterMode.filterMode << LLWU_FILT1_FILTE_SHIFT);
|
||||
/* Clear the Filter Detect Flag */
|
||||
reg |= LLWU_FILT1_FILTF_MASK;
|
||||
*regBase = reg;
|
||||
}
|
||||
#endif /* FSL_FEATURE_LLWU_REG_BITWIDTH */
|
||||
}
|
||||
|
||||
bool LLWU_GetPinFilterFlag(LLWU_Type *base, uint32_t filterIndex)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_LLWU_REG_BITWIDTH) && (FSL_FEATURE_LLWU_REG_BITWIDTH == 32))
|
||||
return (bool)(base->FILT & (1U << (filterIndex * 8U - 1)));
|
||||
#else
|
||||
bool status = false;
|
||||
|
||||
switch (filterIndex)
|
||||
{
|
||||
case 1:
|
||||
status = (base->FILT1 & LLWU_FILT1_FILTF_MASK);
|
||||
break;
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && (FSL_FEATURE_LLWU_HAS_PIN_FILTER > 1))
|
||||
case 2:
|
||||
status = (base->FILT2 & LLWU_FILT2_FILTF_MASK);
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && (FSL_FEATURE_LLWU_HAS_PIN_FILTER > 2))
|
||||
case 3:
|
||||
status = (base->FILT3 & LLWU_FILT3_FILTF_MASK);
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && (FSL_FEATURE_LLWU_HAS_PIN_FILTER > 3))
|
||||
case 4:
|
||||
status = (base->FILT4 & LLWU_FILT4_FILTF_MASK);
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
#endif /* FSL_FEATURE_LLWU_REG_BITWIDTH */
|
||||
}
|
||||
|
||||
void LLWU_ClearPinFilterFlag(LLWU_Type *base, uint32_t filterIndex)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_LLWU_REG_BITWIDTH) && (FSL_FEATURE_LLWU_REG_BITWIDTH == 32))
|
||||
uint32_t reg;
|
||||
|
||||
reg = base->FILT;
|
||||
switch (filterIndex)
|
||||
{
|
||||
case 1:
|
||||
reg |= LLWU_FILT_FILTF1_MASK;
|
||||
break;
|
||||
case 2:
|
||||
reg |= LLWU_FILT_FILTF2_MASK;
|
||||
break;
|
||||
case 3:
|
||||
reg |= LLWU_FILT_FILTF3_MASK;
|
||||
break;
|
||||
case 4:
|
||||
reg |= LLWU_FILT_FILTF4_MASK;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
base->FILT = reg;
|
||||
#else
|
||||
volatile uint8_t *regBase;
|
||||
uint8_t reg;
|
||||
|
||||
switch (filterIndex)
|
||||
{
|
||||
case 1:
|
||||
regBase = &base->FILT1;
|
||||
break;
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && (FSL_FEATURE_LLWU_HAS_PIN_FILTER > 1))
|
||||
case 2:
|
||||
regBase = &base->FILT2;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && (FSL_FEATURE_LLWU_HAS_PIN_FILTER > 2))
|
||||
case 3:
|
||||
regBase = &base->FILT3;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && (FSL_FEATURE_LLWU_HAS_PIN_FILTER > 3))
|
||||
case 4:
|
||||
regBase = &base->FILT4;
|
||||
break;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
|
||||
default:
|
||||
regBase = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (regBase)
|
||||
{
|
||||
reg = *regBase;
|
||||
reg |= LLWU_FILT1_FILTF_MASK;
|
||||
*regBase = reg;
|
||||
}
|
||||
#endif /* FSL_FEATURE_LLWU_REG_BITWIDTH */
|
||||
}
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
|
||||
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_RESET_ENABLE) && FSL_FEATURE_LLWU_HAS_RESET_ENABLE)
|
||||
void LLWU_SetResetPinMode(LLWU_Type *base, bool pinEnable, bool enableInLowLeakageMode)
|
||||
{
|
||||
uint8_t reg;
|
||||
|
||||
reg = base->RST;
|
||||
reg &= ~(LLWU_RST_LLRSTE_MASK | LLWU_RST_RSTFILT_MASK);
|
||||
reg |=
|
||||
(((uint32_t)pinEnable << LLWU_RST_LLRSTE_SHIFT) | ((uint32_t)enableInLowLeakageMode << LLWU_RST_RSTFILT_SHIFT));
|
||||
base->RST = reg;
|
||||
}
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_RESET_ENABLE */
|
||||
321
devices/MK22F51212/drivers/fsl_llwu.h
Normal file
321
devices/MK22F51212/drivers/fsl_llwu.h
Normal file
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_LLWU_H_
|
||||
#define _FSL_LLWU_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*! @addtogroup llwu */
|
||||
/*! @{ */
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief LLWU driver version 2.0.1. */
|
||||
#define FSL_LLWU_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
|
||||
/*@}*/
|
||||
|
||||
/*!
|
||||
* @brief External input pin control modes
|
||||
*/
|
||||
typedef enum _llwu_external_pin_mode
|
||||
{
|
||||
kLLWU_ExternalPinDisable = 0U, /*!< Pin disabled as wakeup input. */
|
||||
kLLWU_ExternalPinRisingEdge = 1U, /*!< Pin enabled with rising edge detection. */
|
||||
kLLWU_ExternalPinFallingEdge = 2U, /*!< Pin enabled with falling edge detection.*/
|
||||
kLLWU_ExternalPinAnyEdge = 3U /*!< Pin enabled with any change detection. */
|
||||
} llwu_external_pin_mode_t;
|
||||
|
||||
/*!
|
||||
* @brief Digital filter control modes
|
||||
*/
|
||||
typedef enum _llwu_pin_filter_mode
|
||||
{
|
||||
kLLWU_PinFilterDisable = 0U, /*!< Filter disabled. */
|
||||
kLLWU_PinFilterRisingEdge = 1U, /*!< Filter positive edge detection.*/
|
||||
kLLWU_PinFilterFallingEdge = 2U, /*!< Filter negative edge detection.*/
|
||||
kLLWU_PinFilterAnyEdge = 3U /*!< Filter any edge detection. */
|
||||
} llwu_pin_filter_mode_t;
|
||||
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_VERID) && FSL_FEATURE_LLWU_HAS_VERID)
|
||||
/*!
|
||||
* @brief IP version ID definition.
|
||||
*/
|
||||
typedef struct _llwu_version_id
|
||||
{
|
||||
uint16_t feature; /*!< Feature Specification Number. */
|
||||
uint8_t minor; /*!< Minor version number. */
|
||||
uint8_t major; /*!< Major version number. */
|
||||
} llwu_version_id_t;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_VERID */
|
||||
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PARAM) && FSL_FEATURE_LLWU_HAS_PARAM)
|
||||
/*!
|
||||
* @brief IP parameter definition.
|
||||
*/
|
||||
typedef struct _llwu_param
|
||||
{
|
||||
uint8_t filters; /*!< Number of pin filter. */
|
||||
uint8_t dmas; /*!< Number of wakeup DMA. */
|
||||
uint8_t modules; /*!< Number of wakeup module. */
|
||||
uint8_t pins; /*!< Number of wake up pin. */
|
||||
} llwu_param_t;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PARAM */
|
||||
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && FSL_FEATURE_LLWU_HAS_PIN_FILTER)
|
||||
/*!
|
||||
* @brief External input pin filter control structure
|
||||
*/
|
||||
typedef struct _llwu_external_pin_filter_mode
|
||||
{
|
||||
uint32_t pinIndex; /*!< Pin number */
|
||||
llwu_pin_filter_mode_t filterMode; /*!< Filter mode */
|
||||
} llwu_external_pin_filter_mode_t;
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @name Low-Leakage Wakeup Unit Control APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_VERID) && FSL_FEATURE_LLWU_HAS_VERID)
|
||||
/*!
|
||||
* @brief Gets the LLWU version ID.
|
||||
*
|
||||
* This function gets the LLWU version ID, including major version number,
|
||||
* minor version number, and feature specification number.
|
||||
*
|
||||
* @param base LLWU peripheral base address.
|
||||
* @param versionId Pointer to version ID structure.
|
||||
*/
|
||||
static inline void LLWU_GetVersionId(LLWU_Type *base, llwu_version_id_t *versionId)
|
||||
{
|
||||
*((uint32_t *)versionId) = base->VERID;
|
||||
}
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_VERID */
|
||||
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PARAM) && FSL_FEATURE_LLWU_HAS_PARAM)
|
||||
/*!
|
||||
* @brief Gets the LLWU parameter.
|
||||
*
|
||||
* This function gets the LLWU parameter, including wakeup pin number, module
|
||||
* number, DMA number, and pin filter number.
|
||||
*
|
||||
* @param base LLWU peripheral base address.
|
||||
* @param param Pointer to LLWU param structure.
|
||||
*/
|
||||
static inline void LLWU_GetParam(LLWU_Type *base, llwu_param_t *param)
|
||||
{
|
||||
*((uint32_t *)param) = base->PARAM;
|
||||
}
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PARAM */
|
||||
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN)
|
||||
/*!
|
||||
* @brief Sets the external input pin source mode.
|
||||
*
|
||||
* This function sets the external input pin source mode that is used
|
||||
* as a wake up source.
|
||||
*
|
||||
* @param base LLWU peripheral base address.
|
||||
* @param pinIndex pin index which to be enabled as external wakeup source, start from 1.
|
||||
* @param pinMode pin configuration mode defined in llwu_external_pin_modes_t
|
||||
*/
|
||||
void LLWU_SetExternalWakeupPinMode(LLWU_Type *base, uint32_t pinIndex, llwu_external_pin_mode_t pinMode);
|
||||
|
||||
/*!
|
||||
* @brief Gets the external wakeup source flag.
|
||||
*
|
||||
* This function checks the external pin flag to detect whether the MCU is
|
||||
* woke up by the specific pin.
|
||||
*
|
||||
* @param base LLWU peripheral base address.
|
||||
* @param pinIndex pin index, start from 1.
|
||||
* @return true if the specific pin is wake up source.
|
||||
*/
|
||||
bool LLWU_GetExternalWakeupPinFlag(LLWU_Type *base, uint32_t pinIndex);
|
||||
|
||||
/*!
|
||||
* @brief Clears the external wakeup source flag.
|
||||
*
|
||||
* This function clears the external wakeup source flag for a specific pin.
|
||||
*
|
||||
* @param base LLWU peripheral base address.
|
||||
* @param pinIndex pin index, start from 1.
|
||||
*/
|
||||
void LLWU_ClearExternalWakeupPinFlag(LLWU_Type *base, uint32_t pinIndex);
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE) && FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE)
|
||||
/*!
|
||||
* @brief Enables/disables the internal module source.
|
||||
*
|
||||
* This function enables/disables the internal module source mode that is used
|
||||
* as a wake up source.
|
||||
*
|
||||
* @param base LLWU peripheral base address.
|
||||
* @param moduleIndex module index which to be enabled as internal wakeup source, start from 1.
|
||||
* @param enable enable or disable setting
|
||||
*/
|
||||
static inline void LLWU_EnableInternalModuleInterruptWakup(LLWU_Type *base, uint32_t moduleIndex, bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
base->ME |= 1U << moduleIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->ME &= ~(1U << moduleIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets the external wakeup source flag.
|
||||
*
|
||||
* This function checks the external pin flag to detect whether the system is
|
||||
* woke up by the specific pin.
|
||||
*
|
||||
* @param base LLWU peripheral base address.
|
||||
* @param moduleIndex module index, start from 1.
|
||||
* @return true if the specific pin is wake up source.
|
||||
*/
|
||||
static inline bool LLWU_GetInternalWakeupModuleFlag(LLWU_Type *base, uint32_t moduleIndex)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_LLWU_REG_BITWIDTH) && (FSL_FEATURE_LLWU_REG_BITWIDTH == 32))
|
||||
return (bool)(base->MF & (1U << moduleIndex));
|
||||
#else
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN) && (FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN > 16))
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PF) && FSL_FEATURE_LLWU_HAS_PF)
|
||||
return (bool)(base->MF5 & (1U << moduleIndex));
|
||||
#else
|
||||
return (bool)(base->F5 & (1U << moduleIndex));
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PF */
|
||||
#else
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PF) && FSL_FEATURE_LLWU_HAS_PF)
|
||||
return (bool)(base->PF3 & (1U << moduleIndex));
|
||||
#else
|
||||
return (bool)(base->F3 & (1U << moduleIndex));
|
||||
#endif
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN */
|
||||
#endif /* FSL_FEATURE_LLWU_REG_BITWIDTH */
|
||||
}
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE */
|
||||
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_DMA_ENABLE_REG) && FSL_FEATURE_LLWU_HAS_DMA_ENABLE_REG)
|
||||
/*!
|
||||
* @brief Enables/disables the internal module DMA wakeup source.
|
||||
*
|
||||
* This function enables/disables the internal DMA that is used as a wake up source.
|
||||
*
|
||||
* @param base LLWU peripheral base address.
|
||||
* @param moduleIndex Internal module index which used as DMA request source, start from 1.
|
||||
* @param enable Enable or disable DMA request source
|
||||
*/
|
||||
static inline void LLWU_EnableInternalModuleDmaRequestWakup(LLWU_Type *base, uint32_t moduleIndex, bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
base->DE |= 1U << moduleIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->DE &= ~(1U << moduleIndex);
|
||||
}
|
||||
}
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_DMA_ENABLE_REG */
|
||||
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_PIN_FILTER) && FSL_FEATURE_LLWU_HAS_PIN_FILTER)
|
||||
/*!
|
||||
* @brief Sets the pin filter configuration.
|
||||
*
|
||||
* This function sets the pin filter configuration.
|
||||
*
|
||||
* @param base LLWU peripheral base address.
|
||||
* @param filterIndex pin filter index which used to enable/disable the digital filter, start from 1.
|
||||
* @param filterMode filter mode configuration
|
||||
*/
|
||||
void LLWU_SetPinFilterMode(LLWU_Type *base, uint32_t filterIndex, llwu_external_pin_filter_mode_t filterMode);
|
||||
|
||||
/*!
|
||||
* @brief Gets the pin filter configuration.
|
||||
*
|
||||
* This function gets the pin filter flag.
|
||||
*
|
||||
* @param base LLWU peripheral base address.
|
||||
* @param filterIndex pin filter index, start from 1.
|
||||
* @return true if the flag is a source of existing a low-leakage power mode.
|
||||
*/
|
||||
bool LLWU_GetPinFilterFlag(LLWU_Type *base, uint32_t filterIndex);
|
||||
|
||||
/*!
|
||||
* @brief Clear the pin filter configuration.
|
||||
*
|
||||
* This function clear the pin filter flag.
|
||||
*
|
||||
* @param base LLWU peripheral base address.
|
||||
* @param filterIndex pin filter index which to be clear the flag, start from 1.
|
||||
*/
|
||||
void LLWU_ClearPinFilterFlag(LLWU_Type *base, uint32_t filterIndex);
|
||||
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_PIN_FILTER */
|
||||
|
||||
#if (defined(FSL_FEATURE_LLWU_HAS_RESET_ENABLE) && FSL_FEATURE_LLWU_HAS_RESET_ENABLE)
|
||||
/*!
|
||||
* @brief Sets the reset pin mode.
|
||||
*
|
||||
* This function sets how the reset pin is used as a low leakage mode exit source.
|
||||
*
|
||||
* @param pinEnable Enable reset pin filter
|
||||
* @param pinFilterEnable Specify whether pin filter is enabled in Low-Leakage power mode.
|
||||
*/
|
||||
void LLWU_SetResetPinMode(LLWU_Type *base, bool pinEnable, bool enableInLowLeakageMode);
|
||||
#endif /* FSL_FEATURE_LLWU_HAS_RESET_ENABLE */
|
||||
|
||||
/*@}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
#endif /* _FSL_LLWU_H_*/
|
||||
117
devices/MK22F51212/drivers/fsl_lptmr.c
Normal file
117
devices/MK22F51212/drivers/fsl_lptmr.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_lptmr.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
/*!
|
||||
* @brief Gets the instance from the base address to be used to gate or ungate the module clock
|
||||
*
|
||||
* @param base LPTMR peripheral base address
|
||||
*
|
||||
* @return The LPTMR instance
|
||||
*/
|
||||
static uint32_t LPTMR_GetInstance(LPTMR_Type *base);
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
/*! @brief Pointers to LPTMR bases for each instance. */
|
||||
static LPTMR_Type *const s_lptmrBases[] = LPTMR_BASE_PTRS;
|
||||
|
||||
/*! @brief Pointers to LPTMR clocks for each instance. */
|
||||
static const clock_ip_name_t s_lptmrClocks[] = LPTMR_CLOCKS;
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
static uint32_t LPTMR_GetInstance(LPTMR_Type *base)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
/* Find the instance index from base address mappings. */
|
||||
for (instance = 0; instance < FSL_FEATURE_SOC_LPTMR_COUNT; instance++)
|
||||
{
|
||||
if (s_lptmrBases[instance] == base)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(instance < FSL_FEATURE_SOC_LPTMR_COUNT);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void LPTMR_Init(LPTMR_Type *base, const lptmr_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
/* Ungate the LPTMR clock*/
|
||||
CLOCK_EnableClock(s_lptmrClocks[LPTMR_GetInstance(base)]);
|
||||
|
||||
/* Configure the timers operation mode and input pin setup */
|
||||
base->CSR = (LPTMR_CSR_TMS(config->timerMode) | LPTMR_CSR_TFC(config->enableFreeRunning) |
|
||||
LPTMR_CSR_TPP(config->pinPolarity) | LPTMR_CSR_TPS(config->pinSelect));
|
||||
|
||||
/* Configure the prescale value and clock source */
|
||||
base->PSR = (LPTMR_PSR_PRESCALE(config->value) | LPTMR_PSR_PBYP(config->bypassPrescaler) |
|
||||
LPTMR_PSR_PCS(config->prescalerClockSource));
|
||||
}
|
||||
|
||||
void LPTMR_Deinit(LPTMR_Type *base)
|
||||
{
|
||||
/* Disable the LPTMR and reset the internal logic */
|
||||
base->CSR &= ~LPTMR_CSR_TEN_MASK;
|
||||
/* Gate the LPTMR clock*/
|
||||
CLOCK_DisableClock(s_lptmrClocks[LPTMR_GetInstance(base)]);
|
||||
}
|
||||
|
||||
void LPTMR_GetDefaultConfig(lptmr_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
/* Use time counter mode */
|
||||
config->timerMode = kLPTMR_TimerModeTimeCounter;
|
||||
/* Use input 0 as source in pulse counter mode */
|
||||
config->pinSelect = kLPTMR_PinSelectInput_0;
|
||||
/* Pulse input pin polarity is active-high */
|
||||
config->pinPolarity = kLPTMR_PinPolarityActiveHigh;
|
||||
/* Counter resets whenever TCF flag is set */
|
||||
config->enableFreeRunning = false;
|
||||
/* Bypass the prescaler */
|
||||
config->bypassPrescaler = true;
|
||||
/* LPTMR clock source */
|
||||
config->prescalerClockSource = kLPTMR_PrescalerClock_1;
|
||||
/* Divide the prescaler clock by 2 */
|
||||
config->value = kLPTMR_Prescale_Glitch_0;
|
||||
}
|
||||
351
devices/MK22F51212/drivers/fsl_lptmr.h
Normal file
351
devices/MK22F51212/drivers/fsl_lptmr.h
Normal file
@@ -0,0 +1,351 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_LPTMR_H_
|
||||
#define _FSL_LPTMR_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup lptmr_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
#define FSL_LPTMR_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0 */
|
||||
/*@}*/
|
||||
|
||||
/*! @brief LPTMR pin selection, used in pulse counter mode.*/
|
||||
typedef enum _lptmr_pin_select
|
||||
{
|
||||
kLPTMR_PinSelectInput_0 = 0x0U, /*!< Pulse counter input 0 is selected */
|
||||
kLPTMR_PinSelectInput_1 = 0x1U, /*!< Pulse counter input 1 is selected */
|
||||
kLPTMR_PinSelectInput_2 = 0x2U, /*!< Pulse counter input 2 is selected */
|
||||
kLPTMR_PinSelectInput_3 = 0x3U /*!< Pulse counter input 3 is selected */
|
||||
} lptmr_pin_select_t;
|
||||
|
||||
/*! @brief LPTMR pin polarity, used in pulse counter mode.*/
|
||||
typedef enum _lptmr_pin_polarity
|
||||
{
|
||||
kLPTMR_PinPolarityActiveHigh = 0x0U, /*!< Pulse Counter input source is active-high */
|
||||
kLPTMR_PinPolarityActiveLow = 0x1U /*!< Pulse Counter input source is active-low */
|
||||
} lptmr_pin_polarity_t;
|
||||
|
||||
/*! @brief LPTMR timer mode selection.*/
|
||||
typedef enum _lptmr_timer_mode
|
||||
{
|
||||
kLPTMR_TimerModeTimeCounter = 0x0U, /*!< Time Counter mode */
|
||||
kLPTMR_TimerModePulseCounter = 0x1U /*!< Pulse Counter mode */
|
||||
} lptmr_timer_mode_t;
|
||||
|
||||
/*! @brief LPTMR prescaler/glitch filter values*/
|
||||
typedef enum _lptmr_prescaler_glitch_value
|
||||
{
|
||||
kLPTMR_Prescale_Glitch_0 = 0x0U, /*!< Prescaler divide 2, glitch filter does not support this setting */
|
||||
kLPTMR_Prescale_Glitch_1 = 0x1U, /*!< Prescaler divide 4, glitch filter 2 */
|
||||
kLPTMR_Prescale_Glitch_2 = 0x2U, /*!< Prescaler divide 8, glitch filter 4 */
|
||||
kLPTMR_Prescale_Glitch_3 = 0x3U, /*!< Prescaler divide 16, glitch filter 8 */
|
||||
kLPTMR_Prescale_Glitch_4 = 0x4U, /*!< Prescaler divide 32, glitch filter 16 */
|
||||
kLPTMR_Prescale_Glitch_5 = 0x5U, /*!< Prescaler divide 64, glitch filter 32 */
|
||||
kLPTMR_Prescale_Glitch_6 = 0x6U, /*!< Prescaler divide 128, glitch filter 64 */
|
||||
kLPTMR_Prescale_Glitch_7 = 0x7U, /*!< Prescaler divide 256, glitch filter 128 */
|
||||
kLPTMR_Prescale_Glitch_8 = 0x8U, /*!< Prescaler divide 512, glitch filter 256 */
|
||||
kLPTMR_Prescale_Glitch_9 = 0x9U, /*!< Prescaler divide 1024, glitch filter 512*/
|
||||
kLPTMR_Prescale_Glitch_10 = 0xAU, /*!< Prescaler divide 2048 glitch filter 1024 */
|
||||
kLPTMR_Prescale_Glitch_11 = 0xBU, /*!< Prescaler divide 4096, glitch filter 2048 */
|
||||
kLPTMR_Prescale_Glitch_12 = 0xCU, /*!< Prescaler divide 8192, glitch filter 4096 */
|
||||
kLPTMR_Prescale_Glitch_13 = 0xDU, /*!< Prescaler divide 16384, glitch filter 8192 */
|
||||
kLPTMR_Prescale_Glitch_14 = 0xEU, /*!< Prescaler divide 32768, glitch filter 16384 */
|
||||
kLPTMR_Prescale_Glitch_15 = 0xFU /*!< Prescaler divide 65536, glitch filter 32768 */
|
||||
} lptmr_prescaler_glitch_value_t;
|
||||
|
||||
/*!
|
||||
* @brief LPTMR prescaler/glitch filter clock select.
|
||||
* @note Clock connections are SoC-specific
|
||||
*/
|
||||
typedef enum _lptmr_prescaler_clock_select
|
||||
{
|
||||
kLPTMR_PrescalerClock_0 = 0x0U, /*!< Prescaler/glitch filter clock 0 selected. */
|
||||
kLPTMR_PrescalerClock_1 = 0x1U, /*!< Prescaler/glitch filter clock 1 selected. */
|
||||
kLPTMR_PrescalerClock_2 = 0x2U, /*!< Prescaler/glitch filter clock 2 selected. */
|
||||
kLPTMR_PrescalerClock_3 = 0x3U, /*!< Prescaler/glitch filter clock 3 selected. */
|
||||
} lptmr_prescaler_clock_select_t;
|
||||
|
||||
/*! @brief List of LPTMR interrupts */
|
||||
typedef enum _lptmr_interrupt_enable
|
||||
{
|
||||
kLPTMR_TimerInterruptEnable = LPTMR_CSR_TIE_MASK, /*!< Timer interrupt enable */
|
||||
} lptmr_interrupt_enable_t;
|
||||
|
||||
/*! @brief List of LPTMR status flags */
|
||||
typedef enum _lptmr_status_flags
|
||||
{
|
||||
kLPTMR_TimerCompareFlag = LPTMR_CSR_TCF_MASK, /*!< Timer compare flag */
|
||||
} lptmr_status_flags_t;
|
||||
|
||||
/*!
|
||||
* @brief LPTMR config structure
|
||||
*
|
||||
* This structure holds the configuration settings for the LPTMR peripheral. To initialize this
|
||||
* structure to reasonable defaults, call the LPTMR_GetDefaultConfig() function and pass a
|
||||
* pointer to your config structure instance.
|
||||
*
|
||||
* The config struct can be made const so it resides in flash
|
||||
*/
|
||||
typedef struct _lptmr_config
|
||||
{
|
||||
lptmr_timer_mode_t timerMode; /*!< Time counter mode or pulse counter mode */
|
||||
lptmr_pin_select_t pinSelect; /*!< LPTMR pulse input pin select; used only in pulse counter mode */
|
||||
lptmr_pin_polarity_t pinPolarity; /*!< LPTMR pulse input pin polarity; used only in pulse counter mode */
|
||||
bool enableFreeRunning; /*!< true: enable free running, counter is reset on overflow
|
||||
false: counter is reset when the compare flag is set */
|
||||
bool bypassPrescaler; /*!< true: bypass prescaler; false: use clock from prescaler */
|
||||
lptmr_prescaler_clock_select_t prescalerClockSource; /*!< LPTMR clock source */
|
||||
lptmr_prescaler_glitch_value_t value; /*!< Prescaler or glitch filter value */
|
||||
} lptmr_config_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @name Initialization and deinitialization
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Ungate the LPTMR clock and configures the peripheral for basic operation.
|
||||
*
|
||||
* @note This API should be called at the beginning of the application using the LPTMR driver.
|
||||
*
|
||||
* @param base LPTMR peripheral base address
|
||||
* @param config Pointer to user's LPTMR config structure.
|
||||
*/
|
||||
void LPTMR_Init(LPTMR_Type *base, const lptmr_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Gate the LPTMR clock
|
||||
*
|
||||
* @param base LPTMR peripheral base address
|
||||
*/
|
||||
void LPTMR_Deinit(LPTMR_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Fill in the LPTMR config struct with the default settings
|
||||
*
|
||||
* The default values are:
|
||||
* @code
|
||||
* config->timerMode = kLPTMR_TimerModeTimeCounter;
|
||||
* config->pinSelect = kLPTMR_PinSelectInput_0;
|
||||
* config->pinPolarity = kLPTMR_PinPolarityActiveHigh;
|
||||
* config->enableFreeRunning = false;
|
||||
* config->bypassPrescaler = true;
|
||||
* config->prescalerClockSource = kLPTMR_PrescalerClock_1;
|
||||
* config->value = kLPTMR_Prescale_Glitch_0;
|
||||
* @endcode
|
||||
* @param config Pointer to user's LPTMR config structure.
|
||||
*/
|
||||
void LPTMR_GetDefaultConfig(lptmr_config_t *config);
|
||||
|
||||
/*! @}*/
|
||||
|
||||
/*!
|
||||
* @name Interrupt Interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Enables the selected LPTMR interrupts.
|
||||
*
|
||||
* @param base LPTMR peripheral base address
|
||||
* @param mask The interrupts to enable. This is a logical OR of members of the
|
||||
* enumeration ::lptmr_interrupt_enable_t
|
||||
*/
|
||||
static inline void LPTMR_EnableInterrupts(LPTMR_Type *base, uint32_t mask)
|
||||
{
|
||||
base->CSR |= mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disables the selected LPTMR interrupts.
|
||||
*
|
||||
* @param base LPTMR peripheral base address
|
||||
* @param mask The interrupts to disable. This is a logical OR of members of the
|
||||
* enumeration ::lptmr_interrupt_enable_t
|
||||
*/
|
||||
static inline void LPTMR_DisableInterrupts(LPTMR_Type *base, uint32_t mask)
|
||||
{
|
||||
base->CSR &= ~mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets the enabled LPTMR interrupts.
|
||||
*
|
||||
* @param base LPTMR peripheral base address
|
||||
*
|
||||
* @return The enabled interrupts. This is the logical OR of members of the
|
||||
* enumeration ::lptmr_interrupt_enable_t
|
||||
*/
|
||||
static inline uint32_t LPTMR_GetEnabledInterrupts(LPTMR_Type *base)
|
||||
{
|
||||
return (base->CSR & LPTMR_CSR_TIE_MASK);
|
||||
}
|
||||
|
||||
/*! @}*/
|
||||
|
||||
/*!
|
||||
* @name Status Interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Gets the LPTMR status flags
|
||||
*
|
||||
* @param base LPTMR peripheral base address
|
||||
*
|
||||
* @return The status flags. This is the logical OR of members of the
|
||||
* enumeration ::lptmr_status_flags_t
|
||||
*/
|
||||
static inline uint32_t LPTMR_GetStatusFlags(LPTMR_Type *base)
|
||||
{
|
||||
return (base->CSR & LPTMR_CSR_TCF_MASK);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Clears the LPTMR status flags
|
||||
*
|
||||
* @param base LPTMR peripheral base address
|
||||
* @param mask The status flags to clear. This is a logical OR of members of the
|
||||
* enumeration ::lptmr_status_flags_t
|
||||
*/
|
||||
static inline void LPTMR_ClearStatusFlags(LPTMR_Type *base, uint32_t mask)
|
||||
{
|
||||
base->CSR |= mask;
|
||||
}
|
||||
|
||||
/*! @}*/
|
||||
|
||||
/*!
|
||||
* @name Read and Write the timer period
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Sets the timer period in units of count.
|
||||
*
|
||||
* Timers counts from 0 till it equals the count value set here. The count value is written to
|
||||
* the CMR register.
|
||||
*
|
||||
* @note
|
||||
* 1. The TCF flag is set with the CNR equals the count provided here and then increments.
|
||||
* 2. User can call the utility macros provided in fsl_common.h to convert to ticks
|
||||
*
|
||||
* @param base LPTMR peripheral base address
|
||||
* @param ticks Timer period in units of ticks
|
||||
*/
|
||||
static inline void LPTMR_SetTimerPeriod(LPTMR_Type *base, uint16_t ticks)
|
||||
{
|
||||
base->CMR = ticks;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reads the current timer counting value.
|
||||
*
|
||||
* This function returns the real-time timer counting value, in a range from 0 to a
|
||||
* timer period.
|
||||
*
|
||||
* @note User can call the utility macros provided in fsl_common.h to convert ticks to usec or msec
|
||||
*
|
||||
* @param base LPTMR peripheral base address
|
||||
*
|
||||
* @return Current counter value in ticks
|
||||
*/
|
||||
static inline uint16_t LPTMR_GetCurrentTimerCount(LPTMR_Type *base)
|
||||
{
|
||||
/* Must first write any value to the CNR. This will synchronize and register the current value
|
||||
* of the CNR into a temporary register which can then be read
|
||||
*/
|
||||
base->CNR = 0U;
|
||||
return (uint16_t)base->CNR;
|
||||
}
|
||||
|
||||
/*! @}*/
|
||||
|
||||
/*!
|
||||
* @name Timer Start and Stop
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Starts the timer counting.
|
||||
*
|
||||
* After calling this function, the timer counts up to the CMR register value.
|
||||
* Each time the timer reaches CMR value and then increments, it generates a
|
||||
* trigger pulse and sets the timeout interrupt flag. An interrupt will also be
|
||||
* triggered if the timer interrupt is enabled.
|
||||
*
|
||||
* @param base LPTMR peripheral base address
|
||||
*/
|
||||
static inline void LPTMR_StartTimer(LPTMR_Type *base)
|
||||
{
|
||||
base->CSR |= LPTMR_CSR_TEN_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Stops the timer counting.
|
||||
*
|
||||
* This function stops the timer counting and resets the timer's counter register
|
||||
*
|
||||
* @param base LPTMR peripheral base address
|
||||
*/
|
||||
static inline void LPTMR_StopTimer(LPTMR_Type *base)
|
||||
{
|
||||
base->CSR &= ~LPTMR_CSR_TEN_MASK;
|
||||
}
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_LPTMR_H_ */
|
||||
1103
devices/MK22F51212/drivers/fsl_lpuart.c
Normal file
1103
devices/MK22F51212/drivers/fsl_lpuart.c
Normal file
File diff suppressed because it is too large
Load Diff
753
devices/MK22F51212/drivers/fsl_lpuart.h
Normal file
753
devices/MK22F51212/drivers/fsl_lpuart.h
Normal file
File diff suppressed because it is too large
Load Diff
334
devices/MK22F51212/drivers/fsl_lpuart_edma.c
Normal file
334
devices/MK22F51212/drivers/fsl_lpuart_edma.c
Normal file
@@ -0,0 +1,334 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_lpuart_edma.h"
|
||||
#include "fsl_dmamux.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*<! Structure definition for lpuart_edma_private_handle_t. The structure is private. */
|
||||
typedef struct _lpuart_edma_private_handle
|
||||
{
|
||||
LPUART_Type *base;
|
||||
lpuart_edma_handle_t *handle;
|
||||
} lpuart_edma_private_handle_t;
|
||||
|
||||
/* LPUART EDMA transfer handle. */
|
||||
enum _lpuart_edma_tansfer_states
|
||||
{
|
||||
kLPUART_TxIdle, /* TX idle. */
|
||||
kLPUART_TxBusy, /* TX busy. */
|
||||
kLPUART_RxIdle, /* RX idle. */
|
||||
kLPUART_RxBusy /* RX busy. */
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*<! Private handle only used for internally. */
|
||||
static lpuart_edma_private_handle_t s_edmaPrivateHandle[FSL_FEATURE_SOC_LPUART_COUNT];
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief LPUART EDMA send finished callback function.
|
||||
*
|
||||
* This function is called when LPUART EDMA send finished. It disables the LPUART
|
||||
* TX EDMA request and sends @ref kStatus_LPUART_TxIdle to LPUART callback.
|
||||
*
|
||||
* @param handle The EDMA handle.
|
||||
* @param param Callback function parameter.
|
||||
*/
|
||||
static void LPUART_SendEDMACallback(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds);
|
||||
|
||||
/*!
|
||||
* @brief LPUART EDMA receive finished callback function.
|
||||
*
|
||||
* This function is called when LPUART EDMA receive finished. It disables the LPUART
|
||||
* RX EDMA request and sends @ref kStatus_LPUART_RxIdle to LPUART callback.
|
||||
*
|
||||
* @param handle The EDMA handle.
|
||||
* @param param Callback function parameter.
|
||||
*/
|
||||
static void LPUART_ReceiveEDMACallback(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds);
|
||||
|
||||
/*!
|
||||
* @brief Get the LPUART instance from peripheral base address.
|
||||
*
|
||||
* @param base LPUART peripheral base address.
|
||||
* @return LPUART instance.
|
||||
*/
|
||||
extern uint32_t LPUART_GetInstance(LPUART_Type *base);
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
static void LPUART_SendEDMACallback(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds)
|
||||
{
|
||||
lpuart_edma_private_handle_t *lpuartPrivateHandle = (lpuart_edma_private_handle_t *)param;
|
||||
|
||||
/* Avoid the warning for unused variables. */
|
||||
handle = handle;
|
||||
tcds = tcds;
|
||||
|
||||
if (transferDone)
|
||||
{
|
||||
LPUART_TransferAbortSendEDMA(lpuartPrivateHandle->base, lpuartPrivateHandle->handle);
|
||||
|
||||
if (lpuartPrivateHandle->handle->callback)
|
||||
{
|
||||
lpuartPrivateHandle->handle->callback(lpuartPrivateHandle->base, lpuartPrivateHandle->handle,
|
||||
kStatus_LPUART_TxIdle, lpuartPrivateHandle->handle->userData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void LPUART_ReceiveEDMACallback(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds)
|
||||
{
|
||||
lpuart_edma_private_handle_t *lpuartPrivateHandle = (lpuart_edma_private_handle_t *)param;
|
||||
|
||||
/* Avoid warning for unused parameters. */
|
||||
handle = handle;
|
||||
tcds = tcds;
|
||||
|
||||
if (transferDone)
|
||||
{
|
||||
/* Disable transfer. */
|
||||
LPUART_TransferAbortReceiveEDMA(lpuartPrivateHandle->base, lpuartPrivateHandle->handle);
|
||||
|
||||
if (lpuartPrivateHandle->handle->callback)
|
||||
{
|
||||
lpuartPrivateHandle->handle->callback(lpuartPrivateHandle->base, lpuartPrivateHandle->handle,
|
||||
kStatus_LPUART_RxIdle, lpuartPrivateHandle->handle->userData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LPUART_TransferCreateHandleEDMA(LPUART_Type *base,
|
||||
lpuart_edma_handle_t *handle,
|
||||
lpuart_edma_transfer_callback_t callback,
|
||||
void *userData,
|
||||
edma_handle_t *txEdmaHandle,
|
||||
edma_handle_t *rxEdmaHandle)
|
||||
{
|
||||
assert(handle);
|
||||
|
||||
uint32_t instance = LPUART_GetInstance(base);
|
||||
|
||||
s_edmaPrivateHandle[instance].base = base;
|
||||
s_edmaPrivateHandle[instance].handle = handle;
|
||||
|
||||
memset(handle, 0, sizeof(*handle));
|
||||
|
||||
handle->rxState = kLPUART_RxIdle;
|
||||
handle->txState = kLPUART_TxIdle;
|
||||
|
||||
handle->rxEdmaHandle = rxEdmaHandle;
|
||||
handle->txEdmaHandle = txEdmaHandle;
|
||||
|
||||
handle->callback = callback;
|
||||
handle->userData = userData;
|
||||
|
||||
#if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
|
||||
/* Note:
|
||||
Take care of the RX FIFO, EDMA request only assert when received bytes
|
||||
equal or more than RX water mark, there is potential issue if RX water
|
||||
mark larger than 1.
|
||||
For example, if RX FIFO water mark is 2, upper layer needs 5 bytes and
|
||||
5 bytes are received. the last byte will be saved in FIFO but not trigger
|
||||
EDMA transfer because the water mark is 2.
|
||||
*/
|
||||
if (rxEdmaHandle)
|
||||
{
|
||||
base->WATER &= (~LPUART_WATER_RXWATER_MASK);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Configure TX. */
|
||||
if (txEdmaHandle)
|
||||
{
|
||||
EDMA_SetCallback(handle->txEdmaHandle, LPUART_SendEDMACallback, &s_edmaPrivateHandle[instance]);
|
||||
}
|
||||
|
||||
/* Configure RX. */
|
||||
if (rxEdmaHandle)
|
||||
{
|
||||
EDMA_SetCallback(handle->rxEdmaHandle, LPUART_ReceiveEDMACallback, &s_edmaPrivateHandle[instance]);
|
||||
}
|
||||
}
|
||||
status_t LPUART_SendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer)
|
||||
{
|
||||
assert(handle->txEdmaHandle);
|
||||
|
||||
edma_transfer_config_t xferConfig;
|
||||
status_t status;
|
||||
|
||||
/* Return error if xfer invalid. */
|
||||
if ((0U == xfer->dataSize) || (NULL == xfer->data))
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
/* If previous TX not finished. */
|
||||
if (kLPUART_TxBusy == handle->txState)
|
||||
{
|
||||
status = kStatus_LPUART_TxBusy;
|
||||
}
|
||||
else
|
||||
{
|
||||
handle->txState = kLPUART_TxBusy;
|
||||
handle->txDataSizeAll = xfer->dataSize;
|
||||
|
||||
/* Prepare transfer. */
|
||||
EDMA_PrepareTransfer(&xferConfig, xfer->data, sizeof(uint8_t), (void *)LPUART_GetDataRegisterAddress(base),
|
||||
sizeof(uint8_t), sizeof(uint8_t), xfer->dataSize, kEDMA_MemoryToPeripheral);
|
||||
|
||||
/* Submit transfer. */
|
||||
EDMA_SubmitTransfer(handle->txEdmaHandle, &xferConfig);
|
||||
EDMA_StartTransfer(handle->txEdmaHandle);
|
||||
|
||||
/* Enable LPUART TX EDMA. */
|
||||
LPUART_EnableTxDMA(base, true);
|
||||
|
||||
status = kStatus_Success;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
status_t LPUART_ReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer)
|
||||
{
|
||||
assert(handle->rxEdmaHandle);
|
||||
|
||||
edma_transfer_config_t xferConfig;
|
||||
status_t status;
|
||||
|
||||
/* Return error if xfer invalid. */
|
||||
if ((0U == xfer->dataSize) || (NULL == xfer->data))
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
/* If previous RX not finished. */
|
||||
if (kLPUART_RxBusy == handle->rxState)
|
||||
{
|
||||
status = kStatus_LPUART_RxBusy;
|
||||
}
|
||||
else
|
||||
{
|
||||
handle->rxState = kLPUART_RxBusy;
|
||||
handle->rxDataSizeAll = xfer->dataSize;
|
||||
|
||||
/* Prepare transfer. */
|
||||
EDMA_PrepareTransfer(&xferConfig, (void *)LPUART_GetDataRegisterAddress(base), sizeof(uint8_t), xfer->data,
|
||||
sizeof(uint8_t), sizeof(uint8_t), xfer->dataSize, kEDMA_PeripheralToMemory);
|
||||
|
||||
/* Submit transfer. */
|
||||
EDMA_SubmitTransfer(handle->rxEdmaHandle, &xferConfig);
|
||||
EDMA_StartTransfer(handle->rxEdmaHandle);
|
||||
|
||||
/* Enable LPUART RX EDMA. */
|
||||
LPUART_EnableRxDMA(base, true);
|
||||
|
||||
status = kStatus_Success;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void LPUART_TransferAbortSendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle)
|
||||
{
|
||||
assert(handle->txEdmaHandle);
|
||||
|
||||
/* Disable LPUART TX EDMA. */
|
||||
LPUART_EnableTxDMA(base, false);
|
||||
|
||||
/* Stop transfer. */
|
||||
EDMA_AbortTransfer(handle->txEdmaHandle);
|
||||
|
||||
handle->txState = kLPUART_TxIdle;
|
||||
}
|
||||
|
||||
void LPUART_TransferAbortReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle)
|
||||
{
|
||||
assert(handle->rxEdmaHandle);
|
||||
|
||||
/* Disable LPUART RX EDMA. */
|
||||
LPUART_EnableRxDMA(base, false);
|
||||
|
||||
/* Stop transfer. */
|
||||
EDMA_AbortTransfer(handle->rxEdmaHandle);
|
||||
|
||||
handle->rxState = kLPUART_RxIdle;
|
||||
}
|
||||
|
||||
status_t LPUART_TransferGetReceiveCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count)
|
||||
{
|
||||
assert(handle->rxEdmaHandle);
|
||||
|
||||
if (kLPUART_RxIdle == handle->rxState)
|
||||
{
|
||||
return kStatus_NoTransferInProgress;
|
||||
}
|
||||
|
||||
if (!count)
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
*count = handle->rxDataSizeAll - EDMA_GetRemainingBytes(handle->rxEdmaHandle->base, handle->rxEdmaHandle->channel);
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
status_t LPUART_TransferGetSendCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count)
|
||||
{
|
||||
assert(handle->txEdmaHandle);
|
||||
|
||||
if (kLPUART_TxIdle == handle->txState)
|
||||
{
|
||||
return kStatus_NoTransferInProgress;
|
||||
}
|
||||
|
||||
if (!count)
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
*count = handle->txDataSizeAll - EDMA_GetRemainingBytes(handle->txEdmaHandle->base, handle->txEdmaHandle->channel);
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
190
devices/MK22F51212/drivers/fsl_lpuart_edma.h
Normal file
190
devices/MK22F51212/drivers/fsl_lpuart_edma.h
Normal file
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_LPUART_EDMA_H_
|
||||
#define _FSL_LPUART_EDMA_H_
|
||||
|
||||
#include "fsl_lpuart.h"
|
||||
#include "fsl_dmamux.h"
|
||||
#include "fsl_edma.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup lpuart_edma_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/* Forward declaration of the handle typedef. */
|
||||
typedef struct _lpuart_edma_handle lpuart_edma_handle_t;
|
||||
|
||||
/*! @brief LPUART transfer callback function. */
|
||||
typedef void (*lpuart_edma_transfer_callback_t)(LPUART_Type *base,
|
||||
lpuart_edma_handle_t *handle,
|
||||
status_t status,
|
||||
void *userData);
|
||||
|
||||
/*!
|
||||
* @brief LPUART eDMA handle
|
||||
*/
|
||||
struct _lpuart_edma_handle
|
||||
{
|
||||
lpuart_edma_transfer_callback_t callback; /*!< Callback function. */
|
||||
void *userData; /*!< LPUART callback function parameter.*/
|
||||
size_t rxDataSizeAll; /*!< Size of the data to receive. */
|
||||
size_t txDataSizeAll; /*!< Size of the data to send out. */
|
||||
|
||||
edma_handle_t *txEdmaHandle; /*!< The eDMA TX channel used. */
|
||||
edma_handle_t *rxEdmaHandle; /*!< The eDMA RX channel used. */
|
||||
|
||||
volatile uint8_t txState; /*!< TX transfer state. */
|
||||
volatile uint8_t rxState; /*!< RX transfer state */
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @name eDMA transactional
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes the LPUART handle which is used in transactional functions.
|
||||
* @param base LPUART peripheral base address.
|
||||
* @param handle Pointer to lpuart_edma_handle_t structure.
|
||||
* @param callback Callback function.
|
||||
* @param userData User data.
|
||||
* @param txEdmaHandle User requested DMA handle for TX DMA transfer.
|
||||
* @param rxEdmaHandle User requested DMA handle for RX DMA transfer.
|
||||
*/
|
||||
void LPUART_TransferCreateHandleEDMA(LPUART_Type *base,
|
||||
lpuart_edma_handle_t *handle,
|
||||
lpuart_edma_transfer_callback_t callback,
|
||||
void *userData,
|
||||
edma_handle_t *txEdmaHandle,
|
||||
edma_handle_t *rxEdmaHandle);
|
||||
|
||||
/*!
|
||||
* @brief Sends data using eDMA.
|
||||
*
|
||||
* This function sends data using eDMA. This is a non-blocking function, which returns
|
||||
* right away. When all data is sent, the send callback function is called.
|
||||
*
|
||||
* @param base LPUART peripheral base address.
|
||||
* @param handle LPUART handle pointer.
|
||||
* @param xfer LPUART eDMA transfer structure. See #lpuart_transfer_t.
|
||||
* @retval kStatus_Success if succeed, others failed.
|
||||
* @retval kStatus_LPUART_TxBusy Previous transfer on going.
|
||||
* @retval kStatus_InvalidArgument Invalid argument.
|
||||
*/
|
||||
status_t LPUART_SendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer);
|
||||
|
||||
/*!
|
||||
* @brief Receives data using eDMA.
|
||||
*
|
||||
* This function receives data using eDMA. This is non-blocking function, which returns
|
||||
* right away. When all data is received, the receive callback function is called.
|
||||
*
|
||||
* @param base LPUART peripheral base address.
|
||||
* @param handle Pointer to lpuart_edma_handle_t structure.
|
||||
* @param xfer LPUART eDMA transfer structure, refer to #lpuart_transfer_t.
|
||||
* @retval kStatus_Success if succeed, others fail.
|
||||
* @retval kStatus_LPUART_RxBusy Previous transfer ongoing.
|
||||
* @retval kStatus_InvalidArgument Invalid argument.
|
||||
*/
|
||||
status_t LPUART_ReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer);
|
||||
|
||||
/*!
|
||||
* @brief Aborts the sent data using eDMA.
|
||||
*
|
||||
* This function aborts the sent data using eDMA.
|
||||
*
|
||||
* @param base LPUART peripheral base address.
|
||||
* @param handle Pointer to lpuart_edma_handle_t structure.
|
||||
*/
|
||||
void LPUART_TransferAbortSendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle);
|
||||
|
||||
/*!
|
||||
* @brief Aborts the received data using eDMA.
|
||||
*
|
||||
* This function aborts the received data using eDMA.
|
||||
*
|
||||
* @param base LPUART peripheral base address.
|
||||
* @param handle Pointer to lpuart_edma_handle_t structure.
|
||||
*/
|
||||
void LPUART_TransferAbortReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle);
|
||||
|
||||
/*!
|
||||
* @brief Get the number of bytes that have been written to LPUART TX register.
|
||||
*
|
||||
* This function gets the number of bytes that have been written to LPUART TX
|
||||
* register by DMA.
|
||||
*
|
||||
* @param base LPUART peripheral base address.
|
||||
* @param handle LPUART handle pointer.
|
||||
* @param count Send bytes count.
|
||||
* @retval kStatus_NoTransferInProgress No send in progress.
|
||||
* @retval kStatus_InvalidArgument Parameter is invalid.
|
||||
* @retval kStatus_Success Get successfully through the parameter \p count;
|
||||
*/
|
||||
status_t LPUART_TransferGetSendCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count);
|
||||
|
||||
/*!
|
||||
* @brief Get the number of bytes that have been received.
|
||||
*
|
||||
* This function gets the number of bytes that have been received.
|
||||
*
|
||||
* @param base LPUART peripheral base address.
|
||||
* @param handle LPUART handle pointer.
|
||||
* @param count Receive bytes count.
|
||||
* @retval kStatus_NoTransferInProgress No receive in progress.
|
||||
* @retval kStatus_InvalidArgument Parameter is invalid.
|
||||
* @retval kStatus_Success Get successfully through the parameter \p count;
|
||||
*/
|
||||
status_t LPUART_TransferGetReceiveCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count);
|
||||
|
||||
/*@}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_LPUART_EDMA_H_ */
|
||||
135
devices/MK22F51212/drivers/fsl_pdb.c
Normal file
135
devices/MK22F51212/drivers/fsl_pdb.c
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_pdb.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
/*!
|
||||
* @brief Get instance number for PDB module.
|
||||
*
|
||||
* @param base PDB peripheral base address
|
||||
*/
|
||||
static uint32_t PDB_GetInstance(PDB_Type *base);
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
/*! @brief Pointers to PDB bases for each instance. */
|
||||
static PDB_Type *const s_pdbBases[] = PDB_BASE_PTRS;
|
||||
/*! @brief Pointers to PDB clocks for each instance. */
|
||||
const clock_ip_name_t s_pdbClocks[] = PDB_CLOCKS;
|
||||
|
||||
/*******************************************************************************
|
||||
* Codes
|
||||
******************************************************************************/
|
||||
static uint32_t PDB_GetInstance(PDB_Type *base)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
/* Find the instance index from base address mappings. */
|
||||
for (instance = 0; instance < FSL_FEATURE_SOC_PDB_COUNT; instance++)
|
||||
{
|
||||
if (s_pdbBases[instance] == base)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(instance < FSL_FEATURE_SOC_PDB_COUNT);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void PDB_Init(PDB_Type *base, const pdb_config_t *config)
|
||||
{
|
||||
assert(NULL != config);
|
||||
|
||||
uint32_t tmp32;
|
||||
|
||||
/* Enable the clock. */
|
||||
CLOCK_EnableClock(s_pdbClocks[PDB_GetInstance(base)]);
|
||||
|
||||
/* Configure. */
|
||||
/* PDBx_SC. */
|
||||
tmp32 = base->SC &
|
||||
~(PDB_SC_LDMOD_MASK | PDB_SC_PRESCALER_MASK | PDB_SC_TRGSEL_MASK | PDB_SC_MULT_MASK | PDB_SC_CONT_MASK);
|
||||
|
||||
tmp32 |= PDB_SC_LDMOD(config->loadValueMode) | PDB_SC_PRESCALER(config->prescalerDivider) |
|
||||
PDB_SC_TRGSEL(config->triggerInputSource) | PDB_SC_MULT(config->dividerMultiplicationFactor);
|
||||
if (config->enableContinuousMode)
|
||||
{
|
||||
tmp32 |= PDB_SC_CONT_MASK;
|
||||
}
|
||||
base->SC = tmp32;
|
||||
|
||||
PDB_Enable(base, true); /* Enable the PDB module. */
|
||||
}
|
||||
|
||||
void PDB_Deinit(PDB_Type *base)
|
||||
{
|
||||
PDB_Enable(base, false); /* Disable the PDB module. */
|
||||
|
||||
/* Disable the clock. */
|
||||
CLOCK_DisableClock(s_pdbClocks[PDB_GetInstance(base)]);
|
||||
}
|
||||
|
||||
void PDB_GetDefaultConfig(pdb_config_t *config)
|
||||
{
|
||||
assert(NULL != config);
|
||||
|
||||
config->loadValueMode = kPDB_LoadValueImmediately;
|
||||
config->prescalerDivider = kPDB_PrescalerDivider1;
|
||||
config->dividerMultiplicationFactor = kPDB_DividerMultiplicationFactor1;
|
||||
config->triggerInputSource = kPDB_TriggerSoftware;
|
||||
config->enableContinuousMode = false;
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_PDB_HAS_DAC) && FSL_FEATURE_PDB_HAS_DAC
|
||||
void PDB_SetDACTriggerConfig(PDB_Type *base, uint32_t channel, pdb_dac_trigger_config_t *config)
|
||||
{
|
||||
assert(channel < PDB_INTC_COUNT);
|
||||
assert(NULL != config);
|
||||
|
||||
uint32_t tmp32 = 0U;
|
||||
|
||||
/* PDBx_DACINTC. */
|
||||
if (config->enableExternalTriggerInput)
|
||||
{
|
||||
tmp32 |= PDB_INTC_EXT_MASK;
|
||||
}
|
||||
if (config->enableIntervalTrigger)
|
||||
{
|
||||
tmp32 |= PDB_INTC_TOE_MASK;
|
||||
}
|
||||
base->DAC[channel].INTC = tmp32;
|
||||
}
|
||||
#endif /* FSL_FEATURE_PDB_HAS_DAC */
|
||||
576
devices/MK22F51212/drivers/fsl_pdb.h
Normal file
576
devices/MK22F51212/drivers/fsl_pdb.h
Normal file
File diff suppressed because it is too large
Load Diff
119
devices/MK22F51212/drivers/fsl_pit.c
Normal file
119
devices/MK22F51212/drivers/fsl_pit.c
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_pit.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
/*!
|
||||
* @brief Gets the instance from the base address to be used to gate or ungate the module clock
|
||||
*
|
||||
* @param base PIT peripheral base address
|
||||
*
|
||||
* @return The PIT instance
|
||||
*/
|
||||
static uint32_t PIT_GetInstance(PIT_Type *base);
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
/*! @brief Pointers to PIT bases for each instance. */
|
||||
static PIT_Type *const s_pitBases[] = PIT_BASE_PTRS;
|
||||
|
||||
/*! @brief Pointers to PIT clocks for each instance. */
|
||||
static const clock_ip_name_t s_pitClocks[] = PIT_CLOCKS;
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
static uint32_t PIT_GetInstance(PIT_Type *base)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
/* Find the instance index from base address mappings. */
|
||||
for (instance = 0; instance < FSL_FEATURE_SOC_PIT_COUNT; instance++)
|
||||
{
|
||||
if (s_pitBases[instance] == base)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(instance < FSL_FEATURE_SOC_PIT_COUNT);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void PIT_Init(PIT_Type *base, const pit_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
/* Ungate the PIT clock*/
|
||||
CLOCK_EnableClock(s_pitClocks[PIT_GetInstance(base)]);
|
||||
|
||||
/* Enable PIT timers */
|
||||
base->MCR &= ~PIT_MCR_MDIS_MASK;
|
||||
|
||||
/* Config timer operation when in debug mode */
|
||||
if (config->enableRunInDebug)
|
||||
{
|
||||
base->MCR &= ~PIT_MCR_FRZ_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->MCR |= PIT_MCR_FRZ_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
void PIT_Deinit(PIT_Type *base)
|
||||
{
|
||||
/* Disable PIT timers */
|
||||
base->MCR |= PIT_MCR_MDIS_MASK;
|
||||
|
||||
/* Gate the PIT clock*/
|
||||
CLOCK_DisableClock(s_pitClocks[PIT_GetInstance(base)]);
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_PIT_HAS_LIFETIME_TIMER) && FSL_FEATURE_PIT_HAS_LIFETIME_TIMER
|
||||
|
||||
uint64_t PIT_GetLifetimeTimerCount(PIT_Type *base)
|
||||
{
|
||||
uint32_t valueH = 0U;
|
||||
uint32_t valueL = 0U;
|
||||
|
||||
/* LTMR64H should be read before LTMR64L */
|
||||
valueH = base->LTMR64H;
|
||||
valueL = base->LTMR64L;
|
||||
|
||||
return (((uint64_t)valueH << 32U) + (uint64_t)(valueL));
|
||||
}
|
||||
|
||||
#endif /* FSL_FEATURE_PIT_HAS_LIFETIME_TIMER */
|
||||
355
devices/MK22F51212/drivers/fsl_pit.h
Normal file
355
devices/MK22F51212/drivers/fsl_pit.h
Normal file
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_PIT_H_
|
||||
#define _FSL_PIT_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup pit_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
#define FSL_PIT_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0 */
|
||||
/*@}*/
|
||||
|
||||
/*!
|
||||
* @brief List of PIT channels
|
||||
* @note Actual number of available channels is SoC dependent
|
||||
*/
|
||||
typedef enum _pit_chnl
|
||||
{
|
||||
kPIT_Chnl_0 = 0U, /*!< PIT channel number 0*/
|
||||
kPIT_Chnl_1, /*!< PIT channel number 1 */
|
||||
kPIT_Chnl_2, /*!< PIT channel number 2 */
|
||||
kPIT_Chnl_3, /*!< PIT channel number 3 */
|
||||
} pit_chnl_t;
|
||||
|
||||
/*! @brief List of PIT interrupts */
|
||||
typedef enum _pit_interrupt_enable
|
||||
{
|
||||
kPIT_TimerInterruptEnable = PIT_TCTRL_TIE_MASK, /*!< Timer interrupt enable*/
|
||||
} pit_interrupt_enable_t;
|
||||
|
||||
/*! @brief List of PIT status flags */
|
||||
typedef enum _pit_status_flags
|
||||
{
|
||||
kPIT_TimerFlag = PIT_TFLG_TIF_MASK, /*!< Timer flag */
|
||||
} pit_status_flags_t;
|
||||
|
||||
/*!
|
||||
* @brief PIT config structure
|
||||
*
|
||||
* This structure holds the configuration settings for the PIT peripheral. To initialize this
|
||||
* structure to reasonable defaults, call the PIT_GetDefaultConfig() function and pass a
|
||||
* pointer to your config structure instance.
|
||||
*
|
||||
* The config struct can be made const so it resides in flash
|
||||
*/
|
||||
typedef struct _pit_config
|
||||
{
|
||||
bool enableRunInDebug; /*!< true: Timers run in debug mode; false: Timers stop in debug mode */
|
||||
} pit_config_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @name Initialization and deinitialization
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Ungates the PIT clock, enables the PIT module and configures the peripheral for basic operation.
|
||||
*
|
||||
* @note This API should be called at the beginning of the application using the PIT driver.
|
||||
*
|
||||
* @param base PIT peripheral base address
|
||||
* @param config Pointer to user's PIT config structure
|
||||
*/
|
||||
void PIT_Init(PIT_Type *base, const pit_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Gate the PIT clock and disable the PIT module
|
||||
*
|
||||
* @param base PIT peripheral base address
|
||||
*/
|
||||
void PIT_Deinit(PIT_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Fill in the PIT config struct with the default settings
|
||||
*
|
||||
* The default values are:
|
||||
* @code
|
||||
* config->enableRunInDebug = false;
|
||||
* @endcode
|
||||
* @param config Pointer to user's PIT config structure.
|
||||
*/
|
||||
static inline void PIT_GetDefaultConfig(pit_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
/* Timers are stopped in Debug mode */
|
||||
config->enableRunInDebug = false;
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_PIT_HAS_CHAIN_MODE) && FSL_FEATURE_PIT_HAS_CHAIN_MODE
|
||||
|
||||
/*!
|
||||
* @brief Enables or disables chaining a timer with the previous timer.
|
||||
*
|
||||
* When a timer has a chain mode enabled, it only counts after the previous
|
||||
* timer has expired. If the timer n-1 has counted down to 0, counter n
|
||||
* decrements the value by one. Each timer is 32-bits, this allows the developers
|
||||
* to chain timers together and form a longer timer (64-bits and larger). The first timer
|
||||
* (timer 0) cannot be chained to any other timer.
|
||||
*
|
||||
* @param base PIT peripheral base address
|
||||
* @param channel Timer channel number which is chained with the previous timer
|
||||
* @param enable Enable or disable chain.
|
||||
* true: Current timer is chained with the previous timer.
|
||||
* false: Timer doesn't chain with other timers.
|
||||
*/
|
||||
static inline void PIT_SetTimerChainMode(PIT_Type *base, pit_chnl_t channel, bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
base->CHANNEL[channel].TCTRL |= PIT_TCTRL_CHN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->CHANNEL[channel].TCTRL &= ~PIT_TCTRL_CHN_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* FSL_FEATURE_PIT_HAS_CHAIN_MODE */
|
||||
|
||||
/*! @}*/
|
||||
|
||||
/*!
|
||||
* @name Interrupt Interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Enables the selected PIT interrupts.
|
||||
*
|
||||
* @param base PIT peripheral base address
|
||||
* @param channel Timer channel number
|
||||
* @param mask The interrupts to enable. This is a logical OR of members of the
|
||||
* enumeration ::pit_interrupt_enable_t
|
||||
*/
|
||||
static inline void PIT_EnableInterrupts(PIT_Type *base, pit_chnl_t channel, uint32_t mask)
|
||||
{
|
||||
base->CHANNEL[channel].TCTRL |= mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disables the selected PIT interrupts.
|
||||
*
|
||||
* @param base PIT peripheral base address
|
||||
* @param channel Timer channel number
|
||||
* @param mask The interrupts to disable. This is a logical OR of members of the
|
||||
* enumeration ::pit_interrupt_enable_t
|
||||
*/
|
||||
static inline void PIT_DisableInterrupts(PIT_Type *base, pit_chnl_t channel, uint32_t mask)
|
||||
{
|
||||
base->CHANNEL[channel].TCTRL &= ~mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets the enabled PIT interrupts.
|
||||
*
|
||||
* @param base PIT peripheral base address
|
||||
* @param channel Timer channel number
|
||||
*
|
||||
* @return The enabled interrupts. This is the logical OR of members of the
|
||||
* enumeration ::pit_interrupt_enable_t
|
||||
*/
|
||||
static inline uint32_t PIT_GetEnabledInterrupts(PIT_Type *base, pit_chnl_t channel)
|
||||
{
|
||||
return (base->CHANNEL[channel].TCTRL & PIT_TCTRL_TIE_MASK);
|
||||
}
|
||||
|
||||
/*! @}*/
|
||||
|
||||
/*!
|
||||
* @name Status Interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Gets the PIT status flags
|
||||
*
|
||||
* @param base PIT peripheral base address
|
||||
* @param channel Timer channel number
|
||||
*
|
||||
* @return The status flags. This is the logical OR of members of the
|
||||
* enumeration ::pit_status_flags_t
|
||||
*/
|
||||
static inline uint32_t PIT_GetStatusFlags(PIT_Type *base, pit_chnl_t channel)
|
||||
{
|
||||
return (base->CHANNEL[channel].TFLG & PIT_TFLG_TIF_MASK);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Clears the PIT status flags.
|
||||
*
|
||||
* @param base PIT peripheral base address
|
||||
* @param channel Timer channel number
|
||||
* @param mask The status flags to clear. This is a logical OR of members of the
|
||||
* enumeration ::pit_status_flags_t
|
||||
*/
|
||||
static inline void PIT_ClearStatusFlags(PIT_Type *base, pit_chnl_t channel, uint32_t mask)
|
||||
{
|
||||
base->CHANNEL[channel].TFLG = mask;
|
||||
}
|
||||
|
||||
/*! @}*/
|
||||
|
||||
/*!
|
||||
* @name Read and Write the timer period
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Sets the timer period in units of count.
|
||||
*
|
||||
* Timers begin counting from the value set by this function until it reaches 0,
|
||||
* then it will generate an interrupt and load this regiter value again.
|
||||
* Writing a new value to this register will not restart the timer; instead the value
|
||||
* will be loaded after the timer expires.
|
||||
*
|
||||
* @note User can call the utility macros provided in fsl_common.h to convert to ticks
|
||||
*
|
||||
* @param base PIT peripheral base address
|
||||
* @param channel Timer channel number
|
||||
* @param count Timer period in units of ticks
|
||||
*/
|
||||
static inline void PIT_SetTimerPeriod(PIT_Type *base, pit_chnl_t channel, uint32_t count)
|
||||
{
|
||||
base->CHANNEL[channel].LDVAL = count;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reads the current timer counting value.
|
||||
*
|
||||
* This function returns the real-time timer counting value, in a range from 0 to a
|
||||
* timer period.
|
||||
*
|
||||
* @note User can call the utility macros provided in fsl_common.h to convert ticks to usec or msec
|
||||
*
|
||||
* @param base PIT peripheral base address
|
||||
* @param channel Timer channel number
|
||||
*
|
||||
* @return Current timer counting value in ticks
|
||||
*/
|
||||
static inline uint32_t PIT_GetCurrentTimerCount(PIT_Type *base, pit_chnl_t channel)
|
||||
{
|
||||
return base->CHANNEL[channel].CVAL;
|
||||
}
|
||||
|
||||
/*! @}*/
|
||||
|
||||
/*!
|
||||
* @name Timer Start and Stop
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Starts the timer counting.
|
||||
*
|
||||
* After calling this function, timers load period value, count down to 0 and
|
||||
* then load the respective start value again. Each time a timer reaches 0,
|
||||
* it generates a trigger pulse and sets the timeout interrupt flag.
|
||||
*
|
||||
* @param base PIT peripheral base address
|
||||
* @param channel Timer channel number.
|
||||
*/
|
||||
static inline void PIT_StartTimer(PIT_Type *base, pit_chnl_t channel)
|
||||
{
|
||||
base->CHANNEL[channel].TCTRL |= PIT_TCTRL_TEN_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Stops the timer counting.
|
||||
*
|
||||
* This function stops every timer counting. Timers reload their periods
|
||||
* respectively after the next time they call the PIT_DRV_StartTimer.
|
||||
*
|
||||
* @param base PIT peripheral base address
|
||||
* @param channel Timer channel number.
|
||||
*/
|
||||
static inline void PIT_StopTimer(PIT_Type *base, pit_chnl_t channel)
|
||||
{
|
||||
base->CHANNEL[channel].TCTRL &= ~PIT_TCTRL_TEN_MASK;
|
||||
}
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#if defined(FSL_FEATURE_PIT_HAS_LIFETIME_TIMER) && FSL_FEATURE_PIT_HAS_LIFETIME_TIMER
|
||||
|
||||
/*!
|
||||
* @brief Reads the current lifetime counter value.
|
||||
*
|
||||
* The lifetime timer is a 64-bit timer which chains timer 0 and timer 1 together.
|
||||
* Timer 0 and 1 are chained by calling the PIT_SetTimerChainMode before using this timer.
|
||||
* The period of lifetime timer is equal to the "period of timer 0 * period of timer 1".
|
||||
* For the 64-bit value, the higher 32-bit has the value of timer 1, and the lower 32-bit
|
||||
* has the value of timer 0.
|
||||
*
|
||||
* @param base PIT peripheral base address
|
||||
*
|
||||
* @return Current lifetime timer value
|
||||
*/
|
||||
uint64_t PIT_GetLifetimeTimerCount(PIT_Type *base);
|
||||
|
||||
#endif /* FSL_FEATURE_PIT_HAS_LIFETIME_TIMER */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_PIT_H_ */
|
||||
93
devices/MK22F51212/drivers/fsl_pmc.c
Normal file
93
devices/MK22F51212/drivers/fsl_pmc.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "fsl_pmc.h"
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_PARAM) && FSL_FEATURE_PMC_HAS_PARAM)
|
||||
void PMC_GetParam(PMC_Type *base, pmc_param_t *param)
|
||||
{
|
||||
uint32_t reg = base->PARAM;
|
||||
;
|
||||
param->vlpoEnable = (bool)(reg & PMC_PARAM_VLPOE_MASK);
|
||||
param->hvdEnable = (bool)(reg & PMC_PARAM_HVDE_MASK);
|
||||
}
|
||||
#endif /* FSL_FEATURE_PMC_HAS_PARAM */
|
||||
|
||||
void PMC_ConfigureLowVoltDetect(PMC_Type *base, const pmc_low_volt_detect_config_t *config)
|
||||
{
|
||||
base->LVDSC1 = (0U |
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_LVDV) && FSL_FEATURE_PMC_HAS_LVDV)
|
||||
((uint32_t)config->voltSelect << PMC_LVDSC1_LVDV_SHIFT) |
|
||||
#endif
|
||||
((uint32_t)config->enableInt << PMC_LVDSC1_LVDIE_SHIFT) |
|
||||
((uint32_t)config->enableReset << PMC_LVDSC1_LVDRE_SHIFT)
|
||||
/* Clear the Low Voltage Detect Flag with previouse power detect setting */
|
||||
| PMC_LVDSC1_LVDACK_MASK);
|
||||
}
|
||||
|
||||
void PMC_ConfigureLowVoltWarning(PMC_Type *base, const pmc_low_volt_warning_config_t *config)
|
||||
{
|
||||
base->LVDSC2 = (0U |
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_LVWV) && FSL_FEATURE_PMC_HAS_LVWV)
|
||||
((uint32_t)config->voltSelect << PMC_LVDSC2_LVWV_SHIFT) |
|
||||
#endif
|
||||
((uint32_t)config->enableInt << PMC_LVDSC2_LVWIE_SHIFT)
|
||||
/* Clear the Low Voltage Warning Flag with previouse power detect setting */
|
||||
| PMC_LVDSC2_LVWACK_MASK);
|
||||
}
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_HVDSC1) && FSL_FEATURE_PMC_HAS_HVDSC1)
|
||||
void PMC_ConfigureHighVoltDetect(PMC_Type *base, const pmc_high_volt_detect_config_t *config)
|
||||
{
|
||||
base->HVDSC1 = (((uint32_t)config->voltSelect << PMC_HVDSC1_HVDV_SHIFT) |
|
||||
((uint32_t)config->enableInt << PMC_HVDSC1_HVDIE_SHIFT) |
|
||||
((uint32_t)config->enableReset << PMC_HVDSC1_HVDRE_SHIFT)
|
||||
/* Clear the High Voltage Detect Flag with previouse power detect setting */
|
||||
| PMC_HVDSC1_HVDACK_MASK);
|
||||
}
|
||||
#endif /* FSL_FEATURE_PMC_HAS_HVDSC1 */
|
||||
|
||||
#if ((defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE) || \
|
||||
(defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN) || \
|
||||
(defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS))
|
||||
void PMC_ConfigureBandgapBuffer(PMC_Type *base, const pmc_bandgap_buffer_config_t *config)
|
||||
{
|
||||
base->REGSC = (0U
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE)
|
||||
| ((uint32_t)config->enable << PMC_REGSC_BGBE_SHIFT)
|
||||
#endif /* FSL_FEATURE_PMC_HAS_BGBE */
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN)
|
||||
| (((uint32_t)config->enableInLowPowerMode << PMC_REGSC_BGEN_SHIFT))
|
||||
#endif /* FSL_FEATURE_PMC_HAS_BGEN */
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS)
|
||||
| ((uint32_t)config->drive << PMC_REGSC_BGBDS_SHIFT)
|
||||
#endif /* FSL_FEATURE_PMC_HAS_BGBDS */
|
||||
);
|
||||
}
|
||||
#endif
|
||||
423
devices/MK22F51212/drivers/fsl_pmc.h
Normal file
423
devices/MK22F51212/drivers/fsl_pmc.h
Normal file
@@ -0,0 +1,423 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_PMC_H_
|
||||
#define _FSL_PMC_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*! @addtogroup pmc */
|
||||
/*! @{ */
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief PMC driver version */
|
||||
#define FSL_PMC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0. */
|
||||
/*@}*/
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_LVDV) && FSL_FEATURE_PMC_HAS_LVDV)
|
||||
/*!
|
||||
* @brief Low-Voltage Detect Voltage Select
|
||||
*/
|
||||
typedef enum _pmc_low_volt_detect_volt_select
|
||||
{
|
||||
kPMC_LowVoltDetectLowTrip = 0U, /*!< Low trip point selected (VLVD = VLVDL )*/
|
||||
kPMC_LowVoltDetectHighTrip = 1U /*!< High trip point selected (VLVD = VLVDH )*/
|
||||
} pmc_low_volt_detect_volt_select_t;
|
||||
#endif
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_LVWV) && FSL_FEATURE_PMC_HAS_LVWV)
|
||||
/*!
|
||||
* @brief Low-Voltage Warning Voltage Select
|
||||
*/
|
||||
typedef enum _pmc_low_volt_warning_volt_select
|
||||
{
|
||||
kPMC_LowVoltWarningLowTrip = 0U, /*!< Low trip point selected (VLVW = VLVW1)*/
|
||||
kPMC_LowVoltWarningMid1Trip = 1U, /*!< Mid 1 trip point selected (VLVW = VLVW2)*/
|
||||
kPMC_LowVoltWarningMid2Trip = 2U, /*!< Mid 2 trip point selected (VLVW = VLVW3)*/
|
||||
kPMC_LowVoltWarningHighTrip = 3U /*!< High trip point selected (VLVW = VLVW4)*/
|
||||
} pmc_low_volt_warning_volt_select_t;
|
||||
#endif
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_HVDSC1) && FSL_FEATURE_PMC_HAS_HVDSC1)
|
||||
/*!
|
||||
* @brief High-Voltage Detect Voltage Select
|
||||
*/
|
||||
typedef enum _pmc_high_volt_detect_volt_select
|
||||
{
|
||||
kPMC_HighVoltDetectLowTrip = 0U, /*!< Low trip point selected (VHVD = VHVDL )*/
|
||||
kPMC_HighVoltDetectHighTrip = 1U /*!< High trip point selected (VHVD = VHVDH )*/
|
||||
} pmc_high_volt_detect_volt_select_t;
|
||||
#endif /* FSL_FEATURE_PMC_HAS_HVDSC1 */
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS)
|
||||
/*!
|
||||
* @brief Bandgap Buffer Drive Select.
|
||||
*/
|
||||
typedef enum _pmc_bandgap_buffer_drive_select
|
||||
{
|
||||
kPMC_BandgapBufferDriveLow = 0U, /*!< Low drive. */
|
||||
kPMC_BandgapBufferDriveHigh = 1U /*!< High drive. */
|
||||
} pmc_bandgap_buffer_drive_select_t;
|
||||
#endif /* FSL_FEATURE_PMC_HAS_BGBDS */
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_VLPO) && FSL_FEATURE_PMC_HAS_VLPO)
|
||||
/*!
|
||||
* @brief VLPx Option
|
||||
*/
|
||||
typedef enum _pmc_vlp_freq_option
|
||||
{
|
||||
kPMC_FreqRestrict = 0U, /*!< Frequency is restricted in VLPx mode. */
|
||||
kPMC_FreqUnrestrict = 1U /*!< Frequency is unrestricted in VLPx mode. */
|
||||
} pmc_vlp_freq_mode_t;
|
||||
#endif /* FSL_FEATURE_PMC_HAS_VLPO */
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_VERID) && FSL_FEATURE_PMC_HAS_VERID)
|
||||
/*!
|
||||
@brief IP version ID definition.
|
||||
*/
|
||||
typedef struct _pmc_version_id
|
||||
{
|
||||
uint16_t feature; /*!< Feature Specification Number. */
|
||||
uint8_t minor; /*!< Minor version number. */
|
||||
uint8_t major; /*!< Major version number. */
|
||||
} pmc_version_id_t;
|
||||
#endif /* FSL_FEATURE_PMC_HAS_VERID */
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_PARAM) && FSL_FEATURE_PMC_HAS_PARAM)
|
||||
/*! @brief IP parameter definition. */
|
||||
typedef struct _pmc_param
|
||||
{
|
||||
bool vlpoEnable; /*!< VLPO enable. */
|
||||
bool hvdEnable; /*!< HVD enable. */
|
||||
} pmc_param_t;
|
||||
#endif /* FSL_FEATURE_PMC_HAS_PARAM */
|
||||
|
||||
/*!
|
||||
* @brief Low-Voltage Detect Configuration Structure
|
||||
*/
|
||||
typedef struct _pmc_low_volt_detect_config
|
||||
{
|
||||
bool enableInt; /*!< Enable interrupt when low voltage detect*/
|
||||
bool enableReset; /*!< Enable system reset when low voltage detect*/
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_LVDV) && FSL_FEATURE_PMC_HAS_LVDV)
|
||||
pmc_low_volt_detect_volt_select_t voltSelect; /*!< Low voltage detect trip point voltage selection*/
|
||||
#endif
|
||||
} pmc_low_volt_detect_config_t;
|
||||
|
||||
/*!
|
||||
* @brief Low-Voltage Warning Configuration Structure
|
||||
*/
|
||||
typedef struct _pmc_low_volt_warning_config
|
||||
{
|
||||
bool enableInt; /*!< Enable interrupt when low voltage warning*/
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_LVWV) && FSL_FEATURE_PMC_HAS_LVWV)
|
||||
pmc_low_volt_warning_volt_select_t voltSelect; /*!< Low voltage warning trip point voltage selection*/
|
||||
#endif
|
||||
} pmc_low_volt_warning_config_t;
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_HVDSC1) && FSL_FEATURE_PMC_HAS_HVDSC1)
|
||||
/*!
|
||||
* @brief High-Voltage Detect Configuration Structure
|
||||
*/
|
||||
typedef struct _pmc_high_volt_detect_config
|
||||
{
|
||||
bool enableInt; /*!< Enable interrupt when high voltage detect*/
|
||||
bool enableReset; /*!< Enable system reset when high voltage detect*/
|
||||
pmc_high_volt_detect_volt_select_t voltSelect; /*!< High voltage detect trip point voltage selection*/
|
||||
} pmc_high_volt_detect_config_t;
|
||||
#endif /* FSL_FEATURE_PMC_HAS_HVDSC1 */
|
||||
|
||||
#if ((defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE) || \
|
||||
(defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN) || \
|
||||
(defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS))
|
||||
/*!
|
||||
* @brief Bandgap Buffer configuration.
|
||||
*/
|
||||
typedef struct _pmc_bandgap_buffer_config
|
||||
{
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE)
|
||||
bool enable; /*!< Enable bandgap buffer. */
|
||||
#endif
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN)
|
||||
bool enableInLowPowerMode; /*!< Enable bandgap buffer in low power mode. */
|
||||
#endif /* FSL_FEATURE_PMC_HAS_BGEN */
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS)
|
||||
pmc_bandgap_buffer_drive_select_t drive; /*!< Bandgap buffer drive select. */
|
||||
#endif /* FSL_FEATURE_PMC_HAS_BGBDS */
|
||||
} pmc_bandgap_buffer_config_t;
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus*/
|
||||
|
||||
/*! @name Power Management Controller Control APIs*/
|
||||
/*@{*/
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_VERID) && FSL_FEATURE_PMC_HAS_VERID)
|
||||
/*!
|
||||
* @brief Gets the PMC version ID.
|
||||
*
|
||||
* This function gets the PMC version ID, including major version number,
|
||||
* minor version number and feature specification number.
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
* @param versionId Pointer to version ID structure.
|
||||
*/
|
||||
static inline void PMC_GetVersionId(PMC_Type *base, pmc_version_id_t *versionId)
|
||||
{
|
||||
*((uint32_t *)versionId) = base->VERID;
|
||||
}
|
||||
#endif /* FSL_FEATURE_PMC_HAS_VERID */
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_PARAM) && FSL_FEATURE_PMC_HAS_PARAM)
|
||||
/*!
|
||||
* @brief Gets the PMC parameter.
|
||||
*
|
||||
* This function gets the PMC parameter, including VLPO enable and HVD enable.
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
* @param param Pointer to PMC param structure.
|
||||
*/
|
||||
void PMC_GetParam(PMC_Type *base, pmc_param_t *param);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Configure the low voltage detect setting.
|
||||
*
|
||||
* This function configures the low voltage detect setting, including the trip
|
||||
* point voltage setting, enable interrupt or not, enable system reset or not.
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
* @param config Low-Voltage detect configuration structure.
|
||||
*/
|
||||
void PMC_ConfigureLowVoltDetect(PMC_Type *base, const pmc_low_volt_detect_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Get Low-Voltage Detect Flag status
|
||||
*
|
||||
* This function reads the current LVDF status. If it returns 1, a low
|
||||
* voltage event is detected.
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
* @return Current low voltage detect flag
|
||||
* - true: Low-Voltage detected
|
||||
* - false: Low-Voltage not detected
|
||||
*/
|
||||
static inline bool PMC_GetLowVoltDetectFlag(PMC_Type *base)
|
||||
{
|
||||
return (bool)(base->LVDSC1 & PMC_LVDSC1_LVDF_MASK);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Acknowledge to clear the Low-Voltage Detect flag
|
||||
*
|
||||
* This function acknowledges the low voltage detection errors (write 1 to
|
||||
* clear LVDF).
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
*/
|
||||
static inline void PMC_ClearLowVoltDetectFlag(PMC_Type *base)
|
||||
{
|
||||
base->LVDSC1 |= PMC_LVDSC1_LVDACK_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Configure the low voltage warning setting.
|
||||
*
|
||||
* This function configures the low voltage warning setting, including the trip
|
||||
* point voltage setting and enable interrupt or not.
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
* @param config Low-Voltage warning configuration structure.
|
||||
*/
|
||||
void PMC_ConfigureLowVoltWarning(PMC_Type *base, const pmc_low_volt_warning_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Get Low-Voltage Warning Flag status
|
||||
*
|
||||
* This function polls the current LVWF status. When 1 is returned, it
|
||||
* indicates a low-voltage warning event. LVWF is set when V Supply transitions
|
||||
* below the trip point or after reset and V Supply is already below the V LVW.
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
* @return Current LVWF status
|
||||
* - true: Low-Voltage Warning Flag is set.
|
||||
* - false: the Low-Voltage Warning does not happen.
|
||||
*/
|
||||
static inline bool PMC_GetLowVoltWarningFlag(PMC_Type *base)
|
||||
{
|
||||
return (bool)(base->LVDSC2 & PMC_LVDSC2_LVWF_MASK);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Acknowledge to Low-Voltage Warning flag
|
||||
*
|
||||
* This function acknowledges the low voltage warning errors (write 1 to
|
||||
* clear LVWF).
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
*/
|
||||
static inline void PMC_ClearLowVoltWarningFlag(PMC_Type *base)
|
||||
{
|
||||
base->LVDSC2 |= PMC_LVDSC2_LVWACK_MASK;
|
||||
}
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_HVDSC1) && FSL_FEATURE_PMC_HAS_HVDSC1)
|
||||
/*!
|
||||
* @brief Configure the high voltage detect setting.
|
||||
*
|
||||
* This function configures the high voltage detect setting, including the trip
|
||||
* point voltage setting, enable interrupt or not, enable system reset or not.
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
* @param config High-Voltage detect configuration structure.
|
||||
*/
|
||||
void PMC_ConfigureHighVoltDetect(PMC_Type *base, const pmc_high_volt_detect_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Get High-Voltage Detect Flag status
|
||||
*
|
||||
* This function reads the current HVDF status. If it returns 1, a low
|
||||
* voltage event is detected.
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
* @return Current high voltage detect flag
|
||||
* - true: High-Voltage detected
|
||||
* - false: High-Voltage not detected
|
||||
*/
|
||||
static inline bool PMC_GetHighVoltDetectFlag(PMC_Type *base)
|
||||
{
|
||||
return (bool)(base->HVDSC1 & PMC_HVDSC1_HVDF_MASK);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Acknowledge to clear the High-Voltage Detect flag
|
||||
*
|
||||
* This function acknowledges the high voltage detection errors (write 1 to
|
||||
* clear HVDF).
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
*/
|
||||
static inline void PMC_ClearHighVoltDetectFlag(PMC_Type *base)
|
||||
{
|
||||
base->HVDSC1 |= PMC_HVDSC1_HVDACK_MASK;
|
||||
}
|
||||
#endif /* FSL_FEATURE_PMC_HAS_HVDSC1 */
|
||||
|
||||
#if ((defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE) || \
|
||||
(defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN) || \
|
||||
(defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS))
|
||||
/*!
|
||||
* @brief Configure the PMC bandgap
|
||||
*
|
||||
* This function configures the PMC bandgap, including the drive select and
|
||||
* behavior in low power mode.
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
* @param config Pointer to the configuration structure
|
||||
*/
|
||||
void PMC_ConfigureBandgapBuffer(PMC_Type *base, const pmc_bandgap_buffer_config_t *config);
|
||||
#endif
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_ACKISO) && FSL_FEATURE_PMC_HAS_ACKISO)
|
||||
/*!
|
||||
* @brief Gets the acknowledge Peripherals and I/O pads isolation flag.
|
||||
*
|
||||
* This function reads the Acknowledge Isolation setting that indicates
|
||||
* whether certain peripherals and the I/O pads are in a latched state as
|
||||
* a result of having been in the VLLS mode.
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
* @param base Base address for current PMC instance.
|
||||
* @return ACK isolation
|
||||
* 0 - Peripherals and I/O pads are in a normal run state.
|
||||
* 1 - Certain peripherals and I/O pads are in an isolated and
|
||||
* latched state.
|
||||
*/
|
||||
static inline bool PMC_GetPeriphIOIsolationFlag(PMC_Type *base)
|
||||
{
|
||||
return (bool)(base->REGSC & PMC_REGSC_ACKISO_MASK);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Acknowledge to Peripherals and I/O pads isolation flag.
|
||||
*
|
||||
* This function clears the ACK Isolation flag. Writing one to this setting
|
||||
* when it is set releases the I/O pads and certain peripherals to their normal
|
||||
* run mode state.
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
*/
|
||||
static inline void PMC_ClearPeriphIOIsolationFlag(PMC_Type *base)
|
||||
{
|
||||
base->REGSC |= PMC_REGSC_ACKISO_MASK;
|
||||
}
|
||||
#endif /* FSL_FEATURE_PMC_HAS_ACKISO */
|
||||
|
||||
#if (defined(FSL_FEATURE_PMC_HAS_REGONS) && FSL_FEATURE_PMC_HAS_REGONS)
|
||||
/*!
|
||||
* @brief Gets the Regulator regulation status.
|
||||
*
|
||||
* This function returns the regulator to a run regulation status. It provides
|
||||
* the current status of the internal voltage regulator.
|
||||
*
|
||||
* @param base PMC peripheral base address.
|
||||
* @param base Base address for current PMC instance.
|
||||
* @return Regulation status
|
||||
* 0 - Regulator is in a stop regulation or in transition to/from the regulation.
|
||||
* 1 - Regulator is in a run regulation.
|
||||
*
|
||||
*/
|
||||
static inline bool PMC_IsRegulatorInRunRegulation(PMC_Type *base)
|
||||
{
|
||||
return (bool)(base->REGSC & PMC_REGSC_REGONS_MASK);
|
||||
}
|
||||
#endif /* FSL_FEATURE_PMC_HAS_REGONS */
|
||||
|
||||
/*@}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus*/
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_PMC_H_*/
|
||||
382
devices/MK22F51212/drivers/fsl_port.h
Normal file
382
devices/MK22F51212/drivers/fsl_port.h
Normal file
@@ -0,0 +1,382 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SDRVL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_PORT_H_
|
||||
#define _FSL_PORT_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup port_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! Version 2.0.1. */
|
||||
#define FSL_PORT_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
|
||||
/*@}*/
|
||||
|
||||
/*! @brief Internal resistor pull feature selection */
|
||||
enum _port_pull
|
||||
{
|
||||
kPORT_PullDisable = 0U, /*!< internal pull-up/down resistor is disabled. */
|
||||
kPORT_PullDown = 2U, /*!< internal pull-down resistor is enabled. */
|
||||
kPORT_PullUp = 3U, /*!< internal pull-up resistor is enabled. */
|
||||
};
|
||||
|
||||
/*! @brief Slew rate selection */
|
||||
enum _port_slew_rate
|
||||
{
|
||||
kPORT_FastSlewRate = 0U, /*!< fast slew rate is configured. */
|
||||
kPORT_SlowSlewRate = 1U, /*!< slow slew rate is configured. */
|
||||
};
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_OPEN_DRAIN) && FSL_FEATURE_PORT_HAS_OPEN_DRAIN
|
||||
/*! @brief Internal resistor pull feature enable/disable */
|
||||
enum _port_open_drain_enable
|
||||
{
|
||||
kPORT_OpenDrainDisable = 0U, /*!< internal pull-down resistor is disabled. */
|
||||
kPORT_OpenDrainEnable = 1U, /*!< internal pull-up resistor is enabled. */
|
||||
};
|
||||
#endif /* FSL_FEATURE_PORT_HAS_OPEN_DRAIN */
|
||||
|
||||
/*! @brief Passive filter feature enable/disable */
|
||||
enum _port_passive_filter_enable
|
||||
{
|
||||
kPORT_PassiveFilterDisable = 0U, /*!< fast slew rate is configured. */
|
||||
kPORT_PassiveFilterEnable = 1U, /*!< slow slew rate is configured. */
|
||||
};
|
||||
|
||||
/*! @brief Configures the drive strength. */
|
||||
enum _port_drive_strength
|
||||
{
|
||||
kPORT_LowDriveStrength = 0U, /*!< low drive strength is configured. */
|
||||
kPORT_HighDriveStrength = 1U, /*!< high drive strength is configured. */
|
||||
};
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK) && FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK
|
||||
/*! @brief Unlock/lock the pin control register field[15:0] */
|
||||
enum _port_lock_register
|
||||
{
|
||||
kPORT_UnlockRegister = 0U, /*!< Pin Control Register fields [15:0] are not locked. */
|
||||
kPORT_LockRegister = 1U, /*!< Pin Control Register fields [15:0] are locked. */
|
||||
};
|
||||
#endif /* FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK */
|
||||
|
||||
/*! @brief Pin mux selection */
|
||||
typedef enum _port_mux
|
||||
{
|
||||
kPORT_PinDisabledOrAnalog = 0U, /*!< corresponding pin is disabled, but is used as an analog pin. */
|
||||
kPORT_MuxAsGpio = 1U, /*!< corresponding pin is configured as GPIO. */
|
||||
kPORT_MuxAlt2 = 2U, /*!< chip-specific */
|
||||
kPORT_MuxAlt3 = 3U, /*!< chip-specific */
|
||||
kPORT_MuxAlt4 = 4U, /*!< chip-specific */
|
||||
kPORT_MuxAlt5 = 5U, /*!< chip-specific */
|
||||
kPORT_MuxAlt6 = 6U, /*!< chip-specific */
|
||||
kPORT_MuxAlt7 = 7U, /*!< chip-specific */
|
||||
} port_mux_t;
|
||||
|
||||
/*! @brief Configures the interrupt generation condition. */
|
||||
typedef enum _port_interrupt
|
||||
{
|
||||
kPORT_InterruptOrDMADisabled = 0x0U, /*!< Interrupt/DMA request is disabled. */
|
||||
#if defined(FSL_FEATURE_PORT_HAS_DMA_REQUEST) && FSL_FEATURE_PORT_HAS_DMA_REQUEST
|
||||
kPORT_DMARisingEdge = 0x1U, /*!< DMA request on rising edge. */
|
||||
kPORT_DMAFallingEdge = 0x2U, /*!< DMA request on falling edge. */
|
||||
kPORT_DMAEitherEdge = 0x3U, /*!< DMA request on either edge. */
|
||||
#endif
|
||||
#if defined(FSL_FEATURE_PORT_HAS_IRQC_FLAG) && FSL_FEATURE_PORT_HAS_IRQC_FLAG
|
||||
kPORT_FlagRisingEdge = 0x05U, /*!< Flag sets on rising edge. */
|
||||
kPORT_FlagFallingEdge = 0x06U, /*!< Flag sets on falling edge. */
|
||||
kPORT_FlagEitherEdge = 0x07U, /*!< Flag sets on either edge. */
|
||||
#endif
|
||||
kPORT_InterruptLogicZero = 0x8U, /*!< Interrupt when logic zero. */
|
||||
kPORT_InterruptRisingEdge = 0x9U, /*!< Interrupt on rising edge. */
|
||||
kPORT_InterruptFallingEdge = 0xAU, /*!< Interrupt on falling edge. */
|
||||
kPORT_InterruptEitherEdge = 0xBU, /*!< Interrupt on either edge. */
|
||||
kPORT_InterruptLogicOne = 0xCU, /*!< Interrupt when logic one. */
|
||||
#if defined(FSL_FEATURE_PORT_HAS_IRQC_TRIGGER) && FSL_FEATURE_PORT_HAS_IRQC_TRIGGER
|
||||
kPORT_ActiveHighTriggerOutputEnable = 0xDU, /*!< Enable active high trigger output. */
|
||||
kPORT_ActiveLowTriggerOutputEnable = 0xEU, /*!< Enable active low trigger output. */
|
||||
#endif
|
||||
} port_interrupt_t;
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_DIGITAL_FILTER) && FSL_FEATURE_PORT_HAS_DIGITAL_FILTER
|
||||
/*! @brief Digital filter clock source selection */
|
||||
typedef enum _port_digital_filter_clock_source
|
||||
{
|
||||
kPORT_BusClock = 0U, /*!< Digital filters are clocked by the bus clock. */
|
||||
kPORT_LpoClock = 1U, /*!< Digital filters are clocked by the 1 kHz LPO clock. */
|
||||
} port_digital_filter_clock_source_t;
|
||||
|
||||
/*! @brief PORT digital filter feature configuration definition */
|
||||
typedef struct _port_digital_filter_config
|
||||
{
|
||||
uint32_t digitalFilterWidth; /*!< Set digital filter width */
|
||||
port_digital_filter_clock_source_t clockSource; /*!< Set digital filter clockSource */
|
||||
} port_digital_filter_config_t;
|
||||
#endif /* FSL_FEATURE_PORT_HAS_DIGITAL_FILTER */
|
||||
|
||||
/*! @brief PORT pin config structure */
|
||||
typedef struct _port_pin_config
|
||||
{
|
||||
uint16_t pullSelect : 2; /*!< no-pull/pull-down/pull-up select */
|
||||
uint16_t slewRate : 1; /*!< fast/slow slew rate Configure */
|
||||
uint16_t : 1;
|
||||
uint16_t passiveFilterEnable : 1; /*!< passive filter enable/disable */
|
||||
#if defined(FSL_FEATURE_PORT_HAS_OPEN_DRAIN) && FSL_FEATURE_PORT_HAS_OPEN_DRAIN
|
||||
uint16_t openDrainEnable : 1; /*!< open drain enable/disable */
|
||||
#else
|
||||
uint16_t : 1;
|
||||
#endif /* FSL_FEATURE_PORT_HAS_OPEN_DRAIN */
|
||||
uint16_t driveStrength : 1; /*!< fast/slow drive strength configure */
|
||||
uint16_t : 1;
|
||||
uint16_t mux : 3; /*!< pin mux Configure */
|
||||
uint16_t : 4;
|
||||
#if defined(FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK) && FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK
|
||||
uint16_t lockRegister : 1; /*!< lock/unlock the pcr field[15:0] */
|
||||
#else
|
||||
uint16_t : 1;
|
||||
#endif /* FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK */
|
||||
} port_pin_config_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*! @name Configuration */
|
||||
/*@{*/
|
||||
|
||||
/*!
|
||||
* @brief Sets the port PCR register.
|
||||
*
|
||||
* This is an example to define an input pin or output pin PCR configuration:
|
||||
* @code
|
||||
* // Define a digital input pin PCR configuration
|
||||
* port_pin_config_t config = {
|
||||
* kPORT_PullUp,
|
||||
* kPORT_FastSlewRate,
|
||||
* kPORT_PassiveFilterDisable,
|
||||
* kPORT_OpenDrainDisable,
|
||||
* kPORT_LowDriveStrength,
|
||||
* kPORT_MuxAsGpio,
|
||||
* kPORT_UnLockRegister,
|
||||
* };
|
||||
* @endcode
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param pin PORT pin number.
|
||||
* @param config PORT PCR register configure structure.
|
||||
*/
|
||||
static inline void PORT_SetPinConfig(PORT_Type *base, uint32_t pin, const port_pin_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
uint32_t addr = (uint32_t)&base->PCR[pin];
|
||||
*(volatile uint16_t *)(addr) = *((const uint16_t *)config);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets the port PCR register for multiple pins.
|
||||
*
|
||||
* This is an example to define input pins or output pins PCR configuration:
|
||||
* @code
|
||||
* // Define a digital input pin PCR configuration
|
||||
* port_pin_config_t config = {
|
||||
* kPORT_PullUp ,
|
||||
* kPORT_PullEnable,
|
||||
* kPORT_FastSlewRate,
|
||||
* kPORT_PassiveFilterDisable,
|
||||
* kPORT_OpenDrainDisable,
|
||||
* kPORT_LowDriveStrength,
|
||||
* kPORT_MuxAsGpio,
|
||||
* kPORT_UnlockRegister,
|
||||
* };
|
||||
* @endcode
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param mask PORT pins' numbers macro.
|
||||
* @param config PORT PCR register configure structure.
|
||||
*/
|
||||
static inline void PORT_SetMultiplePinsConfig(PORT_Type *base, uint32_t mask, const port_pin_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
uint16_t pcrl = *((const uint16_t *)config);
|
||||
|
||||
if (mask & 0xffffU)
|
||||
{
|
||||
base->GPCLR = ((mask & 0xffffU) << 16) | pcrl;
|
||||
}
|
||||
if (mask >> 16)
|
||||
{
|
||||
base->GPCHR = (mask & 0xffff0000U) | pcrl;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Configures the pin muxing.
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param pin PORT pin number.
|
||||
* @param mux pin muxing slot selection.
|
||||
* - #kPORT_PinDisabledOrAnalog: Pin disabled or work in analog function.
|
||||
* - #kPORT_MuxAsGpio : Set as GPIO.
|
||||
* - #kPORT_MuxAlt2 : chip-specific.
|
||||
* - #kPORT_MuxAlt3 : chip-specific.
|
||||
* - #kPORT_MuxAlt4 : chip-specific.
|
||||
* - #kPORT_MuxAlt5 : chip-specific.
|
||||
* - #kPORT_MuxAlt6 : chip-specific.
|
||||
* - #kPORT_MuxAlt7 : chip-specific.
|
||||
* @Note : This function is NOT recommended to use together with the PORT_SetPinsConfig, because
|
||||
* the PORT_SetPinsConfig need to configure the pin mux anyway (Otherwise the pin mux will
|
||||
* be reset to zero : kPORT_PinDisabledOrAnalog).
|
||||
* This function is recommended to use in the case you just need to reset the pin mux
|
||||
*
|
||||
*/
|
||||
static inline void PORT_SetPinMux(PORT_Type *base, uint32_t pin, port_mux_t mux)
|
||||
{
|
||||
base->PCR[pin] = (base->PCR[pin] & ~PORT_PCR_MUX_MASK) | PORT_PCR_MUX(mux);
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_PORT_HAS_DIGITAL_FILTER) && FSL_FEATURE_PORT_HAS_DIGITAL_FILTER
|
||||
|
||||
/*!
|
||||
* @brief Enables the digital filter in one port, each bit of the 32-bit register represents one pin.
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param mask PORT pins' numbers macro.
|
||||
*/
|
||||
static inline void PORT_EnablePinsDigitalFilter(PORT_Type *base, uint32_t mask, bool enable)
|
||||
{
|
||||
if (enable == true)
|
||||
{
|
||||
base->DFER |= mask;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->DFER &= ~mask;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets the digital filter in one port, each bit of the 32-bit register represents one pin.
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param config PORT digital filter configuration structure.
|
||||
*/
|
||||
static inline void PORT_SetDigitalFilterConfig(PORT_Type *base, const port_digital_filter_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
base->DFCR = PORT_DFCR_CS(config->clockSource);
|
||||
base->DFWR = PORT_DFWR_FILT(config->digitalFilterWidth);
|
||||
}
|
||||
|
||||
#endif /* FSL_FEATURE_PORT_HAS_DIGITAL_FILTER */
|
||||
|
||||
/*@}*/
|
||||
|
||||
/*! @name Interrupt */
|
||||
/*@{*/
|
||||
|
||||
/*!
|
||||
* @brief Configures the port pin interrupt/DMA request.
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param pin PORT pin number.
|
||||
* @param config PORT pin interrupt configuration.
|
||||
* - #kPORT_InterruptOrDMADisabled: Interrupt/DMA request disabled.
|
||||
* - #kPORT_DMARisingEdge : DMA request on rising edge(if the DMA requests exit).
|
||||
* - #kPORT_DMAFallingEdge: DMA request on falling edge(if the DMA requests exit).
|
||||
* - #kPORT_DMAEitherEdge : DMA request on either edge(if the DMA requests exit).
|
||||
* - #kPORT_FlagRisingEdge : Flag sets on rising edge(if the Flag states exit).
|
||||
* - #kPORT_FlagFallingEdge : Flag sets on falling edge(if the Flag states exit).
|
||||
* - #kPORT_FlagEitherEdge : Flag sets on either edge(if the Flag states exit).
|
||||
* - #kPORT_InterruptLogicZero : Interrupt when logic zero.
|
||||
* - #kPORT_InterruptRisingEdge : Interrupt on rising edge.
|
||||
* - #kPORT_InterruptFallingEdge: Interrupt on falling edge.
|
||||
* - #kPORT_InterruptEitherEdge : Interrupt on either edge.
|
||||
* - #kPORT_InterruptLogicOne : Interrupt when logic one.
|
||||
* - #kPORT_ActiveHighTriggerOutputEnable : Enable active high trigger output(if the trigger states exit).
|
||||
* - #kPORT_ActiveLowTriggerOutputEnable : Enable active low trigger output(if the trigger states exit).
|
||||
*/
|
||||
static inline void PORT_SetPinInterruptConfig(PORT_Type *base, uint32_t pin, port_interrupt_t config)
|
||||
{
|
||||
base->PCR[pin] = (base->PCR[pin] & ~PORT_PCR_IRQC_MASK) | PORT_PCR_IRQC(config);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reads the whole port status flag.
|
||||
*
|
||||
* If a pin is configured to generate the DMA request, the corresponding flag
|
||||
* is cleared automatically at the completion of the requested DMA transfer.
|
||||
* Otherwise, the flag remains set until a logic one is written to that flag.
|
||||
* If configured for a level sensitive interrupt that remains asserted, the flag
|
||||
* is set again immediately.
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @return Current port interrupt status flags, for example, 0x00010001 means the
|
||||
* pin 0 and 17 have the interrupt.
|
||||
*/
|
||||
static inline uint32_t PORT_GetPinsInterruptFlags(PORT_Type *base)
|
||||
{
|
||||
return base->ISFR;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Clears the multiple pins' interrupt status flag.
|
||||
*
|
||||
* @param base PORT peripheral base pointer.
|
||||
* @param mask PORT pins' numbers macro.
|
||||
*/
|
||||
static inline void PORT_ClearPinsInterruptFlags(PORT_Type *base, uint32_t mask)
|
||||
{
|
||||
base->ISFR = mask;
|
||||
}
|
||||
|
||||
/*@}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_PORT_H_ */
|
||||
63
devices/MK22F51212/drivers/fsl_rcm.c
Normal file
63
devices/MK22F51212/drivers/fsl_rcm.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_rcm.h"
|
||||
|
||||
void RCM_ConfigureResetPinFilter(RCM_Type *base, const rcm_reset_pin_filter_config_t *config)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_RCM_REG_WIDTH) && (FSL_FEATURE_RCM_REG_WIDTH == 32))
|
||||
uint32_t reg;
|
||||
|
||||
reg = (((uint32_t)config->enableFilterInStop << RCM_RPC_RSTFLTSS_SHIFT) | (uint32_t)config->filterInRunWait);
|
||||
if (config->filterInRunWait == kRCM_FilterBusClock)
|
||||
{
|
||||
reg |= ((uint32_t)config->busClockFilterCount << RCM_RPC_RSTFLTSEL_SHIFT);
|
||||
}
|
||||
base->RPC = reg;
|
||||
#else
|
||||
base->RPFC = ((uint8_t)(config->enableFilterInStop << RCM_RPFC_RSTFLTSS_SHIFT) | (uint8_t)config->filterInRunWait);
|
||||
if (config->filterInRunWait == kRCM_FilterBusClock)
|
||||
{
|
||||
base->RPFW = config->busClockFilterCount;
|
||||
}
|
||||
#endif /* FSL_FEATURE_RCM_REG_WIDTH */
|
||||
}
|
||||
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_BOOTROM) && FSL_FEATURE_RCM_HAS_BOOTROM)
|
||||
void RCM_SetForceBootRomSource(RCM_Type *base, rcm_boot_rom_config_t config)
|
||||
{
|
||||
uint32_t reg;
|
||||
|
||||
reg = base->FM;
|
||||
reg &= ~RCM_FM_FORCEROM_MASK;
|
||||
reg |= ((uint32_t)config << RCM_FM_FORCEROM_SHIFT);
|
||||
base->FM = reg;
|
||||
}
|
||||
#endif /* #if FSL_FEATURE_RCM_HAS_BOOTROM */
|
||||
432
devices/MK22F51212/drivers/fsl_rcm.h
Normal file
432
devices/MK22F51212/drivers/fsl_rcm.h
Normal file
@@ -0,0 +1,432 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_RCM_H_
|
||||
#define _FSL_RCM_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*! @addtogroup rcm */
|
||||
/*! @{*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief RCM driver version 2.0.0. */
|
||||
#define FSL_RCM_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
|
||||
/*@}*/
|
||||
|
||||
/*!
|
||||
* @brief System Reset Source Name definitions
|
||||
*/
|
||||
typedef enum _rcm_reset_source
|
||||
{
|
||||
#if (defined(FSL_FEATURE_RCM_REG_WIDTH) && (FSL_FEATURE_RCM_REG_WIDTH == 32))
|
||||
/* RCM register bit width is 32. */
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_WAKEUP) && FSL_FEATURE_RCM_HAS_WAKEUP)
|
||||
kRCM_SourceWakeup = RCM_SRS_WAKEUP_MASK, /*!< Low-leakage wakeup reset */
|
||||
#endif
|
||||
kRCM_SourceLvd = RCM_SRS_LVD_MASK, /*!< low voltage detect reset */
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_LOC) && FSL_FEATURE_RCM_HAS_LOC)
|
||||
kRCM_SourceLoc = RCM_SRS_LOC_MASK, /*!< Loss of clock reset */
|
||||
#endif /* FSL_FEATURE_RCM_HAS_LOC */
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_LOL) && FSL_FEATURE_RCM_HAS_LOL)
|
||||
kRCM_SourceLol = RCM_SRS_LOL_MASK, /*!< Loss of lock reset */
|
||||
#endif /* FSL_FEATURE_RCM_HAS_LOL */
|
||||
kRCM_SourceWdog = RCM_SRS_WDOG_MASK, /*!< Watchdog reset */
|
||||
kRCM_SourcePin = RCM_SRS_PIN_MASK, /*!< External pin reset */
|
||||
kRCM_SourcePor = RCM_SRS_POR_MASK, /*!< Power on reset */
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_JTAG) && FSL_FEATURE_RCM_HAS_JTAG)
|
||||
kRCM_SourceJtag = RCM_SRS_JTAG_MASK, /*!< JTAG generated reset */
|
||||
#endif /* FSL_FEATURE_RCM_HAS_JTAG */
|
||||
kRCM_SourceLockup = RCM_SRS_LOCKUP_MASK, /*!< Core lock up reset */
|
||||
kRCM_SourceSw = RCM_SRS_SW_MASK, /*!< Software reset */
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_MDM_AP) && FSL_FEATURE_RCM_HAS_MDM_AP)
|
||||
kRCM_SourceMdmap = RCM_SRS_MDM_AP_MASK, /*!< MDM-AP system reset */
|
||||
#endif /* FSL_FEATURE_RCM_HAS_MDM_AP */
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_EZPORT) && FSL_FEATURE_RCM_HAS_EZPORT)
|
||||
kRCM_SourceEzpt = RCM_SRS_EZPT_MASK, /*!< EzPort reset */
|
||||
#endif /* FSL_FEATURE_RCM_HAS_EZPORT */
|
||||
kRCM_SourceSackerr = RCM_SRS_SACKERR_MASK, /*!< Parameter could get all reset flags */
|
||||
|
||||
#else /* (FSL_FEATURE_RCM_REG_WIDTH == 32) */
|
||||
/* RCM register bit width is 8. */
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_WAKEUP) && FSL_FEATURE_RCM_HAS_WAKEUP)
|
||||
kRCM_SourceWakeup = RCM_SRS0_WAKEUP_MASK, /*!< Low-leakage wakeup reset */
|
||||
#endif
|
||||
kRCM_SourceLvd = RCM_SRS0_LVD_MASK, /*!< low voltage detect reset */
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_LOC) && FSL_FEATURE_RCM_HAS_LOC)
|
||||
kRCM_SourceLoc = RCM_SRS0_LOC_MASK, /*!< Loss of clock reset */
|
||||
#endif /* FSL_FEATURE_RCM_HAS_LOC */
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_LOL) && FSL_FEATURE_RCM_HAS_LOL)
|
||||
kRCM_SourceLol = RCM_SRS0_LOL_MASK, /*!< Loss of lock reset */
|
||||
#endif /* FSL_FEATURE_RCM_HAS_LOL */
|
||||
kRCM_SourceWdog = RCM_SRS0_WDOG_MASK, /*!< Watchdog reset */
|
||||
kRCM_SourcePin = RCM_SRS0_PIN_MASK, /*!< External pin reset */
|
||||
kRCM_SourcePor = RCM_SRS0_POR_MASK, /*!< Power on reset */
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_JTAG) && FSL_FEATURE_RCM_HAS_JTAG)
|
||||
kRCM_SourceJtag = RCM_SRS1_JTAG_MASK << 8U, /*!< JTAG generated reset */
|
||||
#endif /* FSL_FEATURE_RCM_HAS_JTAG */
|
||||
kRCM_SourceLockup = RCM_SRS1_LOCKUP_MASK << 8U, /*!< Core lock up reset */
|
||||
kRCM_SourceSw = RCM_SRS1_SW_MASK, /*!< Software reset */
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_MDM_AP) && FSL_FEATURE_RCM_HAS_MDM_AP)
|
||||
kRCM_SourceMdmap = RCM_SRS1_MDM_AP_MASK << 8U, /*!< MDM-AP system reset */
|
||||
#endif /* FSL_FEATURE_RCM_HAS_MDM_AP */
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_EZPORT) && FSL_FEATURE_RCM_HAS_EZPORT)
|
||||
kRCM_SourceEzpt = RCM_SRS1_EZPT_MASK << 8U, /*!< EzPort reset */
|
||||
#endif /* FSL_FEATURE_RCM_HAS_EZPORT */
|
||||
kRCM_SourceSackerr = RCM_SRS1_SACKERR_MASK << 8U, /*!< Parameter could get all reset flags */
|
||||
#endif /* (FSL_FEATURE_RCM_REG_WIDTH == 32) */
|
||||
kRCM_SourceAll = 0xffffffffU,
|
||||
} rcm_reset_source_t;
|
||||
|
||||
/*!
|
||||
* @brief Reset pin filter select in Run and Wait modes
|
||||
*/
|
||||
typedef enum _rcm_run_wait_filter_mode
|
||||
{
|
||||
kRCM_FilterDisable = 0U, /*!< All filtering disabled */
|
||||
kRCM_FilterBusClock = 1U, /*!< Bus clock filter enabled */
|
||||
kRCM_FilterLpoClock = 2U /*!< LPO clock filter enabled */
|
||||
} rcm_run_wait_filter_mode_t;
|
||||
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_BOOTROM) && FSL_FEATURE_RCM_HAS_BOOTROM)
|
||||
/*!
|
||||
* @brief Boot from ROM configuration.
|
||||
*/
|
||||
typedef enum _rcm_boot_rom_config
|
||||
{
|
||||
kRCM_BootFlash = 0U, /*!< Boot from flash */
|
||||
kRCM_BootRomCfg0 = 1U, /*!< Boot from boot ROM due to BOOTCFG0 */
|
||||
kRCM_BootRomFopt = 2U, /*!< Boot from boot ROM due to FOPT[7] */
|
||||
kRCM_BootRomBoth = 3U /*!< Boot from boot ROM due to both BOOTCFG0 and FOPT[7] */
|
||||
} rcm_boot_rom_config_t;
|
||||
#endif /* FSL_FEATURE_RCM_HAS_BOOTROM */
|
||||
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_SRIE) && FSL_FEATURE_RCM_HAS_SRIE)
|
||||
/*!
|
||||
* @brief Max delay time from interrupt asserts to system reset.
|
||||
*/
|
||||
typedef enum _rcm_reset_delay
|
||||
{
|
||||
kRCM_ResetDelay8Lpo = 0U, /*!< Delay 8 LPO cycles. */
|
||||
kRCM_ResetDelay32Lpo = 1U, /*!< Delay 32 LPO cycles. */
|
||||
kRCM_ResetDelay128Lpo = 2U, /*!< Delay 128 LPO cycles. */
|
||||
kRCM_ResetDelay512Lpo = 3U /*!< Delay 512 LPO cycles. */
|
||||
} rcm_reset_delay_t;
|
||||
|
||||
/*!
|
||||
* @brief System reset interrupt enable bit definitions.
|
||||
*/
|
||||
typedef enum _rcm_interrupt_enable
|
||||
{
|
||||
kRCM_IntNone = 0U, /*!< No interrupt enabled. */
|
||||
kRCM_IntLossOfClk = RCM_SRIE_LOC_MASK, /*!< Loss of clock interrupt. */
|
||||
kRCM_IntLossOfLock = RCM_SRIE_LOL_MASK, /*!< Loss of lock interrupt. */
|
||||
kRCM_IntWatchDog = RCM_SRIE_WDOG_MASK, /*!< Watch dog interrupt. */
|
||||
kRCM_IntExternalPin = RCM_SRIE_PIN_MASK, /*!< External pin interrupt. */
|
||||
kRCM_IntGlobal = RCM_SRIE_GIE_MASK, /*!< Global interrupts. */
|
||||
kRCM_IntCoreLockup = RCM_SRIE_LOCKUP_MASK, /*!< Core lock up interrupt */
|
||||
kRCM_IntSoftware = RCM_SRIE_SW_MASK, /*!< software interrupt */
|
||||
kRCM_IntStopModeAckErr = RCM_SRIE_SACKERR_MASK, /*!< Stop mode ACK error interrupt. */
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_CORE1) && FSL_FEATURE_RCM_HAS_CORE1)
|
||||
kRCM_IntCore1 = RCM_SRIE_CORE1_MASK, /*!< Core 1 interrupt. */
|
||||
#endif
|
||||
kRCM_IntAll = RCM_SRIE_LOC_MASK /*!< Enable all interrupts. */
|
||||
|
|
||||
RCM_SRIE_LOL_MASK | RCM_SRIE_WDOG_MASK | RCM_SRIE_PIN_MASK | RCM_SRIE_GIE_MASK |
|
||||
RCM_SRIE_LOCKUP_MASK | RCM_SRIE_SW_MASK | RCM_SRIE_SACKERR_MASK
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_CORE1) && FSL_FEATURE_RCM_HAS_CORE1)
|
||||
|
|
||||
RCM_SRIE_CORE1_MASK
|
||||
#endif
|
||||
} rcm_interrupt_enable_t;
|
||||
#endif /* FSL_FEATURE_RCM_HAS_SRIE */
|
||||
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_VERID) && FSL_FEATURE_RCM_HAS_VERID)
|
||||
/*!
|
||||
* @brief IP version ID definition.
|
||||
*/
|
||||
typedef struct _rcm_version_id
|
||||
{
|
||||
uint16_t feature; /*!< Feature Specification Number. */
|
||||
uint8_t minor; /*!< Minor version number. */
|
||||
uint8_t major; /*!< Major version number. */
|
||||
} rcm_version_id_t;
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Reset pin filter configuration
|
||||
*/
|
||||
typedef struct _rcm_reset_pin_filter_config
|
||||
{
|
||||
bool enableFilterInStop; /*!< Reset pin filter select in stop mode. */
|
||||
rcm_run_wait_filter_mode_t filterInRunWait; /*!< Reset pin filter in run/wait mode. */
|
||||
uint8_t busClockFilterCount; /*!< Reset pin bus clock filter width. */
|
||||
} rcm_reset_pin_filter_config_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus*/
|
||||
|
||||
/*! @name Reset Control Module APIs*/
|
||||
/*@{*/
|
||||
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_VERID) && FSL_FEATURE_RCM_HAS_VERID)
|
||||
/*!
|
||||
* @brief Gets the RCM version ID.
|
||||
*
|
||||
* This function gets the RCM version ID including the major version number,
|
||||
* the minor version number, and the feature specification number.
|
||||
*
|
||||
* @param base RCM peripheral base address.
|
||||
* @param versionId Pointer to version ID structure.
|
||||
*/
|
||||
static inline void RCM_GetVersionId(RCM_Type *base, rcm_version_id_t *versionId)
|
||||
{
|
||||
*((uint32_t *)versionId) = base->VERID;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_PARAM) && FSL_FEATURE_RCM_HAS_PARAM)
|
||||
/*!
|
||||
* @brief Gets the reset source implemented status.
|
||||
*
|
||||
* This function gets the RCM parameter that indicates whether the corresponding reset source is implemented.
|
||||
* Use source masks defined in the rcm_reset_source_t to get the desired source status.
|
||||
*
|
||||
* Example:
|
||||
@code
|
||||
uint32_t status;
|
||||
|
||||
// To test whether the MCU is reset using Watchdog.
|
||||
status = RCM_GetResetSourceImplementedStatus(RCM) & (kRCM_SourceWdog | kRCM_SourcePin);
|
||||
@endcode
|
||||
*
|
||||
* @param base RCM peripheral base address.
|
||||
* @return All reset source implemented status bit map.
|
||||
*/
|
||||
static inline uint32_t RCM_GetResetSourceImplementedStatus(RCM_Type *base)
|
||||
{
|
||||
return base->PARAM;
|
||||
}
|
||||
#endif /* FSL_FEATURE_RCM_HAS_PARAM */
|
||||
|
||||
/*!
|
||||
* @brief Gets the reset source status which caused a previous reset.
|
||||
*
|
||||
* This function gets the current reset source status. Use source masks
|
||||
* defined in the rcm_reset_source_t to get the desired source status.
|
||||
*
|
||||
* Example:
|
||||
@code
|
||||
uint32_t resetStatus;
|
||||
|
||||
// To get all reset source statuses.
|
||||
resetStatus = RCM_GetPreviousResetSources(RCM) & kRCM_SourceAll;
|
||||
|
||||
// To test whether the MCU is reset using Watchdog.
|
||||
resetStatus = RCM_GetPreviousResetSources(RCM) & kRCM_SourceWdog;
|
||||
|
||||
// To test multiple reset sources.
|
||||
resetStatus = RCM_GetPreviousResetSources(RCM) & (kRCM_SourceWdog | kRCM_SourcePin);
|
||||
@endcode
|
||||
*
|
||||
* @param base RCM peripheral base address.
|
||||
* @return All reset source status bit map.
|
||||
*/
|
||||
static inline uint32_t RCM_GetPreviousResetSources(RCM_Type *base)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_RCM_REG_WIDTH) && (FSL_FEATURE_RCM_REG_WIDTH == 32))
|
||||
return base->SRS;
|
||||
#else
|
||||
return (uint32_t)((uint32_t)base->SRS0 | ((uint32_t)base->SRS1 << 8U));
|
||||
#endif /* (FSL_FEATURE_RCM_REG_WIDTH == 32) */
|
||||
}
|
||||
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_SSRS) && FSL_FEATURE_RCM_HAS_SSRS)
|
||||
/*!
|
||||
* @brief Gets the sticky reset source status.
|
||||
*
|
||||
* This function gets the current reset source status that has not been cleared
|
||||
* by software for some specific source.
|
||||
*
|
||||
* Example:
|
||||
@code
|
||||
uint32_t resetStatus;
|
||||
|
||||
// To get all reset source statuses.
|
||||
resetStatus = RCM_GetStickyResetSources(RCM) & kRCM_SourceAll;
|
||||
|
||||
// To test whether the MCU is reset using Watchdog.
|
||||
resetStatus = RCM_GetStickyResetSources(RCM) & kRCM_SourceWdog;
|
||||
|
||||
// To test multiple reset sources.
|
||||
resetStatus = RCM_GetStickyResetSources(RCM) & (kRCM_SourceWdog | kRCM_SourcePin);
|
||||
@endcode
|
||||
*
|
||||
* @param base RCM peripheral base address.
|
||||
* @return All reset source status bit map.
|
||||
*/
|
||||
static inline uint32_t RCM_GetStickyResetSources(RCM_Type *base)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_RCM_REG_WIDTH) && (FSL_FEATURE_RCM_REG_WIDTH == 32))
|
||||
return base->SSRS;
|
||||
#else
|
||||
return (base->SSRS0 | ((uint32_t)base->SSRS1 << 8U));
|
||||
#endif /* (FSL_FEATURE_RCM_REG_WIDTH == 32) */
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Clears the sticky reset source status.
|
||||
*
|
||||
* This function clears the sticky system reset flags indicated by source masks.
|
||||
*
|
||||
* Example:
|
||||
@code
|
||||
// Clears multiple reset sources.
|
||||
RCM_ClearStickyResetSources(kRCM_SourceWdog | kRCM_SourcePin);
|
||||
@endcode
|
||||
*
|
||||
* @param base RCM peripheral base address.
|
||||
* @param sourceMasks reset source status bit map
|
||||
*/
|
||||
static inline void RCM_ClearStickyResetSources(RCM_Type *base, uint32_t sourceMasks)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_RCM_REG_WIDTH) && (FSL_FEATURE_RCM_REG_WIDTH == 32))
|
||||
base->SSRS = sourceMasks;
|
||||
#else
|
||||
base->SSRS0 = (sourceMasks & 0xffU);
|
||||
base->SSRS1 = ((sourceMasks >> 8U) & 0xffU);
|
||||
#endif /* (FSL_FEATURE_RCM_REG_WIDTH == 32) */
|
||||
}
|
||||
#endif /* FSL_FEATURE_RCM_HAS_SSRS */
|
||||
|
||||
/*!
|
||||
* @brief Configures the reset pin filter.
|
||||
*
|
||||
* This function sets the reset pin filter including the filter source, filter
|
||||
* width, and so on.
|
||||
*
|
||||
* @param base RCM peripheral base address.
|
||||
* @param config Pointer to the configuration structure.
|
||||
*/
|
||||
void RCM_ConfigureResetPinFilter(RCM_Type *base, const rcm_reset_pin_filter_config_t *config);
|
||||
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_EZPMS) && FSL_FEATURE_RCM_HAS_EZPMS)
|
||||
/*!
|
||||
* @brief Gets the EZP_MS_B pin assert status.
|
||||
*
|
||||
* This function gets the easy port mode status (EZP_MS_B) pin assert status.
|
||||
*
|
||||
* @param base RCM peripheral base address.
|
||||
* @return status true - asserted, false - reasserted
|
||||
*/
|
||||
static inline bool RCM_GetEasyPortModePinStatus(RCM_Type *base)
|
||||
{
|
||||
return (bool)(base->MR & RCM_MR_EZP_MS_MASK);
|
||||
}
|
||||
#endif /* FSL_FEATURE_RCM_HAS_EZPMS */
|
||||
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_BOOTROM) && FSL_FEATURE_RCM_HAS_BOOTROM)
|
||||
/*!
|
||||
* @brief Gets the ROM boot source.
|
||||
*
|
||||
* This function gets the ROM boot source during the last chip reset.
|
||||
*
|
||||
* @param base RCM peripheral base address.
|
||||
* @return The ROM boot source.
|
||||
*/
|
||||
static inline rcm_boot_rom_config_t RCM_GetBootRomSource(RCM_Type *base)
|
||||
{
|
||||
return (rcm_boot_rom_config_t)((base->MR & RCM_MR_BOOTROM_MASK) >> RCM_MR_BOOTROM_SHIFT);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Clears the ROM boot source flag.
|
||||
*
|
||||
* This function clears the ROM boot source flag.
|
||||
*
|
||||
* @param base Register base address of RCM
|
||||
*/
|
||||
static inline void RCM_ClearBootRomSource(RCM_Type *base)
|
||||
{
|
||||
base->MR |= RCM_MR_BOOTROM_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Forces the boot from ROM.
|
||||
*
|
||||
* This function forces booting from ROM during all subsequent system resets.
|
||||
*
|
||||
* @param base RCM peripheral base address.
|
||||
* @param config Boot configuration.
|
||||
*/
|
||||
void RCM_SetForceBootRomSource(RCM_Type *base, rcm_boot_rom_config_t config);
|
||||
#endif /* FSL_FEATURE_RCM_HAS_BOOTROM */
|
||||
|
||||
#if (defined(FSL_FEATURE_RCM_HAS_SRIE) && FSL_FEATURE_RCM_HAS_SRIE)
|
||||
/*!
|
||||
* @brief Sets the system reset interrupt configuration.
|
||||
*
|
||||
* For graceful shutdown, the RCM supports delaying the assertion of the system
|
||||
* reset for a period of time when the reset interrupt is generated. This function
|
||||
* can be used to enable the interrupt and the delay period. The interrupts
|
||||
* are passed in as bit mask. See rcm_int_t for details. For example, to
|
||||
* delay a reset for 512 LPO cycles after the WDOG timeout or loss-of-clock occurs,
|
||||
* configure as follows:
|
||||
* RCM_SetSystemResetInterruptConfig(kRCM_IntWatchDog | kRCM_IntLossOfClk, kRCM_ResetDelay512Lpo);
|
||||
*
|
||||
* @param base RCM peripheral base address.
|
||||
* @param intMask Bit mask of the system reset interrupts to enable. See
|
||||
* rcm_interrupt_enable_t for details.
|
||||
* @param Delay Bit mask of the system reset interrupts to enable.
|
||||
*/
|
||||
static inline void RCM_SetSystemResetInterruptConfig(RCM_Type *base, uint32_t intMask, rcm_reset_delay_t delay)
|
||||
{
|
||||
base->SRIE = (intMask | delay);
|
||||
}
|
||||
#endif /* FSL_FEATURE_RCM_HAS_SRIE */
|
||||
/*@}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus*/
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_RCM_H_ */
|
||||
281
devices/MK22F51212/drivers/fsl_rnga.c
Normal file
281
devices/MK22F51212/drivers/fsl_rnga.c
Normal file
@@ -0,0 +1,281 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_rnga.h"
|
||||
|
||||
#if defined(FSL_FEATURE_SOC_RNG_COUNT) && FSL_FEATURE_SOC_RNG_COUNT
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* RNG_CR - RNGA Control Register
|
||||
******************************************************************************/
|
||||
/*!
|
||||
* @brief RNG_CR - RNGA Control Register (RW)
|
||||
*
|
||||
* Reset value: 0x00000000U
|
||||
*
|
||||
* Controls the operation of RNGA.
|
||||
*/
|
||||
/*!
|
||||
* @name Constants and macros for entire RNG_CR register
|
||||
*/
|
||||
/*@{*/
|
||||
#define RNG_CR_REG(base) ((base)->CR)
|
||||
#define RNG_RD_CR(base) (RNG_CR_REG(base))
|
||||
#define RNG_WR_CR(base, value) (RNG_CR_REG(base) = (value))
|
||||
#define RNG_RMW_CR(base, mask, value) (RNG_WR_CR(base, (RNG_RD_CR(base) & ~(mask)) | (value)))
|
||||
/*@}*/
|
||||
|
||||
/*!
|
||||
* @name Register RNG_CR, field GO[0] (RW)
|
||||
*
|
||||
* Specifies whether random-data generation and loading (into OR[RANDOUT]) is
|
||||
* enabled.This field is sticky. You must reset RNGA to stop RNGA from loading
|
||||
* OR[RANDOUT] with data.
|
||||
*
|
||||
* Values:
|
||||
* - 0b0 - Disabled
|
||||
* - 0b1 - Enabled
|
||||
*/
|
||||
/*@{*/
|
||||
/*! @brief Read current value of the RNG_CR_GO field. */
|
||||
#define RNG_RD_CR_GO(base) ((RNG_CR_REG(base) & RNG_CR_GO_MASK) >> RNG_CR_GO_SHIFT)
|
||||
|
||||
/*! @brief Set the GO field to a new value. */
|
||||
#define RNG_WR_CR_GO(base, value) (RNG_RMW_CR(base, RNG_CR_GO_MASK, RNG_CR_GO(value)))
|
||||
/*@}*/
|
||||
|
||||
/*!
|
||||
* @name Register RNG_CR, field SLP[4] (RW)
|
||||
*
|
||||
* Specifies whether RNGA is in Sleep or Normal mode. You can also enter Sleep
|
||||
* mode by asserting the DOZE signal.
|
||||
*
|
||||
* Values:
|
||||
* - 0b0 - Normal mode
|
||||
* - 0b1 - Sleep (low-power) mode
|
||||
*/
|
||||
/*@{*/
|
||||
/*! @brief Read current value of the RNG_CR_SLP field. */
|
||||
#define RNG_RD_CR_SLP(base) ((RNG_CR_REG(base) & RNG_CR_SLP_MASK) >> RNG_CR_SLP_SHIFT)
|
||||
|
||||
/*! @brief Set the SLP field to a new value. */
|
||||
#define RNG_WR_CR_SLP(base, value) (RNG_RMW_CR(base, RNG_CR_SLP_MASK, RNG_CR_SLP(value)))
|
||||
/*@}*/
|
||||
|
||||
/*******************************************************************************
|
||||
* RNG_SR - RNGA Status Register
|
||||
******************************************************************************/
|
||||
#define RNG_SR_REG(base) ((base)->SR)
|
||||
|
||||
/*!
|
||||
* @name Register RNG_SR, field OREG_LVL[15:8] (RO)
|
||||
*
|
||||
* Indicates the number of random-data words that are in OR[RANDOUT], which
|
||||
* indicates whether OR[RANDOUT] is valid.If you read OR[RANDOUT] when SR[OREG_LVL]
|
||||
* is not 0, then the contents of a random number contained in OR[RANDOUT] are
|
||||
* returned, and RNGA writes 0 to both OR[RANDOUT] and SR[OREG_LVL].
|
||||
*
|
||||
* Values:
|
||||
* - 0b00000000 - No words (empty)
|
||||
* - 0b00000001 - One word (valid)
|
||||
*/
|
||||
/*@{*/
|
||||
/*! @brief Read current value of the RNG_SR_OREG_LVL field. */
|
||||
#define RNG_RD_SR_OREG_LVL(base) ((RNG_SR_REG(base) & RNG_SR_OREG_LVL_MASK) >> RNG_SR_OREG_LVL_SHIFT)
|
||||
/*@}*/
|
||||
|
||||
/*!
|
||||
* @name Register RNG_SR, field SLP[4] (RO)
|
||||
*
|
||||
* Specifies whether RNGA is in Sleep or Normal mode. You can also enter Sleep
|
||||
* mode by asserting the DOZE signal.
|
||||
*
|
||||
* Values:
|
||||
* - 0b0 - Normal mode
|
||||
* - 0b1 - Sleep (low-power) mode
|
||||
*/
|
||||
/*@{*/
|
||||
/*! @brief Read current value of the RNG_SR_SLP field. */
|
||||
#define RNG_RD_SR_SLP(base) ((RNG_SR_REG(base) & RNG_SR_SLP_MASK) >> RNG_SR_SLP_SHIFT)
|
||||
/*@}*/
|
||||
|
||||
/*******************************************************************************
|
||||
* RNG_OR - RNGA Output Register
|
||||
******************************************************************************/
|
||||
/*!
|
||||
* @brief RNG_OR - RNGA Output Register (RO)
|
||||
*
|
||||
* Reset value: 0x00000000U
|
||||
*
|
||||
* Stores a random-data word generated by RNGA.
|
||||
*/
|
||||
/*!
|
||||
* @name Constants and macros for entire RNG_OR register
|
||||
*/
|
||||
/*@{*/
|
||||
#define RNG_OR_REG(base) ((base)->OR)
|
||||
#define RNG_RD_OR(base) (RNG_OR_REG(base))
|
||||
/*@}*/
|
||||
|
||||
/*******************************************************************************
|
||||
* RNG_ER - RNGA Entropy Register
|
||||
******************************************************************************/
|
||||
/*!
|
||||
* @brief RNG_ER - RNGA Entropy Register (WORZ)
|
||||
*
|
||||
* Reset value: 0x00000000U
|
||||
*
|
||||
* Specifies an entropy value that RNGA uses in addition to its ring oscillators
|
||||
* to seed its pseudorandom algorithm. This is a write-only register; reads
|
||||
* return all zeros.
|
||||
*/
|
||||
/*!
|
||||
* @name Constants and macros for entire RNG_ER register
|
||||
*/
|
||||
/*@{*/
|
||||
#define RNG_ER_REG(base) ((base)->ER)
|
||||
#define RNG_RD_ER(base) (RNG_ER_REG(base))
|
||||
#define RNG_WR_ER(base, value) (RNG_ER_REG(base) = (value))
|
||||
/*@}*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
*******************************************************************************/
|
||||
|
||||
static uint32_t rnga_ReadEntropy(RNG_Type *base);
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
void RNGA_Init(RNG_Type *base)
|
||||
{
|
||||
/* Enable the clock gate. */
|
||||
CLOCK_EnableClock(kCLOCK_Rnga0);
|
||||
CLOCK_DisableClock(kCLOCK_Rnga0); /* To solve the release version on twrkm43z75m */
|
||||
CLOCK_EnableClock(kCLOCK_Rnga0);
|
||||
|
||||
/* Reset the registers for RNGA module to reset state. */
|
||||
RNG_WR_CR(base, 0);
|
||||
/* Enables the RNGA random data generation and loading.*/
|
||||
RNG_WR_CR_GO(base, 1);
|
||||
}
|
||||
|
||||
void RNGA_Deinit(RNG_Type *base)
|
||||
{
|
||||
/* Disable the clock for RNGA module.*/
|
||||
CLOCK_DisableClock(kCLOCK_Rnga0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Get a random data from RNGA.
|
||||
*
|
||||
* @param base RNGA base address
|
||||
*/
|
||||
static uint32_t rnga_ReadEntropy(RNG_Type *base)
|
||||
{
|
||||
uint32_t data = 0;
|
||||
if (RNGA_GetMode(base) == kRNGA_ModeNormal) /* Is in normal mode.*/
|
||||
{
|
||||
/* Wait for valid random-data.*/
|
||||
while (RNG_RD_SR_OREG_LVL(base) == 0)
|
||||
{
|
||||
}
|
||||
data = RNG_RD_OR(base);
|
||||
}
|
||||
/* Get random-data word generated by RNGA.*/
|
||||
return data;
|
||||
}
|
||||
|
||||
status_t RNGA_GetRandomData(RNG_Type *base, void *data, size_t data_size)
|
||||
{
|
||||
status_t result = kStatus_Success;
|
||||
uint32_t random_32;
|
||||
uint8_t *random_p;
|
||||
uint32_t random_size;
|
||||
uint8_t *data_p = (uint8_t *)data;
|
||||
uint32_t i;
|
||||
|
||||
/* Check input parameters.*/
|
||||
if (base && data && data_size)
|
||||
{
|
||||
do
|
||||
{
|
||||
/* Read Entropy.*/
|
||||
random_32 = rnga_ReadEntropy(base);
|
||||
|
||||
random_p = (uint8_t *)&random_32;
|
||||
|
||||
if (data_size < sizeof(random_32))
|
||||
{
|
||||
random_size = data_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
random_size = sizeof(random_32);
|
||||
}
|
||||
|
||||
for (i = 0; i < random_size; i++)
|
||||
{
|
||||
*data_p++ = *random_p++;
|
||||
}
|
||||
|
||||
data_size -= random_size;
|
||||
} while (data_size > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void RNGA_SetMode(RNG_Type *base, rnga_mode_t mode)
|
||||
{
|
||||
RNG_WR_CR_SLP(base, (uint32_t)mode);
|
||||
}
|
||||
|
||||
rnga_mode_t RNGA_GetMode(RNG_Type *base)
|
||||
{
|
||||
return (rnga_mode_t)RNG_RD_SR_SLP(base);
|
||||
}
|
||||
|
||||
void RNGA_Seed(RNG_Type *base, uint32_t seed)
|
||||
{
|
||||
/* Write to RNGA Entropy Register.*/
|
||||
RNG_WR_ER(base, seed);
|
||||
}
|
||||
|
||||
#endif /* FSL_FEATURE_SOC_RNG_COUNT */
|
||||
138
devices/MK22F51212/drivers/fsl_rnga.h
Normal file
138
devices/MK22F51212/drivers/fsl_rnga.h
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_RNGA_DRIVER_H_
|
||||
#define _FSL_RNGA_DRIVER_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
#if defined(FSL_FEATURE_SOC_RNG_COUNT) && FSL_FEATURE_SOC_RNG_COUNT
|
||||
/*!
|
||||
* @addtogroup rnga_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
*******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief RNGA driver version 2.0.1. */
|
||||
#define FSL_RNGA_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
|
||||
/*@}*/
|
||||
|
||||
/*! @brief RNGA working mode */
|
||||
typedef enum _rnga_mode
|
||||
{
|
||||
kRNGA_ModeNormal = 0U, /*!< Normal Mode. The ring-oscillator clocks are active; RNGA generates entropy
|
||||
(randomness) from the clocks and stores it in shift registers.*/
|
||||
kRNGA_ModeSleep = 1U, /*!< Sleep Mode. The ring-oscillator clocks are inactive; RNGA does not generate entropy.*/
|
||||
} rnga_mode_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
*******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Initializes the RNGA.
|
||||
*
|
||||
* This function initializes the RNGA.
|
||||
* When called, the RNGA entropy generation starts immediately.
|
||||
*
|
||||
* @param base RNGA base address
|
||||
*/
|
||||
void RNGA_Init(RNG_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Shuts down the RNGA.
|
||||
*
|
||||
* This function shuts down the RNGA.
|
||||
*
|
||||
* @param base RNGA base address
|
||||
*/
|
||||
void RNGA_Deinit(RNG_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Gets random data.
|
||||
*
|
||||
* This function gets random data from the RNGA.
|
||||
*
|
||||
* @param base RNGA base address
|
||||
* @param data pointer to user buffer to be filled by random data
|
||||
* @param data_size size of data in bytes
|
||||
* @return RNGA status
|
||||
*/
|
||||
status_t RNGA_GetRandomData(RNG_Type *base, void *data, size_t data_size);
|
||||
|
||||
/*!
|
||||
* @brief Feeds the RNGA module.
|
||||
*
|
||||
* This function inputs an entropy value that the RNGA uses to seed its
|
||||
* pseudo-random algorithm.
|
||||
*
|
||||
* @param base RNGA base address
|
||||
* @param seed input seed value
|
||||
*/
|
||||
void RNGA_Seed(RNG_Type *base, uint32_t seed);
|
||||
|
||||
/*!
|
||||
* @brief Sets the RNGA in normal mode or sleep mode.
|
||||
*
|
||||
* This function sets the RNGA in sleep mode or normal mode.
|
||||
*
|
||||
* @param base RNGA base address
|
||||
* @param mode normal mode or sleep mode
|
||||
*/
|
||||
void RNGA_SetMode(RNG_Type *base, rnga_mode_t mode);
|
||||
|
||||
/*!
|
||||
* @brief Gets the RNGA working mode.
|
||||
*
|
||||
* This function gets the RNGA working mode.
|
||||
*
|
||||
* @param base RNGA base address
|
||||
* @return normal mode or sleep mode
|
||||
*/
|
||||
rnga_mode_t RNGA_GetMode(RNG_Type *base);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* FSL_FEATURE_SOC_RNG_COUNT */
|
||||
#endif /* _FSL_RNGA_H_*/
|
||||
370
devices/MK22F51212/drivers/fsl_rtc.c
Normal file
370
devices/MK22F51212/drivers/fsl_rtc.c
Normal file
@@ -0,0 +1,370 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_rtc.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
#define SECONDS_IN_A_DAY (86400U)
|
||||
#define SECONDS_IN_A_HOUR (3600U)
|
||||
#define SECONDS_IN_A_MINUTE (60U)
|
||||
#define DAYS_IN_A_YEAR (365U)
|
||||
#define YEAR_RANGE_START (1970U)
|
||||
#define YEAR_RANGE_END (2099U)
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
/*!
|
||||
* @brief Checks whether the date and time passed in is valid
|
||||
*
|
||||
* @param datetime Pointer to structure where the date and time details are stored
|
||||
*
|
||||
* @return Returns false if the date & time details are out of range; true if in range
|
||||
*/
|
||||
static bool RTC_CheckDatetimeFormat(const rtc_datetime_t *datetime);
|
||||
|
||||
/*!
|
||||
* @brief Converts time data from datetime to seconds
|
||||
*
|
||||
* @param datetime Pointer to datetime structure where the date and time details are stored
|
||||
*
|
||||
* @return The result of the conversion in seconds
|
||||
*/
|
||||
static uint32_t RTC_ConvertDatetimeToSeconds(const rtc_datetime_t *datetime);
|
||||
|
||||
/*!
|
||||
* @brief Converts time data from seconds to a datetime structure
|
||||
*
|
||||
* @param seconds Seconds value that needs to be converted to datetime format
|
||||
* @param datetime Pointer to the datetime structure where the result of the conversion is stored
|
||||
*/
|
||||
static void RTC_ConvertSecondsToDatetime(uint32_t seconds, rtc_datetime_t *datetime);
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
static bool RTC_CheckDatetimeFormat(const rtc_datetime_t *datetime)
|
||||
{
|
||||
/* Table of days in a month for a non leap year. First entry in the table is not used,
|
||||
* valid months start from 1
|
||||
*/
|
||||
uint8_t daysPerMonth[] = {0U, 31U, 28U, 31U, 30U, 31U, 30U, 31U, 31U, 30U, 31U, 30U, 31U};
|
||||
|
||||
/* Check year, month, hour, minute, seconds */
|
||||
if ((datetime->year < YEAR_RANGE_START) || (datetime->year > YEAR_RANGE_END) || (datetime->month > 12U) ||
|
||||
(datetime->month < 1U) || (datetime->hour >= 24U) || (datetime->minute >= 60U) || (datetime->second >= 60U))
|
||||
{
|
||||
/* If not correct then error*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Adjust the days in February for a leap year */
|
||||
if (!(datetime->year & 3U))
|
||||
{
|
||||
daysPerMonth[2] = 29U;
|
||||
}
|
||||
|
||||
/* Check the validity of the day */
|
||||
if (datetime->day > daysPerMonth[datetime->month])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static uint32_t RTC_ConvertDatetimeToSeconds(const rtc_datetime_t *datetime)
|
||||
{
|
||||
/* Number of days from begin of the non Leap-year*/
|
||||
uint16_t monthDays[] = {0U, 0U, 31U, 59U, 90U, 120U, 151U, 181U, 212U, 243U, 273U, 304U, 334U};
|
||||
uint32_t seconds;
|
||||
|
||||
/* Compute number of days from 1970 till given year*/
|
||||
seconds = (datetime->year - 1970U) * DAYS_IN_A_YEAR;
|
||||
/* Add leap year days */
|
||||
seconds += ((datetime->year / 4) - (1970U / 4));
|
||||
/* Add number of days till given month*/
|
||||
seconds += monthDays[datetime->month];
|
||||
/* Add days in given month. We subtract the current day as it is
|
||||
* represented in the hours, minutes and seconds field*/
|
||||
seconds += (datetime->day - 1);
|
||||
/* For leap year if month less than or equal to Febraury, decrement day counter*/
|
||||
if ((!(datetime->year & 3U)) && (datetime->month <= 2U))
|
||||
{
|
||||
seconds--;
|
||||
}
|
||||
|
||||
seconds = (seconds * SECONDS_IN_A_DAY) + (datetime->hour * SECONDS_IN_A_HOUR) +
|
||||
(datetime->minute * SECONDS_IN_A_MINUTE) + datetime->second;
|
||||
|
||||
return seconds;
|
||||
}
|
||||
|
||||
static void RTC_ConvertSecondsToDatetime(uint32_t seconds, rtc_datetime_t *datetime)
|
||||
{
|
||||
uint32_t x;
|
||||
uint32_t secondsRemaining, days;
|
||||
uint16_t daysInYear;
|
||||
/* Table of days in a month for a non leap year. First entry in the table is not used,
|
||||
* valid months start from 1
|
||||
*/
|
||||
uint8_t daysPerMonth[] = {0U, 31U, 28U, 31U, 30U, 31U, 30U, 31U, 31U, 30U, 31U, 30U, 31U};
|
||||
|
||||
/* Start with the seconds value that is passed in to be converted to date time format */
|
||||
secondsRemaining = seconds;
|
||||
|
||||
/* Calcuate the number of days, we add 1 for the current day which is represented in the
|
||||
* hours and seconds field
|
||||
*/
|
||||
days = secondsRemaining / SECONDS_IN_A_DAY + 1;
|
||||
|
||||
/* Update seconds left*/
|
||||
secondsRemaining = secondsRemaining % SECONDS_IN_A_DAY;
|
||||
|
||||
/* Calculate the datetime hour, minute and second fields */
|
||||
datetime->hour = secondsRemaining / SECONDS_IN_A_HOUR;
|
||||
secondsRemaining = secondsRemaining % SECONDS_IN_A_HOUR;
|
||||
datetime->minute = secondsRemaining / 60U;
|
||||
datetime->second = secondsRemaining % SECONDS_IN_A_MINUTE;
|
||||
|
||||
/* Calculate year */
|
||||
daysInYear = DAYS_IN_A_YEAR;
|
||||
datetime->year = YEAR_RANGE_START;
|
||||
while (days > daysInYear)
|
||||
{
|
||||
/* Decrease day count by a year and increment year by 1 */
|
||||
days -= daysInYear;
|
||||
datetime->year++;
|
||||
|
||||
/* Adjust the number of days for a leap year */
|
||||
if (datetime->year & 3U)
|
||||
{
|
||||
daysInYear = DAYS_IN_A_YEAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
daysInYear = DAYS_IN_A_YEAR + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Adjust the days in February for a leap year */
|
||||
if (!(datetime->year & 3U))
|
||||
{
|
||||
daysPerMonth[2] = 29U;
|
||||
}
|
||||
|
||||
for (x = 1U; x <= 12U; x++)
|
||||
{
|
||||
if (days <= daysPerMonth[x])
|
||||
{
|
||||
datetime->month = x;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
days -= daysPerMonth[x];
|
||||
}
|
||||
}
|
||||
|
||||
datetime->day = days;
|
||||
}
|
||||
|
||||
void RTC_Init(RTC_Type *base, const rtc_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
uint32_t reg;
|
||||
|
||||
CLOCK_EnableClock(kCLOCK_Rtc0);
|
||||
|
||||
/* Issue a software reset if timer is invalid */
|
||||
if (RTC_GetStatusFlags(RTC) & kRTC_TimeInvalidFlag)
|
||||
{
|
||||
RTC_Reset(RTC);
|
||||
}
|
||||
|
||||
reg = base->CR;
|
||||
/* Setup the update mode and supervisor access mode */
|
||||
reg &= ~(RTC_CR_UM_MASK | RTC_CR_SUP_MASK);
|
||||
reg |= RTC_CR_UM(config->updateMode) | RTC_CR_SUP(config->supervisorAccess);
|
||||
#if defined(FSL_FEATURE_RTC_HAS_WAKEUP_PIN) && FSL_FEATURE_RTC_HAS_WAKEUP_PIN
|
||||
/* Setup the wakeup pin select */
|
||||
reg &= ~(RTC_CR_WPS_MASK);
|
||||
reg |= RTC_CR_WPS(config->wakeupSelect);
|
||||
#endif /* FSL_FEATURE_RTC_HAS_WAKEUP_PIN */
|
||||
base->CR = reg;
|
||||
|
||||
/* Configure the RTC time compensation register */
|
||||
base->TCR = (RTC_TCR_CIR(config->compensationInterval) | RTC_TCR_TCR(config->compensationTime));
|
||||
}
|
||||
|
||||
void RTC_GetDefaultConfig(rtc_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
/* Wakeup pin will assert if the RTC interrupt asserts or if the wakeup pin is turned on */
|
||||
config->wakeupSelect = false;
|
||||
/* Registers cannot be written when locked */
|
||||
config->updateMode = false;
|
||||
/* Non-supervisor mode write accesses are not supported and will generate a bus error */
|
||||
config->supervisorAccess = false;
|
||||
/* Compensation interval used by the crystal compensation logic */
|
||||
config->compensationInterval = 0;
|
||||
/* Compensation time used by the crystal compensation logic */
|
||||
config->compensationTime = 0;
|
||||
}
|
||||
|
||||
status_t RTC_SetDatetime(RTC_Type *base, const rtc_datetime_t *datetime)
|
||||
{
|
||||
assert(datetime);
|
||||
|
||||
/* Return error if the time provided is not valid */
|
||||
if (!(RTC_CheckDatetimeFormat(datetime)))
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
/* Set time in seconds */
|
||||
base->TSR = RTC_ConvertDatetimeToSeconds(datetime);
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
void RTC_GetDatetime(RTC_Type *base, rtc_datetime_t *datetime)
|
||||
{
|
||||
assert(datetime);
|
||||
|
||||
uint32_t seconds = 0;
|
||||
|
||||
seconds = base->TSR;
|
||||
RTC_ConvertSecondsToDatetime(seconds, datetime);
|
||||
}
|
||||
|
||||
status_t RTC_SetAlarm(RTC_Type *base, const rtc_datetime_t *alarmTime)
|
||||
{
|
||||
assert(alarmTime);
|
||||
|
||||
uint32_t alarmSeconds = 0;
|
||||
uint32_t currSeconds = 0;
|
||||
|
||||
/* Return error if the alarm time provided is not valid */
|
||||
if (!(RTC_CheckDatetimeFormat(alarmTime)))
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
alarmSeconds = RTC_ConvertDatetimeToSeconds(alarmTime);
|
||||
|
||||
/* Get the current time */
|
||||
currSeconds = base->TSR;
|
||||
|
||||
/* Return error if the alarm time has passed */
|
||||
if (alarmSeconds < currSeconds)
|
||||
{
|
||||
return kStatus_Fail;
|
||||
}
|
||||
|
||||
/* Set alarm in seconds*/
|
||||
base->TAR = alarmSeconds;
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
void RTC_GetAlarm(RTC_Type *base, rtc_datetime_t *datetime)
|
||||
{
|
||||
assert(datetime);
|
||||
|
||||
uint32_t alarmSeconds = 0;
|
||||
|
||||
/* Get alarm in seconds */
|
||||
alarmSeconds = base->TAR;
|
||||
|
||||
RTC_ConvertSecondsToDatetime(alarmSeconds, datetime);
|
||||
}
|
||||
|
||||
void RTC_ClearStatusFlags(RTC_Type *base, uint32_t mask)
|
||||
{
|
||||
/* The alarm flag is cleared by writing to the TAR register */
|
||||
if (mask & kRTC_AlarmFlag)
|
||||
{
|
||||
base->TAR = 0U;
|
||||
}
|
||||
|
||||
/* The timer overflow flag is cleared by initializing the TSR register.
|
||||
* The time counter should be disabled for this write to be successful
|
||||
*/
|
||||
if (mask & kRTC_TimeOverflowFlag)
|
||||
{
|
||||
base->TSR = 1U;
|
||||
}
|
||||
|
||||
/* The timer overflow flag is cleared by initializing the TSR register.
|
||||
* The time counter should be disabled for this write to be successful
|
||||
*/
|
||||
if (mask & kRTC_TimeInvalidFlag)
|
||||
{
|
||||
base->TSR = 1U;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_RTC_HAS_MONOTONIC) && (FSL_FEATURE_RTC_HAS_MONOTONIC)
|
||||
|
||||
void RTC_GetMonotonicCounter(RTC_Type *base, uint64_t *counter)
|
||||
{
|
||||
*counter = (((uint64_t)base->MCHR << 32) | ((uint64_t)base->MCLR));
|
||||
}
|
||||
|
||||
void RTC_SetMonotonicCounter(RTC_Type *base, uint64_t counter)
|
||||
{
|
||||
/* Prepare to initialize the register with the new value written */
|
||||
base->MER &= ~RTC_MER_MCE_MASK;
|
||||
|
||||
base->MCHR = (uint32_t)((counter) >> 32);
|
||||
base->MCLR = (uint32_t)(counter);
|
||||
}
|
||||
|
||||
status_t RTC_IncrementMonotonicCounter(RTC_Type *base)
|
||||
{
|
||||
if (base->SR & (RTC_SR_MOF_MASK | RTC_SR_TIF_MASK))
|
||||
{
|
||||
return kStatus_Fail;
|
||||
}
|
||||
|
||||
/* Prepare to switch to increment mode */
|
||||
base->MER |= RTC_MER_MCE_MASK;
|
||||
/* Write anything so the counter increments*/
|
||||
base->MCLR = 1U;
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
#endif /* FSL_FEATURE_RTC_HAS_MONOTONIC */
|
||||
405
devices/MK22F51212/drivers/fsl_rtc.h
Normal file
405
devices/MK22F51212/drivers/fsl_rtc.h
Normal file
@@ -0,0 +1,405 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_RTC_H_
|
||||
#define _FSL_RTC_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup rtc_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
#define FSL_RTC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0 */
|
||||
/*@}*/
|
||||
|
||||
/*! @brief List of RTC interrupts */
|
||||
typedef enum _rtc_interrupt_enable
|
||||
{
|
||||
kRTC_TimeInvalidInterruptEnable = RTC_IER_TIIE_MASK, /*!< Time invalid interrupt.*/
|
||||
kRTC_TimeOverflowInterruptEnable = RTC_IER_TOIE_MASK, /*!< Time overflow interrupt.*/
|
||||
kRTC_AlarmInterruptEnable = RTC_IER_TAIE_MASK, /*!< Alarm interrupt.*/
|
||||
kRTC_SecondsInterruptEnable = RTC_IER_TSIE_MASK /*!< Seconds interrupt.*/
|
||||
} rtc_interrupt_enable_t;
|
||||
|
||||
/*! @brief List of RTC flags */
|
||||
typedef enum _rtc_status_flags
|
||||
{
|
||||
kRTC_TimeInvalidFlag = RTC_SR_TIF_MASK, /*!< Time invalid flag */
|
||||
kRTC_TimeOverflowFlag = RTC_SR_TOF_MASK, /*!< Time overflow flag */
|
||||
kRTC_AlarmFlag = RTC_SR_TAF_MASK /*!< Alarm flag*/
|
||||
} rtc_status_flags_t;
|
||||
|
||||
/*! @brief List of RTC Oscillator capacitor load settings */
|
||||
typedef enum _rtc_osc_cap_load
|
||||
{
|
||||
kRTC_Capacitor_2p = RTC_CR_SC2P_MASK, /*!< 2pF capacitor load */
|
||||
kRTC_Capacitor_4p = RTC_CR_SC4P_MASK, /*!< 4pF capacitor load */
|
||||
kRTC_Capacitor_8p = RTC_CR_SC8P_MASK, /*!< 8pF capacitor load */
|
||||
kRTC_Capacitor_16p = RTC_CR_SC16P_MASK /*!< 16pF capacitor load */
|
||||
} rtc_osc_cap_load_t;
|
||||
|
||||
/*! @brief Structure is used to hold the date and time */
|
||||
typedef struct _rtc_datetime
|
||||
{
|
||||
uint16_t year; /*!< Range from 1970 to 2099.*/
|
||||
uint8_t month; /*!< Range from 1 to 12.*/
|
||||
uint8_t day; /*!< Range from 1 to 31 (depending on month).*/
|
||||
uint8_t hour; /*!< Range from 0 to 23.*/
|
||||
uint8_t minute; /*!< Range from 0 to 59.*/
|
||||
uint8_t second; /*!< Range from 0 to 59.*/
|
||||
} rtc_datetime_t;
|
||||
|
||||
/*!
|
||||
* @brief RTC config structure
|
||||
*
|
||||
* This structure holds the configuration settings for the RTC peripheral. To initialize this
|
||||
* structure to reasonable defaults, call the RTC_GetDefaultConfig() function and pass a
|
||||
* pointer to your config structure instance.
|
||||
*
|
||||
* The config struct can be made const so it resides in flash
|
||||
*/
|
||||
typedef struct _rtc_config
|
||||
{
|
||||
bool wakeupSelect; /*!< true: Wakeup pin outputs the 32KHz clock;
|
||||
false:Wakeup pin used to wakeup the chip */
|
||||
bool updateMode; /*!< true: Registers can be written even when locked under certain
|
||||
conditions, false: No writes allowed when registers are locked */
|
||||
bool supervisorAccess; /*!< true: Non-supervisor accesses are allowed;
|
||||
false: Non-supervisor accesses are not supported */
|
||||
uint32_t compensationInterval; /*!< Compensation interval that is written to the CIR field in RTC TCR Register */
|
||||
uint32_t compensationTime; /*!< Compensation time that is written to the TCR field in RTC TCR Register */
|
||||
} rtc_config_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @name Initialization and deinitialization
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Ungates the RTC clock and configures the peripheral for basic operation.
|
||||
*
|
||||
* This function will issue a software reset if the timer invalid flag is set.
|
||||
*
|
||||
* @note This API should be called at the beginning of the application using the RTC driver.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
* @param config Pointer to user's RTC config structure.
|
||||
*/
|
||||
void RTC_Init(RTC_Type *base, const rtc_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Stop the timer and gate the RTC clock
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
*/
|
||||
static inline void RTC_Deinit(RTC_Type *base)
|
||||
{
|
||||
/* Stop the RTC timer */
|
||||
base->SR &= ~RTC_SR_TCE_MASK;
|
||||
|
||||
/* Gate the module clock */
|
||||
CLOCK_DisableClock(kCLOCK_Rtc0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Fill in the RTC config struct with the default settings
|
||||
*
|
||||
* The default values are:
|
||||
* @code
|
||||
* config->wakeupSelect = false;
|
||||
* config->updateMode = false;
|
||||
* config->supervisorAccess = false;
|
||||
* config->compensationInterval = 0;
|
||||
* config->compensationTime = 0;
|
||||
* @endcode
|
||||
* @param config Pointer to user's RTC config structure.
|
||||
*/
|
||||
void RTC_GetDefaultConfig(rtc_config_t *config);
|
||||
|
||||
/*! @}*/
|
||||
|
||||
/*!
|
||||
* @name Current Time & Alarm
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Sets the RTC date and time according to the given time structure.
|
||||
*
|
||||
* The RTC counter must be stopped prior to calling this function as writes to the RTC
|
||||
* seconds register will fail if the RTC counter is running.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
* @param datetime Pointer to structure where the date and time details to set are stored
|
||||
*
|
||||
* @return kStatus_Success: Success in setting the time and starting the RTC
|
||||
* kStatus_InvalidArgument: Error because the datetime format is incorrect
|
||||
*/
|
||||
status_t RTC_SetDatetime(RTC_Type *base, const rtc_datetime_t *datetime);
|
||||
|
||||
/*!
|
||||
* @brief Gets the RTC time and stores it in the given time structure.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
* @param datetime Pointer to structure where the date and time details are stored.
|
||||
*/
|
||||
void RTC_GetDatetime(RTC_Type *base, rtc_datetime_t *datetime);
|
||||
|
||||
/*!
|
||||
* @brief Sets the RTC alarm time
|
||||
*
|
||||
* The function checks whether the specified alarm time is greater than the present
|
||||
* time. If not, the function does not set the alarm and returns an error.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
* @param alarmTime Pointer to structure where the alarm time is stored.
|
||||
*
|
||||
* @return kStatus_Success: success in setting the RTC alarm
|
||||
* kStatus_InvalidArgument: Error because the alarm datetime format is incorrect
|
||||
* kStatus_Fail: Error because the alarm time has already passed
|
||||
*/
|
||||
status_t RTC_SetAlarm(RTC_Type *base, const rtc_datetime_t *alarmTime);
|
||||
|
||||
/*!
|
||||
* @brief Returns the RTC alarm time.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
* @param datetime Pointer to structure where the alarm date and time details are stored.
|
||||
*/
|
||||
void RTC_GetAlarm(RTC_Type *base, rtc_datetime_t *datetime);
|
||||
|
||||
/*! @}*/
|
||||
|
||||
/*!
|
||||
* @name Interrupt Interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Enables the selected RTC interrupts.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
* @param mask The interrupts to enable. This is a logical OR of members of the
|
||||
* enumeration ::rtc_interrupt_enable_t
|
||||
*/
|
||||
static inline void RTC_EnableInterrupts(RTC_Type *base, uint32_t mask)
|
||||
{
|
||||
base->IER |= mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disables the selected RTC interrupts.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
* @param mask The interrupts to enable. This is a logical OR of members of the
|
||||
* enumeration ::rtc_interrupt_enable_t
|
||||
*/
|
||||
static inline void RTC_DisableInterrupts(RTC_Type *base, uint32_t mask)
|
||||
{
|
||||
base->IER &= ~mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets the enabled RTC interrupts.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
*
|
||||
* @return The enabled interrupts. This is the logical OR of members of the
|
||||
* enumeration ::rtc_interrupt_enable_t
|
||||
*/
|
||||
static inline uint32_t RTC_GetEnabledInterrupts(RTC_Type *base)
|
||||
{
|
||||
return (base->IER & (RTC_IER_TIIE_MASK | RTC_IER_TOIE_MASK | RTC_IER_TAIE_MASK | RTC_IER_TSIE_MASK));
|
||||
}
|
||||
|
||||
/*! @}*/
|
||||
|
||||
/*!
|
||||
* @name Status Interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Gets the RTC status flags
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
*
|
||||
* @return The status flags. This is the logical OR of members of the
|
||||
* enumeration ::rtc_status_flags_t
|
||||
*/
|
||||
static inline uint32_t RTC_GetStatusFlags(RTC_Type *base)
|
||||
{
|
||||
return (base->SR & (RTC_SR_TIF_MASK | RTC_SR_TOF_MASK | RTC_SR_TAF_MASK));
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Clears the RTC status flags.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
* @param mask The status flags to clear. This is a logical OR of members of the
|
||||
* enumeration ::rtc_status_flags_t
|
||||
*/
|
||||
void RTC_ClearStatusFlags(RTC_Type *base, uint32_t mask);
|
||||
|
||||
/*! @}*/
|
||||
|
||||
/*!
|
||||
* @name Timer Start and Stop
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Starts the RTC time counter.
|
||||
*
|
||||
* After calling this function, the timer counter increments once a second provided SR[TOF] or
|
||||
* SR[TIF] are not set.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
*/
|
||||
static inline void RTC_StartTimer(RTC_Type *base)
|
||||
{
|
||||
base->SR |= RTC_SR_TCE_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Stops the RTC time counter.
|
||||
*
|
||||
* RTC's seconds register can be written to only when the timer is stopped.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
*/
|
||||
static inline void RTC_StopTimer(RTC_Type *base)
|
||||
{
|
||||
base->SR &= ~RTC_SR_TCE_MASK;
|
||||
}
|
||||
|
||||
/*! @}*/
|
||||
|
||||
/*!
|
||||
* @brief This function sets the specified capacitor configuration for the RTC oscillator.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
* @param capLoad Oscillator loads to enable. This is a logical OR of members of the
|
||||
* enumeration ::rtc_osc_cap_load_t
|
||||
*/
|
||||
static inline void RTC_SetOscCapLoad(RTC_Type *base, uint32_t capLoad)
|
||||
{
|
||||
uint32_t reg = base->CR;
|
||||
|
||||
reg &= ~(RTC_CR_SC2P_MASK | RTC_CR_SC4P_MASK | RTC_CR_SC8P_MASK | RTC_CR_SC16P_MASK);
|
||||
reg |= capLoad;
|
||||
|
||||
base->CR = reg;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Performs a software reset on the RTC module.
|
||||
*
|
||||
* This resets all RTC registers except for the SWR bit and the RTC_WAR and RTC_RAR
|
||||
* registers. The SWR bit is cleared by software explicitly clearing it.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
*/
|
||||
static inline void RTC_Reset(RTC_Type *base)
|
||||
{
|
||||
base->CR |= RTC_CR_SWR_MASK;
|
||||
base->CR &= ~RTC_CR_SWR_MASK;
|
||||
|
||||
/* Set TSR register to 0x1 to avoid the timer invalid (TIF) bit being set in the SR register */
|
||||
base->TSR = 1U;
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_RTC_HAS_MONOTONIC) && (FSL_FEATURE_RTC_HAS_MONOTONIC)
|
||||
|
||||
/*!
|
||||
* @name Monotonic counter functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Reads the values of the Monotonic Counter High and Monotonic Counter Low and returns
|
||||
* them as a single value.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
* @param counter Pointer to variable where the value is stored.
|
||||
*/
|
||||
void RTC_GetMonotonicCounter(RTC_Type *base, uint64_t *counter);
|
||||
|
||||
/*!
|
||||
* @brief Writes values Monotonic Counter High and Monotonic Counter Low by decomposing
|
||||
* the given single value.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
* @param counter Counter value
|
||||
*/
|
||||
void RTC_SetMonotonicCounter(RTC_Type *base, uint64_t counter);
|
||||
|
||||
/*!
|
||||
* @brief Increments the Monotonic Counter by one.
|
||||
*
|
||||
* Increments the Monotonic Counter (registers RTC_MCLR and RTC_MCHR accordingly) by setting
|
||||
* the monotonic counter enable (MER[MCE]) and then writing to the RTC_MCLR register. A write to the
|
||||
* monotonic counter low that causes it to overflow also increments the monotonic counter high.
|
||||
*
|
||||
* @param base RTC peripheral base address
|
||||
*
|
||||
* @return kStatus_Success: success
|
||||
* kStatus_Fail: error occurred, either time invalid or monotonic overflow flag was found
|
||||
*/
|
||||
status_t RTC_IncrementMonotonicCounter(RTC_Type *base);
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* FSL_FEATURE_RTC_HAS_MONOTONIC */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_RTC_H_ */
|
||||
1048
devices/MK22F51212/drivers/fsl_sai.c
Normal file
1048
devices/MK22F51212/drivers/fsl_sai.c
Normal file
File diff suppressed because it is too large
Load Diff
850
devices/MK22F51212/drivers/fsl_sai.h
Normal file
850
devices/MK22F51212/drivers/fsl_sai.h
Normal file
File diff suppressed because it is too large
Load Diff
379
devices/MK22F51212/drivers/fsl_sai_edma.c
Normal file
379
devices/MK22F51212/drivers/fsl_sai_edma.c
Normal file
@@ -0,0 +1,379 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_sai_edma.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitations
|
||||
******************************************************************************/
|
||||
/* Used for 32byte aligned */
|
||||
#define STCD_ADDR(address) (edma_tcd_t *)(((uint32_t)address + 32) & ~0x1FU)
|
||||
|
||||
/*<! Structure definition for uart_edma_private_handle_t. The structure is private. */
|
||||
typedef struct _sai_edma_private_handle
|
||||
{
|
||||
I2S_Type *base;
|
||||
sai_edma_handle_t *handle;
|
||||
} sai_edma_private_handle_t;
|
||||
|
||||
enum _sai_edma_transfer_state
|
||||
{
|
||||
kSAI_Busy = 0x0U, /*!< SAI is busy */
|
||||
kSAI_Idle, /*!< Transfer is done. */
|
||||
};
|
||||
|
||||
/*<! Private handle only used for internally. */
|
||||
static sai_edma_private_handle_t s_edmaPrivateHandle[FSL_FEATURE_SOC_I2S_COUNT][2];
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
/*!
|
||||
* @brief Get the instance number for SAI.
|
||||
*
|
||||
* @param base SAI base pointer.
|
||||
*/
|
||||
extern uint32_t SAI_GetInstance(I2S_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief SAI EDMA callback for send.
|
||||
*
|
||||
* @param handle pointer to sai_edma_handle_t structure which stores the transfer state.
|
||||
* @param userData Parameter for user callback.
|
||||
* @param done If the DMA transfer finished.
|
||||
* @param tcds The TCD index.
|
||||
*/
|
||||
static void SAI_TxEDMACallback(edma_handle_t *handle, void *userData, bool done, uint32_t tcds);
|
||||
|
||||
/*!
|
||||
* @brief SAI EDMA callback for receive.
|
||||
*
|
||||
* @param handle pointer to sai_edma_handle_t structure which stores the transfer state.
|
||||
* @param userData Parameter for user callback.
|
||||
* @param done If the DMA transfer finished.
|
||||
* @param tcds The TCD index.
|
||||
*/
|
||||
static void SAI_RxEDMACallback(edma_handle_t *handle, void *userData, bool done, uint32_t tcds);
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
static void SAI_TxEDMACallback(edma_handle_t *handle, void *userData, bool done, uint32_t tcds)
|
||||
{
|
||||
sai_edma_private_handle_t *privHandle = (sai_edma_private_handle_t *)userData;
|
||||
sai_edma_handle_t *saiHandle = privHandle->handle;
|
||||
|
||||
/* If finished a blcok, call the callback function */
|
||||
memset(&saiHandle->saiQueue[saiHandle->queueDriver], 0, sizeof(sai_transfer_t));
|
||||
saiHandle->queueDriver = (saiHandle->queueDriver + 1) % SAI_XFER_QUEUE_SIZE;
|
||||
if (saiHandle->callback)
|
||||
{
|
||||
(saiHandle->callback)(privHandle->base, saiHandle, kStatus_SAI_TxIdle, saiHandle->userData);
|
||||
}
|
||||
|
||||
/* If all data finished, just stop the transfer */
|
||||
if (saiHandle->saiQueue[saiHandle->queueDriver].data == NULL)
|
||||
{
|
||||
SAI_TransferAbortSendEDMA(privHandle->base, saiHandle);
|
||||
}
|
||||
}
|
||||
|
||||
static void SAI_RxEDMACallback(edma_handle_t *handle, void *userData, bool done, uint32_t tcds)
|
||||
{
|
||||
sai_edma_private_handle_t *privHandle = (sai_edma_private_handle_t *)userData;
|
||||
sai_edma_handle_t *saiHandle = privHandle->handle;
|
||||
|
||||
/* If finished a blcok, call the callback function */
|
||||
memset(&saiHandle->saiQueue[saiHandle->queueDriver], 0, sizeof(sai_transfer_t));
|
||||
saiHandle->queueDriver = (saiHandle->queueDriver + 1) % SAI_XFER_QUEUE_SIZE;
|
||||
if (saiHandle->callback)
|
||||
{
|
||||
(saiHandle->callback)(privHandle->base, saiHandle, kStatus_SAI_RxIdle, saiHandle->userData);
|
||||
}
|
||||
|
||||
/* If all data finished, just stop the transfer */
|
||||
if (saiHandle->saiQueue[saiHandle->queueDriver].data == NULL)
|
||||
{
|
||||
SAI_TransferAbortReceiveEDMA(privHandle->base, saiHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void SAI_TransferTxCreateHandleEDMA(
|
||||
I2S_Type *base, sai_edma_handle_t *handle, sai_edma_callback_t callback, void *userData, edma_handle_t *dmaHandle)
|
||||
{
|
||||
assert(handle && dmaHandle);
|
||||
|
||||
uint32_t instance = SAI_GetInstance(base);
|
||||
|
||||
/* Set sai base to handle */
|
||||
handle->dmaHandle = dmaHandle;
|
||||
handle->callback = callback;
|
||||
handle->userData = userData;
|
||||
|
||||
/* Set SAI state to idle */
|
||||
handle->state = kSAI_Idle;
|
||||
|
||||
s_edmaPrivateHandle[instance][0].base = base;
|
||||
s_edmaPrivateHandle[instance][0].handle = handle;
|
||||
|
||||
/* Need to use scatter gather */
|
||||
EDMA_InstallTCDMemory(dmaHandle, STCD_ADDR(handle->tcd), SAI_XFER_QUEUE_SIZE);
|
||||
|
||||
/* Install callback for Tx dma channel */
|
||||
EDMA_SetCallback(dmaHandle, SAI_TxEDMACallback, &s_edmaPrivateHandle[instance][0]);
|
||||
}
|
||||
|
||||
void SAI_TransferRxCreateHandleEDMA(
|
||||
I2S_Type *base, sai_edma_handle_t *handle, sai_edma_callback_t callback, void *userData, edma_handle_t *dmaHandle)
|
||||
{
|
||||
assert(handle && dmaHandle);
|
||||
|
||||
uint32_t instance = SAI_GetInstance(base);
|
||||
|
||||
/* Set sai base to handle */
|
||||
handle->dmaHandle = dmaHandle;
|
||||
handle->callback = callback;
|
||||
handle->userData = userData;
|
||||
|
||||
/* Set SAI state to idle */
|
||||
handle->state = kSAI_Idle;
|
||||
|
||||
s_edmaPrivateHandle[instance][1].base = base;
|
||||
s_edmaPrivateHandle[instance][1].handle = handle;
|
||||
|
||||
/* Need to use scatter gather */
|
||||
EDMA_InstallTCDMemory(dmaHandle, STCD_ADDR(handle->tcd), SAI_XFER_QUEUE_SIZE);
|
||||
|
||||
/* Install callback for Tx dma channel */
|
||||
EDMA_SetCallback(dmaHandle, SAI_RxEDMACallback, &s_edmaPrivateHandle[instance][1]);
|
||||
}
|
||||
|
||||
void SAI_TransferTxSetFormatEDMA(I2S_Type *base,
|
||||
sai_edma_handle_t *handle,
|
||||
sai_transfer_format_t *format,
|
||||
uint32_t mclkSourceClockHz,
|
||||
uint32_t bclkSourceClockHz)
|
||||
{
|
||||
assert(handle && format);
|
||||
|
||||
/* Configure the audio format to SAI registers */
|
||||
SAI_TxSetFormat(base, format, mclkSourceClockHz, bclkSourceClockHz);
|
||||
|
||||
/* Get the tranfer size from format, this should be used in EDMA configuration */
|
||||
handle->bytesPerFrame = format->bitWidth / 8U;
|
||||
|
||||
/* Update the data channel SAI used */
|
||||
handle->channel = format->channel;
|
||||
#if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
|
||||
handle->count = FSL_FEATURE_SAI_FIFO_COUNT - format->watermark;
|
||||
#else
|
||||
handle->count = 1U;
|
||||
#endif /* FSL_FEATURE_SAI_FIFO_COUNT */
|
||||
}
|
||||
|
||||
void SAI_TransferRxSetFormatEDMA(I2S_Type *base,
|
||||
sai_edma_handle_t *handle,
|
||||
sai_transfer_format_t *format,
|
||||
uint32_t mclkSourceClockHz,
|
||||
uint32_t bclkSourceClockHz)
|
||||
{
|
||||
assert(handle && format);
|
||||
|
||||
/* Configure the audio format to SAI registers */
|
||||
SAI_RxSetFormat(base, format, mclkSourceClockHz, bclkSourceClockHz);
|
||||
|
||||
/* Get the tranfer size from format, this should be used in EDMA configuration */
|
||||
handle->bytesPerFrame = format->bitWidth / 8U;
|
||||
|
||||
/* Update the data channel SAI used */
|
||||
handle->channel = format->channel;
|
||||
|
||||
#if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1)
|
||||
handle->count = format->watermark;
|
||||
#else
|
||||
handle->count = 1U;
|
||||
#endif /* FSL_FEATURE_SAI_FIFO_COUNT */
|
||||
}
|
||||
|
||||
status_t SAI_TransferSendEDMA(I2S_Type *base, sai_edma_handle_t *handle, sai_transfer_t *xfer)
|
||||
{
|
||||
assert(handle && xfer);
|
||||
|
||||
edma_transfer_config_t config = {0};
|
||||
uint32_t destAddr = SAI_TxGetDataRegisterAddress(base, handle->channel);
|
||||
|
||||
/* Check if input parameter invalid */
|
||||
if ((xfer->data == NULL) || (xfer->dataSize == 0U))
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
if (handle->saiQueue[handle->queueUser].data)
|
||||
{
|
||||
return kStatus_SAI_QueueFull;
|
||||
}
|
||||
|
||||
/* Change the state of handle */
|
||||
handle->state = kSAI_Busy;
|
||||
|
||||
/* Update the queue state */
|
||||
handle->transferSize[handle->queueUser] = xfer->dataSize;
|
||||
handle->saiQueue[handle->queueUser].data = xfer->data;
|
||||
handle->saiQueue[handle->queueUser].dataSize = xfer->dataSize;
|
||||
handle->queueUser = (handle->queueUser + 1) % SAI_XFER_QUEUE_SIZE;
|
||||
|
||||
/* Prepare edma configure */
|
||||
EDMA_PrepareTransfer(&config, xfer->data, handle->bytesPerFrame, (void *)destAddr, handle->bytesPerFrame,
|
||||
handle->count * handle->bytesPerFrame, xfer->dataSize, kEDMA_MemoryToPeripheral);
|
||||
|
||||
EDMA_SubmitTransfer(handle->dmaHandle, &config);
|
||||
|
||||
/* Start DMA transfer */
|
||||
EDMA_StartTransfer(handle->dmaHandle);
|
||||
|
||||
/* Enable DMA enable bit */
|
||||
SAI_TxEnableDMA(base, kSAI_FIFORequestDMAEnable, true);
|
||||
|
||||
/* Enable SAI Tx clock */
|
||||
SAI_TxEnable(base, true);
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
status_t SAI_TransferReceiveEDMA(I2S_Type *base, sai_edma_handle_t *handle, sai_transfer_t *xfer)
|
||||
{
|
||||
assert(handle && xfer);
|
||||
|
||||
edma_transfer_config_t config = {0};
|
||||
uint32_t srcAddr = SAI_RxGetDataRegisterAddress(base, handle->channel);
|
||||
|
||||
/* Check if input parameter invalid */
|
||||
if ((xfer->data == NULL) || (xfer->dataSize == 0U))
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
if (handle->saiQueue[handle->queueUser].data)
|
||||
{
|
||||
return kStatus_SAI_QueueFull;
|
||||
}
|
||||
|
||||
/* Change the state of handle */
|
||||
handle->state = kSAI_Busy;
|
||||
|
||||
/* Update queue state */
|
||||
handle->transferSize[handle->queueUser] = xfer->dataSize;
|
||||
handle->saiQueue[handle->queueUser].data = xfer->data;
|
||||
handle->saiQueue[handle->queueUser].dataSize = xfer->dataSize;
|
||||
handle->queueUser = (handle->queueUser + 1) % SAI_XFER_QUEUE_SIZE;
|
||||
|
||||
/* Prepare edma configure */
|
||||
EDMA_PrepareTransfer(&config, (void *)srcAddr, handle->bytesPerFrame, xfer->data, handle->bytesPerFrame,
|
||||
handle->count * handle->bytesPerFrame, xfer->dataSize, kEDMA_PeripheralToMemory);
|
||||
|
||||
EDMA_SubmitTransfer(handle->dmaHandle, &config);
|
||||
|
||||
/* Start DMA transfer */
|
||||
EDMA_StartTransfer(handle->dmaHandle);
|
||||
|
||||
/* Enable DMA enable bit */
|
||||
SAI_RxEnableDMA(base, kSAI_FIFORequestDMAEnable, true);
|
||||
|
||||
/* Enable SAI Rx clock */
|
||||
SAI_RxEnable(base, true);
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
void SAI_TransferAbortSendEDMA(I2S_Type *base, sai_edma_handle_t *handle)
|
||||
{
|
||||
assert(handle);
|
||||
|
||||
/* Disable dma */
|
||||
EDMA_AbortTransfer(handle->dmaHandle);
|
||||
|
||||
/* Disable DMA enable bit */
|
||||
SAI_TxEnableDMA(base, kSAI_FIFORequestDMAEnable, false);
|
||||
|
||||
/* Set the handle state */
|
||||
handle->state = kSAI_Idle;
|
||||
}
|
||||
|
||||
void SAI_TransferAbortReceiveEDMA(I2S_Type *base, sai_edma_handle_t *handle)
|
||||
{
|
||||
assert(handle);
|
||||
|
||||
/* Disable dma */
|
||||
EDMA_AbortTransfer(handle->dmaHandle);
|
||||
|
||||
/* Disable DMA enable bit */
|
||||
SAI_RxEnableDMA(base, kSAI_FIFORequestDMAEnable, false);
|
||||
|
||||
/* Set the handle state */
|
||||
handle->state = kSAI_Idle;
|
||||
}
|
||||
|
||||
status_t SAI_TransferGetSendCountEDMA(I2S_Type *base, sai_edma_handle_t *handle, size_t *count)
|
||||
{
|
||||
assert(handle);
|
||||
|
||||
status_t status = kStatus_Success;
|
||||
|
||||
if (handle->state != kSAI_Busy)
|
||||
{
|
||||
status = kStatus_NoTransferInProgress;
|
||||
}
|
||||
else
|
||||
{
|
||||
*count = (handle->transferSize[handle->queueDriver] -
|
||||
EDMA_GetRemainingBytes(handle->dmaHandle->base, handle->dmaHandle->channel));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
status_t SAI_TransferGetReceiveCountEDMA(I2S_Type *base, sai_edma_handle_t *handle, size_t *count)
|
||||
{
|
||||
assert(handle);
|
||||
|
||||
status_t status = kStatus_Success;
|
||||
|
||||
if (handle->state != kSAI_Busy)
|
||||
{
|
||||
status = kStatus_NoTransferInProgress;
|
||||
}
|
||||
else
|
||||
{
|
||||
*count = (handle->transferSize[handle->queueDriver] -
|
||||
EDMA_GetRemainingBytes(handle->dmaHandle->base, handle->dmaHandle->channel));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
232
devices/MK22F51212/drivers/fsl_sai_edma.h
Normal file
232
devices/MK22F51212/drivers/fsl_sai_edma.h
Normal file
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_SAI_EDMA_H_
|
||||
#define _FSL_SAI_EDMA_H_
|
||||
|
||||
#include "fsl_sai.h"
|
||||
#include "fsl_edma.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup sai_edma
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
typedef struct _sai_edma_handle sai_edma_handle_t;
|
||||
|
||||
/*! @brief SAI eDMA transfer callback function for finish and error */
|
||||
typedef void (*sai_edma_callback_t)(I2S_Type *base, sai_edma_handle_t *handle, status_t status, void *userData);
|
||||
|
||||
/*! @brief SAI DMA transfer handle, users should not touch the content of the handle.*/
|
||||
struct _sai_edma_handle
|
||||
{
|
||||
edma_handle_t *dmaHandle; /*!< DMA handler for SAI send */
|
||||
uint8_t bytesPerFrame; /*!< Bytes in a frame */
|
||||
uint8_t channel; /*!< Which data channel */
|
||||
uint8_t count; /*!< The transfer data count in a DMA request */
|
||||
uint32_t state; /*!< Internal state for SAI eDMA transfer */
|
||||
sai_edma_callback_t callback; /*!< Callback for users while transfer finish or error occurs */
|
||||
void *userData; /*!< User callback parameter */
|
||||
edma_tcd_t tcd[SAI_XFER_QUEUE_SIZE + 1U]; /*!< TCD pool for eDMA transfer. */
|
||||
sai_transfer_t saiQueue[SAI_XFER_QUEUE_SIZE]; /*!< Transfer queue storing queued transfer. */
|
||||
size_t transferSize[SAI_XFER_QUEUE_SIZE]; /*!< Data bytes need to transfer */
|
||||
volatile uint8_t queueUser; /*!< Index for user to queue transfer. */
|
||||
volatile uint8_t queueDriver; /*!< Index for driver to get the transfer data and size */
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* APIs
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @name eDMA Transactional
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes the SAI eDMA handle.
|
||||
*
|
||||
* This function initializes the SAI master DMA handle, which can be used for other SAI master transactional APIs.
|
||||
* Usually, for a specified SAI instance, call this API once to get the initialized handle.
|
||||
*
|
||||
* @param base SAI base pointer.
|
||||
* @param handle SAI eDMA handle pointer.
|
||||
* @param base SAI peripheral base address.
|
||||
* @param callback Pointer to user callback function.
|
||||
* @param userData User parameter passed to the callback function.
|
||||
* @param dmaHandle eDMA handle pointer, this handle shall be static allocated by users.
|
||||
*/
|
||||
void SAI_TransferTxCreateHandleEDMA(
|
||||
I2S_Type *base, sai_edma_handle_t *handle, sai_edma_callback_t callback, void *userData, edma_handle_t *dmaHandle);
|
||||
|
||||
/*!
|
||||
* @brief Initializes the SAI Rx eDMA handle.
|
||||
*
|
||||
* This function initializes the SAI slave DMA handle, which can be used for other SAI master transactional APIs.
|
||||
* Usually, for a specified SAI instance, call this API once to get the initialized handle.
|
||||
*
|
||||
* @param base SAI base pointer.
|
||||
* @param handle SAI eDMA handle pointer.
|
||||
* @param base SAI peripheral base address.
|
||||
* @param callback Pointer to user callback function.
|
||||
* @param userData User parameter passed to the callback function.
|
||||
* @param dmaHandle eDMA handle pointer, this handle shall be static allocated by users.
|
||||
*/
|
||||
void SAI_TransferRxCreateHandleEDMA(
|
||||
I2S_Type *base, sai_edma_handle_t *handle, sai_edma_callback_t callback, void *userData, edma_handle_t *dmaHandle);
|
||||
|
||||
/*!
|
||||
* @brief Configures the SAI Tx audio format.
|
||||
*
|
||||
* The audio format can be changed at run-time. This function configures the sample rate and audio data
|
||||
* format to be transferred. This function also sets the eDMA parameter according to formatting requirements.
|
||||
*
|
||||
* @param base SAI base pointer.
|
||||
* @param handle SAI eDMA handle pointer.
|
||||
* @param format Pointer to SAI audio data format structure.
|
||||
* @param mclkSourceClockHz SAI master clock source frequency in Hz.
|
||||
* @param bclkSourceClockHz SAI bit clock source frequency in Hz. If bit clock source is master
|
||||
* clock, this value should equals to masterClockHz in format.
|
||||
* @retval kStatus_Success Audio format set successfully.
|
||||
* @retval kStatus_InvalidArgument The input argument is invalid.
|
||||
*/
|
||||
void SAI_TransferTxSetFormatEDMA(I2S_Type *base,
|
||||
sai_edma_handle_t *handle,
|
||||
sai_transfer_format_t *format,
|
||||
uint32_t mclkSourceClockHz,
|
||||
uint32_t bclkSourceClockHz);
|
||||
|
||||
/*!
|
||||
* @brief Configures the SAI Rx audio format.
|
||||
*
|
||||
* The audio format can be changed at run-time. This function configures the sample rate and audio data
|
||||
* format to be transferred. This function also sets the eDMA parameter according to formatting requirements.
|
||||
*
|
||||
* @param base SAI base pointer.
|
||||
* @param handle SAI eDMA handle pointer.
|
||||
* @param format Pointer to SAI audio data format structure.
|
||||
* @param mclkSourceClockHz SAI master clock source frequency in Hz.
|
||||
* @param bclkSourceClockHz SAI bit clock source frequency in Hz. If a bit clock source is the master
|
||||
* clock, this value should equal to masterClockHz in format.
|
||||
* @retval kStatus_Success Audio format set successfully.
|
||||
* @retval kStatus_InvalidArgument The input argument is invalid.
|
||||
*/
|
||||
void SAI_TransferRxSetFormatEDMA(I2S_Type *base,
|
||||
sai_edma_handle_t *handle,
|
||||
sai_transfer_format_t *format,
|
||||
uint32_t mclkSourceClockHz,
|
||||
uint32_t bclkSourceClockHz);
|
||||
|
||||
/*!
|
||||
* @brief Performs a non-blocking SAI transfer using DMA.
|
||||
*
|
||||
* @note This interface returns immediately after the transfer initiates. Call
|
||||
* SAI_GetTransferStatus to poll the transfer status and check whether the SAI transfer is finished.
|
||||
*
|
||||
* @param base SAI base pointer.
|
||||
* @param handle SAI eDMA handle pointer.
|
||||
* @param xfer Pointer to the DMA transfer structure.
|
||||
* @retval kStatus_Success Start a SAI eDMA send successfully.
|
||||
* @retval kStatus_InvalidArgument The input argument is invalid.
|
||||
* @retval kStatus_TxBusy SAI is busy sending data.
|
||||
*/
|
||||
status_t SAI_TransferSendEDMA(I2S_Type *base, sai_edma_handle_t *handle, sai_transfer_t *xfer);
|
||||
|
||||
/*!
|
||||
* @brief Performs a non-blocking SAI receive using eDMA.
|
||||
*
|
||||
* @note This interface returns immediately after the transfer initiates. Call
|
||||
* the SAI_GetReceiveRemainingBytes to poll the transfer status and check whether the SAI transfer is finished.
|
||||
*
|
||||
* @param base SAI base pointer
|
||||
* @param handle SAI eDMA handle pointer.
|
||||
* @param xfer Pointer to DMA transfer structure.
|
||||
* @retval kStatus_Success Start a SAI eDMA receive successfully.
|
||||
* @retval kStatus_InvalidArgument The input argument is invalid.
|
||||
* @retval kStatus_RxBusy SAI is busy receiving data.
|
||||
*/
|
||||
status_t SAI_TransferReceiveEDMA(I2S_Type *base, sai_edma_handle_t *handle, sai_transfer_t *xfer);
|
||||
|
||||
/*!
|
||||
* @brief Aborts a SAI transfer using eDMA.
|
||||
*
|
||||
* @param base SAI base pointer.
|
||||
* @param handle SAI eDMA handle pointer.
|
||||
*/
|
||||
void SAI_TransferAbortSendEDMA(I2S_Type *base, sai_edma_handle_t *handle);
|
||||
|
||||
/*!
|
||||
* @brief Aborts a SAI receive using eDMA.
|
||||
*
|
||||
* @param base SAI base pointer
|
||||
* @param handle SAI eDMA handle pointer.
|
||||
*/
|
||||
void SAI_TransferAbortReceiveEDMA(I2S_Type *base, sai_edma_handle_t *handle);
|
||||
|
||||
/*!
|
||||
* @brief Gets byte count sent by SAI.
|
||||
*
|
||||
* @param base SAI base pointer.
|
||||
* @param handle SAI eDMA handle pointer.
|
||||
* @param count Bytes count sent by SAI.
|
||||
* @retval kStatus_Success Succeed get the transfer count.
|
||||
* @retval kStatus_NoTransferInProgress There is no non-blocking transaction in progress.
|
||||
*/
|
||||
status_t SAI_TransferGetSendCountEDMA(I2S_Type *base, sai_edma_handle_t *handle, size_t *count);
|
||||
|
||||
/*!
|
||||
* @brief Gets byte count received by SAI.
|
||||
*
|
||||
* @param base SAI base pointer
|
||||
* @param handle SAI eDMA handle pointer.
|
||||
* @param count Bytes count received by SAI.
|
||||
* @retval kStatus_Success Succeed get the transfer count.
|
||||
* @retval kStatus_NoTransferInProgress There is no non-blocking transaction in progress.
|
||||
*/
|
||||
status_t SAI_TransferGetReceiveCountEDMA(I2S_Type *base, sai_edma_handle_t *handle, size_t *count);
|
||||
|
||||
/*! @} */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
#endif
|
||||
53
devices/MK22F51212/drivers/fsl_sim.c
Executable file
53
devices/MK22F51212/drivers/fsl_sim.c
Executable file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_sim.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Codes
|
||||
******************************************************************************/
|
||||
#if (defined(FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) && FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR)
|
||||
void SIM_SetUsbVoltRegulatorEnableMode(uint32_t mask)
|
||||
{
|
||||
SIM->SOPT1CFG |= (SIM_SOPT1CFG_URWE_MASK | SIM_SOPT1CFG_UVSWE_MASK | SIM_SOPT1CFG_USSWE_MASK);
|
||||
|
||||
SIM->SOPT1 = (SIM->SOPT1 & ~kSIM_UsbVoltRegEnableInAllModes) | mask;
|
||||
}
|
||||
#endif /* FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR */
|
||||
|
||||
void SIM_GetUniqueId(sim_uid_t *uid)
|
||||
{
|
||||
#if defined(SIM_UIDH)
|
||||
uid->H = SIM->UIDH;
|
||||
#endif
|
||||
uid->MH = SIM->UIDMH;
|
||||
uid->ML = SIM->UIDML;
|
||||
uid->L = SIM->UIDL;
|
||||
}
|
||||
128
devices/MK22F51212/drivers/fsl_sim.h
Executable file
128
devices/MK22F51212/drivers/fsl_sim.h
Executable file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FSL_SIM_H_
|
||||
#define _FSL_SIM_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*! @addtogroup sim */
|
||||
/*! @{*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
*******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
#define FSL_SIM_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Driver version 2.0.0 */
|
||||
/*@}*/
|
||||
|
||||
#if (defined(FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) && FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR)
|
||||
/*!@brief USB voltage regulator enable setting. */
|
||||
enum _sim_usb_volt_reg_enable_mode
|
||||
{
|
||||
kSIM_UsbVoltRegEnable = SIM_SOPT1_USBREGEN_MASK, /*!< Enable voltage regulator. */
|
||||
kSIM_UsbVoltRegEnableInLowPower = SIM_SOPT1_USBVSTBY_MASK, /*!< Enable voltage regulator in VLPR/VLPW modes. */
|
||||
kSIM_UsbVoltRegEnableInStop = SIM_SOPT1_USBSSTBY_MASK, /*!< Enable voltage regulator in STOP/VLPS/LLS/VLLS modes. */
|
||||
kSIM_UsbVoltRegEnableInAllModes = SIM_SOPT1_USBREGEN_MASK | SIM_SOPT1_USBSSTBY_MASK |
|
||||
SIM_SOPT1_USBVSTBY_MASK /*!< Enable voltage regulator in all power modes. */
|
||||
};
|
||||
#endif /* (defined(FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) && FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) */
|
||||
|
||||
/*!@brief Unique ID. */
|
||||
typedef struct _sim_uid
|
||||
{
|
||||
#if defined(SIM_UIDH)
|
||||
uint32_t H; /*!< UIDH. */
|
||||
#endif
|
||||
uint32_t MH; /*!< UIDMH. */
|
||||
uint32_t ML; /*!< UIDML. */
|
||||
uint32_t L; /*!< UIDL. */
|
||||
} sim_uid_t;
|
||||
|
||||
/*!@brief Flash enable mode. */
|
||||
enum _sim_flash_mode
|
||||
{
|
||||
kSIM_FlashDisableInWait = SIM_FCFG1_FLASHDOZE_MASK, /*!< Disable flash in wait mode. */
|
||||
kSIM_FlashDisable = SIM_FCFG1_FLASHDIS_MASK /*!< Disable flash in normal mode. */
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus*/
|
||||
|
||||
#if (defined(FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) && FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR)
|
||||
/*!
|
||||
* @brief Sets the USB voltage regulator setting.
|
||||
*
|
||||
* This function configures whether the USB voltage regulator is enabled in
|
||||
* normal RUN mode, STOP/VLPS/LLS/VLLS modes and VLPR/VLPW modes. The configurations
|
||||
* are passed in as mask value of \ref _sim_usb_volt_reg_enable_mode. For example, enable
|
||||
* USB voltage regulator in RUN/VLPR/VLPW modes and disable in STOP/VLPS/LLS/VLLS mode,
|
||||
* please use:
|
||||
*
|
||||
* SIM_SetUsbVoltRegulatorEnableMode(kSIM_UsbVoltRegEnable | kSIM_UsbVoltRegEnableInLowPower);
|
||||
*
|
||||
* @param mask USB voltage regulator enable setting.
|
||||
*/
|
||||
void SIM_SetUsbVoltRegulatorEnableMode(uint32_t mask);
|
||||
#endif /* FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR */
|
||||
|
||||
/*!
|
||||
* @brief Get the unique identification register value.
|
||||
*
|
||||
* @param uid Pointer to the structure to save the UID value.
|
||||
*/
|
||||
void SIM_GetUniqueId(sim_uid_t *uid);
|
||||
|
||||
/*!
|
||||
* @brief Set the flash enable mode.
|
||||
*
|
||||
* @param mode The mode to set, see \ref _sim_flash_mode for mode details.
|
||||
*/
|
||||
static inline void SIM_SetFlashMode(uint8_t mode)
|
||||
{
|
||||
SIM->FCFG1 = mode;
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus*/
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_SIM_H_ */
|
||||
360
devices/MK22F51212/drivers/fsl_smc.c
Normal file
360
devices/MK22F51212/drivers/fsl_smc.c
Normal file
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_smc.h"
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_PARAM) && FSL_FEATURE_SMC_HAS_PARAM)
|
||||
void SMC_GetParam(SMC_Type *base, smc_param_t *param)
|
||||
{
|
||||
uint32_t reg = base->PARAM;
|
||||
param->hsrunEnable = (bool)(reg & SMC_PARAM_EHSRUN_MASK);
|
||||
param->llsEnable = (bool)(reg & SMC_PARAM_ELLS_MASK);
|
||||
param->lls2Enable = (bool)(reg & SMC_PARAM_ELLS2_MASK);
|
||||
param->vlls0Enable = (bool)(reg & SMC_PARAM_EVLLS0_MASK);
|
||||
}
|
||||
#endif /* FSL_FEATURE_SMC_HAS_PARAM */
|
||||
|
||||
status_t SMC_SetPowerModeRun(SMC_Type *base)
|
||||
{
|
||||
uint8_t reg;
|
||||
|
||||
reg = base->PMCTRL;
|
||||
/* configure Normal RUN mode */
|
||||
reg &= ~SMC_PMCTRL_RUNM_MASK;
|
||||
reg |= (kSMC_RunNormal << SMC_PMCTRL_RUNM_SHIFT);
|
||||
base->PMCTRL = reg;
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE) && FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE)
|
||||
status_t SMC_SetPowerModeHsrun(SMC_Type *base)
|
||||
{
|
||||
uint8_t reg;
|
||||
|
||||
reg = base->PMCTRL;
|
||||
/* configure High Speed RUN mode */
|
||||
reg &= ~SMC_PMCTRL_RUNM_MASK;
|
||||
reg |= (kSMC_Hsrun << SMC_PMCTRL_RUNM_SHIFT);
|
||||
base->PMCTRL = reg;
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
#endif /* FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE */
|
||||
|
||||
status_t SMC_SetPowerModeWait(SMC_Type *base)
|
||||
{
|
||||
/* configure Normal Wait mode */
|
||||
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
|
||||
__WFI();
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
status_t SMC_SetPowerModeStop(SMC_Type *base, smc_partial_stop_option_t option)
|
||||
{
|
||||
uint8_t reg;
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_PSTOPO) && FSL_FEATURE_SMC_HAS_PSTOPO)
|
||||
/* configure the Partial Stop mode in Noraml Stop mode */
|
||||
reg = base->STOPCTRL;
|
||||
reg &= ~SMC_STOPCTRL_PSTOPO_MASK;
|
||||
reg |= ((uint32_t)option << SMC_STOPCTRL_PSTOPO_SHIFT);
|
||||
base->STOPCTRL = reg;
|
||||
#endif
|
||||
|
||||
/* configure Normal Stop mode */
|
||||
reg = base->PMCTRL;
|
||||
reg &= ~SMC_PMCTRL_STOPM_MASK;
|
||||
reg |= (kSMC_StopNormal << SMC_PMCTRL_STOPM_SHIFT);
|
||||
base->PMCTRL = reg;
|
||||
|
||||
/* Set the SLEEPDEEP bit to enable deep sleep mode (stop mode) */
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
|
||||
/* read back to make sure the configuration valid before enter stop mode */
|
||||
(void)base->PMCTRL;
|
||||
__WFI();
|
||||
|
||||
/* check whether the power mode enter Stop mode succeed */
|
||||
if (base->PMCTRL & SMC_PMCTRL_STOPA_MASK)
|
||||
{
|
||||
return kStatus_SMC_StopAbort;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kStatus_Success;
|
||||
}
|
||||
}
|
||||
|
||||
status_t SMC_SetPowerModeVlpr(SMC_Type *base
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LPWUI) && FSL_FEATURE_SMC_HAS_LPWUI)
|
||||
,
|
||||
bool wakeupMode
|
||||
#endif
|
||||
)
|
||||
{
|
||||
uint8_t reg;
|
||||
|
||||
reg = base->PMCTRL;
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LPWUI) && FSL_FEATURE_SMC_HAS_LPWUI)
|
||||
/* configure whether the system remains in VLP mode on an interrupt */
|
||||
if (wakeupMode)
|
||||
{
|
||||
/* exits to RUN mode on an interrupt */
|
||||
reg |= SMC_PMCTRL_LPWUI_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* remains in VLP mode on an interrupt */
|
||||
reg &= ~SMC_PMCTRL_LPWUI_MASK;
|
||||
}
|
||||
#endif /* FSL_FEATURE_SMC_HAS_LPWUI */
|
||||
|
||||
/* configure VLPR mode */
|
||||
reg &= ~SMC_PMCTRL_RUNM_MASK;
|
||||
reg |= (kSMC_RunVlpr << SMC_PMCTRL_RUNM_SHIFT);
|
||||
base->PMCTRL = reg;
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
status_t SMC_SetPowerModeVlpw(SMC_Type *base)
|
||||
{
|
||||
/* Power mode transaction to VLPW can only happen in VLPR mode */
|
||||
if (kSMC_PowerStateVlpr != SMC_GetPowerModeState(base))
|
||||
{
|
||||
return kStatus_Fail;
|
||||
}
|
||||
|
||||
/* configure VLPW mode */
|
||||
/* Set the SLEEPDEEP bit to enable deep sleep mode */
|
||||
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
|
||||
__WFI();
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
status_t SMC_SetPowerModeVlps(SMC_Type *base)
|
||||
{
|
||||
uint8_t reg;
|
||||
|
||||
/* configure VLPS mode */
|
||||
reg = base->PMCTRL;
|
||||
reg &= ~SMC_PMCTRL_STOPM_MASK;
|
||||
reg |= (kSMC_StopVlps << SMC_PMCTRL_STOPM_SHIFT);
|
||||
base->PMCTRL = reg;
|
||||
|
||||
/* Set the SLEEPDEEP bit to enable deep sleep mode */
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
|
||||
/* read back to make sure the configuration valid before enter stop mode */
|
||||
(void)base->PMCTRL;
|
||||
__WFI();
|
||||
|
||||
/* check whether the power mode enter VLPS mode succeed */
|
||||
if (base->PMCTRL & SMC_PMCTRL_STOPA_MASK)
|
||||
{
|
||||
return kStatus_SMC_StopAbort;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kStatus_Success;
|
||||
}
|
||||
}
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE)
|
||||
status_t SMC_SetPowerModeLls(SMC_Type *base
|
||||
#if ((defined(FSL_FEATURE_SMC_HAS_LLS_SUBMODE) && FSL_FEATURE_SMC_HAS_LLS_SUBMODE) || \
|
||||
(defined(FSL_FEATURE_SMC_HAS_LPOPO) && FSL_FEATURE_SMC_HAS_LPOPO))
|
||||
,
|
||||
const smc_power_mode_lls_config_t *config
|
||||
#endif
|
||||
)
|
||||
{
|
||||
uint8_t reg;
|
||||
|
||||
/* configure to LLS mode */
|
||||
reg = base->PMCTRL;
|
||||
reg &= ~SMC_PMCTRL_STOPM_MASK;
|
||||
reg |= (kSMC_StopLls << SMC_PMCTRL_STOPM_SHIFT);
|
||||
base->PMCTRL = reg;
|
||||
|
||||
/* configure LLS sub-mode*/
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LLS_SUBMODE) && FSL_FEATURE_SMC_HAS_LLS_SUBMODE)
|
||||
reg = base->STOPCTRL;
|
||||
reg &= ~SMC_STOPCTRL_LLSM_MASK;
|
||||
reg |= ((uint32_t)config->subMode << SMC_STOPCTRL_LLSM_SHIFT);
|
||||
base->STOPCTRL = reg;
|
||||
#endif /* FSL_FEATURE_SMC_HAS_LLS_SUBMODE */
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LPOPO) && FSL_FEATURE_SMC_HAS_LPOPO)
|
||||
if (config->enableLpoClock)
|
||||
{
|
||||
base->STOPCTRL &= ~SMC_STOPCTRL_LPOPO_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->STOPCTRL |= SMC_STOPCTRL_LPOPO_MASK;
|
||||
}
|
||||
#endif /* FSL_FEATURE_SMC_HAS_LPOPO */
|
||||
|
||||
/* Set the SLEEPDEEP bit to enable deep sleep mode */
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
|
||||
/* read back to make sure the configuration valid before enter stop mode */
|
||||
(void)base->PMCTRL;
|
||||
__WFI();
|
||||
|
||||
/* check whether the power mode enter LLS mode succeed */
|
||||
if (base->PMCTRL & SMC_PMCTRL_STOPA_MASK)
|
||||
{
|
||||
return kStatus_SMC_StopAbort;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kStatus_Success;
|
||||
}
|
||||
}
|
||||
#endif /* FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE */
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE)
|
||||
status_t SMC_SetPowerModeVlls(SMC_Type *base, const smc_power_mode_vlls_config_t *config)
|
||||
{
|
||||
uint8_t reg;
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_PORPO) && FSL_FEATURE_SMC_HAS_PORPO)
|
||||
#if (defined(FSL_FEATURE_SMC_USE_VLLSCTRL_REG) && FSL_FEATURE_SMC_USE_VLLSCTRL_REG) || \
|
||||
(defined(FSL_FEATURE_SMC_USE_STOPCTRL_VLLSM) && FSL_FEATURE_SMC_USE_STOPCTRL_VLLSM) || \
|
||||
(defined(FSL_FEATURE_SMC_HAS_LLS_SUBMODE) && FSL_FEATURE_SMC_HAS_LLS_SUBMODE)
|
||||
if (config->subMode == kSMC_StopSub0)
|
||||
#endif
|
||||
{
|
||||
/* configure whether the Por Detect work in Vlls0 mode */
|
||||
if (config->enablePorDetectInVlls0)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_SMC_USE_VLLSCTRL_REG) && FSL_FEATURE_SMC_USE_VLLSCTRL_REG)
|
||||
base->VLLSCTRL &= ~SMC_VLLSCTRL_PORPO_MASK;
|
||||
#else
|
||||
base->STOPCTRL &= ~SMC_STOPCTRL_PORPO_MASK;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (defined(FSL_FEATURE_SMC_USE_VLLSCTRL_REG) && FSL_FEATURE_SMC_USE_VLLSCTRL_REG)
|
||||
base->VLLSCTRL |= SMC_VLLSCTRL_PORPO_MASK;
|
||||
#else
|
||||
base->STOPCTRL |= SMC_STOPCTRL_PORPO_MASK;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif /* FSL_FEATURE_SMC_HAS_PORPO */
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_RAM2_POWER_OPTION) && FSL_FEATURE_SMC_HAS_RAM2_POWER_OPTION)
|
||||
else if (config->subMode == kSMC_StopSub2)
|
||||
{
|
||||
/* configure whether the Por Detect work in Vlls0 mode */
|
||||
if (config->enableRam2InVlls2)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_SMC_USE_VLLSCTRL_REG) && FSL_FEATURE_SMC_USE_VLLSCTRL_REG)
|
||||
base->VLLSCTRL |= SMC_VLLSCTRL_RAM2PO_MASK;
|
||||
#else
|
||||
base->STOPCTRL |= SMC_STOPCTRL_RAM2PO_MASK;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (defined(FSL_FEATURE_SMC_USE_VLLSCTRL_REG) && FSL_FEATURE_SMC_USE_VLLSCTRL_REG)
|
||||
base->VLLSCTRL &= ~SMC_VLLSCTRL_RAM2PO_MASK;
|
||||
#else
|
||||
base->STOPCTRL &= ~SMC_STOPCTRL_RAM2PO_MASK;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
#endif /* FSL_FEATURE_SMC_HAS_RAM2_POWER_OPTION */
|
||||
|
||||
/* configure to VLLS mode */
|
||||
reg = base->PMCTRL;
|
||||
reg &= ~SMC_PMCTRL_STOPM_MASK;
|
||||
reg |= (kSMC_StopVlls << SMC_PMCTRL_STOPM_SHIFT);
|
||||
base->PMCTRL = reg;
|
||||
|
||||
/* configure the VLLS sub-mode */
|
||||
#if (defined(FSL_FEATURE_SMC_USE_VLLSCTRL_REG) && FSL_FEATURE_SMC_USE_VLLSCTRL_REG)
|
||||
reg = base->VLLSCTRL;
|
||||
reg &= ~SMC_VLLSCTRL_VLLSM_MASK;
|
||||
reg |= ((uint32_t)config->subMode << SMC_VLLSCTRL_VLLSM_SHIFT);
|
||||
base->VLLSCTRL = reg;
|
||||
#else
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LLS_SUBMODE) && FSL_FEATURE_SMC_HAS_LLS_SUBMODE)
|
||||
reg = base->STOPCTRL;
|
||||
reg &= ~SMC_STOPCTRL_LLSM_MASK;
|
||||
reg |= ((uint32_t)config->subMode << SMC_STOPCTRL_LLSM_SHIFT);
|
||||
base->STOPCTRL = reg;
|
||||
#else
|
||||
reg = base->STOPCTRL;
|
||||
reg &= ~SMC_STOPCTRL_VLLSM_MASK;
|
||||
reg |= ((uint32_t)config->subMode << SMC_STOPCTRL_VLLSM_SHIFT);
|
||||
base->STOPCTRL = reg;
|
||||
#endif /* FSL_FEATURE_SMC_HAS_LLS_SUBMODE */
|
||||
#endif
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LPOPO) && FSL_FEATURE_SMC_HAS_LPOPO)
|
||||
if (config->enableLpoClock)
|
||||
{
|
||||
base->STOPCTRL &= ~SMC_STOPCTRL_LPOPO_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->STOPCTRL |= SMC_STOPCTRL_LPOPO_MASK;
|
||||
}
|
||||
#endif /* FSL_FEATURE_SMC_HAS_LPOPO */
|
||||
|
||||
/* Set the SLEEPDEEP bit to enable deep sleep mode */
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
|
||||
/* read back to make sure the configuration valid before enter stop mode */
|
||||
(void)base->PMCTRL;
|
||||
__WFI();
|
||||
|
||||
/* check whether the power mode enter LLS mode succeed */
|
||||
if (base->PMCTRL & SMC_PMCTRL_STOPA_MASK)
|
||||
{
|
||||
return kStatus_SMC_StopAbort;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kStatus_Success;
|
||||
}
|
||||
}
|
||||
#endif /* FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE */
|
||||
419
devices/MK22F51212/drivers/fsl_smc.h
Normal file
419
devices/MK22F51212/drivers/fsl_smc.h
Normal file
@@ -0,0 +1,419 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FSL_SMC_H_
|
||||
#define _FSL_SMC_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*! @addtogroup smc */
|
||||
/*! @{ */
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief SMC driver version 2.0.1. */
|
||||
#define FSL_SMC_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
|
||||
/*@}*/
|
||||
|
||||
/*!
|
||||
* @brief Power Modes Protection
|
||||
*/
|
||||
typedef enum _smc_power_mode_protection
|
||||
{
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE)
|
||||
kSMC_AllowPowerModeVlls = SMC_PMPROT_AVLLS_MASK, /*!< Allow Very-Low-Leakage Stop Mode. */
|
||||
#endif
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE)
|
||||
kSMC_AllowPowerModeLls = SMC_PMPROT_ALLS_MASK, /*!< Allow Low-Leakage Stop Mode. */
|
||||
#endif /* FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE */
|
||||
kSMC_AllowPowerModeVlp = SMC_PMPROT_AVLP_MASK, /*!< Allow Very-Low-Power Mode. */
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE) && FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE)
|
||||
kSMC_AllowPowerModeHsrun = SMC_PMPROT_AHSRUN_MASK, /*!< Allow High Speed Run mode. */
|
||||
#endif /* FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE */
|
||||
kSMC_AllowPowerModeAll = (0U
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE)
|
||||
|
|
||||
SMC_PMPROT_AVLLS_MASK
|
||||
#endif
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE)
|
||||
|
|
||||
SMC_PMPROT_ALLS_MASK
|
||||
#endif /* FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE */
|
||||
|
|
||||
SMC_PMPROT_AVLP_MASK
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE) && FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE)
|
||||
|
|
||||
kSMC_AllowPowerModeHsrun
|
||||
#endif /* FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE */
|
||||
) /*!< Allow all power mode. */
|
||||
} smc_power_mode_protection_t;
|
||||
|
||||
/*!
|
||||
* @brief Power Modes in PMSTAT
|
||||
*/
|
||||
typedef enum _smc_power_state
|
||||
{
|
||||
kSMC_PowerStateRun = 0x01U << 0U, /*!< 0000_0001 - Current power mode is RUN */
|
||||
kSMC_PowerStateStop = 0x01U << 1U, /*!< 0000_0010 - Current power mode is STOP */
|
||||
kSMC_PowerStateVlpr = 0x01U << 2U, /*!< 0000_0100 - Current power mode is VLPR */
|
||||
kSMC_PowerStateVlpw = 0x01U << 3U, /*!< 0000_1000 - Current power mode is VLPW */
|
||||
kSMC_PowerStateVlps = 0x01U << 4U, /*!< 0001_0000 - Current power mode is VLPS */
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE)
|
||||
kSMC_PowerStateLls = 0x01U << 5U, /*!< 0010_0000 - Current power mode is LLS */
|
||||
#endif /* FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE */
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE)
|
||||
kSMC_PowerStateVlls = 0x01U << 6U, /*!< 0100_0000 - Current power mode is VLLS */
|
||||
#endif
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE) && FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE)
|
||||
kSMC_PowerStateHsrun = 0x01U << 7U /*!< 1000_0000 - Current power mode is HSRUN */
|
||||
#endif /* FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE */
|
||||
} smc_power_state_t;
|
||||
|
||||
/*!
|
||||
* @brief Run mode definition
|
||||
*/
|
||||
typedef enum _smc_run_mode
|
||||
{
|
||||
kSMC_RunNormal = 0U, /*!< normal RUN mode. */
|
||||
kSMC_RunVlpr = 2U, /*!< Very-Low-Power RUN mode. */
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE) && FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE)
|
||||
kSMC_Hsrun = 3U /*!< High Speed Run mode (HSRUN). */
|
||||
#endif /* FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE */
|
||||
} smc_run_mode_t;
|
||||
|
||||
/*!
|
||||
* @brief Stop mode definition
|
||||
*/
|
||||
typedef enum _smc_stop_mode
|
||||
{
|
||||
kSMC_StopNormal = 0U, /*!< Normal STOP mode. */
|
||||
kSMC_StopVlps = 2U, /*!< Very-Low-Power STOP mode. */
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE)
|
||||
kSMC_StopLls = 3U, /*!< Low-Leakage Stop mode. */
|
||||
#endif /* FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE */
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE)
|
||||
kSMC_StopVlls = 4U /*!< Very-Low-Leakage Stop mode. */
|
||||
#endif
|
||||
} smc_stop_mode_t;
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_USE_VLLSCTRL_REG) && FSL_FEATURE_SMC_USE_VLLSCTRL_REG) || \
|
||||
(defined(FSL_FEATURE_SMC_USE_STOPCTRL_VLLSM) && FSL_FEATURE_SMC_USE_STOPCTRL_VLLSM) || \
|
||||
(defined(FSL_FEATURE_SMC_HAS_LLS_SUBMODE) && FSL_FEATURE_SMC_HAS_LLS_SUBMODE)
|
||||
/*!
|
||||
* @brief VLLS/LLS stop sub mode definition
|
||||
*/
|
||||
typedef enum _smc_stop_submode
|
||||
{
|
||||
kSMC_StopSub0 = 0U, /*!< Stop submode 0, for VLLS0/LLS0. */
|
||||
kSMC_StopSub1 = 1U, /*!< Stop submode 1, for VLLS1/LLS1. */
|
||||
kSMC_StopSub2 = 2U, /*!< Stop submode 2, for VLLS2/LLS2. */
|
||||
kSMC_StopSub3 = 3U /*!< Stop submode 3, for VLLS3/LLS3. */
|
||||
} smc_stop_submode_t;
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Partial STOP option
|
||||
*/
|
||||
typedef enum _smc_partial_stop_mode
|
||||
{
|
||||
kSMC_PartialStop = 0U, /*!< STOP - Normal Stop mode*/
|
||||
kSMC_PartialStop1 = 1U, /*!< Partial Stop with both system and bus clocks disabled*/
|
||||
kSMC_PartialStop2 = 2U, /*!< Partial Stop with system clock disabled and bus clock enabled*/
|
||||
} smc_partial_stop_option_t;
|
||||
|
||||
/*!
|
||||
* @brief SMC configuration status
|
||||
*/
|
||||
enum _smc_status
|
||||
{
|
||||
kStatus_SMC_StopAbort = MAKE_STATUS(kStatusGroup_POWER, 0) /*!< Entering Stop mode is abort*/
|
||||
};
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_VERID) && FSL_FEATURE_SMC_HAS_VERID)
|
||||
/*!
|
||||
* @brief IP version ID definition.
|
||||
*/
|
||||
typedef struct _smc_version_id
|
||||
{
|
||||
uint16_t feature; /*!< Feature Specification Number. */
|
||||
uint8_t minor; /*!< Minor version number. */
|
||||
uint8_t major; /*!< Major version number. */
|
||||
} smc_version_id_t;
|
||||
#endif /* FSL_FEATURE_SMC_HAS_VERID */
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_PARAM) && FSL_FEATURE_SMC_HAS_PARAM)
|
||||
/*!
|
||||
* @brief IP parameter definition.
|
||||
*/
|
||||
typedef struct _smc_param
|
||||
{
|
||||
bool hsrunEnable; /*!< HSRUN mode enable. */
|
||||
bool llsEnable; /*!< LLS mode enable. */
|
||||
bool lls2Enable; /*!< LLS2 mode enable. */
|
||||
bool vlls0Enable; /*!< VLLS0 mode enable. */
|
||||
} smc_param_t;
|
||||
#endif /* FSL_FEATURE_SMC_HAS_PARAM */
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LLS_SUBMODE) && FSL_FEATURE_SMC_HAS_LLS_SUBMODE) || \
|
||||
(defined(FSL_FEATURE_SMC_HAS_LPOPO) && FSL_FEATURE_SMC_HAS_LPOPO)
|
||||
/*!
|
||||
* @brief SMC Low-Leakage Stop power mode config
|
||||
*/
|
||||
typedef struct _smc_power_mode_lls_config
|
||||
{
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LLS_SUBMODE) && FSL_FEATURE_SMC_HAS_LLS_SUBMODE)
|
||||
smc_stop_submode_t subMode; /*!< Low-leakage Stop sub-mode */
|
||||
#endif
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LPOPO) && FSL_FEATURE_SMC_HAS_LPOPO)
|
||||
bool enableLpoClock; /*!< Enable LPO clock in LLS mode */
|
||||
#endif
|
||||
} smc_power_mode_lls_config_t;
|
||||
#endif /* (FSL_FEATURE_SMC_HAS_LLS_SUBMODE || FSL_FEATURE_SMC_HAS_LPOPO) */
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE)
|
||||
/*!
|
||||
* @brief SMC Very Low-Leakage Stop power mode config
|
||||
*/
|
||||
typedef struct _smc_power_mode_vlls_config
|
||||
{
|
||||
#if (defined(FSL_FEATURE_SMC_USE_VLLSCTRL_REG) && FSL_FEATURE_SMC_USE_VLLSCTRL_REG) || \
|
||||
(defined(FSL_FEATURE_SMC_USE_STOPCTRL_VLLSM) && FSL_FEATURE_SMC_USE_STOPCTRL_VLLSM) || \
|
||||
(defined(FSL_FEATURE_SMC_HAS_LLS_SUBMODE) && FSL_FEATURE_SMC_HAS_LLS_SUBMODE)
|
||||
smc_stop_submode_t subMode; /*!< Very Low-leakage Stop sub-mode */
|
||||
#endif
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_PORPO) && FSL_FEATURE_SMC_HAS_PORPO)
|
||||
bool enablePorDetectInVlls0; /*!< Enable Power on reset detect in VLLS mode */
|
||||
#endif
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_RAM2_POWER_OPTION) && FSL_FEATURE_SMC_HAS_RAM2_POWER_OPTION)
|
||||
bool enableRam2InVlls2; /*!< Enable RAM2 power in VLLS2 */
|
||||
#endif
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LPOPO) && FSL_FEATURE_SMC_HAS_LPOPO)
|
||||
bool enableLpoClock; /*!< Enable LPO clock in VLLS mode */
|
||||
#endif
|
||||
} smc_power_mode_vlls_config_t;
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @name System mode controller APIs*/
|
||||
/*@{*/
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_VERID) && FSL_FEATURE_SMC_HAS_VERID)
|
||||
/*!
|
||||
* @brief Gets the SMC version ID.
|
||||
*
|
||||
* This function gets the SMC version ID, including major version number,
|
||||
* minor version number and feature specification number.
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @param versionId Pointer to version ID structure.
|
||||
*/
|
||||
static inline void SMC_GetVersionId(SMC_Type *base, smc_version_id_t *versionId)
|
||||
{
|
||||
*((uint32_t *)versionId) = base->VERID;
|
||||
}
|
||||
#endif /* FSL_FEATURE_SMC_HAS_VERID */
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_PARAM) && FSL_FEATURE_SMC_HAS_PARAM)
|
||||
/*!
|
||||
* @brief Gets the SMC parameter.
|
||||
*
|
||||
* This function gets the SMC parameter, including the enabled power mdoes.
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @param param Pointer to SMC param structure.
|
||||
*/
|
||||
void SMC_GetParam(SMC_Type *base, smc_param_t *param);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Configures all power mode protection settings.
|
||||
*
|
||||
* This function configures the power mode protection settings for
|
||||
* supported power modes in the specified chip family. The available power modes
|
||||
* are defined in the smc_power_mode_protection_t. This should be done at an early
|
||||
* system level initialization stage. See the reference manual for details.
|
||||
* This register can only write once after the power reset.
|
||||
*
|
||||
* The allowed modes are passed as bit map, for example, to allow LLS and VLLS,
|
||||
* use SMC_SetPowerModeProtection(kSMC_AllowPowerModeVlls | kSMC_AllowPowerModeVlps).
|
||||
* To allow all modes, use SMC_SetPowerModeProtection(kSMC_AllowPowerModeAll).
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @param allowedModes Bitmap of the allowed power modes.
|
||||
*/
|
||||
static inline void SMC_SetPowerModeProtection(SMC_Type *base, uint8_t allowedModes)
|
||||
{
|
||||
base->PMPROT = allowedModes;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets the current power mode status.
|
||||
*
|
||||
* This function returns the current power mode stat. Once application
|
||||
* switches the power mode, it should always check the stat to check whether it
|
||||
* runs into the specified mode or not. An application should check
|
||||
* this mode before switching to a different mode. The system requires that
|
||||
* only certain modes can switch to other specific modes. See the
|
||||
* reference manual for details and the smc_power_state_t for information about
|
||||
* the power stat.
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @return Current power mode status.
|
||||
*/
|
||||
static inline smc_power_state_t SMC_GetPowerModeState(SMC_Type *base)
|
||||
{
|
||||
return (smc_power_state_t)base->PMSTAT;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Configure the system to RUN power mode.
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @return SMC configuration error code.
|
||||
*/
|
||||
status_t SMC_SetPowerModeRun(SMC_Type *base);
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE) && FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE)
|
||||
/*!
|
||||
* @brief Configure the system to HSRUN power mode.
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @return SMC configuration error code.
|
||||
*/
|
||||
status_t SMC_SetPowerModeHsrun(SMC_Type *base);
|
||||
#endif /* FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE */
|
||||
|
||||
/*!
|
||||
* @brief Configure the system to WAIT power mode.
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @return SMC configuration error code.
|
||||
*/
|
||||
status_t SMC_SetPowerModeWait(SMC_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Configure the system to Stop power mode.
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @param option Partial Stop mode option.
|
||||
* @return SMC configuration error code.
|
||||
*/
|
||||
status_t SMC_SetPowerModeStop(SMC_Type *base, smc_partial_stop_option_t option);
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LPWUI) && FSL_FEATURE_SMC_HAS_LPWUI)
|
||||
/*!
|
||||
* @brief Configure the system to VLPR power mode.
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @param wakeupMode Enter Normal Run mode if true, else stay in VLPR mode.
|
||||
* @return SMC configuration error code.
|
||||
*/
|
||||
status_t SMC_SetPowerModeVlpr(SMC_Type *base, bool wakeupMode);
|
||||
#else
|
||||
/*!
|
||||
* @brief Configure the system to VLPR power mode.
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @return SMC configuration error code.
|
||||
*/
|
||||
status_t SMC_SetPowerModeVlpr(SMC_Type *base);
|
||||
#endif /* FSL_FEATURE_SMC_HAS_LPWUI */
|
||||
|
||||
/*!
|
||||
* @brief Configure the system to VLPW power mode.
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @return SMC configuration error code.
|
||||
*/
|
||||
status_t SMC_SetPowerModeVlpw(SMC_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Configure the system to VLPS power mode.
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @return SMC configuration error code.
|
||||
*/
|
||||
status_t SMC_SetPowerModeVlps(SMC_Type *base);
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE)
|
||||
#if ((defined(FSL_FEATURE_SMC_HAS_LLS_SUBMODE) && FSL_FEATURE_SMC_HAS_LLS_SUBMODE) || \
|
||||
(defined(FSL_FEATURE_SMC_HAS_LPOPO) && FSL_FEATURE_SMC_HAS_LPOPO))
|
||||
/*!
|
||||
* @brief Configure the system to LLS power mode.
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @param config The LLS power mode configuration structure
|
||||
* @return SMC configuration error code.
|
||||
*/
|
||||
status_t SMC_SetPowerModeLls(SMC_Type *base, const smc_power_mode_lls_config_t *config);
|
||||
#else
|
||||
/*!
|
||||
* @brief Configure the system to LLS power mode.
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @return SMC configuration error code.
|
||||
*/
|
||||
status_t SMC_SetPowerModeLls(SMC_Type *base);
|
||||
#endif
|
||||
#endif /* FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE */
|
||||
|
||||
#if (defined(FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE) && FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE)
|
||||
/*!
|
||||
* @brief Configure the system to VLLS power mode.
|
||||
*
|
||||
* @param base SMC peripheral base address.
|
||||
* @param config The VLLS power mode configuration structure.
|
||||
* @return SMC configuration error code.
|
||||
*/
|
||||
status_t SMC_SetPowerModeVlls(SMC_Type *base, const smc_power_mode_vlls_config_t *config);
|
||||
#endif /* FSL_FEATURE_SMC_HAS_VERY_LOW_LEAKAGE_STOP_MODE */
|
||||
|
||||
/*@}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_SMC_H_ */
|
||||
1032
devices/MK22F51212/drivers/fsl_uart.c
Normal file
1032
devices/MK22F51212/drivers/fsl_uart.c
Normal file
File diff suppressed because it is too large
Load Diff
757
devices/MK22F51212/drivers/fsl_uart.h
Normal file
757
devices/MK22F51212/drivers/fsl_uart.h
Normal file
File diff suppressed because it is too large
Load Diff
362
devices/MK22F51212/drivers/fsl_uart_edma.c
Normal file
362
devices/MK22F51212/drivers/fsl_uart_edma.c
Normal file
@@ -0,0 +1,362 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_uart_edma.h"
|
||||
#include "fsl_dmamux.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/* Array of UART handle. */
|
||||
#if (defined(UART5))
|
||||
#define UART_HANDLE_ARRAY_SIZE 6
|
||||
#else /* UART5 */
|
||||
#if (defined(UART4))
|
||||
#define UART_HANDLE_ARRAY_SIZE 5
|
||||
#else /* UART4 */
|
||||
#if (defined(UART3))
|
||||
#define UART_HANDLE_ARRAY_SIZE 4
|
||||
#else /* UART3 */
|
||||
#if (defined(UART2))
|
||||
#define UART_HANDLE_ARRAY_SIZE 3
|
||||
#else /* UART2 */
|
||||
#if (defined(UART1))
|
||||
#define UART_HANDLE_ARRAY_SIZE 2
|
||||
#else /* UART1 */
|
||||
#if (defined(UART0))
|
||||
#define UART_HANDLE_ARRAY_SIZE 1
|
||||
#else /* UART0 */
|
||||
#error No UART instance.
|
||||
#endif /* UART 0 */
|
||||
#endif /* UART 1 */
|
||||
#endif /* UART 2 */
|
||||
#endif /* UART 3 */
|
||||
#endif /* UART 4 */
|
||||
#endif /* UART 5 */
|
||||
|
||||
/*<! Structure definition for uart_edma_private_handle_t. The structure is private. */
|
||||
typedef struct _uart_edma_private_handle
|
||||
{
|
||||
UART_Type *base;
|
||||
uart_edma_handle_t *handle;
|
||||
} uart_edma_private_handle_t;
|
||||
|
||||
/* UART EDMA transfer handle. */
|
||||
enum _uart_edma_tansfer_states
|
||||
{
|
||||
kUART_TxIdle, /* TX idle. */
|
||||
kUART_TxBusy, /* TX busy. */
|
||||
kUART_RxIdle, /* RX idle. */
|
||||
kUART_RxBusy /* RX busy. */
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*<! Private handle only used for internally. */
|
||||
static uart_edma_private_handle_t s_edmaPrivateHandle[UART_HANDLE_ARRAY_SIZE];
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief UART EDMA send finished callback function.
|
||||
*
|
||||
* This function is called when UART EDMA send finished. It disables the UART
|
||||
* TX EDMA request and sends @ref kStatus_UART_TxIdle to UART callback.
|
||||
*
|
||||
* @param handle The EDMA handle.
|
||||
* @param param Callback function parameter.
|
||||
*/
|
||||
static void UART_SendEDMACallback(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds);
|
||||
|
||||
/*!
|
||||
* @brief UART EDMA receive finished callback function.
|
||||
*
|
||||
* This function is called when UART EDMA receive finished. It disables the UART
|
||||
* RX EDMA request and sends @ref kStatus_UART_RxIdle to UART callback.
|
||||
*
|
||||
* @param handle The EDMA handle.
|
||||
* @param param Callback function parameter.
|
||||
*/
|
||||
static void UART_ReceiveEDMACallback(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds);
|
||||
|
||||
/*!
|
||||
* @brief Get the UART instance from peripheral base address.
|
||||
*
|
||||
* @param base UART peripheral base address.
|
||||
* @return UART instance.
|
||||
*/
|
||||
extern uint32_t UART_GetInstance(UART_Type *base);
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
static void UART_SendEDMACallback(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds)
|
||||
{
|
||||
uart_edma_private_handle_t *uartPrivateHandle = (uart_edma_private_handle_t *)param;
|
||||
|
||||
/* Avoid the warning for unused variables. */
|
||||
handle = handle;
|
||||
tcds = tcds;
|
||||
|
||||
if (transferDone)
|
||||
{
|
||||
UART_TransferAbortSendEDMA(uartPrivateHandle->base, uartPrivateHandle->handle);
|
||||
|
||||
if (uartPrivateHandle->handle->callback)
|
||||
{
|
||||
uartPrivateHandle->handle->callback(uartPrivateHandle->base, uartPrivateHandle->handle, kStatus_UART_TxIdle,
|
||||
uartPrivateHandle->handle->userData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void UART_ReceiveEDMACallback(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds)
|
||||
{
|
||||
uart_edma_private_handle_t *uartPrivateHandle = (uart_edma_private_handle_t *)param;
|
||||
|
||||
/* Avoid warning for unused parameters. */
|
||||
handle = handle;
|
||||
tcds = tcds;
|
||||
|
||||
if (transferDone)
|
||||
{
|
||||
/* Disable transfer. */
|
||||
UART_TransferAbortReceiveEDMA(uartPrivateHandle->base, uartPrivateHandle->handle);
|
||||
|
||||
if (uartPrivateHandle->handle->callback)
|
||||
{
|
||||
uartPrivateHandle->handle->callback(uartPrivateHandle->base, uartPrivateHandle->handle, kStatus_UART_RxIdle,
|
||||
uartPrivateHandle->handle->userData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UART_TransferCreateHandleEDMA(UART_Type *base,
|
||||
uart_edma_handle_t *handle,
|
||||
uart_edma_transfer_callback_t callback,
|
||||
void *userData,
|
||||
edma_handle_t *txEdmaHandle,
|
||||
edma_handle_t *rxEdmaHandle)
|
||||
{
|
||||
assert(handle);
|
||||
|
||||
uint32_t instance = UART_GetInstance(base);
|
||||
|
||||
s_edmaPrivateHandle[instance].base = base;
|
||||
s_edmaPrivateHandle[instance].handle = handle;
|
||||
|
||||
memset(handle, 0, sizeof(*handle));
|
||||
|
||||
handle->rxState = kUART_RxIdle;
|
||||
handle->txState = kUART_TxIdle;
|
||||
|
||||
handle->rxEdmaHandle = rxEdmaHandle;
|
||||
handle->txEdmaHandle = txEdmaHandle;
|
||||
|
||||
handle->callback = callback;
|
||||
handle->userData = userData;
|
||||
|
||||
#if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
|
||||
/* Note:
|
||||
Take care of the RX FIFO, EDMA request only assert when received bytes
|
||||
equal or more than RX water mark, there is potential issue if RX water
|
||||
mark larger than 1.
|
||||
For example, if RX FIFO water mark is 2, upper layer needs 5 bytes and
|
||||
5 bytes are received. the last byte will be saved in FIFO but not trigger
|
||||
EDMA transfer because the water mark is 2.
|
||||
*/
|
||||
if (rxEdmaHandle)
|
||||
{
|
||||
base->RWFIFO = 1U;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Configure TX. */
|
||||
if (txEdmaHandle)
|
||||
{
|
||||
EDMA_SetCallback(handle->txEdmaHandle, UART_SendEDMACallback, &s_edmaPrivateHandle[instance]);
|
||||
}
|
||||
|
||||
/* Configure RX. */
|
||||
if (rxEdmaHandle)
|
||||
{
|
||||
EDMA_SetCallback(handle->rxEdmaHandle, UART_ReceiveEDMACallback, &s_edmaPrivateHandle[instance]);
|
||||
}
|
||||
}
|
||||
|
||||
status_t UART_SendEDMA(UART_Type *base, uart_edma_handle_t *handle, uart_transfer_t *xfer)
|
||||
{
|
||||
assert(handle->txEdmaHandle);
|
||||
|
||||
edma_transfer_config_t xferConfig;
|
||||
status_t status;
|
||||
|
||||
/* Return error if xfer invalid. */
|
||||
if ((0U == xfer->dataSize) || (NULL == xfer->data))
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
/* If previous TX not finished. */
|
||||
if (kUART_TxBusy == handle->txState)
|
||||
{
|
||||
status = kStatus_UART_TxBusy;
|
||||
}
|
||||
else
|
||||
{
|
||||
handle->txState = kUART_TxBusy;
|
||||
handle->txDataSizeAll = xfer->dataSize;
|
||||
|
||||
/* Prepare transfer. */
|
||||
EDMA_PrepareTransfer(&xferConfig, xfer->data, sizeof(uint8_t), (void *)UART_GetDataRegisterAddress(base),
|
||||
sizeof(uint8_t), sizeof(uint8_t), xfer->dataSize, kEDMA_MemoryToPeripheral);
|
||||
|
||||
/* Submit transfer. */
|
||||
EDMA_SubmitTransfer(handle->txEdmaHandle, &xferConfig);
|
||||
EDMA_StartTransfer(handle->txEdmaHandle);
|
||||
|
||||
/* Enable UART TX EDMA. */
|
||||
UART_EnableTxDMA(base, true);
|
||||
|
||||
status = kStatus_Success;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
status_t UART_ReceiveEDMA(UART_Type *base, uart_edma_handle_t *handle, uart_transfer_t *xfer)
|
||||
{
|
||||
assert(handle->rxEdmaHandle);
|
||||
|
||||
edma_transfer_config_t xferConfig;
|
||||
status_t status;
|
||||
|
||||
/* Return error if xfer invalid. */
|
||||
if ((0U == xfer->dataSize) || (NULL == xfer->data))
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
/* If previous RX not finished. */
|
||||
if (kUART_RxBusy == handle->rxState)
|
||||
{
|
||||
status = kStatus_UART_RxBusy;
|
||||
}
|
||||
else
|
||||
{
|
||||
handle->rxState = kUART_RxBusy;
|
||||
handle->rxDataSizeAll = xfer->dataSize;
|
||||
|
||||
/* Prepare transfer. */
|
||||
EDMA_PrepareTransfer(&xferConfig, (void *)UART_GetDataRegisterAddress(base), sizeof(uint8_t), xfer->data,
|
||||
sizeof(uint8_t), sizeof(uint8_t), xfer->dataSize, kEDMA_PeripheralToMemory);
|
||||
|
||||
/* Submit transfer. */
|
||||
EDMA_SubmitTransfer(handle->rxEdmaHandle, &xferConfig);
|
||||
EDMA_StartTransfer(handle->rxEdmaHandle);
|
||||
|
||||
/* Enable UART RX EDMA. */
|
||||
UART_EnableRxDMA(base, true);
|
||||
|
||||
status = kStatus_Success;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void UART_TransferAbortSendEDMA(UART_Type *base, uart_edma_handle_t *handle)
|
||||
{
|
||||
assert(handle->txEdmaHandle);
|
||||
|
||||
/* Disable UART TX EDMA. */
|
||||
UART_EnableTxDMA(base, false);
|
||||
|
||||
/* Stop transfer. */
|
||||
EDMA_AbortTransfer(handle->txEdmaHandle);
|
||||
|
||||
handle->txState = kUART_TxIdle;
|
||||
}
|
||||
|
||||
void UART_TransferAbortReceiveEDMA(UART_Type *base, uart_edma_handle_t *handle)
|
||||
{
|
||||
assert(handle->rxEdmaHandle);
|
||||
|
||||
/* Disable UART RX EDMA. */
|
||||
UART_EnableRxDMA(base, false);
|
||||
|
||||
/* Stop transfer. */
|
||||
EDMA_AbortTransfer(handle->rxEdmaHandle);
|
||||
|
||||
handle->rxState = kUART_RxIdle;
|
||||
}
|
||||
|
||||
status_t UART_TransferGetReceiveCountEDMA(UART_Type *base, uart_edma_handle_t *handle, uint32_t *count)
|
||||
{
|
||||
assert(handle->rxEdmaHandle);
|
||||
|
||||
if (kUART_RxIdle == handle->rxState)
|
||||
{
|
||||
return kStatus_NoTransferInProgress;
|
||||
}
|
||||
|
||||
if (!count)
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
*count = handle->rxDataSizeAll - EDMA_GetRemainingBytes(handle->rxEdmaHandle->base, handle->rxEdmaHandle->channel);
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
status_t UART_TransferGetSendCountEDMA(UART_Type *base, uart_edma_handle_t *handle, uint32_t *count)
|
||||
{
|
||||
assert(handle->txEdmaHandle);
|
||||
|
||||
if (kUART_TxIdle == handle->txState)
|
||||
{
|
||||
return kStatus_NoTransferInProgress;
|
||||
}
|
||||
|
||||
if (!count)
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
*count = handle->txDataSizeAll - EDMA_GetRemainingBytes(handle->txEdmaHandle->base, handle->txEdmaHandle->channel);
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
190
devices/MK22F51212/drivers/fsl_uart_edma.h
Normal file
190
devices/MK22F51212/drivers/fsl_uart_edma.h
Normal file
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_UART_EDMA_H_
|
||||
#define _FSL_UART_EDMA_H_
|
||||
|
||||
#include "fsl_uart.h"
|
||||
#include "fsl_dmamux.h"
|
||||
#include "fsl_edma.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup uart_edma_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/* Forward declaration of the handle typedef. */
|
||||
typedef struct _uart_edma_handle uart_edma_handle_t;
|
||||
|
||||
/*! @brief UART transfer callback function. */
|
||||
typedef void (*uart_edma_transfer_callback_t)(UART_Type *base,
|
||||
uart_edma_handle_t *handle,
|
||||
status_t status,
|
||||
void *userData);
|
||||
|
||||
/*!
|
||||
* @brief UART eDMA handle
|
||||
*/
|
||||
struct _uart_edma_handle
|
||||
{
|
||||
uart_edma_transfer_callback_t callback; /*!< Callback function. */
|
||||
void *userData; /*!< UART callback function parameter.*/
|
||||
size_t rxDataSizeAll; /*!< Size of the data to receive. */
|
||||
size_t txDataSizeAll; /*!< Size of the data to send out. */
|
||||
|
||||
edma_handle_t *txEdmaHandle; /*!< The eDMA TX channel used. */
|
||||
edma_handle_t *rxEdmaHandle; /*!< The eDMA RX channel used. */
|
||||
|
||||
volatile uint8_t txState; /*!< TX transfer state. */
|
||||
volatile uint8_t rxState; /*!< RX transfer state */
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @name eDMA transactional
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes the UART handle which is used in transactional functions.
|
||||
* @param base UART peripheral base address.
|
||||
* @param handle Pointer to uart_edma_handle_t structure.
|
||||
* @param callback UART callback, NULL means no callback.
|
||||
* @param userData User callback function data.
|
||||
* @param rxEdmaHandle User requested DMA handle for RX DMA transfer.
|
||||
* @param txEdmaHandle User requested DMA handle for TX DMA transfer.
|
||||
*/
|
||||
void UART_TransferCreateHandleEDMA(UART_Type *base,
|
||||
uart_edma_handle_t *handle,
|
||||
uart_edma_transfer_callback_t callback,
|
||||
void *userData,
|
||||
edma_handle_t *txEdmaHandle,
|
||||
edma_handle_t *rxEdmaHandle);
|
||||
|
||||
/*!
|
||||
* @brief Sends data using eDMA.
|
||||
*
|
||||
* This function sends data using eDMA. This is a non-blocking function, which returns
|
||||
* right away. When all data is sent, the send callback function is called.
|
||||
*
|
||||
* @param base UART peripheral base address.
|
||||
* @param handle UART handle pointer.
|
||||
* @param xfer UART eDMA transfer structure. See #uart_transfer_t.
|
||||
* @retval kStatus_Success if succeed, others failed.
|
||||
* @retval kStatus_UART_TxBusy Previous transfer on going.
|
||||
* @retval kStatus_InvalidArgument Invalid argument.
|
||||
*/
|
||||
status_t UART_SendEDMA(UART_Type *base, uart_edma_handle_t *handle, uart_transfer_t *xfer);
|
||||
|
||||
/*!
|
||||
* @brief Receive data using eDMA.
|
||||
*
|
||||
* This function receives data using eDMA. This is a non-blocking function, which returns
|
||||
* right away. When all data is received, the receive callback function is called.
|
||||
*
|
||||
* @param base UART peripheral base address.
|
||||
* @param handle Pointer to uart_edma_handle_t structure.
|
||||
* @param xfer UART eDMA transfer structure. See #uart_transfer_t.
|
||||
* @retval kStatus_Success if succeed, others failed.
|
||||
* @retval kStatus_UART_RxBusy Previous transfer on going.
|
||||
* @retval kStatus_InvalidArgument Invalid argument.
|
||||
*/
|
||||
status_t UART_ReceiveEDMA(UART_Type *base, uart_edma_handle_t *handle, uart_transfer_t *xfer);
|
||||
|
||||
/*!
|
||||
* @brief Aborts the sent data using eDMA.
|
||||
*
|
||||
* This function aborts sent data using eDMA.
|
||||
*
|
||||
* @param base UART peripheral base address.
|
||||
* @param handle Pointer to uart_edma_handle_t structure.
|
||||
*/
|
||||
void UART_TransferAbortSendEDMA(UART_Type *base, uart_edma_handle_t *handle);
|
||||
|
||||
/*!
|
||||
* @brief Aborts the receive data using eDMA.
|
||||
*
|
||||
* This function aborts receive data using eDMA.
|
||||
*
|
||||
* @param base UART peripheral base address.
|
||||
* @param handle Pointer to uart_edma_handle_t structure.
|
||||
*/
|
||||
void UART_TransferAbortReceiveEDMA(UART_Type *base, uart_edma_handle_t *handle);
|
||||
|
||||
/*!
|
||||
* @brief Get the number of bytes that have been written to UART TX register.
|
||||
*
|
||||
* This function gets the number of bytes that have been written to UART TX
|
||||
* register by DMA.
|
||||
*
|
||||
* @param base UART peripheral base address.
|
||||
* @param handle UART handle pointer.
|
||||
* @param count Send bytes count.
|
||||
* @retval kStatus_NoTransferInProgress No send in progress.
|
||||
* @retval kStatus_InvalidArgument Parameter is invalid.
|
||||
* @retval kStatus_Success Get successfully through the parameter \p count;
|
||||
*/
|
||||
status_t UART_TransferGetSendCountEDMA(UART_Type *base, uart_edma_handle_t *handle, uint32_t *count);
|
||||
|
||||
/*!
|
||||
* @brief Get the number of bytes that have been received.
|
||||
*
|
||||
* This function gets the number of bytes that have been received.
|
||||
*
|
||||
* @param base UART peripheral base address.
|
||||
* @param handle UART handle pointer.
|
||||
* @param count Receive bytes count.
|
||||
* @retval kStatus_NoTransferInProgress No receive in progress.
|
||||
* @retval kStatus_InvalidArgument Parameter is invalid.
|
||||
* @retval kStatus_Success Get successfully through the parameter \p count;
|
||||
*/
|
||||
status_t UART_TransferGetReceiveCountEDMA(UART_Type *base, uart_edma_handle_t *handle, uint32_t *count);
|
||||
|
||||
/*@}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_UART_EDMA_H_ */
|
||||
172
devices/MK22F51212/drivers/fsl_vref.c
Normal file
172
devices/MK22F51212/drivers/fsl_vref.c
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_vref.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Gets the instance from the base address
|
||||
*
|
||||
* @param base VREF peripheral base address
|
||||
*
|
||||
* @return The VREF instance
|
||||
*/
|
||||
static uint32_t VREF_GetInstance(VREF_Type *base);
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief Pointers to VREF bases for each instance. */
|
||||
static VREF_Type *const s_vrefBases[] = VREF_BASE_PTRS;
|
||||
|
||||
/*! @brief Pointers to VREF clocks for each instance. */
|
||||
static const clock_ip_name_t s_vrefClocks[] = VREF_CLOCKS;
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
static uint32_t VREF_GetInstance(VREF_Type *base)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
/* Find the instance index from base address mappings. */
|
||||
for (instance = 0; instance < FSL_FEATURE_SOC_VREF_COUNT; instance++)
|
||||
{
|
||||
if (s_vrefBases[instance] == base)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(instance < FSL_FEATURE_SOC_VREF_COUNT);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void VREF_Init(VREF_Type *base, const vref_config_t *config)
|
||||
{
|
||||
assert(config != NULL);
|
||||
|
||||
uint8_t reg = 0U;
|
||||
|
||||
/* Ungate clock for VREF */
|
||||
CLOCK_EnableClock(s_vrefClocks[VREF_GetInstance(base)]);
|
||||
|
||||
/* Configure VREF to a known state */
|
||||
#if defined(FSL_FEATURE_VREF_HAS_CHOP_OSC) && FSL_FEATURE_VREF_HAS_CHOP_OSC
|
||||
/* Set chop oscillator bit */
|
||||
base->TRM |= VREF_TRM_CHOPEN_MASK;
|
||||
#endif /* FSL_FEATURE_VREF_HAS_CHOP_OSC */
|
||||
reg = base->SC;
|
||||
/* Set buffer Mode selection and Regulator enable bit */
|
||||
reg |= VREF_SC_MODE_LV(config->bufferMode) | VREF_SC_REGEN(1U);
|
||||
#if defined(FSL_FEATURE_VREF_HAS_COMPENSATION) && FSL_FEATURE_VREF_HAS_COMPENSATION
|
||||
/* Set second order curvature compensation enable bit */
|
||||
reg |= VREF_SC_ICOMPEN(1U);
|
||||
#endif /* FSL_FEATURE_VREF_HAS_COMPENSATION */
|
||||
/* Enable VREF module */
|
||||
reg |= VREF_SC_VREFEN(1U);
|
||||
/* Update bit-field from value to Status and Control register */
|
||||
base->SC = reg;
|
||||
#if defined(FSL_FEATURE_VREF_HAS_LOW_REFERENCE) && FSL_FEATURE_VREF_HAS_LOW_REFERENCE
|
||||
reg = base->VREFL_TRM;
|
||||
/* Clear old select external voltage reference and VREFL (0.4 V) reference buffer enable bits*/
|
||||
reg &= ~(VREF_VREFL_TRM_VREFL_EN_MASK | VREF_VREFL_TRM_VREFL_SEL_MASK);
|
||||
/* Select external voltage reference and set VREFL (0.4 V) reference buffer enable */
|
||||
reg |= VREF_VREFL_TRM_VREFL_SEL(config->enableExternalVoltRef) | VREF_VREFL_TRM_VREFL_EN(config->enableLowRef);
|
||||
base->VREFL_TRM = reg;
|
||||
#endif /* FSL_FEATURE_VREF_HAS_LOW_REFERENCE */
|
||||
|
||||
/* Wait until internal voltage stable */
|
||||
while ((base->SC & VREF_SC_VREFST_MASK) == 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void VREF_Deinit(VREF_Type *base)
|
||||
{
|
||||
/* Gate clock for VREF */
|
||||
CLOCK_DisableClock(s_vrefClocks[VREF_GetInstance(base)]);
|
||||
}
|
||||
|
||||
void VREF_GetDefaultConfig(vref_config_t *config)
|
||||
{
|
||||
/* Set High power buffer mode in */
|
||||
#if defined(FSL_FEATURE_VREF_MODE_LV_TYPE) && FSL_FEATURE_VREF_MODE_LV_TYPE
|
||||
config->bufferMode = kVREF_ModeHighPowerBuffer;
|
||||
#else
|
||||
config->bufferMode = kVREF_ModeTightRegulationBuffer;
|
||||
#endif /* FSL_FEATURE_VREF_MODE_LV_TYPE */
|
||||
|
||||
#if defined(FSL_FEATURE_VREF_HAS_LOW_REFERENCE) && FSL_FEATURE_VREF_HAS_LOW_REFERENCE
|
||||
/* Select internal voltage reference */
|
||||
config->enableExternalVoltRef = false;
|
||||
/* Set VREFL (0.4 V) reference buffer disable */
|
||||
config->enableLowRef = false;
|
||||
#endif /* FSL_FEATURE_VREF_HAS_LOW_REFERENCE */
|
||||
}
|
||||
|
||||
void VREF_SetTrimVal(VREF_Type *base, uint8_t trimValue)
|
||||
{
|
||||
uint8_t reg = 0U;
|
||||
|
||||
/* Set TRIM bits value in voltage reference */
|
||||
reg = base->TRM;
|
||||
reg = ((reg & ~VREF_TRM_TRIM_MASK) | VREF_TRM_TRIM(trimValue));
|
||||
base->TRM = reg;
|
||||
/* Wait until internal voltage stable */
|
||||
while ((base->SC & VREF_SC_VREFST_MASK) == 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_VREF_HAS_LOW_REFERENCE) && FSL_FEATURE_VREF_HAS_LOW_REFERENCE
|
||||
void VREF_SetLowReferenceTrimVal(VREF_Type *base, uint8_t trimValue)
|
||||
{
|
||||
/* The values 111b and 110b are NOT valid/allowed */
|
||||
assert((trimValue != 0x7U) && (trimValue != 0x6U));
|
||||
|
||||
uint8_t reg = 0U;
|
||||
|
||||
/* Set TRIM bits value in low voltage reference */
|
||||
reg = base->VREFL_TRM;
|
||||
reg = ((reg & ~VREF_VREFL_TRM_VREFL_TRIM_MASK) | VREF_VREFL_TRM_VREFL_TRIM(trimValue));
|
||||
base->VREFL_TRM = reg;
|
||||
/* Wait until internal voltage stable */
|
||||
while ((base->SC & VREF_SC_VREFST_MASK) == 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif /* FSL_FEATURE_VREF_HAS_LOW_REFERENCE */
|
||||
228
devices/MK22F51212/drivers/fsl_vref.h
Normal file
228
devices/MK22F51212/drivers/fsl_vref.h
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FSL_VREF_H_
|
||||
#define _FSL_VREF_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup vref
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
#define FSL_VREF_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0. */
|
||||
/*@}*/
|
||||
|
||||
/* Those macros below defined to support SoC family which have VREFL (0.4V) reference */
|
||||
#if defined(FSL_FEATURE_VREF_HAS_LOW_REFERENCE) && FSL_FEATURE_VREF_HAS_LOW_REFERENCE
|
||||
#define SC VREFH_SC
|
||||
#define VREF_SC_MODE_LV VREF_VREFH_SC_MODE_LV
|
||||
#define VREF_SC_REGEN VREF_VREFH_SC_REGEN
|
||||
#define VREF_SC_VREFEN VREF_VREFH_SC_VREFEN
|
||||
#define VREF_SC_ICOMPEN VREF_VREFH_SC_ICOMPEN
|
||||
#define VREF_SC_REGEN_MASK VREF_VREFH_SC_REGEN_MASK
|
||||
#define VREF_SC_VREFST_MASK VREF_VREFH_SC_VREFST_MASK
|
||||
#define VREF_SC_VREFEN_MASK VREF_VREFH_SC_VREFEN_MASK
|
||||
#define VREF_SC_MODE_LV_MASK VREF_VREFH_SC_MODE_LV_MASK
|
||||
#define VREF_SC_ICOMPEN_MASK VREF_VREFH_SC_ICOMPEN_MASK
|
||||
#define TRM VREFH_TRM
|
||||
#define VREF_TRM_TRIM VREF_VREFH_TRM_TRIM
|
||||
#define VREF_TRM_CHOPEN_MASK VREF_VREFH_TRM_CHOPEN_MASK
|
||||
#define VREF_TRM_TRIM_MASK VREF_VREFH_TRM_TRIM_MASK
|
||||
#define VREF_TRM_CHOPEN_SHIFT VREF_VREFH_TRM_CHOPEN_SHIFT
|
||||
#define VREF_TRM_TRIM_SHIFT VREF_VREFH_TRM_TRIM_SHIFT
|
||||
#define VREF_SC_MODE_LV_SHIFT VREF_VREFH_SC_MODE_LV_SHIFT
|
||||
#define VREF_SC_REGEN_SHIFT VREF_VREFH_SC_REGEN_SHIFT
|
||||
#define VREF_SC_VREFST_SHIFT VREF_VREFH_SC_VREFST_SHIFT
|
||||
#define VREF_SC_ICOMPEN_SHIFT VREF_VREFH_SC_ICOMPEN_SHIFT
|
||||
#endif /* FSL_FEATURE_VREF_HAS_LOW_REFERENCE */
|
||||
|
||||
/*!
|
||||
* @brief VREF modes.
|
||||
*/
|
||||
typedef enum _vref_buffer_mode
|
||||
{
|
||||
kVREF_ModeBandgapOnly = 0U, /*!< Bandgap on only, for stabilization and startup */
|
||||
#if defined(FSL_FEATURE_VREF_MODE_LV_TYPE) && FSL_FEATURE_VREF_MODE_LV_TYPE
|
||||
kVREF_ModeHighPowerBuffer = 1U, /*!< High power buffer mode enabled */
|
||||
kVREF_ModeLowPowerBuffer = 2U /*!< Low power buffer mode enabled */
|
||||
#else
|
||||
kVREF_ModeTightRegulationBuffer = 2U /*!< Tight regulation buffer enabled */
|
||||
#endif /* FSL_FEATURE_VREF_MODE_LV_TYPE */
|
||||
} vref_buffer_mode_t;
|
||||
|
||||
/*!
|
||||
* @brief The description structure for the VREF module.
|
||||
*/
|
||||
typedef struct _vref_config
|
||||
{
|
||||
vref_buffer_mode_t bufferMode; /*!< Buffer mode selection */
|
||||
#if defined(FSL_FEATURE_VREF_HAS_LOW_REFERENCE) && FSL_FEATURE_VREF_HAS_LOW_REFERENCE
|
||||
bool enableLowRef; /*!< Set VREFL (0.4 V) reference buffer enable or disable */
|
||||
bool enableExternalVoltRef; /*!< Select external voltage reference or not (internal) */
|
||||
#endif /* FSL_FEATURE_VREF_HAS_LOW_REFERENCE */
|
||||
} vref_config_t;
|
||||
|
||||
/******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*!
|
||||
* @name VREF functional operation
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Enables the clock gate and configures the VREF module according to the configuration structure.
|
||||
*
|
||||
* This function must be called before calling all the other VREF driver functions,
|
||||
* read/write registers, and configurations with user-defined settings.
|
||||
* The example below shows how to set up vref_config_t parameters and
|
||||
* how to call the VREF_Init function by passing in these parameters:
|
||||
* Example:
|
||||
* @code
|
||||
* vref_config_t vrefConfig;
|
||||
* vrefConfig.bufferMode = kVREF_ModeHighPowerBuffer;
|
||||
* vrefConfig.enableExternalVoltRef = false;
|
||||
* vrefConfig.enableLowRef = false;
|
||||
* VREF_Init(VREF, &vrefConfig);
|
||||
* @endcode
|
||||
*
|
||||
* @param base VREF peripheral address.
|
||||
* @param config Pointer to the configuration structure.
|
||||
*/
|
||||
void VREF_Init(VREF_Type *base, const vref_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Stops and disables the clock for the VREF module.
|
||||
*
|
||||
* This function should be called to shut down the module.
|
||||
* Example:
|
||||
* @code
|
||||
* vref_config_t vrefUserConfig;
|
||||
* VREF_Init(VREF);
|
||||
* VREF_GetDefaultConfig(&vrefUserConfig);
|
||||
* ...
|
||||
* VREF_Deinit(VREF);
|
||||
* @endcode
|
||||
*
|
||||
* @param base VREF peripheral address.
|
||||
*/
|
||||
void VREF_Deinit(VREF_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Initializes the VREF configuration structure.
|
||||
*
|
||||
* This function initializes the VREF configuration structure to a default value.
|
||||
* Example:
|
||||
* @code
|
||||
* vrefConfig->bufferMode = kVREF_ModeHighPowerBuffer;
|
||||
* vrefConfig->enableExternalVoltRef = false;
|
||||
* vrefConfig->enableLowRef = false;
|
||||
* @endcode
|
||||
*
|
||||
* @param config Pointer to the initialization structure.
|
||||
*/
|
||||
void VREF_GetDefaultConfig(vref_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Sets a TRIM value for reference voltage.
|
||||
*
|
||||
* This function sets a TRIM value for reference voltage.
|
||||
* Note that the TRIM value maximum is 0x3F.
|
||||
*
|
||||
* @param base VREF peripheral address.
|
||||
* @param trimValue Value of the trim register to set the output reference voltage (maximum 0x3F (6-bit)).
|
||||
*/
|
||||
void VREF_SetTrimVal(VREF_Type *base, uint8_t trimValue);
|
||||
|
||||
/*!
|
||||
* @brief Reads the value of the TRIM meaning output voltage.
|
||||
*
|
||||
* This function gets the TRIM value from the TRM register.
|
||||
*
|
||||
* @param base VREF peripheral address.
|
||||
* @return Six-bit value of trim setting.
|
||||
*/
|
||||
static inline uint8_t VREF_GetTrimVal(VREF_Type *base)
|
||||
{
|
||||
return (base->TRM & VREF_TRM_TRIM_MASK);
|
||||
}
|
||||
#if defined(FSL_FEATURE_VREF_HAS_LOW_REFERENCE) && FSL_FEATURE_VREF_HAS_LOW_REFERENCE
|
||||
|
||||
/*!
|
||||
* @brief Sets the TRIM value for low voltage reference.
|
||||
*
|
||||
* This function sets the TRIM value for low reference voltage.
|
||||
* NOTE:
|
||||
* - The TRIM value maximum is 0x05U
|
||||
* - The values 111b and 110b are not valid/allowed.
|
||||
*
|
||||
* @param base VREF peripheral address.
|
||||
* @param trimValue Value of the trim register to set output low reference voltage (maximum 0x05U (3-bit)).
|
||||
*/
|
||||
void VREF_SetLowReferenceTrimVal(VREF_Type *base, uint8_t trimValue);
|
||||
|
||||
/*!
|
||||
* @brief Reads the value of the TRIM meaning output voltage.
|
||||
*
|
||||
* This function gets the TRIM value from the VREFL_TRM register.
|
||||
*
|
||||
* @param base VREF peripheral address.
|
||||
* @return Three-bit value of the trim setting.
|
||||
*/
|
||||
static inline uint8_t VREF_GetLowReferenceTrimVal(VREF_Type *base)
|
||||
{
|
||||
return (base->VREFL_TRM & VREF_VREFL_TRM_VREFL_TRIM_MASK);
|
||||
}
|
||||
#endif /* FSL_FEATURE_VREF_HAS_LOW_REFERENCE */
|
||||
|
||||
/*@}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_VREF_H_ */
|
||||
153
devices/MK22F51212/drivers/fsl_wdog.c
Normal file
153
devices/MK22F51212/drivers/fsl_wdog.c
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_wdog.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
void WDOG_GetDefaultConfig(wdog_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
config->enableWdog = true;
|
||||
config->clockSource = kWDOG_LpoClockSource;
|
||||
config->prescaler = kWDOG_ClockPrescalerDivide1;
|
||||
#if defined(FSL_FEATURE_WDOG_HAS_WAITEN) && FSL_FEATURE_WDOG_HAS_WAITEN
|
||||
config->workMode.enableWait = true;
|
||||
#endif /* FSL_FEATURE_WDOG_HAS_WAITEN */
|
||||
config->workMode.enableStop = false;
|
||||
config->workMode.enableDebug = false;
|
||||
config->enableUpdate = true;
|
||||
config->enableInterrupt = false;
|
||||
config->enableWindowMode = false;
|
||||
config->windowValue = 0U;
|
||||
config->timeoutValue = 0xFFFFU;
|
||||
}
|
||||
|
||||
void WDOG_Init(WDOG_Type *base, const wdog_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
uint32_t value = 0U;
|
||||
uint32_t primaskValue = 0U;
|
||||
|
||||
value = WDOG_STCTRLH_WDOGEN(config->enableWdog) | WDOG_STCTRLH_CLKSRC(config->clockSource) |
|
||||
WDOG_STCTRLH_IRQRSTEN(config->enableInterrupt) | WDOG_STCTRLH_WINEN(config->enableWindowMode) |
|
||||
WDOG_STCTRLH_ALLOWUPDATE(config->enableUpdate) | WDOG_STCTRLH_DBGEN(config->workMode.enableDebug) |
|
||||
WDOG_STCTRLH_STOPEN(config->workMode.enableStop) |
|
||||
#if defined(FSL_FEATURE_WDOG_HAS_WAITEN) && FSL_FEATURE_WDOG_HAS_WAITEN
|
||||
WDOG_STCTRLH_WAITEN(config->workMode.enableWait) |
|
||||
#endif /* FSL_FEATURE_WDOG_HAS_WAITEN */
|
||||
WDOG_STCTRLH_DISTESTWDOG(1U);
|
||||
|
||||
/* Disable the global interrupts. Otherwise, an interrupt could effectively invalidate the unlock sequence
|
||||
* and the WCT may expire. After the configuration finishes, re-enable the global interrupts. */
|
||||
primaskValue = DisableGlobalIRQ();
|
||||
WDOG_Unlock(base);
|
||||
/* Wait one bus clock cycle */
|
||||
base->RSTCNT = 0U;
|
||||
/* Set configruation */
|
||||
base->PRESC = WDOG_PRESC_PRESCVAL(config->prescaler);
|
||||
base->WINH = (uint16_t)((config->windowValue >> 16U) & 0xFFFFU);
|
||||
base->WINL = (uint16_t)((config->windowValue) & 0xFFFFU);
|
||||
base->TOVALH = (uint16_t)((config->timeoutValue >> 16U) & 0xFFFFU);
|
||||
base->TOVALL = (uint16_t)((config->timeoutValue) & 0xFFFFU);
|
||||
base->STCTRLH = value;
|
||||
EnableGlobalIRQ(primaskValue);
|
||||
}
|
||||
|
||||
void WDOG_Deinit(WDOG_Type *base)
|
||||
{
|
||||
uint32_t primaskValue = 0U;
|
||||
|
||||
/* Disable the global interrupts */
|
||||
primaskValue = DisableGlobalIRQ();
|
||||
WDOG_Unlock(base);
|
||||
/* Wait one bus clock cycle */
|
||||
base->RSTCNT = 0U;
|
||||
WDOG_Disable(base);
|
||||
EnableGlobalIRQ(primaskValue);
|
||||
WDOG_ClearResetCount(base);
|
||||
}
|
||||
|
||||
void WDOG_SetTestModeConfig(WDOG_Type *base, wdog_test_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
uint32_t value = 0U;
|
||||
uint32_t primaskValue = 0U;
|
||||
|
||||
value = WDOG_STCTRLH_DISTESTWDOG(0U) | WDOG_STCTRLH_TESTWDOG(1U) | WDOG_STCTRLH_TESTSEL(config->testMode) |
|
||||
WDOG_STCTRLH_BYTESEL(config->testedByte) | WDOG_STCTRLH_IRQRSTEN(0U) | WDOG_STCTRLH_WDOGEN(1U) |
|
||||
WDOG_STCTRLH_ALLOWUPDATE(1U);
|
||||
|
||||
/* Disable the global interrupts. Otherwise, an interrupt could effectively invalidate the unlock sequence
|
||||
* and the WCT may expire. After the configuration finishes, re-enable the global interrupts. */
|
||||
primaskValue = DisableGlobalIRQ();
|
||||
WDOG_Unlock(base);
|
||||
/* Wait one bus clock cycle */
|
||||
base->RSTCNT = 0U;
|
||||
/* Set configruation */
|
||||
base->TOVALH = (uint16_t)((config->timeoutValue >> 16U) & 0xFFFFU);
|
||||
base->TOVALL = (uint16_t)((config->timeoutValue) & 0xFFFFU);
|
||||
base->STCTRLH = value;
|
||||
EnableGlobalIRQ(primaskValue);
|
||||
}
|
||||
|
||||
uint32_t WDOG_GetStatusFlags(WDOG_Type *base)
|
||||
{
|
||||
uint32_t status_flag = 0U;
|
||||
|
||||
status_flag |= (base->STCTRLH & WDOG_STCTRLH_WDOGEN_MASK);
|
||||
status_flag |= (base->STCTRLL & WDOG_STCTRLL_INTFLG_MASK);
|
||||
|
||||
return status_flag;
|
||||
}
|
||||
|
||||
void WDOG_ClearStatusFlags(WDOG_Type *base, uint32_t mask)
|
||||
{
|
||||
if (mask & kWDOG_TimeoutFlag)
|
||||
{
|
||||
base->STCTRLL |= WDOG_STCTRLL_INTFLG_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
void WDOG_Refresh(WDOG_Type *base)
|
||||
{
|
||||
uint32_t primaskValue = 0U;
|
||||
|
||||
/* Disable the global interrupt to protect refresh sequence */
|
||||
primaskValue = DisableGlobalIRQ();
|
||||
base->REFRESH = WDOG_FIRST_WORD_OF_REFRESH;
|
||||
base->REFRESH = WDOG_SECOND_WORD_OF_REFRESH;
|
||||
EnableGlobalIRQ(primaskValue);
|
||||
}
|
||||
434
devices/MK22F51212/drivers/fsl_wdog.h
Normal file
434
devices/MK22F51212/drivers/fsl_wdog.h
Normal file
@@ -0,0 +1,434 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _FSL_WDOG_H_
|
||||
#define _FSL_WDOG_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup wdog_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
*******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief Defines WDOG driver version 2.0.0. */
|
||||
#define FSL_WDOG_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
|
||||
/*@}*/
|
||||
|
||||
/*! @name Unlock sequence */
|
||||
/*@{*/
|
||||
#define WDOG_FIRST_WORD_OF_UNLOCK (0xC520U) /*!< First word of unlock sequence */
|
||||
#define WDOG_SECOND_WORD_OF_UNLOCK (0xD928U) /*!< Second word of unlock sequence */
|
||||
/*@}*/
|
||||
|
||||
/*! @name Refresh sequence */
|
||||
/*@{*/
|
||||
#define WDOG_FIRST_WORD_OF_REFRESH (0xA602U) /*!< First word of refresh sequence */
|
||||
#define WDOG_SECOND_WORD_OF_REFRESH (0xB480U) /*!< Second word of refresh sequence */
|
||||
/*@}*/
|
||||
|
||||
/*! @brief Describes WDOG clock source. */
|
||||
typedef enum _wdog_clock_source
|
||||
{
|
||||
kWDOG_LpoClockSource = 0U, /*!< WDOG clock sourced from LPO*/
|
||||
kWDOG_AlternateClockSource = 1U, /*!< WDOG clock sourced from alternate clock source*/
|
||||
} wdog_clock_source_t;
|
||||
|
||||
/*! @brief Defines WDOG work mode. */
|
||||
typedef struct _wdog_work_mode
|
||||
{
|
||||
#if defined(FSL_FEATURE_WDOG_HAS_WAITEN) && FSL_FEATURE_WDOG_HAS_WAITEN
|
||||
bool enableWait; /*!< Enables or disables WDOG in wait mode */
|
||||
#endif /* FSL_FEATURE_WDOG_HAS_WAITEN */
|
||||
bool enableStop; /*!< Enables or disables WDOG in stop mode */
|
||||
bool enableDebug; /*!< Enables or disables WDOG in debug mode */
|
||||
} wdog_work_mode_t;
|
||||
|
||||
/*! @brief Describes the selection of the clock prescaler. */
|
||||
typedef enum _wdog_clock_prescaler
|
||||
{
|
||||
kWDOG_ClockPrescalerDivide1 = 0x0U, /*!< Divided by 1 */
|
||||
kWDOG_ClockPrescalerDivide2 = 0x1U, /*!< Divided by 2 */
|
||||
kWDOG_ClockPrescalerDivide3 = 0x2U, /*!< Divided by 3 */
|
||||
kWDOG_ClockPrescalerDivide4 = 0x3U, /*!< Divided by 4 */
|
||||
kWDOG_ClockPrescalerDivide5 = 0x4U, /*!< Divided by 5 */
|
||||
kWDOG_ClockPrescalerDivide6 = 0x5U, /*!< Divided by 6 */
|
||||
kWDOG_ClockPrescalerDivide7 = 0x6U, /*!< Divided by 7 */
|
||||
kWDOG_ClockPrescalerDivide8 = 0x7U, /*!< Divided by 8 */
|
||||
} wdog_clock_prescaler_t;
|
||||
|
||||
/*! @brief Describes WDOG configuration structure. */
|
||||
typedef struct _wdog_config
|
||||
{
|
||||
bool enableWdog; /*!< Enables or disables WDOG */
|
||||
wdog_clock_source_t clockSource; /*!< Clock source select */
|
||||
wdog_clock_prescaler_t prescaler; /*!< Clock prescaler value */
|
||||
wdog_work_mode_t workMode; /*!< Configures WDOG work mode in debug stop and wait mode */
|
||||
bool enableUpdate; /*!< Update write-once register enable */
|
||||
bool enableInterrupt; /*!< Enables or disables WDOG interrupt */
|
||||
bool enableWindowMode; /*!< Enables or disables WDOG window mode */
|
||||
uint32_t windowValue; /*!< Window value */
|
||||
uint32_t timeoutValue; /*!< Timeout value */
|
||||
} wdog_config_t;
|
||||
|
||||
/*! @brief Describes WDOG test mode. */
|
||||
typedef enum _wdog_test_mode
|
||||
{
|
||||
kWDOG_QuickTest = 0U, /*!< Selects quick test */
|
||||
kWDOG_ByteTest = 1U, /*!< Selects byte test */
|
||||
} wdog_test_mode_t;
|
||||
|
||||
/*! @brief Describes WDOG tested byte selection in byte test mode. */
|
||||
typedef enum _wdog_tested_byte
|
||||
{
|
||||
kWDOG_TestByte0 = 0U, /*!< Byte 0 selected in byte test mode */
|
||||
kWDOG_TestByte1 = 1U, /*!< Byte 1 selected in byte test mode */
|
||||
kWDOG_TestByte2 = 2U, /*!< Byte 2 selected in byte test mode */
|
||||
kWDOG_TestByte3 = 3U, /*!< Byte 3 selected in byte test mode */
|
||||
} wdog_tested_byte_t;
|
||||
|
||||
/*! @brief Describes WDOG test mode configuration structure. */
|
||||
typedef struct _wdog_test_config
|
||||
{
|
||||
wdog_test_mode_t testMode; /*!< Selects test mode */
|
||||
wdog_tested_byte_t testedByte; /*!< Selects tested byte in byte test mode */
|
||||
uint32_t timeoutValue; /*!< Timeout value */
|
||||
} wdog_test_config_t;
|
||||
|
||||
/*!
|
||||
* @brief WDOG interrupt configuration structure, default settings all disabled.
|
||||
*
|
||||
* This structure contains the settings for all of the WDOG interrupt configurations.
|
||||
*/
|
||||
enum _wdog_interrupt_enable_t
|
||||
{
|
||||
kWDOG_InterruptEnable = WDOG_STCTRLH_IRQRSTEN_MASK, /*!< WDOG timeout will generate interrupt before reset*/
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief WDOG status flags.
|
||||
*
|
||||
* This structure contains the WDOG status flags for use in the WDOG functions.
|
||||
*/
|
||||
enum _wdog_status_flags_t
|
||||
{
|
||||
kWDOG_RunningFlag = WDOG_STCTRLH_WDOGEN_MASK, /*!< Running flag, set when WDOG is enabled*/
|
||||
kWDOG_TimeoutFlag = WDOG_STCTRLL_INTFLG_MASK, /*!< Interrupt flag, set when an exception occurs*/
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
*******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*!
|
||||
* @name WDOG Initialization and De-initialization
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes WDOG configure sturcture.
|
||||
*
|
||||
* This function initializes the WDOG configure structure to default value. The default
|
||||
* value are:
|
||||
* @code
|
||||
* wdogConfig->enableWdog = true;
|
||||
* wdogConfig->clockSource = kWDOG_LpoClockSource;
|
||||
* wdogConfig->prescaler = kWDOG_ClockPrescalerDivide1;
|
||||
* wdogConfig->workMode.enableWait = true;
|
||||
* wdogConfig->workMode.enableStop = false;
|
||||
* wdogConfig->workMode.enableDebug = false;
|
||||
* wdogConfig->enableUpdate = true;
|
||||
* wdogConfig->enableInterrupt = false;
|
||||
* wdogConfig->enableWindowMode = false;
|
||||
* wdogConfig->windowValue = 0;
|
||||
* wdogConfig->timeoutValue = 0xFFFFU;
|
||||
* @endcode
|
||||
*
|
||||
* @param config Pointer to WDOG config structure.
|
||||
* @see wdog_config_t
|
||||
*/
|
||||
void WDOG_GetDefaultConfig(wdog_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Initializes the WDOG.
|
||||
*
|
||||
* This function initializes the WDOG. When called, the WDOG runs according to the configuration.
|
||||
* If user wants to reconfigure WDOG without forcing a reset first, enableUpdate must be set to true
|
||||
* in configuration.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* wdog_config_t config;
|
||||
* WDOG_GetDefaultConfig(&config);
|
||||
* config.timeoutValue = 0x7ffU;
|
||||
* config.enableUpdate = true;
|
||||
* WDOG_Init(wdog_base,&config);
|
||||
* @endcode
|
||||
*
|
||||
* @param base WDOG peripheral base address
|
||||
* @param config The configuration of WDOG
|
||||
*/
|
||||
void WDOG_Init(WDOG_Type *base, const wdog_config_t *config);
|
||||
|
||||
/*!
|
||||
* @brief Shuts down the WDOG.
|
||||
*
|
||||
* This function shuts down the WDOG.
|
||||
* Make sure that the WDOG_STCTRLH.ALLOWUPDATE is 1 which means that the register update is enabled.
|
||||
*/
|
||||
void WDOG_Deinit(WDOG_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Configures WDOG functional test.
|
||||
*
|
||||
* This function is used to configure the WDOG functional test. When called, the WDOG goes into test mode
|
||||
* and runs according to the configuration.
|
||||
* Make sure that the WDOG_STCTRLH.ALLOWUPDATE is 1 which means that the register update is enabled.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* wdog_test_config_t test_config;
|
||||
* test_config.testMode = kWDOG_QuickTest;
|
||||
* test_config.timeoutValue = 0xfffffu;
|
||||
* WDOG_SetTestModeConfig(wdog_base, &test_config);
|
||||
* @endcode
|
||||
* @param base WDOG peripheral base address
|
||||
* @param config The functional test configuration of WDOG
|
||||
*/
|
||||
void WDOG_SetTestModeConfig(WDOG_Type *base, wdog_test_config_t *config);
|
||||
|
||||
/* @} */
|
||||
|
||||
/*!
|
||||
* @name WDOG Functional Operation
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Enables the WDOG module.
|
||||
*
|
||||
* This function write value into WDOG_STCTRLH register to enable the WDOG, it is a write-once register,
|
||||
* make sure that the WCT window is still open and this register has not been written in this WCT
|
||||
* while this function is called.
|
||||
*
|
||||
* @param base WDOG peripheral base address
|
||||
*/
|
||||
static inline void WDOG_Enable(WDOG_Type *base)
|
||||
{
|
||||
base->STCTRLH |= WDOG_STCTRLH_WDOGEN_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disables the WDOG module.
|
||||
*
|
||||
* This function write value into WDOG_STCTRLH register to disable the WDOG, it is a write-once register,
|
||||
* make sure that the WCT window is still open and this register has not been written in this WCT
|
||||
* while this function is called.
|
||||
*
|
||||
* @param base WDOG peripheral base address
|
||||
*/
|
||||
static inline void WDOG_Disable(WDOG_Type *base)
|
||||
{
|
||||
base->STCTRLH &= ~WDOG_STCTRLH_WDOGEN_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Enable WDOG interrupt.
|
||||
*
|
||||
* This function write value into WDOG_STCTRLH register to enable WDOG interrupt, it is a write-once register,
|
||||
* make sure that the WCT window is still open and this register has not been written in this WCT
|
||||
* while this function is called.
|
||||
*
|
||||
* @param base WDOG peripheral base address
|
||||
* @param mask The interrupts to enable
|
||||
* The parameter can be combination of the following source if defined:
|
||||
* @arg kWDOG_InterruptEnable
|
||||
*/
|
||||
static inline void WDOG_EnableInterrupts(WDOG_Type *base, uint32_t mask)
|
||||
{
|
||||
base->STCTRLH |= mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disable WDOG interrupt.
|
||||
*
|
||||
* This function write value into WDOG_STCTRLH register to disable WDOG interrupt, it is a write-once register,
|
||||
* make sure that the WCT window is still open and this register has not been written in this WCT
|
||||
* while this function is called.
|
||||
*
|
||||
* @param base WDOG peripheral base address
|
||||
* @param mask The interrupts to disable
|
||||
* The parameter can be combination of the following source if defined:
|
||||
* @arg kWDOG_InterruptEnable
|
||||
*/
|
||||
static inline void WDOG_DisableInterrupts(WDOG_Type *base, uint32_t mask)
|
||||
{
|
||||
base->STCTRLH &= ~mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets WDOG all status flags.
|
||||
*
|
||||
* This function gets all status flags.
|
||||
*
|
||||
* Example for getting Running Flag:
|
||||
* @code
|
||||
* uint32_t status;
|
||||
* status = WDOG_GetStatusFlags(wdog_base) & kWDOG_RunningFlag;
|
||||
* @endcode
|
||||
* @param base WDOG peripheral base address
|
||||
* @return State of the status flag: asserted (true) or not-asserted (false).@see _wdog_status_flags_t
|
||||
* - true: related status flag has been set.
|
||||
* - false: related status flag is not set.
|
||||
*/
|
||||
uint32_t WDOG_GetStatusFlags(WDOG_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Clear WDOG flag.
|
||||
*
|
||||
* This function clears WDOG status flag.
|
||||
*
|
||||
* Example for clearing timeout(interrupt) flag:
|
||||
* @code
|
||||
* WDOG_ClearStatusFlags(wdog_base,kWDOG_TimeoutFlag);
|
||||
* @endcode
|
||||
* @param base WDOG peripheral base address
|
||||
* @param mask The status flags to clear.
|
||||
* The parameter could be any combination of the following values:
|
||||
* kWDOG_TimeoutFlag
|
||||
*/
|
||||
void WDOG_ClearStatusFlags(WDOG_Type *base, uint32_t mask);
|
||||
|
||||
/*!
|
||||
* @brief Set the WDOG timeout value.
|
||||
*
|
||||
* This function sets the timeout value.
|
||||
* It should be ensured that the time-out value for the WDOG is always greater than
|
||||
* 2xWCT time + 20 bus clock cycles.
|
||||
* This function write value into WDOG_TOVALH and WDOG_TOVALL registers which are wirte-once.
|
||||
* Make sure the WCT window is still open and these two registers have not been written in this WCT
|
||||
* while this function is called.
|
||||
*
|
||||
* @param base WDOG peripheral base address
|
||||
* @param timeoutCount WDOG timeout value, count of WDOG clock tick.
|
||||
*/
|
||||
static inline void WDOG_SetTimeoutValue(WDOG_Type *base, uint32_t timeoutCount)
|
||||
{
|
||||
base->TOVALH = (uint16_t)((timeoutCount >> 16U) & 0xFFFFU);
|
||||
base->TOVALL = (uint16_t)((timeoutCount)&0xFFFFU);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets the WDOG window value.
|
||||
*
|
||||
* This function sets the WDOG window value.
|
||||
* This function write value into WDOG_WINH and WDOG_WINL registers which are wirte-once.
|
||||
* Make sure the WCT window is still open and these two registers have not been written in this WCT
|
||||
* while this function is called.
|
||||
*
|
||||
* @param base WDOG peripheral base address
|
||||
* @param windowValue WDOG window value.
|
||||
*/
|
||||
static inline void WDOG_SetWindowValue(WDOG_Type *base, uint32_t windowValue)
|
||||
{
|
||||
base->WINH = (uint16_t)((windowValue >> 16U) & 0xFFFFU);
|
||||
base->WINL = (uint16_t)((windowValue)&0xFFFFU);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Unlocks the WDOG register written.
|
||||
*
|
||||
* This function unlocks the WDOG register written.
|
||||
* Before starting the unlock sequence and following congfiguration, disable the global interrupts.
|
||||
* Otherwise, an interrupt could effectively invalidate the unlock sequence and the WCT may expire,
|
||||
* After the configuration finishes, re-enable the global interrupts.
|
||||
*
|
||||
* @param base WDOG peripheral base address
|
||||
*/
|
||||
static inline void WDOG_Unlock(WDOG_Type *base)
|
||||
{
|
||||
base->UNLOCK = WDOG_FIRST_WORD_OF_UNLOCK;
|
||||
base->UNLOCK = WDOG_SECOND_WORD_OF_UNLOCK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Refreshes the WDOG timer.
|
||||
*
|
||||
* This function feeds the WDOG.
|
||||
* This function should be called before WDOG timer is in timeout. Otherwise, a reset is asserted.
|
||||
*
|
||||
* @param base WDOG peripheral base address
|
||||
*/
|
||||
void WDOG_Refresh(WDOG_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Gets the WDOG reset count.
|
||||
*
|
||||
* This function gets the WDOG reset count value.
|
||||
*
|
||||
* @param base WDOG peripheral base address
|
||||
* @return WDOG reset count value
|
||||
*/
|
||||
static inline uint16_t WDOG_GetResetCount(WDOG_Type *base)
|
||||
{
|
||||
return base->RSTCNT;
|
||||
}
|
||||
/*!
|
||||
* @brief Clears the WDOG reset count.
|
||||
*
|
||||
* This function clears the WDOG reset count value.
|
||||
*
|
||||
* @param base WDOG peripheral base address
|
||||
*/
|
||||
static inline void WDOG_ClearResetCount(WDOG_Type *base)
|
||||
{
|
||||
base->RSTCNT |= UINT16_MAX;
|
||||
}
|
||||
|
||||
/*@}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_WDOG_H_ */
|
||||
57
devices/MK22F51212/fsl_device_registers.h
Normal file
57
devices/MK22F51212/fsl_device_registers.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 2016, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __FSL_DEVICE_REGISTERS_H__
|
||||
#define __FSL_DEVICE_REGISTERS_H__
|
||||
|
||||
/*
|
||||
* Include the cpu specific register header files.
|
||||
*
|
||||
* The CPU macro should be declared in the project or makefile.
|
||||
*/
|
||||
#if (defined(CPU_MK22FN512CAP12) || defined(CPU_MK22FN512VDC12) || defined(CPU_MK22FN512VFX12) || \
|
||||
defined(CPU_MK22FN512VLH12) || defined(CPU_MK22FN512VLL12) || defined(CPU_MK22FN512VMP12))
|
||||
|
||||
#define K22F51212_SERIES
|
||||
|
||||
/* CMSIS-style register definitions */
|
||||
#include "MK22F51212.h"
|
||||
/* CPU specific feature definitions */
|
||||
#include "MK22F51212_features.h"
|
||||
|
||||
#else
|
||||
#error "No valid CPU defined!"
|
||||
#endif
|
||||
|
||||
#endif /* __FSL_DEVICE_REGISTERS_H__ */
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF
|
||||
******************************************************************************/
|
||||
263
devices/MK22F51212/gcc/MK22FN512xxx12_flash.ld
Normal file
263
devices/MK22F51212/gcc/MK22FN512xxx12_flash.ld
Normal file
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
** ###################################################################
|
||||
** Processors: MK22FN512CAP12
|
||||
** MK22FN512VDC12
|
||||
** MK22FN512VFX12
|
||||
** MK22FN512VLH12
|
||||
** MK22FN512VLL12
|
||||
** MK22FN512VMP12
|
||||
**
|
||||
** Compiler: GNU C Compiler
|
||||
** Reference manual: K22P121M120SF7RM, Rev. 1, March 24, 2014
|
||||
** Version: rev. 2.9, 2016-03-21
|
||||
** Build: b160321
|
||||
**
|
||||
** Abstract:
|
||||
** Linker file for the GNU C Compiler
|
||||
**
|
||||
** Copyright (c) 2016 Freescale Semiconductor, Inc.
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without modification,
|
||||
** are permitted provided that the following conditions are met:
|
||||
**
|
||||
** o Redistributions of source code must retain the above copyright notice, this list
|
||||
** of conditions and the following disclaimer.
|
||||
**
|
||||
** o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
** list of conditions and the following disclaimer in the documentation and/or
|
||||
** other materials provided with the distribution.
|
||||
**
|
||||
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
** contributors may be used to endorse or promote products derived from this
|
||||
** software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**
|
||||
** http: www.freescale.com
|
||||
** mail: support@freescale.com
|
||||
**
|
||||
** ###################################################################
|
||||
*/
|
||||
|
||||
/* Entry Point */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x0400;
|
||||
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400;
|
||||
M_VECTOR_RAM_SIZE = DEFINED(__ram_vector_table__) ? 0x0400 : 0x0;
|
||||
|
||||
/* Specify the memory areas */
|
||||
MEMORY
|
||||
{
|
||||
m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000400
|
||||
m_flash_config (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010
|
||||
m_text (RX) : ORIGIN = 0x00000410, LENGTH = 0x0007FBF0
|
||||
m_data (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x00010000
|
||||
m_data_2 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00010000
|
||||
}
|
||||
|
||||
/* Define output sections */
|
||||
SECTIONS
|
||||
{
|
||||
/* The startup code goes first into internal flash */
|
||||
.interrupts :
|
||||
{
|
||||
__VECTOR_TABLE = .;
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
. = ALIGN(4);
|
||||
} > m_interrupts
|
||||
|
||||
.flash_config :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.FlashConfig)) /* Flash Configuration Field (FCF) */
|
||||
. = ALIGN(4);
|
||||
} > m_flash_config
|
||||
|
||||
/* The program code and other data goes into internal flash */
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.text) /* .text sections (code) */
|
||||
*(.text*) /* .text* sections (code) */
|
||||
*(.rodata) /* .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
|
||||
*(.glue_7) /* glue arm to thumb code */
|
||||
*(.glue_7t) /* glue thumb to arm code */
|
||||
*(.eh_frame)
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
. = ALIGN(4);
|
||||
} > m_text
|
||||
|
||||
.ARM.extab :
|
||||
{
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
} > m_text
|
||||
|
||||
.ARM :
|
||||
{
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
} > m_text
|
||||
|
||||
.ctors :
|
||||
{
|
||||
__CTOR_LIST__ = .;
|
||||
/* gcc uses crtbegin.o to find the start of
|
||||
the constructors, so we make sure it is
|
||||
first. Because this is a wildcard, it
|
||||
doesn't matter if the user does not
|
||||
actually link against crtbegin.o; the
|
||||
linker won't look for a file to match a
|
||||
wildcard. The wildcard also means that it
|
||||
doesn't matter which directory crtbegin.o
|
||||
is in. */
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*crtbegin?.o(.ctors))
|
||||
/* We don't want to include the .ctor section from
|
||||
from the crtend.o file until after the sorted ctors.
|
||||
The .ctor section from the crtend file contains the
|
||||
end of ctors marker and it must be last */
|
||||
KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
__CTOR_END__ = .;
|
||||
} > m_text
|
||||
|
||||
.dtors :
|
||||
{
|
||||
__DTOR_LIST__ = .;
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*crtbegin?.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
__DTOR_END__ = .;
|
||||
} > m_text
|
||||
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array*))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
} > m_text
|
||||
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array*))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
} > m_text
|
||||
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
KEEP (*(.fini_array*))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
} > m_text
|
||||
|
||||
__etext = .; /* define a global symbol at end of code */
|
||||
__DATA_ROM = .; /* Symbol is used by startup for data initialization */
|
||||
|
||||
.interrupts_ram :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
__VECTOR_RAM__ = .;
|
||||
__interrupts_ram_start__ = .; /* Create a global symbol at data start */
|
||||
*(.m_interrupts_ram) /* This is a user defined section */
|
||||
. += M_VECTOR_RAM_SIZE;
|
||||
. = ALIGN(4);
|
||||
__interrupts_ram_end__ = .; /* Define a global symbol at data end */
|
||||
} > m_data
|
||||
|
||||
__VECTOR_RAM = DEFINED(__ram_vector_table__) ? __VECTOR_RAM__ : ORIGIN(m_interrupts);
|
||||
__RAM_VECTOR_TABLE_SIZE_BYTES = DEFINED(__ram_vector_table__) ? (__interrupts_ram_end__ - __interrupts_ram_start__) : 0x0;
|
||||
|
||||
.data : AT(__DATA_ROM)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
__DATA_RAM = .;
|
||||
__data_start__ = .; /* create a global symbol at data start */
|
||||
*(.data) /* .data sections */
|
||||
*(.data*) /* .data* sections */
|
||||
KEEP(*(.jcr*))
|
||||
. = ALIGN(4);
|
||||
__data_end__ = .; /* define a global symbol at data end */
|
||||
} > m_data
|
||||
|
||||
__DATA_END = __DATA_ROM + (__data_end__ - __data_start__);
|
||||
text_end = ORIGIN(m_text) + LENGTH(m_text);
|
||||
ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data")
|
||||
|
||||
USB_RAM_GAP = DEFINED(__usb_ram_size__) ? __usb_ram_size__ : 0x800;
|
||||
/* Uninitialized data section */
|
||||
.bss :
|
||||
{
|
||||
/* This is used by the startup in order to initialize the .bss section */
|
||||
. = ALIGN(4);
|
||||
__START_BSS = .;
|
||||
__bss_start__ = .;
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
. = ALIGN(512);
|
||||
USB_RAM_START = .;
|
||||
. += USB_RAM_GAP;
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
__bss_end__ = .;
|
||||
__END_BSS = .;
|
||||
} > m_data
|
||||
|
||||
.heap :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
__end__ = .;
|
||||
PROVIDE(end = .);
|
||||
__HeapBase = .;
|
||||
. += HEAP_SIZE;
|
||||
__HeapLimit = .;
|
||||
__heap_limit = .; /* Add for _sbrk */
|
||||
} > m_data_2
|
||||
|
||||
.stack :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
. += STACK_SIZE;
|
||||
} > m_data_2
|
||||
|
||||
m_usb_bdt USB_RAM_START (NOLOAD) :
|
||||
{
|
||||
*(m_usb_bdt)
|
||||
USB_RAM_BDT_END = .;
|
||||
}
|
||||
|
||||
m_usb_global USB_RAM_BDT_END (NOLOAD) :
|
||||
{
|
||||
*(m_usb_global)
|
||||
}
|
||||
|
||||
/* Initializes stack on the end of block */
|
||||
__StackTop = ORIGIN(m_data_2) + LENGTH(m_data_2);
|
||||
__StackLimit = __StackTop - STACK_SIZE;
|
||||
PROVIDE(__stack = __StackTop);
|
||||
|
||||
.ARM.attributes 0 : { *(.ARM.attributes) }
|
||||
|
||||
ASSERT(__StackLimit >= __HeapLimit, "region m_data_2 overflowed with stack and heap")
|
||||
}
|
||||
|
||||
242
devices/MK22F51212/gcc/MK22FN512xxx12_ram.ld
Normal file
242
devices/MK22F51212/gcc/MK22FN512xxx12_ram.ld
Normal file
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
** ###################################################################
|
||||
** Processors: MK22FN512CAP12
|
||||
** MK22FN512VDC12
|
||||
** MK22FN512VFX12
|
||||
** MK22FN512VLH12
|
||||
** MK22FN512VLL12
|
||||
** MK22FN512VMP12
|
||||
**
|
||||
** Compiler: GNU C Compiler
|
||||
** Reference manual: K22P121M120SF7RM, Rev. 1, March 24, 2014
|
||||
** Version: rev. 2.9, 2016-03-21
|
||||
** Build: b160321
|
||||
**
|
||||
** Abstract:
|
||||
** Linker file for the GNU C Compiler
|
||||
**
|
||||
** Copyright (c) 2016 Freescale Semiconductor, Inc.
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without modification,
|
||||
** are permitted provided that the following conditions are met:
|
||||
**
|
||||
** o Redistributions of source code must retain the above copyright notice, this list
|
||||
** of conditions and the following disclaimer.
|
||||
**
|
||||
** o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
** list of conditions and the following disclaimer in the documentation and/or
|
||||
** other materials provided with the distribution.
|
||||
**
|
||||
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
** contributors may be used to endorse or promote products derived from this
|
||||
** software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**
|
||||
** http: www.freescale.com
|
||||
** mail: support@freescale.com
|
||||
**
|
||||
** ###################################################################
|
||||
*/
|
||||
|
||||
/* Entry Point */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x0400;
|
||||
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400;
|
||||
|
||||
/* Specify the memory areas */
|
||||
MEMORY
|
||||
{
|
||||
m_interrupts (RX) : ORIGIN = 0x1FFF0000, LENGTH = 0x00000400
|
||||
m_text (RX) : ORIGIN = 0x1FFF0400, LENGTH = 0x0000FC00
|
||||
m_data (RW) : ORIGIN = 0x20000000, LENGTH = 0x00010000
|
||||
}
|
||||
|
||||
/* Define output sections */
|
||||
SECTIONS
|
||||
{
|
||||
/* The startup code goes first into internal RAM */
|
||||
.interrupts :
|
||||
{
|
||||
__VECTOR_TABLE = .;
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
. = ALIGN(4);
|
||||
} > m_interrupts
|
||||
|
||||
__VECTOR_RAM = __VECTOR_TABLE;
|
||||
__RAM_VECTOR_TABLE_SIZE_BYTES = 0x0;
|
||||
|
||||
/* The program code and other data goes into internal RAM */
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.text) /* .text sections (code) */
|
||||
*(.text*) /* .text* sections (code) */
|
||||
*(.rodata) /* .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
|
||||
*(.glue_7) /* glue arm to thumb code */
|
||||
*(.glue_7t) /* glue thumb to arm code */
|
||||
*(.eh_frame)
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
. = ALIGN(4);
|
||||
} > m_text
|
||||
|
||||
.ARM.extab :
|
||||
{
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
} > m_text
|
||||
|
||||
.ARM :
|
||||
{
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
} > m_text
|
||||
|
||||
.ctors :
|
||||
{
|
||||
__CTOR_LIST__ = .;
|
||||
/* gcc uses crtbegin.o to find the start of
|
||||
the constructors, so we make sure it is
|
||||
first. Because this is a wildcard, it
|
||||
doesn't matter if the user does not
|
||||
actually link against crtbegin.o; the
|
||||
linker won't look for a file to match a
|
||||
wildcard. The wildcard also means that it
|
||||
doesn't matter which directory crtbegin.o
|
||||
is in. */
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*crtbegin?.o(.ctors))
|
||||
/* We don't want to include the .ctor section from
|
||||
from the crtend.o file until after the sorted ctors.
|
||||
The .ctor section from the crtend file contains the
|
||||
end of ctors marker and it must be last */
|
||||
KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
__CTOR_END__ = .;
|
||||
} > m_text
|
||||
|
||||
.dtors :
|
||||
{
|
||||
__DTOR_LIST__ = .;
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*crtbegin?.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
__DTOR_END__ = .;
|
||||
} > m_text
|
||||
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array*))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
} > m_text
|
||||
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array*))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
} > m_text
|
||||
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
KEEP (*(.fini_array*))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
} > m_text
|
||||
|
||||
__etext = .; /* define a global symbol at end of code */
|
||||
__DATA_ROM = .; /* Symbol is used by startup for data initialization */
|
||||
|
||||
.data : AT(__DATA_ROM)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
__DATA_RAM = .;
|
||||
__data_start__ = .; /* create a global symbol at data start */
|
||||
*(.data) /* .data sections */
|
||||
*(.data*) /* .data* sections */
|
||||
KEEP(*(.jcr*))
|
||||
. = ALIGN(4);
|
||||
__data_end__ = .; /* define a global symbol at data end */
|
||||
} > m_data
|
||||
|
||||
__DATA_END = __DATA_ROM + (__data_end__ - __data_start__);
|
||||
text_end = ORIGIN(m_text) + LENGTH(m_text);
|
||||
ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data")
|
||||
|
||||
USB_RAM_GAP = DEFINED(__usb_ram_size__) ? __usb_ram_size__ : 0x800;
|
||||
/* Uninitialized data section */
|
||||
.bss :
|
||||
{
|
||||
/* This is used by the startup in order to initialize the .bss section */
|
||||
. = ALIGN(4);
|
||||
__START_BSS = .;
|
||||
__bss_start__ = .;
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
. = ALIGN(512);
|
||||
USB_RAM_START = .;
|
||||
. += USB_RAM_GAP;
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
__bss_end__ = .;
|
||||
__END_BSS = .;
|
||||
} > m_data
|
||||
|
||||
.heap :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
__end__ = .;
|
||||
PROVIDE(end = .);
|
||||
__HeapBase = .;
|
||||
. += HEAP_SIZE;
|
||||
__HeapLimit = .;
|
||||
__heap_limit = .; /* Add for _sbrk */
|
||||
} > m_data
|
||||
|
||||
.stack :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
. += STACK_SIZE;
|
||||
} > m_data
|
||||
|
||||
m_usb_bdt USB_RAM_START (NOLOAD) :
|
||||
{
|
||||
*(m_usb_bdt)
|
||||
USB_RAM_BDT_END = .;
|
||||
}
|
||||
|
||||
m_usb_global USB_RAM_BDT_END (NOLOAD) :
|
||||
{
|
||||
*(m_usb_global)
|
||||
}
|
||||
|
||||
/* Initializes stack on the end of block */
|
||||
__StackTop = ORIGIN(m_data) + LENGTH(m_data);
|
||||
__StackLimit = __StackTop - STACK_SIZE;
|
||||
PROVIDE(__stack = __StackTop);
|
||||
|
||||
.ARM.attributes 0 : { *(.ARM.attributes) }
|
||||
|
||||
ASSERT(__StackLimit >= __HeapLimit, "region m_data overflowed with stack and heap")
|
||||
}
|
||||
|
||||
827
devices/MK22F51212/gcc/startup_MK22F51212.S
Normal file
827
devices/MK22F51212/gcc/startup_MK22F51212.S
Normal file
File diff suppressed because it is too large
Load Diff
115
devices/MK22F51212/iar/MK22FN512xxx12_flash.icf
Normal file
115
devices/MK22F51212/iar/MK22FN512xxx12_flash.icf
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
** ###################################################################
|
||||
** Processors: MK22FN512CAP12
|
||||
** MK22FN512VDC12
|
||||
** MK22FN512VFX12
|
||||
** MK22FN512VLH12
|
||||
** MK22FN512VLL12
|
||||
** MK22FN512VMP12
|
||||
**
|
||||
** Compiler: IAR ANSI C/C++ Compiler for ARM
|
||||
** Reference manual: K22P121M120SF7RM, Rev. 1, March 24, 2014
|
||||
** Version: rev. 2.9, 2016-03-21
|
||||
** Build: b160321
|
||||
**
|
||||
** Abstract:
|
||||
** Linker file for the IAR ANSI C/C++ Compiler for ARM
|
||||
**
|
||||
** Copyright (c) 2016 Freescale Semiconductor, Inc.
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without modification,
|
||||
** are permitted provided that the following conditions are met:
|
||||
**
|
||||
** o Redistributions of source code must retain the above copyright notice, this list
|
||||
** of conditions and the following disclaimer.
|
||||
**
|
||||
** o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
** list of conditions and the following disclaimer in the documentation and/or
|
||||
** other materials provided with the distribution.
|
||||
**
|
||||
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
** contributors may be used to endorse or promote products derived from this
|
||||
** software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**
|
||||
** http: www.freescale.com
|
||||
** mail: support@freescale.com
|
||||
**
|
||||
** ###################################################################
|
||||
*/
|
||||
|
||||
define symbol __ram_vector_table_size__ = isdefinedsymbol(__ram_vector_table__) ? 0x00000400 : 0;
|
||||
define symbol __ram_vector_table_offset__ = isdefinedsymbol(__ram_vector_table__) ? 0x000003FF : 0;
|
||||
|
||||
define symbol m_interrupts_start = 0x00000000;
|
||||
define symbol m_interrupts_end = 0x000003FF;
|
||||
|
||||
define symbol m_flash_config_start = 0x00000400;
|
||||
define symbol m_flash_config_end = 0x0000040F;
|
||||
|
||||
define symbol m_text_start = 0x00000410;
|
||||
define symbol m_text_end = 0x0007FFFF;
|
||||
|
||||
define symbol m_interrupts_ram_start = 0x1FFF0000;
|
||||
define symbol m_interrupts_ram_end = 0x1FFF0000 + __ram_vector_table_offset__;
|
||||
|
||||
define symbol m_data_start = m_interrupts_ram_start + __ram_vector_table_size__;
|
||||
define symbol m_data_end = 0x1FFFFFFF;
|
||||
|
||||
define symbol m_data_2_start = 0x20000000;
|
||||
define symbol m_data_2_end = 0x2000FFFF;
|
||||
|
||||
/* Sizes */
|
||||
if (isdefinedsymbol(__stack_size__)) {
|
||||
define symbol __size_cstack__ = __stack_size__;
|
||||
} else {
|
||||
define symbol __size_cstack__ = 0x0400;
|
||||
}
|
||||
|
||||
if (isdefinedsymbol(__heap_size__)) {
|
||||
define symbol __size_heap__ = __heap_size__;
|
||||
} else {
|
||||
define symbol __size_heap__ = 0x0400;
|
||||
}
|
||||
|
||||
define exported symbol __VECTOR_TABLE = m_interrupts_start;
|
||||
define exported symbol __VECTOR_RAM = isdefinedsymbol(__ram_vector_table__) ? m_interrupts_ram_start : m_interrupts_start;
|
||||
define exported symbol __RAM_VECTOR_TABLE_SIZE = __ram_vector_table_size__;
|
||||
|
||||
define memory mem with size = 4G;
|
||||
define region m_flash_config_region = mem:[from m_flash_config_start to m_flash_config_end];
|
||||
define region TEXT_region = mem:[from m_interrupts_start to m_interrupts_end]
|
||||
| mem:[from m_text_start to m_text_end];
|
||||
define region DATA_region = mem:[from m_data_start to m_data_end]
|
||||
| mem:[from m_data_2_start to m_data_2_end-__size_cstack__];
|
||||
define region CSTACK_region = mem:[from m_data_2_end-__size_cstack__+1 to m_data_2_end];
|
||||
define region m_interrupts_ram_region = mem:[from m_interrupts_ram_start to m_interrupts_ram_end];
|
||||
|
||||
define block CSTACK with alignment = 8, size = __size_cstack__ { };
|
||||
define block HEAP with alignment = 8, size = __size_heap__ { };
|
||||
define block RW { readwrite };
|
||||
define block ZI { zi };
|
||||
|
||||
initialize by copy { readwrite, section .textrw };
|
||||
do not initialize { section .noinit };
|
||||
|
||||
place at address mem: m_interrupts_start { readonly section .intvec };
|
||||
place in m_flash_config_region { section FlashConfig };
|
||||
place in TEXT_region { readonly };
|
||||
place in DATA_region { block RW };
|
||||
place in DATA_region { block ZI };
|
||||
place in DATA_region { last block HEAP };
|
||||
place in CSTACK_region { block CSTACK };
|
||||
place in m_interrupts_ram_region { section m_interrupts_ram };
|
||||
|
||||
97
devices/MK22F51212/iar/MK22FN512xxx12_ram.icf
Normal file
97
devices/MK22F51212/iar/MK22FN512xxx12_ram.icf
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
** ###################################################################
|
||||
** Processors: MK22FN512CAP12
|
||||
** MK22FN512VDC12
|
||||
** MK22FN512VFX12
|
||||
** MK22FN512VLH12
|
||||
** MK22FN512VLL12
|
||||
** MK22FN512VMP12
|
||||
**
|
||||
** Compiler: IAR ANSI C/C++ Compiler for ARM
|
||||
** Reference manual: K22P121M120SF7RM, Rev. 1, March 24, 2014
|
||||
** Version: rev. 2.9, 2016-03-21
|
||||
** Build: b160321
|
||||
**
|
||||
** Abstract:
|
||||
** Linker file for the IAR ANSI C/C++ Compiler for ARM
|
||||
**
|
||||
** Copyright (c) 2016 Freescale Semiconductor, Inc.
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without modification,
|
||||
** are permitted provided that the following conditions are met:
|
||||
**
|
||||
** o Redistributions of source code must retain the above copyright notice, this list
|
||||
** of conditions and the following disclaimer.
|
||||
**
|
||||
** o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
** list of conditions and the following disclaimer in the documentation and/or
|
||||
** other materials provided with the distribution.
|
||||
**
|
||||
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
** contributors may be used to endorse or promote products derived from this
|
||||
** software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**
|
||||
** http: www.freescale.com
|
||||
** mail: support@freescale.com
|
||||
**
|
||||
** ###################################################################
|
||||
*/
|
||||
|
||||
define symbol m_interrupts_start = 0x1FFF0000;
|
||||
define symbol m_interrupts_end = 0x1FFF03FF;
|
||||
|
||||
define symbol m_text_start = 0x1FFF0400;
|
||||
define symbol m_text_end = 0x1FFFFFFF;
|
||||
|
||||
define symbol m_data_start = 0x20000000;
|
||||
define symbol m_data_end = 0x2000FFFF;
|
||||
|
||||
/* Sizes */
|
||||
if (isdefinedsymbol(__stack_size__)) {
|
||||
define symbol __size_cstack__ = __stack_size__;
|
||||
} else {
|
||||
define symbol __size_cstack__ = 0x0400;
|
||||
}
|
||||
|
||||
if (isdefinedsymbol(__heap_size__)) {
|
||||
define symbol __size_heap__ = __heap_size__;
|
||||
} else {
|
||||
define symbol __size_heap__ = 0x0400;
|
||||
}
|
||||
|
||||
define exported symbol __VECTOR_TABLE = m_interrupts_start;
|
||||
define exported symbol __VECTOR_RAM = m_interrupts_start;
|
||||
define exported symbol __RAM_VECTOR_TABLE_SIZE = 0x0;
|
||||
|
||||
define memory mem with size = 4G;
|
||||
define region TEXT_region = mem:[from m_interrupts_start to m_interrupts_end]
|
||||
| mem:[from m_text_start to m_text_end];
|
||||
define region DATA_region = mem:[from m_data_start to m_data_end-__size_cstack__];
|
||||
define region CSTACK_region = mem:[from m_data_end-__size_cstack__+1 to m_data_end];
|
||||
|
||||
define block CSTACK with alignment = 8, size = __size_cstack__ { };
|
||||
define block HEAP with alignment = 8, size = __size_heap__ { };
|
||||
define block RW { readwrite };
|
||||
define block ZI { zi };
|
||||
|
||||
do not initialize { section .noinit };
|
||||
|
||||
place at address mem: m_interrupts_start { readonly section .intvec };
|
||||
place in TEXT_region { readonly };
|
||||
place in DATA_region { block RW };
|
||||
place in DATA_region { block ZI };
|
||||
place in DATA_region { last block HEAP };
|
||||
place in CSTACK_region { block CSTACK };
|
||||
|
||||
766
devices/MK22F51212/iar/startup_MK22F51212.s
Normal file
766
devices/MK22F51212/iar/startup_MK22F51212.s
Normal file
File diff suppressed because it is too large
Load Diff
247
devices/MK22F51212/system_MK22F51212.c
Normal file
247
devices/MK22F51212/system_MK22F51212.c
Normal file
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
** ###################################################################
|
||||
** Processors: MK22FN512CAP12
|
||||
** MK22FN512VDC12
|
||||
** MK22FN512VFX12
|
||||
** MK22FN512VLH12
|
||||
** MK22FN512VLL12
|
||||
** MK22FN512VMP12
|
||||
**
|
||||
** Compilers: Keil ARM C/C++ Compiler
|
||||
** Freescale C/C++ for Embedded ARM
|
||||
** GNU C Compiler
|
||||
** IAR ANSI C/C++ Compiler for ARM
|
||||
**
|
||||
** Reference manual: K22P121M120SF7RM, Rev. 1, March 24, 2014
|
||||
** Version: rev. 2.9, 2016-03-21
|
||||
** Build: b160321
|
||||
**
|
||||
** Abstract:
|
||||
** Provides a system configuration function and a global variable that
|
||||
** contains the system frequency. It configures the device and initializes
|
||||
** the oscillator (PLL) that is part of the microcontroller device.
|
||||
**
|
||||
** Copyright (c) 2016 Freescale Semiconductor, Inc.
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without modification,
|
||||
** are permitted provided that the following conditions are met:
|
||||
**
|
||||
** o Redistributions of source code must retain the above copyright notice, this list
|
||||
** of conditions and the following disclaimer.
|
||||
**
|
||||
** o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
** list of conditions and the following disclaimer in the documentation and/or
|
||||
** other materials provided with the distribution.
|
||||
**
|
||||
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
** contributors may be used to endorse or promote products derived from this
|
||||
** software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**
|
||||
** http: www.freescale.com
|
||||
** mail: support@freescale.com
|
||||
**
|
||||
** Revisions:
|
||||
** - rev. 1.0 (2013-07-23)
|
||||
** Initial version.
|
||||
** - rev. 1.1 (2013-09-17)
|
||||
** RM rev. 0.4 update.
|
||||
** - rev. 2.0 (2013-10-29)
|
||||
** Register accessor macros added to the memory map.
|
||||
** Symbols for Processor Expert memory map compatibility added to the memory map.
|
||||
** Startup file for gcc has been updated according to CMSIS 3.2.
|
||||
** System initialization updated.
|
||||
** - rev. 2.1 (2013-10-30)
|
||||
** Definition of BITBAND macros updated to support peripherals with 32-bit acces disabled.
|
||||
** - rev. 2.2 (2013-12-20)
|
||||
** Update according to reference manual rev. 0.6,
|
||||
** - rev. 2.3 (2014-01-13)
|
||||
** Update according to reference manual rev. 0.61,
|
||||
** - rev. 2.4 (2014-02-10)
|
||||
** The declaration of clock configurations has been moved to separate header file system_MK22F51212.h
|
||||
** - rev. 2.5 (2014-05-06)
|
||||
** Update according to reference manual rev. 1.0,
|
||||
** Update of system and startup files.
|
||||
** Module access macro module_BASES replaced by module_BASE_PTRS.
|
||||
** - rev. 2.6 (2014-08-28)
|
||||
** Update of system files - default clock configuration changed.
|
||||
** Update of startup files - possibility to override DefaultISR added.
|
||||
** - rev. 2.7 (2014-10-14)
|
||||
** Interrupt INT_LPTimer renamed to INT_LPTMR0, interrupt INT_Watchdog renamed to INT_WDOG_EWM.
|
||||
** - rev. 2.8 (2015-02-19)
|
||||
** Renamed interrupt vector LLW to LLWU.
|
||||
** - rev. 2.9 (2016-03-21)
|
||||
** Added MK22FN512VFX12 part.
|
||||
** GPIO - renamed port instances: PTx -> GPIOx.
|
||||
**
|
||||
** ###################################################################
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @file MK22F51212
|
||||
* @version 2.9
|
||||
* @date 2016-03-21
|
||||
* @brief Device specific configuration file for MK22F51212 (implementation file)
|
||||
*
|
||||
* Provides a system configuration function and a global variable that contains
|
||||
* the system frequency. It configures the device and initializes the oscillator
|
||||
* (PLL) that is part of the microcontroller device.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "fsl_device_registers.h"
|
||||
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
-- Core clock
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
uint32_t SystemCoreClock = DEFAULT_SYSTEM_CLOCK;
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
-- SystemInit()
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
void SystemInit (void) {
|
||||
#if ((__FPU_PRESENT == 1) && (__FPU_USED == 1))
|
||||
SCB->CPACR |= ((3UL << 10*2) | (3UL << 11*2)); /* set CP10, CP11 Full Access */
|
||||
#endif /* ((__FPU_PRESENT == 1) && (__FPU_USED == 1)) */
|
||||
|
||||
#if (DISABLE_WDOG)
|
||||
/* WDOG->UNLOCK: WDOGUNLOCK=0xC520 */
|
||||
WDOG->UNLOCK = WDOG_UNLOCK_WDOGUNLOCK(0xC520); /* Key 1 */
|
||||
/* WDOG->UNLOCK: WDOGUNLOCK=0xD928 */
|
||||
WDOG->UNLOCK = WDOG_UNLOCK_WDOGUNLOCK(0xD928); /* Key 2 */
|
||||
/* WDOG->STCTRLH: ?=0,DISTESTWDOG=0,BYTESEL=0,TESTSEL=0,TESTWDOG=0,?=0,?=1,WAITEN=1,STOPEN=1,DBGEN=0,ALLOWUPDATE=1,WINEN=0,IRQRSTEN=0,CLKSRC=1,WDOGEN=0 */
|
||||
WDOG->STCTRLH = WDOG_STCTRLH_BYTESEL(0x00) |
|
||||
WDOG_STCTRLH_WAITEN_MASK |
|
||||
WDOG_STCTRLH_STOPEN_MASK |
|
||||
WDOG_STCTRLH_ALLOWUPDATE_MASK |
|
||||
WDOG_STCTRLH_CLKSRC_MASK |
|
||||
0x0100U;
|
||||
#endif /* (DISABLE_WDOG) */
|
||||
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
-- SystemCoreClockUpdate()
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
void SystemCoreClockUpdate (void) {
|
||||
|
||||
uint32_t MCGOUTClock; /* Variable to store output clock frequency of the MCG module */
|
||||
uint16_t Divider;
|
||||
|
||||
if ((MCG->C1 & MCG_C1_CLKS_MASK) == 0x00U) {
|
||||
/* Output of FLL or PLL is selected */
|
||||
if ((MCG->C6 & MCG_C6_PLLS_MASK) == 0x00U) {
|
||||
/* FLL is selected */
|
||||
if ((MCG->C1 & MCG_C1_IREFS_MASK) == 0x00U) {
|
||||
/* External reference clock is selected */
|
||||
switch (MCG->C7 & MCG_C7_OSCSEL_MASK) {
|
||||
case 0x00U:
|
||||
MCGOUTClock = CPU_XTAL_CLK_HZ; /* System oscillator drives MCG clock */
|
||||
break;
|
||||
case 0x01U:
|
||||
MCGOUTClock = CPU_XTAL32k_CLK_HZ; /* RTC 32 kHz oscillator drives MCG clock */
|
||||
break;
|
||||
case 0x02U:
|
||||
default:
|
||||
MCGOUTClock = CPU_INT_IRC_CLK_HZ; /* IRC 48MHz oscillator drives MCG clock */
|
||||
break;
|
||||
}
|
||||
if (((MCG->C2 & MCG_C2_RANGE_MASK) != 0x00U) && ((MCG->C7 & MCG_C7_OSCSEL_MASK) != 0x01U)) {
|
||||
switch (MCG->C1 & MCG_C1_FRDIV_MASK) {
|
||||
case 0x38U:
|
||||
Divider = 1536U;
|
||||
break;
|
||||
case 0x30U:
|
||||
Divider = 1280U;
|
||||
break;
|
||||
default:
|
||||
Divider = (uint16_t)(32LU << ((MCG->C1 & MCG_C1_FRDIV_MASK) >> MCG_C1_FRDIV_SHIFT));
|
||||
break;
|
||||
}
|
||||
} else {/* ((MCG->C2 & MCG_C2_RANGE_MASK) != 0x00U) */
|
||||
Divider = (uint16_t)(1LU << ((MCG->C1 & MCG_C1_FRDIV_MASK) >> MCG_C1_FRDIV_SHIFT));
|
||||
}
|
||||
MCGOUTClock = (MCGOUTClock / Divider); /* Calculate the divided FLL reference clock */
|
||||
} else { /* (!((MCG->C1 & MCG_C1_IREFS_MASK) == 0x00U)) */
|
||||
MCGOUTClock = CPU_INT_SLOW_CLK_HZ; /* The slow internal reference clock is selected */
|
||||
} /* (!((MCG->C1 & MCG_C1_IREFS_MASK) == 0x00U)) */
|
||||
/* Select correct multiplier to calculate the MCG output clock */
|
||||
switch (MCG->C4 & (MCG_C4_DMX32_MASK | MCG_C4_DRST_DRS_MASK)) {
|
||||
case 0x00U:
|
||||
MCGOUTClock *= 640U;
|
||||
break;
|
||||
case 0x20U:
|
||||
MCGOUTClock *= 1280U;
|
||||
break;
|
||||
case 0x40U:
|
||||
MCGOUTClock *= 1920U;
|
||||
break;
|
||||
case 0x60U:
|
||||
MCGOUTClock *= 2560U;
|
||||
break;
|
||||
case 0x80U:
|
||||
MCGOUTClock *= 732U;
|
||||
break;
|
||||
case 0xA0U:
|
||||
MCGOUTClock *= 1464U;
|
||||
break;
|
||||
case 0xC0U:
|
||||
MCGOUTClock *= 2197U;
|
||||
break;
|
||||
case 0xE0U:
|
||||
MCGOUTClock *= 2929U;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else { /* (!((MCG->C6 & MCG_C6_PLLS_MASK) == 0x00U)) */
|
||||
/* PLL is selected */
|
||||
Divider = (((uint16_t)MCG->C5 & MCG_C5_PRDIV0_MASK) + 0x01U);
|
||||
MCGOUTClock = (uint32_t)(CPU_XTAL_CLK_HZ / Divider); /* Calculate the PLL reference clock */
|
||||
Divider = (((uint16_t)MCG->C6 & MCG_C6_VDIV0_MASK) + 24U);
|
||||
MCGOUTClock *= Divider; /* Calculate the MCG output clock */
|
||||
} /* (!((MCG->C6 & MCG_C6_PLLS_MASK) == 0x00U)) */
|
||||
} else if ((MCG->C1 & MCG_C1_CLKS_MASK) == 0x40U) {
|
||||
/* Internal reference clock is selected */
|
||||
if ((MCG->C2 & MCG_C2_IRCS_MASK) == 0x00U) {
|
||||
MCGOUTClock = CPU_INT_SLOW_CLK_HZ; /* Slow internal reference clock selected */
|
||||
} else { /* (!((MCG->C2 & MCG_C2_IRCS_MASK) == 0x00U)) */
|
||||
Divider = (uint16_t)(0x01LU << ((MCG->SC & MCG_SC_FCRDIV_MASK) >> MCG_SC_FCRDIV_SHIFT));
|
||||
MCGOUTClock = (uint32_t) (CPU_INT_FAST_CLK_HZ / Divider); /* Fast internal reference clock selected */
|
||||
} /* (!((MCG->C2 & MCG_C2_IRCS_MASK) == 0x00U)) */
|
||||
} else if ((MCG->C1 & MCG_C1_CLKS_MASK) == 0x80U) {
|
||||
/* External reference clock is selected */
|
||||
switch (MCG->C7 & MCG_C7_OSCSEL_MASK) {
|
||||
case 0x00U:
|
||||
MCGOUTClock = CPU_XTAL_CLK_HZ; /* System oscillator drives MCG clock */
|
||||
break;
|
||||
case 0x01U:
|
||||
MCGOUTClock = CPU_XTAL32k_CLK_HZ; /* RTC 32 kHz oscillator drives MCG clock */
|
||||
break;
|
||||
case 0x02U:
|
||||
default:
|
||||
MCGOUTClock = CPU_INT_IRC_CLK_HZ; /* IRC 48MHz oscillator drives MCG clock */
|
||||
break;
|
||||
}
|
||||
} else { /* (!((MCG->C1 & MCG_C1_CLKS_MASK) == 0x80U)) */
|
||||
/* Reserved value */
|
||||
return;
|
||||
} /* (!((MCG->C1 & MCG_C1_CLKS_MASK) == 0x80U)) */
|
||||
SystemCoreClock = (MCGOUTClock / (0x01U + ((SIM->CLKDIV1 & SIM_CLKDIV1_OUTDIV1_MASK) >> SIM_CLKDIV1_OUTDIV1_SHIFT)));
|
||||
}
|
||||
168
devices/MK22F51212/system_MK22F51212.h
Normal file
168
devices/MK22F51212/system_MK22F51212.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
** ###################################################################
|
||||
** Processors: MK22FN512CAP12
|
||||
** MK22FN512VDC12
|
||||
** MK22FN512VFX12
|
||||
** MK22FN512VLH12
|
||||
** MK22FN512VLL12
|
||||
** MK22FN512VMP12
|
||||
**
|
||||
** Compilers: Keil ARM C/C++ Compiler
|
||||
** Freescale C/C++ for Embedded ARM
|
||||
** GNU C Compiler
|
||||
** IAR ANSI C/C++ Compiler for ARM
|
||||
**
|
||||
** Reference manual: K22P121M120SF7RM, Rev. 1, March 24, 2014
|
||||
** Version: rev. 2.9, 2016-03-21
|
||||
** Build: b160321
|
||||
**
|
||||
** Abstract:
|
||||
** Provides a system configuration function and a global variable that
|
||||
** contains the system frequency. It configures the device and initializes
|
||||
** the oscillator (PLL) that is part of the microcontroller device.
|
||||
**
|
||||
** Copyright (c) 2016 Freescale Semiconductor, Inc.
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without modification,
|
||||
** are permitted provided that the following conditions are met:
|
||||
**
|
||||
** o Redistributions of source code must retain the above copyright notice, this list
|
||||
** of conditions and the following disclaimer.
|
||||
**
|
||||
** o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
** list of conditions and the following disclaimer in the documentation and/or
|
||||
** other materials provided with the distribution.
|
||||
**
|
||||
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
** contributors may be used to endorse or promote products derived from this
|
||||
** software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**
|
||||
** http: www.freescale.com
|
||||
** mail: support@freescale.com
|
||||
**
|
||||
** Revisions:
|
||||
** - rev. 1.0 (2013-07-23)
|
||||
** Initial version.
|
||||
** - rev. 1.1 (2013-09-17)
|
||||
** RM rev. 0.4 update.
|
||||
** - rev. 2.0 (2013-10-29)
|
||||
** Register accessor macros added to the memory map.
|
||||
** Symbols for Processor Expert memory map compatibility added to the memory map.
|
||||
** Startup file for gcc has been updated according to CMSIS 3.2.
|
||||
** System initialization updated.
|
||||
** - rev. 2.1 (2013-10-30)
|
||||
** Definition of BITBAND macros updated to support peripherals with 32-bit acces disabled.
|
||||
** - rev. 2.2 (2013-12-20)
|
||||
** Update according to reference manual rev. 0.6,
|
||||
** - rev. 2.3 (2014-01-13)
|
||||
** Update according to reference manual rev. 0.61,
|
||||
** - rev. 2.4 (2014-02-10)
|
||||
** The declaration of clock configurations has been moved to separate header file system_MK22F51212.h
|
||||
** - rev. 2.5 (2014-05-06)
|
||||
** Update according to reference manual rev. 1.0,
|
||||
** Update of system and startup files.
|
||||
** Module access macro module_BASES replaced by module_BASE_PTRS.
|
||||
** - rev. 2.6 (2014-08-28)
|
||||
** Update of system files - default clock configuration changed.
|
||||
** Update of startup files - possibility to override DefaultISR added.
|
||||
** - rev. 2.7 (2014-10-14)
|
||||
** Interrupt INT_LPTimer renamed to INT_LPTMR0, interrupt INT_Watchdog renamed to INT_WDOG_EWM.
|
||||
** - rev. 2.8 (2015-02-19)
|
||||
** Renamed interrupt vector LLW to LLWU.
|
||||
** - rev. 2.9 (2016-03-21)
|
||||
** Added MK22FN512VFX12 part.
|
||||
** GPIO - renamed port instances: PTx -> GPIOx.
|
||||
**
|
||||
** ###################################################################
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @file MK22F51212
|
||||
* @version 2.9
|
||||
* @date 2016-03-21
|
||||
* @brief Device specific configuration file for MK22F51212 (header file)
|
||||
*
|
||||
* Provides a system configuration function and a global variable that contains
|
||||
* the system frequency. It configures the device and initializes the oscillator
|
||||
* (PLL) that is part of the microcontroller device.
|
||||
*/
|
||||
|
||||
#ifndef _SYSTEM_MK22F51212_H_
|
||||
#define _SYSTEM_MK22F51212_H_ /**< Symbol preventing repeated inclusion */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#ifndef DISABLE_WDOG
|
||||
#define DISABLE_WDOG 1
|
||||
#endif
|
||||
|
||||
/* Define clock source values */
|
||||
|
||||
#define CPU_XTAL_CLK_HZ 8000000u /* Value of the external crystal or oscillator clock frequency in Hz */
|
||||
#define CPU_XTAL32k_CLK_HZ 32768u /* Value of the external 32k crystal or oscillator clock frequency in Hz */
|
||||
#define CPU_INT_SLOW_CLK_HZ 32768u /* Value of the slow internal oscillator clock frequency in Hz */
|
||||
#define CPU_INT_FAST_CLK_HZ 4000000u /* Value of the fast internal oscillator clock frequency in Hz */
|
||||
#define CPU_INT_IRC_CLK_HZ 48000000u /* Value of the 48M internal oscillator clock frequency in Hz */
|
||||
|
||||
/* RTC oscillator setting */
|
||||
/* RTC_CR: SC2P=0,SC4P=0,SC8P=0,SC16P=0,CLKO=1,OSCE=1,WPS=0,UM=0,SUP=0,WPE=0,SWR=0 */
|
||||
#define SYSTEM_RTC_CR_VALUE 0x0300U /* RTC_CR */
|
||||
|
||||
/* Low power mode enable */
|
||||
/* SMC_PMPROT: AHSRUN=1,AVLP=1,ALLS=1,AVLLS=1 */
|
||||
#define SYSTEM_SMC_PMPROT_VALUE 0xAAU /* SMC_PMPROT */
|
||||
|
||||
#define DEFAULT_SYSTEM_CLOCK 20971520u /* Default System clock value */
|
||||
|
||||
|
||||
/**
|
||||
* @brief System clock frequency (core clock)
|
||||
*
|
||||
* The system clock frequency supplied to the SysTick timer and the processor
|
||||
* core clock. This variable can be used by the user application to setup the
|
||||
* SysTick timer or configure other parameters. It may also be used by debugger to
|
||||
* query the frequency of the debug timer or configure the trace clock speed
|
||||
* SystemCoreClock is initialized with a correct predefined value.
|
||||
*/
|
||||
extern uint32_t SystemCoreClock;
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system.
|
||||
*
|
||||
* Typically this function configures the oscillator (PLL) that is part of the
|
||||
* microcontroller device. For systems with variable clock speed it also updates
|
||||
* the variable SystemCoreClock. SystemInit is called from startup_device file.
|
||||
*/
|
||||
void SystemInit (void);
|
||||
|
||||
/**
|
||||
* @brief Updates the SystemCoreClock variable.
|
||||
*
|
||||
* It must be called whenever the core clock is changed during program
|
||||
* execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates
|
||||
* the current core clock.
|
||||
*/
|
||||
void SystemCoreClockUpdate (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SYSTEM_MK22F51212_H_ */
|
||||
1763
devices/MK22F51212/utilities/fsl_debug_console.c
Normal file
1763
devices/MK22F51212/utilities/fsl_debug_console.c
Normal file
File diff suppressed because it is too large
Load Diff
189
devices/MK22F51212/utilities/fsl_debug_console.h
Normal file
189
devices/MK22F51212/utilities/fsl_debug_console.h
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Debug console shall provide input and output functions to scan and print formatted data.
|
||||
* o Support a format specifier for PRINTF follows this prototype "%[flags][width][.precision][length]specifier"
|
||||
* - [flags] :'-', '+', '#', ' ', '0'
|
||||
* - [width]: number (0,1...)
|
||||
* - [.precision]: number (0,1...)
|
||||
* - [length]: do not support
|
||||
* - [specifier]: 'd', 'i', 'f', 'F', 'x', 'X', 'o', 'p', 'u', 'c', 's', 'n'
|
||||
* o Support a format specifier for SCANF follows this prototype " %[*][width][length]specifier"
|
||||
* - [*]: is supported.
|
||||
* - [width]: number (0,1...)
|
||||
* - [length]: 'h', 'hh', 'l','ll','L'. ignore ('j','z','t')
|
||||
* - [specifier]: 'd', 'i', 'u', 'f', 'F', 'e', 'E', 'g', 'G', 'a', 'A', 'o', 'c', 's'
|
||||
*/
|
||||
|
||||
#ifndef _FSL_DEBUGCONSOLE_H_
|
||||
#define _FSL_DEBUGCONSOLE_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*
|
||||
* @addtogroup debug_console
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief Definition to select sdk or toolchain printf, scanf. */
|
||||
#ifndef SDK_DEBUGCONSOLE
|
||||
#define SDK_DEBUGCONSOLE 1U
|
||||
#endif
|
||||
|
||||
/*! @brief Definition to printf float number. */
|
||||
#ifndef PRINTF_FLOAT_ENABLE
|
||||
#define PRINTF_FLOAT_ENABLE 1U
|
||||
#endif /* PRINTF_FLOAT_ENABLE */
|
||||
|
||||
/*! @brief Definition to scanf float number. */
|
||||
#ifndef SCANF_FLOAT_ENABLE
|
||||
#define SCANF_FLOAT_ENABLE 1U
|
||||
#endif /* SCANF_FLOAT_ENABLE */
|
||||
|
||||
/*! @brief Definition to support advanced format specifier for printf. */
|
||||
#ifndef PRINTF_ADVANCED_ENABLE
|
||||
#define PRINTF_ADVANCED_ENABLE 1U
|
||||
#endif /* PRINTF_ADVANCED_ENABLE */
|
||||
|
||||
/*! @brief Definition to support advanced format specifier for scanf. */
|
||||
#ifndef SCANF_ADVANCED_ENABLE
|
||||
#define SCANF_ADVANCED_ENABLE 1U
|
||||
#endif /* SCANF_ADVANCED_ENABLE */
|
||||
|
||||
#if SDK_DEBUGCONSOLE /* Select printf, scanf, putchar, getchar of SDK version. */
|
||||
#define PRINTF DbgConsole_Printf
|
||||
#define SCANF DbgConsole_Scanf
|
||||
#define PUTCHAR DbgConsole_Putchar
|
||||
#define GETCHAR DbgConsole_Getchar
|
||||
#else /* Select printf, scanf, putchar, getchar of toolchain. */
|
||||
#define PRINTF printf
|
||||
#define SCANF scanf
|
||||
#define PUTCHAR putchar
|
||||
#define GETCHAR getchar
|
||||
#endif /* SDK_DEBUGCONSOLE */
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @name Initialization*/
|
||||
/* @{ */
|
||||
|
||||
/*!
|
||||
* @brief Initialize the the peripheral used for debug messages.
|
||||
*
|
||||
* Call this function to enable debug log messages to be output via the specified peripheral,
|
||||
* frequency of peripheral source clock, base address at the specified baud rate.
|
||||
* After this function has returned, stdout and stdin will be connected to the selected peripheral.
|
||||
*
|
||||
* @param baseAddr Which address of peripheral is used to send debug messages.
|
||||
* @param baudRate The desired baud rate in bits per second.
|
||||
* @param device Low level device type for the debug console, could be one of:
|
||||
* @arg DEBUG_CONSOLE_DEVICE_TYPE_UART,
|
||||
* @arg DEBUG_CONSOLE_DEVICE_TYPE_LPUART,
|
||||
* @arg DEBUG_CONSOLE_DEVICE_TYPE_LPSCI,
|
||||
* @arg DEBUG_CONSOLE_DEVICE_TYPE_USBCDC.
|
||||
* @param clkSrcFreq Frequency of peripheral source clock.
|
||||
*
|
||||
* @return Whether initialization was successful or not.
|
||||
* @retval kStatus_Success Execution successfully
|
||||
* @retval kStatus_Fail Execution failure
|
||||
* @retval kStatus_InvalidArgument Invalid argument existed
|
||||
*/
|
||||
status_t DbgConsole_Init(uint32_t baseAddr, uint32_t baudRate, uint8_t device, uint32_t clkSrcFreq);
|
||||
|
||||
/*!
|
||||
* @brief De-initialize the peripheral used for debug messages.
|
||||
*
|
||||
* Call this function to disable debug log messages to be output via the specified peripheral
|
||||
* base address and at the specified baud rate.
|
||||
*
|
||||
* @return Whether de-initialization was successful or not.
|
||||
*/
|
||||
status_t DbgConsole_Deinit(void);
|
||||
|
||||
#if SDK_DEBUGCONSOLE
|
||||
/*!
|
||||
* @brief Writes formatted output to the standard output stream.
|
||||
*
|
||||
* Call this function to Writes formatted output to the standard output stream.
|
||||
*
|
||||
* @param fmt_s Format control string.
|
||||
* @return Returns the number of characters printed, or a negative value if an error occurs.
|
||||
*/
|
||||
int DbgConsole_Printf(char *fmt_s, ...);
|
||||
|
||||
/*!
|
||||
* @brief Writes a character to stdout.
|
||||
*
|
||||
* Call this function to write a character to stdout.
|
||||
*
|
||||
* @param ch Character to be written.
|
||||
* @return Returns the character written.
|
||||
*/
|
||||
int DbgConsole_Putchar(int ch);
|
||||
|
||||
/*!
|
||||
* @brief Reads formatted data from the standard input stream.
|
||||
*
|
||||
* Call this function to read formatted data from the standard input stream.
|
||||
*
|
||||
* @param fmt_ptr Format control string.
|
||||
* @return Returns the number of fields successfully converted and assigned.
|
||||
*/
|
||||
int DbgConsole_Scanf(char *fmt_ptr, ...);
|
||||
|
||||
/*!
|
||||
* @brief Reads a character from standard input.
|
||||
*
|
||||
* Call this function to read a character from standard input.
|
||||
*
|
||||
* @return Returns the character read.
|
||||
*/
|
||||
int DbgConsole_Getchar(void);
|
||||
|
||||
#endif /* SDK_DEBUGCONSOLE */
|
||||
|
||||
/*! @} */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @} */
|
||||
|
||||
#endif /* _FSL_DEBUGCONSOLE_H_ */
|
||||
182
devices/MK22F51212/utilities/fsl_notifier.c
Normal file
182
devices/MK22F51212/utilities/fsl_notifier.c
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_notifier.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
status_t NOTIFIER_CreateHandle(notifier_handle_t *notifierHandle,
|
||||
notifier_user_config_t **configs,
|
||||
uint8_t configsNumber,
|
||||
notifier_callback_config_t *callbacks,
|
||||
uint8_t callbacksNumber,
|
||||
notifier_user_function_t userFunction,
|
||||
void *userData)
|
||||
{
|
||||
/* Check input parameter - at least one configuration is required and userFunction must exist */
|
||||
if ((configs == NULL) || (configsNumber == 0U) || (userFunction == NULL))
|
||||
{
|
||||
return kStatus_Fail;
|
||||
}
|
||||
/* Initialize handle structure */
|
||||
memset(notifierHandle, 0, sizeof(notifier_handle_t));
|
||||
/* Store references to user-defined configurations */
|
||||
notifierHandle->configsTable = configs;
|
||||
notifierHandle->configsNumber = configsNumber;
|
||||
/* Store references to user-defined callback configurations */
|
||||
if (callbacks != NULL)
|
||||
{
|
||||
notifierHandle->callbacksTable = callbacks;
|
||||
notifierHandle->callbacksNumber = callbacksNumber;
|
||||
/* If all callbacks return success, then the errorCallbackIndex is callbacksNumber */
|
||||
notifierHandle->errorCallbackIndex = callbacksNumber;
|
||||
}
|
||||
notifierHandle->userFunction = userFunction;
|
||||
notifierHandle->userData = userData;
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
status_t NOTIFIER_SwitchConfig(notifier_handle_t *notifierHandle, uint8_t configIndex, notifier_policy_t policy)
|
||||
{
|
||||
uint8_t currentStaticCallback = 0U; /* Index to array of statically registered call-backs */
|
||||
status_t returnCode = kStatus_Success; /* Function return */
|
||||
|
||||
notifier_notification_block_t notifyBlock; /* Callback notification block */
|
||||
notifier_callback_config_t *callbackConfig; /* Pointer to callback configuration */
|
||||
|
||||
/* Set errorcallbackindex as callbacksNumber, which means no callback error now */
|
||||
notifierHandle->errorCallbackIndex = notifierHandle->callbacksNumber;
|
||||
|
||||
/* Requested configuration availability check */
|
||||
if (configIndex >= notifierHandle->configsNumber)
|
||||
{
|
||||
return kStatus_OutOfRange;
|
||||
}
|
||||
|
||||
/* Initialization of local variables from the Notifier handle structure */
|
||||
|
||||
notifyBlock.policy = policy;
|
||||
notifyBlock.targetConfig = notifierHandle->configsTable[configIndex];
|
||||
notifyBlock.notifyType = kNOTIFIER_NotifyBefore;
|
||||
|
||||
/* From all statically registered call-backs... */
|
||||
for (currentStaticCallback = 0U; currentStaticCallback < notifierHandle->callbacksNumber; currentStaticCallback++)
|
||||
{
|
||||
callbackConfig = &(notifierHandle->callbacksTable[currentStaticCallback]);
|
||||
/* ...notify only those which asked to be called before the configuration switch */
|
||||
if (((uint32_t)callbackConfig->callbackType) & kNOTIFIER_CallbackBefore)
|
||||
{
|
||||
/* In case that call-back returned error code mark it, store the call-back handle and eventually cancel
|
||||
* the configuration switch */
|
||||
if (callbackConfig->callback(¬ifyBlock, callbackConfig->callbackData) != kStatus_Success)
|
||||
{
|
||||
returnCode = kStatus_NOTIFIER_ErrorNotificationBefore;
|
||||
notifierHandle->errorCallbackIndex = currentStaticCallback;
|
||||
/* If not forcing configuration switch, call all already notified call-backs to revert their state
|
||||
* as the switch is canceled */
|
||||
if (policy != kNOTIFIER_PolicyForcible)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set configuration */
|
||||
|
||||
/* In case that any call-back returned error code and policy doesn't force the configuration set, go to after
|
||||
* switch call-backs */
|
||||
if ((policy == kNOTIFIER_PolicyForcible) || (returnCode == kStatus_Success))
|
||||
{
|
||||
returnCode = notifierHandle->userFunction(notifierHandle->configsTable[configIndex], notifierHandle->userData);
|
||||
if (returnCode != kStatus_Success)
|
||||
{
|
||||
return returnCode;
|
||||
}
|
||||
/* Update current configuration index */
|
||||
notifierHandle->currentConfigIndex = configIndex;
|
||||
notifyBlock.notifyType = kNOTIFIER_NotifyAfter;
|
||||
/* From all statically registered call-backs... */
|
||||
for (currentStaticCallback = 0U; currentStaticCallback < notifierHandle->callbacksNumber;
|
||||
currentStaticCallback++)
|
||||
{
|
||||
callbackConfig = &(notifierHandle->callbacksTable[currentStaticCallback]);
|
||||
/* ...notify only those which asked to be called after the configruation switch */
|
||||
if (((uint32_t)callbackConfig->callbackType) & kNOTIFIER_CallbackAfter)
|
||||
{
|
||||
/* In case that call-back returned error code mark it and store the call-back handle */
|
||||
if (callbackConfig->callback(¬ifyBlock, callbackConfig->callbackData) != kStatus_Success)
|
||||
{
|
||||
returnCode = kStatus_NOTIFIER_ErrorNotificationAfter;
|
||||
notifierHandle->errorCallbackIndex = currentStaticCallback;
|
||||
if (policy != kNOTIFIER_PolicyForcible)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* End of unsuccessful switch */
|
||||
notifyBlock.notifyType = kNOTIFIER_NotifyRecover;
|
||||
while (currentStaticCallback--)
|
||||
{
|
||||
callbackConfig = &(notifierHandle->callbacksTable[currentStaticCallback]);
|
||||
if (((uint32_t)callbackConfig->callbackType) & kNOTIFIER_CallbackBefore)
|
||||
{
|
||||
callbackConfig->callback(¬ifyBlock, callbackConfig->callbackData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
uint8_t NOTIFIER_GetErrorCallbackIndex(notifier_handle_t *notifierHandle)
|
||||
{
|
||||
return notifierHandle->errorCallbackIndex;
|
||||
}
|
||||
259
devices/MK22F51212/utilities/fsl_notifier.h
Normal file
259
devices/MK22F51212/utilities/fsl_notifier.h
Normal file
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FSL_NOTIFIER_H_
|
||||
#define _FSL_NOTIFIER_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
/*!
|
||||
* @addtogroup notifier
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Notifier error codes.
|
||||
*
|
||||
* Used as return value of Notifier functions.
|
||||
*/
|
||||
enum _notifier_status
|
||||
{
|
||||
kStatus_NOTIFIER_ErrorNotificationBefore =
|
||||
MAKE_STATUS(kStatusGroup_NOTIFIER, 0), /*!< Error occurs during send "BEFORE" notification. */
|
||||
kStatus_NOTIFIER_ErrorNotificationAfter =
|
||||
MAKE_STATUS(kStatusGroup_NOTIFIER, 1), /*!< Error occurs during send "AFTER" notification. */
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Notifier policies.
|
||||
*
|
||||
* Defines whether user function execution is forced or not.
|
||||
* For kNOTIFIER_PolicyForcible, the user function is executed regardless of the callback results,
|
||||
* while kNOTIFIER_PolicyAgreement policy is used to exit NOTIFIER_SwitchConfig()
|
||||
* when any of the callbacks returns error code.
|
||||
* See also NOTIFIER_SwitchConfig() description.
|
||||
*/
|
||||
typedef enum _notifier_policy
|
||||
{
|
||||
kNOTIFIER_PolicyAgreement, /*!< NOTIFIER_SwitchConfig() method is exited when any of the callbacks returns error
|
||||
code. */
|
||||
kNOTIFIER_PolicyForcible, /*!< user function is executed regardless of the results. */
|
||||
} notifier_policy_t;
|
||||
|
||||
/*! @brief Notification type. Used to notify registered callbacks */
|
||||
typedef enum _notifier_notification_type
|
||||
{
|
||||
kNOTIFIER_NotifyRecover = 0x00U, /*!< Notify IP to recover to previous work state. */
|
||||
kNOTIFIER_NotifyBefore = 0x01U, /*!< Notify IP that configuration setting is going to change. */
|
||||
kNOTIFIER_NotifyAfter = 0x02U, /*!< Notify IP that configuration setting has been changed. */
|
||||
} notifier_notification_type_t;
|
||||
|
||||
/*!
|
||||
* @brief The callback type, indicates what kinds of notification the callback handles.
|
||||
*
|
||||
* Used in the callback configuration structure (notifier_callback_config_t)
|
||||
* to specify when the registered callback is called during configuration switch initiated by
|
||||
* NOTIFIER_SwitchConfig().
|
||||
* Callback can be invoked in following situations:
|
||||
* - before the configuration switch (Callback return value can affect NOTIFIER_SwitchConfig()
|
||||
* execution. Refer to the NOTIFIER_SwitchConfig() and notifier_policy_t documentation).
|
||||
* - after unsuccessful attempt to switch configuration
|
||||
* - after sucecessful configuration switch
|
||||
*/
|
||||
typedef enum _notifier_callback_type
|
||||
{
|
||||
kNOTIFIER_CallbackBefore = 0x01U, /*!< Callback handles BEFORE notification. */
|
||||
kNOTIFIER_CallbackAfter = 0x02U, /*!< Callback handles AFTER notification. */
|
||||
kNOTIFIER_CallbackBeforeAfter = 0x03U, /*!< Callback handles BEFORE and AFTER notification. */
|
||||
} notifier_callback_type_t;
|
||||
|
||||
/*! @brief notifier user configuration type.
|
||||
*
|
||||
* Reference of user defined configuration is stored in an array, notifer switch between these configurations
|
||||
* based on this array.
|
||||
*/
|
||||
typedef void notifier_user_config_t;
|
||||
|
||||
/*! @brief notifier user function prototype
|
||||
* User can use this function to execute specific operations in configuration switch.
|
||||
* Before and after this function execution, different notification will be sent to registered callbacks.
|
||||
* If this function returns any error code, NOTIFIER_SwitchConfig() will exit.
|
||||
*
|
||||
* @param targetConfig target Configuration.
|
||||
* @param userData Refers to other specific data passed to user function.
|
||||
* @return An error code or kStatus_Success.
|
||||
*/
|
||||
typedef status_t (*notifier_user_function_t)(notifier_user_config_t *targetConfig, void *userData);
|
||||
|
||||
/*! @brief notification block passed to the registered callback function. */
|
||||
typedef struct _notifier_notification_block
|
||||
{
|
||||
notifier_user_config_t *targetConfig; /*!< Pointer to target configuration. */
|
||||
notifier_policy_t policy; /*!< Configure transition policy. */
|
||||
notifier_notification_type_t notifyType; /*!< Configure notification type. */
|
||||
} notifier_notification_block_t;
|
||||
|
||||
/*!
|
||||
* @brief Callback prototype.
|
||||
*
|
||||
* Declaration of callback. It is common for registered callbacks.
|
||||
* Reference to function of this type is part of notifier_callback_config_t callback configuration structure.
|
||||
* Depending on callback type, function of this prototype is called (see NOTIFIER_SwitchConfig())
|
||||
* before configuration switch, after it or in both cases to notify about
|
||||
* the switch progress (see notifier_callback_type_t). When called, type of the notification
|
||||
* is passed as parameter along with reference to the target configuration structure (see notifier_notification_block_t)
|
||||
* and any data passed during the callback registration.
|
||||
* When notified before configuration switch, depending on the configuration switch policy (see
|
||||
* notifier_policy_t) the callback may deny the execution of user function by returning any error code different
|
||||
* from kStatus_Success (see NOTIFIER_SwitchConfig()).
|
||||
*
|
||||
* @param notify Notification block.
|
||||
* @param data Callback data. Refers to the data passed during callback registration. Intended to
|
||||
* pass any driver or application data such as internal state information.
|
||||
* @return An error code or kStatus_Success.
|
||||
*/
|
||||
typedef status_t (*notifier_callback_t)(notifier_notification_block_t *notify, void *data);
|
||||
|
||||
/*!
|
||||
* @brief callback configuration structure
|
||||
*
|
||||
* This structure holds configuration of callbacks.
|
||||
* Callbacks of this type are expected to be statically allocated.
|
||||
* This structure contains following application-defined data:
|
||||
* callback - pointer to the callback function
|
||||
* callbackType - specifies when the callback is called
|
||||
* callbackData - pointer to the data passed to the callback.
|
||||
*/
|
||||
typedef struct _notifier_callback_config
|
||||
{
|
||||
notifier_callback_t callback; /*!< Pointer to the callback function. */
|
||||
notifier_callback_type_t callbackType; /*!< Callback type. */
|
||||
void *callbackData; /*!< Pointer to the data passed to the callback. */
|
||||
} notifier_callback_config_t;
|
||||
|
||||
/*!
|
||||
* @brief Notifier handle structure.
|
||||
*
|
||||
* Notifier handle structure. Contains data necessary for Notifier proper function.
|
||||
* Stores references to registered configurations, callbacks, information about their numbers,
|
||||
* user function, user data and other internal data.
|
||||
* NOTIFIER_CreateHandle() must be called to intialize this handle.
|
||||
*/
|
||||
typedef struct _notifier_handle
|
||||
{
|
||||
notifier_user_config_t **configsTable; /*!< Pointer to configure table. */
|
||||
uint8_t configsNumber; /*!< Number of configurations. */
|
||||
notifier_callback_config_t *callbacksTable; /*!< Pointer to callback table. */
|
||||
uint8_t callbacksNumber; /*!< Maximum number of callback configurations. */
|
||||
uint8_t errorCallbackIndex; /*!< Index of callback returns error. */
|
||||
uint8_t currentConfigIndex; /*!< Index of current configuration. */
|
||||
notifier_user_function_t userFunction; /*!< user function. */
|
||||
void *userData; /*!< user data passed to user function. */
|
||||
} notifier_handle_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Create Notifier handle.
|
||||
*
|
||||
* @param notifierHandle A pointer to notifier handle
|
||||
* @param configs A pointer to an array with references to all configurations which is handled by the Notifier.
|
||||
* @param configsNumber Number of configurations. Size of configs array.
|
||||
* @param callbacks A pointer to an array of callback configurations.
|
||||
* If there are no callbacks to register during Notifier initialization, use NULL value.
|
||||
* @param callbacksNumber Number of registered callbacks. Size of callbacks array.
|
||||
* @param userFunction user function.
|
||||
* @param userData user data passed to user function.
|
||||
* @return An error code or kStatus_Success.
|
||||
*/
|
||||
status_t NOTIFIER_CreateHandle(notifier_handle_t *notifierHandle,
|
||||
notifier_user_config_t **configs,
|
||||
uint8_t configsNumber,
|
||||
notifier_callback_config_t *callbacks,
|
||||
uint8_t callbacksNumber,
|
||||
notifier_user_function_t userFunction,
|
||||
void *userData);
|
||||
|
||||
/*!
|
||||
* @brief Switch configuration according to a pre-defined structure.
|
||||
*
|
||||
* This function sets the system to the target configuration. Before transition,
|
||||
* the Notifier sends notifications to all callbacks registered to the callback table.
|
||||
* Callbacks are invoked in the following order: All registered callbacks are notified
|
||||
* ordered by index in the callbacks array. The same order is used for before and after switch notifications.
|
||||
* The notifications before the configuration switch can be used to obtain confirmation about
|
||||
* the change from registered callbacks. If any registered callback denies the
|
||||
* configuration change, further execution of this function depends on the notifier policy: the
|
||||
* configuration change is either forced (kNOTIFIER_PolicyForcible) or exited (kNOTIFIER_PolicyAgreement).
|
||||
* When configuration change is forced, the result of the before switch notifications are ignored. If
|
||||
* agreement is required, if any callback returns an error code then further notifications
|
||||
* before switch notifications are cancelled and all already notified callbacks are re-invoked
|
||||
* The index of the callback which returned error code during pre-switch notifications is stored
|
||||
* (any error codes during callbacks re-invocation are ignored) and NOTIFIER_GetErrorCallback() can be used to get it.
|
||||
* Regardless of the policies, if any callback returned an error code, an error code denoting in which phase
|
||||
* the error occurred is returned when NOTIFIER_SwitchConfig() exits.
|
||||
* @param notifierHandle pointer to notifier handle
|
||||
* @param configIndex Index of the target configuration.
|
||||
* @param policy Transaction policy, kNOTIFIER_PolicyAgreement or kNOTIFIER_PolicyForcible.
|
||||
*
|
||||
* @return An error code or kStatus_Success.
|
||||
*
|
||||
*/
|
||||
status_t NOTIFIER_SwitchConfig(notifier_handle_t *notifierHandle, uint8_t configIndex, notifier_policy_t policy);
|
||||
|
||||
/*!
|
||||
* @brief This function returns the last failed notification callback.
|
||||
*
|
||||
* This function returns index of the last callback that failed during the configuration switch while
|
||||
* the last NOTIFIER_SwitchConfig() was called. If the last NOTIFIER_SwitchConfig() call ended successfully
|
||||
* value equal to callbacks number is returned. Returned value represents index in the array of
|
||||
* static call-backs.
|
||||
*
|
||||
* @param notifierHandle pointer to notifier handle
|
||||
* @return Callback index of last failed callback or value equal to callbacks count.
|
||||
*/
|
||||
uint8_t NOTIFIER_GetErrorCallbackIndex(notifier_handle_t *notifierHandle);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* _FSL_NOTIFIER_H_ */
|
||||
66
devices/MK22F51212/utilities/fsl_sbrk.c
Normal file
66
devices/MK22F51212/utilities/fsl_sbrk.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
/*!
|
||||
* @brief Function to override ARMGCC default function _sbrk
|
||||
*
|
||||
* _sbrk is called by malloc. ARMGCC default _sbrk compares "SP" register and
|
||||
* heap end, if heap end is larger than "SP", then _sbrk returns error and
|
||||
* memory allocation failed. This function changes to compare __HeapLimit with
|
||||
* heap end.
|
||||
*/
|
||||
caddr_t _sbrk(int incr)
|
||||
{
|
||||
extern char end __asm("end");
|
||||
extern char heap_limit __asm("__HeapLimit");
|
||||
static char *heap_end;
|
||||
char *prev_heap_end;
|
||||
|
||||
if (heap_end == NULL)
|
||||
heap_end = &end;
|
||||
|
||||
prev_heap_end = heap_end;
|
||||
|
||||
if (heap_end + incr > &heap_limit)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return (caddr_t)-1;
|
||||
}
|
||||
|
||||
heap_end += incr;
|
||||
|
||||
return (caddr_t)prev_heap_end;
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user