2929#endif
3030#endif
3131
32- #if defined(BSP_USING_BL61X )
33- #include "bflb_l1c.h"
34-
35- void rt_hw_cpu_dcache_ops (int ops , void * addr , int size )
36- {
37- if (ops == RT_HW_CACHE_FLUSH ) {
38- bflb_l1c_dcache_clean_range (addr , size );
39- } else {
40- bflb_l1c_dcache_invalidate_range (addr , size );
41- }
42- }
32+ #ifdef RT_USING_CACHE
33+ #ifndef CONFIG_USB_DCACHE_ENABLE
34+ #error CONFIG_USB_DCACHE_ENABLE must be enabled to use msc disk
35+ #endif
4336#endif
44-
45- USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t msc_sector [512 ];
4637
4738static rt_err_t rt_udisk_init (rt_device_t dev )
4839{
@@ -60,36 +51,29 @@ static ssize_t rt_udisk_read(rt_device_t dev, rt_off_t pos, void *buffer,
6051{
6152 struct usbh_msc * msc_class = (struct usbh_msc * )dev -> user_data ;
6253 int ret ;
54+ rt_uint8_t * align_buf ;
6355
56+ align_buf = (rt_uint8_t * )buffer ;
6457#ifdef RT_USING_CACHE
65- rt_uint32_t * align_buf ;
66-
67- if ((uint32_t )buffer & (RT_ALIGN_SIZE - 1 )) {
68- align_buf = rt_malloc_align (size * msc_class -> blocksize , RT_ALIGN_SIZE );
58+ if ((uint32_t )buffer & (CONFIG_USB_ALIGN_SIZE - 1 )) {
59+ align_buf = rt_malloc_align (size * msc_class -> blocksize , CONFIG_USB_ALIGN_SIZE );
6960 if (!align_buf ) {
7061 rt_kprintf ("msc get align buf failed\n" );
7162 return 0 ;
7263 }
7364 } else {
74- align_buf = (rt_uint32_t * )buffer ;
7565 }
76-
66+ #endif
7767 ret = usbh_msc_scsi_read10 (msc_class , pos , (uint8_t * )align_buf , size );
7868 if (ret < 0 ) {
7969 rt_kprintf ("usb mass_storage read failed\n" );
8070 return 0 ;
8171 }
82- rt_hw_cpu_dcache_ops ( RT_HW_CACHE_INVALIDATE , align_buf , size * msc_class -> blocksize );
83- if ((uint32_t )buffer & (RT_ALIGN_SIZE - 1 )) {
84- rt_memcpy (buffer , align_buf , size * msc_class -> blocksize );
72+ #ifdef RT_USING_CACHE
73+ if ((uint32_t )buffer & (CONFIG_USB_ALIGN_SIZE - 1 )) {
74+ usb_memcpy (buffer , align_buf , size * msc_class -> blocksize );
8575 rt_free_align (align_buf );
8676 }
87- #else
88- ret = usbh_msc_scsi_read10 (msc_class , pos , buffer , size );
89- if (ret < 0 ) {
90- rt_kprintf ("usb mass_storage read failed\n" );
91- return 0 ;
92- }
9377#endif
9478 return size ;
9579}
@@ -99,37 +83,29 @@ static ssize_t rt_udisk_write(rt_device_t dev, rt_off_t pos, const void *buffer,
9983{
10084 struct usbh_msc * msc_class = (struct usbh_msc * )dev -> user_data ;
10185 int ret ;
86+ rt_uint8_t * align_buf ;
10287
88+ align_buf = (rt_uint8_t * )buffer ;
10389#ifdef RT_USING_CACHE
104- rt_uint32_t * align_buf ;
105-
106- if ((uint32_t )buffer & (RT_ALIGN_SIZE - 1 )) {
107- align_buf = rt_malloc_align (size * msc_class -> blocksize , RT_ALIGN_SIZE );
90+ if ((uint32_t )buffer & (CONFIG_USB_ALIGN_SIZE - 1 )) {
91+ align_buf = rt_malloc_align (size * msc_class -> blocksize , CONFIG_USB_ALIGN_SIZE );
10892 if (!align_buf ) {
10993 rt_kprintf ("msc get align buf failed\n" );
11094 return 0 ;
11195 }
11296
113- rt_memcpy (align_buf , buffer , size * msc_class -> blocksize );
114- } else {
115- align_buf = (rt_uint32_t * )buffer ;
97+ usb_memcpy (align_buf , buffer , size * msc_class -> blocksize );
11698 }
117-
118- rt_hw_cpu_dcache_ops (RT_HW_CACHE_FLUSH , align_buf , size * msc_class -> blocksize );
99+ #endif
119100 ret = usbh_msc_scsi_write10 (msc_class , pos , (uint8_t * )align_buf , size );
120101 if (ret < 0 ) {
121102 rt_kprintf ("usb mass_storage write failed\n" );
122103 return 0 ;
123104 }
124- if ((uint32_t )buffer & (RT_ALIGN_SIZE - 1 )) {
105+ #ifdef RT_USING_CACHE
106+ if ((uint32_t )buffer & (CONFIG_USB_ALIGN_SIZE - 1 )) {
125107 rt_free_align (align_buf );
126108 }
127- #else
128- ret = usbh_msc_scsi_write10 (msc_class , pos , buffer , size );
129- if (ret < 0 ) {
130- rt_kprintf ("usb mass_storage write failed\n" );
131- return 0 ;
132- }
133109#endif
134110
135111 return size ;
0 commit comments