rel_1.6.0 init

This commit is contained in:
guocheng.kgc 2020-06-18 20:06:52 +08:00 committed by shengdong.dsd
commit 27b3e2883d
19359 changed files with 8093121 additions and 0 deletions

View file

@ -0,0 +1,52 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_VFS_ADC_H
#define AOS_VFS_ADC_H
#ifdef __cplusplus
extern "C" {
#endif
#include "vfs_inode.h"
/* adc driver struct */
extern const struct file_ops adc_ops;
/**
* This function is used to open adc device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_adc_open(inode_t *inode, file_t *fp);
/**
* This function is used to close adc device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_adc_close(file_t *fp);
/**
* This function is used to complete the data sample and get the sampled value.
*
* @param[in] fp device pointer.
* @param[out] buf data buffer for sampled data.
* @param[in] nbytes the maximum size of the user-provided buffer.
*
* @return The positive non-zero number of bytes read on success,
* 0 on read nothing, or negative on failure with errno set appropriately.
*/
ssize_t vfs_adc_read(file_t *fp, void *buf, size_t nbytes);
#ifdef __cplusplus
}
#endif
#endif /* AOS_VFS_ADC_H */

View file

@ -0,0 +1,26 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_VFS_DEVICE_H
#define AOS_VFS_DEVICE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "vfs_adc.h"
#include "vfs_gpio.h"
#include "vfs_i2c.h"
#include "vfs_pwm.h"
#include "vfs_rtc.h"
#include "vfs_spi.h"
#include "vfs_uart.h"
#include "vfs_wdg.h"
#ifdef __cplusplus
}
#endif
#endif /* AOS_VFS_DEVICE_H */

View file

@ -0,0 +1,68 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_VFS_GPIO_H
#define AOS_VFS_GPIO_H
#ifdef __cplusplus
extern "C" {
#endif
#include "vfs_inode.h"
/* cmd for ioctl */
#define IOCTL_GPIO_OUTPUT_HIGHT 1 /* output hight */
#define IOCTL_GPIO_OUTPUT_LOW 2 /* output low */
#define IOCTL_GPIO_OUTPUT_TOGGLE 3 /* toggle output */
/* gpio driver struct */
extern const struct file_ops gpio_ops;
/**
* This function is used to open gpio device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_gpio_open(inode_t *inode, file_t *fp);
/**
* This function is used to close gpio device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_gpio_close(file_t *fp);
/**
* This function is used to get data from gpio.
*
* @param[in] fp device pointer.
* @param[out] buf data buffer for data.
* @param[in] nbytes the maximum size of the user-provided buffer.
*
* @return The positive non-zero number of bytes read on success,
* 0 on read nothing, or negative on failure with errno set appropriately.
*/
ssize_t vfs_gpio_read(file_t *fp, void *buf, size_t nbytes);
/**
* This function performs device input and output operations.
*
* @param[in] fp device pointer.
* @param[in] cmd command of input and output operating.
* @param[in] arg argument of input and output operating.
*
* @return 0 on success, negative on failure with errno set appropriately.
*/
int vfs_gpio_ioctl(file_t *fp, int cmd, unsigned long arg);
#ifdef __cplusplus
}
#endif
#endif /* AOS_VFS_GPIO_H */

View file

@ -0,0 +1,64 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_VFS_I2C_H
#define AOS_VFS_I2C_H
#ifdef __cplusplus
extern "C" {
#endif
#include "vfs_inode.h"
/* i2c driver struct */
extern const struct file_ops i2c_ops;
/**
* This function is used to open i2c device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_i2c_open(inode_t *inode, file_t *fp);
/**
* This function is used to close i2c device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_i2c_close(file_t *fp);
/**
* This function is used to get data from i2c.
*
* @param[in] fp device pointer.
* @param[out] buf data buffer for data.
* @param[in] nbytes the maximum size of the user-provided buffer.
*
* @return The positive non-zero number of bytes read on success,
* 0 on read nothing, or negative on failure with errno set appropriately.
*/
ssize_t vfs_i2c_read(file_t *fp, void *buf, size_t nbytes);
/**
* This function is used to send data through i2c.
*
* @param[in] fp device pointer.
* @param[out] buf data buffer for data.
* @param[in] nbytes the maximum size of the user-provided buffer.
*
* @return The positive non-zero number of bytes write on success,
* 0 on write nothing, or negative on failure with errno set appropriately.
*/
ssize_t vfs_i2c_write(file_t *fp, const void *buf, size_t nbytes);
#ifdef __cplusplus
}
#endif
#endif /* AOS_VFS_I2C_H */

