Skip to content

Commit

Permalink
added ATtiny45 in timers and interruptions
Browse files Browse the repository at this point in the history
  • Loading branch information
piif committed Oct 31, 2015
1 parent 4d36a3e commit a39b8bd
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 19 deletions.
57 changes: 50 additions & 7 deletions .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.370206218.1417181949" moduleId="org.eclipse.cdt.core.settings" name="uno">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" 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.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
Expand Down Expand Up @@ -46,12 +46,12 @@
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.370206218.1417181949.2020514329" moduleId="org.eclipse.cdt.core.settings" name="fiov3">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" 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.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
Expand Down Expand Up @@ -87,12 +87,12 @@
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.370206218.1417181949.112706981" moduleId="org.eclipse.cdt.core.settings" name="arduino_due_x_dbg">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" 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.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
Expand Down Expand Up @@ -124,21 +124,64 @@
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
<cconfiguration id="0.370206218.1417181949.2147346315">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.370206218.1417181949.2147346315" moduleId="org.eclipse.cdt.core.settings" name="attinyx5">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="attinyx5" id="0.370206218.1417181949.2147346315" name="attinyx5" parent="org.eclipse.cdt.build.core.prefbase.cfg">
<folderInfo id="0.370206218.1417181949.2147346315." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.base.1385910214" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.base.1754106655" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
<builder arguments="TARGET_BOARD=${ConfigName}" buildPath="${ProjDirPath}" command="${MAKE}" id="cdt.managedbuild.target.gnu.builder.base.1784100831" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.909991675" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1087059310" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.698445656" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.2049295398" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.395287470" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.706304390" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.560771562" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.808429850" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.assembler.base.418887508" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.466459361" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="ArduinoTools.de.innot.avreclipse.project.winavr.staticlib.2113525027" name="AVR Cross Target Static Library"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Mega"/>
<configuration configurationName="arduino_due_x_dbg"/>
<configuration configurationName="Yun"/>
<configuration configurationName="Micro"/>
<configuration configurationName="Uno">
<configuration configurationName="Mega"/>
<configuration configurationName="uno">
<resource resourceType="PROJECT" workspacePath="/ArduinoTools"/>
</configuration>
<configuration configurationName="uno">
<configuration configurationName="fiov3"/>
<configuration configurationName="Uno">
<resource resourceType="PROJECT" workspacePath="/ArduinoTools"/>
</configuration>
<configuration configurationName="Micro"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
<storageModule moduleId="scannerConfiguration">
Expand Down
10 changes: 10 additions & 0 deletions .settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@
</provider>
</extension>
</configuration>
<configuration id="0.370206218.1417181949.2147346315" name="attinyx5">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="true" env-hash="1734337372436893693" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${MAKE} TARGET_BOARD=${ConfigName} CMD=&quot;${COMMAND} ${FLAGS} -E -P -v -dD '${INPUTS}'&quot; discovery">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
</project>
47 changes: 45 additions & 2 deletions ArduinoTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#define NB_INTERRUPT _VECTORS_SIZE / _VECTOR_SIZE
#endif

TCCR_REG_TINY *TCCR1_bits = (TCCR_REG_TINY *)&TCCR1;
GTCCR_REG_TINY *GTCCR_bits = (GTCCR_REG_TINY *)&GTCCR;

extern InterruptHandler interruptHandler[];
extern int interruptData[];

