Author | Matthew Schinkel - borntechi.com, copyright (c) 2009, all rights reserved. |
Adapted-by | |
Compiler | >=2.4k |
this library provides functions for pata/ide hard disk drives.
"connecting ide drives by tilmann reh" - http://www.gaby.de/gide/IDE-TCJ.txt IDE hardware reference & information document by alex t. ivopol ATA Attachement with Packet Interface 6 - d1410r3-ATA-ATAPI-6.pdf
- If you are not using Alternate Status, Digital Output or Drive Address registers pins cs1 & cs0 can be saved by connecting these ide pins to cs0-high, cs1-low at ide connector. normal operation does not require these pins. Set "CONST BYTE PATA_HD_USE_CS0_CS1_PINS = TRUE" if you will be using these registers - You MUST write full sectors of 512 bytes. - this lib does not do error checking
const PATA_HD_PRECOMP_REG = 9 -- write precomp reg
const PATA_HD_COMMAND_REG = 15 -- command register
const PATA_HD_SPIN_DOWN = 0xE0 -- turn off the drive's motor
const dword LARGE_ARRAY_3_SIZE = 512 -- choose number of array variables
const PATA_HD_SEC_COUNT_REG = 10 -- sector count
const PATA_HD_STATUS_REG = 15 -- status register (creates interupt)
const bit PATA_HD_WAIT_READ = 0 -- wait for sector buffer to fill it's contents with data from disk platters
const PATA_HD_CYL_HIGH_REG = 13 -- cylinder high
var byte pata_hd_sector_count = 0 -- counds sectors read, must be a byte.
const bit PATA_HD_WAIT_WRITE = 1 -- wait for sector buffer to empty it's contents to disk platters
const PATA_HD_RECALIBRATE = 0x10 -- sends drive heads to cyl 0, SC, SN, and SDH are not changed
const PATA_HD_CYL_LOW_REG = 12 -- cylinder low
const PATA_HD_DODC_REG = 16 -- digital output / device control
const PATA_HD_WRITE_SECTORS = 0x30 -- write data to sector(s)
const SD_CARD = 1
const PATA_HD_SEC_NUM_REG = 11 -- sector number
const PATA_HD_ALT_STATUS_REG = 16 -- alternate status (no interupt)
var dword pata_hd_sector_select = 0
const PATA_HD_ADDRESS_REG = 17 -- drive address
const PATA_HARD_DISK = 0 -- data media constants for fat32 lib
const PATA_HD_SDH_REG = 14 -- sector/drive/head register
const PATA_HD_IDENTIFY_DRIVE = 0xEC -- read drive info such as make/modem/sn/drive size
const dword LARGE_ARRAY_3_VARIABLE_SIZE = 1 -- choose size of variables
const DATA_MEDIA = PATA_HARD_DISK
var byte pata_hd_word_count = 0 -- counts words read from current sector, must be a byte
const PATA_HD_READ_SECTORS = 0x20 -- reads data from sector(s)
var bit pata_hd_48_bit_lba_support = false -- currently this lib does not support drives > 137,438,952,960 bytes (28 bit addressing)
const PATA_HD_SPIN_UP = 0xE1 -- turn on the drive's motor
const PATA_HD_ERROR_REG = 9 -- error register
const PATA_HD_DATA_REG = 8 -- data register
pata_hd_start_write(dword in address)
pata_hd_write_pulse( byte in z )
pata_hd_data_request(bit in read_write)
pata_hd_go_to_sector(dword in sector, byte in sec_count)
pata_hd_read_data(byte out low_byte, byte out high_byte)
pata_hd_read_sector()
pata_hd_read_pulse(dword in z)
pata_hd_register_read(byte in register, byte out low_byte)
pata_hd_select_register(byte in register)
pata_hd_write_to_sector_end(byte in input_byte)
pata_hd_init()
pata_hd_set_address(byte in pata_hd_head_addr, byte in cyl_high_addr, byte in cyl_low_addr, byte in sec_num_addr, byte in sec_count)
pata_hd_drive_ready()
pata_hd_register_write(byte in register, byte in low_byte)
pata_hd_start_read(dword in address)
pata_hd_write_data(byte in low_byte, byte in high_byte)
pata_hd_busy()
pata_hd_stop_read()
const PATA_HD_PRECOMP_REG = 9 -- write precomp reg
writeable registers
const PATA_HD_COMMAND_REG = 15 -- command register
No documentation found
const PATA_HD_SPIN_DOWN = 0xE0 -- turn off the drive's motor
No documentation found
const dword LARGE_ARRAY_3_SIZE = 512 -- choose number of array variables
No documentation found
const PATA_HD_SEC_COUNT_REG = 10 -- sector count
No documentation found
const PATA_HD_STATUS_REG = 15 -- status register (creates interupt)
No documentation found
const bit PATA_HD_WAIT_READ = 0 -- wait for sector buffer to fill it's contents with data from disk platters
other constants used for pata_hd_data_request()
const PATA_HD_CYL_HIGH_REG = 13 -- cylinder high
No documentation found
var byte pata_hd_sector_count = 0 -- counds sectors read, must be a byte.
No documentation found
const bit PATA_HD_WAIT_WRITE = 1 -- wait for sector buffer to empty it's contents to disk platters
No documentation found
const PATA_HD_RECALIBRATE = 0x10 -- sends drive heads to cyl 0, SC, SN, and SDH are not changed
common commands for command register:
const PATA_HD_CYL_LOW_REG = 12 -- cylinder low
No documentation found
const PATA_HD_DODC_REG = 16 -- digital output / device control
No documentation found
const PATA_HD_WRITE_SECTORS = 0x30 -- write data to sector(s)
No documentation found
const SD_CARD = 1
No documentation found
const PATA_HD_SEC_NUM_REG = 11 -- sector number
No documentation found
const PATA_HD_ALT_STATUS_REG = 16 -- alternate status (no interupt)
No documentation found
var dword pata_hd_sector_select = 0
other vars
const PATA_HD_ADDRESS_REG = 17 -- drive address
No documentation found
const PATA_HARD_DISK = 0 -- data media constants for fat32 lib
No documentation found
const PATA_HD_SDH_REG = 14 -- sector/drive/head register
No documentation found
const PATA_HD_IDENTIFY_DRIVE = 0xEC -- read drive info such as make/modem/sn/drive size
No documentation found
const dword LARGE_ARRAY_3_VARIABLE_SIZE = 1 -- choose size of variables
No documentation found
const DATA_MEDIA = PATA_HARD_DISK
No documentation found
var byte pata_hd_word_count = 0 -- counts words read from current sector, must be a byte
variables
const PATA_HD_READ_SECTORS = 0x20 -- reads data from sector(s)
No documentation found
var bit pata_hd_48_bit_lba_support = false -- currently this lib does not support drives > 137,438,952,960 bytes (28 bit addressing)
No documentation found
const PATA_HD_SPIN_UP = 0xE1 -- turn on the drive's motor
No documentation found
const PATA_HD_ERROR_REG = 9 -- error register
readable registers
const PATA_HD_DATA_REG = 8 -- data register
readable/writeable registers
pata_hd_start_write(dword in address)
Get drive ready for writing at specified address
pata_hd_write_pulse( byte in z )
Send a number of write pulses to data register sending 0's as data. Used to get to the end of a sector or to get to a certain location in a sector. Increment pata_hd_word_count
pata_hd_data_request(bit in read_write)
Wait for drive to be ready for a data transfer. Sets data pins as inputs or outputs for next read or write.
pata_hd_go_to_sector(dword in sector, byte in sec_count)
Go to a specific sector number (lba mode only) Max sector number is 268435455 or the number of sectors the drive has. Max drive size is 268435455 * 512 = 137.439 GB Sector count selects number of sectors that will be read Sector count value of 0 means 256 sectors will be read
pata_hd_read_data(byte out low_byte, byte out high_byte)
Read two bytes from disk.
pata_hd_read_sector()
No documentation found
pata_hd_read_pulse(dword in z)
Send a number of read pulses to data register without getting any data. Used to get to the end of a sector or to get to a certain location in a sector. Increment pata_hd_word_count
pata_hd_register_read(byte in register, byte out low_byte)
Select a register and get data from it.
pata_hd_select_register(byte in register)
Set register select pins to selected register, for internal use only.
pata_hd_write_to_sector_end(byte in input_byte)
Finnish writing the current sector with input byte.
pata_hd_init()
initialize startup settings
pata_hd_set_address(byte in pata_hd_head_addr, byte in cyl_high_addr, byte in cyl_low_addr, byte in sec_num_addr, byte in sec_count)
Go to a specific sector, select lba/chs mode and master/slave drive Max sector number is 0x0F_FF_FF_FF or the number of sectors the drive has. Max drive size is 0x0F_FF_FF_FF * 512 = 137.439 GB Sector count selects number of sectors that will be read Sector count value of 0 means 256 sectors will be read
pata_hd_drive_ready()
Wait for drive to be up to speed and ready for a command.
pata_hd_register_write(byte in register, byte in low_byte)
Select a register and give it a command or data.
pata_hd_start_read(dword in address)
Get drive ready for reading at specified address
pata_hd_write_data(byte in low_byte, byte in high_byte)
Write two bytes to disk Data will not be written unless 256 writes are sent.
pata_hd_busy()
Registers may not be accessed unless bsy bit is low due to internal operations.
pata_hd_stop_read()
Tell drive you are done reading