blob: f62342f5c9165d6d7f285967f51d7a79e6ec1219 [file] [log] [blame]
Jithu Joseph383d9b72016-10-20 19:06:35 -07001/*
2 * Copyright (c) 2016 Intel Corporation.
3 *
David B. Kinderac74d8b2017-01-18 17:01:01 -08004 * SPDX-License-Identifier: Apache-2.0
Jithu Joseph383d9b72016-10-20 19:06:35 -07005 */
6
7/**
8 * @file
9 * @brief Disk Access layer APIs and defines
10 *
11 * This file contains APIs for disk access. Apart from disks, various
12 * other storage media like Flash and RAM disks may implement this interface to
13 * be used by various higher layers(consumers) like USB Mass storage
14 * and Filesystems.
15 */
16
17#ifndef _DISK_ACCESS_H_
18#define _DISK_ACCESS_H_
19
Kumar Gala78908162017-04-19 10:32:08 -050020#include <zephyr/types.h>
Jithu Joseph383d9b72016-10-20 19:06:35 -070021
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/* Possible Cmd Codes for disk_ioctl() */
27
28/* Get the number of sectors in the disk */
29#define DISK_IOCTL_GET_SECTOR_COUNT 1
30/* Get the size of a disk SECTOR in bytes */
31#define DISK_IOCTL_GET_SECTOR_SIZE 2
Jithu Joseph383d9b72016-10-20 19:06:35 -070032/* How many sectors constitute a FLASH Erase block */
33#define DISK_IOCTL_GET_ERASE_BLOCK_SZ 4
34/* Commit any cached read/writes to disk */
35#define DISK_IOCTL_CTRL_SYNC 5
36
Michael Hopecff16052017-12-31 18:15:16 +010037/* 3 is reserved. It used to be DISK_IOCTL_GET_DISK_SIZE */
38
Jithu Joseph383d9b72016-10-20 19:06:35 -070039/* Possible return bitmasks for disk_status() */
40#define DISK_STATUS_OK 0x00
41#define DISK_STATUS_UNINIT 0x01
42#define DISK_STATUS_NOMEDIA 0x02
43#define DISK_STATUS_WR_PROTECT 0x04
44
45/*
David B. Kinder8b986d72017-04-18 15:56:26 -070046 * @brief perform any initialization
Jithu Joseph383d9b72016-10-20 19:06:35 -070047 *
48 * This call is made by the consumer before doing any IO calls so that the
49 * disk or the backing device can do any initialization.
50 *
51 * @return 0 on success, negative errno code on fail
52 */
53int disk_access_init(void);
54
55/*
56 * @brief Get the status of disk
57 *
58 * This call is used to get the status of the disk
59 *
60 * @return DISK_STATUS_OK or other DISK_STATUS_*s
61 */
62int disk_access_status(void);
63
64/*
65 * @brief read data from disk
66 *
67 * Function to read data from disk to a memory buffer.
68 *
69 * @param[in] data_buf Pointer to the memory buffer to put data.
70 * @param[in] start_sector Start disk sector to read from
71 * @param[in] num_sector Number of disk sectors to read
72 *
73 * @return 0 on success, negative errno code on fail
74 */
Kumar Galacc334c72017-04-21 10:55:34 -050075int disk_access_read(u8_t *data_buf, u32_t start_sector,
76 u32_t num_sector);
Jithu Joseph383d9b72016-10-20 19:06:35 -070077
78/*
79 * @brief write data to disk
80 *
81 * Function write data from memory buffer to disk.
82 *
83 * @param[in] data_buf Pointer to the memory buffer
84 * @param[in] start_sector Start disk sector to write to
85 * @param[in] num_sector Number of disk sectors to write
86 *
87 * @return 0 on success, negative errno code on fail
88 */
Kumar Galacc334c72017-04-21 10:55:34 -050089int disk_access_write(const u8_t *data_buf, u32_t start_sector,
90 u32_t num_sector);
Jithu Joseph383d9b72016-10-20 19:06:35 -070091
92/*
93 * @brief Get/Configure disk parameters
94 *
95 * Function to get disk parameters and make any special device requests.
96 *
97 * @param[in] cmd DISK_IOCTL_* code describing the request
98 *
99 * @return 0 on success, negative errno code on fail
100 */
Kumar Galacc334c72017-04-21 10:55:34 -0500101int disk_access_ioctl(u8_t cmd, void *buff);
Jithu Joseph383d9b72016-10-20 19:06:35 -0700102
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif /* _DISK_ACCESS_H_ */