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;
}
進行注冊:
#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 函數
總結
以上是生活随笔為你收集整理的rtthread posix接口支持的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一阶电路分析
- 下一篇: 船舶IPTV电视系统方案注意事项