⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util.c

📁 dm270 source code
💻 C
字号:
/*-----------------------------------------------------------------------------\
@ModuleName  ::	util.c
  
@Description ::	Utility and support routines for DSC25 Demo

@Copyright   ::	Copyright 2001- Texas Instruments, Inc.

@History     ::
-------------------------------------------------------------------------------

	Dec.  26, 2001	Kedar C (kedarc@ti.com)	Start
		

\-----------------------------------------------------------------------------*/


#include <util/util.h>
#include <string.h>

/*-----------------------------------------------------------------------------\
@RoutineName ::	put_str

@Description ::	
	Insert a string into a data stream

@Parameters  ::
	WordStream *ptr		::	Pointer to the data stream
	Uint8 *str			::	The string to insert

@Return		 ::	
	NONE

\-----------------------------------------------------------------------------*/
void put_str(WordStream *ptr, Uint8 *str) {
	strcpy( (char*)ptr->addr + ptr->ix, (char*)str);
	ptr->ix += strlen((char*)str)+1;
}

/*-----------------------------------------------------------------------------\
@RoutineName ::	put_word16

@Description ::	
	Insert a 16-bit word into a data stream in BIG ENDIAN Format

@Parameters  ::
	WordStream *ptr		::	Pointer to the data stream
	Uint16 word			::	The 16-bit word to insert

@Return		 ::	
	NONE

\-----------------------------------------------------------------------------*/
void put_word16(WordStream *ptr, Uint16 word) {

	
	*(ptr->addr + ptr->ix ) = word >> 8 ;
	*(ptr->addr + ptr->ix + 1) = word & 0xFF ;
	
	ptr->ix += 2;
}

/*-----------------------------------------------------------------------------\
@RoutineName ::	put_word32

@Description ::	
	Insert a 32-bit word into a data stream in BIG ENDIAN Format

@Parameters  ::
	WordStream *ptr		::	Pointer to the data stream
	Uint32 word			::	The 32-bit word to insert

@Return		 ::	
	NONE

\-----------------------------------------------------------------------------*/
void put_word32(WordStream *ptr, Uint32 word) {

	*(ptr->addr + ptr->ix ) = word >> 24 ;
	*(ptr->addr + ptr->ix + 1) = word >> 16  ;
	*(ptr->addr + ptr->ix + 2) = word >> 8  ;
	*(ptr->addr + ptr->ix + 3) = word & 0xFF  ;
	ptr->ix += 4;
}

/*-----------------------------------------------------------------------------\
@RoutineName ::	get_word16

@Description ::	
	Get a 16-bit word in BIG ENDIAN Format

@Parameters  ::
	Uint8 *start		::	Pointer to the data stream
	Uint16 word			::	The 16-bit word to insert

@Return		 ::	
	The 16-bit word

\-----------------------------------------------------------------------------*/
Uint16 get_word16( Uint8 *start ) {
	Uint16 tmp;

	tmp =  ( (Uint16)*(start) << 8 ) + *(start + 1);
	return tmp;
}

/*-----------------------------------------------------------------------------\
@RoutineName ::	get_word32

@Description ::	
	Get a 32-bit word in BIG ENDIAN Format

@Parameters  ::
	Uint8 *start		::	Pointer to the data stream
	Uint16 word			::	The 32-bit word to insert

@Return		 ::	
	The 32-bit word

\-----------------------------------------------------------------------------*/
Uint32 get_word32( Uint8 *start ) {
	Uint32 tmp;

		tmp =  ( (Uint32)*(start ) << 24 ) + 
				( (Uint32)*(start + 1) << 16 ) + 
				( (Uint32)*(start + 2) << 8 ) +
				*(start + 3);
		return tmp;
}


/*-----------------------------------------------------------------------------\
@RoutineName ::	byte_swap32

@Description ::	
	byte swap a 32-bit word

@Parameters  ::
	Uint32 word	::	The 32-bit word to byte swap

@Return		 ::	
	The byte swapped 32-bit word

\-----------------------------------------------------------------------------*/
Uint32 byte_swap32(Uint32 word) {
	Uint16 a = word & 0xFFFF;
	Uint16 b = word >> 16;

	a = ( a << 8 ) + ( a >> 8 );
	b = ( b << 8 ) + ( b >> 8 );
	word = ( (Uint32)a << 16 ) + (Uint32)b ;

	return word;
}

/*-----------------------------------------------------------------------------\
@RoutineName ::	byte_swap16

@Description ::	
	byte swap a 16-bit word

@Parameters  ::
	Uint32 word	::	The 16-bit word to byte swap

@Return		 ::	
	The byte swapped 16-bit word

\-----------------------------------------------------------------------------*/
Uint16 byte_swap16(Uint16 word) {
	return  ( word << 8 ) + ( word >> 8 );
}

/*-----------------------------------------------------------------------------\
@RoutineName ::	find_word16

@Description ::	
	Find a 16-bit word in a data stream
	The 16-word is byte swapped before finding it.

@Parameters  ::
	Uint8 *start		::	pointer to start of the data stream
	Uint8 *end			::	pointer to end of data stream
	const Uint16 word	::	the word to find. The 16-word is byte swapped before finding it.
			
@Return		 ::	
	The pointer to the word found.
	NULL, if word is not found

\-----------------------------------------------------------------------------*/
Uint8 *find_word16(Uint8 *start, Uint8 *end, const Uint16 word ) {
	
	while( start < end ) {
		if( *start == (Uint8)( word >> 8 ) && *(start+1) == (Uint8)( word & 0xFF ) )
			return start;
		start++;
	}
	return NULL;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -