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

📄 madevdrv.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************
 *																			*
 *		Copyright (C) 2001-2003	YAMAHA CORPORATION. All rights reserved.	*
 *																			*
 *		Module		: madevdrv.c											*
 *																			*
 *		Description	: MA Device Driver										*
 *																			*
 * 		Version		: 1.3.15.6	2003.05.13									*
 *																			*
 ****************************************************************************/

#include "madevdrv.h"

UINT8 _ma_intstate;
extern void MI_dbgPrintf(const char *const format, ...);

#ifdef COLORLED_SUPPORT
#define MADEVDRV_LED_PATTERN_NUM 8
static const UINT8 abLedPattern[MADEVDRV_LED_PATTERN_NUM] =
					{ 1, 2, 3, 4, 5, 6, 7, 0 };
static UINT32 dwLedCount = 0;
#endif





MADEVDRVINFO ma_devdrv_info;
static PMADEVDRVINFO cinfo_ptr = &ma_devdrv_info;

extern void 	machdep_Wait					( UINT32 wait_time );
extern SINT32	machdep_CheckStatus				( UINT8 flag );
extern SINT32	machdep_WaitValidData			( UINT8 flag );
extern void 	machdep_WriteStatusFlagReg		( UINT8 data );
extern UINT8	machdep_ReadStatusFlagReg		( void );
extern void		machdep_WriteDataReg			( UINT8 data );
extern UINT8	machdep_ReadDataReg				( void );
extern SINT32	machdep_CheckDelayedFifoEmpty	( void );
extern SINT32	machdep_WaitDelayedFifoEmpty 	( void );
extern SINT32	machdep_WaitImmediateFifoEmpty	( void );

/****************************************************************************
	 dummy Description
 ****************************************************************************/
static void dummy_IntFunc( UINT8 ctrl )
{
	(void)ctrl;
	
	MADEVDRV_DBGMSG((" dummy_IntFunc: ctrl=%d\n", ctrl));
}
/****************************************************************************
 *	MaDevDrv_GetSeekBuffer
 *
 *	Description:
 *			Return pointer to buffer and size of buffer for setting control
 *			values when seek.
 *	Arguments:
 *			*size		pointer to buffer size
 *	Return:
 *			pointer to buffer
 *
 ****************************************************************************/
UINT8 * MaDevDrv_GetSeekBuffer( UINT16 * size )
{
	*size = MA_FIFO_SIZE * MA_SBUF_NUM;

	return cinfo_ptr->sbuf_buffer[0];
}
/****************************************************************************
 *	MaDevDrv_SeekControl
 *
 *	Description:
 *			Send control values when seek.
 *	Arguments:
 *			seq_id		sequence id
 *			buf_size	buffer byte size
 *	Return:
 *			0			success
 *			< 0			error code
 *
 ****************************************************************************/
SINT32 MaDevDrv_SeekControl
( 
	SINT32	seq_id,						/* sequence id */
	UINT32	buf_size					/* byte size of buffer */
)
{
	UINT8 *	buf_ptr;					/* pointer to buffer */
	SINT32	result;						/* result of function */
	static UINT8	packet0[3] = { 0x61, 0x82, 0x81 };	/* start sequencer */
	static UINT8	packet1[3] = { 0x61, 0x82, 0x80 };	/* stop sequencer */
	
	/* delayed sequence only */
	if ( seq_id != MASMW_SEQTYPE_DELAYED )
	{
		return MASMW_ERROR;
	}

	/* write control data to H/W FIFO for seek */
	buf_ptr = cinfo_ptr->sbuf_buffer[0];
	if ( buf_size != 0 )
	{
		MaDevDrv_SendDelayedPacket( buf_ptr, buf_size );
	}

	/* disable smooth volume setting */
	MaDevDrv_DeviceControl( 8, 0x00, 0x00, 0x00 );

	/* start the MA-3 H/W sequencer */
	result = MaDevDrv_SendDirectPacket( packet0, 3 );

	/* waiting for FIFO empty */
	result = machdep_WaitDelayedFifoEmpty();
	
	/* stop the MA-3 H/W sequencer */
	MaDevDrv_SendDirectPacket( packet1, 3 );

	/* enable smooth volume setting */
	MaDevDrv_DeviceControl( 8, 0x03, 0x03, 0x03 );

	return result;
}
/****************************************************************************
 *	MaDevDrv_GetStreamPos
 *
 *	Description:
 *			Get position of stream audio.
 *	Arguments:
 *			ctrl	0: get current position
 *					1: reset position count
 *	Return:
 *			position of stream audio [ms]
 *
 ****************************************************************************/
