This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:software:homelab:library:module:sdcard [2012/05/16 12:50] – created raivo.sell | en:software:homelab:library:module:sdcard [2020/07/20 12:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== SD kaart ====== | + | ====== SD-card ====== |
| - | <note important> | + | |
| - | //Seotud mooduliga: [HW] [[et: | + | |
| - | See teegi osa sisaldab Kodulabori SD kaardi kasutamise funktsioone. | + | //Necessary knowledge: [HW] [[en: |
| - | ===== Andmetüübid ===== | + | This section of library contains functions for using HomeLab SD-card. |
| - | * **//static FATFS FATFS_Obj// | + | ===== Data types ===== |
| - | * **//FIL fil_obj//** - Failisüsteemi andmestruktuur, | + | * **//static FATFS FATFS_Obj//** - |
| - | * **//DSTATUS//** - Koodid, mida kettaga seotud funktsioonid tagastavad. | + | * **//FIL fil_obj//** - File system data structure where to store file identificators. |
| - | * //RES_OK// - (0) Toiming õnnestus. | + | |
| - | * // | + | |
| - | * // | + | |
| - | * // | + | |
| - | * // | + | |
| - | * **//FRESULT//** - Tähtsamad koodid, mida failidega seotud funktsioonid tagastavad. | + | * **//DSTATUS//** - Return codes for drive related functions. |
| - | * //FR_OK// - (0) Toiming õnnestus. | + | * //RES_OK// - (0) Procedure successful. |
| - | * //FR_DISK_ERR// - (1) Ketta I/O kihi viga. | + | * //RES_ERROR// - (1) R/W error. |
| - | * //FR_INT_ERR// - (2) Üldine ketta viga. | + | * //RES_WRPRT// - (2) Write protected. |
| - | * //FR_NOT_READY// - (3) Ketas ei ole toiminguks valmis. | + | * //RES_NOTRDY// - (3) Drive not ready. |
| - | * //FR_NO_FILE// - (4) Faili ei leitud. | + | * //RES_PARERR// - (4) Some parameters are false. |
| - | * // | + | |
| - | * // | + | |
| - | * // | + | |
| - | * // | + | |
| - | * // | + | |
| - | * // | + | |
| - | * // | + | |
| - | * // | + | |
| - | * // | + | |
| - | * // | + | |
| - | * **//ModeFlags//** - Faili võimalikud avamisrežiimid. | + | * **//FRESULT//** - Most important codes that are returned from file related functions. |
| - | * //FA_READ// - Fail avatakse lugemisrežiimis. | + | * //FR_OK// - (0) Procedure successful. |
| - | * //FA_WRITE// - Fail avatakse kirjutusrežiimis. | + | * //FR_DISK_ERR// - (1) Drive I/O layer error |
| - | * //FA_OPEN_EXISTING// - Avab faili. Kui faili ei ole, siis tagastatakse veakood. | + | * // |
| - | * //FA_OPEN_ALWAYS// - Avab faili. Kui faili ei ole, siis loob selle. | + | * // |
| - | * //FA_CREATE_NEW// - Loob uue faili. Kui fail on juba olemas, siis tagastatakse veakood. | + | * //FR_NO_FILE// - (4) File not found. |
| - | * //FA_CREATE_ALWAYS// - Loob uue faili. Kui fail on juba olemas, siis kirjutatakse see üle. | + | * // |
| + | * //FR_INVALID_NAME// - (6) Wrong file name format. | ||
| + | * // | ||
| + | * //FR_EXIST// - (8) Access is denied. | ||
| + | * // | ||
| + | * //FR_WRITE_PROTECTED// - (10) Drive is write protected. | ||
| + | * // | ||
| + | * // | ||
| + | * // | ||
| + | * // | ||
| + | * **// | ||
| + | * //FA_READ// - File open in read mode. | ||
| + | * // | ||
| + | * // | ||
| + | * // | ||
| + | * // | ||
| + | * // | ||
| - | ===== Funktsioonid | + | ===== Functions |
| * **//DSTATUS disk_initialize (BYTE drv)//** \\ | * **//DSTATUS disk_initialize (BYTE drv)//** \\ | ||
| - | Seadistab ketta. Parameetrid: | + | Initializes drive. Parameters: |
| - | * //drv// - Ketta number. | + | * //drv// - Drive number. |
| - | * Tagastab | + | * Returns |
| * **//DSTATUS disk_status (BYTE drv)//** \\ | * **//DSTATUS disk_status (BYTE drv)//** \\ | ||
| - | Näitab ketta olekut. Parameetrid: | + | Displays drive status. Parameters: |
| - | * //drv// - Ketta number. | + | * //drv// - Drive number. |
| - | * Tagastab | + | * Returns |
| * **//FRESULT f_mount (BYTE Drive, FATFS* FileSystemObject)// | * **//FRESULT f_mount (BYTE Drive, FATFS* FileSystemObject)// | ||
| - | Seadistab failisüsteemi. Parameetrid: | + | Initializes file system. Parameters: |
| - | * //Drive// - Ketta number. | + | * //Drive// - Drive number. |
| - | * // | + | * // |
| - | * Tagastab | + | * Returns |
| * **//FRESULT f_open (FIL* FileObject, const TCHAR* FileName, BYTE ModeFlags)// | * **//FRESULT f_open (FIL* FileObject, const TCHAR* FileName, BYTE ModeFlags)// | ||
| - | Avab või loob faili. Parameetrid: | + | Opens or creates file. Parameters: |
| - | * // | + | * // |
| - | * // | + | * // |
| - | * // | + | * // |
| - | * Tagastab | + | * Returns |
| * **//FRESULT f_close (FIL* FileObject)// | * **//FRESULT f_close (FIL* FileObject)// | ||
| - | Suleb faili. Parameetrid: | + | Closes file. Parameters: |
| - | * // | + | * // |
| - | * Tagastab | + | * Returns |
| * **//FRESULT f_read (FIL* FileObject, void* Buffer, UINT ByteToRead, UINT* ByteRead)// | * **//FRESULT f_read (FIL* FileObject, void* Buffer, UINT ByteToRead, UINT* ByteRead)// | ||
| - | Loeb failist etteantud arv baite andmeid. Parameetrid: | + | Reads required amount of bytes from file. Parameters: |
| - | * // | + | * // |
| - | * //Buffer// - Viit puhvrile, kuhu kirjutatakse loetud andmed. | + | * //Buffer// - Buffer pointer where to store data. |
| - | * // | + | * // |
| - | * // | + | * // |
| - | * Tagastab | + | * Returns |
| * **//FRESULT f_write (FIL* FileObject, const void* Buffer, UINT ByteToWrite, | * **//FRESULT f_write (FIL* FileObject, const void* Buffer, UINT ByteToWrite, | ||
| - | Kirjutab faili etteantud arv baite andmeid. Parameetrid: | + | Writes required amount of bytes to file. Parameters: |
| - | * // | + | * // |
| - | * //Buffer// - Viit andmetele, mis kirjutatakse faili. | + | * //Buffer// - Point to data being written into file. |
| - | * // | + | * // |
| - | * // | + | * // |
| - | * Tagastab | + | * Returns |
| * **//FRESULT f_sync (FIL* FileObject)// | * **//FRESULT f_sync (FIL* FileObject)// | ||
| - | Kirjutab puhvrites olevad andmed fail, et vähendada andmekadu voolukatkestuse korral. Kasutatakse rakendustes, | + | Writes data from buffers to a file to save them from power loss. Used in applications where a file is open for a long time. Parameters: |
| - | * // | + | * // |
| - | * Tagastab | + | * Returns |
| * **//FRESULT f_mkdir (const TCHAR* DirName)// | * **//FRESULT f_mkdir (const TCHAR* DirName)// | ||
| - | Loob kausta. Parameetrid: | + | Creates folder. Parameters: |
| - | * //DirName// - Kausta nimi. | + | * //DirName// - Folder name. |
| - | * Tagastab | + | * Returns |
| * **//FRESULT f_unlink (const TCHAR* FileName)// | * **//FRESULT f_unlink (const TCHAR* FileName)// | ||
| - | Kustutab faili või kausta. Parameetrid: | + | Deletes file or folder. Parameters: |
| - | * // | + | * // |
| - | * Tagastab | + | * Returns |
| * **//FRESULT f_rename (const TCHAR* OldName, const TCHAR* NewName)// | * **//FRESULT f_rename (const TCHAR* OldName, const TCHAR* NewName)// | ||
| - | Nimetab faili või kausta ümber. Parameetrid: | + | Rename file or folder. Parameters: |
| - | * //OldName// - Objekti vana nimi. | + | * //OldName// - Object old name. |
| - | * //NewName// - Objekti uus nimi. | + | * //NewName// - Object new name. |
| - | * Tagastab | + | * Returns |
| * **//TCHAR* f_gets (TCHAR* Str, int Size, FIL* FileObject)// | * **//TCHAR* f_gets (TCHAR* Str, int Size, FIL* FileObject)// | ||
| - | Loeb failist etteantud pikkusega stringi. Parameetrid: | + | Reads string with given length from file. Parameters: |
| - | * //Str// - Puhver, kuhu loetud andmed salvestatakse. | + | * //Str// - Buffer where to save read data. |
| - | * //Size// - Stringi pikkus. | + | * //Size// - Length of string. |
| - | * // | + | * // |
| - | * Tagastab | + | * Returns |
| * **//int f_putc (TCHAR Chr, FIL* FileObject)// | * **//int f_putc (TCHAR Chr, FIL* FileObject)// | ||
| - | Lisab faili tähemärgi. Parameetrid: | + | Adds a char to file. Parameters: |
| - | * //Chr// - Tähemärk, mis lisatakse faili. | + | * //Chr// - Char to be added into file. |
| - | * // | + | * // |
| - | * Tagastab | + | * Returns |
| * **//int f_printf (FIL* FileObject, const TCHAR* Foramt, ...)//** \\ | * **//int f_printf (FIL* FileObject, const TCHAR* Foramt, ...)//** \\ | ||
| - | Lisab faili vormindatud stringi. Parameetrid: | + | Adds a formated string to file. Parameters: |
| - | * // | + | * // |
| - | * //Foramt// - Stringi formaat. | + | * //Foramt// - String format. |
| * ... | * ... | ||
| - | * Tagastab kirjutatud märkide arvu, kui oli edukas. | + | * Returns the number of written chars if successful. |
| * **//DWORD f_tell (FIL* FileObject)// | * **//DWORD f_tell (FIL* FileObject)// | ||
| - | Kursori asukoht failis. Parameetrid: | + | Cursor position in file. Parameters: |
| - | * // | + | * // |
| - | * Tagastab viitena lugemis/kirjutamiskursori asukoha failis. | + | * Returns read/write cursor position in file as a pointer. |
| * **//FRESULT f_lseek (FIL* FileObject, | * **//FRESULT f_lseek (FIL* FileObject, | ||
| - | Viib kursori sooovitud asukohta failis. Parameetrid: | + | Move cursor to desired position in file. Parameters: |
| - | * // | + | * // |
| - | * //Offset// - Soovitud asukoht baitides faili algusest. | + | * //Offset// - Desired position in bytes from the beginning of the file. |
| - | * Tagastab | + | * Returns |
| | | ||
| - | ~~PB~~ | + | < |
| - | ===== Näide | + | ===== Example |
| <code c> | <code c> | ||
| Line 159: | Line 158: | ||
| FIL fil_obj; | FIL fil_obj; | ||
| - | // SD kaardi initsialiseerimine. | + | // SD card initialization. |
| disk_initialize(0); | disk_initialize(0); | ||
| - | // Failisüsteemi initsialiseerimine. | + | // File system initialization. |
| f_mount(0, & | f_mount(0, & | ||
| - | // Tekitatakse tekstifail | + | // Create text file "file.txt" |
| - | f_open(& | + | f_open(& |
| - | // Fail avatakse kirjutusreziimis. | + | // File to be open for writing. |
| - | f_open(& | + | f_open(& |
| - | // Faili kirjutamine. | + | // Writing into file. |
| f_printf(& | f_printf(& | ||
| - | | + | |
| f_close(& | f_close(& | ||
| } | } | ||