s3c6410_post_proc.c

来自「6410BSP3」· C语言 代码 · 共 639 行 · 第 1/2 页

C
639
字号
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//
// Copyright (c) Samsung Electronics. Co. LTD.  All rights reserved.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name:    s3c6410_post_proc.c

Abstract:       Implementation of Post Processor Control Library
                This module implements Low Level HW control 

Functions:


Notes:


--*/

#include <windows.h>
#include <bsp_cfg.h>
#include <s3c6410.h>
#include "s3c6410_post_proc.h"
#include "s3c6410_post_proc_macro.h"

#define POST_MSG(x)
#define POST_INF(x)    
#define POST_ERR(x)    RETAILMSG(TRUE, x)

#define REDUCE_VCLK_STOP_ON_LOCALPATH

static volatile S3C6410_POST_REG *g_pPostReg = NULL;
static tPostConfig g_PostConfig;

POST_ERROR Post_initialize_register_address(void *pPostReg)
{
    POST_ERROR error = POST_SUCCESS;

    POST_MSG((_T("[POST]++Post_initialize_register_address(0x%08x)\n\r"), pPostReg));

    if (pPostReg == NULL)
    {
        POST_ERR((_T("[POST:ERR] Post_initialize_register_address() : NULL pointer parameter\n\r")));
        error = POST_ERROR_NULL_PARAMETER;
    }
    else
    {
        g_pPostReg = (S3C6410_POST_REG *)pPostReg;
        POST_INF((_T("[POST:INF] g_pPostReg = 0x%08x\n\r"), g_pPostReg));
    }

    memset((void *)(&g_PostConfig), 0x0, sizeof(tPostConfig));

    POST_MSG((_T("[POST]--Post_initialize_register_address() : %d\n\r"), error));

    return error;
}

POST_ERROR Post_initialize(POST_OP_MODE Mode, POST_SCAN_MODE Scan,
                    POST_SRC_TYPE SrcType, unsigned int SrcBaseWidth, unsigned int SrcBaseHeight,
                    unsigned int SrcWidth, unsigned int SrcHeight, unsigned int SrcOffsetX, unsigned int SrcOffsetY,
                    POST_DST_TYPE DstType, unsigned int DstBaseWidth, unsigned int DstBaseHeight,
                    unsigned int DstWidth, unsigned int DstHeight, unsigned int DstOffsetX, unsigned int DstOffsetY)
{
    POST_ERROR error = POST_SUCCESS;

    POST_MSG((_T("[POST]++Post_initialize(%d, %d, %d, [%d, %d, %d, %d, %d, %d], %d, [%d, %d, %d, %d, %d, %d])\n\r"),
                Mode, Scan, SrcType, SrcBaseWidth, SrcBaseHeight, SrcWidth, SrcHeight, SrcOffsetX, SrcOffsetY,
                DstType, DstBaseWidth, DstBaseHeight, DstWidth, DstHeight, DstOffsetX, DstOffsetY));

    error = Post_set_mode(Mode, Scan, SrcType, DstType);
    if (error == POST_SUCCESS)
    {
#ifdef REDUCE_VCLK_STOP_ON_LOCALPATH
        // work-around for VCLK STOP when scaling down on Local Path State
        /*====================================================================*/
        if(Mode == POST_FREE_RUN_MODE)
        {
            if(SrcHeight >= 2*DstHeight)
            {
                int i=2;
                for(i=2;(SrcHeight >= i*DstHeight) && (i<8);i++);
                SrcBaseWidth *= i;
                SrcBaseHeight /= i;
                SrcHeight /= i;
                SrcOffsetY /= i;
            }
        }
        /*====================================================================*/
#endif
        Post_set_source_size(SrcBaseWidth, SrcBaseHeight, SrcWidth, SrcHeight, SrcOffsetX, SrcOffsetY);
        Post_set_destination_size(DstBaseWidth, DstBaseHeight, DstWidth, DstHeight, DstOffsetX, DstOffsetY);
        
        error = Post_update_condition();
    }

    POST_MSG((_T("[POST]--Post_initialize() : %d\n\r"), error));

    return error;
}

POST_ERROR Post_set_source_buffer(unsigned int AddrY, unsigned int AddrCb, unsigned int AddrCr)
{
    POST_ERROR error = POST_SUCCESS;

    POST_MSG((_T("[POST]++Post_set_source_buffer(0x%08x, 0x%08x, 0x%08x)\n\r"), AddrY, AddrCb, AddrCr));

    error = Post_set_dma_address(POST_SRC_ADDRESS, AddrY, AddrCb, AddrCr);

    POST_MSG((_T("[POST]--Post_set_source_buffer() : %d\n\r"), error));

    return error;
}

POST_ERROR Post_set_next_source_buffer(unsigned int AddrY, unsigned int AddrCb, unsigned int AddrCr)
{
    POST_ERROR error = POST_SUCCESS;

    POST_MSG((_T("[POST]++Post_set_next_source_buffer(0x%08x, 0x%08x, 0x%08x)\n\r"), AddrY, AddrCb, AddrCr));

    error = Post_set_dma_address(POST_NEXT_SRC_ADDRESS, AddrY, AddrCb, AddrCr);

    POST_MSG((_T("[POST]--Post_set_next_source_buffer() : %d\n\r"), error));

    return error;
}

POST_ERROR Post_set_destination_buffer(unsigned int AddrY, unsigned int AddrCb, unsigned int AddrCr)
{
    POST_ERROR error = POST_SUCCESS;

    POST_MSG((_T("[POST]++Post_set_destination_buffer(0x%08x, 0x%08x, 0x%08x)\n\r"), AddrY, AddrCb, AddrCr));

    if (g_PostConfig.DstType == POST_DST_FIFO_RGB888 || g_PostConfig.DstType == POST_DST_FIFO_YUV444)
    {
        POST_ERR((_T("[POST:ERR] Post_set_destination_buffer() : FIFO Mode does Not use DMA\n\r")));
        error = POST_ERROR_ILLEGAL_PARAMETER;
    }
    else
    {
        error = Post_set_dma_address(POST_DST_ADDRESS, AddrY, AddrCb, AddrCr);
    }

    POST_MSG((_T("[POST]--Post_set_destination_buffer() : %d\n\r"), error));

    return error;
}

POST_ERROR Post_set_next_destination_buffer(unsigned int AddrY, unsigned int AddrCb, unsigned int AddrCr)
{
    POST_ERROR error = POST_SUCCESS;

    POST_MSG((_T("[POST]++Post_set_next_destination_buffer(0x%08x, 0x%08x, 0x%08x)\n\r"), AddrY, AddrCb, AddrCr));

    if (g_PostConfig.DstType == POST_DST_FIFO_RGB888 || g_PostConfig.DstType == POST_DST_FIFO_YUV444)
    {
        POST_ERR((_T("[POST:ERR] Post_set_next_destination_buffer() : FIFO Mode does Not use DMA\n\r")));
        error = POST_ERROR_ILLEGAL_PARAMETER;
    }
    else
    {
        error = Post_set_dma_address(POST_NEXT_DST_ADDRESS, AddrY, AddrCb, AddrCr);
    }

    POST_MSG((_T("[POST]--Post_set_next_destination_buffer() : %d\n\r"), error));

    return error;
}

void Post_processing_start(void)
{
    POST_MSG((_T("[POST]++Post_processing_start()\n\r")));

    if (g_PostConfig.Mode == POST_FREE_RUN_MODE)    // for FIFO output mode
    {
        g_pPostReg->MODE |= AUTOLOAD_ENABLE;
    }

    g_pPostReg->POSTENVID |= POST_ENVID;

    POST_MSG((_T("[POST]--Post_processing_start()\n\r")));
}

void Post_processing_stop(void)
{
    POST_MSG((_T("[POST]++Post_processing_stop()\n\r")));

    if (g_pPostReg->MODE & AUTOLOAD_ENABLE)    // for FIFO output mode
    {
        // FIFO mode should be stopped by autoload disable
        g_pPostReg->MODE &= ~AUTOLOAD_ENABLE;
    }

    g_pPostReg->POSTENVID &= ~POST_ENVID;

    POST_MSG((_T("[POST]--Post_processing_stop() : %d\n\r"), error));
}

