fix down alignment issue; fix the maximal number of rt_scheduler_lock_nest issue; fix rt_tick_from_millisecond issue.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@790 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
69466590ff
commit
214e44c3f9
@ -137,9 +137,14 @@ typedef rt_uint32_t rt_off_t; /* Type for offset. */
|
|||||||
/**
|
/**
|
||||||
* @def RT_ALIGN(size, align)
|
* @def RT_ALIGN(size, align)
|
||||||
* Return the most contiguous size aligned at specified width. RT_ALIGN(13, 4)
|
* Return the most contiguous size aligned at specified width. RT_ALIGN(13, 4)
|
||||||
* would equal to 16. It is needed in some critical contexts.
|
* would return 16.
|
||||||
|
*
|
||||||
|
* @def RT_ALIGN_DOWN(size, align)
|
||||||
|
* Return the down number of aligned at specified width. RT_ALIGN_DOWN(13, 4)
|
||||||
|
* would return 12.
|
||||||
*/
|
*/
|
||||||
#define RT_ALIGN(size, align) (((size) + (align) - 1) & ~((align)-1))
|
#define RT_ALIGN(size, align) (((size) + (align) - 1) & ~((align)-1))
|
||||||
|
#define RT_ALIGN_DOWN(size, align) ((size) & ~((align) -1))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def RT_NULL
|
* @def RT_NULL
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
* 2006-08-10 Bernard remove the last rt_schedule in rt_tick_increase
|
* 2006-08-10 Bernard remove the last rt_schedule in rt_tick_increase
|
||||||
* 2010-03-08 Bernard remove rt_passed_second
|
* 2010-03-08 Bernard remove rt_passed_second
|
||||||
* 2010-05-20 Bernard fix the tick exceeds the maximum limits
|
* 2010-05-20 Bernard fix the tick exceeds the maximum limits
|
||||||
|
* 2010-07-13 Bernard fix rt_tick_from_millisecond issue found by kuronca
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
@ -95,7 +96,7 @@ void rt_tick_increase()
|
|||||||
rt_tick_t rt_tick_from_millisecond(rt_uint32_t ms)
|
rt_tick_t rt_tick_from_millisecond(rt_uint32_t ms)
|
||||||
{
|
{
|
||||||
/* return the calculated tick */
|
/* return the calculated tick */
|
||||||
return RT_TICK_PER_SECOND * (ms / 1000);
|
return (RT_TICK_PER_SECOND * ms) / 1000 + (RT_TICK_PER_SECOND * ms) % 1000 ? 1:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
28
src/mem.c
28
src/mem.c
@ -12,6 +12,7 @@
|
|||||||
* 2008-7-12 Bernard the first version
|
* 2008-7-12 Bernard the first version
|
||||||
* 2010-06-09 Bernard fix the end stub of heap
|
* 2010-06-09 Bernard fix the end stub of heap
|
||||||
* fix memory check in rt_realloc function
|
* fix memory check in rt_realloc function
|
||||||
|
* 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -170,7 +171,7 @@ void rt_system_heap_init(void* begin_addr, void* end_addr)
|
|||||||
begin_addr = (void*)RT_ALIGN((rt_uint32_t)begin_addr, RT_ALIGN_SIZE);
|
begin_addr = (void*)RT_ALIGN((rt_uint32_t)begin_addr, RT_ALIGN_SIZE);
|
||||||
|
|
||||||
/* calculate the aligned memory size */
|
/* calculate the aligned memory size */
|
||||||
mem_size_aligned = RT_ALIGN((rt_uint32_t)end_addr - (rt_uint32_t)begin_addr, RT_ALIGN_SIZE) - 2 * SIZEOF_STRUCT_MEM;
|
mem_size_aligned = RT_ALIGN_DOWN((rt_uint32_t)end_addr - (rt_uint32_t)begin_addr, RT_ALIGN_SIZE) - 2 * SIZEOF_STRUCT_MEM;
|
||||||
|
|
||||||
/* point to begin address of heap */
|
/* point to begin address of heap */
|
||||||
heap_ptr = begin_addr;
|
heap_ptr = begin_addr;
|
||||||
@ -220,7 +221,10 @@ void *rt_malloc(rt_size_t size)
|
|||||||
if (size == 0) return RT_NULL;
|
if (size == 0) return RT_NULL;
|
||||||
|
|
||||||
#ifdef RT_MEM_DEBUG
|
#ifdef RT_MEM_DEBUG
|
||||||
rt_kprintf("malloc size %d, but align to %d\n", size, RT_ALIGN(size, RT_ALIGN_SIZE));
|
if (size != RT_ALIGN(size, RT_ALIGN_SIZE)
|
||||||
|
rt_kprintf("malloc size %d, but align to %d\n", size, RT_ALIGN(size, RT_ALIGN_SIZE));
|
||||||
|
else
|
||||||
|
rt_kprintf("malloc size %d\n", size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* alignment size */
|
/* alignment size */
|
||||||
@ -351,7 +355,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
|
|||||||
if (newsize > mem_size_aligned)
|
if (newsize > mem_size_aligned)
|
||||||
{
|
{
|
||||||
#ifdef RT_MEM_DEBUG
|
#ifdef RT_MEM_DEBUG
|
||||||
rt_kprintf("no memory\n");
|
rt_kprintf("realloc: out of memory\n");
|
||||||
#endif
|
#endif
|
||||||
return RT_NULL;
|
return RT_NULL;
|
||||||
}
|
}
|
||||||
@ -498,15 +502,15 @@ void rt_free(void *rmem)
|
|||||||
rt_sem_release(&heap_sem);
|
rt_sem_release(&heap_sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_MEM_STATS
|
#ifdef RT_MEM_STATS
|
||||||
void rt_memory_info(rt_uint32_t *total,
|
void rt_memory_info(rt_uint32_t *total,
|
||||||
rt_uint32_t *used,
|
rt_uint32_t *used,
|
||||||
rt_uint32_t *max_used)
|
rt_uint32_t *max_used)
|
||||||
{
|
{
|
||||||
if (total != RT_NULL) *total = mem_size_aligned;
|
if (total != RT_NULL) *total = mem_size_aligned;
|
||||||
if (used != RT_NULL) *used = used_mem;
|
if (used != RT_NULL) *used = used_mem;
|
||||||
if (max_used != RT_NULL) *max_used = max_mem;
|
if (max_used != RT_NULL) *max_used = max_mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_FINSH
|
#ifdef RT_USING_FINSH
|
||||||
#include <finsh.h>
|
#include <finsh.h>
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
* 2006-06-30 Bernard fix the allocate/free block bug
|
* 2006-06-30 Bernard fix the allocate/free block bug
|
||||||
* 2006-08-04 Bernard add hook support
|
* 2006-08-04 Bernard add hook support
|
||||||
* 2006-08-10 Bernard fix interrupt bug in rt_mp_alloc
|
* 2006-08-10 Bernard fix interrupt bug in rt_mp_alloc
|
||||||
|
* 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rthw.h>
|
#include <rthw.h>
|
||||||
@ -88,7 +89,7 @@ rt_err_t rt_mp_init(struct rt_mempool* mp, const char* name, void *start, rt_siz
|
|||||||
|
|
||||||
/* init memory pool */
|
/* init memory pool */
|
||||||
mp->start_address = start;
|
mp->start_address = start;
|
||||||
mp->size = RT_ALIGN(size, RT_ALIGN_SIZE);
|
mp->size = RT_ALIGN_DOWN(size, RT_ALIGN_SIZE);
|
||||||
|
|
||||||
mp->block_size = block_size;
|
mp->block_size = block_size;
|
||||||
|
|
||||||
@ -294,11 +295,11 @@ void *rt_mp_alloc (rt_mp_t mp, rt_int32_t time)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* memory block is unavailable. */
|
/* memory block is unavailable. */
|
||||||
if (time == 0)
|
if (time == 0)
|
||||||
{
|
{
|
||||||
/* enable interrupt */
|
/* enable interrupt */
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
return RT_NULL;
|
return RT_NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,9 @@
|
|||||||
* 2006-09-05 Bernard add 32 priority level support
|
* 2006-09-05 Bernard add 32 priority level support
|
||||||
* 2006-09-24 Bernard add rt_system_scheduler_start function
|
* 2006-09-24 Bernard add rt_system_scheduler_start function
|
||||||
* 2009-09-16 Bernard fix _rt_scheduler_stack_check
|
* 2009-09-16 Bernard fix _rt_scheduler_stack_check
|
||||||
* 2010-04-11 yi.qiu add module feature
|
* 2010-04-11 yi.qiu add module feature
|
||||||
|
* 2010-07-13 Bernard fix the maximal number of rt_scheduler_lock_nest
|
||||||
|
* issue found by kuronca
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
@ -396,8 +398,9 @@ void rt_enter_critical()
|
|||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
if (rt_scheduler_lock_nest < 255u)
|
/* the maximal number of nest is RT_UINT16_MAX, which is big
|
||||||
rt_scheduler_lock_nest++;
|
* enough and does not check here */
|
||||||
|
rt_scheduler_lock_nest++;
|
||||||
|
|
||||||
/* enable interrupt */
|
/* enable interrupt */
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2008-07-12 Bernard the first version
|
* 2008-07-12 Bernard the first version
|
||||||
|
* 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -326,7 +327,7 @@ void rt_system_heap_init(void *begin_addr, void* end_addr)
|
|||||||
|
|
||||||
/* align begin and end addr to page */
|
/* align begin and end addr to page */
|
||||||
heap_start = RT_ALIGN((rt_uint32_t)begin_addr, RT_MM_PAGE_SIZE);
|
heap_start = RT_ALIGN((rt_uint32_t)begin_addr, RT_MM_PAGE_SIZE);
|
||||||
heap_end = RT_ALIGN((rt_uint32_t)end_addr, RT_MM_PAGE_SIZE);
|
heap_end = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_MM_PAGE_SIZE);
|
||||||
|
|
||||||
limsize = heap_end - heap_start;
|
limsize = heap_end - heap_start;
|
||||||
npages = limsize / RT_MM_PAGE_SIZE;
|
npages = limsize / RT_MM_PAGE_SIZE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user