Subversion Repositories svnkaklik

Compare Revisions

No changes between revisions

Ignore whitespace Rev 566 → Rev 567

/programy/C/avr/tests/ATmega168/uart/default/Makefile
0,0 → 1,78
###############################################################################
# Makefile for the project main
###############################################################################
 
## General Flags
PROJECT = main
MCU = atmega168
TARGET = main.elf
CC = avr-gcc.exe
 
## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
 
## Compile options common for all C compilation units.
CFLAGS = $(COMMON)
CFLAGS += -Wall -gdwarf-2 -std=gnu99 -DF_CPU=14318180UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d
 
## Assembly specific flags
ASMFLAGS = $(COMMON)
ASMFLAGS += $(CFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
 
## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS += -Wl,-Map=main.map
 
 
## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom
 
HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
 
 
## Objects that must be built in order to link
OBJECTS = main.o uart.o
 
## Objects explicitly added by the user
LINKONLYOBJECTS =
 
## Build
all: $(TARGET) main.hex main.eep main.lss size
 
## Compile
main.o: ../main.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
 
uart.o: ../uart.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
 
##Link
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)
 
%.hex: $(TARGET)
avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
 
%.eep: $(TARGET)
-avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0
 
%.lss: $(TARGET)
avr-objdump -h -S $< > $@
 
size: ${TARGET}
@echo
@avr-size -C --mcu=${MCU} ${TARGET}
 
## Clean target
.PHONY: clean
clean:
-rm -rf $(OBJECTS) main.elf dep/* main.hex main.eep main.lss main.map
 
 
## Other dependencies
-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*)
 
/programy/C/avr/tests/ATmega168/uart/default/main.elf
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/programy/C/avr/tests/ATmega168/uart/main.aps
0,0 → 1,0
<AVRStudio><MANAGEMENT><ProjectName>main</ProjectName><Created>27-Apr-2008 13:39:11</Created><LastEdit>27-Apr-2008 15:20:23</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>27-Apr-2008 13:39:11</Created><Version>4</Version><Build>4, 14, 0, 589</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\main.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>D:\KAKLIK\projekty\programy\C\avr\tests\ATmega168\uart\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>ICE50</CURRENT_TARGET><CURRENT_PART>ATmega168.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>main.c</SOURCEFILE><SOURCEFILE>uart.c</SOURCEFILE><HEADERFILE>uart.h</HEADERFILE><OTHERFILE>default\main.lss</OTHERFILE><OTHERFILE>default\main.map</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>atmega168</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>main.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>0</ISDIRTY><OPTIONS/><INCDIRS/><LIBDIRS/><LIBS/><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -std=gnu99 -DF_CPU=14318180UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums</OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\Program Files\WinAVR\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\Program Files\WinAVR\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><IOView><usergroups/><sort sorted="0" column="0" ordername="0" orderaddress="0" ordergroup="0"/></IOView><Files><File00000><FileId>00000</FileId><FileName>main.c</FileName><Status>1</Status></File00000><File00001><FileId>00001</FileId><FileName>uart.c</FileName><Status>1</Status></File00001><File00002><FileId>00002</FileId><FileName>uart.h</FileName><Status>1</Status></File00002></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>
/programy/C/avr/tests/ATmega168/uart/main.aws
0,0 → 1,0
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA168"/><Files/></AVRWorkspace>
/programy/C/avr/tests/ATmega168/uart/main.c
0,0 → 1,27
 
 
#include <string.h>
#include <avr/pgmspace.h>
#include <avr/sleep.h>
#include "uart.h"
 
 
int main()
{
/* we will just use ordinary idle mode */
// set_sleep_mode(SLEEP_MODE_IDLE);
 
/* setup uart */
uart_init();
 
/* setup sd card slot */
while(1)
{
uart_puts_p(PSTR("test000000000000000"));
}
 
return 1;
}
 
 
 
/programy/C/avr/tests/ATmega168/uart/uart.c
0,0 → 1,198
 
/*
* Copyright (c) 2006-2007 by Roland Riegel <feedback@roland-riegel.de>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
 
#include <stdio.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/sfr_defs.h>
#include <avr/sleep.h>
 
#include "uart.h"
 
/* some mcus have multiple uarts */
#ifdef UDR0
#define UBRRH UBRR0H
#define UBRRL UBRR0L
#define UDR UDR0
 
#define UCSRA UCSR0A
#define UDRE UDRE0
#define RXC RXC0
 
#define UCSRB UCSR0B
#define RXEN RXEN0
#define TXEN TXEN0
#define RXCIE RXCIE0
 
#define UCSRC UCSR0C
#define URSEL
#define UCSZ0 UCSZ00
#define UCSZ1 UCSZ01
#define UCSRC_SELECT 0
#else
#define UCSRC_SELECT (1 << URSEL)
#endif
 
