⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 w83977atf.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (c) 1999 by TriMedia Technologies. 
 *
 * +------------------------------------------------------------------+
 * | This software is furnished under a license and may only be used  |
 * | and copied in accordance with the terms and conditions of  such  |
 * | a license and with the inclusion of this copyright notice. This  |
 * | software or any other copies of this software may not be provided|
 * | or otherwise made available to any other person.  The ownership  |
 * | and title of this software is not transferred.                   |
 * |                                                                  |
 * | The information in this software is subject  to change without   |
 * | any  prior notice and should not be construed as a commitment by |
 * | TriMedia Technologies.                                           |
 * |                                                                  |
 * | this code and information is provided "as is" without any        |
 * | warranty of any kind, either expressed or implied, including but |
 * | not limited to the implied warranties of merchantability and/or  |
 * | fitness for any particular purpose.                              |
 * +------------------------------------------------------------------+
 *
 *  Module name          : w83977atf.c    1.10
 *
 *  Last update          : 18:43:52 - 00/11/09
 */

#include "w83977atf.h"
#include <tm1/tmGPIOmmio.h>
#include <tm1/tsaIR.h>
#include <tm1/tmPCI.h>
#include <tm1/tmBoardDef.h>
#include <tm1/tsaUart.h>
#include <tmlib/dprintf.h>
#include <tm1/tmAssert.h>

static w83977SioWriteFunc_t   sioWriteFunc;
static w83977SioReadFunc_t    sioReadFunc;

static UInt8 sioByteIORead(UInt32 a);
static void sioByteIOWrite(UInt32 address, UInt8 Value);

static UInt8 uartReadByte(unitSelect_t portID, UInt32 a);
static void uartWriteByte(unitSelect_t portID, UInt32 a, UInt8 Value);
static tmLibdevErr_t w83977atfUartSetInt(unitSelect_t portID, Bool enable);

static UInt8 SetArr[]={
 W83977ATF_IR_SET0, 
 W83977ATF_IR_SET1, 
 W83977ATF_IR_SET2, 
 W83977ATF_IR_SET3, 
 W83977ATF_IR_SET4, 
 W83977ATF_IR_SET5, 
 W83977ATF_IR_SET6, 
 W83977ATF_IR_SET7 
};

static Bool eventHandler(void);
static void ResetButtonInfo(void);
static void LogButtonBit(UInt8 BitVal);

static UInt32        uartPort0BaseAddress;
static UInt32        uartPort1BaseAddress;
static UInt8         uartPort0IRQ;
static UInt8         uartPort1IRQ;
static UInt8         uartIsrStore = 0;
static Int           baudTable[] = {96, 64, 48, 24, 16, 8, 4, 2, 1};
static Bool          irInitialized = False;

/************************** static functions *****************************/
static UInt8 sioByteIORead(UInt32 a)
{
    UInt32         data;
    tmLibdevErr_t err;

    err = sioReadFunc(a, &data);
    if (err)
        DP(("sioByteIORead: err %#x\n", err));

    return ((UInt8) (data & 0xFF));
}

/************************************************************************************************/
static void sioByteIOWrite(UInt32 address, UInt8 Value)
{
    tmLibdevErr_t err;

    err = sioWriteFunc(address, Value);
    if (err)
        DP(("sioByteIOWrite: err %#x\n", err));
}

/************************************************************************************************/
static void EnterExtFnMode()
{
    sioByteIOWrite(W83977ATF_PNP_ADDRESS,0x87);
    sioByteIOWrite(W83977ATF_PNP_ADDRESS,0x87);
}

/************************************************************************************************/
static void ExitExtFnMode()
{
    sioByteIOWrite(W83977ATF_PNP_ADDRESS,0xAA);
}

/************************************************************************************************/
static UInt8 ReadCR(UInt8 CRNum)
{
    sioByteIOWrite(W83977ATF_PNP_ADDRESS,CRNum);
    return sioByteIORead(W83977ATF_PNP_WRITE);
}

/************************************************************************************************/
static void WriteCR(UInt8 CRNum,UInt8 Data)
{
    sioByteIOWrite(W83977ATF_PNP_ADDRESS,CRNum);
    sioByteIOWrite(W83977ATF_PNP_WRITE,Data);
}

static UInt8 CapData;
static UInt32 RawData;
static UInt8 BitNum;
static UInt8 SkipInfo;
static UInt8 LastBit;

/************************************************************************************************/
static void RestartCapture(void)
{
    sioByteIOWrite(W83977ATF_IR_SSR, W83977ATF_IR_SET0); 
    sioByteIOWrite(W83977ATF_IR_AUDR, 0x60);
    sioByteIOWrite(W83977ATF_IR_UFR, 0x57);
}

