Участник:Vooon/crumb128/usb — различия между версиями
Vooon (обсуждение | вклад) (Новая: == Project tree == {{#tree:openlevels=2| *./ **doc **includes ***portpc.h ***portpc.cpp **main.h **main.cpp **Makefile **Doxyfile }}) |
Vooon (обсуждение | вклад) м |
||
| (не показана 1 промежуточная версия этого же участника) | |||
| Строка 1: | Строка 1: | ||
| − | + | __FORCETOC__ | |
== Project tree == | == Project tree == | ||
{{#tree:openlevels=2| | {{#tree:openlevels=2| | ||
*./ | *./ | ||
**doc | **doc | ||
| + | ***html | ||
| + | ****doxygen-html | ||
| + | ***latex | ||
| + | ****doxygen-latex | ||
**includes | **includes | ||
***portpc.h | ***portpc.h | ||
| Строка 12: | Строка 16: | ||
**Doxyfile | **Doxyfile | ||
}} | }} | ||
| + | |||
| + | == ./ == | ||
| + | === includes === | ||
| + | ==== portpc.h ==== | ||
| + | <source lang="cpp"> | ||
| + | /** | ||
| + | * \file portpc.h | ||
| + | * \version PortPC.h, v 0.0.1 01/10/2007 21:20 vovan | ||
| + | * \defgroup port_pc <portpc.h>: Соединение с ПК | ||
| + | * \code #include "portpc.h" \endcode | ||
| + | */ | ||
| + | |||
| + | /** | ||
| + | */ | ||
| + | #ifndef PORTPC_H | ||
| + | #define PORTPC_H | ||
| + | |||
| + | #include <avr/io.h> | ||
| + | #include <inttypes.h> | ||
| + | |||
| + | /** | ||
| + | * \ingroup port_pc | ||
| + | * Скорость обмена с ПК | ||
| + | */ | ||
| + | /*[[[cog | ||
| + | import cog | ||
| + | pc_baud = 115200 | ||
| + | f_cpu = int(f_cpu) | ||
| + | cog.outl( "#define PC_BAUD %s" % pc_baud ) | ||
| + | ]]]*/ | ||
| + | #define PC_BAUD 115200 | ||
| + | //[[[end]]] (checksum: 515e903dc784c9393118884a663d767e) | ||
| + | |||
| + | /** | ||
| + | * \ingroup port_pc | ||
| + | * Формула для расчета значения делителя | ||
| + | */ | ||
| + | /*[[[cog | ||
| + | pc_ubrr = int((f_cpu/(pc_baud*16)) - 1) | ||
| + | pc_real_baud = int(f_cpu / (16 * (pc_ubrr + 1))) | ||
| + | pc_baud_error = ((float(pc_real_baud)/float(pc_baud) - 1.0) * 100.0) | ||
| + | |||
| + | if pc_baud_error != 0 and pc_baud_error < 2: | ||
| + | cog.msg( "WARNING: pc baudrate error: %s%%" % pc_baud_error ) | ||
| + | if pc_baud_error > 2: | ||
| + | cog.error( "pc baudrate error: %s%%" % pc_baud_error ) | ||
| + | |||
| + | cog.outl( "#define PC_UBRR %s" % pc_ubrr ) | ||
| + | cog.outl( "#define PC_UBRRH %s" % (pc_ubrr>>8) ) | ||
| + | cog.outl( "#define PC_UBRRL %s" % (0xff & pc_ubrr) ) | ||
| + | cog.outl( "#define PC_REAL_BAUD %s" % pc_real_baud ) | ||
| + | cog.outl( "#define PC_BAUD_ERR %s" % pc_baud_error ) | ||
| + | ]]]*/ | ||
| + | #define PC_UBRR 7 | ||
| + | #define PC_UBRRH 0 | ||
| + | #define PC_UBRRL 7 | ||
| + | #define PC_REAL_BAUD 115200 | ||
| + | #define PC_BAUD_ERR 0.0 | ||
| + | //[[[end]]] (checksum: 357c9b7125d3f4a2fca94deb9d6e94ea) | ||
| + | |||
| + | /** | ||
| + | * \ingroup port_pc | ||
| + | */ | ||
| + | |||
| + | class port_pc { | ||
| + | public: | ||
| + | void init(void); | ||
| + | void proc(void); | ||
| + | char is_char_available(void); | ||
| + | char receive_char(void); | ||
| + | void send_char(char data); | ||
| + | }; | ||
| + | |||
| + | #endif // PORTPC_H | ||
| + | </source> | ||
| + | |||
| + | ==== portpc.cpp ==== | ||
| + | <source lang="cpp"> | ||
| + | /** | ||
| + | * \file portpc.c | ||
| + | * \version PortPC.c, v 0.0.1 01/10/2007 21:21 vovan | ||
| + | */ | ||
| + | |||
| + | #include <avr/io.h> | ||
| + | #include <inttypes.h> | ||
| + | |||
| + | #include "portpc.h" | ||
| + | |||
| + | /* | ||
| + | * Настройка USART | ||
| + | */ | ||
| + | void port_pc::init(void) | ||
| + | { | ||
| + | UBRR1L = PC_UBRRL; | ||
| + | UBRR1H = PC_UBRRH; | ||
| + | UCSR1C = (1<<UCSZ11) | (1<<UCSZ10); // 8N1 | ||
| + | UCSR1B = (1<<RXEN1) | (1<<TXEN1); | ||
| + | }; | ||
| + | |||
| + | void port_pc::proc(void) | ||
| + | { | ||
| + | while(!is_char_available()); | ||
| + | send_char(receive_char()); | ||
| + | }; | ||
| + | |||
| + | // | ||
| + | //- stdio foo ----------------------------------------------------------------- | ||
| + | // | ||
| + | |||
| + | char port_pc::is_char_available(void) | ||
| + | { | ||
| + | // Does the RX0 bit of the USART Status and Control Register | ||
| + | // indicate a char has been received? | ||
| + | if ( (UCSR1A & _BV(RXC1)) ) return 1; | ||
| + | else return 0; | ||
| + | }; | ||
| + | |||
| + | char port_pc::receive_char(void) | ||
| + | { | ||
| + | // Return the char in the UDR0 register | ||
| + | return UDR1; | ||
| + | }; | ||
| + | |||
| + | void port_pc::send_char(char data) | ||
| + | { | ||
| + | int i = 0; | ||
| + | // To send data with the USART put the data in the USART data register | ||
| + | UDR1 = data; | ||
| + | // Check to see if the global interrupts are enabled | ||
| + | if(SREG & 0x80) | ||
| + | { | ||
| + | // Wait until the byte is sent or we count out | ||
| + | while ( !(UCSR1A & _BV(TXC1)) && (i < 10000) ) | ||
| + | { | ||
| + | i++; | ||
| + | } | ||
| + | } | ||
| + | else // Wait until the byte is sent | ||
| + | while( !(UCSR1A & _BV(TXC1)) ); | ||
| + | // Clear the TXCflag | ||
| + | UCSR1A = UCSR1A | _BV(TXC1); | ||
| + | }; | ||
| + | </source> | ||
| + | |||
| + | === Makefile === | ||
| + | <source lang="bash"> | ||
| + | # output filename | ||
| + | program_name := main | ||
| + | # source directories ('.' - current dir) | ||
| + | #source_dirs := . | ||
| + | source_dirs := . includes | ||
| + | #source_dirs := $(addprefix ../,$(source_dirs)) | ||
| + | |||
| + | # uC type | ||
| + | mcu := atmega128 | ||
| + | # CPU freq | ||
| + | f_cpu := 14745600 | ||
| + | |||
| + | # compiler flags | ||
| + | cpflags := -mmcu=$(mcu) -Wall -g -O2 -DF_CPU=$(f_cpu) | ||
| + | # linker flags | ||
| + | ldflags := -mmcu=$(mcu) -Wl | ||
| + | |||
| + | #- do not need to edit ---------------------------------------------- | ||
| + | rm := rm -rf | ||
| + | cog := cog.py -cr -D f_cpu=$(f_cpu) | ||
| + | # compiller | ||
| + | cc := avr-g++ | ||
| + | cclog := compile.log | ||
| + | # avr-objcopy | ||
| + | objcpy := avr-objcopy | ||
| + | # doxygen | ||
| + | doxygen := doxygen | ||
| + | doxylog := doxygen.log | ||
| + | |||
| + | search_wildcards := $(addsuffix /*.cpp,$(source_dirs)) | ||
| + | |||
| + | $(addsuffix .out,$(program_name)): cog all | ||
| + | |||
| + | all: $(notdir $(patsubst %.cpp,%.o, $(wildcard $(search_wildcards) ) ) ) | ||
| + | $(cc) $(ldflags) $^ -o $(addsuffix .out,$(program_name)) 2>>$(cclog) | ||
| + | $(objcpy) -R.eeprom -O ihex $(addsuffix .out,$(program_name)) $(addsuffix .hex,$(program_name)) 2>>$(cclog) | ||
| + | $(doxygen) 2>> $(doxylog) | ||
| + | |||
| + | VPATH := $(source_dirs) | ||
| + | |||
| + | %.o: %.cpp | ||
| + | $(cc) $(cpflags) $(addprefix -I,$(source_dirs)) -MD -c $< 2>>$(cclog) | ||
| + | |||
| + | cog: | ||
| + | $(cog) $(addprefix -I,$(source_dirs)) $(addsuffix /*.cpp,$(source_dirs)) $(addsuffix /*.h,$(source_dirs)) | ||
| + | |||
| + | include $(wildcard *.d) | ||
| + | |||
| + | upload: | ||
| + | uisp -dprog=abb -dlpt=/dev/parport0 --erase --upload --verify if=./$(addsuffix .hex,$(program_name)) | ||
| + | |||
| + | clean: | ||
| + | $(rm) $(addsuffix .out,$(program_name)) $(addsuffix .hex,$(program_name)) *.d *.o *.hex $(cclog) $(doxylog) doc | ||
| + | $(cog) $(addprefix -I,$(source_dirs)) -x $(addsuffix /*.cpp,$(source_dirs)) $(addsuffix /*.h,$(source_dirs)) | ||
| + | </source> | ||
Текущая версия на 16:19, 17 октября 2007
Project tree
{{#tree:openlevels=2|
- ./
- doc
- html
- doxygen-html
- latex
- doxygen-latex
- html
- includes
- portpc.h
- portpc.cpp
- main.h
- main.cpp
- Makefile
- Doxyfile
- doc
}}
./
includes
portpc.h
<source lang="cpp"> /**
* \file portpc.h * \version PortPC.h, v 0.0.1 01/10/2007 21:20 vovan * \defgroup port_pc <portpc.h>: Соединение с ПК * \code #include "portpc.h" \endcode */
/**
*/
- ifndef PORTPC_H
- define PORTPC_H
- include <avr/io.h>
- include <inttypes.h>
/**
* \ingroup port_pc * Скорость обмена с ПК */
/*[[[cog import cog pc_baud = 115200 f_cpu = int(f_cpu) cog.outl( "#define PC_BAUD %s" % pc_baud ) ]]]*/
- define PC_BAUD 115200
//[[[end]]] (checksum: 515e903dc784c9393118884a663d767e)
/**
* \ingroup port_pc * Формула для расчета значения делителя */
/*[[[cog pc_ubrr = int((f_cpu/(pc_baud*16)) - 1) pc_real_baud = int(f_cpu / (16 * (pc_ubrr + 1))) pc_baud_error = ((float(pc_real_baud)/float(pc_baud) - 1.0) * 100.0)
if pc_baud_error != 0 and pc_baud_error < 2: cog.msg( "WARNING: pc baudrate error: %s%%" % pc_baud_error ) if pc_baud_error > 2: cog.error( "pc baudrate error: %s%%" % pc_baud_error )
cog.outl( "#define PC_UBRR %s" % pc_ubrr ) cog.outl( "#define PC_UBRRH %s" % (pc_ubrr>>8) ) cog.outl( "#define PC_UBRRL %s" % (0xff & pc_ubrr) ) cog.outl( "#define PC_REAL_BAUD %s" % pc_real_baud ) cog.outl( "#define PC_BAUD_ERR %s" % pc_baud_error ) ]]]*/
- define PC_UBRR 7
- define PC_UBRRH 0
- define PC_UBRRL 7
- define PC_REAL_BAUD 115200
- define PC_BAUD_ERR 0.0
//[[[end]]] (checksum: 357c9b7125d3f4a2fca94deb9d6e94ea)
/**
* \ingroup port_pc */
class port_pc { public: void init(void); void proc(void); char is_char_available(void); char receive_char(void); void send_char(char data); };
- endif // PORTPC_H
</source>
portpc.cpp
<source lang="cpp"> /**
* \file portpc.c * \version PortPC.c, v 0.0.1 01/10/2007 21:21 vovan */
- include <avr/io.h>
- include <inttypes.h>
- include "portpc.h"
/*
* Настройка USART */
void port_pc::init(void) { UBRR1L = PC_UBRRL; UBRR1H = PC_UBRRH; UCSR1C = (1<<UCSZ11) | (1<<UCSZ10); // 8N1 UCSR1B = (1<<RXEN1) | (1<<TXEN1); };
void port_pc::proc(void) { while(!is_char_available()); send_char(receive_char()); };
// //- stdio foo ----------------------------------------------------------------- //
char port_pc::is_char_available(void) {
// Does the RX0 bit of the USART Status and Control Register
// indicate a char has been received?
if ( (UCSR1A & _BV(RXC1)) ) return 1; else return 0; };
char port_pc::receive_char(void) {
// Return the char in the UDR0 register
return UDR1; };
void port_pc::send_char(char data) { int i = 0;
// To send data with the USART put the data in the USART data register
UDR1 = data;
// Check to see if the global interrupts are enabled
if(SREG & 0x80) {
// Wait until the byte is sent or we count out
while ( !(UCSR1A & _BV(TXC1)) && (i < 10000) ) { i++; } } else // Wait until the byte is sent while( !(UCSR1A & _BV(TXC1)) );
// Clear the TXCflag
UCSR1A = UCSR1A | _BV(TXC1); }; </source>
Makefile
<source lang="bash">
- output filename
program_name := main
- source directories ('.' - current dir)
- source_dirs := .
source_dirs := . includes
- source_dirs := $(addprefix ../,$(source_dirs))
- uC type
mcu := atmega128
- CPU freq
f_cpu := 14745600
- compiler flags
cpflags := -mmcu=$(mcu) -Wall -g -O2 -DF_CPU=$(f_cpu)
- linker flags
ldflags := -mmcu=$(mcu) -Wl
- - do not need to edit ----------------------------------------------
rm := rm -rf cog := cog.py -cr -D f_cpu=$(f_cpu)
- compiller
cc := avr-g++ cclog := compile.log
- avr-objcopy
objcpy := avr-objcopy
- doxygen
doxygen := doxygen doxylog := doxygen.log
search_wildcards := $(addsuffix /*.cpp,$(source_dirs))
$(addsuffix .out,$(program_name)): cog all
all: $(notdir $(patsubst %.cpp,%.o, $(wildcard $(search_wildcards) ) ) ) $(cc) $(ldflags) $^ -o $(addsuffix .out,$(program_name)) 2>>$(cclog) $(objcpy) -R.eeprom -O ihex $(addsuffix .out,$(program_name)) $(addsuffix .hex,$(program_name)) 2>>$(cclog) $(doxygen) 2>> $(doxylog)
VPATH := $(source_dirs)
%.o: %.cpp $(cc) $(cpflags) $(addprefix -I,$(source_dirs)) -MD -c $< 2>>$(cclog)
cog: $(cog) $(addprefix -I,$(source_dirs)) $(addsuffix /*.cpp,$(source_dirs)) $(addsuffix /*.h,$(source_dirs))
include $(wildcard *.d)
upload: uisp -dprog=abb -dlpt=/dev/parport0 --erase --upload --verify if=./$(addsuffix .hex,$(program_name))
clean: $(rm) $(addsuffix .out,$(program_name)) $(addsuffix .hex,$(program_name)) *.d *.o *.hex $(cclog) $(doxylog) doc $(cog) $(addprefix -I,$(source_dirs)) -x $(addsuffix /*.cpp,$(source_dirs)) $(addsuffix /*.h,$(source_dirs)) </source>