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

📄 hw_a2a.c

📁 瑞星微公司RK27XX系列芯片的SDK开发包
💻 C
字号:
/*********************************************************************************
*     Copyright (C),2004-2005,  Fuzhou Rockchip Co.,Ltd.
*         All Rights Reserved
*          V1.00
* FileName :  hw_a2a.c
* Author :  lzy
* Description:   a2a dma controller
* History  :
*   <author>  <time>    <version>    <desc>
*    lzy        07/8/18        1.0     ORG
                      lzy               07/10/7         1.1
$Log: Hw_a2a.c,v $
Revision 1.2  2008/06/19 04:43:29  Administrator
代码整理!

Revision 1.1.1.1  2008/05/07 04:15:08  Administrator
no message

Revision 1.1.1.1  2008/03/06 13:29:04  Lingzhaojun
no message

Revision 1.4  2007/10/15 09:00:11  Huangxinyu
根据RK27提交修改driver

Revision 1.3  2007/10/08 02:38:37  Lingzhaojun
添加版本自动注释脚本


*********************************************************************************/
#include "Hw_include.h"
#include "HW_a2a.h"

#define RegA2ABase  AHB0_A2A_DMA_BASE
static A2ACallBack A2A_irq[2] = {NULL, NULL};

/**************************************************************************
* 函数描述:  A2A_isr 中断服务程序入口
* 入口参数:  无
* 出口参数:  无
* 返回值:        无
* 注释:
***************************************************************************/
static void A2A_isr(void)
{
    int irqstatic, channel = 1;

    A2ACallBack callback;

    irqstatic = ReadReg32(RegA2A_INT_STS);

    WriteReg32(RegA2A_INT_STS, irqstatic);

    for (channel = 0; channel < 2; channel++)
    {
        if (irqstatic & (0x01 << channel))
        {
            if (A2A_irq[channel])
            {
                callback = A2A_irq[channel];

                A2A_irq[channel] = NULL;

                callback();
            }
        }
    }
}

/**************************************************************************
* 函数描述:  A2A DMA setup
* 入口参数:  SrcAddr:   source address
                            DestinAddr:  destination address
                            Count:         length of transmit
                            Mode:         transmit mode, please see A2A api define
                            CallBack:    call back function
* 出口参数:  通道号,busy , error
* 返回值:
* 注释:             A2A can no transmit byte data when fixed address
                            and source and destination data must be same data width
                            the max transmit size is 64Kbyte-1
***************************************************************************/
int A2A_Transmit(UINT32 SrcAddr, UINT32 DestinAddr, UINT32 Count, UINT32 Mode, A2ACallBack CallBack)
{
    unsigned int config, aamode, channel = 0;

    config = ReadReg32(RegA2A_DMA_STS);

    if (config == 0x03)
        return A2ABusy;

    if (config&0x01)
        channel = 1;

//
// for A2A DMA controller, count is for byte , so we get the byte count here
//
    aamode = (Mode & A2AMode_widthMask) >> 1;
    Count = (Count << aamode);

    WriteReg32(RegA2A_ISRC(channel), TransVAtoPA(SrcAddr));
    WriteReg32(RegA2A_IDST(channel), TransVAtoPA(DestinAddr));
    WriteReg32(RegA2A_ICNT(channel), Count);

    config = Mode & (A2AMode_HwMask
                     | A2AMode_widthMask
                     | A2AMode_DrmodeMask
                     | A2AMode_SrmodeMask
                     | A2AMode_ReqMask
                     | A2AMode_BurstMask);

    if (Mode&A2AMode_OTFMask)
    {
        config |= A2AMode_A1toA2;
        aamode = 0x01 << (channel * 2);
        WriteReg32(RegA2A_DOMAIN, aamode);      // setup domain address
    }

    if (CallBack)
    {
        config |= A2AMode_IntEn;
        A2A_irq[channel] = CallBack;
        Intr_Enable(INTC_A2A_DMA);
    }

    WriteReg32(RegA2A_CON(channel), config);


    if (Mode&A2AMode_HwMask)
//  Enable A2A software mode DMA
        WriteReg32(RegA2A_CON(channel), ReadReg32(RegA2A_CON(channel)) | A2AMode_SoftStart);
    else
//   Enable A2A Hardware mode DMA
        WriteReg32(RegA2A_CON(channel), ReadReg32(RegA2A_CON(channel)) | A2AMode_HwEn);

    return channel;

}

/**************************************************************************
* 函数描述:  A2A 读通道状态
* 入口参数:  无
* 出口参数:  无
* 返回值:        无
* 注释:             采用查询方式使用DMA  时通过此接口判断传输状态
***************************************************************************/
int A2A_GetStatus(A2A_Channel_t channel)
{
    if (ReadReg32(RegA2A_DMA_STS)&(0x01 << channel))
        return A2ABusy;
    else
        return A2ASuccess;
}


/**************************************************************************
* 函数描述:  A2A 开机初始化程序
* 入口参数:  无
* 出口参数:  无
* 返回值:        无
* 注释:             启用A2A DMA 时调用,如arm 或dsp有访问ahb1, A2A必须开启
***************************************************************************/
void A2A_PowerOnInit(void)
{
    int temp, channel;

    Scu_ClockEnable(A2A_HCLOCK);

    for (channel = 0; channel < A2A_chnmax;  channel++)
    {
        temp = ReadReg32(RegA2A_CON(channel));
        temp = (temp & ~A2AMode_SwcMask) | A2AMode_SoftStop;
        WriteReg32(RegA2A_CON(channel), temp);

        WriteReg32(RegA2A_LCNT(channel), 0x01);

        WriteReg32(RegA2A_CON(channel), 0x00);  //ReadReg32(RegA2A_CON(0))|A2AMode_SoftStop);

    }

    WriteReg32(RegA2A_INT_STS, 0x0f);

    Intr_RegISR(INTC_A2A_DMA, A2A_isr);

}

/**************************************************************************
* 函数描述:  A2A 反初始化函数
* 入口参数:  无
* 出口参数:  无
* 返回值:        无
* 注释:             关闭A2A DMA时调用
***************************************************************************/
void A2A_DeInit(void)
{
    WriteReg32(RegA2A_INT_STS, 0x00);

    Intr_RegISR(INTC_A2A_DMA, NULL);
    Intr_Disable(INTC_A2A_DMA);
    Scu_ClockDisable(A2A_HCLOCK);
}



⌨️ 快捷键说明

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