Skip to content

Commit

Permalink
Merge pull request #360 from 173210/master
Browse files Browse the repository at this point in the history
Update TMIO/FatFs
  • Loading branch information
AlbertoSONIC committed Jan 15, 2016
2 parents 3c82cd8 + 4387774 commit a88017a
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 95 deletions.
78 changes: 65 additions & 13 deletions rxtools/source/lib/fatfs/diskio.c
Expand Up @@ -7,14 +7,22 @@
/* storage control module to the FatFs module with a defined API. */
/*-----------------------------------------------------------------------*/

#include <stdbool.h>
#include "diskio.h" /* FatFs lower layer API */
#include <tmio/tmio.h>
#include "fs.h"
#include <nand.h>

/* Definitions of physical drive number for each media */
#define ATA 0
#define MMC 1
#define USB 2
enum {
DRV_SDMC,
DRV_NAND,
DRV_EMU,

DRV_NUM
};

static bool initedTmio = false;
static bool initedCrypto = false;

/*-----------------------------------------------------------------------*/
/* Inidialize a Drive */
Expand All @@ -24,8 +32,33 @@ DSTATUS disk_initialize (
BYTE pdrv /* Physical drive nmuber (0..) */
)
{
tmio_init();
return RES_OK;
uint32_t res;

if (initedTmio == false) {
tmio_init();
initedTmio = true;
}

if ((pdrv == DRV_EMU || pdrv == DRV_NAND) && initedCrypto == false) {
FSNandInitCrypto();
initedCrypto = true;
}

switch (pdrv) {
case DRV_EMU:
case DRV_SDMC:
res = tmio_init_sdmc();
break;

case DRV_NAND:
res = tmio_init_nand();
break;

default:
return RES_PARERR;
}

return res ? RES_ERROR : RES_OK;
}


Expand All @@ -38,7 +71,26 @@ DSTATUS disk_status (
BYTE pdrv /* Physical drive nmuber (0..) */
)
{
return RES_OK; // Stubbed
enum tmio_dev_id d;

if ((pdrv == DRV_EMU || pdrv == DRV_NAND) && initedCrypto == false)
return STA_NOINIT;

switch (pdrv) {
case DRV_EMU:
case DRV_SDMC:
d = TMIO_DEV_SDMC;
break;

case DRV_NAND:
d = TMIO_DEV_SDMC;
break;

default:
return RES_PARERR;
}

return tmio_dev[d].total_size > 0 ? RES_OK : STA_NOINIT;
}


Expand All @@ -55,14 +107,14 @@ DRESULT disk_read (
)
{
switch(pdrv){
case 0:
case DRV_SDMC:
if (tmio_readsectors(TMIO_DEV_SDMC, sector,count,(uint8_t *)buff))
return RES_PARERR;
break;
case 1:
case DRV_NAND:
nand_readsectors(sector, count, (uint8_t *)buff, CTRNAND);
break;
case 2:
case DRV_EMU:
emunand_readsectors(sector, count, (uint8_t *)buff, CTRNAND);
break;
}
Expand All @@ -84,14 +136,14 @@ DRESULT disk_write (
)
{
switch(pdrv){
case 0:
case DRV_SDMC:
if (tmio_writesectors(TMIO_DEV_SDMC, sector,count,(uint8_t *)buff))
return RES_PARERR;
break;
case 1:
case DRV_NAND:
nand_writesectors(sector, count, (uint8_t *)buff, CTRNAND);
break;
case 2:
case DRV_EMU:
emunand_writesectors(sector, count, (uint8_t *)buff, CTRNAND);
break;
}
Expand Down
1 change: 0 additions & 1 deletion rxtools/source/lib/fs.c
Expand Up @@ -22,7 +22,6 @@
static FATFS fs[3];
/**Init FileSystems.*/
bool FSInit(void) {
FSNandInitCrypto();
if (f_mount(&fs[0], _T("0:"), 0) != FR_OK) return 0; //SDCard
if (f_mount(&fs[1], _T("1:"), 0) != FR_OK) return 0; //NAND
if (f_mount(&fs[2], _T("2:"), 0) != FR_OK) ; //return 0; //EmuNAND, Sometimes it doesn't exist
Expand Down
58 changes: 58 additions & 0 deletions rxtools/source/lib/tmio/command.h
@@ -0,0 +1,58 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright (c) 2016 173210
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU General Public License Version 2, as described below:
*
* This file is free software: you may copy, redistribute and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 2 of the License, or (at your
* option) any later version.
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

#ifndef COMMAND_H
#define COMMAND_H

enum {
// Class 1
MMC_IDLE = 0,
MMC_SEND_OP_COND = 1,
MMC_ALL_SEND_CID = 2,
MMC_SET_RELATIVE_ADDR = 3,
MMC_SWITCH = 6,
MMC_SELECT_CARD = 7,
MMC_SEND_CSD = 9,
MMC_SEND_STATUS = 13,

// Class 2
MMC_SET_BLOCKLEN = 16,
MMC_READ_BLOCK_MULTI = 18,

// Class 4
MMC_WRITE_BLOCK_MULTI = 25,

// Class 8
MMC_APP_CMD = 55
};

enum {
// Class 0
SD_SEND_IF_COND = 8,

// Application command
SD_APP_OP_COND = 41
};

#endif

0 comments on commit a88017a

Please sign in to comment.