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

📄 cache_example.c

📁 Dm6455 driver,magbe useful to you!
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  ============================================================================
 *   Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005
 *
 *   Use of this software is controlled by the terms and conditions found in 
 *   the license agreement under which this software has been supplied.
 *  ============================================================================
 */

/** ===========================================================================
 *
 *   @file  Cache_example.c
 *
 *   @path  $(CSLPATH)\example\cache\src
 *
 *   @desc  Example of CACHE
 *
 *  ============================================================================
 *   @n Target Platform: EVM
 *  ============================================================================
 *   @n <b> Example Description </b>
 *   @n Usage of cache CSL API for the following operations
 *       - Invalidate all L2 and L1D cache
 *       - Write back invalidate all L2 and L1D cache
 *       - Write back all L2 and L1D cache 
 *       - Invalidate the L2 and L1D cache
 *       - Write back invalidate L2 and L1D cache
 *       - Write back L2 and L1D cache
 *       - L2 normal mode
 *       - Freeze operation on L2 cache
 * 
 * =============================================================================
 *      
 *   <b> Procedure to run the example </b>
 *   @verbatim
 *      1. Configure the CCS setup to work with the emulator being used
 *      2. Please refer CCS manual for setup configuration and loading 
 *         proper GEL file
 *      3. Launch CCS window
 *      4. Open project Cache_example.pjt
 *      5. Build the project and load the .out file of the project.
 *          
 *   @endverbatim
 *
 */
 
/* ============================================================================
 *  Revision History
 *  ===============
 *  26-Jul-2005 ds     File Created.
 *  08-Feb-2006 ds     Changed during testing on EVM. Added EMIFB CE0 as a  
 *                     device memory and supported DDR2 CSL to initialize and   
 *                     setup EMIFB(DDR2) location.
 *                     
 * ============================================================================
 */
#include <stdio.h>
#include <csl_cache.h>
#include <_csl_cache.h>
#include <csl_ddr2.h>
#include <cslr_dev.h>

/* L1 and L2 Caching Memory area */
#define CACHE_MEM    (0xE0000000)

/* Globals variables used for storing the cache data */
Uint32      temp;
Uint32      Data_1;
Uint32      Data_2;
Uint32      Data_3;
Uint32      Data_4;

/* Foraward declarations */
void subExampleEndPrint(void);
void exampleEndPrint (void);
void init_ddr2 (void);
void enableDdr2 (void);

/*
 * =============================================================================
 *   @func   main
 *
 *   @desc
 *     This is the main routine for the file.
 *
 * =============================================================================
 */

