zhemao / zhemao.github.com

Github pages page
http://zhemao.github.com
Other
4 stars 1 forks source link

Interrupt Example - Kernel #18

Closed ghost closed 9 years ago

ghost commented 9 years ago

Hi,

Just regarding your instruction on the interrupt example

https://github.com/zhemao/interrupt_example

After I ran "insmod fpga_uinput.ko".

I got the following error message:

fpga_uinput: version magic '3.9.0-00161-ged01b8c SMP mod_unload ARMv7 p2v8 ' should be '3.12.0 SMP mod_unload ARMv7 p2v8 ' insmod: ERROR: could not insert module fpga_uinput.ko: Invalid module format

Any idea as to how to get around this? Thanks

Jack

zhemao commented 9 years ago

You must be compiling against the wrong version of the kernel. Which kernel are you running on the ARM board, and which kernel are you cross-compiling against?

ghost commented 9 years ago

Hi Howard,

The kernel on the ARM board is 3.12, and the version of the kernel that I'm compiling is 3.9.0.

However, when I tried to checkout the 3.12 version for the linux-socfpga. I'm running into this error

make[1]: Entering directory /home/jack/programs/others/linux-socfpga' Building modules, stage 2. MODPOST 1 modules scripts/mod/modpost: invalid option -- 'T' make[2]: *** [__modpost] Error 1 make[1]: *** [modules] Error 2 make[1]: Leaving directory/home/jack/programs/others/linux-socfpga' make: *\ [fpga_uinput.ko] Error 2

zhemao commented 9 years ago

Where did you get the 3.12 kernel? Did that come with a pre-built SD card image? You could try building the 3.9 kernel yourself and installing that on the ARM board. I have instructions on how to do it in the tutorials.

ghost commented 9 years ago

Yes, I got that from a pre-built SD card image.

When you say the tutorial, are you referring to this page https://zhehaomao.com/blog/fpga/2013/12/24/sockit-2.html