/************************************************************************************************/
static Bool eventHandler(void)
{
UInt8 Data;

       Data = CapData;
       if((Data & 0x7f )==0x7f){        /* Data End Condition */
           if(LastBit==0x00){
               LogButtonBit(0);               /* Last Transition */
           };
           RestartCapture();
           return True;
       }
       else if((Data & 0x7f )>0x48){ /* more than 1t period handle here */
           LogButtonBit(LastBit);
           LastBit ^= 0x80;
       }
       else if((Data & 0x7f )>0x28){ /*  1t period handle here */
           if((Data & 0x80) == LastBit){
               LogButtonBit(LastBit);
           };
       };
       return False;
}

/************************************************************************************************/
static void ResetButtonInfo(void)
{
    SkipInfo = BitNum = 0;
    RawData = 0;
    LastBit = 0x80;
}

/************************************************************************************************/
static void LogButtonBit(UInt8 BitVal)
{
    UInt8 TempVal;
    TempVal = (BitVal?1:0);
    RawData = (RawData<<1) | TempVal;
    BitNum++;
}

/************************** exported functions ***************************/
extern tmLibdevErr_t w83977atfInit(pw83977atfParams_t params)
{
    sioWriteFunc   = params->sioWriteFunc;
    sioReadFunc    = params->sioReadFunc;

    EnterExtFnMode();    /* Enter extended function mode */
    WriteCR(0x02, 0x01); /* soft reset */
    WriteCR(0x02, 0x00); /* soft reset */
    ExitExtFnMode();     /* Exit extended function mode */

    /* IR initialization */
    ResetButtonInfo();
    irInitialized = False;

    /* UART initialization */
    uartPort0BaseAddress = 0x3f8;
    uartPort1BaseAddress = 0x2f8;
    uartPort0IRQ         = 0x04;
    uartPort1IRQ         = 0x03;

    if (params->sharedInterrupts)
    {
        DP(("w83977atfInit: use shared interrupts.\n"));
        EnterExtFnMode();   /* Enter extended function mode */
        WriteCR(0x28,0x10); /* Enable IRQ Sharing */
        ExitExtFnMode();    /* Exit extended function mode */
    }

    return TMLIBDEV_OK;
}

/************************************************************************************************/
extern Bool w83977atfPICSourceDetect(UInt32 * source)
{
    UInt8 TempBank;
    UInt8 reg;

    DP(("w83977atfPICSourceDetect\n"));

    if (irInitialized)
    {
        TempBank = sioByteIORead(W83977ATF_IR_SSR); /* Store Current Bank */
        sioByteIOWrite(W83977ATF_IR_SSR,0x03);      /* Change Bank to 0 */

        reg = sioByteIORead(W83977ATF_IR_ISR);
        if ((reg & 0x01))
        {
            DP(("  IR event.\n"));
            sioByteIOWrite(W83977ATF_IR_SSR, TempBank);
            *source = 5;
            return True;
        }

        sioByteIOWrite(W83977ATF_IR_SSR, TempBank);
    }

    reg = uartReadByte(unit0, W83977ATF_UART_ISR);
    if (!(reg & 0x01))
    {
        uartIsrStore = reg;
        *source  = 4;
        return True;
    }

    reg = uartReadByte(unit1, W83977ATF_UART_ISR);
    if (!(reg & 0x01))
    {
        uartIsrStore = reg;
        *source  = 3;
        return True;
    }

    return False;
}

/************************************** IR functions *****************************************/
extern void w83977atfIRGetEvent(tsaIREvent_t *event, UInt32 *value)
{
    UInt8 TempBank;
    Bool  done = False;

    TempBank = sioByteIORead(W83977ATF_IR_SSR); /* Store Current Bank */
    sioByteIOWrite(W83977ATF_IR_SSR,0x03);   /* Change Bank to 0 */
    while(sioByteIORead(W83977ATF_IR_USR) & 0x01)
    {
        CapData = sioByteIORead(W83977ATF_IR_RBR);
        if(eventHandler())
        {
            done = True;
            break;		/* Event happened break out of while */
        }
    }
    sioByteIOWrite(W83977ATF_IR_SSR, TempBank);
   
    if (SkipInfo||(BitNum < 14))
        if (done)
            *event = ireError;
        else
            *event = irdNone;
    else
        *event = ireReceivedRc5Code;

    *value = RawData;
    if (done)
        ResetButtonInfo();
}

