mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-22 15:15:18 +02:00
atusb/fw/: split board functions into app-only/shared part (boot overlflowed)
- board.c (timer_h, reset_cpu, read_irq, slp_tr, timer_poll, timer_read, gpio): moved to new file board_app.c - Makefile (OBJS): added board_app.o
This commit is contained in:
parent
b41076135c
commit
e678401ac3
@ -31,7 +31,7 @@ SIZE = $(AVR_PREFIX)size
|
||||
USB_ID = 20b7:1540
|
||||
|
||||
USB_OBJS = usb.o atu2.o
|
||||
OBJS = atusb.o board.o sernum.o spi.o descr.o ep0.o $(USB_OBJS)
|
||||
OBJS = atusb.o board.o board_app.o sernum.o spi.o descr.o ep0.o $(USB_OBJS)
|
||||
BOOT_OBJS = boot.o board.o sernum.o spi.o flash.o dfu.o $(USB_OBJS)
|
||||
|
||||
vpath %.c usb/
|
||||
|
101
atusb/fw/board.c
101
atusb/fw/board.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* fw/board.c - Board-specific functions
|
||||
* fw/board.c - Board-specific functions (for boot loader and application)
|
||||
*
|
||||
* Written 2011 by Werner Almesberger
|
||||
* Copyright 2011 Werner Almesberger
|
||||
@ -29,9 +29,6 @@
|
||||
uint8_t board_sernum[42] = { 42, USB_DT_STRING };
|
||||
|
||||
|
||||
static uint32_t timer_h = 0; /* 2^(16+32) / 8 MHz = ~1.1 years */
|
||||
|
||||
|
||||
static void set_clkm(void)
|
||||
{
|
||||
/* switch CLKM to 8 MHz */
|
||||
@ -84,25 +81,6 @@ void reset_rf(void)
|
||||
}
|
||||
|
||||
|
||||
void reset_cpu(void)
|
||||
{
|
||||
WDTCSR = 1 << WDE;
|
||||
}
|
||||
|
||||
|
||||
uint8_t read_irq(void)
|
||||
{
|
||||
return PIN(IRQ_RF);
|
||||
}
|
||||
|
||||
|
||||
void slp_tr(void)
|
||||
{
|
||||
SET(SLP_TR);
|
||||
CLR(SLP_TR);
|
||||
}
|
||||
|
||||
|
||||
void led(int on)
|
||||
{
|
||||
if (on)
|
||||
@ -124,36 +102,6 @@ void panic(void)
|
||||
}
|
||||
|
||||
|
||||
void timer_poll(void)
|
||||
{
|
||||
if (!(TIFR1 & (1 << TOV1)))
|
||||
return;
|
||||
TIFR1 = 1 << TOV1;
|
||||
timer_h++;
|
||||
}
|
||||
|
||||
|
||||
uint64_t timer_read(void)
|
||||
{
|
||||
uint32_t high;
|
||||
uint8_t low, mid;
|
||||
|
||||
do {
|
||||
timer_poll();
|
||||
high = timer_h;
|
||||
low = TCNT1L;
|
||||
mid = TCNT1H;
|
||||
}
|
||||
while (TIFR1 & (1 << TOV1));
|
||||
|
||||
/*
|
||||
* We need all these casts because the intermediate results are handled
|
||||
* as if they were signed and thus get sign-expanded. Sounds wrong-ish.
|
||||
*/
|
||||
return (uint64_t) high << 16 | (uint64_t) mid << 8 | (uint64_t) low;
|
||||
}
|
||||
|
||||
|
||||
static char hex(uint8_t nibble)
|
||||
{
|
||||
return nibble < 10 ? '0'+nibble : 'a'+nibble-10;
|
||||
@ -173,53 +121,6 @@ static void get_sernum(void)
|
||||
}
|
||||
|
||||
|
||||
int gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res)
|
||||
{
|
||||
switch (port) {
|
||||
case 1:
|
||||
DDRB = (DDRB & ~mask) | dir;
|
||||
PORTB = (PORTB & ~mask) | data;
|
||||
break;
|
||||
case 2:
|
||||
DDRC = (DDRC & ~mask) | dir;
|
||||
PORTC = (PORTC & ~mask) | data;
|
||||
break;
|
||||
case 3:
|
||||
DDRD = (DDRD & ~mask) | dir;
|
||||
PORTD = (PORTD & ~mask) | data;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* disable the UART so that we can meddle with these pins as well. */
|
||||
UCSR1B = 0;
|
||||
_delay_ms(1);
|
||||
|
||||
switch (port) {
|
||||
case 1:
|
||||
res[0] = PINB;
|
||||
res[1] = PORTB;
|
||||
res[2] = DDRB;
|
||||
break;
|
||||
case 2:
|
||||
res[0] = PINC;
|
||||
res[1] = PORTC;
|
||||
res[2] = DDRC;
|
||||
break;
|
||||
case 3:
|
||||
res[0] = PIND;
|
||||
res[1] = PORTD;
|
||||
res[2] = DDRD;
|
||||
break;
|
||||
}
|
||||
|
||||
spi_init();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
/* Disable the watchdog timer */
|
||||
|
125
atusb/fw/board_app.c
Normal file
125
atusb/fw/board_app.c
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* fw/board_app.c - Board-specific functions (for the application)
|
||||
*
|
||||
* Written 2011 by Werner Almesberger
|
||||
* Copyright 2011 Werner Almesberger
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/boot.h>
|
||||
|
||||
#define F_CPU 8000000UL
|
||||
#include <util/delay.h>
|
||||
|
||||
#include "usb.h"
|
||||
#include "at86rf230.h"
|
||||
#include "board.h"
|
||||
#include "spi.h"
|
||||
|
||||
|
||||
static uint32_t timer_h = 0; /* 2^(16+32) / 8 MHz = ~1.1 years */
|
||||
|
||||
|
||||
void reset_cpu(void)
|
||||
{
|
||||
WDTCSR = 1 << WDE;
|
||||
}
|
||||
|
||||
|
||||
uint8_t read_irq(void)
|
||||
{
|
||||
return PIN(IRQ_RF);
|
||||
}
|
||||
|
||||
|
||||
void slp_tr(void)
|
||||
{
|
||||
SET(SLP_TR);
|
||||
CLR(SLP_TR);
|
||||
}
|
||||
|
||||
|
||||
void timer_poll(void)
|
||||
{
|
||||
if (!(TIFR1 & (1 << TOV1)))
|
||||
return;
|
||||
TIFR1 = 1 << TOV1;
|
||||
timer_h++;
|
||||
}
|
||||
|
||||
|
||||
uint64_t timer_read(void)
|
||||
{
|
||||
uint32_t high;
|
||||
uint8_t low, mid;
|
||||
|
||||
do {
|
||||
timer_poll();
|
||||
high = timer_h;
|
||||
low = TCNT1L;
|
||||
mid = TCNT1H;
|
||||
}
|
||||
while (TIFR1 & (1 << TOV1));
|
||||
|
||||
/*
|
||||
* We need all these casts because the intermediate results are handled
|
||||
* as if they were signed and thus get sign-expanded. Sounds wrong-ish.
|
||||
*/
|
||||
return (uint64_t) high << 16 | (uint64_t) mid << 8 | (uint64_t) low;
|
||||
}
|
||||
|
||||
|
||||
int gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res)
|
||||
{
|
||||
switch (port) {
|
||||
case 1:
|
||||
DDRB = (DDRB & ~mask) | dir;
|
||||
PORTB = (PORTB & ~mask) | data;
|
||||
break;
|
||||
case 2:
|
||||
DDRC = (DDRC & ~mask) | dir;
|
||||
PORTC = (PORTC & ~mask) | data;
|
||||
break;
|
||||
case 3:
|
||||
DDRD = (DDRD & ~mask) | dir;
|
||||
PORTD = (PORTD & ~mask) | data;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* disable the UART so that we can meddle with these pins as well. */
|
||||
UCSR1B = 0;
|
||||
_delay_ms(1);
|
||||
|
||||
switch (port) {
|
||||
case 1:
|
||||
res[0] = PINB;
|
||||
res[1] = PORTB;
|
||||
res[2] = DDRB;
|
||||
break;
|
||||
case 2:
|
||||
res[0] = PINC;
|
||||
res[1] = PORTC;
|
||||
res[2] = DDRC;
|
||||
break;
|
||||
case 3:
|
||||
res[0] = PIND;
|
||||
res[1] = PORTD;
|
||||
res[2] = DDRD;
|
||||
break;
|
||||
}
|
||||
|
||||
spi_init();
|
||||
|
||||
return 1;
|
||||
}
|
Loading…
Reference in New Issue
Block a user