Root/atusb/fw/board.h

1/*
2 * fw/board.h - Board-specific functions and definitions
3 *
4 * Written 2008-2011, 2013, 2013 by Werner Almesberger
5 * Copyright 2008-2011, 2013, 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#ifndef BOARD_H
14#define BOARD_H
15
16#include <stdbool.h>
17#include <stdint.h>
18
19#include <atusb/atusb.h>
20
21
22#define LED_PORT B
23#define LED_BIT 6
24#define nRST_RF_PORT C
25#define nRST_RF_BIT 7
26#define SLP_TR_PORT B
27#define SLP_TR_BIT 4
28
29#define SCLK_PORT D
30#define SCLK_BIT 5
31#define MOSI_PORT D
32#define MOSI_BIT 3
33
34#define MISO_PORT D
35#define MISO_BIT 2
36#define nSS_PORT D
37#define nSS_BIT 1
38#define IRQ_RF_PORT D
39#define IRQ_RF_BIT 0
40
41
42#define SET_2(p, b) PORT##p |= 1 << (b)
43#define CLR_2(p, b) PORT##p &= ~(1 << (b))
44#define IN_2(p, b) DDR##p &= ~(1 << (b))
45#define OUT_2(p, b) DDR##p |= 1 << (b)
46#define PIN_2(p, b) ((PIN##p >> (b)) & 1)
47
48#define SET_1(p, b) SET_2(p, b)
49#define CLR_1(p, b) CLR_2(p, b)
50#define IN_1(p, b) IN_2(p, b)
51#define OUT_1(p, b) OUT_2(p, b)
52#define PIN_1(p, b) PIN_2(p, b)
53
54#define SET(n) SET_1(n##_PORT, n##_BIT)
55#define CLR(n) CLR_1(n##_PORT, n##_BIT)
56#define IN(n) IN_1(n##_PORT, n##_BIT)
57#define OUT(n) OUT_1(n##_PORT, n##_BIT)
58#define PIN(n) PIN_1(n##_PORT, n##_BIT)
59
60
61#define USB_VENDOR ATUSB_VENDOR_ID
62#define USB_PRODUCT ATUSB_PRODUCT_ID
63
64#define DFU_USB_VENDOR USB_VENDOR
65#define DFU_USB_PRODUCT USB_PRODUCT
66
67
68#define BOARD_MAX_mA 40
69
70#ifdef BOOT_LOADER
71#define NUM_EPS 1
72#else
73#define NUM_EPS 2
74#endif
75
76#define HAS_BOARD_SERNUM
77
78extern uint8_t board_sernum[42];
79extern uint8_t irq_serial;
80
81
82void reset_rf(void);
83void reset_cpu(void);
84uint8_t read_irq(void);
85void slp_tr(void);
86
87void led(bool on);
88void panic(void);
89
90uint64_t timer_read(void);
91void timer_init(void);
92
93bool gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res);
94void gpio_cleanup(void);
95
96void board_init(void);
97void board_app_init(void);
98
99#endif /* !BOARD_H */
100

Archive Download this file



interactive