Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
飞不过沧海
rt-thread
提交
8a06b07f
R
rt-thread
项目概览
飞不过沧海
/
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,发现更多精彩内容 >>
提交
8a06b07f
编写于
8月 30, 2017
作者:
G
geniusgogo
提交者:
GitHub
8月 30, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update application.c
code style clean
上级
189c999f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
65 addition
and
62 deletion
+65
-62
bsp/samd21/applications/application.c
bsp/samd21/applications/application.c
+65
-62
未找到文件。
bsp/samd21/applications/application.c
浏览文件 @
8a06b07f
...
...
@@ -10,20 +10,20 @@
void
LED_Init
(
void
)
{
struct
port_config
config_port_pin
;
struct
port_config
config_port_pin
;
port_get_config_defaults
(
&
config_port_pin
);
config_port_pin
.
direction
=
PORT_PIN_DIR_INPUT
;
config_port_pin
.
input_pull
=
PORT_PIN_PULL_UP
;
port_pin_set_config
(
PIN_PA15
,
&
config_port_pin
);
port_get_config_defaults
(
&
config_port_pin
);
config_port_pin
.
direction
=
PORT_PIN_DIR_INPUT
;
config_port_pin
.
input_pull
=
PORT_PIN_PULL_UP
;
port_pin_set_config
(
PIN_PA15
,
&
config_port_pin
);
config_port_pin
.
direction
=
PORT_PIN_DIR_OUTPUT
;
port_pin_set_config
(
PIN_PB30
,
&
config_port_pin
);
config_port_pin
.
direction
=
PORT_PIN_DIR_OUTPUT
;
port_pin_set_config
(
PIN_PB30
,
&
config_port_pin
);
}
void
LED_ON
(
void
)
{
port_pin_set_output_level
(
PIN_PB30
,
false
);
port_pin_set_output_level
(
PIN_PB30
,
false
);
}
void
LED_OFF
(
void
)
...
...
@@ -36,106 +36,109 @@ void extint_detection_callback(void);
void
configure_extint_channel
(
void
)
{
//! [setup_1]
struct
extint_chan_conf
config_extint_chan
;
struct
extint_chan_conf
config_extint_chan
;
//! [setup_1]
//! [setup_2]
extint_chan_get_config_defaults
(
&
config_extint_chan
);
extint_chan_get_config_defaults
(
&
config_extint_chan
);
//! [setup_2]
//! [setup_3]
config_extint_chan
.
gpio_pin
=
PIN_PA15A_EIC_EXTINT15
;
config_extint_chan
.
gpio_pin_mux
=
MUX_PA15A_EIC_EXTINT15
;
config_extint_chan
.
gpio_pin_pull
=
EXTINT_PULL_UP
;
config_extint_chan
.
detection_criteria
=
EXTINT_DETECT_BOTH
;
config_extint_chan
.
gpio_pin
=
PIN_PA15A_EIC_EXTINT15
;
config_extint_chan
.
gpio_pin_mux
=
MUX_PA15A_EIC_EXTINT15
;
config_extint_chan
.
gpio_pin_pull
=
EXTINT_PULL_UP
;
config_extint_chan
.
detection_criteria
=
EXTINT_DETECT_BOTH
;
//! [setup_3]
//! [setup_4]
extint_chan_set_config
(
15
,
&
config_extint_chan
);
extint_chan_set_config
(
15
,
&
config_extint_chan
);
//! [setup_4]
}
void
configure_extint_callbacks
(
void
)
{
//! [setup_5]
extint_register_callback
(
extint_detection_callback
,
15
,
EXTINT_CALLBACK_TYPE_DETECT
);
extint_register_callback
(
extint_detection_callback
,
15
,
EXTINT_CALLBACK_TYPE_DETECT
);
//! [setup_5]
//! [setup_6]
extint_chan_enable_callback
(
15
,
EXTINT_CALLBACK_TYPE_DETECT
);
extint_chan_enable_callback
(
15
,
EXTINT_CALLBACK_TYPE_DETECT
);
//! [setup_6]
}
//! [setup_7]
void
extint_detection_callback
(
void
)
{
bool
pin_state
=
port_pin_get_input_level
(
PIN_PA15
);
port_pin_set_output_level
(
PIN_PB30
,
pin_state
);
bool
pin_state
=
port_pin_get_input_level
(
PIN_PA15
);
port_pin_set_output_level
(
PIN_PB30
,
pin_state
);
}
static
struct
rt_semaphore
_rx_sem
;
static
rt_err_t
_rx_ind
(
rt_device_t
dev
,
rt_size_t
size
)
{
return
rt_sem_release
(
&
_rx_sem
);
return
rt_sem_release
(
&
_rx_sem
);
}
void
rt_init_thread_entry
(
void
*
parameter
)
{
rt_thread_t
thread
;
rt_device_t
dev
;
rt_thread_t
thread
;
rt_device_t
dev
;
rt_kprintf
(
"SYSTEM running at %uhz
\n
"
,
SystemCoreClock
);
rt_kprintf
(
"SYSTEM running at %uhz
\n
"
,
SystemCoreClock
);
LED_Init
();
configure_extint_channel
();
configure_extint_callbacks
();
sleep_timer_init
();
#if defined(TEST_UART_RX)
sleep_timer_init
();
// sleep_timer_start(1500);
LED_Init
();
configure_extint_channel
();
configure_extint_callbacks
();
while
(
1
)
{
rt_kprintf
(
"init thread running tick:%u
\n
"
,
rt_tick_get
());
rt_thread_delay
(
2
*
RT_TICK_PER_SECOND
);
}
#if 0
dev = rt_device_find("uart3");
if (dev != RT_NULL)
{
rt_sem_init(&_rx_sem, "rxsem", 0, RT_IPC_FLAG_FIFO);
rt_device_set_rx_indicate(dev, _rx_ind);
rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX);
}
while
(
1
)
{
rt_kprintf
(
"init thread running tick:%u
\n
"
,
rt_tick_get
());
rt_thread_delay
(
2
*
RT_TICK_PER_SECOND
);
}
#else
dev
=
rt_device_find
(
"uart3"
);
if
(
dev
!=
RT_NULL
)
{
rt_sem_init
(
&
_rx_sem
,
"rxsem"
,
0
,
RT_IPC_FLAG_FIFO
);
rt_device_set_rx_indicate
(
dev
,
_rx_ind
);
rt_device_open
(
dev
,
RT_DEVICE_OFLAG_RDWR
|
RT_DEVICE_FLAG_INT_RX
);
}
while
(
1
)
{
rt_size_t r_size;
rt_uint8_t r_buf[1];
// rt_kprintf("SAMD2xJ18A hello thread\n");
// rt_thread_delay(RT_TICK_PER_SECOND
);
rt_sem_take(&_rx_sem, RT_WAITING_FOREVER);
while ((r_size = rt_device_read(dev, 0, r_buf, 1)) > 0)
{
rt_device_write(dev, 0, r_buf, r_size);
if (r_buf[0] == '\r')
{
r_buf[0] = '\n'
;
rt_device_write(dev, 0, r_buf, r_size);
}
}
}
rt_size_t
r_size
;
rt_uint8_t
r_buf
[
1
];
rt_sem_take
(
&
_rx_sem
,
RT_WAITING_FOREVER
);
while
((
r_size
=
rt_device_read
(
dev
,
0
,
r_buf
,
1
))
>
0
)
{
rt_device_write
(
dev
,
0
,
r_buf
,
r_size
);
if
(
r_buf
[
0
]
==
'\r'
)
{
r_buf
[
0
]
=
'\n'
;
rt_device_write
(
dev
,
0
,
r_buf
,
r_size
)
;
}
}
}
#endif
}
int
rt_application_init
(
void
)
{
rt_thread_t
tid
;
rt_thread_t
tid
;
tid
=
rt_thread_create
(
"init"
,
rt_init_thread_entry
,
RT_NULL
,
tid
=
rt_thread_create
(
"init"
,
rt_init_thread_entry
,
RT_NULL
,
512
,
RT_THREAD_PRIORITY_MAX
/
3
,
20
);
if
(
tid
!=
RT_NULL
)
rt_thread_startup
(
tid
);
if
(
tid
!=
RT_NULL
)
rt_thread_startup
(
tid
);
return
0
;
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录