summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
d22dfae)
KFile to a KFIleFlashAvr struct.
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1488
38d2e660-2303-0410-9eaa-
f027e97ec537
-#warning FIXME:This module need to be refactor to kfile interface!
/**
* Definition of type for avr flash module.
*/
/**
* Definition of type for avr flash module.
*/
*/
static int flash_avr_kfileFlush(struct KFile * fd)
{
*/
static int flash_avr_kfileFlush(struct KFile * fd)
{
- KFILE_ASSERT_GENERIC(fd);
(void)fd;
flash_avr_flush();
return 0;
(void)fd;
flash_avr_flush();
return 0;
*/
static size_t flash_avr_write(struct KFile *fd, const void *_buf, size_t size)
{
*/
static size_t flash_avr_write(struct KFile *fd, const void *_buf, size_t size)
{
- KFILE_ASSERT_GENERIC(fd);
const uint8_t *buf =(const uint8_t *)_buf;
avr_page_t page;
avr_page_addr_t page_addr;
size_t total_write = 0;
const uint8_t *buf =(const uint8_t *)_buf;
avr_page_t page;
avr_page_addr_t page_addr;
size_t total_write = 0;
ASSERT(fd->seek_pos + size <= fd->size);
size = MIN((uint32_t)size, fd->size - fd->seek_pos);
ASSERT(fd->seek_pos + size <= fd->size);
size = MIN((uint32_t)size, fd->size - fd->seek_pos);
*/
static void flash_avr_open(struct KFile *fd)
{
*/
static void flash_avr_open(struct KFile *fd)
{
- KFILE_ASSERT_GENERIC(fd);
curr_page = 0;
memcpy_P(page_buf, (const char *)(curr_page * SPM_PAGESIZE), SPM_PAGESIZE);
curr_page = 0;
memcpy_P(page_buf, (const char *)(curr_page * SPM_PAGESIZE), SPM_PAGESIZE);
*/
static int flash_avr_close(UNUSED_ARG(struct KFile *,fd))
{
*/
static int flash_avr_close(UNUSED_ARG(struct KFile *,fd))
{
- KFILE_ASSERT_GENERIC(fd);
flash_avr_flush();
kprintf("Flash file closed\n");
return 0;
flash_avr_flush();
kprintf("Flash file closed\n");
return 0;
*/
static struct KFile *flash_avr_reopen(struct KFile *fd)
{
*/
static struct KFile *flash_avr_reopen(struct KFile *fd)
{
- KFILE_ASSERT_GENERIC(fd);
flash_avr_close(fd);
flash_avr_open(fd);
return fd;
flash_avr_close(fd);
flash_avr_open(fd);
return fd;
*/
static size_t flash_avr_read(struct KFile *fd, void *buf, size_t size)
{
*/
static size_t flash_avr_read(struct KFile *fd, void *buf, size_t size)
{
- KFILE_ASSERT_GENERIC(fd);
ASSERT(fd->seek_pos + size <= fd->size);
size = MIN((uint32_t)size, fd->size - fd->seek_pos);
ASSERT(fd->seek_pos + size <= fd->size);
size = MIN((uint32_t)size, fd->size - fd->seek_pos);
void flash_avr_init(struct KFile *fd)
{
memset(fd, 0, sizeof(*fd));
void flash_avr_init(struct KFile *fd)
{
memset(fd, 0, sizeof(*fd));
- DB(fd->_type = KFT_GENERIC);
+ DB(fd->_type = KFT_FLASHAVR);
// Set up flash programming functions.
fd->reopen = flash_avr_reopen;
// Set up flash programming functions.
fd->reopen = flash_avr_reopen;
#include <cfg/compiler.h>
#include <kern/kfile.h>
#include <cfg/compiler.h>
#include <kern/kfile.h>
+
+/**
+ * FlashAvr KFile context structure.
+ */
+typedef struct KFileFlashAvr
+{
+ KFile fd; ///< File descriptor.
+} KFileFlashAvr;
+
+
+
+/**
+ * ID for FlashAvr
+ */
+#define KFT_FLASHAVR MAKE_ID('F', 'L', 'A', 'V')
+
+/**
+ * Convert + ASSERT from generic KFile to KFileFlashAvr.
+ */
+INLINE KFileFlashAvr * KFILEFLASHAVR(KFile *fd)
+{
+ ASSERT(fd->_type == KFT_FLASHAVR);
+ return (KFileFlashAvr *)fd;
+}
+
+
+
bool flash_avr_test(void);
void flash_avr_init(struct KFile *fd);
bool flash_avr_test(void);
void flash_avr_init(struct KFile *fd);
#endif /* DRV_FLASH_AVR_H */
#endif /* DRV_FLASH_AVR_H */