Changeset 55a685b in rtems for cpukit/libi2c


Ignore:
Timestamp:
Oct 25, 2007, 4:17:56 PM (12 years ago)
Author:
Thomas Doerfler <Thomas.Doerfler@…>
Branches:
4.10, 4.11, 4.9, master
Children:
abe0cdb1
Parents:
0a23c714
Message:

added SPI support to libi2c
added IRQ support to MPC83xx i2c driver
added mpc83xx spi driver

Location:
cpukit/libi2c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libi2c/libi2c.c

    r0a23c714 r55a685b  
    4747 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
    4848 */
     49/*
     50 * adaptations to also handle SPI devices
     51 * by Thomas Doerfler, embedded brains GmbH, Puchheim, Germany
     52 */
    4953#if HAVE_CONFIG_H
    5054#include "config.h"
     
    5660#include <errno.h>
    5761#include <assert.h>
     62#include <stdarg.h>
    5863
    5964#include <rtems.h>
     
    319324{
    320325  rtems_status_code sc;
    321 
     326  static boolean is_initialized = FALSE;
     327
     328  if (is_initialized) {
     329    /*
     330     * already called before? then skip this step
     331     */
     332    return 0;
     333  }
     334 
    322335  if (!(libmutex = mutexCreate (rtems_build_name ('l', 'I', '2', 'C'))))
    323336    return -1;
     
    332345    return -1;
    333346  }
     347  is_initialized = TRUE;
    334348
    335349  return 0;
     
    429443
    430444rtems_status_code
    431 rtems_libi2c_send_start (uint32_t minor)
     445rtems_libi2c_send_start (rtems_device_minor_number minor)
    432446{
    433447  int rval;
     
    460474
    461475rtems_status_code
    462 rtems_libi2c_send_stop (uint32_t minor)
     476rtems_libi2c_send_stop (rtems_device_minor_number minor)
    463477{
    464478  rtems_status_code rval;
     
    477491
    478492rtems_status_code
    479 rtems_libi2c_send_addr (uint32_t minor, int rw)
     493rtems_libi2c_send_addr (rtems_device_minor_number minor, int rw)
    480494{
    481495  rtems_status_code sc;
     
    492506
    493507int
    494 rtems_libi2c_read_bytes (uint32_t minor, unsigned char *bytes, int nbytes)
     508rtems_libi2c_read_bytes (rtems_device_minor_number minor,
     509                         unsigned char *bytes,
     510                         int nbytes)
    495511{
    496512  int sc;
     
    507523
    508524int
    509 rtems_libi2c_write_bytes (uint32_t minor, unsigned char *bytes, int nbytes)
     525rtems_libi2c_write_bytes (rtems_device_minor_number minor,
     526                          unsigned char *bytes,
     527                          int nbytes)
    510528{
    511529  int sc;
     
    521539}
    522540
     541int
     542rtems_libi2c_ioctl (rtems_device_minor_number minor,
     543                    int cmd,
     544                    ...)
     545{
     546  va_list            ap;
     547  int sc = 0;
     548  void *args;
     549  DECL_CHECKED_BH (busno, bush, minor, -)
     550
     551    if (not_started (busno))
     552    return -RTEMS_NOT_OWNER_OF_RESOURCE;
     553
     554  va_start(ap, cmd);
     555  args = va_arg(ap, void *);
     556
     557  switch(cmd) {
     558    /*
     559     * add ioctls defined for this level here:   
     560     */
     561   
     562  case RTEMS_LIBI2C_IOCTL_START_TFM_READ_WRITE:
     563    /*
     564     * address device, then set transfer mode and perform read_write transfer
     565     */
     566    /*
     567     * perform start/address
     568     */
     569    if (sc == 0) {
     570      sc = rtems_libi2c_send_start (minor);
     571    }
     572    /*
     573     * set tfr mode
     574     */
     575    if (sc == 0) {
     576      sc = bush->ops->ioctl
     577        (bush,
     578         RTEMS_LIBI2C_IOCTL_SET_TFRMODE,
     579         &((rtems_libi2c_tfm_read_write_t *)args)->tfr_mode);
     580    }
     581    /*
     582     * perform read_write
     583     */
     584    if (sc == 0) {
     585      sc = bush->ops->ioctl
     586        (bush,
     587         RTEMS_LIBI2C_IOCTL_READ_WRITE,
     588         &((rtems_libi2c_tfm_read_write_t *)args)->rd_wr);
     589    }
     590    break;
     591  default:
     592    sc = bush->ops->ioctl (bush, cmd, args);
     593    break;
     594  }
     595  if (sc < 0)
     596    rtems_libi2c_send_stop (minor);
     597  return sc;
     598}
     599
    523600static int
    524 do_s_rw (uint32_t minor, unsigned char *bytes, int nbytes, int rw)
     601do_s_rw (rtems_device_minor_number minor,
     602         unsigned char *bytes,
     603         int nbytes,
     604         int rw)
    525605{
    526606  rtems_status_code sc;
     
    550630
    551631int
    552 rtems_libi2c_start_read_bytes (uint32_t minor, unsigned char *bytes,
     632rtems_libi2c_start_read_bytes (rtems_device_minor_number minor,
     633                               unsigned char *bytes,
    553634                               int nbytes)
    554635{
     
    557638
    558639int
    559 rtems_libi2c_start_write_bytes (uint32_t minor, unsigned char *bytes,
     640rtems_libi2c_start_write_bytes (rtems_device_minor_number minor,
     641                                unsigned char *bytes,
    560642                                int nbytes)
    561643{
  • cpukit/libi2c/libi2c.h

    r0a23c714 r55a685b  
    4747 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
    4848 */
     49
    4950#include <rtems.h>
    5051
     
    102103  int (*write_bytes) (rtems_libi2c_bus_t * bushdl, unsigned char *bytes,
    103104                      int nbytes);
     105  /* ioctl misc functions */
     106  int (*ioctl) (rtems_libi2c_bus_t * bushdl,
     107                int   cmd,
     108                void *buffer;
     109                );
    104110} rtems_libi2c_bus_ops_t;
    105111
     
    266272/* Send start, send address and read bytes */
    267273int
    268 rtems_libi2c_start_read_bytes (uint32_t minor, unsigned char *bytes,
     274rtems_libi2c_start_read_bytes (rtems_device_minor_number minor,
     275                               unsigned char *bytes,
    269276                               int nbytes);
    270277
    271278/* Send start, send address and write bytes */
    272279int
    273 rtems_libi2c_start_write_bytes (uint32_t minor, unsigned char *bytes,
     280rtems_libi2c_start_write_bytes (rtems_device_minor_number minor,
     281                                unsigned char *bytes,
    274282                                int nbytes);
     283
     284
     285/* call misc iocontrol function */
     286int
     287rtems_libi2c_ioctl (rtems_device_minor_number minor,
     288                    int cmd,
     289                    ...);
     290/*
     291 * NOTE: any low-level driver ioctl returning a negative
     292 * result for release the bus (perform a STOP condition)
     293 */
     294/*******************************
     295 * defined IOCTLs:
     296 *******************************/
     297#define RTEMS_LIBI2C_IOCTL_READ_WRITE  1
     298/*
     299 * retval = rtems_libi2c_ioctl(rtems_device_minor_number minor,
     300 *                             RTEMS_LIBI2C_IOCTL_READ_WRITE,
     301 *                              rtems_libi2c_read_write_t *arg);
     302 *
     303 * This call performs a simultanous read/write transfer,
     304 * which is possible (and sometimes needed) for SPI devices
     305 *
     306 *   arg is a pointer to a rd_wr info data structure
     307 *
     308 * This call is only needed for SPI devices
     309 */
     310#define RTEMS_LIBI2C_IOCTL_START_TFM_READ_WRITE  2
     311/*
     312 * retval = rtems_libi2c_ioctl(rtems_device_minor_number minor,
     313 *                             RTEMS_LIBI2C_IOCTL_START_READ_WRITE,
     314 *                             unsigned char *rd_buffer,
     315 *                             const unsigned char *wr_buffer,
     316 *                             int byte_cnt,
     317 *                             const rtems_libi2c_tfr_mode_t *tfr_mode_ptr);
     318 *
     319 * This call addresses a slave and then:
     320 * - sets the proper transfer mode,
     321 *  - performs a simultanous  read/write transfer,
     322 *    (which is possible and sometimes needed for SPI devices)
     323 *    NOTE: - if rd_buffer is NULL, receive data will be dropped
     324 *          - if wr_buffer is NULL, bytes with content 0 will transmitted
     325 *
     326 *   rd_buffer is a pointer to a receive buffer (or NULL)
     327 *   wr_buffer is a pointer to the data to be sent (or NULL)
     328 *
     329 * This call is only needed for SPI devices
     330 */
     331
     332#define RTEMS_LIBI2C_IOCTL_SET_TFRMODE 3
     333/*
     334 * retval = rtems_libi2c_ioctl(rtems_device_minor_number minor,
     335 *                             RTEMS_LIBI2C_IOCTL_SET_TFRMODE,
     336 *                             const rtems_libi2c_tfr_mode_t *tfr_mode_ptr);
     337 *
     338 * This call sets an SPI device to the transfer mode needed (baudrate etc.)
     339 *
     340 *   tfr_mode is a pointer to a structure defining the SPI transfer mode needed
     341 *   (see below).
     342 *
     343 * This call is only needed for SPI devices
     344 */
     345
     346/*
     347 * arguemtn data structures for IOCTLs defined above
     348 */
     349typedef struct {
     350  unsigned char       *rd_buf;
     351  const unsigned char *wr_buf;
     352  int                  byte_cnt;
     353} rtems_libi2c_read_write_t;
     354
     355typedef struct {
     356  uint32_t baudrate;       /* maximum bits per second               */
     357                           /* only valid for SPI drivers:           */
     358  uint8_t  bits_per_char;  /* how many bits per byte/word/longword? */
     359  boolean  lsb_first;      /* TRUE: send LSB first                  */
     360  boolean  clock_inv;      /* TRUE: inverted clock (high active)    */
     361  boolean  clock_phs;      /* TRUE: clock starts toggling at start of data tfr */
     362} rtems_libi2c_tfr_mode_t;
     363
     364typedef struct {
     365  rtems_libi2c_tfr_mode_t   tfr_mode;
     366  rtems_libi2c_read_write_t rd_wr;
     367} rtems_libi2c_tfm_read_write_t;
     368
    275369
    276370#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.