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

📄 keydrv.c

📁 一个操作系统源代码 用于嵌入式设备 在Vc++环境下仿真 成功移植到多款处理器上
💻 C
字号:
/***************************************************************************************\
 *
 * Copyright (c) 2001 National ASIC Center, All Rights Reserved
 *
 * File Name	:	keydrv.c
 * Version		:	1.0
 * Programmer	:	longn_qi
 * 
 * Date of Creation:	2001/11/01
 * Date of Last Modify:	2001/11/01
 *
 * Description:	This is an application file for simulating key interrupt buffer with read
 *				and write operations.
 *
 * Local Function List:
 * void InitKeyIntBuf( )
 * unsigned char WriteKeyIntBuf( KEYDATA *pKeyData )
 * unsigned char ReadKeyIntBuf( KEYDATA *pKeyData )
 *
 * Global Variable List:
 *
 * Note:		Further file description refers to simdrv.txt
 *
 ***************************************************************************************
 *
 * Modification History
 * 
 * 2001/11/1		by longn_qi		create file.
 *
\***************************************************************************************/
/* System and Standard Header */
#include <string.h>

/* Application Header */
#include <sys\key.h>
#include <intmsg.h>
#include <intdef.h>

/* Local Macro Definition */
//#define MAX_KEY_BUF	9

/* External Variable */
// import
__declspec( dllimport ) KEYDATA	key;

/* Static Variable */
KEYDATA 			KEY_BUF[ MAX_KEY_BUF ];
unsigned char 	KEY_BUF_writecount;
unsigned char 	KEY_BUF_readcount; 

/* Local Defined Function */
//////////////////////////////////////////////////////////////
//  Function Name: InitKeyIntBuf
//  Param In:					Param Description	
//		None
//								
//  Return Type:				Result Code Description
//		void																								
//  Description: Initial key interrupt buffer
//////////////////////////////////////////////////////////////
void InitKeyIntBuf( )
{
 	memset(KEY_BUF,0xff,sizeof(KEYDATA) * MAX_KEY_BUF);

	KEY_BUF_writecount = 0;
	KEY_BUF_readcount = 0; 
	
	return;
}

//////////////////////////////////////////////////////////////
//  Function Name: WriteKeyIntBuf
//  Param In:					Param Description	
//		KEYDATA *pKeyData		pointer to a key interrupt
//								structure
//								
//  Return Type:				Result Code Description
//		unsigned char			BUF_FULL	key buffer is full				
//								NEGLECT		neglect key interrupt
//								SUCCESS		write to key buffer
//											successfully
//  Description: Write key interrupt buffer.
//////////////////////////////////////////////////////////////	
unsigned char WriteKeyIntBuf( KEYDATA *pKeyData )
{
	unsigned char	nextKeyWriteCount,prevKeyWriteCount;

	nextKeyWriteCount = ( KEY_BUF_writecount+1 )%MAX_KEY_BUF;
	prevKeyWriteCount = ( KEY_BUF_writecount-1 + MAX_KEY_BUF )%MAX_KEY_BUF;

	// buffer full
	if( nextKeyWriteCount == KEY_BUF_readcount )
		return BUF_FULL;

	// distinguish key interrupt
	switch( KEY_BUF[prevKeyWriteCount].flag )
	{
		case SM_KEYDOWN:
		case SM_KEYREPEAT:
			if( key.flag != KEYUP )
				KEY_BUF[KEY_BUF_writecount].flag = SM_KEYREPEAT;
			else	
				KEY_BUF[KEY_BUF_writecount].flag = SM_KEYUP;
			break;
		case SM_KEYUP:
			if( key.flag != KEYUP )
				KEY_BUF[KEY_BUF_writecount].flag = SM_KEYDOWN;
			else
				return NEGLECT; // ignore contiuous key up message
			break;
		default:
			KEY_BUF[KEY_BUF_writecount].flag = SM_KEYUP;
	}
	KEY_BUF[KEY_BUF_writecount].keyvalue = key.keyvalue;
	KEY_BUF_writecount = nextKeyWriteCount;
	
	return SUCCESS;
}

//////////////////////////////////////////////////////////////
//  Function Name: ReadKeyIntBuf
//  Param In:					Param Description	
//		KEYDATA *pKeyData		pointer to a key interrupt
//								structure for storing key data
//								read from key buffer.
//								
//  Return Type:				Result Code Description
//		unsigned char			BUF_EMPTY	key buffer is empty				
//								SUCCESS		read key buffer
//											successfully
//  Description: Read key interrupt buffer.
//////////////////////////////////////////////////////////////	
unsigned char ReadKeyIntBuf( KEYDATA *pKeyData )
{

	if( KEY_BUF_readcount == KEY_BUF_writecount ) // buffer empty
		return BUF_EMPTY;
	
	pKeyData->keyvalue = KEY_BUF[ KEY_BUF_readcount ].keyvalue;
	pKeyData->flag = KEY_BUF[ KEY_BUF_readcount ].flag;
	
	KEY_BUF_readcount++;
	
	if( KEY_BUF_readcount >= MAX_KEY_BUF ) KEY_BUF_readcount = 0;

	return SUCCESS;
}

//////////////////////////////////////////////////////////////
//  Function Name: CheckKeyIntBuf
//  Param In:					Param Description	
//	None
//								
//  Return Type:				Result Code Description
//		unsigned char			BUF_EMPTY	key buffer is empty.
//								BUF_FULL	key buffer is full.
//								BUF_NORMAL	key buffer is readable 
//											and writable.
//
//  Description: Check ky interrupt buffer status.
//////////////////////////////////////////////////////////////	
unsigned char CheckKeyIntBuf(  )
{

	unsigned char	nextKeyWriteCount;


	if( KEY_BUF_readcount == KEY_BUF_writecount ) // buffer empty
		return BUF_EMPTY;

	nextKeyWriteCount = ( KEY_BUF_writecount+1 )%MAX_KEY_BUF;	
	if( nextKeyWriteCount == KEY_BUF_readcount ) // buffer full
		return BUF_FULL;

	return BUF_NORMAL;
}

void KeyScanHandler(void)
{
}

⌨️ 快捷键说明

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