View file

@ -0,0 +1,55 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_VFS_PWM_H
#define AOS_VFS_PWM_H
#ifdef __cplusplus
extern "C" {
#endif
#include "vfs_inode.h"
/* cmd for ioctl */
#define IOCTL_PWM_OUTPUT_START 1 /* start output pwm */
#define IOCTL_PWM_OUTPUT_STOP 2 /* stop output pwm */
/* pwm driver struct */
extern const struct file_ops pwm_ops;
/**
* This function is used to open pwm device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_pwm_open(inode_t *inode, file_t *fp);
/**
* This function is used to close pwm device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_pwm_close(file_t *fp);
/**
* This function performs device input and output operations.
*
* @param[in] fp device pointer.
* @param[in] cmd command of input and output operating.
* @param[in] arg argument of input and output operating.
*
* @return 0 on success, negative on failure with errno set appropriately.
*/
int vfs_pwm_ioctl(file_t *fp, int cmd, unsigned long arg);
#ifdef __cplusplus
}
#endif
#endif /* AOS_VFS_PWM_H */

View file

@ -0,0 +1,64 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_VFS_RTC_H
#define AOS_VFS_RTC_H
#ifdef __cplusplus
extern "C" {
#endif
#include "vfs_inode.h"
/* rtc driver struct */
extern const struct file_ops rtc_ops;
/**
* This function is used to open rtc device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_rtc_open(inode_t *inode, file_t *fp);
/**
* This function is used to close rtc device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_rtc_close(file_t *fp);
/**
* This function is used to get Real-Time Clock.
*
* @param[in] fp device pointer.
* @param[out] buf data buffer for data.
* @param[in] nbytes the maximum size of the user-provided buffer.
*
* @return The positive non-zero number of bytes read on success,
* 0 on read nothing, or negative on failure with errno set appropriately.
*/
ssize_t vfs_rtc_read(file_t *fp, void *buf, size_t nbytes);
/**
* This function is used to set Real-Time Clock.
*
* @param[in] fp device pointer.
* @param[out] buf data buffer for data.
* @param[in] nbytes the maximum size of the user-provided buffer.
*
* @return The positive non-zero number of bytes write on success,
* 0 on write nothing, or negative on failure with errno set appropriately.
*/
ssize_t vfs_rtc_write(file_t *fp, const void *buf, size_t nbytes);
#ifdef __cplusplus
}
#endif
#endif /* AOS_VFS_RTC_H */

View file

@ -0,0 +1,64 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_VFS_SPI_H
#define AOS_VFS_SPI_H
#ifdef __cplusplus
extern "C" {
#endif
#include "vfs_inode.h"
/* spi driver struct */
extern const struct file_ops spi_ops;
/**
* This function is used to open spi device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_spi_open(inode_t *inode, file_t *fp);
/**
* This function is used to close spi device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_spi_close(file_t *fp);
/**
* This function is used to get data from spi.
*
* @param[in] fp device pointer.
* @param[out] buf data buffer for data.
* @param[in] nbytes the maximum size of the user-provided buffer.
*
* @return The positive non-zero number of bytes read on success,
* 0 on read nothing, or negative on failure with errno set appropriately.
*/
ssize_t vfs_spi_read(file_t *fp, void *buf, size_t nbytes);
/**
* This function is used to send data through spi.
*
* @param[in] fp device pointer.
* @param[out] buf data buffer for data.
* @param[in] nbytes the maximum size of the user-provided buffer.
*
* @return The positive non-zero number of bytes write on success,
* 0 on write nothing, or negative on failure with errno set appropriately.
*/
ssize_t vfs_spi_write(file_t *fp, const void *buf, size_t nbytes);
#ifdef __cplusplus
}
#endif
#endif /* AOS_VFS_SPI_H */

View file

