📄 philips_dtv_ref5.c
字号:
gpioEnableEV_INTEN(REF5_GPIO_UP_EVENT);
break;
}
case DTV_REF5_PIC_SOURCE_DN:
{
/* Initialize event handler for GPIOJ02. This pin uses event 3. */
gpioSetSOURCE_SEL(REF5_GPIO_DN_EVENT, GPIO_GPIOJ02);
gpioSetEVENT_MODE(REF5_GPIO_DN_EVENT, 0x02);
gpioEnableEV_INTEN(REF5_GPIO_DN_EVENT);
break;
}
default:
return PIC_ERR_SOURCE_NOT_AVAILABLE;
}
return TMLIBDEV_OK;
}
static tmLibdevErr_t dtvRef5PICTerm(UInt32 source)
{
DP_R5(("dtvRef5PICTerm(%d)\n", source));
switch (source)
{
case DTV_REF5_PIC_SOURCE_IR:
DP_R5(("close GPIO 05\n"));
/* Reset event handler for GPIOJ05. */
gpioDisableEV_INTEN(REF5_GPIO_IR_EVENT);
break;
case DTV_REF5_PIC_SOURCE_MENU:
DP_R5(("close GPIO 00\n"));
/* Reset event handler for GPIOJ00. */
gpioDisableEV_INTEN(REF5_GPIO_MENU_EVENT);
break;
case DTV_REF5_PIC_SOURCE_UP:
DP_R5(("close GPIO 01\n"));
/* Reset event handler for GPIOJ01. */
gpioDisableEV_INTEN(REF5_GPIO_UP_EVENT);
break;
case DTV_REF5_PIC_SOURCE_DN:
DP_R5(("close GPIO 02\n"));
/* Reset event handler for GPIOJ02. */
gpioDisableEV_INTEN(REF5_GPIO_DN_EVENT);
break;
default:
DP_R5(("PIC_ERR_SOURCE_NOT_AVAILABLE: %d requested\n", source));
return PIC_ERR_SOURCE_NOT_AVAILABLE;
}
return TMLIBDEV_OK;
}
/* called multiple times, as long as True is returned.
* allows priorization.
* fill in source to indicate which Int to process
*/
static Bool dtvRef5PICSourceDetect(UInt32 * source)
{
#if 0
Int i;
#endif
DP_R5(("dtvRef5PICSourceDetect()\n"));
if (gpioGetEV_OCCUR(REF5_GPIO_IR_EVENT))
{
DP_R5((" REF5_GPIO_IR_EVENT occurred\n"));
*source = DTV_REF5_PIC_SOURCE_IR;
return True;
}
if (gpioGetEV_OCCUR(REF5_GPIO_MENU_EVENT))
{
DP_R5((" REF5_GPIO_MENU_EVENT occurred\n"));
*source = DTV_REF5_PIC_SOURCE_MENU;
return True;
}
if (gpioGetEV_OCCUR(REF5_GPIO_UP_EVENT))
{
DP_R5((" REF5_GPIO_UP_EVENT occurred\n"));
*source = DTV_REF5_PIC_SOURCE_UP;
return True;
}
if (gpioGetEV_OCCUR(REF5_GPIO_DN_EVENT) )
{
DP_R5((" REF5_GPIO_DN_EVENT occurred\n"));
*source = DTV_REF5_PIC_SOURCE_DN;
return True;
}
#if 0
/* check which GPIO event brought us here */
for (i=1; i<8; i++)
{
if (gpioGetEV_INTEN(i))
DP_R5(("gpio event %d enabled\n", i));
if (gpioGetEV_OCCUR(i))
{
DP_R5(("gpio event %d occurred\n", i));
gpioEV_ACK(i);
gpioEV_ACKM(i);
}
}
#endif
/* no event detected */
return False;
}
static tmLibdevErr_t dtvRef5PICStart(UInt32 source)
{
DP_R5((" dtvRef5PICStart(%d)\n", source));
switch (source)
{
case DTV_REF5_PIC_SOURCE_IR:
case DTV_REF5_PIC_SOURCE_MENU:
case DTV_REF5_PIC_SOURCE_UP:
case DTV_REF5_PIC_SOURCE_DN:
return TMLIBDEV_OK;
default:
DP_R5(("source %d not available\n", source));
return PIC_ERR_SOURCE_NOT_AVAILABLE;
}
}
static tmLibdevErr_t dtvRef5PICStop(UInt32 source)
{
DP_R5((" dtvRef5PICStop (%d)\n", source));
switch (source)
{
case DTV_REF5_PIC_SOURCE_IR:
case DTV_REF5_PIC_SOURCE_MENU:
case DTV_REF5_PIC_SOURCE_UP:
case DTV_REF5_PIC_SOURCE_DN:
return TMLIBDEV_OK;
default:
DP_R5(("source %d not available\n", source));
return PIC_ERR_SOURCE_NOT_AVAILABLE;
}
}
static tmLibdevErr_t dtvRef5PICAck(UInt32 source)
{
DP_R5((" dtvRef5PICAck (%d)\n", source));
switch (source)
{
case DTV_REF5_PIC_SOURCE_IR:
gpioEV_ACK(REF5_GPIO_IR_EVENT);
gpioEV_ACKM(REF5_GPIO_IR_EVENT);
break;
case DTV_REF5_PIC_SOURCE_MENU:
gpioEV_ACK(REF5_GPIO_MENU_EVENT);
gpioEV_ACKM(REF5_GPIO_MENU_EVENT);
break;
case DTV_REF5_PIC_SOURCE_UP:
gpioEV_ACK(REF5_GPIO_UP_EVENT);
gpioEV_ACKM(REF5_GPIO_UP_EVENT);
break;
case DTV_REF5_PIC_SOURCE_DN:
gpioEV_ACK(REF5_GPIO_DN_EVENT);
gpioEV_ACKM(REF5_GPIO_DN_EVENT);
break;
default:
return PIC_ERR_SOURCE_NOT_AVAILABLE;
}
return TMLIBDEV_OK;
}
/* declaration of IR functions */
typedef struct irParam {
UInt32 irMmioTSReg;
UInt32 irCurrTS;
UInt32 irPrevTS;
UInt32 t1;
UInt32 t2;
UInt8 tStateCount;
UInt16 irCode;
UInt8 bitNum;
tsaIREvent_t event;
Bool started;
} irParam_t, *pirParam_t;
static irParam_t irRC5;
#define T_RC5 0.001778
static tmLibdevErr_t dtvRef5IRInit(pboardIRParam_t params)
{
pprocCapabilities_t procCap;
Float cpuFreq;
tmLibdevErr_t err;
/* get the clock frequency of the TriMedia CPU */
err = procGetCapabilities(&procCap);
if (err)
return err;
cpuFreq = (Float) procCap->cpuClockFrequency;
irRC5.t1 = (UInt32) (T_RC5 * 0.75 * cpuFreq);
irRC5.t2 = (UInt32) (T_RC5 * 1.25 * cpuFreq);
IR_DP(("cpuFreq is %g, t1 is %d, t2 is %d\n", cpuFreq, irRC5.t1, irRC5.t2));
irRC5.irMmioTSReg = GPIO_TS1; /* IR is using GPIO_EV1 */
irRC5.irCurrTS = 0;
irRC5.irPrevTS = 0;
irRC5.tStateCount = 0;
irRC5.irCode = 0;
irRC5.bitNum = 0;
irRC5.event = irdNone;
irRC5.started = False;
return TMLIBDEV_OK;
}
static tmLibdevErr_t dtvRef5IRTerm(void)
{
return TMLIBDEV_OK;
}
static tmLibdevErr_t dtvRef5IRStart(void)
{
return TMLIBDEV_OK;
}
static tmLibdevErr_t dtvRef5IRStop(void)
{
return TMLIBDEV_OK;
}
#define IR_HI_VAL 0x0
static void dtvRef5IRGetEvent(tsaIREvent_t *event, UInt32 *value)
{
UInt32 temp = 0;
UInt32 val = MMIO(GPIOJ_IN) & 0x00000020;
irRC5.irCurrTS = MMIO(irRC5.irMmioTSReg);
temp = (irRC5.irCurrTS - irRC5.irPrevTS);
*event = irdNone;
IR_DP(("dtvRef5IRGetEvent dT = %d, val = %#x, high value = %#x\n", temp, val, IR_HI_VAL));
if(temp < irRC5.t1)
{
irRC5.tStateCount++;
}
else if(temp < irRC5.t2)
{
irRC5.tStateCount += 2;
}
else if(val == IR_HI_VAL)
{
irRC5.tStateCount = 0; /* Start condition */
irRC5.bitNum = 0;
irRC5.irCode = 0;
irRC5.event = irdNone;
irRC5.started = True;
}
else
{
IR_DP((" invalid condition: %d \n", temp));
irRC5.event = ireError;
irRC5.started = False;
}
if (irRC5.started)
{
if((irRC5.tStateCount % 2) == 0)
{
irRC5.irCode <<=1;
if(val == IR_HI_VAL)
{
irRC5.irCode |= 1;
}
irRC5.bitNum++;
if( irRC5.bitNum > 14 )
{
irRC5.event = ireError;
irRC5.started = False;
IR_DP(("--> ireError\n"));
}
}
if(irRC5.bitNum == 14)
{
IR_DP(("IR end condition\n"));
if (irRC5.event == irdNone)
{
IR_DP(("IR event is ireReceivedRc5Code, code is %#x\n", irRC5.irCode));
*value = irRC5.irCode;
irRC5.event = ireReceivedRc5Code;
irRC5.started = False;
}
*event = irRC5.event;
irRC5.event = irdNone;
}
}
irRC5.irPrevTS = irRC5.irCurrTS;
}
/* static variables for flash functions */
volatile static UInt32 * flashBaseAddress;
static Bool flashInitialized = False;
/***********************************************************************/
static UInt32 findFlashBank(UInt32 address)
{
UInt32 i;
UInt32 b;
for (i = 0; i < 4; i ++)
{
b = i * DTV_REF5_FLASH_BANK_SIZE;
if ((b <= address) && (address < (b + DTV_REF5_FLASH_BANK_SIZE)))
return i;
}
return i;
}
/***********************************************************************/
static tmLibdevErr_t dtvRef5FlashInit(void)
{
flashBaseAddress = (UInt32 *) DTV_REF5_XIO_BASE;
flashInitialized = True;
return TMLIBDEV_OK;
}
/***********************************************************************/
static tmLibdevErr_t dtvRef5FlashReadWord(UInt32 address, UInt32 * data)
{
UInt32 d = 0;
UInt32 a = address << 2;
Int j;
tmAssert(data, FLASH_ERR_NULL_POINTER);
tmAssert(flashInitialized, FLASH_ERR_NOT_INITIALIZED);
#ifdef __BIG_ENDIAN__
for (j = 3; j >= 1; j--)
#else
for (j = 0; j < 3; j++)
#endif
{
d |= flashBaseAddress[a + j] & 0xff000000;
d >>= 8;
}
d |= flashBaseAddress[a + j] & 0xff000000;
*data = d;
return TMLIBDEV_OK;
}
/***********************************************************************/
static tmLibdevErr_t dtvRef5FlashWriteWord(UInt32 address, UInt32 data)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -