RL78 Family EEPROM Emulation Library Pack01 User`s Manual

Add to My manuals
70 Pages

advertisement

RL78 Family EEPROM Emulation Library Pack01 User`s Manual | Manualzz

RL78 Family

EEPROM Emulation Library Pack 01

R01US0054EJ0102

Rev.1.02

Aug 02, 2013

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

1. 1 Basic Specifications of EEPROM Emulation

EEPROM emulation is a feature used to store data in the on-board flash memory in the same way as EEPROM.

During EEPROM emulation, the data flash library and EEPROM emulation library are used, and the data flash memory is written to and read from.

The data flash library is a software library used to perform operations on the data flash memory. The

EEPROM emulation library is a software library used to execute EEPROM emulation from a user-created program. The data flash library and EEPROM emulation library are placed in the code flash memory for use.

By calling the user access function processing (functions) provided by the EEPROM emulation library from a user-created program, use is possible without the awareness of data flash memory operations.

For the EEPROM emulation library Pack01, a one-bye identifier (data ID: 1 to 255) is assigned by the user for each data item, and reading and writing using any unit from 1 to 255 bytes are possible on an assigned identifier basis. (Up to 255 data items assigned on an identifier basis can be handled.)

Note that four or more continuous block area of data flash memory are used to store the data. These blocks are called EEPROM emulation blocks.

Data written by EEPROM emulation is divided into reference data and user-specified data, and the reference data is written to the target blocks from the lower block address, while the user data is written from the higher block address.

Figure 1-1 shows the relationship between the EEPROM emulation library and data flash library, Figures 1-2 and 1-3 show a memory map and data structure example, and Figures 1-4, 1-5, and 1-6 show block usage method and transition examples. Table 1-1 shows each item to be specified for EEPROM emulation and the range of the item.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 6 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-1. Relationship between EEPROM Emulation Library and Data Flash Library

User-created program

The flash data library must be initialized before using the EEPROM emulation library (by executing the FAL_Init function).

EEPROM emulation library (EEL)

Flash data library (FDL)

Hardware (data flash memory)

Figure 1-2. Example of Memory Map

• The following shows an example for the R5F100 where the user-created program, data flash library, and

EEPROM emulation library are placed in the code flash memory, the EEPROM emulation blocks are specified for the data flash memory, and the defined user data (user data A, user data B, and user data C) is written in order to use the data flash memory as EEPROM emulation blocks.

Special function registers SFR

General-purpose registers

EEPROM emulation block

(active block)

User data A (1)

Internal high-speed RAM

User data B (1)

Mirror

F1FFFH

F1000H

Data flash memory (4 KB)

Not usable

User data C (1)

User data A (2)

User data C (2)

User data A (3)

Data area

Special function registers (2nd SFR)

1 KB/4 blocks

Unused area

Data is added from both directions

Not usable

Data flash memory

Block 3

Data flash memory

Block 2

Data flash memory

Block 1

Data flash memory

Block 0

Reference data A (3)

Reference data C (2)

Reference data A (2)

Reference data C (1)

Reference data B (1)

Reference data A (1)

Reserved area

Block management area

Reference area

00000H

Code flash memory

User-created program

+

EEPROM emulation library

+ flash data library

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 7 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-3. EEPROM Emulation Block Details

• In this data structure example, user data of various defined sizes (user data A, user data B, and user data C) are written in a specified sequence (write sequence: user data A

→ user data B → user data A → user data C).

User data is written from the higher address and management data is written from the lower address, and the last written user data becomes valid.

4 bytes

1 byte

Data area

800H

7E4H

1 byte 1 byte

User data A (1)

User data B (1)

1 byte

User data A (2)

User data C (1)

Direction of adding data

Invalid data

Latest/valid data

Latest/valid data

Latest/valid data

Unused area

EEPROM emulation block

(Reference example of active block)

40H

Reference area

20H

Block management area

00H

Direction of adding data

DCS (data checksum)

Index number (widx) RCS

DCS (data checksum)

Index number (widx) RCS

DCS (data checksum)

Index number (widx) RCS

DCS (data checksum)

Index number (widx) RCS

Data ID (C)

Data ID (A)

Data ID (B)

Data ID (A)

DCS

DRP

DCS

DRP

DCS

DRP

DCS

DRP

Reference data C (1)/valid

Reference data A (2)/valid

Reference data B (1)/valid

Reference data A (1)/invalid

Reserved area

10H

Block status flag

1 byte 1 byte 1 byte 1 byte

Start of block

4 bytes

DCS:

D

