1
- /**************************************************************************/
2
- /*!
3
- @file usb_msc_flash.c
4
- @author hathach (tinyusb.org)
5
-
6
- @section LICENSE
7
-
8
- Software License Agreement (BSD License)
9
-
10
- Copyright (c) 2018, Adafruit Industries (adafruit.com)
11
- All rights reserved.
12
-
13
- Redistribution and use in source and binary forms, with or without
14
- modification, are permitted provided that the following conditions are met:
15
- 1. Redistributions of source code must retain the above copyright
16
- notice, this list of conditions and the following disclaimer.
17
- 2. Redistributions in binary form must reproduce the above copyright
18
- notice, this list of conditions and the following disclaimer in the
19
- documentation and/or other materials provided with the distribution.
20
- 3. Neither the name of the copyright holders nor the
21
- names of its contributors may be used to endorse or promote products
22
- derived from this software without specific prior written permission.
23
-
24
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
25
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- */
35
- /**************************************************************************/
1
+ /*
2
+ * This file is part of the MicroPython project, http://micropython.org/
3
+ *
4
+ * The MIT License (MIT)
5
+ *
6
+ * Copyright (c) 2018 hathach for Adafruit Industries
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
36
26
37
27
#include "tusb.h"
38
28
#include "internal_flash.h"
43
33
#include "lib/oofatfs/ff.h"
44
34
#include "py/mpstate.h"
45
35
36
+ #include "supervisor/shared/autoreload.h"
37
+
46
38
/*------------------------------------------------------------------*/
47
39
/* MACRO TYPEDEF CONSTANT ENUM
48
40
*------------------------------------------------------------------*/
56
48
// Callback invoked when received an SCSI command not in built-in list below
57
49
// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE
58
50
// - READ10 and WRITE10 has their own callbacks
59
- int32_t tud_msc_scsi_cb (uint8_t lun , uint8_t const scsi_cmd [16 ], void * buffer , uint16_t bufsize ) {
60
- void const * response = NULL ;
51
+ int32_t tud_msc_scsi_cb (uint8_t lun , const uint8_t scsi_cmd [16 ], void * buffer , uint16_t bufsize ) {
52
+ const void * response = NULL ;
61
53
uint16_t resplen = 0 ;
62
54
63
55
switch ( scsi_cmd [0 ] ) {
@@ -110,7 +102,7 @@ int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buf
110
102
(void ) lun ;
111
103
(void ) offset ;
112
104
113
- uint32_t const block_count = bufsize / MSC_FLASH_BLOCK_SIZE ;
105
+ const uint32_t block_count = bufsize / MSC_FLASH_BLOCK_SIZE ;
114
106
115
107
internal_flash_read_blocks (buffer , lba , block_count );
116
108
@@ -123,7 +115,7 @@ int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* bu
123
115
(void ) lun ;
124
116
(void ) offset ;
125
117
126
- uint32_t const block_count = bufsize / MSC_FLASH_BLOCK_SIZE ;
118
+ const uint32_t block_count = bufsize / MSC_FLASH_BLOCK_SIZE ;
127
119
128
120
// bufsize <= CFG_TUD_MSC_BUFSIZE (4096)
129
121
internal_flash_write_blocks (buffer , lba , block_count );
@@ -145,4 +137,7 @@ void tud_msc_write10_complete_cb (uint8_t lun) {
145
137
146
138
// flush pending cache when write10 is complete
147
139
internal_flash_flush ();
140
+
141
+ // This write is complete, start the autoreload clock.
142
+ autoreload_start ();
148
143
}
0 commit comments