cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
viggsy
Observer
Observer
458 Views
Registered: ‎05-16-2019

Custom IP block device not found

I have been trying to configure an amplifier using a custom ip block. I have connected the streaming interface of the DMA to the IP block and vice versa. Now, I'm trying to program the device through linux. However on invoking the function XAmpl_Initialize(), 2 is returned which implies the device is not found. Also the following error is shown

usr/include/xampl.c:28: void XAmpl_Start(XAmpl*): Assertion `InstancePtr->IsReady == 1' failed.
Aborted

Attached below is the code snippet. Can someone please help?

Thanks in advance

#include "xampl.h"
#include "xampl_linux.c"
#include "xampl.c"

// #include "xil_cache.h"
// #include "xil_printf.h"
// #include "xil_io.h"

#define pi 22.0 / 7
#define No_ofsamples_per_frame 1024000
#define MM2S_DMACR 0x0
#define MM2S_DMASR 0x4 / 4
#define MM2S_SA 0x18 / 4
#define MM2S_SA_MSB 0x1C / 4
#define MM2S_LENGTH 0x28 / 4

#define S2MM_DMACR 0x30 / 4
#define S2MM_DMASR 0x34 / 4
#define S2MM_DA 0x48 / 4
#define S2MM_DA_MSB 0x4C / 4
#define S2MM_LENGTH 0x58 / 4
#define Destination 0x64000000
#define Source 0x60000000

XAmpl amp1;

void *dma0, *dma1, *dma2;
int dmaFd, convFd;

volatile void *amplifier_input, *amplifier_output;

void *mapMemory(unsigned int, unsigned int, unsigned int);

/* This function opens the file name given as the argument*/
int openFile(char *);

/*
 ! Function declarations for dma
*/
/* This function configures and readies the s2mm side of the dma. Takes the destination address, the length of transfer and the base address of the dma as inputs */
int configS2MM(unsigned int, unsigned int, void *);

/* This function configures and starts the mm2s side of the dma. Takes the source address, the length of transfer and the base address of the dma as inputs */
int configMM2S(unsigned int, unsigned int, void *);



using namespace std;
using namespace itpp;

int main()
{
    ofstream f1;
    dmaFd = openFile((char *)"/dev/mem");
    convFd = openFile((char *)"/dev/mem");
    dma0 = mapMemory(0x1000, dmaFd, 0x80000000);
    cout << "zero" << endl;
    int status = XAmpl_Initialize(&amp1, "ampl");
    // amplifier_input = mapMemory(10 * 2 * 2, convFd, Source);
    // amplifier_output = mapMemory(10 * 2 * 2, convFd, Destination);
    amplifier_input = mapMemory(10 * 4, dmaFd, Source);
    amplifier_output = mapMemory(10 * 4, dmaFd, Destination);

    // XAmpl_InterruptGlobalDisable(&amp1);
    // XAmpl_InterruptDisable(&amp1, 1);
    cout << status << endl;
    XAmpl_Start(&amp1);

    memset((void *)amplifier_input, 0, 10 * 4);

    memset((void *)amplifier_output, 0, 10 * 4);
    int input[10];

    int *txinbuf = (int *)amplifier_input;
    int *txoutbuf = (int *)amplifier_output;
    cout << "here" << endl;
    for (int i = 0; i < 10; i++)
    {
        input[i] = i;
    }

    *((uint *)dma0 + MM2S_DMACR) = 0x4; //Clearing the MM2S portion of the DMA
    int count = 0;
    while (count < 3)
    {
        memcpy((int *)amplifier_input, input, 10 * 4);

        configS2MM(Destination, 0x14, dma0);
        configMM2S(Source, 0x14, dma0);
        count++;
        for (int i = 0; i < 10; i++)
        {
            cout << txinbuf[i] << "\t" << txoutbuf[i] << endl;
        }
    }

    // Xil_DCacheFlush();
    // f1.open("amplifieroutput.txt");
    // cout << "input 2" <<endl;
    // for (int i = 0; i < 30; i++)
    // {
    //     input[i] = 3 * i;
    // }
    // memcpy((int *)amplifier_input, input, 10 * 4);
    // memcpy((short *)amplifier_output, (short *)amplifier_input, 10 * 2 * 2);

    // configS2MM(Destination, 0x28, dma0);
    // configMM2S(Source, 0x28, dma0);

    f1.close();
}
int openFile(char *s)
{
    int temp;
    temp = open(s, O_RDWR | O_SYNC);
    if (temp < 0)
    {
        perror("inputFd open:");
        return errno;
    }
    return temp;
}

/* Inputs to this function are Map size, File descriptor, and Starting location. Returns the starting address of the virtual memory when
   successfull. Else return null
   ?@mapSize = size of the to-be mapped region in bytes
   ?@fd = file descriptor of the opened file
   ?@startLoc = starting location of the physical memory
*/
void *mapMemory(unsigned int mapSize, unsigned int fd, unsigned int startLoc)
{
    void *temp;
    temp = mmap(NULL, mapSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, startLoc);
    if (temp == (void *)NULL)
    {
        printf("memory mapping failed \n");
        return NULL;
    }
    return temp;
}

//! Function definitions for DMA
/*
    *This function configures and readies the S2MM partof the dma
    ?@destAddr = Destination Address of S2MM dma transfer
    ?@transferLength = Number of bytes to be transfered in one transfer
    ?@dmaBase = base address of the DMA uio device.
*/
int configS2MM(unsigned int destAddr, unsigned int transferLength, void *dmaBase)
{

    // cout << destAddr << endl;
    *((uint *)dmaBase + S2MM_DMACR) = 0x4;             // Resetting DMA
    *((uint *)dmaBase + S2MM_DMACR) |= 0x1000;         // Enabling IOC interrupt
    *((uint *)dmaBase + S2MM_DA) = destAddr;           // Destination
    *((uint *)dmaBase + S2MM_DMACR) |= 0x1;            // Starting DMA
    *((uint *)dmaBase + S2MM_LENGTH) = transferLength; // Transfer length}
    // *((uint *)dmaBase + S2MM_DMASR) = 0x1002;
}

/*
    *This function configures and starts the MM2S partof the dma
    ?@sourceAddr = Source Address of MM2S dma transfer
    ?@transferLength = Number of bytes to be transfered in one transfer
    ?@dmaBase = base address of the DMA uio device.
*/
int configMM2S(unsigned int sourceAddr, unsigned int transferLength, void *dmaBase)
{
    *((uint *)dmaBase + MM2S_DMACR) |= 0x1000;         //Enabling IOC interrupt
    *((uint *)dmaBase + MM2S_SA) = sourceAddr;         // Source Address
    *((uint *)dmaBase + MM2S_DMACR) |= 0x1;            // Starting DMA
    *((uint *)dmaBase + MM2S_LENGTH) = transferLength; // Transfer length

    while (*((uint *)dmaBase + MM2S_DMASR) != 0x1002)
        ;
    *((uint *)dmaBase + MM2S_DMACR) = 0x1002;
    // while (*((uint *)dmaBase + S2MM_DMASR) != 0x1002)
    //     ;
    // *((uint *)dmaBase + S2MM_DMASR) = 0x1002;
}

 

Tags (4)
0 Kudos
0 Replies