diff options
| author | WBI\nxf44444 <[email protected]> | 2020-10-26 14:58:46 +0800 |
|---|---|---|
| committer | WBI\nxf44444 <[email protected]> | 2020-10-26 14:58:46 +0800 |
| commit | 102976e89f2d5f004dbad25ad42a0dc659294ed2 (patch) | |
| tree | 0d9da35d5b46a075a5ddc36d732a66e8a080b5ce /components/drivers/src | |
| parent | 6bc3301e0880703b7889d69f262f7e633c951737 (diff) | |
| parent | 877921f10bd2904c8e683f0df7a4d2596e3e64ba (diff) | |
note
Diffstat (limited to 'components/drivers/src')
| -rw-r--r-- | components/drivers/src/dataqueue.c | 36 | ||||
| -rw-r--r-- | components/drivers/src/pipe.c | 15 |
2 files changed, 46 insertions, 5 deletions
diff --git a/components/drivers/src/dataqueue.c b/components/drivers/src/dataqueue.c index 7553986b9f..ba4a921da0 100644 --- a/components/drivers/src/dataqueue.c +++ b/components/drivers/src/dataqueue.c @@ -13,6 +13,8 @@ #include <rtdevice.h> #include <rthw.h> +#define DATAQUEUE_MAGIC 0xbead0e0e + struct rt_data_item { const void *data_ptr; @@ -26,9 +28,11 @@ rt_data_queue_init(struct rt_data_queue *queue, void (*evt_notify)(struct rt_data_queue *queue, rt_uint32_t event)) { RT_ASSERT(queue != RT_NULL); + RT_ASSERT((0x10000 % size) == 0); queue->evt_notify = evt_notify; + queue->magic = DATAQUEUE_MAGIC; queue->size = size; queue->lwm = lwm; @@ -57,6 +61,7 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue, rt_thread_t thread; rt_err_t result; + RT_ASSERT(queue->magic == DATAQUEUE_MAGIC); RT_ASSERT(queue != RT_NULL); result = RT_EOK; @@ -145,7 +150,8 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue, rt_ubase_t level; rt_thread_t thread; rt_err_t result; - + + RT_ASSERT(queue->magic == DATAQUEUE_MAGIC); RT_ASSERT(queue != RT_NULL); RT_ASSERT(data_ptr != RT_NULL); RT_ASSERT(size != RT_NULL); @@ -244,7 +250,8 @@ rt_err_t rt_data_queue_peak(struct rt_data_queue *queue, rt_size_t *size) { rt_ubase_t level; - + + RT_ASSERT(queue->magic == DATAQUEUE_MAGIC); RT_ASSERT(queue != RT_NULL); level = rt_hw_interrupt_disable(); @@ -269,7 +276,9 @@ void rt_data_queue_reset(struct rt_data_queue *queue) { struct rt_thread *thread; register rt_ubase_t temp; - + + RT_ASSERT(queue->magic == DATAQUEUE_MAGIC); + rt_enter_critical(); /* wakeup all suspend threads */ @@ -325,3 +334,24 @@ void rt_data_queue_reset(struct rt_data_queue *queue) rt_schedule(); } RTM_EXPORT(rt_data_queue_reset); + +rt_err_t rt_data_queue_deinit(struct rt_data_queue *queue) +{ + rt_ubase_t level; + + RT_ASSERT(queue->magic == DATAQUEUE_MAGIC); + RT_ASSERT(queue != RT_NULL); + + level = rt_hw_interrupt_disable(); + + /* wakeup all suspend threads */ + rt_data_queue_reset(queue); + + queue->magic = 0; + rt_free(queue->queue); + + rt_hw_interrupt_enable(level); + + return RT_EOK; +} +RTM_EXPORT(rt_data_queue_deinit); diff --git a/components/drivers/src/pipe.c b/components/drivers/src/pipe.c index ae87b6f5f2..2a7e143f6c 100644 --- a/components/drivers/src/pipe.c +++ b/components/drivers/src/pipe.c @@ -323,18 +323,29 @@ static const struct dfs_file_ops pipe_fops = rt_err_t rt_pipe_open (rt_device_t device, rt_uint16_t oflag) { rt_pipe_t *pipe = (rt_pipe_t *)device; + rt_err_t ret = RT_EOK; - if (device == RT_NULL) return -RT_EINVAL; + if (device == RT_NULL) + { + ret = -RT_EINVAL; + goto __exit; + } + rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER); if (pipe->fifo == RT_NULL) { pipe->fifo = rt_ringbuffer_create(pipe->bufsz); + if (pipe->fifo == RT_NULL) + { + ret = -RT_ENOMEM; + } } rt_mutex_release(&(pipe->lock)); - return RT_EOK; +__exit: + return ret; } rt_err_t rt_pipe_close (rt_device_t device) |
