OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [i2c/] [m68k/] [mcf52xx/] [current/] [doc/] [mcf52xx_i2c.sgml] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
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
Motorola MCF52xx ColdFire I<superscript>2</superscript>C Bus Driver
38
 
39
40
  
41
    Motorola MCF52xx Coldfire I2C Bus  Driver
42
  
43
  
44
    CYGPKG_DEVS_I2C_MCF52xx
45
    eCos Support for the Motorola Coldfire I2C Bus
46
  
47
 
48
  Description
49
    
50
Several processors in the Motorola ColdFire family come with one or
51
more on-chip I2C bus devices. This package
52
provides an eCos I2C bus driver. It was
53
originally developed on an MCF5280 but should work with any ColdFire
54
processor that uses a compatible bus device. The driver implements the
55
functionality defined by the generic I2C
56
package CYGPKG_IO_I2C.
57
    
58
    
59
The hardware does not support DMA or fifos, so usually a transfer will
60
involve an interrupt for every byte transferred. Since the
61
I2C bus typically runs at 100KHz large
62
transfers will consume much of the available cpu time.
63
    
64
    
65
This package does not provide any cyg_i2c_bus
66
structures. The number of I2C buses varies
67
between ColdFire processors. If multiple buses are available then
68
exactly which one(s) are in use on a given hardware platform depends
69
entirely on that platform. The desired I2C
70
bus speed also depends on the platform, and there may be other issues
71
such as how the processor pins should be set up. Hence it is left to
72
other code, usually the platform HAL, to instantiate the bus
73
structure(s). This driver package supplies the necessary functions and
74
utility macros. Similarly this package does not provide any
75
cyg_i2c_device structures. Which
76
I2C devices are hooked up to which
77
I2C bus is entirely a characteristic of the
78
hardware platform, so again it is up to the platform HAL to
79
instantiate the necessary structures.
80
    
81
    
82
The driver will operate in interrupt-driven mode if interrupts are
83
enabled when a transfer is initiated. Otherwise it will operate in
84
polled mode. This allows the driver to be used in a variety of
85
configurations including inside RedBoot.
86
    
87
  
88
 
89
  Configuration Options
90
    
91
The I2C bus driver package should be loaded
92
automatically when selecting a target containing a suitable ColdFire
93
processor, and it should never be necessary to load the package
94
explicitly. If the application does not use any of the
95
I2C functionality, directly or indirectly,
96
then all the I2C code should be removed at
97
link-time and the application does not suffer any overheads.
98
    
99
    
100
By default the driver assumes a single I2C
101
bus and optimizes for that case. For example options like the ISR
102
vector and priority are handled by compile-time
103
#define's in the platform HAL's exported header
104
files rather than by per-bus structure fields. This helps to reduce
105
both code and data overheads. If the driver should support multiple
106
I2C buses then
107
CYGHWR_DEVS_I2C_MCF52xx_MULTIPLE_BUSES should be
108
enabled. Typically this will be done by the platform HAL using a CDL
109
requires property. If bus instantiation happens
110
outside the platform HAL and hence the HAL's header files do not
111
provide the appropriate definitions, then this configuration option
112
should also be defined.
113
    
114
    
115
The only other configuration options in this package provide control
116
over the compiler flags used to build the driver code.
117
    
118
  
119
 
120
  Defining the Bus and Devices
121
    
122
For most hardware targets the platform HAL will instantiate the
123
cyg_i2c_bus and
124
cyg_i2c_device structures, and it will also
125
initialize the hardware so that the
126
I2C-related pins are connected
127
appropriately. Some development boards have no
128
I2C devices, but the
129
I2C bus signals are accessible via an
130
expansion connector and I2C devices can be
131
put on a daughter board. In such cases it may be necessary for the
132
application to instantiate both the bus and all the device structures.
133
Alternatively the platform HAL may provide a configuration option to
134
enable just the bus, with the devices still left to application code.
135
    
136
    
137
To facilitate bus instantiation the header file 
138
class="headerfile">cyg/io/i2c_mcf52xx.h provides a utility
139
macro CYG_MCF52xx_I2C_BUS. This takes six
140
parameters:
141
    
142
    
143
      
144
The name of the bus, for example
145
hal_dnp5280_i2c_bus. This name will be used when
146
instantiating the I2C devices.
147
      
148
      
149
An initialization function. If no platform-specific initialization is
150
needed then this can be the cyg_mcf52xx_i2c_init
151
function exported by this driver. Otherwise it can be a
152
platform-specific function which, for example, sets up the relevant
153
pins appropriately and then chains into
154
cyg_mcf52xx_i2c_init.
155
      
156
      
157
The base address of the I2C bus. For
158
example on an MCF5282 with the IPSBAR set to its usual value of
159
0x40000000, the I2C bus is at location
160
0x40000300.
161
      
162
      
163
The interrupt vector, for example
164
CYGNUM_HAL_ISR_I2C_IIF on an MCF5282.
165
      
166
      
167
The interrupt priority. Typically this will be a configurable option
168
within the platform HAL.
169
      
170
      
171
A value for the I2C bus's I2FDR register.
172
That register controls the bus speed. Typical bus speeds are 100KHz
173
and 400KHz, depending on the capabilities of the attached devices.
174
There is no simple relationship between the system clock speed, the
175
desired bus speed, and the FDR register. Although the driver could
176
determine the FDR setting using a lookup table and appropriate code,
177
it is better to determine the correct value once during the porting
178
process and avoid unnecessary run-time overheads.
179
      
180
    
181
    
182
For the common case where only a single I2C
183
bus should be supported
184
(CYGHWR_DEVS_I2C_MCF52xx_MULTIPLE_BUSES is
185
disabled), the last four parameters should be provided by preprocessor
186
#define's, typically in 
187
class="headerfile">cyg/hal/plf_io.h which gets
188
#include'd automatically via
189
cyg/hal/hal_io.h. This header can also define the
190
HAL_I2C_EXPORTED_DEVICES macro as per the generic
191
I2C package:
192
    
193
    
194
#include <pkgconf/hal_m68k_dnp5280.h>
195
196
#ifdef CYGHWR_HAL_M68K_DNP5280_I2C
197
#define HAL_MCF52xx_I2C_SINGLETON_BASE   (HAL_MCF52xx_MBAR+HAL_MCF5282_I2C0_BASE)
198
#define HAL_MCF52xx_I2C_SINGLETON_ISRVEC CYGNUM_HAL_ISR_I2C_IIF
199
#define HAL_MCF52xx_I2C_SINGLETON_ISRPRI CYGNUM_HAL_M68K_DNP5280_I2C_ISRPRI
200
#define HAL_MCF52xx_I2C_SINGLETON_FDR    CYGNUM_HAL_M68K_DNP5280_I2C_FDR
201
 
202
#define HAL_I2C_EXPORTED_DEVICES \
203
    extern cyg_i2c_bus hal_dnp5280_i2c_bus;
204
#endif
205
    
206
    
207
On this particular platform the I2C bus is
208
only accessible on an expansion connector so the support is
209
conditional on a configuration option
210
CYGHWR_HAL_M68K_DNP5280_I2C. The interrupt priority
211
and I2FDR values are also controlled by configuration options. On
212
other platforms the I2C support may not be
213
conditional and the priority and/or FDR values may be hard-wired.
214
    
215
    
216
The I2C bus instantiation should happen in
217
an ordinary C or C++ file, typically in the platform HAL. The
218
corresponding object file should go into
219
libtarget.a and the file should only contain
220
I2C-related code to get the maximum benefit
221
of linker garbage collection.
222
    
223
    
224
#include <cyg/infra/cyg_type.h>
225
#include <cyg/hal/hal_io.h>
226
#include <cyg/io/i2c.h>
227
#include <cyg/io/i2c_mcf52xx.h>
228
 
229
static void
230
dnp5280_i2c_init(struct cyg_i2c_bus* bus)
231
{
232
    cyg_uint16   paspar;
233
    // Reset GPIO pins PAS0/1 to their alternative SCL/SDA settings
234
    HAL_READ_UINT16(HAL_MCF5282_IPSBAR + HAL_MCF5282_GPIO_PASPAR, paspar);
235
    paspar &= ~(HAL_MCF5282_GPIO_PASPAR_A0_MASK | HAL_MCF5282_GPIO_PASPAR_A1_MASK);
236
    paspar |= (HAL_MCF5282_GPIO_PASPAR_A0_SCL | HAL_MCF5282_GPIO_PASPAR_A1_SDA);
237
    HAL_WRITE_UINT16(HAL_MCF5282_IPSBAR + HAL_MCF5282_GPIO_PASPAR, paspar);
238
 
239
    // And leave the driver to take care of the rest.
240
    cyg_mcf52xx_i2c_init(bus);
241
}
242
 
243
CYG_MCF52xx_I2C_BUS(hal_dnp5280_i2c_bus,
244
                    &dnp5280_i2c_init,
245
                    HAL_MCF52xx_I2C_SINGLETON_BASE,
246
                    HAL_MCF52xx_I2C_SINGLETON_ISRVEC,
247
                    HAL_MCF52xx_I2C_SINGLETON_ISRPRI,
248
                    HAL_MCF52xx_I2C_SINGLETON_FDR);
249
 
250
    
251
    
252
Obviously if CYGHWR_DEVS_I2C_MCF52xx_MULTIPLE_BUSES
253
is enabled then the singleton macros may not be defined and the
254
appropriate numbers should be used directly. This example uses a
255
custom initialization function which sets up the relevant pins and
256
then chains into the I2C drivers'
257
cyg_mcf52xx_i2c_init function. If the platform
258
HAL has already set up the pins correctly then
259
cyg_mcf52xx_i2c_init could be used directly in
260
the bus instantiation, saving a small amount of code for the custom
261
initialization function.
262
    
263
    
264
I2C device structures can be instantiated
265
in the usual way, for example:
266
    
267
    
268
CYG_I2C_DEVICE(cyg_i2c_wallclock_ds1307,
269
               &hal_dnp5280_i2c_bus,
270
               0x68,
271
               0x00,
272
               CYG_I2C_DEFAULT_DELAY);
273
    
274
  
275
 
276
277

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.