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 <johann.fischer@nordicsemi.no>
This commit is contained in:
Johann Fischer 2021-02-26 12:48:03 +01:00 committed by Carles Cufí
commit 45d468bfdb
7 changed files with 126 additions and 57 deletions

View file

@ -8,7 +8,7 @@
#include <zephyr/types.h>
#include <sys/__assert.h>
#include <sys/util.h>
#include <disk/disk_access.h>
#include <drivers/disk.h>
#include <errno.h>
#include <init.h>
#include <device.h>

View file

@ -7,7 +7,7 @@
#include <string.h>
#include <zephyr/types.h>
#include <sys/__assert.h>
#include <disk/disk_access.h>
#include <drivers/disk.h>
#include <errno.h>
#include <init.h>
#include <device.h>

View file

@ -10,7 +10,7 @@
LOG_MODULE_REGISTER(sdmmc_spi, CONFIG_SDMMC_LOG_LEVEL);
#include <disk/disk_access.h>
#include <drivers/disk.h>
#include <drivers/gpio.h>
#include <sys/byteorder.h>
#include <drivers/spi.h>

View file

@ -7,7 +7,7 @@
#define DT_DRV_COMPAT st_stm32_sdmmc
#include <devicetree.h>
#include <disk/disk_access.h>
#include <drivers/disk.h>
#include <drivers/clock_control.h>
#include <drivers/clock_control/stm32_clock_control.h>
#include <pinmux/stm32/pinmux_stm32.h>

View file

@ -7,7 +7,7 @@
#define DT_DRV_COMPAT nxp_imx_usdhc
#include <sys/__assert.h>
#include <disk/disk_access.h>
#include <drivers/disk.h>
#include <drivers/gpio.h>
#include <sys/byteorder.h>
#include <soc.h>

View file

@ -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 <kernel.h>
#include <zephyr/types.h>
#include <sys/dlist.h>
#include <drivers/disk.h>
#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

118
include/drivers/disk.h Normal file
View file

@ -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 <kernel.h>
#include <zephyr/types.h>
#include <sys/dlist.h>
#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_ */