Date:2011-03-09 06:02:05 (8 years 3 months ago)
Author:Werner Almesberger
Commit:b8fc1a7f54f77fd6ceb906a115b9100b409d6d81
Message:atusb/fw/flash.c: added basic writing support (untested)

Files: atusb/fw/flash.c (1 diff)

Change Details

atusb/fw/flash.c
1313
1414#include <stdint.h>
1515
16#include <avr/io.h>
17#include <avr/interrupt.h>
18
19#define F_CPU 8000000UL
20#include <util/delay.h>
16#include <avr/boot.h>
2117
2218#include "dfu.h"
2319#include "board.h"
2420
2521
22static uint32_t payload;
23
2624
2725void flash_start(void)
2826{
27    payload = 0;
2928}
3029
3130
3231int flash_can_write(uint16_t size)
3332{
34    return 0;
33    return 1;
3534}
3635
3736
3837void flash_write(const uint8_t *buf, uint16_t size)
3938{
39    static uint8_t last;
40        const uint8_t *p;
41
42    eeprom_busy_wait();
43    for (p = buf; p != buf+size; p++) {
44        if (!(payload & (SPM_PAGESIZE-1))) {
45            if (payload) {
46                boot_page_write(payload-SPM_PAGESIZE);
47                boot_spm_busy_wait();
48            }
49            boot_page_erase(payload);
50            boot_spm_busy_wait();
51        }
52        if (payload & 1)
53            boot_page_fill(payload, last | (*p << 0));
54        else
55            last = *p;
56        payload++;
57        }
58
59    if (!(payload & (SPM_PAGESIZE-1))) {
60        boot_page_write(payload);
61        boot_spm_busy_wait();
62    }
63
64    boot_rww_enable();
4065}
4166
4267

Archive Download the corresponding diff file



interactive