ata

C

heck

S

um

RCS:

R

eference

C

heck

S

um

DRP:

D

ata

R

eference

P

ointer

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 8 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-4. Example of Expanding Active EEPROM Emulation Block

• When writing specified data, if there is not enough free space in the active block being used to write the data, the number of active blocks is increased and the specified data is written to the new active block.

EEPROM emulation block

(the first active block )

User data A (1)

User data B (1)

The specified data is written after increasing the number of active blocks .

EEPROM emulation block

(the new active block resulting from increasing the number of active blocks)

User data B (latest)

User data C (1)

User data A (2)

User data C (2)

User data A (3)

Data area

.

.

.

Unused area

.

.

.

Reference data A (3)

Reference data C (2)

Reference data A (2)

Reference data C (1)

Reference data B (1)

Reference data A (1)

Reserved area

Block management area

Reference area

There is not enough free space in the first active block to write the specified user data.

×

Unused area

Reference data B (latest)

Reserved area

Block management area

User data B (latest)

Specified write data

The prepared block is changed to an active block to increase the number of active blocks .

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 9 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-5. EEPROM Emulation Block Usage Method (Four Blocks)

• For EEPROM emulation, blocks 0 to 3 of the data flash memory are added in order as active or prepared blocks, and then, when the last block (block 3) is reached, the first block (block 0) is specified as the next block to loop through the blocks.

Block 0

First address

F1000H

Block 3

Last address

F1FFFH

EEPROM emulation blocks

(data flash: 4 blocks, 4 KB)

EEPROM emulation block adding direction

(usage direction)

Active block adding direction

Prepared block adding direction

Block 0 Block 1 Block 2 Block 3

Data area

Data area

Unused Unused

Unused

Reference area

Reserved area

Management data

Active block

(first)

Reserved area

Management data

Prepared block

(last)

Reserved area

Management data

Prepared block

(first)

Unused

Reference area

Reserved area

Management data

Active block

(last)

When block 3 is reached, the next block becomes block 0 (to loop through the blocks).

Active block: The currently used block

Prepared block: A block that has been prepared and is ready for use

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 10 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-6 (A). EEPROM Emulation Block Transition Example

• The following shows an example of EEPROM emulation blocks to which nothing was written after initializing them.

EEPROM emulation blocks

(data flash: 4 blocks, 4 KB)

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Reserved area

Management data

Active block

Reserved area

Management data

Prepared block

Reserved area

Management data

Prepared block

Reserved area

Management data

Prepared block

Figure 1-6

(B). EEPROM Emulation Block Transition Example

• If only writing processing is executed continuously, the number of active blocks is increased until a certain number of blocks (the number of active blocks such that there are two or fewer prepared blocks remaining) is reached.

EEPROM emulation blocks

(data flash: 4 blocks, 4 KB)

Active block adding direction

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Data area

Data area

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Unused

Reference area

Reserved area

Management data

Active block

Unused

Reference area

Reserved area

Management data

Active block

Reserved area

Management data

Prepared block

Reserved area

Management data

Prepared block

Page 11 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-6

(C). EEPROM Emulation Block Transition Example

• If only writing processing is executed continuously during EEPROM emulation, and the number of active blocks is increased when two or fewer prepared blocks remain, the valid data in the oldest active block is copied to the latest active block, and the oldest active block is erased.

EEPROM emulation blocks

(data flash: 4 blocks, 4 KB)

Data area

Data area

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Reserved area

Management data

Prepared block

Unused

Reference area

Reserved area

Management data

Active block

Reference area

Reserved area

Management data

Active block

Reserved area

Management data

Prepared block

Erased The data is moved.

The specified data is written.

Table 1-1. Settings of Written Data and Usable Ranges

<R>

Item

User data length

Amount of stored user data

Note 1

Data ID range

Number of EEPROM emulation blocks

Note 2

Recommended user data size

Note 1

1 to 255

1 to 255

1 to 255

4 to 255

Range Remark

Number of data types

980

× total number of blocks × 1/4 −

980/2 bytes

This also includes the management reference data provided during writing.

Notes 1. The total size of the user data must be such that it is possible to write all the data into within two

EEPROM emulation blocks. Therefore, the range used for the number of stored user data items differs depending on the size of the stored user data. It is also necessary to consider the size of the reference data provided for each data item for management use when determining the total size. For details about the number of stored user data items and total size, see 1.2.4 Number of stored user data items and

total user data size.

2. EEPROM emulation blocks cannot be set more than maximum number of blocks of on-board data flash memory.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 12 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

