mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-12-23 04:52:05 +02:00
atusb/fw/: convert functions returning "int" to "bool"
Firmware size is down from 5612 to 3590 bytes. Wow !
This commit is contained in:
parent
c9ab070ffd
commit
a8db238cbb
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* fw/board.h - Board-specific functions and definitions
|
||||
*
|
||||
* Written 2008-2011 by Werner Almesberger
|
||||
* Copyright 2008-2011 Werner Almesberger
|
||||
* Written 2008-2011, 2013 by Werner Almesberger
|
||||
* Copyright 2008-2011, 2013 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
|
||||
@ -13,6 +13,7 @@
|
||||
#ifndef BOARD_H
|
||||
#define BOARD_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
@ -87,7 +88,7 @@ void panic(void);
|
||||
uint64_t timer_read(void);
|
||||
void timer_init(void);
|
||||
|
||||
int gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res);
|
||||
bool gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res);
|
||||
void gpio_cleanup(void);
|
||||
|
||||
void board_init(void);
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* fw/board_app.c - Board-specific functions (for the application)
|
||||
*
|
||||
* Written 2011 by Werner Almesberger
|
||||
* Copyright 2011 Werner Almesberger
|
||||
* Written 2011, 2013 by Werner Almesberger
|
||||
* Copyright 2011, 2013 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
|
||||
@ -12,6 +12,7 @@
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <avr/io.h>
|
||||
@ -92,7 +93,7 @@ void timer_init(void)
|
||||
}
|
||||
|
||||
|
||||
int gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res)
|
||||
bool gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res)
|
||||
{
|
||||
EIMSK = 0; /* recover INT_RF to ATUSB_GPIO_CLEANUP or an MCU reset */
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* fw/ep0.c - EP0 extension protocol
|
||||
*
|
||||
* Written 2008-2011 by Werner Almesberger
|
||||
* Copyright 2008-2011 Werner Almesberger
|
||||
* Written 2008-2011, 2013 by Werner Almesberger
|
||||
* Copyright 2008-2011, 2013 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
|
||||
@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -57,7 +58,7 @@ static void do_buf_write(void *user)
|
||||
#define BUILD_OFFSET 7 /* '#' plus "65535" plus ' ' */
|
||||
|
||||
|
||||
static int my_setup(const struct setup_request *setup)
|
||||
static bool my_setup(const struct setup_request *setup)
|
||||
{
|
||||
uint16_t req = setup->bmRequestType | setup->bRequest << 8;
|
||||
unsigned tmp;
|
||||
@ -254,7 +255,7 @@ static int my_setup(const struct setup_request *setup)
|
||||
}
|
||||
|
||||
|
||||
static int my_dfu_setup(const struct setup_request *setup)
|
||||
static bool my_dfu_setup(const struct setup_request *setup)
|
||||
{
|
||||
switch (setup->bmRequestType | setup->bRequest << 8) {
|
||||
case DFU_TO_DEV(DFU_DETACH):
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* fw/flash.c - Board-specific flash functions
|
||||
*
|
||||
* Written 2011 by Werner Almesberger
|
||||
* Copyright 2011 Werner Almesberger
|
||||
* Written 2011, 2013 by Werner Almesberger
|
||||
* Copyright 2011, 2013 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
|
||||
@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <avr/boot.h>
|
||||
@ -29,7 +30,7 @@ void flash_start(void)
|
||||
}
|
||||
|
||||
|
||||
int flash_can_write(uint16_t size)
|
||||
bool flash_can_write(uint16_t size)
|
||||
{
|
||||
return payload+size <= BOOT_ADDR;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ static void change_state(uint8_t new)
|
||||
}
|
||||
|
||||
|
||||
int mac_rx(int on)
|
||||
bool mac_rx(int on)
|
||||
{
|
||||
if (on) {
|
||||
mac_irq = handle_irq;
|
||||
@ -178,7 +178,7 @@ static void do_tx(void *user)
|
||||
}
|
||||
|
||||
|
||||
int mac_tx(uint16_t flags, uint16_t len)
|
||||
bool mac_tx(uint16_t flags, uint16_t len)
|
||||
{
|
||||
if (len > MAX_PSDU)
|
||||
return 0;
|
||||
|
@ -13,13 +13,14 @@
|
||||
#ifndef MAC_H
|
||||
#define MAC_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
extern int (*mac_irq)(void);
|
||||
|
||||
int mac_rx(int on);
|
||||
int mac_tx(uint16_t flags, uint16_t len);
|
||||
bool mac_rx(int on);
|
||||
bool mac_tx(uint16_t flags, uint16_t len);
|
||||
void mac_reset(void);
|
||||
|
||||
#endif /* !MAC_H */
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* fw/sernum.c - ATUSB serial number
|
||||
*
|
||||
* Written 2008-2011 by Werner Almesberger
|
||||
* Copyright 2008-2011 Werner Almesberger
|
||||
* Written 2008-2011, 2013 by Werner Almesberger
|
||||
* Copyright 2008-2011, 2013 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
|
||||
@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "usb.h"
|
||||
@ -26,7 +27,7 @@ static const uint8_t string_descriptor_0[] = {
|
||||
};
|
||||
|
||||
|
||||
int sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply,
|
||||
bool sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply,
|
||||
uint8_t *size)
|
||||
{
|
||||
if (type != USB_DT_STRING)
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* fw/sernum.h - ATUSB serial number
|
||||
*
|
||||
* Written 2011 by Werner Almesberger
|
||||
* Copyright 2011 Werner Almesberger
|
||||
* Written 2011, 2013 by Werner Almesberger
|
||||
* Copyright 2011, 2013 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
|
||||
@ -13,6 +13,7 @@
|
||||
#ifndef SERNUM_H
|
||||
#define SERNUM_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "board.h"
|
||||
@ -20,12 +21,12 @@
|
||||
|
||||
#ifdef HAS_BOARD_SERNUM
|
||||
|
||||
int sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply,
|
||||
bool sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply,
|
||||
uint8_t *size);
|
||||
|
||||
#else /* HAS_BOARD_SERNUM */
|
||||
|
||||
static inline int sernum_get_descr(uint8_t type, uint8_t index,
|
||||
static inline bool sernum_get_descr(uint8_t type, uint8_t index,
|
||||
const uint8_t **reply, uint8_t *size)
|
||||
{
|
||||
return 0;
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* fw/spi.c - ATmega8 family SPI I/O
|
||||
*
|
||||
* Written 2011 by Werner Almesberger
|
||||
* Copyright 2011 Werner Almesberger
|
||||
* Written 2011, 2013 by Werner Almesberger
|
||||
* Copyright 2011, 2013 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
|
||||
@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <avr/io.h>
|
||||
@ -19,7 +20,7 @@
|
||||
#include "spi.h"
|
||||
|
||||
|
||||
static int spi_initialized = 0;
|
||||
static bool spi_initialized = 0;
|
||||
|
||||
|
||||
void spi_begin(void)
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* fw/usb/atu2.c - Chip-specific driver for Atmel ATxxxU2 USB chips
|
||||
*
|
||||
* Written 2008-2011 by Werner Almesberger
|
||||
* Copyright 2008-2011 Werner Almesberger
|
||||
* Written 2008-2011, 2013 by Werner Almesberger
|
||||
* Copyright 2008-2011, 2013 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
|
||||
@ -18,6 +18,7 @@
|
||||
* - enumeration often encounters an error -71 (from which it recovers)
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define F_CPU 8000000UL
|
||||
@ -59,11 +60,10 @@ static void enable_addr(void *user)
|
||||
}
|
||||
|
||||
|
||||
int set_addr(uint8_t addr)
|
||||
void set_addr(uint8_t addr)
|
||||
{
|
||||
UDADDR = addr;
|
||||
usb_send(&eps[0], NULL, 0, enable_addr, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -76,7 +76,7 @@ void usb_ep_change(struct ep_descr *ep)
|
||||
}
|
||||
|
||||
|
||||
static int ep_setup(void)
|
||||
static bool ep_setup(void)
|
||||
{
|
||||
struct setup_request setup;
|
||||
|
||||
@ -96,7 +96,7 @@ static int ep_setup(void)
|
||||
}
|
||||
|
||||
|
||||
static int ep_rx(struct ep_descr *ep)
|
||||
static bool ep_rx(struct ep_descr *ep)
|
||||
{
|
||||
uint8_t size;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* boot/dfu.c - DFU protocol engine
|
||||
*
|
||||
* Written 2008-2011 by Werner Almesberger
|
||||
* Copyright 2008-2011 Werner Almesberger
|
||||
* Written 2008-2011, 2013 by Werner Almesberger
|
||||
* Copyright 2008-2011, 2013 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
|
||||
@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "usb.h"
|
||||
@ -81,7 +82,7 @@ const uint8_t config_descriptor[] = {
|
||||
|
||||
|
||||
static uint16_t next_block = 0;
|
||||
static int did_download;
|
||||
static bool did_download;
|
||||
|
||||
|
||||
static uint8_t buf[EP0_SIZE];
|
||||
@ -95,7 +96,7 @@ static void block_write(void *user)
|
||||
}
|
||||
|
||||
|
||||
static int block_receive(uint16_t length)
|
||||
static bool block_receive(uint16_t length)
|
||||
{
|
||||
static uint16_t size;
|
||||
|
||||
@ -115,7 +116,7 @@ static int block_receive(uint16_t length)
|
||||
}
|
||||
|
||||
|
||||
static int block_transmit(uint16_t length)
|
||||
static bool block_transmit(uint16_t length)
|
||||
{
|
||||
uint16_t got;
|
||||
|
||||
@ -134,9 +135,9 @@ static int block_transmit(uint16_t length)
|
||||
}
|
||||
|
||||
|
||||
static int my_setup(const struct setup_request *setup)
|
||||
static bool my_setup(const struct setup_request *setup)
|
||||
{
|
||||
int ok;
|
||||
bool ok;
|
||||
|
||||
switch (setup->bmRequestType | setup->bRequest << 8) {
|
||||
case DFU_TO_DEV(DFU_DETACH):
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* boot/dfu.h - DFU protocol constants and data structures
|
||||
*
|
||||
* Written 2008, 2011 by Werner Almesberger
|
||||
* Copyright 2008, 2011 Werner Almesberger
|
||||
* Written 2008, 2011, 2013 by Werner Almesberger
|
||||
* Copyright 2008, 2011, 2013 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
|
||||
@ -14,6 +14,7 @@
|
||||
#ifndef DFU_H
|
||||
#define DFU_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "usb.h"
|
||||
@ -101,13 +102,13 @@ extern struct dfu dfu;
|
||||
|
||||
|
||||
void flash_start(void);
|
||||
int flash_can_write(uint16_t size);
|
||||
bool flash_can_write(uint16_t size);
|
||||
void flash_write(const uint8_t *buf, uint16_t size);
|
||||
void flash_end_write(void);
|
||||
uint16_t flash_read(uint8_t *buf, uint16_t size);
|
||||
|
||||
int dfu_setup_common(const struct setup_request *setup);
|
||||
int dfu_my_descr(uint8_t type, uint8_t index, const uint8_t **reply,
|
||||
bool dfu_setup_common(const struct setup_request *setup);
|
||||
bool dfu_my_descr(uint8_t type, uint8_t index, const uint8_t **reply,
|
||||
uint8_t *size);
|
||||
|
||||
void dfu_init(void);
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* boot/dfu_common.c - DFU protocol engine parts common to App/DFU
|
||||
*
|
||||
* Written 2008-2011 by Werner Almesberger
|
||||
* Copyright 2008-2011 Werner Almesberger
|
||||
* Written 2008-2011, 2013 by Werner Almesberger
|
||||
* Copyright 2008-2011, 2013 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
|
||||
@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "usb.h"
|
||||
@ -65,7 +66,7 @@ struct dfu dfu = {
|
||||
};
|
||||
|
||||
|
||||
int dfu_setup_common(const struct setup_request *setup)
|
||||
bool dfu_setup_common(const struct setup_request *setup)
|
||||
{
|
||||
switch (setup->bmRequestType | setup->bRequest << 8) {
|
||||
case DFU_FROM_DEV(DFU_GETSTATUS):
|
||||
@ -89,7 +90,7 @@ int dfu_setup_common(const struct setup_request *setup)
|
||||
}
|
||||
|
||||
|
||||
int dfu_my_descr(uint8_t type, uint8_t index, const uint8_t **reply,
|
||||
bool dfu_my_descr(uint8_t type, uint8_t index, const uint8_t **reply,
|
||||
uint8_t *size)
|
||||
{
|
||||
if (type != DFU_DT_FUNCTIONAL)
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* fw/usb/usb.c - USB hardware setup and standard device requests
|
||||
*
|
||||
* Written 2008-2011 by Werner Almesberger
|
||||
* Copyright 2008-2011 Werner Almesberger
|
||||
* Written 2008-2011, 2013 by Werner Almesberger
|
||||
* Copyright 2008-2011, 2013 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
|
||||
@ -16,6 +16,7 @@
|
||||
* - should support EP clearing and stalling
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "usb.h"
|
||||
@ -33,9 +34,9 @@ extern void panic(void);
|
||||
#define BUG_ON(cond)
|
||||
#endif
|
||||
|
||||
int (*user_setup)(const struct setup_request *setup);
|
||||
bool (*user_setup)(const struct setup_request *setup);
|
||||
void (*user_set_interface)(int nth);
|
||||
int (*user_get_descriptor)(uint8_t type, uint8_t index,
|
||||
bool (*user_get_descriptor)(uint8_t type, uint8_t index,
|
||||
const uint8_t **reply, uint8_t *size);
|
||||
void (*user_reset)(void);
|
||||
|
||||
@ -53,7 +54,7 @@ void usb_io(struct ep_descr *ep, enum ep_state state, uint8_t *buf,
|
||||
}
|
||||
|
||||
|
||||
static int get_descriptor(uint8_t type, uint8_t index, uint16_t length)
|
||||
static bool get_descriptor(uint8_t type, uint8_t index, uint16_t length)
|
||||
{
|
||||
const uint8_t *reply;
|
||||
uint8_t size;
|
||||
@ -82,7 +83,7 @@ static int get_descriptor(uint8_t type, uint8_t index, uint16_t length)
|
||||
}
|
||||
|
||||
|
||||
int handle_setup(const struct setup_request *setup)
|
||||
bool handle_setup(const struct setup_request *setup)
|
||||
{
|
||||
switch (setup->bmRequestType | setup->bRequest << 8) {
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* fw/usb//usb.h - USB hardware setup and standard device requests
|
||||
*
|
||||
* Written 2008, 2009, 2011 by Werner Almesberger
|
||||
* Copyright 2008, 2009, 2011 Werner Almesberger
|
||||
* Written 2008, 2009, 2011, 2013 by Werner Almesberger
|
||||
* Copyright 2008, 2009, 2011, 2013 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
|
||||
@ -15,6 +15,7 @@
|
||||
#define USB_H
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
@ -132,9 +133,9 @@ extern const uint8_t device_descriptor[];
|
||||
extern const uint8_t config_descriptor[];
|
||||
extern struct ep_descr eps[];
|
||||
|
||||
extern int (*user_setup)(const struct setup_request *setup);
|
||||
extern bool (*user_setup)(const struct setup_request *setup);
|
||||
extern void (*user_set_interface)(int nth);
|
||||
extern int (*user_get_descriptor)(uint8_t type, uint8_t index,
|
||||
extern bool (*user_get_descriptor)(uint8_t type, uint8_t index,
|
||||
const uint8_t **reply, uint8_t *size);
|
||||
extern void (*user_reset)(void);
|
||||
|
||||
@ -148,8 +149,8 @@ extern void (*user_reset)(void);
|
||||
void usb_io(struct ep_descr *ep, enum ep_state state, uint8_t *buf,
|
||||
uint8_t size, void (*callback)(void *user), void *user);
|
||||
|
||||
int handle_setup(const struct setup_request *setup);
|
||||
int set_addr(uint8_t addr);
|
||||
bool handle_setup(const struct setup_request *setup);
|
||||
void set_addr(uint8_t addr);
|
||||
void usb_ep_change(struct ep_descr *ep);
|
||||
void usb_reset(void);
|
||||
void usb_init(void);
|
||||
|
Loading…
Reference in New Issue
Block a user