Changeset c85ab23 in rtems for cpukit/libi2c


Ignore:
Timestamp:
Aug 5, 2009, 6:17:12 PM (10 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, master
Children:
21de9dc
Parents:
b053cab
Message:

2009-08-05 Sebastian Huber <sebastian.huber@…>

  • libcsupport/include/rtems/libio_.h, libcsupport/src/fs_null_handlers.c: Null handlers are now const.
  • libi2c/libi2c.c, libi2c/libi2c.h: Documentation. Do not create semaphores on the fly.
  • cpukit/libblock/src/bdpart.c: Fixed format specifier.
  • cpukit/libblock/include/rtems/bdbuf.h, rtems/include/rtems.h, rtems/include/rtems/rtems/asr.h, rtems/include/rtems/rtems/attr.h, rtems/include/rtems/rtems/barrier.h, rtems/include/rtems/rtems/barriermp.h, rtems/include/rtems/rtems/cache.h, rtems/include/rtems/rtems/clock.h, rtems/include/rtems/rtems/config.h, rtems/include/rtems/rtems/dpmem.h, rtems/include/rtems/rtems/event.h, rtems/include/rtems/rtems/eventmp.h, rtems/include/rtems/rtems/eventset.h, rtems/include/rtems/rtems/intr.h, rtems/include/rtems/rtems/message.h, rtems/include/rtems/rtems/modes.h, rtems/include/rtems/rtems/mp.h, rtems/include/rtems/rtems/msgmp.h, rtems/include/rtems/rtems/object.h, rtems/include/rtems/rtems/part.h, rtems/include/rtems/rtems/partmp.h, rtems/include/rtems/rtems/ratemon.h, rtems/include/rtems/rtems/region.h, rtems/include/rtems/rtems/regionmp.h, rtems/include/rtems/rtems/rtemsapi.h, rtems/include/rtems/rtems/sem.h, rtems/include/rtems/rtems/semmp.h, rtems/include/rtems/rtems/signal.h, rtems/include/rtems/rtems/signalmp.h, rtems/include/rtems/rtems/status.h, rtems/include/rtems/rtems/support.h, rtems/include/rtems/rtems/taskmp.h, rtems/include/rtems/rtems/tasks.h, rtems/include/rtems/rtems/timer.h, rtems/include/rtems/rtems/types.h, rtems/inline/rtems/rtems/support.inl: Documentation.
  • include/rtems/irq-extension.h: Documentation. Added API for interrupt servers.
Location:
cpukit/libi2c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libi2c/libi2c.c

    rb053cab rc85ab23  
    111111  rtems_libi2c_bus_t *bush;
    112112  volatile rtems_id mutex;      /* lock this across start -> stop */
    113   volatile short waiting;
    114   volatile char started;
     113  volatile bool started;
    115114  char *name;
    116115} busses[MAX_NO_BUSSES] = { { 0, 0, 0, 0, 0 } };
     
    121120} drvs[MAX_NO_DRIVERS] = { { 0 } };
    122121
    123 static rtems_id libmutex = 0;
     122static rtems_id libmutex = RTEMS_ID_NONE;
    124123
    125124#define LOCK(m)         assert(!rtems_semaphore_obtain((m), RTEMS_WAIT, RTEMS_NO_TIMEOUT))
     
    176175lock_bus (int busno)
    177176{
    178 rtems_status_code sc;
    179 struct i2cbus *bus = &busses[busno];
    180 
    181   LIBLOCK ();
    182   if (!bus->waiting) {
    183         rtems_id m;
    184     /* nobody is holding the bus mutex - it's not there. Create it on the fly */
    185     sc = mutexCreate (rtems_build_name ('i', '2', 'c', '0' + busno), &m);
    186     if ( RTEMS_SUCCESSFUL != sc ) {
    187       LIBUNLOCK ();
    188       rtems_panic (DRVNM "Unable to create bus lock");
    189     } else {
    190           bus->mutex = m;
    191         }
    192   }
    193   /* count number of people waiting on this bus; only the last one deletes the mutex */
    194   bus->waiting++;
    195   LIBUNLOCK ();
     177  struct i2cbus *bus = &busses[busno];
     178
     179  if (bus->mutex == RTEMS_ID_NONE) {
     180    /*
     181     * Nobody is holding the bus mutex - it's not there.  Create it on the fly.
     182     */
     183    LIBLOCK ();
     184    if (bus->mutex == RTEMS_ID_NONE) {
     185      rtems_id m = RTEMS_ID_NONE;
     186      rtems_status_code sc = mutexCreate (
     187        rtems_build_name ('i', '2', 'c', '0' + busno),
     188        &m
     189      );
     190      if (sc != RTEMS_SUCCESSFUL) {
     191        LIBUNLOCK ();
     192        rtems_panic (DRVNM "Unable to create bus lock");
     193        return;
     194      }
     195      bus->mutex = m;
     196    }
     197    LIBUNLOCK ();
     198  }
     199
    196200  /* Now lock this bus */
    197201  LOCK (bus->mutex);
     
    202206{
    203207  struct i2cbus *bus = &busses[busno];
    204   LIBLOCK ();
    205208  UNLOCK (bus->mutex);
    206   if (!--bus->waiting) {
    207     rtems_semaphore_delete (bus->mutex);
    208   }
    209   LIBUNLOCK ();
    210209}
    211210
     
    227226        rtems_libi2c_major = major;
    228227  } else {
    229         libmutex = 0;
     228        libmutex = RTEMS_ID_NONE;
    230229  }
    231230  return rval;
     
    371370             DRVNM "Claiming driver slot failed (rtems status code %i)\n",
    372371             sc);
    373         if ( libmutex )
    374         rtems_semaphore_delete (libmutex);
    375     libmutex = 0;
    376         is_initialized = false;
     372    if (libmutex != RTEMS_ID_NONE) {
     373      rtems_semaphore_delete (libmutex);
     374    }
     375    libmutex = RTEMS_ID_NONE;
     376    is_initialized = false;
    377377    return -1;
    378378  }
     
    418418
    419419
    420   if (!libmutex) {
     420  if (libmutex == RTEMS_ID_NONE) {
    421421    safe_printf ( DRVNM "Library not initialized\n");
    422422    return -RTEMS_NOT_DEFINED;
     
    433433      /* found a free slot */
    434434      busses[i].bush = bus;
    435       busses[i].mutex = 0;
    436       busses[i].waiting = 0;
    437       busses[i].started = 0;
     435      busses[i].mutex = RTEMS_ID_NONE;
     436      busses[i].started = false;
    438437
    439438      if (!name)
     
    498497  } else {
    499498    /* successful 1st start; keep bus locked until stop is sent */
    500     busses[busno].started = 1;
     499    busses[busno].started = true;
    501500  }
    502501  return rval;
     
    514513  rval = bush->ops->send_stop (bush);
    515514
    516   busses[busno].started = 0;
     515  busses[busno].started = false;
    517516
    518517  unlock_bus (busno);
     
    694693  rtems_device_minor_number minor;
    695694
    696   if (!libmutex) {
     695  if (libmutex == RTEMS_ID_NONE) {
    697696    safe_printf ( DRVNM "Library not initialized\n");
    698697    return -RTEMS_NOT_DEFINED;
  • cpukit/libi2c/libi2c.h

    rb053cab rc85ab23  
     1/**
     2 * @file
     3 *
     4 * @ingroup libi2c
     5 *
     6 * @brief I2C library.
     7 */
     8
    19#ifndef _RTEMS_LIBI2C_H
    210#define _RTEMS_LIBI2C_H
     
    5563extern "C" {
    5664#endif
     65
     66/**
     67 * @defgroup libi2c I2C Library
     68 *
     69 * @brief I2C library.
     70 *
     71 * @{
     72 */
    5773
    5874/* Simple I2C driver API */
     
    486502} rtems_libi2c_read_write_async_t;
    487503
     504/** @} */
     505
    488506#ifdef __cplusplus
    489507}
Note: See TracChangeset for help on using the changeset viewer.