Jithu Joseph | 383d9b7 | 2016-10-20 19:06:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Intel Corporation. |
| 3 | * |
David B. Kinder | ac74d8b | 2017-01-18 17:01:01 -0800 | [diff] [blame] | 4 | * SPDX-License-Identifier: Apache-2.0 |
Jithu Joseph | 383d9b7 | 2016-10-20 19:06:35 -0700 | [diff] [blame] | 5 | */ |
| 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 Gala | 7890816 | 2017-04-19 10:32:08 -0500 | [diff] [blame] | 20 | #include <zephyr/types.h> |
Jithu Joseph | 383d9b7 | 2016-10-20 19:06:35 -0700 | [diff] [blame] | 21 | |
| 22 | #ifdef __cplusplus |
| 23 | extern "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 Joseph | 383d9b7 | 2016-10-20 19:06:35 -0700 | [diff] [blame] | 32 | /* 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 Hope | cff1605 | 2017-12-31 18:15:16 +0100 | [diff] [blame] | 37 | /* 3 is reserved. It used to be DISK_IOCTL_GET_DISK_SIZE */ |
| 38 | |
Jithu Joseph | 383d9b7 | 2016-10-20 19:06:35 -0700 | [diff] [blame] | 39 | /* 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. Kinder | 8b986d7 | 2017-04-18 15:56:26 -0700 | [diff] [blame] | 46 | * @brief perform any initialization |
Jithu Joseph | 383d9b7 | 2016-10-20 19:06:35 -0700 | [diff] [blame] | 47 | * |
| 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 | */ |
| 53 | int 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 | */ |
| 62 | int 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 Gala | cc334c7 | 2017-04-21 10:55:34 -0500 | [diff] [blame] | 75 | int disk_access_read(u8_t *data_buf, u32_t start_sector, |
| 76 | u32_t num_sector); |
Jithu Joseph | 383d9b7 | 2016-10-20 19:06:35 -0700 | [diff] [blame] | 77 | |
| 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 Gala | cc334c7 | 2017-04-21 10:55:34 -0500 | [diff] [blame] | 89 | int disk_access_write(const u8_t *data_buf, u32_t start_sector, |
| 90 | u32_t num_sector); |
Jithu Joseph | 383d9b7 | 2016-10-20 19:06:35 -0700 | [diff] [blame] | 91 | |
| 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 Gala | cc334c7 | 2017-04-21 10:55:34 -0500 | [diff] [blame] | 101 | int disk_access_ioctl(u8_t cmd, void *buff); |
Jithu Joseph | 383d9b7 | 2016-10-20 19:06:35 -0700 | [diff] [blame] | 102 | |
| 103 | |
| 104 | #ifdef __cplusplus |
| 105 | } |
| 106 | #endif |
| 107 | |
| 108 | #endif /* _DISK_ACCESS_H_ */ |