# FreeRTOS+lwIP Demo - timer int doesnt work

**URL:** <https://forums.freertos.org/t/freertos-lwip-demo-timer-int-doesnt-work/5517>\
**Category:** Kernel\
**Created:** [September 7, 2006, 8:08pm UTC](https://forums.freertos.org/t/freertos-lwip-demo-timer-int-doesnt-work/5517 "2006-09-07T20:08:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 7, 2006, 8:08pm UTC](https://forums.freertos.org/t/freertos-lwip-demo-timer-int-doesnt-work/5517/1 "2006-09-07T20:08:38Z")

</div>

**nobody** wrote on [Thursday, September 07, 2006](https://sourceforge.net/p/freertos/discussion/382005/thread/f5cf0ee9/#cc83):

Hi,  
I’m trying to build my application based on FreeRTOS+lwIP Rowley Demo.  
Everything works fine with my AT91SAM7X256 board. Now I’m trying to write my own piece of code to understand how everything works.  
I tried to write timer interrupt and toggle a led with it. Code worked when I compiled it without FreeRTOS but when I try to implement it as a part of the system it doesnt work.

My timer init looks like that:  
void timer\_init ( void )  
//\* Begin  
{  
&nbsp;&nbsp;&nbsp; portENTER\_CRITICAL();

&nbsp;&nbsp;&nbsp; //\* Open timer0  
&nbsp;&nbsp;&nbsp; AT91F\_TC\_Open(AT91C\_BASE\_TC0,TC\_CLKS\_MCK8,AT91C\_ID\_TC0);

&nbsp;&nbsp;&nbsp; //\* Open Timer 0 interrupt  
&nbsp;&nbsp;&nbsp; AT91F\_AIC\_ConfigureIt ( AT91C\_ID\_TC0, TIMER0\_INTERRUPT\_LEVEL,AT91C\_AIC\_SRCTYPE\_INT\_HIGH\_LEVEL, timer0\_c\_irq\_handler);  
&nbsp;&nbsp;&nbsp; AT91C\_BASE\_TC0-\>TC\_IER = AT91C\_TC\_CPCS;&nbsp; //&nbsp; IRQ enable CPC  
//&nbsp;&nbsp;&nbsp; AT91F\_AIC\_EnableIt (AT91C\_BASE\_AIC, AT91C\_ID\_TC0);  
&nbsp;&nbsp;&nbsp; AT91C\_BASE\_AIC-\>AIC\_IECR = 0x1 \<\< AT91C\_ID\_TC0;

&nbsp;&nbsp;&nbsp; //\* Start timer0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AT91C\_BASE\_TC0-\>TC\_CCR = AT91C\_TC\_SWTRG ;

&nbsp;&nbsp;&nbsp; portEXIT\_CRITICAL();  
//\* End  
}

And interrupt routine:  
void timer0\_c\_irq\_handler(void) \_\_attribute\_\_ ((naked));

void timer0\_c\_irq\_handler(void)  
{  
&nbsp;&nbsp;&nbsp; portENTER\_SWITCHING\_ISR();

&nbsp;&nbsp;&nbsp; portBASE\_TYPE xSwitchRequired = pdFALSE;  
&nbsp;&nbsp;&nbsp; AT91PS\_TC TC\_pt = AT91C\_BASE\_TC0;  
&nbsp;&nbsp;&nbsp; unsigned int dummy;  
&nbsp;&nbsp;&nbsp; //\* Acknowledge interrupt status  
&nbsp;&nbsp;&nbsp; dummy = TC\_pt-\>TC\_SR;  
&nbsp;&nbsp;&nbsp; //\* Suppress warning variable "dummy" was set but never used  
&nbsp;&nbsp;&nbsp; dummy = dummy;  
&nbsp;&nbsp;&nbsp; count\_timer0\_interrupt++;  
&nbsp;&nbsp;&nbsp; //\* Read the output state  
&nbsp;&nbsp;&nbsp; if ( (AT91F\_PIO\_GetInput(AT91C\_BASE\_PIOB) & LED1 ) == LED1 )  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AT91F\_PIO\_ClearOutput( AT91C\_BASE\_PIOB, LED1 );  
&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp; else  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AT91F\_PIO\_SetOutput( AT91C\_BASE\_PIOB, LED1 );  
&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp; portEXIT\_SWITCHING\_ISR( xSwitchRequired );  
}

Timer init is called from vBasicWEBServer thread.  
The problem is that TimerISR is entered only once and the led flashes but then it hangs. Other tasks work fine.  
I’ve lost many hours to fix it, maybe I dont understand something, but it should work and it doesnt.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 7, 2006, 10:44pm UTC](https://forums.freertos.org/t/freertos-lwip-demo-timer-int-doesnt-work/5517/2 "2006-09-07T22:44:11Z")

</div>

**nobody** wrote on [Thursday, September 07, 2006](https://sourceforge.net/p/freertos/discussion/382005/thread/f5cf0ee9/#cc83/be23):

You should send info to AIC that you finished interrupt service (eg. \*AT91C\_AIC\_EOICR = 0;) before portEXIT\_SWITCHING\_ISR.

Janusz

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 7, 2006, 10:57pm UTC](https://forums.freertos.org/t/freertos-lwip-demo-timer-int-doesnt-work/5517/3 "2006-09-07T22:57:29Z")

</div>

**nobody** wrote on [Thursday, September 07, 2006](https://sourceforge.net/p/freertos/discussion/382005/thread/f5cf0ee9/#cc83/5619):

Well… I’m blind %). How could I miss it while looking at EMAC\_ISR example routine? 😃  
Thanks for help, it works now :]