I downloaded the pre-built image that is linked on that page (http://rocketboards.org/foswiki/Documentation/ArrowSoCKITEvaluationBoardLinuxGettingStarted)

But with that image the system doesn't even start. Is that pre-built image the same as the one you are going through in the tutorial?

ghost commented 9 years ago

I should mention that I'm not using Sockit, but MityArm

https://support.criticallink.com/redmine/projects/altera_soc

Does it make a difference?

Thanks,

Jack

zhemao commented 9 years ago

Yes. It changes what versions of the kernel you will have to use. From the link you sent me, it seems like you should get your kernel from https://support.criticallink.com/redmine/projects/mityarm-5cs/wiki/Linux_Kernel.

ghost commented 9 years ago

So am I correct in saying then that I should use linux-socfpga folder from git://support.criticallink.com/home/git/linux-socfpga.git to compile your file for the kernel (i.e. fpga._uinput.c)?

The kernel I have on the ARM is gotten from this page (https://support.criticallink.com/redmine/projects/mityarm-5cs/wiki/Building_SD_Card_Image)

zhemao commented 9 years ago

Yes, you should do that.

On Thu, Nov 13, 2014 at 4:48 PM, jackzhang273 notifications@github.com wrote:

So am I correct in saying then that I should use linux-socfpga folder from git://support.criticallink.com/home/git/linux-socfpga.git to compile your file for the kernel (i.e. fpga._uinput.c)?

The kernel I have on the ARM is gotten from this page ( https://support.criticallink.com/redmine/projects/mityarm-5cs/wiki/Building_SD_Card_Image )

— Reply to this email directly or view it on GitHub https://github.com/zhemao/zhemao.github.com/issues/18#issuecomment-62993650 .

ghost commented 9 years ago

So I tried doing that, but here's the error that I got now.

fpga_uinput: version magic '3.12.0-g456859b SMP mod_unload ARMv7 p2v8 ' should b e '3.12.0 SMP mod_unload ARMv7 p2v8 ' insmod: ERROR: could not insert module fpga_uinput.ko: Invalid module format

ghost commented 9 years ago

A different question.

Why is it that you do not use the "alt_interrupt.h" library in "altera/.../embedded/ip/altear/hps/altera_hps/hwlib/include"?

I was wondering if you have examples on that, because I tried to work with it and it did not work at all.

Also, I tried polling a register value. What is happening is that, we have a register in the FPGA that indicates when our procedure is done before calling the next run.

We passed this register value through the PIO and read it on the HPS side using a while loop. //Command to initiate our process dispatcher.WriteDescriptor(descriptor);

loopcounter = 0; //Checking on the register connected via PIO to see if it is done while(dmadone.ReadCtrlReg(0) == 0) { loopcounter++; }; That particularly register has been verified by both logic analyzer and pulling it out onto an output pin, and it is confirmed to be 'high', so we should be exiting the while loop. However, from time to time (it's completely random), we will get stuck on the while loop, and that loopcounter variable goes up to 130 million instead of 360 when it does exit, and we are still reading the register value as '0', even though the output pin says it's '1'.

zhemao commented 9 years ago

For your first question, try compiling the new kernel and loading that onto your SD card.

For your second question, I didn't use "alt_interrupt.h" because that is meant to be used with the NIOS soft processor, not the ARM HPS.

As for polling the register, have you made sure you marked the memory pointer as "volatile" in C. Otherwise, the compiler might optimize to cache the value locally, which might explain the behavior you see.

ghost commented 9 years ago

I made sure that it's volatile. But it makes no difference.

while(dmadone.ReadCtrlReg(0) == 0)

The ReadCtrlReg function expands to this.

volatile unsigned int ReadCtrlReg(int offset)
{
    volatile unsigned int* preg = (volatile unsigned int*)((unsigned int)mpRegMapMM);
    return preg[offset];
}

where mpRegMapMM is what initialized earlier in the program.

zhemao commented 9 years ago

What is mpRegMapMM? Why is it being cast to unsigned int before being recast to volatile unsigned int*?

ghost commented 9 years ago

mpRegMapMM is a void pointer.

Here's the header file

class tcCSRMap 
{
public:
    tcCSRMap(unsigned int RegsAddr);
    virtual ~tcCSRMap(void);

    volatile unsigned int ReadCtrlReg(int offset)
    {
        volatile unsigned int* preg = (volatile unsigned int*)((unsigned int)mpRegMapMM);
        return preg[offset];
    }

    void WriteCtrlReg(int offset, unsigned int value)
    {
        volatile unsigned int* preg = (volatile unsigned int*)((unsigned int)mpRegMapMM);
        preg[offset] = value;
    }

    void    *mpRegMapMM;  //!< memory mapped pointer to registers
};

source file

tcCSRMap::tcCSRMap(unsigned int RegsAddr)
: mpRegMapMM(NULL)
{
    int fd;

    /* map in the raw image buffer area */
    if ((fd = open("/dev/mem", O_RDWR)) < 0)
    {
        perror("/dev/mem");
    }
    else
    {
        void *lpmem;

        lpmem = mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, RegsAddr);
        if (lpmem == MAP_FAILED)
        {
            perror("mmap register buffers");
            close(fd);
            return;
        }
        mpRegMapMM = lpmem;
    }

    close(fd);
}

tcCSRMap::~tcCSRMap(void)
{
    if (mpRegMapMM)
        munmap(mpRegMapMM, 4096);
}
zhemao commented 9 years ago

In the future, please indent your source code in four spaces so that they will be properly formatted by the markdown handler. It makes it a lot easier to read.

I can't tell from this code why the behavior you mentioned is happening. The only thing that looks off about this code is casting the void pointer to an int before recasting it to a pointer. That shouldn't be necessary. You can cast directly from void pointer to int pointer.