1. 2 EEPROM Emulation Operation Flow

To use EEPROM emulation from a user-created program, it is necessary to initialize the EEPROM emulation library and execute functions that perform operations such as reading and writing on EEPROM emulation blocks.

Figure 1-7 shows the overall status transitions, and Figure 1-8 shows an operation flow for using basic features.

When using EEPROM emulation, incorporate EEPROM emulation into user-created programs by following this flow.

Figure 1-7. EEPROM Emulation Status Transitions

Reset or Power ON uninitialized

FAL_Init()

EEL_Init() destroy RAM data closed

EEL_Open()

EEL_Close() status

: OK status

: ERROR

EEL_CMD_FORMAT opened status

: OK

Format executing busy

EEL_CMD_STARTUP status

: ERROR

Startup executing busy

Shutdown executing busy status

: OK EEL_CMD_STARTUP

EEL_CMD_FORMAT

EEL_CMD_WRITE

EEL_CMD_READ

EEL_CMD_CLEANUP started status

: OK status

: ERROR

EEL_CMD_SHUTDOWN status

: ERROR

EEPROM commnad executing busy

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 13 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

[Overview of status transitions]

To use EEPROM emulation library to manipulate the data flash memory, it is necessary to execute the provided functions in order to advance the processing.

(1) uninitialized

This is the status after turning the power on or resetting. The system also transitions to this status after executing flash self programming library processing.

(2) closed

This is the status in which the data has been initialized (the status in which operations on the data flash memory are stopped) to execute the FAL_Init() and EEL_Init() functions and then EEPROM emulation. To execute flash self programming library, STOP mode, or HALT mode processing after executing EEPROM emulation, execute EEL_Close in the opened status to switch to the closed status.

(3) opened

This status is switched to by executing EEL_Open in the closed status and makes it possible to perform operations on the data flash memory. It is not possible to execute flash self programming library, STOP mode, or HALT mode processing until EEL_Close is executed and the system switches to the closed status.

(4) started

This status is switched to by executing the EEL_CMD_STARTUP command in the opened status and makes it possible to execute EEPROM emulation. Writes and reads that use EEPROM emulation are performed in this status.

(5) busy

This is the status used when executing a specified command. The status that is switched to differs depending on which command is executed and how it terminates.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 14 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-8. Basic Operation Flow of EEPROM Emulation (When Using Enforced Mode)

START

FAL_Init()

EEL _Init()

<1>

<2>

Start of EEPROM emulation

Initialization processing

EEL _Open () <3>

EEL_Execute()

EEL_CMD_STARTUP command

<4>

Start processing

Executable status loop

Processing (switch)

Write Read

EEL_Execute()

EEL_CMD_WRITE command

<5>

EEL_ Execute()

EEL_ CMD_READ command

<7>

EEL_Execute()

EEL_CMD_READ command

<6>

Main processing

Can continue as executable when there is no need to end.

EEL_Execute()

EEL _CMD_SHUTDOWN command

<8>

EEL_Close() <9>

End processing

End of operation

No

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

RAM reset required when restarting?

<10>

Yes

Page 15 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

[Overview of basic operation flow]

For EEPROM emulation, the method for executing the EEL_Execute function differs depending on the mode setting.

The following three modes are available: the enforced mode, timeout mode, and polling mode. For details about the differences in the execution method for each mode, see EEL_Execute function in 3.2 EEPROM Emulation

Library Functions.

<1> data Flash library initialization processing (FAL_Init)

Because it is necessary to initialize the data flash library parameters (RAM) if using the EEPROM emulation library to access the data flash memory, the FAL_Init function must be executed in advance. If flash self programming library processing was executed after this initialization finished, the initialization processing must be re-executed.

<2> EEPROM emulation library initialization processing (EEL_Init)

Initialize the parameters (RAM) used by the EEPROM emulation library.

<3> EEPROM emulation preparation processing (EEL_Open)

Set the data flash memory to a status (opened) for which control is enabled to execute EEPROM emulation.

<4> EEPROM emulation execution start processing (EEL_Execute: EEL_CMD_STARTUP command)

Set the system to a status (started) in which EEPROM emulation can be executed.

<5> EEPROM emulation data write processing (EEL_Execute: EEL_CMD_WRITE command)

Write the specified data to an EEPROM emulation block.

<6> EEPROM emulation data confirmation processing (EEL_Execute: EEL_CMD_READ command)

Read data, and then make sure that the data was written correctly by comparing it to the original data.

<7> EEPROM emulation data read processing (EEL_Execute: EEL_CMD_READ command)

