flash_avr.c File Reference

Self programming routines. More...

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

Go to the source code of this file.


Typedefs

typedef uint16_t avr_page_addr_t
 Definition of type for avr flash module.

Functions

static int flash_avr_kfileFlush (struct KFile *fd)
 Flush avr flash function.
static void flash_avr_loadPage (avr_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 KFile *fd)
 Open flash file fd name and mode are unused, cause flash memory is threated like one file.
static int flash_avr_close (UNUSED_ARG(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_avr_init (struct KFile *fd)
 Init AVR flash read/write file.

Variables

static uint8_t page_buf [SPM_PAGESIZE]
 Temporary buffer cointaing data block to write on flash.
bool page_modified
 Flag for checking if current page is modified.
static avr_page_t curr_page = 0
 Current buffered page.

Detailed Description

Self programming routines.

Version:
Id
flash_avr.c 1049 2008-01-16 16:15:48Z asterix
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 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 147 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 255 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 177 of file flash_avr.c.