Root/atusb/fw/boot.c

Source at commit ddd00223505d8283637bcd4c0796f2f01262db64 created 8 years 2 months ago.
By Werner Almesberger, atusb/fw/boot.c (main): don't time out until there is an application
1/*
2 * fw/boot.c - DFU boot loader for ATUSB
3 *
4 * Written 2008-2011 by Werner Almesberger
5 * Copyright 2008-2011 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdint.h>
15
16#include <avr/io.h>
17#include <avr/pgmspace.h>
18
19#define F_CPU 8000000UL
20#include <util/delay.h>
21
22#include "usb.h"
23#include "dfu.h"
24
25#include "board.h"
26#include "spi.h"
27#include "atusb/ep0.h"
28
29
30#define MS_TO_LOOPS(ms) ((uint32_t) (ms)*81)
31
32
33static void (*run_payload)(void) = 0;
34
35
36int main(void)
37{
38    /*
39     * pgm_read_byte gets cached and there doesn't seem to be any other
40     * way to dissuade gcc from doing this.
41     */
42    volatile int zero = 0;
43    uint32_t loop = 0;
44
45    board_init();
46    spi_init();
47    reset_rf();
48
49    /* now we should be at 8 MHz */
50
51    usb_init();
52    dfu_init();
53
54    led(1);
55
56    while (loop != MS_TO_LOOPS(2000)) {
57        usb_poll();
58        if (dfu.state == dfuIDLE && pgm_read_byte(zero) != 0xff)
59            loop++;
60        else
61            loop = 0;
62    }
63
64    led(0);
65
66    usb_reset();
67    run_payload();
68
69    while (1); /* not reached */
70}
71

Archive Download this file



interactive