Skip to content

Commit

Permalink
Merge pull request #9 from robbep/master
Browse files Browse the repository at this point in the history
Increase semaphore timeout
  • Loading branch information
robbep committed Feb 15, 2015
2 parents 81ce71e + bd1d392 commit d7edc00
Showing 1 changed file with 40 additions and 36 deletions.
76 changes: 40 additions & 36 deletions Libraries/SpecsUser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extern int errno ;
#define SpecsUserMajorVersion 9
#define SpecsUserMinorVersion 0

static struct timespec LockDelay = { 1 , 0 } ;
static struct timespec LockDelay = { 3 , 0 } ;

// Delay to wait for Slave interrupt
static unsigned int ItDelay = 100 ;
Expand Down Expand Up @@ -160,7 +160,8 @@ void stopSpecsUser( void ) {
//========================================================================
// Function to reserve the Master to protect against concurrent accesses
//========================================================================
SpecsError reserveMaster_checkRecursive( SPECSMASTER * theMaster ) {
SpecsError reserveMaster_checkRecursive( SPECSMASTER * theMaster ,
unsigned int funcFrom ) {
struct sembuf operation ;
int res ;

Expand All @@ -178,6 +179,7 @@ SpecsError reserveMaster_checkRecursive( SPECSMASTER * theMaster ) {
if ( EINTR == errno ) {
retry = true ;
} else {
printf( "Recursive, calling function %d \n" , funcFrom ) ;
perror("") ; return SpecsMasterLocked ;
}
}
Expand All @@ -188,7 +190,8 @@ SpecsError reserveMaster_checkRecursive( SPECSMASTER * theMaster ) {

// Without checking recursivity

SpecsError reserveMaster( SPECSMASTER * theMaster ) {
SpecsError reserveMaster( SPECSMASTER * theMaster ,
unsigned int fromFunc ) {
struct sembuf operation ;
int res ;

Expand All @@ -205,6 +208,7 @@ SpecsError reserveMaster( SPECSMASTER * theMaster ) {
if ( EINTR == errno ) {
retry = true ;
} else {
printf( "Non recursive %d\n" , fromFunc ) ;
perror("") ; return SpecsMasterLocked ;
}
}
Expand Down Expand Up @@ -294,7 +298,7 @@ SpecsError specs_i2c_write( SPECSSLAVE * theSlave ,
RETURN_CODE errorCodeFromLowLevelSpecsLib ;

// Wait for master to be free and block it
theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster ) ;
theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster , 0 ) ;
if ( theError != SpecsSuccess ) return theError ;

errorCodeFromLowLevelSpecsLib =
Expand Down Expand Up @@ -339,7 +343,7 @@ SpecsError specs_i2c_write_sub( SPECSSLAVE * theSlave ,

RETURN_CODE errorCodeFromLowLevelSpecsLib ;

theError = reserveMaster( theSlave -> pSpecsmaster ) ;
theError = reserveMaster( theSlave -> pSpecsmaster , 0 ) ;
if ( theError != SpecsSuccess ) return theError ;

errorCodeFromLowLevelSpecsLib =
Expand Down Expand Up @@ -368,7 +372,7 @@ SpecsError specs_i2c_general_write( SPECSSLAVE * theSlave ,
}
RETURN_CODE errorCodeFromLowLevelSpecsLib ;

theError = reserveMaster( theSlave -> pSpecsmaster ) ;
theError = reserveMaster( theSlave -> pSpecsmaster , 1 ) ;
if ( theError != SpecsSuccess ) return theError ;

errorCodeFromLowLevelSpecsLib =
Expand Down Expand Up @@ -410,7 +414,7 @@ SpecsError specs_i2c_general_write_sub( SPECSSLAVE * theSlave ,
}
RETURN_CODE errorCodeFromLowLevelSpecsLib ;

theError = reserveMaster( theSlave -> pSpecsmaster ) ;
theError = reserveMaster( theSlave -> pSpecsmaster , 2 ) ;
if ( theError != SpecsSuccess ) return theError ;

errorCodeFromLowLevelSpecsLib =
Expand Down Expand Up @@ -463,7 +467,7 @@ SpecsError specs_i2c_read( SPECSSLAVE * theSlave ,

RETURN_CODE errorCodeFromLowLevelSpecsLib ;

theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster ) ;
theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster , 1 ) ;
if ( theError != SpecsSuccess ) return theError ;

errorCodeFromLowLevelSpecsLib =
Expand Down Expand Up @@ -594,7 +598,7 @@ SpecsError specs_i2c_read_sub( SPECSSLAVE * theSlave ,

RETURN_CODE errorCodeFromLowLevelSpecsLib ;

theError = reserveMaster( theSlave -> pSpecsmaster ) ;
theError = reserveMaster( theSlave -> pSpecsmaster , 3 ) ;
if ( theError != SpecsSuccess ) return theError ;

errorCodeFromLowLevelSpecsLib =
Expand Down Expand Up @@ -717,7 +721,7 @@ SpecsError specs_i2c_combinedread( SPECSSLAVE * theSlave ,
if ( ! recursiveLock[ theSlave -> pSpecsmaster ] )
isFromRecursiveLock = false ;

theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster ) ;
theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster , 2 ) ;
if ( theError != SpecsSuccess ) return theError ;

errorCodeFromLowLevelSpecsLib =
Expand Down Expand Up @@ -779,7 +783,7 @@ SpecsError specs_parallel_write( SPECSSLAVE * theSlave ,
else if (nValues == 1)
/* Select Parallel or DMA following the value of nValues */
{
theError = reserveMaster( theSlave -> pSpecsmaster ) ;
theError = reserveMaster( theSlave -> pSpecsmaster , 4 ) ;
if ( theError != SpecsSuccess ) return theError ;

theSpecsLibError = ParallelWrite (theSlave, address, data[0] );
Expand All @@ -805,7 +809,7 @@ SpecsError specs_parallel_write( SPECSSLAVE * theSlave ,
pData[2*i] = (U8) ( ( data[i] & 0xFF00 ) >> 8 ) ;
pData[2*i+1] = (U8) ( data[i] & 0xFF ) ;
}
theError = reserveMaster( theSlave -> pSpecsmaster ) ;
theError = reserveMaster( theSlave -> pSpecsmaster , 5 ) ;
if ( theError != SpecsSuccess ) return theError ;

theSpecsLibError =
Expand Down Expand Up @@ -846,7 +850,7 @@ SpecsError specs_parallel_read ( SPECSSLAVE * theSlave ,
RETURN_CODE theSpecsLibError ;
SPECSMASTER* specsMtr = theSlave->pSpecsmaster ;

theError = reserveMaster( specsMtr ) ;
theError = reserveMaster( specsMtr , 6 ) ;
if ( theError != SpecsSuccess ) return theError ;

if (nValues <= 0)
Expand Down Expand Up @@ -931,7 +935,7 @@ SpecsError specs_jtag_reset( SPECSSLAVE * theSlave ,
tms = 0xF8;
RETURN_CODE specsLibError ;

theError = reserveMaster( theSlave -> pSpecsmaster ) ;
theError = reserveMaster( theSlave -> pSpecsmaster , 7 ) ;
if ( theError != SpecsSuccess ) return theError ;

specsLibError =
Expand Down Expand Up @@ -973,7 +977,7 @@ SpecsError specs_jtag_idle( SPECSSLAVE * theSlave ,
tms = 0x00;
RETURN_CODE specsLibError ;

theError = reserveMaster( theSlave -> pSpecsmaster ) ;
theError = reserveMaster( theSlave -> pSpecsmaster , 8 ) ;
if ( theError != SpecsSuccess ) return theError ;

specsLibError =
Expand Down Expand Up @@ -1045,7 +1049,7 @@ SpecsError specs_register_write( SPECSSLAVE * theSlave ,

RETURN_CODE errorCodeFromLowLevelSpecsLib ;

theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster ) ;
theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster , 3 ) ;
if ( theError != SpecsSuccess ) return theError ;

errorCodeFromLowLevelSpecsLib = RegisterWrite(theSlave, theRegister,
Expand Down Expand Up @@ -1086,7 +1090,7 @@ SpecsError specs_register_read( SPECSSLAVE * theSlave ,

RETURN_CODE errorCodeFromLowLevelSpecsLib ;

theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster ) ;
theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster , 4 ) ;
if ( theError != SpecsSuccess ) return theError ;

errorCodeFromLowLevelSpecsLib = RegisterRead(theSlave,theRegister,data);
Expand Down Expand Up @@ -1131,7 +1135,7 @@ SpecsError specs_slave_internal_reset( SPECSSLAVE * theSlave ) {
if ( 0 == theSlave ) return InvalidParameter ;

SpecsError theError ;
theError = reserveMaster( theSlave -> pSpecsmaster ) ;
theError = reserveMaster( theSlave -> pSpecsmaster , 9 ) ;
if ( theError != SpecsSuccess ) return theError ;

recursiveLock[ theSlave -> pSpecsmaster ] = true ;
Expand Down Expand Up @@ -1163,7 +1167,7 @@ SpecsError specs_slave_external_reset( SPECSSLAVE * theSlave ) {
if ( 0 == theSlave ) return InvalidParameter ;
SpecsError theError ;

theError = reserveMaster( theSlave -> pSpecsmaster ) ;
theError = reserveMaster( theSlave -> pSpecsmaster , 10 ) ;
if ( theError != SpecsSuccess ) return theError ;

recursiveLock[ theSlave -> pSpecsmaster ] = true ;
Expand Down Expand Up @@ -1197,7 +1201,7 @@ SpecsError specs_slave_external_shortreset( SPECSSLAVE * theSlave ) {
if ( 0 == theSlave ) return InvalidParameter ;
SpecsError theError ;

theError = reserveMaster( theSlave -> pSpecsmaster ) ;
theError = reserveMaster( theSlave -> pSpecsmaster , 11 ) ;
if ( theError != SpecsSuccess ) return theError ;

recursiveLock[ theSlave -> pSpecsmaster ] = true ;
Expand Down Expand Up @@ -1244,7 +1248,7 @@ SpecsError specs_master_softreset( SPECSMASTER * theMaster ) {
U32 status ;
unsigned short address ;

theError = reserveMaster_checkRecursive( theMaster ) ;
theError = reserveMaster_checkRecursive( theMaster ,5 ) ;
if ( theError != SpecsSuccess ) return theError ;

// empty the FIFO
Expand Down Expand Up @@ -1585,7 +1589,7 @@ SpecsError specs_dcu_register_write( SPECSSLAVE * theSlave ,
SpecsError theError = SpecsSuccess ;

if ( ! recursiveLock[ theSlave -> pSpecsmaster ] ) fromRecursiveLock = false ;
theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster ) ;
theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster , 6 ) ;
if ( theError != SpecsSuccess ) return theError ;

initialSpeed = getSpeed( theSlave -> pSpecsmaster ) ;
Expand Down Expand Up @@ -1639,7 +1643,7 @@ SpecsError specs_dcu_register_read( SPECSSLAVE * theSlave ,
U8 initialSpeed , isInitialMasked ;
SpecsError theError = SpecsSuccess ;

theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster ) ;
theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster , 7 ) ;
if ( theError != SpecsSuccess ) return theError ;

if ( ! recursiveLock[ theSlave -> pSpecsmaster ] )
Expand Down Expand Up @@ -1700,7 +1704,7 @@ SpecsError specs_dcu_acquire( SPECSSLAVE * theSlave ,
int nIter ;
U8 initialSpeed , isInitialMasked ;

readError = reserveMaster( theSlave -> pSpecsmaster ) ;
readError = reserveMaster( theSlave -> pSpecsmaster , 12 ) ;
if ( readError != SpecsSuccess ) return readError ;

initialSpeed = getSpeed( theSlave -> pSpecsmaster ) ;
Expand Down Expand Up @@ -1936,7 +1940,7 @@ SpecsError specs_dcu_reset( SPECSSLAVE * theSlave ) {
SpecsError readError = SpecsSuccess ;
U8 initialSpeed , isInitialMasked ;

readError = reserveMaster( theSlave -> pSpecsmaster ) ;
readError = reserveMaster( theSlave -> pSpecsmaster , 13 ) ;
if ( readError != SpecsSuccess ) return readError ;

initialSpeed = getSpeed( theSlave -> pSpecsmaster ) ;
Expand Down Expand Up @@ -2010,7 +2014,7 @@ SpecsError specs_dcu_initialize( SPECSSLAVE * theSlave ) {
SpecsError readError = SpecsSuccess ;
U8 initialSpeed , isInitialMasked ;

readError = reserveMaster( theSlave -> pSpecsmaster ) ;
readError = reserveMaster( theSlave -> pSpecsmaster , 14 ) ;
if ( readError != SpecsSuccess ) return readError ;

initialSpeed = getSpeed( theSlave -> pSpecsmaster ) ;
Expand Down Expand Up @@ -2117,7 +2121,7 @@ SpecsError specs_dcu_set_LIR( SPECSSLAVE * theSlave ) {
SpecsError readError = SpecsSuccess ;
U8 initialSpeed , isInitialMasked ;

readError = reserveMaster( theSlave -> pSpecsmaster ) ;
readError = reserveMaster( theSlave -> pSpecsmaster , 15 ) ;
if ( readError != SpecsSuccess ) return readError ;

initialSpeed = getSpeed( theSlave -> pSpecsmaster ) ;
Expand Down Expand Up @@ -2192,7 +2196,7 @@ SpecsError specs_dcu_set_HIR( SPECSSLAVE * theSlave ) {
SpecsError readError = SpecsSuccess ;
U8 initialSpeed , isInitialMasked ;

readError = reserveMaster( theSlave -> pSpecsmaster ) ;
readError = reserveMaster( theSlave -> pSpecsmaster , 16 ) ;
if ( readError != SpecsSuccess ) return readError ;

initialSpeed = getSpeed( theSlave -> pSpecsmaster ) ;
Expand Down Expand Up @@ -2407,7 +2411,7 @@ SpecsError JtagWriteReadMany( SPECSSLAVE * pSpecsslave, U8 outSelect,
}
index--;

theError = reserveMaster( pSpecsslave -> pSpecsmaster ) ;
theError = reserveMaster( pSpecsslave -> pSpecsmaster , 17 ) ;
if ( theError != SpecsSuccess ) return theError ;

for(i = index; i >= 0 ; i--)
Expand Down Expand Up @@ -2452,7 +2456,7 @@ SpecsError JtagWriteReadMany( SPECSSLAVE * pSpecsslave, U8 outSelect,
}
else
{
theError = reserveMaster( pSpecsslave -> pSpecsmaster ) ;
theError = reserveMaster( pSpecsslave -> pSpecsmaster , 18 ) ;
if ( theError != SpecsSuccess ) return theError ;

ret = JtagWriteRead( pSpecsslave, outSelect,
Expand Down Expand Up @@ -2532,7 +2536,7 @@ SpecsError specs_master_setspeed( SPECSMASTER * theMaster , U8 speed ) {
idMapIterator idIt ;
U32 n ;

SpecsError theError = reserveMaster_checkRecursive( theMaster ) ;
SpecsError theError = reserveMaster_checkRecursive( theMaster , 8 ) ;
if ( theError != SpecsSuccess ) return theError ;

n = ( SpecsPlxStatusRead( theMaster ) >> 8 ) & 0xFF ;
Expand Down Expand Up @@ -2570,7 +2574,7 @@ SpecsError specs_master_maskchecksum( SPECSMASTER * theMaster ) {
idMapIterator idIt ;
U32 n ;
U8 speed ;
SpecsError theError = reserveMaster_checkRecursive( theMaster ) ;
SpecsError theError = reserveMaster_checkRecursive( theMaster , 9 ) ;
if ( theError != SpecsSuccess ) return theError ;

n = ( SpecsPlxStatusRead( theMaster ) >> 8 ) & 0xFF ;
Expand Down Expand Up @@ -2614,7 +2618,7 @@ SpecsError specs_master_unmaskchecksum( SPECSMASTER * theMaster ) {
U32 n ;
U8 speed ;

SpecsError theError = reserveMaster_checkRecursive( theMaster ) ;
SpecsError theError = reserveMaster_checkRecursive( theMaster , 10 ) ;
if ( theError != SpecsSuccess ) return theError ;

n = ( SpecsPlxStatusRead( theMaster ) >> 8 ) & 0xFF ;
Expand Down Expand Up @@ -2669,7 +2673,7 @@ SpecsError specs_slave_write_eeprom( SPECSSLAVE * theSlave , U8 pageNumber ,
unsigned int i ;
for ( i = 0 ; i < nValues ; ++i ) newData[ i + 2 ] = data[ i ] ;

theError = reserveMaster( theSlave -> pSpecsmaster ) ;
theError = reserveMaster( theSlave -> pSpecsmaster , 19 ) ;
if ( theError != SpecsSuccess ) return theError ;

initialSpeed = getSpeed( theSlave -> pSpecsmaster ) ;
Expand Down Expand Up @@ -2803,7 +2807,7 @@ SpecsError specs_slave_read_eeprom( SPECSSLAVE * theSlave ,
if ( ! recursiveLock[ theSlave -> pSpecsmaster ] )
isFromRecursiveLock = false ;

theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster ) ;
theError = reserveMaster_checkRecursive( theSlave -> pSpecsmaster , 11 ) ;
if ( theError != SpecsSuccess ) return theError ;

initialSpeed = getSpeed( theSlave -> pSpecsmaster ) ;
Expand Down Expand Up @@ -3134,7 +3138,7 @@ SpecsError specs_register_read_withoutIt( SPECSSLAVE * theSlave ,

RETURN_CODE errorCodeFromLowLevelSpecsLib ;
if (checkLock ) {
theError = reserveMaster( theSlave -> pSpecsmaster ) ;
theError = reserveMaster( theSlave -> pSpecsmaster , 20 ) ;
if ( theError != SpecsSuccess ) return theError ;
}

Expand Down

0 comments on commit d7edc00

Please sign in to comment.