OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [syn/] [components/] [sd_card/] [firmware/] [bsp/] [HAL/] [inc/] [sys/] [alt_driver.h] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 alfik
#ifndef __ALT_DRIVER_H__
2
#define __ALT_DRIVER_H__
3
 
4
/******************************************************************************
5
*                                                                             *
6
* License Agreement                                                           *
7
*                                                                             *
8
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA.           *
9
* All rights reserved.                                                        *
10
*                                                                             *
11
* Permission is hereby granted, free of charge, to any person obtaining a     *
12
* copy of this software and associated documentation files (the "Software"),  *
13
* to deal in the Software without restriction, including without limitation   *
14
* the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
15
* and/or sell copies of the Software, and to permit persons to whom the       *
16
* Software is furnished to do so, subject to the following conditions:        *
17
*                                                                             *
18
* The above copyright notice and this permission notice shall be included in  *
19
* all copies or substantial portions of the Software.                         *
20
*                                                                             *
21
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
22
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
23
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
24
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      *
25
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
26
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
27
* DEALINGS IN THE SOFTWARE.                                                   *
28
*                                                                             *
29
* This agreement shall be governed in all respects by the laws of the State   *
30
* of California and by the laws of the United States of America.              *
31
*                                                                             *
32
* Altera does not recommend, suggest or require that this reference design    *
33
* file be used in conjunction or combination with any other product.          *
34
******************************************************************************/
35
 
36
/*
37
 * Macros used to access a driver without HAL file descriptors.
38
 */
39
 
40
/*
41
 * ALT_MODULE_CLASS
42
 *
43
 * This macro returns the module class name for the specified module instance.
44
 * It uses information in the system.h file.
45
 * Neither the instance name or class name are quoted (so that they can
46
 * be used with other pre-processor macros).
47
 *
48
 * Example:
49
 *   Assume the design has an instance of an altera_avalon_uart called uart1.
50
 *   Calling ALT_MODULE_CLASS(uart1) returns altera_avalon_uart.
51
 */
52
 
53
#define ALT_MODULE_CLASS(instance) ALT_MODULE_CLASS_ ## instance
54
 
55
 
56
/*
57
 * ALT_DRIVER_FUNC_NAME
58
 *
59
 *   --> instance               Instance name.
60
 *   --> func                   Function name.
61
 *
62
 * This macro returns the device driver function name of the specified
63
 * module instance for the specified function name.
64
 *
65
 * Example:
66
 *   Assume the design has an instance of an altera_avalon_uart called uart1.
67
 *   Calling ALT_DRIVER_FUNC_NAME(uart1, write) returns
68
 *   altera_avalon_uart_write.
69
 */
70
 
71
#define ALT_DRIVER_FUNC_NAME(instance, func) \
72
  ALT_DRIVER_FUNC_NAME1(ALT_MODULE_CLASS(instance), func)
73
#define ALT_DRIVER_FUNC_NAME1(module_class, func) \
74
  ALT_DRIVER_FUNC_NAME2(module_class, func)
75
#define ALT_DRIVER_FUNC_NAME2(module_class, func) \
76
  module_class ## _ ## func
77
 
78
/*
79
 * ALT_DRIVER_STATE_STRUCT
80
 *
81
 *   --> instance               Instance name.
82
 *
83
 * This macro returns the device driver state type name of the specified
84
 * module instance.
85
 *
86
 * Example:
87
 *   Assume the design has an instance of an altera_avalon_uart called uart1.
88
 *   Calling ALT_DRIVER_STATE_STRUCT(uart1) returns:
89
 *     struct altera_avalon_uart_state_s
90
 *
91
 * Note that the ALT_DRIVER_FUNC_NAME macro is used even though "state" isn't
92
 * really a function but it does match the required naming convention.
93
 */
94
#define ALT_DRIVER_STATE_STRUCT(instance) \
95
    struct ALT_DRIVER_FUNC_NAME(instance, state_s)
96
 
97
/*
98
 * ALT_DRIVER_STATE
99
 *
100
 *   --> instance               Instance name.
101
 *
102
 * This macro returns the device driver state name of the specified
103
 * module instance.
104
 *
105
 * Example:
106
 *   Assume the design has an instance of an altera_avalon_uart called uart1.
107
 *   Calling ALT_DRIVER_STATE(uart1) returns uart1.
108
 */
109
#define ALT_DRIVER_STATE(instance) instance
110
 
111
/*
112
 * ALT_DRIVER_WRITE
113
 *
114
 *   --> instance               Instance name.
115
 *   --> buffer                 Write buffer.
116
 *   --> len                    Length of write buffer data.
117
 *   --> flags                  Control flags (e.g. O_NONBLOCK)
118
 *
119
 * This macro calls the "write" function of the specified driver instance.
120
 */
121
 
122
#define ALT_DRIVER_WRITE_EXTERNS(instance)                                  \
123
    extern ALT_DRIVER_STATE_STRUCT(instance) ALT_DRIVER_STATE(instance);    \
124
    extern int ALT_DRIVER_FUNC_NAME(instance, write)                        \
125
      (ALT_DRIVER_STATE_STRUCT(instance) *, const char *, int, int);
126
 
127
#define ALT_DRIVER_WRITE(instance, buffer, len, flags)                      \
128
    ALT_DRIVER_FUNC_NAME(instance, write)(&ALT_DRIVER_STATE(instance), buffer, len, flags)
129
 
130
 
131
/*
132
 * ALT_DRIVER_READ
133
 *
134
 *   --> instance               Instance name.
135
 *   <-- buffer                 Read buffer.
136
 *   --> len                    Length of read buffer.
137
 *   --> flags                  Control flags (e.g. O_NONBLOCK)
138
 *
139
 * This macro calls the "read" function of the specified driver instance.
140
 */
141
 
142
#define ALT_DRIVER_READ_EXTERNS(instance)                                   \
143
    extern ALT_DRIVER_STATE_STRUCT(instance) ALT_DRIVER_STATE(instance);    \
144
    extern int ALT_DRIVER_FUNC_NAME(instance, read)                         \
145
      (ALT_DRIVER_STATE_STRUCT(instance) *, const char *, int, int);
146
 
147
#define ALT_DRIVER_READ(instance, buffer, len, flags)                       \
148
    ALT_DRIVER_FUNC_NAME(instance, read)(&ALT_DRIVER_STATE(instance), buffer, len, flags)
149
 
150
/*
151
 * ALT_DRIVER_IOCTL
152
 *
153
 *   --> instance               Instance name.
154
 *   --> req                    ioctl request (e.g. TIOCSTIMEOUT)
155
 *   --> arg                    Optional argument (void*)
156
 *
157
 * This macro calls the "ioctl" function of the specified driver instance
158
 */
159
 
160
#define ALT_DRIVER_IOCTL_EXTERNS(instance)                                  \
161
    extern ALT_DRIVER_STATE_STRUCT(instance) ALT_DRIVER_STATE(instance);    \
162
    extern int ALT_DRIVER_FUNC_NAME(instance, ioctl)                        \
163
      (ALT_DRIVER_STATE_STRUCT(instance) *, int, void*);
164
 
165
#define ALT_DRIVER_IOCTL(instance, req, arg)                                \
166
    ALT_DRIVER_FUNC_NAME(instance, ioctl)(&ALT_DRIVER_STATE(instance), req, arg)
167
 
168
#endif /* __ALT_DRIVER_H__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.