IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Commit Details
Date: | 2016-03-30 00:03:48 (7 years 8 months ago) |
---|---|
Author: | Stefan Schmidt |
Commit: | 65912c2acbced58b4345deae94ddc763d99c7454 |
Message: | atusb: fw: first round of re-factor after the integration of rzusb
as a board Move board specific parts in board_$NAME.c/h for a little abstraction and less ifdef handling in common code. |
Files: |
atusb/fw/Makefile (1 diff) atusb/fw/board.c (3 diffs) atusb/fw/board.h (2 diffs) atusb/fw/board_atusb.c (1 diff) atusb/fw/board_atusb.h (1 diff) atusb/fw/board_rzusb.c (1 diff) atusb/fw/board_rzusb.h (1 diff) |
Change Details
atusb/fw/Makefile | ||
---|---|---|
46 | 46 | BOOT_OBJS = boot.o board.o sernum.o spi.o flash.o dfu.o \ |
47 | 47 | dfu_common.o usb.o boot-atu2.o |
48 | 48 | |
49 | ||
50 | ifeq ($(NAME),rzusb) | |
51 | OBJS += board_rzusb.o | |
52 | BOOT_OBJS += board_rzusb.o | |
53 | else | |
54 | OBJS += board_atusb.o | |
55 | BOOT_OBJS += board_atusb.o | |
56 | endif | |
57 | ||
58 | ||
49 | 59 | vpath %.c usb/ |
50 | 60 | |
51 | 61 | CFLAGS += -Iinclude -Iusb -I. |
atusb/fw/board.c | ||
---|---|---|
29 | 29 | |
30 | 30 | uint8_t board_sernum[42] = { 42, USB_DT_STRING }; |
31 | 31 | |
32 | ||
33 | static void set_clkm(void) | |
34 | { | |
35 | /* switch CLKM to 8 MHz */ | |
36 | ||
37 | /* | |
38 | * @@@ Note: Atmel advise against changing the external clock in | |
39 | * mid-flight. We should therefore switch to the RC clock first, then | |
40 | * crank up the external clock, and finally switch back to the external | |
41 | * clock. The clock switching procedure is described in the ATmega32U2 | |
42 | * data sheet in secton 8.2.2. | |
43 | */ | |
44 | #ifdef ATUSB | |
45 | spi_begin(); | |
46 | spi_send(AT86RF230_REG_WRITE | REG_TRX_CTRL_0); | |
47 | spi_send(CLKM_CTRL_8MHz); | |
48 | spi_end(); | |
49 | #endif | |
50 | #ifdef RZUSB | |
51 | spi_begin(); | |
52 | spi_send(AT86RF230_REG_WRITE | REG_TRX_CTRL_0); | |
53 | spi_send(0x10); | |
54 | spi_end(); | |
55 | ||
56 | /* TX_AUTO_CRC_ON, default disabled */ | |
57 | spi_begin(); | |
58 | spi_send(AT86RF230_REG_WRITE | 0x05); | |
59 | spi_send(0x80); | |
60 | spi_end(); | |
61 | #endif | |
62 | } | |
63 | ||
64 | ||
65 | 32 | void reset_rf(void) |
66 | 33 | { |
67 | 34 | /* set up all the outputs; default port value is 0 */ |
... | ... | |
122 | 89 | } |
123 | 90 | |
124 | 91 | |
125 | static void get_sernum(void) | |
92 | void get_sernum(void) | |
126 | 93 | { |
127 | 94 | uint8_t sig; |
128 | 95 | uint8_t i; |
... | ... | |
133 | 100 | board_sernum[(i << 2)+4] = hex(sig & 0xf); |
134 | 101 | } |
135 | 102 | } |
136 | ||
137 | ||
138 | void board_init(void) | |
139 | { | |
140 | /* Disable the watchdog timer */ | |
141 | ||
142 | MCUSR = 0; /* Remove override */ | |
143 | WDTCSR |= 1 << WDCE; /* Enable change */ | |
144 | WDTCSR = 1 << WDCE; /* Disable watchdog while still enabling | |
145 | change */ | |
146 | ||
147 | CLKPR = 1 << CLKPCE; | |
148 | #ifdef ATUSB | |
149 | /* We start with a 1 MHz/8 clock. Disable the prescaler. */ | |
150 | CLKPR = 0; | |
151 | #endif | |
152 | #ifdef RZUSB | |
153 | /* We start with a 16 MHz/8 clock. Put the prescaler to 2. */ | |
154 | CLKPR = 1 << CLKPS0; | |
155 | #endif | |
156 | ||
157 | get_sernum(); | |
158 | } |
atusb/fw/board.h | ||
---|---|---|
19 | 19 | #include <atusb/atusb.h> |
20 | 20 | |
21 | 21 | #ifdef ATUSB |
22 | #define LED_PORT B | |
23 | #define LED_BIT 6 | |
24 | #define nRST_RF_PORT C | |
25 | #define nRST_RF_BIT 7 | |
26 | #define SLP_TR_PORT B | |
27 | #define SLP_TR_BIT 4 | |
28 | ||
29 | #define SCLK_PORT D | |
30 | #define SCLK_BIT 5 | |
31 | #define MOSI_PORT D | |
32 | #define MOSI_BIT 3 | |
33 | ||
34 | #define MISO_PORT D | |
35 | #define MISO_BIT 2 | |
36 | #define nSS_PORT D | |
37 | #define nSS_BIT 1 | |
38 | #define IRQ_RF_PORT D | |
39 | #define IRQ_RF_BIT 0 | |
40 | ||
41 | #define SPI_WAIT_DONE() while (!(UCSR1A & 1 << RXC1)) | |
42 | #define SPI_DATA UDR1 | |
43 | ||
22 | #include "board_atusb.h" | |
44 | 23 | #endif |
45 | 24 | #ifdef RZUSB |
46 | #define LED_PORT D | |
47 | #define LED_BIT 7 | |
48 | #define nRST_RF_PORT B | |
49 | #define nRST_RF_BIT 5 | |
50 | #define SLP_TR_PORT B | |
51 | #define SLP_TR_BIT 4 | |
52 | ||
53 | #define SCLK_PORT B | |
54 | #define SCLK_BIT 1 | |
55 | #define MOSI_PORT B | |
56 | #define MOSI_BIT 2 | |
57 | ||
58 | #define MISO_PORT B | |
59 | #define MISO_BIT 3 | |
60 | #define nSS_PORT B | |
61 | #define nSS_BIT 0 | |
62 | #define IRQ_RF_PORT D | |
63 | #define IRQ_RF_BIT 4 | |
64 | ||
65 | #define SPI_WAIT_DONE() while ((SPSR & (1 << SPIF)) == 0) | |
66 | #define SPI_DATA SPDR | |
67 | ||
25 | #include "board_rzusb.h" | |
68 | 26 | #endif |
69 | 27 | |
70 | 28 | #define SET_2(p, b) PORT##p |= 1 << (b) |
... | ... | |
121 | 79 | bool gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res); |
122 | 80 | void gpio_cleanup(void); |
123 | 81 | |
124 | void board_init(void); | |
82 | void get_sernum(void); | |
83 | ||
125 | 84 | void board_app_init(void); |
126 | 85 | |
127 | 86 | #endif /* !BOARD_H */ |
atusb/fw/board_atusb.c | ||
---|---|---|
1 | /* | |
2 | * fw/board_atusb.c - ATUSB Board-specific functions (for boot loader and application) | |
3 | * | |
4 | * Written 2016 by Stefan Schmidt | |
5 | * Copyright 2016 Stefan Schmidt | |
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 <stdbool.h> | |
15 | #include <stdint.h> | |
16 | ||
17 | #include <avr/io.h> | |
18 | #include <avr/interrupt.h> | |
19 | #include <avr/boot.h> | |
20 | ||
21 | #define F_CPU 8000000UL | |
22 | #include <util/delay.h> | |
23 | ||
24 | #include "usb.h" | |
25 | #include "at86rf230.h" | |
26 | #include "board.h" | |
27 | #include "spi.h" | |
28 | ||
29 | void set_clkm(void) | |
30 | { | |
31 | /* switch CLKM to 8 MHz */ | |
32 | ||
33 | /* | |
34 | * @@@ Note: Atmel advise against changing the external clock in | |
35 | * mid-flight. We should therefore switch to the RC clock first, then | |
36 | * crank up the external clock, and finally switch back to the external | |
37 | * clock. The clock switching procedure is described in the ATmega32U2 | |
38 | * data sheet in secton 8.2.2. | |
39 | */ | |
40 | spi_begin(); | |
41 | spi_send(AT86RF230_REG_WRITE | REG_TRX_CTRL_0); | |
42 | spi_send(CLKM_CTRL_8MHz); | |
43 | spi_end(); | |
44 | } | |
45 | ||
46 | void board_init(void) | |
47 | { | |
48 | /* Disable the watchdog timer */ | |
49 | ||
50 | MCUSR = 0; /* Remove override */ | |
51 | WDTCSR |= 1 << WDCE; /* Enable change */ | |
52 | WDTCSR = 1 << WDCE; /* Disable watchdog while still enabling | |
53 | change */ | |
54 | ||
55 | CLKPR = 1 << CLKPCE; | |
56 | /* We start with a 1 MHz/8 clock. Disable the prescaler. */ | |
57 | CLKPR = 0; | |
58 | ||
59 | get_sernum(); | |
60 | } |
atusb/fw/board_atusb.h | ||
---|---|---|
1 | /* | |
2 | * fw/board_atusb.h - ATUSB Board-specific functions and definitions | |
3 | * | |
4 | * Written 2016 by Stefan Schmidt | |
5 | * Copyright 2016 Stefan Schmidt | |
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 | #ifndef BOARD_ATUSB_H | |
14 | #define BOARD_ATUSB_H | |
15 | ||
16 | #include <stdbool.h> | |
17 | #include <stdint.h> | |
18 | ||
19 | #define LED_PORT B | |
20 | #define LED_BIT 6 | |
21 | #define nRST_RF_PORT C | |
22 | #define nRST_RF_BIT 7 | |
23 | #define SLP_TR_PORT B | |
24 | #define SLP_TR_BIT 4 | |
25 | ||
26 | #define SCLK_PORT D | |
27 | #define SCLK_BIT 5 | |
28 | #define MOSI_PORT D | |
29 | #define MOSI_BIT 3 | |
30 | ||
31 | #define MISO_PORT D | |
32 | #define MISO_BIT 2 | |
33 | #define nSS_PORT D | |
34 | #define nSS_BIT 1 | |
35 | #define IRQ_RF_PORT D | |
36 | #define IRQ_RF_BIT 0 | |
37 | ||
38 | #define SPI_WAIT_DONE() while (!(UCSR1A & 1 << RXC1)) | |
39 | #define SPI_DATA UDR1 | |
40 | ||
41 | void set_clkm(void); | |
42 | void board_init(void); | |
43 | ||
44 | #endif /* !BOARD_H */ |
atusb/fw/board_rzusb.c | ||
---|---|---|
1 | /* | |
2 | * fw/board_rzusb.c - RZUSB Board-specific functions (for boot loader and application) | |
3 | * | |
4 | * Written 2016 by Stefan Schmidt | |
5 | * Copyright 2016 Stefan Schmidt | |
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 <stdbool.h> | |
15 | #include <stdint.h> | |
16 | ||
17 | #include <avr/io.h> | |
18 | #include <avr/interrupt.h> | |
19 | #include <avr/boot.h> | |
20 | ||
21 | #define F_CPU 8000000UL | |
22 | #include <util/delay.h> | |
23 | ||
24 | #include "usb.h" | |
25 | #include "at86rf230.h" | |
26 | #include "board.h" | |
27 | #include "spi.h" | |
28 | ||
29 | void set_clkm(void) | |
30 | { | |
31 | /* switch CLKM to 8 MHz */ | |
32 | ||
33 | /* | |
34 | * @@@ Note: Atmel advise against changing the external clock in | |
35 | * mid-flight. We should therefore switch to the RC clock first, then | |
36 | * crank up the external clock, and finally switch back to the external | |
37 | * clock. The clock switching procedure is described in the ATmega32U2 | |
38 | * data sheet in secton 8.2.2. | |
39 | */ | |
40 | spi_begin(); | |
41 | spi_send(AT86RF230_REG_WRITE | REG_TRX_CTRL_0); | |
42 | spi_send(0x10); | |
43 | spi_end(); | |
44 | ||
45 | /* TX_AUTO_CRC_ON, default disabled */ | |
46 | spi_begin(); | |
47 | spi_send(AT86RF230_REG_WRITE | 0x05); | |
48 | spi_send(0x80); | |
49 | spi_end(); | |
50 | } | |
51 | ||
52 | void board_init(void) | |
53 | { | |
54 | /* Disable the watchdog timer */ | |
55 | ||
56 | MCUSR = 0; /* Remove override */ | |
57 | WDTCSR |= 1 << WDCE; /* Enable change */ | |
58 | WDTCSR = 1 << WDCE; /* Disable watchdog while still enabling | |
59 | change */ | |
60 | ||
61 | CLKPR = 1 << CLKPCE; | |
62 | /* We start with a 16 MHz/8 clock. Put the prescaler to 2. */ | |
63 | CLKPR = 1 << CLKPS0; | |
64 | ||
65 | get_sernum(); | |
66 | } |
atusb/fw/board_rzusb.h | ||
---|---|---|
1 | /* | |
2 | * fw/board_rzusb.h - RZUSB Board-specific functions and definitions | |
3 | * | |
4 | * Written 2016 by Stefan Schmidt | |
5 | * Copyright 2016 Stefan Schmidt | |
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 | #ifndef BOARD_RZUSB_H | |
14 | #define BOARD_RZUSB_H | |
15 | ||
16 | #include <stdbool.h> | |
17 | #include <stdint.h> | |
18 | ||
19 | #define LED_PORT D | |
20 | #define LED_BIT 7 | |
21 | #define nRST_RF_PORT B | |
22 | #define nRST_RF_BIT 5 | |
23 | #define SLP_TR_PORT B | |
24 | #define SLP_TR_BIT 4 | |
25 | ||
26 | #define SCLK_PORT B | |
27 | #define SCLK_BIT 1 | |
28 | #define MOSI_PORT B | |
29 | #define MOSI_BIT 2 | |
30 | ||
31 | #define MISO_PORT B | |
32 | #define MISO_BIT 3 | |
33 | #define nSS_PORT B | |
34 | #define nSS_BIT 0 | |
35 | #define IRQ_RF_PORT D | |
36 | #define IRQ_RF_BIT 4 | |
37 | ||
38 | #define SPI_WAIT_DONE() while ((SPSR & (1 << SPIF)) == 0) | |
39 | #define SPI_DATA SPDR | |
40 | ||
41 | void set_clkm(void); | |
42 | void board_init(void); | |
43 | ||
44 | #endif /* !BOARD_H */ |