📄 madevdrv.c
字号:
#include "predef.h"
#include "Madevdrv.h"
#include "Machdep.h"
/***********************************************************/
/* Function Name : MaDevDrv_ClearFifo */
/* Description : clear FIFO */
/* Note : It's a part of Initialization */
/***********************************************************/
SINT32 MaDevDrv_ClearFifo(void)
{
static UINT8 packet[3] = { ( ( MA_SEQUENCE + 2 ) & 0x7F ),
( ( ( MA_SEQUENCE + 2 ) >> 7 ) | 0x80 ),
( MA_INT_POINT | 0x80 ) };
machdep_WriteStatusFlagReg( MA_BASIC_SETTING_REG );
machdep_WriteDataReg( 0x28 );
machdep_Wait( 300 ); /* wait 300ns */
machdep_WriteDataReg( 0x00 );
MaDevDrv_SendDirectPacket( packet, 3 );
machdep_WriteStatusFlagReg( 0x80 );
return MASMW_SUCCESS;
}
/***********************************************************/
/* Function Name : MaDevDrv_SendDelayedPacket */
/* Description : Send data via Sequencer (delay path */
/* Note : The delayed path FIFO size is 512 byte. */
/* Set the interrupt point before start. */
/* When the data size less than the POINT, */
/* the FIFO IRQ may be present. */
/***********************************************************/
SINT32 MaDevDrv_SendDelayedPacket
(
const UINT8 * ptr, /* pointer to packets */
UINT32 size /* byte size of packets */
)
{
static UINT8 flag = 0;
static UINT8 count = 0;
UINT32 result;
UINT8 packet[3];
if( flag == 0 )
{
count += size;
/* the sequencer will start while count >256B(INT_POINT) */
if( count > MA_FIFO_SIZE )
{
flag = 1;
/* Enable FIFO interrupt and disable other interrupts */
packet[0] = (UINT8)( MA_INT_SETTING & 0x7F ); /* address */
packet[1] = (UINT8)( (MA_INT_SETTING >> 7) | 0x80 );
packet[2] = (UINT8)( 0x40 | 0x80 ); /* data */
MaDevDrv_SendDirectPacket( packet, 3 );
/* start sequencer */
packet[0] = (UINT8)( MA_START_SEQ & 0x7F ); /* address */
packet[1] = (UINT8)( (MA_START_SEQ >> 7) | 0x80 );
packet[2] = (UINT8)( 0x81 ); /* data */
MaDevDrv_SendDirectPacket( packet, 3 );
}
machdep_WriteStatusFlagReg( MA_DELAYED_WRITE_REG );
while ( (size--) != 0 )
{
machdep_WriteDataReg( *ptr++ );
}
machdep_WriteStatusFlagReg( 0x80 );
return MASMW_SUCCESS;
}
result = machdep_CheckFifoInterrupt();
if( result != MASMW_SUCCESS )
{
machdep_WriteStatusFlagReg( 0x80 );
return result;
}
machdep_WriteStatusFlagReg( MA_DELAYED_WRITE_REG );
while ( (size--) != 0 )
{
machdep_WriteDataReg( *ptr++ );
}
machdep_WriteStatusFlagReg( 0x80 );
return MASMW_SUCCESS;
}
/**************************************************************/
/* Function Name : MaDevDrv_SendDirectPacket */
/* Description : send data via instantaneous path */
/* Note : usually used for Control Event process */
/**************************************************************/
SINT32 MaDevDrv_SendDirectPacket
(
const UINT8 * ptr, /* pointer to packets */
UINT32 size /* byte size of packets */
)
{
UINT32 i, j;
SINT32 result;
machdep_WriteStatusFlagReg( MA_IMMEDIATE_WRITE_REG );
i = size/64;
while ( (i--) != 0 )
{
result = machdep_WaitImmediateFifoEmpty();
if ( result < MASMW_SUCCESS )
{
machdep_WriteStatusFlagReg( 0x80 );
return result;
}
j = 64;
while ( (j--) != 0 )
{
machdep_WriteDataReg( *ptr++ );
}
}
if ( (size %64) != 0 )
{
result = machdep_WaitImmediateFifoEmpty();
if ( result < MASMW_SUCCESS )
{
machdep_WriteStatusFlagReg( 0x80 );
return result;
}
j = size%64;
while ( (j--) != 0 )
{
machdep_WriteDataReg( *ptr++ );
}
}
machdep_WriteStatusFlagReg( 0x80 );
return MASMW_SUCCESS;
}
/*************************************************************/
/* Function Name : MaDevDrv_SendDirectRamData */
/* Description : send data to RAM via instantaneous path. */
/* Note : usually used for Exclusize Event process */
/*************************************************************/
SINT32 MaDevDrv_SendDirectRamData
(
UINT32 address, /* address of internal ram */
UINT8 data_type, /* type of data */
const UINT8 * data_ptr, /* pointer to data */
UINT32 data_size /* size of data */
)
{
UINT32 i, j;
UINT8 packet_buffer[3+2];
UINT32 count;
UINT32 write_size;
UINT8 write_data;
UINT8 temp = 0;
SINT32 result;
if ( data_size == 0 ) return MASMW_SUCCESS;
machdep_WriteStatusFlagReg( MA_IMMEDIATE_WRITE_REG );
packet_buffer[0] = (UINT8)( (address >> 0 ) & 0x7F );
packet_buffer[1] = (UINT8)( (address >> 7 ) & 0x7F );
packet_buffer[2] = (UINT8)( (address >> 14 ) | 0x80 );
if ( data_type == 0 )
{
write_size = data_size;
}
else
{
write_size = (data_size / 8) * 7;
if ( data_size % 8 != 0 )
write_size = (UINT32)( write_size + (data_size % 8 - 1) );
}
if ( write_size < 0x0080 )
{
packet_buffer[3] = (UINT8)( (write_size >> 0) | 0x80 );
count = 4;
}
else
{
packet_buffer[3] = (UINT8)( (write_size >> 0) & 0x7F );
packet_buffer[4] = (UINT8)( (write_size >> 7) | 0x80 );
count = 5;
}
result = machdep_WaitImmediateFifoEmpty();
if ( result < MASMW_SUCCESS )
{
machdep_WriteStatusFlagReg( 0x80 );
return result;
}
for ( i = 0; i < count; i++ )
{
machdep_WriteDataReg( packet_buffer[i] );
}
if ( data_type == 0 )
{
i = data_size/64;
while ( (i--) != 0 )
{
result = machdep_WaitImmediateFifoEmpty();
if ( result < MASMW_SUCCESS )
{
machdep_WriteStatusFlagReg( 0x80 );
return result;
}
j = 64;
while ( (j--) != 0 )
{
machdep_WriteDataReg( *data_ptr++ );
}
}
if ( (data_size%64) != 0 )
{
result = machdep_WaitImmediateFifoEmpty();
if ( result < MASMW_SUCCESS )
{
machdep_WriteStatusFlagReg( 0x80 );
return result;
}
j = data_size%64;
while ( (j--) != 0 )
{
machdep_WriteDataReg( *data_ptr++ );
}
}
}
else
{
for ( i = 0; i < data_size; i++ )
{
if ( (i & 0xFFFFFFC0) == 0 )
{
result = machdep_WaitImmediateFifoEmpty();
if ( result < MASMW_SUCCESS )
{
machdep_WriteStatusFlagReg( 0x80 );
return result;
}
}
if ( ( i % 8 ) == 0 )
{
temp = *data_ptr++;
}
else
{
write_data = *data_ptr++;
write_data |= (UINT8)( ( temp << (i % 8) ) & 0x80 );
machdep_WriteDataReg( write_data );
}
}
}
machdep_WriteStatusFlagReg( 0x80 );
return MASMW_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -