2011-02-14 17:48:42 +02:00
|
|
|
/*
|
|
|
|
* fw/board.h - Board-specific functions and definitions
|
|
|
|
*
|
2013-04-01 11:54:58 +03:00
|
|
|
* Written 2008-2011, 2013, 2013 by Werner Almesberger
|
|
|
|
* Copyright 2008-2011, 2013, 2013 Werner Almesberger
|
2011-02-14 17:48:42 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
2011-02-14 04:46:36 +02:00
|
|
|
#ifndef BOARD_H
|
|
|
|
#define BOARD_H
|
|
|
|
|
2013-03-30 00:14:11 +02:00
|
|
|
#include <stdbool.h>
|
2011-02-14 04:46:36 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2013-04-01 11:54:58 +03:00
|
|
|
#include <atusb/atusb.h>
|
|
|
|
|
2015-05-24 15:37:38 +03:00
|
|
|
#ifdef ATUSB
|
2016-03-30 01:03:48 +03:00
|
|
|
#include "board_atusb.h"
|
2015-05-24 15:37:38 +03:00
|
|
|
#endif
|
|
|
|
#ifdef RZUSB
|
2016-03-30 01:03:48 +03:00
|
|
|
#include "board_rzusb.h"
|
2015-05-24 15:37:38 +03:00
|
|
|
#endif
|
2017-09-11 14:58:33 +03:00
|
|
|
#ifdef HULUSB
|
|
|
|
#include "board_hulusb.h"
|
|
|
|
#endif
|
2011-02-14 04:46:36 +02:00
|
|
|
|
|
|
|
#define SET_2(p, b) PORT##p |= 1 << (b)
|
|
|
|
#define CLR_2(p, b) PORT##p &= ~(1 << (b))
|
|
|
|
#define IN_2(p, b) DDR##p &= ~(1 << (b))
|
|
|
|
#define OUT_2(p, b) DDR##p |= 1 << (b)
|
|
|
|
#define PIN_2(p, b) ((PIN##p >> (b)) & 1)
|
|
|
|
|
|
|
|
#define SET_1(p, b) SET_2(p, b)
|
|
|
|
#define CLR_1(p, b) CLR_2(p, b)
|
|
|
|
#define IN_1(p, b) IN_2(p, b)
|
|
|
|
#define OUT_1(p, b) OUT_2(p, b)
|
|
|
|
#define PIN_1(p, b) PIN_2(p, b)
|
|
|
|
|
|
|
|
#define SET(n) SET_1(n##_PORT, n##_BIT)
|
|
|
|
#define CLR(n) CLR_1(n##_PORT, n##_BIT)
|
|
|
|
#define IN(n) IN_1(n##_PORT, n##_BIT)
|
|
|
|
#define OUT(n) OUT_1(n##_PORT, n##_BIT)
|
|
|
|
#define PIN(n) PIN_1(n##_PORT, n##_BIT)
|
|
|
|
|
2011-02-14 17:48:42 +02:00
|
|
|
|
2013-04-01 11:54:58 +03:00
|
|
|
#define USB_VENDOR ATUSB_VENDOR_ID
|
|
|
|
#define USB_PRODUCT ATUSB_PRODUCT_ID
|
2011-03-09 00:01:54 +02:00
|
|
|
|
2011-03-09 05:41:32 +02:00
|
|
|
#define DFU_USB_VENDOR USB_VENDOR
|
|
|
|
#define DFU_USB_PRODUCT USB_PRODUCT
|
|
|
|
|
2011-03-09 00:01:54 +02:00
|
|
|
|
2011-06-11 00:48:16 +03:00
|
|
|
#define BOARD_MAX_mA 40
|
|
|
|
|
2011-06-26 12:59:13 +03:00
|
|
|
#ifdef BOOT_LOADER
|
|
|
|
#define NUM_EPS 1
|
|
|
|
#else
|
|
|
|
#define NUM_EPS 2
|
|
|
|
#endif
|
|
|
|
|
2011-05-10 23:23:08 +03:00
|
|
|
#define HAS_BOARD_SERNUM
|
|
|
|
|
|
|
|
extern uint8_t board_sernum[42];
|
atusb/fw/: added improved support for interrupt synchronization
At an interrupt barrier, the host must be able to ensure that no
interrupt generated before reaching the barrier is still pending and
will be delivered after crossing the barrier.
For this, we introduce the following concept:
- interrupts have a serial number. This number is sent to the host
on EP 1 (currently bulk) to signal the interrupt, instead of the
zero byte we used previously.
- the new request ATUSB_SPI_WRITE2_SYNC returns the interrupt
serial number from after the register write (the register write
itself is the interrupt barrier).
- the host can now check if the serial indicated from bulk and the
serial from ATUSB_SPI_WRITE2_SYNC are the same. If yes, interrupts
are synchronized. If not, it has to wait for the interrupt to be
signaled on EP 1.
We should also consider the case that the interrupt serial has gotten
ahead of ATUSB_SPI_WRITE2_SYNC. But that seems to happen rarely. In
any case, it's something for the host driver to worry about, not for
the firmware.
- board.h (irq_serial), board_app.c (irq_serial, INT0_vect): count
the interrupt serial number and return it when signaling the
interrupt
- include/atusb/ep0.h (ATUSB_SPI_WRITE2_SYNC), ep0.c (my_setup):
new request ATUSB_SPI_WRITE2_SYNC that does a register write, then
returns the interrupt serial
2011-07-07 21:51:07 +03:00
|
|
|
extern uint8_t irq_serial;
|
2011-05-10 23:23:08 +03:00
|
|
|
|
|
|
|
|
2011-02-14 04:46:36 +02:00
|
|
|
void reset_rf(void);
|
2011-05-10 05:52:00 +03:00
|
|
|
void reset_cpu(void);
|
2011-02-14 04:46:36 +02:00
|
|
|
uint8_t read_irq(void);
|
2011-06-06 04:34:49 +03:00
|
|
|
void slp_tr(void);
|
2011-03-09 05:41:32 +02:00
|
|
|
|
2013-03-30 00:19:49 +02:00
|
|
|
void led(bool on);
|
2011-02-14 04:46:36 +02:00
|
|
|
void panic(void);
|
2011-03-09 05:41:32 +02:00
|
|
|
|
2011-05-30 03:05:28 +03:00
|
|
|
uint64_t timer_read(void);
|
2011-06-11 07:52:16 +03:00
|
|
|
void timer_init(void);
|
2011-05-30 03:05:28 +03:00
|
|
|
|
2013-03-30 00:14:11 +02:00
|
|
|
bool gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res);
|
2011-06-21 05:11:09 +03:00
|
|
|
void gpio_cleanup(void);
|
2011-06-04 15:40:34 +03:00
|
|
|
|
2016-03-30 01:03:48 +03:00
|
|
|
void get_sernum(void);
|
|
|
|
|
2011-06-20 21:49:33 +03:00
|
|
|
void board_app_init(void);
|
2011-02-14 04:46:36 +02:00
|
|
|
|
2017-09-11 14:58:33 +03:00
|
|
|
uint8_t reg_read(uint8_t reg);
|
|
|
|
uint8_t subreg_read(uint8_t address, uint8_t mask, uint8_t position);
|
|
|
|
void reg_write(uint8_t reg, uint8_t value);
|
|
|
|
void subreg_write(uint8_t address, uint8_t mask, uint8_t position, uint8_t value);
|
|
|
|
void change_state(uint8_t new);
|
|
|
|
|
2011-02-14 04:46:36 +02:00
|
|
|
#endif /* !BOARD_H */
|