IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Commit Details
| Date: | 2017-09-11 13:58:32 (6 years 3 months ago) |
|---|---|
| Author: | Josef Filzmaier |
| Commit: | 8c574484b889c7b17d2ba4b6929947050f87d91e |
| Message: | atusb/fw: Introduce DEBUG flag This flag can be used to enable debugging over uart. Currently only available for boards with the at90usb1287 chip. Signed-off-by: Josef Filzmaier <j.filzmaier@gmx.at> |
| Files: |
atusb/fw/Makefile (3 diffs) atusb/fw/atusb.c (2 diffs) atusb/fw/ep0.c (1 diff) atusb/fw/uart.c (1 diff) atusb/fw/uart.h (1 diff) |
Change Details
| atusb/fw/Makefile | ||
|---|---|---|
| 1 | 1 | # |
| 2 | # Makefile - Makefile of the ATUSB firmware | |
| 2 | # Makefile - Makefile of the ATUSB firmware | |
| 3 | 3 | # |
| 4 | 4 | # Written 2010-2011, 2013 by Werner Almesberger |
| 5 | 5 | # Copyright 2010-2011, 2013 by Werner Almesberger |
| ... | ... | |
| 13 | 13 | SHELL = /bin/bash |
| 14 | 14 | |
| 15 | 15 | NAME = atusb |
| 16 | DEBUG = false | |
| 16 | 17 | |
| 17 | 18 | CFLAGS = -g -mmcu=$(CHIP) -DBOOT_ADDR=$(BOOT_ADDR) \ |
| 18 | 19 | -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \ |
| 19 | 20 | -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes |
| 20 | 21 | |
| 22 | ifeq ($(DEBUG),true) | |
| 23 | CFLAGS += -DDEBUG | |
| 24 | endif | |
| 25 | ||
| 21 | 26 | ifeq ($(NAME),rzusb) |
| 22 | 27 | CHIP=at90usb1287 |
| 23 | 28 | CFLAGS += -DRZUSB -DAT86RF230 |
| ... | ... | |
| 46 | 51 | BOOT_OBJS = boot.o board.o sernum.o spi.o flash.o dfu.o \ |
| 47 | 52 | dfu_common.o usb.o boot-atu2.o |
| 48 | 53 | |
| 54 | ifeq ($(DEBUG),true) | |
| 55 | OBJS += uart.o | |
| 56 | endif | |
| 49 | 57 | |
| 50 | 58 | ifeq ($(NAME),rzusb) |
| 51 | 59 | OBJS += board_rzusb.o |
| atusb/fw/atusb.c | ||
|---|---|---|
| 24 | 24 | #include "spi.h" |
| 25 | 25 | #include "atusb/ep0.h" |
| 26 | 26 | |
| 27 | #ifdef DEBUG | |
| 28 | #include "uart.h" | |
| 29 | #endif | |
| 30 | ||
| 27 | 31 | |
| 28 | 32 | int main(void) |
| 29 | 33 | { |
| ... | ... | |
| 35 | 39 | |
| 36 | 40 | /* now we should be at 8 MHz */ |
| 37 | 41 | |
| 42 | #ifdef DEBUG | |
| 43 | uart_init(); | |
| 44 | static FILE atben_stdout = FDEV_SETUP_STREAM(uart_write_char, NULL, | |
| 45 | _FDEV_SETUP_WRITE); | |
| 46 | stdout = &atben_stdout; | |
| 47 | #endif | |
| 48 | ||
| 38 | 49 | usb_init(); |
| 39 | 50 | ep0_init(); |
| 40 | 51 | #ifdef ATUSB |
| atusb/fw/ep0.c | ||
|---|---|---|
| 45 | 45 | #define HW_TYPE HW_TYPE_RZUSB |
| 46 | 46 | #endif |
| 47 | 47 | |
| 48 | #ifdef DEBUG | |
| 49 | #include "uart.h" | |
| 50 | #include <stdio.h> | |
| 51 | #define debug(FORMAT,args...) printf(FORMAT,##args) | |
| 52 | #define error(FORMAT,args...) printf(FORMAT,##args) | |
| 53 | #else | |
| 48 | 54 | #define debug(...) |
| 49 | 55 | #define error(...) |
| 56 | #endif | |
| 50 | 57 | |
| 51 | 58 | |
| 52 | 59 | static const uint8_t id[] = { EP0ATUSB_MAJOR, EP0ATUSB_MINOR, HW_TYPE }; |
| atusb/fw/uart.c | ||
|---|---|---|
| 1 | /* | |
| 2 | * fw/uart.h - Functions needed for debugging over uart | |
| 3 | * | |
| 4 | * Code adapted from http://www.roboternetz.de/wissen/index.php/UART_mit_avr-gcc | |
| 5 | * and http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial | |
| 6 | * | |
| 7 | * Published under the Creative Commons Share-Alike licence | |
| 8 | * https://creativecommons.org/licenses/by-sa/2.0/de/ | |
| 9 | * | |
| 10 | * S. Salewski 2007 | |
| 11 | * | |
| 12 | * Adapted by | |
| 13 | * Josef Filzmaier 2017 | |
| 14 | */ | |
| 15 | ||
| 16 | #include <avr/io.h> | |
| 17 | #include "uart.h" | |
| 18 | ||
| 19 | #define USART_BAUD 38400UL | |
| 20 | #define F_CPU 8000000UL | |
| 21 | ||
| 22 | #define Wait_USART_Ready() while (!(UCSR1A & (1<<UDRE1))) | |
| 23 | #define UART_UBRR (F_CPU/(16L*USART_BAUD)-1) | |
| 24 | ||
| 25 | // initialize USART, 8N1 mode | |
| 26 | void | |
| 27 | uart_init(void) | |
| 28 | { | |
| 29 | /* TODO: Find a working configuration for uart for the atmega32u2 */ | |
| 30 | #if CHIP == at90usb1287 | |
| 31 | CLKPR = (1 << CLKPCE); | |
| 32 | CLKPR = 0; // clock prescaler == 0, so we have 16 MHz mpu frequency | |
| 33 | UBRR1 = UART_UBRR; | |
| 34 | UCSR1C = (1 << UCSZ10) | (1 << UCSZ11); | |
| 35 | UCSR1B = (1 << TXEN1); | |
| 36 | do | |
| 37 | { | |
| 38 | UDR1; | |
| 39 | } | |
| 40 | while (UCSR1A & (1 << RXC1)); | |
| 41 | #endif | |
| 42 | ||
| 43 | } | |
| 44 | ||
| 45 | int uart_write_char(char c, FILE* stream) | |
| 46 | { | |
| 47 | if (c == '\n'){ | |
| 48 | uart_new_line(); | |
| 49 | } | |
| 50 | else { | |
| 51 | Wait_USART_Ready(); | |
| 52 | UDR1 = c; | |
| 53 | } | |
| 54 | return 0; | |
| 55 | } | |
| 56 | ||
| 57 | void | |
| 58 | uart_new_line(void) | |
| 59 | { | |
| 60 | Wait_USART_Ready(); | |
| 61 | UDR1 = '\r'; | |
| 62 | Wait_USART_Ready(); | |
| 63 | UDR1 = '\n'; | |
| 64 | } | |
| atusb/fw/uart.h | ||
|---|---|---|
| 1 | /* | |
| 2 | * fw/uart.h - Functions needed for debugging over uart | |
| 3 | * | |
| 4 | * Code adapted from http://www.roboternetz.de/wissen/index.php/UART_mit_avr-gcc | |
| 5 | * and http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial | |
| 6 | * | |
| 7 | * Published under the Creative Commons Share-Alike licence | |
| 8 | * https://creativecommons.org/licenses/by-sa/2.0/de/ | |
| 9 | * | |
| 10 | * S. Salewski 2007 | |
| 11 | * | |
| 12 | * Adapted by | |
| 13 | * Josef Filzmaier 2017 | |
| 14 | */ | |
| 15 | ||
| 16 | #ifndef UART_H_ | |
| 17 | #define UART_H_ | |
| 18 | ||
| 19 | #include <stdio.h> | |
| 20 | ||
| 21 | void uart_init(void); | |
| 22 | int uart_write_char(char c, FILE* stream); | |
| 23 | void uart_new_line(void); | |
| 24 | ||
| 25 | #endif /* UART_H_ */ | |
