2 * fw/board_app.c - Board-specific functions (for the application)
4 * Written 2011, 2013 by Werner Almesberger
5 * Copyright 2011, 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 <avr/interrupt.h>
21 #define F_CPU 8000000UL
22 #include <util/delay.h>
25 #include "at86rf230.h"
31 static volatile uint32_t timer_h = 0; /* 2^(16+32) / 8 MHz = ~1.1 years */
40 uint8_t read_irq(void)
59 uint64_t timer_read(void)
65 if (TIFR1 & (1 << TOV1)) {
73 while (TIFR1 & (1 << TOV1));
76 * We need all these casts because the intermediate results are handled
77 * as if they were signed and thus get sign-expanded. Sounds wrong-ish.
79 return (uint64_t) high << 16 | (uint64_t) mid << 8 | (uint64_t) low;
85 /* configure timer 1 as a free-running CLK counter */
90 /* enable timer overflow interrupt */
96 bool gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res)
98 EIMSK = 0; /* recover INT_RF to ATUSB_GPIO_CLEANUP or an MCU reset */
102 DDRB = (DDRB & ~mask) | dir;
103 PORTB = (PORTB & ~mask) | data;
106 DDRC = (DDRC & ~mask) | dir;
107 PORTC = (PORTC & ~mask) | data;
110 DDRD = (DDRD & ~mask) | dir;
111 PORTD = (PORTD & ~mask) | data;
117 /* disable the UART so that we can meddle with these pins as well. */
143 void gpio_cleanup(void)
149 static void done(void *user)
157 #if defined(ATUSB) || defined(HULUSB)
161 ISR(TIMER1_CAPT_vect)
168 if (eps[1].state == EP_IDLE) {
170 irq_serial = (irq_serial+1) | 0x80;
171 usb_send(&eps[1], &irq_serial, 1, done, NULL);