Adapted the simple SD test to the new driver and its interface.
This commit is contained in:
parent
12c6dbb7c6
commit
f698ce2577
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Swedish Institute of Computer Science.
|
* Copyright (c) 2009, 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,77 +28,64 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: sd-test.c,v 1.4 2009/05/26 13:23:59 nvt-se Exp $
|
* $Id: sd-test.c,v 1.5 2009/09/22 15:37:18 nvt-se Exp $
|
||||||
*
|
|
||||||
* \file
|
|
||||||
* A simple example of using the SD card on the MSB430 platform.
|
|
||||||
* \author
|
|
||||||
* Nicolas Tsiftes <nvt@sics.se>
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Test for an SD driver.
|
||||||
|
* \author
|
||||||
|
* Nicolas Tsiftes <nvt@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
#include "dev/sd/sd.h"
|
#include "dev/sd.h"
|
||||||
#include "dev/msb430-uart1.h"
|
|
||||||
#include "lib/random.h"
|
#include "lib/random.h"
|
||||||
#include "net/rime.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define BLOCK_SIZE 512UL
|
PROCESS(sd_test, "SD test process");
|
||||||
|
AUTOSTART_PROCESSES(&sd_test);
|
||||||
|
|
||||||
#define CALM_MODE 1
|
PROCESS_THREAD(sd_test, event, data)
|
||||||
#define ALTER_OFFSET 0
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
PROCESS(test_sd_process, "SD test");
|
|
||||||
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 long iter;
|
static unsigned long iter;
|
||||||
static uint32_t offset;
|
static unsigned long offset;
|
||||||
|
char buf[SD_BLOCK_SIZE];
|
||||||
|
static struct etimer et;
|
||||||
|
int r, buflen;
|
||||||
|
|
||||||
PROCESS_BEGIN();
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
printf("starting the SD test\n");
|
etimer_set(&et, CLOCK_SECOND);
|
||||||
|
|
||||||
while(1) {
|
offset = 0;
|
||||||
printf("\n\nIteration %lu\n", ++iter);
|
for(iter = 1;; iter++) {
|
||||||
sprintf(buf, "Testing the SD memory #%lu.", iter);
|
|
||||||
|
|
||||||
#if CALM_MODE
|
|
||||||
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(offset, &buf);
|
memset(buf, 0, sizeof(buf));
|
||||||
if(r != SD_WRITE_SUCCESS) {
|
buflen = sprintf(buf, "(%ld) Testing the SD card (%ld)", iter, iter);
|
||||||
printf("writing failed: %d\n", r);
|
|
||||||
|
if((iter & 7) == 0) {
|
||||||
|
offset = random_rand() & 0xffff;
|
||||||
|
} else {
|
||||||
|
offset += random_rand() & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(buf, 0, sizeof (buf));
|
r = sd_write(offset, buf, buflen + 1);
|
||||||
r = sd_read_block(&buf, offset);
|
|
||||||
if(r > 0) {
|
if(r > 0) {
|
||||||
printf("Read %d bytes\n", r);
|
memset(buf, 0, sizeof(buf));
|
||||||
buf[sizeof(buf) - 1] = '\0';
|
r = sd_read(offset, buf, buflen + 1);
|
||||||
printf("Contents of the buffer: %s\n", buf);
|
if(r > 0) {
|
||||||
} else {
|
printf("read %s (offset %lu)\n", buf, offset);
|
||||||
printf("reading failed\n");
|
} else {
|
||||||
|
printf("read error: %d (%s)\n", r, sd_error_string(r));
|
||||||
|
}
|
||||||
|
etimer_reset(&et);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PROCESS_END();
|
PROCESS_END();
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
|
|
Loading…
Reference in a new issue