📄 hw_lib.c
字号:
#include "hw_lib.h"
#include <stdio.h>
#include <stdarg.h>
static int MemoryAllocBase = 0x01000000;
void* hw_alloc_physmem( int size , u32*phy )
{
int ret = MemoryAllocBase;
MemoryAllocBase += ( (size-1)/4096 + 1 )*4096;
*phy = ret;
return (void*)ret;
}
void hw_free_physmem( void*vir)
{
return;
}
void* hw_map_io( u32 phy , int size , int cacheenable )
{
return (void*)phy;
}
void hw_unmap_io( void*vir , int size )
{
return ;
}
typedef struct
{
volatile int* interruptreg;
int mask;
}InterruptHandle;
void* hw_init_interrupt( int id )
{
InterruptHandle *handle = (InterruptHandle*)malloc( sizeof(InterruptHandle) );
if( handle )
{
switch( id )
{
case InterruptID_ITUInput:
handle->interruptreg = (volatile int*)0x20011000;
handle->mask = 0x07<<3;
break;
case InterruptID_ITUOutput:
handle->interruptreg = (volatile int*)0x20011000;
handle->mask = 0x07;
break;
case InterruptID_Mp4Decoder:
handle->interruptreg = (volatile int*)0x20000000;
handle->mask = 0x02;
break;
case InterruptID_Mp4Encoder:
handle->interruptreg = (volatile int*)0x2000c010;
handle->mask = 0x02;
break;
case InterruptID_VIA:
handle->interruptreg = (volatile int*)0x200120f0;
handle->mask = 0xff;
break;
default:
free( handle );
}
}
return (void*)handle;
}
int hw_wait_interrupt( void*handle , unsigned int timeout )
{
InterruptHandle* h = (InterruptHandle*)handle;
while( !( *h->interruptreg & h->mask) && timeout )
{
hw_delay(1);
timeout --;
}
if( timeout > 0 )
return 0;
else
return -1;
}
void hw_complete_interrupt( void*handle )
{
return ;
}
void hw_release_interrupt( void*handle )
{
return;
}
void hw_delay( int ms )
{
int i;
for( i=0; i<3600*ms ; i++ );
i = i*2;
}
void* hw_init_critical()
{
return (void*)1;
}
int hw_enter_critical(void*c)
{
return 0;
}
int hw_leave_critical(void*c)
{
return 0;
}
void hw_release_critical(void*c)
{
return ;
}
int hw_flush_cache( void* vir , int size )
{
return 0;
}
int hw_get_framebuffer( u32*framebuffer , u32*width , u32*height)
{
if( framebuffer )
*framebuffer = 0x03000000;
if( width )
*width = 640;
if( height )
*height = 480;
return 0;
}
static struct
{
int status;
int type;
int priority;
FILE* tracefp;
}trace = { 0 , 0 , 0 , 0 };
int hw_trace_init( int type , int prio )
{
if( trace.status == 0 )
{
trace.status = 1;
trace.type = type;
trace.priority = prio;
if( type == 0 )
trace.tracefp = fopen("\\trace.txt" , "w" );
if( ((type == 0&&trace.tracefp)||type) )
return 0;
else
{
hw_trace_end();
return -1;
}
}
else
return -1;
}
int hw_trace_msg( int prio , char* fmt, ...)
{
if( trace.status && (prio&trace.priority) )
{
va_list args;
va_start(args, fmt);
if( trace.type == 0 && trace.tracefp )
vfprintf( trace.tracefp , fmt , args );
else
{
vprintf( fmt , args);
}
return 0;
}
else
return -1;
}
int hw_trace_end()
{
if( trace.status )
{
if( trace.type == 0 )
fclose( trace.tracefp );
memset( &trace , 0 , sizeof(trace) );
return 0;
}
else
return -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -