Пример #1
0
/**
 * This function will create a thread object and allocate thread object memory
 * and stack.
 *
 * @param name the name of thread, which shall be unique
 * @param entry the entry function of thread
 * @param parameter the parameter of thread enter function
 * @param stack_size the size of thread stack
 * @param priority the priority of 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,
	rt_uint32_t stack_size,
	rt_uint8_t priority,
	rt_uint32_t tick)
{
	struct rt_thread *thread;
	void *stack_start;

	thread = (struct rt_thread *)rt_object_allocate(RT_Object_Class_Thread, name);
	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; 
	}

	_rt_thread_init(thread, name, entry, parameter,
		stack_start, stack_size,
		priority, tick);

	return thread;
}
Пример #2
0
/**
 * This function will initialize a thread, normally it's used to initialize a
 * static thread object.
 *
 * @param thread the static thread object
 * @param name the name of thread, which shall be unique
 * @param entry the entry function of thread
 * @param parameter the parameter of thread enter function
 * @param stack_start the start address of thread stack
 * @param stack_size the size of thread stack
 * @param priority the priority of 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,
                        void (*entry)(void *parameter),
                        void             *parameter,
                        void             *stack_start,
                        rt_uint32_t       stack_size,
                        rt_uint8_t        priority,
                        rt_uint32_t       tick)
{
    /* thread check */
    RT_ASSERT(thread != RT_NULL);
    RT_ASSERT(stack_start != RT_NULL);

    /* init thread object */
    rt_object_init((rt_object_t)thread, RT_Object_Class_Thread, name);

    return _rt_thread_init(thread,
                           name,
                           entry,
                           parameter,
                           stack_start,
                           stack_size,
                           priority,
                           tick);
}