From 45d468bfdbd5d7db7e5a4977b120eb3b9c10380c Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Fri, 26 Feb 2021 12:48:03 +0100 Subject: [PATCH] include: move disk driver interface to own header Move disk driver interface to own header and separate disk access interface and disk driver interface. Signed-off-by: Johann Fischer --- drivers/disk/flashdisk.c | 2 +- drivers/disk/ramdisk.c | 2 +- drivers/disk/sdmmc_spi.c | 2 +- drivers/disk/sdmmc_stm32.c | 2 +- drivers/disk/usdhc.c | 2 +- include/disk/disk_access.h | 55 +---------------- include/drivers/disk.h | 118 +++++++++++++++++++++++++++++++++++++ 7 files changed, 126 insertions(+), 57 deletions(-) create mode 100644 include/drivers/disk.h diff --git a/drivers/disk/flashdisk.c b/drivers/disk/flashdisk.c index 44590b7ecec..a1447127736 100644 --- a/drivers/disk/flashdisk.c +++ b/drivers/disk/flashdisk.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/disk/ramdisk.c b/drivers/disk/ramdisk.c index 24dc3027a50..a1623d4705e 100644 --- a/drivers/disk/ramdisk.c +++ b/drivers/disk/ramdisk.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/disk/sdmmc_spi.c b/drivers/disk/sdmmc_spi.c index 03dbc1f2281..dae70cf88fa 100644 --- a/drivers/disk/sdmmc_spi.c +++ b/drivers/disk/sdmmc_spi.c @@ -10,7 +10,7 @@ LOG_MODULE_REGISTER(sdmmc_spi, CONFIG_SDMMC_LOG_LEVEL); -#include +#include #include #include #include diff --git a/drivers/disk/sdmmc_stm32.c b/drivers/disk/sdmmc_stm32.c index 18e285a1aea..8d01ab26304 100644 --- a/drivers/disk/sdmmc_stm32.c +++ b/drivers/disk/sdmmc_stm32.c @@ -7,7 +7,7 @@ #define DT_DRV_COMPAT st_stm32_sdmmc #include -#include +#include #include #include #include diff --git a/drivers/disk/usdhc.c b/drivers/disk/usdhc.c index 606c65b77a5..8ccc77ca4b2 100644 --- a/drivers/disk/usdhc.c +++ b/drivers/disk/usdhc.c @@ -7,7 +7,7 @@ #define DT_DRV_COMPAT nxp_imx_usdhc #include -#include +#include #include #include #include diff --git a/include/disk/disk_access.h b/include/disk/disk_access.h index bb250aabea6..b65106151b0 100644 --- a/include/disk/disk_access.h +++ b/include/disk/disk_access.h @@ -6,12 +6,9 @@ /** * @file - * @brief Disk Access layer APIs and defines + * @brief Disk Access layer API * - * This file contains APIs for disk access. Apart from disks, various - * other storage media like Flash and RAM disks may implement this interface to - * be used by various higher layers(consumers) like USB Mass storage - * and Filesystems. + * This file contains APIs for disk access. */ #ifndef ZEPHYR_INCLUDE_DISK_DISK_ACCESS_H_ @@ -23,54 +20,12 @@ * @{ */ -#include -#include -#include +#include #ifdef __cplusplus extern "C" { #endif -/* Possible Cmd Codes for disk_ioctl() */ - -/* Get the number of sectors in the disk */ -#define DISK_IOCTL_GET_SECTOR_COUNT 1 -/* Get the size of a disk SECTOR in bytes */ -#define DISK_IOCTL_GET_SECTOR_SIZE 2 -/* How many sectors constitute a FLASH Erase block */ -#define DISK_IOCTL_GET_ERASE_BLOCK_SZ 4 -/* Commit any cached read/writes to disk */ -#define DISK_IOCTL_CTRL_SYNC 5 - -/* 3 is reserved. It used to be DISK_IOCTL_GET_DISK_SIZE */ - -/* Possible return bitmasks for disk_status() */ -#define DISK_STATUS_OK 0x00 -#define DISK_STATUS_UNINIT 0x01 -#define DISK_STATUS_NOMEDIA 0x02 -#define DISK_STATUS_WR_PROTECT 0x04 - -struct disk_operations; - -struct disk_info { - sys_dnode_t node; - char *name; - const struct disk_operations *ops; - /* Disk device associated to this disk. - */ - const struct device *dev; -}; - -struct disk_operations { - int (*init)(struct disk_info *disk); - int (*status)(struct disk_info *disk); - int (*read)(struct disk_info *disk, uint8_t *data_buf, - uint32_t start_sector, uint32_t num_sector); - int (*write)(struct disk_info *disk, const uint8_t *data_buf, - uint32_t start_sector, uint32_t num_sector); - int (*ioctl)(struct disk_info *disk, uint8_t cmd, void *buff); -}; - /* * @brief perform any initialization * @@ -129,10 +84,6 @@ int disk_access_write(const char *pdrv, const uint8_t *data_buf, */ int disk_access_ioctl(const char *pdrv, uint8_t cmd, void *buff); -int disk_access_register(struct disk_info *disk); - -int disk_access_unregister(struct disk_info *disk); - #ifdef __cplusplus } #endif diff --git a/include/drivers/disk.h b/include/drivers/disk.h new file mode 100644 index 00000000000..627d41d25d9 --- /dev/null +++ b/include/drivers/disk.h @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2016 Intel Corporation. + * Copyright (c) 2021 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief Disk Driver Interface + * + * This file contains interface for disk access. Apart from disks, various + * other storage media like Flash and RAM disks may implement this interface to + * be used by various higher layers(consumers) like USB Mass storage + * and Filesystems. + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_DISK_H_ +#define ZEPHYR_INCLUDE_DRIVERS_DISK_H_ + +/** + * @brief Disk Driver Interface + * @defgroup disk_driver_interface Disk Driver Interface + * @{ + */ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Possible Cmd Codes for disk_ioctl() + */ + +/** Get the number of sectors in the disk */ +#define DISK_IOCTL_GET_SECTOR_COUNT 1 +/** Get the size of a disk SECTOR in bytes */ +#define DISK_IOCTL_GET_SECTOR_SIZE 2 +/** reserved. It used to be DISK_IOCTL_GET_DISK_SIZE */ +#define DISK_IOCTL_RESERVED 3 +/** How many sectors constitute a FLASH Erase block */ +#define DISK_IOCTL_GET_ERASE_BLOCK_SZ 4 +/** Commit any cached read/writes to disk */ +#define DISK_IOCTL_CTRL_SYNC 5 + +/** + * @brief Possible return bitmasks for disk_status() + */ + +/** Disk status okay */ +#define DISK_STATUS_OK 0x00 +/** Disk status uninitialized */ +#define DISK_STATUS_UNINIT 0x01 +/** Disk status no media */ +#define DISK_STATUS_NOMEDIA 0x02 +/** Disk status write protected */ +#define DISK_STATUS_WR_PROTECT 0x04 + +struct disk_operations; + +/** + * @brief Disk info + */ +struct disk_info { + /** Internally used list node */ + sys_dnode_t node; + /** Disk name */ + char *name; + /** Disk operations */ + const struct disk_operations *ops; + /** Device associated to this disk */ + const struct device *dev; +}; + +/** + * @brief Disk operations + */ +struct disk_operations { + int (*init)(struct disk_info *disk); + int (*status)(struct disk_info *disk); + int (*read)(struct disk_info *disk, uint8_t *data_buf, + uint32_t start_sector, uint32_t num_sector); + int (*write)(struct disk_info *disk, const uint8_t *data_buf, + uint32_t start_sector, uint32_t num_sector); + int (*ioctl)(struct disk_info *disk, uint8_t cmd, void *buff); +}; + +/** + * @brief Register disk + * + * @param[in] disk Pointer to the disk info structure + * + * @return 0 on success, negative errno code on fail + */ +int disk_access_register(struct disk_info *disk); + +/** + * @brief Unregister disk + * + * @param[in] disk Pointer to the disk info structure + * + * @return 0 on success, negative errno code on fail + */ +int disk_access_unregister(struct disk_info *disk); + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#endif /* ZEPHYR_INCLUDE_DRIVERS_DISK_H_ */