Legen Dary
/
APP4
APP4 - S5 H16
Revision 5:6315ad5e8686, committed 2016-02-24
- Comitter:
- SonSenpai
- Date:
- Wed Feb 24 06:32:59 2016 +0000
- Parent:
- 4:d773812f9f7b
- Commit message:
- last I guess
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r d773812f9f7b -r 6315ad5e8686 main.cpp --- a/main.cpp Wed Feb 24 05:44:53 2016 +0000 +++ b/main.cpp Wed Feb 24 06:32:59 2016 +0000 @@ -51,7 +51,6 @@ int count = 0; //Variables for receive -Thread* RegReader_Th; struct inboundChargeMail { char* charge; @@ -60,6 +59,7 @@ Mail<inboundChargeMail, 8> inboundChargeUtile; int sync = 0; bool gbitValueOk = 1; +bool in_val; int rcv_count = 0; unsigned long tick_count_read; bool state_adjust = true; @@ -294,27 +294,29 @@ void read() { - //std::printf("WE BE READIN"); - bool in_val = d_in.read(); + in_val = d_in.read(); if( sync < 8 ) { - if( in_val || sync > 0 ){ + if( in_val || sync > 0 ) + { tc_periods[sync] = tick_count_read; sync++; if (sync == 8) { - for (int i = 0; i < sync; i++) + for (int i = 1; i < sync; i++) { period += tc_periods[i]; } - period = (period/8)/2; + period = (period/7)/2; } + debugTH->signal_set(0x1); } } else { - if( tick_count_read > period * 1.6 ) + debugTH->signal_set(0x1); + if( tick_count_read > period * 1.5 ) { rcv_buff[ rcv_count ] = !in_val; gbitValueOk = analyze_state( !in_val ); @@ -365,93 +367,9 @@ extern "C" void TIMER2_IRQHandler() { tick_count_read = LPC_TIM2->CR0; - read(); -} - -void regReader( void const *args ) -{ - bool bitValueOk = 1; - while(true) - { - std::printf("WE'LL BE READIN"); - Thread::signal_wait(0x2); - std::printf("WE BE READIN"); - if( sync < 8 ) - { - tc_periods[sync] = tick_count_read; - sync++; - - if (sync == 8) - { - for (int i = 0; i < sync; i++) - { - period += tc_periods[i]; - } - period = period/8; - } - } - else - { - if( tick_count_read > ( period * 0.8 ) && tick_count_read < ( period * 1.2 ) ) - { - if( rcv_count == 0 ) - { - rcv_buff[0] = 0; - bitValueOk = analyze_state(0); - } - else if( rcv_buff[ rcv_count - 1 ] == 0 ) - { - rcv_buff[ rcv_count ] = 1; - bitValueOk = analyze_state(1); - } - else - { - rcv_buff[ rcv_count ] = 0; - bitValueOk = analyze_state(0); - } - rcv_count++; - } - else if( tick_count_read < ( period * 0.7 ) ) - { - if( state_adjust ) - { - state_adjust = !state_adjust; - } - else - { - state_adjust = !state_adjust; - rcv_buff[ rcv_count ] = rcv_buff[ rcv_count - 1 ]; - bitValueOk = analyze_state( rcv_buff[ rcv_count ] ); - rcv_count++; - } - } - - } - if( messageReady ) - { - inboundChargeMail *mail_t = new inboundChargeMail; - char ctemp[ 80 ]; - strcpy( ctemp, c_chargeUtile ); - mail_t->charge = ctemp; - mail_t->length = LENGTH_CHARGE_UTILE_BYTE; - inboundChargeUtile.put( mail_t ); - - rcv_count = 0; - state_adjust = true; - sync = 0; - messageReady = false; - cntState = 0; - } - if( !bitValueOk ) - { - rcv_count = 0; - state_adjust = true; - sync = 0; - cntState = 0; - } - LPC_TIM2->TC = 0; - LPC_TIM2->IR |= 0xFFFFFFFF; - } + //read(); + LPC_TIM2->TC = 0; + LPC_TIM2->IR |= 0xFFFFFFFF; } extern "C" void TIMER1_IRQHandler( void ) @@ -492,8 +410,10 @@ { tempi1 = d_out; std::printf( "%d", tempi1 & 0x1 ); - std::printf( " %d\r\n", count ); - + std::printf( "%d", in_val & 0x1 ); + std::printf( " %d", count ); + std::printf( " %d", period ); + std::printf( " %d\r\n", tick_count_read ); } } } @@ -522,7 +442,7 @@ sending = false; count = 0; OutGoingMail.free( trm ); - std::printf( "frame sender thread Over\r\n" ); + std::printf( "frame sender thread Over \r\n" ); } } } @@ -588,7 +508,6 @@ Thread fp( frame_printer ); Thread ir( inputReceiver ); frame_sender_Th = new Thread( frame_sender ); - RegReader_Th = new Thread( regReader ); std::printf("done\r\n"); while( true )