Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
21615 Discussions

Interruption program

Altera_Forum
Honored Contributor II
4,910 Views

Hello, 

 

I am trying to do an interruption of a video signal. I am using the hsmc quad video card of Bitec associated to a cyclone III C25 Altera card. An interruption is supposed to be generated at each frame. 

First of all, I don't really understand what is the context, and what I should put in the edge_capture variable. 

I tried to adapt the interuption program which worked on buttons but no success. It should print "coincoin" whenever an interruption occurs. I put below the parts of my program corresponding to the interruption. Tell me if you need more details. 

 

Thanks for helping, 

 

Myriam 

 

 

Program : 

 

volatile int pouet=0; 

volatile int edge_capture; 

 

static void handle_DMA_interrupts(void* context, alt_u32 id) 

volatile int* edge_capture_ptr = (volatile int*) context; 

if (pouet==0) pouet = 1; 

}  

 

Then in, the main : 

 

... 

IOWR(video_in_base[0], 0x0, 0x08 ); // enable bit for interrupt 

IOWR_ALTERA_AVALON_PIO_IRQ_MASK(VIDEO_1_BASE, 0x01); 

alt_irq_register( VIDEO_1_IRQ,&edge_capture, handle_DMA_interrupts ); 

 

 

while ( 1 == 1 )  

{  

if (pouet == 1) 

{printf("coincoin"); 

pouet == 0; 

... 

}
0 Kudos
23 Replies
Altera_Forum
Honored Contributor II
3,166 Views

Hello, 

 

I do not know exactly the context when working with video, but for the interruption, as in your previous program you have to acknowledge the interruption in the ISR (like write on the edgecapture register for PIO port). 

 

Jérôme
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

Hi Jerome, 

 

The only registers I have are those below and I don't see which one could correspond to the edgecapture register. 

The line "IOWR(video_in_base[0], 0x0, 0x08 )" enables the interruption. I tried to put it in the ISR but no more success. 

# define VIDEO_1_NAME "/dev/video_1"# define VIDEO_1_TYPE "bitec_qvideo_in"# define VIDEO_1_BASE 0x00008000# define VIDEO_1_SPAN 128# define VIDEO_1_IRQ 1# define ALT_MODULE_CLASS_video_1 bitec_qvideo_in 

 

Given the registers, do you have an idea ?  

Thank you for your help, 

 

Myriam
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

Can you put a picture of your design to well understand the context please. 

 

Else, the variable context here is just to save values during ISR. For example in the count_binary example, you have the following : 

1 /* A variable to hold the value of the button pio edge capture register. */ 2 volatile int edge_capture; 3 static void init_button_pio() 4 { 5 /* Recast the edge_capture pointer to match the alt_irq_register() function 6 * prototype. */ 7 void* edge_capture_ptr = (void*) &edge_capture; 8 /* Enable all 4 button interrupts. */ 9 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf); 10 /* Reset the edge capture register. */ 11 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0); 12 /* Register the interrupt handler. */ 13 alt_irq_register( BUTTON_PIO_IRQ, edge_capture_ptr, 14 handle_button_interrupts ); 15 } 16 static void handle_button_interrupts(void* context, alt_u32 id) 17 { 18 /* Cast context to edge_capture's type. It is important that this be 19 * declared volatile to avoid unwanted compiler optimization. 20 */ 21 volatile int* edge_capture_ptr = (volatile int*) context; 22 /* Store the value in the Button's edge capture register in *context. */ 23 *edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE); 24 /* Reset the Button's edge capture register. */ 25 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0); 26 IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE); //An extra read call to clear of delay through the bridge 27 28 } In the ISR, you get the value of the edge capture register to know which button has been pushed, and store it at the address pointed by edge_capture_ptr. This variable point to the same address as context (line 21). And context has the same address as edge_capture variable (line 13 and 7).
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

Hi Jerôme, 

 

I attached two pictures of my top level entity. I am thus trying to interrupt video1. Thanks for your explanation of the context. The problem is that I don't see the context here... The interruption is automatically generated at the end of each frame and I see nothing in the registers which could register the context.  

 

Myriam
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

Hi, 

 

About the context forget it for the moment. It is not compulsory to use it. For example you can register the ISR like that. 

