29
29
#endif
30
30
#endif
31
31
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
43
36
#endif
44
-
45
- USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t msc_sector [512 ];
46
37
47
38
static rt_err_t rt_udisk_init (rt_device_t dev )
48
39
{
@@ -60,36 +51,29 @@ static ssize_t rt_udisk_read(rt_device_t dev, rt_off_t pos, void *buffer,
60
51
{
61
52
struct usbh_msc * msc_class = (struct usbh_msc * )dev -> user_data ;
62
53
int ret ;
54
+ rt_uint8_t * align_buf ;
63
55
56
+ align_buf = (rt_uint8_t * )buffer ;
64
57
#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 );
69
60
if (!align_buf ) {
70
61
rt_kprintf ("msc get align buf failed\n" );
71
62
return 0 ;
72
63
}
73
64
} else {
74
- align_buf = (rt_uint32_t * )buffer ;
75
65
}
76
-
66
+ #endif
77
67
ret = usbh_msc_scsi_read10 (msc_class , pos , (uint8_t * )align_buf , size );
78
68
if (ret < 0 ) {
79
69
rt_kprintf ("usb mass_storage read failed\n" );
80
70
return 0 ;
81
71
}
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 );
85
75
rt_free_align (align_buf );
86
76
}
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
- }
93
77
#endif
94
78
return size ;
95
79
}
@@ -99,37 +83,29 @@ static ssize_t rt_udisk_write(rt_device_t dev, rt_off_t pos, const void *buffer,
99
83
{
100
84
struct usbh_msc * msc_class = (struct usbh_msc * )dev -> user_data ;
101
85
int ret ;
86
+ rt_uint8_t * align_buf ;
102
87
88
+ align_buf = (rt_uint8_t * )buffer ;
103
89
#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 );
108
92
if (!align_buf ) {
109
93
rt_kprintf ("msc get align buf failed\n" );
110
94
return 0 ;
111
95
}
112
96
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 );
116
98
}
117
-
118
- rt_hw_cpu_dcache_ops (RT_HW_CACHE_FLUSH , align_buf , size * msc_class -> blocksize );
99
+ #endif
119
100
ret = usbh_msc_scsi_write10 (msc_class , pos , (uint8_t * )align_buf , size );
120
101
if (ret < 0 ) {
121
102
rt_kprintf ("usb mass_storage write failed\n" );
122
103
return 0 ;
123
104
}
124
- if ((uint32_t )buffer & (RT_ALIGN_SIZE - 1 )) {
105
+ #ifdef RT_USING_CACHE
106
+ if ((uint32_t )buffer & (CONFIG_USB_ALIGN_SIZE - 1 )) {
125
107
rt_free_align (align_buf );
126
108
}
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
- }
133
109
#endif
134
110
135
111
return size ;
0 commit comments