Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
AdRainty
rt-thread
提交
7e5034c6
R
rt-thread
项目概览
AdRainty
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7e5034c6
编写于
2月 14, 2021
作者:
L
LeeChunHei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change to use non blocking api and use semaphore to sync the transfer
上级
a4dd106d
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
31 addition
and
1 deletion
+31
-1
bsp/imxrt/libraries/drivers/drv_spi.c
bsp/imxrt/libraries/drivers/drv_spi.c
+31
-1
未找到文件。
bsp/imxrt/libraries/drivers/drv_spi.c
浏览文件 @
7e5034c6
...
@@ -64,6 +64,8 @@ struct imxrt_spi
...
@@ -64,6 +64,8 @@ struct imxrt_spi
char
*
bus_name
;
char
*
bus_name
;
LPSPI_Type
*
base
;
LPSPI_Type
*
base
;
struct
rt_spi_bus
spi_bus
;
struct
rt_spi_bus
spi_bus
;
rt_sem_t
xfer_sem
;
lpspi_master_handle_t
spi_normal
;
struct
dma_config
*
dma
;
struct
dma_config
*
dma
;
rt_uint8_t
dma_flag
;
rt_uint8_t
dma_flag
;
};
};
...
@@ -159,9 +161,18 @@ static void spi_get_dma_config(void)
...
@@ -159,9 +161,18 @@ static void spi_get_dma_config(void)
#endif
#endif
}
}
void
normal_xfer_callback
(
LPSPI_Type
*
base
,
lpspi_master_handle_t
*
handle
,
status_t
status
,
void
*
userData
)
{
/* xfer complete callback */
struct
imxrt_spi
*
spi
=
(
struct
imxrt_spi
*
)
userData
;
rt_sem_release
(
spi
->
xfer_sem
);
}
void
edma_xfer_callback
(
LPSPI_Type
*
base
,
lpspi_master_edma_handle_t
*
handle
,
status_t
status
,
void
*
userData
)
void
edma_xfer_callback
(
LPSPI_Type
*
base
,
lpspi_master_edma_handle_t
*
handle
,
status_t
status
,
void
*
userData
)
{
{
/* xfer complete callback */
/* xfer complete callback */
struct
imxrt_spi
*
spi
=
(
struct
imxrt_spi
*
)
userData
;
rt_sem_release
(
spi
->
xfer_sem
);
}
}
rt_err_t
rt_hw_spi_device_attach
(
const
char
*
bus_name
,
const
char
*
device_name
,
rt_uint32_t
pin
)
rt_err_t
rt_hw_spi_device_attach
(
const
char
*
bus_name
,
const
char
*
device_name
,
rt_uint32_t
pin
)
...
@@ -217,6 +228,17 @@ static uint32_t imxrt_get_lpspi_freq(void)
...
@@ -217,6 +228,17 @@ static uint32_t imxrt_get_lpspi_freq(void)
return
freq
;
return
freq
;
}
}
static
void
lpspi_normal_config
(
struct
imxrt_spi
*
spi
)
{
RT_ASSERT
(
spi
!=
RT_NULL
);
LPSPI_MasterTransferCreateHandle
(
spi
->
base
,
&
spi
->
spi_normal
,
normal_xfer_callback
,
spi
);
LOG_D
(
LOG_TAG
" %s normal config done
\n
"
,
spi
->
bus_name
);
}
static
void
lpspi_dma_config
(
struct
imxrt_spi
*
spi
)
static
void
lpspi_dma_config
(
struct
imxrt_spi
*
spi
)
{
{
RT_ASSERT
(
spi
!=
RT_NULL
);
RT_ASSERT
(
spi
!=
RT_NULL
);
...
@@ -325,12 +347,13 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
...
@@ -325,12 +347,13 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
if
(
RT_FALSE
==
spi
->
dma_flag
)
if
(
RT_FALSE
==
spi
->
dma_flag
)
{
{
status
=
LPSPI_MasterTransfer
Blocking
(
spi
->
base
,
&
transfer
);
status
=
LPSPI_MasterTransfer
NonBlocking
(
spi
->
base
,
&
spi
->
spi_normal
,
&
transfer
);
}
}
else
else
{
{
status
=
LPSPI_MasterTransferEDMA
(
spi
->
base
,
&
spi
->
dma
->
spi_edma
,
&
transfer
);
status
=
LPSPI_MasterTransferEDMA
(
spi
->
base
,
&
spi
->
dma
->
spi_edma
,
&
transfer
);
}
}
rt_sem_take
(
spi
->
xfer_sem
,
RT_WAITING_FOREVER
);
if
(
message
->
cs_release
)
if
(
message
->
cs_release
)
{
{
...
@@ -369,6 +392,13 @@ int rt_hw_spi_bus_init(void)
...
@@ -369,6 +392,13 @@ int rt_hw_spi_bus_init(void)
{
{
lpspi_dma_config
(
&
lpspis
[
i
]);
lpspi_dma_config
(
&
lpspis
[
i
]);
}
}
else
{
lpspi_normal_config
(
&
lpspis
[
i
]);
}
char
sem_name
[
RT_NAME_MAX
];
rt_sprintf
(
sem_name
,
"%s_s"
,
lpspis
[
i
].
bus_name
);
lpspis
[
i
].
xfer_sem
=
rt_sem_create
(
sem_name
,
0
,
RT_IPC_FLAG_PRIO
);
}
}
return
ret
;
return
ret
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录