LPC546XX: Update the SPIFI SDK driver

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
pull/8683/head
Mahesh Mahadevan 2018-11-08 10:24:57 -06:00
parent 82f195c021
commit fffb37534e
3 changed files with 162 additions and 73 deletions

View File

@ -220,6 +220,10 @@ typedef enum _SYSCON_RSTn
{ \
kSHA_RST_SHIFT_RSTn \
} /* Reset bits for SHA peripheral */
#define SPIFI_RSTS \
{ \
kSPIFI_RST_SHIFT_RSTn \
} /* Reset bits for SPIFI peripheral */
#define USB0D_RST \
{ \
kUSB0D_RST_SHIFT_RSTn \

View File

@ -1,35 +1,9 @@
/*
* The Clear BSD License
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted (subject to the limitations in the disclaimer below) provided
* that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "fsl_spifi.h"
@ -38,18 +12,15 @@
* Definitions
******************************************************************************/
/* Component ID definition, used by tools. */
#ifndef FSL_COMPONENT_ID
#define FSL_COMPONENT_ID "platform.drivers.spifi"
#endif
/*******************************************************************************
* Prototypes
******************************************************************************/
/*!
* @brief Get the SPIFI instance from peripheral base address.
*
* @param base SPIFI peripheral base address.
* @return SPIFI instance.
*/
uint32_t SPIFI_GetInstance(SPIFI_Type *base);
/*******************************************************************************
* Variables
******************************************************************************/
@ -62,9 +33,19 @@ static SPIFI_Type *const s_spifiBases[] = SPIFI_BASE_PTRS;
static const clock_ip_name_t s_spifiClock[] = SPIFI_CLOCKS;
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
#if !(defined(FSL_FEATURE_SPIFI_HAS_NO_RESET) && FSL_FEATURE_SPIFI_HAS_NO_RESET)
static const reset_ip_name_t s_spifiResets[] = SPIFI_RSTS;
#endif
/*******************************************************************************
* Code
******************************************************************************/
/*!
* brief Get the SPIFI instance from peripheral base address.
*
* param base SPIFI peripheral base address.
* return SPIFI instance.
*/
uint32_t SPIFI_GetInstance(SPIFI_Type *base)
{
uint32_t instance;
@ -83,8 +64,16 @@ uint32_t SPIFI_GetInstance(SPIFI_Type *base)
return instance;
}
/*!
* brief Get SPIFI default configure settings.
*
* param config SPIFI config structure pointer.
*/
void SPIFI_GetDefaultConfig(spifi_config_t *config)
{
/* Initializes the configure structure to zero. */
memset(config, 0, sizeof(*config));
config->timeout = 0xFFFFU;
config->csHighTime = 0xFU;
config->disablePrefetch = false;
@ -95,6 +84,14 @@ void SPIFI_GetDefaultConfig(spifi_config_t *config)
config->dualMode = kSPIFI_QuadMode;
}
/*!
* brief Initializes the SPIFI with the user configuration structure.
*
* This function configures the SPIFI module with the user-defined configuration.
*
* param base SPIFI peripheral base address.
* param config The pointer to the configuration structure.
*/
void SPIFI_Init(SPIFI_Type *base, const spifi_config_t *config)
{
assert(config);
@ -104,6 +101,10 @@ void SPIFI_Init(SPIFI_Type *base, const spifi_config_t *config)
CLOCK_EnableClock(s_spifiClock[SPIFI_GetInstance(base)]);
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
#if !(defined(FSL_FEATURE_SPIFI_HAS_NO_RESET) && FSL_FEATURE_SPIFI_HAS_NO_RESET)
RESET_PeripheralReset(s_spifiResets[SPIFI_GetInstance(base)]);
#endif
/* Reset the Command register */
SPIFI_ResetCommand(base);
@ -114,6 +115,11 @@ void SPIFI_Init(SPIFI_Type *base, const spifi_config_t *config)
SPIFI_CTRL_RFCLK(config->isReadFullClockCycle) | SPIFI_CTRL_FBCLK(config->isFeedbackClock);
}
/*!
* brief Deinitializes the SPIFI regions.
*
* param base SPIFI peripheral base address.
*/
void SPIFI_Deinit(SPIFI_Type *base)
{
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
@ -122,29 +128,84 @@ void SPIFI_Deinit(SPIFI_Type *base)
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
}
/*!
* brief Set SPIFI flash command.
*
* param base SPIFI peripheral base address.
* param cmd SPIFI command structure pointer.
*/
void SPIFI_SetCommand(SPIFI_Type *base, spifi_command_t *cmd)
{
/* Wait for the CMD and MCINT flag all be 0 */
while (SPIFI_GetStatusFlag(base) & (SPIFI_STAT_MCINIT_MASK | SPIFI_STAT_CMD_MASK))
/* If SPIFI in memory mode, call reset function to abort memory mode */
if (SPIFI_GetStatusFlag(base) & SPIFI_STAT_MCINIT_MASK)
{
SPIFI_ResetCommand(base);
}
/* Wait for other command finished */
while (SPIFI_GetStatusFlag(base) & SPIFI_STAT_CMD_MASK)
{
}
base->CMD = SPIFI_CMD_DATALEN(cmd->dataLen) | SPIFI_CMD_POLL(cmd->isPollMode) | SPIFI_CMD_DOUT(cmd->direction) |
SPIFI_CMD_INTLEN(cmd->intermediateBytes) | SPIFI_CMD_FIELDFORM(cmd->format) |
SPIFI_CMD_FRAMEFORM(cmd->type) | SPIFI_CMD_OPCODE(cmd->opcode);
/* Wait for the command written */
while ((base->STAT & SPIFI_STAT_CMD_MASK) == 0U)
{
}
}
/*!
* brief Set SPIFI flash AHB read command.
*
* Call this function means SPIFI enters to memory mode, while users need to use command, a SPIFI_ResetCommand shall
* be called.
*
* param base SPIFI peripheral base address.
* param cmd SPIFI command structure pointer.
*/
void SPIFI_SetMemoryCommand(SPIFI_Type *base, spifi_command_t *cmd)
{
/* Wait for the CMD and MCINT flag all be 0 */
while (SPIFI_GetStatusFlag(base) & (SPIFI_STAT_MCINIT_MASK | SPIFI_STAT_CMD_MASK))
/* Wait for the CMD flag be 0 */
while (SPIFI_GetStatusFlag(base) & SPIFI_STAT_CMD_MASK)
{
}
base->MCMD = SPIFI_MCMD_POLL(0U) | SPIFI_MCMD_DOUT(0U) | SPIFI_MCMD_INTLEN(cmd->intermediateBytes) |
SPIFI_MCMD_FIELDFORM(cmd->format) | SPIFI_MCMD_FRAMEFORM(cmd->type) | SPIFI_MCMD_OPCODE(cmd->opcode);
/* Wait for the command written */
while ((base->STAT & SPIFI_STAT_MCINIT_MASK) == 0)
{
}
}
/*!
* brief Write a halfword data in address of SPIFI.
*
* Users can write a halfword data into SPIFI address.
*
* param base SPIFI peripheral base address.
* param data Data need be write.
*/
void SPIFI_WriteDataHalfword(SPIFI_Type *base, uint16_t data)
{
volatile uint8_t *dataReg = ((volatile uint8_t *)(&(base->DATA)));
*dataReg = (data & 0xFFU);
dataReg++;
*dataReg = ((data >> 8U) & 0xFFU);
}
/*!
* brief Read a halfword data from serial flash.
*
* param base SPIFI peripheral base address.
* return Data input from flash.
*/
uint16_t SPIFI_ReadDataHalfword(SPIFI_Type *base)
{
uint16_t val = 0;
volatile uint8_t *dataReg = ((volatile uint8_t *)(&(base->DATA)));
val = ((*dataReg) | (uint16_t)((uint16_t)(*(dataReg + 1U)) << 8U));
return val;
}

View File

@ -1,35 +1,9 @@
/*
* The Clear BSD License
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted (subject to the limitations in the disclaimer below) provided
* that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _FSL_SPIFI_H_
#define _FSL_SPIFI_H_
@ -47,8 +21,8 @@
/*! @name Driver version */
/*@{*/
/*! @brief SPIFI driver version 2.0.0. */
#define FSL_SPIFI_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
/*! @brief SPIFI driver version 2.0.2. */
#define FSL_SPIFI_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
/*@}*/
/*! @brief Status structure of SPIFI.*/
@ -162,6 +136,14 @@ extern "C" {
* @{
*/
/*!
* @brief Get the SPIFI instance from peripheral base address.
*
* @param base SPIFI peripheral base address.
* @return SPIFI instance.
*/
uint32_t SPIFI_GetInstance(SPIFI_Type *base);
/*!
* @brief Initializes the SPIFI with the user configuration structure.
*
@ -358,6 +340,29 @@ static inline void SPIFI_WriteData(SPIFI_Type *base, uint32_t data)
base->DATA = data;
}
/*!
* @brief Write a byte data in address of SPIFI.
*
* Users can write a byte data into SPIFI address.
*
* @param base SPIFI peripheral base address.
* @param data Data need be write.
*/
static inline void SPIFI_WriteDataByte(SPIFI_Type *base, uint8_t data)
{
*((volatile uint8_t *)(&(base->DATA))) = data;
}
/*!
* @brief Write a halfword data in address of SPIFI.
*
* Users can write a halfword data into SPIFI address.
*
* @param base SPIFI peripheral base address.
* @param data Data need be write.
*/
void SPIFI_WriteDataHalfword(SPIFI_Type *base, uint16_t data);
/*!
* @brief Read data from serial flash.
*
@ -372,6 +377,25 @@ static inline uint32_t SPIFI_ReadData(SPIFI_Type *base)
return base->DATA;
}
/*!
* @brief Read a byte data from serial flash.
*
* @param base SPIFI peripheral base address.
* @return Data input from flash.
*/
static inline uint8_t SPIFI_ReadDataByte(SPIFI_Type *base)
{
return *((volatile uint8_t *)(&(base->DATA)));
}
/*!
* @brief Read a halfword data from serial flash.
*
* @param base SPIFI peripheral base address.
* @return Data input from flash.
*/
uint16_t SPIFI_ReadDataHalfword(SPIFI_Type *base);
/* @} */
#if defined(__cplusplus)