Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# atadev.c

Go to the documentation of this file.

    00001 /*! \file atadev.c \brief IDE-ATA interface device driver. */
    00002 //*****************************************************************************
    00003 //
    00004 // File Name    : 'atadev.c'
    00005 // Title        : IDE-ATA interface device driver
    00006 // Author       : Pascal Stang
    00007 // Date         : 8/15/2004
    00008 // Revised      : 8/15/2004
    00009 // Version      : 0.1
    00010 // Target MCU   : ARMmini LPC210x
    00011 // Editor Tabs  : 4
    00012 //
    00013 // NOTE: This code is currently below version 1.0, and therefore is considered
    00014 // to be lacking in some functionality or documentation, or may not be fully
    00015 // tested.  Nonetheless, you can expect most functions to work.
    00016 //
    00017 // This code is distributed under the GNU Public License
    00018 //      which can be found at http://www.gnu.org/licenses/gpl.txt
    00019 //
    00020 //*****************************************************************************
    00021
    00022 #include "global.h"
    00023 #include "timer.h"
    00024 #include "rprintf.h"
    00025 #include "membus.h"
    00026
    00027 #include "atadev.h"
    00028
    00029 // global variables
    00030 const DevBlock_t DevBlockAta =
    00031 {
    00032     atadevInit,
    00033     atadevReset,
    00034     atadevReadReg,
    00035     atadevWriteReg,
    00036     atadevReadData,
    00037     atadevWriteData
    00038 };
    00039
    00040 // functions
    00041
    00042 // initialize the interface
    00043 int atadevInit(void)
    00044 {
    00045     membusInit();
    00046     return 0;
    00047 }
    00048
    00049 // reset the interface
    00050 int atadevReset(void)
    00051 {
    00052     return 0;
    00053 }
    00054
    00055 // read a value from an IDE-ATA device register
    00056 u08 atadevReadReg(u16 reg)
    00057 {
    00058     if(reg < 0x08)
    00059         return membusRead(ATA_REG_BASE_CS1+reg);
    00060     else
    00061         return membusRead(ATA_REG_BASE_CS2+reg-0x08);
    00062 }
    00063
    00064 // write a value to an IDE-ATA device register
    00065 void atadevWriteReg(u16 reg, u08 data)
    00066 {
    00067     if(reg < 0x08)
    00068         membusWrite(ATA_REG_BASE_CS1+reg, data);
    00069     else
    00070         membusWrite(ATA_REG_BASE_CS2+reg-0x08, data);
    00071 }
    00072
    00073 // read data from IDE-ATA device
    00074 int atadevReadData(u08 *buffer, int numBytes)
    00075 {
    00076     register unsigned int i;
    00077
    00078     uint16_t* buf = (uint16_t*)buffer;
    00079
    00080     // read data from drive
    00081     for (i=0; i<(numBytes/16); i++)
    00082     {
    00083         // optimize by reading 16 bytes in-line before looping
    00084         *buf++ = membusRead(ATA_REG_BASE_CS1+ATA_REG_DATA);
    00085         *buf++ = membusRead(ATA_REG_BASE_CS1+ATA_REG_DATA);
    00086         *buf++ = membusRead(ATA_REG_BASE_CS1+ATA_REG_DATA);
    00087         *buf++ = membusRead(ATA_REG_BASE_CS1+ATA_REG_DATA);
    00088         *buf++ = membusRead(ATA_REG_BASE_CS1+ATA_REG_DATA);
    00089         *buf++ = membusRead(ATA_REG_BASE_CS1+ATA_REG_DATA);
    00090         *buf++ = membusRead(ATA_REG_BASE_CS1+ATA_REG_DATA);
    00091         *buf++ = membusRead(ATA_REG_BASE_CS1+ATA_REG_DATA);
    00092     }
    00093     return numBytes;
    00094 }
    00095
    00096 // write data to IDE-ATA device
    00097 int atadevWriteData(u08 *buffer, int numBytes)
    00098 {
    00099     register unsigned int i;
    00100
    00101     uint16_t* buf = (uint16_t*)buffer;
    00102
    00103     // write data to drive
    00104     for (i=0; i<(numBytes/16); i++)
    00105     {
    00106         // optimize by writing 16 bytes in-line before looping
    00107         membusWrite(ATA_REG_BASE_CS1+ATA_REG_DATA, *buf++);
    00108         membusWrite(ATA_REG_BASE_CS1+ATA_REG_DATA, *buf++);
    00109         membusWrite(ATA_REG_BASE_CS1+ATA_REG_DATA, *buf++);
    00110         membusWrite(ATA_REG_BASE_CS1+ATA_REG_DATA, *buf++);
    00111         membusWrite(ATA_REG_BASE_CS1+ATA_REG_DATA, *buf++);
    00112         membusWrite(ATA_REG_BASE_CS1+ATA_REG_DATA, *buf++);
    00113         membusWrite(ATA_REG_BASE_CS1+ATA_REG_DATA, *buf++);
    00114         membusWrite(ATA_REG_BASE_CS1+ATA_REG_DATA, *buf++);
    00115     }
    00116     return numBytes;
    00117 }