Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
c5dd2feb
R
rt-thread
项目概览
BaiXuePrincess
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
c5dd2feb
编写于
5月 17, 2013
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #91 from aozima/pulls
Pulls
上级
7cc284d5
c77c69c4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
43 addition
and
41 deletion
+43
-41
components/drivers/rtc/alarm.c
components/drivers/rtc/alarm.c
+43
-41
未找到文件。
components/drivers/rtc/alarm.c
浏览文件 @
c5dd2feb
/*
* File : alarm.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 201
2
, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 201
3
, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
...
...
@@ -10,6 +10,7 @@
* Change Logs:
* Date Author Notes
* 2012-10-27 heyuanjie87 first version.
* 2013-05-17 aozima initial alarm event & mutex in system init.
*/
#include <rtthread.h>
...
...
@@ -21,7 +22,7 @@
#define RT_ALARM_STATE_START 0x01
#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
;
rt_inline
rt_uint32_t
alarm_mkdaysec
(
struct
tm
*
time
)
...
...
@@ -61,7 +62,7 @@ static rt_err_t alarm_set(struct rt_alarm *alarm)
ret
=
rt_device_control
(
device
,
RT_DEVICE_CTRL_RTC_GET_ALARM
,
&
wkalarm
);
if
(
ret
==
RT_EOK
)
{
/*
/*
some RTC device like RX8025,it's alarms precision is 1 minute.
in this case,low level RTC driver should set wkalarm->tm_sec to 0.
*/
...
...
@@ -79,7 +80,7 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now)
rt_uint32_t
sec_alarm
,
sec_now
;
rt_bool_t
wakeup
=
RT_FALSE
;
time_t
timestamp
;
sec_alarm
=
alarm_mkdaysec
(
&
alarm
->
wktime
);
sec_now
=
alarm_mkdaysec
(
now
);
...
...
@@ -97,7 +98,7 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now)
alarm
->
flag
&=
~
RT_ALARM_STATE_START
;
alarm_set
(
alarm
);
wakeup
=
RT_TRUE
;
}
}
}
break
;
case
RT_ALARM_DAILY
:
...
...
@@ -129,10 +130,10 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now)
case
RT_ALARM_YAERLY
:
{
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
)
wakeup
=
RT_TRUE
;
if
((
sec_now
-
sec_alarm
)
<=
RT_ALARM_DELAY
)
wakeup
=
RT_TRUE
;
}
}
break
;
...
...
@@ -142,7 +143,7 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now)
{
timestamp
=
time
(
RT_NULL
);
alarm
->
callback
(
alarm
,
timestamp
);
}
}
}
}
...
...
@@ -253,7 +254,7 @@ static rt_bool_t is_valid_date(struct tm *date)
}
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
);
}
...
...
@@ -351,7 +352,7 @@ static rt_err_t alarm_setup(rt_alarm_t alarm, struct tm *wktime)
goto
_exit
;
}
}
if
((
setup
->
tm_hour
==
23
)
&&
(
setup
->
tm_min
==
59
)
&&
(
setup
->
tm_sec
==
59
))
{
/*
...
...
@@ -363,7 +364,7 @@ static rt_err_t alarm_setup(rt_alarm_t alarm, struct tm *wktime)
/* set initialized state */
alarm
->
flag
|=
RT_ALARM_STATE_INITED
;
ret
=
RT_EOK
;
_exit:
return
(
ret
);
...
...
@@ -372,7 +373,7 @@ _exit:
/** \brief send a rtc alarm event
*
* \param dev pointer to RTC device(currently unused,you can ignore it)
* \param event RTC event(currently unused)
* \param event RTC event(currently unused)
* \return none
*/
void
rt_alarm_update
(
rt_device_t
dev
,
rt_uint32_t
event
)
...
...
@@ -391,30 +392,30 @@ rt_err_t rt_alarm_control(rt_alarm_t alarm, rt_uint8_t cmd, void *arg)
rt_err_t
ret
=
RT_ERROR
;
RT_ASSERT
(
alarm
!=
RT_NULL
);
rt_mutex_take
(
&
_container
.
mutex
,
RT_WAITING_FOREVER
);
switch
(
cmd
)
{
case
RT_ALARM_CTRL_MODIFY
:
{
struct
rt_alarm_setup
*
setup
;
RT_ASSERT
(
arg
!=
RT_NULL
);
RT_ASSERT
(
arg
!=
RT_NULL
);
setup
=
arg
;
rt_alarm_stop
(
alarm
);
alarm
->
flag
=
setup
->
flag
&
0xFF00
;
alarm
->
wktime
=
setup
->
wktime
;
ret
=
alarm_setup
(
alarm
,
&
alarm
->
wktime
);
ret
=
alarm_setup
(
alarm
,
&
alarm
->
wktime
);
}
break
;
break
;
}
rt_mutex_release
(
&
_container
.
mutex
);
rt_mutex_release
(
&
_container
.
mutex
);
return
(
ret
);
}
/** \brief start a alarm
/** \brief start a
n
alarm
*
* \param alarm pointer to alarm
* \return RT_EOK
...
...
@@ -425,7 +426,7 @@ rt_err_t rt_alarm_start(rt_alarm_t alarm)
rt_err_t
ret
=
RT_ERROR
;
time_t
timestamp
;
struct
tm
now
;
if
(
alarm
==
RT_NULL
)
return
(
ret
);
rt_mutex_take
(
&
_container
.
mutex
,
RT_WAITING_FOREVER
);
...
...
@@ -433,12 +434,12 @@ rt_err_t rt_alarm_start(rt_alarm_t alarm)
{
if
(
alarm_setup
(
alarm
,
&
alarm
->
wktime
)
!=
RT_EOK
)
goto
_exit
;
}
}
if
((
alarm
->
flag
&
0x01
)
==
RT_ALARM_STATE_STOP
)
{
timestamp
=
time
(
RT_NULL
);
localtime_r
(
&
timestamp
,
&
now
);
alarm
->
flag
|=
RT_ALARM_STATE_START
;
/* set alarm */
if
(
_container
.
current
==
RT_NULL
)
...
...
@@ -482,7 +483,7 @@ _exit:
return
(
ret
);
}
/** \brief stop a alarm
/** \brief stop a
n
alarm
*
* \param alarm pointer to alarm
* \return RT_EOK
...
...
@@ -490,7 +491,7 @@ _exit:
rt_err_t
rt_alarm_stop
(
rt_alarm_t
alarm
)
{
rt_err_t
ret
=
RT_ERROR
;
if
(
alarm
==
RT_NULL
)
return
(
ret
);
rt_mutex_take
(
&
_container
.
mutex
,
RT_WAITING_FOREVER
);
...
...
@@ -498,12 +499,12 @@ rt_err_t rt_alarm_stop(rt_alarm_t alarm)
goto
_exit
;
/* stop alarm */
alarm
->
flag
&=
~
RT_ALARM_STATE_START
;
if
(
_container
.
current
==
alarm
)
{
ret
=
alarm_set
(
alarm
);
_container
.
current
=
RT_NULL
;
}
}
if
(
ret
==
RT_EOK
)
alarm_update
(
0
);
...
...
@@ -514,7 +515,7 @@ _exit:
return
(
ret
);
}
/** \brief delete a alarm
/** \brief delete a
n
alarm
*
* \param alarm pointer to alarm
* \return RT_EOK
...
...
@@ -522,10 +523,10 @@ _exit:
rt_err_t
rt_alarm_delete
(
rt_alarm_t
alarm
)
{
rt_err_t
ret
=
RT_ERROR
;
if
(
alarm
==
RT_NULL
)
return
(
ret
);
rt_mutex_take
(
&
_container
.
mutex
,
RT_WAITING_FOREVER
);
return
(
ret
);
rt_mutex_take
(
&
_container
.
mutex
,
RT_WAITING_FOREVER
);
/* stop the alarm */
alarm
->
flag
&=
~
RT_ALARM_STATE_START
;
if
(
_container
.
current
==
alarm
)
...
...
@@ -533,17 +534,17 @@ rt_err_t rt_alarm_delete(rt_alarm_t alarm)
ret
=
alarm_set
(
alarm
);
_container
.
current
=
RT_NULL
;
/* set new alarm if necessary */
alarm_update
(
0
);
alarm_update
(
0
);
}
rt_list_remove
(
&
alarm
->
list
);
rt_free
(
alarm
);
rt_mutex_release
(
&
_container
.
mutex
);
return
(
ret
);
}
/** \brief create a alarm
/** \brief create a
n
alarm
*
* \param flag set alarm mode e.g: RT_ALARM_DAILY
* \param setup pointer to setup infomation
...
...
@@ -551,18 +552,18 @@ rt_err_t rt_alarm_delete(rt_alarm_t alarm)
rt_alarm_t
rt_alarm_create
(
rt_alarm_callback_t
callback
,
struct
rt_alarm_setup
*
setup
)
{
struct
rt_alarm
*
alarm
;
if
(
setup
==
RT_NULL
)
return
(
RT_NULL
);
alarm
=
rt_malloc
(
sizeof
(
struct
rt_alarm
));
if
(
alarm
==
RT_NULL
)
return
(
RT_NULL
);
rt_list_init
(
&
alarm
->
list
);
alarm
->
wktime
=
setup
->
wktime
;
alarm
->
flag
=
setup
->
flag
&
0xFF00
;
alarm
->
callback
=
callback
;
rt_mutex_take
(
&
_container
.
mutex
,
RT_WAITING_FOREVER
);
rt_mutex_take
(
&
_container
.
mutex
,
RT_WAITING_FOREVER
);
rt_list_insert_after
(
&
_container
.
head
,
&
alarm
->
list
);
rt_mutex_release
(
&
_container
.
mutex
);
...
...
@@ -576,9 +577,6 @@ static void rt_alarmsvc_thread_init(void *param)
{
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
;
while
(
1
)
...
...
@@ -587,7 +585,7 @@ static void rt_alarmsvc_thread_init(void *param)
RT_EVENT_FLAG_OR
|
RT_EVENT_FLAG_CLEAR
,
RT_WAITING_FOREVER
,
&
recv
)
==
RT_EOK
)
{
alarm_update
(
recv
);
alarm_update
(
recv
);
}
}
}
...
...
@@ -602,6 +600,10 @@ void rt_alarm_system_init(void)
{
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"
,
rt_alarmsvc_thread_init
,
RT_NULL
,
512
,
8
,
1
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录