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

📄 msapi_miu.c

📁 mstar 776 开发的车载dvd
💻 C
📖 第 1 页 / 共 3 页
字号:
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2006-2007 MStar Semiconductor, Inc.
// All rights reserved.
//
// Unless otherwise stipulated in writing, any and all information contained
// herein regardless in any format shall remain the sole proprietary of
// MStar Semiconductor Inc. and be kept in strict confidence
// (¨MStar Confidential Information〃) by the recipient.
// Any unauthorized act including without limitation unauthorized disclosure,
// copying, use, reproduction, sale, distribution, modification, disassembling,
// reverse engineering and compiling of the contents of MStar Confidential
// Information is unlawful and strictly prohibited. MStar hereby reserves the
// rights to any and all damages, losses, costs and expenses resulting therefrom.
//
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
//  [Doxygen]
/// @file msAPI_MIU.h
/// @brief API for MIU
/// @author MStar Semiconductor, Inc.
//
////////////////////////////////////////////////////////////////////////////////

#define MSAPI_MIU_C

#include <stdio.h>

#include "debug.h"
#include "datatype.h"
#include "sysinfo.h"
#include "memtype.h"
#include "drvsys.h"
#include "DrvTimer.h"
#include "drvmiu.h"
#include "drvge.h"
#include "drvflash.h"
#include "msAPI_MIU.h"
#include "msAPI_Memory.h"
#if (FLASH_WP_PIN_CONTROL == ENABLE)
#include "msGPIO.h"
#endif

#include "hwreg.h"

#define APIMIU_DBG(y) //y

#define FLASH_BUF_SIZE 1024


//#define GET_Y_BBOX_FROM_SDRAM_TO_SRAM(sdram_addr, char_index) MDrv_MIU_Copy((sdram_addr) + 2 + ((char_index) << 2), (U16)&g_SRAM_BBox.u8Y0, 2, MIU_SDRAM2SRAM)
//#define GET_Y_BBOX_FROM_SDRAM_TO_SRAM(sdram_addr, char_index) MDrv_MIU_Copy((sdram_addr) + 2 + ((char_index) << 2), (U16)&g_SRAM_BBox.u8Y0, 2, MIU_SDRAM2SDRAM)

//=================================================================================

/// SDRAM map reported by load font
#if 0
typedef struct
{
    U32     u32SdramLen;        ///< Total SDRAM length in bytes
    U32     u32StartAddr;       ///< SDRAM start address of the font

    U32     u32BBoxAddr;        ///< SDRAM address of bbox
    U32     u32CodemapAddr;     ///< SDRAM address of codemap
    U32     u32GlyphAddr;       ///< SDRAM address of glyph
} ST_LOAD_FONT_SDRAM_REPORT;
#endif

extern GLYPH_BBOX  g_SRAM_BBox;
#if ENABLE_QUICK_DATABASE
extern U8 g_u8QuickDataBase;
extern U16 g_u16QuickGenSettingIdx;
#endif

static U32 bmpaddr;
static U32 fontaddr;
#if(SWCHECKSUM_SWITCH)
static U32 CCSAddress;
static U8 CCSValue;
#endif
bool msAPI_MIU_LoadFlashFont_Decompress(U16 u16FontBinID, U32 u32DstAddr, FONT_BIN_HEADER *pFontBinHeader, ST_LOAD_FONT_SDRAM_REPORT *pFontSdramReport);

void GET_Y_BBOX_FROM_SDRAM_TO_SRAM(U32 sdram_addr, U16 char_index)
{

    MDrv_Sys_SetXdataWindow1Base( ((sdram_addr) + 2 + ((char_index) << 2)) / 4096 );

    g_SRAM_BBox.u8Y0 = XBYTE[0xf000+(((sdram_addr) + 2 + ((char_index) << 2))%4096)];
    g_SRAM_BBox.u8Height = XBYTE[0xf000+(((sdram_addr) + 2 + ((char_index) << 2))%4096)+1];
}
//MDrv_MIU_Copy((sdram_addr) + 2 + ((char_index) << 2), (U16)&g_SRAM_BBox.u8Y0, 2, MIU_SDRAM2SRAM)


/******************************************************************************/
/// API for MIU initialization::
/// Initialize bitmap, font buffer address and size.
/// Initialize flash, SRAM and SDRAM base address and length.
/******************************************************************************/
void msAPI_MIU_Init()
{
    bmpaddr = GE_ADDR_ALIGNMENT(BMP_START_ADR);
    fontaddr = GE_ADDR_ALIGNMENT(FONT_START_ADR);

    MDrv_MIU_Set_BinHeader_Addr(BIN_HEADER_ADDR + MDrv_MIU_SPI_GetOffset());

    #if(SWCHECKSUM_SWITCH)
    CCSAddress = CODE_MAP_BASE_ADR;
    CCSValue = 0;
    #endif

    APIMIU_DBG(("\r\n *** Init Bmp/Font/Flah/SDRAM Addr & Len done ***"));
}

/******************************************************************************/
/// API for MIU Load Font::
/// Decompress font table from flash to SDRAM
/// @param u16FontBinID \b IN Font ID in the packed binary
/// @param u32DstAddr \b IN Destination address on SDRAM.
/// @param pFontBinHeader \b IN Pointer to returning FONT_BIN_HEADER
/// @param pFontSdramReport \b IN Pointer to ST_LOAD_FONT_SDRAM_REPORT to keep SDRAM information
/// @return BOOLEAN:
/// - TRUE: Success
/// - FALSE: Fail
/******************************************************************************/
bool msAPI_MIU_LoadFlashFont_Decompress (
    U16 u16FontBinID,
    U32 u32DstAddr,
    FONT_BIN_HEADER *pFontBinHeader,
    ST_LOAD_FONT_SDRAM_REPORT *pFontSdramReport
    )
{
    U32 u32FlashAddr, u32BinBaseAddr;
    U16 u16;
    U16 u16LineBytes, u16CharGlyphBytes;
    int i;
    U8 offset_align;
    U8 u8shift;
    U32 size_bak;
    //U32 t0;

    //t0 = MDrv_Timer_GetTime0();

    pFontSdramReport->u32StartAddr = u32DstAddr;
    pFontSdramReport->u32SdramLen = 0;

    if ( !msAPI_Font_ReadBinHeader(u16FontBinID, pFontBinHeader, &u32BinBaseAddr) )
    {
        return FALSE;
    }

    // Load bbox info to SDRAM
    if (pFontBinHeader->u32BBoxOffset != 0)
    {
        U32 u32Len = pFontBinHeader->u32CharNum * 4;
        u32Len = ((u32Len+(MIU_ALIGN_UNIT-1))/MIU_ALIGN_UNIT)*MIU_ALIGN_UNIT;
        MDrv_MIU_XCopy(MCPY_LOADFONT, u32BinBaseAddr + pFontBinHeader->u32BBoxOffset, u32DstAddr, u32Len);
        pFontSdramReport->u32BBoxAddr = u32DstAddr;
        u32DstAddr += u32Len;
        pFontSdramReport->u32SdramLen += u32Len;
    }
    else
    {
        pFontSdramReport->u32BBoxAddr = 0;
    }

    // Load codemap to SDRAM
    if (pFontBinHeader->u32CodemapBlockNum != 0 && pFontBinHeader->u32CodemapOffset != 0)
    {
        U32 u32Len = pFontBinHeader->u32CodemapBlockNum * sizeof(CHAR_CODEMAP_BLOCK);    // each block contains 6 bytes. 2 bytes for start and 2 for end.
        u32Len = ((u32Len+(MIU_ALIGN_UNIT-1))/MIU_ALIGN_UNIT)*MIU_ALIGN_UNIT;
        MDrv_MIU_XCopy(MCPY_LOADFONT, u32BinBaseAddr + pFontBinHeader->u32CodemapOffset, u32DstAddr, u32Len);
        pFontSdramReport->u32CodemapAddr = u32DstAddr;
        u32DstAddr += u32Len;
        pFontSdramReport->u32SdramLen += u32Len;
    }
    else
    {
        pFontBinHeader->u32CodemapBlockNum = 0;
        pFontBinHeader->u32CodemapOffset = 0;

        pFontSdramReport->u32CodemapAddr = 0;
    }

    // Below load glyph data to SDRAM
    u32DstAddr = GE_ADDR_ALIGNMENT(u32DstAddr);
    pFontSdramReport->u32GlyphAddr = u32DstAddr;
    u16LineBytes = msAPI_Font_GetLineBytes(pFontBinHeader);
    u16CharGlyphBytes = msAPI_Font_GetCharGlyphBytes(pFontBinHeader);

    u32FlashAddr = u32BinBaseAddr + (U32)pFontBinHeader->u32FontGlyphOffset;

    switch (pFontBinHeader->u32Compression)
    {
        case FONT_COMPRESSION_NONE:
            MDrv_MIU_XCopy(MCPY_LOADFONT, u32FlashAddr, u32DstAddr, msAPI_Font_GetFontGlyphBytes(pFontBinHeader));
            break;

        case FONT_COMPRESSION_BOUND_RECTANGLE:
            if (pFontSdramReport->u32BBoxAddr == 0)
            {
                return FALSE;
            }

            // Clear entire buffer to 0.
            MDrv_GE_ClearFrameBuffer( u32DstAddr, msAPI_Font_GetFontGlyphBytes(pFontBinHeader), 0);

            for (u16=0; u16<pFontBinHeader->u32CharNum; u16++)
            {
                GET_Y_BBOX_FROM_SDRAM_TO_SRAM(pFontSdramReport->u32BBoxAddr, u16);

                if (g_SRAM_BBox.u8Height != 0)
                {
                    U16 offset = g_SRAM_BBox.u8Y0 * u16LineBytes;

                    U16 copysize = (g_SRAM_BBox.u8Height) * u16LineBytes;

                    size_bak =copysize;

#if 1
                    if( (u32DstAddr + offset)%MIU_ALIGN_UNIT != 0)
                    {
                         offset_align = 1;
                         u8shift = offset - (offset/MIU_ALIGN_UNIT)*MIU_ALIGN_UNIT;
                         copysize += u8shift;
                         offset = (offset/MIU_ALIGN_UNIT)*MIU_ALIGN_UNIT;
                    }
                    else {
                        u8shift = 0;
                        offset_align = 0;
                    }

#endif

                    //printf("u8Y0 = %02bx, u8Height = %02bx\n", g_SRAM_BBox.u8Y0, g_SRAM_BBox.u8Height);
                    MDrv_MIU_XCopy(MCPY_LOADFONT, u32FlashAddr-u8shift, u32DstAddr + offset, ((copysize +(MIU_ALIGN_UNIT-1))/MIU_ALIGN_UNIT)*MIU_ALIGN_UNIT   );
	             	i = ((copysize+(MIU_ALIGN_UNIT-1))/MIU_ALIGN_UNIT)*MIU_ALIGN_UNIT - copysize;
                    if( i != 0)
                    {
                        MDrv_Sys_SetXdataWindow1Base( (u32DstAddr + offset + copysize ) / (4096) );
                        while(i)
                        {
                            XBYTE[0xf000+((u32DstAddr + offset + copysize + i - 1)%4096)] = 0;
                            i--;
                        }
                    }

#if 1
                    if(offset_align)
                    {
                        MDrv_Sys_SetXdataWindow1Base( (u32DstAddr + offset) / (4096) );
                        i = 0;
                        while(u8shift)
                        {
                            XBYTE[0xf000+((u32DstAddr + offset + i )%4096)] = 0;
                            i++;
                            u8shift--;
                        }

                    }
#endif
                    copysize = size_bak;
                    u32FlashAddr += copysize;
                }
                u32DstAddr += u16CharGlyphBytes;
            }
            break;

        default:
            msWarning(ERR_FONT_WRONG_FORMAT);
            return FALSE;
    }

    // Note that u32FontGlyphBytes may indicate the size of compressed data.
    // So need to update the actual data size here.
    pFontBinHeader->u32FontGlyphBytes = msAPI_Font_GetFontGlyphBytes(pFontBinHeader);
    pFontSdramReport->u32SdramLen += pFontBinHeader->u32FontGlyphBytes;

    APIMIU_DBG(("Load font: %ld ms\n", MDrv_Timer_TimeDifferenceFromCurrent(t0)));
    return TRUE;
}

