4028096b630f9fd0a792e8695fc0ca3dd26c24db
2 /*
3 Copyright (c) 2018, 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 * ======== sio2.h ========
38 * Stream I/O Manager
39 */
41 #ifndef SIO2_
42 #define SIO2_
44 #include <stddef.h>
46 #include <xdc/runtime/IHeap.h>
48 #include <ti/sysbios/knl/Queue.h>
50 #include "dev2.h"
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
56 #define SIO2_OK 0 /* To replace SYS_OK */
57 #define SIO2_ENOMEM (-1) /* To replace SYS_EALLOC */
58 #define SIO2_EINVAL (-2) /* To replace SYS_EINVAL */
59 #define SIO2_ENODEV (-3) /* To replace SYS_ENODEV */
60 #define SIO2_EBADIO (-4) /* Replace SYS_EBADIO */
61 #define SIO2_ETIMEOUT (-5) /* Replace SYS_ETIMEOUT */
62 #define SIO2_EALLOC (-6) /* Replace SYS_EALLOC */
63 #define SIO2_EBUSY (-7) /* Replace SYS_EBUSY */
64 #define SIO2_EMODE (-8) /* Replace SYS_EMODE */
66 #define SIO2_INPUT DEV2_INPUT /* input stream */
67 #define SIO2_OUTPUT DEV2_OUTPUT /* output stream */
69 #define SIO2_STANDARD 0
70 #define SIO2_ISSUERECLAIM 1
72 typedef DEV2_Callback SIO2_Callback; /* for callback mode */
74 typedef struct SIO2_Attrs { /* stream attributes */
75 Int nbufs; /* number of buffers */
76 xdc_runtime_IHeap_Handle bufSeg; /* buffer segment */
77 size_t align; /* buffer alignment */
78 Bool flush; /* TRUE -> don't block in DEV2_idle() */
79 Uns model; /* SIO_STANDARD, SIO_ISSUERECLAIM */
80 Uns timeout; /* passed to all calls to DEV2_reclaim() */
81 SIO2_Callback *callback; /* initializes callback in DEV2_Obj */
82 } SIO2_Attrs;
84 typedef struct SIO2_Obj { /* stream object */
85 DEV2_Obj dobj; /* device object */
86 Bool flush; /* flush */
87 Queue_Struct framelist; /* start of frame list */
88 DEV2_Frame *standardFrame; /* frame for use in SIO_STANDARD model only */
89 Uns model; /* SIO_STANDARD or SIO_ISSUERECLAIM */
90 DEV2_Fxns *pfxns; /* pointer to DEV2_Fxns for static stream init */
91 } SIO2_Obj, *SIO2_Handle;
93 extern __FAR__ SIO2_Attrs SIO2_ATTRS; /* default attributes */
95 extern Int _SIO2_idle(SIO2_Handle stream, Bool flush);
96 #define SIO2_idle(stream) _SIO2_idle(stream, 0)
97 #define SIO2_flush(stream) _SIO2_idle(stream, 1)
99 #define SIO2_ctrl(stream, cmd, arg) DEV2_ctrl((DEV2_Handle)stream, cmd, arg)
100 #define SIO2_ready(stream) DEV2_ready((DEV2_Handle)stream, NULL)
102 #define SIO2_segid(stream) ((stream)->dobj.segid)
103 #define SIO2_bufsize(stream) ((stream)->dobj.bufsize)
104 #define SIO2_nbufs(stream) ((stream)->dobj.nbufs)
106 extern SIO2_Handle SIO2_create(String name, Int mode, size_t size, SIO2_Attrs *attrs);
107 extern Int SIO2_delete(SIO2_Handle stream);
108 extern Int SIO2_get(SIO2_Handle stream, Ptr *buf);
109 extern Int SIO2_staticbuf(SIO2_Handle stream, Ptr *buf);
110 extern Int SIO2_put(SIO2_Handle stream, Ptr *buf, size_t nbytes);
111 extern Uns SIO2_select(SIO2_Handle streamtab[], Int n, Uns timeout);
112 extern Int SIO2_issue(SIO2_Handle stream, Ptr pbuf, size_t nbytes, Arg arg);
113 extern Int SIO2_reclaim(SIO2_Handle stream, Ptr *ppbuf, Arg *parg);
114 extern Int SIO2_reclaimx(SIO2_Handle stream, Ptr *ppbuf, Arg *parg, Int *pfstatus);
116 #ifdef __cplusplus
117 }
118 #endif /* extern "C" */
120 #endif /* SIO2_ */