mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2026-07-11 20:55:39 +00:00
rel_1.6.0 init
This commit is contained in:
commit
27b3e2883d
19359 changed files with 8093121 additions and 0 deletions
16
Living_SDK/kernel/vfs/device/device.mk
Normal file
16
Living_SDK/kernel/vfs/device/device.mk
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
NAME := vfs_device
|
||||
|
||||
$(NAME)_MBINS_TYPE := kernel
|
||||
|
||||
$(NAME)_SOURCES += vfs_adc.c
|
||||
$(NAME)_SOURCES += vfs_uart.c
|
||||
$(NAME)_SOURCES += vfs_gpio.c
|
||||
$(NAME)_SOURCES += vfs_spi.c
|
||||
$(NAME)_SOURCES += vfs_pwm.c
|
||||
$(NAME)_SOURCES += vfs_rtc.c
|
||||
$(NAME)_SOURCES += vfs_wdg.c
|
||||
$(NAME)_SOURCES += vfs_i2c.c
|
||||
|
||||
$(NAME)_INCLUDES += ../include/device/ \
|
||||
../include/ \
|
||||
../../hal/soc/
|
||||
15
Living_SDK/kernel/vfs/device/ucube.py
Normal file
15
Living_SDK/kernel/vfs/device/ucube.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
src = Split('''
|
||||
vfs_adc.c
|
||||
vfs_uart.c
|
||||
vfs_gpio.c
|
||||
vfs_spi.c
|
||||
vfs_pwm.c
|
||||
vfs_rtc.c
|
||||
vfs_wdg.c
|
||||
vfs_i2c.c
|
||||
''')
|
||||
|
||||
component = aos_component('vfs_device', src)
|
||||
|
||||
component.add_global_includes('../include/device', '../include', '../../hal/soc/')
|
||||
|
||||
109
Living_SDK/kernel/vfs/device/vfs_adc.c
Normal file
109
Living_SDK/kernel/vfs/device/vfs_adc.c
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include "device/vfs_adc.h"
|
||||
#include "hal/soc/soc.h"
|
||||
#include "vfs_err.h"
|
||||
|
||||
/* adc driver struct */
|
||||
const struct file_ops adc_ops =
|
||||
{
|
||||
.open = vfs_adc_open,
|
||||
.read = vfs_adc_read,
|
||||
.close = vfs_adc_close
|
||||
};
|
||||
|
||||
int vfs_adc_open(inode_t *inode, file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
adc_dev_t *adc_dev = NULL; /* adc device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* Initialize if the device is first opened. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
adc_dev = (adc_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* init adc device. */
|
||||
ret = hal_adc_init(adc_dev);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vfs_adc_close(file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
adc_dev_t *adc_dev = NULL; /* adc device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* close device if the device is last closed. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
adc_dev = (adc_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* turns off an ADC hardwar. */
|
||||
ret = hal_adc_finalize(adc_dev);
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t vfs_adc_read(file_t *fp, void *buf, size_t nbytes)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
adc_dev_t *adc_dev = NULL; /* adc device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* get the device pointer. */
|
||||
adc_dev = (adc_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* get adc sampled value. */
|
||||
ret = hal_adc_value_get(adc_dev, buf, HAL_WAIT_FOREVER);
|
||||
|
||||
/* If the data is got successfully, set the return
|
||||
value to nbytes. */
|
||||
if (ret == 0) {
|
||||
ret = nbytes;
|
||||
}
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
150
Living_SDK/kernel/vfs/device/vfs_gpio.c
Normal file
150
Living_SDK/kernel/vfs/device/vfs_gpio.c
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include "device/vfs_gpio.h"
|
||||
#include "hal/soc/soc.h"
|
||||
#include "vfs_err.h"
|
||||
|
||||
/* gpio driver struct */
|
||||
const struct file_ops gpio_ops =
|
||||
{
|
||||
.open = vfs_gpio_open,
|
||||
.close = vfs_gpio_close,
|
||||
.read = vfs_gpio_read,
|
||||
.ioctl = vfs_gpio_ioctl
|
||||
};
|
||||
|
||||
int vfs_gpio_open(inode_t *inode, file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
gpio_dev_t *gpio_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* Initialize if the device is first opened. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
gpio_dev = (gpio_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* init gpio device. */
|
||||
ret = hal_gpio_init(gpio_dev);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vfs_gpio_close(file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
gpio_dev_t *gpio_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* close device if the device is last closed. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
gpio_dev = (gpio_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* turns off hardware. */
|
||||
ret = hal_gpio_finalize(gpio_dev);
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t vfs_gpio_read(file_t *fp, void *buf, size_t nbytes)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
gpio_dev_t *gpio_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* get the device pointer. */
|
||||
gpio_dev = (gpio_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* get data from gpio. */
|
||||
ret = hal_gpio_input_get(gpio_dev, (uint32_t *)buf);
|
||||
|
||||
/* If the data is read correctly and the number of read data
|
||||
bytes is not negative, the return value is set to read bytes. */
|
||||
if (ret == 0) {
|
||||
ret = sizeof(uint32_t);
|
||||
}
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vfs_gpio_ioctl(file_t *fp, int cmd, unsigned long arg)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
gpio_dev_t *gpio_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp == NULL) || (fp->node == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* get the device pointer. */
|
||||
gpio_dev = (gpio_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
switch(cmd) {
|
||||
case IOCTL_GPIO_OUTPUT_HIGHT:
|
||||
ret = hal_gpio_output_high(gpio_dev); /* output hight */
|
||||
break;
|
||||
case IOCTL_GPIO_OUTPUT_LOW:
|
||||
ret = hal_gpio_output_low(gpio_dev); /* output low */
|
||||
break;
|
||||
case IOCTL_GPIO_OUTPUT_TOGGLE:
|
||||
ret = hal_gpio_output_toggle(gpio_dev); /* toggle output */
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
152
Living_SDK/kernel/vfs/device/vfs_i2c.c
Normal file
152
Living_SDK/kernel/vfs/device/vfs_i2c.c
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include "device/vfs_i2c.h"
|
||||
#include "hal/soc/soc.h"
|
||||
#include "vfs_err.h"
|
||||
|
||||
/* i2c driver struct */
|
||||
const struct file_ops i2c_ops =
|
||||
{
|
||||
.open = vfs_i2c_open,
|
||||
.close = vfs_i2c_close,
|
||||
.read = vfs_i2c_read,
|
||||
.write = vfs_i2c_write
|
||||
};
|
||||
|
||||
int vfs_i2c_open(inode_t *inode, file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
i2c_dev_t *i2c_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* Initialize if the device is first opened. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
i2c_dev = (i2c_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* init i2c device. */
|
||||
ret = hal_i2c_init(i2c_dev);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vfs_i2c_close(file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
i2c_dev_t *i2c_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* close device if the device is last closed. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
i2c_dev = (i2c_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* turns off hardware. */
|
||||
ret = hal_i2c_finalize(i2c_dev);
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t vfs_i2c_read(file_t *fp, void *buf, size_t nbytes)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
i2c_dev_t *i2c_dev = NULL; /* device pointer */
|
||||
uint16_t dev_addr = 0; /* dev address */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* get the device pointer. */
|
||||
i2c_dev = (i2c_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* get the device address. */
|
||||
dev_addr = i2c_dev->config.dev_addr;
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* get data from i2c. */
|
||||
ret = hal_i2c_master_recv(i2c_dev, dev_addr, (uint8_t *)buf, nbytes, HAL_WAIT_FOREVER);
|
||||
|
||||
/* If the data is read correctly, the return
|
||||
value is set to read bytes. */
|
||||
if (ret == 0) {
|
||||
ret = nbytes;
|
||||
}
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t vfs_i2c_write(file_t *fp, const void *buf, size_t nbytes)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
i2c_dev_t *i2c_dev = NULL; /* device pointer */
|
||||
uint16_t dev_addr = 0; /* dev address */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* get the device pointer. */
|
||||
i2c_dev = (i2c_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* get the device address. */
|
||||
dev_addr = i2c_dev->config.dev_addr;
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* send data from i2c. */
|
||||
ret = hal_i2c_master_send(i2c_dev, dev_addr, (const uint8_t *)buf, nbytes, HAL_WAIT_FOREVER);
|
||||
|
||||
/* If the data is sent successfully, set the return
|
||||
value to nbytes. */
|
||||
if (ret == 0) {
|
||||
ret = nbytes;
|
||||
}
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
112
Living_SDK/kernel/vfs/device/vfs_pwm.c
Normal file
112
Living_SDK/kernel/vfs/device/vfs_pwm.c
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include "device/vfs_pwm.h"
|
||||
#include "hal/soc/soc.h"
|
||||
#include "vfs_err.h"
|
||||
|
||||
/* pwm driver struct */
|
||||
const struct file_ops pwm_ops =
|
||||
{
|
||||
.open = vfs_pwm_open,
|
||||
.close = vfs_pwm_close,
|
||||
.ioctl = vfs_pwm_ioctl
|
||||
};
|
||||
|
||||
int vfs_pwm_open(inode_t *inode, file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
pwm_dev_t *pwm_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* Initialize if the device is first opened. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
pwm_dev = (pwm_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* init pwm device. */
|
||||
ret = hal_pwm_init(pwm_dev);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vfs_pwm_close(file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
pwm_dev_t *pwm_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* close device if the device is last closed. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
pwm_dev = (pwm_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* turns off hardware. */
|
||||
ret = hal_pwm_finalize(pwm_dev);
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vfs_pwm_ioctl(file_t *fp, int cmd, unsigned long arg)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
pwm_dev_t *pwm_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp == NULL) || (fp->node == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* get the device pointer. */
|
||||
pwm_dev = (pwm_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
switch(cmd) {
|
||||
case IOCTL_PWM_OUTPUT_START:
|
||||
ret = hal_pwm_start(pwm_dev);
|
||||
break;
|
||||
case IOCTL_PWM_OUTPUT_STOP:
|
||||
ret = hal_pwm_stop(pwm_dev);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
143
Living_SDK/kernel/vfs/device/vfs_rtc.c
Normal file
143
Living_SDK/kernel/vfs/device/vfs_rtc.c
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include "device/vfs_rtc.h"
|
||||
#include "hal/soc/soc.h"
|
||||
#include "vfs_err.h"
|
||||
|
||||
/* rtc driver struct */
|
||||
const struct file_ops rtc_ops =
|
||||
{
|
||||
.open = vfs_rtc_open,
|
||||
.close = vfs_rtc_close,
|
||||
.read = vfs_rtc_read,
|
||||
.write = vfs_rtc_write
|
||||
};
|
||||
|
||||
int vfs_rtc_open(inode_t *inode, file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
rtc_dev_t *rtc_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* Initialize if the device is first opened. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
rtc_dev = (rtc_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* init rtc device. */
|
||||
ret = hal_rtc_init(rtc_dev);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vfs_rtc_close(file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
rtc_dev_t *rtc_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* close device if the device is last closed. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
rtc_dev = (rtc_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* turns off hardware. */
|
||||
ret = hal_rtc_finalize(rtc_dev);
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t vfs_rtc_read(file_t *fp, void *buf, size_t nbytes)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
rtc_dev_t *rtc_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL) && (nbytes >= sizeof(rtc_time_t))) {
|
||||
|
||||
/* get the device pointer. */
|
||||
rtc_dev = (rtc_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* get data from rtc. */
|
||||
ret = hal_rtc_get_time(rtc_dev, (rtc_time_t *)buf);
|
||||
|
||||
/* If the data is read correctly the return value is set to nbytes. */
|
||||
if (ret == 0) {
|
||||
ret = nbytes;
|
||||
}
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t vfs_rtc_write(file_t *fp, const void *buf, size_t nbytes)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
rtc_dev_t *rtc_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL) && (nbytes >= sizeof(rtc_time_t))) {
|
||||
|
||||
/* get the device pointer. */
|
||||
rtc_dev = (rtc_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* set rtc time. */
|
||||
ret = hal_rtc_set_time(rtc_dev, (const rtc_time_t *)buf);
|
||||
|
||||
/* If the time is set successfully, set the return
|
||||
value to nbytes. */
|
||||
if (ret == 0) {
|
||||
ret = nbytes;
|
||||
}
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
144
Living_SDK/kernel/vfs/device/vfs_spi.c
Normal file
144
Living_SDK/kernel/vfs/device/vfs_spi.c
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include "device/vfs_spi.h"
|
||||
#include "hal/soc/soc.h"
|
||||
#include "vfs_err.h"
|
||||
|
||||
/* spi driver struct */
|
||||
const struct file_ops spi_ops =
|
||||
{
|
||||
.open = vfs_spi_open,
|
||||
.close = vfs_spi_close,
|
||||
.read = vfs_spi_read,
|
||||
.write = vfs_spi_write
|
||||
};
|
||||
|
||||
int vfs_spi_open(inode_t *inode, file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
spi_dev_t *spi_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* Initialize if the device is first opened. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
spi_dev = (spi_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* init spi device. */
|
||||
ret = hal_spi_init(spi_dev);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vfs_spi_close(file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
spi_dev_t *spi_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* close device if the device is last closed. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
spi_dev = (spi_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* turns off hardware. */
|
||||
ret = hal_spi_finalize(spi_dev);
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t vfs_spi_read(file_t *fp, void *buf, size_t nbytes)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
spi_dev_t *spi_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* get the device pointer. */
|
||||
spi_dev = (spi_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* get data from spi. */
|
||||
ret = hal_spi_recv(spi_dev, (unsigned char *)buf, nbytes, HAL_WAIT_FOREVER);
|
||||
|
||||
/* If the data is read correctly and the number of read data
|
||||
bytes is not negative, the return value is set to read bytes. */
|
||||
if (ret == 0) {
|
||||
ret = nbytes;
|
||||
}
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t vfs_spi_write(file_t *fp, const void *buf, size_t nbytes)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
spi_dev_t *spi_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* get the device pointer. */
|
||||
spi_dev = (spi_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* send data from spi. */
|
||||
ret = hal_spi_send(spi_dev, (const uint8_t *)buf, nbytes, HAL_WAIT_FOREVER);
|
||||
|
||||
/* If the data is sent successfully, set the return
|
||||
value to nbytes. */
|
||||
if (ret == 0) {
|
||||
ret = nbytes;
|
||||
}
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
144
Living_SDK/kernel/vfs/device/vfs_uart.c
Normal file
144
Living_SDK/kernel/vfs/device/vfs_uart.c
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include "device/vfs_uart.h"
|
||||
#include "hal/soc/soc.h"
|
||||
#include "vfs_err.h"
|
||||
|
||||
/* uart driver struct */
|
||||
const struct file_ops uart_ops =
|
||||
{
|
||||
.open = vfs_uart_open,
|
||||
.close = vfs_uart_close,
|
||||
.read = vfs_uart_read,
|
||||
.write = vfs_uart_write
|
||||
};
|
||||
|
||||
int vfs_uart_open(inode_t *inode, file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
uart_dev_t *uart_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* Initialize if the device is first opened. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
uart_dev = (uart_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* init uart device. */
|
||||
ret = hal_uart_init(uart_dev);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vfs_uart_close(file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
uart_dev_t *uart_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* close device if the device is last closed. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
uart_dev = (uart_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* turns off hardware. */
|
||||
ret = hal_uart_finalize(uart_dev);
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t vfs_uart_read(file_t *fp, void *buf, size_t nbytes)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
uart_dev_t *uart_dev = NULL; /* device pointer */
|
||||
uint32_t recv_bytes = 0; /* number of bytes received */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* get the device pointer. */
|
||||
uart_dev = (uart_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* get data from uart. */
|
||||
ret = hal_uart_recv_II(uart_dev, buf, nbytes, &recv_bytes, HAL_WAIT_FOREVER);
|
||||
|
||||
/* If the data is read correctly the return value is set to read bytes. */
|
||||
if (ret == 0) {
|
||||
ret = recv_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t vfs_uart_write(file_t *fp, const void *buf, size_t nbytes)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
uart_dev_t *uart_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* get the device pointer. */
|
||||
uart_dev = (uart_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* send data from uart. */
|
||||
ret = hal_uart_send(uart_dev, buf, nbytes, HAL_WAIT_FOREVER);
|
||||
|
||||
/* If the data is sent successfully, set the return
|
||||
value to nbytes. */
|
||||
if (ret == 0) {
|
||||
ret = nbytes;
|
||||
}
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
110
Living_SDK/kernel/vfs/device/vfs_wdg.c
Normal file
110
Living_SDK/kernel/vfs/device/vfs_wdg.c
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include "device/vfs_wdg.h"
|
||||
#include "hal/soc/soc.h"
|
||||
#include "vfs_err.h"
|
||||
|
||||
/* wdg driver struct */
|
||||
const struct file_ops wdg_ops =
|
||||
{
|
||||
.open = vfs_wdg_open,
|
||||
.close = vfs_wdg_close,
|
||||
.ioctl = vfs_wdg_ioctl
|
||||
};
|
||||
|
||||
int vfs_wdg_open(inode_t *inode, file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
wdg_dev_t *wdg_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* Initialize if the device is first opened. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
wdg_dev = (wdg_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* init wdg device. */
|
||||
ret = hal_wdg_init(wdg_dev);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vfs_wdg_close(file_t *fp)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
wdg_dev_t *wdg_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp != NULL) && (fp->node != NULL)) {
|
||||
|
||||
/* close device if the device is last closed. */
|
||||
if (fp->node->refs == 1) {
|
||||
|
||||
/* get the device pointer. */
|
||||
wdg_dev = (wdg_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret == 0) {
|
||||
|
||||
/* turns off hardware. */
|
||||
ret = hal_wdg_finalize(wdg_dev);
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
} else {
|
||||
ret = VFS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vfs_wdg_ioctl(file_t *fp, int cmd, unsigned long arg)
|
||||
{
|
||||
int ret = -1; /* return value */
|
||||
wdg_dev_t *wdg_dev = NULL; /* device pointer */
|
||||
|
||||
/* check empty pointer. */
|
||||
if ((fp == NULL) || (fp->node == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* get the device pointer. */
|
||||
wdg_dev = (wdg_dev_t *)(fp->node->i_arg);
|
||||
|
||||
/* lock the device. */
|
||||
ret = aos_mutex_lock(&fp->node->mutex, AOS_WAIT_FOREVER);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
switch(cmd) {
|
||||
case IOCTL_WDG_RELOAD:
|
||||
hal_wdg_reload(wdg_dev);
|
||||
ret = VFS_SUCCESS;
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* unlock the device. */
|
||||
aos_mutex_unlock(&fp->node->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue