📄 filesys103.txt
字号:
//------------------------------------------------------------------------------
// Contents
//------------------------------------------------------------------------------
Chapter 01. Introducion
Chapter 02. Link with the library
Chapter 03. Develop UI function for camera
Chapter 04. Card module sdram map
Chapter 05. DOS user service function examples
01. Format card
02. Checking disk space
03. Snap a jpeg file
04. Record an avi file
05. Record an wave file
06. Searching file
07. Upload file
08. Playback file
09. Get card infomation
Chapter 06. DOS user service function
Chapter 07. Advance:DOS service function examples
01. Create a directory
02. Changing between directories
03. Write dram data to card as new file
04. Write sram data to file as new file
05. Write video stream data to file
06. Searching file
07. Upload file to host
08. Search pattern within file
09. Read data to dram
10. Read data to sram
Chapter 08. Advance:DOS service function
Chapter 09. Advance:More application examples
01. Switch bewteen two different storage media
Chapter 10. Asic:Develop card module for new asic
Chapter 11. Asic:Develop card module for new card
//------------------------------------------------------------------------------
// Chapter 01. Introduction
//------------------------------------------------------------------------------
To shorten your development cycle for Sunplus's camera asic, we provide you
some library function. The purpose of this draft document is to describe the
library function provided for camera storage media access, these included vari-
ety of flash and card storage media.
The storage media that currently support are smc card, nand flash, cf card,
more storage media will be supported in near future soon.
The capacity supported for smc card and nand flash are 4, 8, 16, 32, 128M byte.
For cf, above 8M byte, up to 256M have been tested.
No matter what storage media supported, we will keep the function calls same
for all storage media unless some special function are required for that type
of media.
For example, File_SnapJpg let you capture a image and store it as JPEG in DOS
formatted media. You call the same function to store image into cf card or smc
card, or nand flash.
Basically, you should read chapter 1 to 5. Chapter 6, 7 should be read if you
want to implement your own whole DOS user service functions or add some DOS
user functions that we don't implement.
You should read chapter 8 if you want to port card module for new asic.
You should read chapter 9 if you want to port card module for new card media.
//------------------------------------------------------------------------------
// Chapter 02. Link with the library
//------------------------------------------------------------------------------
We use the Asic number and media type to name a library. For example if you are
using Sunplus's 503 asic and smc card, the library name should be smc503.lib.
When provide maximal set of functions in library. If after linking, the linker
display "uncall segment" message, you could ignore it by select "ignore warning"
option in linker. If you care about code size, you could use library utility to
delete these uncall functions. Also, "unused local varibles" warning message
could be ignored.
Beside adding the library file into project, we have some link and header files
put in a "cardlink" dicretory. These files are and should be included in your
project:
cardui.h - This file majorly contain some messages that storage library
function tell outside world what is currently undergoing in-
side its inner world. For example, when recording AVI file,
K_File_UI_Periodical message is periordically sent. User In-
terface(UI) implementer could use this message to beep, blink-
ing the LCD icon, doing AE, etc.
dosusr.h - This file majorly contain user dos functions and variables
that library provided.
What means user dos function is that the file and directory
naming convention follow these rules:
1. All capture files is put in \DCIM\100MEDIA directory. This
follow DCIM spec. The name could be modified in cardui.c
provided to you.
2. Storage's file naming convention is ccccnnnn.ext. cccc is
company representation. For example, "SUNP". nnnn is file
index number. For example "0001". If snap JPEG file, ext
is JPG; if AVI file, ext is AVI; if Wave file, ext is WAV,
etc. This namning convension also follow DCIM spec. The
cccc definition could also be modified in cardui.c provid-
ed to you.
3. When mixing AVI, JPG, WAV capture, the file index is
sequatial. For example, "SUNP0001.AVI", "SUNP0002.JPG",
"SUNP0003.WAV".
4. To know about how many files in \DCIM\100MEDIA directory
belong to camare, read the variable G_USR_FileCount.
5. All user dos function beginning with USR_ and apply above
rule to do file action. For example, USR_DeleteLastFile will
delete the "SUNP0003.WAV" in the above example.
6. If your naming rule doesn't follow above convention, you
should implement your own dosuser.c by using function pro-
vided in doslink.h. If this is case, you should use lib-
rary utility to remove the dosusr module included in library
and add you own. We don't encourage you to implement your
own dosusr.c. If we don't meet your requirement, please in-
form us, this could reduce your development effort.
cardlink.h - Majorly declare file capture cuntion.
doslink.h - DOS service function that allow you to create directory, file,
find file, open, close, read, write file.
chipopt.h - This file include some asic number define that storage library
use when compiling. It will be preset to proper asic value when
library is released for that asic.
cardopt.h - This file include some option define that storage library use
when compiling. It will be preset to proper option value when
libray is released. Some option definition same to option.h,
the value must match.
cardimpt.h - Since storage library is not self contain code, it require some
external resource in main code. This header file describe what
external resource should be imported to storage component. It
is suggested that to link the storage library, use our new
architecture main flow code, this new main code provide all
necessary import resource required by storage library.
cardlink.c - This file contain Card_InitRam, Card_InitGlobal. Card_InitRam
initialize sdram map using by storage component. All sdram map
used by storage component are set in these storage sdram map
globals. Card_InitGlobal init some default value to capture
parameters, and library initial values.
When accessing storage media, we require the media be formatted as DOS format.
If you get our new architecture main code, please reference the storage.c,
cardusr.c, cardui.c for example linking to card component. Also, within
general.h, after option.h include chipopt.h, cardopt.h header
If your media is external card, you could either format that card using card
reader and host computer first or using our DOS_Format function. Our storage
library could support DOS format that formatted using computer.
For nand flash, there is no card reader connected to host computer, you could
call DOS_Format provided by our library to format it as DOS format, this func-
tion also support to format external card.
Initial sequence for card library:
1.
// initio.c, after init sram in main flow
// if new architecture code, set G_ucStorageType
G_ucStorageType = 0xff;
2. // storage.c
Card_InitRam();
status = M_Card_Detect();
if ( status )
{
Card_InitRam(); // card it second time
Card_InitGlobal();
M_Card_Initialize()
}
The M_Card_Initialize will initialize all necessary hardware isssue
releated to card, call DOS_Initialize to create \DCIM\100MEDIA direc-
tory, search all files belong to our DCIM naming convention, etc.
//------------------------------------------------------------------------------
// Chapter 03. Sdram map
//------------------------------------------------------------------------------
The storage module use these sdram map variables:
G_DOS_SDRAM_WorkAddr should be assigned card module working buffer sdram
starting address. Card module use this as working buffer for internal DOS and
card operation and internal working structure. The size shoulb be at least 32K
word, this size must set to G_DOS_SDRAM_WorkSize which is word unit representa-
tion.
G_DOS_SDRAM_FAT1Addr should be assigned a sdram starting address to store DOS
FAT table. The size of this buffer must at least 64K word size if using external
flash card. If using internal flash, 32K word size is enough. The size should
set to K_SDRAM_DOS_Fat1BufSize which is word unit representation.
G_SDRAM_ImageAddr should be assigned a sdram start addres to allow card module
to store dsc image during capture process. Besides dsc image, the card module
may also use this buffer for header format, fdb search buffer during usb upload,
or even using this buffer to store 2 video frame, etc. The buffer size must at
least 350K bytes. It depend on what kind of image you are going to capture and
calculate the maximal size of that image plus thumnail size plus 32K header size.
G_DOS_SDRAM_MaxAddr should be assigned sdram size minus 1.
G_File_SDRAM_AviIdx1BufAddr is used only when using card module AVI releated
function. It should be assigned sdram starting address to store idx chunk
which use in AVI recording and playback. Each idx chunk is 16 bytes and each
video frame must attach 1 idx chunk. So if you which to record a 200 frames
avi files, the size of idx buffer should be 8+16*200 = 3208 bytes. This size
should set to G_File_SDRAM_AviIdx1BufSize which is word unit representation.
But normally, you hope to record avi until card is full. We will give you an
example for how to calculate the suitable G_File_SDRAM_AviIdx1BufSize.
G_File_SDRAM_AudioBufAddr is for card module to store audio data during record-
ing and playback process. Currently, the G_File_SDRAM_AudioBufSize determine
how long the audio could be recorded and playback. For example, if value of
G_File_SDRAM_AudioBufSize is 512000 word, sample rate is 8K, no compression, and
mono channel, then longest recording time is (512000*2)/8000 = 128 seconds.
When recording avi without audio, the card module will automactically determine
between card space full, idx buffer full, audio buffer full condition, user stop
action to stop avi recording.
Example C04E010:
Assume that your camera have 8M byte of RAM, no audio, no avi funtion, support
16M nand flash, sensor is 1280x960. Typical sdram map for this system is as
below:
0x00000000 _______________
| Video |
| Buffer |
| |
0x0012C000 |---------------|
| VLC |
| Buffer |
| |
0x00294000 |---------------|
| Thumbnail |
| Buffer |
0x0029D600 |---------------|
DOS_WorkAddr | DOS Working | Use as DOS working buffer.
| Buffer | DOS_WorkSize = 32K word
0x002A5600 |---------------|
DOS_FAT1Addr | FAT | Use as DOS fat buffer. For internal
| Buffer | flash, DOS_Fat1BufSize = 32K word
0x002AD600 |---------------|
ImageBufAddr | Card | Use as card module still image buffer,
| Image | plus file header size. Or during upload,
| Buffer | use as DOS fdb storage buffer.
| |
|---------------|
| . |
| . |
| . |
0x003FFFFF |_______________|
Example C04E020:
Assume that your camera have 8M byte of RAM, no audio, have avi funtion, support
128 SMC card, sensor is 1280x960, avi frame rate is 15, allow user to record 1
hour of video to card. Typical sdram map for this system is as below:
maximal frame count = 1hr x 15 = 3600 x 15 = 54000 frames
Idx1 buffer caculation = ( 8 + maximal frame count * 16 ) / 2 = 0x69784 word
0x00000000 _______________
| Video |
| Buffer |
| |
0x0012C000 |---------------|
| VLC |
| Buffer |
| |
0x00294000 |---------------|
| Thumbnail |
| Buffer |
0x0029D600 |---------------|
DOS_WorkAddr | DOS Working | Use as DOS working buffer.
| Buffer | DOS_WorkSize = 32K
0x002A5600 |---------------|
DOS_FAT1Addr | FAT | Use as DOS fat buffer. For external
| Buffer | flash, DOS_Fat1BufSize= 64K word.
0x002B5600 |---------------|
| AVI Idx1 |
| Buffer |
| |
0x0031ED84 |---------------|
ImageBufAddr | Card | Use as card module still image buffer,
| Image | plus file header size. Or during upload,
| Buffer | use as DOS fdb storage buffer.
| |
|---------------|
| . |
| . |
| . |
0x003FFFFF |_______________|
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -