04-09-2015 01:55 AM
Hello everyone,
i have been trying an implementation in sdk. There are a number of print statements in my logic to indicate the start and stop of a loop.
If i comment out some of the print statements from my code, i am getting some values of the final result printed. If i comment out all the statements except the one which prints the result, the result is always zero. Can somebody help me figure out what the problem is?
thanks in advance
04-16-2015 01:28 AM
thanks alot norman_wong,
there was a problem in my code. after i corrected it everything worked fine
04-09-2015 04:17 AM
04-09-2015 08:52 AM
hi,
is the instruction that you are trying to execute expecting a delay?
--hem
04-09-2015 08:10 PM
The code i am using is given below. If i uncomment the print statements then i get a different result
#include "stdio.h" #include "xgpio_l.h" #include "xparameters.h" #include "xil_types.h" #include "xbasic_types.h" #include "xuartlite.h" int main(void) { //Xuint8 FRAME_BIT_SIZE=16; /* g_table is array of length STATES. g_table[i] contains g0g1 output from state i if input bit is zero. This table is used in conv_decode() to calculate branch metrics */ Xuint8 g_table[64] = { 0, 3, 1, 2, 0, 3, 1, 2, 3, 0, 2, 1, 3, 0, 2, 1, 3, 0, 2, 1, 3, 0, 2, 1, 0, 3, 1, 2, 0, 3, 1, 2, 2, 1, 3, 0, 2, 1, 3, 0, 1, 2, 0, 3, 1, 2, 0, 3, 1, 2, 0, 3, 1, 2, 0, 3, 2, 1, 3, 0, 2, 1, 3, 0} ; /* this table stores the output codes corresponding to an input '0'. The output corresponding to input '1' can be obtained by XOR of 2 with the output corresponding to '0' */ /* transition_table is used in conv_decode() to store decision data which is used in traceback */ Xuint8 transition_table[64][16]; /* path metrics */ Xuint8 new_metrics[64] = {0}; Xuint8 old_metrics[64] = {0}; Xuint8 *ptr_to_new_metrics; Xuint8 *ptr_to_old_metrics; Xuint8 *temp_ptr; Xuint8 conv_dec_in[32]={1,1,1,0,0,0,0,1,0,0,0,0,1,1,1,1,0,1,1,1,1,1,1,0,1,0,1,0,1,1,0,0}; Xuint8 conv_dec_out[16]={}; //INPUT:Total input bits = 2*FRAME_BYTE_SIZE*BYTE_LENGTH = 2*FRAME_BIT_SIZE = 32 bits; // Input contains g0,g1 values in packed format same as conv_encode() output int i=0; int j=0; int k=0,m=0; Xuint8 temp,count,dist0,dist1; int symbol_count; Xuint8 current_state=0, prev_state=0; Xuint8 bit=0; Xuint8 in_g0, in_g1; Xuint8 symbol; symbol_count =0; ptr_to_new_metrics = new_metrics; ptr_to_old_metrics = old_metrics; for(i=0;i<32;i=i+2); { in_g0=conv_dec_in[i]; in_g1=conv_dec_in[i+1]; symbol=(in_g0<<1)|in_g1; for(k=0;k<32;k++) { /* calculate branch metric (hamming distance) */ temp = symbol ^ g_table[2*k]; count = 0; while(temp) { if(temp & 0x1) count++; temp = temp >> 1; } dist0 = count; dist1 = 2-count; /* compare-select-store operation for state c */ if((ptr_to_old_metrics[2*k] + dist0) <= (ptr_to_old_metrics[2*k+1] + dist1)) { transition_table[k][symbol_count] = 0; ptr_to_new_metrics[k] = ptr_to_old_metrics[2*k] + dist0; } else { transition_table[k][symbol_count] = 1; ptr_to_new_metrics[k] = ptr_to_old_metrics[2*k+1] + dist1; } /* compare-select-store operation for state d */ if((ptr_to_old_metrics[2*k] + dist1) <= (ptr_to_old_metrics[2*k+1] + dist0)) { transition_table[k+32][symbol_count] = 0; ptr_to_new_metrics[k+32] = ptr_to_old_metrics[2*k] + dist1; } else { transition_table[k+32][symbol_count] = 1; ptr_to_new_metrics[k+32] = ptr_to_old_metrics[2*k+1] + dist0; } } /* after all state metrics are updated for all 64 states switch pointers to new_metrics and old_metrics. new_metrics[] will become old_metrics[] and old_metrics[] will become new_metrics[] which will be updated in next symbol interval */ temp_ptr = ptr_to_new_metrics; ptr_to_new_metrics = ptr_to_old_metrics; ptr_to_old_metrics = temp_ptr; symbol_count++; } while(1) { current_state = 0; j = 0; for(i=16-1;i>0;i--) /* for each frame bit (10)*/ { /* read bit while traceback */ // xil_printf("\r Transition table value is %d\n", transition_table[current_state][i]); bit = transition_table[current_state][i]; for (m=0;m<5;m++); //xil_printf("\r current state is %d\n", current_state); xil_printf("\r bit value is %d\n", bit); /* find previous state */ prev_state = (current_state << 1) | bit; prev_state = prev_state & 0x3F; /* calculate decoded bit and store in convo_dec_out */ conv_dec_out[j] = ((current_state & 0x20) >> 5); //xil_printf("\r j value : %d\n", j); //XGpio_WriteReg(XPAR_XPS_GPIO_0_BASEADDR, 0, conv_dec_out[j]); xil_printf("\rThe output bit is : %d\n", conv_dec_out[j]); current_state = prev_state; j++; } } }
04-11-2015 09:34 PM
Maybe some of your code is being optimized out. Adding the printfs ends up using variables that the compiler thinks you don't need. It will stop the compiler from removing that code. Try compiling with no optimization. Or adding "volatile" to all your variables. Also, you are putting a sizeable amount of data on the stack. Perhaps you should move your big arrays to global array to move it off the stack onto the heap.
04-16-2015 01:28 AM
thanks alot norman_wong,
there was a problem in my code. after i corrected it everything worked fine