TI中文支持网
TI专业的中文技术问题搜集分享网站

CC3200 flash文件操作

       使用sl_FsOpen创建一个文件,使用sl_FsWrite 从偏移为0的位置,一段一段写入文件中,一直写文件最后,然后再继续从偏移为0的位置,写入数据。发现第二次从偏移为0的位置写入时,数据会出错。这是什么原因?有什么办法可以解决吗?

      测试过程中,如果每次写到文件最后,关闭文件,再打开文件,从偏移为0的位置写入,数据是正常的。

Viki Shi:

参考一下这边的类似问题:e2echina.ti.com/…/110727

,

user5065865:

我查看了您说的帖子,但未找到合适的答案。因为我希望只打开一次文件,实现数据更新功能。如果重新打开文件比耗时,因为文件比较大(>200KB)。我遇到的问题是不重新打开文件的情况下,每次从偏移为0的位置写入数据,前面的数据会出错。

,

Viki Shi:

手册列出了文件添加的步骤,如下:
There are several options to implement file appending from the host application. All options are based on
read → modify → write.
The assumption is that the host processor does not have enough resources to read the entire file to its
space so the serial flash needs to be used as a mediator. The proposed approach is to keep two files that
hold the same copy but in different time instances. The update/append is applied to the “older” instance
(based on the “newer” instance) and upon successful update/append, it becomes the “newer” instance. So
practically this approach implements rollback option in host level and does not make use of the file system
fail-safe option.
The procedure for file appending is as follows:
1. Create a file and write some content into it. The file would be denoted as file1.
2. Initialize a counter to file1 denoted as file1_counter and initialize it to 1.
3. The other instance is denoted as file2 and its counter file2_counter is initialized to 0. The “newer” file at
this point is file1 and its counter indicates it (file1_counter> file2_counter).
4. 4. Now, if an update/append is required:
a. Look for the “older” instance. If (file1_counter<file2_counter) file1 is the “older” instance, otherwise
it is file2.
b. Open the “newer” file for read.
c. Open the “older” file for write.
d. Read from the “newer” and write to the “older”. At this point, any power fail would not corrupt the
file as the “newer” instance is opened for read.
e. When reading from “newer” and writing to “older” is done, apply the followings:
i. Update/append to “older” instance.
ii. Close the “newer” instance.
iii. Close the “older” instance.
iv. Increase the counter of the “older” instance by 2 so it becomes the “newer” instance.
5. Go to step 4 for further operations.
Note that this approach does not use more space than a regular fail-safe file. The main difference is that
this method implements fail-safe functionality in the host application. Additionally, write operations and
flash erases are kept to a minimum.

请按照步骤进行操作,更多信息请参考:www.ti.com/…/swra657.pdf

赞(0)
未经允许不得转载:TI中文支持网 » CC3200 flash文件操作
分享到: 更多 (0)