Some problems about floppy disk driver

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Doroty

Some problems about floppy disk driver

Post by Doroty »

For 3 weeks Im trying to implement my floppy disk driver, but I still have problems. Im trying to read one sector starting from second sector. But results of my read sector says that Im trying to read 2 sectors starting from 3rd sector.
   
for command "FloppyRead(2, 1, Buf);"
FDCResulsts: 0 0 0 0 0 3 2

Ill be glad if someone check my code. I couldnt find where Im wrong. Ill become crazyyy.....

Code: Select all

void motoron(void)
{
    out(FDC_DOR, CMD_MOTORON);
    delay(1500);
}

void motoroff(void)
{
    delay(1500);
    out(FDC_DOR, CMD_MOTOROFF);
}

bool recalibrate(void)
{
    int recalibratemaxtry = 10;

    motoron();

    for(; recalibratemaxtry > 0; recalibratemaxtry--) {
        JobDone = FALSE;
        sendbyte(CMD_RECAL);
        sendbyte(0); // [......00]DriveNo 0->A

        while(!JobDone);
        if(CheckInterruptStatus())
            break;
    }

    motoroff();

    if(CurrentCylindir != 0)
        return FALSE;
        //SetError(FDC_RECALIBRATE_FAIL);

    return TRUE;
}

bool sendbyte(byte fByte)
{
    int FloppyTimeOut = 128;
    char Buf[50];

    for(;FloppyTimeOut > 0; FloppyTimeOut--) {
        if((in(FDC_MSR) & (ST_DATAREGREADY | ST_DIR)) == ST_DATAREGREADY) {
            out(FDC_DATA, fByte);
            return TRUE;
        }
        in(0x80); //Delay
    }

//    SetError(FLOPPY_TIME_OUT);
    Print("\nSend byte error!!!");
    Print(FormatString(Buf, "-> %d\n", (in(FDC_MSR))));
    return FALSE;
}

byte getbyte(void)
{
    int FloppyTimeOut = 128;

    for(;FloppyTimeOut > 0; FloppyTimeOut--) {
        if((in(FDC_MSR) & (ST_DATAREGREADY | ST_DIR | ST_BUSY)) == (ST_DATAREGREADY | ST_DIR | ST_BUSY))
            return in(FDC_DATA);
        in(0x80); //Delay
    }

//    SetError(FLOPPY_TIME_OUT);
    Print("Get byte error\n");
    return FALSE;
}

bool seek(unsigned int CylindirNo)
{
    if(CurrentCylindir == CylindirNo)
        return TRUE;

    JobDone = FALSE;
    sendbyte(CMD_SEEK);
    sendbyte(0);         //[.....0..]HeadNo(0), [......00]DriveNo(A)
    sendbyte(CylindirNo);

    while(!JobDone);

    if(CheckInterruptStatus()) {
        if((CurrentCylindir == CylindirNo) && (status[0] == 0x20))
            return TRUE;
    }

    Print("\nFDC error!");
    return FALSE;
}

void FloppyHandler(void)
{
    JobDone = TRUE;

    Print("\n!IRQ6!->[Done]");
    ResetPIC(MASTER_PIC);
}

Doroty

Some problems about floppy disk driver

Post by Doroty »

extern void FloppyHandler(void);

asm (
".globl _FloppyISR \n"
"_FloppyISR: \n"
" pusha \n"
" pushw %ds \n"
" pushw %es \n"
" pushw %ss \n"
" pushw %ss \n"
" popw %ds \n"
" popw %es \n"
" \n"
" call _FloppyHandler \n"
" \n"
" popw %es \n"
" popw %ds \n"
" popa \n"
" iret \n"
);

