From 0f6954cc43bc5508cfc1ae09f76d3a2aae3128fe Mon Sep 17 00:00:00 2001 From: nvt-se Date: Tue, 26 May 2009 13:00:37 +0000 Subject: [PATCH] added test options for stressing the card and for switching blocks randomly. --- platform/msb430/apps/sd-test.c | 36 +++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/platform/msb430/apps/sd-test.c b/platform/msb430/apps/sd-test.c index fd9881e03..c0135d62b 100644 --- a/platform/msb430/apps/sd-test.c +++ b/platform/msb430/apps/sd-test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Swedish Institute of Computer Science. + * Copyright (c) 2007 Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,7 +28,7 @@ * * 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 * A simple example of using the SD card on the MSB430 platform. @@ -37,13 +37,18 @@ */ #include "contiki.h" -#include "net/rime.h" #include "dev/sd/sd.h" #include "dev/msb430-uart1.h" +#include "lib/random.h" +#include "net/rime.h" #include +#include -#define BLOCK_SIZE 512 +#define BLOCK_SIZE 512UL + +#define CALM_MODE 0 +#define ALTER_OFFSET 0 /*---------------------------------------------------------------------------*/ PROCESS(test_sd_process, "SD test"); @@ -52,9 +57,12 @@ AUTOSTART_PROCESSES(&test_sd_process); PROCESS_THREAD(test_sd_process, ev, data) { static char buf[BLOCK_SIZE]; +#if CALM_MODE static struct etimer et; +#endif static int r; static unsigned iter; + static uint32_t offset; PROCESS_BEGIN(); @@ -64,20 +72,30 @@ PROCESS_THREAD(test_sd_process, ev, data) printf("\n\nIteration %u\n", ++iter); sprintf(buf, "Testing the SD memory #%u.", iter); +#if CALM_MODE etimer_set(&et, CLOCK_SECOND); 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) { - printf("sd_write_block failed: %d\n", r); + printf("writing failed: %d\n", r); } - + memset(buf, 0, sizeof (buf)); - r = sd_read_block(&buf, BLOCK_SIZE); - printf("Read %d bytes\n", r); + r = sd_read_block(&buf, offset); if(r > 0) { + printf("Read %d bytes\n", r); buf[sizeof(buf) - 1] = '\0'; printf("Contents of the buffer: %s\n", buf); + } else { + printf("reading failed\n"); } }