Changeset c85ab23 in rtems for cpukit/libi2c
- Timestamp:
- Aug 5, 2009, 6:17:12 PM (10 years ago)
- Branches:
- 4.10, 4.11, master
- Children:
- 21de9dc
- Parents:
- b053cab
- Location:
- cpukit/libi2c
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/libi2c/libi2c.c
rb053cab rc85ab23 111 111 rtems_libi2c_bus_t *bush; 112 112 volatile rtems_id mutex; /* lock this across start -> stop */ 113 volatile short waiting; 114 volatile char started; 113 volatile bool started; 115 114 char *name; 116 115 } busses[MAX_NO_BUSSES] = { { 0, 0, 0, 0, 0 } }; … … 121 120 } drvs[MAX_NO_DRIVERS] = { { 0 } }; 122 121 123 static rtems_id libmutex = 0;122 static rtems_id libmutex = RTEMS_ID_NONE; 124 123 125 124 #define LOCK(m) assert(!rtems_semaphore_obtain((m), RTEMS_WAIT, RTEMS_NO_TIMEOUT)) … … 176 175 lock_bus (int busno) 177 176 { 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 196 200 /* Now lock this bus */ 197 201 LOCK (bus->mutex); … … 202 206 { 203 207 struct i2cbus *bus = &busses[busno]; 204 LIBLOCK ();205 208 UNLOCK (bus->mutex); 206 if (!--bus->waiting) {207 rtems_semaphore_delete (bus->mutex);208 }209 LIBUNLOCK ();210 209 } 211 210 … … 227 226 rtems_libi2c_major = major; 228 227 } else { 229 libmutex = 0;228 libmutex = RTEMS_ID_NONE; 230 229 } 231 230 return rval; … … 371 370 DRVNM "Claiming driver slot failed (rtems status code %i)\n", 372 371 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; 377 377 return -1; 378 378 } … … 418 418 419 419 420 if ( !libmutex) {420 if (libmutex == RTEMS_ID_NONE) { 421 421 safe_printf ( DRVNM "Library not initialized\n"); 422 422 return -RTEMS_NOT_DEFINED; … … 433 433 /* found a free slot */ 434 434 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; 438 437 439 438 if (!name) … … 498 497 } else { 499 498 /* successful 1st start; keep bus locked until stop is sent */ 500 busses[busno].started = 1;499 busses[busno].started = true; 501 500 } 502 501 return rval; … … 514 513 rval = bush->ops->send_stop (bush); 515 514 516 busses[busno].started = 0;515 busses[busno].started = false; 517 516 518 517 unlock_bus (busno); … … 694 693 rtems_device_minor_number minor; 695 694 696 if ( !libmutex) {695 if (libmutex == RTEMS_ID_NONE) { 697 696 safe_printf ( DRVNM "Library not initialized\n"); 698 697 return -RTEMS_NOT_DEFINED; -
cpukit/libi2c/libi2c.h
rb053cab rc85ab23 1 /** 2 * @file 3 * 4 * @ingroup libi2c 5 * 6 * @brief I2C library. 7 */ 8 1 9 #ifndef _RTEMS_LIBI2C_H 2 10 #define _RTEMS_LIBI2C_H … … 55 63 extern "C" { 56 64 #endif 65 66 /** 67 * @defgroup libi2c I2C Library 68 * 69 * @brief I2C library. 70 * 71 * @{ 72 */ 57 73 58 74 /* Simple I2C driver API */ … … 486 502 } rtems_libi2c_read_write_async_t; 487 503 504 /** @} */ 505 488 506 #ifdef __cplusplus 489 507 }
Note: See TracChangeset
for help on using the changeset viewer.