Skip to content

Commit

Permalink
Merge pull request #2 from mbedmicro/master
Browse files Browse the repository at this point in the history
Update 2
  • Loading branch information
PrzemekWirkus committed Aug 20, 2014
2 parents e4419e7 + 4e54e07 commit f44b3ab
Show file tree
Hide file tree
Showing 193 changed files with 385 additions and 308 deletions.
6 changes: 3 additions & 3 deletions libraries/USBDevice/USBMSD/USBMSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void USBMSD::memoryWrite (uint8_t * buf, uint16_t size) {
// if the array is filled, write it in memory
if (!((addr + size)%BlockSize)) {
if (!(disk_status() & WRITE_PROTECT)) {
disk_write(page, addr/BlockSize);
disk_write(page, addr/BlockSize, 1);
}
}

Expand All @@ -257,7 +257,7 @@ void USBMSD::memoryVerify (uint8_t * buf, uint16_t size) {

// beginning of a new block -> load a whole block in RAM
if (!(addr%BlockSize))
disk_read(page, addr/BlockSize);
disk_read(page, addr/BlockSize, 1);

// info are in RAM -> no need to re-read memory
for (n = 0; n < size; n++) {
Expand Down Expand Up @@ -505,7 +505,7 @@ void USBMSD::memoryRead (void) {

// we read an entire block
if (!(addr%BlockSize))
disk_read(page, addr/BlockSize);
disk_read(page, addr/BlockSize, 1);

// write data which are in RAM
writeNB(EPBULK_IN, &page[addr%BlockSize], n, MAX_PACKET_SIZE_EPBULK);
Expand Down
14 changes: 8 additions & 6 deletions libraries/USBDevice/USBMSD/USBMSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,24 @@ class USBMSD: public USBDevice {
protected:

/*
* read a block on a storage chip
* read one or more blocks on a storage chip
*
* @param data pointer where will be stored read data
* @param block block number
* @param block starting block number
* @param count number of blocks to read
* @returns 0 if successful
*/
virtual int disk_read(uint8_t * data, uint64_t block) = 0;
virtual int disk_read(uint8_t* data, uint64_t block, uint8_t count) = 0;

/*
* write a block on a storage chip
* write one or more blocks on a storage chip
*
* @param data data to write
* @param block block number
* @param block starting block number
* @param count number of blocks to write
* @returns 0 if successful
*/
virtual int disk_write(const uint8_t * data, uint64_t block) = 0;
virtual int disk_write(const uint8_t* data, uint64_t block, uint8_t count) = 0;

/*
* Disk initilization
Expand Down
22 changes: 16 additions & 6 deletions libraries/USBHost/USBHostMSD/USBHostMSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,24 +323,34 @@ int USBHostMSD::disk_initialize() {
return readCapacity();
}

int USBHostMSD::disk_write(const uint8_t *buffer, uint64_t block_number) {
USB_DBG("FILESYSTEM: write block: %lld", block_number);
int USBHostMSD::disk_write(const uint8_t* buffer, uint64_t block_number, uint8_t count) {
USB_DBG("FILESYSTEM: write block: %lld, count: %d", block_number, count);
if (!disk_init) {
disk_initialize();
}
if (!disk_init)
return -1;
return dataTransfer((uint8_t *)buffer, block_number, 1, HOST_TO_DEVICE);
for (uint64_t b = block_number; b < block_number + count; b++) {
if (dataTransfer((uint8_t*)buffer, b, 1, HOST_TO_DEVICE))
return -1;
buffer += 512;
}
return 0;
}

int USBHostMSD::disk_read(uint8_t * buffer, uint64_t block_number) {
USB_DBG("FILESYSTEM: read block %lld", block_number);
int USBHostMSD::disk_read(uint8_t* buffer, uint64_t block_number, uint8_t count) {
USB_DBG("FILESYSTEM: read block: %lld, count: %d", block_number, count);
if (!disk_init) {
disk_initialize();
}
if (!disk_init)
return -1;
return dataTransfer((uint8_t *)buffer, block_number, 1, DEVICE_TO_HOST);
for (uint64_t b = block_number; b < block_number + count; b++) {
if (dataTransfer((uint8_t*)buffer, b, 1, DEVICE_TO_HOST))
return -1;
buffer += 512;
}
return 0;
}

uint64_t USBHostMSD::disk_sectors() {
Expand Down
4 changes: 2 additions & 2 deletions libraries/USBHost/USBHostMSD/USBHostMSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class USBHostMSD : public IUSBEnumerator, public FATFileSystem {
// From FATFileSystem
virtual int disk_initialize();
virtual int disk_status() {return 0;};
virtual int disk_read(uint8_t * buffer, uint64_t sector);
virtual int disk_write(const uint8_t * buffer, uint64_t sector);
virtual int disk_read(uint8_t* buffer, uint64_t sector, uint8_t count);
virtual int disk_write(const uint8_t* buffer, uint64_t sector, uint8_t count);
virtual int disk_sync() {return 0;};
virtual uint64_t disk_sectors();

Expand Down
26 changes: 8 additions & 18 deletions libraries/fs/fat/ChaN/diskio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,10 @@ DRESULT disk_read (
)
{
debug_if(FFS_DBG, "disk_read(sector %d, count %d) on drv [%d]\n", sector, count, drv);
for(DWORD s=sector; s<sector+count; s++) {
debug_if(FFS_DBG, " disk_read(sector %d)\n", s);
int res = FATFileSystem::_ffs[drv]->disk_read((uint8_t*)buff, s);
if(res) {
return RES_PARERR;
}
buff += 512;
}
return RES_OK;
if (FATFileSystem::_ffs[drv]->disk_read((uint8_t*)buff, sector, count))
return RES_PARERR;
else
return RES_OK;
}

#if _READONLY == 0
Expand All @@ -56,15 +51,10 @@ DRESULT disk_write (
)
{
debug_if(FFS_DBG, "disk_write(sector %d, count %d) on drv [%d]\n", sector, count, drv);
for(DWORD s = sector; s < sector + count; s++) {
debug_if(FFS_DBG, " disk_write(sector %d)\n", s);
int res = FATFileSystem::_ffs[drv]->disk_write((uint8_t*)buff, s);
if(res) {
return RES_PARERR;
}
buff += 512;
}
return RES_OK;
if (FATFileSystem::_ffs[drv]->disk_write((uint8_t*)buff, sector, count))
return RES_PARERR;
else
return RES_OK;
}
#endif /* _READONLY */

Expand Down
38 changes: 36 additions & 2 deletions libraries/fs/fat/FATFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

using namespace mbed;

/**
* FATFileSystem based on ChaN's Fat Filesystem library v0.8
*/
class FATFileSystem : public FileSystemLike {
public:

Expand All @@ -39,19 +42,50 @@ class FATFileSystem : public FileSystemLike {
FATFS _fs; // Work area (file system object) for logical drive
int _fsid;

/**
* Opens a file on the filesystem
*/
virtual FileHandle *open(const char* name, int flags);

/**
* Removes a file path
*/
virtual int remove(const char *filename);

/**
* Renames a file
*/
virtual int rename(const char *oldname, const char *newname);

/**
* Formats a logical drive, FDISK artitioning rule, 512 bytes per cluster
*/
virtual int format();

/**
* Opens a directory on the filesystem
*/
virtual DirHandle *opendir(const char *name);

/**
* Creates a directory path
*/
virtual int mkdir(const char *name, mode_t mode);

/**
* Mounts the filesystem
*/
virtual int mount();

/**
* Unmounts the filesystem
*/
virtual int unmount();

virtual int disk_initialize() { return 0; }
virtual int disk_status() { return 0; }
virtual int disk_read(uint8_t * buffer, uint64_t sector) = 0;
virtual int disk_write(const uint8_t * buffer, uint64_t sector) = 0;
virtual int disk_read(uint8_t * buffer, uint64_t sector, uint8_t count) = 0;
virtual int disk_write(const uint8_t * buffer, uint64_t sector, uint8_t count) = 0;
virtual int disk_sync() { return 0; }
virtual uint64_t disk_sectors() = 0;

Expand Down
38 changes: 23 additions & 15 deletions libraries/fs/sd/SDFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,33 +223,41 @@ int SDFileSystem::disk_initialize() {
return 0;
}

int SDFileSystem::disk_write(const uint8_t *buffer, uint64_t block_number) {
int SDFileSystem::disk_write(const uint8_t* buffer, uint64_t block_number, uint8_t count) {
if (!_is_initialized) {
return -1;
}

// set write address for single block (CMD24)
if (_cmd(24, block_number * cdv) != 0) {
return 1;

for (uint64_t b = block_number; b < block_number + count; b++) {
// set write address for single block (CMD24)
if (_cmd(24, b * cdv) != 0) {
return 1;
}

// send the data block
_write(buffer, 512);
buffer += 512;
}

// send the data block
_write(buffer, 512);

return 0;
}

int SDFileSystem::disk_read(uint8_t *buffer, uint64_t block_number) {
int SDFileSystem::disk_read(uint8_t* buffer, uint64_t block_number, uint8_t count) {
if (!_is_initialized) {
return -1;
}

// set read address for single block (CMD17)
if (_cmd(17, block_number * cdv) != 0) {
return 1;

for (uint64_t b = block_number; b < block_number + count; b++) {
// set read address for single block (CMD17)
if (_cmd(17, b * cdv) != 0) {
return 1;
}

// receive the data
_read(buffer, 512);
buffer += 512;
}

// receive the data
_read(buffer, 512);
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/fs/sd/SDFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class SDFileSystem : public FATFileSystem {
SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);
virtual int disk_initialize();
virtual int disk_status();
virtual int disk_read(uint8_t * buffer, uint64_t block_number);
virtual int disk_write(const uint8_t * buffer, uint64_t block_number);
virtual int disk_read(uint8_t* buffer, uint64_t block_number, uint8_t count);
virtual int disk_write(const uint8_t* buffer, uint64_t block_number, uint8_t count);
virtual int disk_sync();
virtual uint64_t disk_sectors();

Expand Down
4 changes: 2 additions & 2 deletions libraries/mbed/api/mbed.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef MBED_H
#define MBED_H

#define MBED_LIBRARY_VERSION 86
#define MBED_LIBRARY_VERSION 88

#include "platform.h"

Expand All @@ -25,7 +25,7 @@
#include <time.h>

// mbed Debug libraries
#include "error.h"
#include "mbed_error.h"
#include "mbed_interface.h"

// mbed Peripheral components
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion libraries/mbed/common/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <stdarg.h>
#include "device.h"
#include "toolchain.h"
#include "error.h"
#include "mbed_error.h"
#if DEVICE_STDIO_MESSAGES
#include <stdio.h>
#endif
Expand Down
2 changes: 1 addition & 1 deletion libraries/mbed/common/mbed_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "gpio_api.h"
#include "wait_api.h"
#include "semihost_api.h"
#include "error.h"
#include "mbed_error.h"
#include "toolchain.h"

#if DEVICE_SEMIHOST
Expand Down
2 changes: 1 addition & 1 deletion libraries/mbed/common/pinmap_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "pinmap.h"
#include "error.h"
#include "mbed_error.h"

void pinmap_pinout(PinName pin, const PinMap *map) {
if (pin == NC)
Expand Down
2 changes: 1 addition & 1 deletion libraries/mbed/common/retarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ extern "C" int mkdir(const char *path, mode_t mode) {

#if defined(TOOLCHAIN_GCC)
/* prevents the exception handling name demangling code getting pulled in */
#include "error.h"
#include "mbed_error.h"
namespace __gnu_cxx {
void __verbose_terminate_handler() {
error("Exception");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ __initial_sp EQU 0x20002000 ; Top of RAM (8 KB for STM32F030R8)
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Heap_Size EQU 0x00000000
Heap_Size EQU 0x00000400

AREA HEAP, NOINIT, READWRITE, ALIGN=3
EXPORT __heap_base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ __initial_sp EQU 0x20004000 ; Top of RAM (16KB)
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Heap_Size EQU 0x00000200
Heap_Size EQU 0x00000400

AREA HEAP, NOINIT, READWRITE, ALIGN=3
EXPORT __heap_base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ __initial_sp EQU 0x20005000 ; Top of RAM
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Heap_Size EQU 0x00000000
Heap_Size EQU 0x00000400

AREA HEAP, NOINIT, READWRITE, ALIGN=3
EXPORT __heap_base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ __initial_sp EQU 0x20004000 ; Top of RAM
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Heap_Size EQU 0x00000000
Heap_Size EQU 0x00000400

AREA HEAP, NOINIT, READWRITE, ALIGN=3
EXPORT __heap_base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ __initial_sp EQU 0x20003000 ; Top of RAM
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Heap_Size EQU 0x00000000
Heap_Size EQU 0x00000400

AREA HEAP, NOINIT, READWRITE, ALIGN=3
EXPORT __heap_base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ __initial_sp EQU 0x20020000 ; Top of RAM
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Heap_Size EQU 0x00000000
Heap_Size EQU 0x00000400

AREA HEAP, NOINIT, READWRITE, ALIGN=3
EXPORT __heap_base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ __initial_sp EQU 0x20002000 ; Top of RAM
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Heap_Size EQU 0x00000000
Heap_Size EQU 0x00000400

AREA HEAP, NOINIT, READWRITE, ALIGN=3
EXPORT __heap_base
Expand Down
Loading

0 comments on commit f44b3ab

Please sign in to comment.