Commit 1bac208a authored by hu's avatar hu

关于D1M1A操作DATA FLASH的驱动更改为FDL

parent 411f87f0
...@@ -34,4 +34,21 @@ ...@@ -34,4 +34,21 @@
.\CD4051\CD4051.c .\CD4051\CD4051.c
.\BU98R10\BU98R10.c .\BU98R10\BU98R10.c
.\Buzzer\Buzzer.c .\Buzzer\Buzzer.c
.\FDL\r_fdl.h
.\FDL\fdl_descriptor.c
.\FDL\fdl_user.c
.\FDL\fdlapp_control.c
.\FDL\fdlapp_main.c
.\FDL\app.h
.\FDL\fdl_cfg.h
.\FDL\fdl_descriptor.h
.\FDL\fdl_user.h
.\FDL\r_fdl_mem_map.h
.\FDL\r_fdl_types.h
.\FDL\target.h
.\FDL\lib\r_fdl_env.h
.\FDL\lib\r_fdl_global.h
.\FDL\lib\r_fdl_hw_access.c
.\FDL\lib\r_fdl_user_if.c
.\FDL\lib\r_fdl_user_if_init.c
No preview for this file type
...@@ -57,6 +57,7 @@ primaryTarget=v800_standalone.tgt ...@@ -57,6 +57,7 @@ primaryTarget=v800_standalone.tgt
-I..\source\Driver\Timer -I..\source\Driver\Timer
-I..\source\Driver\IS31FL3236 -I..\source\Driver\IS31FL3236
-I..\source\Driver\Buzzer -I..\source\Driver\Buzzer
-I..\source\Driver\FDL
-I..\source\Graphic\cdi\lib -I..\source\Graphic\cdi\lib
-I..\source\Graphic\cdi\src -I..\source\Graphic\cdi\src
-I..\source\Graphic\device\d1mx\lib -I..\source\Graphic\device\d1mx\lib
......
This source diff could not be displayed because it is too large. You can view the blob instead.
project .intvect 1536 project .intvect 1536
project .text 325980 project .text 327836
project .rodata 411127 project .rodata 412319
project .secinfo 120 project .secinfo 120
project .syscall 6 project .syscall 6
project .romdata 8805 project .romdata 8805
project .ROM.ramfunc 208 project .R_FDL_Text 5796
project .ramfunc 208
...@@ -74,6 +74,7 @@ void Popups_Polling(void) ...@@ -74,6 +74,7 @@ void Popups_Polling(void)
Popup_Clear(POPUP1_BRAKE_SPACING_R); Popup_Clear(POPUP1_BRAKE_SPACING_R);
Popup_Clear(POPUP1_BRAKE_SPACING_COLLISION); Popup_Clear(POPUP1_BRAKE_SPACING_COLLISION);
Popup_Clear(POPUP1_BRAKE_SPACING_Y); Popup_Clear(POPUP1_BRAKE_SPACING_Y);
Popup_Clear(POPUT1_ASR_OPERATE);
return ; return ;
} }
else else
...@@ -90,6 +91,7 @@ void Popups_Polling(void) ...@@ -90,6 +91,7 @@ void Popups_Polling(void)
Popup_Clear(POPUP1_BRAKE_SPACING_R); Popup_Clear(POPUP1_BRAKE_SPACING_R);
Popup_Clear(POPUP1_BRAKE_SPACING_COLLISION); Popup_Clear(POPUP1_BRAKE_SPACING_COLLISION);
Popup_Clear(POPUP1_BRAKE_SPACING_Y); Popup_Clear(POPUP1_BRAKE_SPACING_Y);
Popup_Clear(POPUT1_ASR_OPERATE);
return ; return ;
} }
else else
...@@ -106,6 +108,7 @@ void Popups_Polling(void) ...@@ -106,6 +108,7 @@ void Popups_Polling(void)
Popup_Request(POPUP1_BRAKE_SPACING_R); Popup_Request(POPUP1_BRAKE_SPACING_R);
Popup_Clear(POPUP1_BRAKE_SPACING_COLLISION); Popup_Clear(POPUP1_BRAKE_SPACING_COLLISION);
Popup_Clear(POPUP1_BRAKE_SPACING_Y); Popup_Clear(POPUP1_BRAKE_SPACING_Y);
Popup_Clear(POPUT1_ASR_OPERATE);
return ; return ;
} }
else else
...@@ -120,6 +123,7 @@ void Popups_Polling(void) ...@@ -120,6 +123,7 @@ void Popups_Polling(void)
{ {
Popup_Request(POPUP1_BRAKE_SPACING_COLLISION); Popup_Request(POPUP1_BRAKE_SPACING_COLLISION);
Popup_Clear(POPUP1_BRAKE_SPACING_Y); Popup_Clear(POPUP1_BRAKE_SPACING_Y);
Popup_Clear(POPUT1_ASR_OPERATE);
return ; return ;
} }
else else
...@@ -134,6 +138,7 @@ void Popups_Polling(void) ...@@ -134,6 +138,7 @@ void Popups_Polling(void)
if ((variable_1 == 0x05u) || (variable_2 == 0x05u)) if ((variable_1 == 0x05u) || (variable_2 == 0x05u))
{ {
Popup_Request(POPUP1_BRAKE_SPACING_Y); Popup_Request(POPUP1_BRAKE_SPACING_Y);
Popup_Clear(POPUT1_ASR_OPERATE);
return ; return ;
} }
else else
......
/*********************************************************************************************************************
* File Name : $Source: app.h $
* Mod. Revision : $Revision: 1.7 $
* Mod. Date : $Date: 2016/05/31 16:15:23JST $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : Sample application header file
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2014-2016 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
#ifndef SAMPLEAPP_H
#define SAMPLEAPP_H
/*********************************************************************************************************************
* Global compiler definition
*********************************************************************************************************************/
#define APP_COMP_GHS 1
#define APP_COMP_IAR 2
#define APP_COMP_REC 3
#if defined (__IAR_SYSTEMS_ASM__)
#define APP_COMPILER APP_COMP_IAR
#elif defined (__IAR_SYSTEMS_ICC__)
#define APP_COMPILER APP_COMP_IAR
#elif defined(__v850e3v5__)
#define APP_COMPILER APP_COMP_REC
#else /*GHS */
#define APP_COMPILER APP_COMP_GHS
#endif
/*********************************************************************************************************************/
#endif /* #ifndef SAMPLEAPP_H */
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_OFF 0292
#endif
/*********************************************************************************************************************
* File Name : $Source: fdl_cfg.h $
* Mod. Revision : $Revision: 1.5 $
* Mod. Date : $Date: 2016/06/01 10:39:51JST $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : FDL pre-compile definitions
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2015-2016 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_ON 0292
#endif
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 3.1 (QAC message 0292)
* Reason: To support automatic insertion of revision, module name etc. by the source revision control system
* it is necessary to violate the rule, because the system uses non basic characters as placeholders.
* Verification: The placeholders are used in commentars only. Therefore rule violation cannot influency code
* compilation.
*********************************************************************************************************************/
#ifndef FDL_CFG_H
#define FDL_CFG_H
/*********************************************************************************************************************
* device specific define
*********************************************************************************************************************/
/******************************************************************************************************************
* Callback defines to disable interrupts during execution of critical code sections in the
* function R_FDL_Init.
* All possibly occurring exceptions must be disabled because during execution of the critical
* sections the Flash is not accessible
******************************************************************************************************************/
void FDL_User_CriticalSetionBegin (void);
void FDL_User_CriticalSetionEnd (void);
#define FDL_CRITICAL_SECTION_BEGIN FDL_User_CriticalSetionBegin (); /* PRQA S 3412 */
#define FDL_CRITICAL_SECTION_END FDL_User_CriticalSetionEnd (); /* PRQA S 3412 */
/******************************************************************************************************************
* Optional configuration
******************************************************************************************************************/
/*********************************************************************************************************************/
#endif /* #ifndef FDL_CFG_H */
/*********************************************************************************************************************
* File Name : $Source: fdl_descriptor.c $
* Mod. Revision : $Revision: 1.11 $
* Mod. Date : $Date: 2016/05/31 16:15:26JST $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : Descriptor variable definition
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2015-2016 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
/*********************************************************************************************************************
* FDL header files include
*********************************************************************************************************************/
#include "r_typedefs.h"
#include "r_fdl.h"
#include "fdl_descriptor.h"
/*********************************************************************************************************************
* FDL descriptor variable definition
*********************************************************************************************************************/
/**< FDL descriptor structure */
const r_fdl_descriptor_t sampleApp_fdlConfig_enu =
{
CPU_FREQUENCY_MHZ, /**< CPU frequency in MHz */
FDL_POOL_SIZE, /**< Number of Data Flash blocks, accessible by the FDL.
Typically no. of available Data Flash blocks */
EEL_POOL_START, /**< 1st block of the EEL pool */
EEL_POOL_SIZE /**< Number of blocks in the EEL pool */
};
/*********************************************************************************************************************
* File Name : $Source: fdl_descriptor.h $
* Mod. Revision : $Revision: 1.4 $
* Mod. Date : $Date: 2016/06/01 10:39:59JST $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : FDL run-time configuration descriptor variable related defines.
* To be configured according to the application needs
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2015-2016 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
#ifndef FDL_DESCRIPTOR_H
#define FDL_DESCRIPTOR_H
#include "r_fdl_types.h"
/*********************************************************************************************************************
User changeable defines
*********************************************************************************************************************/
/*****************************************************************************************************************
* Important definitions for run-time configuration of the FDL:
* - Frequency -
*****************************************************************************************************************/
/* The Flash programming hardware is provided with a clock, derived from the CPU subsystem frequency. Check that
the frequency is correct as this has an impact on the programming quality and performance! */
#define CPU_FREQUENCY_MHZ (240) // (240) /**< CPU frequency in MHz */
/*****************************************************************************************************************
* Important definitions for run-time configuration of the FDL:
* - EEL/FDL Pool -
*****************************************************************************************************************/
/* The physical erase unit of the Data Flash is 64Byte.
The Renesas EEL works with a ring buffer consisting of ring buffer (virtual) blocks that merge a certain number
of physical blocks.
E.g. virtual block size of 2kB equals 32 physical blocks of 64Bytes --> EEL_VIRTUALBLOCKSIZE = 32
virtual block size of 4kB equals 64 physical blocks of 64Bytes --> EEL_VIRTUALBLOCKSIZE = 64
Note: If the Renesas EEL is not used, an alignment is not necessary "EEL_VIRTUALBLOCKSIZE" need not be defined
and the pools start and size definitions can be set free to the application needs */
#define EEL_VIRTUALBLOCKSIZE (64u)
#define FDL_POOL_SIZE (16u * EEL_VIRTUALBLOCKSIZE) /**< Number of Data Flash blocks, accessible by
the FDL. Typically it is the complete
no. of available Data Flash blocks */
#define EEL_POOL_START (0u * EEL_VIRTUALBLOCKSIZE) /**< 1st block of the EEL pool */
#define EEL_POOL_SIZE (0u * EEL_VIRTUALBLOCKSIZE) /**< no. of blocks for the EEL pool */
/*********************************************************************************************************************
* Even if possible, this section should not be changed by the user
*********************************************************************************************************************/
/*****************************************************************************************************************
* Descriptor variable declaration
*****************************************************************************************************************/
extern const r_fdl_descriptor_t sampleApp_fdlConfig_enu; /**< FDL descriptor variable */
/*********************************************************************************************************************/
#endif /* #ifndef FDL_DESCRIPTOR_H */
/*********************************************************************************************************************
* File Name : $Source: fdl_user.c $
* Mod. Revision : $Revision: 1.17 $
* Mod. Date : $Date: 2016/05/31 16:15:27JST $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : library related functions, which may be edited by the user
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2015-2016 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
/*********************************************************************************************************************
* FDL header files include
*********************************************************************************************************************/
#include "r_typedefs.h"
#include "app.h"
#include "target.h"
/*********************************************************************************************************************
* Compiler specific defines
*********************************************************************************************************************/
#if APP_COMPILER == APP_COMP_GHS
#elif APP_COMPILER == APP_COMP_IAR
#define asm __asm
#elif APP_COMPILER == APP_COMP_REC
#endif
/*********************************************************************************************************************
* module global variable
*********************************************************************************************************************/
uint32_t PSWSafe; /* Variable to backup the PSW value before disabling ID/NP */
/*********************************************************************************************************************
* Function name: FDL_User_CriticalSetionBegin
*********************************************************************************************************************/
/**
* Function to disable Maskable / non maskable exceptions and NMI when critical code shall be
* executed that allows no access to the code Flash or might have problems with synchronization
*
* @param ---
* @return ---
*/
/*********************************************************************************************************************/
#if APP_COMPILER == APP_COMP_GHS
void FDL_User_CriticalSetionBegin (void)
{
asm( "ldsr r0, 31" ); /* select system register bank 0
(contains PSW)*/
asm( "stsr 0x05, r7" ); /* load PSW (register 5) */
asm( "mov _PSWSafe, r6" ); /* backup PSW */
asm( "st.w r7, 0[r6]" ); /* " */
asm( "movea 0x00A0, r0, r6" ); /* NMI Flag=1, ID=1 */
asm( "or r7, r6 "); /* " */
asm( "ldsr r6, 5" ); /* write PSW */
}
#elif APP_COMPILER == APP_COMP_REC
#pragma inline_asm FDL_User_CriticalSetionBegin
void FDL_User_CriticalSetionBegin (void)
{
ldsr r0, 31 /* select system register bank 0 */
/* (contains PSW) */
stsr 0x05, r7 /* load PSW (register 5) */
mov #_PSWSafe, r6 /* backup PSW */
st.w r7, 0[r6] /* " */
movea 0x00A0, r0, r6 /* NMI Flag=1, ID=1 */
or r7, r6 /* " */
ldsr r6, 5 /* write PSW */
}
#else
/* IAR */
void FDL_User_CriticalSetionBegin (void)
{
__asm(" ldsr r0, 31 \n"
" stsr 0x05, r7 \n"
" mov _PSWSafe, r6 \n"
" st.w r7, 0[r6] \n"
" movea 0x00A0, r0, r6 \n"
" or r7, r6 \n"
" ldsr r6, 5 \n"
);
}
#endif
/*********************************************************************************************************************
* Function name: FDL_User_CriticalSetionEnd
*********************************************************************************************************************/
/**
* Function to enable Maskable / non maskable exceptions and NMI after critical code has been
* executed
*
* @param ---
* @return ---
*/
/*********************************************************************************************************************/
#if APP_COMPILER == APP_COMP_GHS
void FDL_User_CriticalSetionEnd (void)
{
asm( "ldsr r0, 31" ); /* select system register bank 0
(contains PSW)*/
asm( "mov _PSWSafe, r6" ); /* Restore PSW value */
asm( "ld.w 0[r6], r7" ); /* " */
asm( "ldsr r7, 5" ); /* write PSW */
}
#elif APP_COMPILER == APP_COMP_REC
#pragma inline_asm FDL_User_CriticalSetionEnd
void FDL_User_CriticalSetionEnd (void)
{
ldsr r0, 31 /* select system register bank 0
(contains PSW) */
mov #_PSWSafe, r6 /* Restore PSW value */
ld.w 0[r6], r7 /* " */
ldsr r7, 5 /* write PSW */
}
#else
/* IAR */
void FDL_User_CriticalSetionEnd (void)
{
__asm(" ldsr r0, 31 \n"
" mov _PSWSafe, r6 \n"
" ld.w 0[r6], r7 \n"
" ldsr r7, 5 \n"
);
}
#endif
/*********************************************************************************************************************
* Function name: FDL_Open
*********************************************************************************************************************/
/**
* Function to open the FDL operation.
* The user modifiable function e.g. Initializes/Configures the Data Flash access
*
* @param ---
* @return ---
*/
/*********************************************************************************************************************/
void FDL_Open (void)
{
//INIT_FLASHACCESS //keith
}
/*********************************************************************************************************************
* Function name: FDL_Close
*********************************************************************************************************************/
/**
* Function to close the FDL operation.
* The user modifyable function might disable Flash access, ... currently, it is empty
*
* @param ---
* @return ---
*/
/*********************************************************************************************************************/
void FDL_Close (void)
{
// DISABLE_FLASHACCESS //keith
}
/*********************************************************************************************************************
* File Name : $Source: fdl_user.h $
* Mod. Revision : $Revision: 1.7 $
* Mod. Date : $Date: 2016/05/31 16:15:23JST $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : header for library related functions, which may be edited by the user
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2015-2016 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
#ifndef FDL_USER_H
#define FDL_USER_H
/*********************************************************************************************************************
* Global function prototypes
*********************************************************************************************************************/
void FDL_User_CriticalSetionBegin (void);
void FDL_User_CriticalSetionEnd (void);
void FDL_Open (void);
void FDL_Close (void);
/*********************************************************************************************************************/
#endif /* #ifndef FDL_USER_H */
/*********************************************************************************************************************
* File Name : $Source: fdlapp_control.c $
* Mod. Revision : $Revision: 1.8 $
* Mod. Date : $Date: 2014/07/30 13:14:47MESZ $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : Application sample program control module
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2014 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
/*********************************************************************************************************************
* header files include
*********************************************************************************************************************/
#include "r_typedefs.h"
#include "r_fdl.h"
#include "fdl_descriptor.h"
#include "target.h"
#include "Watchdog.h"
#include "Emulated_EEPROM_Access.h"
#include "fdl_user.h"
#include <stdint.h>
/*********************************************************************************************************************
* Module internal function prototypes
*********************************************************************************************************************/
/*********************************************************************************************************************
Function name: SampleApp_FDL_Control
*********************************************************************************************************************/
/**
EEL sample function to handle FDL functionality. Executing a set of dummy Flash operations
@param ---
@return ---
*/
/*********************************************************************************************************************/
#define OFFSET_ADDR 0xFF200000UL
void SampleApp_FDL_Control(void)
{
r_fdl_status_t fdlRet;
r_fdl_request_t req;
uint8_t wBuf_au08[64] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f};
uint32_t rBuf_au32[64]; /* Read buffer must be 32bit aligned as the read operation accesses it 32bit aligned */
volatile uint16_t data;
/* 1st initialize the FDL */
fdlRet = R_FDL_Init(&sampleApp_fdlConfig_enu);
if (R_FDL_OK != fdlRet)
{
/* Error handler */
while (1)
;
}
#ifndef R_FDL_LIB_V1_COMPATIBILITY
/* Prepare the environment */
req.idx_u32 = 0;
req.command_enu = R_FDL_CMD_PREPARE_ENV;
req.cnt_u16 = 0;
req.accessType_enu = R_FDL_ACCESS_NONE;
R_FDL_Execute(&req);
while (R_FDL_BUSY == req.status_enu)
{
R_FDL_Handler();
}
if (R_FDL_OK != req.status_enu)
{
/* Error handler */
while (1)
;
}
#endif
/* -----------------------------------------------------------------------
Example...
Read a Word --> address 0x0004 of the Data Flash
1) Do a blank check to distinguish if the read value is based on erased
data or written data. We can only trust written data
2) read the data
----------------------------------------------------------------------- */
req.command_enu = R_FDL_CMD_BLANKCHECK;
req.idx_u32 = 0; //地址
req.cnt_u16 = 1; //
req.accessType_enu = R_FDL_ACCESS_USER;
R_FDL_Execute(&req);
while (R_FDL_BUSY == req.status_enu)
{
R_FDL_Handler();
}
if (R_FDL_OK == req.status_enu)
{
/* The half word is blank... we may not read */
}
else if (R_FDL_ERR_BLANKCHECK == req.status_enu)
{
/* Read the data */
data = (*(uint16_t *)0xff200004);
}
else
{
/* Error handler.. on an internal error */
while (1)
;
}
/* -----------------------------------------------------------------------
Example...
Erase Flash block 0
----------------------------------------------------------------------- */
req.command_enu = R_FDL_CMD_ERASE;
req.idx_u32 = 0; //起始块///32K
req.cnt_u16 = 1; //块计数
req.accessType_enu = R_FDL_ACCESS_USER;
R_FDL_Execute(&req);
while (R_FDL_BUSY == req.status_enu)
{
R_FDL_Handler();
}
if (R_FDL_OK != req.status_enu)
{
/* Error handler */
while (1)
;
}
/* wBuf_au08[0] = 0xaa;
wBuf_au08[1] = 0x55;
wBuf_au08[2] = 0xCC;
wBuf_au08[3] = 0xFF;
wBuf_au08[20] = 0xaa;
wBuf_au08[21] = 0x55;
wBuf_au08[22] = 0xCC;
wBuf_au08[23] = 0xFF;*/
/* -----------------------------------------------------------------------
Write data:
addresses 0x00000000 - 0x0000001F
----------------------------------------------------------------------- */
req.command_enu = R_FDL_CMD_WRITE;
req.idx_u32 = 0x0000; //地址
req.cnt_u16 = 0x8; //长度 单位u32
req.bufAddr_u32 = (uint32_t)(&wBuf_au08[0]);
req.accessType_enu = R_FDL_ACCESS_USER;
R_FDL_Execute(&req);
while (R_FDL_BUSY == req.status_enu)
{
R_FDL_Handler();
}
if (R_FDL_OK != req.status_enu)
{
/* Error handler */
while (1)
;
}
/* -----------------------------------------------------------------------
Read data:
addresses 0x00000000 - 0x0000001F
----------------------------------------------------------------------- */
req.command_enu = R_FDL_CMD_READ;
req.idx_u32 = 0x0000; //地址
req.cnt_u16 = 0x8; //长度 单位u32
req.bufAddr_u32 = (uint32_t)(&rBuf_au32[0]);
req.accessType_enu = R_FDL_ACCESS_USER;
R_FDL_Execute(&req);
while (R_FDL_BUSY == req.status_enu)
{
R_FDL_Handler();
}
if (R_FDL_OK != req.status_enu)
{
/* Error handler */
while (1)
;
}
/* -----------------------------------------------------------------------
Read data:
addresses 0x00000020 - 0x00000023
... Most probably resulting in ECC error
----------------------------------------------------------------------- */
req.command_enu = R_FDL_CMD_READ;
req.idx_u32 = 0x0020;
req.cnt_u16 = 0x1;
req.bufAddr_u32 = (uint32_t)(&rBuf_au32[0]);
req.accessType_enu = R_FDL_ACCESS_USER;
R_FDL_Execute(&req);
while (R_FDL_BUSY == req.status_enu)
{
R_FDL_Handler();
}
if ((R_FDL_ERR_ECC_SED != req.status_enu) &&
(R_FDL_ERR_ECC_DED != req.status_enu))
{
/* Error handler */
while (1)
;
}
return;
}
/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/
r_fdl_status_t TYW_FDL_Init(void)
{
r_fdl_status_t fdlRet;
r_fdl_request_t req;
FDL_Open();
/* 1st initialize the FDL */
fdlRet = R_FDL_Init(&sampleApp_fdlConfig_enu);
if (R_FDL_OK != fdlRet)
{
/* Error handler */
return fdlRet;
}
#ifndef R_FDL_LIB_V1_COMPATIBILITY
/* Prepare the environment */
req.command_enu = R_FDL_CMD_PREPARE_ENV;
req.idx_u32 = 0;
req.cnt_u16 = 0;
req.accessType_enu = R_FDL_ACCESS_NONE;
R_FDL_Execute(&req);
while (R_FDL_BUSY == req.status_enu)
{
R_FDL_Handler();
WDT_Clear();
}
return req.status_enu;
#endif
}
r_fdl_status_t TYW_FDL_Erase(uint32_t u32StartAddr, uint32_t u32EndAddr)
{
r_fdl_request_t req;
uint32_t StartBlockIndex = 0U;
uint32_t EndBlockIndex = 0U;
StartBlockIndex = ((u32StartAddr - OFFSET_ADDR) / 64U);
EndBlockIndex = ((u32EndAddr - OFFSET_ADDR) / 64U);
req.command_enu = R_FDL_CMD_ERASE;
req.idx_u32 = StartBlockIndex; //起始块///32K
req.cnt_u16 = (EndBlockIndex + 1 - StartBlockIndex); //1; //块计数
req.accessType_enu = R_FDL_ACCESS_USER;
R_FDL_Execute(&req);
while (R_FDL_BUSY == req.status_enu)
{
R_FDL_Handler();
WDT_Clear();
}
if (R_FDL_OK == req.status_enu)
{
EEPROM_Mem_Access_Complete_Callback();
}
return req.status_enu;
}
r_fdl_status_t TYW_FDL_Write(uint32_t u32Addr, uint32_t u32Data[], uint32_t u32Len)
{
r_fdl_request_t req;
req.command_enu = R_FDL_CMD_WRITE;
req.idx_u32 = u32Addr - OFFSET_ADDR; //地址
req.cnt_u16 = u32Len; //长度 单位u32
req.bufAddr_u32 = (uint32_t)(&u32Data[0]);
req.accessType_enu = R_FDL_ACCESS_USER;
R_FDL_Execute(&req);
while (R_FDL_BUSY == req.status_enu)
{
R_FDL_Handler();
WDT_Clear();
}
if (R_FDL_OK == req.status_enu)
{
EEPROM_Mem_Access_Complete_Callback();
}
return req.status_enu;
}
/*
u32StartAddr:需是4的倍数
u32EndAddr:加1之后需是4的倍数
*/
uint32_t TYW_FDL_Blank_Check(uint32_t u32StartAddr, uint32_t u32EndAddr)
{
r_fdl_request_t req;
uint32_t u32Addr = 0xFFFFFFFFU;
uint32_t i;
uint32_t Result;
uint32_t Count = (u32EndAddr - u32StartAddr + 1) / 4;
uint32_t CalBuf = 0U;
CalBuf = u32EndAddr - (u32EndAddr % 4);
for (i = 0; i < Count; i++)
{
req.command_enu = R_FDL_CMD_BLANKCHECK;
req.idx_u32 = CalBuf - OFFSET_ADDR; //
req.cnt_u16 = 1; //
req.accessType_enu = R_FDL_ACCESS_USER;
R_FDL_Execute(&req);
while (R_FDL_BUSY == req.status_enu)
{
R_FDL_Handler();
WDT_Clear();
}
if (R_FDL_OK == req.status_enu)
{
u32Addr = CalBuf - u32StartAddr;
CalBuf -= 4;
}
else
{
break;
}
}
return (u32Addr);
}
r_fdl_status_t TYW_FDL_Flash_Read(uint32_t u32Addr, uint32_t u32Data[], uint32_t u32Len)
{
r_fdl_request_t req;
uint32_t u32BlankCeck = 0UL;
u32BlankCeck = TYW_FDL_Blank_Check(u32Addr, (u32Addr + u32Len * 4UL-1UL));
if (u32BlankCeck == 0xFFFFFFFFU)
{
req.command_enu = R_FDL_CMD_READ;
req.idx_u32 = u32Addr - OFFSET_ADDR; //地址
req.cnt_u16 = u32Len; //长度 单位u32
req.bufAddr_u32 = (uint32_t)(&u32Data[0]);
req.accessType_enu = R_FDL_ACCESS_USER;
R_FDL_Execute(&req);
while (R_FDL_BUSY == req.status_enu)
{
R_FDL_Handler();
WDT_Clear();
}
return req.status_enu;
}
return R_FDL_ERR_ECC_DED;
}
/*********************************************************************************************************************
* File Name : $Source: fdlapp_main.c $
* Mod. Revision : $Revision: 1.7 $
* Mod. Date : $Date: 2014/09/10 16:24:34MESZ $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : Application sample main module
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2014 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
/*********************************************************************************************************************
* FDL header files include
*********************************************************************************************************************/
#define EEELIB_INTDEF
#include "r_typedefs.h"
#include "target.h"
#include "fdl_user.h"
/*********************************************************************************************************************
* External Function headers
*********************************************************************************************************************/
void SampleApp_FDL_Control ( void );
/*********************************************************************************************************************
* Function name: main
*********************************************************************************************************************/
/**
* main function
*
* @param ---
* @return ---
*/
/*********************************************************************************************************************/
void dataflash_test(void)
{
/*****************************************************************************************************************
* CPU initialization
*****************************************************************************************************************/
/* Initialize the CPU and Peripheral clock system */
// INIT_CPU_AND_FPERIPHERAL_CLK
#if (defined R_FDL_DEVICE_SPECIFIC_INIT)
/* Some older devices like F1L WS2.0 need Flash authentication prior to switch mode */
R_FDL_DEVICE_SPECIFIC_INIT;
#endif
/*****************************************************************************************************************
* Open the FDL / Data Flash access
*****************************************************************************************************************/
/* Initialize the data FLash is required to be able to access the data Flash. As this is considered to be a user
function, it is not part of the libraries, but part of the application sample */
FDL_Open ();
/*****************************************************************************************************************
* Call sample functions
*****************************************************************************************************************/
/* Sample of FDL handling */
SampleApp_FDL_Control ();
/*****************************************************************************************************************
* Close the FDL / Data Flash access
*****************************************************************************************************************/
FDL_Close ();
/*****************************************************************************************************************
* Wait forever
*****************************************************************************************************************/
/* Not reachable */
}
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_OFF 0292
#endif
/*********************************************************************************************************************
* Library : Data Flash Access Library for Renesas RH850 devices
*
* File Name : $Source: r_fdl_env.h $
* Lib. Version : $RH850_FDL_LIB_VERSION_T01: V2.11 $
* Mod. Revision : $Revision: 1.21 $
* Mod. Date : $Date: 2016/06/01 12:39:17JST $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : Flash programming hardware related definitions
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2015-2016 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_ON 0292
#endif
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 3.1 (QAC message 0292)
* Reason: To support automatic insertion of revision, module name etc. by the source revision control system
* it is necessary to violate the rule, because the system uses non basic characters as placeholders.
* Verification: The placeholders are used in commentaries only. Therefore rule violation cannot influence code
* compilation.
*********************************************************************************************************************/
#ifndef R_FDL_ENV_H
#define R_FDL_ENV_H
/*********************************************************************************************************************
* Global constants (define, const, ...)
*********************************************************************************************************************/
/* ---------------- FCU definitions ---------------------------------------- */
#ifdef R_FDL_CPE_SUPPORT
#include "r_fdl_env_cpe.h"
#else
#define R_FCU_BASE (0xFFA10000uL)
#define R_FCU_RAM_ADD (0xFFA12000uL)
#define R_FCU_DFLASH_CMD_ADD (0xFFA20000uL)
#define R_BWCBUF_G3K_ADD (0xFFBC0700uL)
#define R_BWCBUF_G3KH_ADD (0xFFC5B000uL)
#endif
#define R_FCU_REGADD_FASTAT_U08 (R_FCU_BASE + 0x010uL)
#define R_FCU_REGBIT_FASTAT_CMDLK (0x10u)
#define R_FCU_REGADD_FAEINT_U08 (R_FCU_BASE + 0x014uL)
#define R_FCU_REGVAL_FAEINT_DISABLE (0x88u)
#define R_FCU_REGVAL_FAEINT_ENABLE (0x99u)
#define R_FCU_REGADD_FMATSELC_U16 (R_FCU_BASE + 0x020uL)
#define R_FCU_REGBIT_FMATSELC_KEY (0x3B00u)
#define R_FCU_REGBIT_FMATSELC_EX3S (0x0004u) /* Select EXA3 */
#define R_FCU_REGBIT_FMATSELC_RESET (0x0000u)
#define R_FCU_REGADD_FSADR_U32 (R_FCU_BASE + 0x030uL)
#define R_FCU_REGADD_FEADR_U32 (R_FCU_BASE + 0x034uL)
#define R_FCU_REGADD_FCURAME_U16 (R_FCU_BASE + 0x054uL)
#define R_FCU_REGBIT_FCURAME_KEY (0xC400u)
#define R_FCU_REGBIT_FCURAME_FCRME (0x0001u) /* 1: on, 0: off */
#define R_FCU_REGBIT_FCURAME_FRAMTRAN (0x0002u) /* 0: RW, 1: High speed */
#define R_FCU_REGBIT_FCURAME_RESET (0x0000u)
#define R_FCU_REGADD_FSTATR_U32 (R_FCU_BASE + 0x080uL)
#define R_FCU_REGBIT_FSTATR_FRCRCT (0x00000001uL)
#define R_FCU_REGBIT_FSTATR_FRDTCT (0x00000002uL)
#define R_FCU_REGBIT_FSTATR_TBLDTCT (0x00000008uL)
#define R_FCU_REGBIT_FSTATR_CFGDTCT (0x00000020uL)
#define R_FCU_REGBIT_FSTATR_FHVEERR (0x00000040uL)
#define R_FCU_REGBIT_FSTATR_FCUERR (0x00000080uL)
#define R_FCU_REGBIT_FSTATR_PRGSPD (0x00000100uL)
#define R_FCU_REGBIT_FSTATR_ERSSPD (0x00000200uL)
#define R_FCU_REGBIT_FSTATR_DBFULL (0x00000400uL)
#define R_FCU_REGBIT_FSTATR_SUSRDY (0x00000800uL)
#define R_FCU_REGBIT_FSTATR_PRGERR (0x00001000uL)
#define R_FCU_REGBIT_FSTATR_ERSERR (0x00002000uL)
#define R_FCU_REGBIT_FSTATR_ILGERR (0x00004000uL)
#define R_FCU_REGBIT_FSTATR_FRDY (0x00008000uL)
#define R_FCU_REGBIT_FSTATR_OTPDTCT (0x00020000uL)
#define R_FCU_REGBIT_FSTATR_RESET (0x00000000uL)
#define R_FCU_REGADD_FENTRYR_U16 (R_FCU_BASE + 0x084uL)
#define R_FCU_REGBIT_FENTRY_FENTRYD (0x0080u)
#define R_FCU_REGBIT_FENTRY_FENTRYC (0x0001u)
#define R_FCU_REGBIT_FENTRY_KEY (0xAA00u)
#define R_FCU_REGBIT_FENTRY_OFF (0x0000u)
#define R_FCU_REGBIT_FENTRY_KEYMASK (0x00FFu)
#define R_FCU_MODE_PE (R_FCU_REGBIT_FENTRY_FENTRYD)
#define R_FCU_MODE_CPE (R_FCU_REGBIT_FENTRY_FENTRYC)
#define R_FCU_MODE_USER (R_FCU_REGBIT_FENTRY_OFF)
#define R_FCU_REGADD_FBCSTAT_U08 (R_FCU_BASE + 0x0D4uL)
#define R_FCU_REGBIT_FBCSTAT_BCST (0x01u)
#define R_FCU_REGADD_FPSADDR_U32 (R_FCU_BASE + 0x0D8uL)
#define R_FCU_REGADD_PCKAR_U16 (R_FCU_BASE + 0x0E4uL)
#define R_FCU_REGBIT_PCKAR_KEY (0x1E00u)
#define R_DECC_BASE_E1X (0xFFC62C00uL)
#define R_DECC_BASE_F1X (0xFFC66000uL)
#define R_DECC_BASE (g_fdl_str.baseAddrECC_u32)
#define R_FCU_REGADD_DFERSTR_U32 (R_DECC_BASE + 0x004uL)
#define R_FCU_REGBIT_DFERSTR_SEDF (0x00000001u)
#define R_FCU_REGBIT_DFERSTR_DEDF (0x00000002u)
#define R_FCU_REGVAL_DFERSTR_NOERR (0x00000000u)
#define R_FCU_REGADD_DFERSTC_U08 (R_DECC_BASE + 0x008uL)
#define R_FCU_REGBIT_DFERSTC_ERRCLR (0x01u)
#define R_FCU_REGADD_DFERINT_U08 (R_DECC_BASE + 0x014uL)
#define R_FCU_REGVAL_DFERINT_NOINT (0x00u)
/* The BFA defines are just dummy defines in order to remember that the values are required.
The values are used in in-line assembly code and cannot be derived from this header file */
#define R_CCIB_BASE (0xFFC59000uL)
#define R_FCU_REGADD_BFASELR_U08 (R_CCIB_BASE + 0x008uL)
#define R_FCU_REGBIT_BFASELR_BFASEL (0x01u)
#define R_FCU_REGBIT_BFASELR_RESET (0x00u)
/* ---------------- Other Data Flash related defines ----------------------- */
#define R_FCU_RAM_SIZE (0x00001000uL)
#ifdef R_FDL_NO_BFA_SWITCH
#define R_FCU_RAM_BASE_ADD (0x01037000uL)
#define R_FCU_FWPARAM_BASE_ADD (0x01030000uL)
#else
#define R_FCU_RAM_BASE_ADD (0x00017000uL)
#define R_FCU_FWPARAM_BASE_ADD (0x00010000uL)
#endif
#define R_FCU_RAM_SRC_ADD (R_FCU_RAM_BASE_ADD)
#define R_FCU_RAM_ADD_CHKSUM_END (R_FCU_RAM_BASE_ADD + 0x00000FF8uL)
#define R_FCU_RAM_ADD_CHKSUM (R_FCU_RAM_BASE_ADD + 0x00000FFCuL)
#define R_EXTRA3_FWVER (R_FCU_FWPARAM_BASE_ADD + 0x00000219uL)
#define R_EXTRA3_FMAX (R_FCU_FWPARAM_BASE_ADD + 0x00000234uL)
#define R_EXTRA3_FMIN (R_FCU_FWPARAM_BASE_ADD + 0x00000238uL)
#define R_EXTRA3_FDIV_FWVER_03 (R_FCU_FWPARAM_BASE_ADD + 0x00000264uL)
#define R_EXTRA3_FPCLK_FWVER_03 (R_FCU_FWPARAM_BASE_ADD + 0x00000274uL)
#define R_EXTRA3_FDIV_FWVER_04 (R_FCU_FWPARAM_BASE_ADD + 0x00000265uL)
#define R_EXTRA3_FPCLK_FWVER_04 (R_FCU_FWPARAM_BASE_ADD + 0x00000278uL)
#define R_EXTRA3_SCDSADD (R_FCU_FWPARAM_BASE_ADD + 0x00000270uL)
#define R_EXTRA3_ECCADDR (R_FCU_FWPARAM_BASE_ADD + 0x00000288uL)
#define R_FCU_FWVER_03 (0x03u)
#define R_FCU_FWVER_04 (0x04u)
#define R_PRDSEL3_OFFSET (0xC8uL)
#define R_PRDNAME2_OFFSET (0xD4uL)
#define R_PRDNAME_010x (0x00303130u)
#define R_FCU_DFLASH_READ_ADD (0xFF200000uL)
#define R_FCU_CMD_ERASE (0x20u) /* FCU erase command */
#define R_FCU_CMD_CLEARSTAT (0x50u) /* FCU clear status reg. command */
#define R_FCU_CMD_BLANKCHECK (0x71u) /* FCU BC command */
#define R_FCU_CMD_SUSPEND (0xB0u) /* FCU suspend command */
#define R_FCU_CMD_FORCED_STOP (0xB3u) /* Stop and reset FCU */
#define R_FCU_CMD_WRITE (0xE8u) /* FCU write command */
#define R_FCU_CMD_EXE (0xD0u) /* FCU start execution */
#define R_FCU_DATA_TRANSFERSIZE (0x02uL)
#define R_FCU_FMIN (0x0004u)
#define R_FCU_FMAX (0x0064u)
#define R_BLOCK_SIZE (0x0040u) /* EEP Flash block size in bytes */
#define R_BLOCK_SIZE_2N (0x0006u) /* EEP block size as 2^N Bytes */
#define R_WRITE_SIZE (0x00000004uL) /* Normal write granularity */
#define R_WRITE_SIZE_16B (0x00000010uL) /* 16 bytes write granularity */
#define R_MACROSIZE_MIN (0x00001000uL) /* Minimum Flash macro size */
#define R_SYSTEM_REGISTER_PID 6, 1 /* do not use brackets to access system register */
#define R_PID_CORE_MASK (0x000000E0)
#define R_PID_CORE_G3K (0x00000020)
#define R_PID_CORE_G3KH (0x000000a0)
/* ---------------------------- Other defines ------------------------------ */
#define R_U32_ALIGNED (0x03u)
/*********************************************************************************************************************/
#endif /* ifndef R_FDL_ENV_H */
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_OFF 0292
#endif
/*********************************************************************************************************************
* Library : Data Flash Access Library for Renesas RH850 devices
*
* File Name : $Source: r_fdl_global.h $
* Lib. Version : $RH850_FDL_LIB_VERSION_T01: V2.11 $
* Mod. Revision : $Revision: 1.43 $
* Mod. Date : $Date: 2016/06/07 09:29:27JST $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : FDL internal definitions and global functions
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2015-2016 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_ON 0292
#endif
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 3.1 (QAC message 0292)
* Reason: To support automatic insertion of revision, module name etc. by the source revision control system
* it is necessary to violate the rule, because the system uses non basic characters as placeholders.
* Verification: The placeholders are used in commentaries only. Therefore rule violation cannot influence code
* compilation.
*********************************************************************************************************************/
#ifndef R_FDL_GLOBAL_H
#define R_FDL_GLOBAL_H
/*********************************************************************************************************************
* Include list
*********************************************************************************************************************/
#include "r_typedefs.h"
#include "r_fdl.h"
#include "r_fdl_env.h"
#if R_FDL_COMPILER == R_FDL_COMP_GHS
uint32_t __STSR(int32_t regID, int32_t selID);
#elif R_FDL_COMPILER == R_FDL_COMP_IAR
__intrinsic int32_t __STSR(int32_t reg, int32_t selID);
#elif R_FDL_COMPILER == R_FDL_COMP_REC
#endif
/*********************************************************************************************************************
* Global constants (define, const, ...)
*********************************************************************************************************************/
/* -------------------- Library version string ----------------------------- */
#define R_FDL_VERSION_STRING "DH850T01xxxxxxV211"
/* -------------------- Misc constants ------------------------------------- */
/* Reset value of request pointers */
#define R_FDL_REQUEST_POINTER_UNDEFINED (r_fdl_request_t *)(0x00000000uL)
#define R_FDL_DESCRIPTOR_POINTER_UNDEFINED (r_fdl_descriptor_t *)(0x00000000uL)
#define R_FDL_NULL (0x00000000uL)
/* -------------------- Size of RAM buffer for Code exececution ------------ */
/* Estimation of stack variable size:
- Code size R_FDL_FCUFct_InitRAM_Asm: 166 Bytes (GHS/REC/IAR)
- Code 1st address must be 16Byte aligned (fetch size): +16Bytes
- Code last address must be 16Byte aligned (fetch size)
- Prefetch: 4*16Byte
--> 176Bytes (166Bytes aligned to 16Bytes) + 16Bytes + 64Bytes
= 256Bytes = 128half words (=instruction alignment)
- Code size R_FDL_IFct_GetFWParam_Asm: always less than R_FDL_FCUFct_InitRAM_Asm
*/
#define R_FDL_RAM_CODE_SIZE_HW (128)
/* ----- Unique timeout value is 40us ----- */
/* Clear cache register check loop timeout */
/* clocks per timeout loop */
#define R_FDL_TIMEOUT_CC_CLK_P_LOOP (3)
/* timeout loop_count: (40us * f_MHz) / (clk per loop) --- but rounding up to be considered */
#define R_FDL_TIMEOUT_CC ( ( (40 * g_fdl_str.RTCfg_pstr->cpuFrequencyMHz_u16) \
+ (R_FDL_TIMEOUT_CC_CLK_P_LOOP - 1) ) / R_FDL_TIMEOUT_CC_CLK_P_LOOP )
/* IO register check loop timeout */
/* clocks per timeout loop */
#define R_FDL_TIMEOUT_CHKREG_CLK_P_LOOP (19)
/* timeout loop_count: (40us * f_MHz) / (clk per loop) --- but rounding up to be considered */
#define R_FDL_TIMEOUT_CHKREG ( ( (40 * g_fdl_str.RTCfg_pstr->cpuFrequencyMHz_u16) \
+ (R_FDL_TIMEOUT_CHKREG_CLK_P_LOOP - 1) ) / R_FDL_TIMEOUT_CHKREG_CLK_P_LOOP )
/*********************************************************************************************************************
* Global type definitions
*********************************************************************************************************************/
/**
\enum r_fdl_flag_t
standard FDL internal flag definition
*/
typedef enum R_FDL_FLAG_T
{
R_FDL_FALSE, /**< Flag false */
R_FDL_TRUE /**< Flag true */
} r_fdl_flag_t;
/**
\enum r_fdl_int_status_t
definition of the FDL operational status
*/
typedef enum R_FDL_INT_STATUS_T
{
R_FDL_ISTAT_NOINIT = 0x00000000uL, /**< Pattern for uninitialized library (0x00000000) */
R_FDL_ISTAT_INIT = 0x55555554uL, /**< Pattern for initialized library after R_FDL_Init */
R_FDL_ISTAT_NORMALOP = 0x55555555uL, /**< Pattern for prepared library after
R_FDL_CMD_PREPARE_ENV execution */
R_FDL_ISTAT_SUSPEND_PR = 0x55555556uL, /**< Pattern for library in suspend processing */
R_FDL_ISTAT_SUSPENDED = 0x55555557uL, /**< Pattern for library in suspend status */
R_FDL_ISTAT_STANDBY_PR = 0x55555558uL, /**< Pattern for library in standby processing */
R_FDL_ISTAT_STANDBY = 0x55555559uL /**< Pattern for library in standby */
} r_fdl_int_status_t;
/**
\typedef r_fdl_pFct_ExeInRAM
pointer to a function. Is used in e.g. R_FDL_FCUFct_InitRAM_...
*/
typedef void (* r_fdl_pFct_ExeInRAM)(uint32_t * param_pu32);
/**
\enum r_fdl_op_status_t
definition of the internal operation status required for switch mode handling
*/
typedef enum R_FDL_OP_STATUS_T
{
R_FDL_OP_IDLE = 0, /**< No on-going operation */
R_FDL_OP_EXECUTE_SYNC_ON = 1, /**< Operation ready to start, switch mode
to P/E requested */
R_FDL_OP_PREPARE_START = 2, /**< Prepare environment operation ready to start,
switch mode to P/E requested */
R_FDL_OP_PREPARE_RST_FCU = 3, /**< Prepare environment operation started,
switch mode to P/E requested */
R_FDL_OP_PREPARE_END = 4, /**< Prepare environment operation on-going, FCU reset performed,
switch mode to read requested */
R_FDL_OP_RESUME_SYNC_ON = 5, /**< Resume request accepted, switch mode
to P/E requested */
R_FDL_OP_RESUME_MULTI_SYNC_ON = 6, /**< Resume request accepted to restart a multiple operation,
switch mode to P/E requested */
R_FDL_OP_BUSY = 7, /**< On-going operation */
R_FDL_OP_SUSPEND_SYNC_OFF = 8, /**< Suspend processing finished, switch mode to read requested */
R_FDL_OP_END_SYNC_OFF = 9 /**< Operation finished, switch mode to read requested */
} r_fdl_op_status_t;
/**
\struct r_fdl_multiOp_t
structure containing the data required for multi operations (erase multiple blocks, write multiple half words data)
*/
typedef struct R_FDL_MULTIOP_T
{
uint32_t flashAdd_u32; /**< source data pointer */
uint32_t bufAdd_u32; /**< destination data pointer */
uint32_t flashAddEnd_u32; /**< last source address to write */
r_fdl_accessType_t accessType_enu; /**< access type */
} r_fdl_multiOp_t;
/**
\struct r_fdl_data_t
this structure contains all FDL internal data
*/
typedef struct R_FDL_DATA_T
{
const r_fdl_descriptor_t * RTCfg_pstr; /**< pointer to descriptor structure, initialized by
R_FDL_ISTAT_INIT */
r_fdl_multiOp_t mulOp_str; /**< multi operation (erase/write) variables. Set when a multi
operation is started, checked/updated when a single
erase/write is finished */
r_fdl_multiOp_t spdMulOp_str; /**< multi operation variables backup for FDL suspend */
r_fdl_request_t * reqSuspend_pstr; /**< request structure pointer backup buffer for suspend/resume */
r_fdl_request_t * reqInt_pstr; /**< request structure pointer for current operation */
r_fdl_op_status_t opStatus_enu; /**< Operation status required for switch mode handling */
uint32_t opFailAddr_u32; /**< fail address of the blank check operation */
uint32_t dfSize_u32; /**< Data Flash size, required for boundary checks */
uint32_t baseAddrECC_u32; /**< ECC base address determined on firmware
parameter version */
uint32_t chksumEndAddr_u32; /**< Checksum end address */
uint32_t chksumVal_u32; /**< Checksum value */
uint16_t flashMode_u16; /**< Current Flash operating mode: P/E or Read */
r_fdl_status_t spdResStatus_enu; /**< result backup buffer for suspend/resume */
r_fdl_status_t opResult_enu; /**< result backup buffer for switch mode handling */
r_fdl_flag_t cancelRequest_enu; /**< cancel request indication to the handler */
r_fdl_flag_t spdSpdRequest_enu; /**< suspend request indication to the handler */
r_fdl_flag_t spdResRequest_enu; /**< resume request indication to the handler */
r_fdl_int_status_t stByIStatBackUp_enu; /**< internal status backup for StandBy processing */
r_fdl_int_status_t iStat_enu; /**< FDL operational status variable */
} r_fdl_data_t;
/*********************************************************************************************************************
* Global macros
*********************************************************************************************************************/
/* Static functions definition */
#ifndef R_FDL_STATIC
#define R_FDL_STATIC static
#endif
/*********************************************************************************************************************
* Global function prototypes
*********************************************************************************************************************/
r_fdl_status_t R_FDL_FCUFct_CheckFatalError (void);
r_fdl_flag_t R_FDL_FCUFct_ChkReady (void);
r_fdl_flag_t R_FDL_FCUFct_ChkSuspendable (void);
r_fdl_flag_t R_FDL_FCUFct_ChkStartable (r_fdl_command_t cmd_enu);
void R_FDL_FCUFct_ClearStatus (void);
r_fdl_status_t R_FDL_FCUFct_GetStat (void);
r_fdl_status_t R_FDL_FCUFct_InitRAM (void);
r_fdl_status_t R_FDL_FCUFct_ReadOperation (volatile uint32_t * pAddSrc_u32,
uint32_t addDest_u32,
uint32_t cnt_u32);
r_fdl_flag_t R_FDL_FCUFct_ResumeChkNeed (void);
void R_FDL_FCUFct_Resume (void);
r_fdl_status_t R_FDL_FCUFct_SetFrequency (void);
r_fdl_status_t R_FDL_FCUFct_GetDFSize (uint32_t *size);
r_fdl_status_t R_FDL_FCUFct_StartBCEraseOperation (uint32_t addStart_u32,
uint32_t addEnd_u32,
uint8_t fcuCmd_u08,
r_fdl_accessType_t accType_enu);
r_fdl_status_t R_FDL_FCUFct_StartWriteOperation (uint32_t addSrc_u32,
uint32_t addDest_u32,
uint32_t cnt_u32,
r_fdl_accessType_t accType_enu);
void R_FDL_FCUFct_Suspend (void);
r_fdl_status_t R_FDL_FCUFct_SwitchMode_Start (uint16_t mode_u16);
r_fdl_status_t R_FDL_FCUFct_SwitchMode_Check (void);
r_fdl_status_t R_FDL_IFct_ChkAccessBoundaries (uint32_t addrStart_u32,
uint32_t bCnt_u32,
r_fdl_accessType_t accType_enu,
uint32_t granularity_u32);
void R_FDL_IFct_WriteMemoryU08 (uint32_t addr_u32,
uint8_t val_u08);
void R_FDL_IFct_CalcFOpUnitCnt_BC (uint32_t * cnt_pu32,
uint32_t addr_u32);
r_fdl_status_t R_FDL_FCUFct_ForcedStop (void);
void R_FDL_FCUFct_Switch_FAEINT (r_fdl_flag_t on_t);
r_fdl_status_t R_FDL_FCUFct_VerifyChecksum (void);
/*********************************************************************************************************************
* Global data declarations
*********************************************************************************************************************/
#define R_FDL_START_SEC_VAR
#include "r_fdl_mem_map.h"
#if R_FDL_COMPILER == R_FDL_COMP_GHS
#define R_FDL_NOINIT
#elif R_FDL_COMPILER == R_FDL_COMP_IAR
#define R_FDL_NOINIT __no_init
#elif R_FDL_COMPILER == R_FDL_COMP_REC
#define R_FDL_NOINIT
#endif
extern R_FDL_NOINIT r_fdl_data_t g_fdl_str; /**< fdl global variable structure */
#define R_FDL_STOP_SEC_VAR
#include "r_fdl_mem_map.h"
#ifndef R_FDL_EXE_INIT_CODE_ON_STACK
#define R_FDL_START_SEC_CODERAM
#include "r_fdl_mem_map.h"
/* Code size calculation described in r_fdl_global.h */
extern R_FDL_NOINIT uint16_t g_fdl_ramCodeBuf_au16[R_FDL_RAM_CODE_SIZE_HW];
#define R_FDL_STOP_SEC_CODERAM
#include "r_fdl_mem_map.h"
#endif
/*********************************************************************************************************************/
/*********************************************************************************************************************
* Add test defines and typedefs
*********************************************************************************************************************/
#ifdef PATCH_TO_SIMULATE_ERRORS
#include "FDL-tc_common.h"
#endif
/* specific defines for coverage measurement */
#ifdef _BullseyeCoverage
#define R_FDL_COV_SAVEOFF _Pragma ("BullseyeCoverage save off")
#define R_FDL_COV_RESTORE _Pragma ("BullseyeCoverage restore")
#else
#define R_FDL_COV_SAVEOFF
#define R_FDL_COV_RESTORE
#endif
/*********************************************************************************************************************/
#endif /* ifndef R_FDL_GLOBAL_H */
This source diff could not be displayed because it is too large. You can view the blob instead.
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_OFF 0292
#endif
/*********************************************************************************************************************
* Library : Data Flash Access Library for Renesas RH850 devices
*
* File Name : $Source: r_fdl_user_if.c $
* Lib. Version : $RH850_FDL_LIB_VERSION_T01: V2.11 $
* Mod. Revision : $Revision: 1.52 $
* Mod. Date : $Date: 2016/06/01 12:39:21JST $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : FDL user interface functions
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2015-2016 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_ON 0292
#endif
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 3.1 (QAC message 0292)
* Reason: To support automatic insertion of revision, module name etc. by the source revision control system
* it is necessary to violate the rule, because the system uses non basic characters as placeholders.
* Verification: The placeholders are used in commentaries only. Therefore rule violation cannot influence code
* compilation.
*********************************************************************************************************************/
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 11.3 (QAC message 0306)
* Reason: For effective embedded programming, integer to pointer conversions are used
* Verification: The converted addresses are essential for complete code execution. Incorrect
* conversion would result in test fails.
*********************************************************************************************************************/
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 14.1 (QAC message 1503)
* Reason: This function is not used within the library, it is only used by the user
* application.
* Verification: This function is part of the library API and therefore essential on the one hand.
* On the other hand the QAC warning is correct, because this function is never
* called within the library. To solve this dilemma it is necessary and suitable
* to disable the message.
*********************************************************************************************************************/
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 19.1 (QAC message 5087)
* Reason: The section mapping concept (Mapping code, constants and data to specific linker sections) bases on
* a central include file containing all section mapping defines and pragmas. This need to be included
* multiple times within the code. The file itself only contains those defines and pragmas.
* Verification: This is the standard concept defined for AUTOSAR implementations
*********************************************************************************************************************/
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 9.1 (QAC message 2962)
* Reason: Apparent using value of an uninitialized variable fcuCmd, used to convert API commands
* (see r_fdl_command_t enum) into commands passed to the hardware.
* Verification: The variable fcuCmd is set properly for all commands except R_FDL_CMD_READ, for which is not used
* at all.
*********************************************************************************************************************/
#define R_FDL_USERIF_C
/*********************************************************************************************************************
* FDL header files include
*********************************************************************************************************************/
#include "r_fdl_global.h"
/*********************************************************************************************************************
* Module internal function prototypes
*********************************************************************************************************************/
R_FDL_STATIC void R_FDL_UFct_EndCurrentOperation (r_fdl_status_t ret_enu);
R_FDL_STATIC r_fdl_flag_t R_FDL_UFct_FlashOpStart (r_fdl_request_t * request_pstr,
r_fdl_status_t * tmpStat_penu,
r_fdl_flag_t isCalledFromExecute_enu);
R_FDL_STATIC r_fdl_flag_t R_FDL_Handler_BusyAndSuspendPossible (void);
R_FDL_STATIC r_fdl_flag_t R_FDL_Handler_ChkResume (r_fdl_status_t * tmpStat_penu);
R_FDL_STATIC r_fdl_flag_t R_FDL_Handler_ReactOnFatalErrors (r_fdl_status_t * tmpStat_penu);
R_FDL_STATIC r_fdl_flag_t R_FDL_Handler_StatusCheckAndSuspendOnReady (r_fdl_status_t * tmpStat_penu);
R_FDL_STATIC r_fdl_flag_t R_FDL_Handler_MultiOperation (r_fdl_status_t * tmpStat_penu);
R_FDL_STATIC r_fdl_flag_t R_FDL_UFct_StateNotStandBy (void);
R_FDL_STATIC r_fdl_flag_t R_FDL_Handler_OperationStates (r_fdl_status_t * tmpStat_penu);
R_FDL_STATIC r_fdl_flag_t R_FDL_Handler_CancelReq (r_fdl_status_t * tmpStat_penu);
/*********************************************************************************************************************
* Global variables
*********************************************************************************************************************/
/*********************************************************************************************************************
* MISRA Rule: QAC message 2022
* Reason: Basically, global variables should be initialized. However, as the library is used for multiple
* compilers and not all compilers support explicit initialization for variables in not standard
* sections, this variable is initialized in the library initialization function rather than by the
* compiler.
* Verification: test case
*********************************************************************************************************************/
/* Note:
* The define "R_FDL_COV_ENABLED" is a specific define for library testing purpose only.
* The user application shall not set this define */
#if (!defined R_FDL_COV_ENABLED)
#define R_FDL_START_SEC_VAR
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
R_FDL_NOINIT r_fdl_data_t g_fdl_str; /* PRQA S 2022 */
#define R_FDL_STOP_SEC_VAR
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
#ifndef R_FDL_EXE_INIT_CODE_ON_STACK
#define R_FDL_START_SEC_CODERAM
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/* Code size calculation described in r_fdl_global.h */
R_FDL_NOINIT uint16_t g_fdl_ramCodeBuf_au16[R_FDL_RAM_CODE_SIZE_HW]; /* PRQA S 2022 */
#define R_FDL_STOP_SEC_CODERAM
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
#endif
#else /* #if (!defined R_FDL_COV_ENABLED) */
R_FDL_NOINIT r_fdl_data_t g_fdl_str; /* PRQA S 2022 */
#ifndef R_FDL_EXE_INIT_CODE_ON_STACK
R_FDL_NOINIT uint16_t g_fdl_ramCodeBuf_au16[R_FDL_RAM_CODE_SIZE_HW]; /* PRQA S 2022 */
#endif
#endif /* #else #if (!defined R_FDL_COV_ENABLED) */
/*********************************************************************************************************************
* Function name: R_FDL_InitVariables
*********************************************************************************************************************/
/**
* Part of the R_FDL_Init function.
* This function initializes the FDL internal variables and does the FDL configuration parameter checks.
* The following parameter checks are done:
* - Descriptor variable is defined
* - FDL pool is defined
* - EEL pool is within FDL pool
*
* In error case the library is set to not initialized (R_FDL_ISTAT_NOINIT)
*
* @param[in] descriptor_pstr - Pointer to the FDL descriptor structure
* @return Initialization status when returned from function call:
* - R_FDL_OK - Initialization was successful
* - R_FDL_ERR_CONFIGURATION - FDL configuration parameter error
*/
/*********************************************************************************************************************/
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 8.8 (QAC message 3408)
* Reason: Library is delivered as source code and as a precompiled object.
* The file r_fdl_user_if_init.c is not included on generation of the precompiled object.
* It is delivered as a separate file and cannot include any other header files, except the
* defined interface header files. The function is a library internal function and its declaration
* is not part of the interface header files.
* Verification: -
*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
r_fdl_status_t R_FDL_InitVariables (const r_fdl_descriptor_t * descriptor_pstr) /* PRQA S 3408 */
{
r_fdl_status_t ret;
uint32_t fdAdd;
uint32_t i;
uint16_t blkEnd;
/* Initially clear the complete r_fdl_data structure */
fdAdd = (uint32_t)(&g_fdl_str); /* PRQA S 0306 */
for (i = 0; i < sizeof (g_fdl_str); i++)
{
R_FDL_IFct_WriteMemoryU08 (fdAdd, 0u);
fdAdd++;
}
g_fdl_str.iStat_enu = R_FDL_ISTAT_NOINIT;
ret = R_FDL_OK;
/* We have a descriptor at all */
if (R_FDL_DESCRIPTOR_POINTER_UNDEFINED != descriptor_pstr)
{
/* Set pointer to FDL static configuration */
g_fdl_str.RTCfg_pstr = descriptor_pstr;
/* Parameter independent initializations */
(g_fdl_str.reqSuspend_pstr) = R_FDL_REQUEST_POINTER_UNDEFINED;
(g_fdl_str.reqInt_pstr) = R_FDL_REQUEST_POINTER_UNDEFINED;
/* Reset misc flags */
g_fdl_str.cancelRequest_enu = R_FDL_FALSE;
g_fdl_str.spdSpdRequest_enu = R_FDL_FALSE;
g_fdl_str.spdResRequest_enu = R_FDL_FALSE;
g_fdl_str.flashMode_u16 = R_FCU_MODE_USER;
g_fdl_str.opStatus_enu = R_FDL_OP_IDLE;
/* FDL Pool is available */
if (0u != g_fdl_str.RTCfg_pstr->fdlPoolSize_u16)
{
blkEnd = (g_fdl_str.RTCfg_pstr->eelPoolStart_u16)
+ (g_fdl_str.RTCfg_pstr->eelPoolSize_u16);
/* EEL Pool fits into FDL pool */
if (blkEnd >= (g_fdl_str.RTCfg_pstr->fdlPoolSize_u16 + 1u) )
{
ret = R_FDL_ERR_CONFIGURATION;
}
}
else
{
ret = R_FDL_ERR_CONFIGURATION;
}
}
/* We don't have a descriptor at all */
else
{
ret = R_FDL_ERR_CONFIGURATION;
}
/* Only if no error occurred, the library status is set to initialized */
if (R_FDL_OK == ret)
{
g_fdl_str.iStat_enu = R_FDL_ISTAT_INIT;
}
return (ret);
} /* R_FDL_InitVariables */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_Execute
*********************************************************************************************************************/
/**
* User interface function:
* This function initiates a Flash operation (Erase/Write/Read/Prepare Environment).
* After initiation, the function R_FDL_Handler need to be called regularly to finish the operation.
*
* @param[in, out] request_pstr Pointer to the operation request structure.
* - Structure input elements: \n
* command_enu, bufAddr_u32, idx_u32, cnt_u16, accessType_enu
* - Structure output element: \n
* status_enu
* @return ---
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
void R_FDL_Execute (r_fdl_request_t * request_pstr) /* PRQA S 1503 */
{
r_fdl_status_t reqErr;
reqErr = R_FDL_ERR_REJECTED;
/* Request structure pointer parameter is not "0x00" */
if (R_FDL_REQUEST_POINTER_UNDEFINED != request_pstr)
{
/* library internal request structure pointer is "0x00" (No operation ongoing) */
if (R_FDL_REQUEST_POINTER_UNDEFINED == g_fdl_str.reqInt_pstr)
{
/* Library is initialized */
if (R_FDL_ISTAT_INIT == g_fdl_str.iStat_enu)
{
/* Only Prepare command is allowed when teh library is in initialized status */
if (R_FDL_CMD_PREPARE_ENV == request_pstr->command_enu)
{
reqErr = R_FDL_FCUFct_SwitchMode_Start (R_FCU_MODE_PE);
/* No invalid FACI programming mode detected */
if (R_FDL_OK == reqErr)
{
reqErr = R_FDL_BUSY;
g_fdl_str.opStatus_enu = R_FDL_OP_EXECUTE_SYNC_ON;
}
}
}
/* Library is prepared and not busy and no cancel request */
else if ( (R_FDL_ISTAT_NORMALOP == g_fdl_str.iStat_enu) ||
( (R_FDL_ISTAT_SUSPENDED == g_fdl_str.iStat_enu) &&
(R_FDL_FALSE == g_fdl_str.cancelRequest_enu) ) )
{
/* Command selection */
switch (request_pstr->command_enu)
{
case R_FDL_CMD_BLANKCHECK:
{
(void)R_FDL_UFct_FlashOpStart (request_pstr, &reqErr, R_FDL_TRUE);
break;
}
#if (defined ENABLE_CMD_WRITE16B)
case R_FDL_CMD_WRITE16B:
#endif
case R_FDL_CMD_ERASE:
case R_FDL_CMD_WRITE:
{
/* Check FACI suspend flags points out that the command can be started */
if (R_FDL_TRUE == R_FDL_FCUFct_ChkStartable (request_pstr->command_enu) )
{
(void)R_FDL_UFct_FlashOpStart (request_pstr, &reqErr, R_FDL_TRUE);
}
break;
}
case R_FDL_CMD_READ:
{
(void)R_FDL_UFct_FlashOpStart (request_pstr, &reqErr, R_FDL_TRUE);
break;
}
case R_FDL_CMD_PREPARE_ENV:
{
reqErr = R_FDL_ERR_REJECTED;
break;
}
default:
{
reqErr = R_FDL_ERR_COMMAND;
break;
}
} /* switch */
}
else
{
/* Nothing to do, added to fix QAC warning message 2004 */
}
}
/* Command execution started */
if (R_FDL_BUSY == reqErr)
{
/* set internal pointer to the request structure, required by the handler */
g_fdl_str.reqInt_pstr = request_pstr;
}
/* Command execution rejected */
else
{
/* At operations end (In error case or if the operation requires no handler calls), reset
the access type */
request_pstr->accessType_enu = R_FDL_ACCESS_NONE;
g_fdl_str.opStatus_enu = R_FDL_OP_IDLE;
}
/* Set the return state */
request_pstr->status_enu = reqErr;
}
return;
} /* R_FDL_Execute */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_Handler_CancelReq
*********************************************************************************************************************/
/**
* Part of the R_FDL_Handler function.
* This function cancels an ongoing Flash operation if:
* - cancel request flag set
* - switch mode is performed
*
* @param[out] tmpStat_penu - Status return value. Is modified, if an operation is cancelled.
* @return handler function flow may continue after this function or handler need to exit
* - R_FDL_TRUE - continue handler
* - R_FDL_FALSE - exit handler
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
R_FDL_STATIC r_fdl_flag_t R_FDL_Handler_CancelReq (r_fdl_status_t * tmpStat_penu)
{
r_fdl_flag_t cont;
r_fdl_status_t res;
cont = R_FDL_TRUE;
/* Only do something is cancel request flag is not already set */
if (R_FDL_TRUE == g_fdl_str.cancelRequest_enu)
{
if (R_FDL_OK == R_FDL_FCUFct_SwitchMode_Check() )
{
/* FACI in programming mode */
if (R_FCU_MODE_PE == g_fdl_str.flashMode_u16)
{
res = R_FDL_FCUFct_ForcedStop();
/* Timeout error in forced stop - internal error
Note: If FACI remains busy, it might happen that a mode switch will not be performed.
Thus, don't try to do it but finish with internal error immediately.
This means that DF is possibly not readable */
if (R_FDL_OK != res)
{
(*tmpStat_penu) = R_FDL_ERR_INTERNAL;
cont = R_FDL_FALSE;
}
/* After forced stop, switch to user mode */
else
{
(void)R_FDL_FCUFct_SwitchMode_Start (R_FCU_MODE_USER);
g_fdl_str.opResult_enu = R_FDL_CANCELLED;
(*tmpStat_penu) = R_FDL_BUSY;
g_fdl_str.opStatus_enu = R_FDL_OP_END_SYNC_OFF;
}
}
/* FACI is idle */
else
{
(*tmpStat_penu) = R_FDL_CANCELLED;
cont = R_FDL_FALSE;
}
g_fdl_str.cancelRequest_enu = R_FDL_FALSE;
g_fdl_str.spdSpdRequest_enu = R_FDL_FALSE;
g_fdl_str.spdResRequest_enu = R_FDL_FALSE;
g_fdl_str.iStat_enu = R_FDL_ISTAT_NORMALOP;
/* In case of suspended Flash operation, also the suspended operation's request
structure need to be updated */
if (R_FDL_REQUEST_POINTER_UNDEFINED != g_fdl_str.reqSuspend_pstr)
{
g_fdl_str.reqSuspend_pstr->status_enu = R_FDL_CANCELLED;
g_fdl_str.reqSuspend_pstr = R_FDL_REQUEST_POINTER_UNDEFINED;
}
}
else
{
cont = R_FDL_FALSE;
}
}
return (cont);
} /* R_FDL_Handler_CancelReq */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_Handler_BusyAndSuspendPossible
*********************************************************************************************************************/
/**
* Part of the R_FDL_Handler function.
* This function suspends an ongoing Flash operation if:
* - suspend request flag set
* - function is suspendable
*
* @param[in,out] -
* @return Handler function flow may continue afte this function or handler need to exit
* - R_FDL_TRUE - continue handler
* - R_FDL_FALSE - exit handler
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
R_FDL_STATIC r_fdl_flag_t R_FDL_Handler_BusyAndSuspendPossible (void)
{
r_fdl_flag_t cont;
cont = R_FDL_TRUE;
/* Handle a suspend request */
if (R_FDL_TRUE == g_fdl_str.spdSpdRequest_enu)
{
/* FACI allows suspending */
if (R_FDL_TRUE == R_FDL_FCUFct_ChkSuspendable() )
{
/* Must be called before changing g_fdl_str.iStat_enu because
g_fdl_str.iStat_enu is checked in R_FDL_Standby! */
R_FDL_FCUFct_Suspend();
g_fdl_str.spdSpdRequest_enu = R_FDL_FALSE;
g_fdl_str.iStat_enu = R_FDL_ISTAT_SUSPEND_PR;
cont = R_FDL_FALSE;
}
}
return (cont);
} /* R_FDL_Handler_BusyAndSuspendPossible */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_Handler_ChkResume
*********************************************************************************************************************/
/**
* Part of the R_FDL_Handler function.
* This function resumes a suspended Flash operation if:
* - resume request flag set (can only be set if a function was suspended)
* - No Flash operation is ongoing
*
* @param[out] tmpStat_penu - Status return value. Is modified, if an operation is resumed.
* @return handler function flow may continue after this function or handler need to exit:
* - R_FDL_TRUE - continue handler
* - R_FDL_FALSE - exit handler
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
R_FDL_STATIC r_fdl_flag_t R_FDL_Handler_ChkResume (r_fdl_status_t * tmpStat_penu)
{
r_fdl_flag_t cont;
r_fdl_status_t res;
cont = R_FDL_FALSE;
/* Resume request flag set and no operation ongoing */
if ( (R_FDL_REQUEST_POINTER_UNDEFINED == g_fdl_str.reqInt_pstr)
&& (R_FDL_TRUE == g_fdl_str.spdResRequest_enu) )
{
g_fdl_str.spdResRequest_enu = R_FDL_FALSE;
/* We need to resume a Flash operation */
if (R_FDL_BUSY == g_fdl_str.spdResStatus_enu)
{
res = R_FDL_FCUFct_SwitchMode_Start (R_FCU_MODE_PE);
/* protection error during mode switching */
if (R_FDL_OK != res)
{
g_fdl_str.reqSuspend_pstr->status_enu = res;
}
/* Continue resuming */
else
{
g_fdl_str.opStatus_enu = R_FDL_OP_RESUME_SYNC_ON;
cont = R_FDL_TRUE;
g_fdl_str.iStat_enu = R_FDL_ISTAT_NORMALOP;
}
}
/* We need to resume to command execution end or to start of a new Flash operation */
else
{
/* In order to support continuing Multi-Operations, we need to patch the
R_FDL_OK to R_FDL_BUSY. Errors result in operation end (Write, Erase, BC errors) */
if ( (R_FDL_OK == g_fdl_str.spdResStatus_enu)
&& (g_fdl_str.spdMulOp_str.flashAdd_u32 < g_fdl_str.spdMulOp_str.flashAddEnd_u32) )
{
res = R_FDL_FCUFct_SwitchMode_Start (R_FCU_MODE_PE);
/* protection error during mode switching */
if (R_FDL_OK != res)
{
g_fdl_str.reqSuspend_pstr->status_enu = res;
}
/* Continue with next resume step */
else
{
g_fdl_str.opStatus_enu = R_FDL_OP_RESUME_MULTI_SYNC_ON;
g_fdl_str.spdResStatus_enu = R_FDL_BUSY;
cont = R_FDL_TRUE;
g_fdl_str.iStat_enu = R_FDL_ISTAT_NORMALOP;
}
}
/* Operation ends */
else
{
g_fdl_str.iStat_enu = R_FDL_ISTAT_NORMALOP;
(*tmpStat_penu) = g_fdl_str.spdResStatus_enu;
}
}
/* on successful resume, restore the FDL operation data */
if (R_FDL_ISTAT_SUSPENDED != g_fdl_str.iStat_enu)
{
/* Restore variables for resume */
g_fdl_str.reqInt_pstr = g_fdl_str.reqSuspend_pstr;
/* if operation finished, the result will be set in the end of the handler function */
g_fdl_str.reqInt_pstr->status_enu = R_FDL_BUSY;
g_fdl_str.reqSuspend_pstr = R_FDL_REQUEST_POINTER_UNDEFINED;
g_fdl_str.mulOp_str.flashAdd_u32 = g_fdl_str.spdMulOp_str.flashAdd_u32;
g_fdl_str.mulOp_str.bufAdd_u32 = g_fdl_str.spdMulOp_str.bufAdd_u32;
g_fdl_str.mulOp_str.flashAddEnd_u32 = g_fdl_str.spdMulOp_str.flashAddEnd_u32;
g_fdl_str.mulOp_str.accessType_enu = g_fdl_str.spdMulOp_str.accessType_enu;
}
}
else
{
cont = R_FDL_TRUE;
}
return (cont);
} /* R_FDL_Handler_ChkResume */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_Handler_ReactOnFatalErrors
*********************************************************************************************************************/
/**
* Part of the R_FDL_Handler function.
* Read out Flash operation error status after operation end and react on fatal errors.
*
* @param[out] tmpStat_penu - Status return value. Is set to internal error in case of detection
* of a fatal HW error
* @return handler function flow may continue after this function or handler need to exit:
* - R_FDL_TRUE - continue handler
* - R_FDL_FALSE - exit handler
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
R_FDL_STATIC r_fdl_flag_t R_FDL_Handler_ReactOnFatalErrors (r_fdl_status_t * tmpStat_penu)
{
r_fdl_flag_t cont;
r_fdl_status_t stat;
cont = R_FDL_TRUE;
/* Check for fatal error (protection or internal error) */
stat = R_FDL_FCUFct_CheckFatalError();
/* Error case */
if (R_FDL_OK != stat)
{
R_FDL_FCUFct_ClearStatus();
(void)R_FDL_FCUFct_SwitchMode_Start (R_FCU_MODE_USER);
/* Switch mode function passed */
if (R_FDL_BUSY == R_FDL_FCUFct_SwitchMode_Check() )
{
g_fdl_str.opStatus_enu = R_FDL_OP_END_SYNC_OFF;
/* save status, will be returned on mode switch confirmation */
g_fdl_str.opResult_enu = stat;
(*tmpStat_penu) = R_FDL_BUSY;
}
else
{
(*tmpStat_penu) = stat;
}
cont = R_FDL_FALSE;
}
return (cont);
} /* R_FDL_Handler_ReactOnFatalErrors */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_Handler_StatusCheckAndSuspendOnReady
*********************************************************************************************************************/
/**
* Part of the R_FDL_Handler function.
* Get and judge Flash operation result (not fatal errors, just operation results) and
* do further suspend processing in case of pending suspend request or already suspended
* Flash operation.
*
* @param[out] tmpStat_penu - Status return value. Is set to operation result or to suspended in
* case of suspend processing.
* @return handler function flow may continue after this function or handler need to exit:
* - R_FDL_TRUE - continue handler
* - R_FDL_FALSE - exit handler
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
R_FDL_STATIC r_fdl_flag_t R_FDL_Handler_StatusCheckAndSuspendOnReady (r_fdl_status_t * tmpStat_penu)
{
r_fdl_flag_t cont;
r_fdl_status_t res;
cont = R_FDL_TRUE;
/* Get operation status after operation end and reset the hardware status */
(*tmpStat_penu) = R_FDL_FCUFct_GetStat();
R_FDL_FCUFct_ClearStatus();
/* Suspend handling
- suspend possible, part 2 (Flash operation is suspended now) -or-
- suspend impossible (operation finished but suspend request still active) */
if (R_FDL_TRUE == g_fdl_str.spdSpdRequest_enu)
{
/* suspend was impossible --> handle it now after operation completion */
g_fdl_str.spdSpdRequest_enu = R_FDL_FALSE;
g_fdl_str.iStat_enu = R_FDL_ISTAT_SUSPEND_PR;
}
if (R_FDL_ISTAT_SUSPEND_PR == g_fdl_str.iStat_enu)
{
g_fdl_str.spdResStatus_enu = (*tmpStat_penu);
(void)R_FDL_FCUFct_SwitchMode_Start (R_FCU_MODE_USER);
res = R_FDL_FCUFct_SwitchMode_Check();
/* Mode already switched */
if (R_FDL_OK == res)
{
(*tmpStat_penu) = R_FDL_SUSPENDED;
/* Backup variables for resume */
g_fdl_str.reqSuspend_pstr = g_fdl_str.reqInt_pstr;
g_fdl_str.iStat_enu = R_FDL_ISTAT_SUSPENDED;
}
/* Wait for mode switch confirmation */
else
{
(*tmpStat_penu) = R_FDL_BUSY;
g_fdl_str.opStatus_enu = R_FDL_OP_SUSPEND_SYNC_OFF;
}
g_fdl_str.spdMulOp_str.flashAdd_u32 = g_fdl_str.mulOp_str.flashAdd_u32;
g_fdl_str.spdMulOp_str.bufAdd_u32 = g_fdl_str.mulOp_str.bufAdd_u32;
g_fdl_str.spdMulOp_str.flashAddEnd_u32 = g_fdl_str.mulOp_str.flashAddEnd_u32;
g_fdl_str.spdMulOp_str.accessType_enu = g_fdl_str.mulOp_str.accessType_enu;
cont = R_FDL_FALSE;
}
return (cont);
} /* R_FDL_Handler_StatusCheckAndSuspendOnReady */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_Handler_MultiOperation
*********************************************************************************************************************/
/**
* Part of the R_FDL_Handler function.
*
* In case of multi-operations (erase multiple blocks or write multiple half words), after end
* of a single Flash erase/write Flash operation, the next operation is started.
*
* @param[in, out] tmpStat_penu - current operation status. Used to judge previous operation result
* and is updated in case of multi-operation requiring start of new
* Flash operation
* @return handler function flow may continue after this function or handler need to exit:
* - R_FDL_TRUE - continue handler
* - R_FDL_FALSE - exit handler
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
R_FDL_STATIC r_fdl_flag_t R_FDL_Handler_MultiOperation (r_fdl_status_t * tmpStat_penu)
{
r_fdl_flag_t cont;
uint32_t cnt;
r_fdl_command_t cmd;
cont = R_FDL_TRUE;
cmd = g_fdl_str.reqInt_pstr->command_enu;
/* Check if more data to handle:
- erase, write, blank check operation
- internal status = OK
- more data to erase/write */
if ( (R_FDL_OK == (*tmpStat_penu) )
&& (g_fdl_str.mulOp_str.flashAdd_u32 < g_fdl_str.mulOp_str.flashAddEnd_u32) )
{
/* Write command starts a new FACI write operation */
#if (defined ENABLE_CMD_WRITE16B)
if ( (R_FDL_CMD_WRITE == cmd) || (R_FDL_CMD_WRITE16B == cmd) ) /* PRQA S 0505 */
#else
if (R_FDL_CMD_WRITE == cmd)
#endif
{
#if (defined ENABLE_CMD_WRITE16B)
if (R_FDL_CMD_WRITE == cmd)
{
cnt = R_WRITE_SIZE;
}
else
{
cnt = R_WRITE_SIZE_16B;
}
#else
cnt = R_WRITE_SIZE;
#endif
(*tmpStat_penu) = R_FDL_FCUFct_StartWriteOperation (g_fdl_str.mulOp_str.bufAdd_u32,
g_fdl_str.mulOp_str.flashAdd_u32,
cnt,
g_fdl_str.mulOp_str.accessType_enu);
g_fdl_str.mulOp_str.flashAdd_u32 += cnt;
g_fdl_str.mulOp_str.bufAdd_u32 += cnt;
}
/* Erase command starts a new FACI erase operation */
else if (R_FDL_CMD_ERASE == cmd) /* PRQA S 0505 */
{
(*tmpStat_penu) = R_FDL_FCUFct_StartBCEraseOperation (g_fdl_str.mulOp_str.flashAdd_u32,
(g_fdl_str.mulOp_str.flashAdd_u32 + R_BLOCK_SIZE) - 1u,
R_FCU_CMD_ERASE,
g_fdl_str.mulOp_str.accessType_enu);
g_fdl_str.mulOp_str.flashAdd_u32 += R_BLOCK_SIZE;
}
/* Blank Check command (exceeding 4kB boundary) starts a new FACI blank check operation */
else
{
cnt = ( (g_fdl_str.mulOp_str.flashAddEnd_u32 + 1uL) - g_fdl_str.mulOp_str.flashAdd_u32);
/* Limit count to max */
R_FDL_IFct_CalcFOpUnitCnt_BC (&cnt, g_fdl_str.mulOp_str.flashAdd_u32);
(*tmpStat_penu) = R_FDL_FCUFct_StartBCEraseOperation (g_fdl_str.mulOp_str.flashAdd_u32,
( (g_fdl_str.mulOp_str.flashAdd_u32 + cnt) - 1u),
R_FCU_CMD_BLANKCHECK,
g_fdl_str.mulOp_str.accessType_enu);
g_fdl_str.mulOp_str.flashAdd_u32 += cnt;
}
/* In command execution end (OK or error) */
if (R_FDL_BUSY != (*tmpStat_penu) )
{
(void)R_FDL_FCUFct_SwitchMode_Start (R_FCU_MODE_USER);
/* Mode already switched */
if (R_FDL_BUSY == R_FDL_FCUFct_SwitchMode_Check() )
{
g_fdl_str.opStatus_enu = R_FDL_OP_END_SYNC_OFF;
/* save status, will be returned on mode switch confirmation */
g_fdl_str.opResult_enu = (*tmpStat_penu);
(*tmpStat_penu) = R_FDL_BUSY;
}
}
cont = R_FDL_FALSE;
}
return (cont);
} /* R_FDL_Handler_MultiOperation */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_Handler_OperationStates
*********************************************************************************************************************/
/**
* Part of the R_FDL_Handler function.
*
* This function checks if switch mode is performed.
* If yes, it executes different operations depending on internal operation status.
* Prepare environment is performed here also.
* If not, do nothing
*
* @param[in, out] tmpStat_penu - current operation status. Used to judge previous operation result
* and is updated in case of start of new Flash operation
*
* @return handler function flow may continue after this function or handler need to exit:
* - R_FDL_TRUE - continue handler
* - R_FDL_FALSE - exit handler
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
R_FDL_STATIC r_fdl_flag_t R_FDL_Handler_OperationStates (r_fdl_status_t * tmpStat_penu)
{
r_fdl_flag_t cont;
r_fdl_status_t res;
cont = R_FDL_TRUE;
if ( (R_FDL_OP_IDLE != g_fdl_str.opStatus_enu) &&
(R_FDL_OP_BUSY != g_fdl_str.opStatus_enu) )
{
(*tmpStat_penu) = R_FDL_FCUFct_SwitchMode_Check();
/* Mode switch passed */
if (R_FDL_OK == (*tmpStat_penu) )
{
/* Select current operation status */
switch (g_fdl_str.opStatus_enu)
{
/* Next step after mode switch confirmation for normal operations and prepare */
case R_FDL_OP_EXECUTE_SYNC_ON:
{
if (R_FDL_CMD_PREPARE_ENV == g_fdl_str.reqInt_pstr->command_enu)
{
res = R_FDL_FCUFct_ForcedStop();
(void)R_FDL_FCUFct_SwitchMode_Start (R_FCU_MODE_USER);
/* No timeout during forced stop processing */
if (R_FDL_OK == res)
{
g_fdl_str.opStatus_enu = R_FDL_OP_PREPARE_START;
}
else
{
g_fdl_str.opStatus_enu = R_FDL_OP_END_SYNC_OFF;
g_fdl_str.opResult_enu = R_FDL_ERR_INTERNAL;
}
cont = R_FDL_FALSE;
(*tmpStat_penu) = R_FDL_BUSY;
}
else
{
cont = R_FDL_UFct_FlashOpStart (g_fdl_str.reqInt_pstr, tmpStat_penu, R_FDL_FALSE);
}
break;
}
/* Prepare operation 1st state */
case R_FDL_OP_PREPARE_START:
{
/* Disable FCU error interrupt which will occur always during FCU initialization from power up */
R_FDL_FCUFct_Switch_FAEINT (R_FDL_FALSE);
/* Initialize the FCU code RAM */
(*tmpStat_penu) = R_FDL_FCUFct_InitRAM();
/* No timeout error during RAM initialization */
if (R_FDL_OK == (*tmpStat_penu) )
{
(*tmpStat_penu) = R_FDL_FCUFct_SwitchMode_Start (R_FCU_MODE_PE);
/* No protection error during mode switch */
if (R_FDL_OK == (*tmpStat_penu) )
{
(*tmpStat_penu) = R_FDL_BUSY;
g_fdl_str.opStatus_enu = R_FDL_OP_PREPARE_RST_FCU;
}
}
/* In error case we need to activate the FAEINT again as the operation will immediately finish */
if (R_FDL_BUSY != (*tmpStat_penu) )
{
R_FDL_FCUFct_Switch_FAEINT (R_FDL_TRUE);
}
cont = R_FDL_FALSE;
break;
}
/* Prepare operation 2nd state */
case R_FDL_OP_PREPARE_RST_FCU:
{
/* Reset FCU again to clear any possible ECC errors */
res = R_FDL_FCUFct_ForcedStop();
R_FDL_FCUFct_ClearStatus();
(void)R_FDL_FCUFct_SwitchMode_Start (R_FCU_MODE_USER);
/* Enable FCU error interrupt again, now we expect no more ECC error */
R_FDL_FCUFct_Switch_FAEINT (R_FDL_TRUE);
/* No timeout during forced stop processing */
if (R_FDL_OK == res)
{
g_fdl_str.opStatus_enu = R_FDL_OP_PREPARE_END;
}
else
{
g_fdl_str.opStatus_enu = R_FDL_OP_END_SYNC_OFF;
g_fdl_str.opResult_enu = R_FDL_ERR_INTERNAL;
}
(*tmpStat_penu) = R_FDL_BUSY;
cont = R_FDL_FALSE;
break;
}
/* Prepare operation 3rd state */
case R_FDL_OP_PREPARE_END:
{
(*tmpStat_penu) = R_FDL_FCUFct_VerifyChecksum();
/* Checksum check passed */
if (R_FDL_BUSY == (*tmpStat_penu) )
{
(*tmpStat_penu) = R_FDL_FCUFct_GetDFSize (&(g_fdl_str.dfSize_u32) );
#ifdef R_FDL_F1L_PATCH_DF_OVERSIZE
g_fdl_str.dfSize_u32 *= 2uL;
#endif
if (R_FDL_OK == (*tmpStat_penu) )
{
/* FDL pool size does not exceed Data FLash size */
if (g_fdl_str.RTCfg_pstr->fdlPoolSize_u16 <= (g_fdl_str.dfSize_u32 >> R_BLOCK_SIZE_2N) )
{
/* Configure the FCU frequency */
(*tmpStat_penu) = R_FDL_FCUFct_SetFrequency();
}
else
{
(*tmpStat_penu) = R_FDL_ERR_CONFIGURATION;
}
}
}
if (R_FDL_OK == (*tmpStat_penu) )
{
g_fdl_str.iStat_enu = R_FDL_ISTAT_NORMALOP;
}
cont = R_FDL_FALSE;
break;
}
/* Resume command execution (FACI resume) */
case R_FDL_OP_RESUME_SYNC_ON:
{
R_FDL_FCUFct_Resume();
g_fdl_str.opStatus_enu = R_FDL_OP_BUSY;
(*tmpStat_penu) = R_FDL_BUSY;
break;
}
/* Resume command execution (Start new operation) */
case R_FDL_OP_RESUME_MULTI_SYNC_ON:
{
g_fdl_str.opStatus_enu = R_FDL_OP_BUSY;
(*tmpStat_penu) = R_FDL_BUSY;
break;
}
/* Command execution end */
case R_FDL_OP_END_SYNC_OFF:
{
g_fdl_str.opStatus_enu = R_FDL_OP_IDLE;
(*tmpStat_penu) = g_fdl_str.opResult_enu;
cont = R_FDL_FALSE;
break;
}
/* suspend processing end */
case R_FDL_OP_SUSPEND_SYNC_OFF:
{
(*tmpStat_penu) = R_FDL_SUSPENDED;
/* Backup variables for resume */
g_fdl_str.reqSuspend_pstr = g_fdl_str.reqInt_pstr;
g_fdl_str.iStat_enu = R_FDL_ISTAT_SUSPENDED;
cont = R_FDL_FALSE;
break;
}
default:
{
/* Nothing to do */
break;
}
} /* switch */
}
else
{
cont = R_FDL_FALSE;
}
}
return (cont);
} /* R_FDL_Handler_OperationStates */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_Handler
*********************************************************************************************************************/
/**
* User interface function:
* This function forwards an initiated Flash operation until it is finished. At operation end the
* result is set in the request structure.
* After initiation by R_FDL_Execute, the function R_FDL_Handler need to be called regularly to finish
* the operation.
* @param[in,out] -
* @return ---
*
* The function returns the operation result in the status variable, passed to
* the R_FDL_Execute variable (request.status_enu)
*/
/*********************************************************************************************************************/
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 1.2 (QAC message 0505)
* Reason: QAC claims referencing a possibly undefined pointer.
* Verification: Reviewed, that this is not possible. The pointer is always defined
*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
void R_FDL_Handler (void) /* PRQA S 1503 */
{
r_fdl_flag_t contHdrFct;
r_fdl_status_t tmpStatus;
r_fdl_status_t res;
tmpStatus = R_FDL_BUSY;
/* Check if the handler has something to do, block on not initialized library and on StandBy processing */
if ( (R_FDL_TRUE == R_FDL_UFct_StateNotStandBy() ) &&
( (R_FDL_REQUEST_POINTER_UNDEFINED != g_fdl_str.reqInt_pstr) ||
(R_FDL_TRUE == g_fdl_str.spdResRequest_enu) ||
(R_FDL_TRUE == g_fdl_str.cancelRequest_enu) ) )
{
/* Cancel Request management */
contHdrFct = R_FDL_Handler_CancelReq (&tmpStatus);
/* continue handler execution: Suspend handling (suspend possible, part 1)*/
if (R_FDL_TRUE == contHdrFct)
{
contHdrFct = R_FDL_Handler_BusyAndSuspendPossible();
}
/* continue handler execution: Resume handling */
if (R_FDL_TRUE == contHdrFct)
{
contHdrFct = R_FDL_Handler_ChkResume (&tmpStatus);
}
/* continue handler execution: command processing execution */
if (R_FDL_TRUE == contHdrFct)
{
contHdrFct = R_FDL_Handler_OperationStates (&tmpStatus);
}
/* continue handler execution: check if the FCU is busy */
if (R_FDL_TRUE == contHdrFct)
{
contHdrFct = R_FDL_FCUFct_ChkReady();
}
/* continue handler execution: Fatal error evaluation */
if (R_FDL_TRUE == contHdrFct)
{
contHdrFct = R_FDL_Handler_ReactOnFatalErrors (&tmpStatus);
}
/* continue handler execution: judge operation status and do suspend handling part 2 */
if (R_FDL_TRUE == contHdrFct)
{
contHdrFct = R_FDL_Handler_StatusCheckAndSuspendOnReady (&tmpStatus);
}
/* continue handler execution: multi operation (Write/Erase) state machine */
if (R_FDL_TRUE == contHdrFct)
{
contHdrFct = R_FDL_Handler_MultiOperation (&tmpStatus);
}
/* continue handler execution: normal operation end */
if (R_FDL_TRUE == contHdrFct)
{
(void)R_FDL_FCUFct_SwitchMode_Start (R_FCU_MODE_USER);
res = R_FDL_FCUFct_SwitchMode_Check();
if (R_FDL_BUSY == res)
{
g_fdl_str.opStatus_enu = R_FDL_OP_END_SYNC_OFF;
/* save status, will be returned on mode switch confirmation */
g_fdl_str.opResult_enu = tmpStatus;
tmpStatus = R_FDL_BUSY;
}
}
/* Operation end, return status to user */
if (R_FDL_BUSY != tmpStatus)
{
R_FDL_UFct_EndCurrentOperation (tmpStatus);
}
#ifdef PATCH_TO_SIMULATE_ERRORS
tstData_str.simCntHdr_u32++;
#endif
}
} /* R_FDL_Handler */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_GetVersionString
*********************************************************************************************************************/
/**
* User interface function:
* Returns the pointer to the library version string, stores in the library code section.
*
* @param[in,out] -
* @return Pointer to the version string in Flash
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_CONST
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
const uint8_t *R_FDL_GetVersionString (void) /* PRQA S 1503 */
{
static const uint8_t r_fdl_vStr[] = R_FDL_VERSION_STRING;
return (&r_fdl_vStr[0]);
}
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
#define R_FDL_STOP_SEC_CONST
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_SuspendRequest
*********************************************************************************************************************/
/**
* User interface function:
* Sets the suspend request flag for the write or erase operation
*
* Note:
* The operation is not immediately suspended. Suspend handling is controlled by R_FDL_Handler.
* The suspend status is returned by the status variable of the request structure (Set in
* R_FDL_Handler).
*
* Suspend request handling:
* - Reject if
* - we have no active Flash operation
* - we have already a Flash operation suspended
* - we have a cancel request
* - Reset resume request if set (then we have a not yet handled resume request)
* - Set suspend request if we have an operation ongoing and we are not already in suspend
* processing
*
* @param[in,out] -
* @return result of the suspend request
* - R_FDL_OK - Request accepted
* - R_FDL_ERR_REJECTED - Request rejected
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
r_fdl_status_t R_FDL_SuspendRequest (void) /* PRQA S 1503 */
{
r_fdl_status_t ret;
ret = R_FDL_ERR_REJECTED;
/* Block on:
- not initialized library
- StandBy processing */
if (R_FDL_TRUE == R_FDL_UFct_StateNotStandBy() )
{
/* Set the request flag only if we are busy and not in suspend state or suspend processing */
if ( (R_FDL_REQUEST_POINTER_UNDEFINED != g_fdl_str.reqInt_pstr)
&& (R_FDL_REQUEST_POINTER_UNDEFINED == g_fdl_str.reqSuspend_pstr)
&& (R_FDL_ISTAT_NORMALOP == g_fdl_str.iStat_enu)
&& (R_FDL_FALSE == g_fdl_str.cancelRequest_enu) )
{
ret = R_FDL_OK;
g_fdl_str.spdSpdRequest_enu = R_FDL_TRUE;
}
}
return (ret);
} /* R_FDL_SuspendRequest */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_ResumeRequest
*********************************************************************************************************************/
/**
* User interface function:
* Sets the resume request flag for the write or erase operation
*
* Note:
* The operation is not immediately resumed. Resume handling is controlled by R_FDL_Handler.
* The status is returned by the status variable of the request structure (Set in
* R_FDL_Handler).
*
* Resume request handling:
* - Reset suspend request if set (then we have a not yet handled suspend request)
* - Set resume request if we have a suspended operation (reqSuspend_pstr defined)
* and we have not already a resume request
* - Reject all other conditions
*
* @param[in,out] -
* @return result of the resume request
* - R_FDL_OK - Request accepted
* - R_FDL_ERR_REJECTED - Request rejected
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
r_fdl_status_t R_FDL_ResumeRequest (void) /* PRQA S 1503 */
{
r_fdl_status_t ret;
ret = R_FDL_OK;
/* Block on not initialized library and on StandBy processing */
if (R_FDL_TRUE == R_FDL_UFct_StateNotStandBy() )
{
/* Set the request flag only if we are already suspended */
if ( (R_FDL_ISTAT_SUSPENDED == g_fdl_str.iStat_enu)
&& (R_FDL_FALSE == g_fdl_str.cancelRequest_enu) )
{
g_fdl_str.spdResRequest_enu = R_FDL_TRUE;
}
else
{
ret = R_FDL_ERR_REJECTED;
}
}
else
{
ret = R_FDL_ERR_REJECTED;
}
return (ret);
} /* R_FDL_ResumeRequest */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_Standby
*********************************************************************************************************************/
/**
* User interface function:
* Prepares the HW for fast standby entry:
* - on write end erase
* - blank check is not suspendable, here the function is without effect
*
* This function can be called asynchronous (e.g. interrupt function) and so need to take
* care of the current hardware status in order to restore it later on during wakeup
*
* Note:
* the function need to be called continuously until the result is != R_FDL_BUSY
*
* @param[in,out] -
* @return result of the standby operation
* - R_FDL_OK - Flash hardware is in standby or ready (no more Flash operation)
* - R_FDL_BUSY - Flash hardware is still busy. Repeat calling the function
* - R_FDL_ERR_REJECTED - Rejected, as the library is not initialized
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
r_fdl_status_t R_FDL_StandBy (void) /* PRQA S 1503 */
{
r_fdl_status_t ret;
/* Allow execution in each initialized state except StandBy and Init */
if ( ( (R_FDL_TRUE == R_FDL_UFct_StateNotStandBy() ) &&
(R_FDL_ISTAT_INIT != g_fdl_str.iStat_enu) )
|| (R_FDL_ISTAT_STANDBY_PR == g_fdl_str.iStat_enu) )
{
/* On Standby processing start, backup the internal Status */
if (R_FDL_ISTAT_STANDBY_PR != g_fdl_str.iStat_enu)
{
g_fdl_str.stByIStatBackUp_enu = g_fdl_str.iStat_enu;
/* Set to standby processing. By that, other EEL operations are blocked */
g_fdl_str.iStat_enu = R_FDL_ISTAT_STANDBY_PR;
}
/* only operate standby, if any Flash operation is ongoing */
if (R_FDL_FALSE == R_FDL_FCUFct_ChkReady() )
{
/* hardware is still busy */
ret = R_FDL_BUSY;
/* only operate standby if the Flash operation is suspendable
additionally check if we are not already suspended or in suspend
processing */
if (R_FDL_TRUE == R_FDL_FCUFct_ChkSuspendable() )
{
R_FDL_FCUFct_Suspend();
}
}
/* hardware is no longer busy, set library into standby */
else
{
g_fdl_str.iStat_enu = R_FDL_ISTAT_STANDBY;
ret = R_FDL_OK;
}
}
else
{
/* library is not initialized */
ret = R_FDL_ERR_REJECTED;
}
return (ret);
} /* R_FDL_StandBy */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_WakeUp
*********************************************************************************************************************/
/**
* User interface function:
* Wake up the hardware from standby
*
* @param[in,out] -
* @return result of the initialization check
* - R_FDL_OK - Wakeup succeeded
* - R_FDL_ERR_REJECTED - Rejected, as the library is not initialized
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
r_fdl_status_t R_FDL_WakeUp (void) /* PRQA S 1503 */
{
r_fdl_status_t ret;
/* We can only wakeup if we have been in standby before */
if (R_FDL_ISTAT_STANDBY == g_fdl_str.iStat_enu)
{
ret = R_FDL_OK;
g_fdl_str.iStat_enu = g_fdl_str.stByIStatBackUp_enu;
/* check if we need to wakeup */
if (R_FDL_TRUE == R_FDL_FCUFct_ResumeChkNeed() )
{
R_FDL_FCUFct_Resume();
}
}
else
{
ret = R_FDL_ERR_REJECTED;
}
return (ret);
} /* R_FDL_WakeUp */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_CancelRequest
*********************************************************************************************************************/
/**
* User interface function:
* Sets the cancel request flag for an ongoing operation (exception Prepare environment cmd)
*
* Note:
* The operation is not immediately cancelled. Cancel handling is controlled by R_FDL_Handler.
* The status is returned by the status variable of the request structure (Set in
* R_FDL_Handler).
*
* Cancel request handling:
* - Set cancel request if we do not have a standby operation
* and we have not already a cancel request
* - Reject all other conditions
*
* @param[in,out] -
* @return result of the cancel request
* - R_FDL_OK - Request accepted
* - R_FDL_ERR_REJECTED - Request rejected
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
r_fdl_status_t R_FDL_CancelRequest (void) /* PRQA S 1503 */
{
r_fdl_status_t ret;
ret = R_FDL_OK;
/* Block on not initialized library and on StandBy processing */
if ( (R_FDL_TRUE == R_FDL_UFct_StateNotStandBy() ) &&
(R_FDL_ISTAT_INIT != g_fdl_str.iStat_enu) &&
(R_FDL_FALSE == g_fdl_str.cancelRequest_enu) )
{
/* Library is in suspended state, no operation on-going */
if ( (R_FDL_ISTAT_SUSPENDED == g_fdl_str.iStat_enu) &&
(R_FDL_REQUEST_POINTER_UNDEFINED == g_fdl_str.reqInt_pstr) )
{
ret = R_FDL_FCUFct_SwitchMode_Start (R_FCU_MODE_PE);
}
/* No operation ongoing */
else if ( (R_FDL_ISTAT_NORMALOP == g_fdl_str.iStat_enu) &&
(R_FDL_REQUEST_POINTER_UNDEFINED == g_fdl_str.reqInt_pstr) )
{
ret = R_FDL_ERR_REJECTED;
}
else
{
/* Nothing to do, added to fix QAC warning message 2004 */
}
/* All conditions fulfilled for cancel */
if (R_FDL_OK == ret)
{
g_fdl_str.cancelRequest_enu = R_FDL_TRUE;
}
}
else
{
ret = R_FDL_ERR_REJECTED;
}
return (ret);
} /* R_FDL_CancelRequest */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_UFct_FlashOpStart
*********************************************************************************************************************/
/**
* Extract information required for a Flash operation and call the function which starts the operation.
*
* @param[in] request_pstr - pointer to the operation request structure
* @param[out] tmpStat_penu - Status return value. Is set to operation result. Possible values:
* - R_FDL_BUSY
* - R_FDL_ERR_PARAMETER
* - R_FDL_ERR_PROTECTION
* - R_FDL_OK (Read operation)
* - R_FDL_ERR_ECC_SED (Read operation)
* - R_FDL_ERR_ECC_DED (Read operation)
* @param[in] isCalledFromExecute_enu - flag to distinguish if the function is called from:
* - R_FDL_Execute: value R_FDL_TRUE
* - R_FDL_Handler: value R_FDL_FALSE
*
* @return handler function flow may continue after this function or handler need to exit:
* - R_FDL_TRUE - continue handler
* - R_FDL_FALSE - exit handler
* In case the function is called from R_FDL_Execute, the return value can be ignored.
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
R_FDL_STATIC r_fdl_flag_t R_FDL_UFct_FlashOpStart (r_fdl_request_t * request_pstr,
r_fdl_status_t * tmpStat_penu,
r_fdl_flag_t isCalledFromExecute_enu)
{
uint32_t addFlash;
uint32_t cntTotal;
uint32_t addBuf;
uint32_t granularityCurOp;
uint32_t cntCurOp;
uint32_t addEndCurOp;
r_fdl_command_t cmd;
r_fdl_accessType_t accType;
r_fdl_flag_t cont;
uint8_t fcuCmd;
addFlash = (request_pstr->idx_u32);
cntTotal = (request_pstr->cnt_u16);
cmd = (request_pstr->command_enu);
accType = (request_pstr->accessType_enu);
addBuf = (request_pstr->bufAddr_u32);
/* granularityCurOp has the default value for all commands except WRITE_16B */
granularityCurOp = R_WRITE_SIZE;
cont = R_FDL_TRUE;
(*tmpStat_penu) = R_FDL_BUSY;
if (R_FDL_CMD_ERASE == cmd)
{
addFlash <<= R_BLOCK_SIZE_2N;
cntTotal <<= R_BLOCK_SIZE_2N;
/* granularityCurOp has the default value */
cntCurOp = (1 << R_BLOCK_SIZE_2N);
/* Set buffer address to a valid address */
addBuf = 0x00000001uL;
fcuCmd = R_FCU_CMD_ERASE;
}
else if (R_FDL_CMD_BLANKCHECK == cmd)
{
cntTotal *= R_WRITE_SIZE;
cntCurOp = cntTotal;
/* Limit count to max */
R_FDL_IFct_CalcFOpUnitCnt_BC (&cntCurOp, addFlash);
/* Set buffer address to a valid address */
addBuf = 0x00000001uL;
fcuCmd = R_FCU_CMD_BLANKCHECK;
}
/* write 4 bytes (1 words) at once */
else if (R_FDL_CMD_WRITE == cmd)
{
cntCurOp = R_WRITE_SIZE;
cntTotal *= R_WRITE_SIZE;
fcuCmd = R_FCU_CMD_WRITE;
}
#if (defined ENABLE_CMD_WRITE16B)
/* write 16 bytes (4 words) at once */
else if (R_FDL_CMD_WRITE16B == cmd)
{
cntCurOp = R_WRITE_SIZE_16B;
cntTotal *= R_WRITE_SIZE_16B;
granularityCurOp = cntCurOp;
fcuCmd = R_FCU_CMD_WRITE;
}
#endif
/* Read command */
else
{
cntTotal *= R_WRITE_SIZE;
cntCurOp = cntTotal;
/* for the read cmd there is not equivalent FCU cmd, it is initialized here to fix QAC error message */
fcuCmd = 0x00;
}
addEndCurOp = (addFlash + cntCurOp) - 1uL;
/* Check against invalid buffer address (R_FDL_CMD_WRITE, R_FDL_CMD_WRITE16B, R_FDL_CMD_READ)
- Only if function is called by R_FDL_Execute */
if (R_FDL_TRUE == isCalledFromExecute_enu)
{
if (R_FDL_NULL == addBuf)
{
(*tmpStat_penu) = R_FDL_ERR_PARAMETER;
}
else
{
(*tmpStat_penu) = R_FDL_IFct_ChkAccessBoundaries (addFlash, cntTotal, accType, granularityCurOp);
}
/* Reset flag; it is updated later on in case the switch mode to PE is performed correctly */
cont = R_FDL_FALSE;
}
if (R_FDL_BUSY == (*tmpStat_penu) )
{
/* Read command is treated only in R_FDL_Execute,
no need to check given parameter isCalledFromExecute_enu */
if (R_FDL_CMD_READ == cmd)
{
/* user destination buffer must be 4 bytes aligned */
if (0 == (addBuf & R_U32_ALIGNED) )
{
(*tmpStat_penu) = R_FDL_FCUFct_ReadOperation ( (volatile uint32_t *)(&addFlash),
addBuf,
(cntTotal / R_WRITE_SIZE) );
request_pstr->idx_u32 = addFlash; /* Store possible fail address to request structure */
}
else
{
(*tmpStat_penu) = R_FDL_ERR_PARAMETER;
}
}
/* all commands except Read */
else
{
/* Switch mode only required once */
if (R_FDL_TRUE == isCalledFromExecute_enu)
{
(*tmpStat_penu) = R_FDL_FCUFct_SwitchMode_Start (R_FCU_MODE_PE);
if (R_FDL_OK == (*tmpStat_penu) )
{
(*tmpStat_penu) = R_FDL_FCUFct_SwitchMode_Check();
if (R_FDL_OK == (*tmpStat_penu) )
{
cont = R_FDL_TRUE;
}
else
{
g_fdl_str.opStatus_enu = R_FDL_OP_EXECUTE_SYNC_ON;
}
}
}
/* continue if mode switch passed (either immediately after the mode switch
start or if the function is later on called by the handler */
if (R_FDL_TRUE == cont)
{
if ( (R_FDL_CMD_ERASE == cmd) || (R_FDL_CMD_BLANKCHECK == cmd) )
{
(*tmpStat_penu) = R_FDL_FCUFct_StartBCEraseOperation (addFlash, addEndCurOp, fcuCmd, accType);
}
/* Write command */
else
{
(*tmpStat_penu) = R_FDL_FCUFct_StartWriteOperation (addBuf, addFlash, cntCurOp, accType);
g_fdl_str.mulOp_str.bufAdd_u32 = addBuf + cntCurOp; /* Next Source Address */
}
/* command can be executed */
if (R_FDL_BUSY == (*tmpStat_penu) )
{
g_fdl_str.opStatus_enu = R_FDL_OP_BUSY;
/* Prepare for multi-word write */
g_fdl_str.mulOp_str.flashAdd_u32 = addEndCurOp + 1uL;
g_fdl_str.mulOp_str.flashAddEnd_u32 = (addFlash + cntTotal) - 1uL; /* Source End Address */
g_fdl_str.mulOp_str.accessType_enu = accType;
}
/* error --> switch back to user mode */
else
{
(void)R_FDL_FCUFct_SwitchMode_Start (R_FCU_MODE_USER);
/* save operation status and return it after switch mode confirmation */
g_fdl_str.opResult_enu = (*tmpStat_penu);
g_fdl_str.opStatus_enu = R_FDL_OP_END_SYNC_OFF;
cont = R_FDL_FALSE;
(*tmpStat_penu) = R_FDL_BUSY;
}
}
}
}
return (cont);
} /* R_FDL_UFct_FlashOpStart */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_UFct_EndCurrentOperation
*********************************************************************************************************************/
/**
* At the end of a Flash operation, this function updates the request structure elements and
* resets the library internal pointer to this structure.
*
* @param[in] ret_enu - status return value
* @return ---
*
* The function modifies the global structure g_fdl_str.reqInt_pstr to set the operation
* status
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
R_FDL_STATIC void R_FDL_UFct_EndCurrentOperation (r_fdl_status_t ret_enu)
{
(g_fdl_str.reqInt_pstr)->status_enu = ret_enu;
/* For Blank Check, return fail address too */
if ( (R_FDL_CMD_BLANKCHECK == (g_fdl_str.reqInt_pstr)->command_enu) && (R_FDL_ERR_BLANKCHECK == ret_enu) )
{
(g_fdl_str.reqInt_pstr)->idx_u32 = g_fdl_str.opFailAddr_u32;
}
(g_fdl_str.reqInt_pstr)->accessType_enu = R_FDL_ACCESS_NONE;
(g_fdl_str.reqInt_pstr) = R_FDL_REQUEST_POINTER_UNDEFINED;
g_fdl_str.opStatus_enu = R_FDL_OP_IDLE;
/* In case of internal error enforce re-initialization. No more command execution will be allowed */
if (R_FDL_ERR_INTERNAL == ret_enu)
{
g_fdl_str.iStat_enu = R_FDL_ISTAT_NOINIT;
}
} /* R_FDL_UFct_EndCurrentOperation */
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_UFct_StateNotStandBy
*********************************************************************************************************************/
/**
* Check if the library is initialized and not in StandBy or StandBy processing
*
* @param[in,out] -
* @return - R_FDL_TRUE Library is initialized
* - R_FDL_FALSE Library is not initialized
*/
/*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
R_FDL_STATIC r_fdl_flag_t R_FDL_UFct_StateNotStandBy (void)
{
r_fdl_flag_t ret;
/* Any states except StandBy related states or uninitialized state */
if ( (R_FDL_ISTAT_NORMALOP == g_fdl_str.iStat_enu)
|| (R_FDL_ISTAT_INIT == g_fdl_str.iStat_enu)
|| ( (R_FDL_ISTAT_SUSPEND_PR == g_fdl_str.iStat_enu)
|| (R_FDL_ISTAT_SUSPENDED == g_fdl_str.iStat_enu) ) )
{
ret = R_FDL_TRUE;
}
/* StandBy related state or uninitialized state */
else
{
ret = R_FDL_FALSE;
}
return (ret);
} /* R_FDL_UFct_StateNotStandBy */
/*********************************************************************************************************************/
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************/
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_OFF 0292
#endif
/*********************************************************************************************************************
* Library : Data Flash Access Library for Renesas RH850 devices
*
* File Name : $Source: r_fdl_user_if_init.c $
* Lib. Version : $RH850_FDL_LIB_VERSION_T01: V2.11 $
* Mod. Revision : $Revision: 1.7 $
* Mod. Date : $Date: 2016/06/01 12:39:22JST $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : Source code for FDL initialization
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2015-2016 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_ON 0292
#endif
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 3.1 (QAC message 0292)
* Reason: To support automatic insertion of revision, module name etc. by the source revision control system
* it is necessary to violate the rule, because the system uses non basic characters as placeholders.
* Verification: The placeholders are used in commentaries only. Therefore rule violation cannot influence code
* compilation.
*********************************************************************************************************************/
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 19.1 (QAC message 5087)
* Reason: The section mapping concept (Mapping code, constants and data to specific linker sections) bases on
* a central include file containing all section mapping defines and pragmas. This need to be included
* multiple times within the code. The file itself only contains those defines and pragmas.
* Verification: This is the standard concept defined for AUTOSAR implementations
*********************************************************************************************************************/
/*********************************************************************************************************************
* FDL header files include
*********************************************************************************************************************/
#include "r_typedefs.h"
#include "r_fdl.h"
/*********************************************************************************************************************
* Global function prototypes
*********************************************************************************************************************/
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 8.8 (QAC message 3447)
* Reason: Library is delivered as source code and as a precompiled object.
* The file r_fdl_user_if_init.c is not included on generation of the precompiled object.
* It is delivered as a separate file and cannot include any other header files, except the
* defined interface header files. The function is a library internal function and its declaration
* is not part of the interface header files.
* Verification: -
*********************************************************************************************************************/
extern r_fdl_status_t R_FDL_InitVariables (const r_fdl_descriptor_t * descriptor_pstr); /* PRQA S 3447 */
/*********************************************************************************************************************
* FDL internal section mapping definitions
*********************************************************************************************************************/
#define R_FDL_START_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************
* Function name: R_FDL_Init
*********************************************************************************************************************/
/**
* User interface function:
* This function initializes the FDL. It must be called before any execution of a FDL function.
* Sequence:
* - Call the function to initialize the library RAM and do parameter checks
* If compatibility mode is used then:
* - Call the function to initialize the FCU RAM
* - Call the function to set the frequency information with frequency check
* - Frequency is within reasonable range between R_FCU_FMIN and R_FCU_FMAX
*
* In error case the library is set to not initialized (R_FDL_ISTAT_NOINIT)
*
* @param[in] descriptor_pstr - Pointer to the FDL descriptor structure
* @return Initialization status when returned from function call:
* - R_FDL_OK - Initialization was successful
* - R_FDL_ERR_CONFIGURATION - FDL configuration parameter error
* If compatibility mode is used then following error codes may be returned:
* - R_FDL_ERR_PROTECTION - Programming hardware reset was prohibited
* - R_FDL_ERR_INTERNAL - Internal (HW) error during HW initialization
*/
/*********************************************************************************************************************/
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 14.1 (QAC message 1503)
* Reason: This function is not used within the library, it is only used by the user
* application.
* Verification: This function is part of the library API and therefore essential on the one hand.
* On the other hand the QAC warning is correct, because this function is never
* called within the library. To solve this dilemma it is necessary and suitable
* to disable the message.
*********************************************************************************************************************/
#ifdef R_FDL_LIB_V1_COMPATIBILITY
r_fdl_status_t R_FDL_Init (const r_fdl_descriptor_t * descriptor_pstr) /* PRQA S 1503 */
{
r_fdl_status_t ret;
r_fdl_request_t request;
ret = R_FDL_InitVariables (descriptor_pstr);
/* Init_Variables already does some configuration checks */
if (R_FDL_OK == ret)
{
request.command_enu = R_FDL_CMD_PREPARE_ENV;
R_FDL_Execute (&request);
while (R_FDL_BUSY == request.status_enu)
{
R_FDL_Handler ();
}
ret = request.status_enu;
}
return (ret);
} /* R_FDL_Init */
#else
r_fdl_status_t R_FDL_Init (const r_fdl_descriptor_t * descriptor_pstr) /* PRQA S 1503 */
{
r_fdl_status_t ret;
ret = R_FDL_InitVariables (descriptor_pstr);
return (ret);
} /* R_FDL_Init */
#endif /* ifdef R_FDL_LIB_V1_COMPATIBILITY */
/*********************************************************************************************************************/
#define R_FDL_STOP_SEC_PUBLIC_CODE
#include "r_fdl_mem_map.h" /* PRQA S 5087 */
/*********************************************************************************************************************/
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_OFF 0292
#endif
/*********************************************************************************************************************
* Library : Data Flash Access Library for Renesas RH850 devices
*
* File Name : $Source: r_fdl.h $
* Lib. Version : $RH850_FDL_LIB_VERSION_T01: V2.11 $
* Mod. Revision : $Revision: 1.12 $
* Mod. Date : $Date: 2016/06/01 12:39:16JST $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : User interface function prototypes
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2015-2016 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_ON 0292
#endif
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 3.1 (QAC message 0292)
* Reason: To support automatic insertion of revision, module name etc. by the source revision control system
* it is necessary to violate the rule, because the system uses non basic characters as placeholders.
* Verification: The placeholders are used in commentaries only. Therefore rule violation cannot influence code
* compilation.
*********************************************************************************************************************/
#ifndef R_FDL_H
#define R_FDL_H
/*********************************************************************************************************************
* Global compiler definitions
*********************************************************************************************************************/
#define R_FDL_COMP_GHS 1
#define R_FDL_COMP_IAR 2
#define R_FDL_COMP_REC 3
#if defined (__IAR_SYSTEMS_ASM__)
#define R_FDL_COMPILER R_FDL_COMP_IAR
#elif defined (__IAR_SYSTEMS_ICC__)
#define R_FDL_COMPILER R_FDL_COMP_IAR
#elif defined (__v850e3v5__)
#define R_FDL_COMPILER R_FDL_COMP_REC
#else /*GHS */
#define R_FDL_COMPILER R_FDL_COMP_GHS
#endif
/*********************************************************************************************************************
* Include list
*********************************************************************************************************************/
#include "fdl_cfg.h"
#include "r_fdl_types.h"
#ifdef R_FDL_USERIF_C
#define R_FDL_EXTERN
#else
#define R_FDL_EXTERN extern
#endif
/*********************************************************************************************************************
* Global function prototypes
*********************************************************************************************************************/
/* FDL initialization function */
R_FDL_EXTERN r_fdl_status_t R_FDL_Init (const r_fdl_descriptor_t * descriptor_pstr);
/* Flash operation initiation */
R_FDL_EXTERN void R_FDL_Execute (r_fdl_request_t * request_pstr);
/* Flash operation forwarding and status check */
R_FDL_EXTERN void R_FDL_Handler (void);
/* Flash operation suspend request */
R_FDL_EXTERN r_fdl_status_t R_FDL_SuspendRequest (void);
/* Flash operation resume request after suspend */
R_FDL_EXTERN r_fdl_status_t R_FDL_ResumeRequest (void);
/* Asynchronous function to prepare FDL for device power save modes */
R_FDL_EXTERN r_fdl_status_t R_FDL_StandBy (void);
/* Asynchronous function to resume FDL after leaving device power save modes */
R_FDL_EXTERN r_fdl_status_t R_FDL_WakeUp (void);
/* Flash operation cancel request */
R_FDL_EXTERN r_fdl_status_t R_FDL_CancelRequest (void);
/* Return of FDL library version string */
R_FDL_EXTERN const uint8_t * R_FDL_GetVersionString (void);
/*********************************************************************************************************************/
#endif /* ifndef R_FDL_H */
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_OFF 0292
#endif
/*********************************************************************************************************************
* Library : Data Flash Access Library for Renesas RH850 devices
*
* File Name : $Source: r_fdl_mem_map.h $
* Lib. Version : $RH850_FDL_LIB_VERSION_T01: V2.11 $
* Mod. Revision : $Revision: 1.11 $
* Mod. Date : $Date: 2016/06/01 12:39:18JST $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : FDL section mapping definitions
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2015-2016 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_ON 0292
#endif
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 3.1 (QAC message 0292)
* Reason: To support automatic insertion of revision, module name etc. by the source revision control system
* it is necessary to violate the rule, because the system uses non basic characters as placeholders.
* Verification: The placeholders are used in commentars only. Therefore rule violation cannot influency code
* compilation.
*********************************************************************************************************************/
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 19.6 (QAC message 0841), 19.15 (QAC message 0883)
* Reason: The section mapping concept (Mapping code, constants and data to specific linker sections) bases on
* a central include file containing all section mapping defines and pragmas. This need to be included
* multiple times within the code. The file itself only contains those defines, pragmas and checks
* including #undef to ensure correct file usage
* Verification: This is the standard concept defined for AUTOSAR implementations
*********************************************************************************************************************/
/*********************************************************************************************************************
* Global compiler definitions
*********************************************************************************************************************/
#ifdef AUTOSAR_IMPLEMENTATION
#if defined R_FDL_START_SEC_PUBLIC_CODE
#define FDL_START_SEC_PUBLIC_CODE /* PRQA S 0883 */
#elif defined R_FDL_STOP_SEC_PUBLIC_CODE
#define FDL_STOP_SEC_PUBLIC_CODE
#elif defined R_FDL_START_SEC_CONST
#define FDL_START_SEC_CONST_UNSPECIFIED
#elif defined R_FDL_STOP_SEC_CONST
#define FDL_STOP_SEC_CONST_UNSPECIFIED
#elif defined R_FDL_START_SEC_VAR
#define FDL_START_SEC_VAR_UNSPECIFIED
#elif defined R_FDL_STOP_SEC_VAR
#define FDL_STOP_SEC_VAR_UNSPECIFIED
#else
#error "r_fdl_mem_map.h: No valid section define found"
#endif
#include "MemMap.h"
#else
#if defined R_FDL_START_SEC_PUBLIC_CODE
#undef R_FDL_START_SEC_PUBLIC_CODE /* PRQA S 0841 */
#if R_FDL_COMPILER == R_FDL_COMP_GHS
#pragma ghs section text=".R_FDL_Text"
#elif R_FDL_COMPILER == R_FDL_COMP_IAR
#pragma location = "R_FDL_Text"
#elif R_FDL_COMPILER == R_FDL_COMP_REC
#pragma section text "R_FDL_Text"
#endif
#elif defined R_FDL_STOP_SEC_PUBLIC_CODE
#undef R_FDL_STOP_SEC_PUBLIC_CODE /* PRQA S 0841 */
#if R_FDL_COMPILER == R_FDL_COMP_GHS
#pragma ghs section text=default
#elif R_FDL_COMPILER == R_FDL_COMP_IAR
/* location only for one function, so no default required */
#elif R_FDL_COMPILER == R_FDL_COMP_REC
#pragma section default
#endif
#elif defined R_FDL_START_SEC_CONST
#undef R_FDL_START_SEC_CONST /* PRQA S 0841 */
#if R_FDL_COMPILER == R_FDL_COMP_GHS
#pragma ghs startdata
#pragma ghs section rodata=".R_FDL_Const"
#elif R_FDL_COMPILER == R_FDL_COMP_IAR
#pragma constseg = "R_FDL_Const"
#elif R_FDL_COMPILER == R_FDL_COMP_REC
#pragma section const "R_FDL_Const"
#endif
#elif defined R_FDL_STOP_SEC_CONST
#undef R_FDL_STOP_SEC_CONST /* PRQA S 0841 */
#if R_FDL_COMPILER == R_FDL_COMP_GHS
#pragma ghs section rodata=default
#pragma ghs enddata
#elif R_FDL_COMPILER == R_FDL_COMP_IAR
#pragma constseg = default
#elif R_FDL_COMPILER == R_FDL_COMP_REC
#pragma section default
#endif
#elif defined R_FDL_START_SEC_VAR
#undef R_FDL_START_SEC_VAR /* PRQA S 0841 */
#if R_FDL_COMPILER == R_FDL_COMP_GHS
#pragma ghs startdata
#pragma ghs section bss = ".R_FDL_Data"
#elif R_FDL_COMPILER == R_FDL_COMP_IAR
#pragma dataseg = R_FDL_Data
#elif R_FDL_COMPILER == R_FDL_COMP_REC
#pragma section r0_disp32 "R_FDL_Data"
#endif
#elif defined R_FDL_STOP_SEC_VAR
#undef R_FDL_STOP_SEC_VAR /* PRQA S 0841 */
#if R_FDL_COMPILER == R_FDL_COMP_GHS
#pragma ghs section bss = default
#pragma ghs enddata
#elif R_FDL_COMPILER == R_FDL_COMP_IAR
#pragma dataseg = default
#elif R_FDL_COMPILER == R_FDL_COMP_REC
#pragma section default
#endif
#elif defined R_FDL_START_SEC_CODERAM
#undef R_FDL_START_SEC_CODERAM /* PRQA S 0841 */
#if R_FDL_COMPILER == R_FDL_COMP_GHS
#pragma ghs startdata
#pragma ghs section bss = ".R_FDL_CodeRam"
#elif R_FDL_COMPILER == R_FDL_COMP_IAR
#pragma dataseg = R_FDL_CodeRam
#elif R_FDL_COMPILER == R_FDL_COMP_REC
#pragma section r0_disp32 "R_FDL_CodeRam"
#endif
#elif defined R_FDL_STOP_SEC_CODERAM
#undef R_FDL_STOP_SEC_CODERAM /* PRQA S 0841 */
#if R_FDL_COMPILER == R_FDL_COMP_GHS
#pragma ghs section bss = default
#pragma ghs enddata
#elif R_FDL_COMPILER == R_FDL_COMP_IAR
#pragma dataseg = default
#elif R_FDL_COMPILER == R_FDL_COMP_REC
#pragma section default
#endif
#else
#error "r_fdl_mem_map.h: No valid section define found"
#endif /* if defined R_FDL_START_SEC_PUBLIC_CODE */
#endif /* ifdef AUTOSAR_IMPLEMENTATION */
/*********************************************************************************************************************/
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_OFF 0292
#endif
/*********************************************************************************************************************
* Library : Data Flash Access Library for Renesas RH850 devices
*
* File Name : $Source: r_fdl_types.h $
* Lib. Version : $RH850_FDL_LIB_VERSION_T01: V2.11 $
* Mod. Revision : $Revision: 1.18 $
* Mod. Date : $Date: 2016/06/01 12:39:19JST $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : User interface type definitions
*********************************************************************************************************************/
/*********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS
* AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
* REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2015-2016 Renesas Electronics Corporation. All rights reserved.
*********************************************************************************************************************/
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_ON 0292
#endif
/*********************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 3.1 (QAC message 0292)
* Reason: To support automatic insertion of revision, module name etc. by the source revision control system
* it is necessary to violate the rule, because the system uses non basic characters as placeholders.
* Verification: The placeholders are used in commentaries only. Therefore rule violation cannot influence code
* compilation.
*********************************************************************************************************************/
#ifndef R_FDL_TYPES_H
#define R_FDL_TYPES_H
/*********************************************************************************************************************
* Global type definitions
*********************************************************************************************************************/
/* ---------------- Configuration ------------------------------------------ */
/**
\struct r_fdl_descriptor_t
FDL descriptor variable definition.
*/
typedef struct R_FDL_DESCRIPTOR_T
{
uint16_t cpuFrequencyMHz_u16; /**< Flash hardware frequency in MHz */
uint16_t fdlPoolSize_u16; /**< FDL pool size in no. of blocks */
uint16_t eelPoolStart_u16; /**< 1st block of the EEL pool */
uint16_t eelPoolSize_u16; /**< Last block of the EEL pool */
} r_fdl_descriptor_t;
/* ---------------- Operation ---------------------------------------------- */
/**
\enum r_fdl_status_t
FDL status return values
*/
typedef enum R_FDL_STATUS_T
{
R_FDL_OK = 0, /**< Operation terminated successfully */
R_FDL_BUSY = 1, /**< Operation is still ongoing */
R_FDL_SUSPENDED = 2, /**< Flash operation is suspended */
R_FDL_ERR_CONFIGURATION = 3, /**< The FDL configuration (descriptor) was wrong */
R_FDL_ERR_PARAMETER = 4, /**< A parameter of the FDL function call was wrong */
R_FDL_ERR_PROTECTION = 5, /**< Operation blocked due to wrong parameters */
R_FDL_ERR_REJECTED = 6, /**< Flow error, e.g. another operation is still busy */
R_FDL_ERR_WRITE = 7, /**< Flash write error */
R_FDL_ERR_ERASE = 8, /**< Flash erase error */
R_FDL_ERR_BLANKCHECK = 9, /**< Flash blank check error */
R_FDL_ERR_COMMAND = 10, /**< Unknown command */
R_FDL_ERR_ECC_SED = 11, /**< Single bit error detected by ECC */
R_FDL_ERR_ECC_DED = 12, /**< Double bit error detected by ECC */
R_FDL_ERR_INTERNAL = 13, /**< Library internal error */
R_FDL_CANCELLED = 14 /**< Flash operation is cancelled */
} r_fdl_status_t;
/**
\enum r_fdl_accessType_t
FDL operations originator defines.
Set by the user when starting an FDL operation.
Reset to ..._NONE by the library on operation end.
*/
typedef enum R_FDL_ACCESS_TYPE_T
{
R_FDL_ACCESS_NONE = 0, /**< FDL internal value. Not used by the application */
R_FDL_ACCESS_USER = 1, /**< User application wants to execute an FDL operation */
R_FDL_ACCESS_EEL = 2 /**< The EEL wants to execute an FDL operation */
} r_fdl_accessType_t;
/**
\enum r_fdl_command_t
FDL operation commands
*/
typedef enum R_FDL_COMMAND_T
{
R_FDL_CMD_ERASE = 0, /**< Flash block erase (Multiple blocks) */
R_FDL_CMD_WRITE = 1, /**< Flash write (Multiple words) */
R_FDL_CMD_BLANKCHECK = 2, /**< Flash blank check command (Multiple words) */
R_FDL_CMD_READ = 3, /**< Flash read with ECC error polling (Multiple words) */
#if (defined ENABLE_CMD_WRITE16B)
R_FDL_CMD_WRITE16B = 4, /**< Flash write (Multiple of 16 bytes unit)
This command is supported only by the particular products.
If the product is not allowed to use this command explicitly,
then this command must not be used */
#endif
R_FDL_CMD_PREPARE_ENV = 5 /**< Prepare Flash environment */
} r_fdl_command_t;
/**
\struct r_fdl_request_t
FDL operations request structure, required for R_FDL_Execute
*/
typedef volatile struct R_FDL_REQUEST_T
{
r_fdl_command_t command_enu; /**< FDL operation, e.g. R_FDL_CMD_ERASE */
uint32_t bufAddr_u32; /**< Write operation: Source data address */
uint32_t idx_u32; /**< Write, blank check, read operation: byte index (address)\n
Erase operation: block number of the first block to erase */
uint16_t cnt_u16; /**< Write operation: Number of words to write \n
Erase operation: Number of blocks to erase \n
Blank Check operation: Number of words to check \n
Read operation: Number of words to read */
r_fdl_accessType_t accessType_enu; /**< Data Flash access originator: \n
R_FDL_ACCESS_USER: User code \n
R_FDL_ACCESS_EEL: EEL library */
r_fdl_status_t status_enu; /**< status return value of the FDL */
} r_fdl_request_t;
extern uint32_t TYW_FDL_Blank_Check(uint32_t u32StartAddr, uint32_t u32EndAddr);
extern r_fdl_status_t TYW_FDL_Flash_Read(uint32_t u32Addr, uint32_t u32Data[], uint32_t u32Len);
extern r_fdl_status_t TYW_FDL_Write(uint32_t u32Addr, uint32_t u32Data[], uint32_t u32Len);
extern r_fdl_status_t TYW_FDL_Erase(uint32_t u32StartAddr, uint32_t u32EndAddr);
extern r_fdl_status_t TYW_FDL_Init(void);
/*********************************************************************************************************************/
#endif /* ifndef R_FDL_TYPES_H */
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_OFF 0292
#endif
/************************************************************************************************************
* File Name : $Source: target.h $
* Mod. Revision : $Revision: 1.2 $
* Mod. Date : $Date: 2016/05/31 13:16:53JST $
* Device(s) : RV40 Flash based RH850 microcontroller
* Description : Target specific defines
************************************************************************************************************/
/************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with
* Renesas products. No other uses are authorized. This software is owned by Renesas Electronics
* Corporation and is protected under all applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR
* ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR
* CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the
* availability of this software. By using this software, you agree to the additional terms and conditions
* found by accessing the following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2015-2016 Renesas Electronics Corporation. All rights reserved.
************************************************************************************************************/
#ifdef ENABLE_QAC_TEST
#pragma PRQA_MESSAGES_ON 0292
#endif
/************************************************************************************************************
* MISRA Rule: MISRA-C 2004 rule 3.1 (QAC message 0292)
* Reason: To support automatic insertion of revision, module name etc. by the source
* revision control system it is necessary to violate the rule, because the
* system uses non basic characters as placeholders.
* Verification: The placeholders are used in commentars only. Therefore rule violation cannot
* influency code compilation.
************************************************************************************************************/
#ifndef TARGET_H
#define TARGET_H
#if R_FCL_COMPILER == R_FCL_COMP_GHS
#include "dr7f701441.dvf.h"
#elif R_FCL_COMPILER == R_FCL_COMP_IAR
#error include
#elif R_FCL_COMPILER == R_FCL_COMP_REC
#include "iodefine.h"
#endif
/************************************************************************************************************
Macro definitions
************************************************************************************************************/
#define protected_write(preg,pstatus,reg,value) do { \
(preg)=0xa5u; \
(reg)=(value); \
(reg)=~(value); \
(reg)=(value); \
}while((pstatus)==1u)
#define R_FCL_INIT_CPU_AND_FPERIPHERAL_CLK \
/* Prepare MainOSC */ \
SYSMOSCC=0x06u; /* set MainOSC gain (8 MHz) */ \
SYSMOSCST=0x8000u; /* set MainOSC stabilization time to 4 ms */ \
protected_write(SYSPROTCMD0,SYSPROTS0,SYSMOSCE,0x01u); /* trigger enable (protected write) */ \
while (0x4u != (SYSMOSCS&0x04u)){} /* wait for active MainOSC */ \
\
/* Set PLL0 to 480MHz*/ \
SYSPLL0C=0x6000003B; /* PLL0 configuration: \
Fixed frequency mode(dithering disabled) \
Nr = 60 \
Pr = 1 \
Mr = 1 \
fPLL= MainOsc * Nr /(Mr * Pr) \
fPLL= 8Mhz * 60 /( 1 * 1) = 480 MHz */ \
protected_write(SYSPROTCMD1,SYSPROTS1,SYSPLL0E,0x01u); /* trigger PLL0 Enable (protected write) */ \
while((SYSPLL0S&(1<<2))!=(1<<2)){} /* wait until PLL0 stable bit is set*/ \
\
/* Set PLL1 to 320MHz (PLL1CLK = 320MHz)*/ \
SYSPLL1C=0x00000027; /* PLL1 configuration: \
Fixed frequency mode(dithering disabled) \
Nr = 40 \
Pr = 1 \
Mr = 1 \
fPLL= MainOsc * Nr /(Mr * Pr) \
fPLL= 8Mhz * 40 /( 1 * 1) = 320 MHz */ \
protected_write(SYSPROTCMD1,SYSPROTS1,SYSPLL1E,0x01u); /* trigger PLL1 Enable (protected write) */ \
while((SYSPLL0S&(1<<2))!=(1<<2)){} /* wait until PLL0 stable bit is set*/ \
\
/* set CPU clock divider to 2 */ \
protected_write(SYSPROTCMD1,SYSPROTS1,SYSCKSC_ICPUCLKD_CTL,0x02u); /* divider 2 */ \
while(0x02u != SYSCKSC_ICPUCLKD_ACT){} \
\
/* set CPU clock to PLL1CLK (320MHz)*/ \
protected_write(SYSPROTCMD1,SYSPROTS1,SYSCKSC_ICPUCLKS_CTL ,0x04u); /* PLL1CLK */ \
while(0x04u != SYSCKSC_ICPUCLKS_ACT){} \
\
/* set CLKFIX to PLLFIXCLK/12 (40MHz) */ \
protected_write(SYSPROTCMDD1,SYSPROTSD1,SYSCKSC_ICLKFIXS_CTL ,0x01u); /* PLLFIXCLK/12 */ \
while(0x01u != SYSCKSC_ICLKFIXS_ACT){} \
\
/* set TAUB0 clock -> CLKFIX (40MHz) */ \
protected_write(SYSPROTCMDD1,SYSPROTSD1,SYSCKSC_ITAUB01S_CTL,0x01u); /* CLKFIX */ \
while(0x01u != SYSCKSC_ITAUB01S_ACT){}
#define FLMD0_PROTECTION_OFF (0x01u)
#define FLMD0_PROTECTION_ON (0x00u)
#define FCL_INIT_FLASHACCESS \
uint32_t i; \
\
/* enable FLMD0 */ \
FLMDPCMD = 0xa5; \
FLMDCNT = FLMD0_PROTECTION_OFF; \
FLMDCNT = ~FLMD0_PROTECTION_OFF; \
FLMDCNT = FLMD0_PROTECTION_OFF; \
for (i = 0; i < 10000; i++) \
{ \
/* do nothing ... delay time may depend on */ \
/* external FLMD0 pin connection */ \
}
#define FCL_DISABLE_FLASHACCESS \
uint32_t i; \
\
/* enable FLMD0 */ \
FLMDPCMD = 0xa5; \
FLMDCNT = FLMD0_PROTECTION_ON; \
FLMDCNT = ~FLMD0_PROTECTION_ON; \
FLMDCNT = FLMD0_PROTECTION_ON; \
for (i = 0; i < 10000; i++) \
{ \
/* do nothing ... delay time may depend on */ \
/* external FLMD0 pin connection */ \
}
/************************************************************************************************************
Typedef definitions
************************************************************************************************************/
/************************************************************************************************************
Exported global variables
************************************************************************************************************/
/************************************************************************************************************
Exported global functions (to be accessed by other files)
************************************************************************************************************/
#endif /* end of TARGET_H */
...@@ -4,7 +4,7 @@ static const HanSansCNFontPos_t Hansans00002ce20[] = ...@@ -4,7 +4,7 @@ static const HanSansCNFontPos_t Hansans00002ce20[] =
{ {
//{charid, xpos, ypos, width, height, xoffset, yoffset, xadvance} //{charid, xpos, ypos, width, height, xoffset, yoffset, xadvance}
{ 0 , 3995 , 552 , 4 , 22 , 0 , 0 , 4 }, { 0 , 3995 , 552 , 4 , 22 , 0 , 0 , 4 },
#if 0 #if 1
{ 1 , 3995 , 23 , 4 , 22 , 0 , 0 , 4 }, { 1 , 3995 , 23 , 4 , 22 , 0 , 0 , 4 },
{ 2 , 3995 , 805 , 4 , 22 , 0 , 0 , 4 }, { 2 , 3995 , 805 , 4 , 22 , 0 , 0 , 4 },
{ 3 , 3995 , 759 , 4 , 22 , 0 , 0 , 4 }, { 3 , 3995 , 759 , 4 , 22 , 0 , 0 , 4 },
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "Internal_Flash.h" #include "Internal_Flash.h"
#include "Emulated_EEPROM.h" #include "Emulated_EEPROM.h"
#include "Emulated_EEPROM_Access.h" #include "Emulated_EEPROM_Access.h"
#include "r_fdl_types.h"
/**************************************************************************** /****************************************************************************
* !!! The following code should be generated by configuration tool !!! * * !!! The following code should be generated by configuration tool !!! *
...@@ -39,7 +40,7 @@ uint32_t g_u32EEPROMBlock9Buffer[EEPROM_BLOCK9_BUFFER_SIZE / 4U]; ...@@ -39,7 +40,7 @@ uint32_t g_u32EEPROMBlock9Buffer[EEPROM_BLOCK9_BUFFER_SIZE / 4U];
#define EEPROM_BLOCK10_BUFFER_SIZE (EEPROM_BLOCK_CTRL_BYTE_SIZE + EEPROM_BLOCK_EOL_K_LINE_SIZE) #define EEPROM_BLOCK10_BUFFER_SIZE (EEPROM_BLOCK_CTRL_BYTE_SIZE + EEPROM_BLOCK_EOL_K_LINE_SIZE)
uint32_t g_u32EEPROMBlock10Buffer[EEPROM_BLOCK10_BUFFER_SIZE / 4U]; uint32_t g_u32EEPROMBlock10Buffer[EEPROM_BLOCK10_BUFFER_SIZE / 4U];
static const EEPROM_Block_st_t g_stEEPROMBlockTable[] = static const EEPROM_Block_st_t g_stEEPROMBlockTable[] =
{ {
/* u32StartAddr u32EndAddr u32DataSize pu32DataBuffer */ /* u32StartAddr u32EndAddr u32DataSize pu32DataBuffer */
{0xFF200000UL, 0xFF20007FUL, EEPROM_BLOCK0_BUFFER_SIZE, g_u32EEPROMBlock0Buffer,}, {0xFF200000UL, 0xFF20007FUL, EEPROM_BLOCK0_BUFFER_SIZE, g_u32EEPROMBlock0Buffer,},
...@@ -64,14 +65,16 @@ EEPROM_Block_Access_st_t g_stEEPROMBlockAccess[EEPROM_TOTAL_BLOCK_NUM]; ...@@ -64,14 +65,16 @@ EEPROM_Block_Access_st_t g_stEEPROMBlockAccess[EEPROM_TOTAL_BLOCK_NUM];
void EEPROM_Init(void) void EEPROM_Init(void)
{ {
EEPROM_Media_Access_st_t stFlashAccessFunc; EEPROM_Media_Access_st_t stFlashAccessFunc;
stFlashAccessFunc.pfnMemErase = Int_Data_Flash_Erase; TYW_FDL_Init();
stFlashAccessFunc.pfnMemBlankChk = Int_Data_Flash_Blank_Check;
stFlashAccessFunc.pfnMemRead = Int_Data_Flash_Read; stFlashAccessFunc.pfnMemErase = TYW_FDL_Erase;//Int_Data_Flash_Erase;
stFlashAccessFunc.pfnMemWrite = Int_Data_Flash_Write; stFlashAccessFunc.pfnMemBlankChk = TYW_FDL_Blank_Check;//Int_Data_Flash_Blank_Check;
stFlashAccessFunc.pfnMemRead = TYW_FDL_Flash_Read;//Int_Data_Flash_Read;
stFlashAccessFunc.pfnMemWrite = TYW_FDL_Write;//Int_Data_Flash_Write;
Int_Data_Flash_Register_P_E_Complete_Cb(EEPROM_Mem_Access_Complete_Callback); Int_Data_Flash_Register_P_E_Complete_Cb(EEPROM_Mem_Access_Complete_Callback);
EEPROM_Access_Init( g_stEEPROMBlockTable, EEPROM_Access_Init( g_stEEPROMBlockTable,
g_stEEPROMBlockAccess, g_stEEPROMBlockAccess,
&stFlashAccessFunc, &stFlashAccessFunc,
...@@ -81,8 +84,8 @@ void EEPROM_Init(void) ...@@ -81,8 +84,8 @@ void EEPROM_Init(void)
EEPROM_Status_en_t EEPROM_Get_Status(void) EEPROM_Status_en_t EEPROM_Get_Status(void)
{ {
EEPROM_Status_en_t enStatus; EEPROM_Status_en_t enStatus;
if(EEPROM_Access_Busy()) if (EEPROM_Access_Busy())
{ {
enStatus = EEPROM_STAT_BUSY; enStatus = EEPROM_STAT_BUSY;
} }
...@@ -90,7 +93,7 @@ EEPROM_Status_en_t EEPROM_Get_Status(void) ...@@ -90,7 +93,7 @@ EEPROM_Status_en_t EEPROM_Get_Status(void)
{ {
enStatus = EEPROM_STAT_IDLE; enStatus = EEPROM_STAT_IDLE;
} }
return enStatus; return enStatus;
} }
...@@ -98,7 +101,7 @@ EEPROM_Block_Status_en_t EEPROM_Get_Block_Status(uint16_t u16BlockID) ...@@ -98,7 +101,7 @@ EEPROM_Block_Status_en_t EEPROM_Get_Block_Status(uint16_t u16BlockID)
{ {
uint8_t u8BlockStatus; uint8_t u8BlockStatus;
EEPROM_Block_Status_en_t enStatus; EEPROM_Block_Status_en_t enStatus;
u8BlockStatus = EEPROM_Block_Access_Status(u16BlockID); u8BlockStatus = EEPROM_Block_Access_Status(u16BlockID);
if (u8BlockStatus == EEPROM_BLOCK_BLANK) if (u8BlockStatus == EEPROM_BLOCK_BLANK)
{ {
...@@ -112,7 +115,7 @@ EEPROM_Block_Status_en_t EEPROM_Get_Block_Status(uint16_t u16BlockID) ...@@ -112,7 +115,7 @@ EEPROM_Block_Status_en_t EEPROM_Get_Block_Status(uint16_t u16BlockID)
{ {
enStatus = EEPROM_STAT_ERROR; enStatus = EEPROM_STAT_ERROR;
} }
return enStatus; return enStatus;
} }
...@@ -120,7 +123,7 @@ EEPROM_RW_Result_en_t EEPROM_Read_Data(uint16_t u16BlockID, uint32_t u32Data[], ...@@ -120,7 +123,7 @@ EEPROM_RW_Result_en_t EEPROM_Read_Data(uint16_t u16BlockID, uint32_t u32Data[],
{ {
uint8_t u8Error; uint8_t u8Error;
EEPROM_RW_Result_en_t enResult; EEPROM_RW_Result_en_t enResult;
u8Error = EEPROM_Read_Block_Data(u16BlockID, u32Data, u16Len); u8Error = EEPROM_Read_Block_Data(u16BlockID, u32Data, u16Len);
if (u8Error) if (u8Error)
{ {
...@@ -130,7 +133,7 @@ EEPROM_RW_Result_en_t EEPROM_Read_Data(uint16_t u16BlockID, uint32_t u32Data[], ...@@ -130,7 +133,7 @@ EEPROM_RW_Result_en_t EEPROM_Read_Data(uint16_t u16BlockID, uint32_t u32Data[],
{ {
enResult = EEPROM_RW_PASS; enResult = EEPROM_RW_PASS;
} }
return enResult; return enResult;
} }
...@@ -138,7 +141,7 @@ EEPROM_RW_Result_en_t EEPROM_Write_Data(uint16_t u16BlockID, uint32_t u32Data[], ...@@ -138,7 +141,7 @@ EEPROM_RW_Result_en_t EEPROM_Write_Data(uint16_t u16BlockID, uint32_t u32Data[],
{ {
uint8_t u8Error; uint8_t u8Error;
EEPROM_RW_Result_en_t enResult; EEPROM_RW_Result_en_t enResult;
u8Error = EEPROM_Write_Block_Data(u16BlockID, u32Data, u16Len); u8Error = EEPROM_Write_Block_Data(u16BlockID, u32Data, u16Len);
if (u8Error) if (u8Error)
{ {
...@@ -148,7 +151,7 @@ EEPROM_RW_Result_en_t EEPROM_Write_Data(uint16_t u16BlockID, uint32_t u32Data[], ...@@ -148,7 +151,7 @@ EEPROM_RW_Result_en_t EEPROM_Write_Data(uint16_t u16BlockID, uint32_t u32Data[],
{ {
enResult = EEPROM_RW_PASS; enResult = EEPROM_RW_PASS;
} }
return enResult; return enResult;
} }
#include "stddef.h" #include "stddef.h"
#include "stdint.h" #include "stdint.h"
#include "Emulated_EEPROM_Access.h" #include "Emulated_EEPROM_Access.h"
typedef union typedef union
{ {
uint32_t u32Word[1U]; uint32_t u32Word[1U];
struct struct
{ {
uint16_t u16Index; uint16_t u16Index;
uint16_t u16IndexInv; uint16_t u16IndexInv;
}stField; }stField;
}EEPROM_Ctrl_Data_un_t; }EEPROM_Ctrl_Data_un_t;
typedef struct typedef struct
{ {
uint8_t u8State; uint8_t u8State;
uint16_t u16BlockNum; uint16_t u16BlockNum;
uint16_t u16ProgLen; uint16_t u16ProgLen;
uint32_t u32ProgAddr; uint32_t u32ProgAddr;
uint32_t* pu32ProgData; uint32_t* pu32ProgData;
}EEPROM_Access_Ctrl_st_t; }EEPROM_Access_Ctrl_st_t;
#define EEPROM_BLANK_CHECK_RECORD_NUM (3U) #define EEPROM_BLANK_CHECK_RECORD_NUM (3U)
#define EEPROM_OVER_SEARCH_RECORD_NUM (3U) #define EEPROM_OVER_SEARCH_RECORD_NUM (3U)
#define EEPROM_WR_STATE_IDLE (0U) #define EEPROM_WR_STATE_IDLE (0U)
#define EEPROM_WR_STATE_ERASE (1U) #define EEPROM_WR_STATE_ERASE (1U)
#define EEPROM_WR_STATE_PROG (2U) #define EEPROM_WR_STATE_PROG (2U)
// -------------------------------------------------------------- // --------------------------------------------------------------
// CRC16计算方法1:使用2个256长度的校验表 // CRC16计算方法1:使用2个256长度的校验表
// -------------------------------------------------------------- // --------------------------------------------------------------
static const uint8_t g_u8EEPROMCRCTableH[] = static const uint8_t g_u8EEPROMCRCTableH[] =
{ {
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U,
0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U, 0x01U, 0xC0U, 0x80U, 0x41U, 0x00U, 0xC1U, 0x81U, 0x40U,
}; };
static const uint8_t g_u8EEPROMCRCTableL[] = static const uint8_t g_u8EEPROMCRCTableL[] =
{ {
0x00U, 0xC0U, 0xC1U, 0x01U, 0xC3U, 0x03U, 0x02U, 0xC2U, 0x00U, 0xC0U, 0xC1U, 0x01U, 0xC3U, 0x03U, 0x02U, 0xC2U,
0xC6U, 0x06U, 0x07U, 0xC7U, 0x05U, 0xC5U, 0xC4U, 0x04U, 0xC6U, 0x06U, 0x07U, 0xC7U, 0x05U, 0xC5U, 0xC4U, 0x04U,
0xCCU, 0x0CU, 0x0DU, 0xCDU, 0x0FU, 0xCFU, 0xCEU, 0x0EU, 0xCCU, 0x0CU, 0x0DU, 0xCDU, 0x0FU, 0xCFU, 0xCEU, 0x0EU,
0x0AU, 0xCAU, 0xCBU, 0x0BU, 0xC9U, 0x09U, 0x08U, 0xC8U, 0x0AU, 0xCAU, 0xCBU, 0x0BU, 0xC9U, 0x09U, 0x08U, 0xC8U,
0xD8U, 0x18U, 0x19U, 0xD9U, 0x1BU, 0xDBU, 0xDAU, 0x1AU, 0xD8U, 0x18U, 0x19U, 0xD9U, 0x1BU, 0xDBU, 0xDAU, 0x1AU,
0x1EU, 0xDEU, 0xDFU, 0x1FU, 0xDDU, 0x1DU, 0x1CU, 0xDCU, 0x1EU, 0xDEU, 0xDFU, 0x1FU, 0xDDU, 0x1DU, 0x1CU, 0xDCU,
0x14U, 0xD4U, 0xD5U, 0x15U, 0xD7U, 0x17U, 0x16U, 0xD6U, 0x14U, 0xD4U, 0xD5U, 0x15U, 0xD7U, 0x17U, 0x16U, 0xD6U,
0xD2U, 0x12U, 0x13U, 0xD3U, 0x11U, 0xD1U, 0xD0U, 0x10U, 0xD2U, 0x12U, 0x13U, 0xD3U, 0x11U, 0xD1U, 0xD0U, 0x10U,
0xF0U, 0x30U, 0x31U, 0xF1U, 0x33U, 0xF3U, 0xF2U, 0x32U, 0xF0U, 0x30U, 0x31U, 0xF1U, 0x33U, 0xF3U, 0xF2U, 0x32U,
0x36U, 0xF6U, 0xF7U, 0x37U, 0xF5U, 0x35U, 0x34U, 0xF4U, 0x36U, 0xF6U, 0xF7U, 0x37U, 0xF5U, 0x35U, 0x34U, 0xF4U,
0x3CU, 0xFCU, 0xFDU, 0x3DU, 0xFFU, 0x3FU, 0x3EU, 0xFEU, 0x3CU, 0xFCU, 0xFDU, 0x3DU, 0xFFU, 0x3FU, 0x3EU, 0xFEU,
0xFAU, 0x3AU, 0x3BU, 0xFBU, 0x39U, 0xF9U, 0xF8U, 0x38U, 0xFAU, 0x3AU, 0x3BU, 0xFBU, 0x39U, 0xF9U, 0xF8U, 0x38U,
0x28U, 0xE8U, 0xE9U, 0x29U, 0xEBU, 0x2BU, 0x2AU, 0xEAU, 0x28U, 0xE8U, 0xE9U, 0x29U, 0xEBU, 0x2BU, 0x2AU, 0xEAU,
0xEEU, 0x2EU, 0x2FU, 0xEFU, 0x2DU, 0xEDU, 0xECU, 0x2CU, 0xEEU, 0x2EU, 0x2FU, 0xEFU, 0x2DU, 0xEDU, 0xECU, 0x2CU,
0xE4U, 0x24U, 0x25U, 0xE5U, 0x27U, 0xE7U, 0xE6U, 0x26U, 0xE4U, 0x24U, 0x25U, 0xE5U, 0x27U, 0xE7U, 0xE6U, 0x26U,
0x22U, 0xE2U, 0xE3U, 0x23U, 0xE1U, 0x21U, 0x20U, 0xE0U, 0x22U, 0xE2U, 0xE3U, 0x23U, 0xE1U, 0x21U, 0x20U, 0xE0U,
0xA0U, 0x60U, 0x61U, 0xA1U, 0x63U, 0xA3U, 0xA2U, 0x62U, 0xA0U, 0x60U, 0x61U, 0xA1U, 0x63U, 0xA3U, 0xA2U, 0x62U,
0x66U, 0xA6U, 0xA7U, 0x67U, 0xA5U, 0x65U, 0x64U, 0xA4U, 0x66U, 0xA6U, 0xA7U, 0x67U, 0xA5U, 0x65U, 0x64U, 0xA4U,
0x6CU, 0xACU, 0xADU, 0x6DU, 0xAFU, 0x6FU, 0x6EU, 0xAEU, 0x6CU, 0xACU, 0xADU, 0x6DU, 0xAFU, 0x6FU, 0x6EU, 0xAEU,
0xAAU, 0x6AU, 0x6BU, 0xABU, 0x69U, 0xA9U, 0xA8U, 0x68U, 0xAAU, 0x6AU, 0x6BU, 0xABU, 0x69U, 0xA9U, 0xA8U, 0x68U,
0x78U, 0xB8U, 0xB9U, 0x79U, 0xBBU, 0x7BU, 0x7AU, 0xBAU, 0x78U, 0xB8U, 0xB9U, 0x79U, 0xBBU, 0x7BU, 0x7AU, 0xBAU,
0xBEU, 0x7EU, 0x7FU, 0xBFU, 0x7DU, 0xBDU, 0xBCU, 0x7CU, 0xBEU, 0x7EU, 0x7FU, 0xBFU, 0x7DU, 0xBDU, 0xBCU, 0x7CU,
0xB4U, 0x74U, 0x75U, 0xB5U, 0x77U, 0xB7U, 0xB6U, 0x76U, 0xB4U, 0x74U, 0x75U, 0xB5U, 0x77U, 0xB7U, 0xB6U, 0x76U,
0x72U, 0xB2U, 0xB3U, 0x73U, 0xB1U, 0x71U, 0x70U, 0xB0U, 0x72U, 0xB2U, 0xB3U, 0x73U, 0xB1U, 0x71U, 0x70U, 0xB0U,
0x50U, 0x90U, 0x91U, 0x51U, 0x93U, 0x53U, 0x52U, 0x92U, 0x50U, 0x90U, 0x91U, 0x51U, 0x93U, 0x53U, 0x52U, 0x92U,
0x96U, 0x56U, 0x57U, 0x97U, 0x55U, 0x95U, 0x94U, 0x54U, 0x96U, 0x56U, 0x57U, 0x97U, 0x55U, 0x95U, 0x94U, 0x54U,
0x9CU, 0x5CU, 0x5DU, 0x9DU, 0x5FU, 0x9FU, 0x9EU, 0x5EU, 0x9CU, 0x5CU, 0x5DU, 0x9DU, 0x5FU, 0x9FU, 0x9EU, 0x5EU,
0x5AU, 0x9AU, 0x9BU, 0x5BU, 0x99U, 0x59U, 0x58U, 0x98U, 0x5AU, 0x9AU, 0x9BU, 0x5BU, 0x99U, 0x59U, 0x58U, 0x98U,
0x88U, 0x48U, 0x49U, 0x89U, 0x4BU, 0x8BU, 0x8AU, 0x4AU, 0x88U, 0x48U, 0x49U, 0x89U, 0x4BU, 0x8BU, 0x8AU, 0x4AU,
0x4EU, 0x8EU, 0x8FU, 0x4FU, 0x8DU, 0x4DU, 0x4CU, 0x8CU, 0x4EU, 0x8EU, 0x8FU, 0x4FU, 0x8DU, 0x4DU, 0x4CU, 0x8CU,
0x44U, 0x84U, 0x85U, 0x45U, 0x87U, 0x47U, 0x46U, 0x86U, 0x44U, 0x84U, 0x85U, 0x45U, 0x87U, 0x47U, 0x46U, 0x86U,
0x82U, 0x42U, 0x43U, 0x83U, 0x41U, 0x81U, 0x80U, 0x40U, 0x82U, 0x42U, 0x43U, 0x83U, 0x41U, 0x81U, 0x80U, 0x40U,
}; };
static uint16_t EEPROM_CRC_Calc(uint32_t * pu32Data, uint16_t u16Len); /*static const uint8_t g_u8EEPROMCRCTableH[] =
{
EEPROM_Access_Ctrl_st_t g_stEEPROMAccess; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
EEPROM_Block_Access_st_t * g_pstEEPROMBlock; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
EEPROM_Mem_Erase_Func_ptr_t g_pfnEEPROMMemErase; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
EEPROM_Mem_Blank_Chk_Func_ptr_t g_pfnEEPROMMemBlankCheck; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
EEPROM_Mem_Read_Func_ptr_t g_pfnEEPROMMemRead; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
EEPROM_Mem_Write_Func_ptr_t g_pfnEEPROMMemWrite; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
void EEPROM_Access_Init(const EEPROM_Block_st_t * pstBlockTable, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
EEPROM_Block_Access_st_t * pstBlockAccess, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
EEPROM_Media_Access_st_t * pstMediaAccess, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
uint16_t u16BlockNum) 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
{ 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
uint16_t i; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
uint8_t u8Loop; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
uint8_t u8Ready; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
uint16_t u16Index; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
uint16_t u16IndexBkup; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
uint16_t u16RecordNum; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
uint16_t u16MaxRecordNum[2U]; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
uint16_t u16WordNum; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
uint16_t u16Result; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
uint32_t u32DataAddr; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
uint32_t u32DataAddrBase; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
uint32_t u32DataAddrEnd; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
EEPROM_Ctrl_Data_un_t unCtrlData; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
if ((pstBlockTable != NULL) && (pstBlockAccess != NULL) &&\ 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
(pstMediaAccess != NULL) && (u16BlockNum != 0U)) 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
{ 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
/*** Step 1 : Setup media(data flash) access functions ***/ };
g_pfnEEPROMMemErase = pstMediaAccess->pfnMemErase;
g_pfnEEPROMMemBlankCheck = pstMediaAccess->pfnMemBlankChk; static const uint8_t g_u8EEPROMCRCTableL[] =
g_pfnEEPROMMemRead = pstMediaAccess->pfnMemRead; {
g_pfnEEPROMMemWrite = pstMediaAccess->pfnMemWrite; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
/*** Step 2 : Generate flash read / write control data ***/ 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
g_stEEPROMAccess.u8State = EEPROM_WR_STATE_IDLE; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
g_stEEPROMAccess.u16BlockNum = u16BlockNum; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
g_pstEEPROMBlock = pstBlockAccess; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
for (i = 0U; i < g_stEEPROMAccess.u16BlockNum; i++) 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
{ 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
u32DataAddr = pstBlockTable[i].u32EndAddr - pstBlockTable[i].u32StartAddr + 1UL; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
g_pstEEPROMBlock[i].u8Status = EEPROM_BLOCK_BLANK; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
g_pstEEPROMBlock[i].u32BaseAddr = pstBlockTable[i].u32StartAddr; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
g_pstEEPROMBlock[i].u16SectorSize = (uint16_t)(u32DataAddr / 2UL); 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
g_pstEEPROMBlock[i].u8SectorOffset = 0U; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
g_pstEEPROMBlock[i].u16Index = 0U; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
g_pstEEPROMBlock[i].u16BlockSize = (uint16_t)(pstBlockTable[i].u32DataSize); 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
g_pstEEPROMBlock[i].u16MaxRecordNum = g_pstEEPROMBlock[i].u16SectorSize / g_pstEEPROMBlock[i].u16BlockSize; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
g_pstEEPROMBlock[i].u16RecordNum = 0U; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
g_pstEEPROMBlock[i].pu32Data = pstBlockTable[i].pu32DataBuffer; 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
} 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
/*** Step 3 : Blank check and find start record ***/ 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
for (i = 0U; i < g_stEEPROMAccess.u16BlockNum; i++) 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
{ 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
/*** 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
Step 3.1 Blank check and find start record 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
- Check if the logic data block related memory is blank. 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
- Then find out which logic sector contains the most recent record. 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
- The found sector will define the starting search point of step 3.2. 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U, 0x55U,
***/ };*/
/* Search sector +0 */ static uint16_t EEPROM_CRC_Calc(uint32_t * pu32Data, uint16_t u16Len);
u32DataAddrBase = g_pstEEPROMBlock[i].u32BaseAddr;
u32DataAddrEnd = u32DataAddrBase + (uint32_t)(g_pstEEPROMBlock[i].u16SectorSize) - 1UL; EEPROM_Access_Ctrl_st_t g_stEEPROMAccess;
u32DataAddr = g_pfnEEPROMMemBlankCheck(u32DataAddrBase, u32DataAddrEnd); EEPROM_Block_Access_st_t * g_pstEEPROMBlock;
if ((u32DataAddr == 0x00000000UL) || (u32DataAddr == 0xFFFFFFFFUL))
{ EEPROM_Mem_Erase_Func_ptr_t g_pfnEEPROMMemErase;
u8Loop = 0U; EEPROM_Mem_Blank_Chk_Func_ptr_t g_pfnEEPROMMemBlankCheck;
u16MaxRecordNum[0U] = 0U; EEPROM_Mem_Read_Func_ptr_t g_pfnEEPROMMemRead;
} EEPROM_Mem_Write_Func_ptr_t g_pfnEEPROMMemWrite;
else
{ void EEPROM_Access_Init(const EEPROM_Block_st_t * pstBlockTable,
u8Loop = 1U; EEPROM_Block_Access_st_t * pstBlockAccess,
u16MaxRecordNum[0U] = (uint16_t)u32DataAddr / g_pstEEPROMBlock[i].u16BlockSize; EEPROM_Media_Access_st_t * pstMediaAccess,
} uint16_t u16BlockNum)
{
u16RecordNum = 0U; uint16_t i;
u8Ready = 0U;
uint8_t u8Loop;
while (u8Loop) uint8_t u8Ready;
{ uint16_t u16Index;
/* Fetch block control data */ uint16_t u16IndexBkup;
u32DataAddr = u32DataAddrBase + (uint32_t)u16RecordNum * (uint32_t)g_pstEEPROMBlock[i].u16BlockSize; uint16_t u16RecordNum;
g_pfnEEPROMMemRead(u32DataAddr, unCtrlData.u32Word, 1UL); uint16_t u16MaxRecordNum[2U];
uint16_t u16WordNum;
if (unCtrlData.stField.u16Index + unCtrlData.stField.u16IndexInv == 0xFFFFU) uint16_t u16Result;
{ uint32_t u32DataAddr;
u8Loop = 0U; uint32_t u32DataAddrBase;
u8Ready = 1U; uint32_t u32DataAddrEnd;
g_pstEEPROMBlock[i].u8Status = EEPROM_BLOCK_ACTIVE; EEPROM_Ctrl_Data_un_t unCtrlData;
g_pstEEPROMBlock[i].u8SectorOffset = 0U;
g_pstEEPROMBlock[i].u16RecordNum = u16RecordNum; if ((pstBlockTable != NULL) && (pstBlockAccess != NULL) &&\
g_pstEEPROMBlock[i].u16Index = unCtrlData.stField.u16Index; (pstMediaAccess != NULL) && (u16BlockNum != 0U))
u16IndexBkup = unCtrlData.stField.u16Index; {
} /*** Step 1 : Setup media(data flash) access functions ***/
else g_pfnEEPROMMemErase = pstMediaAccess->pfnMemErase;
{ g_pfnEEPROMMemBlankCheck = pstMediaAccess->pfnMemBlankChk;
u16RecordNum++; g_pfnEEPROMMemRead = pstMediaAccess->pfnMemRead;
if ((u16RecordNum >= u16MaxRecordNum[0U]) || \ g_pfnEEPROMMemWrite = pstMediaAccess->pfnMemWrite;
(u16RecordNum >= EEPROM_BLANK_CHECK_RECORD_NUM))
{ /*** Step 2 : Generate flash read / write control data ***/
u8Loop = 0U; g_stEEPROMAccess.u8State = EEPROM_WR_STATE_IDLE;
} g_stEEPROMAccess.u16BlockNum = u16BlockNum;
}
} g_pstEEPROMBlock = pstBlockAccess;
/* Search sector +1 */ for (i = 0U; i < g_stEEPROMAccess.u16BlockNum; i++)
u32DataAddrBase += (uint32_t)(g_pstEEPROMBlock[i].u16SectorSize); {
u32DataAddrEnd += (uint32_t)(g_pstEEPROMBlock[i].u16SectorSize); u32DataAddr = pstBlockTable[i].u32EndAddr - pstBlockTable[i].u32StartAddr + 1UL;
u32DataAddr = g_pfnEEPROMMemBlankCheck(u32DataAddrBase, u32DataAddrEnd);
if ((u32DataAddr == 0x00000000UL) || (u32DataAddr == 0xFFFFFFFFUL)) g_pstEEPROMBlock[i].u8Status = EEPROM_BLOCK_BLANK;
{ g_pstEEPROMBlock[i].u32BaseAddr = pstBlockTable[i].u32StartAddr;
u8Loop = 0U; g_pstEEPROMBlock[i].u16SectorSize = (uint16_t)(u32DataAddr / 2UL);
u16MaxRecordNum[1U] = 0U; g_pstEEPROMBlock[i].u8SectorOffset = 0U;
} g_pstEEPROMBlock[i].u16Index = 0U;
else g_pstEEPROMBlock[i].u16BlockSize = (uint16_t)(pstBlockTable[i].u32DataSize);
{ g_pstEEPROMBlock[i].u16MaxRecordNum = g_pstEEPROMBlock[i].u16SectorSize / g_pstEEPROMBlock[i].u16BlockSize;
u8Loop = 1U; g_pstEEPROMBlock[i].u16RecordNum = 0U;
u16MaxRecordNum[1U] = (uint16_t)u32DataAddr / g_pstEEPROMBlock[i].u16BlockSize; g_pstEEPROMBlock[i].pu32Data = pstBlockTable[i].pu32DataBuffer;
} }
u16RecordNum = 0U;
/*** Step 3 : Blank check and find start record ***/
while (u8Loop) for (i = 0U; i < g_stEEPROMAccess.u16BlockNum; i++)
{ {
/* Fetch block control data */ /***
u32DataAddr = u32DataAddrBase + (uint32_t)u16RecordNum * (uint32_t)g_pstEEPROMBlock[i].u16BlockSize; Step 3.1 Blank check and find start record
g_pfnEEPROMMemRead(u32DataAddr, unCtrlData.u32Word, 1UL); - Check if the logic data block related memory is blank.
- Then find out which logic sector contains the most recent record.
if (unCtrlData.stField.u16Index + unCtrlData.stField.u16IndexInv == 0xFFFFU) - The found sector will define the starting search point of step 3.2.
{ ***/
u8Loop = 0U;
/* Search sector +0 */
if (u8Ready == 0U) u32DataAddrBase = g_pstEEPROMBlock[i].u32BaseAddr;
{ u32DataAddrEnd = u32DataAddrBase + (uint32_t)(g_pstEEPROMBlock[i].u16SectorSize) - 1UL;
u8Ready = 1U; u32DataAddr = g_pfnEEPROMMemBlankCheck(u32DataAddrBase, u32DataAddrEnd);
g_pstEEPROMBlock[i].u8Status = EEPROM_BLOCK_ACTIVE; if (u32DataAddr == 0x00000000UL)
g_pstEEPROMBlock[i].u8SectorOffset = 1U; {
g_pstEEPROMBlock[i].u16RecordNum = u16RecordNum; u8Loop = 0U;
g_pstEEPROMBlock[i].u16Index = unCtrlData.stField.u16Index; u16MaxRecordNum[0U] = 0U;
u16IndexBkup = unCtrlData.stField.u16Index; }
} else if (u32DataAddr == 0xFFFFFFFFUL)
else {
{ u8Loop = 1U;
if (unCtrlData.stField.u16Index >= u16IndexBkup) u16MaxRecordNum[0U] = g_pstEEPROMBlock[i].u16MaxRecordNum;
{ }
u16Index = unCtrlData.stField.u16Index - u16IndexBkup; else
} {
else u8Loop = 1U;
{ u16MaxRecordNum[0U] = (uint16_t)u32DataAddr / g_pstEEPROMBlock[i].u16BlockSize;
u16Index = unCtrlData.stField.u16Index + (0xFFFFU - u16IndexBkup) + 1U; }
}
u16RecordNum = 0U;
if (u16Index < g_pstEEPROMBlock[i].u16MaxRecordNum + EEPROM_BLANK_CHECK_RECORD_NUM) u8Ready = 0U;
{
g_pstEEPROMBlock[i].u8SectorOffset = 1U; while (u8Loop)
g_pstEEPROMBlock[i].u16RecordNum = u16RecordNum; {
g_pstEEPROMBlock[i].u16Index = unCtrlData.stField.u16Index; /* Fetch block control data */
} u32DataAddr = u32DataAddrBase + (uint32_t)u16RecordNum * (uint32_t)g_pstEEPROMBlock[i].u16BlockSize;
} g_pfnEEPROMMemRead(u32DataAddr, unCtrlData.u32Word, 1UL);
}
else if (unCtrlData.stField.u16Index + unCtrlData.stField.u16IndexInv == 0xFFFFU)
{ {
u16RecordNum++; u8Loop = 0U;
if ((u16RecordNum >= u16MaxRecordNum[1U]) || \ u8Ready = 1U;
(u16RecordNum >= EEPROM_BLANK_CHECK_RECORD_NUM))
{ g_pstEEPROMBlock[i].u8Status = EEPROM_BLOCK_ACTIVE;
u8Loop = 0U; g_pstEEPROMBlock[i].u8SectorOffset = 0U;
} g_pstEEPROMBlock[i].u16RecordNum = u16RecordNum;
} g_pstEEPROMBlock[i].u16Index = unCtrlData.stField.u16Index;
} u16IndexBkup = unCtrlData.stField.u16Index;
}
/*** else
Step 3.2 Search for the most recent record and load data {
- Find the last record's address u16RecordNum++;
- Load data form the address if ((u16RecordNum >= u16MaxRecordNum[0U]) || \
***/ (u16RecordNum >= EEPROM_BLANK_CHECK_RECORD_NUM))
if (g_pstEEPROMBlock[i].u8Status == EEPROM_BLOCK_ACTIVE) {
{ u8Loop = 0U;
/* Find the last record by index */ }
u32DataAddrBase = g_pstEEPROMBlock[i].u32BaseAddr; }
u32DataAddrBase += (uint32_t)(g_pstEEPROMBlock[i].u16SectorSize * (uint16_t)g_pstEEPROMBlock[i].u8SectorOffset); }
u16Index = g_pstEEPROMBlock[i].u16Index;
u16RecordNum = g_pstEEPROMBlock[i].u16RecordNum; /* Search sector +1 */
u8Loop = 1U; u32DataAddrBase += (uint32_t)(g_pstEEPROMBlock[i].u16SectorSize);
u32DataAddrEnd += (uint32_t)(g_pstEEPROMBlock[i].u16SectorSize);
while (u8Loop) u32DataAddr = g_pfnEEPROMMemBlankCheck(u32DataAddrBase, u32DataAddrEnd);
{ if (u32DataAddr == 0x00000000UL)
u16RecordNum++; {
u16Index++; u8Loop = 0U;
if ((u16RecordNum >= u16MaxRecordNum[g_pstEEPROMBlock[i].u8SectorOffset]) || \ u16MaxRecordNum[1U] = 0U;
(u16RecordNum - g_pstEEPROMBlock[i].u16RecordNum >= EEPROM_OVER_SEARCH_RECORD_NUM)) }
{ else if (u32DataAddr == 0xFFFFFFFFUL)
u8Loop = 0U; {
} u8Loop = 1U;
else u16MaxRecordNum[1U] = g_pstEEPROMBlock[i].u16MaxRecordNum;
{ }
/* Fetch block control data */ else
u32DataAddr = u32DataAddrBase + (uint32_t)u16RecordNum * (uint32_t)g_pstEEPROMBlock[i].u16BlockSize; {
g_pfnEEPROMMemRead(u32DataAddr, unCtrlData.u32Word, 1UL); u8Loop = 1U;
u16MaxRecordNum[1U] = (uint16_t)u32DataAddr / g_pstEEPROMBlock[i].u16BlockSize;
if (unCtrlData.stField.u16Index + unCtrlData.stField.u16IndexInv == 0xFFFFU) }
{
if (unCtrlData.stField.u16Index == u16Index) u16RecordNum = 0U;
{
g_pstEEPROMBlock[i].u16RecordNum = u16RecordNum; while (u8Loop)
g_pstEEPROMBlock[i].u16Index = unCtrlData.stField.u16Index; {
} /* Fetch block control data */
} u32DataAddr = u32DataAddrBase + (uint32_t)u16RecordNum * (uint32_t)g_pstEEPROMBlock[i].u16BlockSize;
} g_pfnEEPROMMemRead(u32DataAddr, unCtrlData.u32Word, 1UL);
}
if (unCtrlData.stField.u16Index + unCtrlData.stField.u16IndexInv == 0xFFFFU)
/* Load data */ {
u16RecordNum = g_pstEEPROMBlock[i].u16RecordNum; u8Loop = 0U;
u16Index = g_pstEEPROMBlock[i].u16Index;
u16IndexBkup = u16Index; if (u8Ready == 0U)
u8Loop = 1U; {
u8Ready = 1U;
do g_pstEEPROMBlock[i].u8Status = EEPROM_BLOCK_ACTIVE;
{ g_pstEEPROMBlock[i].u8SectorOffset = 1U;
u32DataAddr = u32DataAddrBase + (uint32_t)u16RecordNum * (uint32_t)g_pstEEPROMBlock[i].u16BlockSize; g_pstEEPROMBlock[i].u16RecordNum = u16RecordNum;
g_pfnEEPROMMemRead(u32DataAddr, unCtrlData.u32Word, 1UL); g_pstEEPROMBlock[i].u16Index = unCtrlData.stField.u16Index;
u16IndexBkup = unCtrlData.stField.u16Index;
if (unCtrlData.stField.u16Index + unCtrlData.stField.u16IndexInv == 0xFFFFU) }
{ else
if (u16Index == unCtrlData.stField.u16Index) {
{ if (unCtrlData.stField.u16Index >= u16IndexBkup)
u16IndexBkup = u16Index; {
u16WordNum = g_pstEEPROMBlock[i].u16BlockSize / 4U; u16Index = unCtrlData.stField.u16Index - u16IndexBkup;
}
/* Load data */ else
g_pfnEEPROMMemRead(u32DataAddr, g_pstEEPROMBlock[i].pu32Data, (uint32_t)u16WordNum); {
u16Result = EEPROM_CRC_Calc(g_pstEEPROMBlock[i].pu32Data, u16WordNum - 1U); u16Index = unCtrlData.stField.u16Index + (0xFFFFU - u16IndexBkup) + 1U;
}
if ((uint16_t)(g_pstEEPROMBlock[i].pu32Data[u16WordNum - 1U]) == u16Result)
{ if (u16Index < g_pstEEPROMBlock[i].u16MaxRecordNum + EEPROM_BLANK_CHECK_RECORD_NUM)
u8Loop = 0U; {
} g_pstEEPROMBlock[i].u8SectorOffset = 1U;
} g_pstEEPROMBlock[i].u16RecordNum = u16RecordNum;
} g_pstEEPROMBlock[i].u16Index = unCtrlData.stField.u16Index;
}
if (u8Loop) /* CRC check fail */ }
{ }
u16Index--; /* Go to previous record */ else
{
if (u16IndexBkup >= u16Index) u16RecordNum++;
{ if ((u16RecordNum >= u16MaxRecordNum[1U]) || \
u16Result = u16IndexBkup - u16Index; (u16RecordNum >= EEPROM_BLANK_CHECK_RECORD_NUM))
} {
else u8Loop = 0U;
{ }
u16Result = u16IndexBkup + (0xFFFFU - u16Index) + 1U; }
} }
if ((u16Result <= u16MaxRecordNum[0U] + u16MaxRecordNum[1U]) &&\ /***
(u16Result <= EEPROM_OVER_SEARCH_RECORD_NUM)) Step 3.2 Search for the most recent record and load data
{ - Find the last record's address
if (u16RecordNum == 0U) /* Cross sector access */ - Load data form the address
{ ***/
if (g_pstEEPROMBlock[i].u8SectorOffset) if (g_pstEEPROMBlock[i].u8Status == EEPROM_BLOCK_ACTIVE)
{ {
u32DataAddrBase -= (uint32_t)g_pstEEPROMBlock[i].u16BlockSize; /* Find the last record by index */
u16RecordNum = u16MaxRecordNum[0U]; u32DataAddrBase = g_pstEEPROMBlock[i].u32BaseAddr;
if (u16RecordNum == 0U) u32DataAddrBase += (uint32_t)(g_pstEEPROMBlock[i].u16SectorSize * (uint16_t)g_pstEEPROMBlock[i].u8SectorOffset);
{ u16Index = g_pstEEPROMBlock[i].u16Index;
u8Loop = 0U; u16RecordNum = g_pstEEPROMBlock[i].u16RecordNum;
g_pstEEPROMBlock[i].u8Status = EEPROM_BLOCK_ERROR; u8Loop = 1U;
}
else while (u8Loop)
{ {
u16RecordNum -= 1U; u16RecordNum++;
} u16Index++;
} if ((u16RecordNum >= u16MaxRecordNum[g_pstEEPROMBlock[i].u8SectorOffset]) || \
else (u16RecordNum - g_pstEEPROMBlock[i].u16RecordNum >= EEPROM_OVER_SEARCH_RECORD_NUM))
{ {
u32DataAddrBase += g_pstEEPROMBlock[i].u16BlockSize; u8Loop = 0U;
u16RecordNum = u16MaxRecordNum[1U]; }
if (u16RecordNum == 0U) else
{ {
u8Loop = 0U; /* Fetch block control data */
g_pstEEPROMBlock[i].u8Status = EEPROM_BLOCK_ERROR; u32DataAddr = u32DataAddrBase + (uint32_t)u16RecordNum * (uint32_t)g_pstEEPROMBlock[i].u16BlockSize;
} g_pfnEEPROMMemRead(u32DataAddr, unCtrlData.u32Word, 1UL);
else
{ if (unCtrlData.stField.u16Index + unCtrlData.stField.u16IndexInv == 0xFFFFU)
u16RecordNum -= 1U; {
} if (unCtrlData.stField.u16Index == u16Index)
} {
} g_pstEEPROMBlock[i].u16RecordNum = u16RecordNum;
else g_pstEEPROMBlock[i].u16Index = unCtrlData.stField.u16Index;
{ }
u16RecordNum--; }
} }
} }
else
{ /* Load data */
/* No correct data found, set error flag */ u16RecordNum = g_pstEEPROMBlock[i].u16RecordNum;
u8Loop = 0U; u16Index = g_pstEEPROMBlock[i].u16Index;
g_pstEEPROMBlock[i].u8Status = EEPROM_BLOCK_ERROR; u16IndexBkup = u16Index;
} u8Loop = 1U;
}
}while(u8Loop); do
} {
} u32DataAddr = u32DataAddrBase + (uint32_t)u16RecordNum * (uint32_t)g_pstEEPROMBlock[i].u16BlockSize;
} g_pfnEEPROMMemRead(u32DataAddr, unCtrlData.u32Word, 1UL);
}
if (unCtrlData.stField.u16Index + unCtrlData.stField.u16IndexInv == 0xFFFFU)
uint8_t EEPROM_Access_Busy(void) {
{ if (u16Index == unCtrlData.stField.u16Index)
return g_stEEPROMAccess.u8State; {
} u16IndexBkup = u16Index;
u16WordNum = g_pstEEPROMBlock[i].u16BlockSize / 4U;
uint8_t EEPROM_Block_Access_Status(uint16_t u16BlockID)
{ /* Load data */
uint8_t u8Status; g_pfnEEPROMMemRead(u32DataAddr, g_pstEEPROMBlock[i].pu32Data, (uint32_t)u16WordNum);
u16Result = EEPROM_CRC_Calc(g_pstEEPROMBlock[i].pu32Data, u16WordNum - 1U);
u8Status = EEPROM_BLOCK_ERROR;
if (u16BlockID < g_stEEPROMAccess.u16BlockNum) if ((uint16_t)(g_pstEEPROMBlock[i].pu32Data[u16WordNum - 1U]) == u16Result)
{ {
u8Status = g_pstEEPROMBlock[u16BlockID].u8Status; u8Loop = 0U;
} }
}
return u8Status; }
}
if (u8Loop) /* CRC check fail */
/* u16Len : DWord(32-bit) number to be read */ {
/* Retval 0 - OK 1 - Error */ u16Index--; /* Go to previous record */
uint8_t EEPROM_Read_Block_Data(uint16_t u16BlockID, uint32_t u32Data[], uint16_t u16Len)
{ if (u16IndexBkup >= u16Index)
uint16_t i; {
uint8_t u8Error; u16Result = u16IndexBkup - u16Index;
}
u8Error = 1U; else
if ((u16BlockID < g_stEEPROMAccess.u16BlockNum) && (u32Data != NULL) && (u16Len != 0U)) {
{ u16Result = u16IndexBkup + (0xFFFFU - u16Index) + 1U;
if ((g_pstEEPROMBlock[u16BlockID].u8Status == EEPROM_BLOCK_ACTIVE) && \ }
(u16Len <= (g_pstEEPROMBlock[u16BlockID].u16BlockSize - EEPROM_BLOCK_CTRL_BYTE_SIZE) / 4U))
{ if ((u16Result <= u16MaxRecordNum[0U] + u16MaxRecordNum[1U]) &&\
for (i = 0U; i < u16Len; i++) (u16Result <= EEPROM_OVER_SEARCH_RECORD_NUM))
{ {
u32Data[i] = g_pstEEPROMBlock[u16BlockID].pu32Data[i + 1U]; if (u16RecordNum == 0U) /* Cross sector access */
} {
if (g_pstEEPROMBlock[i].u8SectorOffset)
u8Error = 0U; {
} u32DataAddrBase -= (uint32_t)g_pstEEPROMBlock[i].u16BlockSize;
} u16RecordNum = u16MaxRecordNum[0U];
if (u16RecordNum == 0U)
return u8Error; {
} u8Loop = 0U;
g_pstEEPROMBlock[i].u8Status = EEPROM_BLOCK_ERROR;
/* u16Len : DWord(32-bit) number to be written */ }
/* Retval 0 - OK 1 - Error */ else
uint8_t EEPROM_Write_Block_Data(uint16_t u16BlockID, uint32_t u32Data[], uint16_t u16Len) {
{ u16RecordNum -= 1U;
uint16_t i; }
}
uint8_t u8Error; else
uint16_t u16WordNum; {
uint16_t u16Result; u32DataAddrBase += g_pstEEPROMBlock[i].u16BlockSize;
uint32_t u32EndAddr; u16RecordNum = u16MaxRecordNum[1U];
if (u16RecordNum == 0U)
EEPROM_Ctrl_Data_un_t unCtrlData; {
u8Loop = 0U;
u8Error = 1U; g_pstEEPROMBlock[i].u8Status = EEPROM_BLOCK_ERROR;
if ((g_stEEPROMAccess.u8State == EEPROM_WR_STATE_IDLE) && \ }
(g_stEEPROMAccess.u16BlockNum > u16BlockID) && (u32Data != NULL) && (u16Len != 0U)) else
{ {
if (u16Len <= (g_pstEEPROMBlock[u16BlockID].u16BlockSize - EEPROM_BLOCK_CTRL_BYTE_SIZE) / 4U) u16RecordNum -= 1U;
{ }
g_stEEPROMAccess.u8State = EEPROM_WR_STATE_PROG; }
u16WordNum = g_pstEEPROMBlock[u16BlockID].u16BlockSize / 4U - 1U; /* CRC checksum is ignored */ }
else
if (g_pstEEPROMBlock[u16BlockID].u8Status == EEPROM_BLOCK_ACTIVE) {
{ u16RecordNum--;
g_pstEEPROMBlock[u16BlockID].u16RecordNum++; }
if (g_pstEEPROMBlock[u16BlockID].u16RecordNum >= g_pstEEPROMBlock[u16BlockID].u16MaxRecordNum) }
{ else
g_stEEPROMAccess.u8State = EEPROM_WR_STATE_ERASE; {
g_pstEEPROMBlock[u16BlockID].u16RecordNum = 0U; /* No correct data found, set error flag */
if (g_pstEEPROMBlock[u16BlockID].u8SectorOffset == 0U) u8Loop = 0U;
{ g_pstEEPROMBlock[i].u8Status = EEPROM_BLOCK_ERROR;
g_pstEEPROMBlock[u16BlockID].u8SectorOffset = 1U; }
} }
else }while(u8Loop);
{ }
g_pstEEPROMBlock[u16BlockID].u8SectorOffset = 0U; }
} }
} }
g_pstEEPROMBlock[u16BlockID].u16Index++; uint8_t EEPROM_Access_Busy(void)
unCtrlData.stField.u16Index = g_pstEEPROMBlock[u16BlockID].u16Index; {
unCtrlData.stField.u16IndexInv = 0xFFFFU - unCtrlData.stField.u16Index; return g_stEEPROMAccess.u8State;
g_pstEEPROMBlock[u16BlockID].pu32Data[0U] = unCtrlData.u32Word[0U]; }
}
else uint8_t EEPROM_Block_Access_Status(uint16_t u16BlockID)
{ {
g_stEEPROMAccess.u8State = EEPROM_WR_STATE_ERASE; uint8_t u8Status;
g_pstEEPROMBlock[u16BlockID].u16RecordNum = 0U;
g_pstEEPROMBlock[u16BlockID].u8SectorOffset = 0U; u8Status = EEPROM_BLOCK_ERROR;
g_pstEEPROMBlock[u16BlockID].u16Index = 0U; if (u16BlockID < g_stEEPROMAccess.u16BlockNum)
g_pstEEPROMBlock[u16BlockID].pu32Data[0U] = 0xFFFF0000UL; {
u8Status = g_pstEEPROMBlock[u16BlockID].u8Status;
for (i = 1U; i < u16WordNum; i++) }
{
g_pstEEPROMBlock[u16BlockID].pu32Data[i] = 0x00000000UL; return u8Status;
} }
g_pstEEPROMBlock[u16BlockID].u8Status = EEPROM_BLOCK_ACTIVE;
} /* u16Len : DWord(32-bit) number to be read */
/* Retval 0 - OK 1 - Error */
u16Len += 1U; uint8_t EEPROM_Read_Block_Data(uint16_t u16BlockID, uint32_t u32Data[], uint16_t u16Len)
for (i = 1U; i < u16Len; i++) {
{ uint16_t i;
g_pstEEPROMBlock[u16BlockID].pu32Data[i] = u32Data[i - 1U]; uint8_t u8Error;
}
u8Error = 1U;
u16Result = EEPROM_CRC_Calc(g_pstEEPROMBlock[u16BlockID].pu32Data, u16WordNum); if ((u16BlockID < g_stEEPROMAccess.u16BlockNum) && (u32Data != NULL) && (u16Len != 0U))
g_pstEEPROMBlock[u16BlockID].pu32Data[u16WordNum] = (uint32_t)u16Result; {
if ((g_pstEEPROMBlock[u16BlockID].u8Status == EEPROM_BLOCK_ACTIVE) && \
g_stEEPROMAccess.u32ProgAddr = g_pstEEPROMBlock[u16BlockID].u32BaseAddr; (u16Len <= (g_pstEEPROMBlock[u16BlockID].u16BlockSize - EEPROM_BLOCK_CTRL_BYTE_SIZE) / 4U))
g_stEEPROMAccess.u32ProgAddr += (uint32_t)g_pstEEPROMBlock[u16BlockID].u16SectorSize * (uint32_t)g_pstEEPROMBlock[u16BlockID].u8SectorOffset; {
g_stEEPROMAccess.u32ProgAddr += (uint32_t)g_pstEEPROMBlock[u16BlockID].u16BlockSize * (uint32_t)g_pstEEPROMBlock[u16BlockID].u16RecordNum; for (i = 0U; i < u16Len; i++)
g_stEEPROMAccess.u16ProgLen = g_pstEEPROMBlock[u16BlockID].u16BlockSize / 4U; {
g_stEEPROMAccess.pu32ProgData = g_pstEEPROMBlock[u16BlockID].pu32Data; u32Data[i] = g_pstEEPROMBlock[u16BlockID].pu32Data[i + 1U];
}
if (g_stEEPROMAccess.u8State == EEPROM_WR_STATE_ERASE)
{ u8Error = 0U;
u32EndAddr = g_stEEPROMAccess.u32ProgAddr + (uint32_t)g_pstEEPROMBlock[u16BlockID].u16SectorSize - 1UL; }
g_pfnEEPROMMemErase(g_stEEPROMAccess.u32ProgAddr, u32EndAddr); }
}
else return u8Error;
{ }
g_pfnEEPROMMemWrite(g_stEEPROMAccess.u32ProgAddr, g_stEEPROMAccess.pu32ProgData, (uint32_t)g_stEEPROMAccess.u16ProgLen);
} /* u16Len : DWord(32-bit) number to be written */
/* Retval 0 - OK 1 - Error */
u8Error = 0U; uint8_t EEPROM_Write_Block_Data(uint16_t u16BlockID, uint32_t u32Data[], uint16_t u16Len)
} {
} uint16_t i;
return u8Error; uint8_t u8Error;
} uint16_t u16WordNum;
uint16_t u16Result;
void EEPROM_Mem_Access_Complete_Callback(void) uint32_t u32EndAddr;
{
if (g_stEEPROMAccess.u8State == EEPROM_WR_STATE_ERASE) EEPROM_Ctrl_Data_un_t unCtrlData;
{
g_stEEPROMAccess.u8State = EEPROM_WR_STATE_PROG; u8Error = 1U;
g_pfnEEPROMMemWrite(g_stEEPROMAccess.u32ProgAddr, g_stEEPROMAccess.pu32ProgData, (uint32_t)g_stEEPROMAccess.u16ProgLen); if ((g_stEEPROMAccess.u8State == EEPROM_WR_STATE_IDLE) && \
} (g_stEEPROMAccess.u16BlockNum > u16BlockID) && (u32Data != NULL) && (u16Len != 0U))
else {
{ if (u16Len <= (g_pstEEPROMBlock[u16BlockID].u16BlockSize - EEPROM_BLOCK_CTRL_BYTE_SIZE) / 4U)
g_stEEPROMAccess.u8State = EEPROM_WR_STATE_IDLE; {
} g_stEEPROMAccess.u8State = EEPROM_WR_STATE_PROG;
} u16WordNum = g_pstEEPROMBlock[u16BlockID].u16BlockSize / 4U - 1U; /* CRC checksum is ignored */
static uint16_t EEPROM_CRC_Calc(uint32_t * pu32Data, uint16_t u16Len) if (g_pstEEPROMBlock[u16BlockID].u8Status == EEPROM_BLOCK_ACTIVE)
{ {
uint16_t i; g_pstEEPROMBlock[u16BlockID].u16RecordNum++;
if (g_pstEEPROMBlock[u16BlockID].u16RecordNum >= g_pstEEPROMBlock[u16BlockID].u16MaxRecordNum)
uint8_t u8CRCHi; {
uint8_t u8CRCLo; g_stEEPROMAccess.u8State = EEPROM_WR_STATE_ERASE;
uint8_t u8Index; g_pstEEPROMBlock[u16BlockID].u16RecordNum = 0U;
uint8_t *pu8DataByte; if (g_pstEEPROMBlock[u16BlockID].u8SectorOffset == 0U)
uint16_t u16CRCResult; {
g_pstEEPROMBlock[u16BlockID].u8SectorOffset = 1U;
u16CRCResult = 0xFFFFU; }
if (pu32Data != NULL) else
{ {
u8CRCHi = 0xFFU; g_pstEEPROMBlock[u16BlockID].u8SectorOffset = 0U;
u8CRCLo = 0xFFU; }
u16Len <<= 2U; /* u16Len = u16Len * 4U */ }
pu8DataByte = (uint8_t *)pu32Data;
g_pstEEPROMBlock[u16BlockID].u16Index++;
for (i = 0; i < u16Len; i++) unCtrlData.stField.u16Index = g_pstEEPROMBlock[u16BlockID].u16Index;
{ unCtrlData.stField.u16IndexInv = 0xFFFFU - unCtrlData.stField.u16Index;
u8Index = u8CRCLo ^ pu8DataByte[i]; g_pstEEPROMBlock[u16BlockID].pu32Data[0U] = unCtrlData.u32Word[0U];
u8CRCLo = u8CRCHi ^ g_u8EEPROMCRCTableH[u8Index]; }
u8CRCHi = g_u8EEPROMCRCTableL[u8Index]; else
} {
g_stEEPROMAccess.u8State = EEPROM_WR_STATE_ERASE;
u16CRCResult = (uint16_t)u8CRCHi; g_pstEEPROMBlock[u16BlockID].u16RecordNum = 0U;
u16CRCResult <<= 8U; g_pstEEPROMBlock[u16BlockID].u8SectorOffset = 0U;
u16CRCResult |= (uint16_t)u8CRCLo; g_pstEEPROMBlock[u16BlockID].u16Index = 0U;
} g_pstEEPROMBlock[u16BlockID].pu32Data[0U] = 0xFFFF0000UL;
return u16CRCResult; for (i = 1U; i < u16WordNum; i++)
} {
g_pstEEPROMBlock[u16BlockID].pu32Data[i] = 0x00000000UL;
}
g_pstEEPROMBlock[u16BlockID].u8Status = EEPROM_BLOCK_ACTIVE;
}
u16Len += 1U;
for (i = 1U; i < u16Len; i++)
{
g_pstEEPROMBlock[u16BlockID].pu32Data[i] = u32Data[i - 1U];
}
u16Result = EEPROM_CRC_Calc(g_pstEEPROMBlock[u16BlockID].pu32Data, u16WordNum);
g_pstEEPROMBlock[u16BlockID].pu32Data[u16WordNum] = (uint32_t)u16Result;
g_stEEPROMAccess.u32ProgAddr = g_pstEEPROMBlock[u16BlockID].u32BaseAddr;
g_stEEPROMAccess.u32ProgAddr += (uint32_t)g_pstEEPROMBlock[u16BlockID].u16SectorSize * (uint32_t)g_pstEEPROMBlock[u16BlockID].u8SectorOffset;
g_stEEPROMAccess.u32ProgAddr += (uint32_t)g_pstEEPROMBlock[u16BlockID].u16BlockSize * (uint32_t)g_pstEEPROMBlock[u16BlockID].u16RecordNum;
g_stEEPROMAccess.u16ProgLen = g_pstEEPROMBlock[u16BlockID].u16BlockSize / 4U;
g_stEEPROMAccess.pu32ProgData = g_pstEEPROMBlock[u16BlockID].pu32Data;
if (g_stEEPROMAccess.u8State == EEPROM_WR_STATE_ERASE)
{
u32EndAddr = g_stEEPROMAccess.u32ProgAddr + (uint32_t)g_pstEEPROMBlock[u16BlockID].u16SectorSize - 1UL;
g_pfnEEPROMMemErase(g_stEEPROMAccess.u32ProgAddr, u32EndAddr);
}
else
{
g_pfnEEPROMMemWrite(g_stEEPROMAccess.u32ProgAddr, g_stEEPROMAccess.pu32ProgData, (uint32_t)g_stEEPROMAccess.u16ProgLen);
}
u8Error = 0U;
}
}
return u8Error;
}
void EEPROM_Mem_Access_Complete_Callback(void)
{
if (g_stEEPROMAccess.u8State == EEPROM_WR_STATE_ERASE)
{
g_stEEPROMAccess.u8State = EEPROM_WR_STATE_PROG;
g_pfnEEPROMMemWrite(g_stEEPROMAccess.u32ProgAddr, g_stEEPROMAccess.pu32ProgData, (uint32_t)g_stEEPROMAccess.u16ProgLen);
}
else
{
g_stEEPROMAccess.u8State = EEPROM_WR_STATE_IDLE;
}
}
static uint16_t EEPROM_CRC_Calc(uint32_t * pu32Data, uint16_t u16Len)
{
uint16_t i;
uint8_t u8CRCHi;
uint8_t u8CRCLo;
uint8_t u8Index;
uint8_t *pu8DataByte;
uint16_t u16CRCResult;
u16CRCResult = 0xFFFFU;
if (pu32Data != NULL)
{
u8CRCHi = 0xFFU;
u8CRCLo = 0xFFU;
u16Len <<= 2U; /* u16Len = u16Len * 4U */
pu8DataByte = (uint8_t *)pu32Data;
for (i = 0; i < u16Len; i++)
{
u8Index = u8CRCLo ^ pu8DataByte[i];
u8CRCLo = u8CRCHi ^ g_u8EEPROMCRCTableH[u8Index];
u8CRCHi = g_u8EEPROMCRCTableL[u8Index];
}
u16CRCResult = (uint16_t)u8CRCHi;
u16CRCResult <<= 8U;
u16CRCResult |= (uint16_t)u8CRCLo;
}
return u16CRCResult;
}
...@@ -87,7 +87,11 @@ SECTIONS ...@@ -87,7 +87,11 @@ SECTIONS
.romsdata ROM(.sdata) :>. /* constant data to initialize variables in SDA area (copied to RAM at startup)*/ .romsdata ROM(.sdata) :>. /* constant data to initialize variables in SDA area (copied to RAM at startup)*/
.romtdata ROM(.tdata) :>. /* constant data to initialize variables in TDA area (copied to RAM at startup)*/ .romtdata ROM(.tdata) :>. /* constant data to initialize variables in TDA area (copied to RAM at startup)*/
.ROM.ramfunc ROM(.ramfunc) :>. /* program code to be copied to RAM (copied to RAM at startup) */ .ROM.ramfunc ROM(.ramfunc) :>. /* program code to be copied to RAM (copied to RAM at startup) */
/* Renesas FDL Program code sections */
.R_FDL_Text align(4) :>. /* FDL code in ROM */
.R_FDL_Const align(4) :>. /* FDL constants in ROM */
/* Start of internal RAM area (iRAM) */ /* Start of internal RAM area (iRAM) */
.data :>iRAM_0 /* initialized data */ .data :>iRAM_0 /* initialized data */
...@@ -104,7 +108,9 @@ SECTIONS ...@@ -104,7 +108,9 @@ SECTIONS
.tdata align(4) MAX_SIZE(0x0100) :>. /* initialized and zero-initialized data in TDA area */ .tdata align(4) MAX_SIZE(0x0100) :>. /* initialized and zero-initialized data in TDA area */
.ramfunc align(4) :>. /* program code in RAM area */ .ramfunc align(4) :>. /* program code in RAM area */
.stack align(4) pad(0x4000) :>. /* definition of stack size */ .stack align(4) pad(0x4000) :>. /* definition of stack size */
/* Renesas FDL data sections */
.R_FDL_Data :>. /* FDL data */
.heapbase align(4) :>. .heapbase align(4) :>.
.heap align(4) .heap align(4)
pad(MEMENDADDR(iRAM_0)-addr(.heapbase)) pad(MEMENDADDR(iRAM_0)-addr(.heapbase))
......
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
#include "RTE_ADC.h" #include "RTE_ADC.h"
#include "COM_CAN.h" #include "COM_CAN.h"
#include "UDS_Common.h" #include "UDS_Common.h"
#include "r_fdl_types.h"
/* Private typedef -----------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/
...@@ -89,6 +91,11 @@ extern uint32_t TestBackupRam; ...@@ -89,6 +91,11 @@ extern uint32_t TestBackupRam;
void Sys_Startup_Init(void) void Sys_Startup_Init(void)
{ {
uint8_t u8ResetFlag = 0;
uint32_t u32FDLDataFlag[4] = {0, 0, 0, 0};
uint32_t u32FDLBlank = 0;
Clock_Init(); Clock_Init();
/* Enable interrupts globally */ /* Enable interrupts globally */
enable_interrupt(); enable_interrupt();
...@@ -111,20 +118,37 @@ void Sys_Startup_Init(void) ...@@ -111,20 +118,37 @@ void Sys_Startup_Init(void)
Int_Flash_Init(); Int_Flash_Init();
EEPROM_Init();
BU98R10_Init(); BU98R10_Init();
/*EOL诊断 配置数据读取 DFLASH*/
ReadAllDFlashData();
/*读取K-LINE*/
ReadDTCEOLValue_Meter_K_LINE();
d_printf("Init complete!\n"); d_printf("Init complete!\n");
InitSeriFlashExternReadMode(); InitSeriFlashExternReadMode();
//APP_Startup_Init(Clock_Get_Startup_Mode());
u8ResetFlag = Clock_Get_Startup_Mode(); u8ResetFlag = Clock_Get_Startup_Mode();
if (u8ResetFlag == CLOCK_STARTUP_PWR_ON)
{
TYW_FDL_Init();
TYW_FDL_Flash_Read(0xFF20FF00 , u32FDLDataFlag, 4 );
if ((u32FDLDataFlag[0] == 0x66666666) && (u32FDLDataFlag[1] == 0x55555555) && (u32FDLDataFlag[2] == 0xA555A55A) && (u32FDLDataFlag[3] == 0X12345678))
{
}
else
{
u32FDLDataFlag[0] = 0x66666666;
u32FDLDataFlag[1] = 0x55555555;
u32FDLDataFlag[2] = 0xA555A55A;
u32FDLDataFlag[3] = 0X12345678;
TYW_FDL_Erase(0XFF200000, 0XFF20FFFF);
TYW_FDL_Write(0xFF20FF00 , u32FDLDataFlag, 4);
}
}
EEPROM_Init();
if (u32ResetFlag != 0xA55AA55AUL) if (u32ResetFlag != 0xA55AA55AUL)
{ {
u8ResetFlag = 0; u8ResetFlag = 0;
...@@ -138,6 +162,12 @@ void Sys_Startup_Init(void) ...@@ -138,6 +162,12 @@ void Sys_Startup_Init(void)
} }
} }
/*EOL诊断 配置数据读取 DFLASH*/
ReadAllDFlashData();
/*读取K-LINE*/
ReadDTCEOLValue_Meter_K_LINE();
/*30电初始化*/ /*30电初始化*/
APP_Startup_Init(u8ResetFlag); APP_Startup_Init(u8ResetFlag);
APP_Startup_Init(u8ResetFlag); APP_Startup_Init(u8ResetFlag);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment