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