alt_irq_register( BUTTON_PIO_IRQ, 0, handle_button_interrupts ); And in the ISR function, you do not use the variable context. But it is not the problem, so forget it for the moment. 

 

So if I understand well, the interrupt is active when you have activity on the LSB of your video port. What is the name of this signal on your design ? 

 

To be sure if you have an interruption and the program goes to the ISR, you can switch on a LED in the ISR. Like that you know rapidly if the problem is here or not. 

 

After, as it is a the video port is a PIO port, like in your design with the buttons, the principle is the same. In the ISR, you have to write on the edgecapture register for PIO port (IOWR_ALTERA_AVALON_PIO_EDGE_CAP(VIDEO_1_BASE, 0xFF)). 

 

Jérôme
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

Hello, 

 

I don't manage to add buttons and led to my design. Indeed, I based my design on an example given by BITEC on their website. I changed .v files but never changed SoPC files. When I regenerate SOPC without changing anything, the design does not work anymore. I have then a time limited .sof so maybe I am missing some licenses (?) and some files are not correctly regenerated (?). Therefore, I can't touch to SoPC. 

 

However, I used your piece of advice and noticed first that like you said, I did not acknoledge the interruption which I did (it is not a PIO port but I found the way to do it). Second, my interruption signal was not generated. Now, it prints "coincoin" :) (see my first post). This means it goes to the ISR. The problem is that whether or not I generate an irq, the video (that is to say the rest of my program) does not work anymore.  

At least, when there is no irq generated, the rest of the program (which is the while (1)) should work, right ? Do I have to disable/enable something ? 

Do you have an idea where it may come from ? 

Your help is very precious ! 

 

Myriam
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

Hello, 

 

Sorry but I am not sure of what you say (I have to improve my english). If you don't have interruption the video works. And if you enable it, it does not work. Is that correct, or it never works ? 

 

If it never works, I have no idea because I never works with this design. So what I recommend is to use the default design provide by BITEC, check that it works, and modify it little by little until you have what you want. 

If it is the interruption that cause problem, like that I don't see where that can coming from. Maybe if you can give details of the different steps of your program please. 

 

