Fix Luminary LM3S detection.
[bertos.git] / bertos / drv / dataflash.c
index 5347d451aa97c3812ba4012d397aaf2d0237c678..0f0d06041e39ca6142f5cbca7dba2eef95a0ba12 100644 (file)
  * the GNU General Public License.
  *
  * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
- *
  * -->
  *
- *  \brief Function library for dataflash AT45DB family (implementation).
- *
+ * \brief Function library for dataflash AT45DB family (implementation).
  *
  * \version $Id: dataflash.c 21658 2008-06-05 16:42:54Z asterix $
  * \author Daniele Basile <asterix@develer.com>
 #include <cfg/module.h>
 
 // Define logging setting (for cfg/log.h module).
-#define LOG_LEVEL         DATAFLASH_LOG_LEVEL
-#define LOG_VERBOSITY     DATAFLASH_LOG_VERBOSITY
+#define LOG_LEVEL   DATAFLASH_LOG_LEVEL
+#define LOG_FORMAT  DATAFLASH_LOG_FORMAT
 #include <cfg/log.h>
 
 #include <drv/timer.h>
 
 #include <kern/kfile.h>
 
-#if CONFIG_KERNEL
-#include <kern/proc.h>
-#endif
+#include <cpu/power.h> /* cpu_relax() */
 
 #include <string.h>
 
@@ -213,11 +209,7 @@ static uint8_t dataflash_cmd(DataFlash *fd, dataflash_page_t page_addr, dataflas
         * is high.
         */
        while (!(dataflash_stat(fd) & BUSY_BIT))
-       {
-               #if CONFIG_KERNEL
-               proc_switch();
-               #endif
-       }
+               cpu_relax();
 
        stat = dataflash_stat(fd);
 
@@ -287,7 +279,7 @@ static void dataflash_loadPage(DataFlash *fd, dataflash_page_t page_addr)
  */
 static int dataflash_flush(KFile *_fd)
 {
-       DataFlash *fd = DATAFLASH(_fd);
+       DataFlash *fd = DATAFLASH_CAST(_fd);
        if (fd->page_dirty)
        {
                dataflash_cmd(fd, fd->current_page, 0x00, DFO_WRITE_BUFF1_TO_MEM_E);
@@ -316,7 +308,7 @@ static int dataflash_close(struct KFile *_fd)
  */
 static KFile *dataflash_reopen(KFile *_fd)
 {
-       DataFlash *fd = DATAFLASH(_fd);
+       DataFlash *fd = DATAFLASH_CAST(_fd);
        dataflash_close(_fd);
 
        fd->current_page = 0;
@@ -344,15 +336,15 @@ static KFile *dataflash_reopen(KFile *_fd)
  */
 static size_t dataflash_read(struct KFile *_fd, void *buf, size_t size)
 {
-       DataFlash *fd = DATAFLASH(_fd);
+       DataFlash *fd = DATAFLASH_CAST(_fd);
 
        dataflash_offset_t byte_addr;
        dataflash_page_t page_addr;
        uint8_t *data = (uint8_t *)buf;
 
 
-       ASSERT(fd->fd.seek_pos + size <= (kfile_size_t)fd->fd.size);
-       size = MIN((kfile_size_t)size, fd->fd.size - fd->fd.seek_pos);
+       ASSERT(fd->fd.seek_pos + size <= (kfile_off_t)fd->fd.size);
+       size = MIN((kfile_off_t)size, fd->fd.size - fd->fd.seek_pos);
 
        LOG_INFO("Reading at pos[%lu]\n", fd->fd.seek_pos);
 
@@ -394,7 +386,7 @@ static size_t dataflash_read(struct KFile *_fd, void *buf, size_t size)
  */
 static size_t dataflash_write(struct KFile *_fd, const void *_buf, size_t size)
 {
-       DataFlash *fd = DATAFLASH(_fd);
+       DataFlash *fd = DATAFLASH_CAST(_fd);
 
        dataflash_offset_t offset;
        dataflash_page_t new_page;
@@ -403,7 +395,7 @@ static size_t dataflash_write(struct KFile *_fd, const void *_buf, size_t size)
        const uint8_t *data = (const uint8_t *) _buf;
 
        ASSERT(fd->fd.seek_pos + size <= (kfile_off_t)fd->fd.size);
-       size = MIN((kfile_size_t)size, fd->fd.size - fd->fd.seek_pos);
+       size = MIN((kfile_off_t)size, fd->fd.size - fd->fd.seek_pos);
 
        LOG_INFO("Writing at pos[%lu]\n", fd->fd.seek_pos);