www.pudn.com > jtag_src.rar > tool.c


/* 
 * tool.c:	this file implements some routes as	public tools 
 * 
 * Copyright (C) 2004, OPEN-JTAG, All rights reserved. 
 */ 
 
#include "types.h" 
 
 
/* 
 * tool_reverse_bit_order() - 
 *		Reverse the bit order of the input. 
 *		The input is regarded as a bit sequence. This sequence is  
 *		totally reversed. 
 */ 
void tool_reverse_bit_order(int bit_len, const u32 *input, u32 *output) 
{ 
	int bit_idx, bit_val; 
	int b_len, w_len; 
	u32 in_data, out_data; 
	 
	if(bit_len <= 0) 
		return; 
 
	b_len = bit_len%32; 
	w_len = bit_len/32; 
	in_data = 0; 
	out_data = 0; 
 
	for(bit_idx = 0; bit_idx < bit_len; bit_idx++){ 
		if( (bit_idx % 32) == 0) 
			in_data = input[bit_idx/32]; 
		 
		bit_val = in_data & 0x1; 
		in_data >>= 1; 
	 
		if(b_len == 0){ 
			out_data = 0; 
			b_len = 32; 
			w_len --; 
		} 
 
		b_len --; 
		out_data |= (bit_val << b_len); 
 
		if(b_len == 0) 
			output[w_len] = out_data; 
	} 
	 
	return; 
}