Read written data.

<8> EEPROM emulation execution stop processing (EEL_Execute: EEL_CMD_SHUTDOWN command)

Set the EEPROM emulation operation to the stopped status (opened).

<9> EEPROM emulation end processing (EEL_Close)

Set the data flash memory to a status (closed) for which control is disabled to stop EEPROM emulation.

<10> Confirmation before re-executing EEPROM emulation

If reinitializing the RAM is necessary before re-executing EEPROM emulation, such as when executing flash self programming after EEPROM emulation stops, use the FAL_Init function to re-execute the initialization processing.

1. 2. 1 EEPROM Emulation Blocks

The EEPROM emulation library Pack01 uses four or more block data flash memory as EEPROM emulation blocks.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 16 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

1. 2. 2 Data structure

The data flash memory is written to in word (four-byte) units. Therefore, when the EEPROM emulation library writes to the data flash memory, the data length is always adjusted to word (four-byte) units.

In addition, when writing user data, because the reference data for managing data is also written, when calculating the capacity required for writing, the two words (eight bytes) of management reference data must be added to the size of the user data in words. Figures 1-9 to 1-11 show an example of the data structure used when user data is written to the data flash memory.

Figure 1-9. Data Length and Data Structure Example 1 (When User Data Is 8 Bytes)

4 bytes = 1 word

1 byte 1 byte 1 byte 1 byte

User data User data: 8 bytes

Reference data (8 bytes)

DCS

DRP

+

DCS (data checksum)

Index number (widx) RCS Data ID

Total size: 4 words (16 bytes) = reference data: 2 words (8 bytes) + [user data (8 bytes)/word size (4 bytes)]

* Change the user data to word units.

Figure 1-10. Data Length and Data Structure Example 2 (When User Data Is 6 Bytes)

4 bytes = 1 word

1 byte 1 byte 1 byte 1 byte

User data User data: 6 bytes

0xFF

Invalid data

0xFF

Reference data (8 bytes)

DCS

DRP

+

DCS (data checksum)

Index number (widx) RCS Data ID

Total size: 4 words (16 bytes) = reference data: 2 words (8 bytes) + [user data (6 bytes)/word size (4 bytes)]

* Change the user data to word units. (Round any fractions up to the nearest integer.)

Page 17 of 70 R01US0054EJ0102 Rev.1.02

Aug 02, 2013

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-11. Data Length and Data Structure Example 3 (When User Data Is 21 Bytes)

4 bytes = 1 word

1 byte 1 byte 1 byte 1 byte

User data

User data: 21 bytes

0xFF 0xFF 0xFF

Invalid data

Reference data (8 bytes)

DCS

DRP

+

DCS (data checksum)

Index number (widx) RCS Data ID

Total size: 8 words (32 bytes) = reference data: 2 words (8 bytes) + [user data (21 bytes)/word size (4 bytes)]

* Change the user data to word units. (Round any fractions up to the nearest integer.)

(1) DRP

This stands for data reference pointer. This area records the ID of the recorded user data and the reference position.

(2) Index number (widx)

This is the user data index number (reference position).

(3) RCS

This stands for reference checksum. This is the (8-bit) checksum value for the DRP.

(4) Data ID

This is a unique ID for the data being used during EEPROM emulation. User-specified IDs

Note

are registered.

(5) DCS

This stands for data checksum. This is the (32-bit) checksum value for the user data and reference data.

Note Before specifying a data ID, it must be registered in the descriptor table.

For details, see 2.3 Initial Values to Be Set by User.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 18 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

1. 2. 3 Block status flags

The block status flags start at the beginning of the block and include the P flag, A flag, I flag, and X flag, each of which is four bytes, for a total of 16 bytes of data. This data indicates the EEPROM emulation block status, and the combination of flags indicates the block status.

Figure 1-12 shows the placement status of flags, and Table 1-2 shows the combination status of flags.

Figure 1-12. Block Status Flag Placement Positions

10H

00H

X flag

I flag

A flag

P flag

Block status flags

Block start address

4 bytes

Table 1-2. Overview of Block Status Flags

P Flag

55555555H

55555555H

55555555H

Block Status Flag

A Flag I Flag

FFFFFFFFH

55555555H

55555555H

Data other than the above

FFFFFFFFH

FFFFFFFFH

00000000H

− − −

X Flag

FFFFFFFFH

FFFFFFFFH

FFFFFFFFH

FFFFFFFFH

Other than

FFFFFFFFH

Status

Prepared

Active

Inactive

Use prohibited

Note

