Main Page Data Structures File List Data Fields Globals Related Pages

# clib/ide.c File Reference

`#include "define.h"`
`#include <dos.h>`
`#include <stdio.h>`
`#include "ide.h"`
`#include "rtxapi.h"`
`#include "rtos.h"`
`#include "hwapi.h"`

Go to the source code of this file.

## Defines
#define | IDE_IDENTIFY (uchar)0xEC
#define | IDE_READ_SECTOR (uchar)0x20
#define | IDE_WRITE_SECTOR (uchar)0x30
#define | IDE_VERIFY_SECTOR (uchar)0x40
#define | IDE_SEEK (uchar)0x70
#define | IDE_SET_FEATURES (uchar)0xEF
#define | IDE_STANDBY (uchar)0xE2
#define | IDE_IDLE_MODE (uchar)0xE3
#define | IDE_SET_DRV_PARAM (uchar)0x91
#define | IDE_RECALIBRATE (uchar)0x10
#define | IDE_DATA (IDE_PORT0 + 0)
#define | IDE_FEATURE (IDE_PORT0 + 1)
#define | IDE_ERROR (IDE_PORT0 + 1)
#define | IDE_COUNT (IDE_PORT0 + 2)
#define | IDE_SECTOR (IDE_PORT0 + 3)
#define | IDE_CYL_LO (IDE_PORT0 + 4)
#define | IDE_CYL_HI (IDE_PORT0 + 5)
#define | IDE_HEAD (IDE_PORT0 + 6)
#define | IDE_COMMAND (IDE_PORT0 + 7)
#define | IDE_STATUS (IDE_PORT0 + 7)
#define | IDE_CONTROL (IDE_PORT1 + 6)
#define | IDE_ALT_STS (IDE_PORT1 + 6)
#define | IDE_ADDRESS (IDE_PORT1 + 7)
#define | IDE_STS_BSY (uchar)0x80
#define | IDE_STS_DRDY (uchar)0x40
#define | IDE_STS_DWF (uchar)0x20
#define | IDE_STS_DSC (uchar)0x10
#define | IDE_STS_DRQ (uchar)0x08
#define | IDE_STS_CORR (uchar)0x04
#define | IDE_STS_ERR (uchar)0x01
#define | IDE_ERR_BBK (uchar)0x80
#define | IDE_ERR_UNC (uchar)0x40
#define | IDE_ERR_TMOUT (uchar)0x20
#define | IDE_ERR_IDNF (uchar)0x10
#define | IDE_ERR_ABRT (uchar)0x04
#define | IDE_ERR_TK0NF (uchar)0x02
#define | IDE_ERR_AMNF (uchar)0x01
#define | ID_CYL 1
#define | ID_HEADS 3
#define | ID_SECT 6
## Typedefs
typedef unsigned char | uchar
typedef unsigned int | uint
## Functions
uchar near | IDE_waitirq (void)
uchar near | IDE_waitdrq (void)
uchar near | IDE_datarequest (void)
uchar near | IDE_error (void)
uchar near | IDE_status (void)
uchar near | IDE_command (uchar feat, uint cyl, uchar head, uchar sect, uchar cnt, uchar cmd)
uchar near | IDE_LBA_command (uchar feat, unsigned long sector, uchar cnt, uchar cmd)
void | IDE_bit_mode (void)
void | IDE_reset (void)
int | IDE_LBA_read (unsigned long sector, int cnt, unsigned char *buf)
int | IDE_LBA_write (unsigned long sector, int cnt, unsigned char *buf)
int | IDE_read (int cyl, int head, int sect, int cnt, unsigned char *buf)
int | IDE_write (int cyl, int head, int sect, int cnt, unsigned char *buf)
int | IDE_ReadSRAM (unsigned char *bfr)
int | IDE_WriteSRAM (unsigned char *bfr)
int | IDE_identify (void)
## Variables
uchar | err
uchar | sts
T_DRIVE_PARAM | drive = {0}

## Define Documentation

#define ID_CYL 1

| Definition at line 519 of file ide.c. Referenced by IDE_identify().

#define ID_HEADS 3

| Definition at line 520 of file ide.c. Referenced by IDE_identify().

#define ID_SECT 6

| Definition at line 521 of file ide.c. Referenced by IDE_identify().

#define IDE_ADDRESS (IDE_PORT1 + 7)

| Definition at line 57 of file ide.c.

#define IDE_ALT_STS (IDE_PORT1 + 6)

| Definition at line 56 of file ide.c.

#define IDE_COMMAND (IDE_PORT0 + 7)

| Definition at line 52 of file ide.c. Referenced by IDE_command(), IDE_identify(), IDE_LBA_command(), IDE_ReadSRAM(), and IDE_WriteSRAM().

#define IDE_CONTROL (IDE_PORT1 + 6)

| Definition at line 55 of file ide.c. Referenced by IDE_command(), IDE_LBA_command(), and IDE_reset().

#define IDE_COUNT (IDE_PORT0 + 2)

| Definition at line 47 of file ide.c. Referenced by IDE_command(), and IDE_LBA_command().

#define IDE_CYL_HI (IDE_PORT0 + 5)

| Definition at line 50 of file ide.c. Referenced by IDE_command(), and IDE_LBA_command().

#define IDE_CYL_LO (IDE_PORT0 + 4)

| Definition at line 49 of file ide.c. Referenced by IDE_command(), and IDE_LBA_command().

#define IDE_DATA (IDE_PORT0 + 0)

| Definition at line 44 of file ide.c.

#define IDE_ERR_ABRT (uchar)0x04

| Definition at line 79 of file ide.c.

#define IDE_ERR_AMNF (uchar)0x01

| Definition at line 81 of file ide.c.

#define IDE_ERR_BBK (uchar)0x80

| Definition at line 75 of file ide.c.

#define IDE_ERR_IDNF (uchar)0x10

| Definition at line 78 of file ide.c.

#define IDE_ERR_TK0NF (uchar)0x02

| Definition at line 80 of file ide.c.

#define IDE_ERR_TMOUT (uchar)0x20

| Definition at line 77 of file ide.c. Referenced by IDE_waitirq().

#define IDE_ERR_UNC (uchar)0x40

| Definition at line 76 of file ide.c.

#define IDE_ERROR (IDE_PORT0 + 1)

| Definition at line 46 of file ide.c. Referenced by IDE_error().

#define IDE_FEATURE (IDE_PORT0 + 1)

| Definition at line 45 of file ide.c. Referenced by IDE_command(), IDE_LBA_command(), and IDE_waitirq().

#define IDE_HEAD (IDE_PORT0 + 6)

| Definition at line 51 of file ide.c. Referenced by IDE_command(), IDE_identify(), IDE_LBA_command(), IDE_ReadSRAM(), and IDE_WriteSRAM().

#define IDE_IDENTIFY (uchar)0xEC

| Definition at line 33 of file ide.c. Referenced by IDE_identify().

#define IDE_IDLE_MODE (uchar)0xE3

| Definition at line 40 of file ide.c.

#define IDE_READ_SECTOR (uchar)0x20

| Definition at line 34 of file ide.c. Referenced by IDE_LBA_read(), and IDE_read().

#define IDE_RECALIBRATE (uchar)0x10

| Definition at line 42 of file ide.c.

#define IDE_SECTOR (IDE_PORT0 + 3)

| Definition at line 48 of file ide.c. Referenced by IDE_command(), and IDE_LBA_command().

#define IDE_SEEK (uchar)0x70

| Definition at line 37 of file ide.c.

#define IDE_SET_DRV_PARAM (uchar)0x91

| Definition at line 41 of file ide.c.

#define IDE_SET_FEATURES (uchar)0xEF

