Contiki-NG
disk.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Benoît Thébaudeau <benoit@wsystem.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 /**
32  * \addtogroup dev
33  * @{
34  *
35  * \defgroup disk Disk device drivers
36  *
37  * Documentation for all the disk device drivers.
38  * @{
39  *
40  * \file
41  * Header file defining the disk device driver API.
42  */
43 #ifndef DISK_H_
44 #define DISK_H_
45 
46 #include <stdint.h>
47 
48 /** Disk status flags. */
49 typedef enum {
50  DISK_STATUS_INIT = 0x01, /**< Device initialized and ready to work */
51  DISK_STATUS_DISK = 0x02, /**< Medium present in the drive */
52  DISK_STATUS_WRITABLE = 0x04 /**< Writable medium */
54 
55 /** Generic disk I/O control commands. */
56 typedef enum {
57  DISK_IOCTL_CTRL_SYNC, /**< Synchronize the cached writes to persistent storage */
58  DISK_IOCTL_GET_SECTOR_COUNT, /**< Get the sector count through the \c uint32_t pointed to by \c buff */
59  DISK_IOCTL_GET_SECTOR_SIZE, /**< Get the sector size through the \c uint16_t pointed to by \c buff */
60  DISK_IOCTL_GET_BLOCK_SIZE, /**< Get the erase block size (in sectors) through the \c uint32_t pointed to by \c buff */
61  DISK_IOCTL_CTRL_TRIM /**< Trim the sector range within the \c uint32_t boundaries pointed to by \c buff */
62 } disk_ioctl_t;
63 
64 /** Disk access result codes. */
65 typedef enum {
66  DISK_RESULT_OK, /**< Success */
67  DISK_RESULT_IO_ERROR, /**< Unrecoverable I/O error */
68  DISK_RESULT_WR_PROTECTED, /**< Write-protected medium */
69  DISK_RESULT_NO_INIT, /**< Device not initialized */
70  DISK_RESULT_INVALID_ARG /**< Invalid argument */
72 
73 /** Disk driver API structure. */
74 struct disk_driver {
75  /** Get device status. */
76  disk_status_t (*status)(uint8_t dev);
77 
78  /** Initialize device. */
79  disk_status_t (*initialize)(uint8_t dev);
80 
81  /** Read sector(s). */
82  disk_result_t (*read)(uint8_t dev, void *buff, uint32_t sector,
83  uint32_t count);
84 
85  /** Write sector(s). */
86  disk_result_t (*write)(uint8_t dev, const void *buff, uint32_t sector,
87  uint32_t count);
88 
89  /** Control device-specific features. */
90  disk_result_t (*ioctl)(uint8_t dev, uint8_t cmd, void *buff);
91 };
92 
93 #endif /* DISK_H_ */
94 
95 /**
96  * @}
97  * @}
98  */
static volatile uint64_t count
Num.
Definition: clock.c:50
disk_status_t(* status)(uint8_t dev)
Get device status.
Definition: disk.h:76
Invalid argument.
Definition: disk.h:70
Disk driver API structure.
Definition: disk.h:74
disk_result_t(* ioctl)(uint8_t dev, uint8_t cmd, void *buff)
Control device-specific features.
Definition: disk.h:90
Synchronize the cached writes to persistent storage.
Definition: disk.h:57
disk_result_t
Disk access result codes.
Definition: disk.h:65
disk_status_t
Disk status flags.
Definition: disk.h:49
Write-protected medium.
Definition: disk.h:68
Device not initialized.
Definition: disk.h:69
disk_result_t(* write)(uint8_t dev, const void *buff, uint32_t sector, uint32_t count)
Write sector(s).
Definition: disk.h:86
disk_ioctl_t
Generic disk I/O control commands.
Definition: disk.h:56
disk_status_t(* initialize)(uint8_t dev)
Initialize device.
Definition: disk.h:79
Writable medium.
Definition: disk.h:52
disk_result_t(* read)(uint8_t dev, void *buff, uint32_t sector, uint32_t count)
Read sector(s).
Definition: disk.h:82
Get the sector count through the uint32_t pointed to by buff.
Definition: disk.h:58
Medium present in the drive.
Definition: disk.h:51
Trim the sector range within the uint32_t boundaries pointed to by buff.
Definition: disk.h:61
Success.
Definition: disk.h:66
Unrecoverable I/O error.
Definition: disk.h:67
Get the sector size through the uint16_t pointed to by buff.
Definition: disk.h:59
Device initialized and ready to work.
Definition: disk.h:50
Get the erase block size (in sectors) through the uint32_t pointed to by buff.
Definition: disk.h:60