MityDSP Documentation Index
Classes | Public Member Functions | Protected Member Functions | Protected Attributes
MityDSP::tcDspAta Class Reference

The tcDspAta class is used for low-level reading and writing to ATA storage devices such as disk drives or CompactFlash cards. More...

#include <core/DspAta.h>

Inheritance diagram for MityDSP::tcDspAta:
MityDSP::tcDspStorageBase

List of all members.

Classes

union  tuAtaErr
 ATA Error Register. More...
union  tuAtaSr
 ATA Status Register. More...

Public Member Functions

 tcDspAta (void *apAddress, int anDevice)
 This constructor is used to open an ATA interface at the specified address.
virtual ~tcDspAta ()
 Default destructor.
virtual int write (void *apAddr, void *apData, int anBytes)
 This routine writes an arbitrary amount of data to an ATA device at a specified offset from the start of the device.
virtual int write (unsigned int anSector, unsigned int anOffset, void *apData, int anBytes)
 Sector-based version of the write method.
virtual int read (void *apStartAddr, void *apBuffer, int anBytes)
 This routine reads an arbitrary amount of data from an ATA device from the specified offset position.
virtual int read (unsigned int anSector, unsigned int anOffset, void *apBuffer, int anBytes)
 Sector-based version of the read method.
virtual bool reset (void)
 This routine performs a soft reset of the ATA device.
tuAtaSr get_status (void)
 This routine gets the current value of the ATA status register.
double get_size (void)
 This routine returns the size of the device in KB (using the getSizeKB method in the tcDspStorageBase base class).
tuAtaErr get_error (void)
 This routine gets the current value of the ATA error register.
- Public Member Functions inherited from MityDSP::tcDspStorageBase
 tcDspStorageBase ()
 This constructor is used to initialize storage base class.
virtual ~tcDspStorageBase ()
 Default Destructor.
virtual bool erase (unsigned int anSector)
 This routine provides a default erase method.
virtual void registerISRCallback (tfIsrCallback afCallback, void *apUserArg)
 This method is used to register a callback that is activated whenever the device changes state.
virtual void * getAddress (unsigned int anSector, unsigned int anOffset)
 This routine uses the device's sector map to compute an offset address from a supplied sector and offset.
virtual unsigned int getSize (unsigned int anSector)
 This routine uses the device's sector map to determine the size of the specified sector.
virtual unsigned int getSector (void *apAddr)
 This routine uses the device's sector map to compute a sector from a from a supplied offset address.
virtual double getDeviceSizeKB (void)
 This routine returns the size of the device in kilobytes.
const tsSectorMapgetMap (int &anNumSectors)
 This routine returns a pointer to access the device's sector map.
virtual bool getMediaPresent ()

Protected Member Functions

bool initialize (void)
 This routine initializes the ATA device, and returns true if successful.
void select_device (int anDevice)
 This routine configures the drive/head register for the specified device (always in LBA mode).
void identify (unsigned short *apIdBuffer)
 This routine reads device identity data into the supplied buffer.
bool read_sector (unsigned int anBlock)
 This routine reads the specified LBA block of the device into the page buffer.
bool write_sector (unsigned int anBlock)
 This routine writes the current contents of the page buffer to the specified LBA block of the device.
void send_command (unsigned char anCmd)
 This routine sends a new command to the ATA command register.
bool ready (void)
 This routine reads the current ATA status and returns a boolean indicating whether or not the device is ready.
bool busy (void)
 This routine reads the current ATA status and returns a boolean indicating whether or not the device is busy.
bool drq (void)
 This routine reads the current ATA status and returns a boolean indicating whether or not the device is requesting data.
bool ata_err (void)
 This routine reads the current ATA status and returns a boolean indicating whether or not the device is reporting an error.
bool wait_for_drq (bool aDrq, int aTimeout)
 This routine waits till the drq flag is set or a timeout expires.
bool wait_for_busy (bool aBusy, int aTimeout)
 This routine waits till the busy flag is set or a timeout expires.

Protected Attributes

volatile unsigned char * mpBaseAddr
int mnDevice
SEM_Handle mhSemaphore
unsigned int mnSectorSize
 Sector size (bytes)
unsigned short * mpPageBuffer
 Buffer for a sector of data.
volatile unsigned short * mpAtaData
 Pointer to the device data FIFO.
- Protected Attributes inherited from MityDSP::tcDspStorageBase
unsigned int mnNumSectors
 Number of sectors in this device.
double mnDeviceSize
 Overall device size (in bytes)
tsSectorMapmpSectorInfo
 Map of sectors and sizes.
bool mbMediaPresent
 True if device is loaded.
tfIsrCallback mfIsrCallback
void * mpUserArg
 User-supplied argument for ISR callback.

Additional Inherited Members

- Public Types inherited from MityDSP::tcDspStorageBase
typedef void(* tfIsrCallback )(bool, void *)
 prototype for the ISR callback
