summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2021-03-02 15:00:43 +0800
committerGitHub <[email protected]>2021-03-02 15:00:43 +0800
commit2c12493ff342ea9ba808311c3f6835eba31a8d3e (patch)
treeb1e1dfbeaead7c08ab8d7d0f34066154c125841b /components/drivers
parent5f17cf9204e501d971cd28486e0a7193d2f1fae4 (diff)
parent19871ac32e41590b1f3e3742d9ab023dc3147ba0 (diff)
Merge pull request #4404 from KyleChenjh/lts-v3.1.x
[Update] Sync from v4.0.3
Diffstat (limited to 'components/drivers')
-rwxr-xr-xcomponents/drivers/Kconfig21
-rw-r--r--components/drivers/audio/audio.c14
-rw-r--r--components/drivers/audio/audio_pipe.c2
-rw-r--r--components/drivers/audio/audio_pipe.h5
-rw-r--r--components/drivers/can/can.c1
-rw-r--r--components/drivers/hwtimer/hwtimer.c10
-rw-r--r--components/drivers/i2c/i2c-bit-ops.c14
-rw-r--r--components/drivers/include/drivers/alarm.h9
-rw-r--r--components/drivers/include/drivers/i2c.h12
-rw-r--r--components/drivers/include/drivers/rt_inputcapture.h2
-rw-r--r--components/drivers/include/drivers/spi.h26
-rw-r--r--components/drivers/include/drivers/usb_common.h16
-rw-r--r--components/drivers/include/ipc/dataqueue.h16
-rw-r--r--components/drivers/include/ipc/ringbuffer.h1
-rw-r--r--components/drivers/sdio/block_dev.c2
-rw-r--r--components/drivers/sdio/mmc.c23
-rw-r--r--components/drivers/sdio/sd.c36
-rw-r--r--components/drivers/sdio/sdio.c6
-rw-r--r--components/drivers/sensors/SConscript2
-rw-r--r--components/drivers/sensors/sensor.c14
-rw-r--r--components/drivers/sensors/sensor.h2
-rw-r--r--components/drivers/serial/serial.c47
-rw-r--r--components/drivers/spi/sfud/inc/sfud_cfg.h12
-rw-r--r--components/drivers/spi/sfud/inc/sfud_flash_def.h13
-rw-r--r--components/drivers/spi/sfud/src/sfud.c2
-rw-r--r--components/drivers/spi/spi_flash_sfud.c132
-rw-r--r--components/drivers/spi/spi_flash_sfud.h13
-rw-r--r--components/drivers/spi/spi_msd.c10
-rw-r--r--components/drivers/src/dataqueue.c135
-rw-r--r--components/drivers/src/pipe.c15
-rw-r--r--components/drivers/src/ringbuffer.c34
-rw-r--r--components/drivers/src/workqueue.c2
-rw-r--r--components/drivers/touch/SConscript2
-rw-r--r--components/drivers/touch/touch.c26
-rw-r--r--components/drivers/touch/touch.h5
-rw-r--r--components/drivers/usb/usbdevice/SConscript2
-rw-r--r--components/drivers/usb/usbdevice/class/audio_mic.c3
-rw-r--r--components/drivers/usb/usbdevice/class/audio_speaker.c3
-rw-r--r--components/drivers/usb/usbdevice/class/cdc_vcom.c9
-rw-r--r--components/drivers/usb/usbdevice/class/ecm.c7
-rw-r--r--components/drivers/usb/usbdevice/class/hid.c23
-rw-r--r--components/drivers/usb/usbdevice/class/mstorage.c31
-rw-r--r--components/drivers/usb/usbdevice/class/winusb.c4
-rw-r--r--components/drivers/usb/usbdevice/core/usbdevice_core.c (renamed from components/drivers/usb/usbdevice/core/core.c)16
-rw-r--r--components/drivers/usb/usbhost/SConscript2
-rw-r--r--components/drivers/usb/usbhost/class/adk.h4
-rw-r--r--components/drivers/usb/usbhost/class/udisk.c2
-rw-r--r--components/drivers/usb/usbhost/core/hub.c16
-rw-r--r--components/drivers/usb/usbhost/core/usbhost_core.c (renamed from components/drivers/usb/usbhost/core/core.c)8
-rw-r--r--components/drivers/watchdog/watchdog.c2
-rw-r--r--components/drivers/wlan/wlan_dev.c6
-rw-r--r--components/drivers/wlan/wlan_mgnt.c2
52 files changed, 527 insertions, 295 deletions
diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig
index c567233c84..a966c7a412 100755
--- a/components/drivers/Kconfig
+++ b/components/drivers/Kconfig
@@ -89,18 +89,18 @@ config RT_USING_I2C
if RT_USING_I2C
config RT_I2C_DEBUG
- bool "Use I2C debug mesage"
+ bool "Use I2C debug message"
default n
config RT_USING_I2C_BITOPS
bool "Use GPIO to simulate I2C"
default y
-endif
-if RT_USING_I2C_BITOPS
- config RT_I2C_BITOPS_DEBUG
- bool "Use simulate I2C debug mesage"
- default n
+ if RT_USING_I2C_BITOPS
+ config RT_I2C_BITOPS_DEBUG
+ bool "Use simulate I2C debug message"
+ default n
+ endif
endif
config RT_USING_PIN
@@ -257,11 +257,11 @@ config RT_USING_AUDIO
if RT_USING_AUDIO
config RT_AUDIO_REPLAY_MP_BLOCK_SIZE
- int "Replay memmory pool block size"
+ int "Replay memory pool block size"
default 4096
config RT_AUDIO_REPLAY_MP_BLOCK_COUNT
- int "Replay memmory pool block count"
+ int "Replay memory pool block count"
default 2
config RT_AUDIO_RECORD_PIPE_SIZE
@@ -283,6 +283,11 @@ endif
config RT_USING_TOUCH
bool "Using Touch device drivers"
default n
+ if RT_USING_TOUCH
+ config RT_TOUCH_PIN_IRQ
+ bool "touch irq use pin irq"
+ default n
+ endif
menuconfig RT_USING_HWCRYPTO
bool "Using Hardware Crypto drivers"
diff --git a/components/drivers/audio/audio.c b/components/drivers/audio/audio.c
index 28ddf0fe56..c3f8723db6 100644
--- a/components/drivers/audio/audio.c
+++ b/components/drivers/audio/audio.c
@@ -12,14 +12,15 @@
#include <stdio.h>
#include <string.h>
#include <rthw.h>
-#include <rtthread.h>
#include <rtdevice.h>
#define DBG_TAG "audio"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
+#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
enum
{
@@ -33,7 +34,7 @@ static rt_err_t _audio_send_replay_frame(struct rt_audio_device *audio)
rt_err_t result = RT_EOK;
rt_uint8_t *data;
rt_size_t dst_size, src_size;
- rt_uint16_t position, remain_bytes, index = 0;
+ rt_uint16_t position, remain_bytes = 0, index = 0;
struct rt_audio_buf_info *buf_info;
RT_ASSERT(audio != RT_NULL);
@@ -43,8 +44,8 @@ static rt_err_t _audio_send_replay_frame(struct rt_audio_device *audio)
position = audio->replay->pos;
dst_size = buf_info->block_size;
- /* check repaly queue is empty */
- if (rt_data_queue_peak(&audio->replay->queue, (const void **)&data, &src_size) != RT_EOK)
+ /* check replay queue is empty */
+ if (rt_data_queue_peek(&audio->replay->queue, (const void **)&data, &src_size) != RT_EOK)
{
/* ack stop event */
if (audio->replay->event & REPLAY_EVT_STOP)
@@ -63,7 +64,7 @@ static rt_err_t _audio_send_replay_frame(struct rt_audio_device *audio)
/* copy data from memory pool to hardware device fifo */
while (index < dst_size)
{
- result = rt_data_queue_peak(&audio->replay->queue, (const void **)&data, &src_size);
+ result = rt_data_queue_peek(&audio->replay->queue, (const void **)&data, &src_size);
if (result != RT_EOK)
{
LOG_D("under run %d, remain %d", audio->replay->pos, remain_bytes);
@@ -235,7 +236,7 @@ static rt_err_t _audio_dev_init(struct rt_device *dev)
if (replay->mp == RT_NULL)
{
rt_free(replay);
- LOG_E("create memory pool for repaly failed");
+ LOG_E("create memory pool for replay failed");
return -RT_ENOMEM;
}
@@ -588,7 +589,6 @@ int rt_audio_samplerate_to_speed(rt_uint32_t bitValue)
speed = 192000;
break;
default:
-
break;
}
diff --git a/components/drivers/audio/audio_pipe.c b/components/drivers/audio/audio_pipe.c
index d7c37009b6..e9de1ffb74 100644
--- a/components/drivers/audio/audio_pipe.c
+++ b/components/drivers/audio/audio_pipe.c
@@ -9,9 +9,7 @@
*/
#include <rthw.h>
-#include <rtthread.h>
#include <rtdevice.h>
-
#include "audio_pipe.h"
static void _rt_pipe_resume_writer(struct rt_audio_pipe *pipe)
diff --git a/components/drivers/audio/audio_pipe.h b/components/drivers/audio/audio_pipe.h
index 85a3eb1793..3ae3bc8498 100644
--- a/components/drivers/audio/audio_pipe.h
+++ b/components/drivers/audio/audio_pipe.h
@@ -12,7 +12,6 @@
/**
* Pipe Device
*/
-#include <rtthread.h>
#include <rtdevice.h>
#ifndef RT_PIPE_BUFSZ
@@ -71,6 +70,6 @@ rt_err_t rt_audio_pipe_detach(struct rt_audio_pipe *pipe);
#ifdef RT_USING_HEAP
rt_err_t rt_audio_pipe_create(const char *name, rt_int32_t flag, rt_size_t size);
void rt_audio_pipe_destroy(struct rt_audio_pipe *pipe);
-#endif
-#endif
+#endif /* RT_USING_HEAP */
+#endif /* __AUDIO_PIPE_H__ */
diff --git a/components/drivers/can/can.c b/components/drivers/can/can.c
index 3d60dbaa55..9f4612355b 100644
--- a/components/drivers/can/can.c
+++ b/components/drivers/can/can.c
@@ -422,6 +422,7 @@ static rt_err_t rt_can_close(struct rt_device *dev)
tx_fifo = (struct rt_can_tx_fifo *)can->can_tx;
RT_ASSERT(tx_fifo != RT_NULL);
+ rt_sem_detach(&(tx_fifo->sem));
rt_free(tx_fifo);
dev->open_flag &= ~RT_DEVICE_FLAG_INT_TX;
can->can_tx = RT_NULL;
diff --git a/components/drivers/hwtimer/hwtimer.c b/components/drivers/hwtimer/hwtimer.c
index 83a76c7b9d..976d8bbf32 100644
--- a/components/drivers/hwtimer/hwtimer.c
+++ b/components/drivers/hwtimer/hwtimer.c
@@ -10,6 +10,7 @@
#include <rtthread.h>
#include <rtdevice.h>
+#include <rthw.h>
rt_inline rt_uint32_t timeout_calc(rt_hwtimer_t *timer, rt_hwtimerval_t *tv)
{
@@ -144,19 +145,25 @@ static rt_size_t rt_hwtimer_read(struct rt_device *dev, rt_off_t pos, void *buff
rt_hwtimer_t *timer;
rt_hwtimerval_t tv;
rt_uint32_t cnt;
+ rt_base_t level;
+ rt_int32_t overflow;
float t;
timer = (rt_hwtimer_t *)dev;
if (timer->ops->count_get == RT_NULL)
return 0;
+ level = rt_hw_interrupt_disable();
cnt = timer->ops->count_get(timer);
+ overflow = timer->overflow;
+ rt_hw_interrupt_enable(level);
+
if (timer->info->cntmode == HWTIMER_CNTMODE_DW)
{
cnt = (timer->freq * timer->period_sec) - cnt;
}
- t = timer->overflow * timer->period_sec + cnt/(float)timer->freq;
+ t = overflow * timer->period_sec + cnt/(float)timer->freq;
tv.sec = t;
tv.usec = (t - tv.sec) * 1000000;
size = size > sizeof(tv)? sizeof(tv) : size;
@@ -255,6 +262,7 @@ static rt_err_t rt_hwtimer_control(struct rt_device *dev, int cmd, void *args)
*((struct rt_hwtimer_info*)args) = *timer->info;
}
+ break;
case HWTIMER_CTRL_MODE_SET:
{
rt_hwtimer_mode_t *m;
diff --git a/components/drivers/i2c/i2c-bit-ops.c b/components/drivers/i2c/i2c-bit-ops.c
index 99338eef54..96af567a1e 100644
--- a/components/drivers/i2c/i2c-bit-ops.c
+++ b/components/drivers/i2c/i2c-bit-ops.c
@@ -375,8 +375,6 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
rt_int32_t i, ret;
rt_uint16_t ignore_nack;
- LOG_D("send start condition");
- i2c_start(ops);
for (i = 0; i < num; i++)
{
msg = &msgs[i];
@@ -387,6 +385,11 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
{
i2c_restart(ops);
}
+ else
+ {
+ LOG_D("send start condition");
+ i2c_start(ops);
+ }
ret = i2c_bit_send_address(bus, msg);
if ((ret != RT_EOK) && !ignore_nack)
{
@@ -423,8 +426,11 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
ret = i;
out:
- LOG_D("send stop condition");
- i2c_stop(ops);
+ if (!(msg->flags & RT_I2C_NO_STOP))
+ {
+ LOG_D("send stop condition");
+ i2c_stop(ops);
+ }
return ret;
}
diff --git a/components/drivers/include/drivers/alarm.h b/components/drivers/include/drivers/alarm.h
index b5ebbc86d9..e59c4142c7 100644
--- a/components/drivers/include/drivers/alarm.h
+++ b/components/drivers/include/drivers/alarm.h
@@ -6,6 +6,8 @@
* Change Logs:
* Date Author Notes
* 2012-10-27 heyuanjie87 first version.
+ * 2013-05-17 aozima initial alarm event & mutex in system init.
+ * 2020-10-15 zhangsz add alarm flags hour minute second.
*/
#ifndef __ALARM_H__
@@ -22,6 +24,9 @@
#define RT_ALARM_WEEKLY 0x200 /* alarm weekly at Monday or Friday etc. */
#define RT_ALARM_MONTHLY 0x400 /* alarm monthly at someday */
#define RT_ALARM_YAERLY 0x800 /* alarm yearly at a certain date */
+#define RT_ALARM_HOUR 0x1000 /* alarm each hour at a certain min:second */
+#define RT_ALARM_MINUTE 0x2000 /* alarm each minute at a certain second */
+#define RT_ALARM_SECOND 0x4000 /* alarm each second */
/* alarm control cmd */
#define RT_ALARM_CTRL_MODIFY 1 /* modify alarm time or alarm flag */
@@ -44,6 +49,8 @@ struct rt_alarm
rt_uint32_t flag;
rt_alarm_callback_t callback;
struct tm wktime;
+
+ void *user_data;
};
struct rt_alarm_setup
@@ -67,6 +74,6 @@ 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);
rt_err_t rt_alarm_stop(rt_alarm_t alarm);
-void rt_alarm_system_init(void);
+int rt_alarm_system_init(void);
#endif /* __ALARM_H__ */
diff --git a/components/drivers/include/drivers/i2c.h b/components/drivers/include/drivers/i2c.h
index 17d57288cd..d93e82fc2b 100644
--- a/components/drivers/include/drivers/i2c.h
+++ b/components/drivers/include/drivers/i2c.h
@@ -23,6 +23,7 @@ extern "C" {
#define RT_I2C_NO_START (1u << 4)
#define RT_I2C_IGNORE_NACK (1u << 5)
#define RT_I2C_NO_READ_ACK (1u << 6) /* when I2C reading, we do not ACK */
+#define RT_I2C_NO_STOP (1u << 7)
struct rt_i2c_msg
{
@@ -83,6 +84,17 @@ rt_size_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus,
rt_uint16_t flags,
rt_uint8_t *buf,
rt_uint32_t count);
+
+rt_inline rt_err_t rt_i2c_bus_lock(struct rt_i2c_bus_device *bus, rt_tick_t timeout)
+{
+ return rt_mutex_take(&bus->lock, timeout);
+}
+
+rt_inline rt_err_t rt_i2c_bus_unlock(struct rt_i2c_bus_device *bus)
+{
+ return rt_mutex_release(&bus->lock);
+}
+
int rt_i2c_core_init(void);
#ifdef __cplusplus
diff --git a/components/drivers/include/drivers/rt_inputcapture.h b/components/drivers/include/drivers/rt_inputcapture.h
index 0cadf6444c..40cd55883d 100644
--- a/components/drivers/include/drivers/rt_inputcapture.h
+++ b/components/drivers/include/drivers/rt_inputcapture.h
@@ -48,7 +48,7 @@ struct rt_inputcapture_ops
rt_err_t (*get_pulsewidth)(struct rt_inputcapture_device *inputcapture, rt_uint32_t *pulsewidth_us);
};
-void rt_hw_capture_isr(struct rt_inputcapture_device *inputcapture, rt_bool_t level);
+void rt_hw_inputcapture_isr(struct rt_inputcapture_device *inputcapture, rt_bool_t level);
rt_err_t rt_device_inputcapture_register(struct rt_inputcapture_device *inputcapture,
const char *name,
diff --git a/components/drivers/include/drivers/spi.h b/components/drivers/include/drivers/spi.h
index 04a65421a5..d92518cd94 100644
--- a/components/drivers/include/drivers/spi.h
+++ b/components/drivers/include/drivers/spi.h
@@ -1,11 +1,12 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2020, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2012-11-23 Bernard Add extern "C"
+ * 2020-06-13 armink fix the 3 wires issue
*/
#ifndef __SPI_H__
@@ -18,8 +19,6 @@
extern "C"{
#endif
-#define RT_SPI_CPHA (1<<0) /* bit[0]:CPHA, clock phase */
-#define RT_SPI_CPOL (1<<1) /* bit[1]:CPOL, clock polarity */
/**
* At CPOL=0 the base value of the clock is zero
* - For CPHA=0, data are captured on the clock's rising edge (low->high transition)
@@ -32,26 +31,29 @@ extern "C"{
* - For CPHA=1, data are captured on clock's rising edge and data are propagated
* on a falling edge.
*/
+#define RT_SPI_CPHA (1<<0) /* bit[0]:CPHA, clock phase */
+#define RT_SPI_CPOL (1<<1) /* bit[1]:CPOL, clock polarity */
+
#define RT_SPI_LSB (0<<2) /* bit[2]: 0-LSB */
#define RT_SPI_MSB (1<<2) /* bit[2]: 1-MSB */
#define RT_SPI_MASTER (0<<3) /* SPI master device */
#define RT_SPI_SLAVE (1<<3) /* SPI slave device */
+#define RT_SPI_CS_HIGH (1<<4) /* Chipselect active high */
+#define RT_SPI_NO_CS (1<<5) /* No chipselect */
+#define RT_SPI_3WIRE (1<<6) /* SI/SO pin shared */
+#define RT_SPI_READY (1<<7) /* Slave pulls low to pause */
+
+#define RT_SPI_MODE_MASK (RT_SPI_CPHA | RT_SPI_CPOL | RT_SPI_MSB | RT_SPI_SLAVE | RT_SPI_CS_HIGH | RT_SPI_NO_CS | RT_SPI_3WIRE | RT_SPI_READY)
+
#define RT_SPI_MODE_0 (0 | 0) /* CPOL = 0, CPHA = 0 */
#define RT_SPI_MODE_1 (0 | RT_SPI_CPHA) /* CPOL = 0, CPHA = 1 */
#define RT_SPI_MODE_2 (RT_SPI_CPOL | 0) /* CPOL = 1, CPHA = 0 */
#define RT_SPI_MODE_3 (RT_SPI_CPOL | RT_SPI_CPHA) /* CPOL = 1, CPHA = 1 */
-#define RT_SPI_MODE_MASK (RT_SPI_CPHA | RT_SPI_CPOL | RT_SPI_MSB)
-
-#define RT_SPI_BUS_MODE_SPI (1<<0)
-#define RT_SPI_BUS_MODE_QSPI (1<<1)
-
-#define RT_SPI_CS_HIGH (1<<4) /* Chipselect active high */
-#define RT_SPI_NO_CS (1<<5) /* No chipselect */
-#define RT_SPI_3WIRE (1<<6) /* SI/SO pin shared */
-#define RT_SPI_READY (1<<7) /* Slave pulls low to pause */
+#define RT_SPI_BUS_MODE_SPI (1<<0)
+#define RT_SPI_BUS_MODE_QSPI (1<<1)
/**
* SPI message structure
diff --git a/components/drivers/include/drivers/usb_common.h b/components/drivers/include/drivers/usb_common.h
index c26d83391e..4d85a85e35 100644
--- a/components/drivers/include/drivers/usb_common.h
+++ b/components/drivers/include/drivers/usb_common.h
@@ -435,15 +435,15 @@ typedef struct usb_os_proerty * usb_os_proerty_t;
// 5 A big-endian 32-bit integer (REG_DWORD_BIG_ENDIAN)
// 6 A NULL-terminated Unicode string that contains a symbolic link (REG_LINK)
// 7 Multiple NULL-terminated Unicode strings (REG_MULTI_SZ)
-#define USB_OS_PROERTY_TYPE_REG_SZ 0x01UL
-#define USB_OS_PROERTY_TYPE_REG_EXPAND_SZ 0x02UL
-#define USB_OS_PROERTY_TYPE_REG_BINARY 0x03UL
-#define USB_OS_PROERTY_TYPE_REG_DWORD_LITTLE_ENDIAN 0x04UL
-#define USB_OS_PROERTY_TYPE_REG_DWORD_BIG_ENDIAN 0x05UL
-#define USB_OS_PROERTY_TYPE_REG_LINK 0x06UL
-#define USB_OS_PROERTY_TYPE_REG_MULTI_SZ 0x07UL
+#define USB_OS_PROPERTY_TYPE_REG_SZ 0x01UL
+#define USB_OS_PROPERTY_TYPE_REG_EXPAND_SZ 0x02UL
+#define USB_OS_PROPERTY_TYPE_REG_BINARY 0x03UL
+#define USB_OS_PROPERTY_TYPE_REG_DWORD_LITTLE_ENDIAN 0x04UL
+#define USB_OS_PROPERTY_TYPE_REG_DWORD_BIG_ENDIAN 0x05UL
+#define USB_OS_PROPERTY_TYPE_REG_LINK 0x06UL
+#define USB_OS_PROPERTY_TYPE_REG_MULTI_SZ 0x07UL
-#define USB_OS_PROERTY_DESC(PropertyDataType,PropertyName,PropertyData) \
+#define USB_OS_PROPERTY_DESC(PropertyDataType,PropertyName,PropertyData) \
{\
.dwSize = sizeof(struct usb_os_proerty)-sizeof(const char *)*2\
+sizeof(PropertyName)*2+sizeof(PropertyData)*2,\
diff --git a/components/drivers/include/ipc/dataqueue.h b/components/drivers/include/ipc/dataqueue.h
index f584c267bf..76203c404d 100644
--- a/components/drivers/include/ipc/dataqueue.h
+++ b/components/drivers/include/ipc/dataqueue.h
@@ -17,17 +17,19 @@
#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_uint32_t magic;
+
rt_uint16_t size;
rt_uint16_t lwm;
- rt_bool_t waiting_lwm;
- rt_uint16_t get_index;
- rt_uint16_t put_index;
+ rt_uint16_t get_index : 15;
+ rt_uint16_t is_empty : 1;
+ rt_uint16_t put_index : 15;
+ rt_uint16_t is_full : 1;
struct rt_data_item *queue;
@@ -53,9 +55,11 @@ 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,
+rt_err_t rt_data_queue_peek(struct rt_data_queue *queue,
const void **data_ptr,
rt_size_t *size);
void rt_data_queue_reset(struct rt_data_queue *queue);
+rt_err_t rt_data_queue_deinit(struct rt_data_queue *queue);
+rt_uint16_t rt_data_queue_len(struct rt_data_queue *queue);
#endif
diff --git a/components/drivers/include/ipc/ringbuffer.h b/components/drivers/include/ipc/ringbuffer.h
index 4487d02c47..2afd2ca213 100644
--- a/components/drivers/include/ipc/ringbuffer.h
+++ b/components/drivers/include/ipc/ringbuffer.h
@@ -71,6 +71,7 @@ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, const rt_uint8_t *pt
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_peak(struct rt_ringbuffer *rb, rt_uint8_t **ptr);
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);
diff --git a/components/drivers/sdio/block_dev.c b/components/drivers/sdio/block_dev.c
index 5db0f38c08..602acb9aa7 100644
--- a/components/drivers/sdio/block_dev.c
+++ b/components/drivers/sdio/block_dev.c
@@ -460,8 +460,6 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
rt_device_register(&blk_dev->dev, "sd0",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
rt_list_insert_after(&blk_devices, &blk_dev->list);
-
- break;
}
else
{
diff --git a/components/drivers/sdio/mmc.c b/components/drivers/sdio/mmc.c
index 7b1f7ee193..c1c56d37fd 100644
--- a/components/drivers/sdio/mmc.c
+++ b/components/drivers/sdio/mmc.c
@@ -191,7 +191,7 @@ static int mmc_parse_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd)
}
card->flags |= CARD_FLAG_HIGHSPEED;
- card->hs_max_data_rate = 200000000;
+ card->hs_max_data_rate = 52000000;
card_capacity = *((rt_uint32_t *)&ext_csd[EXT_CSD_SEC_CNT]);
card_capacity *= card->card_blksize;
@@ -318,8 +318,17 @@ static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd)
* the device to work in 8bit transfer mode. If the
* mmc switch command returns error then switch to
* 4bit transfer mode. On success set the corresponding
- * bus width on the host.
+ * bus width on the host. Meanwhile, mmc core would
+ * bail out early if corresponding bus capable wasn't
+ * set by drivers.
*/
+ if ((!(host->flags & MMCSD_BUSWIDTH_8) &&
+ ext_csd_bits[idx] == EXT_CSD_BUS_WIDTH_8) ||
+ (!(host->flags & MMCSD_BUSWIDTH_4) &&
+ (ext_csd_bits[idx] == EXT_CSD_BUS_WIDTH_4 ||
+ ext_csd_bits[idx] == EXT_CSD_BUS_WIDTH_8)))
+ continue;
+
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
EXT_CSD_BUS_WIDTH,
ext_csd_bits[idx]);
@@ -504,16 +513,10 @@ static rt_int32_t mmcsd_mmc_init_card(struct rt_mmcsd_host *host,
card->flags |= CARD_FLAG_SDHC;
/* set bus speed */
- max_data_rate = (unsigned int)-1;
if (card->flags & CARD_FLAG_HIGHSPEED)
- {
- if (max_data_rate > card->hs_max_data_rate)
- max_data_rate = card->hs_max_data_rate;
- }
- else if (max_data_rate > card->max_data_rate)
- {
+ max_data_rate = card->hs_max_data_rate;
+ else
max_data_rate = card->max_data_rate;
- }
mmcsd_set_clock(host, max_data_rate);
diff --git a/components/drivers/sdio/sd.c b/components/drivers/sdio/sd.c
index 183eba169d..f7e4e46720 100644
--- a/components/drivers/sdio/sd.c
+++ b/components/drivers/sdio/sd.c
@@ -93,25 +93,6 @@ static rt_int32_t mmcsd_parse_csd(struct rt_mmcsd_card *card)
card->tacc_ns = (tacc_uint[csd->taac&0x07] * tacc_value[(csd->taac&0x78)>>3] + 9) / 10;
card->max_data_rate = tran_unit[csd->tran_speed&0x07] * tran_value[(csd->tran_speed&0x78)>>3];
- #if 0
- val = GET_BITS(resp, 115, 4);
- unit = GET_BITS(resp, 112, 3);
- csd->tacc_ns = (tacc_uint[unit] * tacc_value[val] + 9) / 10;
- csd->tacc_clks = GET_BITS(resp, 104, 8) * 100;
-
- val = GET_BITS(resp, 99, 4);
- unit = GET_BITS(resp, 96, 3);
- csd->max_data_rate = tran_unit[unit] * tran_value[val];
- csd->ccc = GET_BITS(resp, 84, 12);
-
- unit = GET_BITS(resp, 47, 3);
- val = GET_BITS(resp, 62, 12);
- csd->device_size = (1 + val) << (unit + 2);
-
- csd->read_bl_len = GET_BITS(resp, 80, 4);
- csd->write_bl_len = GET_BITS(resp, 22, 4);
- csd->r2w_factor = GET_BITS(resp, 26, 3);
- #endif
break;
case 1:
card->flags |= CARD_FLAG_SDHC;
@@ -142,23 +123,6 @@ static rt_int32_t mmcsd_parse_csd(struct rt_mmcsd_card *card)
card->tacc_ns = 0;
card->max_data_rate = tran_unit[csd->tran_speed&0x07] * tran_value[(csd->tran_speed&0x78)>>3];
- #if 0
- csd->tacc_ns = 0;
- csd->tacc_clks = 0;
-
- val = GET_BITS(resp, 99, 4);
- unit = GET_BITS(resp, 96, 3);
- csd->max_data_rate = tran_unit[unit] * tran_value[val];
- csd->ccc = GET_BITS(resp, 84, 12);
-
- val = GET_BITS(resp, 48, 22);
- csd->device_size = (1 + val) << 10;
-
- csd->read_bl_len = 9;
- csd->write_bl_len = 9;
- /* host should not use this factor and should use 250ms for write timeout */
- csd->r2w_factor = 2;
- #endif
break;
default:
LOG_E("unrecognised CSD structure version %d!", csd->csd_structure);
diff --git a/components/drivers/sdio/sdio.c b/components/drivers/sdio/sdio.c
index 65bf87b895..f5d97cdd08 100644
--- a/components/drivers/sdio/sdio.c
+++ b/components/drivers/sdio/sdio.c
@@ -892,9 +892,9 @@ static rt_int32_t sdio_init_card(struct rt_mmcsd_host *host, rt_uint32_t ocr)
if (card->flags & CARD_FLAG_HIGHSPEED)
{
- mmcsd_set_clock(host, 50000000);
- }
- else
+ mmcsd_set_clock(host, card->host->freq_max > 50000000 ? 50000000 : card->host->freq_max);
+ }
+ else
{
mmcsd_set_clock(host, card->cis.max_tran_speed);
}
diff --git a/components/drivers/sensors/SConscript b/components/drivers/sensors/SConscript
index 51c4b50eef..b56ae5ce6e 100644
--- a/components/drivers/sensors/SConscript
+++ b/components/drivers/sensors/SConscript
@@ -7,7 +7,7 @@ src = ['sensor.c']
CPPPATH = [cwd, cwd + '/../include']
if GetDepend('RT_USING_SENSOR_CMD'):
- src += ['sensor_cmd.c'];
+ src += ['sensor_cmd.c']
group = DefineGroup('Sensors', src, depend = ['RT_USING_SENSOR', 'RT_USING_DEVICE'], CPPPATH = CPPPATH)
diff --git a/components/drivers/sensors/sensor.c b/components/drivers/sensors/sensor.c
index 91b256bd66..fbe64c81f2 100644
--- a/components/drivers/sensors/sensor.c
+++ b/components/drivers/sensors/sensor.c
@@ -305,7 +305,7 @@ static rt_err_t rt_sensor_control(rt_device_t dev, int cmd, void *args)
case RT_SENSOR_CTRL_GET_ID:
if (args)
{
- sensor->ops->control(sensor, RT_SENSOR_CTRL_GET_ID, args);
+ result = sensor->ops->control(sensor, RT_SENSOR_CTRL_GET_ID, args);
}
break;
case RT_SENSOR_CTRL_GET_INFO:
@@ -350,7 +350,17 @@ static rt_err_t rt_sensor_control(rt_device_t dev, int cmd, void *args)
result = sensor->ops->control(sensor, RT_SENSOR_CTRL_SELF_TEST, args);
break;
default:
- return -RT_ERROR;
+
+ if (cmd > RT_SENSOR_CTRL_USER_CMD_START)
+ {
+ /* Custom commands */
+ result = sensor->ops->control(sensor, cmd, args);
+ }
+ else
+ {
+ result = -RT_ERROR;
+ }
+ break;
}
if (sensor->module)
diff --git a/components/drivers/sensors/sensor.h b/components/drivers/sensors/sensor.h
index 9c6e5ecc55..f9470ecb0d 100644
--- a/components/drivers/sensors/sensor.h
+++ b/components/drivers/sensors/sensor.h
@@ -106,6 +106,8 @@ extern "C" {
#define RT_SENSOR_CTRL_SET_POWER (5) /* Set power mode. args type of sensor power mode. ex. RT_SENSOR_POWER_DOWN,RT_SENSOR_POWER_NORMAL */
#define RT_SENSOR_CTRL_SELF_TEST (6) /* Take a self test */
+#define RT_SENSOR_CTRL_USER_CMD_START 0x100 /* User commands should be greater than 0x100 */
+
struct rt_sensor_info
{
rt_uint8_t type; /* The sensor type */
diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c
index 50dd7e188b..5e0af51425 100644
--- a/components/drivers/serial/serial.c
+++ b/components/drivers/serial/serial.c
@@ -219,7 +219,10 @@ rt_inline int _serial_poll_rx(struct rt_serial_device *serial, rt_uint8_t *data,
*data = ch;
data ++; length --;
- if (ch == '\n') break;
+ if(serial->parent.open_flag & RT_DEVICE_FLAG_STREAM)
+ {
+ if (ch == '\n') break;
+ }
}
return size - length;
@@ -315,6 +318,19 @@ rt_inline int _serial_int_tx(struct rt_serial_device *serial, const rt_uint8_t *
while (length)
{
+ /*
+ * to be polite with serial console add a line feed
+ * to the carriage return character
+ */
+ if (*data == '\n' && (serial->parent.open_flag & RT_DEVICE_FLAG_STREAM))
+ {
+ if (serial->ops->putc(serial, '\r') == -1)
+ {
+ rt_completion_wait(&(tx->completion), RT_WAITING_FOREVER);
+ continue;
+ }
+ }
+
if (serial->ops->putc(serial, *(char*)data) == -1)
{
rt_completion_wait(&(tx->completion), RT_WAITING_FOREVER);
@@ -330,14 +346,16 @@ rt_inline int _serial_int_tx(struct rt_serial_device *serial, const rt_uint8_t *
static void _serial_check_buffer_size(void)
{
static rt_bool_t already_output = RT_FALSE;
-
+
if (already_output == RT_FALSE)
{
+#if !defined(RT_USING_ULOG) || defined(ULOG_USING_ISR_LOG)
LOG_W("Warning: There is no enough buffer for saving data,"
" please increase the RT_SERIAL_RB_BUFSZ option.");
+#endif
already_output = RT_TRUE;
}
-}
+}
#if defined(RT_USING_POSIX) || defined(RT_SERIAL_USING_DMA)
static rt_size_t _serial_fifo_calc_recved_len(struct rt_serial_device *serial)
@@ -731,6 +749,7 @@ static rt_err_t rt_serial_close(struct rt_device *dev)
rt_free(rx_fifo);
serial->serial_rx = RT_NULL;
dev->open_flag &= ~RT_DEVICE_FLAG_INT_RX;
+
/* configure low level device */
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void*)RT_DEVICE_FLAG_INT_RX);
}
@@ -752,10 +771,11 @@ static rt_err_t rt_serial_close(struct rt_device *dev)
rt_free(rx_fifo);
}
- /* configure low level device */
- serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *) RT_DEVICE_FLAG_DMA_RX);
serial->serial_rx = RT_NULL;
dev->open_flag &= ~RT_DEVICE_FLAG_DMA_RX;
+
+ /* configure low level device */
+ serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *) RT_DEVICE_FLAG_DMA_RX);
}
#endif /* RT_SERIAL_USING_DMA */
@@ -769,6 +789,7 @@ static rt_err_t rt_serial_close(struct rt_device *dev)
rt_free(tx_fifo);
serial->serial_tx = RT_NULL;
dev->open_flag &= ~RT_DEVICE_FLAG_INT_TX;
+
/* configure low level device */
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void*)RT_DEVICE_FLAG_INT_TX);
}
@@ -780,10 +801,19 @@ static rt_err_t rt_serial_close(struct rt_device *dev)
tx_dma = (struct rt_serial_tx_dma*)serial->serial_tx;
RT_ASSERT(tx_dma != RT_NULL);
+ rt_data_queue_deinit(&(tx_dma->data_queue));
+
rt_free(tx_dma);
serial->serial_tx = RT_NULL;
dev->open_flag &= ~RT_DEVICE_FLAG_DMA_TX;
+
+ /* configure low level device */
+ serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *) RT_DEVICE_FLAG_DMA_TX);
}
+
+ serial->ops->control(serial, RT_DEVICE_CTRL_CLOSE, RT_NULL);
+ dev->flag &= ~RT_DEVICE_FLAG_ACTIVATED;
+
#endif /* RT_SERIAL_USING_DMA */
return RT_EOK;
}
@@ -980,7 +1010,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
}
break;
-
+#ifdef RT_USING_POSIX
#ifdef RT_USING_POSIX_TERMIOS
case TCGETA:
{
@@ -1072,8 +1102,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
break;
case TCXONC:
break;
-#endif
-#ifdef RT_USING_POSIX
+#endif /*RT_USING_POSIX_TERMIOS*/
case FIONREAD:
{
rt_size_t recved = 0;
@@ -1228,7 +1257,7 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
tx_dma = (struct rt_serial_tx_dma*) serial->serial_tx;
rt_data_queue_pop(&(tx_dma->data_queue), &last_data_ptr, &data_size, 0);
- if (rt_data_queue_peak(&(tx_dma->data_queue), &data_ptr, &data_size) == RT_EOK)
+ if (rt_data_queue_peek(&(tx_dma->data_queue), &data_ptr, &data_size) == RT_EOK)
{
/* transmit next data node */
tx_dma->activated = RT_TRUE;
diff --git a/components/drivers/spi/sfud/inc/sfud_cfg.h b/components/drivers/spi/sfud/inc/sfud_cfg.h
index 3b7860062d..01255775c8 100644
--- a/components/drivers/spi/sfud/inc/sfud_cfg.h
+++ b/components/drivers/spi/sfud/inc/sfud_cfg.h
@@ -38,6 +38,18 @@
#define SFUD_DEBUG_MODE
#endif
+#ifdef RT_DEBUG_SFUD
+#define DBG_LVL DBG_LOG
+#define SFUD_DEBUG(fmt, ...) LOG_D("(%s:%ld) "fmt"", __FILE__, __LINE__, ##__VA_ARGS__)
+#else
+#define DBG_LVL DBG_INFO
+#endif /* RT_DEBUG_SFUD */
+
+#define DBG_TAG "SFUD"
+#include <rtdbg.h>
+extern void rt_kprintf(const char *fmt, ...);
+#define SFUD_INFO(...) LOG_I(__VA_ARGS__)
+
/**
* Using probe flash JEDEC SFDP parameter.
*/
diff --git a/components/drivers/spi/sfud/inc/sfud_flash_def.h b/components/drivers/spi/sfud/inc/sfud_flash_def.h
index 13a0e702a8..03b95cd008 100644
--- a/components/drivers/spi/sfud/inc/sfud_flash_def.h
+++ b/components/drivers/spi/sfud/inc/sfud_flash_def.h
@@ -87,7 +87,7 @@ typedef struct {
#define SFUD_MF_ID_FUDAN 0xA1
#define SFUD_MF_ID_HYUNDAI 0xAD
#define SFUD_MF_ID_SST 0xBF
-#define SFUD_MF_ID_MICRONIX 0xC2
+#define SFUD_MF_ID_MACRONIX 0xC2
#define SFUD_MF_ID_GIGADEVICE 0xC8
#define SFUD_MF_ID_ISSI 0xD5
#define SFUD_MF_ID_WINBOND 0xEF
@@ -110,7 +110,7 @@ typedef struct {
{"GigaDevice", SFUD_MF_ID_GIGADEVICE}, \
{"ISSI", SFUD_MF_ID_ISSI}, \
{"Winbond", SFUD_MF_ID_WINBOND}, \
- {"Micronix", SFUD_MF_ID_MICRONIX}, \
+ {"Macronix", SFUD_MF_ID_MACRONIX}, \
}
#ifdef SFUD_USING_FLASH_INFO_TABLE
@@ -124,6 +124,7 @@ typedef struct {
{"AT45DB161E", SFUD_MF_ID_ATMEL, 0x26, 0x00, 2L*1024L*1024L, SFUD_WM_BYTE|SFUD_WM_DUAL_BUFFER, 512, 0x81}, \
{"W25Q40BV", SFUD_MF_ID_WINBOND, 0x40, 0x13, 512L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \
{"W25Q16BV", SFUD_MF_ID_WINBOND, 0x40, 0x15, 2L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \
+ {"W25Q64CV", SFUD_MF_ID_WINBOND, 0x40, 0x17, 8L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \
{"W25Q64DW", SFUD_MF_ID_WINBOND, 0x60, 0x17, 8L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \
{"W25Q128BV", SFUD_MF_ID_WINBOND, 0x40, 0x18, 16L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \
{"W25Q256FV", SFUD_MF_ID_WINBOND, 0x40, 0x19, 32L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \
@@ -143,7 +144,7 @@ typedef struct {
#endif /* SFUD_USING_FLASH_INFO_TABLE */
#ifdef SFUD_USING_QSPI
-/* This table saves flash read-fast instructions in QSPI mode,
+/* This table saves flash read-fast instructions in QSPI mode,
* SFUD can use this table to select the most appropriate read instruction for flash.
* | mf_id | type_id | capacity_id | qspi_read_mode |
*/
@@ -156,7 +157,7 @@ typedef struct {
/* W25Q16BV */ \
{SFUD_MF_ID_WINBOND, 0x40, 0x15, NORMAL_SPI_READ|DUAL_OUTPUT}, \
/* W25Q32BV */ \
- {SFUD_MF_ID_WINBOND, 0x40, 0x16, NORMAL_SPI_READ|DUAL_OUTPUT}, \
+ {SFUD_MF_ID_WINBOND, 0x40, 0x16, NORMAL_SPI_READ|DUAL_OUTPUT|QUAD_OUTPUT|QUAD_IO}, \
/* W25Q64JV */ \
{SFUD_MF_ID_WINBOND, 0x40, 0x17, NORMAL_SPI_READ|DUAL_OUTPUT|DUAL_IO|QUAD_OUTPUT|QUAD_IO}, \
/* W25Q128JV */ \
@@ -172,7 +173,9 @@ typedef struct {
/* A25LQ64 */ \
{SFUD_MF_ID_AMIC, 0x40, 0x17, NORMAL_SPI_READ|DUAL_OUTPUT|DUAL_IO|QUAD_IO}, \
/* MX25L3206E and KH25L3206E */ \
- {SFUD_MF_ID_MICRONIX, 0x20, 0x16, NORMAL_SPI_READ|DUAL_OUTPUT}, \
+ {SFUD_MF_ID_MACRONIX, 0x20, 0x16, NORMAL_SPI_READ|DUAL_OUTPUT}, \
+ /* MX25L51245G */ \
+ {SFUD_MF_ID_MACRONIX, 0x20, 0x1A, NORMAL_SPI_READ|DUAL_OUTPUT|DUAL_IO|QUAD_OUTPUT|QUAD_IO}, \
/* GD25Q64B */ \
{SFUD_MF_ID_GIGADEVICE, 0x40, 0x17, NORMAL_SPI_READ|DUAL_OUTPUT}, \
}
diff --git a/components/drivers/spi/sfud/src/sfud.c b/components/drivers/spi/sfud/src/sfud.c
index f666b06806..e5b03131ff 100644
--- a/components/drivers/spi/sfud/src/sfud.c
+++ b/components/drivers/spi/sfud/src/sfud.c
@@ -897,7 +897,7 @@ static sfud_err set_write_enabled(const sfud_flash *flash, bool enabled) {
if (enabled && (register_status & SFUD_STATUS_REGISTER_WEL) == 0) {
SFUD_INFO("Error: Can't enable write status.");
return SFUD_ERR_WRITE;
- } else if (!enabled && (register_status & SFUD_STATUS_REGISTER_WEL) == 1) {
+ } else if (!enabled && (register_status & SFUD_STATUS_REGISTER_WEL) != 0) {
SFUD_INFO("Error: Can't disable write status.");
return SFUD_ERR_WRITE;
}
diff --git a/components/drivers/spi/spi_flash_sfud.c b/components/drivers/spi/spi_flash_sfud.c
index eff604fe02..2333c9ccb3 100644
--- a/components/drivers/spi/spi_flash_sfud.c
+++ b/components/drivers/spi/spi_flash_sfud.c
@@ -15,12 +15,6 @@
#ifdef RT_USING_SFUD
-#ifdef RT_DEBUG_SFUD
-#define DEBUG_TRACE rt_kprintf("[SFUD] "); rt_kprintf
-#else
-#define DEBUG_TRACE(...)
-#endif /* RT_DEBUG_SFUD */
-
#ifndef RT_SFUD_DEFAULT_SPI_CFG
#ifndef RT_SFUD_SPI_MAX_HZ
@@ -34,7 +28,7 @@
.data_width = 8, \
.max_hz = RT_SFUD_SPI_MAX_HZ, \
}
-#endif
+#endif /* RT_SFUD_DEFAULT_SPI_CFG */
#ifdef SFUD_USING_QSPI
#define RT_SFUD_DEFAULT_QSPI_CFG \
@@ -44,11 +38,7 @@
.ddr_mode = 0, \
.qspi_dl_width = 4, \
}
-#endif
-
-static char log_buf[RT_CONSOLEBUF_SIZE];
-
-void sfud_log_debug(const char *file, const long line, const char *format, ...);
+#endif /* SFUD_USING_QSPI */
static rt_err_t rt_sfud_control(rt_device_t dev, int cmd, void *args) {
RT_ASSERT(dev);
@@ -259,44 +249,6 @@ static void retry_delay_100us(void) {
rt_thread_delay((RT_TICK_PER_SECOND * 1 + 9999) / 10000);
}
-/**
- * This function is print debug info.
- *
- * @param file the file which has call this function
- * @param line the line number which has call this function
- * @param format output format
- * @param ... args
- */
-void sfud_log_debug(const char *file, const long line, const char *format, ...) {
- va_list args;
-
- /* args point to the first variable parameter */
- va_start(args, format);
- rt_kprintf("[SFUD] (%s:%ld) ", file, line);
- /* must use vprintf to print */
- rt_vsnprintf(log_buf, sizeof(log_buf), format, args);
- rt_kprintf("%s\n", log_buf);
- va_end(args);
-}
-
-/**
- * This function is print routine info.
- *
- * @param format output format
- * @param ... args
- */
-void sfud_log_info(const char *format, ...) {
- va_list args;
-
- /* args point to the first variable parameter */
- va_start(args, format);
- rt_kprintf("[SFUD] ");
- /* must use vprintf to print */
- rt_vsnprintf(log_buf, sizeof(log_buf), format, args);
- rt_kprintf("%s\n", log_buf);
- va_end(args);
-}
-
sfud_err sfud_spi_port_init(sfud_flash *flash) {
sfud_err result = SFUD_SUCCESS;
@@ -311,7 +263,7 @@ sfud_err sfud_spi_port_init(sfud_flash *flash) {
flash->spi.unlock = spi_unlock;
flash->spi.user_data = flash;
if (RT_TICK_PER_SECOND < 1000) {
- rt_kprintf("[SFUD] Warning: The OS tick(%d) is less than 1000. So the flash write will take more time.\n", RT_TICK_PER_SECOND);
+ LOG_W("[SFUD] Warning: The OS tick(%d) is less than 1000. So the flash write will take more time.", RT_TICK_PER_SECOND);
}
/* 100 microsecond delay */
flash->retry.delay = retry_delay_100us;
@@ -334,23 +286,23 @@ const static struct rt_device_ops flash_device_ops =
#endif
/**
- * Probe SPI flash by SFUD(Serial Flash Universal Driver) driver library and though SPI device.
+ * Probe SPI flash by SFUD (Serial Flash Universal Driver) driver library and though SPI device by specified configuration.
*
* @param spi_flash_dev_name the name which will create SPI flash device
* @param spi_dev_name using SPI device name
+ * @param spi_cfg SPI device configuration
+ * @param qspi_cfg QSPI device configuration
*
* @return probed SPI flash device, probe failed will return RT_NULL
*/
-rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const char *spi_dev_name) {
+rt_spi_flash_device_t rt_sfud_flash_probe_ex(const char *spi_flash_dev_name, const char *spi_dev_name,
+ struct rt_spi_configuration *spi_cfg, struct rt_qspi_configuration *qspi_cfg)
+{
rt_spi_flash_device_t rtt_dev = RT_NULL;
sfud_flash *sfud_dev = RT_NULL;
char *spi_flash_dev_name_bak = RT_NULL, *spi_dev_name_bak = RT_NULL;
- /* using default flash SPI configuration for initialize SPI Flash
- * @note you also can change the SPI to other configuration after initialized finish */
- struct rt_spi_configuration cfg = RT_SFUD_DEFAULT_SPI_CFG;
extern sfud_err sfud_device_init(sfud_flash *flash);
#ifdef SFUD_USING_QSPI
- struct rt_qspi_configuration qspi_cfg = RT_SFUD_DEFAULT_QSPI_CFG;
struct rt_qspi_device *qspi_dev = RT_NULL;
#endif
@@ -380,7 +332,7 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
/* RT-Thread SPI device initialize */
rtt_dev->rt_spi_device = (struct rt_spi_device *) rt_device_find(spi_dev_name);
if (rtt_dev->rt_spi_device == RT_NULL || rtt_dev->rt_spi_device->parent.type != RT_Device_Class_SPIDevice) {
- rt_kprintf("ERROR: SPI device %s not found!\n", spi_dev_name);
+ LOG_E("ERROR: SPI device %s not found!", spi_dev_name);
goto error;
}
sfud_dev->spi.name = spi_dev_name_bak;
@@ -389,12 +341,12 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
/* set the qspi line number and configure the QSPI bus */
if(rtt_dev->rt_spi_device->bus->mode &RT_SPI_BUS_MODE_QSPI) {
qspi_dev = (struct rt_qspi_device *)rtt_dev->rt_spi_device;
- qspi_cfg.qspi_dl_width = qspi_dev->config.qspi_dl_width;
- rt_qspi_configure(qspi_dev, &qspi_cfg);
+ qspi_cfg->qspi_dl_width = qspi_dev->config.qspi_dl_width;
+ rt_qspi_configure(qspi_dev, qspi_cfg);
}
else
#endif
- rt_spi_configure(rtt_dev->rt_spi_device, &cfg);
+ rt_spi_configure(rtt_dev->rt_spi_device, spi_cfg);
}
/* SFUD flash device initialize */
{
@@ -406,7 +358,7 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
sfud_dev->user_data = rtt_dev;
/* initialize SFUD device */
if (sfud_device_init(sfud_dev) != SFUD_SUCCESS) {
- rt_kprintf("ERROR: SPI flash probe failed by SPI device %s.\n", spi_dev_name);
+ LOG_E("ERROR: SPI flash probe failed by SPI device %s.", spi_dev_name);
goto error;
}
/* when initialize success, then copy SFUD flash device's geometry to RT-Thread SPI flash device */
@@ -416,8 +368,8 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
#ifdef SFUD_USING_QSPI
/* reconfigure the QSPI bus for medium size */
if(rtt_dev->rt_spi_device->bus->mode &RT_SPI_BUS_MODE_QSPI) {
- qspi_cfg.medium_size = sfud_dev->chip.capacity;
- rt_qspi_configure(qspi_dev, &qspi_cfg);
+ qspi_cfg->medium_size = sfud_dev->chip.capacity;
+ rt_qspi_configure(qspi_dev, qspi_cfg);
if(qspi_dev->enter_qspi_mode != RT_NULL)
qspi_dev->enter_qspi_mode(qspi_dev);
@@ -442,10 +394,10 @@ rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const
rt_device_register(&(rtt_dev->flash_device), spi_flash_dev_name, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE);
- DEBUG_TRACE("Probe SPI flash %s by SPI device %s success.\n",spi_flash_dev_name, spi_dev_name);
+ LOG_I("Probe SPI flash %s by SPI device %s success.",spi_flash_dev_name, spi_dev_name);
return rtt_dev;
} else {
- rt_kprintf("ERROR: Low memory.\n");
+ LOG_E("ERROR: Low memory.");
goto error;
}
@@ -464,6 +416,26 @@ error:
}
/**
+ * Probe SPI flash by SFUD(Serial Flash Universal Driver) driver library and though SPI device.
+ *
+ * @param spi_flash_dev_name the name which will create SPI flash device
+ * @param spi_dev_name using SPI device name
+ *
+ * @return probed SPI flash device, probe failed will return RT_NULL
+ */
+rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const char *spi_dev_name)
+{
+ struct rt_spi_configuration cfg = RT_SFUD_DEFAULT_SPI_CFG;
+#ifndef SFUD_USING_QSPI
+ return rt_sfud_flash_probe_ex(spi_flash_dev_name, spi_dev_name, &cfg, RT_NULL);
+#else
+ struct rt_qspi_configuration qspi_cfg = RT_SFUD_DEFAULT_QSPI_CFG;
+
+ return rt_sfud_flash_probe_ex(spi_flash_dev_name, spi_dev_name, &cfg, &qspi_cfg);
+#endif
+}
+
+/**
* Delete SPI flash device
*
* @param spi_flash_dev SPI flash device
@@ -496,7 +468,7 @@ sfud_flash_t rt_sfud_flash_find(const char *spi_dev_name)
rt_spi_device = (struct rt_spi_device *) rt_device_find(spi_dev_name);
if (rt_spi_device == RT_NULL || rt_spi_device->parent.type != RT_Device_Class_SPIDevice) {
- rt_kprintf("ERROR: SPI device %s not found!\n", spi_dev_name);
+ LOG_E("ERROR: SPI device %s not found!", spi_dev_name);
goto __error;
}
@@ -505,7 +477,7 @@ sfud_flash_t rt_sfud_flash_find(const char *spi_dev_name)
sfud_dev = (sfud_flash_t) (rtt_dev->user_data);
return sfud_dev;
} else {
- rt_kprintf("ERROR: SFUD flash device not found!\n");
+ LOG_E("ERROR: SFUD flash device not found!");
goto __error;
}
@@ -520,7 +492,7 @@ sfud_flash_t rt_sfud_flash_find_by_dev_name(const char *flash_dev_name)
rtt_dev = (rt_spi_flash_device_t) rt_device_find(flash_dev_name);
if (rtt_dev == RT_NULL || rtt_dev->flash_device.type != RT_Device_Class_Block) {
- rt_kprintf("ERROR: Flash device %s not found!\n", flash_dev_name);
+ LOG_E("ERROR: Flash device %s not found!", flash_dev_name);
goto __error;
}
@@ -528,7 +500,7 @@ sfud_flash_t rt_sfud_flash_find_by_dev_name(const char *flash_dev_name)
sfud_dev = (sfud_flash_t) (rtt_dev->user_data);
return sfud_dev;
} else {
- rt_kprintf("ERROR: SFUD flash device not found!\n");
+ LOG_E("ERROR: SFUD flash device not found!");
goto __error;
}
@@ -712,11 +684,13 @@ static void sf(uint8_t argc, char **argv) {
addr = 0;
size = sfud_dev->chip.capacity;
uint32_t start_time, time_cast;
- size_t write_size = SFUD_WRITE_MAX_PAGE_SIZE, read_size = SFUD_WRITE_MAX_PAGE_SIZE;
+ size_t write_size = SFUD_WRITE_MAX_PAGE_SIZE, read_size = SFUD_WRITE_MAX_PAGE_SIZE, cur_op_size;
uint8_t *write_data = rt_malloc(write_size), *read_data = rt_malloc(read_size);
if (write_data && read_data) {
- rt_memset(write_data, 0x55, write_size);
+ for (i = 0; i < write_size; i ++) {
+ write_data[i] = i & 0xFF;
+ }
/* benchmark testing */
rt_kprintf("Erasing the %s %ld bytes data, waiting...\n", sfud_dev->name, size);
start_time = rt_tick_get();
@@ -732,7 +706,12 @@ static void sf(uint8_t argc, char **argv) {
rt_kprintf("Writing the %s %ld bytes data, waiting...\n", sfud_dev->name, size);
start_time = rt_tick_get();
for (i = 0; i < size; i += write_size) {
- result = sfud_write(sfud_dev, addr + i, write_size, write_data);
+ if (i + write_size <= size) {
+ cur_op_size = write_size;
+ } else {
+ cur_op_size = size - i;
+ }
+ result = sfud_write(sfud_dev, addr + i, cur_op_size, write_data);
if (result != SFUD_SUCCESS) {
rt_kprintf("Writing %s failed, already wr for %lu bytes, write %d each time\n", sfud_dev->name, i, write_size);
break;
@@ -750,12 +729,13 @@ static void sf(uint8_t argc, char **argv) {
start_time = rt_tick_get();
for (i = 0; i < size; i += read_size) {
if (i + read_size <= size) {
- result = sfud_read(sfud_dev, addr + i, read_size, read_data);
+ cur_op_size = read_size;
} else {
- result = sfud_read(sfud_dev, addr + i, size - i, read_data);
+ cur_op_size = size - i;
}
+ result = sfud_read(sfud_dev, addr + i, cur_op_size, read_data);
/* data check */
- if (memcmp(write_data, read_data, read_size))
+ if (memcmp(write_data, read_data, cur_op_size))
{
rt_kprintf("Data check ERROR! Please check you flash by other command.\n");
result = SFUD_ERR_READ;
diff --git a/components/drivers/spi/spi_flash_sfud.h b/components/drivers/spi/spi_flash_sfud.h
index 490f2feadb..932b7f879c 100644
--- a/components/drivers/spi/spi_flash_sfud.h
+++ b/components/drivers/spi/spi_flash_sfud.h
@@ -27,6 +27,19 @@
rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const char *spi_dev_name);
/**
+ * Probe SPI flash by SFUD (Serial Flash Universal Driver) driver library and though SPI device by specified configuration.
+ *
+ * @param spi_flash_dev_name the name which will create SPI flash device
+ * @param spi_dev_name using SPI device name
+ * @param spi_cfg SPI device configuration
+ * @param qspi_cfg QSPI device configuration
+ *
+ * @return probed SPI flash device, probe failed will return RT_NULL
+ */
+rt_spi_flash_device_t rt_sfud_flash_probe_ex(const char *spi_flash_dev_name, const char *spi_dev_name,
+ struct rt_spi_configuration *spi_cfg, struct rt_qspi_configuration *qspi_cfg);
+
+/**
* Delete SPI flash device
*
* @param spi_flash_dev SPI flash device
diff --git a/components/drivers/spi/spi_msd.c b/components/drivers/spi/spi_msd.c
index a109fd9488..191933e421 100644
--- a/components/drivers/spi/spi_msd.c
+++ b/components/drivers/spi/spi_msd.c
@@ -234,24 +234,30 @@ static rt_err_t _send_cmd(
else if (type == response_r2)
{
/* initial message */
+ /* Prevent non-aligned address access, use recv_buffer to receive data */
message.send_buf = RT_NULL;
- message.recv_buf = response + 1;
+ message.recv_buf = recv_buffer;
message.length = 1;
message.cs_take = message.cs_release = 0;
/* transfer message */
device->bus->ops->xfer(device, &message);
+ response[1] = recv_buffer[0];
}
else if ((type == response_r3) || (type == response_r7))
{
/* initial message */
message.send_buf = RT_NULL;
- message.recv_buf = response + 1;
+ message.recv_buf = recv_buffer;
message.length = 4;
message.cs_take = message.cs_release = 0;
/* transfer message */
device->bus->ops->xfer(device, &message);
+ response[1] = recv_buffer[0];
+ response[2] = recv_buffer[1];
+ response[3] = recv_buffer[2];
+ response[4] = recv_buffer[3];
}
else
{
diff --git a/components/drivers/src/dataqueue.c b/components/drivers/src/dataqueue.c
index 7553986b9f..1651417bb9 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,14 +28,18 @@ 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(size > 0);
queue->evt_notify = evt_notify;
+ queue->magic = DATAQUEUE_MAGIC;
queue->size = size;
queue->lwm = lwm;
queue->get_index = 0;
queue->put_index = 0;
+ queue->is_empty = 1;
+ queue->is_full = 0;
rt_list_init(&(queue->suspended_push_list));
rt_list_init(&(queue->suspended_pop_list));
@@ -58,12 +64,13 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
rt_err_t result;
RT_ASSERT(queue != RT_NULL);
+ RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
result = RT_EOK;
thread = rt_thread_self();
level = rt_hw_interrupt_disable();
- while (queue->put_index - queue->get_index == queue->size)
+ while (queue->is_full)
{
/* queue is full */
if (timeout == 0)
@@ -104,9 +111,18 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
if (result != RT_EOK) goto __exit;
}
- queue->queue[queue->put_index % queue->size].data_ptr = data_ptr;
- queue->queue[queue->put_index % queue->size].data_size = data_size;
+ queue->queue[queue->put_index].data_ptr = data_ptr;
+ queue->queue[queue->put_index].data_size = data_size;
queue->put_index += 1;
+ if (queue->put_index == queue->size)
+ {
+ queue->put_index = 0;
+ }
+ queue->is_empty = 0;
+ if (queue->put_index == queue->get_index)
+ {
+ queue->is_full = 1;
+ }
/* there is at least one thread in suspended list */
if (!rt_list_isempty(&(queue->suspended_pop_list)))
@@ -145,8 +161,9 @@ 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 != RT_NULL);
+ RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
RT_ASSERT(data_ptr != RT_NULL);
RT_ASSERT(size != RT_NULL);
@@ -154,7 +171,7 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
thread = rt_thread_self();
level = rt_hw_interrupt_disable();
- while (queue->get_index == queue->put_index)
+ while (queue->is_empty)
{
/* queue is empty */
if (timeout == 0)
@@ -195,12 +212,20 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
goto __exit;
}
- *data_ptr = queue->queue[queue->get_index % queue->size].data_ptr;
- *size = queue->queue[queue->get_index % queue->size].data_size;
-
+ *data_ptr = queue->queue[queue->get_index].data_ptr;
+ *size = queue->queue[queue->get_index].data_size;
queue->get_index += 1;
+ if (queue->get_index == queue->size)
+ {
+ queue->get_index = 0;
+ }
+ queue->is_full = 0;
+ if (queue->put_index == queue->get_index)
+ {
+ queue->is_empty = 1;
+ }
- if ((queue->put_index - queue->get_index) <= queue->lwm)
+ if (rt_data_queue_len(queue) <= queue->lwm)
{
/* there is at least one thread in suspended list */
if (!rt_list_isempty(&(queue->suspended_push_list)))
@@ -239,37 +264,48 @@ __exit:
}
RTM_EXPORT(rt_data_queue_pop);
-rt_err_t rt_data_queue_peak(struct rt_data_queue *queue,
+rt_err_t rt_data_queue_peek(struct rt_data_queue *queue,
const void** data_ptr,
rt_size_t *size)
{
rt_ubase_t level;
-
+
RT_ASSERT(queue != RT_NULL);
+ RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
- level = rt_hw_interrupt_disable();
-
- if (queue->get_index == queue->put_index)
+ if (queue->is_empty)
{
- rt_hw_interrupt_enable(level);
-
return -RT_EEMPTY;
}
- *data_ptr = queue->queue[queue->get_index % queue->size].data_ptr;
- *size = queue->queue[queue->get_index % queue->size].data_size;
+ level = rt_hw_interrupt_disable();
+
+ *data_ptr = queue->queue[queue->get_index].data_ptr;
+ *size = queue->queue[queue->get_index].data_size;
rt_hw_interrupt_enable(level);
return RT_EOK;
}
-RTM_EXPORT(rt_data_queue_peak);
+RTM_EXPORT(rt_data_queue_peek);
void rt_data_queue_reset(struct rt_data_queue *queue)
{
+ rt_ubase_t level;
struct rt_thread *thread;
- register rt_ubase_t temp;
+
+ RT_ASSERT(queue != RT_NULL);
+ RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
+
+ level = rt_hw_interrupt_disable();
+ queue->get_index = 0;
+ queue->put_index = 0;
+ queue->is_empty = 1;
+ queue->is_full = 0;
+
+ rt_hw_interrupt_enable(level);
+
rt_enter_critical();
/* wakeup all suspend threads */
@@ -277,7 +313,7 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
while (!rt_list_isempty(&(queue->suspended_pop_list)))
{
/* disable interrupt */
- temp = rt_hw_interrupt_disable();
+ level = rt_hw_interrupt_disable();
/* get next suspend thread */
thread = rt_list_entry(queue->suspended_pop_list.next,
@@ -294,14 +330,14 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
rt_thread_resume(thread);
/* enable interrupt */
- rt_hw_interrupt_enable(temp);
+ rt_hw_interrupt_enable(level);
}
/* resume on push list */
while (!rt_list_isempty(&(queue->suspended_push_list)))
{
/* disable interrupt */
- temp = rt_hw_interrupt_disable();
+ level = rt_hw_interrupt_disable();
/* get next suspend thread */
thread = rt_list_entry(queue->suspended_push_list.next,
@@ -318,10 +354,61 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
rt_thread_resume(thread);
/* enable interrupt */
- rt_hw_interrupt_enable(temp);
+ rt_hw_interrupt_enable(level);
}
rt_exit_critical();
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 != RT_NULL);
+ RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
+
+ /* wakeup all suspend threads */
+ rt_data_queue_reset(queue);
+
+ level = rt_hw_interrupt_disable();
+ queue->magic = 0;
+ rt_hw_interrupt_enable(level);
+
+ rt_free(queue->queue);
+
+ return RT_EOK;
+}
+RTM_EXPORT(rt_data_queue_deinit);
+
+rt_uint16_t rt_data_queue_len(struct rt_data_queue *queue)
+{
+ rt_ubase_t level;
+ rt_int16_t len;
+
+ RT_ASSERT(queue != RT_NULL);
+ RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
+
+ if (queue->is_empty)
+ {
+ return 0;
+ }
+
+ level = rt_hw_interrupt_disable();
+
+ if (queue->put_index > queue->get_index)
+ {
+ len = queue->put_index - queue->get_index;
+ }
+ else
+ {
+ len = queue->size + queue->put_index - queue->get_index;
+ }
+
+ rt_hw_interrupt_enable(level);
+
+ return len;
+}
+RTM_EXPORT(rt_data_queue_len);
+
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)
diff --git a/components/drivers/src/ringbuffer.c b/components/drivers/src/ringbuffer.c
index c6a491a7cc..88afd19506 100644
--- a/components/drivers/src/ringbuffer.c
+++ b/components/drivers/src/ringbuffer.c
@@ -194,6 +194,40 @@ rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb,
RTM_EXPORT(rt_ringbuffer_get);
/**
+ * peak data from ring buffer
+ */
+rt_size_t rt_ringbuffer_peak(struct rt_ringbuffer *rb, rt_uint8_t **ptr)
+{
+ RT_ASSERT(rb != RT_NULL);
+
+ *ptr = RT_NULL;
+
+ /* whether has enough data */
+ rt_size_t size = rt_ringbuffer_data_len(rb);
+
+ /* no data */
+ if (size == 0)
+ return 0;
+
+ *ptr = &rb->buffer_ptr[rb->read_index];
+
+ if(rb->buffer_size - rb->read_index > size)
+ {
+ rb->read_index += size;
+ return size;
+ }
+
+ size = rb->buffer_size - rb->read_index;
+
+ /* we are going into the other side of the mirror */
+ rb->read_mirror = ~rb->read_mirror;
+ rb->read_index = 0;
+
+ return size;
+}
+RTM_EXPORT(rt_ringbuffer_peak);
+
+/**
* put a character into ring buffer
*/
rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch)
diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c
index 2e0280df3a..2b5630d8d0 100644
--- a/components/drivers/src/workqueue.c
+++ b/components/drivers/src/workqueue.c
@@ -424,6 +424,6 @@ int rt_work_sys_workqueue_init(void)
return RT_EOK;
}
-INIT_DEVICE_EXPORT(rt_work_sys_workqueue_init);
+INIT_PREV_EXPORT(rt_work_sys_workqueue_init);
#endif
#endif
diff --git a/components/drivers/touch/SConscript b/components/drivers/touch/SConscript
index f370b2aba6..6c2a126c9c 100644
--- a/components/drivers/touch/SConscript
+++ b/components/drivers/touch/SConscript
@@ -6,6 +6,6 @@ cwd = GetCurrentDir()
src = ['touch.c']
CPPPATH = [cwd, cwd + '/../include']
-group = DefineGroup('Touch', src, depend = ['RT_USING_TOUCH', 'RT_USING_DEVICE'], CPPPATH = CPPPATH)
+group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_TOUCH', 'RT_USING_DEVICE'], CPPPATH = CPPPATH)
Return('group')
diff --git a/components/drivers/touch/touch.c b/components/drivers/touch/touch.c
index 80ba6378bb..e9595e9f8f 100644
--- a/components/drivers/touch/touch.c
+++ b/components/drivers/touch/touch.c
@@ -16,12 +16,9 @@
#include <rtdbg.h>
/* ISR for touch interrupt */
-static void irq_callback(void *args)
+void rt_hw_touch_isr(rt_touch_t touch)
{
- rt_touch_t touch;
-
- touch = (rt_touch_t)args;
-
+ RT_ASSERT(touch);
if (touch->parent.rx_indicate == RT_NULL)
{
return;
@@ -35,9 +32,17 @@ static void irq_callback(void *args)
touch->parent.rx_indicate(&touch->parent, 1);
}
+#ifdef RT_TOUCH_PIN_IRQ
+static void touch_irq_callback(void *param)
+{
+ rt_hw_touch_isr((rt_touch_t)param);
+}
+#endif
+
/* touch interrupt initialization function */
static rt_err_t rt_touch_irq_init(rt_touch_t touch)
{
+#ifdef RT_TOUCH_PIN_IRQ
if (touch->config.irq_pin.pin == RT_PIN_NONE)
{
return -RT_EINVAL;
@@ -47,18 +52,19 @@ static rt_err_t rt_touch_irq_init(rt_touch_t touch)
if (touch->config.irq_pin.mode == PIN_MODE_INPUT_PULLDOWN)
{
- rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING, irq_callback, (void *)touch);
+ rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING, touch_irq_callback, (void *)touch);
}
else if (touch->config.irq_pin.mode == PIN_MODE_INPUT_PULLUP)
{
- rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_FALLING, irq_callback, (void *)touch);
+ rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_FALLING, touch_irq_callback, (void *)touch);
}
else if (touch->config.irq_pin.mode == PIN_MODE_INPUT)
{
- rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING_FALLING, irq_callback, (void *)touch);
+ rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING_FALLING, touch_irq_callback, (void *)touch);
}
rt_pin_irq_enable(touch->config.irq_pin.pin, PIN_IRQ_ENABLE);
+#endif
return RT_EOK;
}
@@ -66,19 +72,23 @@ static rt_err_t rt_touch_irq_init(rt_touch_t touch)
/* touch interrupt enable */
static void rt_touch_irq_enable(rt_touch_t touch)
{
+#ifdef RT_TOUCH_PIN_IRQ
if (touch->config.irq_pin.pin != RT_PIN_NONE)
{
rt_pin_irq_enable(touch->config.irq_pin.pin, RT_TRUE);
}
+#endif
}
/* touch interrupt disable */
static void rt_touch_irq_disable(rt_touch_t touch)
{
+#ifdef RT_TOUCH_PIN_IRQ
if (touch->config.irq_pin.pin != RT_PIN_NONE)
{
rt_pin_irq_enable(touch->config.irq_pin.pin, RT_FALSE);
}
+#endif
}
static rt_err_t rt_touch_open(rt_device_t dev, rt_uint16_t oflag)
diff --git a/components/drivers/touch/touch.h b/components/drivers/touch/touch.h
index 6b7288a5a0..73d4d2e488 100644
--- a/components/drivers/touch/touch.h
+++ b/components/drivers/touch/touch.h
@@ -63,7 +63,9 @@ struct rt_touch_info
struct rt_touch_config
{
+#ifdef RT_TOUCH_PIN_IRQ
struct rt_device_pin_mode irq_pin; /* Interrupt pin, The purpose of this pin is to notification read data */
+#endif
char *dev_name; /* The name of the communication device */
void *user_data;
};
@@ -100,6 +102,9 @@ int rt_hw_touch_register(rt_touch_t touch,
rt_uint32_t flag,
void *data);
+/* if you doesn't use pin device. you must call this function in your touch irq callback */
+void rt_hw_touch_isr(rt_touch_t touch);
+
#ifdef __cplusplus
}
#endif
diff --git a/components/drivers/usb/usbdevice/SConscript b/components/drivers/usb/usbdevice/SConscript
index 010b9837a4..b6dfa8da10 100644
--- a/components/drivers/usb/usbdevice/SConscript
+++ b/components/drivers/usb/usbdevice/SConscript
@@ -3,7 +3,7 @@ from building import *
cwd = GetCurrentDir()
src = Split("""
-core/core.c
+core/usbdevice_core.c
core/usbdevice.c
""")
diff --git a/components/drivers/usb/usbdevice/class/audio_mic.c b/components/drivers/usb/usbdevice/class/audio_mic.c
index 4ac85711ad..23ade2d9b6 100644
--- a/components/drivers/usb/usbdevice/class/audio_mic.c
+++ b/components/drivers/usb/usbdevice/class/audio_mic.c
@@ -9,10 +9,7 @@
*/
#include <rthw.h>
-#include <rtthread.h>
-#include <rtservice.h>
#include <rtdevice.h>
-
#include "drivers/usb_device.h"
#include "audio.h"
diff --git a/components/drivers/usb/usbdevice/class/audio_speaker.c b/components/drivers/usb/usbdevice/class/audio_speaker.c
index 84c36d2053..e9a3ffaf40 100644
--- a/components/drivers/usb/usbdevice/class/audio_speaker.c
+++ b/components/drivers/usb/usbdevice/class/audio_speaker.c
@@ -9,10 +9,7 @@
*/
#include <rthw.h>
-#include <rtthread.h>
-#include <rtservice.h>
#include <rtdevice.h>
-
#include "drivers/usb_device.h"
#include "audio.h"
diff --git a/components/drivers/usb/usbdevice/class/cdc_vcom.c b/components/drivers/usb/usbdevice/class/cdc_vcom.c
index b6044b37a7..ca9576ed2e 100644
--- a/components/drivers/usb/usbdevice/class/cdc_vcom.c
+++ b/components/drivers/usb/usbdevice/class/cdc_vcom.c
@@ -13,8 +13,6 @@
*/
#include <rthw.h>
-#include <rtthread.h>
-#include <rtservice.h>
#include <rtdevice.h>
#include <drivers/serial.h>
#include "drivers/usb_device.h"
@@ -489,6 +487,7 @@ static rt_err_t _function_enable(ufunction_t func)
data = (struct vcom*)func->user_data;
data->ep_out->buffer = rt_malloc(CDC_RX_BUFSIZE);
+ RT_ASSERT(data->ep_out->buffer != RT_NULL);
data->ep_out->request.buffer = data->ep_out->buffer;
data->ep_out->request.size = EP_MAXPACKET(data->ep_out);
@@ -584,11 +583,13 @@ ufunction_t rt_usbd_function_cdc_create(udevice_t device)
/* create a cdc function */
func = rt_usbd_function_new(device, &dev_desc, &ops);
- //not support HS
- //rt_usbd_device_set_qualifier(device, &dev_qualifier);
+
+ /* support HS */
+ rt_usbd_device_set_qualifier(device, &dev_qualifier);
/* allocate memory for cdc vcom data */
data = (struct vcom*)rt_malloc(sizeof(struct vcom));
+ RT_ASSERT(data != RT_NULL);
rt_memset(data, 0, sizeof(struct vcom));
func->user_data = (void*)data;
diff --git a/components/drivers/usb/usbdevice/class/ecm.c b/components/drivers/usb/usbdevice/class/ecm.c
index b98b5007f4..36557dad74 100644
--- a/components/drivers/usb/usbdevice/class/ecm.c
+++ b/components/drivers/usb/usbdevice/class/ecm.c
@@ -419,12 +419,12 @@ rt_err_t rt_ecm_eth_tx(rt_device_t dev, struct pbuf* p)
p->tot_len = USB_ETH_MTU;
}
- result = rt_sem_take(&device->tx_buffer_free, rt_tick_from_millisecond(1000));
+ result = rt_sem_take(&ecm_eth_dev->tx_buffer_free, rt_tick_from_millisecond(1000));
if(result != RT_EOK)
{
LOG_W("wait for buffer free timeout");
/* if cost 1s to wait send done it said that connection is close . drop it */
- rt_sem_release(&device->tx_buffer_free);
+ rt_sem_release(&ecm_eth_dev->tx_buffer_free);
return result;
}
@@ -565,7 +565,8 @@ ufunction_t rt_usbd_function_ecm_create(udevice_t device)
/* create a cdc class */
cdc = rt_usbd_function_new(device, &_dev_desc, &ops);
rt_usbd_device_set_qualifier(device, &dev_qualifier);
- _ecm_eth= rt_malloc(sizeof(struct rt_ecm_eth));
+ _ecm_eth= rt_malloc(sizeof(struct rt_ecm_eth));
+ RT_ASSERT(_ecm_eth != RT_NULL);
rt_memset(_ecm_eth, 0, sizeof(struct rt_ecm_eth));
cdc->user_data = _ecm_eth;
diff --git a/components/drivers/usb/usbdevice/class/hid.c b/components/drivers/usb/usbdevice/class/hid.c
index a9b2e62d70..52e50296a4 100644
--- a/components/drivers/usb/usbdevice/class/hid.c
+++ b/components/drivers/usb/usbdevice/class/hid.c
@@ -11,13 +11,9 @@
*/
#include <rthw.h>
-#include <rtthread.h>
-#include <rtservice.h>
#include <rtdevice.h>
-
#include "drivers/usb_common.h"
#include "drivers/usb_device.h"
-
#include "hid.h"
#ifdef RT_USB_DEVICE_HID
@@ -29,7 +25,7 @@ struct hid_s
uep_t ep_in;
uep_t ep_out;
int status;
- rt_uint16_t protocol;
+ rt_uint8_t protocol;
rt_uint8_t report_buf[MAX_REPORT_SIZE];
struct rt_messagequeue hid_mq;
};
@@ -246,7 +242,7 @@ static struct udevice_descriptor _dev_desc =
USB_DESC_LENGTH_DEVICE, //bLength;
USB_DESC_TYPE_DEVICE, //type;
USB_BCD_VERSION, //bcdUSB;
- USB_CLASS_HID, //bDeviceClass;
+ 0x0, //bDeviceClass;
0x00, //bDeviceSubClass;
0x00, //bDeviceProtocol;
64, //bMaxPacketSize0;
@@ -266,8 +262,8 @@ static struct usb_qualifier_descriptor dev_qualifier =
sizeof(dev_qualifier), //bLength
USB_DESC_TYPE_DEVICEQUALIFIER, //bDescriptorType
0x0200, //bcdUSB
- USB_CLASS_MASS_STORAGE, //bDeviceClass
- 0x06, //bDeviceSubClass
+ 0x0, //bDeviceClass
+ 0x0, //bDeviceSubClass
0x50, //bDeviceProtocol
64, //bMaxPacketSize0
0x01, //bNumConfigurations
@@ -347,7 +343,7 @@ const static struct uhid_comm_descriptor _hid_comm_desc =
USB_DYNAMIC | USB_DIR_IN,
USB_EP_ATTR_INT,
0x40,
- 0x01,
+ 0x0A,
},
/* Endpoint Descriptor OUT */
@@ -458,8 +454,6 @@ static rt_err_t _interface_handler(ufunction_t func, ureq_t setup)
struct hid_s *data = (struct hid_s *) func->user_data;
- if(setup->wIndex != 0)
- return -RT_EIO;
switch (setup->bRequest)
{
@@ -489,7 +483,7 @@ static rt_err_t _interface_handler(ufunction_t func, ureq_t setup)
dcd_ep0_send_status(func->device->dcd);
break;
case USB_HID_REQ_GET_PROTOCOL:
- rt_usbd_ep0_write(func->device, &data->protocol,2);
+ rt_usbd_ep0_write(func->device, &data->protocol,1);
break;
case USB_HID_REQ_SET_REPORT:
@@ -695,8 +689,9 @@ ufunction_t rt_usbd_function_hid_create(udevice_t device)
/* create a cdc function */
func = rt_usbd_function_new(device, &_dev_desc, &ops);
- //not support hs
- //rt_usbd_device_set_qualifier(device, &_dev_qualifier);
+
+ /* For high speed mode supporting */
+ rt_usbd_device_set_qualifier(device, &dev_qualifier);
/* allocate memory for cdc vcom data */
data = (struct hid_s*)rt_malloc(sizeof(struct hid_s));
diff --git a/components/drivers/usb/usbdevice/class/mstorage.c b/components/drivers/usb/usbdevice/class/mstorage.c
index 6a6e92415b..0cee2c3e16 100644
--- a/components/drivers/usb/usbdevice/class/mstorage.c
+++ b/components/drivers/usb/usbdevice/class/mstorage.c
@@ -12,7 +12,6 @@
*/
#include <rtthread.h>
-#include <rtservice.h>
#include "drivers/usb_device.h"
#include "mstorage.h"
@@ -422,7 +421,7 @@ static rt_size_t _read_capacity(ufunction_t func, ustorage_cbw_t cbw)
data = (struct mstorage*)func->user_data;
buf = data->ep_in->buffer;
- sector_count = data->geometry.sector_count;
+ sector_count = data->geometry.sector_count - 1; /* Last Logical Block Address */
sector_size = data->geometry.bytes_per_sector;
buf[0] = sector_count >> 24;
@@ -606,8 +605,11 @@ static rt_err_t _ep_in_handler(ufunction_t func, rt_size_t size)
rt_usbd_ep_set_stall(func->device, data->ep_out);
}
else
- {
- rt_usbd_ep_set_stall(func->device, data->ep_in);
+ {
+ //rt_kprintf("warning:in stall path but not stall\n");
+
+ /* FIXME: Disable the operation or the disk cannot work. */
+ //rt_usbd_ep_set_stall(func->device, data->ep_in);
}
data->csw_response.data_reside = 0;
}
@@ -715,9 +717,22 @@ static void _cb_len_calc(ufunction_t func, struct scsi_cmd* cmd,
break;
}
}
+
+ //workaround: for stability in full-speed mode
+ else if(cmd->cmd_len == 12)
+ {
+ switch(cmd->type)
+ {
+ case COUNT:
+ data->cb_data_size = cbw->cb[4];
+ break;
+ default:
+ break;
+ }
+ }
else
{
-// rt_kprintf("cmd_len error %d\n", cmd->cmd_len);
+ rt_kprintf("cmd_len error %d\n", cmd->cmd_len);
}
}
@@ -733,7 +748,7 @@ static rt_bool_t _cbw_verify(ufunction_t func, struct scsi_cmd* cmd,
data = (struct mstorage*)func->user_data;
if(cmd->cmd_len != cbw->cb_len)
{
- // rt_kprintf("cb_len error\n");
+ rt_kprintf("cb_len error\n");
cmd->cmd_len = cbw->cb_len;
}
@@ -764,7 +779,7 @@ static rt_bool_t _cbw_verify(ufunction_t func, struct scsi_cmd* cmd,
if(cbw->xfer_len < data->cb_data_size)
{
- // rt_kprintf("xfer_len < data_size\n");
+ rt_kprintf("xfer_len < data_size\n");
data->cb_data_size = cbw->xfer_len;
data->csw_response.status = 1;
}
@@ -955,7 +970,7 @@ static rt_err_t _function_enable(ufunction_t func)
struct mstorage *data;
RT_ASSERT(func != RT_NULL);
RT_DEBUG_LOG(RT_DEBUG_USB, ("Mass storage function enabled\n"));
- data = (struct mstorage*)func->user_data;
+ data = (struct mstorage*)func->user_data;
data->disk = rt_device_find(RT_USB_MSTORAGE_DISK_NAME);
if(data->disk == RT_NULL)
diff --git a/components/drivers/usb/usbdevice/class/winusb.c b/components/drivers/usb/usbdevice/class/winusb.c
index bf4b353d73..4af6dba3cf 100644
--- a/components/drivers/usb/usbdevice/class/winusb.c
+++ b/components/drivers/usb/usbdevice/class/winusb.c
@@ -8,8 +8,6 @@
* 2017-11-16 ZYH first version
*/
#include <rthw.h>
-#include <rtthread.h>
-#include <rtservice.h>
#include <rtdevice.h>
#include <drivers/usb_device.h>
#include "winusb.h"
@@ -121,7 +119,7 @@ const static char* _ustring[] =
ALIGN(4)
struct usb_os_proerty winusb_proerty[] =
{
- USB_OS_PROERTY_DESC(USB_OS_PROERTY_TYPE_REG_SZ,"DeviceInterfaceGUID",RT_WINUSB_GUID),
+ USB_OS_PROPERTY_DESC(USB_OS_PROPERTY_TYPE_REG_SZ,"DeviceInterfaceGUID",RT_WINUSB_GUID),
};
ALIGN(4)
diff --git a/components/drivers/usb/usbdevice/core/core.c b/components/drivers/usb/usbdevice/core/usbdevice_core.c
index 584556303f..ef569d7bf2 100644
--- a/components/drivers/usb/usbdevice/core/core.c
+++ b/components/drivers/usb/usbdevice/core/usbdevice_core.c
@@ -1010,7 +1010,7 @@ udevice_t rt_usbd_device_new(void)
udevice = (udevice_t)rt_malloc(sizeof(struct udevice));
if(udevice == RT_NULL)
{
- rt_kprintf("alloc memery failed\n");
+ rt_kprintf("alloc memory failed\n");
return RT_NULL;
}
rt_memset(udevice, 0, sizeof(struct udevice));
@@ -1124,7 +1124,7 @@ uconfig_t rt_usbd_config_new(void)
cfg = (uconfig_t)rt_malloc(sizeof(struct uconfig));
if(cfg == RT_NULL)
{
- rt_kprintf("alloc memery failed\n");
+ rt_kprintf("alloc memory failed\n");
return RT_NULL;
}
rt_memset(cfg, 0, sizeof(struct uconfig));
@@ -1163,7 +1163,7 @@ uintf_t rt_usbd_interface_new(udevice_t device, uintf_handler_t handler)
intf = (uintf_t)rt_malloc(sizeof(struct uinterface));
if(intf == RT_NULL)
{
- rt_kprintf("alloc memery failed\n");
+ rt_kprintf("alloc memory failed\n");
return RT_NULL;
}
intf->intf_num = device->nr_intf;
@@ -1198,14 +1198,14 @@ ualtsetting_t rt_usbd_altsetting_new(rt_size_t desc_size)
setting = (ualtsetting_t)rt_malloc(sizeof(struct ualtsetting));
if(setting == RT_NULL)
{
- rt_kprintf("alloc memery failed\n");
+ rt_kprintf("alloc memory failed\n");
return RT_NULL;
}
/* allocate memory for the desc */
setting->desc = rt_malloc(desc_size);
if (setting->desc == RT_NULL)
{
- rt_kprintf("alloc desc memery failed\n");
+ rt_kprintf("alloc desc memory failed\n");
rt_free(setting);
return RT_NULL;
}
@@ -1263,7 +1263,7 @@ ufunction_t rt_usbd_function_new(udevice_t device, udev_desc_t dev_desc,
func = (ufunction_t)rt_malloc(sizeof(struct ufunction));
if(func == RT_NULL)
{
- rt_kprintf("alloc memery failed\n");
+ rt_kprintf("alloc memory failed\n");
return RT_NULL;
}
func->dev_desc = dev_desc;
@@ -1298,7 +1298,7 @@ uep_t rt_usbd_endpoint_new(uep_desc_t ep_desc, udep_handler_t handler)
ep = (uep_t)rt_malloc(sizeof(struct uendpoint));
if(ep == RT_NULL)
{
- rt_kprintf("alloc memery failed\n");
+ rt_kprintf("alloc memory failed\n");
return RT_NULL;
}
ep->ep_desc = ep_desc;
@@ -2204,7 +2204,7 @@ static struct rt_thread usb_thread;
#define USBD_MQ_MAX_MSG 16
/* internal of the message queue: every message is associated with a pointer,
* so in order to recveive USBD_MQ_MAX_MSG messages, we have to allocate more
- * than USBD_MQ_MSG_SZ*USBD_MQ_MAX_MSG memery. */
+ * than USBD_MQ_MSG_SZ*USBD_MQ_MAX_MSG memory. */
static rt_uint8_t usb_mq_pool[(USBD_MQ_MSG_SZ+sizeof(void*))*USBD_MQ_MAX_MSG];
/**
diff --git a/components/drivers/usb/usbhost/SConscript b/components/drivers/usb/usbhost/SConscript
index b12adfc5ad..081c732819 100644
--- a/components/drivers/usb/usbhost/SConscript
+++ b/components/drivers/usb/usbhost/SConscript
@@ -3,7 +3,7 @@ from building import *
cwd = GetCurrentDir()
src = Split("""
-core/core.c
+core/usbhost_core.c
core/driver.c
core/usbhost.c
core/hub.c
diff --git a/components/drivers/usb/usbhost/class/adk.h b/components/drivers/usb/usbhost/class/adk.h
index 041d47c674..c582ad7f17 100644
--- a/components/drivers/usb/usbhost/class/adk.h
+++ b/components/drivers/usb/usbhost/class/adk.h
@@ -8,8 +8,8 @@
* 2011-12-12 Yi Qiu first version
*/
-#ifndef __HID_H__
-#define __HID_H__
+#ifndef __ADK_H__
+#define __ADK_H__
#include <rtthread.h>
diff --git a/components/drivers/usb/usbhost/class/udisk.c b/components/drivers/usb/usbhost/class/udisk.c
index 1509a26105..6c8030b29a 100644
--- a/components/drivers/usb/usbhost/class/udisk.c
+++ b/components/drivers/usb/usbhost/class/udisk.c
@@ -186,7 +186,7 @@ rt_err_t rt_udisk_run(struct uhintf* intf)
{
int i = 0;
rt_err_t ret;
- char dname[4];
+ char dname[8];
char sname[8];
rt_uint8_t max_lun, *sector, sense[18], inquiry[36];
struct dfs_partition part[MAX_PARTITION_COUNT];
diff --git a/components/drivers/usb/usbhost/core/hub.c b/components/drivers/usb/usbhost/core/hub.c
index 80ed9b4e3f..eefa571472 100644
--- a/components/drivers/usb/usbhost/core/hub.c
+++ b/components/drivers/usb/usbhost/core/hub.c
@@ -417,8 +417,13 @@ static rt_err_t rt_usbh_hub_port_change(uhub_t hub)
if(reconnect)
{
- if(hub->child[i] != RT_NULL && hub->child[i]->status != DEV_STATUS_IDLE)
+ if(hub->child[i] != RT_NULL && hub->child[i]->status != DEV_STATUS_IDLE)
+ {
rt_usbh_detach_instance(hub->child[i]);
+
+ /* Child device have been detach. Set hub->child[i] to NULL. */
+ hub->child[i] = RT_NULL;
+ }
ret = rt_usbh_hub_port_debounce(hub, i + 1);
if(ret != RT_EOK) continue;
@@ -508,6 +513,7 @@ static rt_err_t rt_usbh_hub_enable(void *arg)
/* create a hub instance */
hub = rt_malloc(sizeof(struct uhub));
+ RT_ASSERT(hub != RT_NULL);
rt_memset(hub, 0, sizeof(struct uhub));
/* make interface instance's user data point to hub instance */
@@ -531,7 +537,12 @@ static rt_err_t rt_usbh_hub_enable(void *arg)
}
/* get hub ports number */
- hub->num_ports = hub->hub_desc.num_ports;
+ /* If hub device supported ports over USB_HUB_PORT_NUM(Ex: 8 port hub). Set hub->num_ports to USB_HUB_PORT_NUM */
+ if(hub->hub_desc.num_ports > USB_HUB_PORT_NUM)
+ hub->num_ports = USB_HUB_PORT_NUM;
+ else
+ hub->num_ports = hub->hub_desc.num_ports;
+
hub->hcd = device->hcd;
hub->self = device;
@@ -606,7 +617,6 @@ static rt_err_t rt_usbh_hub_disable(void* arg)
}
if(hub != RT_NULL) rt_free(hub);
- if(intf != RT_NULL) rt_free(intf);
return RT_EOK;
}
diff --git a/components/drivers/usb/usbhost/core/core.c b/components/drivers/usb/usbhost/core/usbhost_core.c
index 71341a33c3..d72dca82f2 100644
--- a/components/drivers/usb/usbhost/core/core.c
+++ b/components/drivers/usb/usbhost/core/usbhost_core.c
@@ -162,6 +162,10 @@ rt_err_t rt_usbh_attatch_instance(uinst_t device)
/* alloc memory for configuration descriptor */
device->cfg_desc = (ucfg_desc_t)rt_malloc(cfg_desc.wTotalLength);
+ if(device->cfg_desc == RT_NULL)
+ {
+ return RT_ENOMEM;
+ }
rt_memset(device->cfg_desc, 0, cfg_desc.wTotalLength);
/* get full configuration descriptor */
@@ -219,6 +223,10 @@ rt_err_t rt_usbh_attatch_instance(uinst_t device)
{
/* allocate memory for interface device */
device->intf[i] = (struct uhintf*)rt_malloc(sizeof(struct uhintf));
+ if(device->intf[i] == RT_NULL)
+ {
+ return RT_ENOMEM;
+ }
device->intf[i]->drv = drv;
device->intf[i]->device = device;
device->intf[i]->intf_desc = intf_desc;
diff --git a/components/drivers/watchdog/watchdog.c b/components/drivers/watchdog/watchdog.c
index 196f02039d..09a6bf4fad 100644
--- a/components/drivers/watchdog/watchdog.c
+++ b/components/drivers/watchdog/watchdog.c
@@ -14,7 +14,7 @@
/* RT-Thread Device Interface */
/*
- * This function initializes serial
+ * This function initializes watchdog
*/
static rt_err_t rt_watchdog_init(struct rt_device *dev)
{
diff --git a/components/drivers/wlan/wlan_dev.c b/components/drivers/wlan/wlan_dev.c
index cbfd50a6c3..347e6a57d4 100644
--- a/components/drivers/wlan/wlan_dev.c
+++ b/components/drivers/wlan/wlan_dev.c
@@ -102,7 +102,7 @@ rt_err_t rt_wlan_dev_connect(struct rt_wlan_device *device, struct rt_wlan_info
if ((password_len > RT_WLAN_PASSWORD_MAX_LENGTH) ||
(info->ssid.len > RT_WLAN_SSID_MAX_LENGTH))
{
- LOG_E("L:%d password or ssid is to long", __LINE__);
+ LOG_E("L:%d password or ssid is too long", __LINE__);
return -RT_ERROR;
}
rt_memset(&sta_info, 0, sizeof(struct rt_sta_info));
@@ -150,7 +150,7 @@ rt_err_t rt_wlan_dev_ap_start(struct rt_wlan_device *device, struct rt_wlan_info
if ((password_len > RT_WLAN_PASSWORD_MAX_LENGTH) ||
(info->ssid.len > RT_WLAN_SSID_MAX_LENGTH))
{
- LOG_E("L:%d password or ssid is to long", __LINE__);
+ LOG_E("L:%d password or ssid is too long", __LINE__);
return -RT_ERROR;
}
@@ -530,7 +530,7 @@ rt_err_t rt_wlan_dev_scan(struct rt_wlan_device *device, struct rt_wlan_info *in
{
if (info->ssid.len > RT_WLAN_SSID_MAX_LENGTH)
{
- LOG_E("L:%d ssid is to long", __LINE__);
+ LOG_E("L:%d ssid is too long", __LINE__);
return -RT_EINVAL;
}
rt_memcpy(&scan_info.ssid, &info->ssid, sizeof(rt_wlan_ssid_t));
diff --git a/components/drivers/wlan/wlan_mgnt.c b/components/drivers/wlan/wlan_mgnt.c
index cf2204c6b3..fefe700acc 100644
--- a/components/drivers/wlan/wlan_mgnt.c
+++ b/components/drivers/wlan/wlan_mgnt.c
@@ -713,7 +713,7 @@ static void rt_wlan_event_dispatch(struct rt_wlan_device *device, rt_wlan_dev_ev
}
COMPLETE_UNLOCK();
#ifdef RT_WLAN_WORK_THREAD_ENABLE
- rt_wlan_send_to_thread(user_event, RT_NULL, 0);
+ rt_wlan_send_to_thread(user_event, user_buff.data, user_buff.len);
#else
{
void *user_parameter;