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 * This function is used to give energy to the Generator
113 * driver to process its IO packets. It simulates real ISR.
114 *
115 * The application needs to call this function within a hwi, swi or
116 * task thread if any channels are opened in {@link #returnPending}
117 * mode.
118 *
119 * The Generator module will process all channels with returnPending set
120 * to true within this function. One packet per channel for all
121 * generator instances gets processed during a single call to this
122 * function.
123 */
124 Void simulateIsr(UArg arg);
125
126 internal:
127
128 struct ChanObj {
129 List.Elem elem;
130 Bool inUse;
131 Bool returnPending;
132 List.Handle pendList;
133 DriverTypes.DoneFxn cbFxn;
134 UArg cbArg;
135 GenFunc userFxn;
136 UArg userArg;
137 };
138
139 struct Instance_State{
140 ChanObj chans[NUMCHANS];
141 };
142
143 struct Module_State {
144 List.Object chanList;
145 }
146 }
147 148 149
150