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

📄 gammadl.c

📁 IT projecotr reference design.
💻 C
字号:
/****************************************************************************/
/*             TEXAS INSTRUMENTS PROPRIETARY INFORMATION                    */
/*                                                                          */
/*  (c) Copyright, Texas Instruments Incorporated, 2006.                    */
/*      All Rights Reserved.                                                */
/*                                                                          */
/*  Property of Texas Instruments Incorporated. Restricted Rights -         */
/*  Use, duplication, or disclosure is subject to restrictions set          */
/*  forth in TI's program license agreement and associated documentation.   */
/****************************************************************************/

/****************************************************************************/
/* gammaDL.c                                                                */
/****************************************************************************/

#include <string.h>

#include "common.h"
#include "flash_table.h"
#include "src.h"
#include "img.h"
#include "int.h"
#include "ddp2230_rtos_include.h"

#include "global.h"
#include "gammaDL.h"
#include "dbmessage.h"



#define FLASHADDRESS    0xfa000000               /* flash ROM start address */
#define SECTORSIZE      65536                              /* size of table */
#define UNKNOWN         0xffff       /* value is unknown or not initialized */


                        /****************************************************/
                        /* Gamma table entry.                               */
                        /****************************************************/

typedef uint16 TABLEID[16];
typedef uint16 GAMMATAB[512*3];

typedef struct
{
    TABLEID  tableID;            /* 16 unicode or 32 single byte characters */
    GAMMATAB gamma;                       /* Red[512] + Grn[512] + blu[512] */
} FROMGAMMAENTRY;


                        /****************************************************/
                        /* Local data.                                      */
                        /****************************************************/

static uint32  fromTable = NULL;            /* location of FROM gamma table */
static uint16 *ramTable  = NULL;            /* location of RAM gamma buffer */
static uint32  tabOffset = 0xfffffff0;                /* offset in FROM/RAM */

static uint16  device    = UNKNOWN;                    /* device identifier */


                        /****************************************************/
                        /* Flash programming functions from flash library.  */
                        /****************************************************/

int08 FL_DetermineFlashType(uint32 Address, uint16 *Dev_Id, uint16 *Man_Id);
int08 FL_FlashSectorErase(uint32 Address);
int08 FL_FlashWriteWord(uint32 Address, uint16 Data);

                        /****************************************************/
                        /* Local functions.                                 */
                        /****************************************************/

uint32 _initFromTableAddress( void );



/****************************************************************************/
/* Get identifier string for specified index.                               */
/****************************************************************************/

BOOL gdlFromID( int08 index, uint08 *pointer )
{
    fromTable = _initFromTableAddress();

                        /****************************************************/
                        /* Verify that requested index is within table.     */
                        /****************************************************/

    if( SECTORSIZE < sizeof( FROMGAMMAENTRY ) * ( index + 1 ))
        return FALSE;
    
                        /****************************************************/
                        /* Verify that requested index is programmed.       */
                        /****************************************************/

    if( UNKNOWN == ((FROMGAMMAENTRY*)fromTable)[ index ].tableID[ 0 ] )
        return FALSE;
        
                        /****************************************************/
                        /* Copy identifier.                                 */
                        /****************************************************/

    if( NULL != pointer )
        memcpy( pointer, ((FROMGAMMAENTRY*)fromTable)[ index ].tableID, sizeof( TABLEID ));
    
    return TRUE;
}



/****************************************************************************/
/* Initialize for FROM table load by erasing the sector.                    */
/****************************************************************************/

BOOL gdlFromInit( void )
{
                        /****************************************************/
                        /* - Set flash type.                                */
                        /* - Read location of sector from flash table.      */
                        /* - Erase the sector.                              */
                        /****************************************************/

    INT_DisableARMInterrupts();
    
    if( PASS == FL_DetermineFlashType( FLASHADDRESS, &device, &device ))
        if( NULL != ( fromTable = _initFromTableAddress()))
            FL_FlashSectorErase( fromTable );

    INT_EnableARMInterrupts();

    return TRUE;
}



/****************************************************************************/
/* Load table at specified index.                                           */
/****************************************************************************/

