rtthread posix接口支持

rtthread 支持POSIX 接口,驱动现在也需要支持posix接口,让linux 的应用同样可以运行到让rtthread上 .应用通用可以减少上层应用的改动。加快产品开发速度,同样测试也可以通用,减少维护成本,提高测试效率。
驱动部分需要实现:
应用声明文件:
#include <dfs_file.h>
#include <dfs_posix.h>
#include <dfs_poll.h>
实现的接口结构体:
static const struct dfs_file_ops rtc_fops = {
rtc_fops_open,
RT_NULL,
RT_NULL,
rtc_fops_read,
RT_NULL,
RT_NULL,
RT_NULL,
RT_NULL,
rtc_fops_poll,
};
以上接口函数的实现:
int rtc_fops_open(struct dfs_fd *fd)
{
return 0;
}

static int rtc_fops_read(struct dfs_fd *fd, void *buf, size_t count)
{
*(int *)buf = (core_int_count<<8) | 0x0;
return 0;
}

static int rtc_fops_poll(struct dfs_fd *fd, rt_pollreq_t *req)
{
int mask = 0;

rt_completion_wait(&rtc_uie_completion, RT_WAITING_FOREVER);
return mask;

}

进行注册:
#ifdef RT_USING_POSIX
rtc.fops = (void *)&rtc_fops;
#endif

这样驱动的准备就完成了。
应用进行调用的流程:
rtc_fd = open("/dev/rtc", O_RDONLY, 0);//open 设备
if (rtc_fd < 0)
{
rt_kprintf(“open rtc dev failed %d\n”,rtc_fd);
return;
};

while(1){
FD_ZERO(&readfds);
FD_SET(rtc_fd, &readfds);
rt_kprintf(“select fd:%d readfds:%d\n”,rtc_fd,readfds);
ret = select(rtc_fd+1, &readfds, RT_NULL, RT_NULL, &timeout);// 应用调用select 接口,驱动进入到poll
if (ret < 0)
{
rt_kprintf(“select failed %d\n”, ret);
test_rlt = -1;

}

read(rtc_fd, &buf, 3);// 驱动部分会进入read 函数

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值