Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

IdeTimer.c File Reference

IDE driver::Timing. More...

#include <arch/i386.h>
#include <kernel/clock.h>
#include <kernel/console.h>
#include <kernel/IdeTimer.h>
#include <kernel/IdeLow.h>
#include <kernel/Ide.h>
#include <kernel/keyboard.h>
#include <kernel/task.h>

Go to the source code of this file.

Functions

void GoIdle ()
void Delay (dword ms)
Timer_Struct TimerStart (dword ms)
int TimerElapsed (Timer_Struct Timer)
int WaitForInt (Timer_Struct Timer)
int WaitForBsy (Timer_Struct Timer, word Port)
void AtapiDelay (int Dev)
void WaitKeyPress (char *Message)

Variables

dword ticks
 System ticks.

IdeChannel_StructCurrentChannel


Detailed Description

IDE driver::Timing.

Author:
Luca Giovacchini
Date:
Last update: 2003-11-07
Note:
Copyright (©) 2003 Luca Giovacchini
This driver is based on Atadrv by Hale Landis but it is completely rearranged for the minirighi32.
IMPORTANT!!!
Here you can find all subs regarding waiting and timing. Look at the specific sub comment.

Definition in file IdeTimer.c.


Function Documentation

void AtapiDelay int    Dev
 

Definition at line 146 of file IdeTimer.c.

00147 {
00148         if ( CurrentChannel->Device[Dev].Type == CC_DEVTYPE_ATAPI )
00149                 delay(HDC_ATAPIDELAY);
00150 }

void Delay dword    ms
 

Definition at line 44 of file IdeTimer.c.

00045 {
00046         
00047         dword Start=ticks;
00048         // we work with integer and not float, we have resolution greater than 1 ms
00049         // so we must trunc at the tick higher expected
00050         dword Stop;
00051         byte Cross;
00052         if ( (ms*HZ)%1000 == 0 )
00053                 // We can wait exactely ms 
00054                 Stop=Start+ms*HZ/1000;
00055         else
00056                 // We must wait little more than ms because our 
00057                 // timer resolution can't permit to wait exactely ms
00058                 Stop=(Start+ms*HZ/1000)+1;
00059 
00060         Cross=(Stop<Start);
00061         // need to pay attention while waiting 
00062         // for overflow of ticks and overflow of Stop
00063         while ( Cross ? (ticks >= Start) || (ticks < Stop) : (ticks>=Start) && (ticks<Stop) )
00064                 GoIdle();
00065 
00066 }

void GoIdle  
 

Definition at line 32 of file IdeTimer.c.

00033 {
00034         dword IF = GET_IF();
00035         // Auto-sleep //
00036         enable();
00037         idle(); 
00038         SET_IF(IF);
00039 }

int TimerElapsed Timer_Struct    Timer
 

Definition at line 90 of file IdeTimer.c.

00091 {
00092         // need to pay attention for overflow of ticks while waiting
00093         // and overflow of Stop
00094         return ( Timer.Cross ? (ticks < Timer.Start) && (ticks >= Timer.Stop) : (ticks<Timer.Start) || (ticks>=Timer.Stop) );
00095 }

Timer_Struct TimerStart dword    ms
 

Definition at line 71 of file IdeTimer.c.

00072 {       
00073         Timer_Struct Timer;
00074         Timer.Start=ticks;
00075 
00076         if ( ms*HZ % 1000 == 0 )
00077                 // We can wait exactely ms
00078                 Timer.Stop=Timer.Start+ms*HZ/1000;
00079         else
00080                 // We must wait little more than ms because our
00081                 // timer resolution can't permit to wait exactely ms
00082                 Timer.Stop=(Timer.Start+ms*HZ/1000)+1;
00083         Timer.Cross=(Timer.Stop<Timer.Start);
00084         return Timer;
00085 }

int WaitForBsy Timer_Struct    Timer,
word    Port
 

Definition at line 126 of file IdeTimer.c.

00127 {
00128         byte Status=0;
00129         
00130         while (TRUE)
00131         {
00132                 Status = InPortAta( Port );       // poll for not busy
00133                 if ( ( Status & HDC_STAT_BSY ) == 0 )
00134                         return FALSE;
00135                 
00136                 if ( TimerElapsed(Timer) )               // time out yet ?
00137                         return TRUE;
00138                 
00139                 GoIdle();
00140         }
00141 }

int WaitForInt Timer_Struct    Timer
 

Definition at line 103 of file IdeTimer.c.

00104 {
00105         while (TRUE)
00106         {
00107                 if (CurrentChannel->IntDone == TRUE)
00108                 {
00109                         // reset interrupt flag;
00110                         CurrentChannel->IntDone=FALSE;
00111                         return FALSE;
00112                 }
00113 
00114                 if ( TimerElapsed(Timer) )
00115                         return TRUE;
00116 
00117                 GoIdle();
00118         }
00119 }

void WaitKeyPress char *    Message
 

Definition at line 156 of file IdeTimer.c.

00157 {
00158         int Tmp;
00159         if (Message)
00160                 kprintf("\n\r%s\n\r",Message);
00161         Tmp=kgetchar();
00162 }


Variable Documentation

IdeChannel_Struct* CurrentChannel
 

Definition at line 26 of file IdeTimer.c.

dword ticks
 

System ticks.

Definition at line 25 of file IdeTimer.c.


Generated on Fri Feb 20 15:32:18 2004 for Minirighi by doxygen1.2.18