View previous topic :: View next topic |
Author |
Message |
sandy
Joined: 08 Mar 2008 Posts: 79
|
Posted: Fri Jul 11, 2014 2:29 pm Post subject: AVR-DOS file copying |
|
|
Hi Board;
I attach two sd cards(card-1 & Card-2) to my atmega128. After making logs and different files(.txt) . I need to copy file from card-1 to card-2 can someone advice me how to do this, or which is the best trick to be adopted here. Thanks for your time
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Mon Jul 14, 2014 1:01 am Post subject: |
|
|
Copying a file is just the process of opening the file, reading all the bytes out in convenient size chunks. and writing those chunks back into a file on the other card.
Because copying is relatively slow on an AVR, its far better to put the files from a logger only on one card, and then copy or transfer them with a PC. A PC card driver takes advantage of systems on the card which allow far faster transfer than the simple SPI single serial line that an AVR can use. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Mon Jul 14, 2014 1:40 am Post subject: |
|
|
Hello Sandy
As Adrian says its a slow process as you have to store the data in a variable then write it to the other card so the bigger the variable the better but you are restricted by how much ram you have.
In your case you could turn to external ram and using the $bigstrings mode of bascom create a large variable with 8K bytes or more.
If you can not add external ram use as much as you can to create a large variable to hold the data.
If you look in the blog section at my W5100 web server code you will see how I read from an SD card into a bigstring of 1001 bytes then write that to the W5100 chip.
The files I read are large and can total over 100K of files to send but take only seconds to do.
Note I only have 8K of ram like you so you should be able to make one of 2000 bytes.
Note the string variable is 1001 bytes so we can detect it is full, when it is over 1000 bytes
Now when using variables try to use local variables in sub's and functions as much as possible so put as much of your program into them as you can avoiding global variables see my W5100 web server code for examples
Regards Paul |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Mon Jul 14, 2014 3:45 am Post subject: |
|
|
I know you are using text files, but even so its more efficient to read files as binary.
If you really want to do this, and I must admit i cannot see why you would want to, use a binary ( byte ) array of 512 bytes. That happens to be the card sector size, so reading the card is done in the most efficient way possible, with the minimum number of directory lookups.
That will give you the fastest possible transfer speed. But it will still be far slower than what a PC can do with a card. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
sandy
Joined: 08 Mar 2008 Posts: 79
|
Posted: Wed Jul 16, 2014 10:37 am Post subject: |
|
|
Thanks for the replies, My log looks like below;
Code: |
S.No. DATE X-Variable Y-Variable
1
2
.
.
100
|
Is there a way to copy combinedly 20 lines into internal RAM (say 2Kb) and then shift it to other file location. If I do it one by one it will be slow. Paul your server blog project is good, keep up the good work.
Rgds |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Wed Jul 16, 2014 12:24 pm Post subject: |
|
|
Hello sandy
Have a look at how I read the file from the SD card into the buffer you can use that code (see some below) once you have it in the buffer you need to change cards then write (append) the the buffer to the second card. Then clear the buffer and repeat. Note see the dim of the buffer Also you need $bigstrings look in help
Regards Paul
Code: |
Dim Txbuffer As String * 1000
Dim Txbuf(1001) As Byte At Txbuffer Overlay 'taking into account the terminator at the end of the string
Call Activate_sdcard()
Fl = Filelen(shtml) 'find the length of the file
Call Activate_sdcard
Open Shtml For Binary As #4
' Print "Not CGI >" ; Filetype
Call Activate_sdcard
If Fl > 1000 Then 'send 1000 Bytes
Get #4 , Txbuf(1) , , 1000 'read 1000 Bytes from card
Fl = Fl - 1000 : Wsize = 1000
Else
Get #4 , Txbuf(1) , , Fl 'send the rest
Wsize = Fl : Fl = 0
End If
|
|
|
Back to top |
|
|
sandy
Joined: 08 Mar 2008 Posts: 79
|
Posted: Tue Jul 22, 2014 11:44 am Post subject: |
|
|
Hi;
@Paulvk , Thanks .
@AdrianJ, Thanks I will also look for binary transfer , but it sounds like more coding and would take more effort. |
|
Back to top |
|
|
|