#if 0
/******************************************************************************/
/// API for MIU Reload Font::
/// Reload a font table from flash to the same SDRAM space that previously allocated.
/// @param handle \b IN Font handle
/// @param u16FontBinID \b IN Font ID in the packed binary
/******************************************************************************/
void msAPI_MIU_ReloadFlashFontToSDRAM(FONTHANDLE handle, U16 u16FontBinID)
{
    FONT_INFO finfo;
    FONT_BIN_HEADER FontBinHeader;
    ST_LOAD_FONT_SDRAM_REPORT FontSdramInfo;

    MDrv_GE_GetFontInfo(handle, &finfo);

    if (!msAPI_MIU_LoadFlashFont_Decompress(u16FontBinID, finfo.start_addr, &FontBinHeader, &FontSdramInfo))
    {
        return;
    }
}
#endif

/******************************************************************************/
/// MIU Load Font
/// Copy font table from flash to SDRAM, and config GE Font information
/// @param u16FontBinID \b IN Font ID in the packed binary
/// @return font handle
/******************************************************************************/
FONTHANDLE msAPI_MIU_LoadFlashFontToSDRAM(U16 u16FontBinID)
{
    FONTHANDLE handle = INVALID_FONTHANDLE;
    FONT_BIN_HEADER         FontBinHeader;
    ST_LOAD_FONT_SDRAM_REPORT FontSdramInfo;

    //APIMIU_DBG(printf("u16FontBinID          0x%x\n", (U16)u16FontBinID));
    if (!msAPI_MIU_LoadFlashFont_Decompress(u16FontBinID, fontaddr, &FontBinHeader, &FontSdramInfo))
    {
        return INVALID_FONTHANDLE;
    }

    //APIMIU_DBG(printf("FONT_START_ADR          0x%08lX\n", (U32)FONT_START_ADR));
    //APIMIU_DBG(printf("FONT_LEN          0x%08lX\n", (U32)FONT_LEN));

    if (fontaddr + FontSdramInfo.u32SdramLen <= FONT_START_ADR + FONT_LEN)
    {
        handle = MDrv_GE_LoadFont( FontSdramInfo.u32StartAddr,
                                   FontSdramInfo.u32GlyphAddr,
                                   FontSdramInfo.u32BBoxAddr,
                                   FontSdramInfo.u32CodemapAddr,
                                   FontBinHeader.u32CharNum,
                                   FontBinHeader.u32CodemapBlockNum,
                                   FontBinHeader.u32Width,
                                   FontBinHeader.u32Height,
                                   FontBinHeader.u32BPP,
                                   FontBinHeader.u32CharGlyphBytes,
                                   FontBinHeader.u32Pitch,
                                   MIU_SDRAM
                                   );

⌨️ 快捷键说明

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