commit
c5dd2feb07
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* File : alarm.c
|
* File : alarm.c
|
||||||
* This file is part of RT-Thread RTOS
|
* This file is part of RT-Thread RTOS
|
||||||
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
|
* COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* The license and distribution terms for this file may be
|
* The license and distribution terms for this file may be
|
||||||
* found in the file LICENSE in this distribution or at
|
* found in the file LICENSE in this distribution or at
|
||||||
|
@ -10,6 +10,7 @@
|
||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2012-10-27 heyuanjie87 first version.
|
* 2012-10-27 heyuanjie87 first version.
|
||||||
|
* 2013-05-17 aozima initial alarm event & mutex in system init.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
@ -21,7 +22,7 @@
|
||||||
#define RT_ALARM_STATE_START 0x01
|
#define RT_ALARM_STATE_START 0x01
|
||||||
#define RT_ALARM_STATE_STOP 0x00
|
#define RT_ALARM_STATE_STOP 0x00
|
||||||
|
|
||||||
#if(defined(RT_USING_RTC) && defined(RT_USING_ALARM))
|
#if (defined(RT_USING_RTC) && defined(RT_USING_ALARM))
|
||||||
static struct rt_alarm_container _container;
|
static struct rt_alarm_container _container;
|
||||||
|
|
||||||
rt_inline rt_uint32_t alarm_mkdaysec(struct tm *time)
|
rt_inline rt_uint32_t alarm_mkdaysec(struct tm *time)
|
||||||
|
@ -129,9 +130,9 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now)
|
||||||
case RT_ALARM_YAERLY:
|
case RT_ALARM_YAERLY:
|
||||||
{
|
{
|
||||||
if ((alarm->wktime.tm_mday == now->tm_mday) && \
|
if ((alarm->wktime.tm_mday == now->tm_mday) && \
|
||||||
(alarm->wktime.tm_mon == now->tm_mon))
|
(alarm->wktime.tm_mon == now->tm_mon))
|
||||||
{
|
{
|
||||||
if ((sec_now - sec_alarm) <= RT_ALARM_DELAY)
|
if ((sec_now - sec_alarm) <= RT_ALARM_DELAY)
|
||||||
wakeup = RT_TRUE;
|
wakeup = RT_TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,7 +254,7 @@ static rt_bool_t is_valid_date(struct tm *date)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((date->tm_mday < 1) || \
|
if ((date->tm_mday < 1) || \
|
||||||
(date->tm_mday > days_of_year_month(date->tm_year, date->tm_mon)))
|
(date->tm_mday > days_of_year_month(date->tm_year, date->tm_mon)))
|
||||||
{
|
{
|
||||||
return (RT_FALSE);
|
return (RT_FALSE);
|
||||||
}
|
}
|
||||||
|
@ -414,7 +415,7 @@ rt_err_t rt_alarm_control(rt_alarm_t alarm, rt_uint8_t cmd, void *arg)
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief start a alarm
|
/** \brief start an alarm
|
||||||
*
|
*
|
||||||
* \param alarm pointer to alarm
|
* \param alarm pointer to alarm
|
||||||
* \return RT_EOK
|
* \return RT_EOK
|
||||||
|
@ -482,7 +483,7 @@ _exit:
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief stop a alarm
|
/** \brief stop an alarm
|
||||||
*
|
*
|
||||||
* \param alarm pointer to alarm
|
* \param alarm pointer to alarm
|
||||||
* \return RT_EOK
|
* \return RT_EOK
|
||||||
|
@ -514,7 +515,7 @@ _exit:
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief delete a alarm
|
/** \brief delete an alarm
|
||||||
*
|
*
|
||||||
* \param alarm pointer to alarm
|
* \param alarm pointer to alarm
|
||||||
* \return RT_EOK
|
* \return RT_EOK
|
||||||
|
@ -543,7 +544,7 @@ rt_err_t rt_alarm_delete(rt_alarm_t alarm)
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief create a alarm
|
/** \brief create an alarm
|
||||||
*
|
*
|
||||||
* \param flag set alarm mode e.g: RT_ALARM_DAILY
|
* \param flag set alarm mode e.g: RT_ALARM_DAILY
|
||||||
* \param setup pointer to setup infomation
|
* \param setup pointer to setup infomation
|
||||||
|
@ -576,9 +577,6 @@ static void rt_alarmsvc_thread_init(void *param)
|
||||||
{
|
{
|
||||||
rt_uint32_t recv;
|
rt_uint32_t recv;
|
||||||
|
|
||||||
rt_list_init(&_container.head);
|
|
||||||
rt_event_init(&_container.event, "alarmsvc", RT_IPC_FLAG_FIFO);
|
|
||||||
rt_mutex_init(&_container.mutex, "alarmsvc", RT_IPC_FLAG_FIFO);
|
|
||||||
_container.current = RT_NULL;
|
_container.current = RT_NULL;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
|
@ -602,6 +600,10 @@ void rt_alarm_system_init(void)
|
||||||
{
|
{
|
||||||
rt_thread_t tid;
|
rt_thread_t tid;
|
||||||
|
|
||||||
|
rt_list_init(&_container.head);
|
||||||
|
rt_event_init(&_container.event, "alarmsvc", RT_IPC_FLAG_FIFO);
|
||||||
|
rt_mutex_init(&_container.mutex, "alarmsvc", RT_IPC_FLAG_FIFO);
|
||||||
|
|
||||||
tid = rt_thread_create("alarmsvc",
|
tid = rt_thread_create("alarmsvc",
|
||||||
rt_alarmsvc_thread_init, RT_NULL,
|
rt_alarmsvc_thread_init, RT_NULL,
|
||||||
512, 8, 1);
|
512, 8, 1);
|
||||||
|
|
Loading…
Reference in New Issue