📄 flashvmem.c
字号:
/*
* File : flashvmem.c
* Synopsys : OS21 virtual memory FLASH access functions.
*
* Copyright 2006 STMicroelectronics Limited. All right reserved.
*
* FLASH memory access functions which use the OS21 vmem API. These functions
* are unsuitable for use in a multi-threaded application (static variables are
* not protected).
*/
#include <stdio.h>
#include <stdlib.h>
#include "flash.h"
#ifdef __ST200__
#include "tlbhelper.h"
#endif
/* Globals used in accessing FLASH */
static unsigned int uncachedFlashBase = 0;
static unsigned int cachedFlashBase = 0;
/* Based on FLASH_BASE, work out what size we will map for FLASH */
static unsigned int getMappedFlashSize(void)
{
static unsigned int mappedFlashSize = 0;
if (!mappedFlashSize)
{
/* We decide to use from FLASH_BASE to the next 256MB aligned address. If
FLASH_BASE is 256MB aligned this should be TLB entry efficient.
*/
unsigned int mask = 0x0FFFFFFF;
while (mask)
{
if ((mask & FLASH_START) == 0)
{
mappedFlashSize = mask + 1;
break;
}
mask = mask >> 1;
}
}
return mappedFlashSize;
}
/* Function for getting the uncached base address of FLASH */
unsigned int getUncachedFlashBase(void)
{
if (!uncachedFlashBase)
{
uncachedFlashBase = (unsigned int)vmem_create((void*)FLASH_START, getMappedFlashSize(), (void*)0, VMEM_CREATE_UNCACHED);
if (!uncachedFlashBase)
{
fprintf(stderr, "flashdir: Unable to obtain uncached virtual memory mapping for FLASH\n");
exit(1);
}
}
return uncachedFlashBase;
}
/* Function for getting the cached base address of FLASH */
unsigned int getCachedFlashBase(void)
{
if (!cachedFlashBase)
{
cachedFlashBase = (unsigned int)vmem_create((void*)FLASH_START, getMappedFlashSize(), (void*)0, VMEM_CREATE_CACHED);
if (!cachedFlashBase)
{
fprintf(stderr, "flashdir: Unable to obtain cached virtual memory mapping for FLASH\n");
exit(1);
}
}
return cachedFlashBase;
}
/* Function for converting a physical FLASH address to uncached */
unsigned int physToUncachedFlashAddr(unsigned int addr)
{
return getUncachedFlashBase() + (addr - FLASH_START);
}
/* Function for converting a physical FLASH address to cached */
unsigned int physToCachedFlashAddr(unsigned int addr)
{
return getCachedFlashBase() + (addr - FLASH_START);
}
/* Unmap any vmem mapped FLASH regions implicitly created by the
get<mode>FlashBase functions.
*/
void unmapFlash()
{
if (uncachedFlashBase)
vmem_delete((void*)uncachedFlashBase);
if (cachedFlashBase)
vmem_delete((void*)cachedFlashBase);
}
/*
* Perform core specific memory initialisation.
*/
void init_flash_access(void)
{
#if defined(__ST231__)
/* Enable speculative loads over the flash region so we can use the Toolset
library functions on it safely (they are compiled with speculation on by
default).
*/
if (ensureSCURegion((void*)(FLASH_START & 0xF0000000), 0x10000000))
{
fprintf(stderr, "Failed to cover Flash region for speculative loads\n");
exit(1);
}
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -