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 import xdc.rov.ViewInfo;
42
43 import xdc.runtime.IHeap;
44 import xdc.runtime.Error;
45 import ti.sdo.io.DriverTypes;
46 import ti.sdo.utils.List;
47
48 /*!
49 * Generator module
50 *
51 * Using this module clients can simulate a device with an input channel and
52 * an output channel.
53 * Generator channels are used to generate sequences of constants, sine waves,
54 * random noise, or other streams of data defined by a user function.
55 *
56 * When a channel is opened, the user gets to specify a function to simulate
57 * the input channel and a function to simulate the output channel
58 * characteristics.
59 *
60 * The Generator module can be configured to process the io just like
61 * a real driver, where a {@link #submit} call will return pending and
62 * io will be completed in the context of an isr. This mode is called
63 * returnPending.
64 * However the user has to call {@link #simulateIsrFxn} in an isr, Swi or a
65 * Task to support this mode. In simulateIsr, one pending IO Packet for both
66 * channel for all Generator instances is processed.
67 */
68 module Generator inherits ti.sdo.io.IDriver {
69
70 /*! typedef for user specified I/O generators
71 *
72 * Functions of this type get passed the buffer, buffer size and a
73 * function specific argument
74 */
75 typedef Void (*GenFunc)(Ptr, SizeT, UArg);
76
77 /*! Number of channels per generator device.
78 *
79 * one input and one output channel
80 */
81 const Int NUMCHANS = 2;
82
83 /*! Channel parameters used along with open */
84 struct ChanParams {
85 GenFunc userFxn;
86 UArg userArg;
87 Bool returnPending; 88
89 };
90
91 metaonly struct BasicView {
92 String label;
93 };
94
95 metaonly struct GeneratorView {
96 String mode;
97 Bool inUse;
98 Bool returnPending;
99 String callbackFxn[];
100 UArg callbackArg;
101 String userFxn[];
102 UArg userArg;
103 }
104
105 @Facet
106 metaonly config ViewInfo.Instance rovViewInfo =
107 ViewInfo.create({
108 viewMap: [
109 ['Basic', {type: ViewInfo.INSTANCE, viewInitFxn: 'viewInitBasic', structName: 'BasicView'}],
110 ['Data', {type: ViewInfo.INSTANCE_DATA, viewInitFxn: 'viewInitData', structName: 'GeneratorView'}],
111 ]
112 });
113
114
115 /*!
116 * Error raised when NULL chanParams is specified.
117 */
118 config Error.Id E_nullParams = {
119 msg: "E_nullParams: chanParams is null."
120 };
121
122 /*!
123 * This function is used to give energy to the Generator
124 * driver to process its IO packets. It simulates real ISR.
125 *
126 * The application needs to call this function within a hwi, swi or
127 * task thread if any channels are opened in {@link #returnPending}
128 * mode.
129 *
130 * The Generator module will process all channels with returnPending set
131 * to true within this function. One packet per channel for all
132 * generator instances gets processed during a single call to this
133 * function.
134 */
135 Void simulateIsr(UArg arg);
136
137 internal:
138
139 struct ChanObj {
140 List.Elem elem;
141 Bool inUse;
142 Bool returnPending;
143 List.Handle pendList;
144 DriverTypes.DoneFxn cbFxn;
145 UArg cbArg;
146 GenFunc userFxn;
147 UArg userArg;
148 };
149
150 struct Instance_State{
151 ChanObj chans[NUMCHANS];
152 };
153
154 struct Module_State {
155 List.Object chanList;
156 }
157 }