Skip to content

Commit e0fedaa

Browse files
committed
refactor(class/usbd_msc): replace cherryrb with only variable
Signed-off-by: sakumisu <1203593632@qq.com>
1 parent d10b88c commit e0fedaa

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

class/msc/usbd_msc.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include "usb_scsi.h"
1010
#if defined(CONFIG_USBDEV_MSC_THREAD)
1111
#include "usb_osal.h"
12-
#elif defined(CONFIG_USBDEV_MSC_POLLING)
13-
#include "chry_ringbuffer.h"
1412
#endif
1513

1614
#define MSD_OUT_EP_IDX 0
@@ -53,8 +51,7 @@ USB_NOCACHE_RAM_SECTION struct usbd_msc_priv {
5351
usb_osal_thread_t usbd_msc_thread;
5452
uint32_t nbytes;
5553
#elif defined(CONFIG_USBDEV_MSC_POLLING)
56-
chry_ringbuffer_t msc_rb;
57-
uint8_t msc_rb_pool[2];
54+
uint32_t event;
5855
uint32_t nbytes;
5956
#endif
6057
} g_usbd_msc[CONFIG_USBDEV_MAX_BUS];
@@ -114,7 +111,7 @@ void msc_storage_notify_handler(uint8_t busid, uint8_t event, void *arg)
114111
USB_LOG_ERR("No memory to alloc for g_usbd_msc[busid].usbd_msc_thread\r\n");
115112
}
116113
#elif defined(CONFIG_USBDEV_MSC_POLLING)
117-
chry_ringbuffer_init(&g_usbd_msc[busid].msc_rb, g_usbd_msc[busid].msc_rb_pool, sizeof(g_usbd_msc[busid].msc_rb_pool));
114+
g_usbd_msc[busid].event = 0;
118115
#endif
119116
break;
120117
case USBD_EVENT_DEINIT:
@@ -539,7 +536,7 @@ static bool SCSI_read10(uint8_t busid, uint8_t **data, uint32_t *len)
539536
usb_osal_mq_send(g_usbd_msc[busid].usbd_msc_mq, MSC_DATA_IN);
540537
return true;
541538
#elif defined(CONFIG_USBDEV_MSC_POLLING)
542-
chry_ringbuffer_write_byte(&g_usbd_msc[busid].msc_rb, MSC_DATA_IN);
539+
g_usbd_msc[busid].event = MSC_DATA_IN;
543540
return true;
544541
#else
545542
return SCSI_processRead(busid);
@@ -577,7 +574,7 @@ static bool SCSI_read12(uint8_t busid, uint8_t **data, uint32_t *len)
577574
usb_osal_mq_send(g_usbd_msc[busid].usbd_msc_mq, MSC_DATA_IN);
578575
return true;
579576
#elif defined(CONFIG_USBDEV_MSC_POLLING)
580-
chry_ringbuffer_write_byte(&g_usbd_msc[busid].msc_rb, MSC_DATA_IN);
577+
g_usbd_msc[busid].event = MSC_DATA_IN;
581578
return true;
582579
#else
583580
return SCSI_processRead(busid);
@@ -852,7 +849,7 @@ void mass_storage_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
852849
usb_osal_mq_send(g_usbd_msc[busid].usbd_msc_mq, MSC_DATA_OUT);
853850
#elif defined(CONFIG_USBDEV_MSC_POLLING)
854851
g_usbd_msc[busid].nbytes = nbytes;
855-
chry_ringbuffer_write_byte(&g_usbd_msc[busid].msc_rb, MSC_DATA_OUT);
852+
g_usbd_msc[busid].event = MSC_DATA_OUT;
856853
#else
857854
if (SCSI_processWrite(busid, nbytes) == false) {
858855
usbd_msc_send_csw(busid, CSW_STATUS_CMD_FAILED); /* send fail status to host,and the host will retry*/
@@ -881,7 +878,7 @@ void mass_storage_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
881878
#if defined(CONFIG_USBDEV_MSC_THREAD)
882879
usb_osal_mq_send(g_usbd_msc[busid].usbd_msc_mq, MSC_DATA_IN);
883880
#elif defined(CONFIG_USBDEV_MSC_POLLING)
884-
chry_ringbuffer_write_byte(&g_usbd_msc[busid].msc_rb, MSC_DATA_IN);
881+
g_usbd_msc[busid].event = MSC_DATA_IN;
885882
#else
886883
if (SCSI_processRead(busid) == false) {
887884
usbd_msc_send_csw(busid, CSW_STATUS_CMD_FAILED); /* send fail status to host,and the host will retry*/
@@ -940,7 +937,10 @@ void usbd_msc_polling(uint8_t busid)
940937
{
941938
uint8_t event;
942939

943-
if (chry_ringbuffer_read_byte(&g_usbd_msc[busid].msc_rb, &event)) {
940+
event = g_usbd_msc[busid].event;
941+
942+
if (event != 0) {
943+
g_usbd_msc[busid].event = 0;
944944
USB_LOG_DBG("event:%d\r\n", event);
945945
if (event == MSC_DATA_OUT) {
946946
if (SCSI_processWrite(busid, g_usbd_msc[busid].nbytes) == false) {
@@ -979,7 +979,8 @@ struct usbd_interface *usbd_msc_init_intf(uint8_t busid, struct usbd_interface *
979979

980980
if (CONFIG_USBDEV_MSC_MAX_BUFSIZE % g_usbd_msc[busid].scsi_blk_size[i]) {
981981
USB_LOG_ERR("CONFIG_USBDEV_MSC_MAX_BUFSIZE must be a multiple of block size\r\n");
982-
while(1){}
982+
while (1) {
983+
}
983984
}
984985
}
985986

0 commit comments

Comments
 (0)