diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2009-08-05 18:17:12 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2009-08-05 18:17:12 +0000 |
commit | c85ab23ab7169b2c7a30f3d747b5f6339bc4a6e9 (patch) | |
tree | 3d2d2e54047e6998e8d5bab5c647aedc53807644 /cpukit/libi2c | |
parent | b053cab093896ec765294a3ed109670f94063036 (diff) |
2009-08-05 Sebastian Huber <sebastian.huber@embedded-brains.de>
* 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.
Diffstat (limited to 'cpukit/libi2c')
-rw-r--r-- | cpukit/libi2c/libi2c.c | 71 | ||||
-rw-r--r-- | cpukit/libi2c/libi2c.h | 18 |
2 files changed, 53 insertions, 36 deletions
diff --git a/cpukit/libi2c/libi2c.c b/cpukit/libi2c/libi2c.c index 2d54a640ed..c07a03d92d 100644 --- a/cpukit/libi2c/libi2c.c +++ b/cpukit/libi2c/libi2c.c @@ -110,8 +110,7 @@ static struct i2cbus { rtems_libi2c_bus_t *bush; volatile rtems_id mutex; /* lock this across start -> stop */ - volatile short waiting; - volatile char started; + volatile bool started; char *name; } busses[MAX_NO_BUSSES] = { { 0, 0, 0, 0, 0 } }; @@ -120,7 +119,7 @@ static struct rtems_libi2c_drv_t *drv; } drvs[MAX_NO_DRIVERS] = { { 0 } }; -static rtems_id libmutex = 0; +static rtems_id libmutex = RTEMS_ID_NONE; #define LOCK(m) assert(!rtems_semaphore_obtain((m), RTEMS_WAIT, RTEMS_NO_TIMEOUT)) #define UNLOCK(m) rtems_semaphore_release((m)) @@ -175,24 +174,29 @@ mutexCreate (rtems_name nm, rtems_id *pm) static void lock_bus (int busno) { -rtems_status_code sc; -struct i2cbus *bus = &busses[busno]; + struct i2cbus *bus = &busses[busno]; - LIBLOCK (); - if (!bus->waiting) { - rtems_id m; - /* nobody is holding the bus mutex - it's not there. Create it on the fly */ - sc = mutexCreate (rtems_build_name ('i', '2', 'c', '0' + busno), &m); - if ( RTEMS_SUCCESSFUL != sc ) { - LIBUNLOCK (); - rtems_panic (DRVNM "Unable to create bus lock"); - } else { - bus->mutex = m; - } + if (bus->mutex == RTEMS_ID_NONE) { + /* + * Nobody is holding the bus mutex - it's not there. Create it on the fly. + */ + LIBLOCK (); + if (bus->mutex == RTEMS_ID_NONE) { + rtems_id m = RTEMS_ID_NONE; + rtems_status_code sc = mutexCreate ( + rtems_build_name ('i', '2', 'c', '0' + busno), + &m + ); + if (sc != RTEMS_SUCCESSFUL) { + LIBUNLOCK (); + rtems_panic (DRVNM "Unable to create bus lock"); + return; + } + bus->mutex = m; + } + LIBUNLOCK (); } - /* count number of people waiting on this bus; only the last one deletes the mutex */ - bus->waiting++; - LIBUNLOCK (); + /* Now lock this bus */ LOCK (bus->mutex); } @@ -201,12 +205,7 @@ static void unlock_bus (int busno) { struct i2cbus *bus = &busses[busno]; - LIBLOCK (); UNLOCK (bus->mutex); - if (!--bus->waiting) { - rtems_semaphore_delete (bus->mutex); - } - LIBUNLOCK (); } /* Note that 'arg' is always passed in as NULL */ @@ -226,7 +225,7 @@ rtems_i2c_init (rtems_device_major_number major, rtems_device_minor_number minor is_initialized = true; rtems_libi2c_major = major; } else { - libmutex = 0; + libmutex = RTEMS_ID_NONE; } return rval; } @@ -370,10 +369,11 @@ rtems_libi2c_initialize (void) safe_printf( DRVNM "Claiming driver slot failed (rtems status code %i)\n", sc); - if ( libmutex ) - rtems_semaphore_delete (libmutex); - libmutex = 0; - is_initialized = false; + if (libmutex != RTEMS_ID_NONE) { + rtems_semaphore_delete (libmutex); + } + libmutex = RTEMS_ID_NONE; + is_initialized = false; return -1; } @@ -417,7 +417,7 @@ rtems_libi2c_register_bus (const char *name, rtems_libi2c_bus_t * bus) /* should be a directory since name terminates in '/' */ - if (!libmutex) { + if (libmutex == RTEMS_ID_NONE) { safe_printf ( DRVNM "Library not initialized\n"); return -RTEMS_NOT_DEFINED; } @@ -432,9 +432,8 @@ rtems_libi2c_register_bus (const char *name, rtems_libi2c_bus_t * bus) if (!busses[i].bush) { /* found a free slot */ busses[i].bush = bus; - busses[i].mutex = 0; - busses[i].waiting = 0; - busses[i].started = 0; + busses[i].mutex = RTEMS_ID_NONE; + busses[i].started = false; if (!name) sprintf (nmcpy + strlen (nmcpy), "%i", i); @@ -497,7 +496,7 @@ rtems_libi2c_send_start (rtems_device_minor_number minor) unlock_bus (busno); } else { /* successful 1st start; keep bus locked until stop is sent */ - busses[busno].started = 1; + busses[busno].started = true; } return rval; } @@ -513,7 +512,7 @@ rtems_libi2c_send_stop (rtems_device_minor_number minor) rval = bush->ops->send_stop (bush); - busses[busno].started = 0; + busses[busno].started = false; unlock_bus (busno); return rval; @@ -693,7 +692,7 @@ rtems_libi2c_register_drv (const char *name, rtems_libi2c_drv_t * drvtbl, rtems_status_code err; rtems_device_minor_number minor; - if (!libmutex) { + if (libmutex == RTEMS_ID_NONE) { safe_printf ( DRVNM "Library not initialized\n"); return -RTEMS_NOT_DEFINED; } diff --git a/cpukit/libi2c/libi2c.h b/cpukit/libi2c/libi2c.h index fa0a5850ea..3ab4432b9f 100644 --- a/cpukit/libi2c/libi2c.h +++ b/cpukit/libi2c/libi2c.h @@ -1,3 +1,11 @@ +/** + * @file + * + * @ingroup libi2c + * + * @brief I2C library. + */ + #ifndef _RTEMS_LIBI2C_H #define _RTEMS_LIBI2C_H /*$Id$*/ @@ -55,6 +63,14 @@ extern "C" { #endif +/** + * @defgroup libi2c I2C Library + * + * @brief I2C library. + * + * @{ + */ + /* Simple I2C driver API */ /* Initialize the libary - may fail if no semaphore or no driver slot is available */ @@ -485,6 +501,8 @@ typedef struct { void *arg; } rtems_libi2c_read_write_async_t; +/** @} */ + #ifdef __cplusplus } #endif |