Renamed memory_region_t in memory_area_t because naming confusion with MPU regions.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15098 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
7bd05fc08f
commit
0d3278d54f
|
@ -45,21 +45,21 @@
|
|||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Type of a memory region.
|
||||
* @brief Type of a memory area.
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* @brief Memory region base.
|
||||
* @brief Memory area base.
|
||||
* @note Value -1 is reserved as end-on-array marker.
|
||||
*/
|
||||
uint8_t *base;
|
||||
/**
|
||||
* @brief Memory region size.
|
||||
* @brief Memory area size.
|
||||
* @note Value 0 represents the whole address space and is only valid
|
||||
* when @p base is also zero.
|
||||
*/
|
||||
size_t size;
|
||||
} memory_region_t;
|
||||
} memory_area_t;
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module macros. */
|
||||
|
@ -73,7 +73,7 @@ typedef struct {
|
|||
extern "C" {
|
||||
#endif
|
||||
#if CH_CFG_USE_MEMCHECKS == TRUE
|
||||
bool chMemIsAreaContainedX(const memory_region_t regions[],
|
||||
bool chMemIsAreaContainedX(const memory_area_t areas[],
|
||||
const void *base,
|
||||
size_t size);
|
||||
bool chMemIsAreaWritableX(const void *p,
|
||||
|
@ -93,36 +93,36 @@ extern "C" {
|
|||
|
||||
/**
|
||||
* @brief Memory area check.
|
||||
* @details Checks if specified area belongs to the specified region.
|
||||
* @details Checks if specified area belongs to the specified area.
|
||||
*
|
||||
* @param[in] mrp pointer to an array of valid regions terminated with
|
||||
* @param[in] map pointer to an array of valid areas terminated with
|
||||
* a zero element
|
||||
* @param[in] p pointer to the area to be checked
|
||||
* @param[in] size size of the area to be checked
|
||||
* @return The test result.
|
||||
* @retval false if the area is entirely contained within one of the
|
||||
* specified regions.
|
||||
* specified areas.
|
||||
* @retval true if the area check failed.
|
||||
*
|
||||
* @xclass
|
||||
*/
|
||||
static inline bool chMemIsAreaWithinX(const memory_region_t *mrp,
|
||||
static inline bool chMemIsAreaWithinX(const memory_area_t *map,
|
||||
const void *p,
|
||||
size_t size) {
|
||||
uint8_t *base = (uint8_t *)p;
|
||||
|
||||
return (bool)((base >= mrp->base) &&
|
||||
(size <= (size_t)(mrp->base + mrp->size - base)));
|
||||
return (bool)((base >= map->base) &&
|
||||
(size <= (size_t)(map->base + map->size - base)));
|
||||
}
|
||||
|
||||
#if CH_CFG_USE_MEMCHECKS == FALSE
|
||||
/* Stub implementations for when the functionality is disabled, areas are
|
||||
always reported as valid.*/
|
||||
static inline bool chMemIsAreaContainedX(const memory_region_t regions[],
|
||||
static inline bool chMemIsAreaContainedX(const memory_area_t areas[],
|
||||
const void *base,
|
||||
size_t size) {
|
||||
|
||||
(void)regions;
|
||||
(void)areas;
|
||||
(void)base;
|
||||
(void)size;
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ extern "C" {
|
|||
void *chCoreAllocFromTopI(size_t size, unsigned align, size_t offset);
|
||||
void *chCoreAllocFromBase(size_t size, unsigned align, size_t offset);
|
||||
void *chCoreAllocFromTop(size_t size, unsigned align, size_t offset);
|
||||
void chCoreGetStatusX(memory_region_t *mrp);
|
||||
void chCoreGetStatusX(memory_area_t *map);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -117,9 +117,9 @@ struct memory_heap {
|
|||
*/
|
||||
memgetfunc2_t provider;
|
||||
/**
|
||||
* @brief Memory region for this heap.
|
||||
* @brief Memory area for this heap.
|
||||
*/
|
||||
memory_region_t region;
|
||||
memory_area_t area;
|
||||
/**
|
||||
* @brief Free blocks list header.
|
||||
*/
|
||||
|
|
|
@ -37,23 +37,23 @@
|
|||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Default writable memory regions.
|
||||
* @brief Default writable memory areas.
|
||||
* @details By default all memory is writable, user must provide its own
|
||||
* writable regions array for the device in use.
|
||||
* writable areas array for the device in use.
|
||||
* @note The array is terminated by an end marker (base=-1).
|
||||
*/
|
||||
CC_WEAK memory_region_t __ch_mem_writable_regions[] = {
|
||||
CC_WEAK memory_area_t __ch_mem_writable_areas[] = {
|
||||
{(uint8_t *)0, 0U}, /* Whole space is writable. */
|
||||
{(uint8_t *)-1, 0U},
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Default readable memory regions.
|
||||
* @brief Default readable memory areas.
|
||||
* @details By default all memory is readable, user must provide its own
|
||||
* readable regions array for the device in use.
|
||||
* readable areas array for the device in use.
|
||||
* @note The array is terminated by an end marker (base=-1).
|
||||
*/
|
||||
CC_WEAK memory_region_t __ch_mem_readable_regions[] = {
|
||||
CC_WEAK memory_area_t __ch_mem_readable_areas[] = {
|
||||
{(uint8_t *)0, 0U}, /* Whole space is readable. */
|
||||
{(uint8_t *)-1, 0U},
|
||||
};
|
||||
|
@ -76,31 +76,31 @@ CC_WEAK memory_region_t __ch_mem_readable_regions[] = {
|
|||
|
||||
/**
|
||||
* @brief Memory area check.
|
||||
* @details Checks if specified area belongs to one of the specified regions.
|
||||
* @details Checks if specified area belongs to one of the specified areas.
|
||||
*
|
||||
* @param[in] mrp array of valid regions terminated with a zero element
|
||||
* @param[in] map array of valid areas terminated with a zero element
|
||||
* @param[in] base pointer to the area to be checked
|
||||
* @param[in] size size of the area to be checked
|
||||
* @return The test result.
|
||||
* @retval false if the area is entirely contained within one of the
|
||||
* specified regions.
|
||||
* specified areas.
|
||||
* @retval true if the area check failed.
|
||||
*
|
||||
* @xclass
|
||||
*/
|
||||
bool chMemIsAreaContainedX(const memory_region_t regions[],
|
||||
bool chMemIsAreaContainedX(const memory_area_t areas[],
|
||||
const void *base,
|
||||
size_t size) {
|
||||
const memory_region_t *mrp = ®ions[0];
|
||||
const memory_area_t *map = &areas[0];
|
||||
|
||||
chDbgCheck(base != NULL);
|
||||
|
||||
/* Scanning the array of the valid regions for a mismatch.*/
|
||||
while (mrp->base != (uint8_t *)-1) {
|
||||
if (chMemIsAreaWithinX(mrp, base, size)) {
|
||||
/* Scanning the array of the valid areas for a mismatch.*/
|
||||
while (map->base != (uint8_t *)-1) {
|
||||
if (chMemIsAreaWithinX(map, base, size)) {
|
||||
return true;
|
||||
}
|
||||
mrp++;
|
||||
map++;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -109,19 +109,19 @@ bool chMemIsAreaContainedX(const memory_region_t regions[],
|
|||
/**
|
||||
* @brief Memory writable area check.
|
||||
* @details Checks if specified pointer belongs to one of the system-defined
|
||||
* writable regions and is aligned as specified.
|
||||
* writable areas and is aligned as specified.
|
||||
* @note This function is only effective if @p CH_CFG_SYS_WRITABLE_REGIONS
|
||||
* is defined, if it is not defined then just the alignment of
|
||||
* the pointer is checked.
|
||||
* @note @p __ch_mem_writable_regions must be the name of a global
|
||||
* @p memory_region_t array terminated with an end marker (-1, 0).
|
||||
* @note @p __ch_mem_writable_areas must be the name of a global
|
||||
* @p memory_area_t array terminated with an end marker (-1, 0).
|
||||
*
|
||||
* @param[in] p pointer to be checked
|
||||
* @param[in] align required pointer alignment to be checked, must be
|
||||
* a power of two
|
||||
* @return The test result.
|
||||
* @retval false if the area is entirely contained within one of the
|
||||
* system-defined writable regions.
|
||||
* system-defined writable areas.
|
||||
* @retval true if the area check failed.
|
||||
*
|
||||
* @xclass
|
||||
|
@ -136,25 +136,25 @@ bool chMemIsAreaWritableX(const void *p,
|
|||
return true;
|
||||
}
|
||||
|
||||
return chMemIsAreaContainedX(__ch_mem_writable_regions, p, size);
|
||||
return chMemIsAreaContainedX(__ch_mem_writable_areas, p, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Memory readable area check.
|
||||
* @details Checks if specified pointer belongs to one of the system-defined
|
||||
* readable regions and is aligned as specified.
|
||||
* readable areas and is aligned as specified.
|
||||
* @note This function is only effective if @p CH_CFG_SYS_READABLE_REGIONS
|
||||
* is defined, if it is not defined then just the alignment of
|
||||
* the pointer is checked.
|
||||
* @note @p __ch_mem_readable_regions must be the name of a global
|
||||
* @p memory_region_t array terminated with an end marker (-1, 0).
|
||||
* @note @p __ch_mem_readable_areas must be the name of a global
|
||||
* @p memory_area_t array terminated with an end marker (-1, 0).
|
||||
*
|
||||
* @param[in] p pointer to be checked
|
||||
* @param[in] align required pointer alignment to be checked, must be
|
||||
* a power of two
|
||||
* @return The test result.
|
||||
* @retval false if the area is entirely contained within one of the
|
||||
* system-defined readable regions.
|
||||
* system-defined readable areas.
|
||||
* @retval true if the area check failed.
|
||||
*
|
||||
* @xclass
|
||||
|
@ -169,7 +169,7 @@ bool chMemIsAreaReadableX(const void *p,
|
|||
return true;
|
||||
}
|
||||
|
||||
return chMemIsAreaContainedX(__ch_mem_readable_regions, p, size);
|
||||
return chMemIsAreaContainedX(__ch_mem_readable_areas, p, size);
|
||||
}
|
||||
|
||||
#endif /* CH_CFG_USE_MEMCHECKS == TRUE */
|
||||
|
|
|
@ -212,15 +212,15 @@ void *chCoreAllocFromTop(size_t size, unsigned align, size_t offset) {
|
|||
/**
|
||||
* @brief Core memory status.
|
||||
*
|
||||
* @param[in] mrp Memory region representing available core space.
|
||||
* @param[in] map Memory area representing available core space.
|
||||
*
|
||||
* @xclass
|
||||
*/
|
||||
void chCoreGetStatusX(memory_region_t *mrp) {
|
||||
void chCoreGetStatusX(memory_area_t *map) {
|
||||
|
||||
mrp->base = ch_memcore.basemem;
|
||||
map->base = ch_memcore.basemem;
|
||||
/*lint -save -e9033 [10.8] The cast is safe.*/
|
||||
mrp->size = (size_t)(ch_memcore.topmem - ch_memcore.basemem);
|
||||
map->size = (size_t)(ch_memcore.topmem - ch_memcore.basemem);
|
||||
/*lint -restore*/
|
||||
}
|
||||
#endif /* CH_CFG_USE_MEMCORE == TRUE */
|
||||
|
|
|
@ -109,7 +109,7 @@ static memory_heap_t default_heap;
|
|||
void __heap_init(void) {
|
||||
|
||||
default_heap.provider = chCoreAllocAlignedWithOffset;
|
||||
chCoreGetStatusX(&default_heap.region);
|
||||
chCoreGetStatusX(&default_heap.area);
|
||||
H_FREE_NEXT(&default_heap.header) = NULL;
|
||||
H_FREE_PAGES(&default_heap.header) = 0;
|
||||
#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
|
||||
|
@ -148,8 +148,8 @@ void chHeapObjectInit(memory_heap_t *heapp, void *buf, size_t size) {
|
|||
H_FREE_PAGES(&heapp->header) = 0;
|
||||
H_FREE_NEXT(hp) = NULL;
|
||||
H_FREE_PAGES(hp) = (size - sizeof (heap_header_t)) / CH_HEAP_ALIGNMENT;
|
||||
heapp->region.base = (uint8_t *)(void *)hp;
|
||||
heapp->region.size = H_FREE_FULLSIZE(hp);
|
||||
heapp->area.base = (uint8_t *)(void *)hp;
|
||||
heapp->area.size = H_FREE_FULLSIZE(hp);
|
||||
#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
|
||||
chMtxObjectInit(&heapp->mtx);
|
||||
#else
|
||||
|
@ -447,7 +447,7 @@ bool chHeapIntegrityCheck(memory_heap_t *heapp) {
|
|||
}
|
||||
|
||||
/* Validating the found free block.*/
|
||||
if (!chMemIsAreaWithinX(&heapp->region,
|
||||
if (!chMemIsAreaWithinX(&heapp->area,
|
||||
(void *)hp,
|
||||
H_FREE_FULLSIZE(hp))) {
|
||||
result = true;
|
||||
|
|
|
@ -74,7 +74,7 @@ typedef struct {
|
|||
/**
|
||||
* @brief Associated memory area.
|
||||
*/
|
||||
memory_region_t area;
|
||||
memory_area_t area;
|
||||
/**
|
||||
* @brief Writable memory range.
|
||||
*/
|
||||
|
|
|
@ -463,13 +463,13 @@ namespace chibios_rt {
|
|||
/**
|
||||
* @brief Core memory status.
|
||||
*
|
||||
* @param[in] mrp Memory region representing available core space.
|
||||
* @param[in] map Memory area representing available core space.
|
||||
*
|
||||
* @xclass
|
||||
*/
|
||||
static void getStatusX(memory_region_t *mrp) {
|
||||
static void getStatusX(memory_area_t *map) {
|
||||
|
||||
chCoreGetStatusX(mrp);
|
||||
chCoreGetStatusX(map);
|
||||
}
|
||||
};
|
||||
#endif /* CH_CFG_USE_MEMCORE == TRUE */
|
||||
|
|
|
@ -130,7 +130,7 @@ static void cmd_systime(BaseSequentialStream *chp, int argc, char *argv[]) {
|
|||
#if (SHELL_CMD_MEM_ENABLED == TRUE) || defined(__DOXYGEN__)
|
||||
static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
|
||||
size_t n, total, largest;
|
||||
memory_region_t region;
|
||||
memory_area_t area;
|
||||
|
||||
(void)argv;
|
||||
if (argc > 0) {
|
||||
|
@ -138,8 +138,8 @@ static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
|
|||
return;
|
||||
}
|
||||
n = chHeapStatus(NULL, &total, &largest);
|
||||
chCoreGetStatusX(®ion);
|
||||
chprintf(chp, "core free memory : %u bytes" SHELL_NEWLINE_STR, region.size);
|
||||
chCoreGetStatusX(&area);
|
||||
chprintf(chp, "core free memory : %u bytes" SHELL_NEWLINE_STR, area.size);
|
||||
chprintf(chp, "heap fragments : %u" SHELL_NEWLINE_STR, n);
|
||||
chprintf(chp, "heap free total : %u bytes" SHELL_NEWLINE_STR, total);
|
||||
chprintf(chp, "heap free largest: %u bytes" SHELL_NEWLINE_STR, largest);
|
||||
|
|
Loading…
Reference in New Issue