Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

driveinit() & initfilesystem() problem resolved

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR-DOS
View previous topic :: View next topic  
Author Message
njepsen

Bascom Member



Joined: 13 Aug 2007
Posts: 469

newzealand.gif
PostPosted: Tue Aug 02, 2022 8:08 am    Post subject: driveinit() & initfilesystem() problem resolved Reply with quote

After some more testing and re-reading the docs several times, the following code runs without creating unexplained errors.

Code:

'****************************************
$regfile = "m1284pdef.dat"
$crystal = 9830400
$framesize =1500
$hwstack = 400                                              '
$swstack = 400

'Reset Cause. Must go here
'-------------------------
dim breset as byte
breset = getreg(r0)
MCUCSR =0
$frameprotect = 1
config submode = old                                        'old =  need to declare subs or functions
$include "config_mmcsd_hc.inc"                              'set up the high capacity SD card comms

'Lots of dims, cofig of subs & functions etc


do
    'main loop code
    ' before any SD card write, sd_error_check is called



loop

 '****************************************************************************
 function sd_err_check()as byte
    're-written 2.08.2022

    '(
       ------------------------------------------------------------------------------------------------
      |   Config_mmcsd_HC.inc   is included at boot.                                                   |
      |   Driveinit is run when this include happens.                                                  |
      |   This also sets the variables  mmcsd_card type and Gbdriveerror                               |
      |                                                                                                |
      |   If drive error is 0 we can load DOS                                                          |
      |   If a card is removed and reinserted hot,then driveinit and   initfilesystem must be re-run   |
      --------------------------------------------------------------------------------------------------

    ')

    local error_count as byte
    dim miscb as byte
    error_count = 0


      Select Case Mmcsd_cardtype    'card type is set when we call earlier config mmcsd_hc.inc
        Case 1
          Print #1, ">. MMC-Card detected"
        Case 2
          Print #1,">. SD-Card Spec. 1.x detected"
        Case 4
          Print #1,">> SD-Card Spec. 2.0 detected"
        Case 12
          Print #1,">> SD-Card Spec. 2.0 High Capacity detected"
        Case Else
          Print #1,">> No Card detected"
          error_count  = 3    'this results in 3 retries and exit.

      End Select


    for n = 1 to 3



        if Gbdriveerror = 0 then
           $include "Config_AVR-DOS.inc"
           print #1, ">> initilise file system"
           miscb = initfilesystem(1)
           if miscb = 0 then
             print #1,"{027}[92m";">> drive init & file init are good"; "{027}[0m"     'green
             exit for

           else
             print #1,"{027}[91m";">> file init is bad"; "{027}[0m"     'red
              miscb = driveinit()

           end if
        else
           Print #1,"{027}[91m";">> driveinit is bad"; "{027}[0m"       'red
           miscb = driveinit()

        end if
        error_count = 1


    next

     sd_err_check = error_count

 end function





 '*****************************************************************************************







 

I'm guessing that the error I was getting was caused by calling driveinit twice but im not sure about this.

Question: what is the difference between including a .bas and a .inc and why the 2 possibilities ?

_________________
Neil
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Tue Aug 02, 2022 11:45 am    Post subject: Reply with quote

what i tried to explain in another reply is that driveinit depends on the driver and hardware.
AVR-DOS supports various media : hard disc, MMC,SD, xram for simulation

each media has a different hardware connection, using SPI, soft spi, ports, or nothing.
driveinit() you find in the lib driver.
for ATA/HD the port pins are brought to the right state and it is checked if there is a drive.
for MMC/SD the SPI is initialized. and the card init procedure is executed. this only has to be done once.
i do not see a reason why it would fail when done a second time. especial when you eject/insert the card.
but is suspect the vcc. there is a difference between you power the whole circuit or just hot swap the card.


there is no difference between including bas or inc files. you can include any file you like. as long it contains bascom code.
long time ago code was not that much so all wend in one bas file. include could be done by including other bas file.
but it is better to use inc so it is clear that this is to be included and will not run on its own. that is why most samples that include files were changed to include INC instead of bas.

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR-DOS 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