DMA in C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kid joe

    DMA in C

    Hi all,

    I'm wondering if it's possible to request a data transfer from one device
    (given its device name and its offset and the transfer length) to another
    file w/o reading in the data. I could do a fread() followed by a fwrite()
    but I would love to have some sort of DMA-like function to do this job.

    Thanks.

  • viza

    #2
    Re: DMA in C

    Hi

    On Fri, 27 Jun 2008 20:47:01 +0100, kid joe wrote:
    I'm wondering if it's possible to request a data transfer from one
    device (given its device name and its offset and the transfer length) to
    another file w/o reading in the data. I could do a fread() followed by
    a fwrite() but I would love to have some sort of DMA-like function to do
    this job.
    That is quite a low level operation. The generic C FILE functions do not
    let you do anything like that.

    Most operating systems will not allow you direct control of DMA devices,
    but if you are in a *nix environment, you can sometimes make reading and
    writing to block devices more efficient by using the O_DIRECT flag to
    open().

    Alternatively you might be able to make certain file to file operations
    on pipes or sockets quicker by using system calls like sendfile() or
    splice().

    HTH
    viza

    Comment

    • santosh

      #3
      Re: DMA in C

      kid joe wrote:
      Hi all,
      >
      I'm wondering if it's possible to request a data transfer from one
      device (given its device name and its offset and the transfer length)
      to another file w/o reading in the data. I could do a fread()
      followed by a fwrite() but I would love to have some sort of DMA-like
      function to do this job.
      This is absolutely beyond the scope of standard C. You should normally
      let your operating system take care using DMA wherever possible. It
      almost certainly knows more than you do about the capabilities (or lack
      thereof) of the devices in your system.

      Comment

      • Malcolm McLean

        #4
        Re: DMA in C


        "kid joe" <spamtrap@spamt rap.invalidwrot e in message news
        I'm wondering if it's possible to request a data transfer from one device
        (given its device name and its offset and the transfer length) to another
        file w/o reading in the data. I could do a fread() followed by a fwrite()
        but I would love to have some sort of DMA-like function to do this job.
        >
        There's quite possibly a call to DMA engines. It depends on your OS and is,
        of course, non-standard.
        However the problem for conventional C is that DMA is usually carried out in
        parallel to the main processor. So you need to ensure that the DMA has
        completed before trying to use the buffer, which can get tricky.

        --
        Free games and programming goodies.


        Comment

        • kid joe

          #5
          Re: DMA in C

          OK, thanks for all the info.


          On Fri, 27 Jun 2008 22:55:18 +0100, Malcolm McLean wrote:
          >
          "kid joe" <spamtrap@spamt rap.invalidwrot e in message news
          >I'm wondering if it's possible to request a data transfer from one device
          >(given its device name and its offset and the transfer length) to another
          >file w/o reading in the data. I could do a fread() followed by a fwrite()
          >but I would love to have some sort of DMA-like function to do this job.
          >>
          There's quite possibly a call to DMA engines. It depends on your OS and is,
          of course, non-standard.
          However the problem for conventional C is that DMA is usually carried out in
          parallel to the main processor. So you need to ensure that the DMA has
          completed before trying to use the buffer, which can get tricky.

          Comment

          • fnegroni

            #6
            Re: DMA in C

            On 27 Jun, 23:58, kid joe <spamt...@spamt rap.invalidwrot e:
            OK, thanks for all the info.
            >
            On Fri, 27 Jun 2008 22:55:18 +0100, Malcolm McLean wrote:
            >
            "kid joe" <spamt...@spamt rap.invalidwrot e in message news
            I'm wondering if it's possible to request a data transfer from one device
            (given its device name and its offset and the transfer length) to another
            file w/o reading in the data.  I could do a fread() followed by a fwrite()
            but I would love to have some sort of DMA-like function to do this job..
            >
            There's quite possibly a call to DMA engines. It depends on your OS andis,
            of course, non-standard.
            However the problem for conventional C is that DMA is usually carried out in
            parallel to the main processor. So you need to ensure that the DMA has
            completed before trying to use the buffer, which can get tricky.
            >
            >
            Possibly also look into memory mapped IO.

            Comment

            Working...