/************************************************************************************************/
extern tmLibdevErr_t w83977atfIRInit(pw83977atfIRParams_t params)
{
/* configure IR device */

    DP(("w83977atfIRInit\n"));

    EnterExtFnMode(); /* Enter extended function mode */

    WriteCR(W83977ATF_SEL_LDEV,6); /* IR */

    WriteCR(0x60,0x04); /* UART C (IR) base IO address 0x400 */
    WriteCR(0x61,0x00);
    WriteCR(0x70,0x05); /* IRQ 5 should be used */

    WriteCR(0xf0,0x01); /* Enable IR Bank Selection */
    WriteCR(0x30,0x01); /* Activate logical device */

    ExitExtFnMode(); /* Exit extended function mode */
   
    sioByteIOWrite(W83977ATF_IR_SSR,W83977ATF_IR_SET2); 
    sioByteIOWrite(W83977ATF_IR_ADCR1, 0x00); /* Deselect advanced mode */

    sioByteIOWrite(W83977ATF_IR_SSR,W83977ATF_IR_SET0); 
    sioByteIOWrite(W83977ATF_IR_HCR, 0x08); /* Enable Global IRQ */

    sioByteIOWrite(W83977ATF_IR_SSR,W83977ATF_IR_SET2); 
    sioByteIOWrite(W83977ATF_IR_ADCR1, 0x01); /* select advanced mode */


    sioByteIOWrite(W83977ATF_IR_SSR,W83977ATF_IR_SET0); 
    sioByteIOWrite(W83977ATF_IR_UFR, 0x57); /* Enable FIFO */

    sioByteIOWrite(W83977ATF_IR_SSR,W83977ATF_IR_SET7); 
    sioByteIOWrite(W83977ATF_IR_BASE+2, 0xc0);   /* disable internal decoder */
    sioByteIOWrite(W83977ATF_IR_BASE+7, 0x20);


    sioByteIOWrite(W83977ATF_IR_SSR,W83977ATF_IR_SET5);
    sioByteIOWrite(W83977ATF_IR_BASE+4, 0x10);

    sioByteIOWrite(W83977ATF_IR_SSR,W83977ATF_IR_SET2); 
    sioByteIOWrite(W83977ATF_IR_BASE+0, 0x02); /* Baud rate devisor */
    sioByteIOWrite(W83977ATF_IR_BASE+1, 0x00); 
    sioByteIOWrite(W83977ATF_IR_ADCR1, 0x05); /* select advanced mode */
    sioByteIOWrite(W83977ATF_IR_ADCR2, 0x05); /* select advanced mode */

    sioByteIOWrite(W83977ATF_IR_SSR,W83977ATF_IR_SET0); 
    sioByteIOWrite(W83977ATF_IR_AUDR, 0x60); 
    sioByteIOWrite(W83977ATF_IR_HCR, 0xC0); /* Consumer IR mode */

    sioByteIOWrite(W83977ATF_IR_SSR,W83977ATF_IR_SET0);
    sioByteIOWrite(W83977ATF_IR_ICR,0x01); /* Enable Rx Int */

    irInitialized = True;

    return TMLIBDEV_OK;
}

/************************************ UART support ***********************************/
static UInt8 uartReadByte(unitSelect_t portID, UInt32 a)
{
    UInt32         data;
    tmLibdevErr_t  err;

    if (portID == unit0)
        a += uartPort0BaseAddress;
    else
        a += uartPort1BaseAddress;

    err = sioReadFunc(a, &data);
    if (err)
        DP(("uartReadByte: err %#x\n", err));

    return ((UInt8) (data & 0xFF));
}

/************************************************************************************************/
static void uartWriteByte(unitSelect_t portID, UInt32 a, UInt8 Value)
{
    tmLibdevErr_t err;

    if (portID == unit0)
        a += uartPort0BaseAddress;
    else
        a += uartPort1BaseAddress;

    err = sioWriteFunc(a, Value);
    if (err)
        DP(("uartWriteByte: err %#x\n", err));
}

/************************************************************************************************/
static tmLibdevErr_t w83977atfUartSetInt(unitSelect_t portID, Bool enable)
{
    UInt8 reg;

    reg = uartReadByte(portID, W83977ATF_UART_HCR);

    if (enable)
        reg |= 0x08;
    else
        reg &= 0xf7;

    uartWriteByte(portID, W83977ATF_UART_HCR, reg);

    return TMLIBDEV_OK;
}

/************************************************************************************************/
extern tmLibdevErr_t w83977atfUartInitPort(unitSelect_t portID, pboardUartParam_t params)
{
    tmLibdevErr_t err;
    UInt32        baseAddress;
    UInt8         irq;

    DP(("w83977atfUartInitPort\n"));

    EnterExtFnMode(); /* Enter extended function mode */

    if (portID == unit0)
    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -