Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46254178
rt-thread
提交
f8012b90
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,发现更多精彩内容 >>
提交
f8012b90
编写于
9月 06, 2015
作者:
H
heyuanjie87
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[lpc408x]添加定时器驱动
上级
8f9bda57
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
161 addition
and
0 deletion
+161
-0
bsp/lpc408x/drivers/drv_hwtimer.c
bsp/lpc408x/drivers/drv_hwtimer.c
+153
-0
bsp/lpc408x/drivers/drv_hwtimer.h
bsp/lpc408x/drivers/drv_hwtimer.h
+8
-0
未找到文件。
bsp/lpc408x/drivers/drv_hwtimer.c
0 → 100644
浏览文件 @
f8012b90
/*
* File : drv_hwtimer.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2015, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2015-09-02 heyuanjie87 the first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "lpc_timer.h"
#include "lpc_clkpwr.h"
#include "drv_hwtimer.h"
#ifdef RT_USING_HWTIMER
static
void
NVIC_Configuration
(
void
)
{
NVIC_EnableIRQ
(
TIMER0_IRQn
);
}
static
void
timer_init
(
rt_hwtimer_t
*
timer
,
rt_uint32_t
state
)
{
LPC_TIM_TypeDef
*
tim
;
TIM_TIMERCFG_Type
cfg
;
tim
=
(
LPC_TIM_TypeDef
*
)
timer
->
parent
.
user_data
;
TIM_DeInit
(
tim
);
if
(
state
==
1
)
{
NVIC_Configuration
();
cfg
.
PrescaleOption
=
TIM_PRESCALE_TICKVAL
;
cfg
.
PrescaleValue
=
0xFFFF
;
TIM_Init
(
tim
,
TIM_TIMER_MODE
,
&
cfg
);
}
}
static
rt_err_t
timer_start
(
rt_hwtimer_t
*
timer
,
rt_uint32_t
t
,
rt_hwtimer_mode_t
opmode
)
{
LPC_TIM_TypeDef
*
tim
;
TIM_MATCHCFG_Type
match
;
tim
=
(
LPC_TIM_TypeDef
*
)
timer
->
parent
.
user_data
;
match
.
MatchChannel
=
0
;
match
.
IntOnMatch
=
ENABLE
;
match
.
ResetOnMatch
=
ENABLE
;
match
.
StopOnMatch
=
(
opmode
==
HWTIMER_MODE_ONESHOT
)
?
ENABLE
:
DISABLE
;
match
.
ExtMatchOutputType
=
0
;
match
.
MatchValue
=
t
;
TIM_ConfigMatch
(
tim
,
&
match
);
TIM_Cmd
(
tim
,
ENABLE
);
return
RT_EOK
;
}
static
void
timer_stop
(
rt_hwtimer_t
*
timer
)
{
LPC_TIM_TypeDef
*
tim
;
tim
=
(
LPC_TIM_TypeDef
*
)
timer
->
parent
.
user_data
;
TIM_Cmd
(
tim
,
DISABLE
);
}
static
rt_err_t
timer_ctrl
(
rt_hwtimer_t
*
timer
,
rt_uint32_t
cmd
,
void
*
arg
)
{
LPC_TIM_TypeDef
*
tim
;
rt_err_t
err
=
RT_EOK
;
tim
=
(
LPC_TIM_TypeDef
*
)
timer
->
parent
.
user_data
;
switch
(
cmd
)
{
case
HWTIMER_CTRL_FREQ_SET
:
{
uint32_t
clk
;
uint32_t
pre
;
clk
=
CLKPWR_GetCLK
(
CLKPWR_CLKTYPE_PER
);
pre
=
clk
/
*
((
uint32_t
*
)
arg
)
-
1
;
tim
->
PR
=
pre
;
}
break
;
default:
{
err
=
-
RT_ENOSYS
;
}
break
;
}
return
err
;
}
static
rt_uint32_t
timer_counter_get
(
rt_hwtimer_t
*
timer
)
{
LPC_TIM_TypeDef
*
tim
;
tim
=
(
LPC_TIM_TypeDef
*
)
timer
->
parent
.
user_data
;
return
tim
->
TC
;
}
static
const
struct
rt_hwtimer_info
_info
=
{
1000000
,
/* the maximum count frequency can be set */
2000
,
/* the minimum count frequency can be set */
0xFFFFFF
,
/* the maximum counter value */
HWTIMER_CNTMODE_UP
,
/* Increment or Decreasing count mode */
};
static
const
struct
rt_hwtimer_ops
_ops
=
{
timer_init
,
timer_start
,
timer_stop
,
timer_counter_get
,
timer_ctrl
,
};
static
rt_hwtimer_t
_timer0
;
int
lpc_hwtimer_init
(
void
)
{
_timer0
.
info
=
&
_info
;
_timer0
.
ops
=
&
_ops
;
rt_device_hwtimer_register
(
&
_timer0
,
"timer0"
,
LPC_TIM0
);
return
0
;
}
void
TIMER0_IRQHandler
(
void
)
{
if
(
TIM_GetIntStatus
(
LPC_TIM0
,
TIM_MR0_INT
)
!=
RESET
)
{
TIM_ClearIntPending
(
LPC_TIM0
,
TIM_MR0_INT
);
rt_device_hwtimer_isr
(
&
_timer0
);
}
}
INIT_BOARD_EXPORT
(
lpc_hwtimer_init
);
#endif
bsp/lpc408x/drivers/drv_hwtimer.h
0 → 100644
浏览文件 @
f8012b90
#ifndef __DRV_HWTIMER_H__
#define __DRV_HWTIMER_H__
int
stm32_hwtimer_init
(
void
);
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录