EmbeddedRelated.com
Forums

interrupts before FreeRTOS scheduler start

Started by Michał April 29, 2009
Hello,

I working on project that is based on FreeRTOS for AT91SAM7X256
(Crossworks compiler). I would like to implement following
functionality. Let’s assume that because of some system conditions (e.g.
number of watchdog system restarts) I would like to decide if software
should start FreeRTOS kernel or not. If not it would start typical
while(1) loop and work without FreeRTOS but with interrupts (something
like safe mode).

Seams easy but there is something that I do not understand. I have
problem with interrupts in this little alternative system. I am quite
sure that this is caused by general freertos concept because code used
in “alternative system” works normally in another GCC project without
FreeRTOS. Problem occurs when I call function that enables global
interrupts (this is done after enabling timer and uart interrupts).
After calling: libarm_enable_irq() or vPortEnableInterruptsFromThumb()
or portENABLE_INTERRUPTS() CPU goes to undefined mode. This functions
are called under supervisor mode.

I have tried changing CPU modes before enabling global interrupts but
without any luck. Can anyone give me a clue how to solve this problem?

Kind Regards
Michal
> Hello,
>
> I working on project that is based on FreeRTOS for AT91SAM7X256
> (Crossworks compiler). I would like to implement following
> functionality. Lets assume that because of some system
> conditions (e.g.
> number of watchdog system restarts) I would like to decide if
> software
> should start FreeRTOS kernel or not. If not it would start typical
> while(1) loop and work without FreeRTOS but with interrupts
> (something
> like safe mode).
>
> Seams easy but there is something that I do not understand. I have
> problem with interrupts in this little alternative system. I am quite
> sure that this is caused by general freertos concept because
> code used
> in alternative system works normally in another GCC project without
> FreeRTOS. Problem occurs when I call function that enables global
> interrupts (this is done after enabling timer and uart interrupts).
> After calling: libarm_enable_irq() or
> vPortEnableInterruptsFromThumb()
> or portENABLE_INTERRUPTS() CPU goes to undefined mode. This functions
> are called under supervisor mode.
>
> I have tried changing CPU modes before enabling global interrupts but
> without any luck. Can anyone give me a clue how to solve this problem?
>

Interrupts that attempt to use a FreeRTOS API function must not be allowed
to execute before the scheduler has been started. In your safe mode I
presume you are using the same peripheral and interrupt setup? If so then
enusre peripherals that could cause an interrupt are un-initialised before
interrupts are enabled.

Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers. More than 7000 downloads per month.

+ http://www.SafeRTOS.com
Certified by T as meeting the requirements for safety related systems.
Hi,

Thank you for your answer. My safe mode doesn’t use FreeRTOS API
functions. It is simple register access written by myself (mainly to
provide code redundancy). Actually I am enabling global interrupts after
performing peripherals setup, so maybe this is the problem. Could you
explain why?

I will have access to my hardware tomorrow and I will check if changing
setup sequence helps.

Kind Reagards
Michal
FreeRTOS info pisze:
>> Hello,
>>
>> I working on project that is based on FreeRTOS for AT91SAM7X256
>> (Crossworks compiler). I would like to implement following
>> functionality. Let’s assume that because of some system
>> conditions (e.g.
>> number of watchdog system restarts) I would like to decide if
>> software
>> should start FreeRTOS kernel or not. If not it would start typical
>> while(1) loop and work without FreeRTOS but with interrupts
>> (something
>> like safe mode).
>>
>> Seams easy but there is something that I do not understand. I have
>> problem with interrupts in this little alternative system. I am quite
>> sure that this is caused by general freertos concept because
>> code used
>> in “alternative system” works normally in another GCC project without
>> FreeRTOS. Problem occurs when I call function that enables global
>> interrupts (this is done after enabling timer and uart interrupts).
>> After calling: libarm_enable_irq() or
>> vPortEnableInterruptsFromThumb()
>> or portENABLE_INTERRUPTS() CPU goes to undefined mode. This functions
>> are called under supervisor mode.
>>
>> I have tried changing CPU modes before enabling global interrupts but
>> without any luck. Can anyone give me a clue how to solve this problem?
>>
>>
>
> Interrupts that attempt to use a FreeRTOS API function must not be allowed
> to execute before the scheduler has been started. In your safe mode I
> presume you are using the same peripheral and interrupt setup? If so then
> enusre peripherals that could cause an interrupt are un-initialised before
> interrupts are enabled.
>
> Regards,
> Richard.
>
> + http://www.FreeRTOS.org
> Designed for Microcontrollers. More than 7000 downloads per month.
>
> + http://www.SafeRTOS.com
> Certified by TÜV as meeting the requirements for safety related systems.
>
Ok. so I tried to change initialization sequence but without any
success. It looks like ARM cpu is going into undefined mode when
interrupt routine should be called. I am slowly running out of options :(.
Below you can find my code:

unsigned int TICK_COUNTER;

void safeMode_Main()
{
libarm_enable_irq();
initSysTimer();

while(1){

TICK_COUNTER++;
}
}

void sysTimer_IrqHandler()
{
//clear interrupt flag!
//read status register
unsigned int stat_reg = AT91C_BASE_TC0->TC_SR;
//TICK_COUNTER++;

}

void initSysTimer()
{
//AT91C_BASE_PIOA->PIO_PDR = LED1;//AT91C_ID_TC0; //disable PIOA
form controlling the pin
//AT91C_BASE_PIOA->PIO_BSR = LED1;//AT91C_ID_TC0; //select
peripheral B to control pin

AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = (unsigned
int)sysTimer_IrqHandler; //assign interrupt handler

AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0]
=(AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 0x6 ); //level sensitive and priority

AT91C_BASE_PMC->PMC_PCER = (1< //peripherial clock enable

AT91C_BASE_TCB->TCB_BCR = 0; // no sync

AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC0XC0S_NONE |
AT91C_TCB_TC2XC2S_NONE; //no external clock

AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;//AT91C_TC_SWTRG |
AT91C_TC_CLKEN; //clock disable, comment enable and start

AT91C_BASE_TC0->TC_CMR = AT91C_TC_ACPC_TOGGLE | AT91C_TC_WAVE |
AT91C_TC_WAVESEL_UP_AUTO | AT91C_TC_CLKS_TIMER_DIV1_CLOCK;//CPC

//Overiden in adc start
AT91C_BASE_TC0->TC_RC = 24000;
AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS; //enable RC compare int
AT91C_BASE_TC0->TC_IDR = ~AT91C_TC_CPCS; //disable other
AT91C_BASE_AIC->AIC_IECR = (1< AT91C_BASE_AIC->AIC_ICCR = (1< //TIC_NUM = 0;

//startTimer
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG | AT91C_TC_CLKEN;

}
Kind regards
Michal
Michał pisze:
> Hi,
>
> Thank you for your answer. My safe mode doesn’t use FreeRTOS API
> functions. It is simple register access written by myself (mainly to
> provide code redundancy). Actually I am enabling global interrupts after
> performing peripherals setup, so maybe this is the problem. Could you
> explain why?
>
> I will have access to my hardware tomorrow and I will check if changing
> setup sequence helps.
>
> Kind Reagards
> Michal
> FreeRTOS info pisze:
>
>>> Hello,
>>>
>>> I working on project that is based on FreeRTOS for AT91SAM7X256
>>> (Crossworks compiler). I would like to implement following
>>> functionality. Let’s assume that because of some system
>>> conditions (e.g.
>>> number of watchdog system restarts) I would like to decide if
>>> software
>>> should start FreeRTOS kernel or not. If not it would start typical
>>> while(1) loop and work without FreeRTOS but with interrupts
>>> (something
>>> like safe mode).
>>>
>>> Seams easy but there is something that I do not understand. I have
>>> problem with interrupts in this little alternative system. I am quite
>>> sure that this is caused by general freertos concept because
>>> code used
>>> in “alternative system” works normally in another GCC project without
>>> FreeRTOS. Problem occurs when I call function that enables global
>>> interrupts (this is done after enabling timer and uart interrupts).
>>> After calling: libarm_enable_irq() or
>>> vPortEnableInterruptsFromThumb()
>>> or portENABLE_INTERRUPTS() CPU goes to undefined mode. This functions
>>> are called under supervisor mode.
>>>
>>> I have tried changing CPU modes before enabling global interrupts but
>>> without any luck. Can anyone give me a clue how to solve this problem?
>>>
>>>
>>>
>> Interrupts that attempt to use a FreeRTOS API function must not be allowed
>> to execute before the scheduler has been started. In your safe mode I
>> presume you are using the same peripheral and interrupt setup? If so then
>> enusre peripherals that could cause an interrupt are un-initialised before
>> interrupts are enabled.
>>
>> Regards,
>> Richard.
>>
>> + http://www.FreeRTOS.org
>> Designed for Microcontrollers. More than 7000 downloads per month.
>>
>> + http://www.SafeRTOS.com
>> Certified by TÜV as meeting the requirements for safety related systems.
>>
>>
>> Yahoo! Groups Links
>>
>>
>
>
>
> Yahoo! Groups Links
>
So I have continued my research on interrupt problem before FreeRTOS
scheduler start. I have created clean new project in crossworks and used
my timer code and simple while(1) loop. Everything works correctly so I
assume that my code is written properly.

Using JTAG I have observed that there is an important difference between
clean corssworks project and freertos demo project. Clean project starts
without thumb and in system mode. FreeRTOS demo project starts in thumb
and in supervisor mode. I suspect that because of that my code that
tries to use interrupts before scheduler start, ends up in undefined mode.

So basically my question remains unsolved. How to use interrupts before
FreeRTOS scheduler start?

Kind Regards
Michal M.

Michał pisze:
> Ok. so I tried to change initialization sequence but without any
> success. It looks like ARM cpu is going into undefined mode when
> interrupt routine should be called. I am slowly running out of options :(.
> Below you can find my code:
>
> unsigned int TICK_COUNTER;
>
> void safeMode_Main()
> {
> libarm_enable_irq();
> initSysTimer();
>
> while(1){
>
> TICK_COUNTER++;
> }
> }
>
> void sysTimer_IrqHandler()
> {
> //clear interrupt flag!
> //read status register
> unsigned int stat_reg = AT91C_BASE_TC0->TC_SR;
> //TICK_COUNTER++;
>
> }
>
> void initSysTimer()
> {
> //AT91C_BASE_PIOA->PIO_PDR = LED1;//AT91C_ID_TC0; //disable PIOA
> form controlling the pin
> //AT91C_BASE_PIOA->PIO_BSR = LED1;//AT91C_ID_TC0; //select
> peripheral B to control pin
>
>
> AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = (unsigned
> int)sysTimer_IrqHandler; //assign interrupt handler
>
> AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0]
> =(AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 0x6 ); //level sensitive and
> priority
>
> AT91C_BASE_PMC->PMC_PCER = (1< > //peripherial clock enable
>
> AT91C_BASE_TCB->TCB_BCR = 0; // no sync
>
> AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC0XC0S_NONE |
> AT91C_TCB_TC2XC2S_NONE; //no external clock
>
> AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;//AT91C_TC_SWTRG |
> AT91C_TC_CLKEN; //clock disable, comment enable and start
>
> AT91C_BASE_TC0->TC_CMR = AT91C_TC_ACPC_TOGGLE | AT91C_TC_WAVE |
> AT91C_TC_WAVESEL_UP_AUTO | AT91C_TC_CLKS_TIMER_DIV1_CLOCK;//CPC
>
> //Overiden in adc start
> AT91C_BASE_TC0->TC_RC = 24000;
> AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS; //enable RC compare int
> AT91C_BASE_TC0->TC_IDR = ~AT91C_TC_CPCS; //disable other
> AT91C_BASE_AIC->AIC_IECR = (1< > AT91C_BASE_AIC->AIC_ICCR = (1< > //TIC_NUM = 0;
>
> //startTimer
> AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG | AT91C_TC_CLKEN;
>
> }
> Kind regards
> Michal
> Michał pisze:
>> Hi,
>>
>> Thank you for your answer. My safe mode doesn’t use FreeRTOS API
>> functions. It is simple register access written by myself (mainly to
>> provide code redundancy). Actually I am enabling global interrupts after
>> performing peripherals setup, so maybe this is the problem. Could you
>> explain why?
>>
>> I will have access to my hardware tomorrow and I will check if changing
>> setup sequence helps.
>>
>> Kind Reagards
>> Michal
>> FreeRTOS info pisze:
>>
>>>> Hello,
>>>>
>>>> I working on project that is based on FreeRTOS for AT91SAM7X256
>>>> (Crossworks compiler). I would like to implement following
>>>> functionality. Let’s assume that because of some system
>>>> conditions (e.g.
>>>> number of watchdog system restarts) I would like to decide if
>>>> software
>>>> should start FreeRTOS kernel or not. If not it would start typical
>>>> while(1) loop and work without FreeRTOS but with interrupts
>>>> (something
>>>> like safe mode).
>>>>
>>>> Seams easy but there is something that I do not understand. I have
>>>> problem with interrupts in this little alternative system. I am quite
>>>> sure that this is caused by general freertos concept because
>>>> code used
>>>> in “alternative system” works normally in another GCC project without
>>>> FreeRTOS. Problem occurs when I call function that enables global
>>>> interrupts (this is done after enabling timer and uart interrupts).
>>>> After calling: libarm_enable_irq() or
>>>> vPortEnableInterruptsFromThumb()
>>>> or portENABLE_INTERRUPTS() CPU goes to undefined mode. This functions
>>>> are called under supervisor mode.
>>>>
>>>> I have tried changing CPU modes before enabling global interrupts but
>>>> without any luck. Can anyone give me a clue how to solve this problem?
>>>>
>>>>
>>>>
>>> Interrupts that attempt to use a FreeRTOS API function must not be allowed
>>> to execute before the scheduler has been started. In your safe mode I
>>> presume you are using the same peripheral and interrupt setup? If so then
>>> enusre peripherals that could cause an interrupt are un-initialised before
>>> interrupts are enabled.
>>>
>>> Regards,
>>> Richard.
>>>
>>> + http://www.FreeRTOS.org
>>> Designed for Microcontrollers. More than 7000 downloads per month.
>>>
>>> + http://www.SafeRTOS.com
>>> Certified by TÜV as meeting the requirements for safety related systems.
>>>
>>>
>>>
>>>
>>> Yahoo! Groups Links
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>> Yahoo! Groups Links
>>
> -----Original Message-----
> From: A...
> [mailto:A...] On Behalf Of Michal
> Sent: 04 May 2009 20:53
> To: A...
> Subject: Re: [AT91SAM] interrupts before FreeRTOS scheduler start
>
>
>
> So I have continued my research on interrupt problem before
> FreeRTOS scheduler start. I have created clean new project in
> crossworks and used my timer code and simple while(1) loop.
> Everything works correctly so I assume that my code is
> written properly.
>
> Using JTAG I have observed that there is an important
> difference between clean corssworks project and freertos demo
> project. Clean project starts without thumb and in system
> mode. FreeRTOS demo project starts in thumb and in supervisor
> mode. I suspect that because of that my code that tries to
> use interrupts before scheduler start, ends up in undefined mode.
>
> So basically my question remains unsolved. How to use
> interrupts before FreeRTOS scheduler start?

The FreeRTOS project can be compiled for either THUMB or ARM mode (change
the compiler options and ensure THUMB_INTERWORK is defined to use THUMB
mode). The interrupt service routines must be in ARM mode, even when the
rest of the code is compiled into THUMB. Are you compiling your ISRs as ARM
code?

Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers. More than 7000 downloads per month.

+ http://www.SafeRTOS.com
Certified by T as meeting the requirements for safety related systems.
Yes, that was the problem. I have changed interrupt routines to ARM mode
and it works. Thank you for your help.

Kind Regards
Michal M.

FreeRTOS info pisze:
>> -----Original Message-----
>> From: A...
>> [mailto:A...] On Behalf Of Michal
>> Sent: 04 May 2009 20:53
>> To: A...
>> Subject: Re: [AT91SAM] interrupts before FreeRTOS scheduler start
>>
>> So I have continued my research on interrupt problem before
>> FreeRTOS scheduler start. I have created clean new project in
>> crossworks and used my timer code and simple while(1) loop.
>> Everything works correctly so I assume that my code is
>> written properly.
>>
>> Using JTAG I have observed that there is an important
>> difference between clean corssworks project and freertos demo
>> project. Clean project starts without thumb and in system
>> mode. FreeRTOS demo project starts in thumb and in supervisor
>> mode. I suspect that because of that my code that tries to
>> use interrupts before scheduler start, ends up in undefined mode.
>>
>> So basically my question remains unsolved. How to use
>> interrupts before FreeRTOS scheduler start?
>>
>
> The FreeRTOS project can be compiled for either THUMB or ARM mode (change
> the compiler options and ensure THUMB_INTERWORK is defined to use THUMB
> mode). The interrupt service routines must be in ARM mode, even when the
> rest of the code is compiled into THUMB. Are you compiling your ISRs as ARM
> code?
>
> Regards,
> Richard.
>
> + http://www.FreeRTOS.org
> Designed for Microcontrollers. More than 7000 downloads per month.
>
> + http://www.SafeRTOS.com
> Certified by TÜV as meeting the requirements for safety related systems.
>