Note A block for which use has been prohibited cannot be reused.

Description

This block is ready to be written.

This block is being used.

Inactive block

This block cannot be written.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 19 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

1. 2. 4 Number of stored user data items and total user data size

The following restriction applies to the total size of user data that can be used for EEPROM emulation: The total size of the user data must be such that it is possible to write all the data into within two EEPROM emulation blocks. Therefore, the number of stored data items that can be used differs depending on the size of user data that is actually stored. In addition, because it is not possible to place stored user data such that one data item extends across multiple blocks, if the total size necessary to write the user data exceeds one block, it is also necessary to consider the maximum size of an area for which use might not be possible if one block is exceeded.

The following shows how to calculate the size that can be used when actually writing user data, as well as the total user data size, and Figure 1-13 shows the size concepts when the total user data size is more than

<R>

<R>

<R>

<R> one blocks.

• Maximum usable size of one block that can be used to write the user data

Size of one block of data flash memory:

Size required for EEPROM emulation block management:

1, 024 bytes

32 bytes

Free space necessary as termination information (separator): 12 bytes

Maximum usable size of one block = 1, 024 bytes

− 32 bytes − 12 bytes = 980 bytes

• Maximum size and recommended size

The maximum size is the total of the usable sizes of EEPROM emulation blocks. The recommended size is less than the maximum size to account for problems such as writing not being possible due to momentary power loss and other issues. It is recommended to only use within a value subtracting half a block capacity from the overall capacity.

Maximum size = 980 bytes ×number of EEPROM emulation blocks ×1/4

Recommended size = maximum size

− 980/2

• Calculating the size for writing each user data item

Note

Size of each written user data item = data size (a size in bytes adjusted to word units) + reference data size (8 bytes)

• Calculating the basic total user data size

Basic total size = (user data 1 + 8) + (user data 2 + 8) ... + (user data n + 8)

• Calculating the total size when the basic total user data size exceeds the maximum size of one block

If the basic total user data size exceeds 988 bytes, the maximum usable size of one block, it is necessary to include the maximum size that might become unusable in the calculation when increasing the number of active blocks.

Total size when more than one blocks are used = basic total size + ((largest user data size + 8)

− minimum writing unit for EEPROM emulation (4 bytes)) × (number of necessary blocks

− 1)

Note For details, see 1.2.2 Data structure.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 20 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-13. Size Concepts When Total User Data Size Is Two Blocks (Which Exceeds One Block)

• The size of the user data must fit within a quarter of EEPROM emulation blocks when recording all the data, but, if the total user data size does not fit in one block, it is necessary to include the maximum size that might become unusable in the calculation when increasing the number of active blocks.

The maximum size that might become unusable is equal to the size of the largest user data that cannot be written.

EEPROM emulation block

(the first used active block)

The number of active blocks is increased to write new data.

EEPROM emulation block

(the first active block resulting from increasing the number of active blocks)

Maximum size of user data

User data that has been written

Data area

This area becomes unusable when the new active block is added.

Unused area

×

Reference data that has been written

Reference area

Reserved area

Block management area

Maximum size of user data (including the reference data)

The data that did not fit in the first block is written to the added active block, but the free space that was in the first active block before increasing the number of active blocks becomes unusable.

Unused area

Reference data

Reserved area

Block management area

Maximum size required for writing = largest user data size + reference data (8 bytes)

Maximum size that might become unusable = maximum size required for writing

− size of the minimum writing unit for EEPROM

Total size when 2 blocks are used = emulation (4 bytes) basic total size + maximum size that might become unusable

Page 21 of 70 R01US0054EJ0102 Rev.1.02

Aug 02, 2013

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

1. 3 Initializing EEPROM Emulation Blocks

To use the data flash memory for the EEPROM emulation library, it is necessary to initialize the blocks as

EEPROM emulation blocks. If there are blocks that need to be initialized, an

EEL_ERR_POOL_INCONSISTENT error occurs when the EEL_CMD_STARTUP command is executed because there are no active EEPROM emulation blocks. To make the EEPROM emulation blocks usable, it is necessary to initialize the blocks by executing the EEL_CMD_FORMAT command.

In addition, if it becomes necessary to change the initial settings, such as because the data flash memory area is corrupted or because user data is added after initialization, or it otherwise becomes impossible to continue using the EEPROM emulation blocks in their current status, or if you just want to perform initialization, initialization can be performed at any time by executing the EEL_CMD_FORMAT command.

Figures 1-14 and 1-15 show the initialization flow and block status transitions used when the

