flash_avr.c File Reference

Self programming routines. More...

#include "flash_avr.h"
#include <cpu/types.h>
#include <cfg/compiler.h>
#include <kern/kfile.h>
#include <avr/io.h>
#include "cfg/cfg_flash_avr.h"
#include <cfg/macros.h>
#include <cfg/debug.h>
#include <cpu/irq.h>
#include <cfg/log.h>
#include <drv/wdt.h>
#include <drv/flash.h>
#include <avr/boot.h>
#include <avr/pgmspace.h>
#include <string.h>

Go to the source code of this file.

Typedefs

typedef uint16_t page_addr_t
 Definition of type for avr flash module.

Functions

static void flash_avr_flush (Flash *fd)
 Private avr flush funtion.
static int flash_avr_kfileFlush (struct KFile *_fd)
 Flush avr flash function.
static void flash_avr_loadPage (Flash *fd, page_t page)
 Check current page and if page is different, load it in temporary buffer.
static size_t flash_avr_write (struct KFile *_fd, const void *_buf, size_t size)
 Write program memory.
static void flash_avr_open (struct Flash *fd)
 Open flash file fd name and mode are unused, cause flash memory is threated like one file.
static int flash_avr_close (struct KFile *_fd)
 Close file fd.
static struct KFileflash_avr_reopen (struct KFile *fd)
 Reopen file fd.
static size_t flash_avr_read (struct KFile *_fd, void *buf, size_t size)
 Read from file fd size bytes and put it in buffer buf.
void flash_hw_init (struct Flash *fd)
 Init AVR flash read/write file.

Detailed Description

Self programming routines.

Author:
Francesco Sacchi <batt@develer.com>
Daniele Basile <asterix@develer.com>

This module implements a kfile-like access for Atmel avr internal flash. Internal flash writing access is controlled by BOOTSZ fuses, check datasheet for details.

Definition in file flash_avr.c.


Function Documentation

static void flash_avr_flush ( Flash fd  )  [static]

Private avr flush funtion.

Write current buffered page in flash memory (if modified). This function erase flash memory page before writing.

This function is only use internally in this module.

Definition at line 83 of file flash_avr.c.

static int flash_avr_kfileFlush ( struct KFile _fd  )  [static]

Flush avr flash function.

Write current buffered page in flash memory (if modified). This function erase flash memory page before writing.

Definition at line 139 of file flash_avr.c.

static size_t flash_avr_read ( struct KFile _fd,
void *  buf,
size_t  size 
) [static]

Read from file fd size bytes and put it in buffer buf.

Returns:
the number of bytes read.

Definition at line 246 of file flash_avr.c.

static size_t flash_avr_write ( struct KFile _fd,
const void *  _buf,
size_t  size 
) [static]

Write program memory.

Write size bytes from buffer _buf to file fd

Note:
Write operations are buffered.

Definition at line 168 of file flash_avr.c.

void flash_hw_init ( struct Flash fd  ) 

Init AVR flash read/write file.

Init module to perform write and read operation on internal flash memory.

Definition at line 272 of file flash_avr.c.