Skip to content

Commit f2c960e

Browse files
authored
Merge pull request #1205 from hathach/nrf52_autoreload
add autoreload for nrf52
2 parents 839b791 + e1fe7e7 commit f2c960e

File tree

1 file changed

+34
-39
lines changed

1 file changed

+34
-39
lines changed

ports/nrf/usb/usb_msc_flash.c

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
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+
*/
3626

3727
#include "tusb.h"
3828
#include "internal_flash.h"
@@ -43,6 +33,8 @@
4333
#include "lib/oofatfs/ff.h"
4434
#include "py/mpstate.h"
4535

36+
#include "supervisor/shared/autoreload.h"
37+
4638
/*------------------------------------------------------------------*/
4739
/* MACRO TYPEDEF CONSTANT ENUM
4840
*------------------------------------------------------------------*/
@@ -56,8 +48,8 @@
5648
// Callback invoked when received an SCSI command not in built-in list below
5749
// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE
5850
// - 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;
6153
uint16_t resplen = 0;
6254

6355
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
110102
(void) lun;
111103
(void) offset;
112104

113-
uint32_t const block_count = bufsize / MSC_FLASH_BLOCK_SIZE;
105+
const uint32_t block_count = bufsize / MSC_FLASH_BLOCK_SIZE;
114106

115107
internal_flash_read_blocks(buffer, lba, block_count);
116108

@@ -123,7 +115,7 @@ int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* bu
123115
(void) lun;
124116
(void) offset;
125117

126-
uint32_t const block_count = bufsize / MSC_FLASH_BLOCK_SIZE;
118+
const uint32_t block_count = bufsize / MSC_FLASH_BLOCK_SIZE;
127119

128120
// bufsize <= CFG_TUD_MSC_BUFSIZE (4096)
129121
internal_flash_write_blocks(buffer, lba, block_count);
@@ -145,4 +137,7 @@ void tud_msc_write10_complete_cb (uint8_t lun) {
145137

146138
// flush pending cache when write10 is complete
147139
internal_flash_flush();
140+
141+
// This write is complete, start the autoreload clock.
142+
autoreload_start();
148143
}

0 commit comments

Comments
 (0)