Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46254178
rt-thread
提交
7ba7b996
R
rt-thread
项目概览
weixin_46254178
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
7ba7b996
编写于
6月 28, 2020
作者:
B
Bernard Xiong
提交者:
GitHub
6月 28, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3717 from imgtec/bsp-ls2k/rtc-v2
bsp: ls2k: internal rtc driver
上级
08048bbc
e58c7bb2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
179 addition
and
0 deletion
+179
-0
bsp/ls2kdev/drivers/drv_rtc.c
bsp/ls2kdev/drivers/drv_rtc.c
+178
-0
bsp/ls2kdev/drivers/ls2k1000.h
bsp/ls2kdev/drivers/ls2k1000.h
+1
-0
未找到文件。
bsp/ls2kdev/drivers/drv_rtc.c
0 → 100644
浏览文件 @
7ba7b996
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2020, Du Huanpeng <548708880@qq.com>
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-01-30 armink the first version
* 2020-06-23 Du Huanpeng based on components/drivers/rtc/soft_rtc.c
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <rtthread.h>
#include "ls2k1000.h"
struct
loongson_rtc
{
rt_uint32_t
sys_toytrim
;
rt_uint32_t
sys_toywrite0
;
rt_uint32_t
sys_toywrite1
;
rt_uint32_t
sys_toyread0
;
rt_uint32_t
sys_toyread1
;
rt_uint32_t
sys_toymatch0
;
rt_uint32_t
sys_toymatch1
;
rt_uint32_t
sys_toymatch2
;
rt_uint32_t
sys_rtcctrl
;
rt_uint32_t
__pad4
[
3
];
rt_uint32_t
__pad5
[
4
];
rt_uint32_t
sys_rtctrim
;
rt_uint32_t
sys_rtcwrite0
;
rt_uint32_t
sys_rtcread0
;
rt_uint32_t
sys_rtcmatch0
;
rt_uint32_t
sys_rtcmatch1
;
rt_uint32_t
sys_rtcmatch2
;
};
/* bit field helpers. */
#define __M(n) (~(~0<<(n)))
#define __RBF(number, n) ((number)&__M(n))
#define __BF(number, n, m) __RBF((number>>m), (n-m+1))
#define BF(number, n, m) (m<n ? __BF(number, n, m) : __BF(number, m, n))
struct
rtctime
{
rt_uint32_t
sys_toyread0
;
rt_uint32_t
sys_toyread1
;
rt_uint32_t
sys_rtcread0
;
};
typedef
struct
rtctime
rtctime_t
;
struct
tm
*
localrtctime
(
const
rtctime_t
*
rtctp
)
{
static
struct
tm
time
;
int
msec
;
msec
=
BF
(
rtctp
->
sys_toyread0
,
3
,
0
);
msec
*=
100
;
time
.
tm_sec
=
BF
(
rtctp
->
sys_toyread0
,
9
,
4
);
time
.
tm_min
=
BF
(
rtctp
->
sys_toyread0
,
15
,
10
);
time
.
tm_hour
=
BF
(
rtctp
->
sys_toyread0
,
20
,
16
);
time
.
tm_mday
=
BF
(
rtctp
->
sys_toyread0
,
21
,
25
);
time
.
tm_mon
=
BF
(
rtctp
->
sys_toyread0
,
26
,
31
);
/* struct tm has three more members:
time.tm_isdst
time.tm_wday
time.tm_yday
*/
time
.
tm_mon
-=
1
;
time
.
tm_year
=
rtctp
->
sys_toyread1
;
return
&
time
;
}
rtctime_t
mkrtctime
(
struct
tm
*
tm
)
{
rtctime_t
rtctm
;
struct
tm
tmptime
;
rtctm
.
sys_toyread0
<<=
31
-
26
+
1
;
rtctm
.
sys_toyread0
|=
tm
->
tm_mon
+
1
;
rtctm
.
sys_toyread0
<<=
25
-
21
+
1
;
rtctm
.
sys_toyread0
|=
tm
->
tm_mday
;
rtctm
.
sys_toyread0
<<=
20
-
16
+
1
;
rtctm
.
sys_toyread0
|=
tm
->
tm_hour
;
rtctm
.
sys_toyread0
<<=
15
-
10
+
1
;
rtctm
.
sys_toyread0
|=
tm
->
tm_min
;
rtctm
.
sys_toyread0
<<=
9
-
4
+
1
;
rtctm
.
sys_toyread0
|=
tm
->
tm_sec
;
/* Fixme: 0.1 second */
rtctm
.
sys_toyread0
<<=
3
-
0
+
1
;
rtctm
.
sys_toyread0
|=
0
;
rtctm
.
sys_toyread1
=
tm
->
tm_year
;
tmptime
=
*
localrtctime
(
&
rtctm
);
return
rtctm
;
}
static
rt_err_t
rt_rtc_open
(
rt_device_t
dev
,
rt_uint16_t
oflag
)
{
return
RT_EOK
;
}
static
rt_size_t
rt_rtc_read
(
rt_device_t
dev
,
rt_off_t
pos
,
void
*
buffer
,
rt_size_t
size
)
{
return
0
;
}
static
rt_err_t
rt_rtc_ioctl
(
rt_device_t
dev
,
int
cmd
,
void
*
args
)
{
rt_err_t
err
=
RT_ENOSYS
;
static
int
count
=
0
;
struct
loongson_rtc
*
hw_rtc
;
rtctime_t
rtctm
;
struct
tm
time
;
struct
tm
tmptime
;
time_t
*
t
;
hw_rtc
=
dev
->
user_data
;
t
=
(
time_t
*
)
args
;
time
=
*
localtime
(
t
);
rtctm
.
sys_toyread0
=
hw_rtc
->
sys_toyread0
;
rtctm
.
sys_toyread1
=
hw_rtc
->
sys_toyread1
;
rtctm
.
sys_rtcread0
=
hw_rtc
->
sys_rtcread0
;
tmptime
=
*
localrtctime
(
&
rtctm
);
switch
(
cmd
)
{
case
RT_DEVICE_CTRL_RTC_GET_TIME
:
*
t
=
mktime
(
&
tmptime
);
break
;
case
RT_DEVICE_CTRL_RTC_SET_TIME
:
tmptime
.
tm_hour
=
time
.
tm_hour
;
tmptime
.
tm_min
=
time
.
tm_min
;
tmptime
.
tm_sec
=
time
.
tm_sec
;
tmptime
.
tm_year
=
time
.
tm_year
;
tmptime
.
tm_mon
=
time
.
tm_mon
;
tmptime
.
tm_mday
=
time
.
tm_mday
;
rtctm
=
mkrtctime
(
&
tmptime
);
/* write to hw RTC */
hw_rtc
->
sys_toywrite0
=
rtctm
.
sys_toyread0
;
hw_rtc
->
sys_toywrite1
=
rtctm
.
sys_toyread1
;
break
;
case
RT_DEVICE_CTRL_RTC_GET_ALARM
:
break
;
case
RT_DEVICE_CTRL_RTC_SET_ALARM
:
break
;
default:
break
;
}
return
RT_EOK
;
}
int
rt_hw_rtc_init
(
void
)
{
static
struct
rt_device
rtc
=
{
.
type
=
RT_Device_Class_RTC
,
.
init
=
RT_NULL
,
.
open
=
rt_rtc_open
,
.
close
=
RT_NULL
,
.
read
=
rt_rtc_read
,
.
write
=
RT_NULL
,
.
control
=
rt_rtc_ioctl
,
.
user_data
=
(
void
*
)
RTC_BASE
,
};
rt_device_register
(
&
rtc
,
"rtc"
,
RT_DEVICE_FLAG_RDWR
);
}
INIT_DEVICE_EXPORT
(
rt_hw_rtc_init
);
bsp/ls2kdev/drivers/ls2k1000.h
浏览文件 @
7ba7b996
...
...
@@ -20,6 +20,7 @@
#define GPIO_BASE 0xFFFFFFFFBFE10500
#define PLL_SYS_BASE 0xFFFFFFFFBFE10480
#define RTC_BASE 0xFFFFFFFFBFE07820
void
rt_hw_timer_handler
(
void
);
void
rt_hw_uart_init
(
void
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录