void Post_autoload_disable(void)
{
    POST_MSG((_T("[POST]++Post_autoload_disable()\n\r")));

    g_pPostReg->MODE &= ~AUTOLOAD_ENABLE;

    POST_MSG((_T("[POST]--Post_autoload_disable()\n\r")));
}

POST_STATE Post_get_processing_state(void)
{
    POST_STATE state;

    POST_MSG((_T("[POST]++Post_get_processing_state()\n\r")));

    if (g_pPostReg->POSTENVID & POST_ENVID)
    {
        state = POST_BUSY;
    }
    else
    {
        state = POST_IDLE;
    }

    POST_MSG((_T("[POST]--Post_get_processing_state() = %d\n\r"), state));

    return state;
}

void Post_enable_interrupt(void)
{
    POST_MSG((_T("[POST]++Post_enable_interrupt()\n\r")));

    g_PostConfig.bIntEnable = TRUE;

    g_pPostReg->MODE &= ~POSTINT_PEND;    // Pending Clear
    g_pPostReg->MODE |= POSTINT_ENABLE;    // Interrupt Enable

    POST_MSG((_T("[POST]--Post_enable_interrupt()\n\r")));
}

void Post_disable_interrupt(void)
{
    POST_MSG((_T("[POST]++Post_disable_interrupt()\n\r")));

    g_PostConfig.bIntEnable = FALSE;

    g_pPostReg->MODE &= ~POSTINT_ENABLE;    // Interrupt Disable
    g_pPostReg->MODE &= ~POSTINT_PEND;    // Pending Clear

    POST_MSG((_T("[POST]--Post_disable_interrupt()\n\r")));
}

BOOL Post_clear_interrupt_pending(void)
{
    BOOL IntPend = FALSE;

    POST_MSG((_T("[POST]++Post_clear_interrupt_pending()\n\r")));

    if (g_pPostReg->MODE & POSTINT_PEND)
    {
        g_pPostReg->MODE &= ~POSTINT_PEND;    // Pending Clear
        IntPend = TRUE;
    }

    POST_MSG((_T("[POST]--Post_clear_interrupt_pending()\n\r")));

    return IntPend;
}

static POST_ERROR Post_set_mode(POST_OP_MODE Mode, POST_SCAN_MODE Scan, POST_SRC_TYPE SrcType, POST_DST_TYPE DstType)
{
    POST_ERROR error = POST_SUCCESS;

    POST_MSG((_T("[POST]++Post_set_mode(%d, %d, %d, %d)\n\r"), Mode, Scan, SrcType, DstType));

    g_PostConfig.Mode = Mode;
    g_PostConfig.Scan = Scan;
    g_PostConfig.SrcType = SrcType;
    g_PostConfig.DstType = DstType;

    // For some application PostProcessor May be need to faster CLK
    // setting for faster CLK : CLKVALUP_ALWAYS | CLKVAL_F(0) | CLKDIR_DIRECT | CLKSEL_F_HCLK | CSC_R2Y_WIDE | CSC_Y2R_WIDE | IRQ_LEVEL
    g_pPostReg->MODE = CLKVALUP_ALWAYS | CLKVAL_F(2) | CLKDIR_DIVIDED | CLKSEL_F_HCLK | CSC_R2Y_NARROW | CSC_Y2R_NARROW | IRQ_LEVEL;    // Clock = HCLK/2

    if (g_PostConfig.bIntEnable)
    {
        g_pPostReg->MODE |= POSTINT_ENABLE;
    }

    if (Mode == POST_PER_FRAME_MODE)
    {
        g_pPostReg->MODE |= AUTOLOAD_DISABLE;
    }
    else if (Mode == POST_FREE_RUN_MODE)
    {
        g_pPostReg->MODE |= AUTOLOAD_ENABLE;
    }
    else
    {
        POST_ERR((_T("[POST:ERR] Post_set_mode() : Unknown Operation Mode %d)\n\r"), Mode));
        return POST_ERROR_ILLEGAL_PARAMETER;
    }

    if (Scan == POST_PROGRESSIVE)
    {
        g_pPostReg->MODE |= PROGRESSIVE;

⌨️ 快捷键说明

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