From bed2f6eb5e79364ec494d294ba7a1aa63e49d852 Mon Sep 17 00:00:00 2001 From: bsongis Date: Fri, 14 Sep 2012 18:44:56 +0000 Subject: [PATCH] [sky9x] Massstorage again (format / umount still not ok) --- src/ersky9x/diskio.c | 35 +++++++++++++++-- .../usb/common/massstorage/massstorage.dir | 39 ------------------- 2 files changed, 31 insertions(+), 43 deletions(-) delete mode 100644 src/ersky9x/libraries/usb/common/massstorage/massstorage.dir diff --git a/src/ersky9x/diskio.c b/src/ersky9x/diskio.c index 4fd2702ee..bca15136c 100644 --- a/src/ersky9x/diskio.c +++ b/src/ersky9x/diskio.c @@ -39,6 +39,7 @@ /*-----------------------------------------------------------------------*/ #include "board.h" +#include "debug.h" #include "../FatFs/diskio.h" #include "../FatFs/ff.h" #include "../CoOS/kernel/CoOS.h" @@ -965,6 +966,7 @@ uint32_t sd_read_block(uint32_t block_no, uint32_t *data) { uint32_t result = 0; Hsmci *phsmci = HSMCI; + int32_t retry; CoEnterMutexSection(sdMutex); @@ -979,8 +981,8 @@ uint32_t sd_read_block(uint32_t block_no, uint32_t *data) phsmci->HSMCI_PTCR = HSMCI_PTCR_RXTEN; phsmci->HSMCI_CMDR = SD_READ_SINGLE_BLOCK; - uint8_t retry = 100; - while (retry-- > 0) { + retry = 500; + while (--retry >= 0) { CoTickDelay(1); // 2ms if (phsmci->HSMCI_SR & HSMCI_SR_ENDRX) { result = 1; @@ -1001,11 +1003,25 @@ uint32_t sd_write_block( uint32_t block_no, uint32_t *data ) { uint32_t result = 0; Hsmci *phsmci = HSMCI; + int32_t retry; CoEnterMutexSection(sdMutex); if (sd_card_ready()) { + + TRACE_ERROR("Sector %d ", block_no); + + retry = 500; + while (--retry >= 0) { + if (phsmci->HSMCI_SR & HSMCI_SR_NOTBUSY) { + break; + } + CoTickDelay(1); // 2ms + } + + if (retry >= 0) { sd_cmd16(); + // Block size = 512, nblocks = 1 phsmci->HSMCI_BLKR = ((512) << 16) | 1; phsmci->HSMCI_MR = (phsmci->HSMCI_MR & (~(HSMCI_MR_BLKLEN_Msk|HSMCI_MR_FBYTE))) | (HSMCI_MR_PDCMODE|HSMCI_MR_WRPROOF|HSMCI_MR_RDPROOF) | (512 << 16); @@ -1015,14 +1031,25 @@ uint32_t sd_write_block( uint32_t block_no, uint32_t *data ) phsmci->HSMCI_CMDR = SD_WRITE_SINGLE_BLOCK; phsmci->HSMCI_PTCR = HSMCI_PTCR_TXTEN; - uint8_t retry = 100; - while (retry-- > 0) { + retry = 500; + while (--retry >= 0) { CoTickDelay(1); // 2ms if (phsmci->HSMCI_SR & HSMCI_SR_NOTBUSY) { result = 1; break; } } + + if (retry < 0) { + TRACE_ERROR("ko (data=%d)\n\r", (uint32_t)data); + } + else { + TRACE_ERROR("ok\n\r"); + } + } + else { + TRACE_ERROR("wait ko\n\r"); + } } /* Disable PDC */ diff --git a/src/ersky9x/libraries/usb/common/massstorage/massstorage.dir b/src/ersky9x/libraries/usb/common/massstorage/massstorage.dir deleted file mode 100644 index f9474f1af..000000000 --- a/src/ersky9x/libraries/usb/common/massstorage/massstorage.dir +++ /dev/null @@ -1,39 +0,0 @@ -/* ---------------------------------------------------------------------------- - * ATMEL Microcontroller Software Support - * ---------------------------------------------------------------------------- - * Copyright (c) 2008, Atmel Corporation - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the disclaimer below. - * - * Atmel's name may not be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE - * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * ---------------------------------------------------------------------------- - */ - -//------------------------------------------------------------------------------ -/// \dir -/// !Purpose -/// -/// This directory contains structures and definitions related to the USB mass -/// storage specification. -/// - Mass-storage-specific descriptors, prefixed with MS and suffixed with -/// Descriptor. -//------------------------------------------------------------------------------ -