View previous topic :: View next topic |
Author |
Message |
ardroudi
Joined: 18 Oct 2005 Posts: 4 Location: Tehran
|
Posted: Wed Feb 01, 2006 12:56 pm Post subject: Problem in AVRDOS And Harddisk |
|
|
Hi.
I'm trying to setup atmega128 and a harddisk with avrdos
I use the test program, but error 17 occurs during file system init.
I dont know what should i do.
please help me
the harddisk is formated with fat32 and has two Partitions.
one is primary dos partition and another is logical partition.
Here is the code :
$regfile = "M128def.dat"
$crystal = 12000000
'------------------------------------------------------------------------------
$baud = 9600
Open "Com1:" As Binary As #1 ' use #1 for fs_interpreter
Config Clock = Soft
Enable Interrupts
Config Date = Mdy , Separator = .
'------------------------------------------------------------------------------
Dim Btemp1 As Byte
'------------------------------------------------------------------------------
Print #1 , "Wait for Drive"
$Include "Config_HardDisk_M128.bas"
If Gbdriveerror = 0 Then
$Include "Config_AVR-DOS.BAS"
Print #1 , "Init File System ... ";
Btemp1 = Initfilesystem(1) ' Partition 1
' use 0 for drive without Master boot record
If Btemp1 <> 0 Then
Print #1 , "Error: " ; Btemp1 ; " at Init file system"
Else
Print #1 , " OK"
Print #1 , "Filesystem: " ; Gbfilesystem
Print #1 , "FAT Start Sector: " ; Glfatfirstsector
Print #1 , "Root Start Sector: " ; Glrootfirstsector
Print #1 , "Data First Sector: " ; Gldatafirstsector
Print #1 , "Max. Cluster Nummber: " ; Gwmaxclusternumber
Print #1 , "Sectors per Cluster: " ; Gbsectorspercluster
Print #1 , "Root Entries: " ; Gwrootentries
Print #1 , "Sectors per FAT: " ; Gwsectorsperfat
Print #1 , "Number of FATs: " ; Gbnumberoffats
End If
Else
Print #1 , "Error during Drive Init: " ; Gbdriveerror
End If |
|
Back to top |
|
|
oe9vfj
Joined: 17 Jun 2004 Posts: 269 Location: Austria, Hard
|
Posted: Thu Feb 02, 2006 12:51 pm Post subject: |
|
|
Hi ardroudi ,
Check, whether you can read the raw sectors of the disk.
If you use the TEST_DOS_Drive program with the FS_Interpreter you can dump a sector (for example sector 0) with SD 0.
Sector 0 is the master boot record. If you get an output from the command SD 0 without error, can you please post it, so I can see, what is the problem? _________________ regards Josef
DOS - File System for BASCOM-AVR on http://members.aon.at/voegel |
|
Back to top |
|
|
oe9vfj
Joined: 17 Jun 2004 Posts: 269 Location: Austria, Hard
|
|
Back to top |
|
|
ardroudi
Joined: 18 Oct 2005 Posts: 4 Location: Tehran
|
Posted: Sat Feb 04, 2006 11:17 am Post subject: |
|
|
Dear Josef ,
It is much better for me to read and write raw data in memories such as mmc , hard disk or compact flash.
let me describe my project for you :
sorry. it is very long and i hope that you read this note and help me.
I designed a LED sign board in 3 colors and size 128*64.(it need 2Kbyte for each picture frame). main controller is a FPGA that send address out and read related data for that address. and the FPGA repeat this for another address.So in a loop the FPGA send address number 0 to 2047 and wants to read data for each address.
I must use a mass storage memory for that.(more than 32Mbyte)
It is too hard for me to write a VHDL code for the FPGA that read a MMC or hard disk or ...
So i decide to use an AVR.
AVR continuously read address (that sent by FPGA) and send related data that stored in internal 2Kbyte ram.AVR exactly act like a 2Kbyte ram.
but by a timer interrupt ,it will update the internal 2Kbyte ram with new data and after that it return to the past job(acting like a ram).
AVR code is look like below :
-START
-MAINLOOP:
-----ADDRESS = PORTX 'fpga will put it address to portx of avr
-----PORTY = RAM(ADDRESS) 'avr send related data to porty for fpga
-GOTO MAINLOOP
-TIMER INTERRUPT ROUTIN :
-----FOR I = 1 TO 2047
----------READ NEW DATA FROM A MEMORY
----------RAM(I) = NEW DATA
-----NEXT I
-RETURN
-END
You know when we want to show an animation, we must change picture frames rapidly to create the animation.
I made my animation data, frame by frame, and i put them to a MMC.
AVR in timer interrupt routin read 2Kbyte data (4 Sectors) from MMC.
but MMC is a little slow and main problem is here:
A GAP WILL OCCUR BITWEEN ANIMATION FRAMES.
NOW THE ANIMATION IS BLINKING AND IT'S NOT GOOD!
AVR must update internal ram in less than 20ms for a good animation.
So i have to use a fast and huge memory. MMC is good in amount of memory but not enough fast becouse of SPI mode.
I think harddisk is good because it send 16bit of data in a moment.
If i use a harddisk or compactflash i have to read data sector by sector.
I found AN#123 (Accessing a Compact Flash Card from BASCOM) files.
functions in file FlashCardDrive.bas is very suitable for me.
But i don't know how to use it for a harddisk.
please help me to read and write sectors of a harddisk.
Thank you
Best Regards
---------------------------
Amirreza Ardroudi |
|
Back to top |
|
|
ardroudi
Joined: 18 Oct 2005 Posts: 4 Location: Tehran
|
Posted: Sun Feb 05, 2006 2:32 pm Post subject: |
|
|
Hi ,
In fact i want to use AN#123(Accessing a Compact Flash Card from BASCOM) files and fuctions, to read and write sectors of a harddisk.
Using Avr-Dos is not necessary for me.
Thank you in advance.
----------------------------
Amirreza Ardoudi |
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Sun Feb 19, 2006 9:23 am Post subject: low level routines |
|
|
There are some low level harddisk and compact flash routines on my homepage.
/software/bascom-examples
Have fun
Ben Zijlstra |
|
Back to top |
|
|
ardroudi
Joined: 18 Oct 2005 Posts: 4 Location: Tehran
|
Posted: Sun Feb 19, 2006 9:31 am Post subject: |
|
|
Thank you for your help ben.
I will check it. |
|
Back to top |
|
|
oe9vfj
Joined: 17 Jun 2004 Posts: 269 Location: Austria, Hard
|
Posted: Sun Feb 19, 2006 8:01 pm Post subject: |
|
|
You can not use the code from AN123 for a HardDisk. The code works with the CF with 8-bit data exchange. Most HD support only an 16-Bit data bus.
You can read and write single sectors from/to Harddisk with the driver provided with AVR-DOS.
Check the schematic http://members.aon.at/voegel/Downloads/Driver/CF_HD/HardDisk_Schematic.gif and include the HD-driver to your application with following code:
Code: | $Include "Config_HardDisk_M128.bas"
If gbDriveError <> 0 then
Print "Error at Hard Disk Init " ; gbDriveError
' Insert here your error handler
End If |
You must check the Pin-setting in Config_HardDisk_M128.bas, if you use other pins than them of the schematic. You need Cf_HD.LBX in your Lib-Path. In the Basic file Config_HardDisk_M128.bas the Drive Init routine is called. Whether the Init was succesful, you can check at the return value in the variable gbDriveError. Values greater than zero indicate an error.
Now you can read or write blocks of 512 Bytes (Sector) with the Hard Disk.
Code: | Dim bError as Byte
Dim aBuffer(512)as Byte' Hold Sector to and from CF-Card
Dim wSRAMPointer as Word' Address-Pointer for write
Dim lSectorNumber as Long' Sector Number
' give Address of first Byte of the 512 Byte Buffer to Word-Variable
wSRAMPointer =VarPtr(aBuffer(1))
' Set Sectornumber, sector 32 normally holds the Boot record sector of first partition
lSectorNumber = 32
' Now read in sector 32 from CF-Card
bError = DriveReadSector( wSRAMPointer , lSectorNumber)
' Now Sector number 32 is in Byte-Array bBuffer |
Please note that you have not to pass the buffer as parameter to DriveReadSector, you have to pass a Word Variable with the starting address to the function.
This is done to be able to use any SRAM-range to tansferring with the drive. You must only pass the SRAM address as first parameter. _________________ regards Josef
DOS - File System for BASCOM-AVR on http://members.aon.at/voegel |
|
Back to top |
|
|
|