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

📄 ex_mem01_sample.c

📁 oki67500系列arm工程例程源代码
💻 C
字号:
/**********************************************************************************/
/*                                                                                */
/*    Copyright (C) 2003 Oki Electric Industry Co., LTD.                          */
/*                                                                                */
/*    System Name    :  ML675001 series                                           */
/*    Module Name    :  Connection with external SRAM/ROM                         */
/*    File   Name    :  ext_mem1_sample.c                                         */
/*    Revision       :  01.00                                                     */
/*    Date           :  2003/08/18                                                */
/*                                                                                */
/**********************************************************************************/
#include "ML675001.h"
#include "common.h"
#include "cache.h"

/* definition of constants */
#define SRAM_BASE   (0xD0000000)    /* base address of external SRAM */
#define SRAM_SIZE   (0x80000)  /* size of external SRAM : 512kbyte */
#define SRAM_TOP    ((void*)(SRAM_BASE+SRAM_SIZE))  /* top address of
                                                       external SRAM */

/* functions */
void setup_ext_sram_rom(void);
UHWORD read_write_check(void);
UHWORD read_write_check_byte(void);
UHWORD read_write_check_hword(void);
UHWORD read_write_check_word(void);
void IRQ_Handler(void){}    /* this handler isn't used in this sample. */

const UHWORD LED_PATTERN[16] = {0x003F, 0x0006, 0x005B, 0x004F, /* 0, 1, 2, 3, */
                                0x0066, 0x006D, 0x007D, 0x0027, /* 4, 5, 6, 7, */
                                0x007F, 0x006F, 0x0077, 0x007C, /* 8, 9, A, b, */
                                0x0039, 0x005E, 0x0079, 0x0071};/* C, d, E, F  */

/****************************************************************************/
/*  Entry point                                                             */
/*  Function : main                                                         */
/*      Parameters                                                          */
/*          Input   :   Nothing                                             */
/*          Output  :   0                                                   */
/****************************************************************************/
int main(void)
{
    UHWORD led_pattern;

    init_cache();  /* Initialize CACHE memory */
    cache_on(CACHE_BANK0);  /* Bank0 : Cache enable */

    /* LED on */
    init_led();    /* output mode */
    led_on(LED_START_PATTERN);

    setup_ext_sram_rom();   /* setup external SRAM/ROM */

    led_pattern = read_write_check();   /* read/write check */

    led_on(led_pattern);
     
    return 0;
}

/****************************************************************************/
/*  Setup of external SRAM/ROM                                              */
/*  Function : setup_ext_sram_rom                                           */
/*      Parameters                                                          */
/*          Input   :   Nothing                                             */
/*          Output  :   Nothing                                             */
/****************************************************************************/
void setup_ext_sram_rom(void)
{
    /* setup of bus width control register (BWC@0x7810_0000) */
    put_wvalue(BWC, 0x28);  /* setup of bus width
                               ROM/SRAM : 16bits.
                               IO0/IO1  : nothing */

    /* setup of ROM access control register (ROMAC@0x7810_0004) */
    put_wvalue(ROMAC, 0x7); /* OE/WE pulse width:8, read off time:4 (slowest) */

    /* setup of SRAM access control register (RAMAC@0x7810_0008) */
    put_wvalue(RAMAC, 0x7); /* OE/WE pulse width:8, read off time:4 (slowest) */

    return;
}

/****************************************************************************/
/*  Write data to all the ranges of external SRAM and                       */
/*  values of all the ranges of external SRAM is read and compared.         */
/*  Write patterns are '00', '55', 'AA' and 'FF'.                           */
/*  Read/Write sizes are 8bits, 16bits and 32bits.                          */
/*  Function : read_write_check                                             */
/*      Parameters                                                          */
/*          Input   :   Nothing                                             */
/*          Output  :   LED pattern                                         */
/*                         LED_NORMAL_END_PATTERN -> Narmal end.            */
/*                                         others -> Error occurred         */
/****************************************************************************/
UHWORD read_write_check(void)
{
    UHWORD led_pattern;
    
    /* BYTE access check */
    if((led_pattern = read_write_check_byte()) != LED_NORMAL_END_PATTERN){
        return led_pattern;
    }
    /* HWORD access check */
    else if((led_pattern = read_write_check_hword()) != LED_NORMAL_END_PATTERN){
        return led_pattern;
    }
    /* WORD access check */
    else if((led_pattern = read_write_check_word()) != LED_NORMAL_END_PATTERN){
        return led_pattern;
    }

    return led_pattern; /* led_pattern == LED_NORMAL_END_PATTERN */
}

