#include <rtl.h>
void os_resume (
U32 sleep_time ); /* Number of ticks the system was in sleep mode. */
/* After Wake-up */
sleep = (tc - LPC_WWDT->TV) / 250;
}
os_resume(sleep);
#include <rtl.h>
U32 os_suspend (void);
#include <rtl.h>
__task void os_idle_demon (void) {
uint32_t sleep;
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; /* Configure Cortex-M3 for deep sleep */
PWR->CR &= ~PWR_CR_PDDS; /* Enter Stop mode when in deepsleep */
PWR->CR |= PWR_CR_LPDS; /* Voltage regulator in low-power */
/* Enable LSI clock and wait until ready */
RCC->CSR |= RCC_CSR_LSION;
while ((RCC->CSR & RCC_CSR_LSIRDY) == 0);
/* Enable power interface clock */
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
/* Disable backup domain write protection */
PWR->CR |= PWR_CR_DBP;
/* Select LSI as clock source for RTC and enable RTC */
RCC->BDCR &= ~RCC_BDCR_RTCSEL;
RCC->BDCR |= RCC_BDCR_RTCSEL_1;
RCC->BDCR |= RCC_BDCR_RTCEN;
/* Disable the write protection for RTC registers */
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
/* Configure RTC auto-wakeup mode */
RTC->ISR &= ~RTC_ISR_WUTF; /* Clear wakeup timer flag */
RTC->CR &= ~RTC_CR_WUCKSEL; /* Set RTC clock to 2kHz */
RTC->CR |= RTC_CR_WUTIE; /* Enable RTC wakeup timer interrupt */
/* Configure EXTI line 22 for wakeup on rising edge */
EXTI->EMR |= (1 << 22); /* Event request is not masked */
EXTI->RTSR |= (1 << 22); /* Rising trigger enabled */
NVIC_EnableIRQ (RTC_WKUP_IRQn); /* Enable RTC WakeUp IRQ */
for (;;) {
/* HERE: include optional user code to be executed when no task runs. */
sleep = os_suspend (); /* OS Suspend */
if (sleep) {
RTC->ISR &= ~RTC_ISR_WUTF; /* Clear timer wakeup flag */
RTC->CR &= ~RTC_CR_WUTE; /* Disable wakeup timer */
while ((RTC->ISR & RTC_ISR_WUTWF) == 0);
/* RTC clock is @2kHz, set wakeup time for OS_TICK >= 1ms */
RTC->WUTR = (sleep * (OS_TICK / 1000) * 2);
RTC->CR |= RTC_CR_WUTE; /* Enable wakeup timer */
__WFE (); /* Enter STOP mode */
/* After Wake-up */
if ((RTC->ISR & RTC_ISR_WUTF) == 0) {
sleep = 0; /* We didn‘t enter Stop mode */
}
}
os_resume (sleep); /* OS Resume */
}
}
#include <rtl.h>
void tsk_lock (void);
#include <rtl.h>
void protect_critical_op () {
tsk_lock ();
do_critical_op ();
tsk_unlock ();
}
#include <rtl.h>
void tsk_unlock (void);
#include <rtl.h>
void protect_critical_op () {
tsk_lock ();
do_critical_op ();
tsk_unlock ();
}
原文:http://www.cnblogs.com/dengxiaojun/p/fee1ab410029b002b7dd4979bf451640.html