BOOL  gdlFromLoad( int08 index )
{
    if( !gdlFromID( index, NULL ))   /* if unprogrammed table at spec index */
        return FALSE;

    return PASS == IMG_GAM_LoadLutFromMem( ((FROMGAMMAENTRY*)fromTable)[index].gamma, FALSE );
}



/****************************************************************************/
/* Write 16-bit element to FROM.                                            */
/****************************************************************************/

BOOL  gdlFromWrite( uint16 element )
{
    BOOL cc = FALSE;                                     /* assumes failure */
    
                        /****************************************************/
                        /* Write, if device has been identified and offset  */
                        /* is within sector bounds.                         */
                        /****************************************************/

    if(( device != UNKNOWN ) && ( tabOffset < SECTORSIZE ))
    {
        INT_DisableARMInterrupts();
        cc = FL_FlashWriteWord( fromTable + tabOffset, element );
        INT_EnableARMInterrupts();
        
        tabOffset += 2;
    }
        
    return cc;
}



/****************************************************************************/
/* Return length of identifier string.                                      */
/****************************************************************************/

int32 gdlIDLength( void )
{
    return sizeof( TABLEID );
}



/****************************************************************************/
/* Set write offset.                                                        */
/****************************************************************************/

BOOL  gdlOffset( uint32 offset )
{
    tabOffset = offset;                                              /* set */
    
                        /****************************************************/
                        /* Ensure offset is even and within range.          */
                        /****************************************************/

    if( offset & 1 )                               
        return FALSE;
    
    return offset < SECTORSIZE;
}



/****************************************************************************/
/* Initialize for RAM buffer load                                           */
/****************************************************************************/

BOOL gdlRamInit( BOOL begin )
{
                        /****************************************************/
                        /* If begin is TRUE, this is a request to start the */
                        /* gamma load process.                              */
                        /****************************************************/

    if( begin )
    {
        tabOffset = 0;
        
        if( NULL == ramTable )   /* allocate table if not already allocated */
            return RTA_SUCCESS == RTA_MemRequest( gID_MemPool, sizeof( GAMMATAB ), (void**)&ramTable );
        
        return TRUE;
    }
        
                        /****************************************************/
                        /* If begin is FALSE, this is a request to halt the */
                        /* gamma load process due to some abnormal cause.   */
                        /****************************************************/

    else
    {
        if( NULL != ramTable )                   /* if a table is allocated */
        {
            RTA_MemRelease( ramTable );
            ramTable = NULL;
        }
    }
    
    return TRUE;
}        



/****************************************************************************/
/* Load RAM table.                                                          */
/****************************************************************************/

BOOL gdlRamLoad( void )
{
    BOOL cc = FALSE;                                     /* assumes failure */
    
    if( NULL != ramTable )                         /* if table is allocated */
    {
        cc = ( PASS == IMG_GAM_LoadLutFromMem( ramTable, FALSE ));
        RTA_MemRelease( ramTable );
        ramTable = NULL;
    }
    
    return cc;
}

    

/****************************************************************************/
/* Write 16-bit element to RAM buffer.                                      */
/****************************************************************************/

BOOL gdlRamWrite( uint16 element )
{
    BOOL cc = FALSE;                                     /* assumes failure */
    
                        /****************************************************/
                        /* Write, if device has been identified and offset  */
                        /* is within sector bounds.                         */
                        /****************************************************/

    if(( NULL != ramTable ) && ( tabOffset < sizeof( GAMMATAB )))
    {
       *(ramTable + tabOffset / 2 ) = element;
        tabOffset += 2;
        cc = TRUE;
    }
    
    return cc;
}



/****************************************************************************/
/* Set FROM table address.                                                  */
/****************************************************************************/

uint32 _initFromTableAddress( void )
{
    uint32 address;
    
                        /****************************************************/
                        /* If table address is non-NULL, return the address */
                        /****************************************************/

    if( NULL != fromTable )
        return fromTable;
        
                        /****************************************************/
                        /* Get address from flash table                     */
                        /****************************************************/

    if( PASS != FLASH_GetFlashAddr( APPL_OTHER_BINARY, 0, &address ))
        return NULL;
        
    return address;
}

⌨️ 快捷键说明

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