unify the coding style of kernel

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1998 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
dzzxzz committed 2012-03-17 06:43:49 +00:00
1 parent 3b06be1cde
commit 12b5e56f46
22 files changed
+341 -177

No files matched your search

+1 -3
View File
@@ -1,7 +1,7 @@
/*
* File : rtdebug.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -78,6 +78,4 @@
#endif /* RT_DEBUG */
#endif /* __RTDEBUG_H__ */
+32 -12
View File
@@ -1,7 +1,7 @@
/*
* File : rtdef.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -28,15 +28,16 @@ extern "C" {
/**
* @addtogroup BasicDef
*/
/*@{*/
/* RT-Thread version information */
#define RT_VERSION 1L /**< major version number */
#define RT_SUBVERSION 1L /**< minor version number */
#define RT_REVISION 0L /**< revise version number */
#define RT_REVISION 0L /**< revise version number */
/* RT-Thread version */
#define RTTHREAD_VERSION ((RT_VERSION * 10000) + \
#define RTTHREAD_VERSION ((RT_VERSION * 10000) + \
(RT_SUBVERSION * 100) + RT_REVISION)
/* RT-Thread basic data type definitions */
@@ -63,6 +64,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset
/* boolean type definitions */
#define RT_TRUE 1 /**< boolean true */
#define RT_FALSE 0 /**< boolean fails */
/*@}*/
/* maximum value of base type */
@@ -137,7 +139,9 @@ typedef rt_base_t rt_off_t; /**< Type for offset
/**
* @addtogroup Error
*/
/*@{*/
/* RT-Thread error code definitions */
#define RT_EOK 0 /**< There is no error */
#define RT_ERROR 1 /**< A generic error happens */
@@ -148,6 +152,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset
#define RT_ENOSYS 6 /**< No system */
#define RT_EBUSY 7 /**< Busy */
#define RT_EIO 8 /**< IO error */
/*@}*/
/**
@@ -158,6 +163,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset
* would return 16.
*/
#define RT_ALIGN(size, align) (((size) + (align) - 1) & ~((align) - 1))
/**
* @ingroup BasicDef
*
@@ -185,6 +191,7 @@ typedef struct rt_list_node rt_list_t; /* Type for lists. *
/**
* @addtogroup KernelObject
*/
/*@{*/
/*
@@ -280,6 +287,7 @@ struct rt_object_information
/**
* @addtogroup Clock
*/
/*@{*/
/**
@@ -314,11 +322,13 @@ struct rt_timer
rt_tick_t timeout_tick; /**< timeout tick */
};
typedef struct rt_timer *rt_timer_t;
/*@}*/
/**
* @addtogroup Thread
*/
/*@{*/
/*
@@ -338,16 +348,13 @@ typedef struct rt_timer *rt_timer_t;
/**
* thread control command definitions
*/
#define RT_THREAD_CTRL_STARTUP 0x00 /**< Startup thread. */
#define RT_THREAD_CTRL_STARTUP 0x00 /**< Startup thread. */
#define RT_THREAD_CTRL_CLOSE 0x01 /**< Close thread. */
#define RT_THREAD_CTRL_CHANGE_PRIORITY 0x02 /**< Change thread priority. */
#define RT_THREAD_CTRL_INFO 0x03 /**< Get thread information. */
typedef struct rt_thread *rt_thread_t;
/**
* Thread structure
*
*/
struct rt_thread
{
@@ -399,11 +406,14 @@ struct rt_thread
rt_uint32_t user_data; /**< private user data beyond this thread */
};
typedef struct rt_thread *rt_thread_t;
/*@}*/
/**
* @addtogroup IPC
*/
/*@{*/
/**
@@ -521,17 +531,21 @@ struct rt_messagequeue
};
typedef struct rt_messagequeue *rt_mq_t;
#endif
/*@}*/
#ifdef RT_USING_MEMPOOL
/**
* @addtogroup MM
*/
/*@{*/
/*
* memory management
* heap & partition
*/
#ifdef RT_USING_MEMPOOL
/**
* Base structure of Memory pool object
*/
@@ -552,13 +566,15 @@ struct rt_mempool
rt_size_t suspend_thread_count; /**< numbers of thread pended on this resource */
};
typedef struct rt_mempool *rt_mp_t;
#endif
/*@}*/
#endif
#ifdef RT_USING_DEVICE
/**
* @addtogroup Device
*/
/*@{*/
/**
@@ -689,6 +705,7 @@ enum
RTGRAPHIC_PIXEL_FORMAT_RGB888,
RTGRAPHIC_PIXEL_FORMAT_ARGB888
};
/**
* build a pixel position according to (x, y) coordinates.
*/
@@ -732,13 +749,17 @@ struct rt_device_graphic_ops
void (*blit_line) (const char *pixel, int x, int y, rt_size_t size);
};
#define rt_graphix_ops(device) ((struct rt_device_graphic_ops *)(device->user_data))
/*@}*/
/*@}*/
#endif
#ifdef RT_USING_MODULE
/**
* @addtogroup Module
*/
/*@{*/
#ifdef RT_USING_MODULE
/*
* module system
*/
@@ -774,7 +795,6 @@ struct rt_module
struct rt_object_information module_object[RT_Object_Class_Unknown];
};
typedef struct rt_module *rt_module_t;
#endif
/*@}*/
#endif
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* File : rthw.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
+1 -2
View File
@@ -1,7 +1,7 @@
/*
* File : rtm.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -22,7 +22,6 @@ const struct rt_module_symtab __rtmsym_##symbol SECTION("RTMSymTab")= \
(void *)&symbol, \
__rtmsym_##symbol##_name \
};
#else
#define RTM_EXPORT(symbol)
#endif
+29 -10
View File
@@ -1,7 +1,7 @@
/*
* File : rtthread.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -30,11 +30,12 @@ extern "C" {
/**
* @addtogroup KernelObject
*/
/*@{*/
/*
* kernel object interface
*/
void rt_system_object_init(void);
struct rt_object_information *rt_object_get_information(enum rt_object_class_type type);
void rt_object_init(struct rt_object *object, enum rt_object_class_type type, const char *name);
@@ -57,7 +58,9 @@ void rt_object_put_sethook(void (*hook)(struct rt_object *object));
/**
* @addtogroup Clock
*/
/*@{*/
/*
* clock & timer interface
*/
@@ -86,12 +89,15 @@ rt_err_t rt_timer_control(rt_timer_t timer, rt_uint8_t cmd, void *arg);
#ifdef RT_USING_HOOK
void rt_timer_timeout_sethook(void (*hook)(struct rt_timer *timer));
#endif
/*@}*/
/**
* @addtogroup Thread
*/
/*@{*/
/*
* thread interface
*/
@@ -142,12 +148,15 @@ void rt_exit_critical(void);
#ifdef RT_USING_HOOK
void rt_scheduler_sethook(void (*hook)(rt_thread_t from, rt_thread_t to));
#endif
/*@}*/
/**
* @addtogroup MM
*/
/*@{*/
/*
* memory management interface
*/
@@ -167,6 +176,7 @@ void rt_mp_free(void *block);
void rt_mp_alloc_sethook(void (*hook)(struct rt_mempool *mp, void *block));
void rt_mp_free_sethook(void (*hook)(struct rt_mempool *mp, void *block));
#endif
#endif
#ifdef RT_USING_HEAP
@@ -179,8 +189,8 @@ void *rt_malloc(rt_size_t nbytes);
void rt_free(void *ptr);
void *rt_realloc(void *ptr, rt_size_t nbytes);
void *rt_calloc(rt_size_t count, rt_size_t size);
void* rt_malloc_align(rt_size_t size, rt_size_t align);
void rt_free_align(void* ptr);
void *rt_malloc_align(rt_size_t size, rt_size_t align);
void rt_free_align(void *ptr);
void rt_memory_info(rt_uint32_t *total, rt_uint32_t *used, rt_uint32_t *max_used);
@@ -195,12 +205,15 @@ void rt_free_sethook(void (*hook)(void *ptr));
#endif
#endif
/*@}*/
/**
* @addtogroup IPC
*/
/*@{*/
#ifdef RT_USING_SEMAPHORE
/*
* semaphore interface
@@ -247,7 +260,6 @@ rt_err_t rt_event_control(rt_event_t event, rt_uint8_t cmd, void *arg);
#ifdef RT_USING_MAILBOX
/*
* mailbox interface
*
*/
rt_err_t rt_mb_init(rt_mailbox_t mb, const char *name, void *msgpool, rt_size_t size, rt_uint8_t flag);
rt_err_t rt_mb_detach(rt_mailbox_t mb);
@@ -274,17 +286,19 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, void *buffer, rt_size_t size);
rt_err_t rt_mq_recv(rt_mq_t mq, void *buffer, rt_size_t size, rt_int32_t timeout);
rt_err_t rt_mq_control(rt_mq_t mq, rt_uint8_t cmd, void *arg);
#endif
/*@}*/
#ifdef RT_USING_DEVICE
/**
* @addtogroup Device
*/
/*@{*/
/*
* device (I/O) system interface
*/
rt_device_t rt_device_find(const char *name);
rt_err_t rt_device_register(rt_device_t dev, const char *name, rt_uint16_t flags);
@@ -300,6 +314,7 @@ rt_err_t rt_device_close(rt_device_t dev);
rt_size_t rt_device_read (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
rt_size_t rt_device_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
rt_err_t rt_device_control(rt_device_t dev, rt_uint8_t cmd, void *arg);
/*@}*/
#endif
@@ -307,11 +322,12 @@ rt_err_t rt_device_control(rt_device_t dev, rt_uint8_t cmd, void *arg);
/**
* @addtogroup Module
*/
/*@{*/
/*
* module interface
*/
rt_module_t rt_module_load(const char *name, void *module_ptr);
rt_err_t rt_module_unload(rt_module_t module);
rt_module_t rt_module_open(const char *filename);
@@ -327,8 +343,8 @@ void rt_module_load_sethook(void (*hook)(rt_module_t module));
void rt_module_unload_sethook(void (*hook)(rt_module_t module));
#endif
#endif
/*@}*/
#endif
/*
* interrupt service
@@ -340,6 +356,7 @@ typedef void (*rt_isr_handler_t)(int vector);
*/
void rt_interrupt_enter(void);
void rt_interrupt_leave(void);
/*
* the number of nested interrupts.
*/
@@ -348,10 +365,13 @@ rt_uint8_t rt_interrupt_get_nest(void);
/**
* @addtogroup KernelService
*/
/*@{*/
/*
* general kernel service
*/
void rt_kprintf(const char *fmt, ...);
rt_int32_t rt_sprintf(char *buf ,const char *format, ...);
rt_int32_t rt_vsprintf(char *dest, const char *format, va_list arg_ptr);
rt_int32_t rt_sprintf(char *buf ,const char *format, ...);
@@ -360,7 +380,6 @@ rt_int32_t rt_snprintf(char *buf, rt_size_t size, const char *format, ...);
#ifdef RT_USING_DEVICE
rt_device_t rt_console_set_device(const char *name);
#endif
void rt_kprintf(const char *fmt, ...);
rt_err_t rt_get_errno(void);
void rt_set_errno(rt_err_t no);
@@ -393,5 +412,5 @@ void rt_show_version(void);
#ifdef __cplusplus
}
#endif
/*@}*/
#endif
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* File : clock.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
+11 -4
View File
@@ -1,7 +1,7 @@
/*
* File : device.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -29,7 +29,8 @@
*/
rt_err_t rt_device_register(rt_device_t dev, const char *name, rt_uint16_t flags)
{
if (dev == RT_NULL) return -RT_ERROR;
if (dev == RT_NULL)
return -RT_ERROR;
rt_object_init(&(dev->parent), RT_Object_Class_Device, name);
dev->flag = flags;
@@ -155,7 +156,7 @@ rt_err_t rt_device_init(rt_device_t dev)
init = dev->init;
if (init != RT_NULL)
{
if(!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
{
result = init(dev);
if (result != RT_EOK)
@@ -169,7 +170,8 @@ rt_err_t rt_device_init(rt_device_t dev)
}
}
}
else result = -RT_ENOSYS;
else
result = -RT_ENOSYS;
return result;
}
@@ -199,6 +201,7 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
{
rt_kprintf("To initialize device:%s failed. The error code is %d\n",
dev->parent.name, result);
return result;
}
else
@@ -290,6 +293,7 @@ rt_size_t rt_device_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t
/* set error code */
rt_set_errno(-RT_ENOSYS);
return 0;
}
@@ -320,6 +324,7 @@ rt_size_t rt_device_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_
/* set error code */
rt_set_errno(-RT_ENOSYS);
return 0;
}
@@ -362,6 +367,7 @@ rt_err_t rt_device_set_rx_indicate(rt_device_t dev, rt_err_t (*rx_ind)(rt_device
RT_ASSERT(dev != RT_NULL);
dev->rx_indicate = rx_ind;
return RT_EOK;
}
@@ -379,6 +385,7 @@ rt_err_t rt_device_set_tx_complete(rt_device_t dev, rt_err_t (*tx_done)(rt_devic
RT_ASSERT(dev != RT_NULL);
dev->tx_complete = tx_done;
return RT_EOK;
}
+7 -3
View File
@@ -1,7 +1,7 @@
/*
* File : idle.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -35,6 +35,7 @@ extern rt_list_t rt_thread_defunct;
/**
* @addtogroup Hook
*/
/*@{*/
static void (*rt_thread_idle_hook)();
@@ -50,6 +51,7 @@ void rt_thread_idle_sethook(void (*hook)())
{
rt_thread_idle_hook = hook;
}
/*@}*/
#endif
@@ -92,7 +94,8 @@ void rt_thread_idle_excute(void)
/* remove defunct thread */
rt_list_remove(&(thread->tlist));
/* invoke thread cleanup */
if (thread->cleanup != RT_NULL) thread->cleanup(thread);
if (thread->cleanup != RT_NULL)
thread->cleanup(thread);
/* if it's a system object, not delete it */
if (rt_object_is_systemobject((rt_object_t)thread) == RT_EOK)
@@ -139,7 +142,8 @@ void rt_thread_idle_excute(void)
}
/* unload module */
if (module->nref == 0) rt_module_unload(module);
if (module->nref == 0)
rt_module_unload(module);
#endif
}
}
+17 -3
View File
@@ -1,7 +1,7 @@
/*
* File : ipc.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -333,6 +333,7 @@ rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time)
if (time == 0 )
{
rt_hw_interrupt_enable(temp);
return -RT_ETIMEOUT;
}
else
@@ -423,7 +424,8 @@ rt_err_t rt_sem_release(rt_sem_t sem)
rt_ipc_list_resume(&(sem->parent.suspend_thread));
need_schedule = RT_TRUE;
}
else sem->value ++; /* increase value */
else
sem->value ++; /* increase value */
/* enable interrupt */
rt_hw_interrupt_enable(temp);
@@ -1337,6 +1339,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, rt_uint32_t value, rt_int32_t timeout)
if (mb->entry == mb->size && timeout == 0)
{
rt_hw_interrupt_enable(temp);
return -RT_EFULL;
}
@@ -1351,6 +1354,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, rt_uint32_t value, rt_int32_t timeout)
{
/* enable interrupt */
rt_hw_interrupt_enable(temp);
return -RT_EFULL;
}
@@ -1416,6 +1420,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, rt_uint32_t value, rt_int32_t timeout)
rt_hw_interrupt_enable(temp);
rt_schedule();
return RT_EOK;
}
@@ -1473,6 +1478,7 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_uint32_t *value, rt_int32_t timeout)
if (mb->entry == 0 && timeout == 0)
{
rt_hw_interrupt_enable(temp);
return -RT_ETIMEOUT;
}
@@ -1489,6 +1495,7 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_uint32_t *value, rt_int32_t timeout)
rt_hw_interrupt_enable(temp);
thread->error = -RT_ETIMEOUT;
return -RT_ETIMEOUT;
}
@@ -1734,6 +1741,7 @@ rt_mq_t rt_mq_create(const char *name, rt_size_t msg_size, rt_size_t max_msgs, r
if (mq->msg_pool == RT_NULL)
{
rt_mq_delete(mq);
return RT_NULL;
}
@@ -1852,7 +1860,8 @@ rt_err_t rt_mq_send(rt_mq_t mq, void *buffer, rt_size_t size)
/* set new tail */
mq->msg_queue_tail = msg;
/* if the head is empty, set head */
if (mq->msg_queue_head == RT_NULL)mq->msg_queue_head = msg;
if (mq->msg_queue_head == RT_NULL)
mq->msg_queue_head = msg;
/* increase message entry */
mq->entry ++;
@@ -1866,6 +1875,7 @@ rt_err_t rt_mq_send(rt_mq_t mq, void *buffer, rt_size_t size)
rt_hw_interrupt_enable(temp);
rt_schedule();
return RT_EOK;
}
@@ -1946,6 +1956,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, void *buffer, rt_size_t size)
rt_hw_interrupt_enable(temp);
rt_schedule();
return RT_EOK;
}
@@ -1990,6 +2001,7 @@ rt_err_t rt_mq_recv(rt_mq_t mq, void *buffer, rt_size_t size, rt_int32_t timeout
if (mq->entry == 0 && timeout == 0)
{
rt_hw_interrupt_enable(temp);
return -RT_ETIMEOUT;
}
@@ -2008,6 +2020,7 @@ rt_err_t rt_mq_recv(rt_mq_t mq, void *buffer, rt_size_t size, rt_int32_t timeout
rt_hw_interrupt_enable(temp);
thread->error = -RT_ETIMEOUT;
return -RT_ETIMEOUT;
}
@@ -2137,4 +2150,5 @@ rt_err_t rt_mq_control(rt_mq_t mq, rt_uint8_t cmd, void *arg)
return -RT_ERROR;
}
#endif /* end of RT_USING_MESSAGEQUEUE */
/*@}*/
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* File : irq.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
+54 -29
View File
File diff suppressed because it is too large. Load diff
+2 -1
View File
@@ -1,7 +1,7 @@
/*
* File : kservice.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -26,6 +26,7 @@ extern "C" {
/**
* @addtogroup KernelService
*/
/*@{*/
/**
+22 -9
View File
@@ -1,7 +1,7 @@
/*
* File : mem.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -63,6 +63,7 @@ static void (*rt_free_hook)(void *ptr);
/**
* @addtogroup Hook
*/
/*@{*/
/**
@@ -163,7 +164,6 @@ static void plug_holes(struct heap_mem *mem)
*
* @param begin_addr the beginning address of system page
* @param end_addr the end address of system page
*
*/
void rt_system_heap_init(void *begin_addr, void *end_addr)
{
@@ -183,6 +183,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
else
{
rt_kprintf("mem init, error begin address 0x%x, and end address 0x%x\n", (rt_uint32_t)begin_addr, (rt_uint32_t)end_addr);
return;
}
@@ -232,7 +233,8 @@ void *rt_malloc(rt_size_t size)
RT_DEBUG_NOT_IN_INTERRUPT;
if (size == 0) return RT_NULL;
if (size == 0)
return RT_NULL;
if (size != RT_ALIGN(size, RT_ALIGN_SIZE))
RT_DEBUG_LOG(RT_DEBUG_MEM, ("malloc size %d, but align to %d\n", size, RT_ALIGN(size, RT_ALIGN_SIZE)));
@@ -250,7 +252,8 @@ void *rt_malloc(rt_size_t size)
}
/* every data block must be at least MIN_SIZE_ALIGNED long */
if (size < MIN_SIZE_ALIGNED) size = MIN_SIZE_ALIGNED;
if (size < MIN_SIZE_ALIGNED)
size = MIN_SIZE_ALIGNED;
/* take memory semaphore */
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
@@ -295,7 +298,8 @@ void *rt_malloc(rt_size_t size)
}
#ifdef RT_MEM_STATS
used_mem += (size + SIZEOF_STRUCT_MEM);
if (max_mem < used_mem) max_mem = used_mem;
if (max_mem < used_mem)
max_mem = used_mem;
#endif
}
else
@@ -310,7 +314,8 @@ void *rt_malloc(rt_size_t size)
mem->used = 1;
#ifdef RT_MEM_STATS
used_mem += mem->next - ((rt_uint8_t*)mem - heap_ptr);
if (max_mem < used_mem) max_mem = used_mem;
if (max_mem < used_mem)
max_mem = used_mem;
#endif
}
/* set memory block magic */
@@ -319,7 +324,8 @@ void *rt_malloc(rt_size_t size)
if (mem == lfree)
{
/* Find next free block after mem and update lowest free pointer */
while (lfree->used && lfree != heap_end) lfree = (struct heap_mem *)&heap_ptr[lfree->next];
while (lfree->used && lfree != heap_end)
lfree = (struct heap_mem *)&heap_ptr[lfree->next];
RT_ASSERT(((lfree == heap_end) || (!lfree->used)));
}
@@ -334,12 +340,14 @@ void *rt_malloc(rt_size_t size)
(rt_uint32_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
RT_OBJECT_HOOK_CALL(rt_malloc_hook, (((void*)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM)), size));
/* return the memory data except mem struct */
return (rt_uint8_t *)mem + SIZEOF_STRUCT_MEM;
}
}
rt_sem_release(&heap_sem);
return RT_NULL;
}
@@ -380,6 +388,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
{
/* illegal memory */
rt_sem_release(&heap_sem);
return rmem;
}
@@ -391,6 +400,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
{
/* the size is the same as */
rt_sem_release(&heap_sem);
return rmem;
}
@@ -416,6 +426,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
plug_holes(mem2);
rt_sem_release(&heap_sem);
return rmem;
}
rt_sem_release(&heap_sem);
@@ -453,7 +464,8 @@ void *rt_calloc(rt_size_t count, rt_size_t size)
p = rt_malloc(count * size);
/* zero the memory */
if (p) rt_memset(p, 0, count * size);
if (p)
rt_memset(p, 0, count * size);
return p;
}
@@ -470,7 +482,8 @@ void rt_free(void *rmem)
RT_DEBUG_NOT_IN_INTERRUPT;
if (rmem == RT_NULL) return;
if (rmem == RT_NULL)
return;
RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE-1)) == 0);
RT_ASSERT((rt_uint8_t *)rmem >= (rt_uint8_t *)heap_ptr &&
(rt_uint8_t *)rmem < (rt_uint8_t *)heap_end);
+8 -10
View File
@@ -1,7 +1,7 @@
/*
* File : mempool.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -33,6 +33,7 @@ static void (*rt_mp_free_hook)(struct rt_mempool *mp, void *block);
/**
* @addtogroup Hook
*/
/*@{*/
/**
@@ -77,7 +78,6 @@ void rt_mp_free_sethook(void (*hook)(struct rt_mempool *mp, void *block))
* @param block_size the size for each block
*
* @return RT_EOK
*
*/
rt_err_t rt_mp_init(struct rt_mempool *mp, const char *name, void *start, rt_size_t size, rt_size_t block_size)
{
@@ -174,7 +174,6 @@ rt_err_t rt_mp_detach(struct rt_mempool *mp)
* @param block_size the size for each block
*
* @return the created mempool object
*
*/
rt_mp_t rt_mp_create(const char *name, rt_size_t block_count, rt_size_t block_size)
{
@@ -186,7 +185,8 @@ rt_mp_t rt_mp_create(const char *name, rt_size_t block_count, rt_size_t block_si
/* allocate object */
mp = (struct rt_mempool *)rt_object_allocate(RT_Object_Class_MemPool, name);
if (mp == RT_NULL) return RT_NULL; /* allocate object failed */
if (mp == RT_NULL)
return RT_NULL; /* allocate object failed */
/* init memory pool */
mp->block_size = RT_ALIGN(block_size, RT_ALIGN_SIZE);
@@ -230,7 +230,6 @@ rt_mp_t rt_mp_create(const char *name, rt_size_t block_count, rt_size_t block_si
* @param mp the memory pool object
*
* @return RT_EOK
*
*/
rt_err_t rt_mp_delete(rt_mp_t mp)
{
@@ -291,7 +290,6 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
* @param time the waiting time
*
* @return the allocated memory block or RT_NULL on allocated failed
*
*/
void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
{
@@ -348,7 +346,8 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
/* do a schedule */
rt_schedule();
if (thread->error != RT_EOK) return RT_NULL;
if (thread->error != RT_EOK)
return RT_NULL;
/* disable interrupt */
level = rt_hw_interrupt_disable();
@@ -377,7 +376,6 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
* This function will release a memory block
*
* @param block the address of memory block to be released
*
*/
void rt_mp_free(void *block)
{
@@ -429,7 +427,7 @@ void rt_mp_free(void *block)
rt_hw_interrupt_enable(level);
}
#endif
/*@}*/
#endif
+67 -33
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* File : module.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
+6 -2
View File
@@ -1,7 +1,7 @@
/*
* File : object.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -74,6 +74,7 @@ void (*rt_object_put_hook)(struct rt_object *object);
/**
* @addtogroup Hook
*/
/*@{*/
/**
@@ -164,6 +165,7 @@ void rt_system_object_init(void)
/**
* @addtogroup KernelObject
*/
/*@{*/
/**
@@ -359,7 +361,8 @@ rt_err_t rt_object_is_systemobject(rt_object_t object)
/* object check */
RT_ASSERT(object != RT_NULL);
if (object->type & RT_Object_Class_Static) return RT_EOK;
if (object->type & RT_Object_Class_Static)
return RT_EOK;
return -RT_ERROR;
}
@@ -413,4 +416,5 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
return RT_NULL;
}
/*@}*/
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* File : rtm.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
+3 -2
View File
@@ -1,7 +1,7 @@
/*
* File : scheduler.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -76,6 +76,7 @@ static void (*rt_scheduler_hook)(struct rt_thread *from, struct rt_thread *to);
/**
* @addtogroup Hook
*/
/*@{*/
/**
@@ -123,7 +124,6 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread)
/**
* @ingroup SystemInit
* This function will initialize the system scheduler
*
*/
void rt_system_scheduler_init(void)
{
@@ -208,6 +208,7 @@ void rt_system_scheduler_start(void)
/**
* @addtogroup Thread
*/
/*@{*/
/**
+61 -24
View File
File diff suppressed because it is too large. Load diff
+4 -13
View File
@@ -1,7 +1,7 @@
/*
* File : thread.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -142,7 +142,6 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
* @param tick the time slice if there are same priority thread
*
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
rt_err_t rt_thread_init(struct rt_thread *thread,
const char *name,
@@ -166,7 +165,6 @@ rt_err_t rt_thread_init(struct rt_thread *thread,
* This function will return self thread object
*
* @return the self thread object
*
*/
rt_thread_t rt_thread_self(void)
{
@@ -179,7 +177,6 @@ rt_thread_t rt_thread_self(void)
* @param thread the thread to be started
*
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
rt_err_t rt_thread_startup(rt_thread_t thread)
{
@@ -221,7 +218,6 @@ rt_err_t rt_thread_startup(rt_thread_t thread)
* @param thread the thread to be deleted
*
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
rt_err_t rt_thread_detach(rt_thread_t thread)
{
@@ -270,7 +266,6 @@ rt_err_t rt_thread_detach(rt_thread_t thread)
* @param tick the time slice if there are same priority thread
*
* @return the created thread object
*
*/
rt_thread_t rt_thread_create(const char *name,
void (*entry)(void *parameter), void *parameter,
@@ -282,13 +277,15 @@ rt_thread_t rt_thread_create(const char *name,
void *stack_start;
thread = (struct rt_thread *)rt_object_allocate(RT_Object_Class_Thread, name);
if (thread == RT_NULL) return RT_NULL;
if (thread == RT_NULL)
return RT_NULL;
stack_start = (void *)rt_malloc(stack_size);
if (stack_start == RT_NULL)
{
/* allocate stack failure */
rt_object_delete((rt_object_t)thread);
return RT_NULL;
}
@@ -306,7 +303,6 @@ rt_thread_t rt_thread_create(const char *name,
* @param thread the thread to be deleted
*
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
rt_err_t rt_thread_delete(rt_thread_t thread)
{
@@ -343,7 +339,6 @@ rt_err_t rt_thread_delete(rt_thread_t thread)
* is still in READY state.
*
* @return RT_EOK
*
*/
rt_err_t rt_thread_yield(void)
{
@@ -386,7 +381,6 @@ rt_err_t rt_thread_yield(void)
* @param tick the sleep ticks
*
* @return RT_EOK
*
*/
rt_err_t rt_thread_sleep(rt_tick_t tick)
{
@@ -424,7 +418,6 @@ rt_err_t rt_thread_sleep(rt_tick_t tick)
* @param tick the delay ticks
*
* @return RT_EOK
*
*/
rt_err_t rt_thread_delay(rt_tick_t tick)
{
@@ -556,7 +549,6 @@ rt_err_t rt_thread_suspend(rt_thread_t thread)
* @param thread the thread to be resumed
*
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
rt_err_t rt_thread_resume(rt_thread_t thread)
{
@@ -601,7 +593,6 @@ rt_err_t rt_thread_resume(rt_thread_t thread)
* when thread is timeout to wait some resource.
*
* @param parameter the parameter of thread timeout function
*
*/
void rt_thread_timeout(void *parameter)
{
+11 -12
View File
@@ -1,7 +1,7 @@
/*
* File : timer.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -40,6 +40,7 @@ static void (*rt_timer_timeout_hook)(struct rt_timer *timer);
/**
* @addtogroup Hook
*/
/*@{*/
/**
@@ -79,6 +80,7 @@ static void _rt_timer_init(rt_timer_t timer,
/**
* @addtogroup Clock
*/
/*@{*/
/**
@@ -168,7 +170,6 @@ rt_timer_t rt_timer_create(const char *name, void (*timeout)(void *parameter), v
* @param timer the timer to be deleted
*
* @return the operation status, RT_EOK on OK; RT_ERROR on error
*
*/
rt_err_t rt_timer_delete(rt_timer_t timer)
{
@@ -198,7 +199,6 @@ rt_err_t rt_timer_delete(rt_timer_t timer)
* @param timer the timer to be started
*
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
rt_err_t rt_timer_start(rt_timer_t timer)
{
@@ -208,7 +208,8 @@ rt_err_t rt_timer_start(rt_timer_t timer)
/* timer check */
RT_ASSERT(timer != RT_NULL);
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED) return -RT_ERROR;
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
return -RT_ERROR;
RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(timer->parent)));
@@ -265,7 +266,6 @@ rt_err_t rt_timer_start(rt_timer_t timer)
* @param timer the timer to be stopped
*
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
rt_err_t rt_timer_stop(rt_timer_t timer)
{
@@ -273,7 +273,8 @@ rt_err_t rt_timer_stop(rt_timer_t timer)
/* timer check */
RT_ASSERT(timer != RT_NULL);
if (!(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)) return -RT_ERROR;
if (!(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED))
return -RT_ERROR;
RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(timer->parent)));
@@ -300,7 +301,6 @@ rt_err_t rt_timer_stop(rt_timer_t timer)
* @param arg the argument
*
* @return RT_EOK
*
*/
rt_err_t rt_timer_control(rt_timer_t timer, rt_uint8_t cmd, void *arg)
{
@@ -386,7 +386,8 @@ void rt_timer_check(void)
t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
}
}
else break;
else
break;
}
/* enable interrupt */
@@ -421,7 +422,6 @@ void rt_soft_timer_tick_increase(void)
/**
* This function will check timer list, if a timeout event happens, the
* corresponding timeout function will be invoked.
*
*/
void rt_soft_timer_check(void)
{
@@ -471,7 +471,8 @@ void rt_soft_timer_check(void)
t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
}
}
else break; /* not check anymore */
else
break; /* not check anymore */
}
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n"));
@@ -501,7 +502,6 @@ static void rt_thread_timer_entry(void *parameter)
* @ingroup SystemInit
*
* This function will initialize system timer
*
*/
void rt_system_timer_init(void)
{
@@ -517,7 +517,6 @@ void rt_system_timer_init(void)
* @ingroup SystemInit
*
* This function will initialize system timer thread
*
*/
void rt_system_timer_thread_init(void)
{