From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Driver Development Kit (DDK)

cancel
Showing results for 
Search instead for 
Did you mean: 

Using DMA for 6133 board only returns zeros

Solved!
Go to solution

I have code (attached) derived from examples and past undocumented R&D for getting analog input data from the 6133 DAQ board via either register based I/O, or DMA. The register based I/O works. However, the DMA provides all zero samples. I would appreciate it if someone with more experience with the MHDDK can have a look at it.

Thanks.

 

Definitions used from outside the file provided are:

#define DAQ_SAMPLE_RATE 2000000

#define NUM_ADC_CHANNELS 2

#define ADC_RESOLUTION 14

#define END_OF_CONVERT_DELAY 17

#define SAMPLES_PER_REV 4000

#define NUM_CHANNELS 2

0 Kudos
Message 1 of 4
(6,201 Views)

Maybe there is an issue with the iBus::allocDMA function for QNX Neutrino?

0 Kudos
Message 2 of 4
(6,080 Views)
Solution
Accepted by topic author Sorterralee

The problem has been fixed by using the 64 bit versions of memory related functions mmap and mem_offset in osiUserCode for Neutrino 6.

0 Kudos
Message 3 of 4
(6,061 Views)

ie. The fix is done in the function below, found in nimhddk/QNXNeutrino6/osiUserCode.cpp. Refer to lines in "#if NI6133_DMA_USE_MEM64"

 

tDMAMemory * iBus::allocDMA (u32 size)
{

    void *virtualAddress;
#if NI6133_DMA_USE_MEM64
    off64_t physicalAddress;
#else
    off_t physicalAddress;
#endif

    // Allocate DMA buffer
#if NI6133_DMA_USE_MEM64
    virtualAddress = mmap64( 0, // set target 0 means that the system can put it anywhere it wants
#else
    virtualAddress = mmap( 0, // set target 0 means that the system can put it anywhere it wants
#endif
    size,
    PROT_READ|PROT_WRITE|PROT_NOCACHE, // Can read, write. Should not be cached.
    MAP_PHYS|MAP_ANON, // Dealing with physical memory. With MAP_ANON means physical contiguous memory is allocated (required for DMA buffer).
    NOFD, // fd
    0 ); // offset within shared memory. "Common to map in an entire shared object, in which case offset will be zero"
    if (virtualAddress == MAP_FAILED)
    {
        munmap (virtualAddress, size);
        return NULL;
    }
    // Get physical adddress
#if NI6133_DMA_USE_MEM64
    if (mem_offset64( virtualAddress, NOFD, size, &physicalAddress, 0) == -1)
#else
    if (mem_offset( virtualAddress, NOFD, size, &physicalAddress, 0) == -1)
#endif
    {
        munmap (virtualAddress, size);
        return NULL;
    }
    tDMAMemory *dma = new tDMAMemory (virtualAddress, physicalAddress, size);
    if (NULL == dma)
    {
        munmap (virtualAddress, size);
    }

    return dma;
}

0 Kudos
Message 4 of 4
(6,041 Views)