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

📄 memory.c

📁 AT91RM9200的完整启动代码:包括loader, boot及U-boot三部分均已编译通过!欢迎下载使用!
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Memory.c - Memory mappings and remapping functions *//* Copyright - Galileo technology. *//* modified by Josh Huber to clean some things up, and * fit it into the U-Boot framework */#include <galileo/core.h>#include <galileo/memory.h>/********************************************************************* memoryGetBankBaseAddress - Gets the base address of a memory bank*      - If the memory bank size is 0 then this base address has no meaning!!!*** INPUTS:   MEMORY_BANK bank - The bank we ask for its base Address.* OUTPUT:   N/A* RETURNS: Memory bank base address.*********************************************************************/static unsigned long memoryGetBankRegOffset(MEMORY_BANK bank){    switch (bank)    {	case BANK0:	    return SCS_0_LOW_DECODE_ADDRESS;	case BANK1:	    return SCS_1_LOW_DECODE_ADDRESS;	case BANK2:	    return SCS_2_LOW_DECODE_ADDRESS;	case BANK3:	    return SCS_3_LOW_DECODE_ADDRESS;    }    return SCS_0_LOW_DECODE_ADDRESS; /* default value */}unsigned int memoryGetBankBaseAddress(MEMORY_BANK bank){    unsigned int base;    unsigned int regOffset=memoryGetBankRegOffset(bank);    GT_REG_READ(regOffset,&base);    base = base << 20;    return base;}/********************************************************************* memoryGetDeviceBaseAddress - Gets the base address of a device.*           - If the device size is 0 then this base address has no meaning!!!*** INPUT:   DEVICE device - The device we ask for its base address.* OUTPUT:   N/A* RETURNS: Device base address.*********************************************************************/static unsigned int memoryGetDeviceRegOffset(DEVICE device){    switch (device)    {	case DEVICE0:	    return CS_0_LOW_DECODE_ADDRESS;	case DEVICE1:	    return CS_1_LOW_DECODE_ADDRESS;	case DEVICE2:	    return CS_2_LOW_DECODE_ADDRESS;	case DEVICE3:	    return CS_3_LOW_DECODE_ADDRESS;	case BOOT_DEVICE:	    return BOOTCS_LOW_DECODE_ADDRESS;    }    return CS_0_LOW_DECODE_ADDRESS; /* default value */}unsigned int memoryGetDeviceBaseAddress(DEVICE device){    unsigned int regBase;    unsigned int regEnd;    unsigned int regOffset=memoryGetDeviceRegOffset(device);    GT_REG_READ(regOffset, &regBase);    GT_REG_READ(regOffset+8, &regEnd);    if(regEnd<=regBase) return 0xffffffff;	/* ERROR !!! */    regBase = regBase << 20;    return regBase;}/********************************************************************* memoryGetBankSize - Returns the size of a memory bank.*** INPUT:    MEMORY_BANK bank - The bank we ask for its size.* OUTPUT:   N/A* RETURNS: Memory bank size.*********************************************************************/unsigned int memoryGetBankSize(MEMORY_BANK bank){    unsigned int size,base;    unsigned int highValue;    unsigned int highAddress=memoryGetBankRegOffset(bank)+8;    base = memoryGetBankBaseAddress(bank);    GT_REG_READ(highAddress,&highValue);    highValue = (highValue + 1) << 20;    if(base > highValue)        size=0;    else        size = highValue - base;    return size;}/********************************************************************* memoryGetDeviceSize - Returns the size of a device memory space*** INPUT:    DEVICE device - The device we ask for its base address.* OUTPUT:   N/A* RETURNS:  Size of a device memory space.*********************************************************************/unsigned int memoryGetDeviceSize(DEVICE device){    unsigned int size,base;    unsigned int highValue;    unsigned int highAddress=memoryGetDeviceRegOffset(device)+8;    base = memoryGetDeviceBaseAddress(device);    GT_REG_READ(highAddress,&highValue);    if (highValue == 0xfff)    {        size = (~base) + 1;	/* what the heck is this? */        return size;    }    else        highValue = (highValue + 1) << 20;    if(base > highValue)        size=0;    else        size = highValue - base;    return size;}/********************************************************************* memoryGetDeviceWidth - A device can be with: 1,2,4 or 8 Bytes data width.*                  The width is determine in registers: 'Device Parameters'*                  registers (0x45c, 0x460, 0x464, 0x468, 0x46c - for each device.*                  at bits: [21:20].** INPUT:    DEVICE device - Device number* OUTPUT:   N/A* RETURNS:  Device width in Bytes (1,2,4 or 8), 0 if error had occurred.*********************************************************************/unsigned int memoryGetDeviceWidth(DEVICE device){    unsigned int width;    unsigned int regValue;    GT_REG_READ(DEVICE_BANK0PARAMETERS + device*4,&regValue);    width =  (regValue & 0x00300000) >> 20;    switch (width)    {        case 0:            return 1;        case 1:            return 2;        case 2:            return 4;        case 3:            return 8;        default:            return 0;    }}bool memoryMapBank(MEMORY_BANK bank, unsigned int bankBase,unsigned int bankLength){    unsigned int low=0xfff;    unsigned int high=0x0;    unsigned int regOffset=memoryGetBankRegOffset(bank);    if(bankLength!=0) {	low = (bankBase >> 20) & 0xffff;	high=((bankBase+bankLength)>>20)-1;    }#ifdef DEBUG    {	unsigned int oldLow, oldHigh;	GT_REG_READ(regOffset,&oldLow);	GT_REG_READ(regOffset+8,&oldHigh);	printf("b%d %x-%x->%x-%x\n", bank, oldLow, oldHigh, low, high);    }#endif    GT_REG_WRITE(regOffset,low);    GT_REG_WRITE(regOffset+8,high);    return true;}bool memoryMapDeviceSpace(DEVICE device, unsigned int deviceBase,unsigned int deviceLength){    /* TODO: what are appropriate "unmapped" values? */    unsigned int low=0xfff;    unsigned int high=0x0;    unsigned int regOffset=memoryGetDeviceRegOffset(device);    if(deviceLength != 0) {	low=deviceBase>>20;	high=((deviceBase+deviceLength)>>20)-1;    } else {	/* big problems in here... */	/* this will HANG */    }    GT_REG_WRITE(regOffset,low);    GT_REG_WRITE(regOffset+8,high);    return true;}/********************************************************************* memoryMapInternalRegistersSpace - Sets new base address for the internals*                                   registers.** INPUTS:  unsigned int internalRegBase - The new base address.* RETURNS: true on success, false on failure*********************************************************************/

⌨️ 快捷键说明

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