Date:2013-03-29 23:14:11 (10 years 11 months ago)
Author:Werner Almesberger
Commit:a8db238cbb1cd9796c2d5d44988cb35a8e9d2889
Message:atusb/fw/: convert functions returning "int" to "bool"

Firmware size is down from 5612 to 3590 bytes. Wow !
Files: atusb/fw/board.h (3 diffs)
atusb/fw/board_app.c (3 diffs)
atusb/fw/ep0.c (4 diffs)
atusb/fw/flash.c (3 diffs)
atusb/fw/mac.c (2 diffs)
atusb/fw/mac.h (1 diff)
atusb/fw/sernum.c (3 diffs)
atusb/fw/sernum.h (3 diffs)
atusb/fw/spi.c (3 diffs)
atusb/fw/usb/atu2.c (5 diffs)
atusb/fw/usb/dfu.c (6 diffs)
atusb/fw/usb/dfu.h (3 diffs)
atusb/fw/usb/dfu_common.c (4 diffs)
atusb/fw/usb/usb.c (5 diffs)
atusb/fw/usb/usb.h (4 diffs)

Change Details

atusb/fw/board.h
11/*
22 * fw/board.h - Board-specific functions and definitions
33 *
4 * Written 2008-2011 by Werner Almesberger
5 * Copyright 2008-2011 Werner Almesberger
4 * Written 2008-2011, 2013 by Werner Almesberger
5 * Copyright 2008-2011, 2013 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1313#ifndef BOARD_H
1414#define BOARD_H
1515
16#include <stdbool.h>
1617#include <stdint.h>
1718
1819
...... 
8788uint64_t timer_read(void);
8889void timer_init(void);
8990
90int gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res);
91bool gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res);
9192void gpio_cleanup(void);
9293
9394void board_init(void);
atusb/fw/board_app.c
11/*
22 * fw/board_app.c - Board-specific functions (for the application)
33 *
4 * Written 2011 by Werner Almesberger
5 * Copyright 2011 Werner Almesberger
4 * Written 2011, 2013 by Werner Almesberger
5 * Copyright 2011, 2013 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1212
1313
1414#include <stddef.h>
15#include <stdbool.h>
1516#include <stdint.h>
1617
1718#include <avr/io.h>
...... 
9293}
9394
9495
95int gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res)
96bool gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res)
9697{
9798    EIMSK = 0; /* recover INT_RF to ATUSB_GPIO_CLEANUP or an MCU reset */
9899
atusb/fw/ep0.c
11/*
22 * fw/ep0.c - EP0 extension protocol
33 *
4 * Written 2008-2011 by Werner Almesberger
5 * Copyright 2008-2011 Werner Almesberger
4 * Written 2008-2011, 2013 by Werner Almesberger
5 * Copyright 2008-2011, 2013 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1111 */
1212
1313
14#include <stdbool.h>
1415#include <stdint.h>
1516#include <string.h>
1617
...... 
5758#define BUILD_OFFSET 7 /* '#' plus "65535" plus ' ' */
5859
5960
60static int my_setup(const struct setup_request *setup)
61static bool my_setup(const struct setup_request *setup)
6162{
6263    uint16_t req = setup->bmRequestType | setup->bRequest << 8;
6364    unsigned tmp;
...... 
254255}
255256
256257
257static int my_dfu_setup(const struct setup_request *setup)
258static bool my_dfu_setup(const struct setup_request *setup)
258259{
259260    switch (setup->bmRequestType | setup->bRequest << 8) {
260261    case DFU_TO_DEV(DFU_DETACH):
atusb/fw/flash.c
11/*
22 * fw/flash.c - Board-specific flash functions
33 *
4 * Written 2011 by Werner Almesberger
5 * Copyright 2011 Werner Almesberger
4 * Written 2011, 2013 by Werner Almesberger
5 * Copyright 2011, 2013 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1111 */
1212
1313
14#include <stdbool.h>
1415#include <stdint.h>
1516
1617#include <avr/boot.h>
...... 
2930}
3031
3132
32int flash_can_write(uint16_t size)
33bool flash_can_write(uint16_t size)
3334{
3435    return payload+size <= BOOT_ADDR;
3536}
atusb/fw/mac.c
118118}
119119
120120
121int mac_rx(int on)
121bool mac_rx(int on)
122122{
123123    if (on) {
124124        mac_irq = handle_irq;
...... 
178178}
179179
180180
181int mac_tx(uint16_t flags, uint16_t len)
181bool mac_tx(uint16_t flags, uint16_t len)
182182{
183183    if (len > MAX_PSDU)
184184        return 0;
atusb/fw/mac.h
1313#ifndef MAC_H
1414#define MAC_H
1515
16#include <stdbool.h>
1617#include <stdint.h>
1718
1819
1920extern int (*mac_irq)(void);
2021
21int mac_rx(int on);
22int mac_tx(uint16_t flags, uint16_t len);
22bool mac_rx(int on);
23bool mac_tx(uint16_t flags, uint16_t len);
2324void mac_reset(void);
2425
2526#endif /* !MAC_H */
atusb/fw/sernum.c
11/*
22 * fw/sernum.c - ATUSB serial number
33 *
4 * Written 2008-2011 by Werner Almesberger
5 * Copyright 2008-2011 Werner Almesberger
4 * Written 2008-2011, 2013 by Werner Almesberger
5 * Copyright 2008-2011, 2013 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1111 */
1212
1313
14#include <stdbool.h>
1415#include <stdint.h>
1516
1617#include "usb.h"
...... 
2627};
2728
2829
29int sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply,
30bool sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply,
3031    uint8_t *size)
3132{
3233    if (type != USB_DT_STRING)
atusb/fw/sernum.h
11/*
22 * fw/sernum.h - ATUSB serial number
33 *
4 * Written 2011 by Werner Almesberger
5 * Copyright 2011 Werner Almesberger
4 * Written 2011, 2013 by Werner Almesberger
5 * Copyright 2011, 2013 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1313#ifndef SERNUM_H
1414#define SERNUM_H
1515
16#include <stdbool.h>
1617#include <stdint.h>
1718
1819#include "board.h"
...... 
2021
2122#ifdef HAS_BOARD_SERNUM
2223
23int sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply,
24bool sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply,
2425    uint8_t *size);
2526
2627#else /* HAS_BOARD_SERNUM */
2728
28static inline int sernum_get_descr(uint8_t type, uint8_t index,
29static inline bool sernum_get_descr(uint8_t type, uint8_t index,
2930    const uint8_t **reply, uint8_t *size)
3031{
3132    return 0;
atusb/fw/spi.c
11/*
22 * fw/spi.c - ATmega8 family SPI I/O
33 *
4 * Written 2011 by Werner Almesberger
5 * Copyright 2011 Werner Almesberger
4 * Written 2011, 2013 by Werner Almesberger
5 * Copyright 2011, 2013 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1111 */
1212
1313
14#include <stdbool.h>
1415#include <stdint.h>
1516
1617#include <avr/io.h>
...... 
1920#include "spi.h"
2021
2122
22static int spi_initialized = 0;
23static bool spi_initialized = 0;
2324
2425
2526void spi_begin(void)
atusb/fw/usb/atu2.c
11/*
22 * fw/usb/atu2.c - Chip-specific driver for Atmel ATxxxU2 USB chips
33 *
4 * Written 2008-2011 by Werner Almesberger
5 * Copyright 2008-2011 Werner Almesberger
4 * Written 2008-2011, 2013 by Werner Almesberger
5 * Copyright 2008-2011, 2013 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1818 * - enumeration often encounters an error -71 (from which it recovers)
1919 */
2020
21#include <stdbool.h>
2122#include <stdint.h>
2223
2324#define F_CPU 8000000UL
...... 
5960}
6061
6162
62int set_addr(uint8_t addr)
63void set_addr(uint8_t addr)
6364{
6465    UDADDR = addr;
6566    usb_send(&eps[0], NULL, 0, enable_addr, NULL);
66    return 1;
6767}
6868
6969
...... 
7676}
7777
7878
79static int ep_setup(void)
79static bool ep_setup(void)
8080{
8181    struct setup_request setup;
8282
...... 
9696}
9797
9898
99static int ep_rx(struct ep_descr *ep)
99static bool ep_rx(struct ep_descr *ep)
100100{
101101    uint8_t size;
102102
atusb/fw/usb/dfu.c
11/*
22 * boot/dfu.c - DFU protocol engine
33 *
4 * Written 2008-2011 by Werner Almesberger
5 * Copyright 2008-2011 Werner Almesberger
4 * Written 2008-2011, 2013 by Werner Almesberger
5 * Copyright 2008-2011, 2013 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
2525 */
2626
2727
28#include <stdbool.h>
2829#include <stdint.h>
2930
3031#include "usb.h"
...... 
8182
8283
8384static uint16_t next_block = 0;
84static int did_download;
85static bool did_download;
8586
8687
8788static uint8_t buf[EP0_SIZE];
...... 
9596}
9697
9798
98static int block_receive(uint16_t length)
99static bool block_receive(uint16_t length)
99100{
100101    static uint16_t size;
101102
...... 
115116}
116117
117118
118static int block_transmit(uint16_t length)
119static bool block_transmit(uint16_t length)
119120{
120121    uint16_t got;
121122
...... 
134135}
135136
136137
137static int my_setup(const struct setup_request *setup)
138static bool my_setup(const struct setup_request *setup)
138139{
139    int ok;
140    bool ok;
140141
141142    switch (setup->bmRequestType | setup->bRequest << 8) {
142143    case DFU_TO_DEV(DFU_DETACH):
atusb/fw/usb/dfu.h
11/*
22 * boot/dfu.h - DFU protocol constants and data structures
33 *
4 * Written 2008, 2011 by Werner Almesberger
5 * Copyright 2008, 2011 Werner Almesberger
4 * Written 2008, 2011, 2013 by Werner Almesberger
5 * Copyright 2008, 2011, 2013 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1414#ifndef DFU_H
1515#define DFU_H
1616
17#include <stdbool.h>
1718#include <stdint.h>
1819
1920#include "usb.h"
...... 
101102
102103
103104void flash_start(void);
104int flash_can_write(uint16_t size);
105bool flash_can_write(uint16_t size);
105106void flash_write(const uint8_t *buf, uint16_t size);
106107void flash_end_write(void);
107108uint16_t flash_read(uint8_t *buf, uint16_t size);
108109
109int dfu_setup_common(const struct setup_request *setup);
110int dfu_my_descr(uint8_t type, uint8_t index, const uint8_t **reply,
110bool dfu_setup_common(const struct setup_request *setup);
111bool dfu_my_descr(uint8_t type, uint8_t index, const uint8_t **reply,
111112    uint8_t *size);
112113
113114void dfu_init(void);
atusb/fw/usb/dfu_common.c
11/*
22 * boot/dfu_common.c - DFU protocol engine parts common to App/DFU
33 *
4 * Written 2008-2011 by Werner Almesberger
5 * Copyright 2008-2011 Werner Almesberger
4 * Written 2008-2011, 2013 by Werner Almesberger
5 * Copyright 2008-2011, 2013 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
2525 */
2626
2727
28#include <stdbool.h>
2829#include <stdint.h>
2930
3031#include "usb.h"
...... 
6566};
6667
6768
68int dfu_setup_common(const struct setup_request *setup)
69bool dfu_setup_common(const struct setup_request *setup)
6970{
7071    switch (setup->bmRequestType | setup->bRequest << 8) {
7172    case DFU_FROM_DEV(DFU_GETSTATUS):
...... 
8990}
9091
9192
92int dfu_my_descr(uint8_t type, uint8_t index, const uint8_t **reply,
93bool dfu_my_descr(uint8_t type, uint8_t index, const uint8_t **reply,
9394    uint8_t *size)
9495{
9596    if (type != DFU_DT_FUNCTIONAL)
atusb/fw/usb/usb.c
11/*
22 * fw/usb/usb.c - USB hardware setup and standard device requests
33 *
4 * Written 2008-2011 by Werner Almesberger
5 * Copyright 2008-2011 Werner Almesberger
4 * Written 2008-2011, 2013 by Werner Almesberger
5 * Copyright 2008-2011, 2013 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1616 * - should support EP clearing and stalling
1717 */
1818
19#include <stdbool.h>
1920#include <stdint.h>
2021
2122#include "usb.h"
...... 
3334#define BUG_ON(cond)
3435#endif
3536
36int (*user_setup)(const struct setup_request *setup);
37bool (*user_setup)(const struct setup_request *setup);
3738void (*user_set_interface)(int nth);
38int (*user_get_descriptor)(uint8_t type, uint8_t index,
39bool (*user_get_descriptor)(uint8_t type, uint8_t index,
3940    const uint8_t **reply, uint8_t *size);
4041void (*user_reset)(void);
4142
...... 
5354}
5455
5556
56static int get_descriptor(uint8_t type, uint8_t index, uint16_t length)
57static bool get_descriptor(uint8_t type, uint8_t index, uint16_t length)
5758{
5859    const uint8_t *reply;
5960    uint8_t size;
...... 
8283}
8384
8485
85int handle_setup(const struct setup_request *setup)
86bool handle_setup(const struct setup_request *setup)
8687{
8788    switch (setup->bmRequestType | setup->bRequest << 8) {
8889
atusb/fw/usb/usb.h
11/*
22 * fw/usb//usb.h - USB hardware setup and standard device requests
33 *
4 * Written 2008, 2009, 2011 by Werner Almesberger
5 * Copyright 2008, 2009, 2011 Werner Almesberger
4 * Written 2008, 2009, 2011, 2013 by Werner Almesberger
5 * Copyright 2008, 2009, 2011, 2013 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1515#define USB_H
1616
1717
18#include <stdbool.h>
1819#include <stdint.h>
1920
2021
...... 
132133extern const uint8_t config_descriptor[];
133134extern struct ep_descr eps[];
134135
135extern int (*user_setup)(const struct setup_request *setup);
136extern bool (*user_setup)(const struct setup_request *setup);
136137extern void (*user_set_interface)(int nth);
137extern int (*user_get_descriptor)(uint8_t type, uint8_t index,
138extern bool (*user_get_descriptor)(uint8_t type, uint8_t index,
138139    const uint8_t **reply, uint8_t *size);
139140extern void (*user_reset)(void);
140141
...... 
148149void usb_io(struct ep_descr *ep, enum ep_state state, uint8_t *buf,
149150    uint8_t size, void (*callback)(void *user), void *user);
150151
151int handle_setup(const struct setup_request *setup);
152int set_addr(uint8_t addr);
152bool handle_setup(const struct setup_request *setup);
153void set_addr(uint8_t addr);
153154void usb_ep_change(struct ep_descr *ep);
154155void usb_reset(void);
155156void usb_init(void);

Archive Download the corresponding diff file



interactive