Update preset.
[bertos.git] / bertos / drv / flash25.c
index 70d9229a468f4db70e817e38b874c1eaeb947107..f12e41e9aee7fa40714809b12232b7175cd0ce92 100644 (file)
  * the GNU General Public License.
  *
  * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
- *
  * -->
  *
- *  \brief Function library for serial Flash memory.
+ * \brief Function library for serial Flash memory.
  *
  * Module provide a kfile interface, that ensure an abstraction
  * from comunication channel and give a standard interface.
  * Typicaly this kind of memory use an SPI bus, but you should
  * use another comunication channel you have defined.
  *
- * \version $Id$
  * \author Daniele Basile <asterix@develer.com>
  */
 
 #include <drv/timer.h>
 #include <drv/flash25.h>
 
-#include <kern/kfile.h>
+#include <io/kfile.h>
 
-#if CONFIG_KERNEL
-#include <kern/proc.h>
-#endif
+#include <cpu/power.h> /* cpu_relax() */
 
-#warning FIXME:This file was change, but is untest!
+#warning FIXME:This file was changed, but is untested!
 
 /**
  * Wait until flash memory is ready.
@@ -79,10 +75,8 @@ static void flash25_waitReady(Flash25 *fd)
 
                if (!(stat & RDY_BIT))
                        break;
-               #if CONFIG_KERNEL
-               else
-                       proc_switch();
-               #endif
+
+               cpu_relax();
        }
 }
 
@@ -140,7 +134,7 @@ static bool flash25_pin_init(Flash25 *fd)
  */
 static KFile * flash25_reopen(struct KFile *_fd)
 {
-       Flash25 *fd = FLASH25KFILE(_fd);
+       Flash25 *fd = FLASH25_CAST(_fd);
 
        fd->fd.seek_pos = 0;
        fd->fd.size = FLASH25_MEM_SIZE;
@@ -176,10 +170,10 @@ static size_t flash25_read(struct KFile *_fd, void *buf, size_t size)
 {
        uint8_t *data = (uint8_t *)buf;
 
-       Flash25 *fd = FLASH25KFILE(_fd);
+       Flash25 *fd = FLASH25_CAST(_fd);
 
-       ASSERT(fd->fd.seek_pos + (kfile_size_t)size <= fd->fd.size);
-       size = MIN((kfile_size_t)size, fd->fd.size - fd->fd.seek_pos);
+       ASSERT(fd->fd.seek_pos + (kfile_off_t)size <= fd->fd.size);
+       size = MIN((kfile_off_t)size, fd->fd.size - fd->fd.seek_pos);
 
        //kprintf("Reading at addr[%lu], size[%d]\n", fd->seek_pos, size);
        CS_ENABLE();
@@ -229,11 +223,11 @@ static size_t flash25_write(struct KFile *_fd, const void *_buf, size_t size)
        flash25Size_t wr_len;
        const uint8_t *data = (const uint8_t *) _buf;
 
-       Flash25 *fd = FLASH25KFILE(_fd);
+       Flash25 *fd = FLASH25_CAST(_fd);
 
-       ASSERT(fd->fd.seek_pos + (kfile_size_t)size <= fd->fd.size);
+       ASSERT(fd->fd.seek_pos + (kfile_off_t)size <= 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);
 
        while (size)
        {
@@ -330,8 +324,7 @@ void flash25_sectorErase(Flash25 *fd, Flash25Sector sector)
         */
        flash25_waitReady(fd);
 
-       DB(kprintf("Erased sector [%ld] in %d ms\n", sector, ticks_to_ms(timer_clock() - start_time)));
-
+       DB(kprintf("Erased sector [%ld] in %ld ms\n", (unsigned long)sector, (unsigned long)ticks_to_ms(timer_clock() - start_time)));
 }
 
 /**