Abstract:
A microcomputer retains a group definition table associating the sector sections created by dividing all sectors into multiple sections under a given condition with different memory regions on a flash memory, respectively. A memory control section makes reference to the group definition table to identify a memory region corresponding to a specified sector, and searches the identified memory region range for a physical address corresponding to the specified sector. Furthermore, the memory control section moves a specified sector within the identified memory region range for rewriting data corresponding to the specified sector.

Description:
TECHNICAL FIELD 
       [0001]    The present invention relates to a technique of accessing a nonvolatile storage medium such as a flash memory. 
       BACKGROUND ART 
       [0002]    Recently, flash memories, a nonvolatile storage medium, are used with various electronic devices such as information processing devices including personal computers, cell-phones, and digital cameras. Also, various techniques for accessing a flash memory have been proposed in the prior art (for example, Patent Literature 1). 
         [0003]    The memory card disclosed in Patent Literature 1 comprises a flash memory and a controller controlling the flash memory, wherein the controller can receives, from an external source, a command to write data in the direction that the address increases and detects the last writing position after the writing for the received command. The controller refers to a conversion table presenting the relationship between a sector and the corresponding physical address on a flash memory and searches for the physical address corresponding to the sector (logical data) on the flash memory. 
       CITATION LIST 
     Patent Literature 
       [0004]    Patent Literature 1: Unexamined Japanese Patent Application Kokai Publication No. 2006-40264. 
       SUMMARY OF INVENTION 
     Technical Problem 
       [0005]    However, the conversion table designed to make the physical address on a flash memory corresponding to a sector immediately known, as in the technique disclosed in the Patent Literature 1, significantly grows in size as the flash memory size is large. Therefore, it is not easy to use such a conversion table in a microcomputer system requiring a smaller memory or the like. 
         [0006]    The present invention is invented to solve the above prior art problem and an exemplary objective of the present invention is to provide a memory controller capable of accessing the physical address corresponding to a specified sector on a readable/writable storage medium such as a flash memory without significantly increasing the size of a table used. 
       Solution to Problem 
       [0007]    In order to achieve the above objective, the memory controller according to the present invention comprises: 
         [0008]    memory control means accessing a readable/writable nonvolatile memory and reading and writing data on the basis of a sector unit of a file system established for the nonvolatile memory; and 
         [0009]    table storage means storing a table associating the sector sections created by dividing all sectors of the file system into multiple sections under a given condition with different memory regions on the nonvolatile memory, respectively, 
         [0010]    wherein the memory control means: 
         [0011]    makes reference to the table to identify a memory region corresponding to a specified sector, and searches the identified memory region range for a physical address corresponding to the specified sector, and 
         [0012]    moves a specified sector within the identified memory region range for rewriting data corresponding to the specified sector. 
       Advantageous Effects of Invention 
       [0013]    The present invention makes reference to a table associating sector sections with memory regions on a nonvolatile memory in search for a physical address corresponding to a specified sector, whereby the processing can be expedited without significantly increasing the table size. 
     
    
     
       BRIEF DESCRIPTION OF DRAWINGS 
         [0014]      FIG. 1  is a block diagram showing the configuration of a microcomputer functioning as a memory controller according to an embodiment of the present invention; 
           [0015]      FIG. 2  is an illustration schematically showing a memory structure of the flash memory in  FIG. 1 ; 
           [0016]      FIG. 3  is an illustration showing an example of a file system definition table; 
           [0017]      FIG. 4  is an illustration showing an example of a group definition table; 
           [0018]      FIG. 5  is an illustration showing the relationship between the beginning of the groups and the physical addresses on the flash memory in the embodiment; 
           [0019]      FIG. 6  is a flowchart showing a procedure of a data reading processing; 
           [0020]      FIG. 7  is an illustration for explaining a specific example of reading data; 
           [0021]      FIG. 8  is a flowchart showing a procedure of a data writing processing; 
           [0022]      FIG. 9  is an illustration for explaining a specific example of writing data; 
           [0023]      FIG. 10  is a flowchart showing a procedure of a free sector allocation processing; 
           [0024]      FIG. 11  is an illustration showing an example of a group definition table in a modification of the embodiment; 
           [0025]      FIG. 12  is a flowchart showing a procedure of a group leveling processing; and 
           [0026]      FIG. 13  is an illustration showing an example of the group definition table after the group leveling processing. 
       
    
    
     DESCRIPTION OF EMBODIMENTS 
       [0027]    The memory controller according to an embodiment of the present invention will be described in detail hereafter with reference to the drawings. 
         [0028]      FIG. 1  is an illustration showing the general configuration of a flash memory system  1  comprising a microcomputer  10  functioning as a memory controller according to this embodiment and a flash memory  20 . The microcomputer  10  and flash memory  20  are connected by a data bus  30 . 
         [0029]    The microcomputer  10  is installed in various electronic devices or various electric appliances and controls the entire operation of the device. The microcomputer  10  comprises, from the viewpoint of hardware, a microprocessor, a ROM (Read Only Memory), a RAM (Random Access Memory), a memory interface, a clock source such as a quartz oscillator (none of the above is shown), and the like. 
         [0030]    The microcomputer  10  functionally comprises, as shown in  FIG. 1 , an application process section  100 , a file system manager  110 , a memory control section  120 , and a table storage  130 . The file system manager  110 , memory control section  120 , and table storage  130  are in charge of the function of the memory controller of the present invention. 
         [0031]    The application process section  100  executes the processing according to various application software programs stored on the ROM or the like for realizing the function of the device. The file system manager  110  manages the file system established for the flash memory  20 . The memory control section  120  accesses the flash memory  20  according to a request from the application process section  100  via the file system manager  110  to execute various kinds of processing (reading data, writing data and the like). 
         [0032]    The data storage  130  stores various tables for defining the file system. In this embodiment, the data storage  130  stores a file system definition table  131  and a group definition table  132 . These tables will be described in detail later. 
         [0033]    The memory region of the flash memory  20  comprises multiple blocks as shown in  FIG. 2 . A block (purging block) is the unit for deleting data. A sector, which is the unit for managing data in the file system, is a division of a block divided to a given size (for example, 520 bytes), comprising a “sector number” region, a “sector state” region, and a “data” region. 
         [0034]    The “sector number” region stores a number assigned to each sector (a sector number) managed by the file system. In this embodiment, serial numbers starting from 1 are assigned to the sectors. 
         [0035]    The “sector state” region stores information indicating the usage state of the sector (sector state). With reference to the “sector state” region, it is known that the sector is in one of the states “used,” “unused” and “deleted.” For example, immediately after a block is purged, all sectors in the block are “unused.” The “data” region stores data corresponding to the sector number stored in the “sector number” region. 
         [0036]    For accessing data stored on the flash memory  20  and corresponding to the sector number specified by the file system manager  110 , the memory control section  120  scans the memory region of the flash memory  20  on the basis of a sector unit (for example, 520 bytes) in sequence. Then, the memory control section  120  accesses the “data” region of the sector of which the “sector number” region stores the same sector number as the specified one and the “sector state” region stores information indicating “used.” 
         [0037]    On the other hand, for writing new data on the flash memory  20 , the memory control section  120  allocates one or multiple “unused” sectors corresponding to the data size specified by the file system manager  110  and writes the data. 
         [0038]    Furthermore, for overwriting data, the memory control section  120  writes data and a sector number in an “unused” sector different from the “used” sector corresponding to the specified sector number and changes the sector state to “used.” Furthermore, the memory control section  120  changes the sector state of the original sector to “deleted.” 
         [0039]    The file system definition table  131  comprises, as shown in  FIG. 3 , fields “start address,” “start sector,” “drive size,” “number of grouped sectors,” and the like. 
         [0040]    The “start address” stores a first address of the memory region of the flash memory  20  (0x0000000 in this embodiment). The “start sector” stores a start sector number (1 in this embodiment). The “drive size” stores a maximum memory capacity of the flash memory  20  managed by the file system (19.2 MB in this embodiment). 
         [0041]    The number of sectors usable by the file system as a group comprising a given number of successive blocks is set in the “number of grouped sectors.” In this embodiment, when the file system is established, all blocks of the flash memory  20  are divided into groups of three successive blocks from the first one as shown in  FIG. 2 , and each group is given a group number for identifying the group (serial numbers beginning with 0 in this embodiment). In this embodiment, it is assumed that 252 sectors are usable in a group. 
         [0042]    The group definition table  132  comprises, as shown in  FIG. 4 , fields “group number,” “start address,” “start sector,” and the like. 
         [0043]    The “group number” stores the group number of each group. The “start address” stores a first physical address of a memory region corresponding to the group on the flash memory  20 . In this embodiment, the block size is 64 KB and the group size is 64×3 KB 192 KB. The relationship between the groups and their first physical addresses is as shown in  FIG. 5 . 
         [0044]    The “start sector” stores a first (lowest) sector number among the sectors corresponding to the group (that is, usable sectors). For example, as shown in  FIG. 4 , the “start sector” of the group having a group number 0 stores 1 and the “start sector” of the group having a group number 1 stores  253 . 
         [0045]    From the contents of the group definition table  132  shown in  FIG. 4 , it is understood that, for example, a memory region from 0x0000000 to 0x002FFFF on the flash memory  20  is assigned to the group having a group number 0 and the sectors having sector numbers from 1 to 252 are usable in this embodiment. 
         [0046]    The above-described file system definition table  131  and group definition table  132  are created by the file system manager  110 , memory control section  120 , and/or the like and stored on the table storage  130  at the start of using the flash memory  20 , in other words when the file system for the flash memory  20  is established. 
         [0047]    Operation of reading in (reading out) data from the flash memory  20  in the flash memory system  1  having the above configuration will be described hereafter.  FIG. 6  is a flowchart showing a procedure of a data reading processing executed by the file system manager  110  and memory control section  120  of the microcomputer  10 . The data reading processing starts as the application process section  100  notifies the file system manager  110  of a data reading request. Here, the application process section  100  specifies the name of a file (a file name) to read in the data reading request. 
         [0048]    The file system manager  110  makes reference to a not-shown file information table to acquire the sector number corresponding to the specified file name (Step S 101 ). The file information table is a table associating the file names with the sector numbers and stored on the table storage  130 . Here, if a file has a large size and cannot be stored in the “data” region of a sector, the file is divided into multiple pieces of data and stored in different sectors. Therefore, in such a case, the divided data of the same file are associated with different sector numbers in the file information table. 
         [0049]    The file system manager  110  notifies the memory control section  120  of the acquired sector number and instructs the memory control section  120  to read the corresponding data. 
         [0050]    The memory control section  120  acquires the group number corresponding to the sector number notified from the file system manager  110  (Step S 102 ). Here, the memory control section  120  makes reference to the file system definition table  131  to acquire the group number corresponding to the sector number. More specifically, the memory control section  120  divides the sector number by the value stored in the “number of grouped sectors” of the file system definition table  131 . Then, the resultant quotient is the group number corresponding to the sector number. 
         [0051]    For example, if the specified sector number is 265, the corresponding group number is 265/252=1. 
         [0052]    Then, the memory control section  120  makes reference to the group definition table  132  to acquire the value stored in the “start address” (namely, the first physical address) corresponding to the acquired group number (Step S 103 ). In this embodiment, if the group number is 1, the corresponding physical address is 0x0030000. 
         [0053]    The memory control section  120  accesses and scans the flash memory  20  on the basis of a sector unit (for example, 520 bytes) downward (in the direction toward the rear blocks) from the memory region indicated by the acquired physical address in sequence in search for a sector having the same sector number and being “used” (step S 104 ). If the sector is found in this search (step S 105 : YES), the memory control section  120  reads data from the “data” region of the sector (Step S 106 ). 
         [0054]    The memory control section  120  supplies the read data to the file system manager  110  and notifies the file system manager  110  that reading the data has completed. Receiving the notification, the file system manager  110  supplies the data read by the memory control section  120  to the application process section  100  as the required file (Step S 107 ) and notifies the application process section  100  that reading the data has completed; then, the processing ends. 
         [0055]    As described above, if a file required from the application process section  100  is divided and stored in multiple different sectors, the file system manager  110  calls on the memory control section  120  to execute the above data reading operation as many times as the number of pieces of divided data. Then, the tile system manager  110  consolidates the multiple read, divided data to restore the original file and supplies the original file to the application process section  100 . 
         [0056]      FIG. 7  shows a case of reading the sector having a sector number  265  in the above data reading processing. In this case, the memory control section  120  starts searching for the sector from the sector (having a sector number  289 ) at the first address (0x0030000) of the group 1 (here, the first address of the block  3 ). Then, the memory control section  120  reads the data in the third sector (having a sector number  265 ) from the first one. 
         [0057]      FIG. 8  is a flowchart showing a procedure of a data writing processing executed by the file system manager  110  and memory control section  120  of the microcomputer  10 . The data writing processing tarts as the application process section  100  notifies the file system manager  110  of a data writing request. The application process section  100  specifies the name of a file (a file name) to write, data to write, and size of the data in the data writing request. 
         [0058]    Here, for writing a new file, nearly the same processing in the prior art is executed. Therefore, the following processing described in regard to overwriting data. Incidentally, if a new file to write should be divided and stored, it is desirable that the divided data are stored in sectors belonging to the same group. 
         [0059]    The file system manager  110  makes reference to the above-mentioned not-shown file information table to acquire the sector number corresponding to the specified file name (Step S 201 ). The file system manager  110  notifies the memory control section  120  of the sector number and data to write. 
         [0060]    The memory control section  120  makes reference to the file system definition table  131  to acquire the group number corresponding to the sector number notified from the file system manager  110  (Step S 202 ). Then, the memory control section  120  makes reference to the group definition table  132  to acquire the value (physical address) stored in the “start address” corresponding to the acquired group number (Step S 203 ). 
         [0061]    The memory control section  120  accesses and scans the flash memory  20  downward on the basis of a sector unit from the memory region indicated by the acquired physical address in sequence and checks on the state of each sector in all blocks corresponding to the group. Then, the memory control section  120  determines whether the number of “unused” sectors (free sectors) is equal to or greater than a given number (Step S 204 ). 
         [0062]    As a result, if the number of free sectors is less than a given number (Step S 204 ; NO), the memory control section  120  executes a free sector allocation processing described later (Step S 205 ). On the other hand, if the number of free sectors is equal to or greater than a given number (Step S 204 ; YES) or after executing the free sector allocation processing, the memory control section  120  scans the memory region, on the basis of a sector unit, downward from the physical address acquired earlier (the first address of the group) in sequence in search for a sector having the same sector number and being “used,” namely a sector where the old data are stored (Step S 206 ). If the sector is found in the search (Step S 207 ; YES), the memory control section  120  updates the state of the sector to “deleted” (Step S 208 ). 
         [0063]    Furthermore, the memory control section  120  searches for an “unused” sector downward from the first address of the group and writes the data in the found “unused” sector (Step S 209 ). More specifically, the memory control section  120  writes the notified data in the “data” region of the found “unused” sector, stores the notified sector number in the “sector number” region of the sector, and changes the sector state to “used.” 
         [0064]    The memory control section  120  notifies the file system manager  110  that writing the data has completed. Then, the file system manager  110  notifies the application process section  100  that writing the data has completed (Step S 210 ) and the processing ends. 
         [0065]    If the file required by the application process section  100  to write has a large size and should be divided and stored in multiple different sectors, the file system manager  110  notifies the memory control section  120  of the divided data and corresponding sector numbers of the file in sequence so that memory control section  120  executes the above-described data writing operation as many times as the number of pieces divided data. 
         [0066]      FIG. 9  shows a case in which the memory control section  120  writes new data “DAT-124” to overwrite (update) data in the sector having a sector number  265  in the above data writing processing. In this case, the memory control section  120  searches for the sector having a sector number  265  and changes the “sector state” of the sector where old data (“DAT-123”) is stored to “deleted.” Then, the memory control section  120  searches for a free sector, writes “DAT-124” in the “data” region of the found free sector, stores  265  in the “sector number,” and changes the “sector state” to “used.” 
         [0067]    The above-mentioned free sector allocation processing will be described hereafter with reference to the flowchart in  FIG. 10 . First, the memory control section  120  selects a block to purge (a purging block) among the blocks belonging to the group (Step S 301 ). Here, the memory control section  120  selects a block including the highest number of sectors of which the sector state is “deleted” in the group as the purging block. 
         [0068]    Subsequently, the memory control section  120  copies all “used” sectors belonging to the selected purging block in “unused” sectors of another block belonging to the group (Step S 302 ). Then, the memory control section  120  purges the purging block (Step S 303 ). 
         [0069]    As described above, the microcomputer (memory controller) of this embodiment uses a table in which the correspondence between the sector ranges and the physical address ranges on a flash memory is defined in accessing the sector having a specified sector number on the flash memory. Therefore, the search range is narrowed and the sector is efficiently found, whereby the processing is expedited. 
         [0070]    Furthermore, the table does not associate every single sector with a physical address, Therefore, the table does not significantly grow even if the flash memory capacity is increased. Then, the present invention is easily applicable even to a microcomputer requiring a smaller memory or the like. 
         [0071]    The present invention is not confined to the above embodiment and various changes can be made without departing from the gist of the present invention. 
         [0072]    For example, any number, such as two or four or more, of blocks can belong to a group. 
         [0073]    Furthermore, the microcomputer  10  of the above embodiment can further comprise the function of leveling the number of times of block purging operation and/or the number of times of rewriting. A modification of the microcomputer  10  (the memory controller) in Embodiment 1 comprising such a function will be described hereafter. 
         [0074]    In such a case, the group definition table  132  retained in the microcomputer  10  additionally includes a field “number of times of GC (garbage collection)” as shown in  FIG. 11 . Upon executing the above-described free sector allocation procedure, the memory control section  120  of the microcomputer  10  adds the resultant number of times of copying sectors (namely, the number of times of writing data) to the value stored in the “number of times of GC” of the group, In this modification, the relationship between the group number and corresponding physical address is changed as appropriate. Furthermore, the group having a predetermined group number (99 in this embodiment) is used as a temporary group described later. 
         [0075]      FIG. 12  is a flowchart showing the group leveling procedure executed by the memory control section  120  in this modification. The memory control section  120  executes the group leveling procedure at given times (for example, at given time intervals or immediately after the free sector allocation procedure). 
         [0076]    First, the memory control section  120  checks on the group definition table  132  to determine whether there is any group of which the value stored in the “number of times of GC” (the accumulated number of times) is greater than a preset maximum number of times of GC (a group with the maximum number of times) (Step S 401 ). As a result, if there is no group with the maximum number of times (Step S 401 ; NO), the processing ends. On the other hand, if there is any group with the maximum number of times (Step S 401 ; YES), the memory control section  120  copies all sectors belonging to the group with the maximum number of times and being “used” in a block corresponding to the temporary group (namely, the group having a group number 99) (Step S 402 ). 
         [0077]    Then, the memory control section  120  purges all blocks belonging to the copy source group or the group with the maximum number of times (Step S 403 ). Then, the memory control section  120  searches for a group having the lowest value stored in the “number of times of GC” (a group with the lowest number of times) (Step S 404 ). Then, the memory control section  120  copies all sectors belonging to the found group with the lowest number of times and being “used” in the blocks purged earlier (namely, the blocks belonging to the former group with the maximum number of times) (Step S 405 ). 
         [0078]    Then, the memory control section  120  purges all blocks belonging to the copy source group or the group with the lowest number of times (Step S 406 ). These multiple purged blocks will belong to the next temporary group. Then, the memory control section  120  updates the group definition table  132  (Step S 407 ). Here, the “start address” and “number of times of GC” of the group involved in the copying are updated. 
         [0079]    A case of the above group leveling procedure will be described hereafter in which the group definition table  132  has the contents shown in  FIG. 11 , the preset maximum number of times of GC is 400, and the group having a group number 0 has the lowest number of times of GC. 
         [0080]    In the above case, all sectors belonging to the group having a group number 1 and being in “used” are copied in the blocks corresponding to the group having a group number 99. After all blocks belonging to the group having a group number 1 are purged, all sectors belonging to the group having a group number 0 and being “used” are copied in the blocks purged. After the copying, all blocks belonging to the group having a group number 0 are purged. Then, the contents changed as a result of the copying between the groups are reflected in the group definition table  132 .  FIG. 13  shows the contents of the group definition table  132  after the group leveling processing is executed. 
         [0081]    Provision of the function of leveling the number of times of block purging operation and/or the number of times of rewriting as described above allows the flash memory to have an extended life. 
         [0082]    Various embodiments and modifications are available to the present invention without departing from the broad sense of spirit and scope of the present invention. The above-described embodiment is given for explaining the present invention and do not confine the scope of the present invention. In other words, the scope of the present invention is set forth by the scope of claims, not by the embodiments. Various modifications made within the scope of claims and scope of significance of the invention equivalent thereto are considered to fall under the scope of the present invention. 
       INDUSTRIAL APPLICABILITY 
       [0083]    The present invention can preferably be used in various electronic devices using readable/writable storage media such as flash memories. 
       REFERENCE SIGNS LIST 
       [0084]      1  Flash memory system 
         [0085]      10  Microcomputer 
         [0086]      100  Application process section 
         [0087]      110  File system manager 
         [0088]      120  Memory control section 
         [0089]      130  Table storage 
         [0090]      131  File system definition table 
         [0091]      132  Group definition table 
         [0092]      20  Flash memory 
         [0093]      30  Data bus