1 | .. comment SPDX-License-Identifier: CC-BY-SA-4.0 |
---|
2 | |
---|
3 | .. COMMENT: COPYRIGHT (c) 1988-2002. |
---|
4 | .. COMMENT: On-Line Applications Research Corporation (OAR). |
---|
5 | .. COMMENT: All rights reserved. |
---|
6 | |
---|
7 | Analog Driver |
---|
8 | ############# |
---|
9 | |
---|
10 | The Analog driver is responsible for providing an interface to Digital to |
---|
11 | Analog Converters (DACs) and Analog to Digital Converters (ADCs). The |
---|
12 | capabilities provided by this class of device driver are: |
---|
13 | |
---|
14 | - Initialize an Analog Board |
---|
15 | |
---|
16 | - Open a Particular Analog |
---|
17 | |
---|
18 | - Close a Particular Analog |
---|
19 | |
---|
20 | - Read from a Particular Analog |
---|
21 | |
---|
22 | - Write to a Particular Analog |
---|
23 | |
---|
24 | - Reset DACs |
---|
25 | |
---|
26 | - Reinitialize DACS |
---|
27 | |
---|
28 | Most analog devices are found on I/O cards that support multiple DACs or ADCs |
---|
29 | on a single card. |
---|
30 | |
---|
31 | There are currently no analog device drivers included in the RTEMS source tree. |
---|
32 | The information provided in this chapter is based on drivers developed for |
---|
33 | applications using RTEMS. It is hoped that this driver model information can |
---|
34 | form the basis for a standard analog driver model that can be supported in |
---|
35 | future RTEMS distribution. |
---|
36 | |
---|
37 | Major and Minor Numbers |
---|
38 | ======================= |
---|
39 | |
---|
40 | The ``major`` number of a device driver is its index in the RTEMS Device |
---|
41 | Address Table. |
---|
42 | |
---|
43 | A ``minor`` number is associated with each device instance managed by a |
---|
44 | particular device driver. An RTEMS minor number is an ``unsigned32`` entity. |
---|
45 | Convention calls for dividing the bits in the minor number down into categories |
---|
46 | like the following: |
---|
47 | |
---|
48 | - ``board`` - indicates the board a particular device is located on |
---|
49 | |
---|
50 | - ``port`` - indicates the particular device on a board. |
---|
51 | |
---|
52 | From the above, it should be clear that a single device driver can support |
---|
53 | multiple copies of the same board in a single system. The minor number is used |
---|
54 | to distinguish the devices. |
---|
55 | |
---|
56 | Analog Driver Configuration |
---|
57 | =========================== |
---|
58 | |
---|
59 | There is not a standard analog driver configuration table but some fields are |
---|
60 | common across different drivers. The analog driver configuration table is |
---|
61 | typically an array of structures with each structure containing the information |
---|
62 | for a particular board. The following is a list of the type of information |
---|
63 | normally required to configure an analog board: |
---|
64 | |
---|
65 | ``board_offset`` |
---|
66 | is the base address of a board. |
---|
67 | |
---|
68 | ``DAC_initial_values`` |
---|
69 | is an array of the voltages that should be written to each DAC during |
---|
70 | initialization. This allows the driver to start the board in a known |
---|
71 | state. |
---|
72 | |
---|
73 | Initialize an Analog Board |
---|
74 | ========================== |
---|
75 | |
---|
76 | At system initialization, the analog driver's initialization entry point will |
---|
77 | be invoked. As part of initialization, the driver will perform whatever board |
---|
78 | initialization is required and then set all outputs to their configured initial |
---|
79 | state. |
---|
80 | |
---|
81 | The analog driver may register a device name for each DAC and ADC in the |
---|
82 | system. |
---|
83 | |
---|
84 | Open a Particular Analog |
---|
85 | ======================== |
---|
86 | |
---|
87 | This is the driver open call. Usually this call does nothing other than |
---|
88 | validate the minor number. |
---|
89 | |
---|
90 | With some drivers, it may be necessary to allocate memory when a particular |
---|
91 | device is opened. If that is the case, then this is often the place to do this |
---|
92 | operation. |
---|
93 | |
---|
94 | Close a Particular Analog |
---|
95 | ========================= |
---|
96 | |
---|
97 | This is the driver close call. Usually this call does nothing. |
---|
98 | |
---|
99 | With some drivers, it may be necessary to allocate memory when a particular |
---|
100 | device is opened. If that is the case, then this is the place where that |
---|
101 | memory should be deallocated. |
---|
102 | |
---|
103 | Read from a Particular Analog |
---|
104 | ============================= |
---|
105 | |
---|
106 | This corresponds to the driver read call. After validating the minor number |
---|
107 | and arguments, this call reads the indicated device. Most analog devices store |
---|
108 | the last value written to a DAC. Since DACs are output only devices, saving |
---|
109 | the last written value gives the appearance that DACs can be read from also. |
---|
110 | If the device is an ADC, then it is sampled. |
---|
111 | |
---|
112 | .. note:: |
---|
113 | |
---|
114 | Many boards have multiple analog inputs but only one ADC. On these boards, |
---|
115 | it will be necessary to provide some type of mutual exclusion during reads. |
---|
116 | On these boards, there is a MUX which must be switched before sampling the |
---|
117 | ADC. After the MUX is switched, the driver must delay some short period of |
---|
118 | time (usually microseconds) before the signal is stable and can be sampled. |
---|
119 | To make matters worse, some ADCs cannot respond to wide voltage swings in a |
---|
120 | single sample. On these ADCs, one must do two samples when the voltage |
---|
121 | swing is too large. On a practical basis, this means that the driver |
---|
122 | usually ends up double sampling the ADC on these systems. |
---|
123 | |
---|
124 | The value returned is a single precision floating point number representing the |
---|
125 | voltage read. This value is stored in the ``argument_block`` passed in to the |
---|
126 | call. By returning the voltage, the caller is freed from having to know the |
---|
127 | number of bits in the analog and board dependent conversion algorithm. |
---|
128 | |
---|
129 | Write to a Particular Analog |
---|
130 | ============================ |
---|
131 | |
---|
132 | This corresponds to the driver write call. After validating the minor number |
---|
133 | and arguments, this call writes the indicated device. If the specified device |
---|
134 | is an ADC, then an error is usually returned. |
---|
135 | |
---|
136 | The value written is a single precision floating point number representing the |
---|
137 | voltage to be written to the specified DAC. This value is stored in the |
---|
138 | ``argument_block`` passed in to the call. By passing the voltage to the device |
---|
139 | driver, the caller is freed from having to know the number of bits in the |
---|
140 | analog and board dependent conversion algorithm. |
---|
141 | |
---|
142 | Reset DACs |
---|
143 | ========== |
---|
144 | |
---|
145 | This is one of the IOCTL functions supported by the I/O control device driver |
---|
146 | entry point. When this IOCTL function is invoked, all of the DACs are written |
---|
147 | to 0.0 volts. |
---|
148 | |
---|
149 | Reinitialize DACS |
---|
150 | ================= |
---|
151 | |
---|
152 | This is one of the IOCTL functions supported by the I/O control device driver |
---|
153 | entry point. When this IOCTL function is invoked, all of the DACs are written |
---|
154 | with the initial value configured for this device. |
---|
155 | |
---|
156 | Get Last Written Values |
---|
157 | ======================= |
---|
158 | |
---|
159 | This is one of the IOCTL functions supported by the I/O control device driver |
---|
160 | entry point. When this IOCTL function is invoked, the following information is |
---|
161 | returned to the caller: |
---|
162 | |
---|
163 | - last value written to the specified DAC |
---|
164 | |
---|
165 | - timestamp of when the last write was performed |
---|