| Definition at line 38 of file ide.c. Referenced by IDE_bit_mode().

#define IDE_STANDBY (uchar)0xE2

| Definition at line 39 of file ide.c.

#define IDE_STATUS (IDE_PORT0 + 7)

| Definition at line 53 of file ide.c. Referenced by IDE_status().

#define IDE_STS_BSY (uchar)0x80

| Definition at line 63 of file ide.c. Referenced by IDE_reset(), and IDE_waitirq().

#define IDE_STS_CORR (uchar)0x04

| Definition at line 68 of file ide.c.

#define IDE_STS_DRDY (uchar)0x40

| Definition at line 64 of file ide.c. Referenced by IDE_waitirq().

#define IDE_STS_DRQ (uchar)0x08

| Definition at line 67 of file ide.c. Referenced by IDE_datarequest().

#define IDE_STS_DSC (uchar)0x10

| Definition at line 66 of file ide.c. Referenced by IDE_waitirq().

#define IDE_STS_DWF (uchar)0x20

| Definition at line 65 of file ide.c. Referenced by IDE_error().

#define IDE_STS_ERR (uchar)0x01

| Definition at line 69 of file ide.c. Referenced by IDE_error().

#define IDE_VERIFY_SECTOR (uchar)0x40

| Definition at line 36 of file ide.c.

#define IDE_WRITE_SECTOR (uchar)0x30

| Definition at line 35 of file ide.c. Referenced by IDE_LBA_write(), and IDE_write().

## Typedef Documentation

typedef unsigned char uchar

| Definition at line 87 of file ide.c. Referenced by IDE_command(), and IDE_LBA_command().

typedef unsigned int uint

| Definition at line 88 of file ide.c. Referenced by IDE_identify().

## Function Documentation

void IDE_bit_mode | ( | void |  | ) | `[static]`

| Definition at line 290 of file ide.c. References IDE_command(), IDE_SET_FEATURES, and IDE_waitirq(). Referenced by IDE_identify(), and IDE_reset().

uchar near IDE_command | ( | uchar | feat,
|  | uint | cyl,
|  | uchar | head,
|  | uchar | sect,
|  | uchar | cnt,
|  | uchar | cmd
| ) | `[static]`

| Definition at line 163 of file ide.c. References hal_outportb, IDE_COMMAND, IDE_CONTROL, IDE_COUNT, IDE_CYL_HI, IDE_CYL_LO, IDE_FEATURE, IDE_HEAD, IDE_SECTOR, IDE_waitdrq(), and uchar. Referenced by IDE_bit_mode(), IDE_read(), and IDE_write().

uchar near IDE_datarequest | ( | void |  | ) | `[static]`

| Definition at line 130 of file ide.c. References IDE_status(), and IDE_STS_DRQ. Referenced by IDE_identify(), and IDE_waitdrq().

uchar near IDE_error | ( | void |  | ) | `[static]`

| Definition at line 274 of file ide.c. References err, hal_inportb, IDE_ERROR, IDE_status(), IDE_STS_DWF, IDE_STS_ERR, and sts. Referenced by IDE_identify(), IDE_LBA_read(), IDE_LBA_write(), IDE_read(), and IDE_write().

int IDE_identify | ( | void |  | ) |

| Definition at line 527 of file ide.c. References T_DRIVE_PARAM::cylinders, hal_outportb, T_DRIVE_PARAM::heads, T_DRIVE_PARAM::id, ID_CYL, ID_HEADS, ID_SECT, IDE_bit_mode(), IDE_COMMAND, IDE_datarequest(), IDE_error(), IDE_HEAD, IDE_IDENTIFY, IDE_reset(), IDE_waitdrq(), T_DRIVE_PARAM::sector_size, T_DRIVE_PARAM::sectors, and uint.