EEL_ERR_POOL_INCONSISTENT error occurs upon executing the EEL_CMD_STARTUP command, and

Figures 1-16 and 1-17 show the flow and block status transitions used when performing initialization at an arbitrary time.

Figure 1-14. Initialization Flow When EEL_ERR_POOL_INCONSISTENT Error Occurs

(When Using Enforced Mode)

START

FAL_Init()

EEL_Init()

EEL_Open()

EEPROM emulation block initialization processing

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

EEL_Execute()

EEL_CMD_STARTUP command

Command execution status

Error: EEL_ERR_POOL_INCONSISTENT

EEL_Execute()

EEL_CMD_FORMAT command

Command execution status

Normal end: EEL_OK

Other

Perform the necessary processing according to the command execution status.

An error occurs.

Check the settings and device status.

Page 22 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-15. Example Block Status Transitions When Initialization Is Performed Upon Occurrence of

EEL_ERR_POOL_INCONSISTENT Error

EEPROM emulation blocks

(data flash: 4 blocks, 4 KB)

Block status before using EEPROM emulation

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Inactive block

Inactive block

Inactive block

Inactive block

The FORMAT command is executed.

EEPROM emulation blocks

(data flash: 4 blocks, 4 KB)

Block status after executing the FORMAT command

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Reserved area

Management data

Active block

Reserved area

Management data

Prepared block

Reserved area

Management data

Prepared block

Reserved area

Management data

Prepared block

Page 23 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-16. Flow When Performing Initialization at Arbitrary Time (When Using Enforced Mode)

START

FAL_Init()

EEL_Init()

EEL_Open()

EEPROM emulation block initialization processing

EEL_Execute()

EEL_CMD_FORMAT command

Command execution status

EEL_OK: Normal end

To the next process

An error occurs.

Check the settings and device status.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 24 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-17. Example Block Status Transitions When Used EEPROM Emulation Blocks Are Initialized at

Arbitrary Time

EEPROM emulation blocks

(data flash: 4 blocks, 4 KB)

Example blocks used during

EEPROM emulation

Data area

Data area

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Reserved area

Management data

Prepared block

Unused

Reference area

Reserved area

Management data

Active block

Reference area

Reserved area

Management data

Active block

Reserved area

Management data

Prepared block

The FORMAT command is executed.

EEPROM emulation blocks

(data flash: 4 blocks, 4 KB)

Block status after executing the FORMAT command

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Reserved area

Management data

Active block

Reserved area

Management data

Prepared block

Reserved area

Management data

Prepared block

Reserved area

Management data

Prepared block

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 25 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

1. 4 Adjusting EEPROM Emulation Blocks

When writing to the EEPROM emulation blocks, a prepared block is erased each time an active block is added, but, if it is necessary to add an active block when there are two or fewer prepared blocks remaining, the active block is added, the valid data remaining in the old block is moved, and the old block is erased before writing the specified data. If writing is performed when erasing a block is required, the time necessary to move the data and erase the block is added to the time necessary for writing.

If this additional processing time is not permissible, it is possible to perform maintenance at a time that will not adversely affect the system in order to avoid moving and erasing data at the same time when high-priority data must be written.

To perform maintenance, either adjust blocks by executing the EEL_CMD_CLEANUP command or execute the maintenance mode processing of the EEL_Handler function.

Figure 1-18 shows an example of the block status when moving and erasing data upon adding an active block, and Figure 1-19 shows how the processing time is changed according to the block status when writing data.

Figure 1-18. Example Block Status When Moving and Erasing Data upon Adding Active Block

EEPROM emulation blocks

(data flash: 4 blocks, 4 KB)

If there are few prepared blocks remaining when an active block is added, the old block is erased.

Data is written to add the active block.

Data area

Data area

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Unused area

(ALL 0xFF)

Reserved area

Management data

Active

Prepared block

Unused

Reference area

Reserved area

Management data

Active block

Reference area

Reserved area

Management data

Prepared

Active block

Reserved area

Management data

Prepared block

Data is moved.

Data is erased to create a prepared block, and prepared block writing is performed.

After all the processing finishes, the specified data is written.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 26 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-19. Changes in Processing Time According to Block Status When Writing Data (When Using

Enforced Mode)

Command execution status Change in the writing operation and time according to the block status

WRITE command processing

When only performing writing

When performing writing while adding an active block

When performing writing while adding a block and erasing data

EEL_Execute()

WRITE command processing

Processing to write the specified data

Active block creation

Processing to write the specified data

Active block creation

The valid data in the old active block is moved

