Root/atusb/fw/boot.c

Source at commit d233c04c86c2fde39b5e069bb6750caef3393f32 created 8 years 7 months ago.
By Werner Almesberger, atusb/fw: implemented USB bus reset (to host) and polling of reset from host
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
18#define F_CPU 8000000UL
19#include <util/delay.h>
20
21#include "usb.h"
22#include "dfu.h"
23
24#include "board.h"
25#include "spi.h"
26#include "atusb/ep0.h"
27
28
29#define MS_TO_LOOPS(ms) ((uint32_t) (ms)*81)
30
31
32static void (*run_payload)(void) = 0;
33
34
35int main(void)
36{
37    uint32_t loop = 0;
38
39    board_init();
40    spi_init();
41    reset_rf();
42
43    /* now we should be at 8 MHz */
44
45    usb_init();
46    dfu_init();
47
48    led(1);
49
50    while (loop != MS_TO_LOOPS(2000)) {
51        usb_poll();
52        if (dfu.state == dfuIDLE)
53            loop++;
54        else
55            loop = 0;
56    }
57
58    led(0);
59
60    usb_reset();
61    run_payload();
62
63    while (1); /* not reached */
64}
65

Archive Download this file



interactive