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. */
49typedef 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 */
53 DISK_STATUS_ERROR = 0x08 /**< Device error */
55
56/** Generic disk I/O control commands. */
57typedef enum {
58 DISK_IOCTL_CTRL_SYNC, /**< Synchronize the cached writes to persistent storage */
59 DISK_IOCTL_GET_SECTOR_COUNT, /**< Get the sector count through the \c uint32_t pointed to by \c buff */
60 DISK_IOCTL_GET_SECTOR_SIZE, /**< Get the sector size through the \c uint16_t pointed to by \c buff */
61 DISK_IOCTL_GET_BLOCK_SIZE, /**< Get the erase block size (in sectors) through the \c uint32_t pointed to by \c buff */
62 DISK_IOCTL_CTRL_TRIM /**< Trim the sector range within the \c uint32_t boundaries pointed to by \c buff */
64
65/** Disk access result codes. */
66typedef enum {
67 DISK_RESULT_OK, /**< Success */
68 DISK_RESULT_IO_ERROR, /**< Unrecoverable I/O error */
69 DISK_RESULT_WR_PROTECTED, /**< Write-protected medium */
70 DISK_RESULT_NO_INIT, /**< Device not initialized */
71 DISK_RESULT_INVALID_ARG /**< Invalid argument */
73
74/** Disk driver API structure. */
76 /** Get device status. */
77 disk_status_t (*status)(uint8_t dev);
78
79 /** Initialize device. */
80 disk_status_t (*initialize)(uint8_t dev);
81
82 /** Read sector(s). */
83 disk_result_t (*read)(uint8_t dev, void *buff, uint32_t sector,
84 uint32_t count);
85
86 /** Write sector(s). */
87 disk_result_t (*write)(uint8_t dev, const void *buff, uint32_t sector,
88 uint32_t count);
89
90 /** Control device-specific features. */
91 disk_result_t (*ioctl)(uint8_t dev, uint8_t cmd, void *buff);
92};
93
94#endif /* DISK_H_ */
95
96/**
97 * @}
98 * @}
99 */
static volatile uint64_t count
Num.
Definition: clock.c:50
disk_result_t
Disk access result codes.
Definition: disk.h:66
disk_ioctl_t
Generic disk I/O control commands.
Definition: disk.h:57
disk_status_t
Disk status flags.
Definition: disk.h:49
@ DISK_RESULT_IO_ERROR
Unrecoverable I/O error.
Definition: disk.h:68
@ DISK_RESULT_OK
Success.
Definition: disk.h:67
@ DISK_RESULT_INVALID_ARG
Invalid argument.
Definition: disk.h:71
@ DISK_RESULT_WR_PROTECTED
Write-protected medium.
Definition: disk.h:69
@ DISK_RESULT_NO_INIT
Device not initialized.
Definition: disk.h:70
@ DISK_IOCTL_GET_SECTOR_SIZE
Get the sector size through the uint16_t pointed to by buff.
Definition: disk.h:60
@ DISK_IOCTL_GET_BLOCK_SIZE
Get the erase block size (in sectors) through the uint32_t pointed to by buff.
Definition: disk.h:61
@ DISK_IOCTL_GET_SECTOR_COUNT
Get the sector count through the uint32_t pointed to by buff.
Definition: disk.h:59
@ DISK_IOCTL_CTRL_SYNC
Synchronize the cached writes to persistent storage.
Definition: disk.h:58
@ DISK_IOCTL_CTRL_TRIM
Trim the sector range within the uint32_t boundaries pointed to by buff.
Definition: disk.h:62
@ DISK_STATUS_WRITABLE
Writable medium.
Definition: disk.h:52
@ DISK_STATUS_INIT
Device initialized and ready to work.
Definition: disk.h:50
@ DISK_STATUS_DISK
Medium present in the drive.
Definition: disk.h:51
@ DISK_STATUS_ERROR
Device error.
Definition: disk.h:53
Disk driver API structure.
Definition: disk.h:75
disk_result_t(* read)(uint8_t dev, void *buff, uint32_t sector, uint32_t count)
Read sector(s).
Definition: disk.h:83
disk_status_t(* status)(uint8_t dev)
Get device status.
Definition: disk.h:77
disk_status_t(* initialize)(uint8_t dev)
Initialize device.
Definition: disk.h:80
disk_result_t(* ioctl)(uint8_t dev, uint8_t cmd, void *buff)
Control device-specific features.
Definition: disk.h:91
disk_result_t(* write)(uint8_t dev, const void *buff, uint32_t sector, uint32_t count)
Write sector(s).
Definition: disk.h:87