mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-21 02:06:14 +08:00
adapter frdm-mcxn236 iar project (#9083)
* adapter frdm-mcxn236 iar project * formate MCXN236 bsp
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2021-2022 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "fsl_cache_lpcac.h"
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/* Component ID definition, used by tools. */
|
||||
#ifndef FSL_COMPONENT_ID
|
||||
#define FSL_COMPONENT_ID "platform.drivers.cache_lpcac"
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright 2021-2023 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#ifndef FSL_CACHE_LPCAC_H_
|
||||
#define FSL_CACHE_LPCAC_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup cache_lpcac
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief cache driver version */
|
||||
#define FSL_CACHE_LPCAC_DRIVER_VERSION (MAKE_VERSION(2, 1, 1))
|
||||
/*@}*/
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @name cache control for the L1 low power cache controller
|
||||
*@{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Enables the processor code bus cache.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_EnableCodeCache(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL &= ~SYSCON_LPCAC_CTRL_DIS_LPCAC_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disables the processor code bus cache.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_DisableCodeCache(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL |= SYSCON_LPCAC_CTRL_DIS_LPCAC_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Clears cache.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_InvalidateCodeCache(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL |= SYSCON_LPCAC_CTRL_CLR_LPCAC_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Enables allocation.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_EnableAllocation(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL &= ~SYSCON_LPCAC_CTRL_FRC_NO_ALLOC_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disables allocation.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_DisableAllocation(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL |= SYSCON_LPCAC_CTRL_FRC_NO_ALLOC_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Enables parity.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_EnableParity(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL |= SYSCON_LPCAC_CTRL_PARITY_MISS_EN_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disable parity.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_DisableParity(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL &= ~SYSCON_LPCAC_CTRL_PARITY_MISS_EN_MASK;
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_LPCAC_SUPPORT_WRITE_BUFFER_CONTROL) && FSL_FEATURE_LPCAC_SUPPORT_WRITE_BUFFER_CONTROL
|
||||
/*!
|
||||
* @brief Enables write through buffer.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_EnableWriteBuffer(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL &= ~SYSCON_LPCAC_CTRL_DIS_LPCAC_WTBF_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disables write through buffer.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_DisableWriteBuffer(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL |= SYSCON_LPCAC_CTRL_DIS_LPCAC_WTBF_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Limits write through buffer.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_LimitWriteBuffer(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL &= ~SYSCON_LPCAC_CTRL_LIM_LPCAC_WTBF_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Unlimits write through buffer.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_UnlimitParity(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL |= SYSCON_LPCAC_CTRL_LIM_LPCAC_WTBF_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Enables parity error report.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_EnableParityErrorReport(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL |= SYSCON_LPCAC_CTRL_PARITY_FAULT_EN_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disables parity error report.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_DisableParityErrorReport(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL &= ~SYSCON_LPCAC_CTRL_PARITY_FAULT_EN_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Enables XOM(eXecute-Only-Memory) control.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_EnableXOMControl(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL |= SYSCON_LPCAC_CTRL_LPCAC_XOM_MASK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Disables XOM(eXecute-Only-Memory) control.
|
||||
*
|
||||
*/
|
||||
static inline void L1CACHE_DisableXOMControl(void)
|
||||
{
|
||||
SYSCON->LPCAC_CTRL &= ~SYSCON_LPCAC_CTRL_LPCAC_XOM_MASK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*@}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* FSL_CACHE_LPCAC_H_*/
|
||||
@@ -0,0 +1,396 @@
|
||||
/*
|
||||
* Copyright 2020-2022 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "fsl_cdog.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
*******************************************************************************/
|
||||
|
||||
/* Component ID definition, used by tools. */
|
||||
#ifndef FSL_COMPONENT_ID
|
||||
#define FSL_COMPONENT_ID "platform.drivers.cdog"
|
||||
#endif
|
||||
|
||||
/* Reset CONTROL mask */
|
||||
#define RESERVED_CTRL_MASK 0x800u
|
||||
|
||||
#if defined(CDOG_IRQS)
|
||||
/* Array of IRQs */
|
||||
static const IRQn_Type s_CdogIrqs[] = CDOG_IRQS;
|
||||
#endif /* CDOG_IRQS */
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
#if defined(CDOG)
|
||||
/*!
|
||||
* Weak implementation of CDOG IRQ, should be re-defined by user when using CDOG IRQ
|
||||
*/
|
||||
__WEAK void CDOG_DriverIRQHandler(void)
|
||||
{
|
||||
/* NVIC_DisableIRQ(CDOG_IRQn);
|
||||
* CDOG_Stop(CDOG, s_start);
|
||||
* CDOG->FLAGS = 0x0U;
|
||||
* CDOG_Start(CDOG, 0xFFFFFFU, s_start);
|
||||
* NVIC_EnableIRQ(CDOG_IRQn);
|
||||
*/
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CDOG0)
|
||||
/*!
|
||||
* Weak implementation of CDOG0 IRQ, should be re-defined by user when using CDOG IRQ
|
||||
*/
|
||||
__WEAK void CDOG0_DriverIRQHandler(void)
|
||||
{
|
||||
/* NVIC_DisableIRQ(CDOG0_IRQn);
|
||||
* CDOG_Stop(CDOG0, s_start);
|
||||
* CDOG0->FLAGS = 0x0U;
|
||||
* CDOG_Start(CDOG0, 0xFFFFFFU, s_start);
|
||||
* NVIC_EnableIRQ(CDOG0_IRQn);
|
||||
*/
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CDOG1)
|
||||
/*!
|
||||
* Weak implementation of CDOG1 IRQ, should be re-defined by user when using CDOG IRQ
|
||||
*/
|
||||
__WEAK void CDOG1_DriverIRQHandler(void)
|
||||
{
|
||||
/* NVIC_DisableIRQ(CDOG1_IRQn);
|
||||
* CDOG_Stop(CDOG1, s_start);
|
||||
* CDOG1->FLAGS = 0x0U;
|
||||
* CDOG_Start(CDOG1, 0xFFFFFFU, s_start);
|
||||
* NVIC_EnableIRQ(CDOG1_IRQn);
|
||||
*/
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* brief Sets the default configuration of CDOG
|
||||
*
|
||||
* This function initialize CDOG config structure to default values.
|
||||
*
|
||||
* param conf CDOG configuration structure
|
||||
*/
|
||||
void CDOG_GetDefaultConfig(cdog_config_t *conf)
|
||||
{
|
||||
/* Default configuration after reset */
|
||||
conf->lock = (uint8_t)kCDOG_LockCtrl_Unlock; /* Lock control */
|
||||
conf->timeout = (uint8_t)kCDOG_FaultCtrl_NoAction; /* Timeout control */
|
||||
conf->miscompare = (uint8_t)kCDOG_FaultCtrl_NoAction; /* Miscompare control */
|
||||
conf->sequence = (uint8_t)kCDOG_FaultCtrl_NoAction; /* Sequence control */
|
||||
conf->state = (uint8_t)kCDOG_FaultCtrl_NoAction; /* State control */
|
||||
conf->address = (uint8_t)kCDOG_FaultCtrl_NoAction; /* Address control */
|
||||
conf->irq_pause = (uint8_t)kCDOG_IrqPauseCtrl_Run; /* IRQ pause control */
|
||||
conf->debug_halt = (uint8_t)kCDOG_DebugHaltCtrl_Run; /* Debug halt control */
|
||||
return;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Sets secure counter and instruction timer values
|
||||
*
|
||||
* This function sets value in RELOAD and START registers for instruction timer.
|
||||
*
|
||||
* param base CDOG peripheral base address
|
||||
* param reload reload value
|
||||
* param start start value
|
||||
*/
|
||||
void CDOG_Start(CDOG_Type *base, uint32_t reload, uint32_t start)
|
||||
{
|
||||
base->RELOAD = reload;
|
||||
base->START = start;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Stops secure counter and instruction timer
|
||||
*
|
||||
* This function stops instruction timer and secure counter.
|
||||
* This also change state of CDOG to IDLE.
|
||||
*
|
||||
* param base CDOG peripheral base address
|
||||
* param stop expected value which will be compared with value of secure counter
|
||||
*/
|
||||
void CDOG_Stop(CDOG_Type *base, uint32_t stop)
|
||||
{
|
||||
base->STOP = stop;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Sets secure counter and instruction timer values
|
||||
*
|
||||
* This function sets value in STOP, RELOAD and START registers
|
||||
* for instruction timer and secure counter.
|
||||
*
|
||||
* param base CDOG peripheral base address
|
||||
* param stop expected value which will be compared with value of secure counter
|
||||
* param reload reload value for instruction timer
|
||||
* param start start value for secure timer
|
||||
*/
|
||||
void CDOG_Set(CDOG_Type *base, uint32_t stop, uint32_t reload, uint32_t start)
|
||||
{
|
||||
base->STOP = stop;
|
||||
base->RELOAD = reload;
|
||||
base->START = start;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Add value to secure counter
|
||||
*
|
||||
* This function add specified value to secure counter.
|
||||
*
|
||||
* param base CDOG peripheral base address.
|
||||
* param add Value to be added.
|
||||
*/
|
||||
void CDOG_Add(CDOG_Type *base, uint32_t add)
|
||||
{
|
||||
base->ADD = (secure_counter_t)add;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Add 1 to secure counter
|
||||
*
|
||||
* This function add 1 to secure counter.
|
||||
*
|
||||
* param base CDOG peripheral base address.
|
||||
* param add Value to be added.
|
||||
*/
|
||||
void CDOG_Add1(CDOG_Type *base)
|
||||
{
|
||||
base->ADD1 = (secure_counter_t)0x1U;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Add 16 to secure counter
|
||||
*
|
||||
* This function add 16 to secure counter.
|
||||
*
|
||||
* param base CDOG peripheral base address.
|
||||
* param add Value to be added.
|
||||
*/
|
||||
void CDOG_Add16(CDOG_Type *base)
|
||||
{
|
||||
base->ADD16 = (secure_counter_t)0x1U;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Add 256 to secure counter
|
||||
*
|
||||
* This function add 256 to secure counter.
|
||||
*
|
||||
* param base CDOG peripheral base address.
|
||||
* param add Value to be added.
|
||||
*/
|
||||
void CDOG_Add256(CDOG_Type *base)
|
||||
{
|
||||
base->ADD256 = (secure_counter_t)0x1U;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Substract value to secure counter
|
||||
*
|
||||
* This function substract specified value to secure counter.
|
||||
*
|
||||
* param base CDOG peripheral base address.
|
||||
* param sub Value to be substracted.
|
||||
*/
|
||||
void CDOG_Sub(CDOG_Type *base, uint32_t sub)
|
||||
{
|
||||
base->SUB = (secure_counter_t)sub;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Substract 1 from secure counter
|
||||
*
|
||||
* This function substract specified 1 from secure counter.
|
||||
*
|
||||
* param base CDOG peripheral base address.
|
||||
*/
|
||||
void CDOG_Sub1(CDOG_Type *base)
|
||||
{
|
||||
base->SUB1 = (secure_counter_t)0x1U;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Substract 16 from secure counter
|
||||
*
|
||||
* This function substract specified 16 from secure counter.
|
||||
*
|
||||
* param base CDOG peripheral base address.
|
||||
*/
|
||||
void CDOG_Sub16(CDOG_Type *base)
|
||||
{
|
||||
base->SUB16 = (secure_counter_t)0x1U;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Substract 256 from secure counter
|
||||
*
|
||||
* This function substract specified 256 from secure counter.
|
||||
*
|
||||
* param base CDOG peripheral base address.
|
||||
*/
|
||||
void CDOG_Sub256(CDOG_Type *base)
|
||||
{
|
||||
base->SUB256 = (secure_counter_t)0x1U;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Checks secure counter.
|
||||
*
|
||||
* This function compares stop value with secure counter value
|
||||
* by writting to RELOAD refister.
|
||||
*
|
||||
* param base CDOG peripheral base address
|
||||
* param check expected (stop) value.
|
||||
*/
|
||||
void CDOG_Check(CDOG_Type *base, uint32_t check)
|
||||
{
|
||||
base->RESTART = check;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Set the CDOG persistent word.
|
||||
*
|
||||
* param base CDOG peripheral base address.
|
||||
* param value The value to be written.
|
||||
*/
|
||||
void CDOG_WritePersistent(CDOG_Type *base, uint32_t value)
|
||||
{
|
||||
base->PERSISTENT = value;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Get the CDOG persistent word.
|
||||
*
|
||||
* param base CDOG peripheral base address.
|
||||
* return The persistent word.
|
||||
*/
|
||||
uint32_t CDOG_ReadPersistent(CDOG_Type *base)
|
||||
{
|
||||
return base->PERSISTENT;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Initialize CDOG
|
||||
*
|
||||
* This function initializes CDOG setting and enable all interrupts.
|
||||
*
|
||||
* param base CDOG peripheral base address
|
||||
* param conf CDOG configuration structure
|
||||
* return Status of the init operation
|
||||
*/
|
||||
status_t CDOG_Init(CDOG_Type *base, cdog_config_t *conf)
|
||||
{
|
||||
/* Ungate clock to CDOG engine and reset it */
|
||||
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
|
||||
#ifdef CDOG_CLOCKS
|
||||
CLOCK_EnableClock(kCLOCK_Cdog);
|
||||
#endif /* CDOG_CLOCKS */
|
||||
#endif /* !FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
|
||||
|
||||
#if !(defined(FSL_FEATURE_CDOG_HAS_NO_RESET) && FSL_FEATURE_CDOG_HAS_NO_RESET)
|
||||
RESET_PeripheralReset(kCDOG_RST_SHIFT_RSTn);
|
||||
#endif /* !FSL_FEATURE_CDOG_HAS_NO_RESET */
|
||||
|
||||
if (base->CONTROL == 0x0U)
|
||||
{
|
||||
/* CDOG is not in IDLE mode, which may be cause after SW reset. */
|
||||
/* Writing to CONTROL register will trigger fault. */
|
||||
return kStatus_Fail;
|
||||
}
|
||||
|
||||
/* Clear pending errors, otherwise the device will reset */
|
||||
/* itself immediately after enable Code Watchdog */
|
||||
if ((uint32_t)kCDOG_LockCtrl_Lock ==
|
||||
((base->CONTROL & CDOG_CONTROL_LOCK_CTRL_MASK) >> CDOG_CONTROL_LOCK_CTRL_SHIFT))
|
||||
|
||||
{
|
||||
base->FLAGS = CDOG_FLAGS_TO_FLAG(1U) | CDOG_FLAGS_MISCOM_FLAG(1U) | CDOG_FLAGS_SEQ_FLAG(1U) |
|
||||
CDOG_FLAGS_CNT_FLAG(1U) | CDOG_FLAGS_STATE_FLAG(1U) | CDOG_FLAGS_ADDR_FLAG(1U) |
|
||||
CDOG_FLAGS_POR_FLAG(1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* load default values for CDOG->CONTROL before flags clear */
|
||||
#if defined(FSL_FEATURE_CDOG_NEED_LOAD_DEFAULT_CONF) && (FSL_FEATURE_CDOG_NEED_LOAD_DEFAULT_CONF > 0)
|
||||
cdog_config_t default_conf;
|
||||
|
||||
/* Initialize CDOG */
|
||||
CDOG_GetDefaultConfig(&default_conf);
|
||||
|
||||
/* Write default value to CDOG->CONTROL*/
|
||||
base->CONTROL =
|
||||
CDOG_CONTROL_TIMEOUT_CTRL(default_conf.timeout) | /* Action if the timeout event is triggered */
|
||||
CDOG_CONTROL_MISCOMPARE_CTRL(default_conf.miscompare) | /* Action if the miscompare error event is triggered */
|
||||
CDOG_CONTROL_SEQUENCE_CTRL(default_conf.sequence) | /* Action if the sequence error event is triggered */
|
||||
CDOG_CONTROL_STATE_CTRL(default_conf.state) | /* Action if the state error event is triggered */
|
||||
CDOG_CONTROL_ADDRESS_CTRL(default_conf.address) | /* Action if the address error event is triggered */
|
||||
CDOG_CONTROL_IRQ_PAUSE(default_conf.irq_pause) | /* Pause running during interrupts setup */
|
||||
CDOG_CONTROL_DEBUG_HALT_CTRL(default_conf.debug_halt) | /* Halt CDOG timer during debug */
|
||||
CDOG_CONTROL_LOCK_CTRL(default_conf.lock) | RESERVED_CTRL_MASK; /* Lock control register, RESERVED */
|
||||
#endif /* FSL_FEATURE_CDOG_NEED_LOAD_DEFAULT_CONF */
|
||||
|
||||
base->FLAGS = CDOG_FLAGS_TO_FLAG(0U) | CDOG_FLAGS_MISCOM_FLAG(0U) | CDOG_FLAGS_SEQ_FLAG(0U) |
|
||||
CDOG_FLAGS_CNT_FLAG(0U) | CDOG_FLAGS_STATE_FLAG(0U) | CDOG_FLAGS_ADDR_FLAG(0U) |
|
||||
CDOG_FLAGS_POR_FLAG(0U);
|
||||
}
|
||||
|
||||
base->CONTROL =
|
||||
CDOG_CONTROL_TIMEOUT_CTRL(conf->timeout) | /* Action if the timeout event is triggered */
|
||||
CDOG_CONTROL_MISCOMPARE_CTRL(conf->miscompare) | /* Action if the miscompare error event is triggered */
|
||||
CDOG_CONTROL_SEQUENCE_CTRL(conf->sequence) | /* Action if the sequence error event is triggered */
|
||||
CDOG_CONTROL_STATE_CTRL(conf->state) | /* Action if the state error event is triggered */
|
||||
CDOG_CONTROL_ADDRESS_CTRL(conf->address) | /* Action if the address error event is triggered */
|
||||
CDOG_CONTROL_IRQ_PAUSE(conf->irq_pause) | /* Pause running during interrupts setup */
|
||||
CDOG_CONTROL_DEBUG_HALT_CTRL(conf->debug_halt) | /* Halt CDOG timer during debug */
|
||||
CDOG_CONTROL_LOCK_CTRL(conf->lock) | RESERVED_CTRL_MASK; /* Lock control register, RESERVED */
|
||||
|
||||
#if defined(CDOG_IRQS)
|
||||
/* Enable peripheral IRQs, if defined in array */
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(s_CdogIrqs); i++)
|
||||
{
|
||||
NVIC_EnableIRQ(s_CdogIrqs[i]);
|
||||
}
|
||||
#endif /* CDOG_IRQS */
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Deinitialize CDOG
|
||||
*
|
||||
* This function stops CDOG secure counter.
|
||||
*
|
||||
* param base CDOG peripheral base address
|
||||
*/
|
||||
void CDOG_Deinit(CDOG_Type *base)
|
||||
{
|
||||
#if defined(CDOG_IRQS)
|
||||
/* Enable peripheral IRQs, if defined in array */
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(s_CdogIrqs); i++)
|
||||
{
|
||||
NVIC_DisableIRQ(s_CdogIrqs[i]);
|
||||
}
|
||||
#endif /* CDOG_IRQS */
|
||||
|
||||
#if !(defined(FSL_FEATURE_CDOG_HAS_NO_RESET) && FSL_FEATURE_CDOG_HAS_NO_RESET)
|
||||
RESET_SetPeripheralReset(kCDOG_RST_SHIFT_RSTn);
|
||||
#endif /* !FSL_FEATURE_CDOG_HAS_NO_RESET */
|
||||
|
||||
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
|
||||
#ifdef CDOG_CLOCKS
|
||||
CLOCK_DisableClock(kCLOCK_Cdog);
|
||||
#endif /* CDOG_CLOCKS */
|
||||
#endif /* !FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
/*
|
||||
* Copyright 2020-2022 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#ifndef FSL_CDOG_H_
|
||||
#define FSL_CDOG_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup CDOG
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! @file */
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
*******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief Defines CDOG driver version 2.1.2.
|
||||
*
|
||||
* Change log:
|
||||
* - Version 2.1.2
|
||||
* - Support multiple IRQs
|
||||
* - Fix default CONTROL values
|
||||
* - Version 2.1.1
|
||||
* - Remove bit CONTROL[CONTROL_CTRL]
|
||||
* - Version 2.1.0
|
||||
* - Rename CWT to CDOG
|
||||
* - Version 2.0.2
|
||||
* - Fix MISRA-2012 issues
|
||||
* - Version 2.0.1
|
||||
* - Fix doxygen issues
|
||||
* - Version 2.0.0
|
||||
* - initial version
|
||||
*/
|
||||
#define FSL_CDOG_DRIVER_VERSION (MAKE_VERSION(2, 1, 2))
|
||||
/*@}*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t lock : 2;
|
||||
uint8_t timeout : 3;
|
||||
uint8_t miscompare : 3;
|
||||
uint8_t sequence : 3;
|
||||
uint8_t state : 3;
|
||||
uint8_t address : 3;
|
||||
uint8_t reserved : 8;
|
||||
uint8_t irq_pause : 2;
|
||||
uint8_t debug_halt : 2;
|
||||
} cdog_config_t;
|
||||
|
||||
enum __cdog_debug_Action_ctrl_enum
|
||||
{
|
||||
kCDOG_DebugHaltCtrl_Run = 0x1,
|
||||
kCDOG_DebugHaltCtrl_Pause = 0x2,
|
||||
};
|
||||
|
||||
enum __cdog_irq_pause_ctrl_enum
|
||||
{
|
||||
kCDOG_IrqPauseCtrl_Run = 0x1,
|
||||
kCDOG_IrqPauseCtrl_Pause = 0x2,
|
||||
};
|
||||
|
||||
enum __cdog_fault_ctrl_enum
|
||||
{
|
||||
kCDOG_FaultCtrl_EnableReset = 0x1U,
|
||||
kCDOG_FaultCtrl_EnableInterrupt = 0x2U,
|
||||
kCDOG_FaultCtrl_NoAction = 0x4U,
|
||||
};
|
||||
|
||||
enum __code_lock_ctrl_enum
|
||||
{
|
||||
kCDOG_LockCtrl_Lock = 0x1,
|
||||
kCDOG_LockCtrl_Unlock = 0x2,
|
||||
};
|
||||
|
||||
typedef uint32_t secure_counter_t;
|
||||
|
||||
#define SC_ADD(add) \
|
||||
do \
|
||||
{ \
|
||||
CDOG->ADD = (secure_counter_t)(add); \
|
||||
} while (0)
|
||||
|
||||
#define SC_ADD1 \
|
||||
do \
|
||||
{ \
|
||||
CDOG->ADD1 = (secure_counter_t)0x1U; \
|
||||
} while (0)
|
||||
|
||||
#define SC_ADD16 \
|
||||
do \
|
||||
{ \
|
||||
CDOG->ADD16 = (secure_counter_t)0x1U; \
|
||||
} while (0)
|
||||
|
||||
#define SC_ADD256 \
|
||||
do \
|
||||
{ \
|
||||
CDOG->ADD256 = (secure_counter_t)0x1U; \
|
||||
} while (0)
|
||||
|
||||
#define SC_SUB(sub) \
|
||||
do \
|
||||
{ \
|
||||
CDOG->SUB = (secure_counter_t)(sub); \
|
||||
} while (0)
|
||||
|
||||
#define SC_SUB1 \
|
||||
do \
|
||||
{ \
|
||||
CDOG->SUB1 = (secure_counter_t)0x1U; \
|
||||
} while (0)
|
||||
|
||||
#define SC_SUB16 \
|
||||
do \
|
||||
{ \
|
||||
CDOG->SUB16 = (secure_counter_t)0x1U; \
|
||||
} while (0)
|
||||
|
||||
#define SC_SUB256 \
|
||||
do \
|
||||
{ \
|
||||
CDOG->SUB256 = (secure_counter_t)0x1U; \
|
||||
} while (0)
|
||||
|
||||
#define SC_CHECK(val) \
|
||||
do \
|
||||
{ \
|
||||
CDOG->RESTART = (secure_counter_t)val; \
|
||||
} while (0)
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
*******************************************************************************/
|
||||
#if defined(CDOG)
|
||||
extern void CDOG_DriverIRQHandler(void);
|
||||
#endif
|
||||
|
||||
#if defined(CDOG0)
|
||||
extern void CDOG0_DriverIRQHandler(void);
|
||||
#endif
|
||||
|
||||
#if defined(CDOG1)
|
||||
extern void CDOG1_DriverIRQHandler(void);
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*!
|
||||
* @name CDOG Functional Operation
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initialize CDOG
|
||||
*
|
||||
* This function initializes CDOG block and setting.
|
||||
*
|
||||
* @param base CDOG peripheral base address
|
||||
* @param conf CDOG configuration structure
|
||||
* @return Status of the init operation
|
||||
*/
|
||||
status_t CDOG_Init(CDOG_Type *base, cdog_config_t *conf);
|
||||
|
||||
/*!
|
||||
* @brief Deinitialize CDOG
|
||||
*
|
||||
* This function deinitializes CDOG secure counter.
|
||||
*
|
||||
* @param base CDOG peripheral base address
|
||||
*/
|
||||
void CDOG_Deinit(CDOG_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Sets the default configuration of CDOG
|
||||
*
|
||||
* This function initialize CDOG config structure to default values.
|
||||
*
|
||||
* @param conf CDOG configuration structure
|
||||
*/
|
||||
void CDOG_GetDefaultConfig(cdog_config_t *conf);
|
||||
|
||||
/*!
|
||||
* @brief Stops secure counter and instruction timer
|
||||
*
|
||||
* This function stops instruction timer and secure counter.
|
||||
* This also change state od CDOG to IDLE.
|
||||
*
|
||||
* @param base CDOG peripheral base address
|
||||
* @param stop expected value which will be compared with value of secure counter
|
||||
*/
|
||||
void CDOG_Stop(CDOG_Type *base, uint32_t stop);
|
||||
|
||||
/*!
|
||||
* @brief Sets secure counter and instruction timer values
|
||||
*
|
||||
* This function sets value in RELOAD and START registers
|
||||
* for instruction timer and secure counter
|
||||
*
|
||||
* @param base CDOG peripheral base address
|
||||
* @param reload reload value
|
||||
* @param start start value
|
||||
*/
|
||||
void CDOG_Start(CDOG_Type *base, uint32_t reload, uint32_t start);
|
||||
|
||||
/*!
|
||||
* @brief Checks secure counter.
|
||||
*
|
||||
* This function compares stop value in handler with secure counter value
|
||||
* by writting to RELOAD refister.
|
||||
*
|
||||
* @param base CDOG peripheral base address
|
||||
* @param check expected (stop) value
|
||||
*/
|
||||
void CDOG_Check(CDOG_Type *base, uint32_t check);
|
||||
|
||||
/*!
|
||||
* @brief Sets secure counter and instruction timer values
|
||||
*
|
||||
* This function sets value in STOP, RELOAD and START registers
|
||||
* for instruction timer and secure counter.
|
||||
*
|
||||
* @param base CDOG peripheral base address
|
||||
* @param stop expected value which will be compared with value of secure counter
|
||||
* @param reload reload value for instruction timer
|
||||
* @param start start value for secure timer
|
||||
*/
|
||||
void CDOG_Set(CDOG_Type *base, uint32_t stop, uint32_t reload, uint32_t start);
|
||||
|
||||
/*!
|
||||
* @brief Add value to secure counter
|
||||
*
|
||||
* This function add specified value to secure counter.
|
||||
*
|
||||
* @param base CDOG peripheral base address.
|
||||
* @param add Value to be added.
|
||||
*/
|
||||
void CDOG_Add(CDOG_Type *base, uint32_t add);
|
||||
|
||||
/*!
|
||||
* @brief Add 1 to secure counter
|
||||
*
|
||||
* This function add 1 to secure counter.
|
||||
*
|
||||
* @param base CDOG peripheral base address.
|
||||
*/
|
||||
void CDOG_Add1(CDOG_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Add 16 to secure counter
|
||||
*
|
||||
* This function add 16 to secure counter.
|
||||
*
|
||||
* @param base CDOG peripheral base address.
|
||||
*/
|
||||
void CDOG_Add16(CDOG_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Add 256 to secure counter
|
||||
*
|
||||
* This function add 256 to secure counter.
|
||||
*
|
||||
* @param base CDOG peripheral base address.
|
||||
*/
|
||||
void CDOG_Add256(CDOG_Type *base);
|
||||
|
||||
/*!
|
||||
* brief Substract value to secure counter
|
||||
*
|
||||
* This function substract specified value to secure counter.
|
||||
*
|
||||
* param base CDOG peripheral base address.
|
||||
* param sub Value to be substracted.
|
||||
*/
|
||||
void CDOG_Sub(CDOG_Type *base, uint32_t sub);
|
||||
|
||||
/*!
|
||||
* @brief Substract 1 from secure counter
|
||||
*
|
||||
* This function substract specified 1 from secure counter.
|
||||
*
|
||||
* @param base CDOG peripheral base address.
|
||||
*/
|
||||
void CDOG_Sub1(CDOG_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Substract 16 from secure counter
|
||||
*
|
||||
* This function substract specified 16 from secure counter.
|
||||
*
|
||||
* @param base CDOG peripheral base address.
|
||||
*/
|
||||
void CDOG_Sub16(CDOG_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Substract 256 from secure counter
|
||||
*
|
||||
* This function substract specified 256 from secure counter.
|
||||
*
|
||||
* @param base CDOG peripheral base address.
|
||||
*/
|
||||
void CDOG_Sub256(CDOG_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Set the CDOG persistent word.
|
||||
*
|
||||
* @param base CDOG peripheral base address.
|
||||
* @param value The value to be written.
|
||||
*/
|
||||
void CDOG_WritePersistent(CDOG_Type *base, uint32_t value);
|
||||
|
||||
/*!
|
||||
* @brief Get the CDOG persistent word.
|
||||
*
|
||||
* @param base CDOG peripheral base address.
|
||||
* @return The persistent word.
|
||||
*/
|
||||
uint32_t CDOG_ReadPersistent(CDOG_Type *base);
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @}*/ /* end of group cdog */
|
||||
|
||||
#endif /* FSL_CDOG_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,315 @@
|
||||
/*
|
||||
* Copyright 2022 ~ 2023 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#include "fsl_cmc.h"
|
||||
|
||||
/* Component ID definition, used by tools. */
|
||||
#ifndef FSL_COMPONENT_ID
|
||||
#define FSL_COMPONENT_ID "platform.drivers.mcx_cmc"
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
#if (defined(FSL_FEATURE_MCX_CMC_HAS_SRAM_DIS_REG) && FSL_FEATURE_MCX_CMC_HAS_SRAM_DIS_REG)
|
||||
#define CMC_SRAMDIS_RESERVED_MASK \
|
||||
(~(kCMC_RAMX0 | kCMC_RAMX1 | kCMC_RAMX2 | kCMC_RAMB | kCMC_RAMC0 | kCMC_RAMC1 | kCMC_RAMD0 | kCMC_RAMD1 | \
|
||||
kCMC_RAME0 | kCMC_RAME1 | kCMC_RAMF0 | kCMC_RAMF1 | kCMC_RAMG0_RAMG1 | kCMC_RAMG2_RAMG3 | kCMC_RAMH0_RAMH1 | \
|
||||
kCMC_LPCAC | kCMC_DMA0_DMA1_PKC | kCMC_USB0 | kCMC_PQ | kCMC_CAN0_CAN1_ENET_USB1 | kCMC_FlexSPI))
|
||||
|
||||
#define CMC_SRAMRET_RESERVED_MASK (CMC_SRAMDIS_RESERVED_MASK)
|
||||
#endif /* FSL_FEATURE_MCX_CMC_HAS_SRAM_DIS_REG */
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
static uint32_t g_savedPrimask;
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* brief Sets clock mode.
|
||||
*
|
||||
* This function configs the amount of clock gating when the core asserts
|
||||
* Sleeping due to WFI, WFE or SLEEPONEXIT.
|
||||
*
|
||||
* param base CMC peripheral base address.
|
||||
* param mode System clock mode.
|
||||
*/
|
||||
void CMC_SetClockMode(CMC_Type *base, cmc_clock_mode_t mode)
|
||||
{
|
||||
uint32_t reg;
|
||||
|
||||
reg = base->CKCTRL;
|
||||
reg &= ~CMC_CKCTRL_CKMODE_MASK;
|
||||
reg |= CMC_CKCTRL_CKMODE((mode));
|
||||
base->CKCTRL = reg;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Configures all power mode protection settings.
|
||||
*
|
||||
* This function configures the power mode protection settings for
|
||||
* supported power modes. This should be done before setting the lowPower mode
|
||||
* for each power doamin.
|
||||
*
|
||||
* The allowed lowpower modes are passed as bit map. For example, to allow
|
||||
* Sleep and DeepSleep, use CMC_SetPowerModeProtection(CMC_base, kCMC_AllowSleepMode|kCMC_AllowDeepSleepMode).
|
||||
* To allow all low power modes, use CMC_SetPowerModeProtection(CMC_base, kCMC_AllowAllLowPowerModes).
|
||||
*
|
||||
* param base CMC peripheral base address.
|
||||
* param allowedModes Bitmaps of the allowed power modes.
|
||||
*/
|
||||
void CMC_SetPowerModeProtection(CMC_Type *base, uint32_t allowedModes)
|
||||
{
|
||||
uint32_t reg;
|
||||
|
||||
reg = base->PMPROT;
|
||||
reg &= ~0xFUL;
|
||||
reg |= allowedModes;
|
||||
|
||||
base->PMPROT = reg;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Configure reset pin.
|
||||
*
|
||||
* This function configures reset pin. When enabled, the low power filter is enabled in both
|
||||
* Active and Low power modes, the reset filter is only enabled in Active mode. When both filers
|
||||
* are enabled, they operate in series.
|
||||
*
|
||||
* param base CMC peripheral base address.
|
||||
* param config Pointer to the reset pin config structure.
|
||||
*/
|
||||
void CMC_ConfigResetPin(CMC_Type *base, const cmc_reset_pin_config_t *config)
|
||||
{
|
||||
assert(config != NULL);
|
||||
|
||||
uint32_t reg = base->RPC;
|
||||
|
||||
if (config->lowpowerFilterEnable)
|
||||
{
|
||||
reg |= CMC_RPC_LPFEN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
reg &= ~CMC_RPC_LPFEN_MASK;
|
||||
}
|
||||
if (config->resetFilterEnable)
|
||||
{
|
||||
reg |= (CMC_RPC_FILTEN_MASK | CMC_RPC_FILTCFG(config->resetFilterWidth));
|
||||
}
|
||||
else
|
||||
{
|
||||
reg &= ~(CMC_RPC_FILTEN_MASK | CMC_RPC_FILTCFG_MASK);
|
||||
}
|
||||
base->RPC = reg;
|
||||
}
|
||||
|
||||
#if (defined(FSL_FEATURE_MCX_CMC_HAS_SRAM_DIS_REG) && FSL_FEATURE_MCX_CMC_HAS_SRAM_DIS_REG)
|
||||
/*!
|
||||
* brief Power off the selected system SRAM always.
|
||||
*
|
||||
* This function powers off the selected system SRAM always. The SRAM arrays should
|
||||
* not be accessed while they are shut down. SRAM array contents are not retained
|
||||
* if they are powered off.
|
||||
*
|
||||
* param base CMC peripheral base address.
|
||||
* param mask Bitmap of the SRAM arrays to be powered off all modes.
|
||||
*/
|
||||
void CMC_PowerOffSRAMAllMode(CMC_Type *base, uint32_t mask)
|
||||
{
|
||||
uint32_t reg = base->SRAMDIS[0];
|
||||
|
||||
reg &= ~(CMC_SRAMDIS_DIS_MASK | CMC_SRAMDIS_RESERVED_MASK);
|
||||
reg |= CMC_SRAMDIS_DIS(mask);
|
||||
base->SRAMDIS[0] = reg;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Power off the selected system SRAm during low power mode only.
|
||||
*
|
||||
* This function powers off the selected system SRAM only during low power mode.
|
||||
* SRAM array contents are not retained if they are power off.
|
||||
*
|
||||
* param base CMC peripheral base address.
|
||||
* param mask Bitmap of the SRAM arrays to be power off during low power mode only.
|
||||
*/
|
||||
void CMC_PowerOffSRAMLowPowerOnly(CMC_Type *base, uint32_t mask)
|
||||
{
|
||||
uint32_t reg = base->SRAMRET[0];
|
||||
|
||||
reg &= ~(CMC_SRAMRET_RET_MASK | CMC_SRAMRET_RESERVED_MASK);
|
||||
reg |= CMC_SRAMRET_RET(mask);
|
||||
base->SRAMRET[0] = reg;
|
||||
}
|
||||
#endif /* FSL_FEATURE_MCX_CMC_HAS_SRAM_DIS_REG */
|
||||
|
||||
#if (defined(FSL_FEATURE_MCX_CMC_HAS_NO_FLASHCR_WAKE) && FSL_FEATURE_MCX_CMC_HAS_NO_FLASHCR_WAKE)
|
||||
/*!
|
||||
* brief Configs the low power mode of the on-chip flash memory.
|
||||
*
|
||||
* This function configs the low power mode of the on-chip flash memory.
|
||||
*
|
||||
* param base CMC peripheral base address.
|
||||
* param doze true: Flash is disabled while core is sleeping
|
||||
* false: No effect.
|
||||
* param disable true: Flash memory is placed in low power state.
|
||||
* false: No effect.
|
||||
*/
|
||||
void CMC_ConfigFlashMode(CMC_Type *base, bool doze, bool disable)
|
||||
{
|
||||
uint32_t reg = 0UL;
|
||||
|
||||
reg |= (disable ? CMC_FLASHCR_FLASHDIS(1U) : CMC_FLASHCR_FLASHDIS(0U)) |
|
||||
(doze ? CMC_FLASHCR_FLASHDOZE(1U) : CMC_FLASHCR_FLASHDOZE(0U));
|
||||
base->FLASHCR = reg;
|
||||
}
|
||||
#else
|
||||
/*!
|
||||
* brief Configs the low power mode of the on-chip flash memory.
|
||||
*
|
||||
* This function config the low power mode of the on-chip flash memory.
|
||||
*
|
||||
* param base CMC peripheral base address.
|
||||
* param wake
|
||||
* true - Flash will exit low power state during the flash memory accesses.
|
||||
* false - No effect.
|
||||
* param doze
|
||||
* true - Flash is disabled while core is sleeping
|
||||
* false - No effect.
|
||||
* param disable
|
||||
* true - Flash memory is placed in low power state.
|
||||
* false - No effect.
|
||||
*/
|
||||
void CMC_ConfigFlashMode(CMC_Type *base, bool wake, bool doze, bool disable)
|
||||
{
|
||||
uint32_t reg = 0UL;
|
||||
|
||||
reg |= (disable ? CMC_FLASHCR_FLASHDIS(1U) : CMC_FLASHCR_FLASHDIS(0U)) |
|
||||
(doze ? CMC_FLASHCR_FLASHDOZE(1U) : CMC_FLASHCR_FLASHDOZE(0U)) |
|
||||
(wake ? CMC_FLASHCR_FLASHWAKE(1U) : CMC_FLASHCR_FLASHWAKE(0U));
|
||||
base->FLASHCR = reg;
|
||||
}
|
||||
#endif /* FSL_FEATURE_MCX_CMC_HAS_NO_FLASHCR_WAKE */
|
||||
|
||||
/*!
|
||||
* brief Prepares to enter stop modes.
|
||||
*
|
||||
* This function should be called before entering low power modes.
|
||||
*
|
||||
*/
|
||||
void CMC_PreEnterLowPowerMode(void)
|
||||
{
|
||||
g_savedPrimask = DisableGlobalIRQ();
|
||||
__ISB();
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Recovers after wake up from stop modes.
|
||||
*
|
||||
* This function should be called after waking up from low power modes.
|
||||
* This function should be used with CMC_PreEnterLowPowerMode()
|
||||
*
|
||||
*/
|
||||
void CMC_PostExitLowPowerMode(void)
|
||||
{
|
||||
EnableGlobalIRQ(g_savedPrimask);
|
||||
__ISB();
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Configs the entry into the same low power mode for each power domains.
|
||||
*
|
||||
* This function provides the feature to entry into the same low power mode for each power
|
||||
* domains. Before invoking this function, please ensure the selected power mode have been allowed.
|
||||
*
|
||||
* param base CMC peripheral base address.
|
||||
* param lowPowerMode The low power mode to be entered. See @ref cmc_low_power_mode_t for the details.
|
||||
*
|
||||
*/
|
||||
void CMC_GlobalEnterLowPowerMode(CMC_Type *base, cmc_low_power_mode_t lowPowerMode)
|
||||
{
|
||||
/* Note: unlock the CKCTRL register if this API will be reinvoked later. */
|
||||
CMC_SetClockMode(base, kCMC_GateAllSystemClocksEnterLowPowerMode);
|
||||
CMC_SetGlobalPowerMode(base, lowPowerMode);
|
||||
/* Before executing WFI instruction read back the last register to
|
||||
* ensure all registers writes have completed. */
|
||||
(void)base->GPMCTRL;
|
||||
/* Set the core into DeepSleep mode. */
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
__DSB();
|
||||
__WFI();
|
||||
__ISB();
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Configs the entry into different low power modes for each of the power domains.
|
||||
*
|
||||
* This function provides the feature to entry into different low power modes for
|
||||
* each power domains. Before invoking this function please ensure the selected
|
||||
* modes are allowed.
|
||||
*
|
||||
* param base CMC peripheral base address.
|
||||
* param base config Pointer to the cmc_power_domain_config_t structure.
|
||||
*/
|
||||
void CMC_EnterLowPowerMode(CMC_Type *base, const cmc_power_domain_config_t *config)
|
||||
{
|
||||
assert(config != NULL);
|
||||
|
||||
#if (CMC_PMCTRL_COUNT > 1U)
|
||||
/* The WAKE domain must never be configured to a lower power mode compared with main power mode. */
|
||||
assert(config->wake_domain <= config->main_domain);
|
||||
#endif /* (CMC_PMCTRL_COUNT > 1U) */
|
||||
|
||||
if (config->clock_mode < kCMC_GateAllSystemClocksEnterLowPowerMode)
|
||||
{
|
||||
/* In This case the power domain doesn't need to be placed in low power state. */
|
||||
/* Note: unlock the register if this API will be reinvoked later. */
|
||||
CMC_SetClockMode(base, config->clock_mode);
|
||||
|
||||
CMC_SetMAINPowerMode(base, kCMC_ActiveOrSleepMode);
|
||||
#if (CMC_PMCTRL_COUNT > 1U)
|
||||
CMC_SetWAKEPowerMode(base, kCMC_ActiveOrSleepMode);
|
||||
#endif /* (CMC_PMCTRL_COUNT > 1U) */
|
||||
|
||||
/* Before executing WFI instruction read back the last register to
|
||||
* ensure all registers writes have completed. */
|
||||
(void)base->CKCTRL;
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
__DSB();
|
||||
__WFI();
|
||||
__ISB();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Note: unlock the register if this API will be reinvoked later. */
|
||||
CMC_SetClockMode(base, kCMC_GateAllSystemClocksEnterLowPowerMode);
|
||||
CMC_SetMAINPowerMode(base, config->main_domain);
|
||||
#if (CMC_PMCTRL_COUNT > 1U)
|
||||
CMC_SetWAKEPowerMode(base, config->wake_domain);
|
||||
#endif /* (CMC_PMCTRL_COUNT > 1U) */
|
||||
|
||||
/* Before execute WFI instruction read back the last register to
|
||||
* ensure all registers writes have completed. */
|
||||
#if (CMC_PMCTRL_COUNT > 1U)
|
||||
if ((CMC_GetWAKEPowerMode(base) == config->wake_domain) && (CMC_GetMAINPowerMode(base) == config->main_domain))
|
||||
{
|
||||
#endif /* (CMC_PMCTRL_COUNT > 1U) */
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
__DSB();
|
||||
__WFI();
|
||||
__ISB();
|
||||
#if (CMC_PMCTRL_COUNT > 1U)
|
||||
}
|
||||
#endif /* (CMC_PMCTRL_COUNT > 1U) */
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2021 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
#define SDK_MEM_MAGIC_NUMBER 12345U
|
||||
|
||||
typedef struct _mem_align_control_block
|
||||
{
|
||||
uint16_t identifier; /*!< Identifier for the memory control block. */
|
||||
uint16_t offset; /*!< offset from aligned address to real address */
|
||||
} mem_align_cb_t;
|
||||
|
||||
/* Component ID definition, used by tools. */
|
||||
#ifndef FSL_COMPONENT_ID
|
||||
#define FSL_COMPONENT_ID "platform.drivers.common"
|
||||
#endif
|
||||
|
||||
#if !((defined(__DSC__) && defined(__CW__)))
|
||||
void *SDK_Malloc(size_t size, size_t alignbytes)
|
||||
{
|
||||
mem_align_cb_t *p_cb = NULL;
|
||||
uint32_t alignedsize;
|
||||
|
||||
/* Check overflow. */
|
||||
alignedsize = (uint32_t)(unsigned int)SDK_SIZEALIGN(size, alignbytes);
|
||||
if (alignedsize < size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (alignedsize > SIZE_MAX - alignbytes - sizeof(mem_align_cb_t))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
alignedsize += alignbytes + (uint32_t)sizeof(mem_align_cb_t);
|
||||
|
||||
union
|
||||
{
|
||||
void *pointer_value;
|
||||
uintptr_t unsigned_value;
|
||||
} p_align_addr, p_addr;
|
||||
|
||||
p_addr.pointer_value = malloc((size_t)alignedsize);
|
||||
|
||||
if (p_addr.pointer_value == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p_align_addr.unsigned_value = SDK_SIZEALIGN(p_addr.unsigned_value + sizeof(mem_align_cb_t), alignbytes);
|
||||
|
||||
p_cb = (mem_align_cb_t *)(p_align_addr.unsigned_value - 4U);
|
||||
p_cb->identifier = SDK_MEM_MAGIC_NUMBER;
|
||||
p_cb->offset = (uint16_t)(p_align_addr.unsigned_value - p_addr.unsigned_value);
|
||||
|
||||
return p_align_addr.pointer_value;
|
||||
}
|
||||
|
||||
void SDK_Free(void *ptr)
|
||||
{
|
||||
union
|
||||
{
|
||||
void *pointer_value;
|
||||
uintptr_t unsigned_value;
|
||||
} p_free;
|
||||
p_free.pointer_value = ptr;
|
||||
mem_align_cb_t *p_cb = (mem_align_cb_t *)(p_free.unsigned_value - 4U);
|
||||
|
||||
if (p_cb->identifier != SDK_MEM_MAGIC_NUMBER)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
p_free.unsigned_value = p_free.unsigned_value - p_cb->offset;
|
||||
|
||||
free(p_free.pointer_value);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2022 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef FSL_COMMON_H_
|
||||
#define FSL_COMMON_H_
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(__ICCARM__) || (defined(__CC_ARM) || defined(__ARMCC_VERSION)) || defined(__GNUC__)
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
#include "fsl_device_registers.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup ksdk_common
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Configurations
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief Macro to use the default weak IRQ handler in drivers. */
|
||||
#ifndef FSL_DRIVER_TRANSFER_DOUBLE_WEAK_IRQ
|
||||
#define FSL_DRIVER_TRANSFER_DOUBLE_WEAK_IRQ 1
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief Construct a status code value from a group and code number. */
|
||||
#define MAKE_STATUS(group, code) ((((group)*100L) + (code)))
|
||||
|
||||
/*! @brief Construct the version number for drivers.
|
||||
*
|
||||
* The driver version is a 32-bit number, for both 32-bit platforms(such as Cortex M)
|
||||
* and 16-bit platforms(such as DSC).
|
||||
*
|
||||
* @verbatim
|
||||
|
||||
| Unused || Major Version || Minor Version || Bug Fix |
|
||||
31 25 24 17 16 9 8 0
|
||||
|
||||
@endverbatim
|
||||
*/
|
||||
#define MAKE_VERSION(major, minor, bugfix) (((major)*65536L) + ((minor)*256L) + (bugfix))
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief common driver version. */
|
||||
#define FSL_COMMON_DRIVER_VERSION (MAKE_VERSION(2, 4, 0))
|
||||
/*@}*/
|
||||
|
||||
/* Debug console type definition. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_NONE 0U /*!< No debug console. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_UART 1U /*!< Debug console based on UART. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_LPUART 2U /*!< Debug console based on LPUART. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_LPSCI 3U /*!< Debug console based on LPSCI. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_USBCDC 4U /*!< Debug console based on USBCDC. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_FLEXCOMM 5U /*!< Debug console based on FLEXCOMM. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_IUART 6U /*!< Debug console based on i.MX UART. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_VUSART 7U /*!< Debug console based on LPC_VUSART. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_MINI_USART 8U /*!< Debug console based on LPC_USART. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_SWO 9U /*!< Debug console based on SWO. */
|
||||
#define DEBUG_CONSOLE_DEVICE_TYPE_QSCI 10U /*!< Debug console based on QSCI. */
|
||||
|
||||
/*! @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_FLEXIO_MCULCD = 24, /*!< Group number for FLEXIO LCD status codes */
|
||||
kStatusGroup_FLASHIAP = 25, /*!< Group number for FLASHIAP status codes */
|
||||
kStatusGroup_FLEXCOMM_I2C = 26, /*!< Group number for FLEXCOMM I2C status codes */
|
||||
kStatusGroup_I2S = 27, /*!< Group number for I2S status codes */
|
||||
kStatusGroup_IUART = 28, /*!< Group number for IUART status codes */
|
||||
kStatusGroup_CSI = 29, /*!< Group number for CSI status codes */
|
||||
kStatusGroup_MIPI_DSI = 30, /*!< Group number for MIPI DSI 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_LPC_SPI = 56, /*!< Group number for LPC_SPI status codes. */
|
||||
kStatusGroup_LPC_USART = 57, /*!< Group number for LPC_USART status codes. */
|
||||
kStatusGroup_DMIC = 58, /*!< Group number for DMIC status codes. */
|
||||
kStatusGroup_SDIF = 59, /*!< Group number for SDIF status codes.*/
|
||||
kStatusGroup_SPIFI = 60, /*!< Group number for SPIFI status codes. */
|
||||
kStatusGroup_OTP = 61, /*!< Group number for OTP status codes. */
|
||||
kStatusGroup_MCAN = 62, /*!< Group number for MCAN status codes. */
|
||||
kStatusGroup_CAAM = 63, /*!< Group number for CAAM status codes. */
|
||||
kStatusGroup_ECSPI = 64, /*!< Group number for ECSPI status codes. */
|
||||
kStatusGroup_USDHC = 65, /*!< Group number for USDHC status codes.*/
|
||||
kStatusGroup_LPC_I2C = 66, /*!< Group number for LPC_I2C status codes.*/
|
||||
kStatusGroup_DCP = 67, /*!< Group number for DCP status codes.*/
|
||||
kStatusGroup_MSCAN = 68, /*!< Group number for MSCAN status codes.*/
|
||||
kStatusGroup_ESAI = 69, /*!< Group number for ESAI status codes. */
|
||||
kStatusGroup_FLEXSPI = 70, /*!< Group number for FLEXSPI status codes. */
|
||||
kStatusGroup_MMDC = 71, /*!< Group number for MMDC status codes. */
|
||||
kStatusGroup_PDM = 72, /*!< Group number for MIC status codes. */
|
||||
kStatusGroup_SDMA = 73, /*!< Group number for SDMA status codes. */
|
||||
kStatusGroup_ICS = 74, /*!< Group number for ICS status codes. */
|
||||
kStatusGroup_SPDIF = 75, /*!< Group number for SPDIF status codes. */
|
||||
kStatusGroup_LPC_MINISPI = 76, /*!< Group number for LPC_MINISPI status codes. */
|
||||
kStatusGroup_HASHCRYPT = 77, /*!< Group number for Hashcrypt status codes */
|
||||
kStatusGroup_LPC_SPI_SSP = 78, /*!< Group number for LPC_SPI_SSP status codes. */
|
||||
kStatusGroup_I3C = 79, /*!< Group number for I3C status codes */
|
||||
kStatusGroup_LPC_I2C_1 = 97, /*!< Group number for LPC_I2C_1 status codes. */
|
||||
kStatusGroup_NOTIFIER = 98, /*!< Group number for NOTIFIER status codes. */
|
||||
kStatusGroup_DebugConsole = 99, /*!< Group number for debug console status codes. */
|
||||
kStatusGroup_SEMC = 100, /*!< Group number for SEMC status codes. */
|
||||
kStatusGroup_ApplicationRangeStart = 101, /*!< Starting number for application groups. */
|
||||
kStatusGroup_IAP = 102, /*!< Group number for IAP status codes */
|
||||
kStatusGroup_SFA = 103, /*!< Group number for SFA status codes*/
|
||||
kStatusGroup_SPC = 104, /*!< Group number for SPC status codes. */
|
||||
kStatusGroup_PUF = 105, /*!< Group number for PUF status codes. */
|
||||
kStatusGroup_TOUCH_PANEL = 106, /*!< Group number for touch panel status codes */
|
||||
kStatusGroup_VBAT = 107, /*!< Group number for VBAT status codes */
|
||||
|
||||
kStatusGroup_HAL_GPIO = 121, /*!< Group number for HAL GPIO status codes. */
|
||||
kStatusGroup_HAL_UART = 122, /*!< Group number for HAL UART status codes. */
|
||||
kStatusGroup_HAL_TIMER = 123, /*!< Group number for HAL TIMER status codes. */
|
||||
kStatusGroup_HAL_SPI = 124, /*!< Group number for HAL SPI status codes. */
|
||||
kStatusGroup_HAL_I2C = 125, /*!< Group number for HAL I2C status codes. */
|
||||
kStatusGroup_HAL_FLASH = 126, /*!< Group number for HAL FLASH status codes. */
|
||||
kStatusGroup_HAL_PWM = 127, /*!< Group number for HAL PWM status codes. */
|
||||
kStatusGroup_HAL_RNG = 128, /*!< Group number for HAL RNG status codes. */
|
||||
kStatusGroup_HAL_I2S = 129, /*!< Group number for HAL I2S status codes. */
|
||||
kStatusGroup_HAL_ADC_SENSOR = 130, /*!< Group number for HAL ADC SENSOR status codes. */
|
||||
kStatusGroup_TIMERMANAGER = 135, /*!< Group number for TiMER MANAGER status codes. */
|
||||
kStatusGroup_SERIALMANAGER = 136, /*!< Group number for SERIAL MANAGER status codes. */
|
||||
kStatusGroup_LED = 137, /*!< Group number for LED status codes. */
|
||||
kStatusGroup_BUTTON = 138, /*!< Group number for BUTTON status codes. */
|
||||
kStatusGroup_EXTERN_EEPROM = 139, /*!< Group number for EXTERN EEPROM status codes. */
|
||||
kStatusGroup_SHELL = 140, /*!< Group number for SHELL status codes. */
|
||||
kStatusGroup_MEM_MANAGER = 141, /*!< Group number for MEM MANAGER status codes. */
|
||||
kStatusGroup_LIST = 142, /*!< Group number for List status codes. */
|
||||
kStatusGroup_OSA = 143, /*!< Group number for OSA status codes. */
|
||||
kStatusGroup_COMMON_TASK = 144, /*!< Group number for Common task status codes. */
|
||||
kStatusGroup_MSG = 145, /*!< Group number for messaging status codes. */
|
||||
kStatusGroup_SDK_OCOTP = 146, /*!< Group number for OCOTP status codes. */
|
||||
kStatusGroup_SDK_FLEXSPINOR = 147, /*!< Group number for FLEXSPINOR status codes.*/
|
||||
kStatusGroup_CODEC = 148, /*!< Group number for codec status codes. */
|
||||
kStatusGroup_ASRC = 149, /*!< Group number for codec status ASRC. */
|
||||
kStatusGroup_OTFAD = 150, /*!< Group number for codec status codes. */
|
||||
kStatusGroup_SDIOSLV = 151, /*!< Group number for SDIOSLV status codes. */
|
||||
kStatusGroup_MECC = 152, /*!< Group number for MECC status codes. */
|
||||
kStatusGroup_ENET_QOS = 153, /*!< Group number for ENET_QOS status codes. */
|
||||
kStatusGroup_LOG = 154, /*!< Group number for LOG status codes. */
|
||||
kStatusGroup_I3CBUS = 155, /*!< Group number for I3CBUS status codes. */
|
||||
kStatusGroup_QSCI = 156, /*!< Group number for QSCI status codes. */
|
||||
kStatusGroup_ELEMU = 157, /*!< Group number for ELEMU status codes. */
|
||||
kStatusGroup_QUEUEDSPI = 158, /*!< Group number for QSPI status codes. */
|
||||
kStatusGroup_POWER_MANAGER = 159, /*!< Group number for POWER_MANAGER status codes. */
|
||||
kStatusGroup_IPED = 160, /*!< Group number for IPED status codes. */
|
||||
kStatusGroup_ELS_PKC = 161, /*!< Group number for ELS PKC status codes. */
|
||||
kStatusGroup_CSS_PKC = 162, /*!< Group number for CSS PKC status codes. */
|
||||
kStatusGroup_HOSTIF = 163, /*!< Group number for HOSTIF status codes. */
|
||||
kStatusGroup_CLIF = 164, /*!< Group number for CLIF status codes. */
|
||||
kStatusGroup_BMA = 165, /*!< Group number for BMA status codes. */
|
||||
kStatusGroup_NETC = 166, /*!< Group number for NETC status codes. */
|
||||
kStatusGroup_ELE = 167, /*!< Group number for ELE status codes. */
|
||||
};
|
||||
|
||||
/*! \public
|
||||
* @brief Generic status return codes.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
kStatus_Success = MAKE_STATUS(kStatusGroup_Generic, 0), /*!< Generic status for Success. */
|
||||
kStatus_Fail = MAKE_STATUS(kStatusGroup_Generic, 1), /*!< Generic status for Fail. */
|
||||
kStatus_ReadOnly = MAKE_STATUS(kStatusGroup_Generic, 2), /*!< Generic status for read only failure. */
|
||||
kStatus_OutOfRange = MAKE_STATUS(kStatusGroup_Generic, 3), /*!< Generic status for out of range access. */
|
||||
kStatus_InvalidArgument = MAKE_STATUS(kStatusGroup_Generic, 4), /*!< Generic status for invalid argument check. */
|
||||
kStatus_Timeout = MAKE_STATUS(kStatusGroup_Generic, 5), /*!< Generic status for timeout. */
|
||||
kStatus_NoTransferInProgress =
|
||||
MAKE_STATUS(kStatusGroup_Generic, 6), /*!< Generic status for no transfer in progress. */
|
||||
kStatus_Busy = MAKE_STATUS(kStatusGroup_Generic, 7), /*!< Generic status for module is busy. */
|
||||
kStatus_NoData =
|
||||
MAKE_STATUS(kStatusGroup_Generic, 8), /*!< Generic status for no data is found for the operation. */
|
||||
};
|
||||
|
||||
/*! @brief Type used for all status and error return values. */
|
||||
typedef int32_t status_t;
|
||||
|
||||
/*!
|
||||
* @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. */
|
||||
#if !defined(ARRAY_SIZE)
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
#endif
|
||||
|
||||
/*! @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 Suppress fallthrough warning macro */
|
||||
/* For switch case code block, if case section ends without "break;" statement, there wil be
|
||||
fallthrough warning with compiler flag -Wextra or -Wimplicit-fallthrough=n when using armgcc.
|
||||
To suppress this warning, "SUPPRESS_FALL_THROUGH_WARNING();" need to be added at the end of each
|
||||
case section which misses "break;"statement.
|
||||
*/
|
||||
/* @{ */
|
||||
#if defined(__GNUC__) && !defined(__ARMCC_VERSION)
|
||||
#define SUPPRESS_FALL_THROUGH_WARNING() __attribute__((fallthrough))
|
||||
#else
|
||||
#define SUPPRESS_FALL_THROUGH_WARNING()
|
||||
#endif
|
||||
/* @} */
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !((defined(__DSC__) && defined(__CW__)))
|
||||
/*!
|
||||
* @brief Allocate memory with given alignment and aligned size.
|
||||
*
|
||||
* This is provided to support the dynamically allocated memory
|
||||
* used in cache-able region.
|
||||
* @param size The length required to malloc.
|
||||
* @param alignbytes The alignment size.
|
||||
* @retval The allocated memory.
|
||||
*/
|
||||
void *SDK_Malloc(size_t size, size_t alignbytes);
|
||||
|
||||
/*!
|
||||
* @brief Free memory.
|
||||
*
|
||||
* @param ptr The memory to be release.
|
||||
*/
|
||||
void SDK_Free(void *ptr);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Delay at least for some time.
|
||||
* Please note that, this API uses while loop for delay, different run-time environments make the time not precise,
|
||||
* if precise delay count was needed, please implement a new delay function with hardware timer.
|
||||
*
|
||||
* @param delayTime_us Delay time in unit of microsecond.
|
||||
* @param coreClock_Hz Core clock frequency with Hz.
|
||||
*/
|
||||
void SDK_DelayAtLeastUs(uint32_t delayTime_us, uint32_t coreClock_Hz);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @} */
|
||||
|
||||
#if (defined(__DSC__) && defined(__CW__))
|
||||
#include "fsl_common_dsc.h"
|
||||
#elif defined(__XTENSA__)
|
||||
#include "fsl_common_dsp.h"
|
||||
#else
|
||||
#include "fsl_common_arm.h"
|
||||
#endif
|
||||
|
||||
#endif /* FSL_COMMON_H_ */
|
||||
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2021 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/* Component ID definition, used by tools. */
|
||||
#ifndef FSL_COMPONENT_ID
|
||||
#define FSL_COMPONENT_ID "platform.drivers.common_arm"
|
||||
#endif
|
||||
|
||||
#ifndef __GIC_PRIO_BITS
|
||||
#if defined(ENABLE_RAM_VECTOR_TABLE)
|
||||
uint32_t InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler)
|
||||
{
|
||||
#ifdef __VECTOR_TABLE
|
||||
#undef __VECTOR_TABLE
|
||||
#endif
|
||||
|
||||
/* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */
|
||||
#if defined(__CC_ARM) || defined(__ARMCC_VERSION)
|
||||
extern uint32_t Image$$VECTOR_ROM$$Base[];
|
||||
extern uint32_t Image$$VECTOR_RAM$$Base[];
|
||||
extern uint32_t Image$$VECTOR_RAM$$ZI$$Limit[];
|
||||
|
||||
#define __VECTOR_TABLE Image$$VECTOR_ROM$$Base
|
||||
#define __VECTOR_RAM Image$$VECTOR_RAM$$Base
|
||||
#define __RAM_VECTOR_TABLE_SIZE (((uint32_t)Image$$VECTOR_RAM$$ZI$$Limit - (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) || defined(__ARMCC_VERSION) */
|
||||
uint32_t n;
|
||||
uint32_t ret;
|
||||
uint32_t irqMaskValue;
|
||||
|
||||
irqMaskValue = DisableGlobalIRQ();
|
||||
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;
|
||||
}
|
||||
|
||||
ret = __VECTOR_RAM[(int32_t)irq + 16];
|
||||
/* make sure the __VECTOR_RAM is noncachable */
|
||||
__VECTOR_RAM[(int32_t)irq + 16] = irqHandler;
|
||||
|
||||
EnableGlobalIRQ(irqMaskValue);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* ENABLE_RAM_VECTOR_TABLE. */
|
||||
#endif /* __GIC_PRIO_BITS. */
|
||||
|
||||
#if (defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0))
|
||||
|
||||
/*
|
||||
* When FSL_FEATURE_POWERLIB_EXTEND is defined to non-zero value,
|
||||
* powerlib should be used instead of these functions.
|
||||
*/
|
||||
#if !(defined(FSL_FEATURE_POWERLIB_EXTEND) && (FSL_FEATURE_POWERLIB_EXTEND != 0))
|
||||
|
||||
/*
|
||||
* When the SYSCON STARTER registers are discontinuous, these functions are
|
||||
* implemented in fsl_power.c.
|
||||
*/
|
||||
#if !(defined(FSL_FEATURE_SYSCON_STARTER_DISCONTINUOUS) && FSL_FEATURE_SYSCON_STARTER_DISCONTINUOUS)
|
||||
|
||||
void EnableDeepSleepIRQ(IRQn_Type interrupt)
|
||||
{
|
||||
uint32_t intNumber = (uint32_t)interrupt;
|
||||
|
||||
uint32_t index = 0;
|
||||
|
||||
while (intNumber >= 32u)
|
||||
{
|
||||
index++;
|
||||
intNumber -= 32u;
|
||||
}
|
||||
|
||||
SYSCON->STARTERSET[index] = 1UL << intNumber;
|
||||
(void)EnableIRQ(interrupt); /* also enable interrupt at NVIC */
|
||||
}
|
||||
|
||||
void DisableDeepSleepIRQ(IRQn_Type interrupt)
|
||||
{
|
||||
uint32_t intNumber = (uint32_t)interrupt;
|
||||
|
||||
(void)DisableIRQ(interrupt); /* also disable interrupt at NVIC */
|
||||
uint32_t index = 0;
|
||||
|
||||
while (intNumber >= 32u)
|
||||
{
|
||||
index++;
|
||||
intNumber -= 32u;
|
||||
}
|
||||
|
||||
SYSCON->STARTERCLR[index] = 1UL << intNumber;
|
||||
}
|
||||
#endif /* FSL_FEATURE_SYSCON_STARTER_DISCONTINUOUS */
|
||||
#endif /* FSL_FEATURE_POWERLIB_EXTEND */
|
||||
#endif /* FSL_FEATURE_SOC_SYSCON_COUNT */
|
||||
|
||||
#if defined(DWT)
|
||||
/* Use WDT. */
|
||||
void MSDK_EnableCpuCycleCounter(void)
|
||||
{
|
||||
/* Make sure the DWT trace fucntion is enabled. */
|
||||
if (CoreDebug_DEMCR_TRCENA_Msk != (CoreDebug_DEMCR_TRCENA_Msk & CoreDebug->DEMCR))
|
||||
{
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
}
|
||||
|
||||
/* CYCCNT not supported on this device. */
|
||||
assert(DWT_CTRL_NOCYCCNT_Msk != (DWT->CTRL & DWT_CTRL_NOCYCCNT_Msk));
|
||||
|
||||
/* Read CYCCNT directly if CYCCENT has already been enabled, otherwise enable CYCCENT first. */
|
||||
if (DWT_CTRL_CYCCNTENA_Msk != (DWT_CTRL_CYCCNTENA_Msk & DWT->CTRL))
|
||||
{
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t MSDK_GetCpuCycleCount(void)
|
||||
{
|
||||
return DWT->CYCCNT;
|
||||
}
|
||||
#endif /* defined(DWT) */
|
||||
|
||||
#if !(defined(SDK_DELAY_USE_DWT) && defined(DWT))
|
||||
/* Use software loop. */
|
||||
#if defined(__CC_ARM) /* This macro is arm v5 specific */
|
||||
/* clang-format off */
|
||||
__ASM static void DelayLoop(uint32_t count)
|
||||
{
|
||||
loop
|
||||
SUBS R0, R0, #1
|
||||
CMP R0, #0
|
||||
BNE loop
|
||||
BX LR
|
||||
}
|
||||
#elif defined(__ARM_ARCH_8A__) /* This macro is ARMv8-A specific */
|
||||
static void DelayLoop(uint32_t count)
|
||||
{
|
||||
__ASM volatile(" MOV X0, %0" : : "r"(count));
|
||||
__ASM volatile(
|
||||
"loop: \n"
|
||||
" SUB X0, X0, #1 \n"
|
||||
" CMP X0, #0 \n"
|
||||
|
||||
" BNE loop \n"
|
||||
:
|
||||
:
|
||||
: "r0");
|
||||
}
|
||||
/* clang-format on */
|
||||
#elif defined(__ARMCC_VERSION) || defined(__ICCARM__) || defined(__GNUC__)
|
||||
/* Cortex-M0 has a smaller instruction set, SUBS isn't supported in thumb-16 mode reported from __GNUC__ compiler,
|
||||
* use SUB and CMP here for compatibility */
|
||||
static void DelayLoop(uint32_t count)
|
||||
{
|
||||
__ASM volatile(" MOV R0, %0" : : "r"(count));
|
||||
__ASM volatile(
|
||||
"loop: \n"
|
||||
#if defined(__GNUC__) && !defined(__ARMCC_VERSION)
|
||||
" SUB R0, R0, #1 \n"
|
||||
#else
|
||||
" SUBS R0, R0, #1 \n"
|
||||
#endif
|
||||
" CMP R0, #0 \n"
|
||||
|
||||
" BNE loop \n"
|
||||
:
|
||||
:
|
||||
: "r0");
|
||||
}
|
||||
#endif /* defined(__CC_ARM) */
|
||||
#endif /* defined(SDK_DELAY_USE_DWT) && defined(DWT) */
|
||||
|
||||
/*!
|
||||
* @brief Delay at least for some time.
|
||||
* Please note that, if not uses DWT, this API will use while loop for delay, different run-time environments have
|
||||
* effect on the delay time. If precise delay is needed, please enable DWT delay. The two parmeters delayTime_us and
|
||||
* coreClock_Hz have limitation. For example, in the platform with 1GHz coreClock_Hz, the delayTime_us only supports
|
||||
* up to 4294967 in current code. If long time delay is needed, please implement a new delay function.
|
||||
*
|
||||
* @param delayTime_us Delay time in unit of microsecond.
|
||||
* @param coreClock_Hz Core clock frequency with Hz.
|
||||
*/
|
||||
void SDK_DelayAtLeastUs(uint32_t delayTime_us, uint32_t coreClock_Hz)
|
||||
{
|
||||
uint64_t count;
|
||||
|
||||
if (delayTime_us > 0U)
|
||||
{
|
||||
count = USEC_TO_COUNT(delayTime_us, coreClock_Hz);
|
||||
|
||||
assert(count <= UINT32_MAX);
|
||||
|
||||
#if defined(SDK_DELAY_USE_DWT) && defined(DWT) /* Use DWT for better accuracy */
|
||||
|
||||
MSDK_EnableCpuCycleCounter();
|
||||
/* Calculate the count ticks. */
|
||||
count += MSDK_GetCpuCycleCount();
|
||||
|
||||
if (count > UINT32_MAX)
|
||||
{
|
||||
count -= UINT32_MAX;
|
||||
/* Wait for cyccnt overflow. */
|
||||
while (count < MSDK_GetCpuCycleCount())
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait for cyccnt reach count value. */
|
||||
while (count > MSDK_GetCpuCycleCount())
|
||||
{
|
||||
}
|
||||
#else
|
||||
/* Divide value may be different in various environment to ensure delay is precise.
|
||||
* Every loop count includes three instructions, due to Cortex-M7 sometimes executes
|
||||
* two instructions in one period, through test here set divide 1.5. Other M cores use
|
||||
* divide 4. By the way, divide 1.5 or 4 could let the count lose precision, but it does
|
||||
* not matter because other instructions outside while loop is enough to fill the time.
|
||||
*/
|
||||
#if (__CORTEX_M == 7)
|
||||
count = count / 3U * 2U;
|
||||
#else
|
||||
count = count / 4U;
|
||||
#endif
|
||||
DelayLoop((uint32_t)count);
|
||||
#endif /* defined(SDK_DELAY_USE_DWT) && defined(DWT) */
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,371 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2017, 2020 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#include "fsl_crc.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/* Component ID definition, used by tools. */
|
||||
#ifndef FSL_COMPONENT_ID
|
||||
#define FSL_COMPONENT_ID "platform.drivers.crc"
|
||||
#endif
|
||||
|
||||
/*! @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
|
||||
|
||||
#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 */
|
||||
|
||||
#if defined(CRC_RSTS)
|
||||
#define CRC_RESETS_ARRAY CRC_RSTS
|
||||
#endif
|
||||
|
||||
/*! @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;
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
#if defined(CRC_RESETS_ARRAY)
|
||||
/*!
|
||||
* @brief Get instance number for CRC module.
|
||||
*
|
||||
* @param base CRC peripheral base address
|
||||
*/
|
||||
static uint32_t CRC_GetInstance(CRC_Type *base);
|
||||
#endif
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
#if defined(CRC_RESETS_ARRAY)
|
||||
static CRC_Type *const s_crcBases[] = CRC_BASE_PTRS;
|
||||
|
||||
/* Reset array */
|
||||
static const reset_ip_name_t s_crcResets[] = CRC_RESETS_ARRAY;
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
#if defined(CRC_RESETS_ARRAY)
|
||||
static uint32_t CRC_GetInstance(CRC_Type *base)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
/* Find the instance index from base address mappings. */
|
||||
for (instance = 0; instance < ARRAY_SIZE(s_crcBases); instance++)
|
||||
{
|
||||
if (s_crcBases[instance] == base)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(instance < ARRAY_SIZE(s_crcBases));
|
||||
|
||||
return instance;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @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 = 0U | 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);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Enables and configures the CRC peripheral module.
|
||||
*
|
||||
* This function enables the clock gate in the SIM module for the CRC peripheral.
|
||||
* It also configures the CRC module and starts a 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)
|
||||
{
|
||||
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
|
||||
/* ungate clock */
|
||||
CLOCK_EnableClock(kCLOCK_Crc0);
|
||||
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
|
||||
|
||||
#if defined(CRC_RESETS_ARRAY)
|
||||
RESET_ReleasePeripheralReset(s_crcResets[CRC_GetInstance(base)]);
|
||||
#endif
|
||||
|
||||
/* configure CRC module and write the seed */
|
||||
if (config->crcResult == kCrcFinalChecksum)
|
||||
{
|
||||
CRC_SetProtocolConfig(base, config);
|
||||
}
|
||||
else
|
||||
{
|
||||
CRC_SetRawProtocolConfig(base, config);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Loads default values to the CRC protocol configuration structure.
|
||||
*
|
||||
* Loads default values to the CRC protocol configuration structure. The default values are as follows.
|
||||
* 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)
|
||||
{
|
||||
/* Initializes the configure structure to zero. */
|
||||
(void)memset(config, 0, sizeof(*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;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Writes data to the CRC module.
|
||||
*
|
||||
* Writes input data buffer bytes to the 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)
|
||||
{
|
||||
const uint32_t *data32;
|
||||
|
||||
/* 8-bit reads and writes till source address is aligned 4 bytes */
|
||||
while ((0U != dataSize) && (0U != ((uint32_t)data & 3U)))
|
||||
{
|
||||
base->ACCESS8BIT.DATALL = *data;
|
||||
data++;
|
||||
dataSize--;
|
||||
}
|
||||
|
||||
/* use 32-bit reads and writes as long as possible */
|
||||
data32 = (const uint32_t *)(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 != 0U)
|
||||
{
|
||||
base->ACCESS8BIT.DATALL = *data;
|
||||
data++;
|
||||
dataSize--;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Reads the 32-bit checksum from the CRC module.
|
||||
*
|
||||
* Reads the CRC data register (either an intermediate or the final checksum).
|
||||
* The configured type of transpose and complement is applied.
|
||||
*
|
||||
* param base CRC peripheral address.
|
||||
* return An intermediate or the final 32-bit checksum, after configured transpose and complement operations.
|
||||
*/
|
||||
uint32_t CRC_Get32bitResult(CRC_Type *base)
|
||||
{
|
||||
return base->DATA;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Reads a 16-bit checksum from the CRC module.
|
||||
*
|
||||
* Reads the CRC data register (either an intermediate or the final checksum).
|
||||
* The configured type of transpose and complement is applied.
|
||||
*
|
||||
* param base CRC peripheral address.
|
||||
* return An intermediate or the final 16-bit checksum, after configured transpose and complement operations.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2017, 2020 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef FSL_CRC_H_
|
||||
#define FSL_CRC_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup crc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief CRC driver version. Version 2.0.4.
|
||||
*
|
||||
* Current version: 2.0.4
|
||||
*
|
||||
* Change log:
|
||||
*
|
||||
* - Version 2.0.4
|
||||
* - Release peripheral from reset if necessary in init function.
|
||||
*
|
||||
* - Version 2.0.3
|
||||
* - Fix MISRA issues
|
||||
*
|
||||
* - Version 2.0.2
|
||||
* - Fix MISRA issues
|
||||
*
|
||||
* - Version 2.0.1
|
||||
* - move DATA and DATALL macro definition from header file to source file
|
||||
*/
|
||||
#define FSL_CRC_DRIVER_VERSION (MAKE_VERSION(2, 0, 4))
|
||||
/*@}*/
|
||||
|
||||
#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 function enables the clock gate in the SIM module for the CRC peripheral.
|
||||
* It also configures the CRC module and starts a 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 function disables the clock gate in the SIM module for the CRC peripheral.
|
||||
*
|
||||
* @param base CRC peripheral address.
|
||||
*/
|
||||
static inline void CRC_Deinit(CRC_Type *base)
|
||||
{
|
||||
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
|
||||
/* gate clock */
|
||||
CLOCK_DisableClock(kCLOCK_Crc0);
|
||||
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Loads default values to the CRC protocol configuration structure.
|
||||
*
|
||||
* Loads default values to the CRC protocol configuration structure. The default values are as follows.
|
||||
* @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 the 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 the 32-bit checksum from the CRC module.
|
||||
*
|
||||
* Reads the CRC data register (either an intermediate or the final checksum).
|
||||
* The configured type of transpose and complement is applied.
|
||||
*
|
||||
* @param base CRC peripheral address.
|
||||
* @return An intermediate or the final 32-bit checksum, after configured transpose and complement operations.
|
||||
*/
|
||||
uint32_t CRC_Get32bitResult(CRC_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Reads a 16-bit checksum from the CRC module.
|
||||
*
|
||||
* Reads the CRC data register (either an intermediate or the final checksum).
|
||||
* The configured type of transpose and complement is applied.
|
||||
*
|
||||
* @param base CRC peripheral address.
|
||||
* @return An intermediate or the 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_ */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
* Copyright 2022 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#ifndef FSL_EDMA_CORE_H_
|
||||
#define FSL_EDMA_CORE_H_
|
||||
|
||||
#include "fsl_edma_soc.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup edma_core
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
#if defined(FSL_EDMA_SOC_IP_DMA3) && defined(FSL_EDMA_SOC_IP_DMA4) && FSL_EDMA_SOC_IP_DMA3 && FSL_EDMA_SOC_IP_DMA4
|
||||
#define DMA_CSR_INTMAJOR_MASK DMA_TCD_CSR_INTMAJOR_MASK
|
||||
#define DMA_CSR_INTHALF_MASK DMA_TCD_CSR_INTHALF_MASK
|
||||
#define DMA_CSR_DREQ_MASK DMA_TCD_CSR_DREQ_MASK
|
||||
#define DMA_CSR_ESG_MASK DMA_TCD_CSR_ESG_MASK
|
||||
#define DMA_CSR_BWC_MASK DMA_TCD_CSR_BWC_MASK
|
||||
#define DMA_CSR_BWC(x) DMA_TCD_CSR_BWC(x)
|
||||
#define DMA_CSR_START_MASK DMA_TCD_CSR_START_MASK
|
||||
#define DMA_CITER_ELINKNO_CITER_MASK DMA_TCD_CITER_ELINKNO_CITER_MASK
|
||||
#define DMA_BITER_ELINKNO_BITER_MASK DMA_TCD_BITER_ELINKNO_BITER_MASK
|
||||
#define DMA_CITER_ELINKNO_CITER_SHIFT DMA_TCD_CITER_ELINKNO_CITER_SHIFT
|
||||
#define DMA_CITER_ELINKYES_CITER_MASK DMA_TCD_CITER_ELINKYES_CITER_MASK
|
||||
#define DMA_CITER_ELINKYES_CITER_SHIFT DMA_TCD_CITER_ELINKYES_CITER_SHIFT
|
||||
#define DMA_ATTR_SMOD_MASK DMA_TCD_ATTR_SMOD_MASK
|
||||
#define DMA_ATTR_DMOD_MASK DMA_TCD_ATTR_DMOD_MASK
|
||||
#define DMA_CITER_ELINKNO_ELINK_MASK DMA_TCD_CITER_ELINKNO_ELINK_MASK
|
||||
#define DMA_CSR_MAJORELINK_MASK DMA_TCD_CSR_MAJORELINK_MASK
|
||||
#define DMA_BITER_ELINKYES_ELINK_MASK DMA_TCD_BITER_ELINKYES_ELINK_MASK
|
||||
#define DMA_CITER_ELINKYES_ELINK_MASK DMA_TCD_CITER_ELINKYES_ELINK_MASK
|
||||
#define DMA_CSR_MAJORLINKCH_MASK DMA_TCD_CSR_MAJORLINKCH_MASK
|
||||
#define DMA_BITER_ELINKYES_LINKCH_MASK DMA_TCD_BITER_ELINKYES_LINKCH_MASK
|
||||
#define DMA_CITER_ELINKYES_LINKCH_MASK DMA_TCD_CITER_ELINKYES_LINKCH_MASK
|
||||
#define DMA_NBYTES_MLOFFYES_MLOFF_MASK DMA_TCD_NBYTES_MLOFFYES_MLOFF_MASK
|
||||
#define DMA_NBYTES_MLOFFYES_DMLOE_MASK DMA_TCD_NBYTES_MLOFFYES_DMLOE_MASK
|
||||
#define DMA_NBYTES_MLOFFYES_SMLOE_MASK DMA_TCD_NBYTES_MLOFFYES_SMLOE_MASK
|
||||
#define DMA_NBYTES_MLOFFNO_NBYTES_MASK DMA_TCD_NBYTES_MLOFFNO_NBYTES_MASK
|
||||
#define DMA_ATTR_DMOD(x) DMA_TCD_ATTR_DMOD(x)
|
||||
#define DMA_ATTR_SMOD(X) DMA_TCD_ATTR_SMOD(X)
|
||||
#define DMA_BITER_ELINKYES_LINKCH(x) DMA_TCD_BITER_ELINKYES_LINKCH(x)
|
||||
#define DMA_CITER_ELINKYES_LINKCH(x) DMA_TCD_CITER_ELINKYES_LINKCH(x)
|
||||
#define DMA_NBYTES_MLOFFYES_MLOFF(x) DMA_TCD_NBYTES_MLOFFYES_MLOFF(x)
|
||||
#define DMA_NBYTES_MLOFFYES_DMLOE(x) DMA_TCD_NBYTES_MLOFFYES_DMLOE(x)
|
||||
#define DMA_NBYTES_MLOFFYES_SMLOE(x) DMA_TCD_NBYTES_MLOFFYES_SMLOE(x)
|
||||
#define DMA_NBYTES_MLOFFNO_NBYTES(x) DMA_TCD_NBYTES_MLOFFNO_NBYTES(x)
|
||||
#define DMA_NBYTES_MLOFFYES_NBYTES(x) DMA_TCD_NBYTES_MLOFFYES_NBYTES(x)
|
||||
#define DMA_ATTR_DSIZE(x) DMA_TCD_ATTR_DSIZE(x)
|
||||
#define DMA_ATTR_SSIZE(x) DMA_TCD_ATTR_SSIZE(x)
|
||||
#define DMA_CSR_DREQ(x) DMA_TCD_CSR_DREQ(x)
|
||||
#define DMA_CSR_MAJORLINKCH(x) DMA_TCD_CSR_MAJORLINKCH(x)
|
||||
#define DMA_CH_MATTR_WCACHE(x) DMA4_CH_MATTR_WCACHE(x)
|
||||
#define DMA_CH_MATTR_RCACHE(x) DMA4_CH_MATTR_RCACHE(x)
|
||||
#define DMA_CH_CSR_SIGNEXT_MASK DMA4_CH_CSR_SIGNEXT_MASK
|
||||
#define DMA_CH_CSR_SIGNEXT_SHIFT DMA4_CH_CSR_SIGNEXT_SHIFT
|
||||
#define DMA_CH_CSR_SWAP_MASK DMA4_CH_CSR_SWAP_MASK
|
||||
#define DMA_CH_CSR_SWAP_SHIFT DMA4_CH_CSR_SWAP_SHIFT
|
||||
#define DMA_CH_SBR_INSTR_MASK DMA4_CH_SBR_INSTR_MASK
|
||||
#define DMA_CH_SBR_INSTR_SHIFT DMA4_CH_SBR_INSTR_SHIFT
|
||||
#define DMA_CH_MUX_SOURCE(x) DMA4_CH_MUX_SRC(x)
|
||||
#elif defined(FSL_EDMA_SOC_IP_DMA3) && FSL_EDMA_SOC_IP_DMA3 && \
|
||||
(!defined(FSL_EDMA_SOC_IP_DMA4) || (defined(FSL_EDMA_SOC_IP_DMA4) && !FSL_EDMA_SOC_IP_DMA4))
|
||||
#define DMA_CSR_INTMAJOR_MASK DMA_TCD_CSR_INTMAJOR_MASK
|
||||
#define DMA_CSR_INTHALF_MASK DMA_TCD_CSR_INTHALF_MASK
|
||||
#define DMA_CSR_DREQ_MASK DMA_TCD_CSR_DREQ_MASK
|
||||
#define DMA_CSR_ESG_MASK DMA_TCD_CSR_ESG_MASK
|
||||
#define DMA_CSR_BWC_MASK DMA_TCD_CSR_BWC_MASK
|
||||
#define DMA_CSR_BWC(x) DMA_TCD_CSR_BWC(x)
|
||||
#define DMA_CSR_START_MASK DMA_TCD_CSR_START_MASK
|
||||
#define DMA_CITER_ELINKNO_CITER_MASK DMA_TCD_CITER_ELINKNO_CITER_MASK
|
||||
#define DMA_BITER_ELINKNO_BITER_MASK DMA_TCD_BITER_ELINKNO_BITER_MASK
|
||||
#define DMA_CITER_ELINKNO_CITER_SHIFT DMA_TCD_CITER_ELINKNO_CITER_SHIFT
|
||||
#define DMA_CITER_ELINKYES_CITER_MASK DMA_TCD_CITER_ELINKYES_CITER_MASK
|
||||
#define DMA_CITER_ELINKYES_CITER_SHIFT DMA_TCD_CITER_ELINKYES_CITER_SHIFT
|
||||
#define DMA_ATTR_SMOD_MASK DMA_TCD_ATTR_SMOD_MASK
|
||||
#define DMA_ATTR_DMOD_MASK DMA_TCD_ATTR_DMOD_MASK
|
||||
#define DMA_CITER_ELINKNO_ELINK_MASK DMA_TCD_CITER_ELINKNO_ELINK_MASK
|
||||
#define DMA_CSR_MAJORELINK_MASK DMA_TCD_CSR_MAJORELINK_MASK
|
||||
#define DMA_BITER_ELINKYES_ELINK_MASK DMA_TCD_BITER_ELINKYES_ELINK_MASK
|
||||
#define DMA_CITER_ELINKYES_ELINK_MASK DMA_TCD_CITER_ELINKYES_ELINK_MASK
|
||||
#define DMA_CSR_MAJORLINKCH_MASK DMA_TCD_CSR_MAJORLINKCH_MASK
|
||||
#define DMA_BITER_ELINKYES_LINKCH_MASK DMA_TCD_BITER_ELINKYES_LINKCH_MASK
|
||||
#define DMA_CITER_ELINKYES_LINKCH_MASK DMA_TCD_CITER_ELINKYES_LINKCH_MASK
|
||||
#define DMA_NBYTES_MLOFFYES_MLOFF_MASK DMA_TCD_NBYTES_MLOFFYES_MLOFF_MASK
|
||||
#define DMA_NBYTES_MLOFFYES_DMLOE_MASK DMA_TCD_NBYTES_MLOFFYES_DMLOE_MASK
|
||||
#define DMA_NBYTES_MLOFFYES_SMLOE_MASK DMA_TCD_NBYTES_MLOFFYES_SMLOE_MASK
|
||||
#define DMA_ATTR_DMOD(x) DMA_TCD_ATTR_DMOD(x)
|
||||
#define DMA_ATTR_SMOD(X) DMA_TCD_ATTR_SMOD(X)
|
||||
#define DMA_BITER_ELINKYES_LINKCH(x) DMA_TCD_BITER_ELINKYES_LINKCH(x)
|
||||
#define DMA_CITER_ELINKYES_LINKCH(x) DMA_TCD_CITER_ELINKYES_LINKCH(x)
|
||||
#define DMA_NBYTES_MLOFFYES_MLOFF(x) DMA_TCD_NBYTES_MLOFFYES_MLOFF(x)
|
||||
#define DMA_NBYTES_MLOFFYES_DMLOE(x) DMA_TCD_NBYTES_MLOFFYES_DMLOE(x)
|
||||
#define DMA_NBYTES_MLOFFYES_SMLOE(x) DMA_TCD_NBYTES_MLOFFYES_SMLOE(x)
|
||||
#define DMA_NBYTES_MLOFFNO_NBYTES(x) DMA_TCD_NBYTES_MLOFFNO_NBYTES(x)
|
||||
#define DMA_NBYTES_MLOFFYES_NBYTES(x) DMA_TCD_NBYTES_MLOFFYES_NBYTES(x)
|
||||
#define DMA_ATTR_DSIZE(x) DMA_TCD_ATTR_DSIZE(x)
|
||||
#define DMA_ATTR_SSIZE(x) DMA_TCD_ATTR_SSIZE(x)
|
||||
#define DMA_CSR_DREQ(x) DMA_TCD_CSR_DREQ(x)
|
||||
#define DMA_CSR_MAJORLINKCH(x) DMA_TCD_CSR_MAJORLINKCH(x)
|
||||
#define DMA_CH_MUX_SOURCE(x) DMA_CH_MUX_SRC(x)
|
||||
#elif defined(FSL_EDMA_SOC_IP_DMA4) && FSL_EDMA_SOC_IP_DMA4 && \
|
||||
(!defined(FSL_EDMA_SOC_IP_DMA3) || (defined(FSL_EDMA_SOC_IP_DMA3) && !FSL_EDMA_SOC_IP_DMA3))
|
||||
#define DMA_CSR_INTMAJOR_MASK DMA4_CSR_INTMAJOR_MASK
|
||||
#define DMA_CSR_INTHALF_MASK DMA4_CSR_INTHALF_MASK
|
||||
#define DMA_CSR_DREQ_MASK DMA4_CSR_DREQ_MASK
|
||||
#define DMA_CSR_ESG_MASK DMA4_CSR_ESG_MASK
|
||||
#define DMA_CSR_BWC_MASK DMA4_CSR_BWC_MASK
|
||||
#define DMA_CSR_BWC(x) DMA4_CSR_BWC(x)
|
||||
#define DMA_CSR_START_MASK DMA4_CSR_START_MASK
|
||||
#define DMA_CITER_ELINKNO_CITER_MASK DMA4_CITER_ELINKNO_CITER_MASK
|
||||
#define DMA_BITER_ELINKNO_BITER_MASK DMA4_BITER_ELINKNO_BITER_MASK
|
||||
#define DMA_CITER_ELINKNO_CITER_SHIFT DMA4_CITER_ELINKNO_CITER_SHIFT
|
||||
#define DMA_CITER_ELINKYES_CITER_MASK DMA4_CITER_ELINKYES_CITER_MASK
|
||||
#define DMA_CITER_ELINKYES_CITER_SHIFT DMA4_CITER_ELINKYES_CITER_SHIFT
|
||||
#define DMA_ATTR_SMOD_MASK DMA4_ATTR_SMOD_MASK
|
||||
#define DMA_ATTR_DMOD_MASK DMA4_ATTR_DMOD_MASK
|
||||
#define DMA_CITER_ELINKNO_ELINK_MASK DMA4_CITER_ELINKNO_ELINK_MASK
|
||||
#define DMA_CSR_MAJORELINK_MASK DMA4_CSR_MAJORELINK_MASK
|
||||
#define DMA_BITER_ELINKYES_ELINK_MASK DMA4_BITER_ELINKYES_ELINK_MASK
|
||||
#define DMA_CITER_ELINKYES_ELINK_MASK DMA4_CITER_ELINKYES_ELINK_MASK
|
||||
#define DMA_CSR_MAJORLINKCH_MASK DMA4_CSR_MAJORLINKCH_MASK
|
||||
#define DMA_BITER_ELINKYES_LINKCH_MASK DMA4_BITER_ELINKYES_LINKCH_MASK
|
||||
#define DMA_CITER_ELINKYES_LINKCH_MASK DMA4_CITER_ELINKYES_LINKCH_MASK
|
||||
#define DMA_NBYTES_MLOFFYES_MLOFF_MASK DMA4_NBYTES_MLOFFYES_MLOFF_MASK
|
||||
#define DMA_NBYTES_MLOFFYES_DMLOE_MASK DMA4_NBYTES_MLOFFYES_DMLOE_MASK
|
||||
#define DMA_NBYTES_MLOFFYES_SMLOE_MASK DMA4_NBYTES_MLOFFYES_SMLOE_MASK
|
||||
#define DMA_ATTR_DMOD(x) DMA4_ATTR_DMOD(x)
|
||||
#define DMA_ATTR_SMOD(X) DMA4_ATTR_SMOD(X)
|
||||
#define DMA_BITER_ELINKYES_LINKCH(x) DMA4_BITER_ELINKYES_LINKCH(x)
|
||||
#define DMA_CITER_ELINKYES_LINKCH(x) DMA4_CITER_ELINKYES_LINKCH(x)
|
||||
#define DMA_NBYTES_MLOFFYES_MLOFF(x) DMA4_NBYTES_MLOFFYES_MLOFF(x)
|
||||
#define DMA_NBYTES_MLOFFYES_DMLOE(x) DMA4_NBYTES_MLOFFYES_DMLOE(x)
|
||||
#define DMA_NBYTES_MLOFFYES_SMLOE(x) DMA4_NBYTES_MLOFFYES_SMLOE(x)
|
||||
#define DMA_NBYTES_MLOFFNO_NBYTES(x) DMA4_NBYTES_MLOFFNO_NBYTES(x)
|
||||
#define DMA_NBYTES_MLOFFYES_NBYTES(x) DMA4_NBYTES_MLOFFYES_NBYTES(x)
|
||||
#define DMA_ATTR_DSIZE(x) DMA4_ATTR_DSIZE(x)
|
||||
#define DMA_ATTR_SSIZE(x) DMA4_ATTR_SSIZE(x)
|
||||
#define DMA_CSR_DREQ(x) DMA4_CSR_DREQ(x)
|
||||
#define DMA_CSR_MAJORLINKCH(x) DMA4_CSR_MAJORLINKCH(x)
|
||||
#define DMA_CH_MATTR_WCACHE(x) DMA4_CH_MATTR_WCACHE(x)
|
||||
#define DMA_CH_MATTR_RCACHE(x) DMA4_CH_MATTR_RCACHE(x)
|
||||
#define DMA_CH_CSR_SIGNEXT_MASK DMA4_CH_CSR_SIGNEXT_MASK
|
||||
#define DMA_CH_CSR_SIGNEXT_SHIFT DMA4_CH_CSR_SIGNEXT_SHIFT
|
||||
#define DMA_CH_CSR_SWAP_MASK DMA4_CH_CSR_SWAP_MASK
|
||||
#define DMA_CH_CSR_SWAP_SHIFT DMA4_CH_CSR_SWAP_SHIFT
|
||||
#define DMA_CH_SBR_INSTR_MASK DMA4_CH_SBR_INSTR_MASK
|
||||
#define DMA_CH_SBR_INSTR_SHIFT DMA4_CH_SBR_INSTR_SHIFT
|
||||
#define DMA_CH_MUX_SOURCE(x) DMA4_CH_MUX_SRC(x)
|
||||
#define DMA_CH_CSR_DONE_MASK DMA4_CH_CSR_DONE_MASK
|
||||
#define DMA_CH_CSR_ERQ_MASK DMA4_CH_CSR_ERQ_MASK
|
||||
#elif defined(FSL_EDMA_SOC_IP_EDMA) && FSL_EDMA_SOC_IP_EDMA
|
||||
/*! intentional empty */
|
||||
#endif
|
||||
|
||||
/*! @brief DMA error flag */
|
||||
#if defined(FSL_EDMA_SOC_IP_EDMA) && FSL_EDMA_SOC_IP_EDMA
|
||||
#define DMA_ERR_DBE_FLAG DMA_ES_DBE_MASK
|
||||
#define DMA_ERR_SBE_FLAG DMA_ES_SBE_MASK
|
||||
#define DMA_ERR_SGE_FLAG DMA_ES_SGE_MASK
|
||||
#define DMA_ERR_NCE_FLAG DMA_ES_NCE_MASK
|
||||
#define DMA_ERR_DOE_FLAG DMA_ES_DOE_MASK
|
||||
#define DMA_ERR_DAE_FLAG DMA_ES_DAE_MASK
|
||||
#define DMA_ERR_SOE_FLAG DMA_ES_SOE_MASK
|
||||
#define DMA_ERR_SAE_FLAG DMA_ES_SAE_MASK
|
||||
#define DMA_ERR_ERRCHAN_FLAG DMA_ES_ERRCHN_MASK
|
||||
#define DMA_ERR_CPE_FLAG DMA_ES_CPE_MASK
|
||||
#define DMA_ERR_ECX_FLAG DMA_ES_ECX_MASK
|
||||
#if defined(FSL_FEATURE_EDMA_CHANNEL_GROUP_COUNT) && (FSL_FEATURE_EDMA_CHANNEL_GROUP_COUNT > 1)
|
||||
#define DMA_ERR_GPE_FLAG DMA_ES_GPE_MASK
|
||||
#endif
|
||||
#define DMA_ERR_FLAG DMA_ES_VLD_MASK
|
||||
|
||||
/*! @brief get/clear DONE status*/
|
||||
#define DMA_CLEAR_DONE_STATUS(base, channel) (EDMA_BASE(base)->CDNE = (uint8_t)channel)
|
||||
#define DMA_GET_DONE_STATUS(base, channel) \
|
||||
((EDMA_TCD_BASE(base, channel)->CSR & DMA_CSR_DONE_MASK) >> DMA_CSR_DONE_SHIFT)
|
||||
/*! @brief enable/disable error interrupt*/
|
||||
#define DMA_ENABLE_ERROR_INT(base, channel) (base->EEI |= ((uint32_t)0x1U << channel))
|
||||
#define DMA_DISABLE_ERROR_INT(base, channel) (base->EEI &= (~((uint32_t)0x1U << channel)))
|
||||
/*! @brief get/clear error status*/
|
||||
#define DMA_GET_ERROR_STATUS(base, channel) (((uint32_t)EDMA_BASE(base)->ERR >> channel) & 0x1U)
|
||||
#define DMA_CLEAR_ERROR_STATUS(base, channel) ((uint32_t)EDMA_BASE(base)->CERR = (uint8_t)channel)
|
||||
/*! @brief get/clear int status*/
|
||||
#define DMA_GET_INT_STATUS(base, channel) ((((uint32_t)EDMA_BASE(base)->INT >> channel) & 0x1U))
|
||||
#define DMA_CLEAR_INT_STATUS(base, channel) ((uint32_t)EDMA_BASE(base)->CINT = (uint8_t)channel)
|
||||
|
||||
#else
|
||||
|
||||
#define DMA_ERR_DBE_FLAG DMA_MP_ES_DBE_MASK
|
||||
#define DMA_ERR_SBE_FLAG DMA_MP_ES_SBE_MASK
|
||||
#define DMA_ERR_SGE_FLAG DMA_MP_ES_SGE_MASK
|
||||
#define DMA_ERR_NCE_FLAG DMA_MP_ES_NCE_MASK
|
||||
#define DMA_ERR_DOE_FLAG DMA_MP_ES_DOE_MASK
|
||||
#define DMA_ERR_DAE_FLAG DMA_MP_ES_DAE_MASK
|
||||
#define DMA_ERR_SOE_FLAG DMA_MP_ES_SOE_MASK
|
||||
#define DMA_ERR_SAE_FLAG DMA_MP_ES_SAE_MASK
|
||||
#define DMA_ERR_ERRCHAN_FLAG DMA_MP_ES_ERRCHN_MASK
|
||||
#define DMA_ERR_ECX_FLAG DMA_MP_ES_ECX_MASK
|
||||
#define DMA_ERR_FLAG DMA_MP_ES_VLD_MASK
|
||||
|
||||
/*! @brief get/clear DONE bit*/
|
||||
#define DMA_CLEAR_DONE_STATUS(base, channel) (EDMA_CHANNEL_BASE(base, channel)->CH_CSR |= DMA_CH_CSR_DONE_MASK)
|
||||
#define DMA_GET_DONE_STATUS(base, channel) \
|
||||
((EDMA_CHANNEL_BASE(base, channel)->CH_CSR & DMA_CH_CSR_DONE_MASK) >> DMA_CH_CSR_DONE_SHIFT)
|
||||
/*! @brief enable/disable error interupt*/
|
||||
#define DMA_ENABLE_ERROR_INT(base, channel) (EDMA_CHANNEL_BASE(base, channel)->CH_CSR |= DMA_CH_CSR_EEI_MASK)
|
||||
#define DMA_DISABLE_ERROR_INT(base, channel) (EDMA_CHANNEL_BASE(base, channel)->CH_CSR &= ~DMA_CH_CSR_EEI_MASK)
|
||||
/*! @brief get/clear error status*/
|
||||
#define DMA_CLEAR_ERROR_STATUS(base, channel) (EDMA_CHANNEL_BASE(base, channel)->CH_ES |= DMA_CH_ES_ERR_MASK)
|
||||
#define DMA_GET_ERROR_STATUS(base, channel) \
|
||||
(((uint32_t)EDMA_CHANNEL_BASE(base, channel)->CH_ES >> DMA_CH_ES_ERR_SHIFT) & 0x1U)
|
||||
/*! @brief get/clear INT status*/
|
||||
#define DMA_CLEAR_INT_STATUS(base, channel) (EDMA_CHANNEL_BASE(base, channel)->CH_INT = DMA_CH_INT_INT_MASK)
|
||||
#define DMA_GET_INT_STATUS(base, channel) ((((uint32_t)EDMA_CHANNEL_BASE(base, channel)->CH_INT) & 0x1U))
|
||||
#endif /*FSL_EDMA_SOC_IP_EDMA*/
|
||||
|
||||
/*! @brief enable/dsiable MAJOR/HALF INT*/
|
||||
#define DMA_ENABLE_MAJOR_INT(base, channel) (EDMA_TCD_BASE(base, channel)->CSR |= DMA_CSR_INTMAJOR_MASK)
|
||||
#define DMA_ENABLE_HALF_INT(base, channel) (EDMA_TCD_BASE(base, channel)->CSR |= DMA_CSR_INTHALF_MASK)
|
||||
#define DMA_DISABLE_MAJOR_INT(base, channel) (EDMA_TCD_BASE(base, channel)->CSR &= ~(uint16_t)DMA_CSR_INTMAJOR_MASK)
|
||||
#define DMA_DISABLE_HALF_INT(base, channel) (EDMA_TCD_BASE(base, channel)->CSR &= ~(uint16_t)DMA_CSR_INTHALF_MASK)
|
||||
|
||||
/*!@brief EDMA tcd align size */
|
||||
#define EDMA_TCD_ALIGN_SIZE (32U)
|
||||
|
||||
/*!@brief edma core channel struture definition */
|
||||
typedef struct _edma_core_mp
|
||||
{
|
||||
__IO uint32_t MP_CSR; /**< Channel Control and Status, array offset: 0x10000, array step: 0x10000 */
|
||||
__IO uint32_t MP_ES; /**< Channel Error Status, array offset: 0x10004, array step: 0x10000 */
|
||||
} edma_core_mp_t;
|
||||
|
||||
/*!@brief edma core channel struture definition */
|
||||
typedef struct _edma_core_channel
|
||||
{
|
||||
__IO uint32_t CH_CSR; /**< Channel Control and Status, array offset: 0x10000, array step: 0x10000 */
|
||||
__IO uint32_t CH_ES; /**< Channel Error Status, array offset: 0x10004, array step: 0x10000 */
|
||||
__IO uint32_t CH_INT; /**< Channel Interrupt Status, array offset: 0x10008, array step: 0x10000 */
|
||||
__IO uint32_t CH_SBR; /**< Channel System Bus, array offset: 0x1000C, array step: 0x10000 */
|
||||
__IO uint32_t CH_PRI; /**< Channel Priority, array offset: 0x10010, array step: 0x10000 */
|
||||
__IO uint32_t CH_MUX; /**< Channel Multiplexor Configuration, array offset: 0x10014, array step: 0x10000 */
|
||||
__IO uint16_t CH_MATTR; /**< Memory Attributes Register, array offset: 0x10018, array step: 0x8000 */
|
||||
} edma_core_channel_t;
|
||||
|
||||
/*!@brief edma core TCD struture definition */
|
||||
typedef struct _edma_core_tcd
|
||||
{
|
||||
__IO uint32_t SADDR; /*!< SADDR register, used to save source address */
|
||||
__IO uint16_t SOFF; /*!< SOFF register, save offset bytes every transfer */
|
||||
__IO uint16_t ATTR; /*!< ATTR register, source/destination transfer size and modulo */
|
||||
__IO uint32_t NBYTES; /*!< Nbytes register, minor loop length in bytes */
|
||||
__IO uint32_t SLAST; /*!< SLAST register */
|
||||
__IO uint32_t DADDR; /*!< DADDR register, used for destination address */
|
||||
__IO uint16_t DOFF; /*!< DOFF register, used for destination offset */
|
||||
__IO uint16_t CITER; /*!< CITER register, current minor loop numbers, for unfinished minor loop.*/
|
||||
__IO uint32_t DLAST_SGA; /*!< DLASTSGA register, next tcd address used in scatter-gather mode */
|
||||
__IO uint16_t CSR; /*!< CSR register, for TCD control status */
|
||||
__IO uint16_t BITER; /*!< BITER register, begin minor loop count. */
|
||||
} edma_core_tcd_t;
|
||||
|
||||
/*!@brief EDMA typedef */
|
||||
typedef edma_core_channel_t EDMA_ChannelType;
|
||||
typedef edma_core_tcd_t EDMA_TCDType;
|
||||
typedef void EDMA_Type;
|
||||
|
||||
/*!@brief EDMA base address convert macro */
|
||||
#define EDMA_BASE(base)
|
||||
#define EDMA_CHANNEL_BASE(base, channel) \
|
||||
((edma_core_channel_t *)((uint32_t)(uint32_t *)(base) + EDMA_CHANNEL_OFFSET + \
|
||||
(channel)*EDMA_CHANNEL_ARRAY_STEP(base)))
|
||||
#define EDMA_TCD_BASE(base, channel) \
|
||||
((edma_core_tcd_t *)((uint32_t)(uint32_t *)(base) + EDMA_CHANNEL_OFFSET + \
|
||||
(channel)*EDMA_CHANNEL_ARRAY_STEP(base) + 0x20U))
|
||||
#define EDMA_MP_BASE(base) ((edma_core_mp_t *)((uint32_t)(uint32_t *)(base)))
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* FSL_EDMA_CORE_H_ */
|
||||
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* Copyright 2023 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "fsl_edma_soc.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/* Component ID definition, used by tools. */
|
||||
#ifndef FSL_COMPONENT_ID
|
||||
#define FSL_COMPONENT_ID "platform.drivers.edma_soc"
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
extern void EDMA_0_CH0_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH1_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH2_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH3_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH4_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH5_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH6_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH7_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH8_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH9_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH10_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH11_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH12_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH13_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH14_DriverIRQHandler(void);
|
||||
extern void EDMA_0_CH15_DriverIRQHandler(void);
|
||||
extern void EDMA_1_CH0_DriverIRQHandler(void);
|
||||
extern void EDMA_1_CH1_DriverIRQHandler(void);
|
||||
extern void EDMA_1_CH2_DriverIRQHandler(void);
|
||||
extern void EDMA_1_CH3_DriverIRQHandler(void);
|
||||
extern void EDMA_1_CH4_DriverIRQHandler(void);
|
||||
extern void EDMA_1_CH5_DriverIRQHandler(void);
|
||||
extern void EDMA_1_CH6_DriverIRQHandler(void);
|
||||
extern void EDMA_1_CH7_DriverIRQHandler(void);
|
||||
extern void EDMA_DriverIRQHandler(uint32_t instance, uint32_t channel);
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
/*!
|
||||
* brief DMA instance 0, channel 0 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH0_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 0 */
|
||||
EDMA_DriverIRQHandler(0U, 0U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 1 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH1_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 1 */
|
||||
EDMA_DriverIRQHandler(0U, 1U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 2 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH2_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 2 */
|
||||
EDMA_DriverIRQHandler(0U, 2U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 3 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH3_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 3 */
|
||||
EDMA_DriverIRQHandler(0U, 3U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 4 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH4_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 4 */
|
||||
EDMA_DriverIRQHandler(0U, 4U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 5 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH5_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 5 */
|
||||
EDMA_DriverIRQHandler(0U, 5U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 6 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH6_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 6 */
|
||||
EDMA_DriverIRQHandler(0U, 6U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 7 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH7_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 7 */
|
||||
EDMA_DriverIRQHandler(0U, 7U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 8 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH8_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 8 */
|
||||
EDMA_DriverIRQHandler(0U, 8U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 9 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH9_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 9 */
|
||||
EDMA_DriverIRQHandler(0U, 9U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 10 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH10_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 10 */
|
||||
EDMA_DriverIRQHandler(0U, 10U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 11 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH11_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 11 */
|
||||
EDMA_DriverIRQHandler(0U, 11U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 12 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH12_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 12 */
|
||||
EDMA_DriverIRQHandler(0U, 12U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 13 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH13_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 13 */
|
||||
EDMA_DriverIRQHandler(0U, 13U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 14 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH14_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 14 */
|
||||
EDMA_DriverIRQHandler(0U, 14U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 0, channel 15 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_0_CH15_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 0 channel 15 */
|
||||
EDMA_DriverIRQHandler(0U, 15U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 1, channel 0 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_1_CH0_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 1 channel 0 */
|
||||
EDMA_DriverIRQHandler(1U, 0U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 1, channel 1 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_1_CH1_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 1 channel 1 */
|
||||
EDMA_DriverIRQHandler(1U, 1U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 1, channel 2 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_1_CH2_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 1 channel 2 */
|
||||
EDMA_DriverIRQHandler(1U, 2U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 1, channel 3 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_1_CH3_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 1 channel 3 */
|
||||
EDMA_DriverIRQHandler(1U, 3U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 1, channel 4 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_1_CH4_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 1 channel 4 */
|
||||
EDMA_DriverIRQHandler(1U, 4U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 1, channel 5 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_1_CH5_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 1 channel 5 */
|
||||
EDMA_DriverIRQHandler(1U, 5U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 1, channel 6 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_1_CH6_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 1 channel 6 */
|
||||
EDMA_DriverIRQHandler(1U, 6U);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief DMA instance 1, channel 7 IRQ handler.
|
||||
*
|
||||
*/
|
||||
void EDMA_1_CH7_DriverIRQHandler(void)
|
||||
{
|
||||
/* Instance 1 channel 7 */
|
||||
EDMA_DriverIRQHandler(1U, 7U);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2023 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#ifndef _FSL_EDMA_SOC_H_
|
||||
#define _FSL_EDMA_SOC_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup edma_soc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief Driver version 1.0.0. */
|
||||
#define FSL_EDMA_SOC_DRIVER_VERSION (MAKE_VERSION(1, 0, 0))
|
||||
/*@}*/
|
||||
|
||||
/*!@brief DMA IP version */
|
||||
#define FSL_EDMA_SOC_IP_DMA3 (1)
|
||||
#define FSL_EDMA_SOC_IP_DMA4 (0)
|
||||
|
||||
/*!@brief DMA base table */
|
||||
#define EDMA_BASE_PTRS \
|
||||
{ \
|
||||
DMA0, DMA1 \
|
||||
}
|
||||
|
||||
#define EDMA_CHN_IRQS \
|
||||
{ \
|
||||
{EDMA_0_CH0_IRQn, EDMA_0_CH1_IRQn, EDMA_0_CH2_IRQn, EDMA_0_CH3_IRQn, EDMA_0_CH4_IRQn, EDMA_0_CH5_IRQn, \
|
||||
EDMA_0_CH6_IRQn, EDMA_0_CH7_IRQn, EDMA_0_CH8_IRQn, EDMA_0_CH9_IRQn, EDMA_0_CH10_IRQn, EDMA_0_CH11_IRQn, \
|
||||
EDMA_0_CH12_IRQn, EDMA_0_CH13_IRQn, EDMA_0_CH14_IRQn, EDMA_0_CH15_IRQn}, \
|
||||
{ \
|
||||
EDMA_1_CH0_IRQn, EDMA_1_CH1_IRQn, EDMA_1_CH2_IRQn, EDMA_1_CH3_IRQn, EDMA_1_CH4_IRQn, EDMA_1_CH5_IRQn, \
|
||||
EDMA_1_CH6_IRQn, EDMA_1_CH7_IRQn, NotAvail_IRQn, NotAvail_IRQn, NotAvail_IRQn, \
|
||||
NotAvail_IRQn, NotAvail_IRQn, NotAvail_IRQn, NotAvail_IRQn, NotAvail_IRQn \
|
||||
} \
|
||||
}
|
||||
|
||||
/*!@brief EDMA base address convert macro */
|
||||
#define EDMA_CHANNEL_OFFSET 0x1000U
|
||||
#define EDMA_CHANNEL_ARRAY_STEP(base) (0x1000U)
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* _FSL_EDMA_SOC_H_ */
|
||||
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* Copyright 2022 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "fsl_eim.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/* Component ID definition, used by tools. */
|
||||
#ifndef FSL_COMPONENT_ID
|
||||
#define FSL_COMPONENT_ID "platform.drivers.eim"
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
/*! @brief Pointers to EIM bases for each instance. */
|
||||
static EIM_Type *const s_eimBases[] = EIM_BASE_PTRS;
|
||||
|
||||
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
|
||||
/*! @brief Pointers to EIM clocks for each instance. */
|
||||
static const clock_ip_name_t s_eimClocks[] = EIM_CLOCKS;
|
||||
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
static uint32_t EIM_GetInstance(EIM_Type *base)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
/* Find the instance index from base address mappings. */
|
||||
for (instance = 0; instance < ARRAY_SIZE(s_eimBases); instance++)
|
||||
{
|
||||
if (s_eimBases[instance] == base)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(instance < ARRAY_SIZE(s_eimBases));
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief EIM module initialization function.
|
||||
*
|
||||
* param base EIM base address.
|
||||
*/
|
||||
void EIM_Init(EIM_Type *base)
|
||||
{
|
||||
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
|
||||
/* Ungate EIM clock. */
|
||||
CLOCK_EnableClock(s_eimClocks[EIM_GetInstance(base)]);
|
||||
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
|
||||
|
||||
base->EIMCR = 0x00U;
|
||||
base->EICHEN = 0x00U;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Deinitializes the EIM.
|
||||
*
|
||||
*/
|
||||
void EIM_Deinit(EIM_Type *base)
|
||||
{
|
||||
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
|
||||
/* Ungate EIM clock. */
|
||||
CLOCK_DisableClock(s_eimClocks[EIM_GetInstance(base)]);
|
||||
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
|
||||
}
|
||||
|
||||
void EIM_InjectCheckBitError(EIM_Type *base, eim_memory_channel_t channel, uint8_t mask)
|
||||
{
|
||||
switch ((uint8_t)channel)
|
||||
{
|
||||
case 0U:
|
||||
base->EICHD0_WORD0 = EIM_EICHD0_WORD0_CHKBIT_MASK(mask);
|
||||
break;
|
||||
#ifdef EIM_EICHEN_EICH1EN_MASK
|
||||
case 1U:
|
||||
base->EICHD1_WORD0 = EIM_EICHD1_WORD0_CHKBIT_MASK(mask);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef EIM_EICHEN_EICH2EN_MASK
|
||||
case 2U:
|
||||
base->EICHD2_WORD0 = EIM_EICHD2_WORD0_CHKBIT_MASK(mask);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH3EN_MASK
|
||||
case 3U:
|
||||
base->EICHD3_WORD0 = EIM_EICHD3_WORD0_CHKBIT_MASK(mask);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH4EN_MASK
|
||||
case 4U:
|
||||
base->EICHD4_WORD0 = EIM_EICHD4_WORD0_CHKBIT_MASK(mask);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH5EN_MASK
|
||||
case 5U:
|
||||
base->EICHD5_WORD0 = EIM_EICHD5_WORD0_CHKBIT_MASK(mask);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH6EN_MASK
|
||||
case 6U:
|
||||
base->EICHD6_WORD0 = EIM_EICHD6_WORD0_CHKBIT_MASK(mask);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH7EN_MASK
|
||||
case 7U:
|
||||
base->EICHD7_WORD0 = EIM_EICHD7_WORD0_CHKBIT_MASK(mask);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH8EN_MASK
|
||||
case 8U:
|
||||
base->EICHD8_WORD0 = EIM_EICHD8_WORD0_CHKBIT_MASK(mask);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
assert(NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t EIM_GetCheckBitMask(EIM_Type *base, eim_memory_channel_t channel)
|
||||
{
|
||||
uint8_t mask = 0x00U;
|
||||
|
||||
switch ((uint8_t)channel)
|
||||
{
|
||||
case 0U:
|
||||
mask = (uint8_t)((base->EICHD0_WORD0 & EIM_EICHD0_WORD0_CHKBIT_MASK_MASK) >>
|
||||
EIM_EICHD0_WORD0_CHKBIT_MASK_SHIFT);
|
||||
break;
|
||||
#ifdef EIM_EICHEN_EICH1EN_MASK
|
||||
case 1U:
|
||||
mask = (uint8_t)((base->EICHD1_WORD0 & EIM_EICHD1_WORD0_CHKBIT_MASK_MASK) >>
|
||||
EIM_EICHD1_WORD0_CHKBIT_MASK_SHIFT);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH2EN_MASK
|
||||
case 2U:
|
||||
mask = (uint8_t)((base->EICHD2_WORD0 & EIM_EICHD2_WORD0_CHKBIT_MASK_MASK) >>
|
||||
EIM_EICHD2_WORD0_CHKBIT_MASK_SHIFT);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH3EN_MASK
|
||||
case 3U:
|
||||
mask = (uint8_t)((base->EICHD3_WORD0 & EIM_EICHD3_WORD0_CHKBIT_MASK_MASK) >>
|
||||
EIM_EICHD3_WORD0_CHKBIT_MASK_SHIFT);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH4EN_MASK
|
||||
case 4U:
|
||||
mask = (uint8_t)((base->EICHD4_WORD0 & EIM_EICHD4_WORD0_CHKBIT_MASK_MASK) >>
|
||||
EIM_EICHD4_WORD0_CHKBIT_MASK_SHIFT);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH5EN_MASK
|
||||
case 5U:
|
||||
mask = (uint8_t)((base->EICHD5_WORD0 & EIM_EICHD5_WORD0_CHKBIT_MASK_MASK) >>
|
||||
EIM_EICHD5_WORD0_CHKBIT_MASK_SHIFT);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH6EN_MASK
|
||||
case 6U:
|
||||
mask = (uint8_t)((base->EICHD6_WORD0 & EIM_EICHD6_WORD0_CHKBIT_MASK_MASK) >>
|
||||
EIM_EICHD6_WORD0_CHKBIT_MASK_SHIFT);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH7EN_MASK
|
||||
case 7U:
|
||||
mask = (uint8_t)((base->EICHD7_WORD0 & EIM_EICHD7_WORD0_CHKBIT_MASK_MASK) >>
|
||||
EIM_EICHD7_WORD0_CHKBIT_MASK_SHIFT);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH8EN_MASK
|
||||
case 8U:
|
||||
mask = (uint8_t)((base->EICHD8_WORD0 & EIM_EICHD8_WORD0_CHKBIT_MASK_MASK) >>
|
||||
EIM_EICHD8_WORD0_CHKBIT_MASK_SHIFT);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
assert(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
void EIM_InjectDataBitError(EIM_Type *base, eim_memory_channel_t channel, uint8_t mask)
|
||||
{
|
||||
switch ((uint8_t)channel)
|
||||
{
|
||||
case 0U:
|
||||
base->EICHD0_WORD1 = mask;
|
||||
break;
|
||||
#ifdef EIM_EICHEN_EICH1EN_MASK
|
||||
case 1U:
|
||||
base->EICHD1_WORD1 = mask;
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH2EN_MASK
|
||||
case 2U:
|
||||
base->EICHD2_WORD1 = mask;
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH3EN_MASK
|
||||
case kEIM_MemoryChannelRAMC:
|
||||
base->EICHD3_WORD1 = mask;
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH4EN_MASK
|
||||
case kEIM_MemoryChannelRAMD:
|
||||
base->EICHD4_WORD1 = mask;
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH5EN_MASK
|
||||
case kEIM_MemoryChannelRAME:
|
||||
base->EICHD5_WORD1 = mask;
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH6EN_MASK
|
||||
case kEIM_MemoryChannelRAMF:
|
||||
base->EICHD6_WORD1 = mask;
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH7EN_MASK
|
||||
case kEIM_MemoryChannelLPCACRAM:
|
||||
base->EICHD7_WORD1 = mask;
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH8EN_MASK
|
||||
case kEIM_MemoryChannelPKCRAM:
|
||||
base->EICHD8_WORD1 = mask;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
assert(NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t EIM_GetDataBitMask(EIM_Type *base, eim_memory_channel_t channel)
|
||||
{
|
||||
uint32_t mask = 0x00U;
|
||||
|
||||
switch ((uint8_t)channel)
|
||||
{
|
||||
case 0U:
|
||||
mask = (base->EICHD0_WORD0 & EIM_EICHD0_WORD1_B0_3DATA_MASK_MASK) >> EIM_EICHD0_WORD1_B0_3DATA_MASK_SHIFT;
|
||||
break;
|
||||
|
||||
#ifdef EIM_EICHEN_EICH1EN_MASK
|
||||
case 1U:
|
||||
mask = (base->EICHD1_WORD0 & EIM_EICHD1_WORD1_B0_3DATA_MASK_MASK) >> EIM_EICHD1_WORD1_B0_3DATA_MASK_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH2EN_MASK
|
||||
case 2U:
|
||||
mask = (base->EICHD2_WORD0 & EIM_EICHD2_WORD1_B0_3DATA_MASK_MASK) >> EIM_EICHD2_WORD1_B0_3DATA_MASK_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH3EN_MASK
|
||||
case 3U:
|
||||
mask = (base->EICHD3_WORD0 & EIM_EICHD3_WORD1_B0_3DATA_MASK_MASK) >> EIM_EICHD3_WORD1_B0_3DATA_MASK_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH4EN_MASK
|
||||
case 4U:
|
||||
mask = (base->EICHD4_WORD0 & EIM_EICHD4_WORD1_B0_3DATA_MASK_MASK) >> EIM_EICHD4_WORD1_B0_3DATA_MASK_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH5EN_MASK
|
||||
case 5U:
|
||||
mask = (base->EICHD5_WORD0 & EIM_EICHD5_WORD1_B0_3DATA_MASK_MASK) >> EIM_EICHD5_WORD1_B0_3DATA_MASK_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH6EN_MASK
|
||||
case 6U:
|
||||
mask = (base->EICHD6_WORD0 & EIM_EICHD6_WORD1_B0_3DATA_MASK_MASK) >> EIM_EICHD6_WORD1_B0_3DATA_MASK_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH7EN_MASK
|
||||
case 7U:
|
||||
mask = (base->EICHD7_WORD0 & EIM_EICHD7_WORD1_B0_3DATA_MASK_MASK) >> EIM_EICHD7_WORD1_B0_3DATA_MASK_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef EIM_EICHEN_EICH8EN_MASK
|
||||
case 8U:
|
||||
mask = (base->EICHD8_WORD1 & EIM_EICHD8_WORD1_B0_3DATA_MASK_MASK) >> EIM_EICHD8_WORD1_B0_3DATA_MASK_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
assert(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
return mask;
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright 2022 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef FSL_EIM_H_
|
||||
#define FSL_EIM_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup eim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* Definitions.
|
||||
*****************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief Driver version. */
|
||||
#define FSL_ERM_DRIVER_VERSION (MAKE_VERSION(2U, 0U, 1U))
|
||||
/*@}*/
|
||||
|
||||
/*******************************************************************************
|
||||
* APIs
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief EIM module initialization function.
|
||||
*
|
||||
* @param base EIM base address.
|
||||
*/
|
||||
void EIM_Init(EIM_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief De-initializes the EIM.
|
||||
*
|
||||
*/
|
||||
void EIM_Deinit(EIM_Type *base);
|
||||
|
||||
/* @} */
|
||||
|
||||
/*!
|
||||
* @name functional
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief EIM module enable global error injection.
|
||||
*
|
||||
* @param base EIM base address.
|
||||
* @param mask The interrupts to enable.
|
||||
*/
|
||||
static inline void EIM_EnableGlobalErrorInjection(EIM_Type *base, bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
base->EIMCR = EIM_EIMCR_GEIEN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
base->EIMCR = ~EIM_EIMCR_GEIEN_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief EIM module enable error injection for memory channel n, this function enables the corresponding error
|
||||
* injection channel. The Global Error Injection Enable function must also be called to enable error injection.
|
||||
*
|
||||
* @param base EIM base address.
|
||||
* @param mask The interrupts to enable. Refer to "_eim_error_injection_channel_enable" enumeration.
|
||||
*/
|
||||
static inline void EIM_EnableErrorInjectionChannels(EIM_Type *base, uint32_t mask)
|
||||
{
|
||||
base->EICHEN |= mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief EIM module disable error injection for memory channel n.
|
||||
*
|
||||
* @param base EIM base address.
|
||||
* @param mask The interrupts to enable. Refer to "_eim_error_injection_channel_enable" enumeration.
|
||||
*/
|
||||
static inline void EIM_DisableErrorInjectionChannels(EIM_Type *base, uint32_t mask)
|
||||
{
|
||||
base->EICHEN &= ~mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief EIM module inject checkbit error for memory channel n, an attempt to invert more than 2 bits in one operation
|
||||
* might result in undefined behavior.
|
||||
*
|
||||
* @param base EIM base address.
|
||||
* @param channel memory channel.
|
||||
* @param mask The interrupts to enable.
|
||||
*/
|
||||
void EIM_InjectCheckBitError(EIM_Type *base, eim_memory_channel_t channel, uint8_t mask);
|
||||
|
||||
/*!
|
||||
* @brief EIM module get checkbit mask for memory channel n.
|
||||
*
|
||||
* @param base EIM base address.
|
||||
* @param channel memory channel.
|
||||
* @retval return checkbit mask.
|
||||
*/
|
||||
uint8_t EIM_GetCheckBitMask(EIM_Type *base, eim_memory_channel_t channel);
|
||||
|
||||
/*!
|
||||
* @brief EIM module inject databit error for memory channel n, an attempt to invert more than 2 bits in one operation
|
||||
* might result in undefined behavior.
|
||||
*
|
||||
* @param base EIM base address.
|
||||
* @param channel memory channel.
|
||||
* @param mask The interrupts to enable.
|
||||
*/
|
||||
void EIM_InjectDataBitError(EIM_Type *base, eim_memory_channel_t channel, uint8_t mask);
|
||||
|
||||
/*!
|
||||
* @brief EIM module get databit mask for memory channel n.
|
||||
*
|
||||
* @param base EIM base address.
|
||||
* @param channel memory channel.
|
||||
* @retval return checkbit mask.
|
||||
*/
|
||||
uint32_t EIM_GetDataBitMask(EIM_Type *base, eim_memory_channel_t channel);
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,317 @@
|
||||
/*
|
||||
* Copyright 2022 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "fsl_erm.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/* Component ID definition, used by tools. */
|
||||
#ifndef FSL_COMPONENT_ID
|
||||
#define FSL_COMPONENT_ID "platform.drivers.erm"
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
/*! @brief Pointers to ERM bases for each instance. */
|
||||
static ERM_Type *const s_ermBases[] = ERM_BASE_PTRS;
|
||||
|
||||
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
|
||||
/*! @brief Pointers to ERM clocks for each instance. */
|
||||
static const clock_ip_name_t s_ermClocks[] = ERM_CLOCKS;
|
||||
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
static uint32_t ERM_GetInstance(ERM_Type *base)
|
||||
{
|
||||
uint32_t instance;
|
||||
|
||||
/* Find the instance index from base address mappings. */
|
||||
for (instance = 0; instance < ARRAY_SIZE(s_ermBases); instance++)
|
||||
{
|
||||
if (s_ermBases[instance] == base)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(instance < ARRAY_SIZE(s_ermBases));
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief ERM module initialization function.
|
||||
*
|
||||
* param base ERM base address.
|
||||
*/
|
||||
void ERM_Init(ERM_Type *base)
|
||||
{
|
||||
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
|
||||
/* Ungate ERM clock. */
|
||||
CLOCK_EnableClock(s_ermClocks[ERM_GetInstance(base)]);
|
||||
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
|
||||
|
||||
base->CR0 = 0x00U;
|
||||
#ifdef ERM_CR1_ENCIE8_MASK
|
||||
base->CR1 = 0x00U;
|
||||
#endif
|
||||
base->SR0 = 0xFFFFFFFFU;
|
||||
#ifdef ERM_SR1_SBC8_MASK
|
||||
base->SR1 = 0xFFFFFFFFU;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Deinitializes the ERM.
|
||||
*
|
||||
*/
|
||||
void ERM_Deinit(ERM_Type *base)
|
||||
{
|
||||
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
|
||||
/* Ungate ERM clock. */
|
||||
CLOCK_DisableClock(s_ermClocks[ERM_GetInstance(base)]);
|
||||
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
|
||||
}
|
||||
|
||||
uint32_t ERM_GetMemoryErrorAddr(ERM_Type *base, erm_memory_channel_t channel)
|
||||
{
|
||||
uint32_t absoluteErrorAddress = 0x00U;
|
||||
|
||||
switch ((uint8_t)channel)
|
||||
{
|
||||
case 0U:
|
||||
absoluteErrorAddress = base->EAR0;
|
||||
break;
|
||||
#ifdef ERM_EAR1_EAR_MASK
|
||||
case 1U:
|
||||
absoluteErrorAddress = base->EAR1;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_EAR2_EAR_MASK
|
||||
case 2U:
|
||||
absoluteErrorAddress = base->EAR2;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_EAR3_EAR_MASK
|
||||
case 3U:
|
||||
absoluteErrorAddress = base->EAR3;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_EAR4_EAR_MASK
|
||||
case 4U:
|
||||
absoluteErrorAddress = base->EAR4;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_EAR5_EAR_MASK
|
||||
case 5U:
|
||||
absoluteErrorAddress = base->EAR5;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_EAR6_EAR_MASK
|
||||
case 6U:
|
||||
absoluteErrorAddress = base->EAR6;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
assert(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
return absoluteErrorAddress;
|
||||
}
|
||||
|
||||
uint32_t ERM_GetSyndrome(ERM_Type *base, erm_memory_channel_t channel)
|
||||
{
|
||||
uint32_t syndrome = 0x00U;
|
||||
|
||||
switch ((uint8_t)channel)
|
||||
{
|
||||
case 0U:
|
||||
syndrome = (base->SYN0 & ERM_SYN0_SYNDROME_MASK) >> ERM_SYN0_SYNDROME_SHIFT;
|
||||
break;
|
||||
#ifdef ERM_SYN1_SYNDROME_MASK
|
||||
case 1U:
|
||||
syndrome = (base->SYN1 & ERM_SYN1_SYNDROME_MASK) >> ERM_SYN1_SYNDROME_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_SYN2_SYNDROME_MASK
|
||||
case 2U:
|
||||
syndrome = (base->SYN2 & ERM_SYN2_SYNDROME_MASK) >> ERM_SYN2_SYNDROME_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_SYN3_SYNDROME_MASK
|
||||
case 3U:
|
||||
syndrome = (base->SYN3 & ERM_SYN3_SYNDROME_MASK) >> ERM_SYN3_SYNDROME_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_SYN4_SYNDROME_MASK
|
||||
case 4U:
|
||||
syndrome = (base->SYN4 & ERM_SYN4_SYNDROME_MASK) >> ERM_SYN4_SYNDROME_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_SYN5_SYNDROME_MASK
|
||||
case 5U:
|
||||
syndrome = (base->SYN5 & ERM_SYN5_SYNDROME_MASK) >> ERM_SYN5_SYNDROME_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_SYN6_SYNDROME_MASK
|
||||
case 6U:
|
||||
syndrome = (base->SYN6 & ERM_SYN6_SYNDROME_MASK) >> ERM_SYN6_SYNDROME_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_SYN7_SYNDROME_MASK
|
||||
case 7U:
|
||||
syndrome = (base->SYN7 & ERM_SYN6_SYNDROME_MASK) >> ERM_SYN7_SYNDROME_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_SYN8_SYNDROME_MASK
|
||||
case 8U:
|
||||
syndrome = (base->SYN8 & ERM_SYN8_SYNDROME_MASK) >> ERM_SYN8_SYNDROME_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_SYN9_SYNDROME_MASK
|
||||
case 8U:
|
||||
syndrome = (base->SYN9 & ERM_SYN9_SYNDROME_MASK) >> ERM_SYN9_SYNDROME_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
assert(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
return syndrome;
|
||||
}
|
||||
|
||||
uint32_t ERM_GetErrorCount(ERM_Type *base, erm_memory_channel_t channel)
|
||||
{
|
||||
uint32_t count = 0x00U;
|
||||
|
||||
switch ((uint8_t)channel)
|
||||
{
|
||||
case 0U:
|
||||
count = (base->CORR_ERR_CNT0 & ERM_CORR_ERR_CNT0_COUNT_MASK) >> ERM_CORR_ERR_CNT0_COUNT_SHIFT;
|
||||
break;
|
||||
#ifdef ERM_CORR_ERR_CNT1_COUNT_MASK
|
||||
case 1U:
|
||||
count = (base->CORR_ERR_CNT1 & ERM_CORR_ERR_CNT1_COUNT_MASK) >> ERM_CORR_ERR_CNT1_COUNT_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT2_COUNT_MASK
|
||||
case 2U:
|
||||
count = (base->CORR_ERR_CNT2 & ERM_CORR_ERR_CNT2_COUNT_MASK) >> ERM_CORR_ERR_CNT2_COUNT_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT3_COUNT_MASK
|
||||
case 3U:
|
||||
count = (base->CORR_ERR_CNT3 & ERM_CORR_ERR_CNT3_COUNT_MASK) >> ERM_CORR_ERR_CNT3_COUNT_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT4_COUNT_MASK
|
||||
case 4U:
|
||||
count = (base->CORR_ERR_CNT4 & ERM_CORR_ERR_CNT4_COUNT_MASK) >> ERM_CORR_ERR_CNT4_COUNT_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT5_COUNT_MASK
|
||||
case 5U:
|
||||
count = (base->CORR_ERR_CNT5 & ERM_CORR_ERR_CNT5_COUNT_MASK) >> ERM_CORR_ERR_CNT5_COUNT_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT6_COUNT_MASK
|
||||
case 6U:
|
||||
count = (base->CORR_ERR_CNT6 & ERM_CORR_ERR_CNT6_COUNT_MASK) >> ERM_CORR_ERR_CNT6_COUNT_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT7_COUNT_MASK
|
||||
case 7U:
|
||||
count = (base->CORR_ERR_CNT7 & ERM_CORR_ERR_CNT7_COUNT_MASK) >> ERM_CORR_ERR_CNT7_COUNT_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT8_COUNT_MASK
|
||||
case 8U:
|
||||
count = (base->CORR_ERR_CNT8 & ERM_CORR_ERR_CNT8_COUNT_MASK) >> ERM_CORR_ERR_CNT8_COUNT_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT9_COUNT_MASK
|
||||
case 9U:
|
||||
count = (base->CORR_ERR_CNT9 & ERM_CORR_ERR_CNT9_COUNT_MASK) >> ERM_CORR_ERR_CNT9_COUNT_SHIFT;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
assert(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void ERM_ResetErrorCount(ERM_Type *base, erm_memory_channel_t channel)
|
||||
{
|
||||
switch ((uint8_t)channel)
|
||||
{
|
||||
case 0U:
|
||||
base->CORR_ERR_CNT0 = 0x00U;
|
||||
break;
|
||||
|
||||
#ifdef ERM_CORR_ERR_CNT1_COUNT_MASK
|
||||
case 1U:
|
||||
base->CORR_ERR_CNT1 = 0x00U;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT2_COUNT_MASK
|
||||
case 2U:
|
||||
base->CORR_ERR_CNT2 = 0x00U;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT3_COUNT_MASK
|
||||
case 3U:
|
||||
base->CORR_ERR_CNT3 = 0x00U;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT4_COUNT_MASK
|
||||
case 4U:
|
||||
base->CORR_ERR_CNT4 = 0x00U;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT5_COUNT_MASK
|
||||
case 5U:
|
||||
base->CORR_ERR_CNT5 = 0x00U;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT6_COUNT_MASK
|
||||
case 6U:
|
||||
base->CORR_ERR_CNT6 = 0x00U;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT6_COUNT_MASK
|
||||
case 7U:
|
||||
base->CORR_ERR_CNT7 = 0x00U;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT8_COUNT_MASK
|
||||
case 8U:
|
||||
base->CORR_ERR_CNT8 = 0x00U;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ERM_CORR_ERR_CNT9_COUNT_MASK
|
||||
case 9U:
|
||||
base->CORR_ERR_CNT9 = 0x00U;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
assert(NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* Copyright 2022 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef FSL_ERM_H_
|
||||
#define FSL_ERM_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup erm
|
||||
* @{
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* Definitions.
|
||||
*****************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief Driver version. */
|
||||
#define FSL_ERM_DRIVER_VERSION (MAKE_VERSION(2U, 0U, 1U))
|
||||
/*@}*/
|
||||
|
||||
/*!
|
||||
* @brief ERM interrupt configuration structure, default settings all disabled, _erm_interrupt_enable.
|
||||
*
|
||||
* This structure contains the settings for all of the ERM interrupt configurations.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
kERM_SingleCorrectionIntEnable = 0x08U, /*!< Single Correction Interrupt Notification enable.*/
|
||||
kERM_NonCorrectableIntEnable = 0x04U, /*!< Non-Correction Interrupt Notification enable.*/
|
||||
|
||||
kERM_AllInterruptsEnable = 0xFFFFFFFFUL, /*!< All Interrupts enable */
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief ERM interrupt status, _erm_interrupt_flag.
|
||||
*
|
||||
* This provides constants for the ERM event status for use in the ERM functions.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
kERM_SingleBitCorrectionIntFlag = 0x08U, /*!< Single-Bit Correction Event.*/
|
||||
kERM_NonCorrectableErrorIntFlag = 0x04U, /*!< Non-Correctable Error Event.*/
|
||||
|
||||
kERM_AllIntsFlag = 0xFFFFFFFFUL, /*!< All Events. */
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* APIs
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @name Initialization and de-initialization
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief ERM module initialization function.
|
||||
*
|
||||
* @param base ERM base address.
|
||||
*/
|
||||
void ERM_Init(ERM_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief De-initializes the ERM.
|
||||
*
|
||||
*/
|
||||
void ERM_Deinit(ERM_Type *base);
|
||||
|
||||
/* @} */
|
||||
|
||||
/*!
|
||||
* @name Interrupt
|
||||
* @{
|
||||
*/
|
||||
/*!
|
||||
* @brief ERM enable interrupts.
|
||||
*
|
||||
* @param base ERM peripheral base address.
|
||||
* @param channel memory channel.
|
||||
* @param mask single correction interrupt or non-correction interrupt enable to disable for one specific memory region.
|
||||
* Refer to "_erm_interrupt_enable" enumeration.
|
||||
*/
|
||||
static inline void ERM_EnableInterrupts(ERM_Type *base, erm_memory_channel_t channel, uint32_t mask)
|
||||
{
|
||||
uint32_t temp = 0x00U;
|
||||
if ((uint32_t)channel <= 0x07U)
|
||||
{
|
||||
temp = base->CR0;
|
||||
base->CR0 =
|
||||
(temp & ~(0x0CUL << ((0x07U - (uint32_t)channel) * 4U))) | (mask << ((0x07U - (uint32_t)channel) * 4U));
|
||||
}
|
||||
#ifdef ERM_CR1_ESCIE8_MASK
|
||||
else
|
||||
{
|
||||
temp = base->CR1;
|
||||
base->CR1 = (temp & ~(0x0CUL << ((0x07U + 0x08U - (uint32_t)channel) * 4U))) |
|
||||
(mask << ((0x07U + 0x08U - (uint32_t)channel) * 4U));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief ERM module disable interrupts.
|
||||
*
|
||||
* @param base ERM base address.
|
||||
* @param channel memory channel.
|
||||
* @param mask single correction interrupt or non-correction interrupt enable to disable for one specific memory region.
|
||||
* Refer to "_erm_interrupt_enable" enumeration.
|
||||
*/
|
||||
static inline void ERM_DisableInterrupts(ERM_Type *base, erm_memory_channel_t channel, uint32_t mask)
|
||||
{
|
||||
if ((uint32_t)channel <= 0x07U)
|
||||
{
|
||||
base->CR0 &= ~(mask << ((0x07U - (uint32_t)channel) * 4U));
|
||||
}
|
||||
#ifdef ERM_CR1_ESCIE8_MASK
|
||||
else
|
||||
{
|
||||
base->CR1 &= ~(mask << ((0x07U + 0x08U - (uint32_t)channel) * 4U));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets ERM interrupt flags.
|
||||
*
|
||||
* @param base ERM peripheral base address.
|
||||
* @return ERM event flags.
|
||||
*/
|
||||
static inline uint32_t ERM_GetInterruptStatus(ERM_Type *base, erm_memory_channel_t channel)
|
||||
{
|
||||
if ((uint32_t)channel <= 0x07U)
|
||||
{
|
||||
return ((base->SR0 & (uint32_t)kERM_AllIntsFlag) >> (0x07U - (uint32_t)channel) * 4U);
|
||||
}
|
||||
#ifdef ERM_SR1_SBC8_MASK
|
||||
else
|
||||
{
|
||||
return ((base->SR1 & (uint32_t)kERM_AllIntsFlag) >> ((0x07U + 0x08U - (uint32_t)channel) * 4U));
|
||||
}
|
||||
#else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief ERM module clear interrupt status flag.
|
||||
*
|
||||
* @param base ERM base address.
|
||||
* @param mask event flag to clear. Refer to "_erm_interrupt_flag" enumeration.
|
||||
*/
|
||||
static inline void ERM_ClearInterruptStatus(ERM_Type *base, erm_memory_channel_t channel, uint32_t mask)
|
||||
{
|
||||
if ((uint32_t)channel <= 0x07U)
|
||||
{
|
||||
base->SR0 = mask << ((0x07U - (uint32_t)channel) * 4U);
|
||||
}
|
||||
#ifdef ERM_SR1_SBC8_MASK
|
||||
else
|
||||
{
|
||||
base->SR1 = mask << ((0x07U + 0x08U - (uint32_t)channel) * 4U);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* @} */
|
||||
|
||||
/*!
|
||||
* @name functional
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief ERM get memory error absolute address, which capturing the address of the last ECC event in Memory n.
|
||||
*
|
||||
* @param base ERM base address.
|
||||
* @param channel memory channel.
|
||||
* @retval memory error absolute address.
|
||||
*/
|
||||
|
||||
uint32_t ERM_GetMemoryErrorAddr(ERM_Type *base, erm_memory_channel_t channel);
|
||||
|
||||
/*!
|
||||
* @brief ERM get syndrome, which identifies the pertinent bit position on a correctable, single-bit data inversion or a
|
||||
* non-correctable, single-bit address inversion. The syndrome value does not provide any additional diagnostic
|
||||
* information on non-correctable, multi-bit inversions.
|
||||
*
|
||||
* @param base ERM base address.
|
||||
* @param channel memory channel.
|
||||
* @retval syndrome value.
|
||||
*/
|
||||
uint32_t ERM_GetSyndrome(ERM_Type *base, erm_memory_channel_t channel);
|
||||
|
||||
/*!
|
||||
* @brief ERM get error count, which records the count value of the number of correctable ECC error events for Memory
|
||||
* n. Non-correctable errors are considered a serious fault, so the ERM does not provide any mechanism to count
|
||||
* non-correctable errors. Only correctable errors are counted.
|
||||
*
|
||||
* @param base ERM base address.
|
||||
* @param channel memory channel.
|
||||
* @retval error count.
|
||||
*/
|
||||
uint32_t ERM_GetErrorCount(ERM_Type *base, erm_memory_channel_t channel);
|
||||
|
||||
/*!
|
||||
* @brief ERM reset error count.
|
||||
*
|
||||
* @param base ERM base address.
|
||||
* @param channel memory channel.
|
||||
*/
|
||||
void ERM_ResetErrorCount(ERM_Type *base, erm_memory_channel_t channel);
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,418 @@
|
||||
/*
|
||||
* Copyright 2022 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "fsl_evtg.h"
|
||||
|
||||
/* Component ID definition, used by tools. */
|
||||
#ifndef FSL_COMPONENT_ID
|
||||
#define FSL_COMPONENT_ID "platform.drivers.evtg"
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* brief Initialize EVTG with a user configuration structure.
|
||||
*
|
||||
* param base EVTG base address.
|
||||
* param evtgIndex EVTG instance index.
|
||||
* param psConfig EVTG initial configuration structure pointer.
|
||||
*/
|
||||
void EVTG_Init(EVTG_Type *base, evtg_index_t evtgIndex, evtg_config_t *psConfig)
|
||||
{
|
||||
/* Configure Flip-Flop as expected mode. */
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_CTRL = EVTG_EVTG_INST_EVTG_CTRL_MODE_SEL((uint16_t)psConfig->flipflopMode);
|
||||
|
||||
if (kEVTG_FFModeJKFF == psConfig->flipflopMode)
|
||||
{
|
||||
/* When FF Mode is configured as JK-FF mode, need EVTG_OUTA feedback to EVTG input and replace one of the four
|
||||
* inputs.*/
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_CTRL |=
|
||||
EVTG_EVTG_INST_EVTG_CTRL_FB_OVRD((uint16_t)psConfig->outfdbkOverideinput);
|
||||
}
|
||||
|
||||
if (psConfig->enableFlipflopInitOutput == true)
|
||||
{
|
||||
EVTG_ForceFlipflopInitOutput(base, evtgIndex, psConfig->flipflopInitOutputValue);
|
||||
}
|
||||
|
||||
#if defined(FSL_FEATURE_EVTG_HAS_FORCE_BYPASS_FLIPFLOP) && FSL_FEATURE_EVTG_HAS_FORCE_BYPASS_FLIPFLOP
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_CTRL |= EVTG_EVTG_INST_EVTG_CTRL_FORCE_BYPASS(
|
||||
((uint16_t)psConfig->enableForceBypassFlipFlopAOI1 << 1U) | (uint16_t)psConfig->enableForceBypassFlipFlopAOI0);
|
||||
#endif
|
||||
|
||||
/* Configure EVTG input sync. */
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_CTRL |= EVTG_EVTG_INST_EVTG_CTRL_SYNC_CTRL(
|
||||
(((uint16_t)psConfig->enableInputDSync << 3U) | ((uint16_t)psConfig->enableInputCSync << 2U) |
|
||||
((uint16_t)psConfig->enableInputBSync << 1U) | ((uint16_t)psConfig->enableInputASync)));
|
||||
|
||||
/* Configure AOI0. */
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI0_BFT01 =
|
||||
(EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT0_AC((uint8_t)psConfig->aoi0Config.productTerm0.aInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT0_BC((uint8_t)psConfig->aoi0Config.productTerm0.bInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT0_CC((uint8_t)psConfig->aoi0Config.productTerm0.cInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT0_DC((uint8_t)psConfig->aoi0Config.productTerm0.dInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT1_AC((uint8_t)psConfig->aoi0Config.productTerm1.aInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT1_BC((uint8_t)psConfig->aoi0Config.productTerm1.bInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT1_CC((uint8_t)psConfig->aoi0Config.productTerm1.cInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT1_DC((uint8_t)psConfig->aoi0Config.productTerm1.dInput));
|
||||
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI0_BFT23 =
|
||||
(EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT2_AC((uint8_t)psConfig->aoi0Config.productTerm2.aInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT2_BC((uint8_t)psConfig->aoi0Config.productTerm2.bInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT2_CC((uint8_t)psConfig->aoi0Config.productTerm2.cInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT2_DC((uint8_t)psConfig->aoi0Config.productTerm2.dInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT3_AC((uint8_t)psConfig->aoi0Config.productTerm3.aInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT3_BC((uint8_t)psConfig->aoi0Config.productTerm3.bInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT3_CC((uint8_t)psConfig->aoi0Config.productTerm3.cInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT3_DC((uint8_t)psConfig->aoi0Config.productTerm3.dInput));
|
||||
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI0_FILT |=
|
||||
(EVTG_EVTG_INST_EVTG_AOI0_FILT_FILT_CNT((uint16_t)psConfig->aoi0Config.aoiOutFilterConfig.sampleCount) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_FILT_FILT_PER(psConfig->aoi0Config.aoiOutFilterConfig.samplePeriod));
|
||||
|
||||
/* Configure AOI1. */
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI1_BFT01 =
|
||||
(EVTG_EVTG_INST_EVTG_AOI1_BFT01_PT0_AC((uint8_t)psConfig->aoi1Config.productTerm0.aInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_BFT01_PT0_BC((uint8_t)psConfig->aoi1Config.productTerm0.bInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_BFT01_PT0_CC((uint8_t)psConfig->aoi1Config.productTerm0.cInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_BFT01_PT0_DC((uint8_t)psConfig->aoi1Config.productTerm0.dInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_BFT01_PT1_AC((uint8_t)psConfig->aoi1Config.productTerm1.aInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_BFT01_PT1_BC((uint8_t)psConfig->aoi1Config.productTerm1.bInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_BFT01_PT1_CC((uint8_t)psConfig->aoi1Config.productTerm1.cInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_BFT01_PT1_DC((uint8_t)psConfig->aoi1Config.productTerm1.dInput));
|
||||
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI1_BFT23 =
|
||||
(EVTG_EVTG_INST_EVTG_AOI1_BFT23_PT2_AC((uint8_t)psConfig->aoi1Config.productTerm2.aInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_BFT23_PT2_BC((uint8_t)psConfig->aoi1Config.productTerm2.bInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_BFT23_PT2_CC((uint8_t)psConfig->aoi1Config.productTerm2.cInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_BFT23_PT2_DC((uint8_t)psConfig->aoi1Config.productTerm2.dInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_BFT23_PT3_AC((uint8_t)psConfig->aoi1Config.productTerm3.aInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_BFT23_PT3_BC((uint8_t)psConfig->aoi1Config.productTerm3.bInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_BFT23_PT3_CC((uint8_t)psConfig->aoi1Config.productTerm3.cInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_BFT23_PT3_DC((uint8_t)psConfig->aoi1Config.productTerm3.dInput));
|
||||
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI1_FILT |=
|
||||
(EVTG_EVTG_INST_EVTG_AOI1_FILT_FILT_CNT((uint16_t)psConfig->aoi1Config.aoiOutFilterConfig.sampleCount) |
|
||||
EVTG_EVTG_INST_EVTG_AOI1_FILT_FILT_PER(psConfig->aoi1Config.aoiOutFilterConfig.samplePeriod));
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Configure AOI product term by initializing the product term
|
||||
* configuration structure.
|
||||
*
|
||||
* param base EVTG base address.
|
||||
* param evtgIndex EVTG instance index.
|
||||
* param aoiIndex EVTG AOI index. see enum ref evtg_aoi_index_t
|
||||
* param productTerm EVTG AOI product term index.
|
||||
* param psProductTermConfig Pointer to EVTG product term configuration structure.
|
||||
* see ref _evtg_product_term_config
|
||||
*/
|
||||
void EVTG_ConfigAOIProductTerm(EVTG_Type *base,
|
||||
evtg_index_t evtgIndex,
|
||||
evtg_aoi_index_t aoiIndex,
|
||||
evtg_aoi_product_term_t productTerm,
|
||||
evtg_aoi_product_term_config_t *psProductTermConfig)
|
||||
{
|
||||
volatile uint16_t *pu16AOIPT01Config;
|
||||
volatile uint16_t *pu16AOIPT23Config;
|
||||
|
||||
if (kEVTG_AOI0 == aoiIndex)
|
||||
{
|
||||
pu16AOIPT01Config = &base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI0_BFT01;
|
||||
pu16AOIPT23Config = &base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI0_BFT23;
|
||||
}
|
||||
else
|
||||
{
|
||||
pu16AOIPT01Config = &base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI1_BFT01;
|
||||
pu16AOIPT23Config = &base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI1_BFT23;
|
||||
}
|
||||
|
||||
if (kEVTG_ProductTerm0 == productTerm)
|
||||
{
|
||||
*pu16AOIPT01Config &=
|
||||
~(uint16_t)(EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT0_AC_MASK | EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT0_BC_MASK |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT0_CC_MASK | EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT0_DC_MASK);
|
||||
*pu16AOIPT01Config |= (EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT0_AC((uint8_t)psProductTermConfig->aInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT0_BC((uint8_t)psProductTermConfig->bInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT0_CC((uint8_t)psProductTermConfig->cInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT0_DC((uint8_t)psProductTermConfig->dInput));
|
||||
}
|
||||
else if (kEVTG_ProductTerm1 == productTerm)
|
||||
{
|
||||
*pu16AOIPT01Config &=
|
||||
~(uint16_t)(EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT1_AC_MASK | EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT1_BC_MASK |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT1_CC_MASK | EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT1_DC_MASK);
|
||||
*pu16AOIPT01Config |= (EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT1_AC((uint8_t)psProductTermConfig->aInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT1_BC((uint8_t)psProductTermConfig->bInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT1_CC((uint8_t)psProductTermConfig->cInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT01_PT1_DC((uint8_t)psProductTermConfig->dInput));
|
||||
}
|
||||
else if (kEVTG_ProductTerm2 == productTerm)
|
||||
{
|
||||
*pu16AOIPT23Config &=
|
||||
~(uint16_t)(EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT2_AC_MASK | EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT2_BC_MASK |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT2_CC_MASK | EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT2_DC_MASK);
|
||||
*pu16AOIPT23Config |= (EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT2_AC((uint8_t)psProductTermConfig->aInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT2_BC((uint8_t)psProductTermConfig->bInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT2_CC((uint8_t)psProductTermConfig->cInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT2_DC((uint8_t)psProductTermConfig->dInput));
|
||||
}
|
||||
else
|
||||
{
|
||||
*pu16AOIPT23Config &=
|
||||
~(uint16_t)(EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT3_AC_MASK | EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT3_BC_MASK |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT3_CC_MASK | EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT3_DC_MASK);
|
||||
*pu16AOIPT23Config |= (EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT3_AC((uint8_t)psProductTermConfig->aInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT3_BC((uint8_t)psProductTermConfig->bInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT3_CC((uint8_t)psProductTermConfig->cInput) |
|
||||
EVTG_EVTG_INST_EVTG_AOI0_BFT23_PT3_DC((uint8_t)psProductTermConfig->dInput));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Loads default values to the EVTG configuration structure.
|
||||
*
|
||||
* The purpose of this API is to initialize the configuration structure to default value for @ref EVTG_Init()
|
||||
* to use.
|
||||
* The Flip-Flop can be configured as Bypass mode, RS trigger mode, T-FF mode, D-FF mode, JK-FF mode, Latch mode.
|
||||
* Please check RM INTC chapter for more details.
|
||||
*
|
||||
* @param psConfig EVTG initial configuration structure pointer.
|
||||
* @param flipflopMode EVTG flip flop mode. see @ ref _evtg_flipflop_mode
|
||||
*/
|
||||
void EVTG_GetDefaultConfig(evtg_config_t *psConfig, evtg_flipflop_mode_t flipflopMode)
|
||||
{
|
||||
/* Initializes the configure structure to zero. */
|
||||
(void)memset(psConfig, 0, sizeof(evtg_config_t));
|
||||
|
||||
switch (flipflopMode)
|
||||
{
|
||||
case kEVTG_FFModeBypass:
|
||||
|
||||
/*
|
||||
* In this mode, filp-flop will be passed, The two AOI expressions "AOI_0" and "AOI_1"
|
||||
* will be directly assigned to EVTG outputs(EVTG_OUTA and EVTG_OUTB).
|
||||
*
|
||||
* In this mode, user can choose to enable or disable input sync logic and filter function.
|
||||
* Here disable both input sync logic and filter function.
|
||||
*/
|
||||
psConfig->flipflopMode = kEVTG_FFModeBypass;
|
||||
|
||||
psConfig->enableInputASync = false;
|
||||
psConfig->enableInputBSync = false;
|
||||
psConfig->enableInputCSync = false;
|
||||
psConfig->enableInputDSync = false;
|
||||
|
||||
break;
|
||||
|
||||
case kEVTG_FFModeRSTrigger:
|
||||
|
||||
/*
|
||||
* In this mode, AOI_0 expression is Reset port, and AOI_1 is Set port. Both are active
|
||||
* high. When "R"(Reset) is high, whatever "S"(Set) is, EVTG_OUTA will be "0". When "R" is
|
||||
* low and "S" is high, EVTG_OUTA will be "1". If both "R" and "S" are low, EVTG output
|
||||
* will be kept. EVTG_OUTB is always the complement of EVTG_OUTA.
|
||||
*
|
||||
* In this mode, user can choose to enable or disable input sync logic and filter function.
|
||||
* Here disable both input sync logic and filter function.
|
||||
*/
|
||||
psConfig->flipflopMode = kEVTG_FFModeRSTrigger;
|
||||
|
||||
psConfig->enableInputASync = false;
|
||||
psConfig->enableInputBSync = false;
|
||||
psConfig->enableInputCSync = false;
|
||||
psConfig->enableInputDSync = false;
|
||||
|
||||
break;
|
||||
|
||||
case kEVTG_FFModeTFF:
|
||||
|
||||
/*
|
||||
* In this mode, AOI_0 expression is T port of T-FF, AOI_1 is CLK port. When T assert,
|
||||
* the Q port (EVTG_OUTA) will turnover at the rising edge of "CLK". When T dis-assert,
|
||||
* Q(EVTG_OUTA) will be kept. EVTG_OUTB is always the complement of EVTG_OUTA.
|
||||
*
|
||||
* In this mode, input sync or filter has to be enabled to remove the possible glitch.
|
||||
* Here input sync is enabled, filter is disabled. User could override corresponding fields
|
||||
* depends on the actual user case to choose to enable or disable input sync logic and filter
|
||||
* function.
|
||||
*/
|
||||
psConfig->flipflopMode = kEVTG_FFModeTFF;
|
||||
|
||||
psConfig->enableInputASync = true;
|
||||
psConfig->enableInputBSync = true;
|
||||
psConfig->enableInputCSync = true;
|
||||
psConfig->enableInputDSync = true;
|
||||
|
||||
break;
|
||||
|
||||
case kEVTG_FFModeJKFF:
|
||||
|
||||
/*
|
||||
* In general, JK Flip-Flop have four input ports: J, K , Q and CLK(Q is output of Flip-Flop).
|
||||
* And the logical expression is J&~Q | ~K&Q; Here we implement the logic expression by AOI
|
||||
* so that we can reuse the D-FF to implement JK-FF. Suppose we set EVTG input "An" as "J" port,
|
||||
* "Cn" as "K" port, "Dn" as "CLK" port, and "Q" port of FF feed back and override "Bn".
|
||||
* According to the JK logic expression, the AOI_0 expression will be "An&~Bn | Bn&~Cn",
|
||||
* AOI_1 expression will be "Dn".
|
||||
*
|
||||
* In this mode, input sync or filter has to be enabled to remove the possible glitch.
|
||||
* Here input sync is enabled, filter is disabled. User could override corresponding fields
|
||||
* depends on the actual user case to choose to enable or disable input sync logic and filter
|
||||
* function.
|
||||
*
|
||||
* When FF Mode is configured as JK-FF mode, need EVTG_OUTA feedback to EVTG input and replace
|
||||
* one of the four inputs. Here input Bn is replaced, represents which EVTG input(EVTG_OUTA)
|
||||
* is replaced by FF output.
|
||||
*/
|
||||
psConfig->flipflopMode = kEVTG_FFModeJKFF;
|
||||
psConfig->outfdbkOverideinput = kEVTG_OutputOverrideInputB;
|
||||
|
||||
psConfig->enableInputASync = true;
|
||||
psConfig->enableInputBSync = true;
|
||||
psConfig->enableInputCSync = true;
|
||||
psConfig->enableInputDSync = true;
|
||||
|
||||
break;
|
||||
|
||||
case kEVTG_FFModeLatch:
|
||||
|
||||
/*
|
||||
* In this mode, AOI_0 expression is D port, AOI_1 is CLK port. Different from D-FF
|
||||
* mode, in Latch mode, D port will be passed only when CLK is high, and output will be
|
||||
* kept when CLK is low. EVTG_OUTB is always the complement of EVTG_OUTA.
|
||||
*
|
||||
* In this mode, input sync or filter has to be enabled to remove the possible glitch.
|
||||
* Here input sync is enabled, filter is disabled. User could override corresponding fields
|
||||
* depends on the actual user case to choose to enable or disable input sync logic and filter
|
||||
* function.
|
||||
*/
|
||||
psConfig->flipflopMode = kEVTG_FFModeLatch;
|
||||
|
||||
psConfig->enableInputASync = true;
|
||||
psConfig->enableInputBSync = true;
|
||||
psConfig->enableInputCSync = true;
|
||||
psConfig->enableInputDSync = true;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
/* User could choose to enable or disable Flip-flop initial output value. */
|
||||
psConfig->enableFlipflopInitOutput = false;
|
||||
psConfig->flipflopInitOutputValue = kEVTG_FFInitOut0;
|
||||
|
||||
/* User could choose to override this fields to enable filter function. */
|
||||
psConfig->aoi0Config.aoiOutFilterConfig.sampleCount = kEVTG_AOIOutFilterSampleCount3;
|
||||
psConfig->aoi0Config.aoiOutFilterConfig.samplePeriod = 0U;
|
||||
|
||||
psConfig->aoi1Config.aoiOutFilterConfig.sampleCount = kEVTG_AOIOutFilterSampleCount3;
|
||||
psConfig->aoi1Config.aoiOutFilterConfig.samplePeriod = 0U;
|
||||
|
||||
#if defined(FSL_FEATURE_EVTG_HAS_FORCE_BYPASS_FLIPFLOP) && FSL_FEATURE_EVTG_HAS_FORCE_BYPASS_FLIPFLOP
|
||||
psConfig->enableForceBypassFlipFlopAOI0 = false;
|
||||
psConfig->enableForceBypassFlipFlopAOI1 = false;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* For JK-FF Mode, Here we implement the logic expression by AOI so that we can reuse the
|
||||
* D-FF to implement JK-FF. Suppose we set EVTG input "An" as "J" port, "Cn" as "K" port, "Dn"
|
||||
* as "CLK" port, and "Q" port of FF feed back and override "Bn". According to the JK logic
|
||||
* expression, the AOI_0 expression will be "An&~Bn | Bn&~Cn", AOI_1 expression will be "Dn".
|
||||
*
|
||||
* For other FF Mode, the default input here is logical 0. User can configure to produce a logical 0
|
||||
* or 1 or pass the true or complement of the selected event input according to their requirement.
|
||||
*/
|
||||
if (kEVTG_FFModeJKFF == flipflopMode)
|
||||
{
|
||||
psConfig->aoi0Config.productTerm0.aInput = kEVTG_InputDirectPass;
|
||||
psConfig->aoi0Config.productTerm0.bInput = kEVTG_InputComplement;
|
||||
psConfig->aoi0Config.productTerm0.cInput = kEVTG_InputLogicOne;
|
||||
psConfig->aoi0Config.productTerm0.dInput = kEVTG_InputLogicOne;
|
||||
|
||||
psConfig->aoi0Config.productTerm1.aInput = kEVTG_InputLogicOne;
|
||||
psConfig->aoi0Config.productTerm1.bInput = kEVTG_InputDirectPass;
|
||||
psConfig->aoi0Config.productTerm1.cInput = kEVTG_InputComplement;
|
||||
psConfig->aoi0Config.productTerm1.dInput = kEVTG_InputLogicOne;
|
||||
|
||||
psConfig->aoi0Config.productTerm2.aInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm2.bInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm2.cInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm2.dInput = kEVTG_InputLogicZero;
|
||||
|
||||
psConfig->aoi0Config.productTerm3.aInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm3.bInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm3.cInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm3.dInput = kEVTG_InputLogicZero;
|
||||
|
||||
psConfig->aoi1Config.productTerm0.aInput = kEVTG_InputLogicOne;
|
||||
psConfig->aoi1Config.productTerm0.bInput = kEVTG_InputLogicOne;
|
||||
psConfig->aoi1Config.productTerm0.cInput = kEVTG_InputLogicOne;
|
||||
psConfig->aoi1Config.productTerm0.dInput = kEVTG_InputDirectPass;
|
||||
|
||||
psConfig->aoi1Config.productTerm1.aInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm1.bInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm1.cInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm1.dInput = kEVTG_InputLogicZero;
|
||||
|
||||
psConfig->aoi1Config.productTerm2.aInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm2.bInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm2.cInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm2.dInput = kEVTG_InputLogicZero;
|
||||
|
||||
psConfig->aoi1Config.productTerm3.aInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm3.bInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm3.cInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm3.dInput = kEVTG_InputLogicZero;
|
||||
}
|
||||
else
|
||||
{
|
||||
psConfig->aoi0Config.productTerm0.aInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm0.bInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm0.cInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm0.dInput = kEVTG_InputLogicZero;
|
||||
|
||||
psConfig->aoi0Config.productTerm1.aInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm1.bInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm1.cInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm1.dInput = kEVTG_InputLogicZero;
|
||||
|
||||
psConfig->aoi0Config.productTerm2.aInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm2.bInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm2.cInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm2.dInput = kEVTG_InputLogicZero;
|
||||
|
||||
psConfig->aoi0Config.productTerm3.aInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm3.bInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm3.cInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi0Config.productTerm3.dInput = kEVTG_InputLogicZero;
|
||||
|
||||
psConfig->aoi1Config.productTerm0.aInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm0.bInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm0.cInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm0.dInput = kEVTG_InputLogicZero;
|
||||
|
||||
psConfig->aoi1Config.productTerm1.aInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm1.bInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm1.cInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm1.dInput = kEVTG_InputLogicZero;
|
||||
|
||||
psConfig->aoi1Config.productTerm2.aInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm2.bInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm2.cInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm2.dInput = kEVTG_InputLogicZero;
|
||||
|
||||
psConfig->aoi1Config.productTerm3.aInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm3.bInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm3.cInput = kEVTG_InputLogicZero;
|
||||
psConfig->aoi1Config.productTerm3.dInput = kEVTG_InputLogicZero;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
* Copyright 2022 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef FSL_EVTG_H_
|
||||
#define FSL_EVTG_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup evtg
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief EVTG driver version. */
|
||||
#define FSL_EVTG_DRIVER_VERSION (MAKE_VERSION(2, 0, 1)) /*!< Version 2.0.1. */
|
||||
/*@}*/
|
||||
|
||||
/*! @brief EVTG instance index. */
|
||||
typedef enum _evtg_index
|
||||
{
|
||||
kEVTG_Index0 = 0x0U, /*!< EVTG instance index 0. */
|
||||
kEVTG_Index1, /*!< EVTG instance index 1. */
|
||||
kEVTG_Index2, /*!< EVTG instance index 2. */
|
||||
kEVTG_Index3, /*!< EVTG instance index 3. */
|
||||
} evtg_index_t;
|
||||
|
||||
/*! @brief EVTG input index. */
|
||||
typedef enum _evtg_input_index
|
||||
{
|
||||
kEVTG_InputA = 0x0U, /*!< EVTG input A. */
|
||||
kEVTG_InputB, /*!< EVTG input B. */
|
||||
kEVTG_InputC, /*!< EVTG input C. */
|
||||
kEVTG_InputD, /*!< EVTG input D. */
|
||||
} evtg_input_index_t;
|
||||
|
||||
/*! @brief EVTG AOI index. */
|
||||
typedef enum _evtg_aoi_index
|
||||
{
|
||||
kEVTG_AOI0 = 0x0U, /*!< EVTG AOI index 0. */
|
||||
kEVTG_AOI1 = 0x1U, /*!< EVTG AOI index 1. */
|
||||
} evtg_aoi_index_t;
|
||||
|
||||
/*! @brief EVTG AOI product term index. */
|
||||
typedef enum _evtg_aoi_product_term
|
||||
{
|
||||
kEVTG_ProductTerm0 = 0x0U, /*!< EVTG AOI product term index 0. */
|
||||
kEVTG_ProductTerm1, /*!< EVTG AOI product term index 1. */
|
||||
kEVTG_ProductTerm2, /*!< EVTG AOI product term index 2. */
|
||||
kEVTG_ProductTerm3, /*!< EVTG AOI product term index 3. */
|
||||
} evtg_aoi_product_term_t;
|
||||
|
||||
/*! @brief EVTG input configuration. */
|
||||
typedef enum _evtg_aoi_input_config
|
||||
{
|
||||
kEVTG_InputLogicZero = 0x0U, /*!< Force input in product term to a logical zero. */
|
||||
kEVTG_InputDirectPass, /*!< Pass input in product term. */
|
||||
kEVTG_InputComplement, /*!< Complement input in product term. */
|
||||
kEVTG_InputLogicOne, /*!< Force input in product term to a logical one. */
|
||||
} evtg_aoi_input_config_t;
|
||||
|
||||
/*! @brief EVTG AOI Output Filter Sample Count. */
|
||||
typedef enum _evtg_aoi_outfilter_count
|
||||
{
|
||||
kEVTG_AOIOutFilterSampleCount3 = 0x0U, /*!< EVTG AOI output filter sample count is 3. */
|
||||
kEVTG_AOIOutFilterSampleCount4, /*!< EVTG AOI output filter sample count is 4. */
|
||||
kEVTG_AOIOutFilterSampleCount5, /*!< EVTG AOI output filter sample count is 5. */
|
||||
kEVTG_AOIOutFilterSampleCount6, /*!< EVTG AOI output filter sample count is 6. */
|
||||
kEVTG_AOIOutFilterSampleCount7, /*!< EVTG AOI output filter sample count is 7. */
|
||||
kEVTG_AOIOutFilterSampleCount8, /*!< EVTG AOI output filter sample count is 8. */
|
||||
kEVTG_AOIOutFilterSampleCount9, /*!< EVTG AOI output filter sample count is 9. */
|
||||
kEVTG_AOIOutFilterSampleCount10, /*!< EVTG AOI output filter sample count is 10. */
|
||||
} evtg_aoi_outfilter_count_t;
|
||||
|
||||
/*!
|
||||
* @brief EVTG output feedback override control mode. When FF is configured as JK-FF mode,
|
||||
* need EVTG_OUTA feedback to EVTG input and replace one of the four inputs.
|
||||
*/
|
||||
typedef enum _evtg_outfdbk_override_input
|
||||
{
|
||||
kEVTG_OutputOverrideInputA = 0x0U, /*!< Replace input A. */
|
||||
kEVTG_OutputOverrideInputB, /*!< Replace input B. */
|
||||
kEVTG_OutputOverrideInputC, /*!< Replace input C. */
|
||||
kEVTG_OutputOverrideInputD, /*!< Replace input D. */
|
||||
} evtg_outfdbk_override_input_t;
|
||||
|
||||
/*! @brief EVTG flip flop mode configuration. */
|
||||
typedef enum _evtg_flipflop_mode
|
||||
{
|
||||
kEVTG_FFModeBypass = 0x0U, /*!< Bypass mode (default).In this mode, user can choose to enable
|
||||
or disable input sync logic and filter function. */
|
||||
kEVTG_FFModeRSTrigger, /*!< RS trigger mode. In this mode, user can choose to enable
|
||||
or disable input sync logic and filter function. */
|
||||
kEVTG_FFModeTFF, /*!< T-FF mode. In this mode, input sync or filter has to be enabled
|
||||
to remove the possible glitch.*/
|
||||
kEVTG_FFModeDFF, /*!< D-FF mode. In this mode, input sync or filter has to be enabled
|
||||
to remove the possible glitch.*/
|
||||
kEVTG_FFModeJKFF, /*!< JK-FF mode. In this mode, input sync or filter has to be enabled
|
||||
to remove the possible glitch.*/
|
||||
kEVTG_FFModeLatch, /*!< Latch mode. In this mode, input sync or filter has to be enabled
|
||||
to remove the possible glitch.*/
|
||||
} evtg_flipflop_mode_t;
|
||||
|
||||
/*! @brief EVTG flip-flop initial value. */
|
||||
typedef enum _evtg_flipflop_init_output
|
||||
{
|
||||
kEVTG_FFInitOut0 = 0x0U, /*!< Configure the positive output of flip-flop as 0. */
|
||||
kEVTG_FFInitOut1 = 0x1U, /*!< Configure the positive output of flip-flop as 1. */
|
||||
} evtg_flipflop_init_output_t;
|
||||
|
||||
/*! @brief The structure for configuring an AOI output filter sample.
|
||||
*
|
||||
* AOI output filter sample count represent the number of consecutive samples that must agree prior to the AOI output
|
||||
* filter accepting an transition.
|
||||
* AOI output filter sample period represent the sampling period (in IP bus clock cycles) of the AOI output signals.
|
||||
* Each AOI output is sampled multiple times at the rate specified by this period.
|
||||
*
|
||||
* For the modes with Filter function enabled, filter delay is "(FILT_CNT + 3) x FILT_PER + 2".
|
||||
*
|
||||
*/
|
||||
typedef struct _evtg_aoi_outfilter_config
|
||||
{
|
||||
evtg_aoi_outfilter_count_t sampleCount; /*!< EVTG AOI output filter sample count.
|
||||
refer to @ref evtg_aoi_outfilter_count_t. */
|
||||
uint8_t samplePeriod; /*!< EVTG AOI output filter sample period, within 0~255. If sample period
|
||||
value is 0x00 (default), then the input filter is bypassed. */
|
||||
} evtg_aoi_outfilter_config_t;
|
||||
|
||||
/*! @brief The structure for configuring an AOI product term. */
|
||||
typedef struct _evtg_aoi_product_term_config
|
||||
{
|
||||
evtg_aoi_input_config_t aInput; /*!< Input A configuration. */
|
||||
evtg_aoi_input_config_t bInput; /*!< Input B configuration. */
|
||||
evtg_aoi_input_config_t cInput; /*!< Input C configuration. */
|
||||
evtg_aoi_input_config_t dInput; /*!< Input D configuration. */
|
||||
} evtg_aoi_product_term_config_t;
|
||||
|
||||
/*! @brief EVTG AOI configuration structure. */
|
||||
typedef struct _evtg_aoi_config
|
||||
{
|
||||
/* AOI Output Filter configuration. */
|
||||
evtg_aoi_outfilter_config_t aoiOutFilterConfig; /*!< EVTG AOI output filter sample
|
||||
configuration structure. */
|
||||
|
||||
/* Product term configuration. */
|
||||
evtg_aoi_product_term_config_t productTerm0; /*!< Configure AOI product term0. */
|
||||
evtg_aoi_product_term_config_t productTerm1; /*!< Configure AOI product term1. */
|
||||
evtg_aoi_product_term_config_t productTerm2; /*!< Configure AOI product term2. */
|
||||
evtg_aoi_product_term_config_t productTerm3; /*!< Configure AOI product term3. */
|
||||
} evtg_aoi_config_t;
|
||||
|
||||
/*! @brief EVTG configuration covering all configurable fields. */
|
||||
typedef struct _evtg_config
|
||||
{
|
||||
/* Input configuration. */
|
||||
bool enableInputASync; /*!< Enable/Disable EVTG A input synchronous with bus clk. */
|
||||
bool enableInputBSync; /*!< Enable/Disable EVTG B input synchronous with bus clk. */
|
||||
bool enableInputCSync; /*!< Enable/Disable EVTG C input synchronous with bus clk. */
|
||||
bool enableInputDSync; /*!< Enable/Disable EVTG D input synchronous with bus clk. */
|
||||
evtg_outfdbk_override_input_t outfdbkOverideinput; /*!< EVTG output feedback to EVTG input
|
||||
and replace one of the four inputs. */
|
||||
|
||||
/* Flip-flop configuration. */
|
||||
evtg_flipflop_mode_t flipflopMode; /*!< Flip-Flop can be configured as one of Bypass mode, RS trigger mode,
|
||||
T-FF mode, D-FF mode, JK-FF mode, Latch mode. */
|
||||
bool enableFlipflopInitOutput; /*!< Flip-flop initial output value enable/disable. */
|
||||
evtg_flipflop_init_output_t flipflopInitOutputValue; /*!< Flip-flop initial output value configuration. */
|
||||
|
||||
#if defined(FSL_FEATURE_EVTG_HAS_FORCE_BYPASS_FLIPFLOP) && FSL_FEATURE_EVTG_HAS_FORCE_BYPASS_FLIPFLOP
|
||||
bool enableForceBypassFlipFlopAOI0; /*!< Enable/Disable force bypass Flip-Flop and route the AOI_0(Filter_0)
|
||||
value directly to EVTG_OUTA */
|
||||
bool enableForceBypassFlipFlopAOI1; /*!< Enable/Disable force bypass Flip-Flop and route the AOI_1(Filter_1)
|
||||
value directly to EVTG_OUTB */
|
||||
#endif
|
||||
|
||||
/* AOI configuration. */
|
||||
evtg_aoi_config_t aoi0Config; /*!< Configure EVTG AOI0. */
|
||||
evtg_aoi_config_t aoi1Config; /*!< Configure EVTG AOI1. */
|
||||
} evtg_config_t;
|
||||
|
||||
/*! @} */
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @addtogroup evtg_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @name Initialization Interfaces
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initialize EVTG with a user configuration structure.
|
||||
*
|
||||
* @param base EVTG base address.
|
||||
* @param evtgIndex EVTG instance index.
|
||||
* @param psConfig EVTG initial configuration structure pointer.
|
||||
*/
|
||||
void EVTG_Init(EVTG_Type *base, evtg_index_t evtgIndex, evtg_config_t *psConfig);
|
||||
|
||||
/*!
|
||||
* @brief Loads default values to the EVTG configuration structure.
|
||||
*
|
||||
* The purpose of this API is to initialize the configuration structure to default value for @ref EVTG_Init()
|
||||
* to use.
|
||||
* The Flip-Flop can be configured as Bypass mode, RS trigger mode, T-FF mode, D-FF mode, JK-FF mode, Latch mode.
|
||||
* Please check RM INTC chapter for more details.
|
||||
*
|
||||
* @param psConfig EVTG initial configuration structure pointer.
|
||||
* @param flipflopMode EVTG flip flop mode. see @ ref _evtg_flipflop_mode
|
||||
*/
|
||||
void EVTG_GetDefaultConfig(evtg_config_t *psConfig, evtg_flipflop_mode_t flipflopMode);
|
||||
/*! @} */
|
||||
|
||||
/*!
|
||||
* @name Force Init Flipflop Interfaces
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Force Flip-flop initial output value to be presented on flip-flop positive output.
|
||||
*
|
||||
* @param base EVTG base address.
|
||||
* @param evtgIndex EVTG instance index.
|
||||
* @param flipflopInitOutputValue EVTG flip-flop initial output control.
|
||||
* see @ref evtg_flipflop_init_output_t
|
||||
*/
|
||||
static inline void EVTG_ForceFlipflopInitOutput(EVTG_Type *base,
|
||||
evtg_index_t evtgIndex,
|
||||
evtg_flipflop_init_output_t flipflopInitOutputValue)
|
||||
{
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_CTRL &= (~(uint16_t)EVTG_EVTG_INST_EVTG_CTRL_FF_INIT_MASK);
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_CTRL |=
|
||||
EVTG_EVTG_INST_EVTG_CTRL_FF_INIT((uint16_t)flipflopInitOutputValue);
|
||||
/* INIT_EN bit should be set after FF_INIT is set. */
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_CTRL |= EVTG_EVTG_INST_EVTG_CTRL_INIT_EN_MASK;
|
||||
}
|
||||
/*! @} */
|
||||
|
||||
/*!
|
||||
* @name Input Interfaces
|
||||
* @{
|
||||
*/
|
||||
/*!
|
||||
* @brief Configure each input value of AOI product term. Each selected input term in
|
||||
* each product term can be configured to produce a logical 0 or 1 or pass the
|
||||
* true or complement of the selected event input. Adapt to some simple aoi
|
||||
* expressions.
|
||||
*
|
||||
* @param base EVTG base address.
|
||||
* @param evtgIndex EVTG instance index.
|
||||
* @param aoiIndex EVTG AOI index. see enum ref evtg_aoi_index_t
|
||||
* @param productTerm EVTG product term index.
|
||||
* @param inputIndex EVTG input index.
|
||||
* @param input EVTG input configuration with enum @ref evtg_aoi_input_config_t.
|
||||
*/
|
||||
static inline void EVTG_SetProductTermInput(EVTG_Type *base,
|
||||
evtg_index_t evtgIndex,
|
||||
evtg_aoi_index_t aoiIndex,
|
||||
evtg_aoi_product_term_t productTerm,
|
||||
evtg_input_index_t inputIndex,
|
||||
evtg_aoi_input_config_t input)
|
||||
{
|
||||
if (kEVTG_AOI0 == aoiIndex)
|
||||
{
|
||||
if ((productTerm == kEVTG_ProductTerm0) || (productTerm == kEVTG_ProductTerm1))
|
||||
{
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI0_BFT01 &=
|
||||
(uint16_t)(~(3UL << ((3U - ((uint8_t)inputIndex)) * 2U + (((3U - (uint8_t)productTerm) % 2U) * 8U))));
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI0_BFT01 |=
|
||||
((((uint16_t)(input)) << ((3U - ((uint8_t)inputIndex)) * 2U +
|
||||
(((3U - (uint8_t)productTerm) % 2U) * 8U))) &
|
||||
(uint16_t)(3UL << ((3U - ((uint8_t)inputIndex)) * 2U + (((3U - (uint8_t)productTerm) % 2U) * 8U))));
|
||||
}
|
||||
else
|
||||
{
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI0_BFT23 &=
|
||||
(uint16_t)(~(3UL << ((3U - ((uint8_t)inputIndex)) * 2U + (((3U - (uint8_t)productTerm) % 2U) * 8U))));
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI0_BFT23 |=
|
||||
((((uint16_t)(input)) << ((3U - ((uint8_t)inputIndex)) * 2U +
|
||||
(((3U - (uint8_t)productTerm) % 2U) * 8U))) &
|
||||
(uint16_t)(3UL << ((3U - ((uint8_t)inputIndex)) * 2U + (((3U - (uint8_t)productTerm) % 2U) * 8U))));
|
||||
}
|
||||
}
|
||||
else if (kEVTG_AOI1 == aoiIndex)
|
||||
{
|
||||
if ((productTerm == kEVTG_ProductTerm0) || (productTerm == kEVTG_ProductTerm1))
|
||||
{
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI1_BFT01 &=
|
||||
(uint16_t)(~(3UL << ((3U - ((uint8_t)inputIndex)) * 2U + (((3U - (uint8_t)productTerm) % 2U) * 8U))));
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI1_BFT01 |=
|
||||
((((uint16_t)(input)) << ((3U - ((uint8_t)inputIndex)) * 2U +
|
||||
(((3U - (uint8_t)productTerm) % 2U) * 8U))) &
|
||||
(uint16_t)(3UL << ((3U - ((uint8_t)inputIndex)) * 2U + (((3U - (uint8_t)productTerm) % 2U) * 8U))));
|
||||
}
|
||||
else
|
||||
{
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI1_BFT23 &=
|
||||
(uint16_t)(~(3UL << ((3U - ((uint8_t)inputIndex)) * 2U + (((3U - (uint8_t)productTerm) % 2U) * 8U))));
|
||||
base->EVTG_INST[(uint8_t)evtgIndex].EVTG_AOI1_BFT23 |=
|
||||
((((uint16_t)(input)) << ((3U - ((uint8_t)inputIndex)) * 2U +
|
||||
(((3U - (uint8_t)productTerm) % 2U) * 8U))) &
|
||||
(uint16_t)(3UL << ((3U - ((uint8_t)inputIndex)) * 2U + (((3U - (uint8_t)productTerm) % 2U) * 8U))));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
; /* No action*/
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Configure AOI product term by initializing the product term
|
||||
* configuration structure.
|
||||
*
|
||||
* @param base EVTG base address.
|
||||
* @param evtgIndex EVTG instance index.
|
||||
* @param aoiIndex EVTG AOI index. see enum @ref evtg_aoi_index_t
|
||||
* @param productTerm EVTG AOI product term index.
|
||||
* @param psProductTermConfig Pointer to EVTG product term configuration structure.
|
||||
* see ref _evtg_aoi_product_term_config
|
||||
*/
|
||||
void EVTG_ConfigAOIProductTerm(EVTG_Type *base,
|
||||
evtg_index_t evtgIndex,
|
||||
evtg_aoi_index_t aoiIndex,
|
||||
evtg_aoi_product_term_t productTerm,
|
||||
evtg_aoi_product_term_config_t *psProductTermConfig);
|
||||
|
||||
/*! @} */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @} */
|
||||
|
||||
#endif /* FSL_EVTG_H_ */
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2017, 2020 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "fsl_ewm.h"
|
||||
|
||||
/* Component ID definition, used by tools. */
|
||||
#ifndef FSL_COMPONENT_ID
|
||||
#define FSL_COMPONENT_ID "platform.drivers.ewm"
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* 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 the 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.
|
||||
*
|
||||
* This is an 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 the EWM
|
||||
*/
|
||||
void EWM_Init(EWM_Type *base, const ewm_config_t *config)
|
||||
{
|
||||
assert(NULL != config);
|
||||
|
||||
uint8_t value = 0U;
|
||||
|
||||
#if !((defined(FSL_FEATURE_SOC_PCC_COUNT) && FSL_FEATURE_SOC_PCC_COUNT) && \
|
||||
(defined(FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE) && FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE))
|
||||
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
|
||||
CLOCK_EnableClock(kCLOCK_Ewm0);
|
||||
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
|
||||
#endif
|
||||
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 = (uint8_t)config->clockSource;
|
||||
#endif /* FSL_FEATURE_EWM_HAS_CLOCK_SELECT*/
|
||||
|
||||
base->CMPL = config->compareLowValue;
|
||||
base->CMPH = config->compareHighValue;
|
||||
base->CTRL = value;
|
||||
}
|
||||
|
||||
/*!
|
||||
* 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)
|
||||
{
|
||||
EWM_DisableInterrupts(base, (uint32_t)kEWM_InterruptEnable);
|
||||
#if !((defined(FSL_FEATURE_SOC_PCC_COUNT) && FSL_FEATURE_SOC_PCC_COUNT) && \
|
||||
(defined(FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE) && FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE))
|
||||
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
|
||||
CLOCK_DisableClock(kCLOCK_Ewm0);
|
||||
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
|
||||
#endif /* FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE */
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Initializes the EWM configuration structure.
|
||||
*
|
||||
* This function initializes the EWM configuration structure to default values. The default
|
||||
* values are as follows.
|
||||
* 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 the EWM configuration structure.
|
||||
* see ewm_config_t
|
||||
*/
|
||||
void EWM_GetDefaultConfig(ewm_config_t *config)
|
||||
{
|
||||
assert(NULL != config);
|
||||
|
||||
/* Initializes the configure structure to zero. */
|
||||
(void)memset(config, 0, sizeof(*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;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Services the EWM.
|
||||
*
|
||||
* This function resets the EWM counter to zero.
|
||||
*
|
||||
* param base EWM peripheral base address
|
||||
*/
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2017, 2020 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#ifndef FSL_EWM_H_
|
||||
#define FSL_EWM_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup ewm
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
*******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief EWM driver version 2.0.3. */
|
||||
#define FSL_EWM_DRIVER_VERSION (MAKE_VERSION(2, 0, 3))
|
||||
/*@}*/
|
||||
|
||||
/*! @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 with default settings all disabled.
|
||||
*
|
||||
* This structure contains the settings for all of EWM interrupt configurations.
|
||||
*/
|
||||
enum _ewm_interrupt_enable_t
|
||||
{
|
||||
kEWM_InterruptEnable = EWM_CTRL_INTEN_MASK, /*!< Enable the 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 the 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.
|
||||
*
|
||||
* This is an 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 the 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 configuration structure to default values. The default
|
||||
* values are as follows.
|
||||
* @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 the 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 |= (uint8_t)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 &= (uint8_t)(~mask);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets all status flags.
|
||||
*
|
||||
* This function gets all status flags.
|
||||
*
|
||||
* This is an example for getting the 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: a related status flag has been set.
|
||||
* - False: a related status flag is not set.
|
||||
*/
|
||||
static inline uint32_t EWM_GetStatusFlags(EWM_Type *base)
|
||||
{
|
||||
return ((uint32_t)base->CTRL & EWM_CTRL_EWMEN_MASK);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Services the EWM.
|
||||
*
|
||||
* This function resets the 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_ */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,381 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2022 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "fsl_flexcan_edma.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/* Component ID definition, used by tools. */
|
||||
#ifndef FSL_COMPONENT_ID
|
||||
#define FSL_COMPONENT_ID "platform.drivers.flexcan_edma"
|
||||
#endif
|
||||
|
||||
/*<! Structure definition for flexcan_edma_private_handle_t. The structure is private. */
|
||||
typedef struct _flexcan_edma_private_handle
|
||||
{
|
||||
CAN_Type *base;
|
||||
flexcan_edma_handle_t *handle;
|
||||
} flexcan_edma_private_handle_t;
|
||||
|
||||
/* FlexCAN EDMA transfer handle. */
|
||||
enum _flexcan_edma_tansfer_state
|
||||
{
|
||||
KFLEXCAN_RxFifoIdle = 0U, /* Rx Fifo idle. */
|
||||
KFLEXCAN_RxFifoBusy = 1U, /* Rx Fifo busy. */
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
/* Array of FlexCAN peripheral base address. */
|
||||
static CAN_Type *const s_flexcanBases[] = CAN_BASE_PTRS;
|
||||
|
||||
/* Private handle only used for internally. */
|
||||
static flexcan_edma_private_handle_t s_flexcanEdmaPrivateHandle[ARRAY_SIZE(s_flexcanBases)];
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief FlexCAN EDMA receive finished callback function.
|
||||
*
|
||||
* This function is called when FlexCAN Rx FIFO EDMA receive finished.
|
||||
* It disables the FlexCAN Rx FIFO EDMA request and sends
|
||||
* @ref kStatus_FLEXCAN_RxFifoIdle to FlexCAN EDMA callback.
|
||||
*
|
||||
* @param handle The EDMA handle.
|
||||
* @param param Callback function parameter.
|
||||
*/
|
||||
static void FLEXCAN_ReceiveFifoEDMACallback(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds);
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
static void FLEXCAN_ReceiveFifoEDMACallback(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds)
|
||||
{
|
||||
handle = handle;
|
||||
tcds = tcds;
|
||||
#if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
|
||||
flexcan_fd_frame_t *framefd;
|
||||
uint32_t idHitIndex;
|
||||
#endif
|
||||
flexcan_edma_private_handle_t *flexcanPrivateHandle = (flexcan_edma_private_handle_t *)param;
|
||||
|
||||
/*
|
||||
* $Branch Coverage Justification$
|
||||
* (!transferDone) not covered. Unable to simulate DMA transfer error.
|
||||
*/
|
||||
if (transferDone)
|
||||
{
|
||||
#if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
|
||||
if (0U != (flexcanPrivateHandle->base->ERFCR & CAN_ERFCR_ERFEN_MASK))
|
||||
{
|
||||
framefd = flexcanPrivateHandle->handle->framefd;
|
||||
for (uint32_t i = 0; i < flexcanPrivateHandle->handle->frameNum; i++)
|
||||
{
|
||||
/* Enhanced Rx FIFO ID HIT offset is changed dynamically according to data length code (DLC) . */
|
||||
idHitIndex = (DLC_LENGTH_DECODE(framefd->length) + 3U) / 4U;
|
||||
framefd->idhit = framefd->dataWord[idHitIndex];
|
||||
/* Clear the unused frame data. */
|
||||
for (uint32_t j = idHitIndex; j < 16U; j++)
|
||||
{
|
||||
framefd->dataWord[j] = 0x0U;
|
||||
}
|
||||
framefd++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* Disable transfer. */
|
||||
FLEXCAN_TransferAbortReceiveFifoEDMA(flexcanPrivateHandle->base, flexcanPrivateHandle->handle);
|
||||
|
||||
if (NULL != flexcanPrivateHandle->handle->callback)
|
||||
{
|
||||
flexcanPrivateHandle->handle->callback(flexcanPrivateHandle->base, flexcanPrivateHandle->handle,
|
||||
kStatus_FLEXCAN_RxFifoIdle, flexcanPrivateHandle->handle->userData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Initializes the FlexCAN handle, which is used in transactional functions.
|
||||
*
|
||||
* param base FlexCAN peripheral base address.
|
||||
* param handle Pointer to flexcan_edma_handle_t structure.
|
||||
* param callback The callback function.
|
||||
* param userData The parameter of the callback function.
|
||||
* param rxFifoEdmaHandle User-requested DMA handle for Rx FIFO DMA transfer.
|
||||
*/
|
||||
void FLEXCAN_TransferCreateHandleEDMA(CAN_Type *base,
|
||||
flexcan_edma_handle_t *handle,
|
||||
flexcan_edma_transfer_callback_t callback,
|
||||
void *userData,
|
||||
edma_handle_t *rxFifoEdmaHandle)
|
||||
{
|
||||
assert(NULL != handle);
|
||||
|
||||
uint32_t instance = FLEXCAN_GetInstance(base);
|
||||
s_flexcanEdmaPrivateHandle[instance].base = base;
|
||||
s_flexcanEdmaPrivateHandle[instance].handle = handle;
|
||||
|
||||
(void)memset(handle, 0, sizeof(flexcan_edma_handle_t));
|
||||
|
||||
handle->rxFifoState = (uint8_t)KFLEXCAN_RxFifoIdle;
|
||||
handle->rxFifoEdmaHandle = rxFifoEdmaHandle;
|
||||
|
||||
/* Register Callback. */
|
||||
handle->callback = callback;
|
||||
handle->userData = userData;
|
||||
|
||||
/* Configure Legacy/Enhanced Rx FIFO DMA callback. */
|
||||
EDMA_SetCallback(handle->rxFifoEdmaHandle, FLEXCAN_ReceiveFifoEDMACallback, &s_flexcanEdmaPrivateHandle[instance]);
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Prepares the eDMA transfer configuration for FLEXCAN Legacy RX FIFO.
|
||||
*
|
||||
* This function prepares the eDMA transfer configuration structure according to FLEXCAN Legacy RX FIFO.
|
||||
*
|
||||
* param base FlexCAN peripheral base address.
|
||||
* param pFifoXfer FlexCAN Rx FIFO EDMA transfer structure, see #flexcan_fifo_transfer_t.
|
||||
* param pEdmaConfig The user configuration structure of type edma_transfer_t.
|
||||
*
|
||||
*/
|
||||
void FLEXCAN_PrepareTransfConfiguration(CAN_Type *base,
|
||||
flexcan_fifo_transfer_t *pFifoXfer,
|
||||
edma_transfer_config_t *pEdmaConfig)
|
||||
{
|
||||
assert(NULL != pFifoXfer);
|
||||
assert(NULL != pFifoXfer->frame);
|
||||
assert(NULL != pEdmaConfig);
|
||||
|
||||
flexcan_frame_t *fifoAddr = (flexcan_frame_t *)FLEXCAN_GetRxFifoHeadAddr(base);
|
||||
|
||||
#if (defined(FSL_FEATURE_EDMA_SUPPORT_16_BYTES_TRANSFER) && FSL_FEATURE_EDMA_SUPPORT_16_BYTES_TRANSFER)
|
||||
EDMA_PrepareTransfer(pEdmaConfig, (void *)fifoAddr, sizeof(flexcan_frame_t), (void *)pFifoXfer->frame,
|
||||
sizeof(uint32_t), sizeof(flexcan_frame_t), sizeof(flexcan_frame_t) * pFifoXfer->frameNum,
|
||||
kEDMA_PeripheralToMemory);
|
||||
#else
|
||||
/* The Data Size of FLEXCAN Legacy RX FIFO output port is 16 Bytes, but lots of chips not support 16Bytes width DMA
|
||||
* transfer. These chips always support 4Byte width memory transfer, so we need prepare Memory to Memory mode by 4
|
||||
* Bytes width mode.
|
||||
*/
|
||||
EDMA_PrepareTransfer(pEdmaConfig, (void *)fifoAddr, 4U, (void *)pFifoXfer->frame, sizeof(uint32_t),
|
||||
sizeof(flexcan_frame_t), sizeof(flexcan_frame_t) * pFifoXfer->frameNum, kEDMA_MemoryToMemory);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Start Transfer Data from the FLEXCAN Legacy Rx FIFO using eDMA.
|
||||
*
|
||||
* This function to Update edma transfer confiugration and Start eDMA transfer
|
||||
*
|
||||
* param base FlexCAN peripheral base address.
|
||||
* param handle Pointer to flexcan_edma_handle_t structure.
|
||||
* param pEdmaConfig The user configuration structure of type edma_transfer_t.
|
||||
* retval kStatus_Success if succeed, others failed.
|
||||
* retval kStatus_FLEXCAN_RxFifoBusy Previous transfer ongoing.
|
||||
*/
|
||||
status_t FLEXCAN_StartTransferDatafromRxFIFO(CAN_Type *base,
|
||||
flexcan_edma_handle_t *handle,
|
||||
edma_transfer_config_t *pEdmaConfig)
|
||||
{
|
||||
assert(NULL != handle->rxFifoEdmaHandle);
|
||||
assert(NULL != pEdmaConfig);
|
||||
status_t status;
|
||||
|
||||
/* If previous Rx FIFO receive not finished. */
|
||||
if ((uint8_t)KFLEXCAN_RxFifoBusy == handle->rxFifoState)
|
||||
{
|
||||
status = kStatus_FLEXCAN_RxFifoBusy;
|
||||
}
|
||||
else
|
||||
{
|
||||
handle->rxFifoState = (uint8_t)KFLEXCAN_RxFifoBusy;
|
||||
|
||||
/* Enable FlexCAN Rx FIFO EDMA. */
|
||||
FLEXCAN_EnableRxFifoDMA(base, true);
|
||||
|
||||
/* Submit configuration. */
|
||||
(void)EDMA_SubmitTransfer(handle->rxFifoEdmaHandle, (const edma_transfer_config_t *)pEdmaConfig);
|
||||
EDMA_SetModulo(handle->rxFifoEdmaHandle->base, handle->rxFifoEdmaHandle->channel, kEDMA_Modulo16bytes,
|
||||
kEDMA_ModuloDisable);
|
||||
/* Start transfer. */
|
||||
EDMA_StartTransfer(handle->rxFifoEdmaHandle);
|
||||
|
||||
status = kStatus_Success;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Receives the CAN Messages from the Legacy Rx FIFO using eDMA.
|
||||
*
|
||||
* This function receives the CAN Message using eDMA. This is a non-blocking function, which returns
|
||||
* right away. After the CAN Message is received, the receive callback function is called.
|
||||
*
|
||||
* param base FlexCAN peripheral base address.
|
||||
* param handle Pointer to flexcan_edma_handle_t structure.
|
||||
* param pFifoXfer FlexCAN Rx FIFO EDMA transfer structure, see #flexcan_fifo_transfer_t.
|
||||
* retval kStatus_Success if succeed, others failed.
|
||||
* retval kStatus_FLEXCAN_RxFifoBusy Previous transfer ongoing.
|
||||
*/
|
||||
status_t FLEXCAN_TransferReceiveFifoEDMA(CAN_Type *base,
|
||||
flexcan_edma_handle_t *handle,
|
||||
flexcan_fifo_transfer_t *pFifoXfer)
|
||||
{
|
||||
assert(NULL != handle->rxFifoEdmaHandle);
|
||||
assert(NULL != pFifoXfer->frame);
|
||||
|
||||
edma_transfer_config_t dmaXferConfig = {0};
|
||||
status_t status;
|
||||
|
||||
handle->frameNum = pFifoXfer->frameNum;
|
||||
/* Prepare transfer. */
|
||||
FLEXCAN_PrepareTransfConfiguration(base, pFifoXfer, &dmaXferConfig);
|
||||
|
||||
/* Submit configuration and start edma transfer. */
|
||||
status = FLEXCAN_StartTransferDatafromRxFIFO(base, handle, &dmaXferConfig);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Gets the Legacy Rx Fifo transfer status during a interrupt non-blocking receive.
|
||||
*
|
||||
* param base FlexCAN peripheral base address.
|
||||
* param handle FlexCAN handle pointer.
|
||||
* param count Number of CAN messages receive so far by the non-blocking transaction.
|
||||
* retval kStatus_InvalidArgument count is Invalid.
|
||||
* retval kStatus_Success Successfully return the count.
|
||||
*/
|
||||
|
||||
status_t FLEXCAN_TransferGetReceiveFifoCountEMDA(CAN_Type *base, flexcan_edma_handle_t *handle, size_t *count)
|
||||
{
|
||||
assert(NULL != handle);
|
||||
|
||||
status_t result = kStatus_Success;
|
||||
|
||||
if (handle->rxFifoState == (uint32_t)KFLEXCAN_RxFifoIdle)
|
||||
{
|
||||
result = kStatus_NoTransferInProgress;
|
||||
}
|
||||
else
|
||||
{
|
||||
*count = handle->frameNum -
|
||||
EDMA_GetRemainingMajorLoopCount(handle->rxFifoEdmaHandle->base, handle->rxFifoEdmaHandle->channel);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Aborts the receive Legacy/Enhanced Rx FIFO process which used eDMA.
|
||||
*
|
||||
* This function aborts the receive Legacy/Enhanced Rx FIFO process which used eDMA.
|
||||
*
|
||||
* param base FlexCAN peripheral base address.
|
||||
* param handle Pointer to flexcan_edma_handle_t structure.
|
||||
*/
|
||||
void FLEXCAN_TransferAbortReceiveFifoEDMA(CAN_Type *base, flexcan_edma_handle_t *handle)
|
||||
{
|
||||
assert(NULL != handle->rxFifoEdmaHandle);
|
||||
|
||||
/* Stop transfer. */
|
||||
EDMA_AbortTransfer(handle->rxFifoEdmaHandle);
|
||||
|
||||
handle->rxFifoState = (uint8_t)KFLEXCAN_RxFifoIdle;
|
||||
#if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
|
||||
handle->framefd = NULL;
|
||||
#endif
|
||||
handle->frameNum = 0U;
|
||||
/* Disable FlexCAN Legacy/Enhanced Rx FIFO EDMA. */
|
||||
FLEXCAN_EnableRxFifoDMA(base, false);
|
||||
}
|
||||
|
||||
#if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
|
||||
/*!
|
||||
* brief Receives the CAN FD Message from the Enhanced Rx FIFO using eDMA.
|
||||
*
|
||||
* This function receives the CAN FD Message using eDMA. This is a non-blocking function, which returns
|
||||
* right away. After the CAN Message is received, the receive callback function is called.
|
||||
*
|
||||
* param base FlexCAN peripheral base address.
|
||||
* param handle Pointer to flexcan_edma_handle_t structure.
|
||||
* param pFifoXfer FlexCAN Rx FIFO EDMA transfer structure, see #flexcan_fifo_transfer_t.
|
||||
* retval kStatus_Success if succeed, others failed.
|
||||
* retval kStatus_FLEXCAN_RxFifoBusy Previous transfer ongoing.
|
||||
* retval kStatus_InvalidArgument The watermark configuration is invalid, the watermark need be set to
|
||||
1 to do successfully EDMA transfer with this API.
|
||||
*/
|
||||
status_t FLEXCAN_TransferReceiveEnhancedFifoEDMA(CAN_Type *base,
|
||||
flexcan_edma_handle_t *handle,
|
||||
flexcan_fifo_transfer_t *pFifoXfer)
|
||||
{
|
||||
assert(NULL != handle->rxFifoEdmaHandle);
|
||||
assert(NULL != pFifoXfer->framefd);
|
||||
|
||||
edma_transfer_config_t dmaXferConfig;
|
||||
edma_minor_offset_config_t dmaMinorOffsetConfig;
|
||||
status_t status;
|
||||
flexcan_fd_frame_t *fifoAddr = (flexcan_fd_frame_t *)E_RX_FIFO(base);
|
||||
uint32_t perReadWords = ((base->ERFCR & CAN_ERFCR_DMALW_MASK) >> CAN_ERFCR_DMALW_SHIFT) + 1U;
|
||||
uint32_t watermark = ((base->ERFCR & CAN_ERFCR_ERFWM_MASK) >> CAN_ERFCR_ERFWM_SHIFT) + 1U;
|
||||
|
||||
/* If previous Rx FIFO receive not finished. */
|
||||
if ((uint8_t)KFLEXCAN_RxFifoBusy == handle->rxFifoState)
|
||||
{
|
||||
status = kStatus_FLEXCAN_RxFifoBusy;
|
||||
}
|
||||
else
|
||||
{
|
||||
handle->frameNum = pFifoXfer->frameNum;
|
||||
handle->framefd = pFifoXfer->framefd;
|
||||
/*!< To reduce the complexity of DMA software configuration, need to set watermark to 1 to make that each DMA
|
||||
request read once Rx FIFO. Because a DMA transfer cannot be dynamically changed, Number of words read per
|
||||
transfer (ERFCR[DMALW] + 1) should be programmed so that the Enhanced Rx FIFO element can store the largest
|
||||
CAN message present on the CAN bus. */
|
||||
if ((watermark != 1U) || ((sizeof(uint32_t) * perReadWords) != sizeof(flexcan_fd_frame_t)))
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
/* Prepare transfer. */
|
||||
EDMA_PrepareTransfer(
|
||||
&dmaXferConfig, (void *)fifoAddr, sizeof(uint32_t), (void *)pFifoXfer->framefd, sizeof(uint32_t),
|
||||
sizeof(uint32_t) * perReadWords, /* minor loop bytes : 4* perReadWords */
|
||||
sizeof(uint32_t) * perReadWords * handle->frameNum, /* major loop counts : handle->frameNum */
|
||||
kEDMA_MemoryToMemory);
|
||||
/* Submit configuration. */
|
||||
(void)EDMA_SubmitTransfer(handle->rxFifoEdmaHandle, &dmaXferConfig);
|
||||
|
||||
dmaMinorOffsetConfig.enableDestMinorOffset = false;
|
||||
dmaMinorOffsetConfig.enableSrcMinorOffset = true;
|
||||
dmaMinorOffsetConfig.minorOffset = 128U - sizeof(uint32_t) * perReadWords;
|
||||
EDMA_SetMinorOffsetConfig(handle->rxFifoEdmaHandle->base, handle->rxFifoEdmaHandle->channel,
|
||||
&dmaMinorOffsetConfig);
|
||||
|
||||
EDMA_SetModulo(handle->rxFifoEdmaHandle->base, handle->rxFifoEdmaHandle->channel, kEDMA_Modulo128bytes,
|
||||
kEDMA_ModuloDisable);
|
||||
|
||||
handle->rxFifoState = (uint8_t)KFLEXCAN_RxFifoBusy;
|
||||
|
||||
/* Enable FlexCAN Rx FIFO EDMA. */
|
||||
FLEXCAN_EnableRxFifoDMA(base, true);
|
||||
/* Start transfer. */
|
||||
EDMA_StartTransfer(handle->rxFifoEdmaHandle);
|
||||
|
||||
status = kStatus_Success;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2023 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#ifndef FSL_FLEXCAN_EDMA_H_
|
||||
#define FSL_FLEXCAN_EDMA_H_
|
||||
|
||||
#include "fsl_flexcan.h"
|
||||
#include "fsl_edma.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup flexcan_edma_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief FlexCAN EDMA driver version. */
|
||||
#define FSL_FLEXCAN_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 11, 3))
|
||||
/*@}*/
|
||||
|
||||
/* Forward declaration of the handle typedef. */
|
||||
typedef struct _flexcan_edma_handle flexcan_edma_handle_t;
|
||||
|
||||
/*! @brief FlexCAN transfer callback function. */
|
||||
typedef void (*flexcan_edma_transfer_callback_t)(CAN_Type *base,
|
||||
flexcan_edma_handle_t *handle,
|
||||
status_t status,
|
||||
void *userData);
|
||||
|
||||
/*!
|
||||
* @brief FlexCAN eDMA handle
|
||||
*/
|
||||
struct _flexcan_edma_handle
|
||||
{
|
||||
flexcan_edma_transfer_callback_t callback; /*!< Callback function. */
|
||||
void *userData; /*!< FlexCAN callback function parameter.*/
|
||||
edma_handle_t *rxFifoEdmaHandle; /*!< The EDMA handler for Rx FIFO. */
|
||||
volatile uint8_t rxFifoState; /*!< Rx FIFO transfer state. */
|
||||
size_t frameNum; /*!< The number of messages that need to be received. */
|
||||
#if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
|
||||
flexcan_fd_frame_t *framefd; /*!< Point to the buffer of CAN Message to be received from Enhanced Rx FIFO. */
|
||||
#endif
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @name eDMA transactional
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes the FlexCAN handle, which is used in transactional functions.
|
||||
*
|
||||
* @param base FlexCAN peripheral base address.
|
||||
* @param handle Pointer to flexcan_edma_handle_t structure.
|
||||
* @param callback The callback function.
|
||||
* @param userData The parameter of the callback function.
|
||||
* @param rxFifoEdmaHandle User-requested DMA handle for Rx FIFO DMA transfer.
|
||||
*/
|
||||
void FLEXCAN_TransferCreateHandleEDMA(CAN_Type *base,
|
||||
flexcan_edma_handle_t *handle,
|
||||
flexcan_edma_transfer_callback_t callback,
|
||||
void *userData,
|
||||
edma_handle_t *rxFifoEdmaHandle);
|
||||
|
||||
/*!
|
||||
* @brief Prepares the eDMA transfer configuration for FLEXCAN Legacy RX FIFO.
|
||||
*
|
||||
* This function prepares the eDMA transfer configuration structure according to FLEXCAN Legacy RX FIFO.
|
||||
*
|
||||
* @param base FlexCAN peripheral base address.
|
||||
* @param pFifoXfer FlexCAN Rx FIFO EDMA transfer structure, see #flexcan_fifo_transfer_t.
|
||||
* @param pEdmaConfig The user configuration structure of type edma_transfer_t.
|
||||
*
|
||||
*/
|
||||
void FLEXCAN_PrepareTransfConfiguration(CAN_Type *base,
|
||||
flexcan_fifo_transfer_t *pFifoXfer,
|
||||
edma_transfer_config_t *pEdmaConfig);
|
||||
|
||||
/*!
|
||||
* @brief Start Transfer Data from the FLEXCAN Legacy Rx FIFO using eDMA.
|
||||
*
|
||||
* This function to Update edma transfer confiugration and Start eDMA transfer
|
||||
*
|
||||
* @param base FlexCAN peripheral base address.
|
||||
* @param handle Pointer to flexcan_edma_handle_t structure.
|
||||
* @param pEdmaConfig The user configuration structure of type edma_transfer_t.
|
||||
* @retval kStatus_Success if succeed, others failed.
|
||||
* @retval kStatus_FLEXCAN_RxFifoBusy Previous transfer ongoing.
|
||||
*/
|
||||
status_t FLEXCAN_StartTransferDatafromRxFIFO(CAN_Type *base,
|
||||
flexcan_edma_handle_t *handle,
|
||||
edma_transfer_config_t *pEdmaConfig);
|
||||
|
||||
/*!
|
||||
* @brief Receives the CAN Message from the Legacy Rx FIFO using eDMA.
|
||||
*
|
||||
* This function receives the CAN Message using eDMA. This is a non-blocking function, which returns
|
||||
* right away. After the CAN Message is received, the receive callback function is called.
|
||||
*
|
||||
* @param base FlexCAN peripheral base address.
|
||||
* @param handle Pointer to flexcan_edma_handle_t structure.
|
||||
* @param pFifoXfer FlexCAN Rx FIFO EDMA transfer structure, see #flexcan_fifo_transfer_t.
|
||||
* @retval kStatus_Success if succeed, others failed.
|
||||
* @retval kStatus_FLEXCAN_RxFifoBusy Previous transfer ongoing.
|
||||
*/
|
||||
status_t FLEXCAN_TransferReceiveFifoEDMA(CAN_Type *base,
|
||||
flexcan_edma_handle_t *handle,
|
||||
flexcan_fifo_transfer_t *pFifoXfer);
|
||||
/*!
|
||||
* @brief Gets the Legacy Rx Fifo transfer status during a interrupt non-blocking receive.
|
||||
*
|
||||
* @param base FlexCAN peripheral base address.
|
||||
* @param handle FlexCAN handle pointer.
|
||||
* @param count Number of CAN messages receive so far by the non-blocking transaction.
|
||||
* @retval kStatus_InvalidArgument count is Invalid.
|
||||
* @retval kStatus_Success Successfully return the count.
|
||||
*/
|
||||
|
||||
status_t FLEXCAN_TransferGetReceiveFifoCountEMDA(CAN_Type *base, flexcan_edma_handle_t *handle, size_t *count);
|
||||
/*!
|
||||
* @brief Aborts the receive Legacy/Enhanced Rx FIFO process which used eDMA.
|
||||
*
|
||||
* This function aborts the receive Legacy/Enhanced Rx FIFO process which used eDMA.
|
||||
*
|
||||
* @param base FlexCAN peripheral base address.
|
||||
* @param handle Pointer to flexcan_edma_handle_t structure.
|
||||
*/
|
||||
void FLEXCAN_TransferAbortReceiveFifoEDMA(CAN_Type *base, flexcan_edma_handle_t *handle);
|
||||
|
||||
#if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO) && FSL_FEATURE_FLEXCAN_HAS_ENHANCED_RX_FIFO)
|
||||
/*!
|
||||
* @brief Receives the CAN FD Message from the Enhanced Rx FIFO using eDMA.
|
||||
*
|
||||
* This function receives the CAN FD Message using eDMA. This is a non-blocking function, which returns
|
||||
* right away. After the CAN Message is received, the receive callback function is called.
|
||||
*
|
||||
* @param base FlexCAN peripheral base address.
|
||||
* @param handle Pointer to flexcan_edma_handle_t structure.
|
||||
* @param pFifoXfer FlexCAN Rx FIFO EDMA transfer structure, see #flexcan_fifo_transfer_t.
|
||||
* @retval kStatus_Success if succeed, others failed.
|
||||
* @retval kStatus_FLEXCAN_RxFifoBusy Previous transfer ongoing.
|
||||
*/
|
||||
status_t FLEXCAN_TransferReceiveEnhancedFifoEDMA(CAN_Type *base,
|
||||
flexcan_edma_handle_t *handle,
|
||||
flexcan_fifo_transfer_t *pFifoXfer);
|
||||
/*!
|
||||
* @brief Gets the Enhanced Rx Fifo transfer status during a interrupt non-blocking receive.
|
||||
*
|
||||
* @param base FlexCAN peripheral base address.
|
||||
* @param handle FlexCAN handle pointer.
|
||||
* @param count Number of CAN messages receive so far by the non-blocking transaction.
|
||||
* @retval kStatus_InvalidArgument count is Invalid.
|
||||
* @retval kStatus_Success Successfully return the count.
|
||||
*/
|
||||
|
||||
static inline status_t FLEXCAN_TransferGetReceiveEnhancedFifoCountEMDA(CAN_Type *base,
|
||||
flexcan_edma_handle_t *handle,
|
||||
size_t *count)
|
||||
{
|
||||
return FLEXCAN_TransferGetReceiveFifoCountEMDA(base, handle, count);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*@}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* FSL_FLEXCAN_EDMA_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,485 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2020 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#ifndef FSL_FLEXIO_I2C_MASTER_H_
|
||||
#define FSL_FLEXIO_I2C_MASTER_H_
|
||||
|
||||
#include "fsl_common.h"
|
||||
#include "fsl_flexio.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup flexio_i2c_master
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
#define FSL_FLEXIO_I2C_MASTER_DRIVER_VERSION (MAKE_VERSION(2, 5, 0))
|
||||
/*@}*/
|
||||
|
||||
/*! @brief Retry times for waiting flag. */
|
||||
#ifndef I2C_RETRY_TIMES
|
||||
#define I2C_RETRY_TIMES 0U /* Define to zero means keep waiting until the flag is assert/deassert. */
|
||||
#endif
|
||||
|
||||
/*! @brief FlexIO I2C transfer status*/
|
||||
enum
|
||||
{
|
||||
kStatus_FLEXIO_I2C_Busy = MAKE_STATUS(kStatusGroup_FLEXIO_I2C, 0), /*!< I2C is busy doing transfer. */
|
||||
kStatus_FLEXIO_I2C_Idle = MAKE_STATUS(kStatusGroup_FLEXIO_I2C, 1), /*!< I2C is busy doing transfer. */
|
||||
kStatus_FLEXIO_I2C_Nak = MAKE_STATUS(kStatusGroup_FLEXIO_I2C, 2), /*!< NAK received during transfer. */
|
||||
kStatus_FLEXIO_I2C_Timeout = MAKE_STATUS(kStatusGroup_FLEXIO_I2C, 3), /*!< Timeout polling status flags. */
|
||||
};
|
||||
|
||||
/*! @brief Define FlexIO I2C master interrupt mask. */
|
||||
enum _flexio_i2c_master_interrupt
|
||||
{
|
||||
kFLEXIO_I2C_TxEmptyInterruptEnable = 0x1U, /*!< Tx buffer empty interrupt enable. */
|
||||
kFLEXIO_I2C_RxFullInterruptEnable = 0x2U, /*!< Rx buffer full interrupt enable. */
|
||||
};
|
||||
|
||||
/*! @brief Define FlexIO I2C master status mask. */
|
||||
enum _flexio_i2c_master_status_flags
|
||||
{
|
||||
kFLEXIO_I2C_TxEmptyFlag = 0x1U, /*!< Tx shifter empty flag. */
|
||||
kFLEXIO_I2C_RxFullFlag = 0x2U, /*!< Rx shifter full/Transfer complete flag. */
|
||||
kFLEXIO_I2C_ReceiveNakFlag = 0x4U, /*!< Receive NAK flag. */
|
||||
};
|
||||
|
||||
/*! @brief Direction of master transfer.*/
|
||||
typedef enum _flexio_i2c_direction
|
||||
{
|
||||
kFLEXIO_I2C_Write = 0x0U, /*!< Master send to slave. */
|
||||
kFLEXIO_I2C_Read = 0x1U, /*!< Master receive from slave. */
|
||||
} flexio_i2c_direction_t;
|
||||
|
||||
/*! @brief Define FlexIO I2C master access structure typedef. */
|
||||
typedef struct _flexio_i2c_type
|
||||
{
|
||||
FLEXIO_Type *flexioBase; /*!< FlexIO base pointer. */
|
||||
uint8_t SDAPinIndex; /*!< Pin select for I2C SDA. */
|
||||
uint8_t SCLPinIndex; /*!< Pin select for I2C SCL. */
|
||||
uint8_t shifterIndex[2]; /*!< Shifter index used in FlexIO I2C. */
|
||||
uint8_t timerIndex[3]; /*!< Timer index used in FlexIO I2C. */
|
||||
uint32_t baudrate; /*!< Master transfer baudrate, used to calculate delay time. */
|
||||
} FLEXIO_I2C_Type;
|
||||
|
||||
/*! @brief Define FlexIO I2C master user configuration structure. */
|
||||
typedef struct _flexio_i2c_master_config
|
||||
{
|
||||
bool enableMaster; /*!< Enables the FlexIO I2C peripheral at initialization time. */
|
||||
bool enableInDoze; /*!< Enable/disable FlexIO operation in doze mode. */
|
||||
bool enableInDebug; /*!< Enable/disable FlexIO operation in debug mode. */
|
||||
bool enableFastAccess; /*!< Enable/disable fast access to FlexIO registers, fast access requires
|
||||
the FlexIO clock to be at least twice the frequency of the bus clock. */
|
||||
uint32_t baudRate_Bps; /*!< Baud rate in Bps. */
|
||||
} flexio_i2c_master_config_t;
|
||||
|
||||
/*! @brief Define FlexIO I2C master transfer structure. */
|
||||
typedef struct _flexio_i2c_master_transfer
|
||||
{
|
||||
uint32_t flags; /*!< Transfer flag which controls the transfer, reserved for FlexIO I2C. */
|
||||
uint8_t slaveAddress; /*!< 7-bit slave address. */
|
||||
flexio_i2c_direction_t direction; /*!< Transfer direction, read or write. */
|
||||
uint32_t subaddress; /*!< Sub address. Transferred MSB first. */
|
||||
uint8_t subaddressSize; /*!< Size of command buffer. */
|
||||
uint8_t volatile *data; /*!< Transfer buffer. */
|
||||
volatile size_t dataSize; /*!< Transfer size. */
|
||||
} flexio_i2c_master_transfer_t;
|
||||
|
||||
/*! @brief FlexIO I2C master handle typedef. */
|
||||
typedef struct _flexio_i2c_master_handle flexio_i2c_master_handle_t;
|
||||
|
||||
/*! @brief FlexIO I2C master transfer callback typedef. */
|
||||
typedef void (*flexio_i2c_master_transfer_callback_t)(FLEXIO_I2C_Type *base,
|
||||
flexio_i2c_master_handle_t *handle,
|
||||
status_t status,
|
||||
void *userData);
|
||||
|
||||
/*! @brief Define FlexIO I2C master handle structure. */
|
||||
struct _flexio_i2c_master_handle
|
||||
{
|
||||
flexio_i2c_master_transfer_t transfer; /*!< FlexIO I2C master transfer copy. */
|
||||
size_t transferSize; /*!< Total bytes to be transferred. */
|
||||
uint8_t state; /*!< Transfer state maintained during transfer. */
|
||||
flexio_i2c_master_transfer_callback_t completionCallback; /*!< Callback function called at transfer event. */
|
||||
/*!< Callback function called at transfer event. */
|
||||
void *userData; /*!< Callback parameter passed to callback function. */
|
||||
bool needRestart; /*!< Whether master needs to send re-start signal. */
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /*_cplusplus*/
|
||||
|
||||
/*!
|
||||
* @name Initialization and deinitialization
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(FSL_FEATURE_FLEXIO_HAS_PIN_STATUS) && FSL_FEATURE_FLEXIO_HAS_PIN_STATUS
|
||||
/*!
|
||||
* @brief Make sure the bus isn't already pulled down.
|
||||
*
|
||||
* Check the FLEXIO pin status to see whether either of SDA and SCL pin is pulled down.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure..
|
||||
* @retval kStatus_Success
|
||||
* @retval kStatus_FLEXIO_I2C_Busy
|
||||
*/
|
||||
status_t FLEXIO_I2C_CheckForBusyBus(FLEXIO_I2C_Type *base);
|
||||
#endif /*FSL_FEATURE_FLEXIO_HAS_PIN_STATUS*/
|
||||
|
||||
/*!
|
||||
* @brief Ungates the FlexIO clock, resets the FlexIO module, and configures the FlexIO I2C
|
||||
* hardware configuration.
|
||||
*
|
||||
* Example
|
||||
@code
|
||||
FLEXIO_I2C_Type base = {
|
||||
.flexioBase = FLEXIO,
|
||||
.SDAPinIndex = 0,
|
||||
.SCLPinIndex = 1,
|
||||
.shifterIndex = {0,1},
|
||||
.timerIndex = {0,1}
|
||||
};
|
||||
flexio_i2c_master_config_t config = {
|
||||
.enableInDoze = false,
|
||||
.enableInDebug = true,
|
||||
.enableFastAccess = false,
|
||||
.baudRate_Bps = 100000
|
||||
};
|
||||
FLEXIO_I2C_MasterInit(base, &config, srcClock_Hz);
|
||||
@endcode
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
* @param masterConfig Pointer to flexio_i2c_master_config_t structure.
|
||||
* @param srcClock_Hz FlexIO source clock in Hz.
|
||||
* @retval kStatus_Success Initialization successful
|
||||
* @retval kStatus_InvalidArgument The source clock exceed upper range limitation
|
||||
*/
|
||||
status_t FLEXIO_I2C_MasterInit(FLEXIO_I2C_Type *base, flexio_i2c_master_config_t *masterConfig, uint32_t srcClock_Hz);
|
||||
|
||||
/*!
|
||||
* @brief De-initializes the FlexIO I2C master peripheral. Calling this API Resets the FlexIO I2C master
|
||||
* shifer and timer config, module can't work unless the FLEXIO_I2C_MasterInit is called.
|
||||
*
|
||||
* @param base pointer to FLEXIO_I2C_Type structure.
|
||||
*/
|
||||
void FLEXIO_I2C_MasterDeinit(FLEXIO_I2C_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Gets the default configuration to configure the FlexIO module. The configuration
|
||||
* can be used directly for calling the FLEXIO_I2C_MasterInit().
|
||||
*
|
||||
* Example:
|
||||
@code
|
||||
flexio_i2c_master_config_t config;
|
||||
FLEXIO_I2C_MasterGetDefaultConfig(&config);
|
||||
@endcode
|
||||
* @param masterConfig Pointer to flexio_i2c_master_config_t structure.
|
||||
*/
|
||||
void FLEXIO_I2C_MasterGetDefaultConfig(flexio_i2c_master_config_t *masterConfig);
|
||||
|
||||
/*!
|
||||
* @brief Enables/disables the FlexIO module operation.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
* @param enable Pass true to enable module, false does not have any effect.
|
||||
*/
|
||||
static inline void FLEXIO_I2C_MasterEnable(FLEXIO_I2C_Type *base, bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
base->flexioBase->CTRL |= FLEXIO_CTRL_FLEXEN_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
/* @} */
|
||||
|
||||
/*!
|
||||
* @name Status
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Gets the FlexIO I2C master status flags.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure
|
||||
* @return Status flag, use status flag to AND #_flexio_i2c_master_status_flags can get the related status.
|
||||
*/
|
||||
|
||||
uint32_t FLEXIO_I2C_MasterGetStatusFlags(FLEXIO_I2C_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Clears the FlexIO I2C master status flags.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
* @param mask Status flag.
|
||||
* The parameter can be any combination of the following values:
|
||||
* @arg kFLEXIO_I2C_RxFullFlag
|
||||
* @arg kFLEXIO_I2C_ReceiveNakFlag
|
||||
*/
|
||||
|
||||
void FLEXIO_I2C_MasterClearStatusFlags(FLEXIO_I2C_Type *base, uint32_t mask);
|
||||
|
||||
/*@}*/
|
||||
|
||||
/*!
|
||||
* @name Interrupts
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Enables the FlexIO i2c master interrupt requests.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
* @param mask Interrupt source.
|
||||
* Currently only one interrupt request source:
|
||||
* @arg kFLEXIO_I2C_TransferCompleteInterruptEnable
|
||||
*/
|
||||
void FLEXIO_I2C_MasterEnableInterrupts(FLEXIO_I2C_Type *base, uint32_t mask);
|
||||
|
||||
/*!
|
||||
* @brief Disables the FlexIO I2C master interrupt requests.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
* @param mask Interrupt source.
|
||||
*/
|
||||
void FLEXIO_I2C_MasterDisableInterrupts(FLEXIO_I2C_Type *base, uint32_t mask);
|
||||
|
||||
/*@}*/
|
||||
|
||||
/*!
|
||||
* @name Bus Operations
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Sets the FlexIO I2C master transfer baudrate.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure
|
||||
* @param baudRate_Bps the baud rate value in HZ
|
||||
* @param srcClock_Hz source clock in HZ
|
||||
*/
|
||||
void FLEXIO_I2C_MasterSetBaudRate(FLEXIO_I2C_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz);
|
||||
|
||||
/*!
|
||||
* @brief Sends START + 7-bit address to the bus.
|
||||
*
|
||||
* @note This API should be called when the transfer configuration is ready to send a START signal
|
||||
* and 7-bit address to the bus. This is a non-blocking API, which returns directly after the address
|
||||
* is put into the data register but the address transfer is not finished on the bus. Ensure that
|
||||
* the kFLEXIO_I2C_RxFullFlag status is asserted before calling this API.
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
* @param address 7-bit address.
|
||||
* @param direction transfer direction.
|
||||
* This parameter is one of the values in flexio_i2c_direction_t:
|
||||
* @arg kFLEXIO_I2C_Write: Transmit
|
||||
* @arg kFLEXIO_I2C_Read: Receive
|
||||
*/
|
||||
|
||||
void FLEXIO_I2C_MasterStart(FLEXIO_I2C_Type *base, uint8_t address, flexio_i2c_direction_t direction);
|
||||
|
||||
/*!
|
||||
* @brief Sends the stop signal on the bus.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
*/
|
||||
void FLEXIO_I2C_MasterStop(FLEXIO_I2C_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Sends the repeated start signal on the bus.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
*/
|
||||
void FLEXIO_I2C_MasterRepeatedStart(FLEXIO_I2C_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Sends the stop signal when transfer is still on-going.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
*/
|
||||
void FLEXIO_I2C_MasterAbortStop(FLEXIO_I2C_Type *base);
|
||||
|
||||
/*!
|
||||
* @brief Configures the sent ACK/NAK for the following byte.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
* @param enable True to configure send ACK, false configure to send NAK.
|
||||
*/
|
||||
void FLEXIO_I2C_MasterEnableAck(FLEXIO_I2C_Type *base, bool enable);
|
||||
|
||||
/*!
|
||||
* @brief Sets the number of bytes to be transferred from a start signal to a stop signal.
|
||||
*
|
||||
* @note Call this API before a transfer begins because the timer generates a number of clocks according
|
||||
* to the number of bytes that need to be transferred.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
* @param count Number of bytes need to be transferred from a start signal to a re-start/stop signal
|
||||
* @retval kStatus_Success Successfully configured the count.
|
||||
* @retval kStatus_InvalidArgument Input argument is invalid.
|
||||
*/
|
||||
status_t FLEXIO_I2C_MasterSetTransferCount(FLEXIO_I2C_Type *base, uint16_t count);
|
||||
|
||||
/*!
|
||||
* @brief Writes one byte of data to the I2C bus.
|
||||
*
|
||||
* @note This is a non-blocking API, which returns directly after the data is put into the
|
||||
* data register but the data transfer is not finished on the bus. Ensure that
|
||||
* the TxEmptyFlag is asserted before calling this API.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
* @param data a byte of data.
|
||||
*/
|
||||
static inline void FLEXIO_I2C_MasterWriteByte(FLEXIO_I2C_Type *base, uint32_t data)
|
||||
{
|
||||
base->flexioBase->SHIFTBUFBBS[base->shifterIndex[0]] = data;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Reads one byte of data from the I2C bus.
|
||||
*
|
||||
* @note This is a non-blocking API, which returns directly after the data is read from the
|
||||
* data register. Ensure that the data is ready in the register.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
* @return data byte read.
|
||||
*/
|
||||
static inline uint8_t FLEXIO_I2C_MasterReadByte(FLEXIO_I2C_Type *base)
|
||||
{
|
||||
return (uint8_t)(base->flexioBase->SHIFTBUFBIS[base->shifterIndex[1]]);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sends a buffer of data in bytes.
|
||||
*
|
||||
* @note This function blocks via polling until all bytes have been sent.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
* @param txBuff The data bytes to send.
|
||||
* @param txSize The number of data bytes to send.
|
||||
* @retval kStatus_Success Successfully write data.
|
||||
* @retval kStatus_FLEXIO_I2C_Nak Receive NAK during writing data.
|
||||
* @retval kStatus_FLEXIO_I2C_Timeout Timeout polling status flags.
|
||||
*/
|
||||
status_t FLEXIO_I2C_MasterWriteBlocking(FLEXIO_I2C_Type *base, const uint8_t *txBuff, uint8_t txSize);
|
||||
|
||||
/*!
|
||||
* @brief Receives a buffer of bytes.
|
||||
*
|
||||
* @note This function blocks via polling until all bytes have been received.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
* @param rxBuff The buffer to store the received bytes.
|
||||
* @param rxSize The number of data bytes to be received.
|
||||
* @retval kStatus_Success Successfully read data.
|
||||
* @retval kStatus_FLEXIO_I2C_Timeout Timeout polling status flags.
|
||||
*/
|
||||
status_t FLEXIO_I2C_MasterReadBlocking(FLEXIO_I2C_Type *base, uint8_t *rxBuff, uint8_t rxSize);
|
||||
|
||||
/*!
|
||||
* @brief Performs a master polling transfer on the I2C bus.
|
||||
*
|
||||
* @note The API does not return until the transfer succeeds or fails due
|
||||
* to receiving NAK.
|
||||
*
|
||||
* @param base pointer to FLEXIO_I2C_Type structure.
|
||||
* @param xfer pointer to flexio_i2c_master_transfer_t structure.
|
||||
* @return status of status_t.
|
||||
*/
|
||||
status_t FLEXIO_I2C_MasterTransferBlocking(FLEXIO_I2C_Type *base, flexio_i2c_master_transfer_t *xfer);
|
||||
/*@}*/
|
||||
|
||||
/*Transactional APIs*/
|
||||
|
||||
/*!
|
||||
* @name Transactional
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes the I2C handle which is used in transactional functions.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
* @param handle Pointer to flexio_i2c_master_handle_t structure to store the transfer state.
|
||||
* @param callback Pointer to user callback function.
|
||||
* @param userData User param passed to the callback function.
|
||||
* @retval kStatus_Success Successfully create the handle.
|
||||
* @retval kStatus_OutOfRange The FlexIO type/handle/isr table out of range.
|
||||
*/
|
||||
status_t FLEXIO_I2C_MasterTransferCreateHandle(FLEXIO_I2C_Type *base,
|
||||
flexio_i2c_master_handle_t *handle,
|
||||
flexio_i2c_master_transfer_callback_t callback,
|
||||
void *userData);
|
||||
|
||||
/*!
|
||||
* @brief Performs a master interrupt non-blocking transfer on the I2C bus.
|
||||
*
|
||||
* @note The API returns immediately after the transfer initiates.
|
||||
* Call FLEXIO_I2C_MasterTransferGetCount to poll the transfer status to check whether
|
||||
* the transfer is finished. If the return status is not kStatus_FLEXIO_I2C_Busy, the transfer
|
||||
* is finished.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure
|
||||
* @param handle Pointer to flexio_i2c_master_handle_t structure which stores the transfer state
|
||||
* @param xfer pointer to flexio_i2c_master_transfer_t structure
|
||||
* @retval kStatus_Success Successfully start a transfer.
|
||||
* @retval kStatus_FLEXIO_I2C_Busy FlexIO I2C is not idle, is running another transfer.
|
||||
*/
|
||||
status_t FLEXIO_I2C_MasterTransferNonBlocking(FLEXIO_I2C_Type *base,
|
||||
flexio_i2c_master_handle_t *handle,
|
||||
flexio_i2c_master_transfer_t *xfer);
|
||||
|
||||
/*!
|
||||
* @brief Gets the master transfer status during a interrupt non-blocking transfer.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure.
|
||||
* @param handle Pointer to flexio_i2c_master_handle_t structure which stores the transfer state.
|
||||
* @param count Number of bytes transferred so far by the non-blocking transaction.
|
||||
* @retval kStatus_InvalidArgument count is Invalid.
|
||||
* @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress.
|
||||
* @retval kStatus_Success Successfully return the count.
|
||||
*/
|
||||
status_t FLEXIO_I2C_MasterTransferGetCount(FLEXIO_I2C_Type *base, flexio_i2c_master_handle_t *handle, size_t *count);
|
||||
|
||||
/*!
|
||||
* @brief Aborts an interrupt non-blocking transfer early.
|
||||
*
|
||||
* @note This API can be called at any time when an interrupt non-blocking transfer initiates
|
||||
* to abort the transfer early.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_I2C_Type structure
|
||||
* @param handle Pointer to flexio_i2c_master_handle_t structure which stores the transfer state
|
||||
*/
|
||||
void FLEXIO_I2C_MasterTransferAbort(FLEXIO_I2C_Type *base, flexio_i2c_master_handle_t *handle);
|
||||
|
||||
/*!
|
||||
* @brief Master interrupt handler.
|
||||
*
|
||||
* @param i2cType Pointer to FLEXIO_I2C_Type structure
|
||||
* @param i2cHandle Pointer to flexio_i2c_master_transfer_t structure
|
||||
*/
|
||||
void FLEXIO_I2C_MasterTransferHandleIRQ(void *i2cType, void *i2cHandle);
|
||||
|
||||
/*@}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /*_cplusplus*/
|
||||
/*@}*/
|
||||
|
||||
#endif /*FSL_FLEXIO_I2C_MASTER_H_*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2020,2023 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef FSL_FLEXIO_MCULCD_EDMA_H_
|
||||
#define FSL_FLEXIO_MCULCD_EDMA_H_
|
||||
|
||||
#include "fsl_edma.h"
|
||||
#include "fsl_flexio_mculcd.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup flexio_edma_mculcd
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*@{*/
|
||||
/*! @brief FlexIO MCULCD EDMA driver version. */
|
||||
#define FSL_FLEXIO_MCULCD_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 0, 5))
|
||||
/*@}*/
|
||||
|
||||
/*! @brief typedef for flexio_mculcd_edma_handle_t in advance. */
|
||||
typedef struct _flexio_mculcd_edma_handle flexio_mculcd_edma_handle_t;
|
||||
|
||||
/*! @brief FlexIO MCULCD master callback for transfer complete.
|
||||
*
|
||||
* When transfer finished, the callback function is called and returns the
|
||||
* @p status as kStatus_FLEXIO_MCULCD_Idle.
|
||||
*/
|
||||
typedef void (*flexio_mculcd_edma_transfer_callback_t)(FLEXIO_MCULCD_Type *base,
|
||||
flexio_mculcd_edma_handle_t *handle,
|
||||
status_t status,
|
||||
void *userData);
|
||||
|
||||
/*! @brief FlexIO MCULCD eDMA transfer handle, users should not touch the
|
||||
* content of the handle.*/
|
||||
struct _flexio_mculcd_edma_handle
|
||||
{
|
||||
FLEXIO_MCULCD_Type *base; /*!< Pointer to the FLEXIO_MCULCD_Type. */
|
||||
uint8_t txShifterNum; /*!< Number of shifters used for TX. */
|
||||
uint8_t rxShifterNum; /*!< Number of shifters used for RX. */
|
||||
uint32_t minorLoopBytes; /*!< eDMA transfer minor loop bytes. */
|
||||
edma_modulo_t txEdmaModulo; /*!< Modulo value for the FlexIO shifter buffer access. */
|
||||
edma_modulo_t rxEdmaModulo; /*!< Modulo value for the FlexIO shifter buffer access. */
|
||||
uint32_t dataAddrOrSameValue; /*!< When sending the same value for many times,
|
||||
this is the value to send. When writing or
|
||||
reading array, this is the address of the
|
||||
data array. */
|
||||
size_t dataCount; /*!< Total count to be transferred. */
|
||||
volatile size_t remainingCount; /*!< Remaining count still not transfered. */
|
||||
volatile uint32_t state; /*!< FlexIO MCULCD driver internal state. */
|
||||
edma_handle_t *txDmaHandle; /*!< DMA handle for MCULCD TX */
|
||||
edma_handle_t *rxDmaHandle; /*!< DMA handle for MCULCD RX */
|
||||
flexio_mculcd_edma_transfer_callback_t completionCallback; /*!< Callback for MCULCD DMA transfer */
|
||||
void *userData; /*!< User Data for MCULCD DMA callback */
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* APIs
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @name eDMA Transactional
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes the FLEXO MCULCD master eDMA handle.
|
||||
*
|
||||
* This function initializes the FLEXO MCULCD master eDMA handle which can be
|
||||
* used for other FLEXO MCULCD transactional APIs. For a specified FLEXO MCULCD
|
||||
* instance, call this API once to get the initialized handle.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_MCULCD_Type structure.
|
||||
* @param handle Pointer to flexio_mculcd_edma_handle_t structure to store the
|
||||
* transfer state.
|
||||
* @param callback MCULCD transfer complete callback, NULL means no callback.
|
||||
* @param userData callback function parameter.
|
||||
* @param txDmaHandle User requested eDMA handle for FlexIO MCULCD eDMA TX,
|
||||
* the DMA request source of this handle should be the first of TX shifters.
|
||||
* @param rxDmaHandle User requested eDMA handle for FlexIO MCULCD eDMA RX,
|
||||
* the DMA request source of this handle should be the last of RX shifters.
|
||||
* @retval kStatus_Success Successfully create the handle.
|
||||
*/
|
||||
status_t FLEXIO_MCULCD_TransferCreateHandleEDMA(FLEXIO_MCULCD_Type *base,
|
||||
flexio_mculcd_edma_handle_t *handle,
|
||||
flexio_mculcd_edma_transfer_callback_t callback,
|
||||
void *userData,
|
||||
edma_handle_t *txDmaHandle,
|
||||
edma_handle_t *rxDmaHandle);
|
||||
|
||||
/*!
|
||||
* @brief Performs a non-blocking FlexIO MCULCD transfer using eDMA.
|
||||
*
|
||||
* This function returns immediately after transfer initiates. To check whether
|
||||
* the transfer is completed, user could:
|
||||
* 1. Use the transfer completed callback;
|
||||
* 2. Polling function FLEXIO_MCULCD_GetTransferCountEDMA
|
||||
*
|
||||
* @param base pointer to FLEXIO_MCULCD_Type structure.
|
||||
* @param handle pointer to flexio_mculcd_edma_handle_t structure to store the
|
||||
* transfer state.
|
||||
* @param xfer Pointer to FlexIO MCULCD transfer structure.
|
||||
* @retval kStatus_Success Successfully start a transfer.
|
||||
* @retval kStatus_InvalidArgument Input argument is invalid.
|
||||
* @retval kStatus_FLEXIO_MCULCD_Busy FlexIO MCULCD is not idle, it is running another
|
||||
* transfer.
|
||||
*/
|
||||
status_t FLEXIO_MCULCD_TransferEDMA(FLEXIO_MCULCD_Type *base,
|
||||
flexio_mculcd_edma_handle_t *handle,
|
||||
flexio_mculcd_transfer_t *xfer);
|
||||
|
||||
/*!
|
||||
* @brief Aborts a FlexIO MCULCD transfer using eDMA.
|
||||
*
|
||||
* @param base pointer to FLEXIO_MCULCD_Type structure.
|
||||
* @param handle FlexIO MCULCD eDMA handle pointer.
|
||||
*/
|
||||
void FLEXIO_MCULCD_TransferAbortEDMA(FLEXIO_MCULCD_Type *base, flexio_mculcd_edma_handle_t *handle);
|
||||
|
||||
/*!
|
||||
* @brief Gets the remaining bytes for FlexIO MCULCD eDMA transfer.
|
||||
*
|
||||
* @param base pointer to FLEXIO_MCULCD_Type structure.
|
||||
* @param handle FlexIO MCULCD eDMA handle pointer.
|
||||
* @param count Number of count transferred so far by the eDMA transaction.
|
||||
* @retval kStatus_Success Get the transferred count Successfully.
|
||||
* @retval kStatus_NoTransferInProgress No transfer in process.
|
||||
*/
|
||||
status_t FLEXIO_MCULCD_TransferGetCountEDMA(FLEXIO_MCULCD_Type *base,
|
||||
flexio_mculcd_edma_handle_t *handle,
|
||||
size_t *count);
|
||||
|
||||
/*! @} */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
#endif /* FSL_FLEXIO_MCULCD_EDMA_H_ */
|
||||
@@ -0,0 +1,407 @@
|
||||
/*
|
||||
* Copyright 2019-2021,2023 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "fsl_flexio_mculcd_smartdma.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/* Component ID definition, used by tools. */
|
||||
#ifndef FSL_COMPONENT_ID
|
||||
#define FSL_COMPONENT_ID "platform.drivers.flexio_mculcd_smartdma"
|
||||
#endif
|
||||
|
||||
#define FLEXIO_MCULCD_SMARTDMA_TX_START_SHIFTER 0U
|
||||
#define FLEXIO_MCULCD_SMARTDMA_TX_END_SHIFTER 7U
|
||||
#define FLEXIO_MCULCD_SMARTDMA_TX_SHIFTER_NUM \
|
||||
(FLEXIO_MCULCD_SMARTDMA_TX_END_SHIFTER - FLEXIO_MCULCD_SMARTDMA_TX_START_SHIFTER + 1)
|
||||
|
||||
enum _MCULCD_transfer_state
|
||||
{
|
||||
kFLEXIO_MCULCD_StateIdle, /*!< No transfer in progress. */
|
||||
kFLEXIO_MCULCD_StateReadArray, /*!< Reading array in progress. */
|
||||
kFLEXIO_MCULCD_StateWriteArray, /*!< Writing array in progress. */
|
||||
kFLEXIO_MCULCD_StateWriteSameValue, /*!< Writing the same value in progress.
|
||||
*/
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Get the TX chunk size.
|
||||
*
|
||||
* The SMARTDMA TX transfer memory must be 4Byte aligned, the transfer size must
|
||||
* be multiple of 64Byte. So the transfer data is devided in to three part:
|
||||
* part1 + part2 + part3.
|
||||
* The part2 is transfered using SMARTDMA, it should be 4Byte aligned, multiple
|
||||
* of 64Byte.
|
||||
* The part1 and part3 are transfered using blocking method, each of them is
|
||||
* less than 64Byte, and total of them is less than (64 + 4) bytes.
|
||||
*
|
||||
* This function gets the size of each part.
|
||||
*
|
||||
* @param totalLen The total TX size in byte.
|
||||
* @param startAddr The start address of the TX data.
|
||||
* @param part1Len Length of the part 1 in byte.
|
||||
* @param part2Len Length of the part 2 in byte.
|
||||
* @param part3Len Length of the part 3 in byte.
|
||||
*/
|
||||
static void FLEXIO_MCULCD_SMARTDMA_GetTxChunkLen(
|
||||
uint32_t totalLen, uint32_t startAddr, uint32_t *part1Len, uint32_t *part2Len, uint32_t *part3Len);
|
||||
|
||||
/*!
|
||||
* @brief Convert RGB565 to RGB888.
|
||||
*
|
||||
* @param rgb565 Input RGB565.
|
||||
* @param pixelCount Pixel count.
|
||||
* @param rgb888 Output RGB888.
|
||||
*/
|
||||
static void FLEXIO_MCULCD_RGB656ToRGB888(const uint16_t *rgb565, uint32_t pixelCount, uint8_t *rgb888);
|
||||
|
||||
/*!
|
||||
* @brief Callback function registered to SMARTDMA driver.
|
||||
*/
|
||||
static void FLEXIO_MCULCD_SMARTDMA_Callback(void *param);
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
static void FLEXIO_MCULCD_SMARTDMA_GetTxChunkLen(
|
||||
uint32_t totalLen, uint32_t startAddr, uint32_t *part1Len, uint32_t *part2Len, uint32_t *part3Len)
|
||||
{
|
||||
if (totalLen < FLEXIO_MCULCD_SMARTDMA_TX_LEN_ALIGN)
|
||||
{
|
||||
*part1Len = totalLen;
|
||||
*part2Len = 0;
|
||||
*part3Len = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*part3Len = (startAddr + totalLen) & (FLEXIO_MCULCD_SMARTDMA_TX_ADDR_ALIGN - 1U);
|
||||
*part2Len = ((uint32_t)(totalLen - *part3Len)) & (~(FLEXIO_MCULCD_SMARTDMA_TX_LEN_ALIGN - 1U));
|
||||
|
||||
if (FLEXIO_MCULCD_SMARTDMA_TX_LEN_ALIGN > *part2Len)
|
||||
{
|
||||
*part1Len = totalLen;
|
||||
*part2Len = 0;
|
||||
*part3Len = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*part1Len = totalLen - *part2Len - *part3Len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void FLEXIO_MCULCD_RGB656ToRGB888(const uint16_t *rgb565, uint32_t pixelCount, uint8_t *rgb888)
|
||||
{
|
||||
while ((pixelCount--) != 0U)
|
||||
{
|
||||
*rgb888 = (uint8_t)(((*rgb565) & 0x001FU) << 3U);
|
||||
rgb888++;
|
||||
*rgb888 = (uint8_t)(((*rgb565) & 0x07E0U) >> 3U);
|
||||
rgb888++;
|
||||
*rgb888 = (uint8_t)(((*rgb565) & 0xF800U) >> 8U);
|
||||
rgb888++;
|
||||
|
||||
rgb565++;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Initializes the FLEXO MCULCD master SMARTDMA handle.
|
||||
*
|
||||
* This function initializes the FLEXO MCULCD master SMARTDMA handle which can be
|
||||
* used for other FLEXO MCULCD transactional APIs. For a specified FLEXO MCULCD
|
||||
* instance, call this API once to get the initialized handle.
|
||||
*
|
||||
* param base Pointer to FLEXIO_MCULCD_Type structure.
|
||||
* param handle Pointer to flexio_mculcd_smartdma_handle_t structure to store the
|
||||
* transfer state.
|
||||
* param config Pointer to the configuration.
|
||||
* param callback MCULCD transfer complete callback, NULL means no callback.
|
||||
* param userData callback function parameter.
|
||||
* retval kStatus_Success Successfully create the handle.
|
||||
*/
|
||||
status_t FLEXIO_MCULCD_TransferCreateHandleSMARTDMA(FLEXIO_MCULCD_Type *base,
|
||||
flexio_mculcd_smartdma_handle_t *handle,
|
||||
const flexio_mculcd_smartdma_config_t *config,
|
||||
flexio_mculcd_smartdma_transfer_callback_t callback,
|
||||
void *userData)
|
||||
{
|
||||
assert(handle != NULL);
|
||||
|
||||
/* The SMARTDMA firmware only support TX using shifter 0 to shifter 7 */
|
||||
if (base->txShifterStartIndex != FLEXIO_MCULCD_SMARTDMA_TX_START_SHIFTER)
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
if (base->txShifterEndIndex != FLEXIO_MCULCD_SMARTDMA_TX_END_SHIFTER)
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
/* Zero the handle. */
|
||||
(void)memset(handle, 0, sizeof(*handle));
|
||||
|
||||
if (NULL == config)
|
||||
{
|
||||
handle->smartdmaApi = (uint8_t)kSMARTDMA_FlexIO_DMA;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (config->inputPixelFormat == config->outputPixelFormat)
|
||||
{
|
||||
handle->smartdmaApi = (uint8_t)kSMARTDMA_FlexIO_DMA;
|
||||
}
|
||||
else if (((config->inputPixelFormat == kFLEXIO_MCULCD_RGB565) &&
|
||||
(config->outputPixelFormat == kFLEXIO_MCULCD_RGB888)) ||
|
||||
((config->inputPixelFormat == kFLEXIO_MCULCD_BGR565) &&
|
||||
(config->outputPixelFormat == kFLEXIO_MCULCD_BGR888)))
|
||||
{
|
||||
handle->smartdmaApi = (uint8_t)kSMARTDMA_FlexIO_DMA_RGB565To888;
|
||||
handle->needColorConvert = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize the state. */
|
||||
handle->state = (uint32_t)kFLEXIO_MCULCD_StateIdle;
|
||||
|
||||
/* Register callback and userData. */
|
||||
handle->completionCallback = callback;
|
||||
handle->userData = userData;
|
||||
handle->base = base;
|
||||
|
||||
SMARTDMA_InstallFirmware(SMARTDMA_DISPLAY_MEM_ADDR, s_smartdmaDisplayFirmware, SMARTDMA_DISPLAY_FIRMWARE_SIZE);
|
||||
|
||||
SMARTDMA_InstallCallback(FLEXIO_MCULCD_SMARTDMA_Callback, handle);
|
||||
|
||||
/* The shifter interrupt is used by the SMARTDMA. */
|
||||
FLEXIO_EnableShifterStatusInterrupts(base->flexioBase, (1UL << FLEXIO_MCULCD_SMARTDMA_TX_END_SHIFTER));
|
||||
|
||||
#if (defined(SMARTDMA_USE_FLEXIO_SHIFTER_DMA) && SMARTDMA_USE_FLEXIO_SHIFTER_DMA)
|
||||
FLEXIO_EnableShifterStatusDMA(base->flexioBase, 1UL, true);
|
||||
#endif
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Performs a non-blocking FlexIO MCULCD transfer using SMARTDMA.
|
||||
*
|
||||
* This function returns immediately after transfer initiates. Use the callback
|
||||
* function to check whether the transfer is completed.
|
||||
*
|
||||
* param base pointer to FLEXIO_MCULCD_Type structure.
|
||||
* param handle pointer to flexio_mculcd_smartdma_handle_t structure to store the
|
||||
* transfer state.
|
||||
* param xfer Pointer to FlexIO MCULCD transfer structure.
|
||||
* retval kStatus_Success Successfully start a transfer.
|
||||
* retval kStatus_InvalidArgument Input argument is invalid.
|
||||
* retval kStatus_FLEXIO_MCULCD_Busy FlexIO MCULCD is not idle, it is running another
|
||||
* transfer.
|
||||
*/
|
||||
status_t FLEXIO_MCULCD_TransferSMARTDMA(FLEXIO_MCULCD_Type *base,
|
||||
flexio_mculcd_smartdma_handle_t *handle,
|
||||
flexio_mculcd_transfer_t *xfer)
|
||||
{
|
||||
assert(handle != NULL);
|
||||
assert(xfer != NULL);
|
||||
|
||||
uint32_t part1Len, part2Len, part3Len;
|
||||
|
||||
/* Check if the device is busy. */
|
||||
if ((uint32_t)kFLEXIO_MCULCD_StateIdle != handle->state)
|
||||
{
|
||||
return kStatus_FLEXIO_MCULCD_Busy;
|
||||
}
|
||||
|
||||
/* Only support write array. */
|
||||
if (kFLEXIO_MCULCD_WriteArray != xfer->mode)
|
||||
{
|
||||
return kStatus_InvalidArgument;
|
||||
}
|
||||
|
||||
FLEXIO_MCULCD_SMARTDMA_GetTxChunkLen(xfer->dataSize, xfer->dataAddrOrSameValue, &part1Len, &part2Len, &part3Len);
|
||||
|
||||
handle->state = (uint32_t)kFLEXIO_MCULCD_StateWriteArray;
|
||||
|
||||
/* Start transfer. */
|
||||
handle->remainingCount = xfer->dataSize;
|
||||
handle->dataCount = xfer->dataSize;
|
||||
handle->dataAddrOrSameValue = xfer->dataAddrOrSameValue;
|
||||
|
||||
/* Assert the nCS. */
|
||||
FLEXIO_MCULCD_StartTransfer(base);
|
||||
|
||||
if (!xfer->dataOnly)
|
||||
{
|
||||
/* Send the command. */
|
||||
FLEXIO_MCULCD_WriteCommandBlocking(base, xfer->command);
|
||||
}
|
||||
|
||||
if (part1Len > 0U)
|
||||
{
|
||||
if (handle->needColorConvert)
|
||||
{
|
||||
FLEXIO_MCULCD_RGB656ToRGB888((uint16_t *)xfer->dataAddrOrSameValue, part1Len >> 1U,
|
||||
handle->blockingXferBuffer);
|
||||
FLEXIO_MCULCD_WriteDataArrayBlocking(base, handle->blockingXferBuffer, (part1Len >> 1U) * 3U);
|
||||
}
|
||||
else
|
||||
{
|
||||
FLEXIO_MCULCD_WriteDataArrayBlocking(base, (void *)(uint8_t *)xfer->dataAddrOrSameValue, (size_t)part1Len);
|
||||
}
|
||||
handle->remainingCount -= part1Len;
|
||||
handle->dataAddrOrSameValue += part1Len;
|
||||
}
|
||||
|
||||
if (0U == part2Len)
|
||||
{
|
||||
/* In this case, all data are sent out as part 1. Only notify upper layer here. */
|
||||
FLEXIO_MCULCD_StopTransfer(base);
|
||||
handle->state = (uint32_t)kFLEXIO_MCULCD_StateIdle;
|
||||
|
||||
/* Callback to inform upper layer. */
|
||||
if (NULL != handle->completionCallback)
|
||||
{
|
||||
handle->completionCallback(base, handle, kStatus_FLEXIO_MCULCD_Idle, handle->userData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* For 6800, de-assert the RDWR pin. */
|
||||
if (kFLEXIO_MCULCD_6800 == base->busType)
|
||||
{
|
||||
base->setRDWRPin(false);
|
||||
}
|
||||
|
||||
FLEXIO_MCULCD_SetMultiBeatsWriteConfig(base);
|
||||
|
||||
/* Save the part 3 information. */
|
||||
handle->dataCountUsingEzh = part2Len;
|
||||
handle->dataAddrOrSameValue += part2Len;
|
||||
|
||||
/* The part 3 is transfered using blocking method in ISR, convert the color
|
||||
to save time in ISR. */
|
||||
if ((0U != part3Len) && (handle->needColorConvert))
|
||||
{
|
||||
FLEXIO_MCULCD_RGB656ToRGB888((uint16_t *)xfer->dataAddrOrSameValue, part3Len >> 1U,
|
||||
handle->blockingXferBuffer);
|
||||
}
|
||||
|
||||
handle->smartdmaParam.p_buffer = (uint32_t *)(xfer->dataAddrOrSameValue + part1Len);
|
||||
handle->smartdmaParam.buffersize = part2Len;
|
||||
handle->smartdmaParam.smartdma_stack = handle->smartdmaStack;
|
||||
|
||||
SMARTDMA_Reset();
|
||||
SMARTDMA_Boot(handle->smartdmaApi, &(handle->smartdmaParam), 0);
|
||||
}
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Aborts a FlexIO MCULCD transfer using SMARTDMA.
|
||||
*
|
||||
* param base pointer to FLEXIO_MCULCD_Type structure.
|
||||
* param handle FlexIO MCULCD SMARTDMA handle pointer.
|
||||
*/
|
||||
void FLEXIO_MCULCD_TransferAbortSMARTDMA(FLEXIO_MCULCD_Type *base, flexio_mculcd_smartdma_handle_t *handle)
|
||||
{
|
||||
assert(handle != NULL);
|
||||
|
||||
SMARTDMA_Reset();
|
||||
|
||||
/* Set the handle state. */
|
||||
handle->state = (uint32_t)kFLEXIO_MCULCD_StateIdle;
|
||||
handle->dataCount = 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* brief Gets the remaining bytes for FlexIO MCULCD SMARTDMA transfer.
|
||||
*
|
||||
* param base pointer to FLEXIO_MCULCD_Type structure.
|
||||
* param handle FlexIO MCULCD SMARTDMA handle pointer.
|
||||
* param count Number of count transferred so far by the SMARTDMA transaction.
|
||||
* retval kStatus_Success Get the transferred count Successfully.
|
||||
* retval kStatus_NoTransferInProgress No transfer in process.
|
||||
*/
|
||||
status_t FLEXIO_MCULCD_TransferGetCountSMARTDMA(FLEXIO_MCULCD_Type *base,
|
||||
flexio_mculcd_smartdma_handle_t *handle,
|
||||
size_t *count)
|
||||
{
|
||||
assert(handle != NULL);
|
||||
assert(count != NULL);
|
||||
|
||||
uint32_t state = handle->state;
|
||||
|
||||
if ((uint32_t)kFLEXIO_MCULCD_StateIdle == state)
|
||||
{
|
||||
return kStatus_NoTransferInProgress;
|
||||
}
|
||||
else
|
||||
{
|
||||
*count = handle->dataCount - handle->remainingCount;
|
||||
}
|
||||
|
||||
return kStatus_Success;
|
||||
}
|
||||
|
||||
static void FLEXIO_MCULCD_SMARTDMA_Callback(void *param)
|
||||
{
|
||||
flexio_mculcd_smartdma_handle_t *flexioMculcdSmartDmaHandle = (flexio_mculcd_smartdma_handle_t *)param;
|
||||
|
||||
FLEXIO_MCULCD_Type *flexioLcdMcuBase = flexioMculcdSmartDmaHandle->base;
|
||||
|
||||
FLEXIO_MCULCD_WaitTransmitComplete();
|
||||
|
||||
/* Disable the TX shifter and the timer. */
|
||||
FLEXIO_MCULCD_ClearMultiBeatsWriteConfig(flexioLcdMcuBase);
|
||||
|
||||
flexioMculcdSmartDmaHandle->remainingCount -= flexioMculcdSmartDmaHandle->dataCountUsingEzh;
|
||||
|
||||
/* Send the part 3 */
|
||||
if (0U != flexioMculcdSmartDmaHandle->remainingCount)
|
||||
{
|
||||
if (flexioMculcdSmartDmaHandle->needColorConvert)
|
||||
{
|
||||
FLEXIO_MCULCD_WriteDataArrayBlocking(flexioLcdMcuBase, flexioMculcdSmartDmaHandle->blockingXferBuffer,
|
||||
(flexioMculcdSmartDmaHandle->remainingCount >> 1U) * 3U);
|
||||
}
|
||||
else
|
||||
{
|
||||
FLEXIO_MCULCD_WriteDataArrayBlocking(flexioLcdMcuBase,
|
||||
(void *)(uint8_t *)flexioMculcdSmartDmaHandle->dataAddrOrSameValue,
|
||||
flexioMculcdSmartDmaHandle->remainingCount);
|
||||
}
|
||||
}
|
||||
|
||||
flexioMculcdSmartDmaHandle->remainingCount = 0;
|
||||
FLEXIO_MCULCD_StopTransfer(flexioLcdMcuBase);
|
||||
flexioMculcdSmartDmaHandle->state = (uint32_t)kFLEXIO_MCULCD_StateIdle;
|
||||
|
||||
/* Callback to inform upper layer. */
|
||||
if (NULL != flexioMculcdSmartDmaHandle->completionCallback)
|
||||
{
|
||||
flexioMculcdSmartDmaHandle->completionCallback(flexioLcdMcuBase, flexioMculcdSmartDmaHandle,
|
||||
kStatus_FLEXIO_MCULCD_Idle,
|
||||
flexioMculcdSmartDmaHandle->userData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright 2019,2021,2023 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef FSL_FLEXIO_MCULCD_SMARTDMA_H_
|
||||
#define FSL_FLEXIO_MCULCD_SMARTDMA_H_
|
||||
|
||||
#include "fsl_smartdma.h"
|
||||
#include "fsl_flexio_mculcd.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup flexio_smartdma_mculcd
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*@{*/
|
||||
/*! @brief FlexIO MCULCD SMARTDMA driver version. */
|
||||
#define FSL_FLEXIO_MCULCD_SMARTDMA_DRIVER_VERSION (MAKE_VERSION(2, 0, 4))
|
||||
/*@}*/
|
||||
|
||||
/*! @brief SMARTDMA transfer size should be multiple of 64 bytes. */
|
||||
#define FLEXIO_MCULCD_SMARTDMA_TX_LEN_ALIGN 64U
|
||||
|
||||
/*! @brief SMARTDMA transfer memory address should be 4 byte aligned. */
|
||||
#define FLEXIO_MCULCD_SMARTDMA_TX_ADDR_ALIGN 4U
|
||||
|
||||
/*! @brief typedef for flexio_mculcd_smartdma_handle_t in advance. */
|
||||
typedef struct _flexio_mculcd_smartdma_handle flexio_mculcd_smartdma_handle_t;
|
||||
|
||||
/*! @brief FlexIO MCULCD master callback for transfer complete.
|
||||
*
|
||||
* When transfer finished, the callback function is called and returns the
|
||||
* @p status as kStatus_FLEXIO_MCULCD_Idle.
|
||||
*/
|
||||
typedef void (*flexio_mculcd_smartdma_transfer_callback_t)(FLEXIO_MCULCD_Type *base,
|
||||
flexio_mculcd_smartdma_handle_t *handle,
|
||||
status_t status,
|
||||
void *userData);
|
||||
|
||||
/*! @brief FlexIO MCULCD SMARTDMA transfer handle, users should not touch the
|
||||
* content of the handle.*/
|
||||
struct _flexio_mculcd_smartdma_handle
|
||||
{
|
||||
FLEXIO_MCULCD_Type *base; /*!< Pointer to the FLEXIO_MCULCD_Type. */
|
||||
size_t dataCount; /*!< Total count to be transferred. */
|
||||
uint32_t dataAddrOrSameValue; /*!< When sending the same value for many times,
|
||||
this is the value to send. When writing or reading array,
|
||||
this is the address of the data array. */
|
||||
size_t dataCountUsingEzh; /*!< Data transfered using SMARTDMA. */
|
||||
volatile size_t remainingCount; /*!< Remaining count to transfer. */
|
||||
volatile uint32_t state; /*!< FlexIO MCULCD driver internal state. */
|
||||
uint8_t smartdmaApi; /*!< The SMARTDMA API used during transfer. */
|
||||
bool needColorConvert; /*!< Need color convert or not. */
|
||||
uint8_t blockingXferBuffer[FLEXIO_MCULCD_SMARTDMA_TX_LEN_ALIGN * 3 /
|
||||
2]; /*!< Used for blocking method color space convet. */
|
||||
flexio_mculcd_smartdma_transfer_callback_t completionCallback; /*!< Callback for MCULCD SMARTDMA transfer */
|
||||
void *userData; /*!< User Data for MCULCD SMARTDMA callback */
|
||||
smartdma_flexio_mculcd_param_t smartdmaParam; /*!< SMARTDMA function parameters. */
|
||||
uint32_t smartdmaStack[1]; /*!< SMARTDMA function stack. */
|
||||
};
|
||||
|
||||
/*! @brief FlexIO MCULCD SMARTDMA configuration. */
|
||||
typedef struct _flexio_mculcd_smartdma_config
|
||||
{
|
||||
flexio_mculcd_pixel_format_t inputPixelFormat; /*!< The pixel format in the frame buffer. */
|
||||
flexio_mculcd_pixel_format_t outputPixelFormat; /*!< The pixel format on the 8080/68k bus. */
|
||||
} flexio_mculcd_smartdma_config_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* APIs
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @name SMARTDMA Transactional
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes the FLEXO MCULCD master SMARTDMA handle.
|
||||
*
|
||||
* This function initializes the FLEXO MCULCD master SMARTDMA handle which can be
|
||||
* used for other FLEXO MCULCD transactional APIs. For a specified FLEXO MCULCD
|
||||
* instance, call this API once to get the initialized handle.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_MCULCD_Type structure.
|
||||
* @param handle Pointer to flexio_mculcd_smartdma_handle_t structure to store the
|
||||
* transfer state.
|
||||
* @param config Pointer to the configuration.
|
||||
* @param callback MCULCD transfer complete callback, NULL means no callback.
|
||||
* @param userData callback function parameter.
|
||||
* @retval kStatus_Success Successfully create the handle.
|
||||
*/
|
||||
status_t FLEXIO_MCULCD_TransferCreateHandleSMARTDMA(FLEXIO_MCULCD_Type *base,
|
||||
flexio_mculcd_smartdma_handle_t *handle,
|
||||
const flexio_mculcd_smartdma_config_t *config,
|
||||
flexio_mculcd_smartdma_transfer_callback_t callback,
|
||||
void *userData);
|
||||
|
||||
/*!
|
||||
* @brief Performs a non-blocking FlexIO MCULCD transfer using SMARTDMA.
|
||||
*
|
||||
* This function returns immediately after transfer initiates. Use the callback
|
||||
* function to check whether the transfer is completed.
|
||||
*
|
||||
* @param base pointer to FLEXIO_MCULCD_Type structure.
|
||||
* @param handle pointer to flexio_mculcd_smartdma_handle_t structure to store the
|
||||
* transfer state.
|
||||
* @param xfer Pointer to FlexIO MCULCD transfer structure.
|
||||
* @retval kStatus_Success Successfully start a transfer.
|
||||
* @retval kStatus_InvalidArgument Input argument is invalid.
|
||||
* @retval kStatus_FLEXIO_MCULCD_Busy FlexIO MCULCD is not idle, it is running another
|
||||
* transfer.
|
||||
*/
|
||||
status_t FLEXIO_MCULCD_TransferSMARTDMA(FLEXIO_MCULCD_Type *base,
|
||||
flexio_mculcd_smartdma_handle_t *handle,
|
||||
flexio_mculcd_transfer_t *xfer);
|
||||
|
||||
/*!
|
||||
* @brief Aborts a FlexIO MCULCD transfer using SMARTDMA.
|
||||
*
|
||||
* @param base pointer to FLEXIO_MCULCD_Type structure.
|
||||
* @param handle FlexIO MCULCD SMARTDMA handle pointer.
|
||||
*/
|
||||
void FLEXIO_MCULCD_TransferAbortSMARTDMA(FLEXIO_MCULCD_Type *base, flexio_mculcd_smartdma_handle_t *handle);
|
||||
|
||||
/*!
|
||||
* @brief Gets the remaining bytes for FlexIO MCULCD SMARTDMA transfer.
|
||||
*
|
||||
* @param base pointer to FLEXIO_MCULCD_Type structure.
|
||||
* @param handle FlexIO MCULCD SMARTDMA handle pointer.
|
||||
* @param count Number of count transferred so far by the SMARTDMA transaction.
|
||||
* @retval kStatus_Success Get the transferred count Successfully.
|
||||
* @retval kStatus_NoTransferInProgress No transfer in process.
|
||||
*/
|
||||
status_t FLEXIO_MCULCD_TransferGetCountSMARTDMA(FLEXIO_MCULCD_Type *base,
|
||||
flexio_mculcd_smartdma_handle_t *handle,
|
||||
size_t *count);
|
||||
|
||||
/*! @} */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
#endif /* FSL_FLEXIO_MCULCD_SMARTDMA_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2020, 2022 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#ifndef FSL_FLEXIO_SPI_EDMA_H_
|
||||
#define FSL_FLEXIO_SPI_EDMA_H_
|
||||
|
||||
#include "fsl_flexio_spi.h"
|
||||
#include "fsl_edma.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup flexio_edma_spi
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @name Driver version */
|
||||
/*@{*/
|
||||
/*! @brief FlexIO SPI EDMA driver version. */
|
||||
#define FSL_FLEXIO_SPI_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 3, 0))
|
||||
/*@}*/
|
||||
|
||||
/*! @brief typedef for flexio_spi_master_edma_handle_t in advance. */
|
||||
typedef struct _flexio_spi_master_edma_handle flexio_spi_master_edma_handle_t;
|
||||
|
||||
/*! @brief Slave handle is the same with master handle. */
|
||||
typedef flexio_spi_master_edma_handle_t flexio_spi_slave_edma_handle_t;
|
||||
|
||||
/*! @brief FlexIO SPI master callback for finished transmit */
|
||||
typedef void (*flexio_spi_master_edma_transfer_callback_t)(FLEXIO_SPI_Type *base,
|
||||
flexio_spi_master_edma_handle_t *handle,
|
||||
status_t status,
|
||||
void *userData);
|
||||
|
||||
/*! @brief FlexIO SPI slave callback for finished transmit */
|
||||
typedef void (*flexio_spi_slave_edma_transfer_callback_t)(FLEXIO_SPI_Type *base,
|
||||
flexio_spi_slave_edma_handle_t *handle,
|
||||
status_t status,
|
||||
void *userData);
|
||||
|
||||
/*! @brief FlexIO SPI eDMA transfer handle, users should not touch the content of the handle.*/
|
||||
struct _flexio_spi_master_edma_handle
|
||||
{
|
||||
size_t transferSize; /*!< Total bytes to be transferred. */
|
||||
uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
|
||||
bool txInProgress; /*!< Send transfer in progress */
|
||||
bool rxInProgress; /*!< Receive transfer in progress */
|
||||
edma_handle_t *txHandle; /*!< DMA handler for SPI send */
|
||||
edma_handle_t *rxHandle; /*!< DMA handler for SPI receive */
|
||||
flexio_spi_master_edma_transfer_callback_t callback; /*!< Callback for SPI DMA transfer */
|
||||
void *userData; /*!< User Data for SPI DMA callback */
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* APIs
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @name eDMA Transactional
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Initializes the FlexIO SPI master eDMA handle.
|
||||
*
|
||||
* This function initializes the FlexIO SPI master eDMA handle which can be used for other FlexIO SPI master
|
||||
* transactional
|
||||
* APIs.
|
||||
* For a specified FlexIO SPI instance, call this API once to get the initialized handle.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_SPI_Type structure.
|
||||
* @param handle Pointer to flexio_spi_master_edma_handle_t structure to store the transfer state.
|
||||
* @param callback SPI callback, NULL means no callback.
|
||||
* @param userData callback function parameter.
|
||||
* @param txHandle User requested eDMA handle for FlexIO SPI RX eDMA transfer.
|
||||
* @param rxHandle User requested eDMA handle for FlexIO SPI TX eDMA transfer.
|
||||
* @retval kStatus_Success Successfully create the handle.
|
||||
* @retval kStatus_OutOfRange The FlexIO SPI eDMA type/handle table out of range.
|
||||
*/
|
||||
status_t FLEXIO_SPI_MasterTransferCreateHandleEDMA(FLEXIO_SPI_Type *base,
|
||||
flexio_spi_master_edma_handle_t *handle,
|
||||
flexio_spi_master_edma_transfer_callback_t callback,
|
||||
void *userData,
|
||||
edma_handle_t *txHandle,
|
||||
edma_handle_t *rxHandle);
|
||||
|
||||
/*!
|
||||
* @brief Performs a non-blocking FlexIO SPI transfer using eDMA.
|
||||
*
|
||||
* @note This interface returns immediately after transfer initiates. Call
|
||||
* FLEXIO_SPI_MasterGetTransferCountEDMA to poll the transfer status and check
|
||||
* whether the FlexIO SPI transfer is finished.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_SPI_Type structure.
|
||||
* @param handle Pointer to flexio_spi_master_edma_handle_t structure to store the transfer state.
|
||||
* @param xfer Pointer to FlexIO SPI transfer structure.
|
||||
* @retval kStatus_Success Successfully start a transfer.
|
||||
* @retval kStatus_InvalidArgument Input argument is invalid.
|
||||
* @retval kStatus_FLEXIO_SPI_Busy FlexIO SPI is not idle, is running another transfer.
|
||||
*/
|
||||
status_t FLEXIO_SPI_MasterTransferEDMA(FLEXIO_SPI_Type *base,
|
||||
flexio_spi_master_edma_handle_t *handle,
|
||||
flexio_spi_transfer_t *xfer);
|
||||
|
||||
/*!
|
||||
* @brief Aborts a FlexIO SPI transfer using eDMA.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_SPI_Type structure.
|
||||
* @param handle FlexIO SPI eDMA handle pointer.
|
||||
*/
|
||||
void FLEXIO_SPI_MasterTransferAbortEDMA(FLEXIO_SPI_Type *base, flexio_spi_master_edma_handle_t *handle);
|
||||
|
||||
/*!
|
||||
* @brief Gets the number of bytes transferred so far using FlexIO SPI master eDMA.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_SPI_Type structure.
|
||||
* @param handle FlexIO SPI eDMA handle pointer.
|
||||
* @param count Number of bytes transferred so far by the non-blocking transaction.
|
||||
*/
|
||||
status_t FLEXIO_SPI_MasterTransferGetCountEDMA(FLEXIO_SPI_Type *base,
|
||||
flexio_spi_master_edma_handle_t *handle,
|
||||
size_t *count);
|
||||
|
||||
/*!
|
||||
* @brief Initializes the FlexIO SPI slave eDMA handle.
|
||||
*
|
||||
* This function initializes the FlexIO SPI slave eDMA handle.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_SPI_Type structure.
|
||||
* @param handle Pointer to flexio_spi_slave_edma_handle_t structure to store the transfer state.
|
||||
* @param callback SPI callback, NULL means no callback.
|
||||
* @param userData callback function parameter.
|
||||
* @param txHandle User requested eDMA handle for FlexIO SPI TX eDMA transfer.
|
||||
* @param rxHandle User requested eDMA handle for FlexIO SPI RX eDMA transfer.
|
||||
*/
|
||||
static inline void FLEXIO_SPI_SlaveTransferCreateHandleEDMA(FLEXIO_SPI_Type *base,
|
||||
flexio_spi_slave_edma_handle_t *handle,
|
||||
flexio_spi_slave_edma_transfer_callback_t callback,
|
||||
void *userData,
|
||||
edma_handle_t *txHandle,
|
||||
edma_handle_t *rxHandle)
|
||||
{
|
||||
(void)FLEXIO_SPI_MasterTransferCreateHandleEDMA(base, handle, callback, userData, txHandle, rxHandle);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Performs a non-blocking FlexIO SPI transfer using eDMA.
|
||||
*
|
||||
* @note This interface returns immediately after transfer initiates. Call
|
||||
* FLEXIO_SPI_SlaveGetTransferCountEDMA to poll the transfer status and
|
||||
* check whether the FlexIO SPI transfer is finished.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_SPI_Type structure.
|
||||
* @param handle Pointer to flexio_spi_slave_edma_handle_t structure to store the transfer state.
|
||||
* @param xfer Pointer to FlexIO SPI transfer structure.
|
||||
* @retval kStatus_Success Successfully start a transfer.
|
||||
* @retval kStatus_InvalidArgument Input argument is invalid.
|
||||
* @retval kStatus_FLEXIO_SPI_Busy FlexIO SPI is not idle, is running another transfer.
|
||||
*/
|
||||
status_t FLEXIO_SPI_SlaveTransferEDMA(FLEXIO_SPI_Type *base,
|
||||
flexio_spi_slave_edma_handle_t *handle,
|
||||
flexio_spi_transfer_t *xfer);
|
||||
|
||||
/*!
|
||||
* @brief Aborts a FlexIO SPI transfer using eDMA.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_SPI_Type structure.
|
||||
* @param handle Pointer to flexio_spi_slave_edma_handle_t structure to store the transfer state.
|
||||
*/
|
||||
static inline void FLEXIO_SPI_SlaveTransferAbortEDMA(FLEXIO_SPI_Type *base, flexio_spi_slave_edma_handle_t *handle)
|
||||
{
|
||||
FLEXIO_SPI_MasterTransferAbortEDMA(base, handle);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets the number of bytes transferred so far using FlexIO SPI slave eDMA.
|
||||
*
|
||||
* @param base Pointer to FLEXIO_SPI_Type structure.
|
||||
* @param handle FlexIO SPI eDMA handle pointer.
|
||||
* @param count Number of bytes transferred so far by the non-blocking transaction.
|
||||
*/
|
||||
static inline status_t FLEXIO_SPI_SlaveTransferGetCountEDMA(FLEXIO_SPI_Type *base,
|
||||
flexio_spi_slave_edma_handle_t *handle,
|
||||
size_t *count)
|
||||
{
|
||||
return FLEXIO_SPI_MasterTransferGetCountEDMA(base, handle, count);
|
||||
}
|
||||
|
||||
/*! @} */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user