@ -0,0 +1,64 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_VFS_UART_H
#define AOS_VFS_UART_H
#ifdef __cplusplus
extern "C" {
#endif
#include "vfs_inode.h"
/* uart driver struct */
extern const struct file_ops uart_ops;
/**
* This function is used to open uart device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_uart_open(inode_t *inode, file_t *fp);
/**
* This function is used to close uart device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_uart_close(file_t *fp);
/**
* This function is used to get data from uart.
*
* @param[in] fp device pointer.
* @param[out] buf data buffer for data.
* @param[in] nbytes the maximum size of the user-provided buffer.
*
* @return The positive non-zero number of bytes read on success,
* 0 on read nothing, or negative on failure with errno set appropriately.
*/
ssize_t vfs_uart_read(file_t *fp, void *buf, size_t nbytes);
/**
* This function is used to send data through uart.
*
* @param[in] fp device pointer.
* @param[out] buf data buffer for data.
* @param[in] nbytes the maximum size of the user-provided buffer.
*
* @return The positive non-zero number of bytes write on success,
* 0 on write nothing, or negative on failure with errno set appropriately.
*/
ssize_t vfs_uart_write(file_t *fp, const void *buf, size_t nbytes);
#ifdef __cplusplus
}
#endif
#endif /* AOS_VFS_UART_H */

View file

@ -0,0 +1,54 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_VFS_WDG_H
#define AOS_VFS_WDG_H
#ifdef __cplusplus
extern "C" {
#endif
#include "vfs_inode.h"
/* cmd for ioctl */
#define IOCTL_WDG_RELOAD 1 /* reload watchdog */
/* wdg driver struct */
extern const struct file_ops wdg_ops;
/**
* This function is used to open wdg device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_wdg_open(inode_t *inode, file_t *fp);
/**
* This function is used to close wdg device.
*
* @param[in] fp device pointer.
*
* @return 0 on success, others on failure with errno set appropriately.
*/
int vfs_wdg_close(file_t *fp);
/**
* This function performs device input and output operations.
*
* @param[in] fp device pointer.
* @param[in] cmd command of input and output operating.
* @param[in] arg argument of input and output operating.
*
* @return 0 on success, negative on failure with errno set appropriately.
*/
int vfs_wdg_ioctl(file_t *fp, int cmd, unsigned long arg);
#ifdef __cplusplus
}
#endif
#endif /* AOS_VFS_WDG_H */

View file

