LTCD_060719.ISO
This commit is contained in:
commit
f86e69648b
156 files changed
+49537
No files matched your search
@@ -0,0 +1,172 @@
|
||||
public class U1Fifo
|
||||
{
|
||||
U1 *buf;
|
||||
U8 mask,in_ptr,out_ptr;
|
||||
};
|
||||
|
||||
public U1Fifo *NewU1Fifo(U8 size)
|
||||
{
|
||||
U1Fifo *f;
|
||||
f=MAlloc(sizeof(U1Fifo));
|
||||
f->buf=MAlloc(size);
|
||||
f->mask=size-1;
|
||||
f->in_ptr=0;
|
||||
f->out_ptr=0;
|
||||
return f;
|
||||
}
|
||||
|
||||
public void DelU1Fifo(U1Fifo *f)
|
||||
{
|
||||
Free(f->buf);
|
||||
Free(f);
|
||||
}
|
||||
|
||||
public BoolU4 U1FifoInsert(U1Fifo *f,U1 ch)
|
||||
{
|
||||
U8 old_flags=GetFlags,
|
||||
new_in_ptr;
|
||||
Cli;
|
||||
new_in_ptr=(f->in_ptr+1)&f->mask;
|
||||
if (new_in_ptr==f->out_ptr) {
|
||||
SetFlags(old_flags);
|
||||
return FALSE;
|
||||
} else {
|
||||
f->buf[f->in_ptr]=ch;
|
||||
f->in_ptr=new_in_ptr;
|
||||
SetFlags(old_flags);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
public BoolU4 U1FifoRemove(U1Fifo *f,U1 *ch)
|
||||
{
|
||||
U8 old_flags=GetFlags;
|
||||
Cli;
|
||||
if (f->in_ptr==f->out_ptr) {
|
||||
SetFlags(old_flags);
|
||||
return FALSE;
|
||||
} else {
|
||||
*ch=f->buf[f->out_ptr];
|
||||
f->out_ptr=(f->out_ptr+1)&f->mask;
|
||||
SetFlags(old_flags);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
public BoolU4 U1FifoPeek(U1Fifo *f,U1 *ch)
|
||||
{
|
||||
U8 old_flags=GetFlags;
|
||||
Cli;
|
||||
if (f->in_ptr==f->out_ptr) {
|
||||
SetFlags(old_flags);
|
||||
return FALSE;
|
||||
} else {
|
||||
*ch=f->buf[f->out_ptr];
|
||||
SetFlags(old_flags);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
public void U1FifoFlush(U1Fifo *f)
|
||||
{
|
||||
f->out_ptr=f->in_ptr;
|
||||
}
|
||||
|
||||
public U8 U1FifoCnt(U1Fifo *f)
|
||||
{
|
||||
U8 result,old_flags=GetFlags;
|
||||
Cli;
|
||||
if (f->out_ptr>f->in_ptr)
|
||||
result=f->mask+1-(f->out_ptr-f->in_ptr);
|
||||
else
|
||||
result=f->in_ptr-f->out_ptr;
|
||||
SetFlags(old_flags);
|
||||
return result;
|
||||
}
|
||||
|
||||
public class U4Fifo
|
||||
{
|
||||
U4 *buf;
|
||||
U8 mask,in_ptr,out_ptr;
|
||||
};
|
||||
|
||||
public U4Fifo *NewU4Fifo(U8 size)
|
||||
{
|
||||
U4Fifo *f;
|
||||
f=MAlloc(sizeof(U4Fifo));
|
||||
f->buf=MAlloc(size*sizeof(U4));
|
||||
f->mask=size-1;
|
||||
f->in_ptr=0;
|
||||
f->out_ptr=0;
|
||||
return f;
|
||||
}
|
||||
|
||||
public void DelU4Fifo(U4Fifo *f)
|
||||
{
|
||||
Free(f->buf);
|
||||
Free(f);
|
||||
}
|
||||
|
||||
public BoolU4 U4FifoInsert(U4Fifo *f,U4 d)
|
||||
{
|
||||
U8 old_flags=GetFlags,
|
||||
new_in_ptr;
|
||||
Cli;
|
||||
new_in_ptr=(f->in_ptr+1)&f->mask;
|
||||
if (new_in_ptr==f->out_ptr) {
|
||||
SetFlags(old_flags);
|
||||
return FALSE;
|
||||
} else {
|
||||
f->buf[f->in_ptr]=d;
|
||||
f->in_ptr=new_in_ptr;
|
||||
SetFlags(old_flags);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
public BoolU4 U4FifoRemove(U4Fifo *f,U4 *d)
|
||||
{
|
||||
U8 old_flags=GetFlags;
|
||||
Cli;
|
||||
if (f->in_ptr==f->out_ptr) {
|
||||
SetFlags(old_flags);
|
||||
return FALSE;
|
||||
} else {
|
||||
*d=f->buf[f->out_ptr];
|
||||
f->out_ptr=(f->out_ptr+1)&f->mask;
|
||||
SetFlags(old_flags);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
public BoolU4 U4FifoPeek(U1Fifo *f,U4 *d)
|
||||
{
|
||||
U8 old_flags=GetFlags;
|
||||
Cli;
|
||||
if (f->in_ptr==f->out_ptr) {
|
||||
SetFlags(old_flags);
|
||||
return FALSE;
|
||||
} else {
|
||||
*d=f->buf[f->out_ptr];
|
||||
SetFlags(old_flags);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
public void U4FifoFlush(U4Fifo *f)
|
||||
{
|
||||
f->out_ptr=f->in_ptr;
|
||||
}
|
||||
|
||||
public U8 U4FifoCnt(U4Fifo *f)
|
||||
{
|
||||
U8 result,old_flags=GetFlags;
|
||||
Cli;
|
||||
if (f->out_ptr>f->in_ptr)
|
||||
result=f->mask+1-(f->out_ptr-f->in_ptr);
|
||||
else
|
||||
result=f->in_ptr-f->out_ptr;
|
||||
SetFlags(old_flags);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user