- Main Page
- Data Structures
- Files
- Directories

- Search for |

- File List
- Globals

# dma.c

Go to the documentation of this file.

    00001 /*****************************************************************************************
    00002  Copyright (c) 2002-2005 The UbixOS Project
    00003  All rights reserved.
    00004
    00005  Redistribution and use in source and binary forms, with or without modification, are
    00006  permitted provided that the following conditions are met:
    00007
    00008  Redistributions of source code must retain the above copyright notice, this list of
    00009  conditions, the following disclaimer and the list of authors.  Redistributions in binary
    00010  form must reproduce the above copyright notice, this list of conditions, the following
    00011  disclaimer and the list of authors in the documentation and/or other materials provided
    00012  with the distribution. Neither the name of the UbixOS Project nor the names of its
    00013  contributors may be used to endorse or promote products derived from this software
    00014  without specific prior written permission.
    00015
    00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
    00017  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00018  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
    00019  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00020  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
    00021  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    00022  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
    00023  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00024  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00025
    00026  $Id: dma_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
    00027
    00028 *****************************************************************************************/
    00029
    00030 #include <sys/dma.h>
    00031 #include <sys/io.h>
    00032 #include <ubixos/types.h>
    00033
    00034 #define lowByte(x)  (x & 0x00FF)
    00035 #define highByte(x) ((x & 0xFF00) >> 8)
    00036
    00037 static uInt8 maskReg[8]   = { 0x0A, 0x0A, 0x0A, 0x0A, 0xD4, 0xD4, 0xD4, 0xD4 };
    00038 static uInt8 clearReg[8]  = { 0x0C, 0x0C, 0x0C, 0x0C, 0xD8, 0xD8, 0xD8, 0xD8 };
    00039 static uInt8 modeReg[8]   = { 0x0B, 0x0B, 0x0B, 0x0B, 0xD6, 0xD6, 0xD6, 0xD6 };
    00040 static uInt8 addrPort[8]  = { 0x00, 0x02, 0x04, 0x06, 0xC0, 0xC4, 0xC8, 0xCC };
    00041 static uInt8 pagePort[8]  = { 0x87, 0x83, 0x81, 0x82, 0x8F, 0x8B, 0x89, 0x8A };
    00042 static uInt8 countPort[8] = { 0x01, 0x03, 0x05, 0x07, 0xC2, 0xC6, 0xCA, 0xCE };
    00043
    00044 void dmaXfer(uInt8 channel,uInt32 address,uInt length,uInt8 read) {
    00045   unsigned char page=0, mode=0;
    00046   unsigned int offset = 0;
    00047   if (read) {
    00048     mode = 0x48 + channel;
    00049     }
    00050   else {
    00051     mode = 0x44 + channel;
    00052     }
    00053   page = address >> 16;
    00054   offset = address & 0xFFFF;
    00055   length--;
    00056   _dmaXfer(channel, page, offset, length, mode);
    00057   }
    00058
    00059 void _dmaXfer(uInt8 dmaChannel,uInt8 page,uInt offset,uInt length,uInt8 mode) {
    00060   //asm("cli");
    00061   outportByte(maskReg[dmaChannel], 0x04 | dmaChannel);
    00062   outportByte(clearReg[dmaChannel], 0x00);
    00063   outportByte(modeReg[dmaChannel], mode);
    00064   outportByte(addrPort[dmaChannel], lowByte(offset));
    00065   outportByte(addrPort[dmaChannel], highByte(offset));
    00066   outportByte(pagePort[dmaChannel], page);
    00067   outportByte(countPort[dmaChannel], lowByte(length));
    00068   outportByte(countPort[dmaChannel], highByte(length));
    00069   outportByte(maskReg[dmaChannel], dmaChannel);
    00070   //asm("sti");
    00071   }
    00072
    00073 /***
    00074  END
    00075  ***/