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.
earlz
Member
Posts: 1546 Joined: Thu Jul 07, 2005 11:00 pm
Contact:
Post
by earlz » Sun Jul 16, 2006 5:34 pm
In my FDD code I use timeout code, like this:
Code: Select all
unsigned char FDD_ReadyGet(){
unsigned int delay;
delay=timer_ticks+2000; //2second timeout
while(delay>timer_ticks){
if((inportb(MAIN_STAT)&0xC0)==0xC0){return 1;}
}
return 0;
}
I don't need to insert a wait() in there do I like, the Main Status Register is never out of date is it?
and for other ports do I need a wait between in/outport to give it time?
bubach
Member
Posts: 1223 Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:
Post
by bubach » Mon Jul 17, 2006 1:24 pm
Most people programming in C use these, not sure wheter they really are from Intel or not:
Code: Select all
/* sendbyte() routine from intel manual */
void sendbyte(int byte)
{
volatile int msr;
int tmo;
for (tmo = 0;tmo < 128;tmo++) {
msr = inportb(FDC_MSR);
if ((msr & 0xc0) == 0x80) {
outportb(FDC_DATA,byte);
return;
}
inportb(0x80); /* delay */
}
}
/* getbyte() routine from intel manual */
int getbyte()
{
volatile int msr;
int tmo;
for (tmo = 0;tmo < 128;tmo++) {
msr = inportb(FDC_MSR);
if ((msr & 0xd0) == 0xd0) {
return inportb(FDC_DATA);
}
inportb(0x80); /* delay */
}
return -1; /* read timeout */
}
HTH, Christoffer