📄 grentech.c
字号:
//*----------------------------------------------------------------------------
//* GRENTECH INC., LTD
//*----------------------------------------------------------------------------
//*----------------------------------------------------------------------------
//* File Name : grentech.h
//* Object :
//*
//* 1.0 27/10/06 HIi : Creation, yanyuan gr1660
//*----------------------------------------------------------------------------
#include <stdio.h>
#include <AT91RM9200.h>
#include <lib_AT91RM9200.h>
#include <grentech.h>
#include <dataflash.h>
#include <norflash.h>
#include <config.h>
#define RAM_MEMORY_TEST_BLOCK_SIZE 0x4000
/* Hardware configuration */
#define SDRAM_BASE_ADDRESS 0x20000000
#define SDRAM_SIZE 0x2000000
#define H_RWHOLDS 0x0
#define H_RWSETUP 0x0
#define H_ACSS 0x2
#define H_DRP 0x1
#define H_DBW 0x1
#define H_BAT 0x1
#define H_TDF 0x0
#define H_WSEN 0x1
#define H_NWS 0x5
#define AT91C_SMC_CSR2 ((volatile int *)0xFFFFFF78)
#define NCS2_ADDR_BASE 0x30000000
/***********************************************************************************/
/***********************************************************************************/
/****************************GRENTECH**********************************************/
#ifdef INCLUDE_SYS_LED_SUPPORT
//*--------------------------------------------------------------------------------------
//* Function Name : GRENTECH_PIO_Set_High
//* Object :
//* Input Parameters :
//* Output Parameters :
//*--------------------------------------------------------------------------------------
void GRENTECH_PIO_Set_High(int bit)
{
*AT91C_PIOA_PER = bit; /* Enables the PIO to control all the pins */
*AT91C_PIOA_OER = bit; /* Enables all the output pins */
*AT91C_PIOA_SODR = bit;
}
//*--------------------------------------------------------------------------------------
//* Function Name : GRENTECH_PIO_Set_LOW
//* Object :
//* Input Parameters :
//* Output Parameters :
//*--------------------------------------------------------------------------------------
void GRENTECH_PIO_Set_LOW(int bit)
{
*AT91C_PIOA_PER = bit; /* Enables the PIO to control all the pins */
*AT91C_PIOA_OER = bit; /* Enables all the output pins */
*AT91C_PIOA_CODR = bit;
}
//*--------------------------------------------------------------------------------------
//* Function Name : Turn_off_debug_led
//* Object :
//* Input Parameters :
//* Output Parameters :
//*--------------------------------------------------------------------------------------
void Turn_off_debug_led(void)
{
GRENTECH_PIO_Set_High(0x00100000);
}
//*--------------------------------------------------------------------------------------
//* Function Name : Turn_on_debug_led
//* Object :
//* Input Parameters :
//* Output Parameters :
//*--------------------------------------------------------------------------------------
void Turn_on_debug_led(void)
{
GRENTECH_PIO_Set_LOW(0x00100000);
}
#endif /*INCLUDE_SYS_LED_SUPPORT*/
#ifdef INCLUDE_LOGO_SHOW
//*--------------------------------------------------------------------------------------
//* Function Name : GRENTECH_Show_Info
//* Object :
//* Input Parameters :
//* Output Parameters :
//*--------------------------------------------------------------------------------------
void GRENTECH_Show_Info(void)
{
printf ("\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n");
printf ("%28s%s", "", "RRU monitor System Boot");
printf ("\n\r\n\r");
printf ("%19s%s", "", "Copyright 1999-2006 GRENTECH, Co., Ltd.");
printf ("\n\r\n\r");
printf ("CPU: %s\r\n", "AT91RM9200 - ARM920T (ARM)");
printf ("Romboot Version: " GRENTECH_ROMBOOT_VERSION "\n\r");
printf ("Creation Date: %s %s\n\r", __DATE__, __TIME__);
printf ("\n\r");
}
#endif /*INCLUDE_LOGO_SHOW*/
#ifdef INCLUDE_FIQ_SUPPORT
//*--------------------------------------------------------------------------------------
//* Function Name : AT91F_FiqHandler
//* Object :
//* Input Parameters :
//* Output Parameters :
//*--------------------------------------------------------------------------------------
void __irq AT91F_FiqHandler(void)
{
static int lighton = 0;
/* disable and Clear the interrupt */
AT91F_AIC_DisableIt(AT91C_BASE_AIC, AT91C_ID_FIQ);
#if 1
/* light the led */
if (lighton == 0)
{
*AT91C_PIOA_CODR = 0x00100000;
lighton = 1;
}
else
{
*AT91C_PIOA_SODR = 0x00100000;
lighton = 0;
}
#endif
/* enable FIQ the interrupt */
AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_FIQ);
/* Releasing the interrupt finish command */
AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC);
}
#endif /*INCLUDE_FIQ_SUPPORT*/
#ifdef INCLUDE_IRQ0_SUPPORT
//*--------------------------------------------------------------------------------------
//* Function Name : AT91F_Irq0Handler
//* Object :
//* Input Parameters :
//* Output Parameters :
//*--------------------------------------------------------------------------------------
void AT91F_Irq0Handler(void)
{
#if 0
static int lighton = 0;
#endif
/* disable and Clear the interrupt */
AT91F_AIC_DisableIt(AT91C_BASE_AIC, AT91C_ID_IRQ0);
#if 0
/* light the led */
if (lighton == 0)
{
*AT91C_PIOA_CODR = 0x00100000;
lighton = 1;
}
else
{
*AT91C_PIOA_SODR = 0x00100000;
lighton = 0;
}
#endif
/* enable FIQ the interrupt */
AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_IRQ0);
/* Releasing the interrupt finish command */
AT91F_AIC_AcknowledgeIt(AT91C_BASE_AIC);
}
#endif /*INCLUDE_IRQ0_SUPPORT*/
#ifdef INCLUDE_HW_DETECT
static int data_bus_check(int data_bus_width)
{
int pattern = 0, test_data_line = 0;
printf("Data bus...");
for (test_data_line = 0; test_data_line < data_bus_width; test_data_line++)
{
pattern = (1 << test_data_line);
*((volatile unsigned int *)SDRAM_BASE_ADDRESS) = pattern;
if (*((volatile unsigned int *)SDRAM_BASE_ADDRESS) != pattern)
{
printf("D%d failed.\n\r", test_data_line);
return (test_data_line);
}
}
printf("passed.\n\r");
return (test_data_line);
}
static int address_bus_check(unsigned int base_address,
unsigned int data_bus_width,
unsigned int mem_size_in_bytes)
{
int pattern = 0xaaaaaaaa, anti_pattern = 0x55555555;
int test_start_address_line = 0, cur_test_address_line = 0, test_loop_line = 0;
unsigned int test_address = base_address;
unsigned int test_end_address = base_address + mem_size_in_bytes;
unsigned int test_loop_address = 0;
printf("Address bus...");
switch (data_bus_width)
{
case 8:
test_start_address_line = 0;
break;
case 16:
test_start_address_line = 1;
break;
case 32:
test_start_address_line = 2;
break;
}
/* test if a address lines is set to 1 */
cur_test_address_line = test_start_address_line;
for (test_address = base_address + (1 << cur_test_address_line);
test_address < test_end_address;
test_address = base_address + (1 << cur_test_address_line++))
{
*(volatile unsigned int *)test_address = pattern;
}
*(volatile unsigned int *)base_address = anti_pattern;
cur_test_address_line = test_start_address_line;
for (test_address = base_address + (1 << cur_test_address_line);
test_address < test_end_address;
test_address = base_address + (1 << cur_test_address_line++))
{
if (*(volatile unsigned int *)test_address != pattern)
{
printf("A%d failed with 0.\n\r", cur_test_address_line);
return (cur_test_address_line);
}
}
/* test if a address lines is set to 1 */
cur_test_address_line = test_start_address_line;
for (test_address = base_address + (1 << cur_test_address_line);
test_address < test_end_address;
test_address = base_address + (1 << cur_test_address_line++))
{
*(volatile unsigned int *)test_address = pattern;
*(volatile unsigned int *)base_address = anti_pattern;
if (*(volatile unsigned int *)test_address != pattern)
{
printf("A%d failed with 1.\n\r", cur_test_address_line);
return (cur_test_address_line);
}
}
/* test if there is a short lines between two lines. */
cur_test_address_line = test_start_address_line;
for (test_address = base_address + (1 << cur_test_address_line);
test_address < test_end_address;
test_address = base_address + (1 << cur_test_address_line++))
{
test_loop_line = test_start_address_line;
for(test_loop_address = base_address + (1 << test_loop_line);
test_loop_address < test_end_address;
test_loop_address = base_address + (1 << test_loop_line++))
{
*(volatile unsigned int *)test_loop_address = pattern;
}
*(volatile unsigned int *)test_address = anti_pattern;
test_loop_line = test_start_address_line;
for(test_loop_address = base_address + (1 << test_loop_line);
test_loop_address < test_end_address;
test_loop_address = base_address + (1 << test_loop_line++))
{
if ((*(volatile unsigned int *)test_loop_address != pattern) &&
(test_loop_address != test_address))
{
printf("A%d failed with short.\n\r", cur_test_address_line);
return(cur_test_address_line);
}
}
}
printf("passed.\n\r");
return (64);
}
static void ram_check(void)
{
data_bus_check(32);
address_bus_check(SDRAM_BASE_ADDRESS, 32, SDRAM_SIZE);
}
void system_hw_check(void)
{
/* check the sdram first */
printf("********************\r\n");
printf("Starting sdram test.\r\n");
printf("********************\r\n");
ram_check();
}
#endif /*INCLUDE_HW_DETECT*/
#ifdef INCLUDE_SRAM_SUPPORT
void ncs2_init(void)
{
int i;
//*AT91C_EBI_CSA = ((*AT91C_EBI_CSA) & 0xFFFFFFF7);
/*intialize fpga access time*/
AT91C_BASE_SMC2->SMC2_CSR[2] = ((H_RWHOLDS<<28)|(H_RWSETUP<<24)
|(H_ACSS<<16)|(H_DRP<<15)|(H_DBW<<13)
|(H_BAT<<12)|(H_TDF<<8)|(H_WSEN<<7)|(H_NWS));
for(i=0;i<0x100;i++);
//printf("\nNcs3 have been initlized.\n");
}
#endif /*INCLUDE_SRAM_SUPPORT*/
int read_datum_from_flash(unsigned long addr_src, unsigned long size, char *addr_dest)
{
#ifdef INCLUDE_DATAFLASH_SUPPORT
return(read_dataflash(addr_src, size, addr_dest));
#endif /*INCLUDE_DATAFLASH_SUPPORT*/
#ifdef INCLUDE_NOR_FLASH_SUPPORT
return(read_nor_flash(addr_src, size, addr_dest));
#endif /*INCLUDE_NOR_FLASH_SUPPORT*/
}
int write_datum_to_flash(unsigned int addr_src, unsigned int size, unsigned long addr_dest)
{
#ifdef INCLUDE_DATAFLASH_SUPPORT
return(write_dataflash(addr_dest, addr_src, size));
#endif /*INCLUDE_DATAFLASH_SUPPORT*/
#ifdef INCLUDE_NOR_FLASH_SUPPORT
return(write_nor_flash(addr_dest, addr_src, size));
#endif /*INCLUDE_NOR_FLASH_SUPPORT*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -