diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2019-04-09 14:40:36 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-09 14:40:36 -0700 |
| commit | 129e7255995b258c71d06227ac265c2746eac3af (patch) | |
| tree | e4cc247ba93ce0fcca75c614120d8c46c514f46e /supervisor | |
| parent | 19c6b8aa0c572acb2212014e0a2e7e324efbb35d (diff) | |
| parent | 5015036c06e12c158ca0b36a23fade8da6fbbf07 (diff) | |
Merge branch 'master' into master
Diffstat (limited to 'supervisor')
| -rw-r--r-- | supervisor/flash.h | 2 | ||||
| -rw-r--r-- | supervisor/shared/display.c | 5 | ||||
| -rw-r--r-- | supervisor/shared/external_flash/external_flash.c | 38 | ||||
| -rw-r--r-- | supervisor/shared/filesystem.c | 6 | ||||
| -rw-r--r-- | supervisor/shared/serial.c | 10 | ||||
| -rw-r--r-- | supervisor/shared/usb/usb.c | 12 |
6 files changed, 45 insertions, 28 deletions
diff --git a/supervisor/flash.h b/supervisor/flash.h index edf43f4b1..0a124353e 100644 --- a/supervisor/flash.h +++ b/supervisor/flash.h @@ -40,7 +40,6 @@ void supervisor_flash_init(void); uint32_t supervisor_flash_get_block_size(void); uint32_t supervisor_flash_get_block_count(void); -void supervisor_flash_flush(void); // these return 0 on success, non-zero on error mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks); @@ -49,5 +48,6 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, struct _fs_user_mount_t; void supervisor_flash_init_vfs(struct _fs_user_mount_t *vfs); void supervisor_flash_flush(void); +void supervisor_flash_release_cache(void); #endif // MICROPY_INCLUDED_SUPERVISOR_FLASH_H diff --git a/supervisor/shared/display.c b/supervisor/shared/display.c index e1400426e..0b3fbe178 100644 --- a/supervisor/shared/display.c +++ b/supervisor/shared/display.c @@ -34,7 +34,7 @@ #include "shared-bindings/displayio/TileGrid.h" #include "supervisor/memory.h" -extern uint32_t blinka_bitmap_data[]; +extern size_t blinka_bitmap_data[]; extern displayio_bitmap_t blinka_bitmap; extern displayio_group_t circuitpython_splash; @@ -81,6 +81,7 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) { void supervisor_stop_terminal(void) { if (tilegrid_tiles != NULL) { free_memory(tilegrid_tiles); + tilegrid_tiles = NULL; supervisor_terminal_text_grid.inline_tiles = false; supervisor_terminal_text_grid.tiles = NULL; } @@ -106,7 +107,7 @@ void supervisor_display_move_memory(void) { #endif } -uint32_t blinka_bitmap_data[32] = { +size_t blinka_bitmap_data[32] = { 0x00000011, 0x11000000, 0x00000111, 0x53100000, 0x00000111, 0x56110000, diff --git a/supervisor/shared/external_flash/external_flash.c b/supervisor/shared/external_flash/external_flash.c index 73b7f7f91..ad10bab51 100644 --- a/supervisor/shared/external_flash/external_flash.c +++ b/supervisor/shared/external_flash/external_flash.c @@ -272,6 +272,9 @@ uint32_t supervisor_flash_get_block_count(void) { // Flush the cache that was written to the scratch portion of flash. Only used // when ram is tight. static bool flush_scratch_flash(void) { + if (current_sector == NO_SECTOR_LOADED) { + return true; + } // First, copy out any blocks that we haven't touched from the sector we've // cached. bool copy_to_scratch_ok = true; @@ -360,9 +363,25 @@ static bool allocate_ram_cache(void) { return success; } +static void release_ram_cache(void) { + if (supervisor_cache != NULL) { + free_memory(supervisor_cache); + supervisor_cache = NULL; + } else { + m_free(MP_STATE_VM(flash_ram_cache)); + } + MP_STATE_VM(flash_ram_cache) = NULL; +} + // Flush the cached sector from ram onto the flash. We'll free the cache unless // keep_cache is true. static bool flush_ram_cache(bool keep_cache) { + if (current_sector == NO_SECTOR_LOADED) { + if (!keep_cache) { + release_ram_cache(); + } + return true; + } // First, copy out any blocks that we haven't touched from the sector // we've cached. If we don't do this we'll erase the data during the sector // erase below. @@ -403,22 +422,13 @@ static bool flush_ram_cache(bool keep_cache) { } // We're done with the cache for now so give it back. if (!keep_cache) { - if (supervisor_cache != NULL) { - free_memory(supervisor_cache); - supervisor_cache = NULL; - } else { - m_free(MP_STATE_VM(flash_ram_cache)); - } - MP_STATE_VM(flash_ram_cache) = NULL; + release_ram_cache(); } return true; } // Delegates to the correct flash flush method depending on the existing cache. static void spi_flash_flush_keep_cache(bool keep_cache) { - if (current_sector == NO_SECTOR_LOADED) { - return; - } #ifdef MICROPY_HW_LED_MSC port_pin_set_output_level(MICROPY_HW_LED_MSC, true); #endif @@ -436,9 +446,11 @@ static void spi_flash_flush_keep_cache(bool keep_cache) { #endif } -// External flash function used. If called externally we assume we won't need -// the cache after. void supervisor_flash_flush(void) { + spi_flash_flush_keep_cache(true); +} + +void supervisor_flash_release_cache(void) { spi_flash_flush_keep_cache(false); } @@ -502,7 +514,7 @@ bool external_flash_write_block(const uint8_t *data, uint32_t block) { return write_flash(address, data, FILESYSTEM_BLOCK_SIZE); } if (current_sector != NO_SECTOR_LOADED) { - spi_flash_flush_keep_cache(true); + supervisor_flash_flush(); } if (MP_STATE_VM(flash_ram_cache) == NULL && !allocate_ram_cache()) { erase_sector(flash_device->total_size - SPI_FLASH_ERASE_SIZE); diff --git a/supervisor/shared/filesystem.c b/supervisor/shared/filesystem.c index 68c6f4749..fa34ed0da 100644 --- a/supervisor/shared/filesystem.c +++ b/supervisor/shared/filesystem.c @@ -42,7 +42,9 @@ volatile bool filesystem_flush_requested = false; void filesystem_background(void) { if (filesystem_flush_requested) { - filesystem_flush(); + filesystem_flush_interval_ms = CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS; + // Flush but keep caches + supervisor_flash_flush(); filesystem_flush_requested = false; } } @@ -118,6 +120,8 @@ void filesystem_flush(void) { // Reset interval before next flush. filesystem_flush_interval_ms = CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS; supervisor_flash_flush(); + // Don't keep caches because this is called when starting or stopping the VM. + supervisor_flash_release_cache(); } void filesystem_set_internal_writable_by_usb(bool writable) { diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index ed210416f..a61899576 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -52,15 +52,13 @@ bool serial_bytes_available(void) { } void serial_write_substring(const char* text, uint32_t length) { - #if CIRCUITPY_DISPLAYIO +#if CIRCUITPY_DISPLAYIO int errcode; common_hal_terminalio_terminal_write(&supervisor_terminal, (const uint8_t*) text, length, &errcode); - #endif - if (!tud_cdc_connected()) { - return; - } +#endif + uint32_t count = 0; - while (count < length) { + while (count < length && tud_cdc_connected()) { count += tud_cdc_write(text + count, length - count); usb_background(); } diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index c77f1e417..02a5da6c5 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -92,13 +92,15 @@ void tud_mount_cb(void) { void tud_umount_cb(void) { } -uint32_t tusb_hal_millis(void) { - uint64_t ms; - uint32_t us; - current_tick(&ms, &us); - return (uint32_t) ms; +// Invoked when usb bus is suspended +// remote_wakeup_en : if host allows us to perform remote wakeup +// USB Specs: Within 7ms, device must draw an average current less than 2.5 mA from bus +void tud_suspend_cb(bool remote_wakeup_en) { } +// Invoked when usb bus is resumed +void tud_resume_cb(void) { +} // Invoked when cdc when line state changed e.g connected/disconnected // Use to reset to DFU when disconnect with 1200 bps |
