made more conform with contiki indentation.

This commit is contained in:
nvt-se 2008-03-28 23:03:05 +00:00
parent e6cc0105b0
commit 2822ff7ddb
8 changed files with 135 additions and 258 deletions

View file

@ -1,4 +1,3 @@
/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
@ -48,9 +47,9 @@ Berlin, 2007
* @brief MMC-/SD-Card library
*
* @author Michael Baar <baar@inf.fu-berlin.de>
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*
* $Id: sd.c,v 1.2 2008/03/28 15:58:43 nvt-se Exp $
* $Id: sd.c,v 1.3 2008/03/28 23:03:05 nvt-se Exp $
*
* Initialisation and basic functions for read and write access
*/

View file

@ -1,4 +1,3 @@
/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
@ -47,9 +46,9 @@ Berlin, 2007
* @brief MMC-/SD-Card library, Public interface
*
* @author Michael Baar <baar@inf.fu-berlin.de>
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*
* $Id: sd.h,v 1.2 2008/03/28 15:58:43 nvt-se Exp $
* $Id: sd.h,v 1.3 2008/03/28 23:03:05 nvt-se Exp $
*/
/**
@ -130,11 +129,13 @@ __attribute__ ((packed))
/// Card access library state
#define SD_CACHE_LOCKED 0x01
#define SD_CACHE_DIRTY 0x02
typedef struct {
char buffer[SD_WRITE_BLOCKLENGTH];
uint32_t address;
uint8_t state;
} sd_cache_t;
typedef struct {
uint16_t MinBlockLen_bit:4; ///< minimum supported blocklength
uint16_t MaxBlockLen_bit:4; ///< maximum supported blocklength
@ -151,7 +152,7 @@ __attribute__ ((packed))
/**
* @brief Library initialisation
*/
void sd_Init(void);
void sd_init(void);
/**
* @brief Setup ports for sd card communication
@ -268,7 +269,6 @@ __attribute__ ((packed))
uint16_t sd_read_block(void (*const pBuffer), const uint32_t address);
#if SD_READ_BYTE
/**
* @brief Read one byte from any address
* This function reads a single byte from any address. It is optimized for best speed
@ -285,7 +285,6 @@ __attribute__ ((packed))
#endif
#if SD_WRITE
/**
* @brief Write one complete block at a block aligned address from buffer to card
*
@ -372,15 +371,13 @@ __attribute__ ((packed))
uint32_t sd_get_size(void);
#if SD_READ_ANY
/**
* @brief Read any number of bytes from any address into buffer
*
* @param[out] pBuffer Pointer to a buffer to which data is read. It should be least
* size bytes large
* @param[in] address The address of the first byte that shall be read to pBuffer
* @param[in] size Number of bytes which shall be read starting at address
*/
* @param[in] size Number of bytes which shall be read starting at address */
uint16_t sd_read(void *pBuffer, uint32_t address, uint16_t size);
#endif

View file

@ -1,4 +1,3 @@
/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
@ -48,9 +47,9 @@ Berlin, 2007
* @brief MMC-/SD-Card library, cached read and write
*
* @author Michael Baar <baar@inf.fu-berlin.de>
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*
* $Id: sd_cache.c,v 1.2 2008/03/28 15:58:43 nvt-se Exp $
* $Id: sd_cache.c,v 1.3 2008/03/28 23:03:05 nvt-se Exp $
*/
@ -63,235 +62,142 @@ Berlin, 2007
#if SD_CACHE
void
_sd_cache_init()
_sd_cache_init(void)
{
uint32_t adr = 0;
uint32_t addr = 0;
sd_state.Cache->address = 1;
sd_state.Cache->state = 0;
// pre-read first block
sd_cache_read_block(&adr);
sd_cache_read_block(&addr);
SD_FREE_LOCK(sd_state.Cache);
}
void
_sd_cache_flush()
_sd_cache_flush(void)
{
#if SD_WRITE
SD_GET_LOCK(sd_state.Cache);
if (sd_state.Cache->state & SD_CACHE_DIRTY) {
sd_set_blocklength(SD_WRITE_BLOCKLENGTH_BIT);
sd_write_block(sd_state.Cache->address, sd_state.Cache->buffer);
sd_state.Cache->state &= ~SD_CACHE_DIRTY;
}
SD_FREE_LOCK(sd_state.Cache);
#endif /*
*/
#endif
}
sd_cache_t *
sd_cache_read_block(const uint32_t * pblAdr)
{
SD_GET_LOCK(sd_state.Cache);
if (sd_state.Cache->address != *pblAdr) {
sd_set_blocklength(SD_WRITE_BLOCKLENGTH_BIT);
if (sd_state.Cache->state & SD_CACHE_DIRTY) {
sd_write_block(sd_state.Cache->address, sd_state.Cache->buffer);
sd_state.Cache->state &= ~SD_CACHE_DIRTY;
}
sd_state.Cache->address = *pblAdr;
if (!sd_read_block(sd_state.Cache->buffer, *pblAdr)) {
SD_FREE_LOCK(sd_state.Cache);
return false;
}
}
return sd_state.Cache;
}
#if SD_READ_ANY
uint16_t
sd_read(void *pBuffer, uint32_t address, uint16_t size)
{
uint16_t offset; // bytes from aligned address to start of first byte to keep
char *p; // pointer to current pos in receive buffer
uint16_t bytes_left; // num bytes to read
uint16_t read_count; // num bytes to read from current block
//
// parameter processing
//
p = (char *)pBuffer;
bytes_left = size;
// align to block
offset = sd_AlignAddress(&address);
//
// Data transfer
//
do {
// calculate block
if ((offset == 0) && (bytes_left >= sd_state.BlockLen)) {
read_count = sd_state.BlockLen;
sd_read_block(p, address);
} else {
sd_cache_read_block(&address);
read_count = bytes_left + offset;
if (read_count > sd_state.BlockLen)
if (read_count > sd_state.BlockLen) {
read_count = sd_state.BlockLen - offset;
else
} else {
read_count = bytes_left;
}
memcpy(p, sd_state.Cache->buffer + offset, read_count);
SD_FREE_LOCK(sd_state.Cache);
}
bytes_left -= read_count;
if (bytes_left == 0)
if (bytes_left == 0) {
return size;
p += read_count;
address += sd_state.BlockLen;
} while (1);
}
p += read_count;
address += sd_state.BlockLen;
} while (1);
}
#endif // SD_READ_ANY
#if SD_WRITE
uint16_t
sd_write(uint32_t address, void *pBuffer, uint16_t size)
{
uint16_t offset; // bytes from aligned address to start of first byte to keep
char *p; // pointer to current pos in receive buffer
uint16_t bytes_left; // num bytes to read
uint16_t read_count; // num bytes to read from current block
//
// parameter processing
//
p = (char *)pBuffer;
bytes_left = size;
// align to block
offset = sd_AlignAddress(&address);
sd_set_blocklength(SD_WRITE_BLOCKLENGTH_BIT);
//
// Data transfer
//
do {
// calculate block
if ((offset == 0) && (bytes_left >= sd_state.BlockLen)) {
read_count = sd_state.BlockLen;
sd_write_block(address, p);
} else {
sd_cache_read_block(&address);
read_count = bytes_left + offset;
if (read_count > sd_state.BlockLen)
if (read_count > sd_state.BlockLen) {
read_count = sd_state.BlockLen - offset;
else
} else {
read_count = bytes_left;
}
memcpy(sd_state.Cache->buffer + offset, p, read_count);
sd_state.Cache->state |= SD_CACHE_DIRTY;
SD_FREE_LOCK(sd_state.Cache);
}
if (bytes_left == 0)
if (bytes_left == 0) {
return size;
}
p += read_count;
bytes_left -= read_count;
address += sd_state.BlockLen;
} while (1);
}
#endif // SD_WRITE
#endif // SD_CACHE
/** @} */

