unistd.h
5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/****************************************************************************
* Copyright (c) 2015 Mark Charlebois. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#pragma once
/**
* @file
* The declarations in this file are released to DSPAL users and are used to
* make file I/O call's with a device path.
*/
#include "dspal_types.h"
#include <sys/cdefs.h>
#define F_OK 0
#define _SC_CLK_TCK 2
__BEGIN_DECLS
typedef unsigned long useconds_t;
/**
* @brief
* Please refer to the POSIX standard for details.
*/
int usleep(useconds_t usec);
/**
* Close access to the particular port device or bus/peripheral device or file
* This also disables the interrupt on that device if it has been configured so.
* @param fd
* File descriptor returned from the open function.
* @return
* - 0: The bus/port device was successfully closed.
* - TODO: List error codes for all bus/port types.
*/
int close(int fd);
/**
* Requests that data be read from the bus/port device or file associated with
* the fd parameter. In the case of an I2C or SPI bus peripheral the ID of register
* to be read must have been previously written. See the write function
* below for additional information.
* @par Reading from SPI/I2C
* An IOCTL function performing a combined read/write operation for I2C and
* SPI bus peripherals is defined in the def_fs_lib_{bus/port type}.h header file.
*
* @par Reading from GPIO
* This reads the current value, i.e. HIGH or LOW, from the GPIO device associated
* with fd.
*
* @param fd
* File descriptor returned from the open function.
* @param buffer
* Pointer to a character array that will be used to store the accumulated data read
* from the bus/port device.
* @param count
* The length in bytes of the buffer referenced in the buffer parameter.
* In the case of GPIO, count is treated as DON'T CARE.
* @return
* - number of bytes read from fd
* - negative error code on error
* - TODO: List error codes for all bus/port types.
*/
size_t read(int fd, void *buf, size_t count);
/**
* Requests that data be written to the bus/port device or file associated with the
* fd parameter.
* @par Buffer Format for SPI and I2C Bus Devices:
* - SPI and I2C Devices:
* The first byte (or two bytes when addressing 16-bit peripheral devices) of
* this buffer is the register ID on the peripheral device to be written.
*
* @par write to GPIO
* Write the value of the first byte of buffer to GPIO device associated with fd.
*
* @param fd
* File descriptor returned from the open function.
* @param buffer
* Pointer to a character array containing the data to be written to the specified
* bus/port device. For I2C and SPI devices the device ID of the peripheral to
* be written to is specified using the an IOCTL code. See the dev_fs_lib_{bus-type}.h
* files for more information. Also, see the note above about how to specify the
* ID of the register to be written.
* @param count
* number of bytes in buffer to be written to fd
* In the case of GPIO, count is treated as DON'T CARE.
* @return
* - number of bytes written to fd
* - negative error code on error
*/
ssize_t write(int fd, const void *buf, size_t count);
/**
* synchronize a file's in-core state with storage device
* NOTE: this is only applicable to file operation. Calling fsync() on bus
* device has no effect
*
* @param fd
* File descriptor returned from the open function.
*
* @return
* - 0: The fsync operation was successfully processed.
* - -1: on error
* TODO: List error codes for all bus/port types.
*/
int fsync(int fd);
/**
* @brief
* Only supports getting _SC_CLK_TCK
*/
long sysconf(int name);
unsigned int sleep(unsigned int seconds);
__END_DECLS