提交 12b5e56f 编写于 作者: D dzzxzz

unify the coding style of kernel

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1998 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 3b06be1c
/*
* 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__ */
/*
* 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
......
/*
* 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
......
/*
* 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
......
/*
* 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
/*
* 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
......
/*
* 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;
}
......
/*
* 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
}
}
......
/*
* 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 */
/*@}*/
/*
* 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
......
/*
* File : kservice.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
......@@ -23,6 +23,7 @@
/**
* @addtogroup KernelService
*/
/*@{*/
/* global errno in RT-Thread */
......@@ -48,7 +49,8 @@ rt_err_t rt_get_errno(void)
}
tid = rt_thread_self();
if (tid == RT_NULL) return _errno;
if (tid == RT_NULL)
return _errno;
return tid->error;
}
......@@ -66,11 +68,17 @@ void rt_set_errno(rt_err_t error)
{
/* it's in interrupt context */
_errno = error;
return;
}
tid = rt_thread_self();
if (tid == RT_NULL) { _errno = error; return; }
if (tid == RT_NULL)
{
_errno = error;
return;
}
tid->error = error;
}
......@@ -84,10 +92,12 @@ int *_rt_errno(void)
{
rt_thread_t tid;
if (rt_interrupt_get_nest() != 0) return (int *)&_errno;
if (rt_interrupt_get_nest() != 0)
return (int *)&_errno;
tid = rt_thread_self();
if (tid != RT_NULL) return (int *)&(tid->error);
if (tid != RT_NULL)
return (int *)&(tid->error);
return (int *)&_errno;
}
......@@ -100,7 +110,6 @@ int *_rt_errno(void)
* @param count the copied length
*
* @return the address of source memory
*
*/
void *rt_memset(void *s, int c, rt_ubase_t count)
{
......@@ -148,7 +157,7 @@ void *rt_memset(void *s, int c, rt_ubase_t count)
*aligned_addr++ = buffer;
*aligned_addr++ = buffer;
*aligned_addr++ = buffer;
count -= 4*LBLOCKSIZE;
count -= 4 * LBLOCKSIZE;
}
while (count >= LBLOCKSIZE)
......@@ -183,7 +192,6 @@ void *rt_memset(void *s, int c, rt_ubase_t count)
* @param count the copied length
*
* @return the address of destination memory
*
*/
void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
{
......@@ -257,7 +265,6 @@ void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
* @param n the copied length
*
* @return the address of destination memory
*
*/
void *rt_memmove(void *dest, const void *src, rt_ubase_t n)
{
......@@ -297,6 +304,7 @@ rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_ubase_t count)
for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
if ((res = *su1 - *su2) != 0)
break;
return res;
}
......@@ -323,6 +331,7 @@ char *rt_strstr(const char *s1, const char *s2)
return (char *)s1;
s1 ++;
}
return RT_NULL;
}
......@@ -379,6 +388,7 @@ char *rt_strncpy(char *dst, const char *src, rt_ubase_t n)
}
} while (--n != 0);
}
return (dst);
}
......@@ -417,6 +427,7 @@ rt_ubase_t rt_strcmp(const char *cs, const char *ct)
{
while (*cs && *cs == *ct)
cs++, ct++;
return (*cs - *ct);
}
......@@ -451,9 +462,11 @@ char *rt_strdup(const char *s)
rt_size_t len = rt_strlen(s) + 1;
char *tmp = (char *)rt_malloc(len);
if (!tmp) return RT_NULL;
if (!tmp)
return RT_NULL;
rt_memcpy(tmp, s, len);
return tmp;
}
#endif
......@@ -466,7 +479,7 @@ void rt_show_version(void)
rt_kprintf("\n \\ | /\n");
rt_kprintf("- RT - Thread Operating System\n");
rt_kprintf(" / | \\ %d.%d.%d build %s\n", RT_VERSION, RT_SUBVERSION, RT_REVISION, __DATE__);
rt_kprintf(" 2006 - 2011 Copyright by rt-thread team\n");
rt_kprintf(" 2006 - 2012 Copyright by rt-thread team\n");
}
/* private function */
......@@ -494,7 +507,8 @@ rt_inline rt_int32_t divide(rt_int32_t *n, rt_int32_t base)
rt_inline int skip_atoi(const char **s)
{
register int i=0;
while (isdigit(**s)) i = i*10 + *((*s)++) - '0';
while (isdigit(**s))
i = i * 10 + *((*s)++) - '0';
return i;
}
......@@ -528,7 +542,8 @@ static char *print_number(char *buf, char *end, long num, int base, int s, int t
size = s;
digits = (type & LARGE) ? large_digits : small_digits;
if (type & LEFT) type &= ~ZEROPAD;
if (type & LEFT)
type &= ~ZEROPAD;
c = (type & ZEROPAD) ? '0' : ' ';
......@@ -554,14 +569,17 @@ static char *print_number(char *buf, char *end, long num, int base, int s, int t
#endif
i = 0;
if (num == 0) tmp[i++]='0';
if (num == 0)
tmp[i++]='0';
else
{
while (num != 0) tmp[i++] = digits[divide(&num, base)];
while (num != 0)
tmp[i++] = digits[divide(&num, base)];
}
#ifdef RT_PRINTF_PRECISION
if (i > precision) precision = i;
if (i > precision)
precision = i;
size -= precision;
#else
size -= i;
......@@ -571,7 +589,8 @@ static char *print_number(char *buf, char *end, long num, int base, int s, int t
{
while (size-->0)
{
if (buf <= end) *buf = ' ';
if (buf <= end)
*buf = ' ';
++ buf;
}
}
......@@ -591,12 +610,14 @@ static char *print_number(char *buf, char *end, long num, int base, int s, int t
{
if (base==8)
{
if (buf <= end) *buf = '0';
if (buf <= end)
*buf = '0';
++ buf;
}
else if (base == 16)
{
if (buf <= end) *buf = '0';
if (buf <= end)
*buf = '0';
++ buf;
if (buf <= end)
{
......@@ -612,7 +633,8 @@ static char *print_number(char *buf, char *end, long num, int base, int s, int t
{
while (size-- > 0)
{
if (buf <= end) *buf = c;
if (buf <= end)
*buf = c;
++ buf;
}
}
......@@ -620,7 +642,8 @@ static char *print_number(char *buf, char *end, long num, int base, int s, int t
#ifdef RT_PRINTF_PRECISION
while (i < precision--)
{
if (buf <= end) *buf = '0';
if (buf <= end)
*buf = '0';
++ buf;
}
#endif
......@@ -628,13 +651,15 @@ static char *print_number(char *buf, char *end, long num, int base, int s, int t
/* put number in the temporary buffer */
while (i-- > 0)
{
if (buf <= end) *buf = tmp[i];
if (buf <= end)
*buf = tmp[i];
++ buf;
}
while (size-- > 0)
{
if (buf <= end) *buf = ' ';
if (buf <= end)
*buf = ' ';
++ buf;
}
......@@ -655,7 +680,7 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list
rt_uint8_t base; /* the base of number */
rt_uint8_t flags; /* flags to print number */
rt_uint8_t qualifier; /* 'h', 'l', or 'L' for integer fields */
rt_int32_t field_width; /* width of output field */
rt_int32_t field_width; /* width of output field */
#ifdef RT_PRINTF_PRECISION
int precision; /* min. # of digits for integers and max for a string */
......@@ -675,7 +700,8 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list
{
if (*fmt != '%')
{
if (str <= end) *str = *fmt;
if (str <= end)
*str = *fmt;
++ str;
continue;
}
......@@ -893,7 +919,7 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list
/* the trailing null byte doesn't count towards the total
* ++str;
*/
return str-buf;
return str - buf;
}
/**
......@@ -1015,7 +1041,6 @@ void rt_hw_console_output(const char *str)
*/
void rt_kprintf(const char *fmt, ...)
{
va_list args;
rt_size_t length;
static char rt_log_buf[RT_CONSOLEBUF_SIZE];
......@@ -1091,9 +1116,9 @@ void* rt_malloc_align(rt_size_t size, rt_size_t align)
*
* @param ptr the memory block pointer
*/
void rt_free_align(void* ptr)
void rt_free_align(void *ptr)
{
void* real_ptr;
void *real_ptr;
real_ptr = (void*)*(rt_uint32_t*)((rt_uint32_t)ptr - sizeof(void*));
rt_free(real_ptr);
......
/*
* 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
*/
/*@{*/
/**
......
/*
* 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);
......
/*
* 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
/*
* 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
......@@ -91,7 +91,6 @@ static char *_strip_name(const char *string)
* @ingroup SystemInit
*
* This function will initialize system module
*
*/
void rt_system_module_init(void)
{
......@@ -135,7 +134,6 @@ static rt_uint32_t rt_module_symbol_find(const char *sym_str)
* This function will return self module object
*
* @return the self module object
*
*/
rt_module_t rt_module_self(void)
{
......@@ -230,6 +228,7 @@ static int rt_module_arm_relocate(struct rt_module *module, Elf32_Rel *rel, Elf3
offset >= (rt_int32_t)0x01000000)
{
rt_kprintf("only Thumb addresses allowed\n");
return -1;
}
......@@ -322,6 +321,7 @@ static void (*rt_module_unload_hook)(rt_module_t module);
/**
* @addtogroup Hook
*/
/*@{*/
/**
......@@ -349,7 +349,7 @@ void rt_module_unload_sethook(void (*hook)(rt_module_t module))
/*@}*/
#endif
static struct rt_module* _load_shared_object(const char* name, void* module_ptr)
static struct rt_module* _load_shared_object(const char *name, void *module_ptr)
{
rt_uint8_t *ptr = RT_NULL;
rt_module_t module = RT_NULL;
......@@ -374,18 +374,21 @@ static struct rt_module* _load_shared_object(const char* name, void* module_ptr)
if (module_size == 0)
{
rt_kprintf(" module size error\n");
return module;
}
/* allocate module */
module = (struct rt_module *)rt_object_allocate(RT_Object_Class_Module, name);
if (!module) return RT_NULL;
if (!module)
return RT_NULL;
/* allocate module space */
module->module_space = rt_malloc(module_size);
if (module->module_space == RT_NULL)
{
rt_object_delete(&(module->parent));
return RT_NULL;
}
......@@ -450,7 +453,8 @@ static struct rt_module* _load_shared_object(const char* name, void* module_ptr)
rt_kprintf("can't find %s in kernel symbol table\n", strtab + sym->st_name);
unsolved = RT_TRUE;
}
else rt_module_arm_relocate(module, rel, addr);
else
rt_module_arm_relocate(module, rel, addr);
}
rel ++;
}
......@@ -459,6 +463,7 @@ static struct rt_module* _load_shared_object(const char* name, void* module_ptr)
{
rt_object_delete(&(module->parent));
rt_free(module);
return RT_NULL;
}
}
......@@ -482,7 +487,8 @@ static struct rt_module* _load_shared_object(const char* name, void* module_ptr)
{
/* find .dynsym section */
rt_uint8_t *shstrab = (rt_uint8_t *)module_ptr + shdr[elf_module->e_shstrndx].sh_offset;
if (rt_strcmp((const char *)(shstrab + shdr[index].sh_name), ELF_DYNSYM) == 0) break;
if (rt_strcmp((const char *)(shstrab + shdr[index].sh_name), ELF_DYNSYM) == 0)
break;
}
/* found .dynsym section */
......@@ -521,11 +527,11 @@ static struct rt_module* _load_shared_object(const char* name, void* module_ptr)
return module;
}
static struct rt_module* _load_relocated_object(const char* name, void* module_ptr)
static struct rt_module* _load_relocated_object(const char *name, void *module_ptr)
{
rt_uint32_t index, rodata_addr = 0, bss_addr = 0, data_addr = 0;
rt_uint32_t module_addr = 0, module_size = 0;
struct rt_module* module = RT_NULL;
struct rt_module *module = RT_NULL;
rt_uint8_t *ptr, *strtab, *shstrab;
rt_bool_t linked = RT_FALSE;
......@@ -562,17 +568,20 @@ static struct rt_module* _load_relocated_object(const char* name, void* module_p
}
/* no text, data and bss on image */
if (module_size == 0) return RT_NULL;
if (module_size == 0)
return RT_NULL;
/* allocate module */
module = (struct rt_module *)rt_object_allocate(RT_Object_Class_Module, (const char*)name);
if (module == RT_NULL) return RT_NULL;
module = (struct rt_module *)rt_object_allocate(RT_Object_Class_Module, (const char *)name);
if (module == RT_NULL)
return RT_NULL;
/* allocate module space */
module->module_space = rt_malloc(module_size);
if (module->module_space == RT_NULL)
{
rt_object_delete(&(module->parent));
return RT_NULL;
}
......@@ -690,7 +699,8 @@ static struct rt_module* _load_relocated_object(const char* name, void* module_p
rt_module_arm_relocate(module, rel, addr);
RT_DEBUG_LOG(RT_DEBUG_MODULE,("symbol addr 0x%x\n", addr));
}
else rt_kprintf("can't find %s in kernel symbol table\n", strtab + sym->st_name);
else
rt_kprintf("can't find %s in kernel symbol table\n", strtab + sym->st_name);
}
else
{
......@@ -712,9 +722,8 @@ static struct rt_module* _load_relocated_object(const char* name, void* module_p
* @param module_ptr the memory address of module image
*
* @return the module object
*
*/
rt_module_t rt_module_load(const char* name, void* module_ptr)
rt_module_t rt_module_load(const char *name, void *module_ptr)
{
rt_module_t module;
......@@ -727,6 +736,7 @@ rt_module_t rt_module_load(const char* name, void* module_ptr)
&& rt_memcmp(elf_module->e_ident, ELFMAG, SELFMAG) != 0)
{
rt_kprintf(" module magic error\n");
return RT_NULL;
}
......@@ -734,6 +744,7 @@ rt_module_t rt_module_load(const char* name, void* module_ptr)
if(elf_module->e_ident[EI_CLASS] != ELFCLASS32)
{
rt_kprintf(" module class error\n");
return RT_NULL;
}
......@@ -748,10 +759,12 @@ rt_module_t rt_module_load(const char* name, void* module_ptr)
else
{
rt_kprintf("unsupported elf type\n");
return RT_NULL;
}
if(module == RT_NULL) return RT_NULL;
if(module == RT_NULL)
return RT_NULL;
/* init module object container */
rt_module_init_object_container(module);
......@@ -808,7 +821,6 @@ rt_module_t rt_module_load(const char* name, void* module_ptr)
* @param path the full path of application module
*
* @return the module object
*
*/
rt_module_t rt_module_open(const char *path)
{
......@@ -825,12 +837,14 @@ rt_module_t rt_module_open(const char *path)
if (stat(path, &s) !=0)
{
rt_kprintf("access %s failed\n", path);
return RT_NULL;
}
buffer = (char *)rt_malloc(s.st_size);
if (buffer == RT_NULL)
{
rt_kprintf("out of memory\n");
return RT_NULL;
}
......@@ -840,6 +854,7 @@ rt_module_t rt_module_open(const char *path)
{
rt_kprintf("open %s failed\n", path);
rt_free(buffer);
return RT_NULL;
}
......@@ -859,6 +874,7 @@ rt_module_t rt_module_open(const char *path)
{
rt_kprintf("check: read file failed\n");
rt_free(buffer);
return RT_NULL;
}
......@@ -880,7 +896,6 @@ FINSH_FUNCTION_EXPORT_ALIAS(rt_module_open, exec, exec module from file);
* @param module the module to be unloaded
*
* @return the operation status, RT_EOK on OK; -RT_ERROR on error
*
*/
rt_err_t rt_module_unload(rt_module_t module)
{
......@@ -1065,7 +1080,7 @@ rt_err_t rt_module_unload(rt_module_t module)
}
#ifdef RT_USING_SLAB
if(module->page_cnt > 0)
if (module->page_cnt > 0)
{
struct rt_page_info *page = (struct rt_page_info *)module->page_array;
......@@ -1082,8 +1097,10 @@ rt_err_t rt_module_unload(rt_module_t module)
rt_free(module->module_space);
/* release module symbol table */
for (i=0; i<module->nsym; i++) rt_free((void *)module->symtab[i].name);
if (module->symtab != RT_NULL) rt_free(module->symtab);
for (i=0; i<module->nsym; i++)
rt_free((void *)module->symtab[i].name);
if (module->symtab != RT_NULL)
rt_free(module->symtab);
#ifdef RT_USING_HOOK
if (rt_module_unload_hook != RT_NULL)
......@@ -1155,7 +1172,8 @@ static void *rt_module_malloc_page(rt_size_t npages)
struct rt_page_info *page;
chunk = rt_page_alloc(npages);
if (chunk == RT_NULL) return RT_NULL;
if (chunk == RT_NULL)
return RT_NULL;
page = (struct rt_page_info *)rt_current_module->page_array;
page[rt_current_module->page_cnt].page_ptr = chunk;
......@@ -1208,7 +1226,8 @@ static void rt_module_free_page(rt_module_t module, void *page_ptr, rt_size_t np
module->page_cnt--;
}
else RT_ASSERT(RT_FALSE);
else
RT_ASSERT(RT_FALSE);
rt_current_module->page_cnt--;
return;
......@@ -1251,6 +1270,7 @@ void *rt_module_malloc(rt_size_t size)
rt_kprintf("rt_module_malloc 0x%x, %d\n",b + 1, size);
rt_sem_release(&mod_sem);
return (void *)(b + 1);
}
......@@ -1262,19 +1282,22 @@ void *rt_module_malloc(rt_size_t size)
rt_kprintf("rt_module_malloc 0x%x, %d\n",b + 1, size);
rt_sem_release(&mod_sem);
return (void *)(b + 1);
}
}
/* allocate pages from system heap */
npage = (size + sizeof(struct rt_mem_head) + RT_MM_PAGE_SIZE - 1)/RT_MM_PAGE_SIZE;
if ((up = (struct rt_mem_head *)rt_module_malloc_page(npage)) == RT_NULL) return RT_NULL;
if ((up = (struct rt_mem_head *)rt_module_malloc_page(npage)) == RT_NULL)
return RT_NULL;
up->size = npage * RT_MM_PAGE_SIZE / sizeof(struct rt_mem_head);
for (prev = (struct rt_mem_head **)&rt_current_module->mem_list; (b = *prev) != RT_NULL; prev = &(b->next))
{
if (b > up + up->size) break;
if (b > up + up->size)
break;
}
up->next = b;
......@@ -1317,7 +1340,8 @@ void rt_module_free(rt_module_t module, void *addr)
b->size += b->next->size + n->size;
b->next = b->next->next;
}
else b->size += n->size;
else
b->size += n->size;
if ((rt_uint32_t)b % RT_MM_PAGE_SIZE == 0)
{
......@@ -1382,7 +1406,8 @@ void rt_module_free(rt_module_t module, void *addr)
return;
}
if (b > n + n->size) break;
if (b > n + n->size)
break;
prev = &(b->next);
}
......@@ -1428,10 +1453,12 @@ void *rt_module_realloc(void *ptr, rt_size_t size)
RT_DEBUG_NOT_IN_INTERRUPT;
if (!ptr) return rt_module_malloc(size);
if (!ptr)
return rt_module_malloc(size);
if (size == 0)
{
rt_module_free(rt_current_module, ptr);
return RT_NULL;
}
......@@ -1441,13 +1468,15 @@ void *rt_module_realloc(void *ptr, rt_size_t size)
if (nunits <= b->size)
{
/* new size is smaller or equal then before */
if (nunits == b->size) return ptr;
if (nunits == b->size)
return ptr;
else
{
p = b + nunits;
p->size = b->size - nunits;
b->size = nunits;
rt_module_free(rt_current_module, (void *)(p + 1));
return (void *)(b + 1);
}
}
......@@ -1455,7 +1484,8 @@ void *rt_module_realloc(void *ptr, rt_size_t size)
{
/* more space then required */
prev = (struct rt_mem_head *)rt_current_module->mem_list;
for (p = prev->next; p != (b->size + b) && p != RT_NULL; prev = p, p = p->next) break;
for (p = prev->next; p != (b->size + b) && p != RT_NULL; prev = p, p = p->next)
break;
/* available block after ap in freelist */
if (p != RT_NULL && (p->size >= (nunits - (b->size))) && p == (b + b->size))
......@@ -1481,6 +1511,7 @@ void *rt_module_realloc(void *ptr, rt_size_t size)
prev->next = p;
}
rt_current_module->mem_list = (void *)prev;
return (void *)(b + 1);
}
else /* allocate new memory and copy old data */
......@@ -1488,6 +1519,7 @@ void *rt_module_realloc(void *ptr, rt_size_t size)
if ((p = rt_module_malloc(size)) == RT_NULL) return RT_NULL;
rt_memmove(p, (b+1), ((b->size) * sizeof(struct rt_mem_head)));
rt_module_free(rt_current_module, (void *)(b + 1));
return (void *)(p);
}
}
......@@ -1496,14 +1528,15 @@ void *rt_module_realloc(void *ptr, rt_size_t size)
#ifdef RT_USING_FINSH
#include <finsh.h>
void list_memlist(const char* name)
void list_memlist(const char *name)
{
rt_module_t module;
struct rt_mem_head **prev;
struct rt_mem_head *b;
module = rt_module_find(name);
if (module == RT_NULL) return;
if (module == RT_NULL)
return;
for (prev = (struct rt_mem_head **)&module->mem_list; (b = *prev) != RT_NULL; prev = &(b->next))
{
......@@ -1519,7 +1552,8 @@ void list_mempage(const char *name)
int i;
module = rt_module_find(name);
if (module == RT_NULL) return;
if (module == RT_NULL)
return;
page = (struct rt_page_info*)module->page_array;
......
/*
* 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
......
/*
* 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;
}
/*@}*/
/*
* 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
......
/*
* 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
*/
/*@{*/
/**
......
/*
* File : slab.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
......@@ -71,6 +71,7 @@ static void (*rt_free_hook)(void *ptr);
/**
* @addtogroup Hook
*/
/*@{*/
/**
......@@ -235,7 +236,8 @@ void *rt_page_alloc(rt_size_t npages)
struct rt_page_head *b, *n;
struct rt_page_head **prev;
if(npages == 0) return RT_NULL;
if(npages == 0)
return RT_NULL;
/* lock heap */
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
......@@ -304,7 +306,8 @@ void rt_page_free(void *addr, rt_size_t npages)
goto _return;
}
if (b > n + npages) break;
if (b > n + npages)
break;
}
n->page = npages;
......@@ -335,7 +338,6 @@ static void rt_page_init(void *addr, rt_size_t npages)
*
* @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)
{
......@@ -351,6 +353,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
{
rt_kprintf("rt_system_heap_init, wrong address[0x%x - 0x%x]\n",
(rt_uint32_t)begin_addr, (rt_uint32_t)end_addr);
return;
}
......@@ -372,7 +375,8 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
zone_size <<= 1;
zone_limit = zone_size / 4;
if (zone_limit > ZALLOC_ZONE_LIMIT) zone_limit = ZALLOC_ZONE_LIMIT;
if (zone_limit > ZALLOC_ZONE_LIMIT)
zone_limit = ZALLOC_ZONE_LIMIT;
zone_page_cnt = zone_size / RT_MM_PAGE_SIZE;
......@@ -399,11 +403,13 @@ rt_inline int zoneindex(rt_uint32_t *bytes)
if (n < 128)
{
*bytes = n = (n + 7) & ~7;
return(n / 8 - 1); /* 8 byte chunks, 16 zones */
}
if (n < 256)
{
*bytes = n = (n + 15) & ~15;
return(n / 16 + 7);
}
if (n < 8192)
......@@ -411,33 +417,40 @@ rt_inline int zoneindex(rt_uint32_t *bytes)
if (n < 512)
{
*bytes = n = (n + 31) & ~31;
return(n / 32 + 15);
}
if (n < 1024)
{
*bytes = n = (n + 63) & ~63;
return(n / 64 + 23);
}
if (n < 2048)
{
*bytes = n = (n + 127) & ~127;
return(n / 128 + 31);
}
if (n < 4096)
{
*bytes = n = (n + 255) & ~255;
return(n / 256 + 39);
}
*bytes = n = (n + 511) & ~511;
return(n / 512 + 47);
}
if (n < 16384)
{
*bytes = n = (n + 1023) & ~1023;
return(n / 1024 + 55);
}
rt_kprintf("Unexpected byte count %d", n);
return 0;
}
......@@ -457,7 +470,6 @@ rt_inline int zoneindex(rt_uint32_t *bytes)
* @param size the size of memory to be allocated
*
* @return the allocated memory
*
*/
void *rt_malloc(rt_size_t size)
{
......@@ -467,10 +479,12 @@ void *rt_malloc(rt_size_t size)
struct memusage *kup;
/* zero size, return RT_NULL */
if (size == 0) return RT_NULL;
if (size == 0)
return RT_NULL;
#ifdef RT_USING_MODULE
if (rt_module_self() != RT_NULL) return rt_module_malloc(size);
if (rt_module_self() != RT_NULL)
return rt_module_malloc(size);
#endif
/*
......@@ -482,7 +496,8 @@ void *rt_malloc(rt_size_t size)
size = RT_ALIGN(size, RT_MM_PAGE_SIZE);
chunk = rt_page_alloc(size >> RT_MM_PAGE_BITS);
if (chunk == RT_NULL) return RT_NULL;
if (chunk == RT_NULL)
return RT_NULL;
/* set kup */
kup = btokup(chunk);
......@@ -499,7 +514,8 @@ void *rt_malloc(rt_size_t size)
#ifdef RT_MEM_STATS
used_mem += size;
if (used_mem > max_mem) max_mem = used_mem;
if (used_mem > max_mem)
max_mem = used_mem;
#endif
goto done;
}
......@@ -553,7 +569,8 @@ void *rt_malloc(rt_size_t size)
#ifdef RT_MEM_STATS
used_mem += z->z_chunksize;
if (used_mem > max_mem) max_mem = used_mem;
if (used_mem > max_mem)
max_mem = used_mem;
#endif
goto done;
......@@ -583,7 +600,8 @@ void *rt_malloc(rt_size_t size)
/* allocate a zone from page */
z = rt_page_alloc(zone_size / RT_MM_PAGE_SIZE);
if (z == RT_NULL) goto fail;
if (z == RT_NULL)
goto fail;
/* lock heap */
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
......@@ -631,7 +649,8 @@ void *rt_malloc(rt_size_t size)
#ifdef RT_MEM_STATS
used_mem += z->z_chunksize;
if (used_mem > max_mem) max_mem = used_mem;
if (used_mem > max_mem)
max_mem = used_mem;
#endif
}
......@@ -644,6 +663,7 @@ done:
fail:
rt_sem_release(&heap_sem);
return RT_NULL;
}
......@@ -661,15 +681,18 @@ void *rt_realloc(void *ptr, rt_size_t size)
slab_zone *z;
struct memusage *kup;
if (ptr == RT_NULL) return rt_malloc(size);
if (ptr == RT_NULL)
return rt_malloc(size);
if (size == 0)
{
rt_free(ptr);
return RT_NULL;
}
#ifdef RT_USING_MODULE
if (rt_module_self() != RT_NULL) return rt_module_realloc(ptr, size);
if (rt_module_self() != RT_NULL)
return rt_module_realloc(ptr, size);
#endif
/*
......@@ -682,7 +705,8 @@ void *rt_realloc(void *ptr, rt_size_t size)
rt_size_t osize;
osize = kup->size << RT_MM_PAGE_BITS;
if ((nptr = rt_malloc(size)) == RT_NULL) return RT_NULL;
if ((nptr = rt_malloc(size)) == RT_NULL)
return RT_NULL;
rt_memcpy(nptr, ptr, size > osize ? osize : size);
rt_free(ptr);
......@@ -694,14 +718,16 @@ void *rt_realloc(void *ptr, rt_size_t size)
RT_ASSERT(z->z_magic == ZALLOC_SLAB_MAGIC);
zoneindex(&size);
if (z->z_chunksize == size) return(ptr); /* same chunk */
if (z->z_chunksize == size)
return(ptr); /* same chunk */
/*
* Allocate memory for the new request size. Note that zoneindex has
* already adjusted the request size to the appropriate chunk size, which
* should optimize our bcopy(). Then copy and return the new pointer.
*/
if ((nptr = rt_malloc(size)) == RT_NULL) return RT_NULL;
if ((nptr = rt_malloc(size)) == RT_NULL)
return RT_NULL;
rt_memcpy(nptr, ptr, size > z->z_chunksize ? z->z_chunksize : size);
rt_free(ptr);
......@@ -732,7 +758,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;
}
......@@ -750,7 +777,8 @@ void rt_free(void *ptr)
struct memusage *kup;
/* free a RT_NULL pointer */
if (ptr == RT_NULL) return ;
if (ptr == RT_NULL)
return ;
RT_OBJECT_HOOK_CALL(rt_free_hook, (ptr));
......@@ -758,6 +786,7 @@ void rt_free(void *ptr)
if(rt_module_self() != RT_NULL)
{
rt_module_free(rt_module_self(), ptr);
return;
}
#endif
......@@ -796,6 +825,7 @@ void rt_free(void *ptr)
/* free this page */
rt_page_free(ptr, size);
return;
}
......@@ -837,7 +867,8 @@ void rt_free(void *ptr)
RT_DEBUG_LOG(RT_DEBUG_SLAB, ("free zone 0x%x\n", (rt_uint32_t)z, z->z_zoneindex));
/* remove zone from zone array list */
for (pz = &zone_array[z->z_zoneindex]; z != *pz; pz = &(*pz)->z_next);
for (pz = &zone_array[z->z_zoneindex]; z != *pz; pz = &(*pz)->z_next)
;
*pz = z->z_next;
/* reset zone */
......@@ -871,6 +902,7 @@ void rt_free(void *ptr)
/* release pages */
rt_page_free(z, zone_size / RT_MM_PAGE_SIZE);
return;
}
}
......@@ -881,9 +913,14 @@ void rt_free(void *ptr)
#ifdef RT_MEM_STATS
void rt_memory_info(rt_uint32_t *total, rt_uint32_t *used, rt_uint32_t *max_used)
{
if (total != RT_NULL) *total = heap_end - heap_start;
if (used != RT_NULL) *used = used_mem;
if (max_used != RT_NULL) *max_used = max_mem;
if (total != RT_NULL)
*total = heap_end - heap_start;
if (used != RT_NULL)
*used = used_mem;
if (max_used != RT_NULL)
*max_used = max_mem;
}
#ifdef RT_USING_FINSH
......
/*
* 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)
{
......
/*
* 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)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册