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#ifdef ATUSB
22#include "board_atusb.h"
23#endif
24#ifdef RZUSB
25#include "board_rzusb.h"
26#endif
27#ifdef HULUSB
28#include "board_hulusb.h"
29#endif
30
31#define SET_2(p, b) PORT##p |= 1 << (b)
32#define CLR_2(p, b) PORT##p &= ~(1 << (b))
33#define IN_2(p, b) DDR##p &= ~(1 << (b))
34#define OUT_2(p, b) DDR##p |= 1 << (b)
35#define PIN_2(p, b) ((PIN##p >> (b)) & 1)
36
37#define SET_1(p, b) SET_2(p, b)
38#define CLR_1(p, b) CLR_2(p, b)
39#define IN_1(p, b) IN_2(p, b)
40#define OUT_1(p, b) OUT_2(p, b)
41#define PIN_1(p, b) PIN_2(p, b)
42
43#define SET(n) SET_1(n##_PORT, n##_BIT)
44#define CLR(n) CLR_1(n##_PORT, n##_BIT)
45#define IN(n) IN_1(n##_PORT, n##_BIT)
46#define OUT(n) OUT_1(n##_PORT, n##_BIT)
47#define PIN(n) PIN_1(n##_PORT, n##_BIT)
48
49
50#define USB_VENDOR ATUSB_VENDOR_ID
51#define USB_PRODUCT ATUSB_PRODUCT_ID
52
53#define DFU_USB_VENDOR USB_VENDOR
54#define DFU_USB_PRODUCT USB_PRODUCT
55
56
57#define BOARD_MAX_mA 40
58
59#ifdef BOOT_LOADER
60#define NUM_EPS 1
61#else
62#define NUM_EPS 2
63#endif
64
65#define HAS_BOARD_SERNUM
66
67extern uint8_t board_sernum[42];
68extern uint8_t irq_serial;
69
70
71void reset_rf(void);
72void reset_cpu(void);
73uint8_t read_irq(void);
74void slp_tr(void);
75
76void led(bool on);
77void panic(void);
78
79uint64_t timer_read(void);
80void timer_init(void);
81
82bool gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res);
83void gpio_cleanup(void);
84
85void get_sernum(void);
86
87void board_app_init(void);
88
89uint8_t reg_read(uint8_t reg);
90uint8_t subreg_read(uint8_t address, uint8_t mask, uint8_t position);
91void reg_write(uint8_t reg, uint8_t value);
92void subreg_write(uint8_t address, uint8_t mask, uint8_t position, uint8_t value);
93void change_state(uint8_t new);
94
95#endif /* !BOARD_H */
96

Archive Download this file



interactive