- Static Public Member Functions inherited from MityDSP::tcDspStorageBase
static int readDispatch (unsigned int anSector, unsigned int anOffset, char *apBuffer, unsigned int anLength, void *apInstance)
 Static dispatch routine to allow the read method to be registered as a callback.
static int writeDispatch (unsigned int anSector, unsigned int anOffset, char *apData, unsigned int anBytes, void *apInstance)
 Static dispatch routine to allow the write method to be registered as a callback.
- Public Attributes inherited from MityDSP::tcDspStorageBase
unsigned int mnTxBytes
 Count of bytes written (debug)
unsigned int mnRxBytes
 Count of bytes read (debug)

Detailed Description

The tcDspAta class is used for low-level reading and writing to ATA storage devices such as disk drives or CompactFlash cards.

Filesystems and data cache must be provided at a higher level, although these routines may be used for simple read/write access to a device.

See also:
tcDspAta Page

Constructor & Destructor Documentation

tcDspAta::tcDspAta ( void *  apAddress,
int  anDevice 
)

This constructor is used to open an ATA interface at the specified address.

Each interface may handle up to two devices.

Parameters:
[in]apAddressAddress for the ATA interface.
[in]anDeviceStarting device number (0 or 1).
Returns:
None.
See also:
DspAta.h
tcDspAta::~tcDspAta ( )
virtual

Default destructor.


Member Function Documentation

int tcDspAta::write ( void *  apAddr,
void *  apData,
int  anBytes 
)
virtual

This routine writes an arbitrary amount of data to an ATA device at a specified offset from the start of the device.

The routine handles preservation of data when only a partial sector is written. The data does not have to be sector aligned, although writing aligned, full sectors is most efficient.

Parameters:
[in]apAddrPointer to the offset position on the ATA device.
[in]apDataA buffer containing the data to be written.
[in]anBytesSize of the data to be written in bytes.
Returns:
The number of bytes successfully written.
See also:
DspAta.h

Implements MityDSP::tcDspStorageBase.

int tcDspAta::write ( unsigned int  anSector,
unsigned int  anOffset,
void *  apData,
int  anBytes 
)
virtual

Sector-based version of the write method.

Parameters:
[in]anSectorThe sector to write to.
[in]anOffsetThe offset from the start of the sector.
[in]apDataA buffer containing the data to be written.
[in]anBytesSize of the data to be written in bytes.
Returns:
The number of bytes successfully written.
See also:
DspAta.h

Implements MityDSP::tcDspStorageBase.

int tcDspAta::read ( void *  apStartAddr,
void *  apBuffer,
int  anBytes 
)
virtual

This routine reads an arbitrary amount of data from an ATA device from the specified offset position.

Results of the read are stored in apBuffer.

Parameters:
[in]apStartAddrPointer to the data offset on the ATA device.
[out]apBufferA buffer to hold the data that is read.
[in]anBytesSize of the data to be read in bytes.
Returns:
The number of bytes successfully read.
See also:
DspAta.h

Implements MityDSP::tcDspStorageBase.

int tcDspAta::read ( unsigned int  anSector,
unsigned int  anOffset,
void *  apBuffer,
int  anBytes 
)
virtual

Sector-based version of the read method.

Parameters:
[in]anSectorThe sector to copy from.
[in]anOffsetThe offset from the start of the sector.
[out]apBufferA buffer to hold the data that is read.
[in]anBytesSize of the data to be read in bytes.
Returns:
The number of bytes successfully read.
See also:
DspAta.h

Implements MityDSP::tcDspStorageBase.

bool tcDspAta::reset ( void  )
virtual

This routine performs a soft reset of the ATA device.

Returns:
true if reset succedded, false otherwise.
See also:
DspAta.h
tcDspAta::tuAtaSr tcDspAta::get_status ( void  )

This routine gets the current value of the ATA status register.

Returns:
contents of the ATA status register as a tuAtaSr struct
See also:
DspAta.h
double tcDspAta::get_size ( void  )

This routine returns the size of the device in KB (using the getSizeKB method in the tcDspStorageBase base class).

It is provide for backwards compatibility.

Returns:
size of the device in KB.
See also:
DspAta.h
tcDspAta::tuAtaErr tcDspAta::get_error ( void  )

This routine gets the current value of the ATA error register.

Returns:
contents of the ATA error register as a tuAtaErr struct
See also:
DspAta.h
bool tcDspAta::initialize ( void  )
protected

This routine initializes the ATA device, and returns true if successful.

Returns:
True if no errors occurred
See also:
DspAta.h
void tcDspAta::select_device ( int  anDevice)
protected

This routine configures the drive/head register for the specified device (always in LBA mode).

Parameters:
[in]anDeviceDevice number (0 or 1).
Returns:
None.
See also:
DspAta.h
void tcDspAta::identify ( unsigned short *  apIdBuffer)
protected

This routine reads device identity data into the supplied buffer.

