Forum Discussion
Altera_Forum
Honored Contributor
16 years agoCode in tightly coupled memory
Hi all,
I placed a function in a section different from the main code. More exactly, my code is mapped to sdram and I linked a function testcall() into a tightly coupled memory section which I previoulsy defined in sopc builder. So I declared: int testcall(int n) __attribute__ ((section (".tc_code"))); Then, following the suggestion I found in another thread I called ALT_LOAD_SECTION_BY_NAME(tc_code) before calling testcall(). My questions are: - is the ALT_LOAD_SECTION_BY_NAME(tc_code) mandatory? The code seems to work even if I don't use it. - if tc_code section is located in internal fpga memory (cyclone III M9k blocks), how much is the code speed improvement I could roughly obtain with respect to sdram (assume I'm using 2 tse with sgdma). Thank you Cris37 Replies
- Altera_Forum
Honored Contributor
For a single variable I need in TCM I simply use the attribute directive after declaration.
int array_in_tcm[128] __attribute__ (section (".tc_data")); Same for a single function: int function_in_tcm(int param) __attribute__ (section (".tc_code")); tc_data and tc_code are the names I assigned to tcm blocks in sopc builder. I'm not sure, but don't think exception stack placement is so important for performance. This is executed only in case of exceptions, not in normal operation. Application runtime stack is important, since its data is continuosly accessed in function calls, especially if you use a lot of local variables. - Altera_Forum
Honored Contributor
Ok, now I know how to address tc_data, thanks.
But I intend to use TCM for ISRs (Interrupt Service Routine). I need to know, how to define an "Separate Hardware Interrupt Stack". I haven't found any examples. Better I explain my intentions in more detail. My ISR looks like this: static void handle_CPU2_interrupts(void* context, alt_u32 id) __attribute__ ((section (".exceptions"))); static void handle_CPU2_interrupts(void* context, alt_u32 id) { OSSemPost(IRQSem); // <-- benefit from a seperated exception stack ? IOWR_ALTERA_AVALON_PIO_EDGE_CAP(CPU1_INTHAND_BASE, 0x1); } void task(void* pdata) { [... init ...] while (1) { OSSemPend(IRQSem, 0, &err); <-- event waiting [ ... do something ... ] } } SoPC: I set the exception address, on the Core Nios II tab, in the Exception Vector: Memory: list, to tightly_coupled_instruction_memory_s1. RTOS: I use µC/OS-II. Problems: 1. ISR response takes ~16 µs. 2. From OSSemPost, in the ISR, to OSSemPend, in task, it takes ~34 µs. Any chances to reduce these times ? My possible solutions: -> Try TCM -> Try VIC -> will reduce ISR response certainly (<<16µs) If I had examples I wouldn't struggle with TCM and I can test possible performance improvements. I would appreciate any comments / suggestions. I need this for my bachelor thesis. Thanks any help very much. Regards, R2-D2 @chris72your thread "timer interrupt with rtos-ii"
similar to my project.
- Altera_Forum
Honored Contributor
--- Quote Start --- Problems: 1. ISR response takes ~16 µs. 2. From OSSemPost, in the ISR, to OSSemPend, in task, it takes ~34 µs. Any chances to reduce these times ? --- Quote End --- Did you use the custom opcode for interrupt vectors? It changes interrupt response an opcode to do the dispatch from a C function to lookup the vector. OSSemPost and OSSemPend delays are part of uC/OS-II. Unless you don't have compiler optimization on (-O2 or -O3) there's not much you can do - unless you put OSSemPost and OSSemPend in TCM. Bill - Altera_Forum
Honored Contributor
Hi R2-D2,
I have exactly the same situation you described: code placement, RTOS, even same isr and OSSem usage. So, my response times are similar, too. In addition, I use NicheStack for TCP/IP and when I load the system with network traffic I have worst case response times up to 150us. In these cases I also see an increase in isr response to about 40us: I think this is due to OS (or TCP stack) disabling irq in some critical pieces of code. I wrote a post asking if this behaviour is normal, but I had no answers. For BillA I use custom opcode for int vectors and O3 optimization level. Then I believe R2-D2 does, too. Regards Cris - Altera_Forum
Honored Contributor
--- Quote Start --- Did you use the custom opcode for interrupt vectors? It changes interrupt response an opcode to do the dispatch from a C function to lookup the vector. --- Quote End --- Sry, I don't understand this. What do you mean with custom optcode ? Taking the whole bunch of the ISR directly in the VIC, so that I don't need alt_irq_register ? --- Quote Start --- OSSemPost and OSSemPend delays are part of uC/OS-II. Unless you don't have compiler optimization on (-O2 or -O3) there's not much you can do - unless you put ossempost and ossempend in tcm. --- Quote End --- Sounds good to me! Can you explain me in few words how to accomplish this, please ? --- Quote Start --- I use custom opcode for int vectors and O3 optimization level. Then I believe R2-D2 does, too. --- Quote End --- The timings are based on standard IIC (no VIC) and -O0 optimations. So, I haven't done any optimations yet. Thanks for your comments Regards, R2-D2 - Altera_Forum
Honored Contributor
--- Quote Start --- Sry, I don't understand this. What do you mean with custom optcode ? Taking the whole bunch of the ISR directly in the VIC, so that I don't need alt_irq_register ? --- Quote End --- Maybe this helps? http://www.alteraforum.org/forum/showthread.php?p=65073 And Google: ALT_CI_EXCEPTION_VECTOR_N --- Quote Start --- Sounds good to me! Can you explain me in few words how to accomplish this, please ? --- Quote End --- That's covered in this thread in fact: http://www.alteraforum.com/forum/showpost.php?p=92691&postcount=19 --- Quote Start --- The timings are based on standard IIC (no VIC) and -O0 optimations. So, I haven't done any optimations yet --- Quote End --- Don't bother timing anything until you're using -O2 or -O3 - the difference is night and day. Bill - Altera_Forum
Honored Contributor
Actually, I know these links ;) I will take a closer look then. I will post my results when finished or earlier when something strange happens :eek:.
Thank you very much