Else, I missed it before, but you should change the following (I don't know the effect that can have) 

if (pouet == 1) {printf("coincoin"); pouet == 0; } by  

if (pouet == 1) {printf("coincoin"); pouet = 0; } Jérôme
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

Hi Jérôme, 

 

Thanks for the "equal error" ! I managed to have my design work. As my interruption was not on a PIO, I got confused. Actually, I did not need masks for my interruption so I removed this line and my design worked !  

Once more, thank you for your help. 

 

Myriam
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

Hi, 

 

Ok, so your design work as you want, or you still have problem or mysterious things to clarify ? 

Otherwise, I'm glad to have help you. 

 

Jérôme
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

Hi Jérôme, 

 

I am glad you ask because I do have a really mysterious error ! 

Like I told you before, I have a design with a cpu, onchip mem, a ssram, a flash memory interface, a tristate bridge, a jtag,a i2c bus (BITEC module), a vga and 2 video inputs (those are also BITEC modules). 

It was extracted from an example which worked. Until now, I never changed anything in SoPC. I made a test and generated sopc again without changing anything. Then, I have the following errors in NIOS (without changing my C code either). I have 32KBytes onchip mem with 32 bit wide data.  

I made another test and implemented an easy "Hello world" which does not work either ! Do you have an idea where it may come from ? I am really lost there ! 

 

Myriam 

 

 

Here is what is written in NIOS II : 

 

make -s all includes  

Compiling main4.c... 

Linking hsmc_quad_video_mosaic.elf... 

/cygdrive/c/altera/90/nios2eds/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.6/../../../../nios2-elf/bin/ld: region onchip_mem is full (hsmc_quad_video_mosaic.elf section .text). Region needs to be 20832 bytes larger. 

/cygdrive/c/altera/90/nios2eds/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.6/../../../../nios2-elf/bin/ld: address 0x1fd54 of hsmc_quad_video_mosaic.elf section .onchip_mem is not within region onchip_mem 

collect2: ld returned 1 exit status 

make: *** [hsmc_quad_video_mosaic.elf] Error 1 

Build completed in 6.828 seconds
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

Hi Myriam, 

 

You have a problem with the size of the memory, because the compiler told you "region onchip_mem is full" "Region needs to be 20832 bytes large". Your program is too large for the memory designed. 

 

When you regenerate the SOPC file, do you create another project in the Nios II IDE or you still use the same ? 

 

If you create another project you should take care about the project properties. In Nios II IDE, when you have created or open your project, click right on the folder corresponding to your project on the "Nios II C/C++ Projects" window, and select "System Library Properties". 

Check the checkboxs that are enable. if you don't use C++, you can disable "Support C++" , and enable "Program never exits" if the program never exits. Like that the program generated is more light. 

Maybe you can check the properties of the default design to compare. 

 

It is the only thing I see that can cause that, because if you change neither the system in SoPC nor the program, the final size of the program should be the same. 

 

Jérôme
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

It does not work but I need less memory : only 20172 ! 

Yes but with a Hello-world program, how can it be too large ?  

Plus, I was wondering about the onchip mem. With a C25 card, I have 0.6MBits of "total memory" (LEs + M9K memory blocks). Does it mean I have 0.6/8=75kBytes of onchip mem ? In this case, I could add more. 

I am thinking of adding a DDR SDRAM to have more memory, but is it necessarily onchip mem which is missing ? Is there a NIOS command to specify that we want the program to be stored on the DDR SDRAM ? 

Thanks for answering so quickly, 

 

Myriam
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

No, compiler told you that you need 20832 bytes more (I badly copy the sentence, it is not large, it is larger, sorry). How much memory you have in the SOPC of your design ? 

 

Indeed, your FPGA has 66 M9K blocks, which means 594 kbit or 74 kbyte. 

To choose which memory use for what, go to the System Library Properties of your project, as I described before. On the right, you can select which memory to use for the program, data, etc. Here select the DDR SDRAM instead of onchip_memory. 

 

Jérôme
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

I tried to put 70kbytes of onchip mem but I have a "can't fit in design" at the compilation. I am trying with 50kBytes (compilation is 20 minute long) 

I chose DDR SDRAM for the program memory and let the rest of the right column to ssram memory. I also tried to put everything on ddr sdram memory. But now, I have :  

 

Verifying 00010020 ( 0%) 

Verifying 00200000 ( 0%) 

Verifying 02000000 (13%) 

Verify failed between address 0x2000000 and 0x200D7EB 

Leaving target processor paused 

 

So weird !
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

I never use external memory so I have no idea why you have this error. 

Don't you have any design furnished by altera or bitec that use an external memory, to have a clean base ?
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

Hi Jérôme, 

 

No I don't manage to find a clear base... Anyway, I noticed that without adding a ddr-sdram, I could not change nios II : System Library Properties-> program memory from onchip memory to ssram. I have no other choice but onchip memory. Do you know what I need to do (surely in the quartus II design or anywhere) to have this possible ? 

Thanks, 

 

Myriam
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

Hi Myriam, 

 

Normally, what appears in System Library Properties is the memory you used in SoPC. So if you add a SRAM on the SoPC, it should appear here. It is not the case ? 

 

Jérôme
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

No, it was not but I found out why ! I did not connect the instruction data of the cpu to the ssram. Thus, I don't have memory problem anymore but my video does not work now... Still work to do ! Anyway, thank you very much for your help. 

 

Myriam
0 Kudos
Altera_Forum
Honored Contributor II
3,166 Views

We advance, we advance... :-)

0 Kudos
Altera_Forum
Honored Contributor II
3,035 Views

Hi Jérôme, 

 

I come back to you as I managed to target my problem... 

 

I attached to the mail my sopc design. When I put everything to onchip mem in the system library properties, everything works. 

Then, if I put everything to ssram or ddr-sdram except program memory (to onchip mem), nios II compiles but the program does not work. Then, if I put everything to ddr sdram, I have the traditional : 

 

Verifying 00010020 ( 0%) 

Verifying 04000000 ( 2%) 

Verify failed between address 0x4000000 and 0x400369F 

Leaving target processor paused 

 

I don't understand how system library properties is related to quartus II.  

Why doesn't it work with ssram ? I did not even add it like the ddr-sdram, it was already in the original design... 

 

Thanks, 

 

Myriam
0 Kudos
Reply