mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-06 22:24:56 +08:00
fixed the coding style in components/drivers/src
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2529 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
f29cfc5e79
commit
ef5c47e684
@ -60,7 +60,8 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
|
|||||||
/* suspend thread */
|
/* suspend thread */
|
||||||
rt_thread_suspend(thread);
|
rt_thread_suspend(thread);
|
||||||
/* add to suspended list */
|
/* add to suspended list */
|
||||||
rt_list_insert_before(&(completion->suspended_list), &(thread->tlist));
|
rt_list_insert_before(&(completion->suspended_list),
|
||||||
|
&(thread->tlist));
|
||||||
|
|
||||||
/* current context checking */
|
/* current context checking */
|
||||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||||
@ -69,7 +70,9 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
|
|||||||
if (timeout > 0)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
/* reset the timeout of thread timer and start it */
|
/* reset the timeout of thread timer and start it */
|
||||||
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &timeout);
|
rt_timer_control(&(thread->thread_timer),
|
||||||
|
RT_TIMER_CTRL_SET_TIME,
|
||||||
|
&timeout);
|
||||||
rt_timer_start(&(thread->thread_timer));
|
rt_timer_start(&(thread->thread_timer));
|
||||||
}
|
}
|
||||||
/* enable interrupt */
|
/* enable interrupt */
|
||||||
@ -110,8 +113,10 @@ void rt_completion_done(struct rt_completion *completion)
|
|||||||
struct rt_thread *thread;
|
struct rt_thread *thread;
|
||||||
|
|
||||||
/* get thread entry */
|
/* get thread entry */
|
||||||
thread = rt_list_entry(completion->suspended_list.next, struct rt_thread, tlist);
|
thread = rt_list_entry(completion->suspended_list.next,
|
||||||
|
struct rt_thread,
|
||||||
|
tlist);
|
||||||
|
|
||||||
/* resume it */
|
/* resume it */
|
||||||
rt_thread_resume(thread);
|
rt_thread_resume(thread);
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
@ -1,327 +1,343 @@
|
|||||||
/*
|
/*
|
||||||
* File : dataqueue.c
|
* File : dataqueue.c
|
||||||
* This file is part of RT-Thread RTOS
|
* This file is part of RT-Thread RTOS
|
||||||
* COPYRIGHT (C) 2012, RT-Thread Development Team
|
* COPYRIGHT (C) 2012, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* The license and distribution terms for this file may be
|
* The license and distribution terms for this file may be
|
||||||
* found in the file LICENSE in this distribution or at
|
* found in the file LICENSE in this distribution or at
|
||||||
* http://www.rt-thread.org/license/LICENSE
|
* http://www.rt-thread.org/license/LICENSE
|
||||||
*
|
*
|
||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2012-09-30 Bernard first version.
|
* 2012-09-30 Bernard first version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <rtdevice.h>
|
#include <rtdevice.h>
|
||||||
#include <rthw.h>
|
#include <rthw.h>
|
||||||
|
|
||||||
struct rt_data_item
|
struct rt_data_item
|
||||||
{
|
{
|
||||||
const void *data_ptr;
|
const void *data_ptr;
|
||||||
rt_size_t data_size;
|
rt_size_t data_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
rt_err_t
|
rt_err_t
|
||||||
rt_data_queue_init(struct rt_data_queue *queue,
|
rt_data_queue_init(struct rt_data_queue *queue,
|
||||||
rt_uint16_t size,
|
rt_uint16_t size,
|
||||||
rt_uint16_t lwm,
|
rt_uint16_t lwm,
|
||||||
void (*evt_notify)(struct rt_data_queue *queue, rt_uint32_t event))
|
void (*evt_notify)(struct rt_data_queue *queue, rt_uint32_t event))
|
||||||
{
|
{
|
||||||
RT_ASSERT(queue != RT_NULL);
|
RT_ASSERT(queue != RT_NULL);
|
||||||
|
|
||||||
queue->evt_notify = evt_notify;
|
queue->evt_notify = evt_notify;
|
||||||
|
|
||||||
queue->size = size;
|
queue->size = size;
|
||||||
queue->lwm = lwm;
|
queue->lwm = lwm;
|
||||||
queue->waiting_lwm = RT_FALSE;
|
queue->waiting_lwm = RT_FALSE;
|
||||||
|
|
||||||
queue->get_index = 0;
|
queue->get_index = 0;
|
||||||
queue->put_index = 0;
|
queue->put_index = 0;
|
||||||
|
|
||||||
rt_list_init(&(queue->suspended_push_list));
|
rt_list_init(&(queue->suspended_push_list));
|
||||||
rt_list_init(&(queue->suspended_pop_list));
|
rt_list_init(&(queue->suspended_pop_list));
|
||||||
|
|
||||||
queue->queue = (struct rt_data_item *)rt_malloc(sizeof(struct rt_data_item) * size);
|
queue->queue = (struct rt_data_item *)rt_malloc(sizeof(struct rt_data_item) * size);
|
||||||
if (queue->queue == RT_NULL)
|
if (queue->queue == RT_NULL)
|
||||||
{
|
{
|
||||||
return -RT_ENOMEM;
|
return -RT_ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
RTM_EXPORT(rt_data_queue_init);
|
RTM_EXPORT(rt_data_queue_init);
|
||||||
|
|
||||||
rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
|
rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
|
||||||
const void *data_ptr,
|
const void *data_ptr,
|
||||||
rt_size_t data_size,
|
rt_size_t data_size,
|
||||||
rt_int32_t timeout)
|
rt_int32_t timeout)
|
||||||
{
|
{
|
||||||
rt_uint16_t mask;
|
rt_uint16_t mask;
|
||||||
rt_ubase_t level;
|
rt_ubase_t level;
|
||||||
rt_thread_t thread;
|
rt_thread_t thread;
|
||||||
rt_err_t result;
|
rt_err_t result;
|
||||||
|
|
||||||
RT_ASSERT(queue != RT_NULL);
|
RT_ASSERT(queue != RT_NULL);
|
||||||
|
|
||||||
result = RT_EOK;
|
result = RT_EOK;
|
||||||
thread = rt_thread_self();
|
thread = rt_thread_self();
|
||||||
mask = queue->size - 1;
|
mask = queue->size - 1;
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
while (queue->put_index - queue->get_index == queue->size)
|
while (queue->put_index - queue->get_index == queue->size)
|
||||||
{
|
{
|
||||||
queue->waiting_lwm = RT_TRUE;
|
queue->waiting_lwm = RT_TRUE;
|
||||||
|
|
||||||
/* queue is full */
|
/* queue is full */
|
||||||
if (timeout == 0)
|
if (timeout == 0)
|
||||||
{
|
{
|
||||||
result = -RT_ETIMEOUT;
|
result = -RT_ETIMEOUT;
|
||||||
|
|
||||||
goto __exit;
|
goto __exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* current context checking */
|
/* current context checking */
|
||||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||||
|
|
||||||
/* reset thread error number */
|
/* reset thread error number */
|
||||||
thread->error = RT_EOK;
|
thread->error = RT_EOK;
|
||||||
|
|
||||||
/* suspend thread on the push list */
|
/* suspend thread on the push list */
|
||||||
rt_thread_suspend(thread);
|
rt_thread_suspend(thread);
|
||||||
rt_list_insert_before(&(queue->suspended_push_list), &(thread->tlist));
|
rt_list_insert_before(&(queue->suspended_push_list), &(thread->tlist));
|
||||||
/* start timer */
|
/* start timer */
|
||||||
if (timeout > 0)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
/* reset the timeout of thread timer and start it */
|
/* reset the timeout of thread timer and start it */
|
||||||
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &timeout);
|
rt_timer_control(&(thread->thread_timer),
|
||||||
rt_timer_start(&(thread->thread_timer));
|
RT_TIMER_CTRL_SET_TIME,
|
||||||
}
|
&timeout);
|
||||||
|
rt_timer_start(&(thread->thread_timer));
|
||||||
/* enable interrupt */
|
}
|
||||||
rt_hw_interrupt_enable(level);
|
|
||||||
|
/* enable interrupt */
|
||||||
/* do schedule */
|
rt_hw_interrupt_enable(level);
|
||||||
rt_schedule();
|
|
||||||
|
/* do schedule */
|
||||||
/* thread is waked up */
|
rt_schedule();
|
||||||
result = thread->error;
|
|
||||||
level = rt_hw_interrupt_disable();
|
/* thread is waked up */
|
||||||
if (result != RT_EOK) goto __exit;
|
result = thread->error;
|
||||||
}
|
level = rt_hw_interrupt_disable();
|
||||||
|
if (result != RT_EOK) goto __exit;
|
||||||
queue->queue[queue->put_index & mask].data_ptr = data_ptr;
|
}
|
||||||
queue->queue[queue->put_index & mask].data_size = data_size;
|
|
||||||
queue->put_index += 1;
|
queue->queue[queue->put_index & mask].data_ptr = data_ptr;
|
||||||
|
queue->queue[queue->put_index & mask].data_size = data_size;
|
||||||
if (!rt_list_isempty(&(queue->suspended_pop_list)))
|
queue->put_index += 1;
|
||||||
{
|
|
||||||
/* there is at least one thread in suspended list */
|
if (!rt_list_isempty(&(queue->suspended_pop_list)))
|
||||||
|
{
|
||||||
/* get thread entry */
|
/* there is at least one thread in suspended list */
|
||||||
thread = rt_list_entry(queue->suspended_pop_list.next, struct rt_thread, tlist);
|
|
||||||
|
/* get thread entry */
|
||||||
/* resume it */
|
thread = rt_list_entry(queue->suspended_pop_list.next,
|
||||||
rt_thread_resume(thread);
|
struct rt_thread,
|
||||||
rt_hw_interrupt_enable(level);
|
tlist);
|
||||||
|
|
||||||
/* perform a schedule */
|
/* resume it */
|
||||||
rt_schedule();
|
rt_thread_resume(thread);
|
||||||
|
rt_hw_interrupt_enable(level);
|
||||||
return result;
|
|
||||||
}
|
/* perform a schedule */
|
||||||
|
rt_schedule();
|
||||||
__exit:
|
|
||||||
rt_hw_interrupt_enable(level);
|
return result;
|
||||||
if ((result == RT_EOK) && queue->evt_notify != RT_NULL)
|
}
|
||||||
{
|
|
||||||
queue->evt_notify(queue, RT_DATAQUEUE_EVENT_PUSH);
|
__exit:
|
||||||
}
|
rt_hw_interrupt_enable(level);
|
||||||
|
if ((result == RT_EOK) && queue->evt_notify != RT_NULL)
|
||||||
return result;
|
{
|
||||||
}
|
queue->evt_notify(queue, RT_DATAQUEUE_EVENT_PUSH);
|
||||||
RTM_EXPORT(rt_data_queue_push);
|
}
|
||||||
|
|
||||||
rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
|
return result;
|
||||||
const void** data_ptr,
|
}
|
||||||
rt_size_t *size,
|
RTM_EXPORT(rt_data_queue_push);
|
||||||
rt_int32_t timeout)
|
|
||||||
{
|
rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
|
||||||
rt_ubase_t level;
|
const void** data_ptr,
|
||||||
rt_thread_t thread;
|
rt_size_t *size,
|
||||||
rt_err_t result;
|
rt_int32_t timeout)
|
||||||
rt_uint16_t mask;
|
{
|
||||||
|
rt_ubase_t level;
|
||||||
RT_ASSERT(queue != RT_NULL);
|
rt_thread_t thread;
|
||||||
RT_ASSERT(data_ptr != RT_NULL);
|
rt_err_t result;
|
||||||
RT_ASSERT(size != RT_NULL);
|
rt_uint16_t mask;
|
||||||
|
|
||||||
result = RT_EOK;
|
RT_ASSERT(queue != RT_NULL);
|
||||||
thread = rt_thread_self();
|
RT_ASSERT(data_ptr != RT_NULL);
|
||||||
mask = queue->size - 1;
|
RT_ASSERT(size != RT_NULL);
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
result = RT_EOK;
|
||||||
while (queue->get_index == queue->put_index)
|
thread = rt_thread_self();
|
||||||
{
|
mask = queue->size - 1;
|
||||||
/* queue is empty */
|
|
||||||
if (timeout == 0)
|
level = rt_hw_interrupt_disable();
|
||||||
{
|
while (queue->get_index == queue->put_index)
|
||||||
result = -RT_ETIMEOUT;
|
{
|
||||||
goto __exit;
|
/* queue is empty */
|
||||||
}
|
if (timeout == 0)
|
||||||
|
{
|
||||||
/* current context checking */
|
result = -RT_ETIMEOUT;
|
||||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
goto __exit;
|
||||||
|
}
|
||||||
/* reset thread error number */
|
|
||||||
thread->error = RT_EOK;
|
/* current context checking */
|
||||||
|
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||||
/* suspend thread on the pop list */
|
|
||||||
rt_thread_suspend(thread);
|
/* reset thread error number */
|
||||||
rt_list_insert_before(&(queue->suspended_pop_list), &(thread->tlist));
|
thread->error = RT_EOK;
|
||||||
/* start timer */
|
|
||||||
if (timeout > 0)
|
/* suspend thread on the pop list */
|
||||||
{
|
rt_thread_suspend(thread);
|
||||||
/* reset the timeout of thread timer and start it */
|
rt_list_insert_before(&(queue->suspended_pop_list), &(thread->tlist));
|
||||||
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &timeout);
|
/* start timer */
|
||||||
rt_timer_start(&(thread->thread_timer));
|
if (timeout > 0)
|
||||||
}
|
{
|
||||||
|
/* reset the timeout of thread timer and start it */
|
||||||
/* enable interrupt */
|
rt_timer_control(&(thread->thread_timer),
|
||||||
rt_hw_interrupt_enable(level);
|
RT_TIMER_CTRL_SET_TIME,
|
||||||
|
&timeout);
|
||||||
/* do schedule */
|
rt_timer_start(&(thread->thread_timer));
|
||||||
rt_schedule();
|
}
|
||||||
|
|
||||||
/* thread is waked up */
|
/* enable interrupt */
|
||||||
result = thread->error;
|
rt_hw_interrupt_enable(level);
|
||||||
level = rt_hw_interrupt_disable();
|
|
||||||
if (result != RT_EOK) goto __exit;
|
/* do schedule */
|
||||||
}
|
rt_schedule();
|
||||||
|
|
||||||
*data_ptr = queue->queue[queue->get_index & mask].data_ptr;
|
/* thread is waked up */
|
||||||
*size = queue->queue[queue->get_index & mask].data_size;
|
result = thread->error;
|
||||||
|
level = rt_hw_interrupt_disable();
|
||||||
queue->get_index += 1;
|
if (result != RT_EOK)
|
||||||
|
goto __exit;
|
||||||
if ((queue->waiting_lwm == RT_TRUE) &&
|
}
|
||||||
(queue->put_index - queue->get_index) <= queue->lwm)
|
|
||||||
{
|
*data_ptr = queue->queue[queue->get_index & mask].data_ptr;
|
||||||
queue->waiting_lwm = RT_FALSE;
|
*size = queue->queue[queue->get_index & mask].data_size;
|
||||||
|
|
||||||
/* there is at least one thread in suspended list and less than low water mark */
|
queue->get_index += 1;
|
||||||
if (!rt_list_isempty(&(queue->suspended_push_list)))
|
|
||||||
{
|
if ((queue->waiting_lwm == RT_TRUE) &&
|
||||||
/* get thread entry */
|
(queue->put_index - queue->get_index) <= queue->lwm)
|
||||||
thread = rt_list_entry(queue->suspended_push_list.next, struct rt_thread, tlist);
|
{
|
||||||
|
queue->waiting_lwm = RT_FALSE;
|
||||||
/* resume it */
|
|
||||||
rt_thread_resume(thread);
|
/*
|
||||||
rt_hw_interrupt_enable(level);
|
* there is at least one thread in suspended list
|
||||||
|
* and less than low water mark
|
||||||
/* perform a schedule */
|
*/
|
||||||
rt_schedule();
|
if (!rt_list_isempty(&(queue->suspended_push_list)))
|
||||||
}
|
{
|
||||||
|
/* get thread entry */
|
||||||
if (queue->evt_notify != RT_NULL)
|
thread = rt_list_entry(queue->suspended_push_list.next,
|
||||||
queue->evt_notify(queue, RT_DATAQUEUE_EVENT_LWM);
|
struct rt_thread,
|
||||||
|
tlist);
|
||||||
return result;
|
|
||||||
}
|
/* resume it */
|
||||||
|
rt_thread_resume(thread);
|
||||||
__exit:
|
rt_hw_interrupt_enable(level);
|
||||||
rt_hw_interrupt_enable(level);
|
|
||||||
if ((result == RT_EOK) && (queue->evt_notify != RT_NULL))
|
/* perform a schedule */
|
||||||
{
|
rt_schedule();
|
||||||
queue->evt_notify(queue, RT_DATAQUEUE_EVENT_POP);
|
}
|
||||||
}
|
|
||||||
|
if (queue->evt_notify != RT_NULL)
|
||||||
return result;
|
queue->evt_notify(queue, RT_DATAQUEUE_EVENT_LWM);
|
||||||
}
|
|
||||||
RTM_EXPORT(rt_data_queue_pop);
|
return result;
|
||||||
|
}
|
||||||
rt_err_t rt_data_queue_peak(struct rt_data_queue *queue,
|
|
||||||
const void** data_ptr,
|
__exit:
|
||||||
rt_size_t *size)
|
rt_hw_interrupt_enable(level);
|
||||||
{
|
if ((result == RT_EOK) && (queue->evt_notify != RT_NULL))
|
||||||
rt_ubase_t level;
|
{
|
||||||
rt_uint16_t mask;
|
queue->evt_notify(queue, RT_DATAQUEUE_EVENT_POP);
|
||||||
|
}
|
||||||
RT_ASSERT(queue != RT_NULL);
|
|
||||||
|
return result;
|
||||||
mask = queue->size - 1;
|
}
|
||||||
|
RTM_EXPORT(rt_data_queue_pop);
|
||||||
level = rt_hw_interrupt_disable();
|
|
||||||
|
rt_err_t rt_data_queue_peak(struct rt_data_queue *queue,
|
||||||
if (queue->get_index == queue->put_index)
|
const void** data_ptr,
|
||||||
{
|
rt_size_t *size)
|
||||||
rt_hw_interrupt_enable(level);
|
{
|
||||||
|
rt_ubase_t level;
|
||||||
return -RT_EEMPTY;
|
rt_uint16_t mask;
|
||||||
}
|
|
||||||
|
RT_ASSERT(queue != RT_NULL);
|
||||||
*data_ptr = queue->queue[queue->get_index & mask].data_ptr;
|
|
||||||
*size = queue->queue[queue->get_index & mask].data_size;
|
mask = queue->size - 1;
|
||||||
|
|
||||||
rt_hw_interrupt_enable(level);
|
level = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
return RT_EOK;
|
if (queue->get_index == queue->put_index)
|
||||||
}
|
{
|
||||||
RTM_EXPORT(rt_data_queue_peak);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
void rt_data_queue_reset(struct rt_data_queue *queue)
|
return -RT_EEMPTY;
|
||||||
{
|
}
|
||||||
struct rt_thread *thread;
|
|
||||||
register rt_ubase_t temp;
|
*data_ptr = queue->queue[queue->get_index & mask].data_ptr;
|
||||||
|
*size = queue->queue[queue->get_index & mask].data_size;
|
||||||
rt_enter_critical();
|
|
||||||
/* wakeup all suspend threads */
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
/* resume on pop list */
|
return RT_EOK;
|
||||||
while (!rt_list_isempty(&(queue->suspended_pop_list)))
|
}
|
||||||
{
|
RTM_EXPORT(rt_data_queue_peak);
|
||||||
/* disable interrupt */
|
|
||||||
temp = rt_hw_interrupt_disable();
|
void rt_data_queue_reset(struct rt_data_queue *queue)
|
||||||
|
{
|
||||||
/* get next suspend thread */
|
struct rt_thread *thread;
|
||||||
thread = rt_list_entry(queue->suspended_pop_list.next, struct rt_thread, tlist);
|
register rt_ubase_t temp;
|
||||||
/* set error code to RT_ERROR */
|
|
||||||
thread->error = -RT_ERROR;
|
rt_enter_critical();
|
||||||
|
/* wakeup all suspend threads */
|
||||||
/*
|
|
||||||
* resume thread
|
/* resume on pop list */
|
||||||
* In rt_thread_resume function, it will remove current thread from
|
while (!rt_list_isempty(&(queue->suspended_pop_list)))
|
||||||
* suspend list
|
{
|
||||||
*/
|
/* disable interrupt */
|
||||||
rt_thread_resume(thread);
|
temp = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
/* enable interrupt */
|
/* get next suspend thread */
|
||||||
rt_hw_interrupt_enable(temp);
|
thread = rt_list_entry(queue->suspended_pop_list.next,
|
||||||
}
|
struct rt_thread,
|
||||||
|
tlist);
|
||||||
/* resume on push list */
|
/* set error code to RT_ERROR */
|
||||||
while (!rt_list_isempty(&(queue->suspended_push_list)))
|
thread->error = -RT_ERROR;
|
||||||
{
|
|
||||||
/* disable interrupt */
|
/*
|
||||||
temp = rt_hw_interrupt_disable();
|
* resume thread
|
||||||
|
* In rt_thread_resume function, it will remove current thread from
|
||||||
/* get next suspend thread */
|
* suspend list
|
||||||
thread = rt_list_entry(queue->suspended_push_list.next, struct rt_thread, tlist);
|
*/
|
||||||
/* set error code to RT_ERROR */
|
rt_thread_resume(thread);
|
||||||
thread->error = -RT_ERROR;
|
|
||||||
|
/* enable interrupt */
|
||||||
/*
|
rt_hw_interrupt_enable(temp);
|
||||||
* resume thread
|
}
|
||||||
* In rt_thread_resume function, it will remove current thread from
|
|
||||||
* suspend list
|
/* resume on push list */
|
||||||
*/
|
while (!rt_list_isempty(&(queue->suspended_push_list)))
|
||||||
rt_thread_resume(thread);
|
{
|
||||||
|
/* disable interrupt */
|
||||||
/* enable interrupt */
|
temp = rt_hw_interrupt_disable();
|
||||||
rt_hw_interrupt_enable(temp);
|
|
||||||
}
|
/* get next suspend thread */
|
||||||
rt_exit_critical();
|
thread = rt_list_entry(queue->suspended_push_list.next,
|
||||||
|
struct rt_thread,
|
||||||
rt_schedule();
|
tlist);
|
||||||
}
|
/* set error code to RT_ERROR */
|
||||||
RTM_EXPORT(rt_data_queue_reset);
|
thread->error = -RT_ERROR;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* resume thread
|
||||||
|
* In rt_thread_resume function, it will remove current thread from
|
||||||
|
* suspend list
|
||||||
|
*/
|
||||||
|
rt_thread_resume(thread);
|
||||||
|
|
||||||
|
/* enable interrupt */
|
||||||
|
rt_hw_interrupt_enable(temp);
|
||||||
|
}
|
||||||
|
rt_exit_critical();
|
||||||
|
|
||||||
|
rt_schedule();
|
||||||
|
}
|
||||||
|
RTM_EXPORT(rt_data_queue_reset);
|
||||||
|
@ -42,7 +42,8 @@ static rt_size_t rt_pipe_read(rt_device_t dev,
|
|||||||
{
|
{
|
||||||
rt_thread_suspend(thread);
|
rt_thread_suspend(thread);
|
||||||
/* waiting on suspended read list */
|
/* waiting on suspended read list */
|
||||||
rt_list_insert_before(&(pipe->suspended_read_list), &(thread->tlist));
|
rt_list_insert_before(&(pipe->suspended_read_list),
|
||||||
|
&(thread->tlist));
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
rt_schedule();
|
rt_schedule();
|
||||||
@ -52,8 +53,9 @@ static rt_size_t rt_pipe_read(rt_device_t dev,
|
|||||||
if (!rt_list_isempty(&pipe->suspended_write_list))
|
if (!rt_list_isempty(&pipe->suspended_write_list))
|
||||||
{
|
{
|
||||||
/* get suspended thread */
|
/* get suspended thread */
|
||||||
thread = rt_list_entry(pipe->suspended_write_list.next,
|
thread = rt_list_entry(pipe->suspended_write_list.next,
|
||||||
struct rt_thread, tlist);
|
struct rt_thread,
|
||||||
|
tlist);
|
||||||
|
|
||||||
/* resume the write thread */
|
/* resume the write thread */
|
||||||
rt_thread_resume(thread);
|
rt_thread_resume(thread);
|
||||||
@ -102,7 +104,8 @@ static rt_size_t rt_pipe_write(rt_device_t dev,
|
|||||||
/* pipe full, waiting on suspended write list */
|
/* pipe full, waiting on suspended write list */
|
||||||
rt_thread_suspend(thread);
|
rt_thread_suspend(thread);
|
||||||
/* waiting on suspended read list */
|
/* waiting on suspended read list */
|
||||||
rt_list_insert_before(&(pipe->suspended_write_list), &(thread->tlist));
|
rt_list_insert_before(&(pipe->suspended_write_list),
|
||||||
|
&(thread->tlist));
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
rt_schedule();
|
rt_schedule();
|
||||||
@ -113,7 +116,8 @@ static rt_size_t rt_pipe_write(rt_device_t dev,
|
|||||||
{
|
{
|
||||||
/* get suspended thread */
|
/* get suspended thread */
|
||||||
thread = rt_list_entry(pipe->suspended_read_list.next,
|
thread = rt_list_entry(pipe->suspended_read_list.next,
|
||||||
struct rt_thread, tlist);
|
struct rt_thread,
|
||||||
|
tlist);
|
||||||
|
|
||||||
/* resume the read thread */
|
/* resume the read thread */
|
||||||
rt_thread_resume(thread);
|
rt_thread_resume(thread);
|
||||||
@ -158,7 +162,7 @@ rt_err_t rt_pipe_create(const char *name, rt_size_t size)
|
|||||||
/* initialize suspended list */
|
/* initialize suspended list */
|
||||||
rt_list_init(&pipe->suspended_read_list);
|
rt_list_init(&pipe->suspended_read_list);
|
||||||
rt_list_init(&pipe->suspended_write_list);
|
rt_list_init(&pipe->suspended_write_list);
|
||||||
|
|
||||||
/* initialize ring buffer */
|
/* initialize ring buffer */
|
||||||
rt_ringbuffer_init(&pipe->ringbuffer, rb_memptr, size);
|
rt_ringbuffer_init(&pipe->ringbuffer, rb_memptr, size);
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb,
|
|||||||
rt_uint16_t size;
|
rt_uint16_t size;
|
||||||
rt_uint16_t mask;
|
rt_uint16_t mask;
|
||||||
rt_uint16_t write_position;
|
rt_uint16_t write_position;
|
||||||
|
|
||||||
RT_ASSERT(rb != RT_NULL);
|
RT_ASSERT(rb != RT_NULL);
|
||||||
|
|
||||||
mask = rb->buffer_size - 1;
|
mask = rb->buffer_size - 1;
|
||||||
@ -60,9 +60,11 @@ rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memcpy(&rb->buffer_ptr[write_position], ptr,
|
memcpy(&rb->buffer_ptr[write_position],
|
||||||
|
ptr,
|
||||||
rb->buffer_size - write_position);
|
rb->buffer_size - write_position);
|
||||||
memcpy(&rb->buffer_ptr[0], &ptr[rb->buffer_size - write_position],
|
memcpy(&rb->buffer_ptr[0],
|
||||||
|
&ptr[rb->buffer_size - write_position],
|
||||||
length - (rb->buffer_size - write_position));
|
length - (rb->buffer_size - write_position));
|
||||||
}
|
}
|
||||||
rb->write_index += length;
|
rb->write_index += length;
|
||||||
@ -126,9 +128,11 @@ rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* copy first and second */
|
/* copy first and second */
|
||||||
memcpy(ptr, &rb->buffer_ptr[read_position],
|
memcpy(ptr,
|
||||||
|
&rb->buffer_ptr[read_position],
|
||||||
rb->buffer_size - read_position);
|
rb->buffer_size - read_position);
|
||||||
memcpy(&ptr[rb->buffer_size - read_position], &rb->buffer_ptr[0],
|
memcpy(&ptr[rb->buffer_size - read_position],
|
||||||
|
&rb->buffer_ptr[0],
|
||||||
length - rb->buffer_size + read_position);
|
length - rb->buffer_size + read_position);
|
||||||
}
|
}
|
||||||
rb->read_index += length;
|
rb->read_index += length;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user