#ifndef USART_RXC_vect
#if defined(UART0_RX_vect)
#define USART_RXC_vect UART0_RX_vect
#elif defined(UART_RX_vect)
#define USART_RXC_vect UART_RX_vect
#elif defined(USART0_RX_vect)
#define USART_RXC_vect USART0_RX_vect
#elif defined(USART_RX_vect)
#define USART_RXC_vect USART_RX_vect
#elif defined(USART0_RXC_vect)
#define USART_RXC_vect USART0_RXC_vect
#elif defined(USART_RXC_vect)
#define USART_RXC_vect USART_RXC_vect
#else
#error "Uart receive complete interrupt not defined!"
#endif
#endif
 
#define BAUD 9600UL
#define UBRRVAL (F_CPU/(BAUD*16)-1)
#define USE_SLEEP 1
 
void uart_init()
{
/* set baud rate */
UBRRH = UBRRVAL >> 8;
UBRRL = UBRRVAL & 0xff;
/* set frame format: 8 bit, no parity, 1 bit */
UCSRC = UCSRC_SELECT | (1 << UCSZ1) | (1 << UCSZ0);
/* enable serial receiver and transmitter */
#if !USE_SLEEP
UCSRB = (1 << RXEN) | (1 << TXEN);
#else
UCSRB = (1 << RXEN) | (1 << TXEN) | (1 << RXCIE);
#endif
}
 
void uart_putc(uint8_t c)
{
if(c == '\n')
uart_putc('\r');
 
/* wait until transmit buffer is empty */
while(!(UCSRA & (1 << UDRE)));
 
/* send next byte */
UDR = c;
}
 
void uart_putc_hex(uint8_t b)
{
/* upper nibble */
if((b >> 4) < 0x0a)
uart_putc((b >> 4) + '0');
else
uart_putc((b >> 4) - 0x0a + 'a');
 
/* lower nibble */
if((b & 0x0f) < 0x0a)
uart_putc((b & 0x0f) + '0');
else
uart_putc((b & 0x0f) - 0x0a + 'a');
}
 
void uart_putw_hex(uint16_t w)
{
uart_putc_hex((uint8_t) (w >> 8));
uart_putc_hex((uint8_t) (w & 0xff));
}
 
void uart_putdw_hex(uint32_t dw)
{
uart_putw_hex((uint16_t) (dw >> 16));
uart_putw_hex((uint16_t) (dw & 0xffff));
}
 
void uart_putw_dec(uint16_t w)
{
uint16_t num = 10000;
uint8_t started = 0;
 
while(num > 0)
{
uint8_t b = w / num;
if(b > 0 || started || num == 1)
{
uart_putc('0' + b);
started = 1;
}
w -= b * num;
 
num /= 10;
}
}
 
void uart_putdw_dec(uint32_t dw)
{
uint32_t num = 1000000000;
uint8_t started = 0;
 
while(num > 0)
{
uint8_t b = dw / num;
if(b > 0 || started || num == 1)
{
uart_putc('0' + b);
started = 1;
}
dw -= b * num;
 
num /= 10;
}
}
 
void uart_puts(const char* str)
{
while(*str)
uart_putc(*str++);
}
 
void uart_puts_p(PGM_P str)
{
while(1)
{
uint8_t b = pgm_read_byte_near(str++);
if(!b)
break;
 
uart_putc(b);
}
}
 
uint8_t uart_getc()
{
/* wait until receive buffer is full */
#if USE_SLEEP
uint8_t sreg = SREG;
sei();
 
while(!(UCSRA & (1 << RXC)))
sleep_mode();
 
SREG = sreg;
#else
while(!(UCSRA & (1 << RXC)));
#endif
 
uint8_t b = UDR;
if(b == '\r')
b = '\n';
 
return b;
}
 
EMPTY_INTERRUPT(USART_RXC_vect)
 
/programy/C/avr/tests/ATmega168/uart/uart.h
0,0 → 1,33
 
/*
* Copyright (c) 2006-2007 by Roland Riegel <feedback@roland-riegel.de>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
 
#ifndef UART_H
#define UART_H
 
#include <stdint.h>
#include <avr/pgmspace.h>
 
void uart_init();
 
void uart_putc(uint8_t c);
 
void uart_putc_hex(uint8_t b);
void uart_putw_hex(uint16_t w);
void uart_putdw_hex(uint32_t dw);
 
void uart_putw_dec(uint16_t w);
void uart_putdw_dec(uint32_t dw);
 
void uart_puts(const char* str);
void uart_puts_p(PGM_P str);
 
uint8_t uart_getc();
 
#endif