Changeset c47890c in rtems
- Timestamp:
- 10/26/07 09:51:41 (16 years ago)
- Branches:
- 4.10, 4.11, 4.9, 5, master
- Children:
- 7a4e8e7c
- Parents:
- 83374f3
- Location:
- cpukit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/ChangeLog
r83374f3 rc47890c 1 2007-10-26 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de> 2 3 * libi2c/README-libi2c 4 document structure of libi2c library 5 1 6 2007-10-25 Thomas Doerfler <Thomas.Doerfler@embedded-brains.de> 2 7 -
cpukit/libi2c/README_libi2c
r83374f3 rc47890c 73 73 the i2c controller driver (2<->1) 74 74 75 =================================== 76 Differences between i2c and spi bus 77 =================================== 78 SPI and I2C has many similarities, but also some differences: 79 80 - I2C uses inband addressing (the first bits sent select, which slave 81 device is addressed) while SPI uses dedicated select lines to address 82 a slave device 83 84 - SPI supports combined full duplex read-write transactions while I2C 85 either sends or receives data from a slave device 86 87 - SPI supports a varity of per-slave options, which include: 88 - number of bits per character to transfer 89 - polarity and phase of clock wrt data 90 - clock frequency 91 92 The libi2c API defines a superset of functions to handle both flavours 93 of serial data transmission, but care should be taken not to use 94 features dedicated to the wrong type of serial bus. 95 75 96 76 97 ====================== … … 112 133 bus available on the board. 113 134 114 =================== 115 Device Registration 116 =================== 117 tbd 135 ========================== 136 Device/Driver Registration 137 ========================== 138 Each device attached to an i2c or spi bus must be registered with a 139 call to 140 141 int 142 rtems_libi2c_register_drv (char *name, rtems_libi2c_drv_t * drvtbl, 143 unsigned bus, unsigned i2caddr); 144 145 With this call, libi2c is informed, that: 146 147 - a device is attached to the given "bus" number (which in fact is the 148 return value received from a previous rtems_libi2c_register_bus() 149 call) with the address "i2caddr" 150 151 - the device is managed by a driver, who's entry functions are listed 152 in "drvtbl" 153 154 - the device should be registered with the given "name" in the device 155 tree of the filesystem. 156 157 The call will create a proper minor device number, which has the bus 158 number and i2c_address encoded. This minor number is the return value 159 of the call and is also associated with the filesystem node created 160 for this device. 161 162 Note: If you have multiple devices of the same type, you must register 163 each of them through a separate call (with the same "drvtbl", but 164 different name/bus/i2caddr). 118 165 119 166 ==================================================================== … … 138 185 139 186 These calls perform some parameter checking and then call the 140 appropriate high level i2c device driver function, if available. 187 appropriate high level i2c device driver function, if available, 188 according to the entries in the "drvtbl" passed in the 189 rtems_libi2c_register_drv() call. 141 190 142 191 There are two exceptions: when i2c_read or i2c_write is called with a … … 146 195 147 196 The main reason for the libi2c OS adaption layer is, that it 148 dispatches the RTEMS I/O Manager call es to the proper device driver197 dispatches the RTEMS I/O Manager calls to the proper device driver 149 198 according to the minor number used. 150 199 … … 155 204 Each high level i2c device driver provides a set of functions in the 156 205 rtems_libi2c_drv_t data structure passed the libi2c when the device is 157 registered (see "Device registration" ). These function directly match206 registered (see "Device registration" above). These function directly match 158 207 the RTEMS I/O Mangers calls "open", "close", "read", "write", 159 208 "control", and they are passed the same arguments. Functions not 160 needed may be ommited. 209 needed may be ommited (and replaced by a NULL pointer in 210 rtems_libi2c_drv_t). 161 211 162 212 ====================================================================== 163 213 high level i2c device driver and libi2c low level abstraction layer IF 164 214 ====================================================================== 165 tbd 215 libi2c provides a set of functions for the high level drivers. These 216 functions are: 217 218 rtems_libi2c_send_start(); 219 rtems_libi2c_send_stop(); 220 rtems_libi2c_send_addr(); 221 rtems_libi2c_read_bytes(); 222 rtems_libi2c_write_bytes(); 223 rtems_libi2c_start_read_bytes(); 224 rtems_libi2c_start_write_bytes(); 225 rtems_libi2c_ioctl(); 226 227 Please look into libi2c.h for the proper parameters and return codes. 228 229 These functions perform the proper i2c operations when called. 230 231 A typical access sequence for the I2C bus would be: 232 233 rtems_libi2c_send_start(); 234 rtems_libi2c_send_addr(); 235 rtems_libi2c_write_bytes(); 236 rtems_libi2c_send_stop(); 237 238 Alternatively, the rtems_libi2c_write_bytes() call could be relpaced 239 with a 240 rtems_libi2c_read_bytes() 241 242 call or a sequence of multiple calls. 243 244 Note: rtems_libi2c_send_start() locks the i2c/spi bus used, so no other 245 device can use this i2c/spi bus, until rtems_libi2c_send_stop() function 246 is called for the same device. 247 248 Special provisions for SPI devices: 249 =================================== 250 For SPI devices and their drivers, the libi2c interface is used 251 slightly differently: 252 253 rtems_libi2c_send_start() will lock access to the SPI bus, but has no 254 effect on the hardware bus interface. 255 256 rtems_libi2c_ioctl(...,RTEMS_LIBI2C_IOCTL_SET_TFRMODE,...) will set 257 the transfer mode (bit rate, clock phase and polaritiy, bits per 258 char...) according to the rtems_libi2c_tfr_mode_t structure passed in. 259 260 rtems_libi2c_send_addr() will activate the proper select line to 261 address a certain SPI device. The correspondance between an address 262 and the select line pulled is BSP specific. 263 264 rtems_libi2c_send_stop(); will deactivate the address line and unlock 265 the bus. 266 267 A typical access sequence for the SPI bus would be: 268 269 rtems_libi2c_send_start(); 270 rtems_libi2c_ioctl(...,RTEMS_LIBI2C_IOCTL_SET_TFRMODE,...); 271 rtems_libi2c_send_addr(); 272 rtems_libi2c_write_bytes(); 273 rtems_libi2c_send_stop(); 274 275 Alternatively, the rtems_libi2c_write_bytes() call could be relpaced 276 with a 277 rtems_libi2c_read_bytes() 278 or a 279 rtems_libi2c_ioctl(...,RTEMS_LIBI2C_IOCTL_READ_WRITE,...) 280 call or a sequence of multiple calls. 166 281 167 282 ==================================================================== 168 283 libi2c low level abstraction layer and i2c controller driver IF 169 284 ==================================================================== 170 tbd 171 172 Differences between i2c and spi device drivers 173 ================================================== 174 tbd 175 176 Differences between i2c and spi controller drivers 177 ================================================== 178 tbd 285 Each low level i2c/spi driver must provide a set of bus_ops functions 286 as defined in the rtems_libi2c_bus_ops_t structure. 287 288 typedef struct rtems_libi2c_bus_ops_ 289 { 290 /* Initialize the bus; might be called again to reset the bus driver */ 291 rtems_status_code (*init) (rtems_libi2c_bus_t * bushdl); 292 /* Send start condition */ 293 rtems_status_code (*send_start) (rtems_libi2c_bus_t * bushdl); 294 /* Send stop condition */ 295 rtems_status_code (*send_stop) (rtems_libi2c_bus_t * bushdl); 296 /* initiate transfer from (rw!=0) or to a device */ 297 rtems_status_code (*send_addr) (rtems_libi2c_bus_t * bushdl, 298 uint32_t addr, int rw); 299 /* read a number of bytes */ 300 int (*read_bytes) (rtems_libi2c_bus_t * bushdl, unsigned char *bytes, 301 int nbytes); 302 /* write a number of bytes */ 303 int (*write_bytes) (rtems_libi2c_bus_t * bushdl, unsigned char *bytes, 304 int nbytes); 305 /* ioctl misc functions */ 306 int (*ioctl) (rtems_libi2c_bus_t * bushdl, 307 int cmd, 308 void *buffer; 309 ); 310 } rtems_libi2c_bus_ops_t; 311 312 Each of these functions performs the corresponding function to the i2c 313 bus. 314 315 Special provisions for SPI devices: 316 =================================== 317 For SPI busses, special behaviour is required: 318 319 (*send_start) (rtems_libi2c_bus_t * bushdl) 320 normally is an empty function. 321 322 (*send_addr) (rtems_libi2c_bus_t * bushdl, uint32_t addr, int rw) 323 will activate the SPI select line matching to addr. 324 325 (*send_stop) (rtems_libi2c_bus_t * bushdl) 326 will deactivate the SPI select line 327 328 (*ioctl(...,RTEMS_LIBI2C_IOCTL_SET_TFRMODE,...) 329 will set the transfer mode (bit rate, clock phase and 330 polaritiy, bits per char...) according to the 331 rtems_libi2c_tfr_mode_t structure passed in. 332 333 (*ioctl(...,RTEMS_LIBI2C_IOCTL_READ_WRITE,...) 334 will send and receive data at the same time. 335 336 Note: 337 338 - low-level I2C drivers normally are specific to the master 339 device, but independent from the board hardware. So in many cases they 340 can totally reside in libcpu or libchip. 341 342 - low-level SPI drivers are mostly board independent, but the 343 addressing is board/BSP dependent. Therefore the (*send_start), 344 (*send_addr) and (*send_stop) functions are typically defined in the 345 BSP. The rest of the functions can reside in libcpu or libchip.
Note: See TracChangeset
for help on using the changeset viewer.