Expand Down Expand Up @@ -184,13 +187,33 @@ bool enableTimerInterrupt(byte timer, byte mode) {
// }
//#endif

#if defined(__AVR_ATtinyX5__)
if (timer == 0) {
TIMSK |= (1<<mode);
return true;
} else if (timer == 1) {
switch(mode) {
case TIMER_COMPARE_A:
TIMSK |= (1<<OCIE1A);
return true;
case TIMER_COMPARE_B:
TIMSK |= (1<<OCIE1B);
return true;
case TIMER_OVERFLOW:
TIMSK |= (1<<TOIE1);
return true;
}
}
#endif
switch(timer) {
#ifdef TIMSK0
case 0:
TIMSK0 |= (1<<mode);
return true;
case 1:
TIMSK1 |= (1<<mode);
return true;
#endif
// iom32u4.h defines this register, but it does not exists !
#if defined(TIMSK2) && !defined(__AVR_ATmega32U4__)
case 2:
Expand Down Expand Up @@ -236,13 +259,33 @@ bool enableTimerInterrupt(byte timer, byte mode) {
}

bool disableTimerInterrupt(byte timer, byte mode) {
#if defined(__AVR_ATtinyX5__)
if (timer == 0) {
TIMSK = ~(1<<mode);
return true;
} else if (timer == 1) {
switch(mode) {
case TIMER_COMPARE_A:
TIMSK = ~(1<<OCIE1A);
return true;
case TIMER_COMPARE_B:
TIMSK = ~(1<<OCIE1B);
return true;
case TIMER_OVERFLOW:
TIMSK = ~(1<<TOIE1);
return true;
}
}
#endif
switch(timer) {
#ifdef TIMSK0
case 0:
TIMSK0 &= ~(1<<mode);
return true;
case 1:
TIMSK1 &= ~(1<<mode);
return true;
#endif
#if defined(TIMSK2) && !defined(__AVR_ATmega32U4__)
case 2:
TIMSK2 &= ~(1<<mode);
Expand Down Expand Up @@ -409,11 +452,11 @@ void sleepNow(word sleep_mode) {
* SLEEP_MODE_PWR_DOWN -the most power savings
*/
set_sleep_mode(sleep_mode); // sleep mode is set here
sleep_enable(); // then, it's enabled
// sleep_enable(); // then, it's enabled -> done by sleep_mode()

sleep_mode(); // here, we really enter in sleep mode
// Here an external event wake up the CPU
sleep_disable(); // disable sleep mode
// sleep_disable(); // disable sleep mode -> done by sleep_mode()
}

void sleepNow() {
Expand Down
26 changes: 26 additions & 0 deletions ArduinoTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ typedef void (*InterruptHandler)(int data);
((p) == 19) ? 2 : \
((p) == 20) ? 1 : \
((p) == 21) ? 0 : -1)
#elif defined (__AVR_ATtinyX5__)
#define INTERRUPT_FOR_PIN(p) (((p) == 2) ? 0 : -1)
#else
#define INTERRUPT_FOR_PIN(p) (-1)
#warning variant not implemented
Expand Down Expand Up @@ -139,6 +141,30 @@ typedef union _tccr {
} fields;
} TCCR_REG;

#if defined __AVR_ATtinyX5__
// specific case for ATTiny Timer 1
typedef struct _tccr_tiny {
// ordered from low bits to high bits
byte _CS1:4;
byte _COM1A:2;
byte _PWM1A:1; // 0 = off / 1 = active
byte _CTC1:1;
} TCCR_REG_TINY;
extern TCCR_REG_TINY *TCCR1_bits;

typedef struct _gtccr_tiny {
// ordered from low bits to high bits
byte _PSR0:1;
byte _PSR1:1;
byte _FOC1A:1;
byte _FOC1B:1;
byte _COM1B:2;
byte _PWM1B:1;
byte _TSM:1;
} GTCCR_REG_TINY;
extern GTCCR_REG_TINY *GTCCR_bits;
#endif

#if defined __AVR_ATmega32U4__
// different register on timer4
typedef union _tccr4 {
Expand Down
4 changes: 2 additions & 2 deletions hexTools/hexTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void hexDump(byte *data, int len, Stream *s) {
while(iData < (word)len) {
if ((iData & 0xF) == 0) {
if (iData != 0) {
s->write(line, sizeof(HexDumpModel) - 1);
s->write((byte *)line, sizeof(HexDumpModel) - 1);
}
memcpy(line, HexDumpModel, sizeof(HexDumpModel));
iData = 0, iHex = 6, iChar = 55;
Expand All @@ -54,6 +54,6 @@ void hexDump(byte *data, int len, Stream *s) {
iData++;
}
if ((iData & 0xF) != 0) {
s->write(line, sizeof(HexDumpModel) - 1);
s->write((byte *)line, sizeof(HexDumpModel) - 1);
}
}
Loading

0 comments on commit a39b8bd

Please sign in to comment.