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

📄 memory.c

📁 AT91RM9200的完整启动代码:包括loader, boot及U-boot三部分均已编译通过!欢迎下载使用!
💻 C
📖 第 1 页 / 共 2 页
字号:
bool memoryMapInternalRegistersSpace(unsigned int internalRegBase){    unsigned int currentValue;    unsigned int internalValue = internalRegBase;    internalRegBase = (internalRegBase >> 20);    GT_REG_READ(INTERNAL_SPACE_DECODE,&currentValue);    internalRegBase = (currentValue & 0xffff0000) | internalRegBase;    GT_REG_WRITE(INTERNAL_SPACE_DECODE,internalRegBase);    INTERNAL_REG_BASE_ADDR = internalValue;    return true;}/********************************************************************* memoryGetInternalRegistersSpace - Gets internal registers Base Address.** INPUTS:  unsigned int internalRegBase - The new base address.* RETURNS: true on success, false on failure*********************************************************************/unsigned int memoryGetInternalRegistersSpace(void){    return INTERNAL_REG_BASE_ADDR;}/********************************************************************* memorySetProtectRegion - This function modifys one of the 8 regions with*                          one of the three protection mode.*                        - Be advised to check the spec before modifying them.*** Inputs: CPU_PROTECT_REGION - one of the eight regions.*         CPU_ACCESS - general access.*         CPU_WRITE - read only access.*         CPU_CACHE_PROTECT - chache access.*      we defining CPU because there is another protect from the pci SIDE.* Returns: false if one of the parameters is wrong and true else*********************************************************************/bool memorySetProtectRegion(MEMORY_PROTECT_REGION region,                            MEMORY_ACCESS memAccess,                            MEMORY_ACCESS_WRITE memWrite,                            MEMORY_CACHE_PROTECT cacheProtection,                            unsigned int baseAddress,                            unsigned int regionLength){    unsigned int protectHigh = baseAddress + regionLength;    if(regionLength == 0) /* closing the region */    {        GT_REG_WRITE(CPU_LOW_PROTECT_ADDRESS_0 + 0x10*region,0x0000ffff);        GT_REG_WRITE(CPU_HIGH_PROTECT_ADDRESS_0 + 0x10*region,0);        return true;    }    baseAddress =  (baseAddress & 0xfff00000) >> 20;    baseAddress = baseAddress | memAccess << 16 |  memWrite << 17                     | cacheProtection << 18;    GT_REG_WRITE(CPU_LOW_PROTECT_ADDRESS_0 + 0x10*region,baseAddress);    protectHigh = (protectHigh & 0xfff00000) >> 20;    GT_REG_WRITE(CPU_HIGH_PROTECT_ADDRESS_0 + 0x10*region,protectHigh - 1);    return true;}/********************************************************************* memorySetRegionSnoopMode - This function modifys one of the 4 regions which*                            supports Cache Coherency.*** Inputs: SNOOP_REGION region - One of the four regions.*         SNOOP_TYPE snoopType - There is four optional Types:*                               1. No Snoop.*                               2. Snoop to WT region.*                               3. Snoop to WB region.*                               4. Snoop & Invalidate to WB region.*         unsigned int baseAddress - Base Address of this region.*         unsigned int topAddress - Top Address of this region.* Returns: false if one of the parameters is wrong and true else*********************************************************************/bool memorySetRegionSnoopMode(MEMORY_SNOOP_REGION region,                              MEMORY_SNOOP_TYPE snoopType,                              unsigned int baseAddress,                              unsigned int regionLength){    unsigned int snoopXbaseAddress;    unsigned int snoopXtopAddress;    unsigned int data;    unsigned int snoopHigh = baseAddress + regionLength;    if( (region > MEM_SNOOP_REGION3) || (snoopType > MEM_SNOOP_WB) )        return false;    snoopXbaseAddress = SNOOP_BASE_ADDRESS_0 + 0x10 * region;    snoopXtopAddress = SNOOP_TOP_ADDRESS_0 + 0x10 * region;    if(regionLength == 0) /* closing the region */    {        GT_REG_WRITE(snoopXbaseAddress,0x0000ffff);        GT_REG_WRITE(snoopXtopAddress,0);        return true;    }    baseAddress = baseAddress & 0xffff0000;    data = (baseAddress >> 16) | snoopType << 16;    GT_REG_WRITE(snoopXbaseAddress,data);    snoopHigh = (snoopHigh & 0xfff00000) >> 20;    GT_REG_WRITE(snoopXtopAddress,snoopHigh - 1);    return true;}/********************************************************************* memoryRemapAddress - This fubction used for address remapping.*** Inputs: regOffset: remap register*         remapValue :* Returns: false if one of the parameters is erroneous,true otherwise.*********************************************************************/bool memoryRemapAddress(unsigned int remapReg, unsigned int remapValue){    unsigned int valueForReg;    valueForReg = (remapValue & 0xfff00000) >> 20;    GT_REG_WRITE(remapReg, valueForReg);    return true;}/********************************************************************* memoryGetDeviceParam - This function used for getting device parameters from*                        DEVICE BANK PARAMETERS REGISTER*** Inputs:        - deviceParam: STRUCT with paramiters for DEVICE BANK*                  PARAMETERS REGISTER*                - deviceNum : number of device* Returns: false if one of the parameters is erroneous,true otherwise.*********************************************************************/bool memoryGetDeviceParam(DEVICE_PARAM *deviceParam, DEVICE deviceNum){    unsigned int valueOfReg;    unsigned int calcData;    GT_REG_READ(DEVICE_BANK0PARAMETERS + 4 * deviceNum, &valueOfReg);    calcData = (0x7 & valueOfReg) + ((0x400000 & valueOfReg) >> 19);    deviceParam -> turnOff = calcData;          /* Turn Off */    calcData = ((0x78 & valueOfReg) >> 3) + ((0x800000 & valueOfReg) >> 19);    deviceParam -> acc2First = calcData;        /* Access To First */    calcData = ((0x780 & valueOfReg) >> 7) + ((0x1000000 & valueOfReg) >> 20);    deviceParam -> acc2Next = calcData;         /* Access To Next */    calcData = ((0x3800 & valueOfReg) >> 11) + ((0x2000000 & valueOfReg) >> 22);    deviceParam -> ale2Wr = calcData;           /* Ale To Write */    calcData = ((0x1c000 & valueOfReg) >> 14) + ((0x4000000 & valueOfReg) >> 23);    deviceParam -> wrLow = calcData;            /* Write Active */    calcData = ((0xe0000 & valueOfReg) >> 17) + ((0x8000000 & valueOfReg) >> 24);    deviceParam -> wrHigh = calcData;           /* Write High */    calcData = ((0x300000 & valueOfReg) >> 20);    switch (calcData)    {    case 0:        deviceParam -> deviceWidth = 1;         /* one Byte - 8-bit */        break;    case 1:        deviceParam -> deviceWidth = 2;         /* two Bytes - 16-bit */        break;    case 2:        deviceParam -> deviceWidth = 4;         /* four Bytes - 32-bit */        break;    case 3:        deviceParam -> deviceWidth = 8;         /* eight Bytes - 64-bit */        break;    default:        deviceParam -> deviceWidth = 1;        break;    }    return true;}/********************************************************************* memorySetDeviceParam - This function used for setting device parameters to*                        DEVICE BANK PARAMETERS REGISTER*** Inputs:        - deviceParam: STRUCT for store paramiters from DEVICE BANK*                  PARAMETERS REGISTER*                - deviceNum : number of device* Returns: false if one of the parameters is erroneous,true otherwise.*********************************************************************/bool memorySetDeviceParam(DEVICE_PARAM *deviceParam, DEVICE deviceNum){    unsigned int valueForReg;    if((deviceParam -> turnOff >= 0xf) || (deviceParam -> acc2First >= 0x1f) ||       (deviceParam -> acc2Next >= 0x1f) || (deviceParam -> ale2Wr >= 0xf) ||        (deviceParam -> wrLow >= 0xf) || (deviceParam -> wrHigh >= 0xf))        return false;    valueForReg = (((deviceParam -> turnOff) & 0x7) |                   (((deviceParam -> turnOff) & 0x8) << 19) |                   (((deviceParam -> acc2First) & 0xf) << 3) |                   (((deviceParam -> acc2First) & 0x10) << 19) |                   (((deviceParam -> acc2Next) & 0xf) << 7) |                   (((deviceParam -> acc2Next) & 0x10) << 20) |                   (((deviceParam -> ale2Wr) & 0x7) << 11) |                   (((deviceParam -> ale2Wr) & 0xf) << 22) |                   (((deviceParam -> wrLow) & 0x7) << 14) |                   (((deviceParam -> wrLow) & 0xf) << 23) |                   (((deviceParam -> wrHigh) & 0x7) << 17) |                   (((deviceParam -> wrHigh) & 0xf) << 24));    /* insert the device width: */    switch(deviceParam->deviceWidth)    {    case 1:        valueForReg = valueForReg | _8BIT;        break;    case 2:        valueForReg = valueForReg | _16BIT;        break;    case 4:        valueForReg = valueForReg | _32BIT;        break;    case 8:        valueForReg = valueForReg | _64BIT;        break;    default:        valueForReg = valueForReg | _8BIT;        break;    }    GT_REG_WRITE(DEVICE_BANK0PARAMETERS + 4 * deviceNum, valueForReg);    return true;}

⌨️ 快捷键说明

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