Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

AVR-DOS file copying

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
sandy

Bascom Member



Joined: 08 Mar 2008
Posts: 79

blank.gif
PostPosted: Fri Jul 11, 2014 2:29 pm    Post subject: AVR-DOS file copying Reply with quote

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
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2472
Location: Queensland

australia.gif
PostPosted: Mon Jul 14, 2014 1:01 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1197
Location: SYDNEY

australia.gif
PostPosted: Mon Jul 14, 2014 1:40 am    Post subject: Reply with quote

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
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2472
Location: Queensland

australia.gif
PostPosted: Mon Jul 14, 2014 3:45 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
sandy

Bascom Member



Joined: 08 Mar 2008
Posts: 79

blank.gif
PostPosted: Wed Jul 16, 2014 10:37 am    Post subject: Reply with quote

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
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1197
Location: SYDNEY

australia.gif
PostPosted: Wed Jul 16, 2014 12:24 pm    Post subject: Reply with quote

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
View user's profile
sandy

Bascom Member



Joined: 08 Mar 2008
Posts: 79

blank.gif
PostPosted: Tue Jul 22, 2014 11:44 am    Post subject: Reply with quote

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
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum