source: rtems-docs/bsp_howto/discrete.rst @ 36def91

4.115
Last change on this file since 36def91 was 6d7a4d2, checked in by Chris Johns <chrisj@…>, on 06/17/16 at 05:05:41

Update the BSP howto.

Closes #2590.

  • Property mode set to 100644
File size: 6.7 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3Discrete Driver
4###############
5
6The Discrete driver is responsible for providing an interface to Discrete
7Input/Outputs.  The capabilities provided by this class of device driver are:
8
9- Initialize a Discrete I/O Board
10
11- Open a Particular Discrete Bitfield
12
13- Close a Particular Discrete Bitfield
14
15- Read from a Particular Discrete Bitfield
16
17- Write to a Particular Discrete Bitfield
18
19- Reset DACs
20
21- Reinitialize DACS
22
23Most discrete I/O devices are found on I/O cards that support many bits of
24discrete I/O on a single card.  This driver model is centered on the notion of
25reading bitfields from the card.
26
27There are currently no discrete I/O device drivers included in the RTEMS source
28tree.  The information provided in this chapter is based on drivers developed
29for applications using RTEMS.  It is hoped that this driver model information
30can form the discrete I/O driver model that can be supported in future RTEMS
31distribution.
32
33Major and Minor Numbers
34=======================
35
36The ``major`` number of a device driver is its index in the RTEMS Device
37Address Table.
38
39A ``minor`` number is associated with each device instance managed by a
40particular device driver.  An RTEMS minor number is an ``unsigned32`` entity.
41Convention calls for dividing the bits in the minor number down into categories
42that specify a particular bitfield.  This results in categories like the
43following:
44
45- ``board`` - indicates the board a particular bitfield is located on
46
47- ``word`` - indicates the particular word of discrete bits the bitfield is
48  located within
49
50- ``start`` - indicates the starting bit of the bitfield
51
52- ``width`` - indicates the width of the bitfield
53
54From the above, it should be clear that a single device driver can support
55multiple copies of the same board in a single system.  The minor number is used
56to distinguish the devices.
57
58By providing a way to easily access a particular bitfield from the device
59driver, the application is insulated with knowing how to mask fields in and out
60of a discrete I/O.
61
62Discrete I/O Driver Configuration
63=================================
64
65There is not a standard discrete I/O driver configuration table but some fields
66are common across different drivers.  The discrete I/O driver configuration
67table is typically an array of structures with each structure containing the
68information for a particular board.  The following is a list of the type of
69information normally required to configure an discrete I/O board:
70
71``board_offset``
72    is the base address of a board.
73
74``relay_initial_values``
75    is an array of the values that should be written to each output word on the
76    board during initialization.  This allows the driver to start with the
77    board's output in a known state.
78
79Initialize a Discrete I/O Board
80===============================
81
82At system initialization, the discrete I/O driver's initialization entry point
83will be invoked.  As part of initialization, the driver will perform whatever
84board initializatin is required and then set all outputs to their configured
85initial state.
86
87The discrete I/O driver may register a device name for bitfields of particular
88interest to the system.  Normally this will be restricted to the names of each
89word and, if the driver supports it, an "all words".
90
91Open a Particular Discrete Bitfield
92===================================
93
94This is the driver open call.  Usually this call does nothing other than
95validate the minor number.
96
97With some drivers, it may be necessary to allocate memory when a particular
98device is opened.  If that is the case, then this is often the place to do this
99operation.
100
101Close a Particular Discrete Bitfield
102====================================
103
104This is the driver close call.  Usually this call does nothing.
105
106With some drivers, it may be necessary to allocate memory when a particular
107device is opened.  If that is the case, then this is the place where that
108memory should be deallocated.
109
110Read from a Particular Discrete Bitfield
111========================================
112
113This corresponds to the driver read call.  After validating the minor number
114and arguments, this call reads the indicated bitfield.  A discrete I/O devices
115may have to store the last value written to a discrete output.  If the bitfield
116is output only, saving the last written value gives the appearance that it can
117be read from also.  If the bitfield is input, then it is sampled.
118
119.. note::
120
121   Many discrete inputs have a tendency to bounce.  The application may have to
122   take account for bounces.
123
124The value returned is an ``unsigned32`` number representing the bitfield read.
125This value is stored in the ``argument_block`` passed in to the call.
126
127.. note::
128
129   Some discrete I/O drivers have a special minor number used to access all
130   discrete I/O bits on the board.  If this special minor is used, then the
131   area pointed to by ``argument_block`` must be the correct size.
132
133Write to a Particular Discrete Bitfield
134=======================================
135
136This corresponds to the driver write call.  After validating the minor number
137and arguments, this call writes the indicated device.  If the specified device
138is an ADC, then an error is usually returned.
139
140The value written is an ``unsigned32`` number representing the value to be
141written to the specified bitfield.  This value is stored in the
142``argument_block`` passed in to the call.
143
144.. note::
145
146   Some discrete I/O drivers have a special minor number used to access all
147   discrete I/O bits on the board.  If this special minor is used, then the
148   area pointed to by ``argument_block`` must be the correct size.
149
150Disable Discrete Outputs
151========================
152
153This is one of the IOCTL functions supported by the I/O control device driver
154entry point.  When this IOCTL function is invoked, the discrete outputs are
155disabled.
156
157.. note::
158
159   It may not be possible to disable/enable discrete output on all discrete I/O
160   boards.
161
162Enable Discrete Outputs
163=======================
164
165This is one of the IOCTL functions supported by the I/O control device driver
166entry point.  When this IOCTL function is invoked, the discrete outputs are
167enabled.
168
169.. note::
170
171    It may not be possible to disable/enable discrete output on all discrete
172    I/O boards.
173
174Reinitialize Outputs
175====================
176
177This is one of the IOCTL functions supported by the I/O control device driver
178entry point.  When this IOCTL function is invoked, the discrete outputs are
179rewritten with the configured initial output values.
180
181Get Last Written Values
182=======================
183
184This is one of the IOCTL functions supported by the I/O control device driver
185entry point.  When this IOCTL function is invoked, the following information is
186returned to the caller:
187
188- last value written to the specified output word
189
190- timestamp of when the last write was performed
Note: See TracBrowser for help on using the repository browser.