Root/atrf/fw/atspi/atspi.c

Source at commit c2dd23840ce5875deca09673fcb8abb8dc3a8e7a created 9 years 3 months ago.
By Werner Almesberger, Moved fw/ and tools/ into atrf/ as well.
1/*
2 * atspi/atspi.c - ATSPI initialization and main loop
3 *
4 * Written 2008-2010 by Werner Almesberger
5 * Copyright 2008-2010 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 "regs.h"
15#include "io.h"
16#include "usb.h"
17#include "atspi/ep0.h"
18#include "version.h"
19
20
21void reset_rf(void)
22{
23    int i;
24
25    nRST_RF = 0;
26    /*
27     * 11.4.12: min 625 ns.
28     * The pulse we generate is slightly longer than 4 us.
29     */
30    for (i = 0; i != 10; i++);
31    nRST_RF = 1;
32}
33
34
35static void init_io(void)
36{
37    /*
38     * Signal Mode Value
39     *
40     * MOSI push-pull 0
41     * MISO open drain 1 (input)
42     * SCLK push-pull 0
43     * nSS push-pull 1
44     * nRST_RF push-pull 1
45     * IRQ_RF open drain 1 (input)
46     * SLP_TR push-pull 0
47     *
48     * LED push-pull 0 (set up by boot loader)
49     *
50     * all unused open drain 0
51     */
52
53    MOSI = 0;
54    MOSI_MODE |= 1 << MOSI_BIT;
55
56    SCLK = 0;
57    SCLK_MODE |= 1 << SCLK_BIT;
58
59    nSS_MODE |= 1 << nSS_BIT;
60
61    nRST_RF_MODE |= 1 << nRST_RF_BIT;
62
63    SLP_TR = 0;
64    SLP_TR_MODE |= 1 << SLP_TR_BIT;
65
66    P0 &=
67        ~((1 << 0) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7));
68        /* change 1 << 0 to 1 << 2 once 100813 boards are reworked */
69    P3 = 0;
70
71#if 0
72    /*
73     * We can *almost* disable the pull-ups. The only obstacle is that
74     * MISO is not driven when not in use. So we either need an external
75     * pull-up/down or keep all the pull-ups on.
76     */
77
78    /*
79     * Disable pull-ups
80     */
81    GPIOCN |= WEAKPUD;
82#endif
83
84    /*
85     * The manual says the reset is optional, but reality disagrees with
86     * this optimistic assessment quite violently.
87     */
88
89    reset_rf();
90}
91
92
93void main(void)
94{
95    init_io();
96
97    usb_init();
98    ep0_init();
99
100    while (1) {
101        usb_poll();
102    }
103}
104

Archive Download this file



interactive