void main(void) 
{
    Uint32          cacheExampleFail = 0;
    Uint16          loopCount;
    Uint16          count;
    CACHE_L2Size    localSize[4];
    
    /* Initialize the DDR2 module */
    init_ddr2 ();
    
    /* make sure L1P is turned off */
    CACHE_setL1pSize(CACHE_L1_0KCACHE);
    
    /* make sure that L1D is turned off */
    CACHE_setL1dSize(CACHE_L1_0KCACHE);
    
    /* make sure that L2 is turned off */
    CACHE_setL2Size(CACHE_0KCACHE);
    
    /* Array used for setting L2 cache size */
    localSize[0] = CACHE_32KCACHE;
    localSize[1] = CACHE_64KCACHE;
    localSize[2] = CACHE_128KCACHE;
    localSize[3] = CACHE_256KCACHE;
    
    /* This loop is used to display the L2 cache size while performing different
     * operations on different L2 cache sizes 
     */
    for(loopCount = 0; loopCount <4; loopCount++) {
        switch(loopCount) {
            case 0:
                printf("\n");
                subExampleEndPrint();
                printf("CACHE: Performing operations on 32K L2 cache.\n");
                subExampleEndPrint();
                break;

            case 1:
                printf("\n");
                subExampleEndPrint();
                printf("CACHE: Performing operations on 64K L2 cache.\n");
                subExampleEndPrint();
                break;
            case 2:
                printf("\n");
                subExampleEndPrint();
                printf("CACHE: Performing operations on 128K L2 cache.\n");
                subExampleEndPrint();
                break;

            case 3:
                printf("\n");
                subExampleEndPrint();
                printf("CACHE: Performing operations on 256K L2 cache.\n");
                subExampleEndPrint();
                break;

            default:
                break;
        }
        
        for(count = 1; count <= 8; count++) {
            /* set a memory location */
            *(Uint32*)CACHE_MEM = 0xABCDABCD;
            
            Data_2 = 0xa5a5a5a5;
            
            /* set Mar bit for CACHE_MEM */
            CACHE_enableCaching(CACHE_EMIFB_CE00);
            
            /* turn on the L2 cache. */
            CACHE_setL2Size( localSize[loopCount]);
            
            /* read (allocate into cache) */
            Data_1 = *(Uint32*)CACHE_MEM;
            
            /* write (dirty the cache line) */
            *(Uint32*)CACHE_MEM = Data_2;
            
            /* Read the data back (make sure it matches Data_2 */
            Data_3 = *(Uint32*)CACHE_MEM;
            
            if(Data_2 != Data_3)
                printf("CACHE: Data read from cache is not same as \
                        data written.\n");
            
            switch(count) {
                /* Case #1 - invAllL2 */
                case 1:
                    /* Invalidate all the L2 cache */
                    CACHE_invAllL2(CACHE_WAIT);
                    
                    for( temp =0 ; temp < 1000; temp++)
                    {}
                    
                    /* read, this data should match data_1 */
                    Data_4 = *(Uint32*)CACHE_MEM;
                    if(Data_1 != Data_4) {
                        printf("CACHE: Invalidate the All L2 cache Failed.\n");
                        cacheExampleFail++;
                    }
                    else {
                        printf("CACHE: Invalidate the All L2 cache Passed.\n");
                    }
                    
                    break;
                    
                /* Case #2 - wbInvAllL2 */
                case 2:
                    /* Writeback invalidate all the L2 cache */
                    CACHE_wbInvAllL2(CACHE_WAIT);
                    
                    for( temp =0 ; temp < 1000; temp++)
                    {}
                    
                    /* read, this data should match data_2 */
                    Data_4 = *(Uint32*)CACHE_MEM;
                    if(Data_2 != Data_4) {
                        printf("CACHE: Write back invalidate All");
                        printf("L2 cache Failed.\n");
                        cacheExampleFail++;
                    }
                    else {
                        printf("CACHE: Write back invalidate All");
                        printf("L2 cache Passed.\n");
                    }
                    break;
                    
                /* Case #3 wbAll */
                case 3:
                    /* Writeback all the L2 cache */
                    CACHE_wbAllL2(CACHE_WAIT);
                    
                    for( temp =0 ; temp < 1000; temp++)
                    {}
                    
                    /* read, this data should match data_2 */
                    Data_4 = *(Uint32*)CACHE_MEM;
                    if(Data_2 != Data_4){
                        printf("CACHE: Write back All L2 cache Failed.\n");
                        cacheExampleFail++;
                    }
                    else {
                        printf("CACHE: Write back All L2 cache Passed.\n");
                    }
                    break;
                    
                /* Case #4 - invL2 */
                case 4:
                    /* Invalidate the L2 cache */
                    CACHE_invL2((Uint32*)CACHE_MEM, 4, CACHE_WAIT);
                                        
                    /* read, this data should match data_1 */
                    Data_4 = *(Uint32*)CACHE_MEM;
                    if(Data_1 != Data_4) {
                        printf("CACHE: Invalidate the L2 cache Failed.\n");
                        cacheExampleFail++;
                    }
                    else {
                        printf("CACHE: Invalidate the L2 cache Passed.\n");
                    }
                    break;
                    
                /* Case #5 - wbInv */
                case 5:
                    /* Writeback invalidate the L2 cache */
                    CACHE_wbInvL2((Uint32*)CACHE_MEM,1000, CACHE_WAIT);
                    
                    /* read, this data should match data_2 */
                    Data_4 = *(Uint32*)CACHE_MEM;
                    if(Data_2 != Data_4) {
                        printf("CACHE: Write back invalidate");
                        printf(" L2 cache Failed.\n");
                        cacheExampleFail++;
                    }
                    else {
                        printf("CACHE: Write back invalidate");
                        printf("L2 cache Passed.\n");
                    }
                    break;
                    
                /* Case #6 wb */
                case 6:
                    /* Writeback L2 cache */
                    CACHE_wbL2((Uint32*)CACHE_MEM, 4, CACHE_WAIT);
                    
                    /* read, this data should match data_2 */
                    Data_4 = *(Uint32*)CACHE_MEM;
                    if(Data_2 != Data_4) {
                        printf("CACHE: Write back L2 cache Failed.\n");
                        cacheExampleFail++;
                    }
                    else {
                        printf("CACHE: Write back L2 cache Passed.\n");
                    }
                    break;
                    
                /* Case #6 wb */
                case 7:
                    /* Set L2 cache in normal mode */
                    CACHE_setL2Mode(CACHE_L2_NORMAL);
                    
                    /* read, this data should match data_3 */
                    Data_4 = *(Uint32*)CACHE_MEM;
                    if(Data_3 != Data_4) {
                        printf("CACHE: L2 Normal Mode Failed.\n");
                        cacheExampleFail++;
                    }
                    else {
                        printf("CACHE: L2 Normal Mode Passed.\n");
                    }
                    break;
                    
                case 8:
                    /* Writeback invalidate the cache */
                    CACHE_wbInvAllL2(CACHE_WAIT);
                    
                    /* freeze the cache */
                    if(CACHE_setL2Mode(CACHE_L2_FREEZE) != CACHE_L2_NORMAL)
                    {}
                    
                    /* read, this would normally allocate space in the cache */
                    temp = *(Uint32*)CACHE_MEM;
                    *(Uint32*)CACHE_MEM = 0xABCDABCD;
                    
                    /* write to external memory */
                    *(Uint32*)CACHE_MEM =0xA5A5A5A5;
                    if(CACHE_setL2Mode(CACHE_L2_NORMAL) != CACHE_L2_FREEZE)
                    {}
                    Data_4 = *(Uint32*)CACHE_MEM;
                    
                    /* if the cache was frozen then the Data_4 should equal */
                    if(Data_4 != 0xA5A5A5A5) {
                        printf("CACHE: Freeze operation on Cache Failed.\n");
                        cacheExampleFail++;
                    }
                    else {
                        printf("CACHE: Freeze operation on Cache Passed.\n");
                    }

⌨️ 快捷键说明

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