initial
This commit is contained in:
commit
3b0e8e4dec
76
.cproject
Normal file
76
.cproject
Normal file
@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?>
|
||||
|
||||
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
<cconfiguration id="de.innot.avreclipse.configuration.app.release.662345902">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="de.innot.avreclipse.configuration.app.release.662345902" moduleId="org.eclipse.cdt.core.settings" name="Release">
|
||||
<externalSettings/>
|
||||
<extensions>
|
||||
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||
<extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
</extensions>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<configuration artifactName="${ProjName}" buildArtefactType="de.innot.avreclipse.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=de.innot.avreclipse.buildArtefactType.app" description="" id="de.innot.avreclipse.configuration.app.release.662345902" name="Release" parent="de.innot.avreclipse.configuration.app.release">
|
||||
<folderInfo id="de.innot.avreclipse.configuration.app.release.662345902." name="/" resourcePath="">
|
||||
<toolChain id="de.innot.avreclipse.toolchain.winavr.app.release.1853754211" name="AVR-GCC Toolchain" superClass="de.innot.avreclipse.toolchain.winavr.app.release">
|
||||
<option id="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.release.377021338" name="Generate HEX file for Flash memory" superClass="de.innot.avreclipse.toolchain.options.toolchain.objcopy.flash.app.release"/>
|
||||
<option id="de.innot.avreclipse.toolchain.options.toolchain.objcopy.eeprom.app.release.202284040" name="Generate HEX file for EEPROM" superClass="de.innot.avreclipse.toolchain.options.toolchain.objcopy.eeprom.app.release"/>
|
||||
<option id="de.innot.avreclipse.toolchain.options.toolchain.objdump.app.release.2059755902" name="Generate Extended Listing (Source + generated Assembler)" superClass="de.innot.avreclipse.toolchain.options.toolchain.objdump.app.release"/>
|
||||
<option id="de.innot.avreclipse.toolchain.options.toolchain.size.app.release.581707062" name="Print Size" superClass="de.innot.avreclipse.toolchain.options.toolchain.size.app.release"/>
|
||||
<option id="de.innot.avreclipse.toolchain.options.toolchain.avrdude.app.release.1118478761" name="AVRDude" superClass="de.innot.avreclipse.toolchain.options.toolchain.avrdude.app.release"/>
|
||||
<targetPlatform id="de.innot.avreclipse.targetplatform.winavr.app.release.1575568079" name="AVR Cross-Target" superClass="de.innot.avreclipse.targetplatform.winavr.app.release"/>
|
||||
<builder buildPath="${workspace_loc:/MyClock/Release}" id="de.innot.avreclipse.target.builder.winavr.app.release.1607328661" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="AVR GNU Make Builder" superClass="de.innot.avreclipse.target.builder.winavr.app.release"/>
|
||||
<tool id="de.innot.avreclipse.tool.assembler.winavr.app.release.2028826852" name="AVR Assembler" superClass="de.innot.avreclipse.tool.assembler.winavr.app.release">
|
||||
<option id="de.innot.avreclipse.assembler.option.debug.level.1879261658" name="Generate Debugging Info" superClass="de.innot.avreclipse.assembler.option.debug.level" value="de.innot.avreclipse.assembler.option.debug.level.none" valueType="enumerated"/>
|
||||
<inputType id="de.innot.avreclipse.tool.assembler.input.684488257" superClass="de.innot.avreclipse.tool.assembler.input"/>
|
||||
</tool>
|
||||
<tool id="de.innot.avreclipse.tool.compiler.winavr.app.release.1484012078" name="AVR Compiler" superClass="de.innot.avreclipse.tool.compiler.winavr.app.release">
|
||||
<option id="de.innot.avreclipse.compiler.option.debug.level.142332208" name="Generate Debugging Info" superClass="de.innot.avreclipse.compiler.option.debug.level" value="de.innot.avreclipse.compiler.option.debug.level.none" valueType="enumerated"/>
|
||||
<option id="de.innot.avreclipse.compiler.option.optimize.781864802" name="Optimization Level" superClass="de.innot.avreclipse.compiler.option.optimize" value="de.innot.avreclipse.compiler.optimize.size" valueType="enumerated"/>
|
||||
<inputType id="de.innot.avreclipse.compiler.winavr.input.1449392936" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/>
|
||||
</tool>
|
||||
<tool id="de.innot.avreclipse.tool.cppcompiler.app.release.304178828" name="AVR C++ Compiler" superClass="de.innot.avreclipse.tool.cppcompiler.app.release">
|
||||
<option id="de.innot.avreclipse.cppcompiler.option.debug.level.647098977" name="Generate Debugging Info" superClass="de.innot.avreclipse.cppcompiler.option.debug.level" value="de.innot.avreclipse.cppcompiler.option.debug.level.none" valueType="enumerated"/>
|
||||
<option id="de.innot.avreclipse.cppcompiler.option.optimize.388407557" name="Optimization Level" superClass="de.innot.avreclipse.cppcompiler.option.optimize" value="de.innot.avreclipse.cppcompiler.optimize.size" valueType="enumerated"/>
|
||||
</tool>
|
||||
<tool id="de.innot.avreclipse.tool.linker.winavr.app.release.1663002938" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.app.release">
|
||||
<inputType id="de.innot.avreclipse.tool.linker.input.385570111" name="OBJ Files" superClass="de.innot.avreclipse.tool.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
</inputType>
|
||||
</tool>
|
||||
<tool id="de.innot.avreclipse.tool.cpplinker.app.release.1742464383" name="AVR C++ Linker" superClass="de.innot.avreclipse.tool.cpplinker.app.release"/>
|
||||
<tool id="de.innot.avreclipse.tool.archiver.winavr.base.730797197" name="AVR Archiver" superClass="de.innot.avreclipse.tool.archiver.winavr.base"/>
|
||||
<tool id="de.innot.avreclipse.tool.objdump.winavr.app.release.1553821745" name="AVR Create Extended Listing" superClass="de.innot.avreclipse.tool.objdump.winavr.app.release"/>
|
||||
<tool id="de.innot.avreclipse.tool.objcopy.flash.winavr.app.release.1546271656" name="AVR Create Flash image" superClass="de.innot.avreclipse.tool.objcopy.flash.winavr.app.release"/>
|
||||
<tool id="de.innot.avreclipse.tool.objcopy.eeprom.winavr.app.release.1079368587" name="AVR Create EEPROM image" superClass="de.innot.avreclipse.tool.objcopy.eeprom.winavr.app.release"/>
|
||||
<tool id="de.innot.avreclipse.tool.size.winavr.app.release.1958722224" name="Print Size" superClass="de.innot.avreclipse.tool.size.winavr.app.release"/>
|
||||
<tool id="de.innot.avreclipse.tool.avrdude.app.release.1292691772" name="AVRDude" superClass="de.innot.avreclipse.tool.avrdude.app.release"/>
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry excluding="src" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
</cconfiguration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<project id="MyClock.de.innot.avreclipse.project.winavr.elf_2.1.0.582386987" name="AVR Cross Target Application" projectType="de.innot.avreclipse.project.winavr.elf_2.1.0"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="scannerConfiguration">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
<scannerConfigBuildInfo instanceId="de.innot.avreclipse.configuration.app.release.662345902;de.innot.avreclipse.configuration.app.release.662345902.;de.innot.avreclipse.tool.compiler.winavr.app.release.1484012078;de.innot.avreclipse.compiler.winavr.input.1449392936">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="de.innot.avreclipse.core.AVRGCCManagedMakePerProjectProfileC"/>
|
||||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="refreshScope"/>
|
||||
</cproject>
|
27
.project
Normal file
27
.project
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>MyClock</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
<nature>de.innot.avreclipse.core.avrnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
28
.settings/de.innot.avreclipse.core.prefs
Normal file
28
.settings/de.innot.avreclipse.core.prefs
Normal file
@ -0,0 +1,28 @@
|
||||
avrtarget/ClockFrequency=16000000
|
||||
avrtarget/ExtRAMSize=0
|
||||
avrtarget/ExtendedRAM=false
|
||||
avrtarget/MCUType=atmega32
|
||||
avrtarget/UseEEPROM=false
|
||||
avrtarget/UseExtendedRAMforHeap=true
|
||||
avrtarget/avrdude/BitBangDelay=
|
||||
avrtarget/avrdude/Bitclock=5
|
||||
avrtarget/avrdude/EEPROMFile=
|
||||
avrtarget/avrdude/EEPROMFromConfig=true
|
||||
avrtarget/avrdude/FlashFile=
|
||||
avrtarget/avrdude/FlashFromConfig=true
|
||||
avrtarget/avrdude/Fuses/ByteValues=238\:217
|
||||
avrtarget/avrdude/Fuses/FileName=
|
||||
avrtarget/avrdude/Fuses/MCUid=atmega32
|
||||
avrtarget/avrdude/Fuses/UseFile=false
|
||||
avrtarget/avrdude/Fuses/Write=true
|
||||
avrtarget/avrdude/NoChipErase=false
|
||||
avrtarget/avrdude/NoSigCheck=false
|
||||
avrtarget/avrdude/NoVerify=false
|
||||
avrtarget/avrdude/NoWrite=false
|
||||
avrtarget/avrdude/OtherOptions=
|
||||
avrtarget/avrdude/ProgrammerID=programmerconfig.2
|
||||
avrtarget/avrdude/UseCounter=false
|
||||
avrtarget/avrdude/WriteEEPROM=false
|
||||
avrtarget/avrdude/WriteFlash=true
|
||||
avrtarget/perConfig=false
|
||||
eclipse.preferences.version=1
|
110
src/main.c
Normal file
110
src/main.c
Normal file
@ -0,0 +1,110 @@
|
||||
#include <stdint.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#include "uartdrv.h"
|
||||
|
||||
|
||||
|
||||
typedef struct clock_s {
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
uint8_t second;
|
||||
} clock_t;
|
||||
|
||||
volatile clock_t clock;
|
||||
volatile uint8_t tick;
|
||||
volatile uint16_t captValue = 0;
|
||||
volatile uint16_t gapValue = 0;
|
||||
|
||||
ISR(TIMER2_OVF_vect) {
|
||||
//tick = 1;
|
||||
|
||||
clock.second++;
|
||||
if (clock.second >= 60) {
|
||||
clock.second = 0;
|
||||
clock.minute++;
|
||||
}
|
||||
if (clock.minute >= 60) {
|
||||
clock.minute = 0;
|
||||
clock.hour++;
|
||||
}
|
||||
if (clock.hour >= 24) {
|
||||
clock.hour = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ISR(INT0_vect) {
|
||||
uint16_t tmpCnt = TCNT1;
|
||||
gapValue = tmpCnt - captValue;
|
||||
TCNT1 = 0;
|
||||
}
|
||||
|
||||
ISR(INT1_vect) {
|
||||
captValue = TCNT1;
|
||||
tick = 1;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
uartdrvInit();
|
||||
|
||||
clock.hour = 0;
|
||||
clock.minute = 0;
|
||||
clock.second = 0;
|
||||
|
||||
|
||||
TCCR2 = 0b00000101;
|
||||
ASSR |= (1 << AS2);
|
||||
TIMSK |= (1 << TOIE2) | (1 << TICIE1);
|
||||
|
||||
TCCR1A = 0;
|
||||
TCCR1B = (1 << CS12) | (1 << CS10);
|
||||
|
||||
PIND &= ~(1 << PD2);
|
||||
PIND &= ~(1 << PD3);
|
||||
PORTD |= (1 << PD2) | (1 << PD3);
|
||||
|
||||
MCUCR |= (1 << ISC11) | (1 << ISC10) | (1 << ISC01);
|
||||
GICR |= (1 << INT0) | (1 << INT1);
|
||||
|
||||
|
||||
sei();
|
||||
|
||||
printf("Hello world!\n");
|
||||
|
||||
|
||||
uint8_t start = 0;
|
||||
uint8_t bit = 0;
|
||||
|
||||
while (1) {
|
||||
if (tick != 0) {
|
||||
tick = 0;
|
||||
|
||||
uint16_t pulse = (((uint32_t) captValue) * 1000) / 15625;
|
||||
uint16_t gap = (((uint32_t) gapValue) * 1000) / 15625;
|
||||
|
||||
if (gap > 1500) {
|
||||
start = 1;
|
||||
clock.second = 0;
|
||||
}
|
||||
|
||||
if (pulse > 70 && pulse < 130) {
|
||||
bit = 0;
|
||||
} else if (pulse > 170 && pulse < 230) {
|
||||
bit = 1;
|
||||
} else {
|
||||
bit = 2;
|
||||
}
|
||||
|
||||
printf("%02d %02d %02d %u %u %u %u \n", clock.hour, clock.minute, clock.second, start, bit, pulse, gap);
|
||||
|
||||
|
||||
|
||||
start = 0;
|
||||
//printf("tick\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
93
src/uartdrv.c
Normal file
93
src/uartdrv.c
Normal file
@ -0,0 +1,93 @@
|
||||
#include <avr/io.h>
|
||||
#include <stdio.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include "uartdrv.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
volatile uartdrvCmdBuf_t uartdrvCmdBuf;
|
||||
|
||||
|
||||
|
||||
|
||||
void uartdrvInit() {
|
||||
|
||||
// UART
|
||||
// TXD
|
||||
DDRD |= (1 << PD1);
|
||||
|
||||
// transmitter enable
|
||||
UCSRB = (1 << TXEN) | (1 << RXEN) | (1 << RXCIE);
|
||||
// 8 data bit, no parity, 1 stop bit
|
||||
UCSRC = (1 << UCSZ1) | (1 << UCSZ0);
|
||||
// 19200 Baud @ 16MHz
|
||||
UBRRL = 51;
|
||||
UBRRH = 0;
|
||||
FILE *mystdout = fdevopen(uartdrvPutchar, NULL);
|
||||
stdout = mystdout;
|
||||
|
||||
uartdrvCmdBuf.idx = 0;
|
||||
uartdrvCmdBuf.cmd = 0;
|
||||
uartdrvCmdBuf.cmdStart = 0;
|
||||
uartdrvCmdBuf.cmdDelay = 0;
|
||||
uartdrvCmdBuf.cmdReady = 0;
|
||||
}
|
||||
|
||||
void uartdrvWrite(uint8_t o) {
|
||||
loop_until_bit_is_clear(PIND, PD2);
|
||||
loop_until_bit_is_set(UCSRA, UDRE);
|
||||
UDR = o;
|
||||
}
|
||||
|
||||
|
||||
int uartdrvPutchar(char c, FILE *stream) {
|
||||
if (c == '\n')
|
||||
uartdrvPutchar('\r', stream);
|
||||
uartdrvWrite((uint8_t) c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void uartdrvCmdCycle() {
|
||||
if (uartdrvCmdBuf.cmdStart == 1) {
|
||||
uartdrvCmdBuf.cmdDelay++;
|
||||
if (uartdrvCmdBuf.cmdDelay > UART_CMD_CYCLES) {
|
||||
uartdrvCmdBuf.idx = 0;
|
||||
uartdrvCmdBuf.cmdStart = 0;
|
||||
uartdrvCmdBuf.cmdDelay= 0;
|
||||
// myPrintf("clear invalid cmd\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void uartdrvCmdReceived() {
|
||||
uartdrvWrite(0x7f);
|
||||
uartdrvWrite(uartdrvCmdBuf.cmd);
|
||||
uartdrvWrite(0);
|
||||
uartdrvWrite(0);
|
||||
uartdrvWrite(0);
|
||||
}
|
||||
|
||||
ISR(USART_RXC_vect) {
|
||||
uint8_t c = UDR;
|
||||
if (uartdrvCmdBuf.cmdReady != 1) {
|
||||
if (uartdrvCmdBuf.idx == 0) {
|
||||
uartdrvCmdBuf.cmdStart = 1;
|
||||
uartdrvCmdBuf.cmd = c;
|
||||
uartdrvCmdBuf.idx++;
|
||||
} else if (uartdrvCmdBuf.idx >= 1 && uartdrvCmdBuf.idx <= UART_CMD_BUF_SIZE) {
|
||||
uartdrvCmdBuf.buf[uartdrvCmdBuf.idx - 1] = c;
|
||||
uartdrvCmdBuf.idx++;
|
||||
}
|
||||
|
||||
if (uartdrvCmdBuf.idx == (UART_CMD_BUF_SIZE + 1)) {
|
||||
|
||||
uartdrvCmdBuf.idx = 0;
|
||||
uartdrvCmdBuf.cmdStart = 0;
|
||||
uartdrvCmdBuf.cmdDelay = 0;
|
||||
uartdrvCmdBuf.cmdReady = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
32
src/uartdrv.h
Normal file
32
src/uartdrv.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef UARTDRV_H_
|
||||
#define UARTDRV_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#define UART_CMD_BUF_SIZE 4
|
||||
#define UART_CMD_CYCLES 10
|
||||
|
||||
typedef struct uartdrvCmdBuf_s {
|
||||
uint8_t idx;
|
||||
uint8_t cmdStart;
|
||||
uint8_t cmdDelay;
|
||||
uint8_t cmdReady;
|
||||
uint8_t cmd;
|
||||
uint8_t buf[UART_CMD_BUF_SIZE];
|
||||
} uartdrvCmdBuf_t;
|
||||
|
||||
|
||||
extern void uartInitCallback();
|
||||
extern void uartWriteCallback(uint8_t o);
|
||||
|
||||
int uartdrvPutchar(char c, FILE *stream);
|
||||
void uartdrvInit();
|
||||
void uartdrvWrite(uint8_t o);
|
||||
|
||||
void uartdrvCmdCycle();
|
||||
|
||||
void uartdrvCmdReceived();
|
||||
|
||||
#endif /* UARTDRV_H_ */
|
Loading…
x
Reference in New Issue
Block a user