(when the processing occurs).

When an active block is added, how long it takes for writing to finish differs depending on the block status.

Old block erasure processing

Function execution timing

Processing completion timing

Difference compared to when only writing is performed

Prepared block creation

Processing to write the specified data

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 27 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

1. 4. 1 Adjusting blocks by using EEL_CMD_CLEANUP command

Blocks can be adjusted by executing the EEL_CMD_CLEANUP command from the EEL_Execute function.

Because this feature moves all the data to the latest newly created active block even if there is capacity remaining in the latest active block, the possible number of rewrites decreases by worth of data of blocks necessary to store data, but the feature makes it possible to change to a status in which there is only valid data

(a status in which invalid data does not exist).

Figure 1-20 shows the flow when executing the EEL_CMD_CLEANUP command, and Figure 1-21 shows the block status after executing the EEL_CMD_CLEANUP command.

Figure 1-20. Operation Flow of EEL_CMD_CLEANUP Command (When Using Enforced Mode)

START

FAL_Init()

EEL_Init()

EEL_Open()

EEL_Execute()

EEL_CMD_STARTUP command

Command execution status

Normal end: EEL_OK

EEL_Execute()

EEL_CMD_CLEANUP command

Other

Perform the necessary processing according to the command execution status.

Block adjustment processing

Command execution status

Normal end: EEL_OK

Other

To the next process

Perform the necessary processing according to the command execution status.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 28 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-21. Adjusting Blocks by Using EEL_CMD_CLEANUP Command

EEPROM emulation blocks

(data flash: 4 blocks, 4 KB)

Example block status before executing the

CLEANUP command

Data area

Unused area

(ALL

0xFF)

Data area

Reserved area

Management data

Prepared block

Unused

Reference area

Reserved area

Management data

Active block

Unused area

(ALL

0xFF)

Unused area

(ALL

0xFF)

Reference area

Reserved area

Management data

Active block

Reserved area

Management data

Prepared block

The CLEANUP command is executed.

EEPROM emulation blocks

(data flash: 4 blocks, 4 KB)

A new active block is added, and the valid data in all the old active blocks is moved to the latest active block. Blocks for which moving the data finishes are erased and changed to prepared blocks.

Unused area

(ALL

0xFF)

Unused area

(ALL

0xFF)

Reserved area

Management data

Prepared block

Reserved area

Management data

Prepared block

Data area

Unused area

(ALL

0xFF)

Reserved area

Management data

Prepared block

Unused area

(ALL

0xFF)

Reference area

Reserved area

Management data

Active block

Erased Erased

The latest data is moved.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 29 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

1. 4. 2 Adjusting blocks by using EEL_Handler function (maintenance mode)

Block adjustment processing can be automatically performed by executing the EEL_Handler function while no commands are executing. This is called the maintenance mode. When the EEL_Handler function is executed while there are no commands to execute, the block status is checked, block adjustment is judged to be necessary if the number of active blocks exceeds the specified initial value

EEL_REFRESH_BLOCK_THRESHOLD (described in 2.3 Initial Values to Be Set by User), all necessary data in old active blocks is moved to the latest block, and the unnecessary blocks are erased and changed to prepared blocks.

The processing can be interrupted in the maintenance mode. If a new command is executed by the

EEL_Execute function, the maintenance mode is paused, and executing the newly specified command is prioritized. To judge whether maintenance mode processing is being executed, it is necessary to execute the separate EEL_GetDriverStatus function and check the execution status of the EEL_Handler function. If nothing is being performed even when the EEL_Handler function is executed four times, adjustment is finished

(the adjustment completion status).

Figure 1-22 and Table 1-3 show how to check the execution status of the EEL_Handler function, Figures

1-23 to 1-26 show an execution flow example, and Figure 1-27 shows the block transitions when the maintenance mode processing finishes (the adjustment completion status).

Figure 1-22. Flow for Checking Execution Status of EEL_Handler Function

EEL_Handler()

EEL_GetDriverStatus()

EEL_Handler()

execution status

Command execution status: EEL_OK eel_operation_status_t: EEL_OPERATION_IDLE

Command execution and the maintenance mode processing have finished.

Command execution status: EEL_BUSY eel_operation_status_t: EEL_OPERATION_BUSY

A command is being executed.

Command execution status: EEL_OK eel_operation_status_t: EEL_OPERATION_BUSY

Maintenance is being performed.

Table 1-3. EEL_Handler Function Execution Status

EEL_Handler()

Command

Execution Status

EEL_OK

EEL_GetDriverStatus() eel_operation_status_t Status

