RTC wakeup interrupt using FreeRTOS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RTC wakeup interrupt using FreeRTOS

4,146 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by henna on Wed Jun 10 03:09:15 MST 2015
Hi,

I am working on a project which requires to go to deep power down mode after certain period of time using tickless mode of FreeRTOS and wakeup after RTC alarm interrupt is generated.

I am using FreeRTOS blinky demo to start with, and right now there are two tasks led blinking and RTC alarm interrupt generation every 5 seconds.

I have managed to create a task which generates RTC alarm interrupt using FreeRTOS demo code. My problem is after first RTC alarm interrupt, RTC never triggers any alarm even if task is created to re-initialized RTC after every alarm interrupt. 

FreeRTOS is not hang as I can see LED blinking as expected.

Can anybody tell me what I am doing wrong and guide me how do I achieve my goal I stated in first line with some FreeRTOS example.

Is Interrupt Processing using Semaphore is required?

Any help will be appreciated.

Thank you,
Heena 
Labels (1)
0 Kudos
9 Replies

2,248 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by henna on Sat Jun 20 06:06:03 MST 2015
Hi Richards,

You are right I am not calling vPortSuppressTicksAndSleep() directly, it is called automatically.

I believe I am configuring alarm timer correctly as I am toggling one GPIO pin in the alarm interrupt which toggles every 1ms(checked in scope). What I am not sure is the value I updated to alarm timer after lower mode ends due to RTC interrupt.

I am requesting context switch from RTC interrupt ISR.

My question remain the same as my previous post, can you please guide me for those problems.

I appreciate your time you took to reply me so quickly.

Regards,
Heena
0 Kudos

2,248 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by www.FreeRTOS.org on Sat Jun 20 03:21:52 MST 2015
You should not call vPortSuppressTicksAndSleep() directly - it is called automatically when your tasks are blocked.

If you are not sure if you are setting the alarm timer correctly, then, for test purposes only, just use a value that you know will create a tick at the required rate.  Once that is working, then you can try and do something more fancy and actually get the value more accurate.

When you give the semaphore from the ISR - do you the request a context switch from inside the ISR, in the normal way and as documented in the API?  If you don't then the scheduler will not know there is a context switch pending http://www.freertos.org/a00124.html
0 Kudos

2,248 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by henna on Fri Jun 19 20:56:36 MST 2015
Hi Richard,

Thanks for the quick response.

I have working RTC interrupt which generates interrupt every 5 seconds, my problem is related to RTOS.

I understood that scheduler gets suspended before calling vPortSuppressTicksAndSleep() function. My problem is even if I enable the alarm timer interrupt which generates tick interrupt, RTOS does not resumes scheduler to resume LED tasks from main after wake up. I am not sure I am updating the alarm timer with correct tick value after wake up, I need some advise on how to update correct value to tick interrupt.

Second problem is it goes into a loop where vPortSuppressTicksAndSleep()  function is called again and again and MCU goes to sleep and wakes up on RTC interrupt. This is like continuous loop and RTOS does not resume the tasks I call from main which is just to blink LED's. Do I need to create any task which calls vPortSuppressTicksAndSleep() function whenever I want to goto sleep.

My wake up interrupt using RTC is on semaphore and xSemaphoreGiveFromISR function is called from ISR during RTC wake up interrupt, do you think this is the problem as this requires context switch while scheduler is suspended.

Any help or suggestion will appreciated.

Regards,
Heena
0 Kudos

2,248 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by www.FreeRTOS.org on Fri Jun 19 12:05:30 MST 2015
>  the problem was scheduler suspended and resuming the tasks after wake up

I'm not sure I understand that, the scheduler should be suspended at that time, otherwise there will be race conditions.

If you look at where vPortSuppressTicksAndSleep() is called from you will see the scheduler is suspended first, then the tick interrupt is stopped, and the low power mode entered.  Low power mode is then exited when an interrupt occurs.  The interrupt will bring the MCU out of low power mode, but the ISR will not execute until interrupts are re-enabled.  When interrupts are re-enabled the ISR executes.  If the ISR attempts a context switch then the context switch will not occur, because the scheduler is suspended, but instead be held pending.  When the scheduler is unsuspended the context switch that was pending occurs.


> My problem is after first RTC alarm interrupt, RTC never triggers any alarm

Are you saying the RTC interrupt handler executes once, but then never executes again?  Do you have the RTC interrupt executing in the manner you need in an application that is not using an RTOS?  Best to get it working first, then add the code into your RTOS application.

0 Kudos