@ -0,0 +1,23 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef EVENT_DEVICE_H
#define EVENT_DEVICE_H
#ifdef __cplusplus
extern "C" {
#endif
#define IOCTL_WRITE_NORMAL 0x1
#define IOCTL_WRITE_URGENT 0x2
#define MK_CMD(c, l) ((l << 4) | (c))
#define _GET_LEN(cmd) ((cmd) >> 4)
#define _GET_CMD(cmd) ((cmd) & 0xf)
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,23 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_VFS_H
#define AOS_VFS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#include <vfs_conf.h>
int vfs_init(void);
int vfs_device_init(void);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,25 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_VFS_CONFIG_H
#define AOS_VFS_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
#define VFS_FALSE 0u
#define VFS_TRUE 1u
#define AOS_CONFIG_VFS_DEV_NODES 25
/*mem 1000 byte*/
#define AOS_CONFIG_VFS_DEV_MEM 2000
#define AOS_CONFIG_VFS_POLL_SUPPORT 1
#define AOS_CONFIG_VFS_FD_OFFSET 64
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,21 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef VFS_ERRNO_H
#define VFS_ERRNO_H
#ifdef __cplusplus
extern "C" {
#endif
#include <errno.h>
#define VFS_SUCCESS 0u
#ifdef __cplusplus
}
#endif
#endif /* VFS_ERRNO_H */

View file

@ -0,0 +1,24 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef AOS_VFS_FILE_H
#define AOS_VFS_FILE_H
#ifdef __cplusplus
extern "C" {
#endif
int get_fd(file_t *file);
file_t *get_file(int fd);
file_t *new_file(inode_t *node);
void del_file(file_t *file);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,115 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef VFS_INODE_H
#define VFS_INODE_H
#include <stdbool.h>
#include <stdint.h>
#include <sys/stat.h>
#include <aos/aos.h>
#ifdef __cplusplus
extern "C" {
#endif
enum {
VFS_TYPE_NOT_INIT,
VFS_TYPE_CHAR_DEV,
VFS_TYPE_BLOCK_DEV,
VFS_TYPE_FS_DEV
};
#define INODE_IS_TYPE(i,t) \
((i)->type == (t))
#define INODE_IS_CHAR(i) INODE_IS_TYPE(i, VFS_TYPE_CHAR_DEV)
#define INODE_IS_BLOCK(i) INODE_IS_TYPE(i, VFS_TYPE_BLOCK_DEV)
#define INODE_IS_FS(i) INODE_IS_TYPE(i, VFS_TYPE_FS_DEV)
#define INODE_GET_TYPE(i) ((i)->type)
#define INODE_SET_TYPE(i,t) \
do \
{ \
(i)->type = (t); \
} \
while(0)
#define INODE_SET_CHAR(i) INODE_SET_TYPE(i, VFS_TYPE_CHAR_DEV)
#define INODE_SET_BLOCK(i) INODE_SET_TYPE(i, VFS_TYPE_BLOCK_DEV)
#define INODE_SET_FS(i) INODE_SET_TYPE(i, VFS_TYPE_FS_DEV)
typedef const struct file_ops file_ops_t;
typedef const struct fs_ops fs_ops_t;
union inode_ops_t {
const file_ops_t *i_ops; /* char driver operations */
const fs_ops_t *i_fops; /* FS operations */
};
/* this structure represents inode for driver and fs*/
typedef struct {
union inode_ops_t ops; /* inode operations */
void *i_arg; /* per inode private data */
char *i_name; /* name of inode */
int i_flags; /* flags for inode */
uint8_t type; /* type for inode */
uint8_t refs; /* refs for inode */
aos_mutex_t mutex; /* mutex for inode */
} inode_t;
typedef struct {
inode_t *node; /* node for file */
void *f_arg; /* f_arg for file */
size_t offset; /* offset for file */
} file_t;
struct pollfd;
typedef void (*poll_notify_t)(struct pollfd *fd, void *arg);
struct file_ops {
int (*open) (inode_t *node, file_t *fp);
int (*close) (file_t *fp);
ssize_t (*read) (file_t *fp, void *buf, size_t nbytes);
ssize_t (*write) (file_t *fp, const void *buf, size_t nbytes);
int (*ioctl) (file_t *fp, int cmd, unsigned long arg);
#ifdef AOS_CONFIG_VFS_POLL_SUPPORT
int (*poll) (file_t *fp, bool flag, poll_notify_t notify, struct pollfd *fd, void *arg);
#endif
};
struct fs_ops {
int (*open) (file_t *fp, const char *path, int flags);
int (*close) (file_t *fp);
ssize_t (*read) (file_t *fp, char *buf, size_t len);
ssize_t (*write) (file_t *fp, const char *buf, size_t len);
off_t (*lseek) (file_t *fp, off_t off, int whence);
int (*sync) (file_t *fp);
int (*stat) (file_t *fp, const char *path, struct stat *st);
int (*unlink) (file_t *fp, const char *path);
int (*rename) (file_t *fp, const char *oldpath, const char *newpath);
aos_dir_t *(*opendir) (file_t *fp, const char *path);
aos_dirent_t *(*readdir) (file_t *fp, aos_dir_t *dir);
int (*closedir) (file_t *fp, aos_dir_t *dir);
int (*mkdir) (file_t *fp, const char *path);
int (*ioctl) (file_t *fp, int cmd, unsigned long arg);
};
int inode_init(void);
int inode_alloc(void);
int inode_del(inode_t *node);
inode_t *inode_open(const char *path);
int inode_ptr_get(int fd, inode_t **node);
int inode_avail_count(void);
void inode_ref(inode_t *);
void inode_unref(inode_t *);
int inode_busy(inode_t *);
int inode_reserve(const char *path, inode_t **inode);
int inode_release(const char *path);
#ifdef __cplusplus
}
#endif
#endif /*VFS_INODE_H*/

View file

@ -0,0 +1,25 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef VFS_DRIVER_H
#define VFS_DRIVER_H
#include <vfs_inode.h>
#ifdef __cplusplus
extern "C" {
#endif
int aos_register_driver(const char *path, file_ops_t *fops, void *arg);
int aos_unregister_driver(const char *path);
int aos_register_fs(const char *path, fs_ops_t *fops, void *arg);
int aos_unregister_fs(const char *path);
#ifdef __cplusplus
}
#endif
#endif /*VFS_DRIVER_H*/