📄 get_ebi.c
字号:
//*----------------------------------------------------------------------------
//* ATMEL Microcontroller Software Support - ROUSSET -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name : get_ebi.c
//* Object : get the chip ID
//*
//* 1.0 03/11/00 JPP : Creation
//*----------------------------------------------------------------------------
//* --------------------------- include file ----------------------------------
#include <stdio.h>
#include "get_ebi.h"
//* ------------------------------ extern function --------------------------
extern int get_mem_test_abort ( unsigned int *pt_data);
//* ------------------------------ extern global data -----------------------
extern FlashAt49BVDef *flash;
static ChipSelectDesc cs_desc;
//*----------------------------------------------------------------------------
//* Function Name : get_ebi_memory_csr
//* Object : get the Chip select number for an addresss
//* Input Parameters : <address> check address
//* <map_conf> ebi configurationt
//* Output Parameters : Chip select number
//*----------------------------------------------------------------------------
int get_ebi_memory_csr(char * address, ebi_def* map_conf)
{
int count;
char found = FALSE;
for (count=0; (count < NB_CHIP_SELEC) & (found == FALSE) ; count ++)
{
if (
((u_int)address < (map_conf[count].start_address + map_conf[count].size)) &
((u_int)address >= (map_conf[count].start_address))
) found = TRUE;
}
return (--count);
}
//*----------------------------------------------------------------------------
//* Function Name : get_ram_size
//* Object : Check Ram size
//* Input Parameters : <base_address> Memory Base address
//* <type> Type address to update
//* <max_size> size max
//* Output Parameters : Ram size
//* <type> Type address updated
//*----------------------------------------------------------------------------
static u_int get_ram_size(u_int * base_address,u_int *type, u_int max_size)
{
u_int value,new_value;
u_int *next_address;
u_int end=FALSE;
*type = NO_RAM_MODULO;
for ( next_address=base_address+RAM_STEP ;
(end != TRUE ) & (next_address < base_address +max_size) ;
next_address += RAM_STEP)
{
//* check if ram
value = *next_address; //* read n at add
*next_address = value + 1; //* write n+1 at add
new_value = *next_address; //* read n+1
*next_address = value ; //* write n
if ( new_value != value + 1 )
{ //* Check if RAM
end = TRUE;
}
if ( *next_address == *base_address)
{ //* Check RAM modulo
*type = RAM_MODULO;
end = TRUE;
}
}
//* return size in Bytes
return ( (next_address-base_address- RAM_STEP) << 2 );
}
//*----------------------------------------------------------------------------
//* Function Name : get_ebi_csr
//* Object : Read EBI Chip Select
//* Input Parameters : <ebi> Chip select
//* <*message> string to write
//* Output Parameters : <message> updated
//*----------------------------------------------------------------------------
void get_ebi_csr( u_int ebi, char * string )
{
u_int csr;
u_int len=0;
*string = 0;
cs_desc.cs_id = ebi;
//* get CSR status
csr = at91_chip_select_get_status ( &cs_desc );
//* EBI Architecture
len += sprintf(&string[len],"CSR %01d:%08X ",ebi,csr);
if ( csr & EBI_CSEN == EBI_CSEN )
{
//* Data Bus Width
if ( (csr & EBI_DBW) == EBI_DBW_16)
len += sprintf(&string[len],"16 bits ");
else if ( (csr & EBI_DBW) == EBI_DBW_8)
len += sprintf(&string[len],"8 bits ");
else
len += sprintf(&string[len],"Unknown ");
//* Number of Wait States
if ( csr & EBI_WSE == EBI_WSE)
len += sprintf(&string[len],"%d WS ", ((csr & EBI_NWS)>>2)+1);
//* Page size
switch (EBI_PAGES&csr)
{
case EBI_PAGES_1M:
len += sprintf(&string[len],"1 Mb");
break;
case EBI_PAGES_4M:
len += sprintf(&string[len],"4 Mb");
break;
case EBI_PAGES_16M:
len += sprintf(&string[len],"16 Mb");
break;
case EBI_PAGES_64M:
len += sprintf(&string[len],"64 Mb");
break;
default:
len += sprintf(&string[len],"xx");
break;
}
}
else
{
//* EBI not selected
len += sprintf(&string[len],"Disable");
}
}
//*----------------------------------------------------------------------------
//* Function Name : get_ebi_mem_type
//* Object : Read EBI Chip Select and check the men type
//* Input Parameters : <ebi> Chip select
//* <*message> string to write
//* Output Parameters : <message> updated
//*----------------------------------------------------------------------------
void get_ebi_mem_type( u_int ebi, char * string, ebi_def* map_conf )
{
u_int back_ebi;
u_int csr;
u_int len=0;
volatile u_int *pt_data;
u_int data,data_next;
flash_word type;
*string = 0;
cs_desc.cs_id = ebi;
back_ebi =0 ;
csr = at91_chip_select_get_status ( &cs_desc );
flash = 0;
if ( (csr & EBI_CSEN) != EBI_CSEN )
{ //* Open new chip select with max wait state
back_ebi = csr;
cs_desc.base_address = 0xA0000000;
cs_desc.wait_state = 8;
cs_desc.page_size = CS_16_MBYTE;
cs_desc.byte_access_type = CS_BYTE_WRITE;
cs_desc.data_bus_width =CS_16_BIT_BUS;
len += sprintf(&string[len],"open new ");
at91_chip_select_open(&cs_desc);
cs_desc.cs_id = ebi;
csr = at91_chip_select_get_status ( &cs_desc );
}
pt_data= (u_int *) (csr & EBI_BA);
if ( back_ebi != 0 )
map_conf->start_address = 0;
else
map_conf->start_address = pt_data;
map_conf->type = EBI_MEMORY_TYPE_UNKNOWN;
map_conf->name = "Unknow";
map_conf->size = 0;
// read the memory value
if ( get_mem_test_abort ( pt_data))
{
len += sprintf(&string[len],"Data Abort !");
}
else
{// no data_abort
data = *pt_data;
*pt_data = data -1;
data_next = *pt_data;
if ( (data - 1) == data_next)
{ //ram
map_conf->type = EBI_MEMORY_TYPE_RAM;
map_conf->name = "RAM";
map_conf->size = get_ram_size((u_int*)(csr& EBI_BA),&data,(16*1024*1024));
len += sprintf(&string[len],"Ram %d Kb ",map_conf->size/1024);
if (data == 1)
len += sprintf(&string[len],"Modulo");
}
else
{ // Flash
len += sprintf(&string[len],"Flash ");
type = flash_at49_identify((flash_word *) (csr & EBI_BA));
if (type == FLASH_AT49BV_UNKNOW)
{
type = flash_at29_identify((flash_word *) (csr & EBI_BA));
if (type ==FLASH_AT29LV_UNKNOW )
{
len += sprintf(&string[len],"Unknow");
flash = 0;
}
else
{
for (data=0 ; data < NB_FLASH_AT29_SUPPORTED ; data ++)
{
if ( type == FlashTableAT29[data].flash_id )
{
map_conf->type = EBI_MEMORY_TYPE_FLASH_AT29;
map_conf->name = FlashTableAT29[data].flash_name;
map_conf->size = FlashTableAT29[data].flash_size;
map_conf->flash_type = &FlashTableAT29[data];
len += sprintf(&string[len],"%s",FlashTableAT29[data].flash_name);
flash = &FlashTableAT29[data];
}
}
}
}
else
{
for (data=0 ; data < NB_FLASH_SUPPORTED ; data ++)
{
if ( type == FlashTable[data].flash_id )
{
map_conf->type = EBI_MEMORY_TYPE_FLASH_AT49;
map_conf->name = FlashTable[data].flash_name;
map_conf->size = FlashTable[data].flash_size;
map_conf->flash_type = &FlashTable[data];
len += sprintf(&string[len],"%s",FlashTable[data].flash_name);
flash = &FlashTable[data];
}
}
}
}
} //* endif data_abort
if (back_ebi != 0)
{
EBI_BASE->EBI_CSR[cs_desc.cs_id]=back_ebi;
}
//* End
}
//* end of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -