2 * fw/board.h - Board-specific functions and definitions
4 * Written 2008-2011, 2013, 2013 by Werner Almesberger
5 * Copyright 2008-2011, 2013, 2013 Werner Almesberger
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.
19 #include <atusb/atusb.h>
22 #include "board_atusb.h"
25 #include "board_rzusb.h"
28 #include "board_hulusb.h"
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)
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)
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)
50 #define USB_VENDOR ATUSB_VENDOR_ID
51 #define USB_PRODUCT ATUSB_PRODUCT_ID
53 #define DFU_USB_VENDOR USB_VENDOR
54 #define DFU_USB_PRODUCT USB_PRODUCT
57 #define BOARD_MAX_mA 40
65 #define HAS_BOARD_SERNUM
67 extern uint8_t board_sernum[42];
68 extern uint8_t irq_serial;
73 uint8_t read_irq(void);
79 uint64_t timer_read(void);
80 void timer_init(void);
82 bool gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res);
83 void gpio_cleanup(void);
85 void get_sernum(void);
87 void board_app_init(void);
89 uint8_t reg_read(uint8_t reg);
90 uint8_t subreg_read(uint8_t address, uint8_t mask, uint8_t position);
91 void reg_write(uint8_t reg, uint8_t value);
92 void subreg_write(uint8_t address, uint8_t mask, uint8_t position, uint8_t value);
93 void change_state(uint8_t new);