uchar near IDE_LBA_command | ( | uchar | feat,
|  | unsigned long | sector,
|  | uchar | cnt,
|  | uchar | cmd
| ) | `[static]`

| Definition at line 182 of file ide.c. References hal_outportb, IDE_COMMAND, IDE_CONTROL, IDE_COUNT, IDE_CYL_HI, IDE_CYL_LO, IDE_FEATURE, IDE_HEAD, IDE_SECTOR, IDE_waitdrq(), and uchar. Referenced by IDE_LBA_read(), and IDE_LBA_write().

int IDE_LBA_read | ( | unsigned long | sector,
|  | int | cnt,
|  | unsigned char * | buf
| ) |

| Definition at line 340 of file ide.c. References IDE_error(), IDE_LBA_command(), IDE_READ_SECTOR, and IDE_waitdrq().

int IDE_LBA_write | ( | unsigned long | sector,
|  | int | cnt,
|  | unsigned char * | buf
| ) |

| Definition at line 377 of file ide.c. References IDE_error(), IDE_LBA_command(), IDE_waitdrq(), IDE_waitirq(), and IDE_WRITE_SECTOR.

int IDE_read | ( | int | cyl,
|  | int | head,
|  | int | sect,
|  | int | cnt,
|  | unsigned char * | buf
| ) |

| Definition at line 419 of file ide.c. References IDE_command(), IDE_error(), IDE_READ_SECTOR, and IDE_waitdrq().

int IDE_ReadSRAM | ( | unsigned char * | bfr | ) |

| Definition at line 483 of file ide.c. References hal_outportb, IDE_COMMAND, IDE_HEAD, and IDE_waitdrq().

void IDE_reset | ( | void |  | ) |

| Definition at line 300 of file ide.c. References hal_outportb, IDE_bit_mode(), IDE_CONTROL, IDE_status(), IDE_STS_BSY, IDE_waitirq(), and RTX_Sleep_Time(). Referenced by IDE_identify().

uchar near IDE_status | ( | void |  | ) | `[static]`

| Definition at line 206 of file ide.c. References hal_inportb, IDE_STATUS, and sts. Referenced by IDE_datarequest(), IDE_error(), IDE_reset(), and IDE_waitirq().

uchar near IDE_waitdrq | ( | void |  | ) | `[static]`

| Definition at line 120 of file ide.c. References IDE_datarequest(), and IDE_waitirq(). Referenced by IDE_command(), IDE_identify(), IDE_LBA_command(), IDE_LBA_read(), IDE_LBA_write(), IDE_read(), IDE_ReadSRAM(), IDE_write(), and IDE_WriteSRAM().

uchar near IDE_waitirq | ( | void |  | ) | `[static]`

| Definition at line 139 of file ide.c. References hal_outportb, IDE_ERR_TMOUT, IDE_FEATURE, IDE_status(), IDE_STS_BSY, IDE_STS_DRDY, IDE_STS_DSC, and RTX_Get_System_Ticks(). Referenced by IDE_bit_mode(), IDE_LBA_write(), IDE_reset(), IDE_waitdrq(), and IDE_write().

int IDE_write | ( | int | cyl,
|  | int | head,
|  | int | sect,
|  | int | cnt,
|  | unsigned char * | buf
| ) |

| Definition at line 450 of file ide.c. References IDE_command(), IDE_error(), IDE_waitdrq(), IDE_waitirq(), and IDE_WRITE_SECTOR.

int IDE_WriteSRAM | ( | unsigned char * | bfr | ) |

| Definition at line 502 of file ide.c. References hal_outportb, IDE_COMMAND, IDE_HEAD, and IDE_waitdrq().

## Variable Documentation

T_DRIVE_PARAM drive = {0}

| Definition at line 101 of file ide.c.

uchar err

| Definition at line 100 of file ide.c. Referenced by IDE_error().

uchar sts

| Definition at line 100 of file ide.c. Referenced by IDE_error(), and IDE_status().