Style changes.

This commit is contained in:
nvt-se 2007-08-02 08:17:43 +00:00
parent 0412975efd
commit a6af72d129
2 changed files with 61 additions and 61 deletions

View File

@ -57,17 +57,23 @@ Berlin, 2007
#include <msp430/flash.h> #include <msp430/flash.h>
#include "infomem.h" #include "infomem.h"
void infomem_read(void* buffer, unsigned int offset, unsigned char size) { void
infomem_read(void *buffer, unsigned int offset, unsigned char size)
{
UINT8 *address = (UINT8 *) INFOMEM_START + offset; UINT8 *address = (UINT8 *) INFOMEM_START + offset;
memcpy(buffer, address, size); memcpy(buffer, address, size);
} }
bool infomem_write(unsigned int offset, unsigned char count, ...) { bool
infomem_write(unsigned int offset, unsigned char count, ...)
{
char backup[INFOMEM_BLOCK_SIZE]; char backup[INFOMEM_BLOCK_SIZE];
UINT8 *buffer;
register UINT8* buffer; UINT16 i;
register UINT16 i;
UINT8 *flash; UINT8 *flash;
va_list argp;
UINT16 size;
UINT8 *data;
if (offset > (2 * INFOMEM_BLOCK_SIZE)) if (offset > (2 * INFOMEM_BLOCK_SIZE))
return false; return false;
@ -80,19 +86,16 @@ bool infomem_write(unsigned int offset, unsigned char count, ...) {
memcpy(backup, flash, INFOMEM_BLOCK_SIZE); memcpy(backup, flash, INFOMEM_BLOCK_SIZE);
// merge backup with new data // merge backup with new data
va_list argp;
va_start(argp, count); va_start(argp, count);
buffer = (UINT8 *) backup; buffer = (UINT8 *) backup;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
register UINT16 size;
register UINT8* data;
data = va_arg(argp, UINT8*); data = va_arg(argp, UINT8*);
size = va_arg(argp, UINT16); size = va_arg(argp, UINT16);
memcpy(buffer, data, size); memcpy(buffer, data, size);
buffer += size; buffer += size;
} }
va_end(argp); va_end(argp);
// init flash access // init flash access
@ -107,9 +110,9 @@ bool infomem_write(unsigned int offset, unsigned char count, ...) {
FCTL1 = FWKEY + WRT; FCTL1 = FWKEY + WRT;
buffer = (UINT8 *) backup; buffer = (UINT8 *) backup;
for (i = 0; i < INFOMEM_BLOCK_SIZE; i++) { for (i = 0; i < INFOMEM_BLOCK_SIZE; i++) {
*flash = *buffer; *flash++ = *buffer++;
buffer++; flash++;
} }
FCTL1 = FWKEY; FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK; FCTL3 = FWKEY + LOCK;

View File

@ -48,15 +48,11 @@ Berlin, 2006
* @author Michael Baar <baar@inf.fu-berlin.de> * @author Michael Baar <baar@inf.fu-berlin.de>
*/ */
#ifndef INFOMEM_H_ #ifndef INFOMEM_H
#define INFOMEM_H_ #define INFOMEM_H
/* These defines might depend on the specific CPU used and have to be defined in platform:
#define INFOMEM_START 0x1000
#define INFOMEM_BLOCK_SIZE 128
*/
#if !defined(INFOMEM_START) || !defined(INFOMEM_BLOCK_SIZE) #if !defined(INFOMEM_START) || !defined(INFOMEM_BLOCK_SIZE)
#error "Infomemory position (INFOMEM_START) and blocksize (INFOMEM_BLOCK_SIZE) need to be defined for current platform" #error "infomem position (INFOMEM_START) and block size (INFOMEM_BLOCK_SIZE) need to be defined for the platform"
#endif #endif
/** /**
@ -75,11 +71,12 @@ void infomem_read(void* buffer, unsigned int offset, unsigned char size);
* *
* Example: Infomem_write( 0, 2, &a,3, &b,1 ); * Example: Infomem_write( 0, 2, &a,3, &b,1 );
* *
* \note: The MSP430 has two consecutive blocks of infomemory. Each is 128 Bytes large. * \note: The MSP430 has two consecutive blocks of infomemory.
* The offset is the relative address starting at the beginning of the first block. * Each is 128 bytes large. The offset is the relative address
* You can write an arbitrary number of bytes at any offse, but this * starting at the beginning of the first block. You can write an
* function cannot write across the two blocks of infomemory. * arbitrary number of bytes at any offset, but this function
* cannot write across the two blocks of infomemory.
*/ */
bool infomem_write(unsigned int offset, unsigned char count, ...); bool infomem_write(unsigned int offset, unsigned char count, ...);
#endif // INFOMEM_H #endif // !INFOMEM_H