Root/atusb/fw/board.c

Source at commit cec05a0f5ea2fb4ff5637d418c7f5dae196abda8 created 6 years 9 months ago.
By Werner Almesberger, atusb/atusb.pro: we don't use power.lib anymore
1/*
2 * fw/board.c - Board-specific functions (for boot loader and application)
3 *
4 * Written 2011, 2013 by Werner Almesberger
5 * Copyright 2011, 2013 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 <stdbool.h>
15#include <stdint.h>
16
17#include <avr/io.h>
18#include <avr/interrupt.h>
19#include <avr/boot.h>
20
21#define F_CPU 8000000UL
22#include <util/delay.h>
23
24#include "usb.h"
25#include "at86rf230.h"
26#include "board.h"
27#include "spi.h"
28
29
30uint8_t board_sernum[42] = { 42, USB_DT_STRING };
31
32void reset_rf(void)
33{
34    /* set up all the outputs; default port value is 0 */
35
36    DDRB = 0;
37    DDRC = 0;
38    DDRD = 0;
39    PORTB = 0;
40    PORTC = 0;
41    PORTD = 0;
42
43    OUT(LED);
44    OUT(nRST_RF); /* this also resets the transceiver */
45    OUT(SLP_TR);
46
47    spi_init();
48
49    /* AT86RF231 data sheet, 12.4.13, reset pulse width: 625 ns (min) */
50
51    CLR(nRST_RF);
52    _delay_us(2);
53    SET(nRST_RF);
54
55    /* 12.4.14: SPI access latency after reset: 625 ns (min) */
56
57    _delay_us(2);
58
59    /* we must restore TRX_CTRL_0 after each reset (9.6.4) */
60
61    set_clkm();
62}
63
64
65void led(bool on)
66{
67    if (on)
68        SET(LED);
69    else
70        CLR(LED);
71}
72
73
74void panic(void)
75{
76    cli();
77    while (1) {
78        SET(LED);
79        _delay_ms(100);
80        CLR(LED);
81        _delay_ms(100);
82    }
83}
84
85
86static char hex(uint8_t nibble)
87{
88    return nibble < 10 ? '0'+nibble : 'a'+nibble-10;
89}
90
91
92void get_sernum(void)
93{
94    uint8_t sig;
95    uint8_t i;
96
97    for (i = 0; i != 10; i++) {
98        sig = boot_signature_byte_get(i+0xe);
99        board_sernum[(i << 2)+2] = hex(sig >> 4);
100        board_sernum[(i << 2)+4] = hex(sig & 0xf);
101    }
102}
103

Archive Download this file



interactive