📄 hal_unistd_dev.h
字号:
#ifndef __HAL_UNISTD_DEV_H__
#define __HAL_UNISTD_DEV_H__
#include "../pub/hal_llist.h"
#include "hal_dev_llist.h"
#include "../pub/hal_types.h"
extern hal_llist hal_dev_list;
typedef struct hal_dev_s hal_dev;
/*
* 文件描述符结构定义
*/
typedef struct hal_fd_s
{
hal_dev* dev;
hal_u8* priv;
int fd_flags;
int cur_pos; /*文件指针的位置,由于可以由多个任务同时打开同一个文件/器件,
因此必须记忆每个任务打开的文件后文件指针的位置*/
} hal_fd;
typedef struct __hal_uart_dev_spec hal_uart_dev_spec;
/*
* 器件结构定义
*/
typedef struct hal_dev_s
{
hal_llist llist; /* 用于器件链表操作时使用 */
const char* name; /* 器件名字 */
int (*open)(struct hal_fd_s* fd, const char* name, int flags, int mode);
int (*close)(struct hal_fd_s* fd);
int (*read)(struct hal_fd_s* fd, char* ptr, int len);
int (*write)(struct hal_fd_s* fd, const char* ptr, int len);
int (*lseek)(struct hal_fd_s* fd, int ptr, int dir);
int (*fstat)(struct hal_fd_s* fd, struct stat* buf);
int (*ioctl)(struct hal_fd_s* fd, int req, void* arg);
void* dev_spec; /* 指向扩展的器件结构,不同种类的的器件具有不同的结构 */
}hal_dev_s;
struct __hal_uart_dev_spec
{
char* tx_port;
char* rx_port;
hal_u8 irq;
int (*set_baudrate) (struct hal_fd_s* fd, hal_u32 baudrate);
};
/*
* 用于注册一个字符模式器件
*/
int hal_dev_reg (hal_dev* dev);
//#define NEW_UART_DEV(dev_name, set_buadrate_func,/
// open_func, close_func, /
// read_func, write_func, /
// lseek_func, fstat_func, /
// ioctl_func /
// ) /
// hal_uart_dev_spec dev_name##_spec = /
// { /
// dev_name##_TX_PORT, /
// dev_name##_RX_PORT, /
// dev_name##_IRQ, /
// set_buadrate_func /
// }; /
// /
// hal_dev dev_name = /
// { /
// {NULL, NULL}, /
// dev_name##_NAME, /
// NULL, / /* open() */
// NULL, / /* close() */
// read_func, / /* read() */
// write_func, / /* write() */
// lseek_func, / /* lseek() */
// fstat_func, / /* fstat() */
// ioctl_func, / /* ioctl() */
// &dev_name##_spec /
// };
//
#endif /* __HAL_UNISTD_DEV_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -