typedef unsigned char sigbit_t; /**< Type for signal bits. */
typedef unsigned char sigmask_t; /**< Type for signal masks. */
-typedef unsigned char page_t; /**< Type for banked memory pages. */
/**
--- /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 2007 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief Low-level flash module for ARM (interface).
+ *
+ * \author Daniele Basile <asterix@develer.com>
+ *
+ */
+
+#include <cpu/detect.h>
+
+#if CPU_ARM_AT91
+ #include "flash_at91.h"
+/*#elif Add other ARM families here */
+#else
+ #error Unknown CPU
+#endif
#include <io/arm.h>
#include <drv/timer.h>
+#include <drv/flash.h>
#include <string.h>
* Write modified page on internal latch, and then send write command to
* flush page to internal flash.
*/
-RAM_FUNC static void flash_at91_flush(FlashAt91 *fd)
+RAM_FUNC static void flash_at91_flush(Flash *fd)
{
if (fd->page_dirty)
{
//Compute page address of current page.
- arm_page_addr_t *addr = (arm_page_addr_t *)((fd->curr_page * FLASH_PAGE_SIZE_BYTES) + FLASH_BASE);
+ page_addr_t *addr = (page_addr_t *)((fd->curr_page * FLASH_PAGE_SIZE_BYTES) + FLASH_BASE);
//Copy modified page into internal latch.
- for (arm_page_addr_t page_addr = 0; page_addr < FLASH_PAGE_SIZE_BYTES; page_addr += 4)
+ for (page_addr_t page_addr = 0; page_addr < FLASH_PAGE_SIZE_BYTES; page_addr += 4)
{
uint32_t data;
memcpy(&data, &fd->page_buf[page_addr], sizeof(data));
*/
static int flash_at91_kfileFlush(struct KFile *_fd)
{
- FlashAt91 *fd = FLASHAT91_CAST(_fd);
+ Flash *fd = FLASH_CAST(_fd);
flash_at91_flush(fd);
return 0;
}
* Check current page and if \a page is different, load it in
* temporary buffer.
*/
-static void flash_at91_loadPage(FlashAt91 *fd, arm_page_t page)
+static void flash_at91_loadPage(Flash *fd, page_t page)
{
if (page != fd->curr_page)
{
*/
static size_t flash_at91_write(struct KFile *_fd, const void *_buf, size_t size)
{
- FlashAt91 *fd = FLASHAT91_CAST(_fd);
+ Flash *fd = FLASH_CAST(_fd);
const uint8_t *buf =(const uint8_t *)_buf;
- arm_page_t page;
- arm_page_addr_t page_addr;
+ page_t page;
+ page_addr_t page_addr;
size_t total_write = 0;
size = MIN((kfile_off_t)size, (kfile_off_t)(fd->fd.size - (fd->fd.seek_pos - FLASH_BASE)));
*/
static int flash_at91_close(struct KFile *_fd)
{
- FlashAt91 *fd = FLASHAT91_CAST(_fd);
+ Flash *fd = FLASH_CAST(_fd);
flash_at91_flush(fd);
LOG_INFO("Flash file closed\n");
* \a name and \a mode are unused, cause flash memory is
* threated like one file.
*/
-static void flash_at91_open(struct FlashAt91 *fd)
+static void flash_at91_open(struct Flash *fd)
{
fd->fd.size = FLASH_BASE + FLASH_MEM_SIZE;
fd->fd.seek_pos = FLASH_BASE + FLASH_BOOT_SIZE;
*/
static kfile_off_t flash_at91_seek(struct KFile *_fd, kfile_off_t offset, KSeekMode whence)
{
- FlashAt91 *fd = FLASHAT91_CAST(_fd);
+ Flash *fd = FLASH_CAST(_fd);
kfile_off_t seek_pos;
switch (whence)
*/
static struct KFile *flash_at91_reopen(struct KFile *_fd)
{
- FlashAt91 *fd = FLASHAT91_CAST(_fd);
+ Flash *fd = FLASH_CAST(_fd);
flash_at91_close(_fd);
flash_at91_open(fd);
*/
static size_t flash_at91_read(struct KFile *_fd, void *_buf, size_t size)
{
- FlashAt91 *fd = FLASHAT91_CAST(_fd);
+ Flash *fd = FLASH_CAST(_fd);
uint8_t *buf =(uint8_t *)_buf;
size = MIN((kfile_off_t)size, fd->fd.size - fd->fd.seek_pos);
* Init module to perform write and read operation on internal
* flash memory.
*/
-void flash_at91_init(FlashAt91 *fd)
+void flash_hw_init(struct Flash *fd)
{
memset(fd, 0, sizeof(*fd));
- DB(fd->fd._type = KFT_FLASHAT91);
+ DB(fd->fd._type = KFT_FLASH);
// Set up flash programming functions.
fd->fd.reopen = flash_at91_reopen;
#include <io/arm.h>
+#define FLASH_PAGE_SIZE FLASH_PAGE_SIZE_BYTES
+
/**
* Define data type to manage page and memory address.
*/
-typedef uint32_t arm_page_t;
-typedef uint32_t arm_page_addr_t;
+typedef uint32_t page_t;
+typedef uint32_t page_addr_t;
+
+struct Flash;
/**
* FlashAt91 KFile context structure.
+ *
+ * DEPREACTED STRUCTURE!
+ * Use EmbFlash instead
+ *
+ * \{
*/
typedef struct FlashAt91
{
/**
* Current buffered page.
*/
- arm_page_t curr_page;
+ page_t curr_page;
/**
* Temporary buffer cointaing data block to
* write on flash.
*/
uint8_t page_buf[FLASH_PAGE_SIZE_BYTES];
-
-
} FlashAt91;
+/* \} */
-/**
- * ID for FlashAt91
- */
-#define KFT_FLASHAT91 MAKE_ID('F', 'A', '9', '1')
+void flash_hw_init(struct Flash *fd);
/**
- * Convert + ASSERT from generic KFile to FlashAt91.
+ * WARNING!
+ * This function is DEPRECADED!
+ * use the emb_flash module instead.
*/
-INLINE FlashAt91 * FLASHAT91_CAST(KFile *fd)
+INLINE void flash_at91_init(struct FlashAt91 *fd)
{
- ASSERT(fd->_type == KFT_FLASHAT91);
- return (FlashAt91 *)fd;
+ flash_hw_init((struct Flash *)fd);
}
-
-void flash_at91_init(FlashAt91 *fd);
-
-#endif
+#endif /* DRV_FLASH_ARM_H */
*
* \brief Self programming routines.
*
- * \version $Id$
* \author Francesco Sacchi <batt@develer.com>
* \author Daniele Basile <asterix@develer.com>
*
#include <cfg/log.h>
#include <drv/wdt.h>
+#include <drv/flash.h>
#include <kern/kfile.h>
/**
* Definition of type for avr flash module.
*/
-typedef uint16_t avr_page_addr_t;
-
-
+typedef uint16_t page_addr_t;
/**
*
* This function is only use internally in this module.
*/
-static void flash_avr_flush(FlashAvr *fd)
+static void flash_avr_flush(Flash *fd)
{
if (fd->page_dirty)
{
LOG_INFO("Filling temparary page buffer...");
// Fill the temporary buffer of the AVR
- for (avr_page_addr_t page_addr = 0; page_addr < SPM_PAGESIZE; page_addr += 2)
+ for (page_addr_t page_addr = 0; page_addr < SPM_PAGESIZE; page_addr += 2)
{
uint16_t word = ((uint16_t)fd->page_buf[page_addr + 1] << 8) | fd->page_buf[page_addr];
*/
static int flash_avr_kfileFlush(struct KFile *_fd)
{
- FlashAvr *fd = FLASHAVR_CAST(_fd);
+ Flash *fd = FLASH_CAST(_fd);
flash_avr_flush(fd);
return 0;
}
* Check current page and if \a page is different, load it in
* temporary buffer.
*/
-static void flash_avr_loadPage(FlashAvr *fd, avr_page_t page)
+static void flash_avr_loadPage(Flash *fd, page_t page)
{
if (page != fd->curr_page)
{
*/
static size_t flash_avr_write(struct KFile *_fd, const void *_buf, size_t size)
{
- FlashAvr *fd = FLASHAVR_CAST(_fd);
+ Flash *fd = FLASH_CAST(_fd);
const uint8_t *buf =(const uint8_t *)_buf;
- avr_page_t page;
- avr_page_addr_t page_addr;
+ page_t page;
+ page_addr_t page_addr;
size_t total_write = 0;
* \a name and \a mode are unused, cause flash memory is
* threated like one file.
*/
-static void flash_avr_open(struct FlashAvr *fd)
+static void flash_avr_open(struct Flash *fd)
{
fd->curr_page = 0;
memcpy_P(fd->page_buf, (const char *)(fd->curr_page * SPM_PAGESIZE), SPM_PAGESIZE);
*/
static int flash_avr_close(struct KFile *_fd)
{
- FlashAvr *fd = FLASHAVR_CAST(_fd);
+ Flash *fd = FLASH_CAST(_fd);
flash_avr_flush(fd);
LOG_INFO("Flash file closed\n");
return 0;
*/
static struct KFile *flash_avr_reopen(struct KFile *fd)
{
- FlashAvr *_fd = FLASHAVR_CAST(fd);
+ Flash *_fd = FLASH_CAST(fd);
flash_avr_close(fd);
- flash_avr_open(_fd);
+ flash_avr_open((struct Flash *)_fd);
return fd;
}
*/
static size_t flash_avr_read(struct KFile *_fd, void *buf, size_t size)
{
- FlashAvr *fd = FLASHAVR_CAST(_fd);
+ Flash *fd = FLASH_CAST(_fd);
ASSERT(fd->fd.seek_pos + (kfile_off_t)size <= (kfile_off_t)fd->fd.size);
size = MIN((kfile_off_t)size, fd->fd.size - fd->fd.seek_pos);
/**
* Init AVR flash read/write file.
*/
-void flash_avr_init(struct FlashAvr *fd)
+void flash_hw_init(struct Flash *fd)
{
memset(fd, 0, sizeof(*fd));
- DB(fd->fd._type = KFT_FLASHAVR);
+ DB(fd->fd._type = KFT_FLASH);
// Set up flash programming functions.
fd->fd.reopen = flash_avr_reopen;
*
* -->
*
- * \brief Self programming routines (interface).
- *
- * \version $Id$
* \author Francesco Sacchi <batt@develer.com>
* \author Daniele Basile <asterix@develer.com>
+ *
+ * \brief AVR Internal flash read/write driver.
+ *
+ *
*/
-#ifndef DRV_FLASH_AVR_H
-#define DRV_FLASH_AVR_H
+#ifndef FLASH_AT91_H
+#define FLASH_AT91_H
+
+#include <cpu/types.h>
#include <cfg/compiler.h>
+
#include <kern/kfile.h>
+
#include <avr/io.h>
+#define FLASH_PAGE_SIZE SPM_PAGESIZE
+
/**
* Definition of type for avr flash module.
*/
-typedef uint16_t avr_page_t;
+typedef uint16_t page_t;
+/* Forward declaration */
+struct Flash;
/**
* FlashAvr KFile context structure.
+ * DEPREACTED STRUCTURE!
+ * Use Flash instead
+ *
+ * \{
*/
typedef struct FlashAvr
{
KFile fd;
/**
- * Current buffered page.
+ * Flag for checking if current page is modified.
*/
- avr_page_t curr_page;
+ bool page_dirty;
/**
- * Flag for checking if current page is modified.
+ * Current buffered page.
*/
- bool page_dirty;
+ page_t curr_page;
/**
* Temporary buffer cointaing data block to
* write on flash.
*/
uint8_t page_buf[SPM_PAGESIZE];
-
-
} FlashAvr;
+/* \} */
-
-
-/**
- * ID for FlashAvr
- */
-#define KFT_FLASHAVR MAKE_ID('F', 'L', 'A', 'V')
+void flash_hw_init(struct Flash *fd);
/**
- * Convert + ASSERT from generic KFile to FlashAvr.
+ * WARNING!
+ * This function is DEPRECADED!
+ * use the flash module instead.
*/
-INLINE FlashAvr * FLASHAVR_CAST(KFile *fd)
+INLINE void flash_avr_init(struct FlashAvr *fd)
{
- ASSERT(fd->_type == KFT_FLASHAVR);
- return (FlashAvr *)fd;
+ flash_hw_init((struct Flash *)fd);
}
-
-void flash_avr_init(struct FlashAvr *fd);
-
-
-
#endif /* DRV_FLASH_AVR_H */