View file

@ -1,4 +1,3 @@
/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
@ -48,12 +47,11 @@ Berlin, 2007
* @brief MMC-/SD-Card library, Block erase
*
* @author Michael Baar <baar@inf.fu-berlin.de>
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*
* $Id: sd_erase.c,v 1.2 2008/03/28 15:58:44 nvt-se Exp $
* $Id: sd_erase.c,v 1.3 2008/03/28 23:03:05 nvt-se Exp $
*/
/**
* @addtogroup libsd
* @{

View file

@ -1,4 +1,3 @@
/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
@ -48,12 +47,11 @@ Berlin, 2007
* @brief MMC-/SD-Card library, Additional Information
*
* @author Michael Baar <baar@inf.fu-berlin.de>
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*
* $Id: sd_info.c,v 1.2 2008/03/28 15:58:44 nvt-se Exp $
* $Id: sd_info.c,v 1.3 2008/03/28 23:03:05 nvt-se Exp $
*/
/**
* @addtogroup libsd
* @{
@ -64,45 +62,27 @@ Berlin, 2007
unsigned int
sd_read_cid(struct sd_cid *pCID)
{
return _sd_read_register(pCID, SD_CMD_SEND_CID, sizeof (struct sd_cid));
}
unsigned long
sd_get_size()
sd_get_size(void)
{
uint32_t size = 0;
if (uart_lock(UART_MODE_SPI)) {
struct sd_csd csd;
if (_sd_read_register(&csd, SD_CMD_SEND_CSD, sizeof (struct sd_csd))) {
size = SD_CSD_C_SIZE(csd) + 1;
size <<= SD_CSD_C_MULT(csd);
size <<= 2;
size <<= sd_state.MaxBlockLen_bit;
}
uart_unlock(UART_MODE_SPI);
}
return size;
}
/** @} */

View file

@ -1,4 +1,3 @@
/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
@ -49,11 +48,11 @@ Berlin, 2007
*
* @author Michael Baar <baar@inf.fu-berlin.de>
* @date Jan 2007
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*
* Replace this file for use on another platform.
*
* $Id: sd_msb430.c,v 1.1 2008/03/28 15:58:44 nvt-se Exp $
* $Id: sd_msb430.c,v 1.2 2008/03/28 23:03:05 nvt-se Exp $
*/
#include "sd_internals.h"

View file

@ -1,4 +1,3 @@
/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
@ -48,11 +47,11 @@ Berlin, 2007
*
* @author Michael Baar <baar@inf.fu-berlin.de>
* @date Jan 2007
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*
* Replace this file for use on another platform.
*
* $Id: sd_platform.h,v 1.1 2008/03/28 15:58:44 nvt-se Exp $
* $Id: sd_platform.h,v 1.2 2008/03/28 23:03:05 nvt-se Exp $
*/
#ifndef __SCATTERWEB_SD_PLATFORM__

View file

@ -1,4 +1,3 @@
/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.
@ -48,9 +47,9 @@ Berlin, 2007
* @brief Serial Peripheral Interface for SD library
*
* @author Michael Baar <baar@inf.fu-berlin.de>
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*
* $Id: sdspi.c,v 1.1 2008/03/28 15:58:44 nvt-se Exp $
* $Id: sdspi.c,v 1.2 2008/03/28 23:03:05 nvt-se Exp $
*/
#include <msp430x16x.h>