added test options for stressing the card and for switching blocks randomly.

This commit is contained in:
nvt-se 2009-05-26 13:00:37 +00:00
parent 28619eabc0
commit 0f6954cc43
1 changed files with 27 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, Swedish Institute of Computer Science. * Copyright (c) 2007 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: sd-test.c,v 1.1 2008/10/28 12:56:57 nvt-se Exp $ * $Id: sd-test.c,v 1.2 2009/05/26 13:00:37 nvt-se Exp $
* *
* \file * \file
* A simple example of using the SD card on the MSB430 platform. * A simple example of using the SD card on the MSB430 platform.
@ -37,13 +37,18 @@
*/ */
#include "contiki.h" #include "contiki.h"
#include "net/rime.h"
#include "dev/sd/sd.h" #include "dev/sd/sd.h"
#include "dev/msb430-uart1.h" #include "dev/msb430-uart1.h"
#include "lib/random.h"
#include "net/rime.h"
#include <stdio.h> #include <stdio.h>
#include <string.h>
#define BLOCK_SIZE 512 #define BLOCK_SIZE 512UL
#define CALM_MODE 0
#define ALTER_OFFSET 0
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS(test_sd_process, "SD test"); PROCESS(test_sd_process, "SD test");
@ -52,9 +57,12 @@ AUTOSTART_PROCESSES(&test_sd_process);
PROCESS_THREAD(test_sd_process, ev, data) PROCESS_THREAD(test_sd_process, ev, data)
{ {
static char buf[BLOCK_SIZE]; static char buf[BLOCK_SIZE];
#if CALM_MODE
static struct etimer et; static struct etimer et;
#endif
static int r; static int r;
static unsigned iter; static unsigned iter;
static uint32_t offset;
PROCESS_BEGIN(); PROCESS_BEGIN();
@ -64,20 +72,30 @@ PROCESS_THREAD(test_sd_process, ev, data)
printf("\n\nIteration %u\n", ++iter); printf("\n\nIteration %u\n", ++iter);
sprintf(buf, "Testing the SD memory #%u.", iter); sprintf(buf, "Testing the SD memory #%u.", iter);
#if CALM_MODE
etimer_set(&et, CLOCK_SECOND); etimer_set(&et, CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
#else
PROCESS_PAUSE();
#endif
offset = BLOCK_SIZE;
#if ALTER_OFFSET
offset *= (random_rand() & 0xff));
#endif
r = sd_write_block(BLOCK_SIZE, &buf); r = sd_write_block(offset, &buf);
if(r != SD_WRITE_SUCCESS) { if(r != SD_WRITE_SUCCESS) {
printf("sd_write_block failed: %d\n", r); printf("writing failed: %d\n", r);
} }
memset(buf, 0, sizeof (buf)); memset(buf, 0, sizeof (buf));
r = sd_read_block(&buf, BLOCK_SIZE); r = sd_read_block(&buf, offset);
printf("Read %d bytes\n", r);
if(r > 0) { if(r > 0) {
printf("Read %d bytes\n", r);
buf[sizeof(buf) - 1] = '\0'; buf[sizeof(buf) - 1] = '\0';
printf("Contents of the buffer: %s\n", buf); printf("Contents of the buffer: %s\n", buf);
} else {
printf("reading failed\n");
} }
} }