- 博客(1)
- 资源 (7)
- 收藏
- 关注
转载 linux内核不支持嵌套
本文的copyleft归gfree.wind@gmail.com所有,使用GPL发布,可以自由拷贝,转载。但转载请保持文档的完整性,注明原作者及原链接,严禁用于任何商业用途。 作者:gfree.wind@gmail.com 博客:linuxfocus.blog.chinaunix.net 最近一直对Linux中的中断处理过程一直很纠结,觉得很明确的概念和过程,仔细想起来还是有
2012-01-01 22:24:11
601
小小的加密C程序,很简单的思路
static unsigned char *Separate ( unsigned char *pCombine,unsigned int uLength )
{
unsigned int i = 0 ,uOffset = pCombine[ 4 ],uJumpBytes = 4;
unsigned char *pRead = pCombine;
unsigned char *pStored = NULL;
if ( NULL == (pStored = malloc ( (MAXLEN + 1)*sizeof(unsigned char) )) ){
fprintf ( stderr,"Malloc Error!\n" );
return NULL;
}
pCombine += uOffset;
pStored[ 0 ] = pCombine[ 0 ] ;
for ( i = 1 ; i < MAXLEN ; i ++ )
{
uJumpBytes ++ ;
pCombine += uJumpBytes;
pStored[ i ] = *pCombine;
}
pStored[ MAXLEN ] = uOffset;
return pStored;
}
2011-03-25
一个串口通信的小程序
串口通信C程序
//Set CommTimeOuts
BOOL SetCommTimeOuts ( VOID )
{
//SetComm Input & Output Buffer
SetupComm ( hSerial ,MAXLEN * 2 ,MAXLEN * 2 );
//Read TimeOut
TimeOuts.ReadIntervalTimeout = MAXDWORD; //Set Total Read TimeOut as MAXDWORD (0xFFFFFFFF)
TimeOuts.ReadTotalTimeoutConstant = 0; //Read TimeOut Const
TimeOuts.ReadTotalTimeoutMultiplier = 0; //Return Riht now
//Write TimeOut
TimeOuts.WriteTotalTimeoutMultiplier = 50; //TotalTimeOut = TimeAgr*NumOfChars+const time
TimeOuts.WriteTotalTimeoutConstant = 2000; //Set Write TimeOuts
return ( FALSE != SetCommTimeouts ( hSerial,&TimeOuts ) );
}
//Error MsgBox
BOOL ErrMsg ( HWND hWnd,TCHAR *szErr )
{
return ( FALSE != MessageBox ( hWnd,szErr,NULL,MB_OK | MB_ICONWARNING ) );
}
//Read Comm
BOOL ReadCom ( HWND hSet,BYTE InBuff[],INT BytesNum )
{
DWORD dwBytesRead = 0; //Record The bytes already read
INT iBytesToRead = 0;
DWORD dwErrMask = 0;
//Clear Memory
ZeroMemory ( &ComState ,sizeof(ComState) );
ZeroMemory ( &OvLap ,sizeof(OvLap) );
OvLap.Offset = 0;
OvLap.OffsetHigh = 0;
OvLap.hEvent = CreateEvent (NULL,TRUE,FALSE,NULL);
//Clear All sPort error
ClearCommError (hSerial,&dwErrMask,&ComState);
//Get The Bytes to read from buff
iBytesToRead = min (2000,ComState.cbInQue);
if ( 0 == iBytesToRead )
return FALSE;
else;
if ( FALSE == ReadFile (hSerial,InBuff,iBytesToRead,&dwBytesRead,&OvLap ) )
{
if ( GetLastError () == ERROR_IO_PENDING )
{
WaitForSingleObject (OvLap.hEvent,2000);
PurgeComm (hSerial,PURGE_TXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR );
}
else;
}
else;
return (TRUE);
}
///Write Comm
BOOL WriteCom ( BYTE *szBuff,DWORD dwBytes )
{
DWORD dwErrMask = 0 ;
DWORD dwBytesWritten = 0;
ZeroMemory ( &OvLap ,sizeof(OvLap) );
ZeroMemory ( &ComState,sizeof(ComState) );
OvLap.Offset = 0;
OvLap.OffsetHigh = 0;
OvLap.hEvent = CreateEvent (NULL,TRUE,FALSE,NULL);
//Clear All sPort error
ClearCommError (hSerial,&dwErrMask,&ComState);
if ( FALSE == WriteFile ( hSerial,szBuff,dwBytes,&dwBytesWritten ,&OvLap ) )
{
if ( GetLastError () == ERROR_IO_PENDING )
{
WaitForSingleObject (OvLap.hEvent,2000) ;
PurgeComm (hSerial,PURGE_TXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR );
}
else;
}
else;
return ( dwBytesWritten == dwBytes );
}
TCHAR* Caps ( TCHAR *szStr )
{
UINT i = 0;
for ( i = 0 ; szStr[i] != '\0'; i ++ )
{
if ( szStr[i] >= 'A' && szStr[i] <= 'Z' )
szStr[i] += 0x20;
}
return szStr;
}
2011-03-25
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人