UINT32 MaDevDrv_GetStreamPos
(
	UINT8 ctrl
)
{
	UINT32	result = 0;					/* result of function */
	
	switch ( ctrl )
	{
	case 0:
		result = (UINT32)( cinfo_ptr->streaminfo.position[0] * 20 );
		break;
	
	case 1:
		cinfo_ptr->streaminfo.position[0] = 0;
		break;
		
	default:
		break;
	}

	return result;
}
/****************************************************************************
 *	MaDevDrv_SetAudioMode
 *
 *	Description:
 *			Set the flag of audio sequence.
 *	Arguments:
 *			mode	0: none audio sequence
 *					1: audio sequence
 *	Return:
 *			None
 *
 ****************************************************************************/
void MaDevDrv_SetAudioMode( UINT8 mode )
{
	cinfo_ptr->audio_mode = mode;
}
/****************************************************************************
 *	MaDevDrv_ControlInterrupt
 *
 *	Description:
 *			Enable or disable the interrupt.
 *	Arguments:
 *			ctrl		control flag (0: enable, 1: disable)
 *			int_ctrl	interrupt number
 *	Return:
 *			None
 *
 ****************************************************************************/
void MaDevDrv_ControlInterrupt
(
	UINT8	ctrl,
	UINT8	int_ctrl
)
{
	UINT8	data;
	UINT8	packet[3];
	
	/* interrupt disable */

	data = (UINT8)MaDevDrv_ReceiveData( MA_INT_SETTING, 1 );

	if ( ctrl == 0 )		/* enable */
	{
		data |= int_ctrl;
	}
	else					/* diable */
	{
		data &= (UINT8)( ~int_ctrl );
	}
	
	packet[0] = (UINT8)(  MA_INT_SETTING       & 0x7F );
	packet[1] = (UINT8)( (MA_INT_SETTING >> 7) | 0x80 );
	packet[2] = (UINT8)(  data                  | 0x80 );
	MaDevDrv_SendDirectPacket( packet, 3 );

	/* interrupt enable */
}
/****************************************************************************
 *	MaDevDrv_AddIntFunc
 *
 *	Description:
 *			Add the interrupt function of hardware interrupt.
 *	Arguments:
 *			number		interrupt number
 *						  0 SIRQ#0	software interrupt #0
 *						  1 SIRQ#1	software interrupt #1
 *						  2 SIRQ#2	software interrupt #2
 *						  3 SIRQ#3	software interrupt #3
 *						  4
 *						  5 TM#0	timer #0
 *						  6 TM#1	tiemr #1
 *						  7 FIFO	FIFO
 *			int_func	pointer to the interrupt function
 *	Return:
 *
 ****************************************************************************/
SINT32 MaDevDrv_AddIntFunc
(
	UINT8	number,
	void	(* int_func)(UINT8 ctrl)
)
{
	MADEVDRV_DBGMSG(("    MaDevDrv_AddIntFunc: %d\n", number));
	
	cinfo_ptr->int_func[number] = int_func;
	cinfo_ptr->int_func_map |= (UINT8)1 << number;
	
	return MASMW_SUCCESS;
}
/****************************************************************************
 *	MaDevDrv_RemoveIntFunc
 *
 *	Description:
 *			Remove the specified interrupt function.
 *	Argument:
 *			number		function number
 *	Return:
 *			0			success
 *			< 0			error
 *
 ****************************************************************************/
SINT32 MaDevDrv_RemoveIntFunc
(
	UINT8		number
)
{
	MADEVDRV_DBGMSG(("    MaDevDrv_RemoveIntFunc: %d\n", number));
	
	cinfo_ptr->int_func[number] = dummy_IntFunc;
	cinfo_ptr->int_func_map &= ~(UINT8)1 << number;
	
	return MASMW_SUCCESS;
}
/****************************************************************************
 *	MaDevDrv_IntHandler
 *
 *	Description:
 *			Interrupt handler for hardware interrupts.
 *	Argument:
 *			None
 *	Return:
 *			None
 *
 ****************************************************************************/
void MaDevDrv_IntHandler( void )
{
	UINT32	i;
	UINT8	read_data;
	UINT8	int_num;

	static UINT8	ma_int_priority[8] = { 0, 1, 6, 7, 2, 3, 5, 4 };

	MADEVDRV_DBGMSG(("    MaDevDrv_IntHandler\n"));

	machdep_WriteStatusFlagReg( (UINT8)MA_INTERRUPT_FLAG_REG );

	read_data = machdep_ReadDataReg();

	cinfo_ptr->mask_interrupt = 0x00;

	for ( i = 0; i < 8; i++ )
	{
		int_num = ma_int_priority[i];
		
		if ( ( read_data & (1 << int_num) ) != 0 )
		{
			if ( ( cinfo_ptr->int_func_map & (1 << int_num) ) != 0 )
			{
				if ( int_num != 7 )
				{
					machdep_WriteStatusFlagReg( (UINT8)MA_INTERRUPT_FLAG_REG );

					machdep_WriteDataReg( (UINT8)( 1 << int_num ) );
				}

				cinfo_ptr->int_func[int_num](0);
				if ( int_num == 7 )
				{
					machdep_WriteStatusFlagReg( (UINT8)MA_INTERRUPT_FLAG_REG );

					machdep_WriteDataReg( (UINT8)( 1 << int_num ) );
				}
			}
		}
	}
	
	cinfo_ptr->mask_interrupt = 0x80;
	machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );
}
/****************************************************************************
 *	MaDevDrv_SendDelayedPacket
 *
 *	Description:
 *			Write delayed packets to the REG_ID #1 delayed write register.
 *	Argument:
 *			ptr			pointer to the delayed packets
 *			size		size of the delayed packets
 *	Return:
 *			MASMW_SUCCESS(0)
 *
 ****************************************************************************/