2,248 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by henna on Fri Jun 19 07:50:57 MST 2015
Hi,

I tried the first method but it didn't work, the problem was scheduler suspended and resuming the tasks after wake up, so I decided to move on second method by implementing vPortSuppressTicksAndSleep().

Right now I am using alarm timer which is 16 bit timer to generate periodic tick interrupt at every 1 ms with 1024Hz frequency derived from RTC domain. Along with I am using RTC to generate wake up interrupt every 5 seconds(for test purpose in actual it could be several hours). RTC interrupt is on semaphore with high priority and alarm timer with lowest priority.

I managed to configure tick interrupt source as alarm timer which generates the tick interrupt and starts the scheduler and RTC is generating interrupt every 5 second, now the one problem is similar to first method which is scheduler gets suspended and no task resume after wake up. ( I am not sure I am updating the alarm timer with correct after wake up).

Second problem is it goes into a loop where MCU goes to sleep and wake up on RTC interrupt. This is like continuous loop and RTOS does not resume the tasks I call from main which is just to blink LED's.

I took reference of web link mentioned on previous post by Richard and STM32l512 low power discovery demo.

I can post a code if required, can anyone please guide me what I am doing wrong and what is to be done to over come this problem. Also how to calculate the ExpectedIdletime and alarm timer value to update tick interrupt after wake up.

Any help or suggestion will be appreciated.

Regards,
Heena
0 Kudos

2,248 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by henna on Sun Jun 14 15:28:33 MST 2015
Hi Richards,

Thank you for the answer.

I will try your method and will update the results.

Regards,
Heena
0 Kudos

2,248 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by www.FreeRTOS.org on Fri Jun 12 02:28:10 MST 2015
Maybe the simplest way, at least for a first experiment, is to use the pre and post sleep hooks, although that may result in slight time slippage, so it depends on how accurate the time keeping in your system needs to be (the RTC can always be used too).

Continue using the default tick-less implementation for now.  Then in FreeRTOSConfig.h define the configPRE_SLEEP_PROCESSING( xModifiableIdleTime ); macro to set your RTC wakeup interrupt for the correct time [1], enter a deep sleep mode [2], and set xModifiableIdleTime to 0 [3].

[1] The time to sleep, in ticks, is contained in the xExpectedIdleTime variable, which is accessible from the macro.

[2] You can enter whichever deep sleep mode you need to here - provided the RAM and processor contents are maintained, the RTC is still functional, and an interrupt will bring the CPU out of the sleep mode.

[3] Setting xModifiableIdleTime to 0 will prevent FreeRTOS entering a sleep mode, as you have already done it in your macro.  You can see how the configPRE_SLEEP_PROCESSING() macro and its parameter are used in the appropriate port.c file.

If the above does not work for whatever reason then you would have to implement your own vPortSuppressTicksAndSleep() - which is declared as a weak symbol to allow you to do that - you could then use of the architecture specific examples provided in the main FreeRTOS zip file download as a template.  You will find links to those here http://www.freertos.org/low-power-tickless-rtos.html


0 Kudos

2,248 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by henna on Thu Jun 11 16:46:58 MST 2015
My apologies.

My question is how to use or configure tick-less implementation of FreeRTOS to wake-up from deep sleep or deep power down mode using RTC alarm interrupt.

FYI, I have  Cortex-M default tick-less implementation working on my LPC4357 board with RTC alarm generating every 5 seconds.

Below is the scenario:
1) In active mode-Configure hardware setup, configure RTC and other processes.
2) Enable RTC to generate alarm every 5 seconds and enable interrupt.
3) Execute WFI instruction to goto deep sleep/ deep power down.
4) Wait for RTC alarm to wake up.
5) After wake up resume normal activity.

I hope this make sense.!!!

Now as you mentioned default tick-less implementation won't allow to go into deep sleep and deep power down and that's the reason I want to use SysTick in active mode and and RTC clock in deep sleep or deep-power down mode.

Can you tell that is this is the correct way of doing and how to implement tickless FreeRTOS to goto deep sleep using RTC.

Regards,
Heena
0 Kudos

2,248 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by www.FreeRTOS.org on Thu Jun 11 02:44:14 MST 2015
I'm not sure if your question is related to FreeRTOS, or related to using the RTC?

With regards to the tick-less mode - do you have the default Cortex-M tick-less implementation working yet?  That will not allow the deepest of sleeps, or the longest of sleeps, because it uses the SysTick clock, which is presumably why you are wanting to use the RTC.
0 Kudos