[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_dsp / sio_dev2 / dev2.h
2 /*
3 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37 * ======== dev2.h ========
38 */
40 #ifndef DEV2_
41 #define DEV2_
42 #define DEV2_H_
44 #define xdc_runtime_Error__nolocalnames
45 //#define ti_sdo_ipc_DriverTypes__nolocalnames
47 #include <ti/sysbios/knl/Queue.h>
48 #include <ti/sysbios/knl/Semaphore.h>
50 #include <xdc/runtime/Error.h>
51 //#include <ti/sdo/io/DriverTypes.h>
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
57 #define DEV2_OK (0) /* To replace SYS_OK */
58 #define DEV2_ENOMEM (-1) /* Replace SYS_EALLOC */
59 #define DEV2_EINVAL (-2) /* Replace SYS_EINVAL */
60 #define DEV2_ENODEV (-3) /* Replace SYS_ENODEV */
61 #define DEV2_EBADIO (-4) /* Replace SYS_EBADIO */
63 #define DEV2_INPUT (0)
64 #define DEV2_OUTPUT (1)
65 #define DEV2_MODES (2)
67 /*
68 * These types are used to identify the type of the DEV2 driver
69 * in DEV2_D_devtab[].
70 * WARNING -- These ids must match those defined .h62, etc. files!
71 */
72 #define DEV2_SIOTYPE 0
73 #define DEV2_IOMTYPE 1
74 #define DEV2_OTHERTYPE 2
76 typedef struct DEV2_Obj *DEV2_Handle;
78 //typedef xdc_Bits32 ti_sdo_io_DriverTypes_PacketCmd;
79 typedef xdc_Bits32 DEV2_PacketCmd;
81 /*
82 * DEV2_Frame represents hangers which hold the stream buffers
83 * All the buffer exchange between SIO/DEV2 happens using these frames.
84 *
85 * IMPORTANT NOTE: The DEV2_Frame struct has to match DriverTypes_Packet
86 * The size of type of each field within this struct should match.
87 */
88 typedef struct DEV2_Frame { /* frame object */
89 Queue_Elem link; /* queue link */
90 Ptr addr; /*! buffer address */
91 SizeT origSize; /*! size requested */
92 SizeT size; /*! processed size */
93 Arg arg; /*! arg to be used by end app */
94 DEV2_PacketCmd cmd; /*! command for mini-driver */
95 xdc_runtime_Error_Id error; /*! error id */
96 Arg misc; /*! reserved */
97 Int status; /*! reserved for IOM support */
98 UArg drvArg; /*! reserved for driver */
99 } DEV2_Frame;
101 typedef Int (*DEV2_Tclose)(DEV2_Handle);
102 typedef Int (*DEV2_Tctrl)(DEV2_Handle, Uns, Arg);
103 typedef Int (*DEV2_Tidle)(DEV2_Handle, Bool);
104 typedef Void (*DEV2_Tinit)(Void);
105 typedef Int (*DEV2_Tissue)(DEV2_Handle);
106 typedef Int (*DEV2_Topen)(DEV2_Handle, String);
107 typedef Bool (*DEV2_Tready)(DEV2_Handle, Semaphore_Handle);
108 typedef Int (*DEV2_Treclaim)(DEV2_Handle);
110 /*
111 * DEV2_Fxns represent driver functions template in SIO/DEV2 model
112 */
113 typedef struct DEV2_Fxns {
114 DEV2_Tclose close;
115 DEV2_Tctrl ctrl;
116 DEV2_Tidle idle;
117 DEV2_Tissue issue;
118 DEV2_Topen open;
119 DEV2_Tready ready;
120 DEV2_Treclaim reclaim;
121 } DEV2_Fxns;
123 typedef struct DEV2_Callback { /* DEV2 callback structure */
124 Fxn fxn; /* function */
125 Arg arg0; /* argument 0 */
126 Arg arg1; /* argument 1 */
127 } DEV2_Callback;
129 /*
130 * DEV2_Obj provides interface to DEV2 layer and its part of SIO object.
131 */
132 typedef struct DEV2_Obj { /* must be first field in device object */
133 Queue_Handle todevice; /* downstream frames go here */
134 Queue_Handle fromdevice; /* upstream frames go here */
135 size_t bufsize; /* buffer size */
136 Uns nbufs; /* number of buffers */
137 xdc_runtime_IHeap_Handle bufSeg; /* buffer segment */
138 Int mode; /* DEV2_INPUT/DEV2_OUTPUT */
139 Int devid; /* device id */
140 Ptr params; /* device parameters */
141 Ptr object; /* pointer to device specific object */
142 DEV2_Fxns fxns; /* driver function table */
143 Uns timeout; /* timeout for DEV2_reclaim() */
144 Uns align; /* buffer alignment */
145 DEV2_Callback *callback; /* pointer to callback */
146 } DEV2_Obj;
148 /*
149 * DEV2_Device holds the device attributes as specified by the user
150 * in the GCONF DEV2 template or by the DEV2_createDevice API.
151 */
152 typedef struct DEV2_Device { /* device driver specifier */
153 String name; /* device name */
154 Void *fxns; /* device function table */
155 Int devid; /* device id */
156 Ptr params; /* device parameters */
157 Uns type; /* type of the device */
158 Ptr devp; /* pointer to device global data */
159 } DEV2_Device;
161 typedef struct DEV2_TableElem {
162 Queue_Elem qElem;
163 DEV2_Device device;
164 } DEV2_TableElem;
166 /*
167 * DEV2_Attrs is used while creating the device dynamically
168 */
169 typedef struct DEV2_Attrs{
170 Int devid; /* device id */
171 Ptr params; /* device parameters */
172 Uns type; /* type of the device */
173 Ptr devp; /* pointer to device global data */
174 }DEV2_Attrs;
176 /*
177 * DEV2 function macros make SIO code more readable.
178 */
179 #define DEV2_close(_dev) (*((_dev)->fxns.close))(_dev)
180 #define DEV2_ctrl(_dev,_cmd,_arg) (*((_dev)->fxns.ctrl))(_dev,_cmd,_arg)
181 #define DEV2_idle(_dev,_flush) (*((_dev)->fxns.idle))(_dev,_flush)
182 #define DEV2_issue(_dev) (*((_dev)->fxns.issue))(_dev)
183 #define DEV2_open(_dev,_name) (*((_dev)->fxns.open))(_dev,_name)
184 #define DEV2_ready(_dev,_sem) (*((_dev)->fxns.ready))(_dev,_sem)
185 #define DEV2_reclaim(_dev) (*((_dev)->fxns.reclaim))(_dev)
187 /*
188 * ======== default fxns ========
189 */
190 #define DEV2_CLOSE ((DEV2_Tclose)DEV2_zero)
191 #define DEV2_CTRL ((DEV2_Tctrl)DEV2_ebadio)
192 #define DEV2_EXCHANGE ((DEV2_Tinput)DEV2_ebadio)
193 #define DEV2_IDLE ((DEV2_Tidle)DEV2_zero)
194 #define DEV2_ISSUE ((DEV2_Tissue)DEV2_ebadio)
195 #define DEV2_OPEN ((DEV2_Topen)DEV2_zero)
196 #define DEV2_READY ((DEV2_Tready)DEV2_one)
197 #define DEV2_RECLAIM ((DEV2_Treclaim)DEV2_ebadio)
199 extern Int DEV2_one(void);
200 extern Int DEV2_zero(void);
202 /* for backwards compatibility ... */
203 extern Void DEV2_init(Void);
205 extern Int DEV2_ebadio(DEV2_Handle);
207 extern String DEV2_match(String name, DEV2_Device **driver);
208 extern Void DEV2_find(String name, DEV2_Device **driver);
209 extern DEV2_Frame *DEV2_mkframe(xdc_runtime_IHeap_Handle seg,
210 Uns size, Uns align);
211 extern Void DEV2_rmframe(DEV2_Frame *frame,
212 xdc_runtime_IHeap_Handle seg, Uns size);
213 extern Int DEV2_createDevice(String name, Void *fxns, Fxn initFxn,
214 DEV2_Attrs *attrs);
215 extern Int DEV2_deleteDevice(String name);
217 extern __FAR__ DEV2_Attrs DEV2_ATTRS;
219 extern DEV2_TableElem DEV2_table[];
221 #ifdef __cplusplus
222 }
223 #endif /* extern "C" */
225 #endif /* DEV2_*/