IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Commit Details
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 | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * fw/board.h - Board-specific functions and definitions |
3 | 3 | * |
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 | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
13 | 13 | #ifndef BOARD_H |
14 | 14 | #define BOARD_H |
15 | 15 | |
16 | #include <stdbool.h> | |
16 | 17 | #include <stdint.h> |
17 | 18 | |
18 | 19 | |
... | ... | |
87 | 88 | uint64_t timer_read(void); |
88 | 89 | void timer_init(void); |
89 | 90 | |
90 | int gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res); | |
91 | bool gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res); | |
91 | 92 | void gpio_cleanup(void); |
92 | 93 | |
93 | 94 | void board_init(void); |
atusb/fw/board_app.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * fw/board_app.c - Board-specific functions (for the application) |
3 | 3 | * |
4 | * Written 2011 by Werner Almesberger | |
5 | * Copyright 2011 Werner Almesberger | |
4 | * Written 2011, 2013 by Werner Almesberger | |
5 | * Copyright 2011, 2013 Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
12 | 12 | |
13 | 13 | |
14 | 14 | #include <stddef.h> |
15 | #include <stdbool.h> | |
15 | 16 | #include <stdint.h> |
16 | 17 | |
17 | 18 | #include <avr/io.h> |
... | ... | |
92 | 93 | } |
93 | 94 | |
94 | 95 | |
95 | int gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res) | |
96 | bool gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res) | |
96 | 97 | { |
97 | 98 | EIMSK = 0; /* recover INT_RF to ATUSB_GPIO_CLEANUP or an MCU reset */ |
98 | 99 |
atusb/fw/ep0.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * fw/ep0.c - EP0 extension protocol |
3 | 3 | * |
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 | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
11 | 11 | */ |
12 | 12 | |
13 | 13 | |
14 | #include <stdbool.h> | |
14 | 15 | #include <stdint.h> |
15 | 16 | #include <string.h> |
16 | 17 | |
... | ... | |
57 | 58 | #define BUILD_OFFSET 7 /* '#' plus "65535" plus ' ' */ |
58 | 59 | |
59 | 60 | |
60 | static int my_setup(const struct setup_request *setup) | |
61 | static bool my_setup(const struct setup_request *setup) | |
61 | 62 | { |
62 | 63 | uint16_t req = setup->bmRequestType | setup->bRequest << 8; |
63 | 64 | unsigned tmp; |
... | ... | |
254 | 255 | } |
255 | 256 | |
256 | 257 | |
257 | static int my_dfu_setup(const struct setup_request *setup) | |
258 | static bool my_dfu_setup(const struct setup_request *setup) | |
258 | 259 | { |
259 | 260 | switch (setup->bmRequestType | setup->bRequest << 8) { |
260 | 261 | case DFU_TO_DEV(DFU_DETACH): |
atusb/fw/flash.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * fw/flash.c - Board-specific flash functions |
3 | 3 | * |
4 | * Written 2011 by Werner Almesberger | |
5 | * Copyright 2011 Werner Almesberger | |
4 | * Written 2011, 2013 by Werner Almesberger | |
5 | * Copyright 2011, 2013 Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
11 | 11 | */ |
12 | 12 | |
13 | 13 | |
14 | #include <stdbool.h> | |
14 | 15 | #include <stdint.h> |
15 | 16 | |
16 | 17 | #include <avr/boot.h> |
... | ... | |
29 | 30 | } |
30 | 31 | |
31 | 32 | |
32 | int flash_can_write(uint16_t size) | |
33 | bool flash_can_write(uint16_t size) | |
33 | 34 | { |
34 | 35 | return payload+size <= BOOT_ADDR; |
35 | 36 | } |
atusb/fw/mac.c | ||
---|---|---|
118 | 118 | } |
119 | 119 | |
120 | 120 | |
121 | int mac_rx(int on) | |
121 | bool mac_rx(int on) | |
122 | 122 | { |
123 | 123 | if (on) { |
124 | 124 | mac_irq = handle_irq; |
... | ... | |
178 | 178 | } |
179 | 179 | |
180 | 180 | |
181 | int mac_tx(uint16_t flags, uint16_t len) | |
181 | bool mac_tx(uint16_t flags, uint16_t len) | |
182 | 182 | { |
183 | 183 | if (len > MAX_PSDU) |
184 | 184 | return 0; |
atusb/fw/mac.h | ||
---|---|---|
13 | 13 | #ifndef MAC_H |
14 | 14 | #define MAC_H |
15 | 15 | |
16 | #include <stdbool.h> | |
16 | 17 | #include <stdint.h> |
17 | 18 | |
18 | 19 | |
19 | 20 | extern int (*mac_irq)(void); |
20 | 21 | |
21 | int mac_rx(int on); | |
22 | int mac_tx(uint16_t flags, uint16_t len); | |
22 | bool mac_rx(int on); | |
23 | bool mac_tx(uint16_t flags, uint16_t len); | |
23 | 24 | void mac_reset(void); |
24 | 25 | |
25 | 26 | #endif /* !MAC_H */ |
atusb/fw/sernum.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * fw/sernum.c - ATUSB serial number |
3 | 3 | * |
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 | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
11 | 11 | */ |
12 | 12 | |
13 | 13 | |
14 | #include <stdbool.h> | |
14 | 15 | #include <stdint.h> |
15 | 16 | |
16 | 17 | #include "usb.h" |
... | ... | |
26 | 27 | }; |
27 | 28 | |
28 | 29 | |
29 | int sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply, | |
30 | bool sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply, | |
30 | 31 | uint8_t *size) |
31 | 32 | { |
32 | 33 | if (type != USB_DT_STRING) |
atusb/fw/sernum.h | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * fw/sernum.h - ATUSB serial number |
3 | 3 | * |
4 | * Written 2011 by Werner Almesberger | |
5 | * Copyright 2011 Werner Almesberger | |
4 | * Written 2011, 2013 by Werner Almesberger | |
5 | * Copyright 2011, 2013 Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
13 | 13 | #ifndef SERNUM_H |
14 | 14 | #define SERNUM_H |
15 | 15 | |
16 | #include <stdbool.h> | |
16 | 17 | #include <stdint.h> |
17 | 18 | |
18 | 19 | #include "board.h" |
... | ... | |
20 | 21 | |
21 | 22 | #ifdef HAS_BOARD_SERNUM |
22 | 23 | |
23 | int sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply, | |
24 | bool sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply, | |
24 | 25 | uint8_t *size); |
25 | 26 | |
26 | 27 | #else /* HAS_BOARD_SERNUM */ |
27 | 28 | |
28 | static inline int sernum_get_descr(uint8_t type, uint8_t index, | |
29 | static inline bool sernum_get_descr(uint8_t type, uint8_t index, | |
29 | 30 | const uint8_t **reply, uint8_t *size) |
30 | 31 | { |
31 | 32 | return 0; |
atusb/fw/spi.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * fw/spi.c - ATmega8 family SPI I/O |
3 | 3 | * |
4 | * Written 2011 by Werner Almesberger | |
5 | * Copyright 2011 Werner Almesberger | |
4 | * Written 2011, 2013 by Werner Almesberger | |
5 | * Copyright 2011, 2013 Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
11 | 11 | */ |
12 | 12 | |
13 | 13 | |
14 | #include <stdbool.h> | |
14 | 15 | #include <stdint.h> |
15 | 16 | |
16 | 17 | #include <avr/io.h> |
... | ... | |
19 | 20 | #include "spi.h" |
20 | 21 | |
21 | 22 | |
22 | static int spi_initialized = 0; | |
23 | static bool spi_initialized = 0; | |
23 | 24 | |
24 | 25 | |
25 | 26 | void spi_begin(void) |
atusb/fw/usb/atu2.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * fw/usb/atu2.c - Chip-specific driver for Atmel ATxxxU2 USB chips |
3 | 3 | * |
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 | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
18 | 18 | * - enumeration often encounters an error -71 (from which it recovers) |
19 | 19 | */ |
20 | 20 | |
21 | #include <stdbool.h> | |
21 | 22 | #include <stdint.h> |
22 | 23 | |
23 | 24 | #define F_CPU 8000000UL |
... | ... | |
59 | 60 | } |
60 | 61 | |
61 | 62 | |
62 | int set_addr(uint8_t addr) | |
63 | void set_addr(uint8_t addr) | |
63 | 64 | { |
64 | 65 | UDADDR = addr; |
65 | 66 | usb_send(&eps[0], NULL, 0, enable_addr, NULL); |
66 | return 1; | |
67 | 67 | } |
68 | 68 | |
69 | 69 | |
... | ... | |
76 | 76 | } |
77 | 77 | |
78 | 78 | |
79 | static int ep_setup(void) | |
79 | static bool ep_setup(void) | |
80 | 80 | { |
81 | 81 | struct setup_request setup; |
82 | 82 | |
... | ... | |
96 | 96 | } |
97 | 97 | |
98 | 98 | |
99 | static int ep_rx(struct ep_descr *ep) | |
99 | static bool ep_rx(struct ep_descr *ep) | |
100 | 100 | { |
101 | 101 | uint8_t size; |
102 | 102 |
atusb/fw/usb/dfu.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * boot/dfu.c - DFU protocol engine |
3 | 3 | * |
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 | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
25 | 25 | */ |
26 | 26 | |
27 | 27 | |
28 | #include <stdbool.h> | |
28 | 29 | #include <stdint.h> |
29 | 30 | |
30 | 31 | #include "usb.h" |
... | ... | |
81 | 82 | |
82 | 83 | |
83 | 84 | static uint16_t next_block = 0; |
84 | static int did_download; | |
85 | static bool did_download; | |
85 | 86 | |
86 | 87 | |
87 | 88 | static uint8_t buf[EP0_SIZE]; |
... | ... | |
95 | 96 | } |
96 | 97 | |
97 | 98 | |
98 | static int block_receive(uint16_t length) | |
99 | static bool block_receive(uint16_t length) | |
99 | 100 | { |
100 | 101 | static uint16_t size; |
101 | 102 | |
... | ... | |
115 | 116 | } |
116 | 117 | |
117 | 118 | |
118 | static int block_transmit(uint16_t length) | |
119 | static bool block_transmit(uint16_t length) | |
119 | 120 | { |
120 | 121 | uint16_t got; |
121 | 122 | |
... | ... | |
134 | 135 | } |
135 | 136 | |
136 | 137 | |
137 | static int my_setup(const struct setup_request *setup) | |
138 | static bool my_setup(const struct setup_request *setup) | |
138 | 139 | { |
139 | int ok; | |
140 | bool ok; | |
140 | 141 | |
141 | 142 | switch (setup->bmRequestType | setup->bRequest << 8) { |
142 | 143 | case DFU_TO_DEV(DFU_DETACH): |
atusb/fw/usb/dfu.h | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * boot/dfu.h - DFU protocol constants and data structures |
3 | 3 | * |
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 | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
14 | 14 | #ifndef DFU_H |
15 | 15 | #define DFU_H |
16 | 16 | |
17 | #include <stdbool.h> | |
17 | 18 | #include <stdint.h> |
18 | 19 | |
19 | 20 | #include "usb.h" |
... | ... | |
101 | 102 | |
102 | 103 | |
103 | 104 | void flash_start(void); |
104 | int flash_can_write(uint16_t size); | |
105 | bool flash_can_write(uint16_t size); | |
105 | 106 | void flash_write(const uint8_t *buf, uint16_t size); |
106 | 107 | void flash_end_write(void); |
107 | 108 | uint16_t flash_read(uint8_t *buf, uint16_t size); |
108 | 109 | |
109 | int dfu_setup_common(const struct setup_request *setup); | |
110 | int dfu_my_descr(uint8_t type, uint8_t index, const uint8_t **reply, | |
110 | bool dfu_setup_common(const struct setup_request *setup); | |
111 | bool dfu_my_descr(uint8_t type, uint8_t index, const uint8_t **reply, | |
111 | 112 | uint8_t *size); |
112 | 113 | |
113 | 114 | void dfu_init(void); |
atusb/fw/usb/dfu_common.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * boot/dfu_common.c - DFU protocol engine parts common to App/DFU |
3 | 3 | * |
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 | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
25 | 25 | */ |
26 | 26 | |
27 | 27 | |
28 | #include <stdbool.h> | |
28 | 29 | #include <stdint.h> |
29 | 30 | |
30 | 31 | #include "usb.h" |
... | ... | |
65 | 66 | }; |
66 | 67 | |
67 | 68 | |
68 | int dfu_setup_common(const struct setup_request *setup) | |
69 | bool dfu_setup_common(const struct setup_request *setup) | |
69 | 70 | { |
70 | 71 | switch (setup->bmRequestType | setup->bRequest << 8) { |
71 | 72 | case DFU_FROM_DEV(DFU_GETSTATUS): |
... | ... | |
89 | 90 | } |
90 | 91 | |
91 | 92 | |
92 | int dfu_my_descr(uint8_t type, uint8_t index, const uint8_t **reply, | |
93 | bool dfu_my_descr(uint8_t type, uint8_t index, const uint8_t **reply, | |
93 | 94 | uint8_t *size) |
94 | 95 | { |
95 | 96 | if (type != DFU_DT_FUNCTIONAL) |
atusb/fw/usb/usb.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * fw/usb/usb.c - USB hardware setup and standard device requests |
3 | 3 | * |
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 | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
16 | 16 | * - should support EP clearing and stalling |
17 | 17 | */ |
18 | 18 | |
19 | #include <stdbool.h> | |
19 | 20 | #include <stdint.h> |
20 | 21 | |
21 | 22 | #include "usb.h" |
... | ... | |
33 | 34 | #define BUG_ON(cond) |
34 | 35 | #endif |
35 | 36 | |
36 | int (*user_setup)(const struct setup_request *setup); | |
37 | bool (*user_setup)(const struct setup_request *setup); | |
37 | 38 | void (*user_set_interface)(int nth); |
38 | int (*user_get_descriptor)(uint8_t type, uint8_t index, | |
39 | bool (*user_get_descriptor)(uint8_t type, uint8_t index, | |
39 | 40 | const uint8_t **reply, uint8_t *size); |
40 | 41 | void (*user_reset)(void); |
41 | 42 | |
... | ... | |
53 | 54 | } |
54 | 55 | |
55 | 56 | |
56 | static int get_descriptor(uint8_t type, uint8_t index, uint16_t length) | |
57 | static bool get_descriptor(uint8_t type, uint8_t index, uint16_t length) | |
57 | 58 | { |
58 | 59 | const uint8_t *reply; |
59 | 60 | uint8_t size; |
... | ... | |
82 | 83 | } |
83 | 84 | |
84 | 85 | |
85 | int handle_setup(const struct setup_request *setup) | |
86 | bool handle_setup(const struct setup_request *setup) | |
86 | 87 | { |
87 | 88 | switch (setup->bmRequestType | setup->bRequest << 8) { |
88 | 89 |
atusb/fw/usb/usb.h | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * fw/usb//usb.h - USB hardware setup and standard device requests |
3 | 3 | * |
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 | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
15 | 15 | #define USB_H |
16 | 16 | |
17 | 17 | |
18 | #include <stdbool.h> | |
18 | 19 | #include <stdint.h> |
19 | 20 | |
20 | 21 | |
... | ... | |
132 | 133 | extern const uint8_t config_descriptor[]; |
133 | 134 | extern struct ep_descr eps[]; |
134 | 135 | |
135 | extern int (*user_setup)(const struct setup_request *setup); | |
136 | extern bool (*user_setup)(const struct setup_request *setup); | |
136 | 137 | extern void (*user_set_interface)(int nth); |
137 | extern int (*user_get_descriptor)(uint8_t type, uint8_t index, | |
138 | extern bool (*user_get_descriptor)(uint8_t type, uint8_t index, | |
138 | 139 | const uint8_t **reply, uint8_t *size); |
139 | 140 | extern void (*user_reset)(void); |
140 | 141 | |
... | ... | |
148 | 149 | void usb_io(struct ep_descr *ep, enum ep_state state, uint8_t *buf, |
149 | 150 | uint8_t size, void (*callback)(void *user), void *user); |
150 | 151 | |
151 | int handle_setup(const struct setup_request *setup); | |
152 | int set_addr(uint8_t addr); | |
152 | bool handle_setup(const struct setup_request *setup); | |
153 | void set_addr(uint8_t addr); | |
153 | 154 | void usb_ep_change(struct ep_descr *ep); |
154 | 155 | void usb_reset(void); |
155 | 156 | void usb_init(void); |