Add ramdisk storage driver. It will be useful for developing multi-driver storage

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18993 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Frank Gevaerts 2008-11-03 20:52:27 +00:00
parent 65d9ca8a6f
commit 214cd81f08
6 changed files with 206 additions and 4 deletions

View file

@ -117,6 +117,8 @@ drivers/ata_flash.c
target/arm/ata-nand-telechips.c
#elif (CONFIG_STORAGE & STORAGE_ATA)
drivers/ata.c
#elif (CONFIG_STORAGE & STORAGE_RAMDISK)
drivers/ramdisk.c
#endif /* CONFIG_STORAGE */
drivers/fat.c
#if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)

102
firmware/drivers/ramdisk.c Normal file
View file

@ -0,0 +1,102 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id: ramdisk.c 18965 2008-11-01 17:33:21Z gevaerts $
*
* Copyright (C) 2008 Frank Gevaerts
*
* This program is free software; you can redistribute it 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <stdbool.h>
#include <string.h>
#include "storage.h"
#define SECTOR_SIZE 512
#define NUM_SECTORS 16384
extern unsigned char ramdisk[SECTOR_SIZE * NUM_SECTORS];
long last_disk_activity = -1;
int ramdisk_read_sectors(IF_MV2(int drive,)
unsigned long start,
int count,
void* buf)
{
if(start+count>=NUM_SECTORS)
{
return -1;
}
memcpy(buf,&ramdisk[start*SECTOR_SIZE],count*SECTOR_SIZE);
return 0;
}
int ramdisk_write_sectors(IF_MV2(int drive,)
unsigned long start,
int count,
const void* buf)
{
if(start+count>=NUM_SECTORS)
{
return -1;
}
memcpy(&ramdisk[start*SECTOR_SIZE],buf,count*SECTOR_SIZE);
return 0;
}
int ramdisk_init(void)
{
return 0;
}
long ramdisk_last_disk_activity(void)
{
return last_disk_activity;
}
void ramdisk_sleep(void)
{
}
void ramdisk_spin(void)
{
}
void ramdisk_sleepnow(void)
{
}
void ramdisk_spindown(int seconds)
{
(void)seconds;
}
#ifdef STORAGE_GET_INFO
void ramdisk_get_info(struct storage_info *info)
{
/* firmware version */
info->revision="0.00";
/* vendor field, need better name? */
info->vendor="Rockbox";
/* model field, need better name? */
info->product="Ramdisk";
/* blocks count */
info->num_sectors=NUM_SECTORS;
info->sector_size=SECTOR_SIZE;
}
#endif

View file

@ -29,10 +29,11 @@
/* symbolic names for multiple choice configurations: */
/* CONFIG_STORAGE (note these are combineable bit-flags) */
#define STORAGE_ATA 0x01
#define STORAGE_MMC 0x02
#define STORAGE_SD 0x04
#define STORAGE_NAND 0x08
#define STORAGE_ATA 0x01
#define STORAGE_MMC 0x02
#define STORAGE_SD 0x04
#define STORAGE_NAND 0x08
#define STORAGE_RAMDISK 0x10
/* CONFIG_TUNER (note these are combineable bit-flags) */
#define S1A0903X01 0x01 /* Samsung */

53
firmware/export/ramdisk.h Normal file
View file

@ -0,0 +1,53 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Alan Korr
* Copyright (C) 2008 by Frank Gevaerts
*
* This program is free software; you can redistribute it 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __RAMDISK_H__
#define __RAMDISK_H__
#include <stdbool.h>
#include "mv.h" /* for HAVE_MULTIVOLUME or not */
struct storage_info;
void ramdisk_enable(bool on);
void ramdisk_spindown(int seconds);
void ramdisk_sleep(void);
bool ramdisk_disk_is_active(void);
int ramdisk_hard_reset(void);
int ramdisk_soft_reset(void);
int ramdisk_init(void);
void ramdisk_close(void);
int ramdisk_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf);
int ramdisk_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf);
void ramdisk_spin(void);
void ramdisk_sleepnow(void);
#if (CONFIG_LED == LED_REAL)
void ramdisk_set_led_enabled(bool enabled);
#endif
#ifdef STORAGE_GET_INFO
void ramdisk_get_info(IF_MV2(int drive,) struct storage_info *info);
#endif
long ramdisk_last_disk_activity(void);
#endif

View file

@ -38,6 +38,9 @@
#if (CONFIG_STORAGE & STORAGE_NAND)
#include "nand.h"
#endif
#if (CONFIG_STORAGE & STORAGE_RAMDISK)
#include "ramdisk.h"
#endif
struct storage_info
{
@ -165,6 +168,34 @@ struct storage_info
#define storage_removable(drive) nand_removable(IF_MV(drive))
#define storage_present(drive) nand_present(IF_MV(drive))
#endif
#elif (CONFIG_STORAGE & STORAGE_RAMDISK)
#define storage_spindown ramdisk_spindown
#define storage_sleep ramdisk_sleep
#define storage_spin ramdisk_spin
#define storage_enable(on) (void)0
#define storage_sleepnow() ramdisk_sleepnow()
#define storage_disk_is_active() 0
#define storage_hard_reset() (void)0
#define storage_soft_reset() (void)0
#define storage_init() ramdisk_init()
#define storage_close() ramdisk_close()
#define storage_read_sectors(drive, start, count, buf) ramdisk_read_sectors(IF_MV2(drive,) start, count, buf)
#define storage_write_sectors(drive, start, count, buf) ramdisk_write_sectors(IF_MV2(drive,) start, count, buf)
#define storage_last_disk_activity() ramdisk_last_disk_activity()
#define storage_spinup_time() 0
#define storage_get_identify() ramdisk_get_identify()
#if (CONFIG_LED == LED_REAL)
#define storage_set_led_enabled(enabled) ramdisk_set_led_enabled(enabled)
#endif
#ifdef STORAGE_GET_INFO
#define storage_get_info(drive, info) ramdisk_get_info(IF_MV2(drive,) info)
#endif
#ifdef HAVE_HOTSWAP
#define storage_removable(drive) ramdisk_removable(IF_MV(drive))
#define storage_present(drive) ramdisk_present(IF_MV(drive))
#endif
#else
//#error No storage driver!
#endif

View file

@ -300,6 +300,19 @@ static void set_serial_descriptor(void)
}
usb_string_iSerial.bLength=84;
}
#elif (CONFIG_STORAGE & STORAGE_RAMDISK)
/* This "serial number" isn't unique, but it should never actually
appear in non-testing use */
static void set_serial_descriptor(void)
{
short* p = &usb_string_iSerial.wString[1];
int i;
for (i = 0; i < 16; i++) {
*p++ = hex[(2*i)&0xF];
*p++ = hex[(2*i+1)&0xF];
}
usb_string_iSerial.bLength=68;
}
#else
#error No set_serial_descriptor() implementation for this target
#endif