Parameters:
[out]apIdBufferBuffer for holding identity data
Returns:
None.
See also:
DspAta.h
bool tcDspAta::read_sector ( unsigned int  anBlock)
protected

This routine reads the specified LBA block of the device into the page buffer.

The routine returns true if the read is successful.

Note:
Existing mpPageBuffer contents are overwritten. The caller is responsible for providing semaphore locks at a higher level.
Parameters:
[in]anBlockLBA Block to read
Returns:
True if read is successful, false otherwise.
See also:
DspAta.h
bool tcDspAta::write_sector ( unsigned int  anBlock)
protected

This routine writes the current contents of the page buffer to the specified LBA block of the device.

The routine returns true if the write is successful.

Note:
The caller is responsible for filling mpPageBuffer prior to calling this routine. Semaphore locks should be provided at a higher level.
Parameters:
[in]anBlockLBA Block to write to.
Returns:
True if write is successful, false otherwise.
See also:
DspAta.h
void tcDspAta::send_command ( unsigned char  anCmd)
protected

This routine sends a new command to the ATA command register.

Parameters:
[in]anCmdOne of the following ATA commands:
  • CMD_CHECK_POWER_MODE
  • CMD_EXECUTE_DRIVE_DIAGNOSTIC
  • CMD_ERASE_SECTORS
  • CMD_FLUSH_CACHE
  • CMD_FORMAT_TRACK
  • CMD_IDENTIFY_DEVICE
  • CMD_IDLE
  • CMD_IDLE_IMMEDIATE
  • CMD_INITIALIZE_DRIVE_PARAMETERS
  • CMD_NOP
  • CMD_READ_BUFFER
  • CMD_READ_DMA
  • CMD_READ_MULTIPLE
  • CMD_READ_SECTORS
  • CMD_READ_VERIFY_SECTORS
  • CMD_RECALIBRATE
  • CMD_REQUEST_SENSE
  • CMD_SEEK
  • CMD_SET_FEATURES
  • CMD_SET_MULTIPLE_MODE
  • CMD_SET_SLEEP_MODE
  • CMD_STANDBY
  • CMD_STANDBY_IMMEDIATE
  • CMD_TRANSLATE_SECTOR
  • CMD_WRITE_BUFFER
  • CMD_WRITE_DMA
  • CMD_WRITE_MULTIPLE
  • CMD_WRITE_MULTIPLE_WO_ERASE
  • CMD_WRITE_SECTORS
  • CMD_WRITE_SECTORS_WO_ERASE
  • CMD_WRITE_VERIFY
Returns:
None.
See also:
DspAta.h
bool tcDspAta::ready ( void  )
protected

This routine reads the current ATA status and returns a boolean indicating whether or not the device is ready.

Returns:
True if ready, false otherwise.
See also:
DspAta.h
bool tcDspAta::busy ( void  )
protected

This routine reads the current ATA status and returns a boolean indicating whether or not the device is busy.

Returns:
True if busy, false otherwise.
See also:
DspAta.h
bool tcDspAta::drq ( void  )
protected

This routine reads the current ATA status and returns a boolean indicating whether or not the device is requesting data.

Returns:
True if the device is requesting data, false otherwise.
See also:
DspAta.h
bool tcDspAta::ata_err ( void  )
protected

This routine reads the current ATA status and returns a boolean indicating whether or not the device is reporting an error.

Returns:
True if the device is reporting and error, false otherwise.
See also:
DspAta.h
bool tcDspAta::wait_for_drq ( bool  aDrq,
int  aTimeout 
)
protected

This routine waits till the drq flag is set or a timeout expires.

Parameters:
[in]aDrqdrq state we are waiting for
[in]aTimeoutnumber of milliseconds to wait
Returns:
True if drq = aDrq, false otherwise.
See also:
DspAta.h
bool tcDspAta::wait_for_busy ( bool  aBusy,
int  aTimeout 
)
protected

This routine waits till the busy flag is set or a timeout expires.

Parameters:
[in]aBusybusy state we are waiting for
[in]aTimeoutnumber of milliseconds to wait
Returns:
True if busy = aBusy, false otherwise.
See also:
DspAta.h

Member Data Documentation

volatile unsigned char* MityDSP::tcDspAta::mpBaseAddr
protected
int MityDSP::tcDspAta::mnDevice
protected
SEM_Handle MityDSP::tcDspAta::mhSemaphore
protected
unsigned int MityDSP::tcDspAta::mnSectorSize
protected

Sector size (bytes)

unsigned short* MityDSP::tcDspAta::mpPageBuffer
protected

Buffer for a sector of data.

volatile unsigned short* MityDSP::tcDspAta::mpAtaData
protected

Pointer to the device data FIFO.


  
Generated on Mon Apr 22 2013 11:33:03 for MityDSP Core by  Doxygen Version 1.8.1.1
Copyright © 2009, Critical Link LLC, All rights reserved.