SINT32 MaDevDrv_SendDelayedPacket
(
	const UINT8 * ptr,					/* pointer to packets */
	UINT32	      size					/* byte size of packets */
)
{
#if MASMW_DEBUG
	SINT32	result;

	result = madebug_SendDelayedPacket( ptr, (UINT16)size );
	if ( result < MASMW_SUCCESS ) return result;
#endif

	MADEVDRV_DBGMSG(("    MaDevDrv_SendDelayedPacket: pt=%p, sz=%d\n", ptr, size));

	machdep_WriteStatusFlagReg( MA_DELAYED_WRITE_REG );
	
#if 1
	while ( (size--) != 0 )
#else
	for ( i = 0; i < size; i++ )
#endif
	{
		machdep_WriteDataReg( *ptr++ );
	}

	machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );
	
	return MASMW_SUCCESS;
}
/****************************************************************************
 *	MaDevDrv_SendDirectPacket
 *
 *	Description:
 *			Write direct packets to the REG_ID #2 direct write register.
 *	Argument:
 *			ptr			pointer to the direct packets
 *			size		size of the direct packets
 *	Return:
 *			MASMW_SUCCESS(0)
 *
 ****************************************************************************/
SINT32 MaDevDrv_SendDirectPacket
(
	const UINT8 * ptr,					/* pointer to packets */
	UINT32 size							/* byte size of packets */
)
{
	UINT32	i, j;
	SINT32	result;

#if MASMW_DEBUG
	result = madebug_SendDirectPacket( ptr, (UINT16)size );
	if ( result < MASMW_SUCCESS ) return result;
#endif

	MADEVDRV_DBGMSG(("    MaDevDrv_SendDirectPacket: pt=%p, sz=%d\n", ptr, size));
	
	machdep_WriteStatusFlagReg( MA_IMMEDIATE_WRITE_REG );

#if 1
	i = size/64;
	while ( (i--) != 0 )
#else
	for ( i = 0; i < (size/64); i++ )
#endif
	{
		result = machdep_WaitImmediateFifoEmpty();
		if ( result < MASMW_SUCCESS )
		{
			machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );
			return result;
		}
#if 1
		j = 64;
		while ( (j--) != 0 )
#else
		for ( j = 0; j < 64; j++ )
#endif
		{
			machdep_WriteDataReg( *ptr++ );
		}
	}

	if ( (size %64) != 0 )
	{
		result = machdep_WaitImmediateFifoEmpty();
		if ( result < MASMW_SUCCESS )
		{
			machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );
			return result;
		}
		
#if 1
		j = size%64;
		while ( (j--) != 0 )
#else
		for ( j = 0; j < (size%64); j++ )
#endif
		{
			machdep_WriteDataReg( *ptr++ );
		}
	}

	machdep_WriteStatusFlagReg( cinfo_ptr->mask_interrupt );

	return MASMW_SUCCESS;
}
/****************************************************************************
 *	MaDevDrv_ReceiveData
 *
 *	Description:
 *			Read byte data of register or memory.
 *	Argument:
 *			address			address of the register for read
 *			buffer_address	address of the return buffer
 *	Return:
 *			MASMW_SUCCESS(0)
 *
 ****************************************************************************/
SINT32 MaDevDrv_ReceiveData
(
	UINT32	address,			/* address of register */
	UINT8	buffer_address		/* address of read buffer */
)
{
	UINT8	i;
	UINT8	packet_buffer[4];
	UINT8	valid_rx;
	UINT8	read_data;
	UINT8	count;
	SINT32	result;
/*
	MADEVDRV_DBGMSG(("MaDevDrv_ReceiveData: adrs=%ld, bufadrs=%d\n", address, buffer_address));
 */	
	machdep_WriteStatusFlagReg( MA_IMMEDIATE_READ_REG );
	
	
	if		( address < 0x0080 )	count = 0;
	else if ( address < 0x4000 )	count = 1;

⌨️ 快捷键说明

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