bool GetFloppyResults(void)
{
int FloppyTimeOut = 10000;
int ResNum = 0;
int Status;
char Buf[50];

for(; FloppyTimeOut > 0; FloppyTimeOut--) {
Status = in(FDC_MSR) & (ST_DATAREGREADY | ST_DIR | ST_BUSY);
if(Status == (ST_DATAREGREADY | ST_DIR | ST_BUSY)) {
if(ResNum >= MAX_FDC_RESULTS) {
//SetError(FLOPPY_MAX_ERROR);
return FALSE;
} else
FdcResults[ResNum++] = in(FDC_DATA);
} else if(Status == ST_DATAREGREADY) {
FdcResults[ResNum] = NULL;

Print(FormatString(Buf, "FDCRes: %d %d %d %d %d %d %d %d %d\n", FdcResults[0], FdcResults[1], FdcResults[2], FdcResults[3], FdcResults[4], FdcResults[5], FdcResults[6], FdcResults[7], FdcResults[8], FdcResults[9]));
return TRUE;
}
}
//SetError(FLOPPY_TIME_OUT);
return FALSE;
}

bool CheckInterruptStatus(void)
{
char Buf[50];

sendbyte(CMD_SENSEI);

status[0] = getbyte();
if(status[0] == 0x80) {
Print("\nFDC_INVALID_COMMAND");
return FALSE;
}

CurrentCylindir = getbyte();

Print(FormatString(Buf, "CIS: St0:%d CurCyl:%d\n", status[0], CurrentCylindir));
return TRUE;
}

bool FloppyDo(unsigned int StartSector, unsigned int Length, void *Buffer, bool RW)
{
unsigned int cylinder, head, sector;
char Buff[50];
unsigned char *DMATransferAddress;
int tries;


DMATransferAddress = (char *) DMATRANSFERADDRESS;

if((StartSector < 0) && ((StartSector + Length) > (FDC_HEADS * FDC_SECTORSPERTRACK * FDC_TRACKS)))
return FALSE;
//SetError(FDC_INVALID_REQUEST);

if(RW == FDC_WRITE)
memcpy(DMATransferAddress, Buffer, Length * FDC_SECTORSIZE);
else
memcpy(DMATransferAddress, "Empty Buffer....", Length * FDC_SECTORSIZE);

Block2CHS(StartSector, &cylinder, &head, ?or);

motoron();
for(tries = 0; tries < 3; tries++) {

if(in(FDC_DIR) & 0x80) {
Print("disk change");
seek(1);
recalibrate();
continue;
}
seek(cylinder);

JobDone = FALSE;
Print("\nJob Done false...");
out(FDC_CCR, 0x00); // Set Data Transfer Rate to 500 kbits/s

if(RW == FDC_READ){
SetupDMAChannel(CH_FDC, DMACMD_FDCREAD, DMATransferAddress, Length * FDC_SECTORSIZE);
sendbyte(CMD_READ);
} else {
SetupDMAChannel(CH_FDC, DMACMD_FDCWRITE, DMATransferAddress, Length * FDC_SECTORSIZE);
sendbyte(CMD_WRITE);
}

sendbyte(head << 2);
sendbyte(cylinder);
sendbyte(head);
sendbyte(sector);
sendbyte(2); //Sector size 128*2^X ,X is parameter = 2
sendbyte(FDC_SECTORSPERTRACK);
sendbyte(FDC_GAP3RW);
sendbyte(0xFF);

while(!JobDone);

if(!GetFloppyResults()) {
Print("Floppy do error!");
return FALSE;
}
break;
}

if(RW == FDC_READ)
memcpy(Buffer, DMATransferAddress, Length * FDC_SECTORSIZE);

motoroff();

return TRUE;
}

bool FloppyRead(unsigned int StartSector, unsigned int Length, void *Buffer)
{
FloppyDo(StartSector, Length, Buffer, FDC_READ);
return TRUE;
}

bool FloppyWrite(unsigned int StartSector, unsigned int Length, void *Buffer)
{
FloppyDo(StartSector, Length, Buffer, FDC_WRITE);
return TRUE;
}

void Block2CHS(int Block, int *cylinder, int *head, int *sector)
{
*head = (Block % (FDC_SECTORSPERTRACK * FDC_HEADS)) / (FDC_SECTORSPERTRACK);
*cylinder = Block / (FDC_SECTORSPERTRACK * FDC_HEADS);
*sector = Block % (FDC_SECTORSPERTRACK + 1);
}
Doroty