EEL_OPERATION_IDLE

Description

EEL_OK

EEL_BUSY

EEL_OPERATION_BUSY

EEL_OPERATION_BUSY

This is the command execution and maintenance mode processing completion status.

(This includes when the maintenance mode processing is paused.)

If all the results are this status when the EEL_Handler function is executed four times, adjustment is complete.

Maintenance mode processing is being executed.

A command is being executed.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 30 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-23. Maintenance Mode Execution Flow (Example of Execution Until System Enters Adjustment

After the STARTUP command finishes

Completion Status)

EEL_Handler()

EEL_GetDriverStatus()

Other

EEL_Handler() execution status

If the statuses are as follows four times

Command execution status: EEL _OK eel _operation _status_t: EEL _OPERATION_IDLE

The command execution status indicates an error.

Adjustment completion status

To the next process

Perform the necessary processing according to the command execution status.

Figure 1-24. Execution Flow When Performing Adjustment After Executing EEL_CMD_WRITE Command

(Adjustment Completion Status)

EEL_Execute()

EEL_CMD_WRITE command

Command execution status

Normal end: EEL_OK

Block adjustment processing

EEL_Handler()

Other

EEL_GetDriverStatus()

EEL_Handler()

execution status

If the statuses are as follows four times

Command execution status: EEL_OK eel_operation_status_t: EEL_OPERATION_IDLE

Other

Perform the necessary processing according to the command execution status.

The command execution status indicates an error.

Adjustment completion status

To the next process

Perform the necessary processing according to the command execution status.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 31 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-25. Execution Flow When Performing Adjustment upon Starting EEPROM Emulation (Adjustment

Completion Status)

START

FAL_Init()

EEL_Init()

EEL_Open()

EEL_Execute()

EEL_CMD_STARTUP command

Command execution status

Normal end: EEL_OK Other

Perform the necessary processing according to the command execution status.

Block adjustment processing

EEL_Handler()

Other

EEL_GetDriverStatus()

EEL_Handler() execution status

If the statuses are as follows four times

Command execution status: EEL _OK eel _operation _status_t: EEL _OPERATION_IDLE

The command execution status indicates an error.

Adjustment completion status

To the next process

Perform the necessary processing according to the command execution status.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 32 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-26. Example Flow for Executing Command and Maintenance Mode Processing in Polling Mode

START

FAL_Init()

EEL_Init()

EEL_Open()

EEL_Execute()

EEL_CMD_STARTUP command

Various events

Polling processing (user processing loop)

Status and event judgment (user processing)

Judgment processing (switch)

Write

EEL_Execute()

EEL_CMD_WRITE command

Event parameter specification

Read

EEL_Execute()

EEL_CMD_READ command

Event processing

(user processing)

Polling processing

No processing

Processing status judgment (user processing)

Can continue as executable when there is no need to end.

EEL_Execute()

EEL _CMD_SHUTDOWN command

EEL_Close()

END

EEL_Handler()

EEL_GetDriverStatus()

The command is executed, as well as maintenance processing if there is time.

To check the status every time, also call EEL_GetDriverStatus().

Block adjustment processing

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 33 of 70

RL78 Family

EEPROM Emulation Library Pack 01

CHAPTER 1 OVERVIEW OF EEPROM EMULATION

Figure 1-27. Example of Block Adjustment in EEL_Handler Function Maintenance Mode (Adjustment

Completion Status)

EEPROM emulation blocks

(data flash: 4 blocks, 4 KB)

Block status before executing the maintenance mode processing of the EEL_Handler function

Data area

Data area

Unused

Unused area

(ALL

0xFF)

Unused area

(ALL

0xFF)

Unused

Reference area

Reserved area

Management data

Active block

Reference area

Reserved area

Management data

Active block

(latest)

Reserved area

Management data

Prepared block

Reserved area

Management data

Prepared block

Full maintenance execution

EEPROM emulation blocks

(data flash: 4 blocks, 4 KB)

Block status after the maintenance processing is completely executed (when the value of

EEL_REFRESH_BLOCK_THRESHOLD is 1)

Data area

Unused area

(ALL

0xFF)

Unused area

(ALL

0xFF)

Unused area

(ALL

0xFF)

Unused

Reserved area

Management data

Prepared block

Reference area

Reserved area

Management data

Active block

(latest)

Reserved area

Management data

Prepared block

Reserved area

Management data

Prepared block

Erased

The latest data is moved.

R01US0054EJ0102 Rev.1.02

Aug 02, 2013

Page 34 of 70

advertisement