📄 jbighw.c
字号:
/*
* Start of Zoran Standard Header
* Copyright (c) 2002-2004 Zoran Corporation
*
*
* All rights reserved. Proprietary and confidential.
*
* DESCRIPTION for jbighw.c
* JBIG Hardware Access Routines for the ZR4100
*
* NEW HISTORY COMMENT (description must be followed by a blank line)
* <Enter change description here>
* ===== HISTORY of changes in //depot/misc/projects/tps/srcsnk/jbighw.c
*
* 2/Jun/04 #4 pshread Removed prinf's
* 19/Feb/04 #3 emiller Standardize register access on IO_READ32/IO_WRITE32;
* use globally accessible register names from oti4100.h
*
* End of Zoran Standard Header
*/
/* Copyright (c) 2002 Zoran Corporation All rights reserved. */
/** @file jbighw.c
* The JBIG harware interface.
*/
#include "standard.h"
#include "jbig.h"
#include "jbighw.h"
#include "icu.h"
#include "fireregs.h"
#include "iomacros.h"
#include "dbg.h"
#include "ts.h"
//#include "printmgr.h"
/******************************************************************************
Constants/Macros
******************************************************************************/
/* JBIG module registers*/
/** JBIG Mode Register */
#define JMR_DLE (1<<25)
#define JMR_MBE (1<<24)
#define JMR_DST_SHIFT 19 /* JMR */
#define JMR_SST_SHIFT 16
#define JMR_FS 0x8000
#define JMR_PC 0x4000
#define JMR_ENCODE 0
#define JMR_DECODE 0x2000
#define JMR_SBO 0x1000
#define JMR_EOL 0x800
#define JMR_QS 0x400
#define JMR_THROTTLE 0x200
#define JMR_CE 0x100
#define JMR_BS 0x80
#define JMR_TP 0x40
#define JMR_SE 0x20
#define JMR_STEP 0x10
#define JMR_ALOAD 4 /* OP field */
#define JMR_ASTORE 8
#define JMR_AERASE 12
#define JMR_CLP 2
#define JMR_EN 1
/** JBIG Status Register */
#define JSR_BO 0x4 /* JSR */
#define JSR_ME 0x2
#define JSR_EF 0x1
/** JBIG Template Definition Register */
#define TDEF_WA 0x400 /* TDEF */
#define TDEF_CON2 0x280
#define TDEF_CON4 0x300
#define TDEF_CON8 0x380
#define TDEF_ABIC 0x200
#define TDEF_TWOL 0
#define TDEF_THREEL 0x100
/******************************************************************************
Globals
******************************************************************************/
/******************************************************************************
Statics
******************************************************************************/
/** A high level interrupt triggered by the JBIG ISR to release the
WorkingSem.*/
static tsHighISR sJbigHISR;
/** A semaphore to give only one task access to the JBIG hard ware.*/
static tsSemaphore sJbigLock;
/** A semphore to block on while waiting for the JBIG engine to
finish.*/
/******************************************************************************
Prototypes
******************************************************************************/
static void JbigInterruptClear(void);
#if 0
static void JbigInterruptEnable(void);
static void JbigInterruptDisable(void);
/** Enable the JBIG interrupt*/
static void JbigInterruptEnable(void)
{
ICU_InterruptEnable(IRQ_JBIG);
}
/** Disable the JBIG interrupt*/
static void JbigInterruptDisable(void)
{
ICU_InterruptDisable(IRQ_JBIG);
}
#endif
/**Clear the JBIG interrupt*/
static void JbigInterruptClear(void)
{
ICU_InterruptClear(IRQ_JBIG);
}
/**
* LISR gets called by OS when the JBIG interrupt goes off.
* Clears teh interrupt and kicks off the JbigHISR.
*
* @param interrupt the interrupt vector number
*/
void JbigLISR(int interrupt)
{
JbigInterruptClear();
TaskHisrActivate(sJbigHISR);
}
/**
* Release the working semaphore to tell any pending tasks the JBIG
* engine has stopped.
*/
void JbigHISR(void)
{
PSPRINTF("JbigHISR!\n");
/*tell any pending tasks we are done*/
}
/** Install the drivers high level interrupt handler.*/
static Uint32 sJbigStack[128];
void JbigCreateHISR(void)
{
sJbigHISR = TaskHisrCreate(JbigHISR, 2, sizeof(sJbigStack), sJbigStack, "JBIGHISR");
ASSERT(sJbigHISR > INVALIDHISR);
}
/** Create a semaphore to protect the JBIG hardware.*/
void JbigCreateSem(void)
{
sJbigLock = TaskSemCreatePri( 1 );
ASSERT(sJbigLock > INVALIDSEM);
}
/**
* Initialize the JBIG driver. Create the HISR. Install the LISR.
* Reset the JBIG engine. Enable the JBIG interrupt. */
void JbigInit(void)
{
JbigCreateSem();
JbigCreateHISR();
TaskIsrRegister(IRQ_JBIG, JbigLISR, 0x0a);
JbigReset();
//JbigInterruptEnable();
}
/**
* Don't call any functions in this module (except JbigInit()) unless
* you take this sem first.*/
void JbigTakeSem(void)
{
ASSERT(0 == TaskSemWait(sJbigLock));
}
/**
* When done using this module call JbigGiveSem() to release the
* module. */
void JbigGiveSem(void)
{
ASSERT( 0 == TaskSemSignal(sJbigLock));
}
/**Get the number of bytes written to the dst buffer.*/
Uint32 JbigGetBytesWritten(void)
{
return IO_READ32(JDAC);
}
/**Set up the jbig engine to use a two line template.*/
void JbigUseTwoLineTemplate(void)
{
IO_WRITE32(TDEF, TDEF_TWOL);
}
/**Set up the jbig engine to use a three line template.*/
void JbigUseThreeLineTemplate(void)
{
IO_WRITE32(TDEF, TDEF_THREEL);
}
Uint32 JbigGetLineCount(void)
{
return IO_READ32(JDAC);
}
/**Reset the jbig engine.*/
void JbigReset(void)
{
IO_WRITE32(JRST, 0);
}
/**Set the height and width of the image. Height goes into the top 16
bits of JIDR and width into the lower 16.
@param height number of lines in image
@param width width of image pixels
*/
void JbigSetImageDimentions(Uint16 height, Uint16 width)
{
Uint32 dim = height;
dim = dim << 16;
dim = dim | width;
IO_WRITE32(JIDR, dim);
}
// ~~~ Set the source address register. ~~~
void JbigSetSrcAddress(Uint8 *src)
{
IO_WRITE32(JSRC, src);
}
// ~~~ Set the destination address register. ~~~
void JbigSetDstAddress(Uint8 *dst)
{
IO_WRITE32(JDES, dst);
}
/** Set the clip address. This is the address the jbig engine should
stop at. Clipping must be enabled for this to have an effect.*/
void JbigSetClipAddress(Uint8 *clip)
{
IO_WRITE32(JDCL, clip);
}
/** Get the number of bytes read by the jbig engine.*/
Uint32 JbigGetActualSrcCount(void)
{
return IO_READ32(JASC);
}
/** Read the status register.*/
Uint32 JbigGetStatusRegister(void)
{
return IO_READ32(JSR);
}
/** Read and decode the status register. Prints a readable dump to stdout.*/
void JbigDumpStatusRegister()
{
Uint32 sts = JbigGetStatusRegister();
PSPRINTF("JSR:\t");
if( JSR_BO & sts ) PSPRINTF("Buffer Overflow ");
if( JSR_ME & sts ) PSPRINTF("Stripe Corrupted ");
if( JSR_EF & sts ) PSPRINTF("Found Escape");
PSPRINTF("\n");
}
/**Wait until the running bit in the JMR is no longer set.
@todo Change this to pend on semaphore.
*/
void JbigWaitForDone(void)
{
//BOOL high;
//while( IO_READ32(JMR) &1 );
while( IO_READ32(JMR) &1)
{
//high = GPIO35Read(GPIO35MODE_PFHPARSER);
//GPIO35Set(0, GPIO35MODE_PFHPARSER);
NU_Sleep(1);
//GPIO35Set(high, GPIO35MODE_PFHPARSER);
}
}
/** Start a jmem erase operation.*/
void JbigStartErase(void)
{
IO_WRITE32(JMR, JMR_THROTTLE | JMR_DLE | JMR_FS | JMR_AERASE | JMR_EN);
}
/** Start a jmem save operation.*/
void JbigStartJmemSave(void)
{
IO_WRITE32(JMR, JMR_THROTTLE | JMR_FS | JMR_ASTORE | JMR_EN);
}
/** Start a jmem load operation.*/
void JbigStartJmemLoad(void)
{
IO_WRITE32(JMR, JMR_THROTTLE | JMR_FS | JMR_ALOAD | JMR_EN);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ~~~ clear the JMEM ~~~
void JbigJmemErase()
{
JbigReset();
JbigSetImageDimentions(1, 0x2000);
JbigStartErase();
JbigWaitForDone();
}
/** Save the jmem to buffer*/
void JbigJmemSave (Uint8 *buffer)
{
ASSERT(((Uint32)buffer & 0x7)==0);
JbigSetImageDimentions(1, 0x2000);
JbigSetDstAddress(buffer);
JbigStartJmemSave();
JbigWaitForDone();
}
/**Load the jmem with buffer created by a call to JbigJmemSave().*/
void JbigJmemLoad(Uint8 *buffer)
{
ASSERT(((Uint32)buffer & 0x7)==0);
JbigSetImageDimentions(1, 0x2000);
JbigSetSrcAddress(buffer);
JbigStartJmemLoad();
JbigWaitForDone();
}
/**Start an encode on the jbig engine*/
void JbigStartEncode(Bool first_stripe, Bool preserve_coder, Uint32 stripe_end, Uint32 dstoffset, Uint32 srcoffset)
{
Uint32 jmr;
jmr = (JMR_THROTTLE |
JMR_DLE |
JMR_CE |
JMR_EN |
JMR_ENCODE |
(srcoffset << JMR_SST_SHIFT) |
(dstoffset << JMR_DST_SHIFT));
if( stripe_end==SDNORM )
jmr |= JMR_SE;
if( first_stripe )
jmr |= JMR_FS;
if( preserve_coder )
jmr |=JMR_PC;
IO_WRITE32(JMR, jmr);
}
/**Start a decode on the jbig engine*/
void JbigStartDecode(Bool first_stripe, Bool preserve_coder, Uint32 stripe_end,Uint32 dstoffset, Uint32 srcoffset)
{
Uint32 jmr;
jmr = (JMR_THROTTLE |
JMR_DLE |
JMR_CE |
JMR_EN |
JMR_DECODE |
(srcoffset << JMR_SST_SHIFT) |
(dstoffset << JMR_DST_SHIFT));
if( stripe_end==SDNORM )
jmr |= JMR_SE;
if( first_stripe )
jmr |= JMR_FS;
if( preserve_coder )
jmr |=JMR_PC;
IO_WRITE32(JMR, jmr);
}
/**Get the ecape code from the end of an encoded stripe.*/
Uint32 JbigGetEscapeCode(void)
{
Uint32 sts = JbigGetStatusRegister();
Uint32 esc = 0;
if( sts & JSR_EF )
esc = ((sts >> 8) & 0xFF);
return esc;
}
/**Get the number of bytes read by the jbig engine.*/
Uint32 JbigGetBytesRead(void)
{
return JbigGetActualSrcCount();
}
/**Return true is status register shows a corrupted stripe.*/
Bool JbigStripeCorrupted(void)
{
Uint32 sts = JbigGetStatusRegister();
return((sts&JSR_ME)==JSR_ME);
}
// Cellming
// 2006-04-18
Bool JbigOverFlow(void)
{
Uint32 sts = JbigGetStatusRegister();
return((sts&JSR_BO)==JSR_BO);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -