mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-09 20:45:41 +08:00
[DeviceDrivers] change cmd type.
1. Change 'rt_uint8_t' type of cmd to 'int'; 2. Add waitqueue; 3. Split device ipc header files;
This commit is contained in:
1 parent
0f5a68a55e
commit
d7087fdd3b
33 files changed
+1230
-785
No files matched your search
@@ -293,7 +293,7 @@ static rt_size_t _audio_dev_write(struct rt_device *dev, rt_off_t pos, const voi
|
||||
return size;
|
||||
}
|
||||
|
||||
static rt_err_t _audio_dev_control(struct rt_device *dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t _audio_dev_control(struct rt_device *dev, int cmd, void *args)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
struct rt_audio_device *audio;
|
||||
|
||||
@@ -206,7 +206,7 @@ static rt_size_t rt_hwtimer_write(struct rt_device *dev, rt_off_t pos, const voi
|
||||
return size;
|
||||
}
|
||||
|
||||
static rt_err_t rt_hwtimer_control(struct rt_device *dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t rt_hwtimer_control(struct rt_device *dev, int cmd, void *args)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
rt_hwtimer_t *timer;
|
||||
|
||||
@@ -47,7 +47,7 @@ static rt_err_t fm24clxx_close(rt_device_t dev)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t fm24clxx_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t fm24clxx_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ static rt_size_t i2c_bus_device_write(rt_device_t dev,
|
||||
}
|
||||
|
||||
static rt_err_t i2c_bus_device_control(rt_device_t dev,
|
||||
rt_uint8_t cmd,
|
||||
int cmd,
|
||||
void *args)
|
||||
{
|
||||
rt_err_t ret;
|
||||
|
||||
@@ -76,7 +76,7 @@ struct rt_alarm_container
|
||||
|
||||
rt_alarm_t rt_alarm_create(rt_alarm_callback_t callback,
|
||||
struct rt_alarm_setup *setup);
|
||||
rt_err_t rt_alarm_control(rt_alarm_t alarm, rt_uint8_t cmd, void *arg);
|
||||
rt_err_t rt_alarm_control(rt_alarm_t alarm, int cmd, void *arg);
|
||||
void rt_alarm_update(rt_device_t dev, rt_uint32_t event);
|
||||
rt_err_t rt_alarm_delete(rt_alarm_t alarm);
|
||||
rt_err_t rt_alarm_start(rt_alarm_t alarm);
|
||||
|
||||
@@ -159,7 +159,7 @@ struct rt_audio_ops
|
||||
rt_err_t (*suspend) (struct rt_audio_device *audio,int stream);
|
||||
rt_err_t (*resume) (struct rt_audio_device *audio,int stream);
|
||||
|
||||
rt_err_t (*control) (struct rt_audio_device *audio, rt_uint8_t cmd, void *arg);
|
||||
rt_err_t (*control) (struct rt_audio_device *audio, int cmd, void *arg);
|
||||
rt_size_t (*transmit) (struct rt_audio_device *audio, const void *writeBuf,void *readBuf, rt_size_t size);
|
||||
|
||||
//get page size of codec or private buffer's info
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef COMPLETION_H_
|
||||
#define COMPLETION_H_
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
/**
|
||||
* Completion
|
||||
*/
|
||||
|
||||
struct rt_completion
|
||||
{
|
||||
rt_uint32_t flag;
|
||||
|
||||
/* suspended list */
|
||||
rt_list_t suspended_list;
|
||||
};
|
||||
|
||||
void rt_completion_init(struct rt_completion *completion);
|
||||
rt_err_t rt_completion_wait(struct rt_completion *completion,
|
||||
rt_int32_t timeout);
|
||||
void rt_completion_done(struct rt_completion *completion);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef DATAQUEUE_H__
|
||||
#define DATAQUEUE_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#define RT_DATAQUEUE_EVENT_UNKNOWN 0x00
|
||||
#define RT_DATAQUEUE_EVENT_POP 0x01
|
||||
#define RT_DATAQUEUE_EVENT_PUSH 0x02
|
||||
#define RT_DATAQUEUE_EVENT_LWM 0x03
|
||||
|
||||
struct rt_data_item;
|
||||
#define RT_DATAQUEUE_SIZE(dq) ((dq)->put_index - (dq)->get_index)
|
||||
#define RT_DATAQUEUE_EMPTY(dq) ((dq)->size - RT_DATAQUEUE_SIZE(dq))
|
||||
/* data queue implementation */
|
||||
struct rt_data_queue
|
||||
{
|
||||
rt_uint16_t size;
|
||||
rt_uint16_t lwm;
|
||||
rt_bool_t waiting_lwm;
|
||||
|
||||
rt_uint16_t get_index;
|
||||
rt_uint16_t put_index;
|
||||
|
||||
struct rt_data_item *queue;
|
||||
|
||||
rt_list_t suspended_push_list;
|
||||
rt_list_t suspended_pop_list;
|
||||
|
||||
/* event notify */
|
||||
void (*evt_notify)(struct rt_data_queue *queue, rt_uint32_t event);
|
||||
};
|
||||
|
||||
/**
|
||||
* DataQueue for DeviceDriver
|
||||
*/
|
||||
rt_err_t rt_data_queue_init(struct rt_data_queue *queue,
|
||||
rt_uint16_t size,
|
||||
rt_uint16_t lwm,
|
||||
void (*evt_notify)(struct rt_data_queue *queue, rt_uint32_t event));
|
||||
rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
|
||||
const void *data_ptr,
|
||||
rt_size_t data_size,
|
||||
rt_int32_t timeout);
|
||||
rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
|
||||
const void **data_ptr,
|
||||
rt_size_t *size,
|
||||
rt_int32_t timeout);
|
||||
rt_err_t rt_data_queue_peak(struct rt_data_queue *queue,
|
||||
const void **data_ptr,
|
||||
rt_size_t *size);
|
||||
void rt_data_queue_reset(struct rt_data_queue *queue);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef PIPE_H__
|
||||
#define PIPE_H__
|
||||
|
||||
/**
|
||||
* Pipe Device
|
||||
*/
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#ifndef RT_PIPE_BUFSZ
|
||||
#define PIPE_BUFSZ 512
|
||||
#else
|
||||
#define PIPE_BUFSZ RT_PIPE_BUFSZ
|
||||
#endif
|
||||
|
||||
struct rt_pipe_device
|
||||
{
|
||||
struct rt_device parent;
|
||||
|
||||
/* ring buffer in pipe device */
|
||||
struct rt_ringbuffer *fifo;
|
||||
|
||||
rt_uint8_t readers;
|
||||
rt_uint8_t writers;
|
||||
|
||||
rt_wqueue_t reader_queue;
|
||||
rt_wqueue_t writer_queue;
|
||||
|
||||
struct rt_mutex lock;
|
||||
};
|
||||
typedef struct rt_pipe_device rt_pipe_t;
|
||||
|
||||
rt_pipe_t *rt_pipe_create(const char *name);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* File : poll.h
|
||||
* This file is part of Device File System in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006-2017, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2016-09-19 Heyuanjie The first version.
|
||||
* 2016-12-26 Bernard Update poll interface
|
||||
*/
|
||||
#ifndef IPC_POLL_H__
|
||||
#define IPC_POLL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct rt_pollreq;
|
||||
typedef void (*poll_queue_proc)(rt_wqueue_t *, struct rt_pollreq *);
|
||||
|
||||
typedef struct rt_pollreq
|
||||
{
|
||||
poll_queue_proc _proc;
|
||||
short _key;
|
||||
} rt_pollreq_t;
|
||||
|
||||
rt_inline void rt_poll_add(rt_wqueue_t *wq, rt_pollreq_t *req)
|
||||
{
|
||||
if (req && req->_proc && wq)
|
||||
{
|
||||
req->_proc(wq, req);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,88 @@
|
||||
#ifndef RINGBUFFER_H__
|
||||
#define RINGBUFFER_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
/* ring buffer */
|
||||
struct rt_ringbuffer
|
||||
{
|
||||
rt_uint8_t *buffer_ptr;
|
||||
/* use the msb of the {read,write}_index as mirror bit. You can see this as
|
||||
* if the buffer adds a virtual mirror and the pointers point either to the
|
||||
* normal or to the mirrored buffer. If the write_index has the same value
|
||||
* with the read_index, but in a different mirror, the buffer is full.
|
||||
* While if the write_index and the read_index are the same and within the
|
||||
* same mirror, the buffer is empty. The ASCII art of the ringbuffer is:
|
||||
*
|
||||
* mirror = 0 mirror = 1
|
||||
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
|
||||
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 ||| 0 | 1 | 2 | 3 | 4 | 5 | 6 | Full
|
||||
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
|
||||
* read_idx-^ write_idx-^
|
||||
*
|
||||
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
|
||||
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 ||| 0 | 1 | 2 | 3 | 4 | 5 | 6 | Empty
|
||||
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
|
||||
* read_idx-^ ^-write_idx
|
||||
*
|
||||
* The tradeoff is we could only use 32KiB of buffer for 16 bit of index.
|
||||
* But it should be enough for most of the cases.
|
||||
*
|
||||
* Ref: http://en.wikipedia.org/wiki/Circular_buffer#Mirroring */
|
||||
rt_uint16_t read_mirror : 1;
|
||||
rt_uint16_t read_index : 15;
|
||||
rt_uint16_t write_mirror : 1;
|
||||
rt_uint16_t write_index : 15;
|
||||
/* as we use msb of index as mirror bit, the size should be signed and
|
||||
* could only be positive. */
|
||||
rt_int16_t buffer_size;
|
||||
};
|
||||
|
||||
enum rt_ringbuffer_state
|
||||
{
|
||||
RT_RINGBUFFER_EMPTY,
|
||||
RT_RINGBUFFER_FULL,
|
||||
/* half full is neither full nor empty */
|
||||
RT_RINGBUFFER_HALFFULL,
|
||||
};
|
||||
|
||||
/**
|
||||
* RingBuffer for DeviceDriver
|
||||
*
|
||||
* Please note that the ring buffer implementation of RT-Thread
|
||||
* has no thread wait or resume feature.
|
||||
*/
|
||||
void rt_ringbuffer_init(struct rt_ringbuffer *rb, rt_uint8_t *pool, rt_int16_t size);
|
||||
void rt_ringbuffer_reset(struct rt_ringbuffer *rb);
|
||||
rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, rt_uint16_t length);
|
||||
rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, rt_uint16_t length);
|
||||
rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch);
|
||||
rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t ch);
|
||||
rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, rt_uint8_t *ptr, rt_uint16_t length);
|
||||
rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch);
|
||||
rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb);
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
struct rt_ringbuffer* rt_ringbuffer_create(rt_uint16_t length);
|
||||
void rt_ringbuffer_destroy(struct rt_ringbuffer *rb);
|
||||
#endif
|
||||
|
||||
rt_inline rt_uint16_t rt_ringbuffer_get_size(struct rt_ringbuffer *rb)
|
||||
{
|
||||
RT_ASSERT(rb != RT_NULL);
|
||||
return rb->buffer_size;
|
||||
}
|
||||
|
||||
/** return the size of empty space in rb */
|
||||
#define rt_ringbuffer_space_len(rb) ((rb)->buffer_size - rt_ringbuffer_data_len(rb))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef WAITQUEUE_H__
|
||||
#define WAITQUEUE_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
struct rt_wqueue_node;
|
||||
|
||||
typedef rt_list_t rt_wqueue_t;
|
||||
typedef int (*rt_wqueue_func_t)(struct rt_wqueue_node *wait, void *key);
|
||||
|
||||
struct rt_wqueue_node
|
||||
{
|
||||
rt_thread_t polling_thread;
|
||||
rt_list_t list;
|
||||
|
||||
rt_wqueue_func_t wakeup;
|
||||
rt_uint32_t key;
|
||||
};
|
||||
typedef struct rt_wqueue_node rt_wqueue_node_t;
|
||||
|
||||
int __wqueue_default_wake(struct rt_wqueue_node *wait, void *key);
|
||||
|
||||
void rt_wqueue_add(rt_wqueue_t *queue, struct rt_wqueue_node *node);
|
||||
void rt_wqueue_remove(struct rt_wqueue_node *node);
|
||||
int rt_wqueue_wait(rt_wqueue_t *queue, int condition, int timeout);
|
||||
void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key);
|
||||
|
||||
#define DEFINE_WAIT_FUNC(name, function) \
|
||||
struct rt_wqueue_node name = { \
|
||||
rt_current_thread, \
|
||||
RT_LIST_OBJECT_INIT(((name).list)), \
|
||||
\
|
||||
function, \
|
||||
0 \
|
||||
}
|
||||
|
||||
#define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, __wqueue_default_wake)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef WORKQUEUE_H__
|
||||
#define WORKQUEUE_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
/* workqueue implementation */
|
||||
struct rt_workqueue
|
||||
{
|
||||
rt_list_t work_list;
|
||||
struct rt_work *work_current; /* current work */
|
||||
rt_thread_t work_thread;
|
||||
};
|
||||
|
||||
struct rt_work
|
||||
{
|
||||
rt_list_t list;
|
||||
|
||||
void (*work_func)(struct rt_work* work, void* work_data);
|
||||
void *work_data;
|
||||
};
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
/**
|
||||
* WorkQueue for DeviceDriver
|
||||
*/
|
||||
struct rt_workqueue *rt_workqueue_create(const char* name, rt_uint16_t stack_size, rt_uint8_t priority);
|
||||
rt_err_t rt_workqueue_destroy(struct rt_workqueue* queue);
|
||||
rt_err_t rt_workqueue_dowork(struct rt_workqueue* queue, struct rt_work* work);
|
||||
rt_err_t rt_workqueue_cancel_work(struct rt_workqueue* queue, struct rt_work* work);
|
||||
|
||||
rt_inline void rt_work_init(struct rt_work* work, void (*work_func)(struct rt_work* work, void* work_data),
|
||||
void* work_data)
|
||||
{
|
||||
rt_list_init(&(work->list));
|
||||
work->work_func = work_func;
|
||||
work->work_data = work_data;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -60,7 +60,7 @@ static rt_size_t _pin_write(rt_device_t dev, rt_off_t pos, const void *buffer, r
|
||||
return size;
|
||||
}
|
||||
|
||||
static rt_err_t _pin_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t _pin_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
struct rt_device_pin_mode *mode;
|
||||
struct rt_device_pin *pin = (struct rt_device_pin *)dev;
|
||||
|
||||
@@ -64,7 +64,7 @@ static rt_size_t _mtd_write(rt_device_t dev,
|
||||
return size;
|
||||
}
|
||||
|
||||
static rt_err_t _mtd_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t _mtd_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ static rt_size_t _mtd_write(rt_device_t dev,
|
||||
return size;
|
||||
}
|
||||
|
||||
static rt_err_t _mtd_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t _mtd_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
@@ -397,7 +397,7 @@ void rt_alarm_update(rt_device_t dev, rt_uint32_t event)
|
||||
* \param cmd control command
|
||||
* \param arg argument
|
||||
*/
|
||||
rt_err_t rt_alarm_control(rt_alarm_t alarm, rt_uint8_t cmd, void *arg)
|
||||
rt_err_t rt_alarm_control(rt_alarm_t alarm, int cmd, void *arg)
|
||||
{
|
||||
rt_err_t ret = RT_ERROR;
|
||||
|
||||
|
||||
@@ -222,7 +222,7 @@ static rt_err_t rt_mmcsd_close(rt_device_t dev)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t rt_mmcsd_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t rt_mmcsd_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
struct mmcsd_blk_device *blk_dev = (struct mmcsd_blk_device *)dev->user_data;
|
||||
switch (cmd)
|
||||
@@ -247,7 +247,7 @@ static rt_size_t rt_mmcsd_read(rt_device_t dev,
|
||||
|
||||
if (dev == RT_NULL)
|
||||
{
|
||||
rt_set_errno(-DFS_STATUS_EINVAL);
|
||||
rt_set_errno(-EINVAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -259,7 +259,7 @@ static rt_size_t rt_mmcsd_read(rt_device_t dev,
|
||||
/* the length of reading must align to SECTOR SIZE */
|
||||
if (err)
|
||||
{
|
||||
rt_set_errno(-DFS_STATUS_EIO);
|
||||
rt_set_errno(-EIO);
|
||||
return 0;
|
||||
}
|
||||
return size;
|
||||
@@ -276,7 +276,7 @@ static rt_size_t rt_mmcsd_write(rt_device_t dev,
|
||||
|
||||
if (dev == RT_NULL)
|
||||
{
|
||||
rt_set_errno(-DFS_STATUS_EINVAL);
|
||||
rt_set_errno(-EINVAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -288,7 +288,7 @@ static rt_size_t rt_mmcsd_write(rt_device_t dev,
|
||||
/* the length of reading must align to SECTOR SIZE */
|
||||
if (err)
|
||||
{
|
||||
rt_set_errno(-DFS_STATUS_EIO);
|
||||
rt_set_errno(-EIO);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -343,7 +343,7 @@ static rt_err_t enc28j60_init(rt_device_t dev)
|
||||
}
|
||||
|
||||
/* control the interface */
|
||||
static rt_err_t enc28j60_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t enc28j60_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
struct net_device * enc28j60 = (struct net_device *)dev;
|
||||
switch(cmd)
|
||||
|
||||
@@ -54,7 +54,7 @@ static rt_size_t _spi_bus_device_write(rt_device_t dev,
|
||||
}
|
||||
|
||||
static rt_err_t _spi_bus_device_control(rt_device_t dev,
|
||||
rt_uint8_t cmd,
|
||||
int cmd,
|
||||
void *args)
|
||||
{
|
||||
/* TODO: add control command handle */
|
||||
@@ -120,7 +120,7 @@ static rt_size_t _spidev_device_write(rt_device_t dev,
|
||||
}
|
||||
|
||||
static rt_err_t _spidev_device_control(rt_device_t dev,
|
||||
rt_uint8_t cmd,
|
||||
int cmd,
|
||||
void *args)
|
||||
{
|
||||
switch (cmd)
|
||||
|
||||
@@ -117,7 +117,7 @@ static rt_err_t AT45DB_flash_close(rt_device_t dev)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t AT45DB_flash_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t AT45DB_flash_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ static rt_err_t w25qxx_flash_close(rt_device_t dev)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t w25qxx_flash_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t w25qxx_flash_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ static char log_buf[RT_CONSOLEBUF_SIZE];
|
||||
|
||||
void sfud_log_debug(const char *file, const long line, const char *format, ...);
|
||||
|
||||
static rt_err_t rt_sfud_control(rt_device_t dev, rt_uint8_t cmd, void *args) {
|
||||
static rt_err_t rt_sfud_control(rt_device_t dev, int cmd, void *args) {
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
|
||||
switch (cmd) {
|
||||
|
||||
@@ -173,7 +173,7 @@ static rt_err_t sst25vfxx_flash_close(rt_device_t dev)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t sst25vfxx_flash_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t sst25vfxx_flash_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
struct spi_flash_sst25vfxx * spi_flash;
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ static rt_err_t w25qxx_flash_close(rt_device_t dev)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t w25qxx_flash_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t w25qxx_flash_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
|
||||
|
||||
@@ -530,7 +530,7 @@ static rt_size_t rw009_wifi_write(rt_device_t dev, rt_off_t pos, const void *buf
|
||||
return 0;
|
||||
}
|
||||
|
||||
static rt_err_t rw009_wifi_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t rw009_wifi_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
struct rw009_wifi *wifi_device = (struct rw009_wifi *)dev;
|
||||
rt_err_t result = RT_EOK;
|
||||
|
||||
+353
-219
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -21,18 +21,31 @@
|
||||
* Date Author Notes
|
||||
* 2012-09-30 Bernard first version.
|
||||
* 2013-05-08 Grissiom reimplement
|
||||
* 2016-08-18 heyuanjie add interface
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include <string.h>
|
||||
|
||||
rt_inline enum rt_ringbuffer_state rt_ringbuffer_status(struct rt_ringbuffer *rb)
|
||||
{
|
||||
if (rb->read_index == rb->write_index)
|
||||
{
|
||||
if (rb->read_mirror == rb->write_mirror)
|
||||
return RT_RINGBUFFER_EMPTY;
|
||||
else
|
||||
return RT_RINGBUFFER_FULL;
|
||||
}
|
||||
return RT_RINGBUFFER_HALFFULL;
|
||||
}
|
||||
|
||||
void rt_ringbuffer_init(struct rt_ringbuffer *rb,
|
||||
rt_uint8_t *pool,
|
||||
rt_int16_t size)
|
||||
{
|
||||
RT_ASSERT(rb != RT_NULL);
|
||||
RT_ASSERT(size > 0)
|
||||
RT_ASSERT(size > 0);
|
||||
|
||||
/* initialize read and write index */
|
||||
rb->read_mirror = rb->read_index = 0;
|
||||
@@ -284,3 +297,76 @@ rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch)
|
||||
}
|
||||
RTM_EXPORT(rt_ringbuffer_getchar);
|
||||
|
||||
/**
|
||||
* get the size of data in rb
|
||||
*/
|
||||
rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb)
|
||||
{
|
||||
switch (rt_ringbuffer_status(rb))
|
||||
{
|
||||
case RT_RINGBUFFER_EMPTY:
|
||||
return 0;
|
||||
case RT_RINGBUFFER_FULL:
|
||||
return rb->buffer_size;
|
||||
case RT_RINGBUFFER_HALFFULL:
|
||||
default:
|
||||
if (rb->write_index > rb->read_index)
|
||||
return rb->write_index - rb->read_index;
|
||||
else
|
||||
return rb->buffer_size - (rb->read_index - rb->write_index);
|
||||
};
|
||||
}
|
||||
RTM_EXPORT(rt_ringbuffer_data_len);
|
||||
|
||||
/**
|
||||
* empty the rb
|
||||
*/
|
||||
void rt_ringbuffer_reset(struct rt_ringbuffer *rb)
|
||||
{
|
||||
RT_ASSERT(rb != RT_NULL);
|
||||
|
||||
rb->read_mirror = 0;
|
||||
rb->read_index = 0;
|
||||
rb->write_mirror = 0;
|
||||
rb->write_index = 0;
|
||||
}
|
||||
RTM_EXPORT(rt_ringbuffer_reset);
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
|
||||
struct rt_ringbuffer* rt_ringbuffer_create(rt_uint16_t size)
|
||||
{
|
||||
struct rt_ringbuffer *rb;
|
||||
rt_uint8_t *pool;
|
||||
|
||||
RT_ASSERT(size > 0);
|
||||
|
||||
size = RT_ALIGN_DOWN(size, RT_ALIGN_SIZE);
|
||||
|
||||
rb = rt_malloc(sizeof(struct rt_ringbuffer));
|
||||
if (rb == RT_NULL)
|
||||
goto exit;
|
||||
|
||||
pool = rt_malloc(size);
|
||||
if (pool == RT_NULL)
|
||||
{
|
||||
rt_free(rb);
|
||||
goto exit;
|
||||
}
|
||||
rt_ringbuffer_init(rb, pool, size);
|
||||
|
||||
exit:
|
||||
return rb;
|
||||
}
|
||||
RTM_EXPORT(rt_ringbuffer_create);
|
||||
|
||||
void rt_ringbuffer_destroy(struct rt_ringbuffer *rb)
|
||||
{
|
||||
RT_ASSERT(rb != RT_NULL);
|
||||
|
||||
rt_free(rb->buffer_ptr);
|
||||
rt_free(rb);
|
||||
}
|
||||
RTM_EXPORT(rt_ringbuffer_destroy);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,101 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtdevice.h>
|
||||
#include <rtservice.h>
|
||||
|
||||
extern struct rt_thread *rt_current_thread;
|
||||
|
||||
void rt_wqueue_add(rt_wqueue_t *queue, struct rt_wqueue_node *node)
|
||||
{
|
||||
rt_base_t level;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
rt_list_insert_before(queue, &(node->list));
|
||||
rt_hw_interrupt_enable(level);
|
||||
}
|
||||
|
||||
void rt_wqueue_remove(struct rt_wqueue_node *node)
|
||||
{
|
||||
rt_base_t level;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
rt_list_remove(&(node->list));
|
||||
rt_hw_interrupt_enable(level);
|
||||
}
|
||||
|
||||
int __wqueue_default_wake(struct rt_wqueue_node *wait, void *key)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key)
|
||||
{
|
||||
rt_base_t level;
|
||||
register int need_schedule = 0;
|
||||
|
||||
struct rt_list_node *node;
|
||||
struct rt_wqueue_node *entry;
|
||||
|
||||
if (rt_list_isempty(queue))
|
||||
return;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
for (node = queue->next; node != queue; node = node->next)
|
||||
{
|
||||
entry = rt_list_entry(node, struct rt_wqueue_node, list);
|
||||
if (entry->wakeup(entry, key) == 0)
|
||||
{
|
||||
rt_thread_resume(entry->polling_thread);
|
||||
need_schedule = 1;
|
||||
|
||||
rt_wqueue_remove(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
if (need_schedule)
|
||||
rt_schedule();
|
||||
}
|
||||
|
||||
int rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec)
|
||||
{
|
||||
int tick;
|
||||
rt_thread_t tid = rt_current_thread;
|
||||
rt_timer_t tmr = &(tid->thread_timer);
|
||||
struct rt_wqueue_node __wait;
|
||||
|
||||
tick = rt_tick_from_millisecond(msec);
|
||||
|
||||
if ((condition) || (tick == 0))
|
||||
return 0;
|
||||
|
||||
__wait.polling_thread = rt_thread_self();
|
||||
__wait.key = 0;
|
||||
__wait.wakeup = __wqueue_default_wake;
|
||||
rt_list_init(&__wait.list);
|
||||
|
||||
rt_wqueue_add(queue, &__wait);
|
||||
|
||||
/* current context checking */
|
||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||
rt_thread_suspend(tid);
|
||||
|
||||
/* start timer */
|
||||
if (tick != RT_WAITING_FOREVER)
|
||||
{
|
||||
rt_timer_control(tmr,
|
||||
RT_TIMER_CTRL_SET_TIME,
|
||||
&tick);
|
||||
|
||||
rt_timer_start(tmr);
|
||||
}
|
||||
|
||||
rt_schedule();
|
||||
|
||||
rt_wqueue_remove(&__wait);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ static rt_err_t rt_watchdog_close(struct rt_device *dev)
|
||||
}
|
||||
|
||||
static rt_err_t rt_watchdog_control(struct rt_device *dev,
|
||||
rt_uint8_t cmd,
|
||||
int cmd,
|
||||
void *args)
|
||||
{
|
||||
rt_watchdog_t *wtd;
|
||||
|
||||
Reference in new issue
Block a user