--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
+ * All Rights Reserved.
+ * -->
+ *
+ * \brief Configuration file for data flash memory module.
+ *
+ * \version $Id$
+ *
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+#ifndef CFG_DATAFLASH_H
+#define CFG_DATAFLASH_H
+
+/**
+ * Logging level definition.
+ *
+ * Use 0 to log only the error messages
+ * Use 1 to log the error and warning messages
+ * Use 2 to log all messages
+ */
+#define DATAFLASH_LOG_LEVEL 2
+
+/**
+ * Set logging verbosity.
+ *
+ * If verbosity is zero print short log messages.
+ */
+#define DATAFLASH_LOG_VERBOSITY 0
+
+
+#endif /* CFG_DATAFLASH_H */
+
+
*
* -->
*
- * \brief Function library for AT45DBXX Data Flash memory.
+ * \brief Function library for dataflash AT45DB family (implementation).
*
*
- * \version $Id: dataflash.c 20677 2008-02-19 14:29:52Z batt $
+ * \version $Id: dataflash.c 21658 2008-06-05 16:42:54Z asterix $
* \author Daniele Basile <asterix@develer.com>
* \author Francesco Sacchi <batt@develer.com>
*/
#include "dataflash.h"
+#include "cfg/cfg_dataflash.h"
#include <cfg/macros.h>
#include <cfg/debug.h>
#include <cfg/module.h>
+// Define logging setting (for cfg/log.h module).
+#define LOG_LEVEL DATAFLASH_LOG_LEVEL
+#define LOG_VERBOSITY DATAFLASH_LOG_VERBOSITY
+#include <cfg/log.h>
+
#include <drv/timer.h>
#include <kern/kfile.h>
* and reset dataflash command decoder.
*/
CS_TOGGLE(fd);
-
kfile_putc(DFO_READ_STATUS, fd->channel);
-
return kfile_getc(fd->channel);
}
fd->page_dirty = false;
- kprintf("Flushing page <%ld>\n", fd->current_page);
+ LOG_INFO("Flushing page {%ld}\n", fd->current_page);
}
return 0;
}
static int dataflash_close(struct KFile *_fd)
{
dataflash_flush(_fd);
- TRACE;
+ LOG_INFO("Close.\n");
return 0;
}
/* Load selected page from dataflash memory */
dataflash_loadPage(fd, fd->current_page);
- TRACE;
+ LOG_INFO("Reopen.\n");
return &fd->fd;
}
ASSERT(fd->fd.seek_pos + size <= fd->fd.size);
size = MIN((kfile_size_t)size, fd->fd.size - fd->fd.seek_pos);
- kprintf("Reading at pos[%lu]\n", fd->fd.seek_pos);
+ LOG_INFO("Reading at pos[%lu]\n", fd->fd.seek_pos);
/*
* We select page and offest from absolute address.
page_addr = fd->fd.seek_pos / mem_info[fd->dev].page_size;
byte_addr = fd->fd.seek_pos % mem_info[fd->dev].page_size;
- kprintf("[page-<%ld>, byte-<%ld>]", page_addr, byte_addr);
+ LOG_INFO("[page-{%ld}, byte-{%ld}]\n", page_addr, byte_addr);
/*
* Flush current page in main memory if
dataflash_readBlock(fd, page_addr, byte_addr, mem_info[fd->dev].read_cmd, data, size);
fd->fd.seek_pos += size;
- kprintf("Read %ld bytes\n", size);
+ LOG_INFO("Read %ld bytes\n", size);
return size;
}
ASSERT(fd->fd.seek_pos + size <= fd->fd.size);
size = MIN((kfile_size_t)size, fd->fd.size - fd->fd.seek_pos);
- kprintf("Writing at pos[%lu]\n", fd->fd.seek_pos);
+ LOG_INFO("Writing at pos[%lu]\n", fd->fd.seek_pos);
while (size)
{
size_t wr_len = MIN((dataflash_size_t)size, mem_info[fd->dev].page_size - offset);
- kprintf(" [page-<%ld>, byte-<%ld>]",new_page, offset);
+ LOG_INFO("[page-{%ld}, byte-{%ld}]\n",new_page, offset);
if (new_page != fd->current_page)
{
dataflash_loadPage(fd, new_page);
fd->current_page = new_page;
- kprintf(" >> Load page: <%ld> ", new_page);
+ LOG_INFO(" >> Load page: {%ld}\n", new_page);
}
/*
* Write byte in current page, and set true
total_write += wr_len;
}
- kprintf("written %lu bytes\n", total_write);
+ LOG_INFO("written %lu bytes\n", total_write);
return total_write;
}
fd->fd.flush = dataflash_flush;
dataflash_reset(fd);
-
stat = dataflash_stat(fd);
/*
*
* -->
*
- * \brief Function library for AT45DB081D Flash memory.
+ * \brief Function library for dataflash AT45DB family (interface).
*
- * \version $Id: dataflash.h 20677 2008-02-19 14:29:52Z batt $
+ * \version $Id: dataflash.h 21658 2008-06-05 16:42:54Z asterix $
*
* \author Daniele Basile <asterix@develer.com>
*/
bool dataflash_init(KFileDataflash *fd, KFile *ch, DataflashType type, dataflash_setCS_t *setCS, dataflash_setReset_t *setReset);
+/**
+ * To test data falsh drive you could use
+ * this functions. To use these functions make sure to include in your make file the
+ * drv/datafalsh_test.c source.
+ *
+ * (see drv/datafalsh_test.c for more detail)
+ */
+int dataflash_testSetup(void);
+int dataflash_testRun(void);
+int dataflash_testTearDown(void);
+
#endif /* DRV_DATAFLASH_H */
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief DataFlash test.
+ *
+ * This module test the dataflash memory among the supported memory (see drv/dataflash.h
+ * for more detail).
+ * To test memory we fill one buffer with casual char, and write it in different
+ * part of memory. After every write we read the data that we have been write
+ * and compare this with test buffer, checking if write and read command work
+ * correclty. We also check if driver work properly when we make a write out the
+ * limit of memory size.
+ *
+ * Note: dataflash driver use a kfile interface, so for write/read test
+ * we use a kfile_test module that perform some generic test.
+ *
+ *
+ * \version $Id$
+ *
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+#include "hw/hw_dataflash.h"
+#include "cfg/cfg_dataflash.h"
+#include <cfg/debug.h>
+#include <cfg/module.h>
+
+// Define logging setting (for cfg/log.h module).
+#define LOG_LEVEL DATAFLASH_LOG_LEVEL
+#define LOG_VERBOSITY DATAFLASH_LOG_VERBOSITY
+#include <cfg/log.h> // for logging system
+
+#include <drv/timer.h>
+#include <drv/ser.h>
+#include <drv/dataflash.h>
+
+
+#include <kern/kfile.h>
+
+#include <string.h>
+
+/*
+ * Settings for dataflash test
+ *
+ * \{
+ */
+// Datafalsh type memory to test (see drv/dataflash.h for supported memory types)
+#define DATAFLASH_MEM_MODEL DFT_AT45DB642D
+
+// Function to set CS, this is typically implement in hw/hw_dataflash.{c, h}
+#define DATAFLASH_FUNC_CS_SET &dataflash_hw_setCS
+
+// Function to reset memery, this is typically implement in hw/hw_dataflash.{c, h}
+#define DATAFLASH_FUNC_RESET NULL
+
+// Buffer len to test dataflash
+#define DATAFLASH_TEST_STR_LEN 12307
+
+// If you want use a rand function of standard library set to 1.
+#define DATAFLASH_USE_RAND_FUNC 1
+/* \} */
+
+/*
+ * Kfile structure to test a dataflash.
+ */
+static KFileSerial spi_fd;
+static KFileDataflash dflash_fd;
+
+/*
+ * Define tmp buffer to stora data for
+ * write and read flash memory test.
+ */
+static uint8_t test_buf[DATAFLASH_TEST_STR_LEN];
+static uint8_t save_buf[DATAFLASH_TEST_STR_LEN];
+
+/**
+ * Setup all needed to test dataflash memory
+ *
+ */
+int dataflash_testSetup(void)
+{
+ /*
+ * This test use a kfile_test module,
+ * so should include source in your makefile.
+ */
+ MOD_CHECK(kfile_test);
+
+ timer_init();
+ LOG_INFO("Timer init..ok\n");
+
+ /*
+ * Init SPI module and dataflash driver.
+ */
+ // Open SPI comunication channel
+ spimaster_init(&spi_fd, SER_SPI0);
+ LOG_INFO("SPI0 init..ok\n");
+
+ ser_setbaudrate(&spi_fd, 5000000UL);
+ LOG_INFO("SPI0 set baudrate..ok\n");
+
+ //Init dataflash memory
+ dataflash_hw_init();
+ LOG_INFO("DATAFLASH HW..ok\n");
+
+ if (dataflash_init(&dflash_fd, &spi_fd.fd, DATAFLASH_MEM_MODEL, DATAFLASH_FUNC_CS_SET, DATAFLASH_FUNC_RESET))
+ LOG_INFO("DATAFLASH init..ok\n");
+ else
+ LOG_ERR("DATAFLASH init..fail\n");
+
+
+ //Fill tmp buffer with rand chars.
+ for (int i = 0; i < DATAFLASH_TEST_STR_LEN; i++)
+ {
+ #if DATAFLASH_USE_RAND_FUNC
+ #include <stdlib.h> //Rand()
+
+ test_buf[i] = (uint8_t)rand();
+ #else
+ test_buf[i] = (i & 0xff);
+ #endif
+ }
+
+ LOG_INFO("Fill tmp buff..ok\n");
+
+ return 0;
+}
+
+
+/**
+ * Run dataflash test memory
+ *
+ */
+int dataflash_testRun(void)
+{
+ if (!dataflash_testSetup())
+ {
+ LOG_INFO("DATAFLASH setup..ok\n");
+ }
+ else
+ {
+ LOG_ERR("DATAFLASH setup..fail!\n");
+ return EOF;
+ }
+
+ LOG_INFO("Run KFILE test.\n");
+
+ if (kfile_testRun(&dflash_fd.fd, test_buf, save_buf, sizeof(test_buf)))
+ {
+ LOG_INFO("KFILE test..ok\n");
+ }
+ else
+ {
+ LOG_ERR("KFILE test..fail!\n");
+ return EOF;
+ }
+
+ return 0;
+}
+
+/**
+ * End a dataflash Test.
+ * (Unused)
+ */
+int dataflash_testTearDown(void)
+{
+ /* */
+ return 0;
+}
+
+/*
+ * Empty main.
+ *
+ * Look it as exmple, or use it if
+ * you want test a data flash driver stand alone.
+ */
+#if 0
+int main(void)
+{
+ IRQ_ENABLE;
+ kdbg_init();
+
+ dataflash_testRun();
+
+ for(;;)
+ {
+ }
+
+}
+#endif