Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
ea48042f
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看板
未验证
提交
ea48042f
编写于
8月 16, 2018
作者:
B
Bernard Xiong
提交者:
GitHub
8月 16, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1722 from zhaojuntao/sfud
[components/drivers/spi] 增加 sfud flash 设备查找接口
上级
d06f9ac9
651149fc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
45 addition
and
4 deletion
+45
-4
components/drivers/include/drivers/spi.h
components/drivers/include/drivers/spi.h
+3
-2
components/drivers/spi/spi_flash_sfud.c
components/drivers/spi/spi_flash_sfud.c
+32
-2
components/drivers/spi/spi_flash_sfud.h
components/drivers/spi/spi_flash_sfud.h
+10
-0
未找到文件。
components/drivers/include/drivers/spi.h
浏览文件 @
ea48042f
...
...
@@ -36,8 +36,8 @@ extern "C"{
#define RT_SPI_CPOL (1<<1)
/* bit[1]:CPOL, clock polarity */
/**
* At CPOL=0 the base value of the clock is zero
* - For CPHA=0, data are captured on the clock's rising edge (low
hi
gh transition)
* and data are propagated on a falling edge (high
lo
w clock transition).
* - For CPHA=0, data are captured on the clock's rising edge (low
->
high transition)
* and data are propagated on a falling edge (high
->
low clock transition).
* - For CPHA=1, data are captured on the clock's falling edge and data are
* propagated on a rising edge.
* At CPOL=1 the base value of the clock is one (inversion of CPOL=0)
...
...
@@ -118,6 +118,7 @@ struct rt_spi_device
struct
rt_spi_bus
*
bus
;
struct
rt_spi_configuration
config
;
void
*
user_data
;
};
#define SPI_DEVICE(dev) ((struct rt_spi_device *)(dev))
...
...
components/drivers/spi/spi_flash_sfud.c
浏览文件 @
ea48042f
...
...
@@ -97,7 +97,7 @@ static rt_err_t rt_sfud_control(rt_device_t dev, int cmd, void *args) {
static
rt_size_t
rt_sfud_read
(
rt_device_t
dev
,
rt_off_t
pos
,
void
*
buffer
,
rt_size_t
size
)
{
struct
spi_flash_device
*
rtt_dev
=
(
struct
spi_flash_device
*
)
(
dev
->
user_data
);
sfud_flash
*
sfud_dev
=
(
sfud_flash
*
)
(
rtt_dev
->
user_data
);
/* change the block devices logic address to physical address */
/* change the block device
'
s logic address to physical address */
rt_off_t
phy_pos
=
pos
*
rtt_dev
->
geometry
.
bytes_per_sector
;
rt_size_t
phy_size
=
size
*
rtt_dev
->
geometry
.
bytes_per_sector
;
...
...
@@ -111,7 +111,7 @@ static rt_size_t rt_sfud_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_si
static
rt_size_t
rt_sfud_write
(
rt_device_t
dev
,
rt_off_t
pos
,
const
void
*
buffer
,
rt_size_t
size
)
{
struct
spi_flash_device
*
rtt_dev
=
(
struct
spi_flash_device
*
)
(
dev
->
user_data
);
sfud_flash
*
sfud_dev
=
(
sfud_flash
*
)
(
rtt_dev
->
user_data
);
/* change the block devices logic address to physical address */
/* change the block device
'
s logic address to physical address */
rt_off_t
phy_pos
=
pos
*
rtt_dev
->
geometry
.
bytes_per_sector
;
rt_size_t
phy_size
=
size
*
rtt_dev
->
geometry
.
bytes_per_sector
;
...
...
@@ -298,6 +298,7 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
sfud_dev
->
name
=
spi_flash_dev_name_bak
;
/* accessed each other */
rtt_dev
->
user_data
=
sfud_dev
;
rtt_dev
->
rt_spi_device
->
user_data
=
rtt_dev
;
rtt_dev
->
flash_device
.
user_data
=
rtt_dev
;
sfud_dev
->
user_data
=
rtt_dev
;
/* initialize SFUD device */
...
...
@@ -606,6 +607,35 @@ static void sf(uint8_t argc, char **argv) {
}
MSH_CMD_EXPORT
(
sf
,
SPI
Flash
operate
.);
sfud_flash_t
rt_sfud_flash_find
(
const
char
*
spi_dev_name
)
{
rt_spi_flash_device_t
rtt_dev
=
RT_NULL
;
struct
rt_spi_device
*
rt_spi_device
=
RT_NULL
;
sfud_flash_t
sfud_dev
=
RT_NULL
;
rt_spi_device
=
(
struct
rt_spi_device
*
)
rt_device_find
(
spi_dev_name
);
if
(
rt_spi_device
==
RT_NULL
||
rt_spi_device
->
parent
.
type
!=
RT_Device_Class_SPIDevice
)
{
rt_kprintf
(
"ERROR: SPI device %s not found!
\n
"
,
spi_dev_name
);
goto
error
;
}
rtt_dev
=
(
rt_spi_flash_device_t
)(
rt_spi_device
->
user_data
);
if
(
rtt_dev
&&
rtt_dev
->
user_data
)
{
sfud_dev
=
(
sfud_flash_t
)(
rtt_dev
->
user_data
);
return
sfud_dev
;
}
else
{
rt_kprintf
(
"ERROR: SFUD flash device not found!
\n
"
);
goto
error
;
}
error:
return
RT_NULL
;
}
#endif
/* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */
#endif
/* RT_USING_SFUD */
components/drivers/spi/spi_flash_sfud.h
浏览文件 @
ea48042f
...
...
@@ -27,6 +27,7 @@
#include <rtthread.h>
#include "./sfud/inc/sfud.h"
#include "spi_flash.h"
/**
* Probe SPI flash by SFUD(Serial Flash Universal Driver) driver library and though SPI device.
...
...
@@ -47,4 +48,13 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
*/
rt_err_t
rt_sfud_flash_delete
(
rt_spi_flash_device_t
spi_flash_dev
);
/**
* Find sfud flash device
*
* @param spi_dev_name using SPI device name
*
* @return sfud flash device if success, otherwise return RT_NULL
*/
sfud_flash_t
rt_sfud_flash_find
(
const
char
*
spi_dev_name
);
#endif
/* _SPI_FLASH_SFUD_H_ */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录