Compact Flash Library
The Compact Flash Library provides routines for accessing data on Compact Flash card (abbr. CF further in text). CF cards are widely used memory elements, commonly used with digital cameras. Great capacity and excellent access time of only a few microseconds make them very attractive for microcontroller applications.
In CF card, data is divided into sectors. One sector usually comprises 512 bytes. Routines for file handling, the Cf_Fat
routines, are not performed directly but successively through 512B buffer.

- Routines for file handling can be used only with FAT16 file system.
- Library functions create and read files from the root directory only.
- Library functions populate both FAT1 and FAT2 tables when writing to files, but the file data is being read from the FAT1 table only; i.e. there is no recovery if the FAT1 table gets corrupted.
- If MMC/SD card has Master Boot Record (MBR), the library will work with the first available primary (logical) partition that has non-zero size. If MMC/SD card has Volume Boot Record (i.e. there is only one logical partition and no MBRs), the library works with entire card as a single partition. For more information on MBR, physical and logical drives, primary/secondary partitions and partition tables, please consult other resources, e.g. Wikipedia and similar.
- Before writing operation, make sure not to overwrite boot or FAT sector as it could make your card on PC or digital camera unreadable. Drive mapping tools, such as Winhex, can be of great assistance.
Library Dependency Tree

External dependencies of Compact Flash Library
Stellaris
The following variables must be defined in all projects using Compact Flash Library: | Description : | Example : |
---|---|---|
extern sfr unsigned long CF_Data_Port; |
Compact Flash Data Port. | char CF_Data_Port at GPIO_PORTE_DATA; |
extern sfr sbit CF_RDY; |
Ready signal line. | sbit CF_RDY at GPIO_PORTD_DATA7_bit; |
extern sfr sbit CF_WE; |
Write Enable signal line. | sbit CF_WE at GPIO_PORTD_DATA6_bit; |
extern sfr sbit CF_OE; |
Output Enable signal line. | sbit CF_OE at GPIO_PORTD_DATA5_bit; |
extern sfr sbit CF_CD1; |
Chip Detect signal line. | sbit CF_CD1 at GPIO_PORTD_DATA4_bit; |
extern sfr sbit CF_CE1; |
Chip Enable signal line. | sbit CF_CE1 at GPIO_PORTD_DATA3_bit; |
extern sfr sbit CF_A2; |
Address pin 2. | sbit CF_A2 at GPIO_PORTD_DATA2_bit; |
extern sfr sbit CF_A1; |
Address pin 1. | sbit CF_A1 at GPIO_PORTD_DATA1_bit; |
extern sfr sbit CF_A0; |
Address pin 0. | sbit CF_A0 at GPIO_PORTD_DATA0_bit; |
extern sfr sbit CF_RDY_direction; |
Direction of the Ready pin. | sbit CF_RDY_direction at GPIO_PORTD_DIR7_bit; |
extern sfr sbit CF_WE_direction; |
Direction of the Write Enable pin. | sbit CF_WE_direction at GPIO_PORTD_DIR6_bit; |
extern sfr sbit CF_OE_direction; |
Direction of the Output Enable pin. | sbit CF_OE_direction at GPIO_PORTD_DIR5_bit; |
extern sfr sbit CF_CD1_direction; |
Direction of the Chip Detect pin. | sbit CF_CD1_direction at GPIO_PORTD_DIR4_bit; |
extern sfr sbit CF_CE1_direction; |
Direction of the Chip Enable pin. | sbit CF_CE1_direction at GPIO_PORTD_DIR3_bit; |
extern sfr sbit CF_A2_direction; |
Direction of the Address 2 pin. | sbit CF_A2_direction at GPIO_PORTD_DIR2_bit; |
extern sfr sbit CF_A1_direction; |
Direction of the Address 1 pin. | sbit CF_A1_direction at GPIO_PORTD_DIR1_bit; |
extern sfr sbit CF_A0_direction; |
Direction of the Address 0 pin. | sbit CF_A0_direction at GPIO_PORTD_DIR0_bit; |
MSP432
The following variables must be defined in all projects using Compact Flash Library: | Description : | Example : |
---|---|---|
extern sfr unsigned int Cf_Data_Port_Output; |
Compact Data Port Output. | unsigned int Cf_Data_Port_Output at DIO_P5OUT; |
extern sfr unsigned int Cf_Data_Port_Input; |
Compact Data Port Input. | unsigned int Cf_Data_Port_Input at DIO_P5IN; |
extern sfr sbit CF_RDY; |
Ready signal line. | sbit CF_RDY at DIO_P6OUT.B0; |
extern sfr sbit CF_WE; |
Write Enable signal line. | sbit CF_WE at DIO_P6OUT.B1; |
extern sfr sbit CF_OE; |
Output Enable signal line. | sbit CF_OE at DIO_P6OUT.B2; |
extern sfr sbit CF_CD1; |
Chip Detect signal line. | sbit CF_CD1 at DIO_P6OUT.B3; |
extern sfr sbit CF_CE1; |
Chip Enable signal line. | sbit CF_CE1 at DIO_P6OUT.B4; |
extern sfr sbit CF_A2; |
Address pin 2. | sbit CF_A2 at DIO_P6OUT.B5; |
extern sfr sbit CF_A1; |
Address pin 1. | sbit CF_A1 at DIO_P6OUT.B6; |
extern sfr sbit CF_A0; |
Address pin 0. | sbit CF_A0 at DIO_P6OUT.B7; |
extern sfr sbit CF_RDY_direction; |
Direction of the Ready pin. | sbit CF_RDY_direction at DIO_P6DIR.B0; |
extern sfr sbit CF_WE_direction; |
Direction of the Write Enable pin. | sbit CF_WE_direction at DIO_P6DIR.B1; |
extern sfr sbit CF_OE_direction; |
Direction of the Output Enable pin. | sbit CF_OE_direction at DIO_P6DIR.B2; |
extern sfr sbit CF_CD1_direction; |
Direction of the Chip Detect pin. | sbit CF_CD1_direction at DIO_P6DIR.B3; |
extern sfr sbit CF_CE1_direction; |
Direction of the Chip Enable pin. | sbit CF_CE1_direction at DIO_P6DIR.B4; |
extern sfr sbit CF_A2_direction; |
Direction of the Address 2 pin. | sbit CF_A2_direction at DIO_P6DIR.B5; |
extern sfr sbit CF_A1_direction; |
Direction of the Address 1 pin. | sbit CF_A1_direction at DIO_P6DIR.B6; |
extern sfr sbit CF_A0_direction; |
Direction of the Address 0 pin. | sbit CF_A0_direction at DIO_P6DIR.B7; |
STM32
The following variables must be defined in all projects using Compact Flash Library: | Description : | Example : |
---|---|---|
extern sfr unsigned long Cf_Data_Port_Input; |
Compact Flash Data Input Port. | char Cf_Data_Port_Input at GPIOD_IDR; |
extern sfr unsigned long Cf_Data_Port_Output; |
Compact Flash Data Output Port. | char Cf_Data_Port_Output at GPIOD_ODR; |
extern sfr sbit CF_RDY; |
Ready signal line. | sbit CF_RDY at GPIOD_IDR.B15; |
extern sfr sbit CF_WE; |
Write Enable signal line. | sbit CF_WE at GPIOD_ODR.B14; |
extern sfr sbit CF_OE; |
Output Enable signal line. | sbit CF_OE at GPIOD_ODR.B13; |
extern sfr sbit CF_CD1; |
Chip Detect signal line. | sbit CF_CD1 at GPIOD_IDR.B12; |
extern sfr sbit CF_CE1; |
Chip Enable signal line. | sbit CF_CE1 at GPIOD_ODR.B11; |
extern sfr sbit CF_A2; |
Address pin 2. | sbit CF_A2 at GPIOD_ODR.B10; |
extern sfr sbit CF_A1; |
Address pin 1. | sbit CF_A1 at GPIOD_ODR.B9; |
extern sfr sbit CF_A0; |
Address pin 0. | sbit CF_A0 at GPIOD_ODR.B8; |
CEC1x02
The following variables must be defined in all projects using Compact Flash Library: | Description : | Example : |
---|---|---|
extern sfr unsigned long Cf_Data_Port_Input; |
Compact Flash Data Input Port. | char Cf_Data_Port_Input at GPIO_INPUT_010_017; |
extern sfr unsigned long Cf_Data_Port_Output; |
Compact Flash Data Output Port. | char Cf_Data_Port_Output at GPIO_OUTPUT_010_017; |
extern sfr sbit CF_RDY; |
Ready signal line. | sbit CF_RDY at GPIO_INPUT_PIN_001_bit; |
extern sfr sbit CF_WE; |
Write Enable signal line. | sbit CF_WE at GPIO_OUTPUT_PIN_002_bit; |
extern sfr sbit CF_OE; |
Output Enable signal line. | sbit CF_OE at GPIO_OUTPUT_PIN_003_bit; |
extern sfr sbit CF_CD1; |
Chip Detect signal line. | sbit CF_CD1 at GPIO_INPUT_PIN_004_bit; |
extern sfr sbit CF_CE1; |
Chip Enable signal line. | sbit CF_CE1 at GPIO_INPUT_PIN_005_bit; |
extern sfr sbit CF_A2; |
Address pin 2. | sbit CF_A2 at GPIO_INPUT_PIN_006_bit; |
extern sfr sbit CF_A1; |
Address pin 1. | sbit CF_A1 at GPIO_OUTPUT_PIN_007_bit; |
extern sfr sbit CF_A0; |
Address pin 0. | sbit CF_A0 at GPIO_OUTPUT_PIN_147_bit; |
Library Routines
- Cf_Init
- Cf_Detect
- Cf_Enable
- Cf_Disable
- Cf_Read_Init
- Cf_Read_Byte
- Cf_Write_Init
- Cf_Write_Byte
- Cf_Read_Sector
- Cf_Write_Sector
Routines for file handling:
- Cf_Fat_Init
- Cf_Fat_QuickFormat
- Cf_Fat_Assign
- Cf_Fat_Reset
- Cf_Fat_Read
- Cf_Fat_Rewrite
- Cf_Fat_Append
- Cf_Fat_Delete
- Cf_Fat_Write
- Cf_Fat_Set_File_Date
- Cf_Fat_Get_File_Date
- Cf_Fat_Get_File_Date_Modified
- Cf_Fat_Get_File_Size
- Cf_Fat_Get_Swap_File
The following routine is for the internal use by compiler only:
- Cf_Issue_ID_Command
Cf_Init
Prototype |
void Cf_Init(); |
---|---|
Description |
Initializes ports appropriately for communication with CF card. |
Parameters |
None. |
Returns |
Nothing. |
Requires |
External dependencies of the library from the top of the page must be defined before using this function. |
Example |
Stellaris// set compact flash pinout char Cf_Data_Port at GPIO_PORTE_DATA; sbit CF_RDY at GPIO_PORTD_DATA7_bit; sbit CF_WE at GPIO_PORTD_DATA6_bit; sbit CF_OE at GPIO_PORTD_DATA5_bit; sbit CF_CD1 at GPIO_PORTD_DATA4_bit; sbit CF_CE1 at GPIO_PORTD_DATA3_bit; sbit CF_A2 at GPIO_PORTD_DATA2_bit; sbit CF_A1 at GPIO_PORTD_DATA1_bit; sbit CF_A0 at GPIO_PORTD_DATA0_bit; sbit CF_RDY_direction at GPIO_PORTD_DIR7_bit; sbit CF_WE_direction at GPIO_PORTD_DIR6_bit; sbit CF_OE_direction at GPIO_PORTD_DIR5_bit; sbit CF_CD1_direction at GPIO_PORTD_DIR4_bit; sbit CF_CE1_direction at GPIO_PORTD_DIR3_bit; sbit CF_A2_direction at GPIO_PORTD_DIR2_bit; sbit CF_A1_direction at GPIO_PORTD_DIR1_bit; sbit CF_A0_direction at GPIO_PORTD_DIR0_bit; // end of compact flash pinout ... Cf_Init(); // initialize CF MSP432// set compact flash pinout unsigned int Cf_Data_Port_Output at DIO_P5OUT; unsigned int Cf_Data_Port_Input at DIO_P5IN; sbit CF_RDY at DIO_P6OUT.B0; sbit CF_WE at DIO_P6OUT.B1; sbit CF_OE at DIO_P6OUT.B2; sbit CF_CD1 at DIO_P6OUT.B3; sbit CF_CE1 at DIO_P6OUT.B4; sbit CF_A2 at DIO_P6OUT.B5; sbit CF_A1 at DIO_P6OUT.B6; sbit CF_A0 at DIO_P6OUT.B7; sbit CF_RDY_direction at DIO_P6DIR.B0; sbit CF_WE_direction at DIO_P6DIR.B1; sbit CF_OE_direction at DIO_P6DIR.B2; sbit CF_CD1_direction at DIO_P6DIR.B3; sbit CF_CE1_direction at DIO_P6DIR.B4; sbit CF_A2_direction at DIO_P6DIR.B5; sbit CF_A1_direction at DIO_P6DIR.B6; sbit CF_A0_direction at DIO_P6DIR.B7; // end of compact flash pinout ... Cf_Init(); // initialize CF STM32// set compact flash pinout unsigned long Cf_Data_Port_Input at GPIOD_IDR; unsigned long Cf_Data_Port_Output at GPIOD_ODR; sbit CF_RDY at GPIOD_IDR.B15; sbit CF_WE at GPIOD_ODR.B14; sbit CF_OE at GPIOD_ODR.B13; sbit CF_CD1 at GPIOD_IDR.B12; sbit CF_CE1 at GPIOD_ODR.B11; sbit CF_A2 at GPIOD_ODR.B10; sbit CF_A1 at GPIOD_ODR.B9; sbit CF_A0 at GPIOD_ODR.B8; // end of cf pinout ... Cf_Init(); // initialize CF CEC1x02// set compact flash pinout unsigned short CF_Data_Port_Output at GPIO_OUTPUT_010_017; unsigned short CF_Data_Port_Input at GPIO_INPUT_010_017; sbit CF_RDY at GPIO_INPUT_PIN_001_bit; sbit CF_WE at GPIO_OUTPUT_PIN_002_bit; sbit CF_OE at GPIO_OUTPUT_PIN_003_bit; sbit CF_CD1 at GPIO_INPUT_PIN_004_bit; sbit CF_CE1 at GPIO_OUTPUT_PIN_005_bit; sbit CF_A2 at GPIO_OUTPUT_PIN_006_bit; sbit CF_A1 at GPIO_OUTPUT_PIN_007_bit; sbit CF_A0 at GPIO_OUTPUT_PIN_147_bit; // end of cf pinout ... Cf_Init(); // initialize CF |
Notes |
None. |
Cf_Detect
Prototype |
unsigned int Cf_Detect(); |
---|---|
Description |
Checks for presence of CF card by reading the |
Parameters |
None. |
Returns |
|
Requires |
The corresponding MCU ports must be appropriately initialized for CF card. See Cf_Init. |
Example |
// Wait until CF card is inserted: do asm nop; while (!Cf_Detect()); |
Notes |
ARM family MCU and CF card voltage levels are different. The user must ensure that MCU's pin connected to CD line can read CF card Logical One correctly. |
Cf_Enable
Prototype |
void Cf_Enable(); |
---|---|
Description |
Enables the device. Routine needs to be called only if you have disabled the device by means of the Cf_Disable routine. These two routines in conjunction allow you to free/occupy data line when working with multiple devices. |
Parameters |
None. |
Returns |
Nothing. |
Requires |
The corresponding MCU ports must be appropriately initialized for CF card. See Cf_Init. |
Example |
// enable compact flash Cf_Enable(); |
Notes |
None. |
Cf_Disable
Prototype |
void Cf_Disable(); |
---|---|
Description |
Routine disables the device and frees the data lines for other devices. To enable the device again, call Cf_Enable. These two routines in conjunction allow you to free/occupy data line when working with multiple devices. |
Parameters |
None. |
Returns |
Nothing. |
Requires |
The corresponding MCU ports must be appropriately initialized for CF card. See Cf_Init. |
Example |
// disable compact flash Cf_Disable(); |
Notes |
None. |
Cf_Read_Init
Prototype |
void Cf_Read_Init(unsigned long address, unsigned short sector_count); |
---|---|
Description |
Initializes CF card for reading. |
Parameters |
|
Returns |
Nothing. |
Requires |
The corresponding MCU ports must be appropriately initialized for CF card. See Cf_Init. |
Example |
// initialize compact flash for reading from sector 590 Cf_Read_Init(590, 1); |
Notes |
None. |
Cf_Read_Byte
Prototype |
unsigned char Cf_Read_Byte(); |
---|---|
Description |
Reads one byte from Compact Flash sector buffer location currently pointed to by internal read pointers. These pointers will be autoicremented upon reading. |
Parameters |
None. |
Returns |
Returns a byte read from Compact Flash sector buffer. |
Requires |
The corresponding MCU ports must be appropriately initialized for CF card. See Cf_Init. CF card must be initialized for reading operation. See Cf_Read_Init. |
Example |
// Read a byte from compact flash: unsigned char data_; ... data_ = Cf_Read_Byte(); |
Notes |
Higher byte of the unsigned return value is cleared.
|
Cf_Write_Init
Prototype |
void Cf_Write_Init(unsigned long address, unsigned short sectcnt); |
---|---|
Description |
Initializes CF card for writing. |
Parameters |
|
Returns |
Nothing. |
Requires |
The corresponding MCU ports must be appropriately initialized for CF card. See Cf_Init. |
Example |
// initialize compact flash for writing to sector 590 Cf_Write_Init(590, 1); |
Notes |
None. |
Cf_Write_Byte
Prototype |
void Cf_Write_Byte(unsigned short data_); |
---|---|
Description |
Writes a byte to Compact Flash sector buffer location currently pointed to by writing pointers. These pointers will be autoicremented upon reading. When sector buffer is full, its contents will be transfered to appropriate flash memory sector. |
Parameters |
|
Returns |
Nothing. |
Requires |
The corresponding MCU ports must be appropriately initialized for CF card. See Cf_Init. CF card must be initialized for writing operation. See Cf_Write_Init. |
Example |
char data_ = 0xAA; ... Cf_Write_Byte(data_); |
Notes |
None. |
Cf_Read_Sector
Prototype |
void Cf_Read_Sector(unsigned long sector_number, unsigned short *buffer); |
---|---|
Description |
Reads one sector (512 bytes). Read data is stored into buffer provided by the |
Parameters |
|
Returns |
Nothing. |
Requires |
The corresponding MCU ports must be appropriately initialized for CF card. See Cf_Init. |
Example |
// read sector 22 unsigned short data[512]; ... Cf_Read_Sector(22, data); |
Notes |
None. |
Cf_Write_Sector
Prototype |
void Cf_Write_Sector(unsigned long sector_number, unsigned short *buffer); |
---|---|
Description |
Writes 512 bytes of data provided by the |
Parameters |
|
Returns |
Nothing. |
Requires |
The corresponding MCU ports must be appropriately initialized for CF card. See Cf_Init. |
Example |
// write to sector 22 unsigned short data[512]; ... Cf_Write_Sector(22, data); |
Notes |
None. |
Cf_Fat_Init
Prototype |
unsigned int Cf_Fat_Init(); |
---|---|
Description |
Initializes CF card, reads CF FAT16 boot sector and extracts necessary data needed by the library. |
Parameters |
None. |
Returns |
|
Requires |
Nothing. |
Example |
// Init the FAT library if (!Cf_Fat_Init()) { // Init the FAT library ... } |
Notes |
None. |
Cf_Fat_QuickFormat
Prototype |
unsigned int Cf_Fat_QuickFormat(char *cf_fat_label); |
---|---|
Description |
Formats to FAT16 and initializes CF card. |
Parameters |
|
Returns |
|
Requires |
Nothing. |
Example |
// format and initialize the FAT library - if (!Cf_Fat_QuickFormat(&cf_fat_label)) { ... } |
Notes |
|
Cf_Fat_Assign
Prototype |
unsigned int Cf_Fat_Assign(char *filename, char file_cre_attr); |
|||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Assigns file for file operations (read, write, delete...). All subsequent file operations will be applied over the assigned file. |
|||||||||||||||||||||||||||
Parameters |
|
|||||||||||||||||||||||||||
Returns |
|
|||||||||||||||||||||||||||
Requires |
CF card and CF library must be initialized for file operations. See Cf_Fat_Init. |
|||||||||||||||||||||||||||
Example |
// create file with archive attributes if it does not already exist Cf_Fat_Assign("MIKRO007.TXT",0xA0); |
|||||||||||||||||||||||||||
Notes | Long File Names (LFN) are not supported. |
Cf_Fat_Reset
Prototype |
void Cf_Fat_Reset(unsigned long *size); |
---|---|
Description |
Opens currently assigned file for reading. |
Parameters |
|
Returns |
Nothing. |
Requires |
CF card and CF library must be initialized for file operations. See Cf_Fat_Init. File must be previously assigned. See Cf_Fat_Assign. |
Example |
unsigned long size; ... Cf_Fat_Reset(size); |
Notes |
None. |
Cf_Fat_Read
Prototype |
void Cf_Fat_Read(unsigned short *bdata); |
---|---|
Description |
Reads a byte from currently assigned file opened for reading. Upon function execution file pointers will be set to the next character in the file. |
Parameters |
|
Returns |
Nothing. |
Requires |
CF card and CF library must be initialized for file operations. See Cf_Fat_Init. File must be previously assigned. See Cf_Fat_Assign. File must be open for reading. See Cf_Fat_Reset. |
Example |
char character; ... Cf_Fat_Read(&character); |
Notes |
None. |
Cf_Fat_Rewrite
Prototype |
void Cf_Fat_Rewrite(); |
---|---|
Description |
Opens currently assigned file for writing. If the file is not empty its content will be erased. |
Parameters |
None. |
Returns |
Nothing. |
Requires |
CF card and CF library must be initialized for file operations. See Cf_Fat_Init. The file must be previously assigned. See Cf_Fat_Assign. |
Example |
// open file for writing Cf_Fat_Rewrite(); |
Notes |
None. |
Cf_Fat_Append
Prototype |
void Cf_Fat_Append(); |
---|---|
Description |
Opens currently assigned file for appending. Upon this function execution file pointers will be positioned after the last byte in the file, so any subsequent file writing operation will start from there. |
Parameters |
None. |
Returns |
Nothing. |
Requires |
CF card and CF library must be initialized for file operations. See Cf_Fat_Init. File must be previously assigned. See Cf_Fat_Assign. |
Example |
// open file for appending Cf_Fat_Append(); |
Notes |
None. |
Cf_Fat_Delete
Prototype |
void Cf_Fat_Delete(); |
---|---|
Description |
Deletes currently assigned file from CF card. |
Parameters |
None. |
Returns |
Nothing. |
Requires |
CF card and CF library must be initialized for file operations. See Cf_Fat_Init. File must be previously assigned. See Cf_Fat_Assign. |
Example |
// delete current file Cf_Fat_Delete(); |
Notes |
None. |
Cf_Fat_Write
Prototype |
void Cf_Fat_Write(char *fdata, unsigned data_len); |
---|---|
Description |
Writes requested number of bytes to currently assigned file opened for writing. |
Parameters |
|
Returns |
Nothing. |
Requires |
CF card and CF library must be initialized for file operations. See Cf_Fat_Init. File must be previously assigned. See Cf_Fat_Assign. File must be open for writing. See Cf_Fat_Rewrite or Cf_Fat_Append. |
Example |
char file_contents[42]; ... Cf_Fat_Write(file_contents, 42); // write data to the assigned file |
Notes |
None. |
Cf_Fat_Set_File_Date
Prototype |
void Cf_Fat_Set_File_Date(unsigned int year, unsigned short month, unsigned short day, unsigned short hours, unsigned short mins, unsigned short seconds); |
---|---|
Description |
Sets the date/time stamp. Any subsequent file writing operation will write this stamp to currently assigned file's time/date attributes. |
Parameters |
|
Returns |
Nothing. |
Requires |
CF card and CF library must be initialized for file operations. See Cf_Fat_Init. File must be previously assigned. See Cf_Fat_Assign. File must be open for writing. See Cf_Fat_Rewrite or Cf_Fat_Append. |
Example |
Cf_Fat_Set_File_Date(2005,9,30,17,41,0); |
Notes |
None. |
Cf_Fat_Get_File_Date
Prototype |
void Cf_Fat_Get_File_Date(unsigned int *year, unsigned short *month, unsigned short *day, unsigned short *hours, unsigned short *mins); |
---|---|
Description |
Reads time/date attributes of currently assigned file. |
Parameters |
|
Returns |
Nothing. |
Requires |
CF card and CF library must be initialized for file operations. See Cf_Fat_Init. File must be previously assigned. See Cf_Fat_Assign. |
Example |
unsigned year; char month, day, hours, mins; ... Cf_Fat_Get_File_Date(&year, &month, &day, &hours, &mins); |
Notes |
None. |
Cf_Fat_Get_File_Date_Modified
Prototype |
void Cf_Fat_Get_File_Date_Modified(unsigned int *year, unsigned short *month, unsigned short *day, unsigned short *hours, unsigned short *mins); |
---|---|
Description |
Retrieves the last modification date/time of the currently assigned file. |
Parameters |
|
Returns |
Nothing. |
Requires |
CF card and CF library must be initialized for file operations. See Cf_Fat_Init. File must be previously assigned. See Cf_Fat_Assign. |
Example |
unsigned year; char month, day, hours, mins; ... Cf_Fat_Get_File_Date_Modified(&year, &month, &day, &hours, &mins); |
Notes |
None. |
Cf_Fat_Get_File_Size
Prototype |
unsigned long Cf_Fat_Get_File_Size(); |
---|---|
Description |
This function reads size of currently assigned file in bytes. |
Parameters |
None. |
Returns |
Size of the currently assigned file in bytes. |
Requires |
CF card and CF library must be initialized for file operations. See Cf_Fat_Init. File must be previously assigned. See Cf_Fat_Assign. |
Example |
unsigned long my_file_size; ... my_file_size = Cf_Fat_Get_File_Size(); |
Notes |
None. |
Cf_Fat_Get_Swap_File
Prototype |
unsigned long Cf_Fat_Get_Swap_File(unsigned long sectors_cnt, char *filename, char file_attr); |
|||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
This function is used to create a swap file of predefined name and size on the CF media. If a file with specified name already exists on the media, search for consecutive sectors will ignore sectors occupied by this file. Therefore, it is recommended to erase such file if it exists before calling this function. If it is not erased and there is still enough space for a new swap file, this function will delete it after allocating new memory space for a new swap file. The purpose of the swap file is to make reading and writing to CF media as fast as possible, by using the Cf_Read_Sector() and Cf_Write_Sector() functions directly, without potentially damaging the FAT system. Swap file can be considered as a "window" on the media where the user can freely write/read data. It's main purpose in the this library is to be used for fast data acquisition; when the time-critical acquisition has finished, the data can be re-written into a "normal" file, and formatted in the most suitable way. |
|||||||||||||||||||||||||||
Parameters |
|
|||||||||||||||||||||||||||
Returns |
|
|||||||||||||||||||||||||||
Requires |
CF card and CF library must be initialized for file operations. See Cf_Fat_Init. |
|||||||||||||||||||||||||||
Example |
//-------------- Try to create a swap file with archive atribute, whose size will be at least 1000 sectors. // If it succeeds, it sends the No. of start sector over UART unsigned long size; ... size = Cf_Fat_Get_Swap_File(1000, "mikroE.txt", 0x20); if (size) { UART1_Write(0xAA); UART1_Write(Lo(size)); UART1_Write(Hi(size)); UART1_Write(Higher(size)); UART1_Write(Highest(size)); UART1_Write(0xAA); } |
|||||||||||||||||||||||||||
Notes | Long File Names (LFN) are not supported. |
What do you think about this topic ? Send us feedback!