/****************************************************************************/
/*  Write data to all the ranges of external SRAM and                       */
/*  values of all the ranges of external SRAM is read and compared.         */
/*  Write patterns are '00', '55', 'AA' and 'FF'.                           */
/*  Read/Write size is 8bits.                                               */
/*  Function : read_write_check_byte                                        */
/*      Parameters                                                          */
/*          Input   :   Nothing                                             */
/*          Output  :   LED pattern                                         */
/*                         LED_NORMAL_END_PATTERN -> Narmal end.            */
/*                                         others -> Error occurred         */
/****************************************************************************/
UHWORD read_write_check_byte(void)
{
    int i;
    UBYTE write_pattern[] = {0x00, 0x55, 0xAA, 0xFF};   /* writing patterns */
    UBYTE *address; /* address of read/write area */

    for(i=0; i<4; i++){
        /* write data to all region of external SRAM */
        for(address=(UBYTE*)SRAM_BASE; address<(UBYTE*)SRAM_TOP; address++){
            put_value(address, write_pattern[i]);
        }
        /* check data of all region of external SRAM */
        for(address=(UBYTE*)SRAM_BASE; address<(UBYTE*)SRAM_TOP; address++){
            if(get_value(address) != write_pattern[i]){ /* check data */
                /* error occurred */
                return LED_PATTERN[i];   /* return LED pattern */
            }
        }
    }

    return LED_NORMAL_END_PATTERN;
}

/****************************************************************************/
/*  Write data to all the ranges of external SRAM and                       */
/*  values of all the ranges of external SRAM is read and compared.         */
/*  Write patterns are '0000', '5555', 'AAAA' and 'FFFF'.                   */
/*  Read/Write size is 16bits.                                              */
/*  Function : read_write_check_hword                                       */
/*      Parameters                                                          */
/*          Input   :   Nothing                                             */
/*          Output  :   LED pattern                                         */
/*                         LED_NORMAL_END_PATTERN -> Narmal end.            */
/*                                         others -> Error occurred         */
/****************************************************************************/
UHWORD read_write_check_hword(void)
{
    int i;
    UHWORD write_pattern[] = {0x0000, 0x5555, 0xAAAA, 0xFFFF};  /* writing patterns */
    UHWORD *address;    /* address of read/write area */

    for(i=0; i<4; i++){
        /* write data to all region of external SRAM */
        for(address=(UHWORD*)SRAM_BASE; address<(UHWORD*)SRAM_TOP; address++){
            put_hvalue(address, write_pattern[i]);
        }
        /* check data of all region of external SRAM */
        for(address=(UHWORD*)SRAM_BASE; address<(UHWORD*)SRAM_TOP; address++){
            if(get_hvalue(address) != write_pattern[i]){    /* check data */
                /* error occurred */
                return LED_PATTERN[i+4];   /* return LED pattern */
            }
        }
    }

    return LED_NORMAL_END_PATTERN;
}

/****************************************************************************/
/*  Write data to all the ranges of external SRAM and                       */
/*  values of all the ranges of external SRAM is read and compared.         */
/*  Write patterns are '00000000', '55555555', 'AAAAAAAA' and 'FFFFFFFF'.   */
/*  Read/Write size is 32bits.                                              */
/*  Function : read_write_check_word                                        */
/*      Parameters                                                          */
/*          Input   :   Nothing                                             */
/*          Output  :   LED pattern                                         */
/*                         LED_NORMAL_END_PATTERN -> Narmal end.            */
/*                                         others -> Error occurred         */
/****************************************************************************/
UHWORD read_write_check_word(void)
{
    int i;
    UWORD write_pattern[] = {0x00000000, 0x55555555,
                             0xAAAAAAAA, 0xFFFFFFFF};   /* writing patterns */
    UWORD *address; /* address of read/write area */

    for(i=0; i<4; i++){
        /* write data to all region of external SRAM */
        for(address=(UWORD*)SRAM_BASE; address<(UWORD*)SRAM_TOP; address++){
            put_wvalue(address, write_pattern[i]);
        }
        /* check data of all region of external SRAM */
        for(address=(UWORD*)SRAM_BASE; address<(UWORD*)SRAM_TOP; address++){
            if(get_wvalue(address) != write_pattern[i]){    /* check data */
                /* error occurred */
                return LED_PATTERN[i+8];   /* return LED pattern */
            }
        }
    }

    return LED_NORMAL_END_PATTERN;
}

⌨️ 快捷键说明

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