Re:Some problems about floppy disk driver

Post by Doroty »

No answer?
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Some problems about floppy disk driver

Post by Neo »

First of all it would be better if you attached the source instead of filling up here with code(its more readable that way).
Anyway...
is that delay(1500) for a 500ms ? (this is more than enough and needed only at poweron)
next the recalib command does not need to poweron the FDC, on the contrary you have to recalibrate the FDC after calling the powering on function (both which are called from your read function generally).
then I do hope your constants and #defines are correct?
are you initializing the FDC properly at the beginning? (i can't see any init code here) not init'ing the FDC properly was my real problem when i tried out my FDC driver.discussed here
And finally i do think you'll get it working if you follow everything according to the instructions. (you have the manuals don't you??)
Only Human
Dorooty

Re:Some problems about floppy disk driver

Post by Dorooty »

Neo wrote: First of all it would be better if you attached the source instead of filling up here with code(its more readable that way).
Ild like to attach the source file, but even I have logged in, whenever I try to read a topic, the site shows me as a guest.
So I can not attach my source. And I wrote this twice, because, it doest allows me to use my nick and it says this nick is in use..:( (I can log in but cant send messages with my nick)
Anyway...
is that delay(1500) for a 500ms ? (this is more than enough and needed only at poweron)
to guarantie delay...
next the recalib command does not need to poweron the FDC, on the contrary you have to recalibrate the FDC after calling the powering on function (both which are called from your read function generally).
Ok, Ill check my tutorials again.
then I do hope your constants and #defines are correct?
are you initializing the FDC properly at the beginning? (i can't see any init code here) not init'ing the FDC properly was my real problem when i tried out my FDC driver.And finally i do think you'll get it working if you follow everything according to the instructions. (you have the manuals don't you??)
My constants are correct according to tutorials I have. And I dont init my FDC, is it really necessary? and I dont have tutorials, the ones I download are corrupted. So I try to implement according to some tutorials. Ill glad if you give a working url to download manual. thanks for reply, Ill inform with results....
Tim

Re:Some problems about floppy disk driver

Post by Tim »

Dorooty wrote:Ild like to attach the source file, but even I have logged in, whenever I try to read a topic, the site shows me as a guest.
So I can not attach my source. And I wrote this twice, because, it doest allows me to use my nick and it says this nick is in use..:( (I can log in but cant send messages with my nick)
Looks like a problem with cookies. Make sure your web browser isn't blocking cookies from this site.
Dorooty

Re:Some problems about floppy disk driver

Post by Dorooty »

Tim Robinson wrote: Looks like a problem with cookies. Make sure your web browser isn't blocking cookies from this site.
But I can log in. As for now, I logged in but while trying to write you an answer, it logged me out.:(

And if any one send the url of Code Slasher's floppy tutorial, Ill be glad... I couldnt find on net..
Karig

Re:Some problems about floppy disk driver

Post by Karig »

Dorooty wrote: But I can log in. As for now, I logged in but while trying to write you an answer, it logged me out.:(
Try logging in again and clicking the box that says to keep you logged in at all times -- either that, or increase the number in the box that says how many minutes to keep you logged in.

[Edited to add the quote]
someone

Re:Some problems about floppy disk driver

Post by someone »

The only tut that I know of is http://debs.future.easyspace.com/Progra ... loppy.html You have to look into other kernels and see how other people implemented it.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Some problems about floppy disk driver

Post by Neo »

i used debs refrence myself but i would rather recommend intels official manual on the 82077AA floppy controller. i think you can find it in their site or at [url=http://www.osdever.net"]www.osdever.net[/url] it shows you the info in a much better way IMHO.
Only Human
aladdin

Re:Some problems about floppy disk driver

Post by aladdin »

I think the your source code works well, but I want to see what have you wrote in ur fread function, cause I had the same problem with my driver, and that was because, when you send read commands (function 0x66 or 0xe6) you must wait for data transfer by checking status register.
you can also try to check if the seek function put the head on the right cylender (by reading interrupt status register ).
..
Post Reply