/* $Id: fcomOutState.c,v 1.2 2010/03/10 10:36:19 strauman Exp $ */ #include #ifdef MAIN volatile uint32_t drvPadUdpCommChannelsInUseMask = 3; volatile uint32_t fcomOutStateGroup; volatile uint32_t fcomOutStateSent; #else #include #endif #include volatile uint32_t fcomOutStateMask = 0; /* bitmask of channels that should be posted */ volatile uint32_t fcomOutStateEnbl = 0; /* bitmask of channels currently 'in use' */ volatile uint32_t fcomOutStateGood = -1; /* bitmask of currently working channels */ volatile uint32_t fcomOutStateMemb = -1; /* bitmask of channels not yet added to group */ volatile uint32_t fcomOutStateTimo = 0; volatile uint32_t fcomOutStateTost = 0; /* record bitmask of timed-out channels */ #ifdef MAIN #include #include uint32_t fcomOutState_bpmok; #define BITS 2 #define BMSK ((1<>= BITS; fcomOutStateMemb = state & BMSK; } uint32_t getstate(void) { uint32_t state; state = fcomOutStateMemb & BMSK; state <<= BITS; state |= fcomOutStateGood & BMSK; return state; } void fcomOutState_cycle(void) { uint32_t ch; int i,st; fcomOutStateSent = 0; fcomOutStateGroup = 0; fcomOutStateFidCheck(); for ( i=0, ch=1; i>= BITS; drvPadUdpCommChannelsInUseMask = invars >> BITS; fcomOutState_cycle(); cs = getstate(); do { os = cs; fcomOutState_cycle(); cs = getstate(); } while ( cs != os ); return cs; } int checkstate(uint32_t tgt_state, uint32_t curr_state) { if ( fcomOutStateSent != (tgt_state & BMSK & drvPadUdpCommChannelsInUseMask) ) { printf("****MISMATCH****\n"); printf("state: 0x%08"PRIx32"\n", tgt_state); printf("current: 0x%08"PRIx32"\n", curr_state); printf("sent: 0x%08"PRIx32"\n", fcomOutStateSent); return 1; } return 0; } /* This test doesn't cover all possible combinations of * states since it waits for the state variables to settle/converge * before trying new combinations of input variables. */ int main(int argc, char **argv) { int errs = 0; uint32_t state, cs; uint32_t vars,nvars; for ( state=0; state < 1<<(STATS*BITS); state++ ) { for ( vars = 0; vars < 1<<(VARS*BITS); vars++ ) { cs = convstate(state,vars); errs += checkstate(state, cs); /* can we jump to any new combination of input vars? */ for ( nvars = 0; nvars < 1<<(VARS*BITS); nvars++ ) { cs = convstate(state,nvars); errs += checkstate(state, cs); } } } if ( !errs ) { printf("TEST PASSED\n"); } return 0; } #endif