/*
* Copyright 2017-2019 NXP
* All rights reserved.
*
* THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED 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 NXP OR ITS 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.
*/
/*!
* @file flash_c55_driver.c
*
* @page misra_violations MISRA-C:2012 violations
*
* @section [global]
* Violates MISRA 2012 Advisory Rule 8.7, External could be made static.
* The function is defined for use by application code.
*
* @section [global]
* Violates MISRA 2012 Required Rule 11.1, Conversion between a pointer
* to function and another type.
* The cast is required to define a callback function.
*
* @section [global]
* Violates MISRA 2012 Advisory Rule 11.4, Conversion between a pointer and
* integer type.
* The cast is required to initialize a pointer with an unsigned long define,
* representing an address.
*
* @section [global]
* Violates MISRA 2012 Required Rule 11.6, Cast from unsigned int to pointer.
* The cast is required to initialize a pointer with an unsigned long define,
* representing an address.
*
* @section [global]
* Violates MISRA 2012 Required Rule 11.6, cast from pointer to unsigned long
* The cast is needed to get the addresses of register on hardware modules.
*
* @section [global]
* Violates MISRA 2012 Advisory Rule 8.9, An object should be defined at block scope
* The variables FLASH_BLOCK_ADDR,FLASH_BLOCK_MASK identifier only appears in a
* single function and they must be visible.
*
* @section [global]
* Violates MISRA 2012 Required Rule 10.4, Mismatched essential type categories for binary operator.
* This is required by the average calculation of the data conversion.
*/
#include "flash_c55_driver.h"
#include "flash_c55_hw_access.h"
/* Block base address */
static const uint32_t FLASH_BLOCK_ADDR[NUM_BLOCK] = FLASH_BLOCK_ADDR_DEFINE;
/* Block mask */
static const uint32_t FLASH_BLOCK_MASK[NUM_BLOCK] = FLASH_BLOCK_MASK_DEFINE;
static status_t FLASH_DRV_CheckEraseExecution(flash_state_t * opStatus);
static status_t FLASH_DRV_CheckProgramExecution(flash_context_data_t * pCtxData, flash_state_t * opStatus);
static uint32_t FLASH_DRV_GetInterLockWriteAdd(const flash_block_select_t * block);
static uint32_t FLASH_DRV_FindInterLockWriteAddOfBlock(uint32_t valueBlockSelect, uint32_t typeBlockSelect);
static void FLASH_DRV_SuspendExecution(uint32_t MCRAdd, flash_state_t * suspendSta);
static status_t FLASH_DRV_CheckUserTestStatusExecution(const flash_context_data_t * pCtxData, flash_state_t * opStatus);
static status_t FLASH_DRV_ProgramExecution(flash_context_data_t * pCtxData, uint32_t dest, uint32_t size, uint32_t source);
/*******************************************************************************
* Code
******************************************************************************/
/*FUNCTION**********************************************************************
*
* Function Name : FLASH_DRV_CheckProgramExecution
* Description : This function will check the status of on-going high voltage
* in program operation. This one is called by FLASH_DRV_CheckProgram function.
*
*END**************************************************************************/
static status_t FLASH_DRV_CheckProgramExecution(flash_context_data_t * pCtxData,
flash_state_t * opStatus)
{
status_t returnCode = STATUS_SUCCESS; /* return code */
uint32_t RegValue = FLASH_C55->MCR;
uint32_t RegAddress = FLASH_C55_BASE + C55_MCR;
*opStatus = C55_OK;
/* Check PGOOD (PEG) */
if ((RegValue & C55_MCR_PEG) != 0x0U)
{
/* Clear EHV if it is high */
if ((RegValue & C55_MCR_EHV) != 0x0U)
{
REG_BIT_CLEAR32(RegAddress, C55_MCR_EHV);
/* If there is remaining data needs to be programmed */
if ((pCtxData->size) != 0x0U)
{
/* Call FLASH_DRV_Program to continue the operation */
returnCode = FLASH_DRV_Program(pCtxData,
pCtxData->dest,
pCtxData->size,
pCtxData->source);
if (returnCode == STATUS_SUCCESS)
{
returnCode = STATUS_FLASH_INPROGRESS;
}
}
else /* pCtxData->size == 0 */
{
/* Program finished successfully, clear PGM */
REG_BIT_CLEAR32(RegAddress, C55_MCR_PGM);
}
}
else /* EHV == 0 */
{
if ((RegValue & C55_MCR_ERS) != 0x0U)
{
*opStatus = C55_ERS_SUS_PGM_WRITE;
}
else
{
*opStatus = C55_PGM_WRITE;
}
}
}
else /* PEG == 0 */
{
/* PGOOD (PEG) is low */
if ((RegValue & C55_MCR_EHV) != 0x0U)
{
/* Clear EHV */
REG_BIT_CLEAR32(RegAddress, C55_MCR_EHV);
}
else /* EHV == 0 */
{
/* PEG is invalid at this stage */
if ((RegValue & C55_MCR_ERS) != 0x0U)
{
*opStatus = C55_ERS_SUS_PGM_WRITE;
}
else
{
*opStatus = C55_PGM_WRITE;
}
}
/* Program finished unsuccessfully, clear PGM */
REG_BIT_CLEAR32(RegAddress, C55_MCR_PGM);
returnCode = STATUS_ERROR;
}
return returnCode;
}
/*FUNCTION**********************************************************************
*
* Function Name : FLASH_DRV_CheckProgramStatus
* Description : This function will check the status of on-going high voltage
* in program operation.
*
* Implements : FLASH_DRV_CheckProgramStatus_Activity
*END**************************************************************************/
status_t FLASH_DRV_CheckProgramStatus(flash_context_data_t * pCtxData,
flash_state_t * opResult)
{
DEV_ASSERT(pCtxData != NULL);
DEV_ASSERT(opResult != NULL);
status_t returnCode = STATUS_SUCCESS; /* return code */
uint32_t RegValue; /* content of MCR or UT0 register */
*opResult = C55_OK;
RegValue = FLASH_C55->MCR;
/* There must be a program operation */
if ((RegValue & C55_MCR_PGM) != 0x0U)
{
/* If DONE bit goes high */
if ((RegValue & C55_MCR_DONE) != 0x0U)
{
/* If the operation is suspended */
if ((RegValue & C55_MCR_PSUS) != 0x0U)
{
/* Check if the suspended program is PGM_SUS or ERS_SUS_PGM_SUS */
if ((RegValue & C55_MCR_ERS) != 0x0U)
{
*opResult = C55_ERS_SUS_PGM_SUS;
}
else
{
*opResult = C55_PGM_SUS;
}
}
else
{
returnCode = FLASH_DRV_CheckProgramExecution(pCtxData,opResult);
}
}
else /* DONE == 0 */
{
/* DONE bit is still low means the operation is in-prog
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
MPC5748G_bootloader+app (166个子文件)
mpc5748g_bootloader_Z4_0.args 768B
mpc5748g_bootloader_Z4_0.args 745B
mpc5748g_app_Z4_0.args 634B
MPC57xx__Interrupt_Init.args 513B
MPC57xx__Interrupt_Init.args 495B
MPC57xx__Interrupt_Init.args 493B
intc_sw_handlers.args 452B
startup.args 452B
startup.args 434B
intc_sw_handlers.args 434B
intc_sw_handlers.args 432B
startup.args 432B
flash_c55_driver.c 80KB
intc_SW_mode_isr_vectors_MPC5748G.c 45KB
intc_SW_mode_isr_vectors_MPC5748G.c 45KB
flash.c 20KB
main.c 18KB
MPC57xx__Interrupt_Init.c 11KB
MPC57xx__Interrupt_Init.c 11KB
UserAppFlash.c 7KB
linflexd_uart.c 6KB
linflexd_uart.c 5KB
main.c 4KB
Vector.c 3KB
Vector.c 3KB
flashrchw.c 2KB
flashrchw.c 2KB
bootloader.c 2KB
.cproject 70KB
.cproject 70KB
UserAppFlash.d 4KB
UserAppFlash.d 4KB
flash_c55_driver.d 4KB
flash_c55_driver.d 4KB
flash.d 4KB
flash.d 4KB
main.d 4KB
main.d 4KB
linflexd_uart.d 3KB
linflexd_uart.d 3KB
MPC57xx__Interrupt_Init.d 3KB
MPC57xx__Interrupt_Init.d 3KB
linflexd_uart.d 3KB
main.d 3KB
MPC57xx__Interrupt_Init.d 3KB
intc_SW_mode_isr_vectors_MPC5748G.d 2KB
intc_SW_mode_isr_vectors_MPC5748G.d 2KB
intc_SW_mode_isr_vectors_MPC5748G.d 2KB
flashrchw.d 2KB
flashrchw.d 2KB
bootloader.d 2KB
bootloader.d 2KB
Vector.d 763B
Vector.d 763B
Vector.d 727B
mpc5748g_bootloader_Z4_0.elf 1.87MB
mpc5748g_bootloader_Z4_0.elf 1.83MB
mpc5748g_app_Z4_0.elf 672KB
MPC5748G_NEW.h 1.81MB
MPC5748G.h 1.71MB
MPC5748G.h 1.71MB
MPC5748G_features.h 128KB
flash_c55_driver.h 27KB
flash_c55_hw_access.h 13KB
status.h 13KB
project.h 9KB
project.h 9KB
typedefs.h 4KB
typedefs.h 4KB
devassert.h 4KB
can_init.h 3KB
UserAppFlash.h 2KB
compiler_api.h 1KB
compiler_api.h 1KB
bootloader.h 727B
linflexd_uart.h 670B
flash.h 656B
linflexd_uart.h 639B
derivative.h 204B
derivative.h 204B
mpc5748g_bootloader_Z4_0.hex 48KB
mpc5748g_app_Z4_0.hex 18KB
mpc5748g_app_Z4_0_Debug.launch 18KB
mpc5748g_bootloader_Z4_0_Debug.launch 17KB
mpc5748g_bootloader_Z4_0_Debug_RAM.launch 17KB
mpc5748g_app_Z4_0_Debug_RAM.launch 17KB
57xx_flash.ld 5KB
57xx_flash.ld 5KB
57xx_ram.ld 4KB
57xx_ram.ld 4KB
libs.ld 88B
libs.ld 88B
makefile 2KB
makefile 2KB
makefile 2KB
mpc5748g_bootloader_Z4_0.map 65KB
mpc5748g_bootloader_Z4_0.map 63KB
mpc5748g_app_Z4_0.map 39KB
subdir.mk 2KB
subdir.mk 2KB
共 166 条
- 1
- 2
Error_4O4
- 粉丝: 67
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1