Date:2011-02-14 16:06:04 (8 years 5 months ago)
Author:Werner Almesberger
Commit:96f0f2cfc912068ccd5752e73481a20d5c27e1d4
Message:atusb/fw2: removed FreakUSB-based firmware

Files: atusb/fw2/Makefile (1 diff)
atusb/fw2/README (1 diff)
atusb/fw2/atusb.c (1 diff)
atusb/fw2/board.c (1 diff)
atusb/fw2/board.h (1 diff)
atusb/fw2/descr.c (1 diff)
atusb/fw2/ep0.c (1 diff)
atusb/fw2/spi.c (1 diff)
atusb/fw2/spi.h (1 diff)
atusb/fw2/usb/patches/cleanup.patch (1 diff)
atusb/fw2/usb/patches/correct-array-size.patch (1 diff)
atusb/fw2/usb/patches/no-cdc.patch (1 diff)
atusb/fw2/usb/patches/no-vbus-detect.patch (1 diff)
atusb/fw2/usb/patches/series (1 diff)
atusb/fw2/usb/patches/support-vendor-requests.patch (1 diff)

Change Details

atusb/fw2/Makefile
1#
2# Makefile - Makefile of the ATUSB firmware
3#
4# Written 2010-2011 by Werner Almesberger
5# Copyright 2010-2011 by 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
13SHELL = /bin/bash
14
15NAME = atusb
16
17CFLAGS = -g -Wall -Wextra -Wshadow -Werror -Wno-unused \
18     -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes
19
20CHIP=atmega32u2
21
22AVR_PREFIX = $(BIN_PATH) avr-
23CC = $(AVR_PREFIX)gcc
24OBJCOPY = $(AVR_PREFIX)objcopy
25#OBJDUMP = $(AVR_PREFIX)objdump
26
27FreakUSB = usb
28USB_OBJS = usb.o ctrl.o usb_buf.o ep.o hw.o isr.o
29OBJS = atusb.o board.o spi.o descr.o ep0.o $(USB_OBJS)
30
31vpath %.c $(FreakUSB)/usb/
32vpath %.c $(FreakUSB)/hw/at90usbxx2/
33
34CFLAGS += -I../fw/include \
35      -I$(FreakUSB)/usb -I$(FreakUSB)/hw/at90usbxx2 \
36      -DNUM_EPS=1
37
38# ----- Verbosity control -----------------------------------------------------
39
40CC_normal := $(CC)
41BUILD_normal :=
42DEPEND_normal := $(CPP) $(CFLAGS) -MM -MG
43
44CC_quiet = @echo " CC " $@ && $(CC_normal)
45BUILD_quiet = @echo " BUILD " $@ && $(BUILD_normal)
46DEPEND_quiet = @$(DEPEND_normal)
47
48ifeq ($(V),1)
49    CC = $(CC_normal)
50    BUILD = $(BUILD_normal)
51    DEPEND = $(DEPEND_normal)
52else
53    CC = $(CC_quiet)
54    BUILD = $(BUILD_quiet)
55    DEPEND = $(DEPEND_quiet)
56endif
57
58# ----- Rules -----------------------------------------------------------------
59
60.PHONY: all clean upload prog
61
62all: $(NAME).bin
63
64$(NAME).elf: $(OBJS)
65        $(CC) $(CFLAGS) -mmcu=$(CHIP) -o $@ $(OBJS)
66
67%.bin: %.elf
68        $(BUILD) $(OBJCOPY) -j .text -j .data -O binary $< $@
69
70# ----- Cleanup ---------------------------------------------------------------
71
72clean:
73        rm -f $(NAME).bin $(NAME).elf $(OBJS) $(OBJS:.o=.d)
74
75# ----- Dependencies ----------------------------------------------------------
76
77%.o: %.c
78        $(CC) $(CFLAGS) -mmcu=$(CHIP) -Os -c $<
79        $(DEPEND) $< | \
80          sed -e \
81            '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \
82            -e '$${g;p;}' -e d >$*.d; \
83          [ "$${PIPESTATUS[*]}" = "0 0" ] || { rm -f $*.d; exit 1; }
84
85-include $(OBJS:.o=.d)
86
87# ----- Programming and device control ----------------------------------------
88
89upload: $(NAME).bin
90        scp $(NAME).bin jlime:
91
92prog:
93        ssh jlime avrdude -F -p $(CHIP) -c nanonote_atusb -e \
94          -U flash:w:$(NAME).bin:r \
95          -U lfuse:w:0x60:m # external clock, slow start-up
96
97on:
98        ssh jlime poke 0x10010318 4
99
100off:
101        ssh jlime poke 0x10010314 4
atusb/fw2/README
1cd usb
2
3wget http://freaklabs.org/freakusb/FreakUSB%20v0.70.zip
4unzip -a FreakUSB?v0.70.zip
5quilt push -a
6
7cd ..
8
9make
10make upload prog
atusb/fw2/atusb.c
1#include <stdint.h>
2
3#include <avr/io.h>
4
5#define F_CPU 8000000UL
6#include <util/delay.h>
7
8#include "freakusb.h"
9
10#include "board.h"
11#include "spi.h"
12#include "atusb/ep0.h"
13
14
15int main(void)
16{
17    board_init();
18    spi_init();
19    reset_rf();
20
21    /* now we should be at 8 MHz */
22
23    led(1);
24    _delay_ms(100);
25    led(0);
26
27    usb_init();
28    ep0_init();
29    hw_init();
30
31    while (1)
32        usb_poll();
33}
atusb/fw2/board.c
1#include <stdint.h>
2
3#include <avr/io.h>
4
5#define F_CPU 8000000UL
6#include <util/delay.h>
7
8#include "at86rf230.h"
9#include "board.h"
10#include "spi.h"
11
12
13static void set_clkm(void)
14{
15    /* switch CLKM to 8 MHz */
16
17    /*
18     * @@@ Note: Atmel advise against changing the external clock in
19     * mid-flight. We should therefore switch to the RC clock first, then
20     * crank up the external clock, and finally switch back to the external
21     * clock. The clock switching procedure is described in the ATmega32U2
22     * data sheet in secton 8.2.2.
23     */
24
25    spi_begin();
26    spi_send(AT86RF230_REG_WRITE | REG_TRX_CTRL_0);
27    spi_send(CLKM_CTRL_8MHz);
28    spi_end();
29}
30
31
32void reset_rf(void)
33{
34    /* AT86RF231 data sheet, 12.4.13, reset pulse width: 625 ns (min) */
35
36    CLR(nRST_RF);
37    _delay_us(1);
38    SET(nRST_RF);
39
40    /* 12.4.14: SPI access latency after reset: 625 ns (min) */
41
42    _delay_us(1);
43
44    /* we must restore TRX_CTRL_0 after each reset (9.6.4) */
45
46    set_clkm();
47}
48
49
50uint8_t read_irq(void)
51{
52    return PIN(IRQ_RF);
53}
54
55
56void led(int on)
57{
58    if (on)
59        SET(LED);
60    else
61        CLR(LED);
62}
63
64
65void board_init(void)
66{
67    /* We start with a 1 MHz/8 clock. Disable the prescaler. */
68
69    CLKPR = 1 << CLKPCE;
70    CLKPR = 0;
71
72    /* set up all the outputs; default port value is 0 */
73
74    OUT(LED);
75    OUT(nRST_RF); /* resets the transceiver */
76    OUT(SLP_TR);
77}
atusb/fw2/board.h
1#ifndef BOARD_H
2#define BOARD_H
3
4#include <stdint.h>
5
6
7#define LED_PORT B
8#define LED_BIT 6
9#define nRST_RF_PORT C
10#define nRST_RF_BIT 7
11#define SLP_TR_PORT B
12#define SLP_TR_BIT 4
13
14#define SCLK_PORT D
15#define SCLK_BIT 5
16#define MOSI_PORT D
17#define MOSI_BIT 3
18
19#define MISO_PORT D
20#define MISO_BIT 2
21#define nSS_PORT D
22#define nSS_BIT 1
23#define IRQ_RF_PORT D
24#define IRQ_RF_BIT 0
25
26
27#define SET_2(p, b) PORT##p |= 1 << (b)
28#define CLR_2(p, b) PORT##p &= ~(1 << (b))
29#define IN_2(p, b) DDR##p &= ~(1 << (b))
30#define OUT_2(p, b) DDR##p |= 1 << (b)
31#define PIN_2(p, b) ((PIN##p >> (b)) & 1)
32
33#define SET_1(p, b) SET_2(p, b)
34#define CLR_1(p, b) CLR_2(p, b)
35#define IN_1(p, b) IN_2(p, b)
36#define OUT_1(p, b) OUT_2(p, b)
37#define PIN_1(p, b) PIN_2(p, b)
38
39#define SET(n) SET_1(n##_PORT, n##_BIT)
40#define CLR(n) CLR_1(n##_PORT, n##_BIT)
41#define IN(n) IN_1(n##_PORT, n##_BIT)
42#define OUT(n) OUT_1(n##_PORT, n##_BIT)
43#define PIN(n) PIN_1(n##_PORT, n##_BIT)
44
45void reset_rf(void);
46uint8_t read_irq(void);
47void led(int on);
48void board_init(void);
49
50#endif /* !BOARD_H */
atusb/fw2/descr.c
1/*
2 * atspi/descr.c - USB descriptors
3 *
4 * Written 2008-2011 by Werner Almesberger
5 * Copyright 2008-2011 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
14#include "freakusb.h"
15#include <avr/pgmspace.h>
16
17
18#if 0
19/* f32xbase/fw/common/usb.h */
20
21#define USB_DT_DEVICE 1
22#define USB_DT_CONFIG 2
23#define USB_DT_STRING 3
24#define USB_DT_INTERFACE 4
25#define USB_DT_ENDPOINT 5
26
27#endif
28
29#define USB_CLASS_VENDOR_SPEC 0xff
30
31#define USB_ATTR_BUS_POWERED 0x80
32
33#define USB_DT_DEVICE DEV_DESCR
34#define USB_DT_CONFIG CFG_DESCR
35#define USB_DT_INTERFACE INTF_DESCR
36#define USB_DT_ENDPOINT EP_DESCR
37
38#define EP0_SIZE MAX_BUF_SZ
39#define EP1_SIZE MAX_BUF_SZ
40#define USB_VENDOR 0x20b7 /* Qi Hardware */
41#define USB_PRODUCT 0x1540 /* ben-wpan atusb */
42
43#define LE(x) ((uint16_t) (x) & 0xff), ((uint16_t) (x) >> 8)
44
45/*
46 * Device descriptor
47 */
48
49uint8_t device_descriptor[18] PROGMEM = {
50    18, /* bLength */
51    USB_DT_DEVICE, /* bDescriptorType */
52    LE(0x200), /* bcdUSB */
53    USB_CLASS_VENDOR_SPEC, /* bDeviceClass */
54    0x00, /* bDeviceSubClass */
55    0x00, /* bDeviceProtocol */
56    EP0_SIZE, /* bMaxPacketSize */
57    LE(USB_VENDOR), /* idVendor */
58    LE(USB_PRODUCT), /* idProduct */
59    LE(0x0001), /* bcdDevice */
60    0, /* iManufacturer */
61    0, /* iProduct */
62    0, /* iSerialNumber */
63    1 /* bNumConfigurations */
64};
65
66
67/*
68 * Our configuration
69 *
70 * We're always bus-powered.
71 */
72
73uint8_t config_descriptor[] PROGMEM = {
74    9, /* bLength */
75    USB_DT_CONFIG, /* bDescriptorType */
76#if 0
77    LE(9+9+7+7), /* wTotalLength */
78#else
79    LE(9+9), /* wTotalLength */
80#endif
81    1, /* bNumInterfaces */
82    1, /* bConfigurationValue (> 0 !) */
83    0, /* iConfiguration */
84    USB_ATTR_BUS_POWERED, /* bmAttributes */
85    50/2, /* bMaxPower (50 mA) */
86
87    /* Interface #0 */
88
89    9, /* bLength */
90    USB_DT_INTERFACE, /* bDescriptorType */
91    0, /* bInterfaceNumber */
92    0, /* bAlternateSetting */
93#if 0
94    2, /* bNumEndpoints */
95#else
96    0,
97#endif
98    USB_CLASS_VENDOR_SPEC, /* bInterfaceClass */
99    0, /* bInterfaceSubClass */
100    0, /* bInterfaceProtocol */
101    0, /* iInterface */
102
103#if 0
104    /* EP OUT */
105
106    7, /* bLength */
107    USB_DT_ENDPOINT, /* bDescriptorType */
108    0x01, /* bEndPointAddress */
109    0x02, /* bmAttributes (bulk) */
110    LE(EP1_SIZE), /* wMaxPacketSize */
111    0, /* bInterval */
112
113    /* EP IN */
114
115    7, /* bLength */
116    USB_DT_ENDPOINT, /* bDescriptorType */
117    0x81, /* bEndPointAddress */
118    0x02, /* bmAttributes (bulk) */
119    LE(EP1_SIZE), /* wMaxPacketSize */
120    0, /* bInterval */
121#endif
122};
123
124
125#define dev_desc device_descriptor
126#define cfg_desc config_descriptor
127
128U8 *desc_dev_get()
129{
130    return dev_desc;
131}
132U8 desc_dev_get_len()
133{
134    return pgm_read_byte(dev_desc);
135}
136U8 *desc_cfg_get()
137{
138    return cfg_desc;
139}
140U8 desc_cfg_get_len()
141{
142    return pgm_read_byte(cfg_desc + 2);
143}
144U8 *desc_dev_qual_get()
145{
146    return NULL;
147}
148U8 desc_dev_qual_get_len()
149{
150    return 0;
151}
152U8 *desc_str_get(U8 index)
153{
154    return NULL;
155}
156U8 desc_str_get_len(U8 index)
157{
158    return 0;
159}
atusb/fw2/ep0.c
1/*
2 * atspi/ep0.c - EP0 extension protocol
3 *
4 * Written 2008-2010 by Werner Almesberger
5 * Copyright 2008-2010 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
14#include <stdint.h>
15
16#include <avr/io.h>
17//#ifndef NULL
18//#define NULL 0
19//#endif
20
21//#include "regs.h"
22//#include "uart.h"
23//#include "usb.h"
24
25#include "freakusb.h"
26
27#include "at86rf230.h"
28#include "atusb/ep0.h"
29//#include "version.h"
30#include "board.h"
31#include "spi.h"
32
33
34#define HW_TYPE HW_TYPE_110131
35static const char *build_date = "today";
36static unsigned build_number = 42;
37
38#define debug(...)
39#define error(...)
40
41
42static const uint8_t id[] = { EP0ATUSB_MAJOR, EP0ATUSB_MINOR, HW_TYPE };
43static uint8_t buf[MAX_PSDU+3]; /* command, PHDR, and LQI */
44static uint8_t size;
45
46
47static void do_buf_write(void *user)
48{
49    uint8_t i;
50
51    spi_begin();
52    for (i = 0; i != size; i++)
53        spi_send(buf[i]);
54    spi_end();
55}
56
57
58static void do_usb_send(const uint8_t *data, int len)
59{
60    int i;
61
62    for (i = 0; i++ != len; data++) {
63        usb_buf_write(EP_CTRL, *data);
64        if (!(i % MAX_BUF_SZ))
65            ep_write(EP_CTRL);
66    }
67    ep_write(EP_CTRL);
68}
69
70
71static void do_usb_recv(uint8_t *data, int len, void (*fn)(void *user),
72    void *user)
73{
74    volatile usb_pcb_t *pcb = usb_pcb_get();
75    uint8_t got;
76
77    /* FreakUSB likes to do things this way. Looks dangerous ... */
78    while (len) {
79        for (got = pcb->fifo[EP_CTRL].len; got; got--) {
80            *data++ = usb_buf_read(EP_CTRL);
81            len--;
82        }
83    }
84    pcb->flags &= ~(1 << SETUP_DATA_AVAIL);
85    fn(user);
86    ep_send_zlp(EP_CTRL);
87}
88
89
90#define usb_send(ep, buf, len, arg1, arg2) do_usb_send(buf, len)
91#define usb_recv(ep, buf, len, fn, user) do_usb_recv(buf, len, fn, user)
92
93
94#define BUILD_OFFSET 7 /* '#' plus "65535" plus ' ' */
95
96
97/* keep things as similar to the original as possible for now */
98#define setup_request req_t
99#define setup req
100#define bmRequestType type
101#define bRequest req
102#define wValue val
103#define wLength len
104#define wIndex idx
105#define __reentrant
106
107
108static int my_setup(struct setup_request *setup) __reentrant
109{
110    unsigned tmp;
111    uint8_t i;
112
113    switch (setup->bmRequestType | setup->bRequest << 8) {
114    case ATUSB_FROM_DEV(ATUSB_ID):
115        debug("ATUSB_ID\n");
116        if (setup->wLength > 3)
117            return 0;
118        usb_send(&ep0, id, setup->wLength, NULL, NULL);
119        return 1;
120    case ATUSB_FROM_DEV(ATUSB_BUILD):
121        debug("ATUSB_BUILD\n");
122        tmp = build_number;
123        for (i = BUILD_OFFSET-2; tmp; i--) {
124            buf[i] = (tmp % 10)+'0';
125            tmp /= 10;
126        }
127        buf[i] = '#';
128        buf[BUILD_OFFSET-1] = ' ';
129        for (size = 0; build_date[size]; size++)
130            buf[BUILD_OFFSET+size] = build_date[size];
131        size += BUILD_OFFSET-i;
132        if (size > setup->wLength)
133            return 0;
134        usb_send(&ep0, buf+i, size, NULL, NULL);
135        return 1;
136
137#ifdef NOTYET
138    case ATUSB_TO_DEV(ATUSB_RESET):
139        debug("ATUSB_RESET\n");
140        RSTSRC = SWRSF;
141        while (1);
142#endif
143
144    case ATUSB_TO_DEV(ATUSB_RF_RESET):
145        debug("ATUSB_RF_RESET\n");
146        reset_rf();
147        ep_send_zlp(EP_CTRL);
148        return 1;
149
150    case ATUSB_FROM_DEV(ATUSB_POLL_INT):
151        debug("ATUSB_POLL_INT\n");
152        if (setup->wLength < 1)
153            return 0;
154        *buf = read_irq();
155        usb_send(&ep0, buf, 1, NULL, NULL);
156        return 1;
157
158    case ATUSB_TO_DEV(ATUSB_REG_WRITE):
159        debug("ATUSB_REG_WRITE\n");
160        spi_begin();
161        spi_send(AT86RF230_REG_WRITE | setup->wIndex);
162        spi_send(setup->wValue);
163        spi_end();
164        ep_send_zlp(EP_CTRL);
165        return 1;
166    case ATUSB_FROM_DEV(ATUSB_REG_READ):
167        debug("ATUSB_REG_READ\n");
168        spi_begin();
169        spi_send(AT86RF230_REG_READ | setup->wIndex);
170        *buf = spi_recv();
171        spi_end();
172        usb_send(&ep0, buf, 1, NULL, NULL);
173        return 1;
174
175    case ATUSB_TO_DEV(ATUSB_BUF_WRITE):
176        debug("ATUSB_BUF_WRITE\n");
177        if (setup->wLength < 1)
178            return 0;
179        if (setup->wLength > MAX_PSDU)
180            return 0;
181        buf[0] = AT86RF230_BUF_WRITE;
182        buf[1] = setup->wLength;
183        size = setup->wLength+2;
184        usb_recv(&ep0, buf+2, setup->wLength, do_buf_write, NULL);
185        return 1;
186    case ATUSB_FROM_DEV(ATUSB_BUF_READ):
187        debug("ATUSB_BUF_READ\n");
188        if (setup->wLength < 2) /* PHR+LQI */
189            return 0;
190        if (setup->wLength > MAX_PSDU+2) /* PHR+PSDU+LQI */
191            return 0;
192        spi_begin();
193        spi_send(AT86RF230_BUF_READ);
194        size = spi_recv();
195        if (size >= setup->wLength)
196            size = setup->wLength-1;
197        for (i = 0; i != size+1; i++)
198            buf[i] = spi_recv();
199        spi_end();
200        usb_send(&ep0, buf, size+1, NULL, NULL);
201        return 1;
202
203    case ATUSB_TO_DEV(ATUSB_SRAM_WRITE):
204        debug("ATUSB_SRAM_WRITE\n");
205        if (setup->wIndex > SRAM_SIZE)
206            return 0;
207        if (setup->wIndex+setup->wLength > SRAM_SIZE)
208            return 0;
209        buf[0] = AT86RF230_SRAM_WRITE;
210        buf[1] = setup->wIndex;
211        size = setup->wLength+2;
212        usb_recv(&ep0, buf+2, setup->wLength, do_buf_write, NULL);
213        return 1;
214    case ATUSB_TO_DEV(ATUSB_SRAM_READ):
215        debug("ATUSB_SRAM_READ\n");
216        if (setup->wIndex > SRAM_SIZE)
217            return 0;
218        if (setup->wIndex+setup->wLength > SRAM_SIZE)
219            return 0;
220        spi_begin();
221        spi_send(AT86RF230_SRAM_READ);
222        spi_send(setup->wIndex);
223        for (i = 0; i != size; i++)
224            buf[i] = spi_recv();
225        spi_end();
226        usb_send(&ep0, buf, size, NULL, NULL);
227        return 1;
228
229    default:
230        error("Unrecognized SETUP: 0x%02x 0x%02x ...\n",
231            setup->bmRequestType, setup->bRequest);
232        return 0;
233    }
234}
235
236
237static void class_init(void)
238{
239}
240
241
242static void req_handler(req_t *req)
243{
244    if (!my_setup(req))
245        ep_set_stall(EP_CTRL);
246}
247
248
249static void rx_handler(void)
250{
251}
252
253
254void ep0_init(void)
255{
256        usb_reg_class_drvr(class_init, req_handler, rx_handler);
257}
atusb/fw2/spi.c
1#include <stdint.h>
2
3#include <avr/io.h>
4
5#include "board.h"
6#include "spi.h"
7
8
9void spi_begin(void)
10{
11    CLR(nSS);
12}
13
14
15uint8_t spi_io(uint8_t v)
16{
17// while (!(UCSR1A & 1 << UDRE1));
18        UDR1 = v;
19        while (!(UCSR1A & 1 << RXC1));
20        return UDR1;
21}
22
23
24void spi_end(void)
25{
26// while (!(UCSR1A & 1 << TXC1));
27    SET(nSS);
28}
29
30
31void spi_init(void)
32{
33    SET(nSS);
34    OUT(SCLK);
35    OUT(MOSI);
36    OUT(nSS);
37    IN(MISO);
38
39    UBRR1 = 0; /* set bit rate to zero to begin */
40    UCSR1C = 1 << UMSEL11 | 1 << UMSEL10;
41            /* set MSPI, MSB first, SPI data mode 0 */
42    UCSR1B = 1 << RXEN1 | 1 << TXEN1;
43            /* enable receiver and transmitter */
44    UBRR1 = 0; /* reconfirm the bit rate */
45}
atusb/fw2/spi.h
1#ifndef SPI_H
2#define SPI_H
3
4#include <stdint.h>
5
6
7void spi_begin(void);
8uint8_t spi_io(uint8_t v);
9void spi_end(void);
10void spi_init(void);
11
12#define spi_send(v) (void) spi_io(v)
13#define spi_recv(v) spi_io(0)
14
15#endif /* !SPI_H */
atusb/fw2/usb/patches/cleanup.patch
1Index: fw4/hw/at90usbxx2/ep.c
2===================================================================
3+++ fw4/hw/at90usbxx2/ep.c 2011-02-08 17:13:46.000000000 -0300
4@@ -56,7 +56,7 @@
5     Get the max packet size of the endpoint.
6 */
7 /**************************************************************************/
8-U8 ep_size_get()
9+static U8 ep_size_get(void)
10 {
11     U8 tmp = (UECFG1X &= (7<<EPSIZE0));
12     tmp >>= EPSIZE0;
13@@ -68,7 +68,7 @@
14     Get the direction of the endpoint.
15 */
16 /**************************************************************************/
17-U8 ep_dir_get()
18+static U8 ep_dir_get(void)
19 {
20     return (UECFG0X & 0x1);
21 }
22@@ -78,7 +78,7 @@
23     Get the endpoint type: BULK, CONTROL, INTERRUPT, ISOCHRONOUS
24 */
25 /**************************************************************************/
26-U8 ep_type_get()
27+static U8 ep_type_get(void)
28 {
29     return ((UECFG0X & (0x3 << EPTYPE0)) >> EPTYPE0);
30 }
31@@ -88,8 +88,9 @@
32     Clear the endpoint configuration registers
33 */
34 /**************************************************************************/
35-void ep_cfg_clear()
36+static void ep_cfg_clear(U8 ep_num)
37 {
38+ ep_select(ep_num);
39     UECFG0X = 0;
40     UECFG1X = 0;
41 }
42@@ -99,8 +100,9 @@
43     Clear the specified endpoint's enable bit.
44 */
45 /**************************************************************************/
46-void ep_disable()
47+static void ep_disable(U8 ep_num)
48 {
49+ ep_select(ep_num);
50     UECONX &= ~(1 << EPEN);
51 }
52
53@@ -279,7 +281,7 @@
54     Clear all endpoints and initialize ep0 for control transfers.
55 */
56 /**************************************************************************/
57-void ep_init()
58+void ep_init(void)
59 {
60     U8 i;
61
62@@ -328,7 +330,7 @@
63     Return the ep where an intp occurred. If no intp occurred, then return 0xff.
64 */
65 /**************************************************************************/
66-U8 ep_intp_get_num()
67+U8 ep_intp_get_num(void)
68 {
69     U8 i;
70
71@@ -348,7 +350,7 @@
72     is found, return 0xFF.
73 */
74 /**************************************************************************/
75-U8 ep_intp_get_src()
76+U8 ep_intp_get_src(void)
77 {
78     U8 i;
79
80Index: fw4/hw/at90usbxx2/hw.c
81===================================================================
82+++ fw4/hw/at90usbxx2/hw.c 2011-02-08 17:13:46.000000000 -0300
83@@ -53,7 +53,7 @@
84     4) Enable the global interrupt.
85 */
86 /**************************************************************************/
87-void hw_init()
88+void hw_init(void)
89 {
90     usb_pcb_t *pcb = usb_pcb_get();
91
92@@ -126,7 +126,7 @@
93     Disable global interrupts
94 */
95 /**************************************************************************/
96-void hw_intp_disable()
97+void hw_intp_disable(void)
98 {
99     cli();
100 }
101@@ -136,7 +136,7 @@
102     Enable global interrupts
103 */
104 /**************************************************************************/
105-void hw_intp_enable()
106+void hw_intp_enable(void)
107 {
108     sei();
109 }
110Index: fw4/hw/at90usbxx2/hw.h
111===================================================================
112+++ fw4/hw/at90usbxx2/hw.h 2011-02-08 17:13:46.000000000 -0300
113@@ -38,9 +38,9 @@
114 #ifndef HW_H
115 #define HW_H
116
117-void hw_init();
118-void hw_intp_disable();
119-void hw_intp_enable();
120+void hw_init(void);
121+void hw_intp_disable(void);
122+void hw_intp_enable(void);
123 U8 hw_flash_get_byte(U8 *addr);
124
125 #endif
126Index: fw4/usb/ctrl.c
127===================================================================
128+++ fw4/usb/ctrl.c 2011-02-08 17:14:46.000000000 -0300
129@@ -48,7 +48,7 @@
130     returning the relevant descriptor stored in flash.
131 */
132 /**************************************************************************/
133-void ctrl_get_desc(req_t *req)
134+static void ctrl_get_desc(req_t *req)
135 {
136     U8 i = 0, desc_len = 0, desc_type, desc_idx;
137     U8 *desc = NULL;
138@@ -117,7 +117,7 @@
139     Return the device configuration number to the host.
140 */
141 /**************************************************************************/
142-void ctrl_get_config()
143+static void ctrl_get_config(void)
144 {
145     usb_pcb_t *pcb = usb_pcb_get();
146
147@@ -130,7 +130,7 @@
148     Return the status of the device or endpoint to the host.
149 */
150 /**************************************************************************/
151-void ctrl_get_status(req_t *req)
152+static void ctrl_get_status(req_t *req)
153 {
154     U8 i, rem_wake_enb = 0;
155     U8 status[2];
156@@ -174,7 +174,7 @@
157     which will setup the endpoints according to the device class.
158 */
159 /**************************************************************************/
160-void ctrl_set_config(req_t *req)
161+static void ctrl_set_config(req_t *req)
162 {
163     usb_pcb_t *pcb;
164
165@@ -201,7 +201,7 @@
166     stall the specified endpoint.
167 */
168 /**************************************************************************/
169-void ctrl_set_feat(req_t *req)
170+static void ctrl_set_feat(req_t *req)
171 {
172     usb_pcb_t *pcb = usb_pcb_get();
173
174@@ -230,7 +230,7 @@
175     don't do anything with the flag.
176 */
177 /**************************************************************************/
178-void ctrl_clear_feat(req_t *req)
179+static void ctrl_clear_feat(req_t *req)
180 {
181     usb_pcb_t *pcb = usb_pcb_get();
182
183@@ -261,7 +261,7 @@
184     then we'll stall the endpoint.
185 */
186 /**************************************************************************/
187-void ctrl_handler()
188+void ctrl_handler(void)
189 {
190     usb_pcb_t *pcb = usb_pcb_get();
191     U8 i, req[CTRL_IN_REQ_SZ];
192Index: fw4/usb/freakusb.h
193===================================================================
194+++ fw4/usb/freakusb.h 2011-02-08 17:13:46.000000000 -0300
195@@ -213,35 +213,35 @@
196     U8 pending_data;
197     U8 test;
198     usb_buffer_t fifo[NUM_EPS];
199- void (*class_init)();
200+ void (*class_init)(void);
201     void (*class_req_handler)(req_t *req);
202- void (*class_rx_handler)();
203+ void (*class_rx_handler)(void);
204 } usb_pcb_t;
205
206 // prototypes
207
208 // usb.c
209-void usb_init();
210-usb_pcb_t *usb_pcb_get();
211-void usb_reg_class_drvr(void (*class_cfg_init)(),
212- void (*class_req_handler)(),
213- void (*class_rx_handler)());
214-void usb_poll();
215-bool usb_ready();
216+void usb_init(void);
217+usb_pcb_t *usb_pcb_get(void);
218+void usb_reg_class_drvr(void (*class_cfg_init)(void),
219+ void (*class_req_handler)(req_t *req),
220+ void (*class_rx_handler)(void));
221+void usb_poll(void);
222+bool usb_ready(void);
223
224 // req.c
225-void ctrl_handler();
226+void ctrl_handler(void);
227
228 // ep.c
229-void ep_init();
230+void ep_init(void);
231 void ep_select(U8 ep_num);
232 void ep_write_from_flash(U8 ep_num, U8 *data, U8 len);
233 void ep_write(U8 ep_num);
234 void ep_write_ctrl(U8 *data, U8 len, bool read_from_flash);
235 void ep_read(U8 ep_num);
236 void ep_set_addr(U8 addr);
237-U8 ep_intp_get_num();
238-U8 ep_intp_get_src();
239+U8 ep_intp_get_num(void);
240+U8 ep_intp_get_src(void);
241 void ep_set_stall(U8 ep_num);
242 void ep_clear_stall(U8 ep_num);
243 void ep_reset_toggle(U8 ep_num);
244@@ -250,12 +250,12 @@
245 void ep_drain_fifo(U8 ep);
246
247 // desc.c
248-U8 *desc_dev_get();
249-U8 desc_dev_get_len();
250-U8 *desc_cfg_get();
251-U8 desc_cfg_get_len();
252-U8 *desc_dev_qual_get();
253-U8 desc_dev_qual_get_len();
254+U8 *desc_dev_get(void);
255+U8 desc_dev_get_len(void);
256+U8 *desc_cfg_get(void);
257+U8 desc_cfg_get_len(void);
258+U8 *desc_dev_qual_get(void);
259+U8 desc_dev_qual_get_len(void);
260 U8 *desc_str_get(U8 index);
261 U8 desc_str_get_len(U8 index);
262
263Index: fw4/usb/usb.c
264===================================================================
265+++ fw4/usb/usb.c 2011-02-08 17:13:46.000000000 -0300
266@@ -47,7 +47,7 @@
267     block for now.
268 */
269 /**************************************************************************/
270-void usb_init()
271+void usb_init(void)
272 {
273     memset(&pcb, 0, sizeof(usb_pcb_t));
274 }
275@@ -57,7 +57,7 @@
276     Get a pointer to the USB stack's protocol control block.
277 */
278 /**************************************************************************/
279-usb_pcb_t *usb_pcb_get()
280+usb_pcb_t *usb_pcb_get(void)
281 {
282     return &pcb;
283 }
284@@ -67,9 +67,9 @@
285     Register the class driver
286 */
287 /**************************************************************************/
288-void usb_reg_class_drvr(void (*class_init)(),
289+void usb_reg_class_drvr(void (*class_init)(void),
290                         void (*class_req_handler)(req_t *req),
291- void (*class_rx_handler)())
292+ void (*class_rx_handler)(void))
293 {
294     pcb.class_req_handler = class_req_handler;
295     pcb.class_init = class_init;
296@@ -83,7 +83,7 @@
297     there are any pending CONTROL transfers.
298 */
299 /**************************************************************************/
300-void usb_poll()
301+void usb_poll(void)
302 {
303     U8 i, ep_num;
304
305Index: fw4/hw/at90usbxx2/isr.c
306===================================================================
307+++ fw4/hw/at90usbxx2/isr.c 2011-02-08 17:13:46.000000000 -0300
308@@ -44,7 +44,7 @@
309     Clear all USB related interrupts.
310 */
311 /**************************************************************************/
312-void intp_clear_all()
313+static void intp_clear_all(void)
314 {
315     U8 i;
316
317@@ -62,7 +62,7 @@
318     Suspend interrupt handler.
319 */
320 /**************************************************************************/
321-void intp_suspend()
322+static void intp_suspend(void)
323 {
324     SUSP_INT_CLR();
325     WAKEUP_INT_ENB();
326@@ -77,7 +77,7 @@
327     Resume interrupt handler.
328 */
329 /**************************************************************************/
330-void intp_resume()
331+static void intp_resume(void)
332 {
333     WAKEUP_INT_DIS();
334     RESM_INT_CLR();
335@@ -89,7 +89,7 @@
336     Wakeup interrupt handler.
337 */
338 /**************************************************************************/
339-void intp_wakeup()
340+static void intp_wakeup(void)
341 {
342     // unfreeze the clock
343     USBCON &= ~(1 << FRZCLK);
344@@ -106,7 +106,7 @@
345     End of Reset interrupt handler. Gets triggered at the end of a bus reset.
346 */
347 /**************************************************************************/
348-void intp_eor()
349+static void intp_eor(void)
350 {
351     EOR_INT_CLR();
352     ep_init();
353Index: fw4/class/CDC/cdc.c
354===================================================================
355+++ fw4/class/CDC/cdc.c 2011-02-08 17:18:59.000000000 -0300
356@@ -63,7 +63,7 @@
357
358 // this is the rx handler callback function. it gets registered by the application program
359 // and will handle any incoming data.
360-static void (*rx_handler)();
361+static void (*rx_handler)(void);
362
363 /**************************************************************************/
364 /*!
365@@ -139,7 +139,7 @@
366     virtual COM data.
367 */
368 /**************************************************************************/
369-void cdc_rx_handler()
370+void cdc_rx_handler(void)
371 {
372     if (rx_handler)
373     {
374@@ -154,7 +154,7 @@
375     usually set this after the host issues the set_configuration request.
376 */
377 /**************************************************************************/
378-void cdc_ep_init()
379+void cdc_ep_init(void)
380 {
381     // setup the endpoints
382     ep_config(EP_1, BULK, DIR_IN, MAX_PACKET_SZ);
383@@ -168,7 +168,7 @@
384     function here since the CDC doesn't know what to do with received data.
385 */
386 /**************************************************************************/
387-void cdc_reg_rx_handler(void (*rx)())
388+void cdc_reg_rx_handler(void (*rx)(void))
389 {
390     if (rx)
391     {
392@@ -212,7 +212,7 @@
393     and rx data handler with the USB core.
394 */
395 /**************************************************************************/
396-void cdc_init()
397+void cdc_init(void)
398 {
399     // hook the putchar function into the printf stdout filestream. This is needed
400     // for printf to work.
atusb/fw2/usb/patches/correct-array-size.patch
1Index: usb/usb/ctrl.c
2===================================================================
3+++ usb/usb/ctrl.c 2011-02-08 23:13:18.000000000 -0300
4@@ -136,7 +136,7 @@
5     U8 status[2];
6     usb_pcb_t *pcb = usb_pcb_get();
7
8- memset(status, 0, 2 * sizeof(status));
9+ memset(status, 0, sizeof(status));
10     switch (req->type)
11     {
12     case GET_DEVICE_STATUS:
atusb/fw2/usb/patches/no-cdc.patch
1Index: fw4/usb/freakusb.h
2===================================================================
3+++ fw4/usb/freakusb.h 2011-02-08 16:40:15.000000000 -0300
4@@ -43,9 +43,6 @@
5 #include <stdio.h>
6 #include "types.h"
7
8-// class specific
9-#include "cdc.h"
10-
11 // hw specific
12 #include "hw.h"
13
atusb/fw2/usb/patches/no-vbus-detect.patch
1Index: fw4/hw/at90usbxx2/at90usb.h
2===================================================================
3+++ fw4/hw/at90usbxx2/at90usb.h 2011-02-08 15:59:22.000000000 -0300
4@@ -42,14 +42,6 @@
5
6 #define AT90USB16
7
8-#define VBUS_SENSE_DDR DDRB
9-#define VBUS_SENSE_PORT PORTB
10-#define VBUS_SENSE_PIN PINB
11-#define VBUS_SENSE_IO 5
12-
13-// test if vbus is present
14-#define is_vbus_on() ((VBUS_SENSE_PIN & (1<<VBUS_SENSE_IO)) != 0)
15-
16 // banks
17 #define SINGLE 0
18 #define DUAL 1
19Index: fw4/hw/at90usbxx2/hw.c
20===================================================================
21+++ fw4/hw/at90usbxx2/hw.c 2011-02-08 16:00:31.000000000 -0300
22@@ -85,26 +85,14 @@
23     // set the interrupts: vbus, suspend, and end of reset
24     UDIEN |= (_BV(SUSPE) | _BV(EORSTE));
25
26- // enable vbus sense pin
27- VBUS_SENSE_DDR &= ~_BV(VBUS_SENSE_IO);
28- VBUS_SENSE_PORT &= ~_BV(VBUS_SENSE_IO);
29-
30- // enable the vbus sense interrupt
31- PCICR |= _BV(PCIE0);
32- PCMSK0 |= _BV(PCINT5);
33-
34- // do an initial check to see if bus power is available. we
35- // need this because we'll miss the first transition to vbus on
36- if (is_vbus_on())
37- {
38- pcb->connected = true;
39+ /* we're bus-powered, so VBUS is on by definition */
40+ pcb->connected = true;
41
42- // attach USB
43- UDCON &= ~_BV(DETACH);
44+ // attach USB
45+ UDCON &= ~_BV(DETACH);
46
47- // reset CPU
48- //UDCON |= _BV(RSTCPU);
49- }
50+ // reset CPU
51+ //UDCON |= _BV(RSTCPU);
52
53     // turn on the global interrupts
54     sei();
55Index: fw4/hw/at90usbxx2/isr.c
56===================================================================
57+++ fw4/hw/at90usbxx2/isr.c 2011-02-08 16:00:56.000000000 -0300
58@@ -249,60 +249,3 @@
59
60     sei();
61 }
62-
63-/**************************************************************************/
64-/*!
65- This ISR is only for the AT90USB16 since we need to use an IO as the VBUS sense
66-*/
67-/**************************************************************************/
68-ISR(PCINT0_vect)
69-{
70- usb_pcb_t *pcb = usb_pcb_get();
71-
72- cli();
73-
74- if (is_vbus_on())
75- {
76- pcb->connected = true;
77-
78- // enable the 3.3V regulator for the USB pads
79- REGCR &= ~_BV(REGDIS);
80-
81- // freeze the clock
82- USBCON |= _BV(FRZCLK);
83-
84- // enable the 48 MHz PLL
85- PLLCSR &= ~(_BV(PLLP2) | _BV(PLLP1) | _BV(PLLP0));
86- PLLCSR |= _BV(1<<PLLE);
87-
88- // busy wait until the PLL is locked
89- while (!(PLLCSR & _BV(PLOCK)));
90-
91- // unfreeze clock
92- USBCON &= ~_BV(FRZCLK);
93-
94- // attach USB
95- UDCON &= ~_BV(DETACH);
96-
97- // reset CPU
98- UDCON |= _BV(RSTCPU);
99- }
100- else
101- {
102- // if we're connected, but VBUS is gone, then detach
103-
104- // detach from the bus
105- UDCON |= _BV(DETACH);
106-
107- // freeze the clock and turn off the USB PLL
108- USBCON |= _BV(FRZCLK);
109- PLLCSR &= ~_BV(PLLE);
110-
111- // disable the USB voltage regulator
112- REGCR |= _BV(REGDIS);
113-
114- pcb->connected = false;
115- pcb->flags = 0;
116- }
117- sei();
118-}
atusb/fw2/usb/patches/series
1cleanup.patch
2no-cdc.patch
3no-vbus-detect.patch
4correct-array-size.patch
5support-vendor-requests.patch
atusb/fw2/usb/patches/support-vendor-requests.patch
1Index: fw4/class/CDC/cdc.c
2===================================================================
3+++ fw4/class/CDC/cdc.c 2011-02-08 17:12:30.000000000 -0300
4@@ -76,7 +76,10 @@
5 {
6     U8 i;
7     usb_pcb_t *pcb = usb_pcb_get();
8-
9+
10+ if (req->type & TYPE_CLASS)
11+ goto reject;
12+
13     switch (req->req)
14     {
15     case GET_LINE_CODING:
16@@ -127,6 +130,7 @@
17         break;
18
19     default:
20+ reject:
21         ep_set_stall(EP_CTRL);
22         break;
23     }
24Index: fw4/usb/ctrl.c
25===================================================================
26+++ fw4/usb/ctrl.c 2011-02-08 17:12:51.000000000 -0300
27@@ -277,7 +277,7 @@
28     reqp = (req_t *)req;
29
30     // decode the standard request
31- if (!(reqp->type & TYPE_CLASS))
32+ if (!(reqp->type & (TYPE_CLASS | TYPE_VENDOR)))
33     {
34         // this is a standard request
35         switch (reqp->req)

Archive Download the corresponding diff file



interactive