[sky9x] Massstorage again (format / umount still not ok)

This commit is contained in:
bsongis
2012-09-14 18:44:56 +00:00
parent 0a1fa6bd7d
commit bed2f6eb5e
2 changed files with 31 additions and 43 deletions
+31 -4
View File
@@ -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 */
@@ -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.
//------------------------------------------------------------------------------