1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17
18
19 import xdc.rov.ViewInfo;
20
21 import xdc.runtime.IHeap;
22 import xdc.runtime.Error;
23 import ti.sdo.io.DriverTypes;
24 import ti.sdo.utils.List;
25
26 /*!
27 * Generator module
28 *
29 * Using this module clients can simulate a device with an input channel and
30 * an output channel.
31 * Generator channels are used to generate sequences of constants, sine waves,
32 * random noise, or other streams of data defined by a user function.
33 *
34 * When a channel is opened, the user gets to specify a function to simulate
35 * the input channel and a function to simulate the output channel
36 * characteristics.
37 *
38 * The Generator module can be configured to process the io just like
39 * a real driver, where a {@link #submit} call will return pending and
40 * io will be completed in the context of an isr. This mode is called
41 * returnPending.
42 * However the user has to call {@link #simulateIsrFxn} in an isr, Swi or a
43 * Task to support this mode. In simulateIsr, one pending IO Packet for both
44 * channel for all Generator instances is processed.
45 */
46 module Generator inherits ti.sdo.io.IDriver {
47
48 /*! typedef for user specified I/O generators
49 *
50 * Functions of this type get passed the buffer, buffer size and a
51 * function specific argument
52 */
53 typedef Void (*GenFunc)(Ptr, SizeT, UArg);
54
55 /*! Number of channels per generator device.
56 *
57 * one input and one output channel
58 */
59 const Int NUMCHANS = 2;
60
61 /*! Channel parameters used along with open */
62 struct ChanParams {
63 GenFunc userFxn;
64 UArg userArg;
65 Bool returnPending; 66
67 };
68
69 metaonly struct BasicView {
70 String label;
71 };
72
73 metaonly struct GeneratorView {
74 String mode;
75 Bool inUse;
76 Bool returnPending;
77 String callbackFxn[];
78 UArg callbackArg;
79 String userFxn[];
80 UArg userArg;
81 }
82
83 @Facet
84 metaonly config ViewInfo.Instance rovViewInfo =
85 ViewInfo.create({
86 viewMap: [
87 ['Basic', {type: ViewInfo.INSTANCE, viewInitFxn: 'viewInitBasic', structName: 'BasicView'}],
88 ['Data', {type: ViewInfo.INSTANCE_DATA, viewInitFxn: 'viewInitData', structName: 'GeneratorView'}],
89 ]
90 });
91
92 /*!
93 * This function is used to give energy to the Generator
94 * driver to process its IO packets. It simulates real ISR.
95 *
96 * The application needs to call this function within a hwi, swi or
97 * task thread if any channels are opened in {@link #returnPending}
98 * mode.
99 *
100 * The Generator module will process all channels with returnPending set
101 * to true within this function. One packet per channel for all
102 * generator instances gets processed during a single call to this
103 * function.
104 */
105 Void simulateIsr(UArg arg);
106
107 internal:
108
109 struct ChanObj {
110 List.Elem elem;
111 Bool inUse;
112 Bool returnPending;
113 List.Handle pendList;
114 DriverTypes.DoneFxn cbFxn;
115 UArg cbArg;
116 GenFunc userFxn;
117 UArg userArg;
118 };
119
120 struct Instance_State{
121 ChanObj chans[NUMCHANS];
122 };
123
124 struct Module_State {
125 List.Object chanList;
126 }
127 }